void Various_Processing_Component::UniformScaling (PolyhedronPtr pMesh, double scalingFactor) { Affine_transformation uniformScaling(CGAL::SCALING, scalingFactor); std::transform(pMesh->points_begin(), pMesh->points_end(), pMesh->points_begin(), uniformScaling); pMesh->compute_normals(); }
void MSDM2_Component::Matching_Multires_Init(PolyhedronPtr m_PolyDegrad, PolyhedronPtr m_PolyOriginal , Facet * _TabMatchedFacet) { // constructs AABB tree AABB_Tree tree(m_PolyOriginal->facets_begin(),m_PolyOriginal->facets_end()); tree.accelerate_distance_queries(); //Searching for the closest point and facet for each vertex int ind=0; for(Vertex_iterator pVertex = m_PolyDegrad->vertices_begin(); pVertex != m_PolyDegrad->vertices_end(); pVertex++) { pVertex->MSDM2_Local=0; // computes closest point and primitive id Point_and_primitive_id pp = tree.closest_point_and_primitive(pVertex->point()); Point3d Nearest=pp.first; Facet_iterator f_Nearest = pp.second; // closest primitive id pVertex->match=Nearest; _TabMatchedFacet[ind]=*f_Nearest; ind++; } }
void Various_Processing_Component::Rotation (PolyhedronPtr pMesh, double xAxis, double yAxis, double zAxis, double angle) { // normalize the translation vector double normAxis = sqrt(xAxis*xAxis + yAxis*yAxis + zAxis*zAxis); xAxis = xAxis / normAxis; yAxis = yAxis / normAxis; zAxis = zAxis / normAxis; // construction of the rotation matrix double c = cos(angle/180.0*PI); double s = sin(angle/180.0*PI); double m00 = xAxis*xAxis + (1.0-xAxis*xAxis)*c; double m01 = xAxis*yAxis*(1.0-c) - zAxis*s; double m02 = xAxis*zAxis*(1.0-c) + yAxis*s; double m10 = xAxis*yAxis*(1.0-c) + zAxis*s; double m11 = yAxis*yAxis + (1.0-yAxis*yAxis)*c; double m12 = yAxis*zAxis*(1.0-c) - xAxis*s; double m20 = xAxis*zAxis*(1.0-c) - yAxis*s; double m21 = yAxis*zAxis*(1.0-c) + xAxis*s; double m22 = zAxis*zAxis + (1.0-zAxis*zAxis)*c; // realize rotation by applying general affine transformation through matrix multiplication Affine_transformation rotation(m00, m01, m02, m10, m11, m12, m20, m21, m22); std::transform(pMesh->points_begin(), pMesh->points_end(), pMesh->points_begin(), rotation); pMesh->compute_normals(); }
int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "syntax: convexify <input> <output>" << std::endl; std::cerr << std::endl; std::cerr << "convexify takes the description of a 3D geometry from the input file (a Wavefront OBJ" << std::endl; std::cerr << "file) and constructs a new Wavefront 3D file of the convex hull of that file." << std::endl; return -1; } // read in the file IndexedTriArray mesh = IndexedTriArray::read_from_obj(std::string(argv[1])); // get the vertices const std::vector<Origin3d>& vertices = mesh.get_vertices(); // compute the convex hull PolyhedronPtr p = CompGeom::calc_convex_hull(vertices.begin(), vertices.end()); // write the resulting mesh to the output file if (!p) { std::cerr << "convexify() - fatal error computing convex hull! (sorry I can't tell you more!" << std::endl; return -1; } // write the file p->get_mesh().write_to_obj(std::string(argv[2])); }
void Various_Processing_Component::Translation (PolyhedronPtr pMesh, double xTranslation, double yTranslation, double zTranslation) { Vector translationVector(xTranslation,yTranslation, zTranslation); Affine_transformation translation(CGAL::TRANSLATION, translationVector); std::transform(pMesh->points_begin(), pMesh->points_end(), pMesh->points_begin(), translation); pMesh->compute_normals(); }
bool Various_Tools_Component::subdivide_loop(PolyhedronPtr pMesh) { Polyhedron_subdivision<Polyhedron>::Loop_subdivision(*pMesh,1); pMesh->compute_normals(); pMesh->compute_type(); return true; }
bool Various_Tools_Component::subdivide_catmull(PolyhedronPtr pMesh) { Polyhedron_subdivision<Polyhedron>::CatmullClark_subdivision(*pMesh,1); pMesh->compute_normals(); pMesh->compute_type(); return true; }
bool Various_Tools_Component::subdivide_sqrt3Twice(PolyhedronPtr pMesh) { CSubdivider_sqrt3<Polyhedron,Enriched_kernel> subdivider; subdivider.subdivide(*pMesh,2); // two iterations pMesh->compute_normals(); pMesh->compute_type(); return true; }
void MSDM2_Component::ConstructColorMap(PolyhedronPtr P, int MetricOrHausdorff) { if(MetricOrHausdorff==1) { if(P->IsDistanceComputed==true) { double R; int indiceLut; Vertex_iterator pVertex = NULL; if(MaxMSDM2>MinMSDM2) { for (pVertex = P->vertices_begin(); pVertex != P->vertices_end(); pVertex++) { R=(pVertex->MSDM2_Local-MinMSDM2)/(MaxMSDM2-MinMSDM2)*255; indiceLut=floor(R); pVertex->color(LUT_CourbureClust[3*indiceLut],LUT_CourbureClust[3*indiceLut+1],LUT_CourbureClust[3*indiceLut+2]); } } } } else { if(P->IsDistanceComputed==true) { double R; int indiceLut; Vertex_iterator pVertex = NULL; if(MaxMSDM2>MinMSDM2) { for (pVertex = P->vertices_begin(); pVertex != P->vertices_end(); pVertex++) { float d=sqrt((pVertex->point()-pVertex->match)*(pVertex->point()-pVertex->match)); R=(d-MinMSDM2)/(MaxMSDM2-MinMSDM2)*255; indiceLut=floor(R); pVertex->color(LUT_CourbureClust[3*indiceLut],LUT_CourbureClust[3*indiceLut+1],LUT_CourbureClust[3*indiceLut+2]); } } } } }
void MSDM2_Component::KmaxKmean(PolyhedronPtr polyhedron_ptr,double coef) { for(Vertex_iterator pVertex = polyhedron_ptr->vertices_begin();pVertex!= polyhedron_ptr->vertices_end();pVertex++) { double kmax=pVertex->KmaxCurv*coef; double kmin=fabs(pVertex->KminCurv*coef); pVertex->KmaxCurv=(kmax+kmin)/2.; } }
void VSA_Component::ConstructFaceColorMap(PolyhedronPtr pMesh) { //Vertex_iterator pVertex = NULL; // MT Facet_iterator pFacet = pMesh->facets_begin(); for(;pFacet != pMesh->facets_end();pFacet++) { double R=(double)(pFacet->LabelVSA)/(double)pMesh->NbFaceLabel*255.; int indiceLut=floor(R); pFacet->color(LUT_Seg[3*indiceLut],LUT_Seg[3*indiceLut+1],LUT_Seg[3*indiceLut+2]); } }
void Various_Processing_Component::NoiseAdditionUniform (PolyhedronPtr pMesh, double noiseIntensity, bool preserveBoundaries) { // mesh centre calculation based on discrete "moment". //TODO: maybe in the future it will be based on volume moment. int numVertex = pMesh->size_of_vertices();; Vector centroid = Point3d(0,0,0) - CGAL::ORIGIN; double distancetoCentroid = 0.0; Vertex_iterator pVertex; for (pVertex = pMesh->vertices_begin(); pVertex != pMesh->vertices_end(); pVertex++) { Vector vectemp = pVertex->point() - CGAL::ORIGIN; centroid = centroid + vectemp; } centroid = centroid/numVertex; // calculate the average distance from vertices to mesh centre for (pVertex = pMesh->vertices_begin(); pVertex!= pMesh->vertices_end(); pVertex++) { Vector vectemp = pVertex->point() - CGAL::ORIGIN; distancetoCentroid = distancetoCentroid + (double)std::sqrt((vectemp - centroid) * (vectemp - centroid)); } distancetoCentroid = distancetoCentroid/numVertex; // add random uniform-distributed (between [-noiseLevel, +noiseLevel]) srand((unsigned)time(NULL)); double noisex, noisey, noisez; double noiseLevel = distancetoCentroid * noiseIntensity; for (pVertex = pMesh->vertices_begin(); pVertex!= pMesh->vertices_end(); pVertex++) { // keep boundaries untouched if demanded by user bool is_border_vertex = false; bool stopFlag = false; Halfedge_around_vertex_circulator hav = (*pVertex).vertex_begin(); do { if (hav->is_border()==true) { is_border_vertex = true; stopFlag = true; } hav++; } while ((hav!=(*pVertex).vertex_begin())&&(stopFlag==false)); if ((preserveBoundaries==true)&&(is_border_vertex==true)) continue; noisex = noiseLevel * (1.0*rand()/RAND_MAX-0.5)*2; noisey = noiseLevel * (1.0*rand()/RAND_MAX-0.5)*2; noisez = noiseLevel * (1.0*rand()/RAND_MAX-0.5)*2; Vector temp = Point3d(noisex, noisey, noisez) - CGAL::ORIGIN; pVertex->point() = pVertex->point() + temp; } // for correct rendering, we need to update the mesh normals pMesh->compute_normals(); }
string Various_Tools_Component::printClickedVertices(PolyhedronPtr pMesh,double x,double y,int tolerance) { GLdouble *model;GLdouble *proj;GLint *view; view = new GLint[4]; proj = new GLdouble[16]; model = new GLdouble[16]; glGetIntegerv(GL_VIEWPORT,view); glGetDoublev(GL_MODELVIEW_MATRIX,model); glGetDoublev(GL_PROJECTION_MATRIX,proj); y = view[3] - y; GLdouble wx,wy,wz; char szInfoVertex[256]; string sInfoVertex = ""; int vertexID = 0; //VertexID + 4就是该顶点在.obj文件中的行数 for(Vertex_iterator pVertex = pMesh->vertices_begin();pVertex != pMesh->vertices_end();pVertex++) { gluProject(pVertex->point().x(),pVertex->point().y (),pVertex->point().z(),model,proj,view,&wx,&wy,&wz); if (wz > 0.0 && wz < 1.0) { if (x > floor(wx)-tolerance && x < floor(wx)+tolerance) { if (y > floor(wy) - tolerance && y < floor(wy)+tolerance) { sprintf(szInfoVertex, "Vertex: %u - (%lf, %lf, %lf)", vertexID, pVertex->point().x(), pVertex->point().y(), pVertex->point().z()); sInfoVertex.assign(szInfoVertex); } } } vertexID++; } delete [] view; delete [] model; delete [] proj; return sInfoVertex; }
void Various_Processing_Component::Subdivision (PolyhedronPtr pMesh, Subdivision_type subdivisionType, int depth) { if (subdivisionType==CATMULLCLARK) SubdivisionCatmullClark(pMesh, depth); else if (subdivisionType==LOOP) SubdivisionLoop(pMesh, depth); else if (subdivisionType==DOOSABIN) SubdivisionDooSabin(pMesh, depth); else if (subdivisionType==SQRT3) SubdivisionSqrt3(pMesh, depth); else if (subdivisionType==MIDPOINT) SubdivisionMidpoint(pMesh, depth); // after connectivity modification of the mesh, we need to update the related internal properties such as "m_pure_quad" or "m_pure_triangle" // other updates can be necessary depending on application pMesh->compute_type(); pMesh->compute_normals(); }
// Description : Initialize all flags -verticeces and facets- to FREE and give order to vertices // This function is called within every conquest. void Init(PolyhedronPtr pMesh) { int i = 0; // vertices flags initialization Vertex_iterator pVertex = NULL; for(pVertex = pMesh->vertices_begin(); pVertex != pMesh->vertices_end(); i++,pVertex++) { pVertex->Vertex_Flag_S = FREE; pVertex->Vertex_Number_S = i; pVertex->Vertex_Sign_S = NOSIGN; } // facets flag initialization. Facet_iterator pFace = NULL; for(pFace = pMesh->facets_begin(); pFace != pMesh->facets_end(); pFace++) { pFace->Facet_Flag_S = FREE; } }
void Various_Processing_Component::LaplacianSmoothing (PolyhedronPtr pMesh, double deformFactor, int iteraNum, bool preserveBoundaries) { Vertex_iterator pVertex; int numVertex = pMesh->size_of_vertices(); Vector * newPositions = new Vector[numVertex]; for (int i=0; i<iteraNum; i++) { int n = 0; for (pVertex = pMesh->vertices_begin(); pVertex != pMesh->vertices_end(); pVertex++) { Vector currentVector = pVertex->point() - CGAL::ORIGIN; // do not smooth the boundary vertices if demanded by user bool is_border_vertex = false; bool stopFlag = false; Halfedge_around_vertex_circulator hav = (*pVertex).vertex_begin(); do { if (hav->is_border()==true) { is_border_vertex = true; stopFlag = true; } hav++; } while ((hav!=(*pVertex).vertex_begin())&&(stopFlag==false)); if ((preserveBoundaries==true)&&(is_border_vertex==true)) { newPositions[n] = currentVector; n++; continue; } std::size_t degree = (*pVertex).vertex_degree(); double alpha = 1.0/degree; Vector vectemp = Point3d(0,0,0) - CGAL::ORIGIN; Halfedge_around_vertex_circulator h = (*pVertex).vertex_begin(); do { vectemp = vectemp+(h->opposite()->vertex()->point()-CGAL::ORIGIN-currentVector)*alpha; ++h; } while (h != (*pVertex).vertex_begin()); newPositions[n] = currentVector + deformFactor*vectemp; n++; } n = 0; for (pVertex = pMesh->vertices_begin(); pVertex != pMesh->vertices_end(); pVertex++) { pVertex->point() = Point3d(0,0,0) + newPositions[n]; n++; } } delete [] newPositions; newPositions = 0; pMesh->compute_normals(); }
void mepp_component_Boolean_Operations_plugin::New_Position() { QApplication::setOverrideCursor(Qt::WaitCursor); // active viewer if (mw->activeMdiChild() != 0) { float x, y, z; double a, b, c, w; Viewer* viewer = (Viewer *)mw->activeMdiChild(); ScenePtr S = viewer->getScenePtr(); for(int i = 0; i<viewer->getScenePtr()->get_nb_polyhedrons(); i++) { Vertex_iterator pVertex = NULL; PolyhedronPtr P = S->get_polyhedron(i); viewer->frame(i)->getPosition(x,y,z); viewer->frame(i)->getOrientation(a,b,c,w); Vec T(x, y, z); Quaternion Q(a, b, c, w); for (pVertex = P->vertices_begin(); pVertex != P->vertices_end(); pVertex++) { Vec V = Q * Vec(pVertex->point().x(), pVertex->point().y(), pVertex->point().z()) + T; pVertex->point() = CGAL::ORIGIN + Vector(V[0], V[1], V[2]); } viewer->frame(i)->setPosition(0,0,0); viewer->frame(i)->setOrientation(0,0,0,1); } viewer->show(); viewer->recreateListsAndUpdateGL(); } QApplication::restoreOverrideCursor(); }
void MSDM2_Component::ComputeMaxMin(PolyhedronPtr P, int MetricOrHausdorff) { if(MetricOrHausdorff==1) { if(P->IsDistanceComputed==true) { MinMSDM2=1000; MaxMSDM2=0; for(Vertex_iterator pVertex = P->vertices_begin();pVertex!= P->vertices_end();pVertex++) { if(pVertex->MSDM2_Local>MaxMSDM2) MaxMSDM2=pVertex->MSDM2_Local; if(pVertex->MSDM2_Local<MinMSDM2) MinMSDM2=pVertex->MSDM2_Local; } } } else { if(P->IsDistanceComputed==true) { MinMSDM2=1000; MaxMSDM2=0; for(Vertex_iterator pVertex = P->vertices_begin();pVertex!= P->vertices_end();pVertex++) { float d=sqrt((pVertex->point()-pVertex->match)*(pVertex->point()-pVertex->match)); if(d>MaxMSDM2) MaxMSDM2=d; if(d<MinMSDM2) MinMSDM2=d; } } } }
bool Various_Tools_Component::subdivide_quad(PolyhedronPtr pMesh) { CSubdivider_quad_triangle<Polyhedron,Enriched_kernel> subdivider; Polyhedron* new_mesh = new Polyhedron; subdivider.subdivide(*pMesh, *new_mesh, true); // copy bounding box (approximate, but fast) //new_mesh->copy_bounding_box(polyhedron); pMesh->copy_from(new_mesh); delete new_mesh; /*polyhedron->compute_normals(); polyhedron->compute_type();*/ // dej?fait lors de la copie return true; }
void Implicit_Surface_Meshing_Component::BuildPolyhedron(const C2t3& c2t3,PolyhedronPtr pMesh) { Polyhedron_C2t3_Importer <Polyhedron::HalfedgeDS> builder (c2t3); pMesh->delegate(builder);//build the polyhedron //compute these properties in order to display the polyhedron in Mepp pMesh->compute_bounding_box(); pMesh->compute_normals(); pMesh->compute_type(); (void)pMesh->calc_nb_components(); (void)pMesh->calc_nb_boundaries(); }
int mepp_component_plugin_interface::load_file_from_component(PolyhedronPtr polyhedron_ptr, QString filename, Viewer* viewer) { // here your code mepp_component_CGAL_Example_plugin *mepp_component_plugin = NULL; for (int i=0; i<viewer->lplugin.size(); ++i) { if (dynamic_cast<mepp_component_CGAL_Example_plugin*>(viewer->lplugin[i]) != 0) { mepp_component_plugin = dynamic_cast<mepp_component_CGAL_Example_plugin*>(viewer->lplugin[i]); //cout << "mepp_component_plugin found" << endl; } } int res; if (mepp_component_plugin) { CGAL_Example_ComponentPtr component_ptr = mepp_component_plugin->findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); res = polyhedron_ptr->load_mesh_off(filename.toStdString()); } else res=-1; return res; }
double MSDM2_Component::ProcessMSDM2_Multires(PolyhedronPtr m_PolyOriginal, PolyhedronPtr m_PolyDegrad,int NbLevel, double maxdim,double & FastMSDM, Curvature_ComponentPtr component_ptr_curvature) { double somme_MSDM2=0; int NbVertex=0; Facet * TabMatchedFacet=new Facet[m_PolyDegrad->size_of_vertices()]; Matching_Multires_Init(m_PolyDegrad, m_PolyOriginal,TabMatchedFacet); double RadiusCurvature=0.002; for (int i=0;i<NbLevel;i++) { m_PolyDegrad->set_index_vertices(); component_ptr_curvature->principal_curvature(m_PolyOriginal,true,RadiusCurvature*maxdim); component_ptr_curvature->principal_curvature(m_PolyDegrad,true,RadiusCurvature*maxdim); KmaxKmean(m_PolyOriginal,maxdim); KmaxKmean(m_PolyDegrad,maxdim); Matching_Multires_Update(m_PolyDegrad,TabMatchedFacet); for(Vertex_iterator pVertex = m_PolyDegrad->vertices_begin(); pVertex != m_PolyDegrad->vertices_end(); pVertex++) { std::vector<double> TabDistance1;std::vector<double> TabDistance2; TabPoint1.clear(); TabPoint2.clear(); ProcessMSDM2_per_vertex(pVertex,RadiusCurvature*5*maxdim,TabDistance1,TabDistance2,TabPoint1,TabPoint2); ComputeStatistics((&(*pVertex)), 0.5,TabDistance1,TabDistance2,TabPoint1,TabPoint2,RadiusCurvature*5*maxdim,maxdim); } RadiusCurvature+=0.001; } for(Vertex_iterator pVertex = m_PolyDegrad->vertices_begin(); pVertex != m_PolyDegrad->vertices_end(); pVertex++) { somme_MSDM2+=pow(pVertex->MSDM2_Local/NbLevel,3); NbVertex++; } FastMSDM=pow(somme_MSDM2/(double)NbVertex,0.33333); delete [] TabMatchedFacet; m_PolyDegrad->IsDistanceComputed=true; return 0; }
void Boolean_Operations_Component::SubdiviserPolyedre(PolyhedronPtr pMesh) { //Each facet must be triangular if(!pMesh->is_pure_triangle()) { pMesh->triangulate(); return; } Facet_iterator pFacet; Vector Vcenter; //Initialization of the tags for (pFacet = pMesh->facets_begin(); pFacet != pMesh->facets_end(); pFacet++) { Halfedge_around_facet_circulator pHEcirc = pFacet->facet_begin(); pFacet->Issub = false; pHEcirc->Isnew = false; pHEcirc->vertex()->Isnew = false; pHEcirc++; pHEcirc->Isnew = false; pHEcirc->vertex()->Isnew = false; pHEcirc++; pHEcirc->Isnew = false; pHEcirc->vertex()->Isnew = false; } //For each facet of the polyhedron for (pFacet = pMesh->facets_begin(); pFacet != pMesh->facets_end(); pFacet++) { //We subdivide the facet if it is not already done if(!(pFacet->Issub)) { Halfedge_handle pHE = pFacet->facet_begin(); for(unsigned int i = 0;i!=5;i++) { if(!pHE->Isnew) { //each edge is splited in its center Vcenter = Vector(0.0, 0.0, 0.0); Vcenter = ( (pHE->vertex()->point() - CGAL::ORIGIN) + (pHE->opposite()->vertex()->point() - CGAL::ORIGIN) ) / 2; pHE = pMesh->split_edge(pHE); pHE->vertex()->point() = CGAL::ORIGIN + Vcenter; //update of the tags (the new vertex and the four new halfedges pHE->vertex()->Isnew = true; pHE->Isnew = true; pHE->opposite()->Isnew = true; pHE->next()->Isnew = true; pHE->next()->opposite()->Isnew = true; } pHE = pHE->next(); } //Three new edges are build between the three new vertices, and the tags of the facets are updated if(!pHE->vertex()->Isnew) pHE = pHE->next(); pHE = pMesh->split_facet(pHE, pHE->next()->next()); pHE->opposite()->facet()->Issub = true; pHE = pMesh->split_facet(pHE, pHE->next()->next()); pHE->opposite()->facet()->Issub = true; pHE = pMesh->split_facet(pHE, pHE->next()->next()); pHE->opposite()->facet()->Issub = true; pHE->facet()->Issub = true; } } }
// this time, we add Gaussian-distributed additive noise to the mesh vertex coordinates // the standard deviation of the Gaussian distribution is "noiseLevel = distancetoCentroid * noiseIntensity" void Various_Processing_Component::NoiseAdditionGaussian (PolyhedronPtr pMesh, double noiseIntensity, bool preserveBoundaries) { int numVertex = pMesh->size_of_vertices();; Vector centroid = Point3d(0,0,0) - CGAL::ORIGIN; double distancetoCentroid = 0.0; Vertex_iterator pVertex; for (pVertex = pMesh->vertices_begin(); pVertex != pMesh->vertices_end(); pVertex++) { Vector vectemp = pVertex->point() - CGAL::ORIGIN; centroid = centroid + vectemp; } centroid = centroid/numVertex; for (pVertex = pMesh->vertices_begin(); pVertex!= pMesh->vertices_end(); pVertex++) { Vector vectemp = pVertex->point() - CGAL::ORIGIN; distancetoCentroid = distancetoCentroid + (double)std::sqrt((vectemp - centroid) * (vectemp - centroid)); } distancetoCentroid = distancetoCentroid/numVertex; srand((unsigned)time(NULL)); double noisex, noisey, noisez; double * gaussNumbers = new double[3]; double noiseLevel = distancetoCentroid * noiseIntensity; for (pVertex = pMesh->vertices_begin(); pVertex!= pMesh->vertices_end(); pVertex++) { bool is_border_vertex = false; bool stopFlag = false; Halfedge_around_vertex_circulator hav = (*pVertex).vertex_begin(); do { if (hav->is_border()==true) { is_border_vertex = true; stopFlag = true; } hav++; } while ((hav!=(*pVertex).vertex_begin())&&(stopFlag==false)); if ((preserveBoundaries==true)&&(is_border_vertex==true)) continue; // pseudo-random Gaussian-distributed numbers generation from uniformly-distributed pseudo-random numbers double x, y, r2; for (int i=0; i<3; i++) { do { x = -1.0 + 2.0 * 1.0*rand()/RAND_MAX; y = -1.0 + 2.0 * 1.0*rand()/RAND_MAX; r2 = x * x + y * y; } while ((r2>1.0)||(r2==0.0)); gaussNumbers[i] = y * sqrt(-2.0 * log(r2) / r2); } noisex = noiseLevel * gaussNumbers[0]; noisey = noiseLevel * gaussNumbers[1]; noisez = noiseLevel * gaussNumbers[2]; Vector temp = Point3d(noisex, noisey, noisez) - CGAL::ORIGIN; pVertex->point() = pVertex->point() + temp; } pMesh->compute_normals(); delete [] gaussNumbers; gaussNumbers = 0; }
double MSDM2_Component::getMaxDim(PolyhedronPtr polyhedron_ptr) { polyhedron_ptr->compute_bounding_box(); double max=polyhedron_ptr->xmax()-polyhedron_ptr->xmin(); if(polyhedron_ptr->ymax()-polyhedron_ptr->ymin()>max) max = polyhedron_ptr->ymax()-polyhedron_ptr->ymin(); if(polyhedron_ptr->zmax()-polyhedron_ptr->zmin()>max) max = polyhedron_ptr->zmax()-polyhedron_ptr->zmin(); return max; }
bool Various_Tools_Component::triangulate(PolyhedronPtr pMesh) { pMesh->triangulate(); return true; }
void MSDM2_Component::Matching_Multires_Update(PolyhedronPtr m_PolyDegrad, Facet * _TabMatchedFacet) { int ind=0; for(Vertex_iterator pVertex = m_PolyDegrad->vertices_begin(); pVertex != m_PolyDegrad->vertices_end(); pVertex++) { //Point3d Nearest=pVertex->match; // MT Facet* f_Nearest=&_TabMatchedFacet[ind]; pVertex->tag(ind); ind++; //for debug //pVertex->point()=Nearest; ///calculation of the nearest point curvature value using vertices of the Nearest triangle //we use linear interpolation using barycentric coordinates Point3d x1=f_Nearest->halfedge()->vertex()->point(); Point3d x2=f_Nearest->halfedge()->next()->vertex()->point(); Point3d x3=f_Nearest->halfedge()->next()->next()->vertex()->point(); double l1=sqrt((x3-x2)*(x3-x2)); double l2=sqrt((x1-x3)*(x1-x3)); double l3=sqrt((x1-x2)*(x1-x2)); Vector v1=f_Nearest->halfedge()->vertex()->point()-pVertex->point(); Vector v2=f_Nearest->halfedge()->next()->vertex()->point()-pVertex->point(); Vector v3=f_Nearest->halfedge()->next()->next()->vertex()->point()-pVertex->point(); double t1=sqrt(v1*v1); double t2=sqrt(v2*v2); double t3=sqrt(v3*v3); double p1=(l1+t2+t3)/2; double p2=(t1+l2+t3)/2; double p3=(t1+t2+l3)/2; double A1=(p1*(p1-l1)*(p1-t3)*(p1-t2)); double A2=(p2*(p2-l2)*(p2-t3)*(p2-t1)); double A3=(p3*(p3-l3)*(p3-t1)*(p3-t2)); if(A1>0) A1=sqrt(A1); else A1=0; if(A2>0) A2=sqrt(A2); else A2=0; if(A3>0) A3=sqrt(A3); else A3=0; double c1=f_Nearest->halfedge()->vertex()->KmaxCurv; double c2=f_Nearest->halfedge()->next()->vertex()->KmaxCurv; double c3=f_Nearest->halfedge()->next()->next()->vertex()->KmaxCurv; if((A1+A2+A3)>0) pVertex->curvmatch=(A1*c1+A2*c2+A3*c3)/(A1+A2+A3); else pVertex->curvmatch=(c1+c2+c3)/3; } }
// TODO: fixing after quantization the potentially introduced degeneracies, such as removing the null surface facet void Various_Processing_Component::CoordinateQuantization (PolyhedronPtr pMesh, int bitDepth) { Vertex_iterator pVertex; double quantizationLevel = std::pow(2.0,bitDepth); pVertex = pMesh->vertices_begin(); Point3d point = pVertex->point(); double xmax = double(point.x()); double xmin = xmax; double ymax = double(point.y()); double ymin = ymax; double zmax = double(point.z()); double zmin = zmax; pVertex++; for (; pVertex != pMesh->vertices_end(); pVertex++) { point = pVertex->point(); double x = double(point.x()); double y = double(point.y()); double z = double(point.z()); if (x>xmax) xmax = x; if (x<xmin) xmin = x; if (y>ymax) ymax = y; if (y<ymin) ymin = y; if (z>zmax) zmax = z; if (z<zmin) zmin = z; } double xstep = (xmax-xmin)/quantizationLevel; double ystep = (ymax-ymin)/quantizationLevel; double zstep = (zmax-zmin)/quantizationLevel; for (pVertex = pMesh->vertices_begin(); pVertex != pMesh->vertices_end();pVertex++) { point = pVertex->point(); double x = double(point.x()); double y = double(point.y()); double z = double(point.z()); double xquantified, yquantified, zquantified; double xint = 1.0*std::floor((x-xmin)/xstep)*xstep + xmin; double xfrac = x - xint; if (xfrac<=(0.5*xstep)) xquantified = xint; else xquantified = xint + xstep; double yint = 1.0*std::floor((y-ymin)/ystep)*ystep + ymin; double yfrac = y - yint; if (yfrac<=(0.5*ystep)) yquantified = yint; else yquantified = yint +ystep; double zint = 1.0*std::floor((z-zmin)/zstep)*zstep + zmin; double zfrac = z - zint; if (zfrac<=(0.5*zstep)) zquantified = zint; else zquantified = zint + zstep; pVertex->point() = Point3d(xquantified,yquantified,zquantified); } pMesh->compute_normals(); }