diff --git a/Code/include/Skeleton/FreeFlyCamera.hpp b/Code/include/Skeleton/FreeFlyCamera.hpp deleted file mode 100644 index 6722bd3..0000000 --- a/Code/include/Skeleton/FreeFlyCamera.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef FREE_FLY_CAMERA_HPP -#define FREE_FLY_CAMERA_HPP - -#include -#include - -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 position; - sf::Vector3 target; - sf::Vector3 forward; - sf::Vector3 left; - - double theta; - double phi; - - void vectorsFromAngles(); - -}; - -#endif // FREE_FLY_CAMERA_HPP diff --git a/Code/include/Skeleton/Skeleton.hpp b/Code/include/Skeleton/Skeleton.hpp index ea3e6f0..acbc9cb 100644 --- a/Code/include/Skeleton/Skeleton.hpp +++ b/Code/include/Skeleton/Skeleton.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 countNeighbors(); @@ -89,7 +90,7 @@ class Skeleton /// \param branches1 /// \param branches2 //////////////////////////////////////////////////////////////////////// - friend couples branchesMatching(couples keypoints, + friend couples branchesMatching(couples const& keypoints, std::vector branches1, std::vector branches2 ); diff --git a/Code/src/SFMLTools/FreeFlyCamera.cpp b/Code/src/SFMLTools/FreeFlyCamera.cpp index 11fbf72..c75c4bf 100644 --- a/Code/src/SFMLTools/FreeFlyCamera.cpp +++ b/Code/src/SFMLTools/FreeFlyCamera.cpp @@ -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(); } diff --git a/Code/src/Skeleton/CMakeLists.txt b/Code/src/Skeleton/CMakeLists.txt index c895e8e..3bfea69 100644 --- a/Code/src/Skeleton/CMakeLists.txt +++ b/Code/src/Skeleton/CMakeLists.txt @@ -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) diff --git a/Code/src/Skeleton/FreeFlyCamera.cpp b/Code/src/Skeleton/FreeFlyCamera.cpp deleted file mode 100644 index f1ae0d2..0000000 --- a/Code/src/Skeleton/FreeFlyCamera.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include -#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 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(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); -} diff --git a/Code/src/Skeleton/Skeleton.cpp b/Code/src/Skeleton/Skeleton.cpp index 7110d5b..2f0eb35 100644 --- a/Code/src/Skeleton/Skeleton.cpp +++ b/Code/src/Skeleton/Skeleton.cpp @@ -4,9 +4,11 @@ #include #include #include + #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 Skeleton::findOnes(std::vector> cons return onesPosition; } -std::vector> branchesMatching(std::vector> keypoints, std::vector branches1, std::vector branches2) +std::vector> branchesMatching(std::vector> const& keypoints, std::vector branches1, std::vector branches2) { std::vector> matchingBranches; @@ -262,12 +264,8 @@ std::vector> branchesMatching(std::vector 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 matchingMatrix + = boost::numeric::ublas::zero_matrix{branches1.size(),branches2.size()}; for (unsigned int i = 0; i < correspondingBranches1.size() ; i++) { @@ -308,7 +306,8 @@ std::vector> branchesMatching(std::vector branches) { unsigned int nearest_branche_index = 0; - float shortest_distance; + float shortest_distance = std::numeric_limits::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; diff --git a/Code/src/Skeleton/main.cpp b/Code/src/Skeleton/main.cpp index 8fef6be..4b576ed 100644 --- a/Code/src/Skeleton/main.cpp +++ b/Code/src/Skeleton/main.cpp @@ -8,14 +8,14 @@ #include #include -#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 const& s, std::vector const& s2, std::vector> const& matching, std::vector> const& colors); +void drawScene(sft::FreeFlyCamera const& camera, std::vector const& s, std::vector const& s2, std::vector> const& matching, std::vector> 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 const& split, std::vector const& split2, std::vector> const& matching, std::vector> const& colors) +void drawScene(sft::FreeFlyCamera const& camera, std::vector const& split, std::vector const& split2, std::vector> const& matching, std::vector> const& colors) { // Initialisation glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);