소스 검색

Ready to pull request.

Former-commit-id: 5dd953c1b4b0b06294f5e7e5e620473d477580ca
Amir Vaxman 7 년 전
부모
커밋
379b170289

+ 0 - 88
tutorial/802_LevenbergMarquadt/CMakeLists.txt

@@ -1,88 +0,0 @@
-cmake_minimum_required(VERSION 2.8.12)
-project(levenberg-marquadt)
-
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
-
-find_package(LIBIGL QUIET)
-find_package(LIBHEDRA QUIET)
-
-if (NOT LIBIGL_FOUND)
-   message(FATAL_ERROR "libigl not found --- You can download it using: \n git clone --recursive https://github.com/libigl/libigl.git ${PROJECT_SOURCE_DIR}/../libigl")
-endif()
-
-if (NOT LIBHEDRA_FOUND)
-   message(FATAL_ERROR "libhedra not found --- You can download it in https://github.com/avaxman/libhedra.git")
-endif()
-
-# Compilation flags: adapt to your needs 
-if(MSVC)
-  # Enable parallel compilation
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj") 
-  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} )
-  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} )
-else()
-  # Libigl requires a modern C++ compiler that supports c++11
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 
-  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "." )
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
-endif()
-
-# libigl options: choose between header only and compiled static library
-# Header-only is preferred for small projects. For larger projects the static build
-# considerably reduces the compilation times
-option(LIBIGL_USE_STATIC_LIBRARY "Use LibIGL as static library" OFF)
-
-# add a customizable menu bar
-option(LIBIGL_WITH_NANOGUI     "Use Nanogui menu"   OFF)
-
-# libigl options: choose your dependencies (by default everything is OFF except opengl) 
-option(LIBIGL_WITH_VIEWER      "Use OpenGL viewer"  ON)
-option(LIBIGL_WITH_OPENGL      "Use OpenGL"         ON)
-option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW"           ON)
-option(LIBIGL_WITH_BBW         "Use BBW"            OFF)
-option(LIBIGL_WITH_EMBREE      "Use Embree"         OFF)
-option(LIBIGL_WITH_PNG         "Use PNG"            OFF)
-option(LIBIGL_WITH_TETGEN      "Use Tetgen"         OFF)
-option(LIBIGL_WITH_TRIANGLE    "Use Triangle"       OFF)
-option(LIBIGL_WITH_XML         "Use XML"            OFF)
-option(LIBIGL_WITH_LIM         "Use LIM"            OFF)
-option(LIBIGL_WITH_COMISO      "Use CoMiso"         OFF)
-option(LIBIGL_WITH_MATLAB      "Use Matlab"         OFF) # This option is not supported yet
-option(LIBIGL_WITH_MOSEK       "Use MOSEK"          OFF) # This option is not supported yet
-option(LIBIGL_WITH_CGAL        "Use CGAL"           OFF)
-if(LIBIGL_WITH_CGAL) # Do not remove or move this block, the cgal build system fails without it
-  find_package(CGAL REQUIRED)
-  set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "CGAL's CMAKE Setup is super annoying ")
-  include(${CGAL_USE_FILE})
-endif()
-
-# Adding libigl: choose the path to your local copy libigl 
-# This is going to compile everything you requested 
-#message(FATAL_ERROR "${PROJECT_SOURCE_DIR}/../libigl/cmake")
-add_subdirectory("${LIBIGL_INCLUDE_DIR}/../shared/cmake" "libigl")
-
-# libigl information 
-message("libigl includes: ${LIBIGL_INCLUDE_DIRS}")
-message("libigl libraries: ${LIBIGL_LIBRARIES}")
-message("libigl extra sources: ${LIBIGL_EXTRA_SOURCES}")
-message("libigl extra libraries: ${LIBIGL_EXTRA_LIBRARIES}")
-message("libigl definitions: ${LIBIGL_DEFINITIONS}")
-
-message("libhedra includes: ${LIBHEDRA_INCLUDE_DIRS}")
-
-# Prepare the build environment
-include_directories(${LIBIGL_INCLUDE_DIRS})
-add_definitions(${LIBIGL_DEFINITIONS})
-
-include_directories(${LIBHEDRA_INCLUDE_DIRS})
-
-# Store location of data directory
-set(DATA_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../data CACHE PATH "location of mesh data")
-add_definitions("-DDATA_PATH=\"${DATA_PATH}\"")
-
-include_directories(${CMAKE_CURRENT_SOURCE_DIR})
-
-# Add your project files
-FILE(GLOB SRCFILES *.cpp)
-add_executable(${PROJECT_NAME}_bin ${SRCFILES} ${LIBIGL_EXTRA_SOURCES})
-target_link_libraries(${PROJECT_NAME}_bin ${LIBIGL_LIBRARIES} ${LIBIGL_EXTRA_LIBRARIES})

