diff --git a/apps/sample/trimesh_intersection_mesh/trimesh_intersection_mesh.cpp b/apps/sample/trimesh_intersection_mesh/trimesh_intersection_mesh.cpp new file mode 100644 index 00000000..3c4855c5 --- /dev/null +++ b/apps/sample/trimesh_intersection_mesh/trimesh_intersection_mesh.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2016 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/*! \file trimesh_intersection_plane.cpp +\ingroup code_sample + +\brief An example of computing the intersection of a mesh with a plane, +saving this polyline as a well projected 2D SVG +and splicing the mesh in the two components below and over the plane + +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; +using namespace vcg; + +class MyFace; +class MyVertex; + +struct MyUsedTypes : public UsedTypes< + Use::AsVertexType, + Use ::AsFaceType>{}; + + +class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::VFAdj, vertex::BitFlags, vertex::Normal3f, vertex::Qualityf, vertex::Mark>{}; +class MyFace : public Face < MyUsedTypes, face::VertexRef, face::VFAdj, face::FFAdj, face::Color4b, face::BitFlags, face::Mark, face::Normal3f> {}; + +class MyMesh: public tri::TriMesh< vector, vector >{}; + +int main(int ,char **) +{ + MyMesh m1, m2; + Sphere(m1); + Hexahedron(m2); + printf("Created a sphere mesh of %i vertices %i edges\n",m1.VN(),m1.FN()); + printf("Created a cube mesh of %i vertices %i edges\n",m2.VN(),m2.FN()); + + math::MarsenneTwisterRNG rnd; + Point3f direction = vcg::math::GeneratePointOnUnitSphereUniform(rnd); + tri::UpdatePosition::Translate(m1,direction); + for(int i=0;i<10;++i) + { + tri::Clean::SelectIntersectingFaces(m1,m2); + tri::UpdateSelection::FaceDilate(m1); + tri::Clean::SelectIntersectingFaces(m2,m1); + tri::UpdateSelection::FaceDilate(m2); + IsotropicRemeshing::Params params; + + float len = (tri::Stat::ComputeFaceEdgeLengthAverage(m1,true) + tri::Stat::ComputeFaceEdgeLengthAverage(m1,true)); + params.SetTargetLen(len); + params.SetFeatureAngleDeg(10); + params.iter=3; + params.selectedOnly=true; + printf(" Input mesh %8i v %8i f\n",m1.VN(),m1.FN()); + IsotropicRemeshing::Do(m1, params); + IsotropicRemeshing::Do(m2, params); + printf(" Input mesh %8i v %8i f\n",m1.VN(),m1.FN()); + } + tri::Clean::SelectIntersectingFaces(m1,m2); + tri::Clean::SelectIntersectingFaces(m2,m1); + int selCnt= tri::UpdateColor::PerFaceConstant(m1,Color4b::Red,true); + printf("Intersected %i faces on sphere\n",selCnt); + selCnt= tri::UpdateColor::PerFaceConstant(m2,Color4b::Red,true); + printf("Intersected %i faces on cube\n",selCnt); + + tri::io::ExporterOFF::Save(m1,"sphere.off",tri::io::Mask::IOM_FACECOLOR); + tri::io::ExporterOFF::Save(m2,"cube.off",tri::io::Mask::IOM_FACECOLOR); + + return 0; +} + diff --git a/apps/sample/trimesh_intersection_mesh/trimesh_intersection_mesh.pro b/apps/sample/trimesh_intersection_mesh/trimesh_intersection_mesh.pro new file mode 100644 index 00000000..9d676c3c --- /dev/null +++ b/apps/sample/trimesh_intersection_mesh/trimesh_intersection_mesh.pro @@ -0,0 +1,3 @@ +include(../common.pri) +TARGET = trimesh_intersection_mesh +SOURCES += trimesh_intersection_mesh.cpp