//////////////////////////////////////////////////////////////////////////////// // // Paella // Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX // Authors : // Thomas FORGIONE // Emilie JALRAS // Marion LENFANT // Thierry MALON // Amandine PAILLOUX // // This file is part of the project Paella // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. // // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it freely, // subject to the following restrictions: // // 1. The origin of this software must not be misrepresented; // you must not claim that you wrote the original software. // If you use this software in a product, an acknowledgment // in the product documentation would be appreciated but is not required. // // 2. Altered source versions must be plainly marked as such, // and must not be misrepresented as being the original software. // // 3. This notice may not be removed or altered from any source distribution. //////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include // Yes, this is a uggly hack... I need it to make this test work #define private public #include #undef private // Full hd : 1920x1080 constexpr auto WIDTH = 1920; constexpr auto HEIGHT = 1080; void drawScene(sft::FreeFlyCamera const& camera, Skeleton const& s, Skeleton const& s2, std::vector> const& matching, std::vector> const& colors); int main(int argc, char *argv[]) { if (argc < 2) { std::cout << "I need a skeleton !" << std::endl; return -1; } std::srand(std::time(0)); // Création de la fenêtre sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Skeleton", sf::Style::Fullscreen, sf::ContextSettings(32)); window.setVerticalSyncEnabled(true); window.setMouseCursorVisible(false); //Initialisation du mode 3D glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70,(double)WIDTH/HEIGHT,0.2,10000); // Initialisation de Z-Buffer glEnable(GL_DEPTH_TEST); // Activer les textures glEnable(GL_TEXTURE_2D); // Autoriser la transparence glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Ces 2 lignes améliorent le rendu glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); glHint(GL_POINT_SMOOTH_HINT,GL_NICEST); // On efface le tampon d'affichage glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush(); // Init mesh Skeleton s, s2; s.loadFromFile(std::string{argv[1]}); std::vector> matching; s.split(); #include "init.cxx" if (argc > 2) { s2.loadFromFile(std::string{argv[2]}); s2.split(); std::swap(s2.m_branches[0], s2.m_branches[1]); std::cout << "Matching..." << std::endl; matching = branchesMatching(keypoints1, s, s2); std::cout << "Finished..." << std::endl; for (auto const& pair : matching) std::cout << pair.first << " -> " << pair.second << std::endl; } std::vector> colors; for (auto i = 0u; i < s.numberOfBranches(); i++) { float r = static_cast(std::rand())/RAND_MAX; float g = static_cast(std::rand())/RAND_MAX; float b = static_cast(std::rand())/RAND_MAX; colors.push_back({{r,g,b}}); } // Camera auto camera = sft::FreeFlyCamera{}; // la boucle principale auto running = true; auto captureRequired = false; while (running) { // gestion des évènements sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { // on stoppe le programme running = false; } else if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::Escape) { running = false; } else if (event.key.code == sf::Keyboard::P) { captureRequired = true; } } else if (event.type == sf::Event::MouseMoved) { // Hum... } else if (event.type == sf::Event::Resized) { // on ajuste le viewport lorsque la fenêtre est redimensionnée glViewport(0, 0, event.size.width, event.size.height); } } // Les trucs qui sont pas des évènements camera.nextStep(WIDTH, HEIGHT); sf::Mouse::setPosition(sf::Vector2i{WIDTH/2, HEIGHT/2}); // Dessin de la scene drawScene(camera, s, s2, matching, colors); if (captureRequired) { window.capture().saveToFile("capture.jpg"); captureRequired = false; } // termine la trame courante (en interne, échange les deux tampons de rendu) window.display(); } // libération des ressources... return 0; } void drawScene(sft::FreeFlyCamera const& camera, Skeleton const& split, Skeleton const& split2, std::vector> const& matching, std::vector> const& colors) { // Initialisation glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Position Camera gluLookAt(positionCamera, positionCible, vecteurVertical) camera.look(); for (auto i = 0u; i < matching.size(); i++) { // Find random color glColor3f(colors[i][0], colors[i][1], colors[i][2]); split.draw(i); glPushMatrix(); glTranslatef(1000,0,0); split2.draw(i); glPopMatrix(); glPushMatrix(); glTranslatef(0,-1500,0); split.draw(matching[i].first); glPushMatrix(); glTranslatef(1000,0,0); split2.draw(matching[i].second); glPopMatrix(); glPopMatrix(); } // MAJ de l'écran glFlush(); }