+ 0 - 24
tutorial/802_LevenbergMarquadt/cmake/FindLIBHEDRA.cmake

@@ -1,24 +0,0 @@
-# - Try to find the LIBHEDRA library
-# Once done this will define
-#
-#  LIBHEDRA_FOUND - system has LIBHEDRA
-#  LIBHEDRA_INCLUDE_DIR - **the** LIBHEDRA include directory
-#  LIBHEDRA_INCLUDE_DIRS - LIBHEDRA include directories
-#  LIBHEDRAL_SOURCES - the LIBHEDRA source files
-if(NOT LIBHEDRA_FOUND)
-message("hello")
-
-FIND_PATH(LIBHEDRA_INCLUDE_DIR hedra/polygonal_read_OFF.h
-   ${PROJECT_SOURCE_DIR}/../../include
-   ${PROJECT_SOURCE_DIR}/../include
-   ${PROJECT_SOURCE_DIR}/include
-   /usr/include
-   /usr/local/include
-)
-
-if(LIBHEDRA_INCLUDE_DIR)
-   set(LIBHEDRA_FOUND TRUE)
-   set(LIBHEDRA_INCLUDE_DIRS ${LIBHEDRA_INCLUDE_DIR})
-endif()
-
-endif()

+ 0 - 35
tutorial/802_LevenbergMarquadt/cmake/FindLIBIGL.cmake

@@ -1,35 +0,0 @@
-# - Try to find the LIBIGL library
-# Once done this will define
-#
-#  LIBIGL_FOUND - system has LIBIGL
-#  LIBIGL_INCLUDE_DIR - **the** LIBIGL include directory
-#  LIBIGL_INCLUDE_DIRS - LIBIGL include directories
-#  LIBIGL_SOURCES - the LIBIGL source files
-if(NOT LIBIGL_FOUND)
-
-FIND_PATH(LIBIGL_INCLUDE_DIR igl/readOBJ.h
-   ${PROJECT_SOURCE_DIR}/../../include
-   ${PROJECT_SOURCE_DIR}/../include
-   ${PROJECT_SOURCE_DIR}/include
-   ${PROJECT_SOURCE_DIR}/../external/libigl/include
-   ${PROJECT_SOURCE_DIR}/../../external/libigl/include
-   $ENV{LIBIGL}/include
-   $ENV{LIBIGLROOT}/include
-   $ENV{LIBIGL_ROOT}/include
-   $ENV{LIBIGL_DIR}/include
-   $ENV{LIBIGL_DIR}/inc
-   /usr/include
-   /usr/local/include
-   /usr/local/igl/libigl/include
-)
-
-
-if(LIBIGL_INCLUDE_DIR)
-   set(LIBIGL_FOUND TRUE)
-   set(LIBIGL_INCLUDE_DIRS ${LIBIGL_INCLUDE_DIR}  ${LIBIGL_INCLUDE_DIR}/../external/Singular_Value_Decomposition)
-   #set(LIBIGL_SOURCES
-   #   ${LIBIGL_INCLUDE_DIR}/igl/viewer/Viewer.cpp
-   #)
-endif()
-
-endif()

+ 0 - 218
tutorial/802_LevenbergMarquadt/main.cpp

