/**************************************************************************** * 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_mesh.cpp \ingroup code_sample \brief An example of adaptively remeshing the intersection between a cube and a sphere */ #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(clock()); Point3f direction = vcg::math::GeneratePointOnUnitSphereUniform(rnd); tri::UpdatePosition::Translate(m1,direction); for(int i=0;i<6;++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*0.8f); params.SetFeatureAngleDeg(10); params.iter=1; // just one iteration to avoid overtessellating. 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; }