Files
igl/tutorial/609_Boolean/main.cpp
T
b0fd49d598 CMake refactor (#1805)
* Start CMake refactoring.

* WIP on instlal().

* Handle install + hunter setup.

* Handle module options + igl_include helper.

* Build all tutorials again.

* Update CMake for unit tests.

* Update triangle lib.

* Update Hunter integration.

* Fix for header-only mode.

* Fix Windows compilation + add GMP/MPFR find_package + set VS folders.

* Fix CGAL build.

* Add copy dll for Windows + improve find gmp/mpfr.

* Update Github Actions.

* Update README.

* Fixes for CMake 3.18

* Fix include option.

* Rename libigl_imgui_front to avoid conflicts.

* Fix when disabling unit tests.

* Build imguizmo with C++11.

* Update CMake option comments.

* Rename nonfree -> restricted.

* Update triangle and tetgen versions.

* Fix compilation issue.

* Update continuous.yml

* remove cork

* finding matlab with default

* mosek module compiles; default detected; osx dylib hack

* Reduce build parallelism.

* Fix find GMP/MPFR on Windows + cleanup CGAL changes.

* Update readme.

Co-authored-by: Alec Jacobson <alecjacobson@adobe.com>
Co-authored-by: Alec Jacobson <alecjacobson@gmail.com>
2022-02-09 18:58:40 -08:00

96 lines
2.4 KiB
C++
Executable File

#include <igl/readOFF.h>
//#undef IGL_STATIC_LIBRARY
#include <igl/copyleft/cgal/mesh_boolean.h>
#include <igl/opengl/glfw/Viewer.h>
#include <Eigen/Core>
#include <iostream>
Eigen::MatrixXd VA,VB,VC;
Eigen::VectorXi J,I;
Eigen::MatrixXi FA,FB,FC;
igl::MeshBooleanType boolean_type(
igl::MESH_BOOLEAN_TYPE_UNION);
const char * MESH_BOOLEAN_TYPE_NAMES[] =
{
"Union",
"Intersect",
"Minus",
"XOR",
"Resolve",
};
void update(igl::opengl::glfw::Viewer &viewer)
{
igl::copyleft::cgal::mesh_boolean(VA,FA,VB,FB,boolean_type,VC,FC,J);
Eigen::MatrixXd C(FC.rows(),3);
for(size_t f = 0;f<C.rows();f++)
{
if(J(f)<FA.rows())
{
C.row(f) = Eigen::RowVector3d(1,0,0);
}else
{
C.row(f) = Eigen::RowVector3d(0,1,0);
}
}
viewer.data().clear();
viewer.data().set_mesh(VC,FC);
viewer.data().set_colors(C);
std::cout<<"A "<<MESH_BOOLEAN_TYPE_NAMES[boolean_type]<<" B."<<std::endl;
}
bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)
{
switch(key)
{
default:
return false;
case '.':
boolean_type =
static_cast<igl::MeshBooleanType>(
(boolean_type+1)% igl::NUM_MESH_BOOLEAN_TYPES);
break;
case ',':
boolean_type =
static_cast<igl::MeshBooleanType>(
(boolean_type+igl::NUM_MESH_BOOLEAN_TYPES-1)%
igl::NUM_MESH_BOOLEAN_TYPES);
break;
case '[':
viewer.core().camera_dnear -= 0.1;
return true;
case ']':
viewer.core().camera_dnear += 0.1;
return true;
}
update(viewer);
return true;
}
int main(int argc, char *argv[])
{
using namespace Eigen;
using namespace std;
igl::readOFF(TUTORIAL_SHARED_PATH "/cheburashka.off",VA,FA);
igl::readOFF(TUTORIAL_SHARED_PATH "/decimated-knight.off",VB,FB);
// Plot the mesh with pseudocolors
igl::opengl::glfw::Viewer viewer;
// Initialize
update(viewer);
viewer.data().show_lines = true;
viewer.callback_key_down = &key_down;
viewer.core().camera_dnear = 3.9;
cout<<
"Press '.' to switch to next boolean operation type."<<endl<<
"Press ',' to switch to previous boolean operation type."<<endl<<
"Press ']' to push near cutting plane away from camera."<<endl<<
"Press '[' to pull near cutting plane closer to camera."<<endl<<
"Hint: investigate _inside_ the model to see orientation changes."<<endl;
viewer.launch();
}