@@ -1,218 +0,0 @@
-#include <igl/unproject_onto_mesh.h>
-#include <igl/viewer/Viewer.h>
-#include <igl/readDMAT.h>
-#include <igl/jet.h>
-#include <hedra/polygonal_read_OFF.h>
-#include <hedra/triangulate_mesh.h>
-#include <hedra/polygonal_edge_topology.h>
-#include <hedra/point_spheres.h>
-#include <hedra/scalar2RGB.h>
-#include <hedra/LMSolver.h>
-#include <hedra/EigenSolverWrapper.h>
-#include <hedra/DiscreteShellsTraits.h>
-#include <Eigen/SparseCholesky>
-#include <hedra/check_traits.h>
-
-
-std::vector<int> Handles;
-std::vector<Eigen::RowVector3d> HandlePoses;
-int CurrentHandle;
-Eigen::MatrixXd VOrig, V;
-Eigen::MatrixXi F, T;
-Eigen::VectorXi D, TF;
-Eigen::MatrixXi EV, EF, FE, EFi;
-Eigen::MatrixXd FEs;
-Eigen::VectorXi innerEdges;
-Eigen::Vector3d spans;
-bool Editing=false;
-bool ChoosingHandleMode=false;
-double CurrWinZ;
-typedef hedra::optimization::EigenSolverWrapper<Eigen::SimplicialLLT<Eigen::SparseMatrix<double> > > LinearSolver;
-hedra::optimization::DiscreteShellsTraits dst;
-LinearSolver esw;
-hedra::optimization::LMSolver<LinearSolver, hedra::optimization::DiscreteShellsTraits> lmSolver;
-
-
-
-bool UpdateCurrentView(igl::viewer::Viewer & viewer)
-{
-    using namespace Eigen;
-    using namespace std;
-    
-    MatrixXd sphereV;
-    MatrixXi sphereT;
-    MatrixXd sphereTC;
-    Eigen::MatrixXd bc(Handles.size(),V.cols());
-    for (int i=0;i<Handles.size();i++)
-        bc.row(i)=HandlePoses[i].transpose();
-    
-    
-    double sphereRadius=spans.sum()/200.0;
-    MatrixXd sphereGreens(Handles.size(),3);
-    sphereGreens.col(0).setZero();
-    sphereGreens.col(1).setOnes();
-    sphereGreens.col(2).setZero();
-
-    hedra::point_spheres(bc, sphereRadius, sphereGreens, 10, false, sphereV, sphereT, sphereTC);
-    
-    Eigen::MatrixXd bigV(V.rows()+sphereV.rows(),3);
-    Eigen::MatrixXi bigT(T.rows()+sphereT.rows(),3);
-    if (sphereV.rows()!=0){
-        bigV<<V, sphereV;
-        bigT<<T, sphereT+Eigen::MatrixXi::Constant(sphereT.rows(), sphereT.cols(), V.rows());
-    } else{
-        bigV<<V;
-        bigT<<T;
-    }
-    
-    viewer.core.show_lines=false;
-    Eigen::MatrixXd OrigEdgeColors(EV.rows(),3);
-    OrigEdgeColors.col(0)=Eigen::VectorXd::Constant(EV.rows(),0.0);
-    OrigEdgeColors.col(1)=Eigen::VectorXd::Constant(EV.rows(),0.0);
-    OrigEdgeColors.col(2)=Eigen::VectorXd::Constant(EV.rows(),0.0);
-    
-    viewer.data.clear();
-    viewer.data.set_mesh(bigV,bigT);
-    viewer.data.compute_normals();
-    viewer.data.set_edges(V,EV,OrigEdgeColors);
-    return true;
-}
-
-bool mouse_move(igl::viewer::Viewer& viewer, int mouse_x, int mouse_y)
-{
-    if (!Editing)
-        return false;
-    
-    double x = viewer.current_mouse_x;
-    double y = viewer.core.viewport(3) - viewer.current_mouse_y;
-    Eigen::RowVector3f NewPos=igl::unproject<float>(Eigen::Vector3f(x,y,CurrWinZ),
-                                                    viewer.core.view * viewer.core.model,
-                                                    viewer.core.proj,
-                                                    viewer.core.viewport);
-    
-    HandlePoses[HandlePoses.size()-1]=NewPos.cast<double>();
-    Eigen::RowVector3d Diff=HandlePoses[HandlePoses.size()-1]-VOrig.row(Handles[HandlePoses.size()-1]);
-    
-    Eigen::MatrixXd bc(Handles.size(),V.cols());
-    for (int i=0;i<Handles.size();i++)
-        bc.row(i)=HandlePoses[i].transpose();
-    
-    dst.qh=bc;
-    lmSolver.solve(true);
-    V=dst.fullSolution;
-    UpdateCurrentView(viewer);
-    return true;
-
-}
-
-
-bool mouse_up(igl::viewer::Viewer& viewer, int button, int modifier)
-{
-    if (((igl::viewer::Viewer::MouseButton)button==igl::viewer::Viewer::MouseButton::Left))
-        return false;
-    
-    Editing=false;
- 
-    return true;
-}
-
-bool mouse_down(igl::viewer::Viewer& viewer, int button, int modifier)
-{
-    if (((igl::viewer::Viewer::MouseButton)button==igl::viewer::Viewer::MouseButton::Left))
-        return false;
-    int vid, fid;
-    Eigen::Vector3f bc;
-    double x = viewer.current_mouse_x;
-    double y = viewer.core.viewport(3) - viewer.current_mouse_y;
-    if (!ChoosingHandleMode){
-        Editing=true;
-        return false;
-    }
-    if(igl::unproject_onto_mesh(Eigen::Vector2f(x,y), viewer.core.view * viewer.core.model,
-                                viewer.core.proj, viewer.core.viewport, V, F, fid, bc))
-    {
-        //add the closest vertex to the handles
-        Eigen::MatrixXf::Index maxRow, maxCol;
-        bc.maxCoeff(&maxRow);
-        int CurrVertex=F(fid, maxRow);
-        bool Found=false;
-        for (int i=0;i<Handles.size();i++)
-            if (Handles[i]==CurrVertex){
-                CurrVertex=Handles[i];
-                Found=true;
-            }
-        
-        if (!Found){
-            Handles.push_back(CurrVertex);
-            HandlePoses.push_back(V.row(CurrVertex));
-        }
-    
-        Eigen::Vector3f WinCoords=igl::project<float>(V.row(CurrVertex).cast<float>(),
-                                               viewer.core.view * viewer.core.model,
-                                               viewer.core.proj,
-                                               viewer.core.viewport);
-
-        CurrWinZ=WinCoords(2);
-        std::cout<<"Choosing Vertex :"<<CurrVertex<<std::endl;
-
-        Eigen::VectorXi b(Handles.size());
-        for (int i=0;i<Handles.size();i++)
-            b(i)=Handles[i];
-        
-        dst.init(VOrig, T, b, EV, EF, EFi,innerEdges);
-        lmSolver.init(&esw, &dst, 250, 10e-6);
-        UpdateCurrentView(viewer);
-    }
-    return true;
-}
-
-bool key_up(igl::viewer::Viewer& viewer, unsigned char key, int modifiers)
-{
-    switch(key)
-    {
-            
-        case '1': ChoosingHandleMode=false;
-            break;
-    }
-    return false;
-}
-
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifiers)
-{
-    switch(key)
-    {
-        case '1': ChoosingHandleMode=true;
-            break;
-    }
-    return false;
-}
-
-
-int main(int argc, char *argv[])
-{
-    
-    // Load a mesh in OFF format
-    using namespace std;
-    using namespace Eigen;
-    
-    hedra::polygonal_read_OFF(DATA_PATH "/moomoo.off", V, D, F);
-    hedra::triangulate_mesh(D, F, T, TF);
-    VectorXi DT=VectorXi::Constant(T.rows(),3);
-    hedra::polygonal_edge_topology(DT, T, EV, FE, EF,EFi,FEs,innerEdges);
-    
-    spans=V.colwise().maxCoeff()-V.colwise().minCoeff();
-    
-    VOrig=V;
-    igl::viewer::Viewer viewer;
-    viewer.callback_mouse_down = &mouse_down;
-    viewer.callback_mouse_move = &mouse_move;
-    viewer.callback_mouse_up=&mouse_up;
-    viewer.callback_key_down=&key_down;
-    viewer.callback_key_up=&key_up;
-    viewer.core.background_color<<0.75,0.75,0.75,1.0;
-    UpdateCurrentView(viewer);
-    viewer.launch();
-    
-    cout<<"press 1+right button to select new handles"<<endl;
-    cout<<"press the right button and drag the edit the mesh"<<endl;
-}

