Removed useless class, cleaning Skeleton.cpp
This commit is contained in:
parent
cca1d78419
commit
b054971625
|
@ -1,33 +0,0 @@
|
|||
#ifndef FREE_FLY_CAMERA_HPP
|
||||
#define FREE_FLY_CAMERA_HPP
|
||||
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
constexpr auto PI_2_MINUS_EPSILON = M_PI_2 - 0.1;
|
||||
|
||||
class FreeFlyCamera
|
||||
{
|
||||
public:
|
||||
FreeFlyCamera();
|
||||
|
||||
void look() const;
|
||||
void nextStep(int width, int height);
|
||||
|
||||
private:
|
||||
double speed;
|
||||
double sensitivity;
|
||||
|
||||
sf::Vector3<double> position;
|
||||
sf::Vector3<double> target;
|
||||
sf::Vector3<double> forward;
|
||||
sf::Vector3<double> left;
|
||||
|
||||
double theta;
|
||||
double phi;
|
||||
|
||||
void vectorsFromAngles();
|
||||
|
||||
};
|
||||
|
||||
#endif // FREE_FLY_CAMERA_HPP
|
|
@ -52,12 +52,13 @@ class Skeleton
|
|||
/// For example, with the following skeleton :
|
||||
///
|
||||
///
|
||||
/// \code
|
||||
/// 3 6
|
||||
/// | |
|
||||
/// 1-2-4-5-8-9
|
||||
/// |
|
||||
/// 7
|
||||
///
|
||||
/// \endcode
|
||||
/// It would return neighbors_counters = [1,3,1,2,4,1,1,2,1]
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
std::vector<unsigned int> countNeighbors();
|
||||
|
@ -89,7 +90,7 @@ class Skeleton
|
|||
/// \param branches1
|
||||
/// \param branches2
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
friend couples<unsigned int> branchesMatching(couples<cv::KeyPoint> keypoints,
|
||||
friend couples<unsigned int> branchesMatching(couples<cv::KeyPoint> const& keypoints,
|
||||
std::vector<Skeleton> branches1,
|
||||
std::vector<Skeleton> branches2
|
||||
);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace sft
|
||||
{
|
||||
|
||||
FreeFlyCamera::FreeFlyCamera() : speed(0.1), sensitivity(0.001), theta(0), phi(0)
|
||||
FreeFlyCamera::FreeFlyCamera() : speed(10), sensitivity(0.001), theta(0), phi(0)
|
||||
{
|
||||
vectorsFromAngles();
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ file(GLOB SKELETON_SRC
|
|||
)
|
||||
|
||||
add_executable(Skeleton ${SKELETON_SRC})
|
||||
target_link_libraries(Skeleton ${SFML_LIBRARIES} ${OPENGL_LIBRARIES})
|
||||
target_link_libraries(Skeleton ${SFML_LIBRARIES} ${OPENGL_LIBRARIES} SFMLTools)
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <GL/glu.h>
|
||||
#include <boost/algorithm/clamp.hpp>
|
||||
#include "Skeleton/VectorFunctions.hpp"
|
||||
#include "Skeleton/FreeFlyCamera.hpp"
|
||||
|
||||
FreeFlyCamera::FreeFlyCamera() : speed(10), sensitivity(0.001), theta(0), phi(0)
|
||||
{
|
||||
vectorsFromAngles();
|
||||
}
|
||||
|
||||
void FreeFlyCamera::nextStep(int width, int height)
|
||||
{
|
||||
// Gestion de la souris
|
||||
sf::Vector2i mouse_position = sf::Mouse::getPosition();
|
||||
theta += sensitivity * (width/2-mouse_position.x);
|
||||
phi += sensitivity * (height/2-mouse_position.y);
|
||||
vectorsFromAngles();
|
||||
|
||||
// Gestion du clavier
|
||||
sf::Vector3<double> move;
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
|
||||
{
|
||||
move += forward * speed;
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
|
||||
{
|
||||
move -= forward * speed;
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
|
||||
{
|
||||
move += left * speed;
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
|
||||
{
|
||||
move -= left * speed;
|
||||
}
|
||||
|
||||
position += move;
|
||||
target += move;
|
||||
}
|
||||
|
||||
void FreeFlyCamera::vectorsFromAngles()
|
||||
{
|
||||
phi = boost::algorithm::clamp(phi,-PI_2_MINUS_EPSILON,PI_2_MINUS_EPSILON);
|
||||
|
||||
// Passage du sphérique au cartésien
|
||||
double r_temp = std::cos(phi);
|
||||
|
||||
forward.z = std::sin(phi);
|
||||
forward.x = r_temp * std::cos(theta);
|
||||
forward.y = r_temp * std::sin(theta);
|
||||
|
||||
left = crossProduct(sf::Vector3<double>(0,0,1), forward);
|
||||
normalize(left);
|
||||
|
||||
target = position + forward;
|
||||
}
|
||||
|
||||
void FreeFlyCamera::look() const
|
||||
{
|
||||
gluLookAt(position.x, position.y, position.z,
|
||||
target.x, target.y, target.z,
|
||||
0,0,1);
|
||||
}
|
|
@ -4,9 +4,11 @@
|
|||
#include <valarray>
|
||||
#include <GL/gl.h>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "Skeleton/Skeleton.hpp"
|
||||
#include "Skeleton/Box.hpp"
|
||||
#include "Geometry/MathFunctions.hpp"
|
||||
|
||||
std::stringstream Skeleton::stream{};
|
||||
|
||||
|
@ -211,7 +213,7 @@ std::vector<unsigned int> Skeleton::findOnes(std::vector<std::vector<bool>> cons
|
|||
return onesPosition;
|
||||
}
|
||||
|
||||
std::vector<std::pair<unsigned int,unsigned int>> branchesMatching(std::vector<std::pair<cv::KeyPoint,cv::KeyPoint>> keypoints, std::vector<Skeleton> branches1, std::vector<Skeleton> branches2)
|
||||
std::vector<std::pair<unsigned int,unsigned int>> branchesMatching(std::vector<std::pair<cv::KeyPoint,cv::KeyPoint>> const& keypoints, std::vector<Skeleton> branches1, std::vector<Skeleton> branches2)
|
||||
{
|
||||
std::vector<std::pair<unsigned int,unsigned int>> matchingBranches;
|
||||
|
||||
|
@ -262,12 +264,8 @@ std::vector<std::pair<unsigned int,unsigned int>> branchesMatching(std::vector<s
|
|||
}
|
||||
|
||||
// Initialisation of a 2D matching matrix couting the number of times that each branche of the first skeleton is associated to another branche of the second skeleton as their respective associated keypoints are paired
|
||||
boost::numeric::ublas::matrix<unsigned int> matchingMatrix{branches1.size(),branches2.size()};
|
||||
for (auto i = 0u; i < branches1.size(); i++)
|
||||
{
|
||||
for (auto j = 0u; j < branches2.size(); j++)
|
||||
matchingMatrix(i,j) = 0;
|
||||
}
|
||||
boost::numeric::ublas::matrix<unsigned int> matchingMatrix
|
||||
= boost::numeric::ublas::zero_matrix<unsigned int>{branches1.size(),branches2.size()};
|
||||
|
||||
for (unsigned int i = 0; i < correspondingBranches1.size() ; i++)
|
||||
{
|
||||
|
@ -308,7 +306,8 @@ std::vector<std::pair<unsigned int,unsigned int>> branchesMatching(std::vector<s
|
|||
unsigned int searchNearestBrancheIndex(cv::KeyPoint const& keypoint, std::vector<Skeleton> branches)
|
||||
{
|
||||
unsigned int nearest_branche_index = 0;
|
||||
float shortest_distance;
|
||||
float shortest_distance = std::numeric_limits<float>::max();
|
||||
|
||||
for (unsigned int j = 0 ; j < branches.size() ; j++)
|
||||
{
|
||||
auto const& branche = branches[j];
|
||||
|
@ -318,55 +317,8 @@ unsigned int searchNearestBrancheIndex(cv::KeyPoint const& keypoint, std::vector
|
|||
auto const& edge = branche.m_edges[k];
|
||||
|
||||
// We compute the coordinates of the projection of the keypoint on each edge
|
||||
float d_keypoint_edge;
|
||||
float d_keypoint_edge = geo::distanceToSegment(keypoint.pt, branche.m_vertices[edge.x()], branche.m_vertices[edge.y()]);
|
||||
|
||||
float xK = keypoint.pt.x;
|
||||
float yK = keypoint.pt.y;
|
||||
|
||||
float xv1 = branche.m_vertices[edge.x()].x();
|
||||
float yv1 = branche.m_vertices[edge.x()].y();
|
||||
float xv2 = branche.m_vertices[edge.y()].x();
|
||||
float yv2 = branche.m_vertices[edge.y()].y();
|
||||
|
||||
float xv1v2 = xv2 - xv1;
|
||||
float yv1v2 = yv2 - yv1;
|
||||
|
||||
float a = yv1v2;
|
||||
float b = -xv1v2;
|
||||
float c = -a*xv1 - b*yv1;
|
||||
|
||||
float na1 = xv1v2;
|
||||
float nb1 = yv1v2;
|
||||
float nc1 = -na1*xv1 - nb1*yv1;
|
||||
float nc2 = -na1*xv2 - nb1*yv2;
|
||||
|
||||
float yH1 = (na1/(na1*na1+nb1*nb1))*(na1*yK-nb1*nc1/na1-nb1*xK);
|
||||
float xH1 = -(nb1*yH1+nc1)/na1;
|
||||
float yH2 = (na1/(na1*na1+nb1*nb1))*(na1*yK-nb1*nc2/na1-nb1*xK);
|
||||
float xH2 = -(nb1*yH2+nc2)/na1;
|
||||
|
||||
float d_v1_v2 = std::sqrt((xv1-xv2)*(xv1-xv2)+(yv1-yv2)*(yv1-yv2));
|
||||
float d_K_H1 = std::sqrt((xK-xH1)*(xK-xH1)+(yK-yH1)*(yK-yH1));
|
||||
float d_K_H2 = std::sqrt((xK-xH2)*(xK-xH2)+(yK-yH2)*(yK-yH2));
|
||||
|
||||
if (d_K_H1 + d_K_H2 <= d_v1_v2)
|
||||
{
|
||||
float yH = (a/(a*a+b*b))*(a*yK-b*c/a-b*xK);
|
||||
float xH = -(b*yH+c)/a;
|
||||
float d_K_H = std::sqrt((xK-xH)*(xK-xH)+(yK-yH)*(yK-yH));
|
||||
d_keypoint_edge = d_K_H;
|
||||
}
|
||||
else
|
||||
{
|
||||
float d_K_v1 = std::sqrt((xK-xv1)*(xK-xv1)+(yK-yv1)*(yK-yv1));
|
||||
float d_K_v2 = std::sqrt((xK-xv2)*(xK-xv2)+(yK-yv2)*(yK-yv2));
|
||||
d_keypoint_edge = std::min(d_K_v1,d_K_v2);
|
||||
}
|
||||
|
||||
if (j+k == 0)
|
||||
{
|
||||
shortest_distance = d_keypoint_edge;
|
||||
}
|
||||
if (d_keypoint_edge < shortest_distance)
|
||||
{
|
||||
shortest_distance = d_keypoint_edge;
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#include "Skeleton/FreeFlyCamera.hpp"
|
||||
#include "SFMLTools/FreeFlyCamera.hpp"
|
||||
#include "Skeleton/Skeleton.hpp"
|
||||
|
||||
// Full hd : 1920x1080
|
||||
constexpr auto WIDTH = 1920;
|
||||
constexpr auto HEIGHT = 1080;
|
||||
|
||||
void drawScene(FreeFlyCamera const& camera, std::vector<Skeleton> const& s, std::vector<Skeleton> const& s2, std::vector<std::pair<unsigned int, unsigned int>> const& matching, std::vector<std::array<float,3>> const& colors);
|
||||
void drawScene(sft::FreeFlyCamera const& camera, std::vector<Skeleton> const& s, std::vector<Skeleton> const& s2, std::vector<std::pair<unsigned int, unsigned int>> const& matching, std::vector<std::array<float,3>> const& colors);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -95,7 +95,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Camera
|
||||
auto camera = FreeFlyCamera{};
|
||||
auto camera = sft::FreeFlyCamera{};
|
||||
|
||||
// la boucle principale
|
||||
auto running = true;
|
||||
|
@ -157,7 +157,7 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
void drawScene(FreeFlyCamera const& camera, std::vector<Skeleton> const& split, std::vector<Skeleton> const& split2, std::vector<std::pair<unsigned int, unsigned int>> const& matching, std::vector<std::array<float,3>> const& colors)
|
||||
void drawScene(sft::FreeFlyCamera const& camera, std::vector<Skeleton> const& split, std::vector<Skeleton> const& split2, std::vector<std::pair<unsigned int, unsigned int>> const& matching, std::vector<std::array<float,3>> const& colors)
|
||||
{
|
||||
// Initialisation
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
|
Loading…
Reference in New Issue