UG_API bool OrientationMatches(FaceVertices* fv, Volume* v) { // find the matching face desc and compare FaceDescriptor fd; for(size_t iface = 0; iface < v->num_faces(); ++iface){ v->face_desc(iface, fd); if(CompareVertices(fv, &fd)){ // check if their orientation matches // find the first vertex of fv in f size_t i; for(i = 0; i < fd.num_vertices(); ++i) { if(fd.vertex(i) == fv->vertex(0)) break; } if(i < fd.num_vertices()) { // the first one has been found. // check whether the second vertex of ed is the // same as the next vertex of f if(fv->vertex(1) == fd.vertex((i+1) % fd.num_vertices())) return true;// the orientation is the same } // the orientation is not the same. return false; } } // the orientation is not the same. return false; }
void OutlineTriangulator_Impl::create_ordered_vertex_list(std::vector<OutlineTriangulator_Vertex *> &vertices) { std::vector<OutlineTriangulator_Polygon>::size_type index_polygons, num_polygons; num_polygons = polygons.size(); for (index_polygons = 0; index_polygons < num_polygons; index_polygons++) { OutlineTriangulator_Polygon &cur_poly = polygons[index_polygons]; std::vector<OutlineTriangulator_Contour>::size_type index_contours, num_contours; num_contours = cur_poly.contours.size(); for (index_contours = 0; index_contours < num_contours; index_contours++) { OutlineTriangulator_Contour &cur_contour = cur_poly.contours[index_contours]; std::vector<OutlineTriangulator_Vertex>::size_type index_vertices, num_vertices; num_vertices = cur_contour.vertices.size(); for (index_vertices = 0; index_vertices < num_vertices; index_vertices++) { vertices.push_back(&cur_contour.vertices[index_vertices]); } } } // Sort list: std::sort(vertices.begin(), vertices.end(), CompareVertices()); // Remove duplicates: auto it = vertices.begin(); if (it == vertices.end()) return; float last_x = (*it)->x; float last_y = (*it)->y; ++it; while (it != vertices.end()) { if (last_x == (*it)->x && last_y == (*it)->y) { it = vertices.erase(it); } else { last_x = (*it)->x; last_y = (*it)->y; ++it; } } }
static int qsort_CompareVertices_minus( const void *pvVertex0, const void *pvVertex1) { BSPVertex<Type, iDimensions> &vx0 = *(BSPVertex<Type, iDimensions> *)pvVertex0; BSPVertex<Type, iDimensions> &vx1 = *(BSPVertex<Type, iDimensions> *)pvVertex1; return -CompareVertices(vx0, vx1, qsort_iCompareAxis); }
void GetVerticesIntoModel(Model3D& Model) { // Search for redundant vertices -- if there are any vertices to look for if (FullVertexList.empty()) return; // First, index-sort them // Set up for index sorting by finding the position range // (this code is a bit smarter than BG's 3DMF Mapper code for doing that); // this is unnecessary for the other vertex data GLfloat PosMin[3], PosMax[3]; for (int c=0; c<3; c++) PosMin[c] = PosMax[c] = FullVertexList[0].Data[FullVertexData::POS_BASE+c]; int OldNumVertices = FullVertexList.size(); for (int k=0; k<OldNumVertices; k++) { GLfloat *Pos = FullVertexList[0].Data + FullVertexData::POS_BASE; for (int c=0; c<3; c++) { GLfloat PC = Pos[c]; PosMin[c] = MIN(PosMin[c],PC); PosMax[c] = MAX(PosMax[c],PC); } } const GLfloat ThresholdConstant = 0.001; for (int c=0; c<3; c++) Thresholds[FullVertexData::POS_BASE+c] = ThresholdConstant*(PosMax[c]-PosMin[c]); for (int c=0; c<2; c++) Thresholds[FullVertexData::TC_BASE+c] = ThresholdConstant; for (int c=0; c<3; c++) Thresholds[FullVertexData::NORM_BASE+c] = ThresholdConstant; for (int c=0; c<3; c++) Thresholds[FullVertexData::COLOR_BASE+c] = ThresholdConstant; // Now the actual sorting vector<int> Indices(OldNumVertices); for (int k=0; k<Indices.size(); k++) Indices[k] = k; // STL sort may be slow qsort(&Indices[0],OldNumVertices,sizeof(int),CompareVertices); // Set up vertex ranks in place; count the distinct vertices. // Also, use the first one of a non-distinct set in sorted order // as the new vertex Model.VertIndices.resize(OldNumVertices); vector<int> VertexSelect; VertexSelect.resize(OldNumVertices); int TopRank = 0; int PrevIndex = Indices[0]; VertexSelect[TopRank] = PrevIndex; Model.VertIndices[PrevIndex] = TopRank; for (int k=1; k<OldNumVertices; k++) { int CurrIndex = Indices[k]; if (CompareVertices(&PrevIndex,&CurrIndex) != 0) { TopRank++; VertexSelect[TopRank] = CurrIndex; } Model.VertIndices[CurrIndex] = TopRank; PrevIndex = CurrIndex; } int NewNumVertices = TopRank + 1; // Fill up the rest of model arrays Model.Positions.resize(3*NewNumVertices); GLfloat *PosPtr = &Model.Positions[0]; GLfloat *TCPtr = NULL; if (TxtrCoordsPresent) { Model.TxtrCoords.resize(2*NewNumVertices); TCPtr = &Model.TxtrCoords[0]; } GLfloat *NormPtr = NULL; if (NormalsPresent) { Model.Normals.resize(3*NewNumVertices); NormPtr = &Model.Normals[0]; } GLfloat *ColorPtr = NULL; if (ColorsPresent) { Model.Colors.resize(3*NewNumVertices); ColorPtr = &Model.Colors[0]; } for (int k=0; k<NewNumVertices; k++) { FullVertexData& FullVertex = FullVertexList[VertexSelect[k]]; GLfloat *Pos = FullVertex.Data + FullVertexData::POS_BASE; for (int c=0; c<3; c++) *(PosPtr++) = *(Pos++); if (TxtrCoordsPresent) { GLfloat *TC = FullVertex.Data + FullVertexData::TC_BASE; for (int c=0; c<2; c++) *(TCPtr++) = *(TC++); } if (NormalsPresent) { GLfloat *Norm = FullVertex.Data + FullVertexData::NORM_BASE; for (int c=0; c<3; c++) *(NormPtr++) = *(Norm++); } if (ColorsPresent) { GLfloat *Color = FullVertex.Data + FullVertexData::COLOR_BASE; for (int c=0; c<3; c++) *(ColorPtr++) = *(Color++); } } // All done! FullVertexList.clear(); }