+ 1 - 1
tutorial/CMakeLists.txt

@@ -16,7 +16,7 @@ option(LIBIGL_WITH_NANOGUI     "Use Nanogui menu"   OFF)
 option(LIBIGL_WITH_EMBREE      "Use Embree"         ON)
 option(LIBIGL_WITH_EMBREE      "Use Embree"         ON)
 
 
 ### libIGL options: choose your dependencies (by default everything is OFF, in this example we need the viewer)
 ### libIGL options: choose your dependencies (by default everything is OFF, in this example we need the viewer)
-option(LIBIGL_WITH_CGAL             "Use CGAL"           OFF)
+option(LIBIGL_WITH_CGAL             "Use CGAL"           "${CGAL_FOUND}")
 option(LIBIGL_WITH_CORK             "Use CORK"           OFF)
 option(LIBIGL_WITH_CORK             "Use CORK"           OFF)
 option(LIBIGL_WITH_MATLAB           "Use Matlab"         "${MATLAB_FOUND}")
 option(LIBIGL_WITH_MATLAB           "Use Matlab"         "${MATLAB_FOUND}")
 option(LIBIGL_WITH_MOSEK            "Use MOSEK"          "${MOSEK_FOUND}")
 option(LIBIGL_WITH_MOSEK            "Use MOSEK"          "${MOSEK_FOUND}")