コード例 #1
0
// Perform the standard normalization and also 
// make every border vertex point to its incident border halfedge.
void HDS_overlay::normalize_border_vertices() {
  Base::normalize_border();
  
  // Loop through all the border halfedges
  Halfedge_iterator it;
  for ( it=border_halfedges_begin(); it!=halfedges_end(); ++it) {
    RFC_assertion(!it->is_border());
    ++it; RFC_assertion(it->is_border());
    Vertex *v = it->vertex();
    if ( v->halfedge() != &*it)
      v->set_halfedge( &*it);
  }
}
コード例 #2
0
ファイル: PolyDataGenerator.cpp プロジェクト: uschille/hemelb
void PolyDataGenerator::ClosePolygon(void){
	Halfedge_iterator j;
	Halfedge_iterator k;
	Halfedge_iterator l;
	Halfedge_iterator m;
	Halfedge_handle newedge;
	
	cout << "The polyhedron has " << ClippedCGALSurface->size_of_facets() << " facets " 
		 << ClippedCGALSurface->size_of_halfedges() << " halfedges " << 
		ClippedCGALSurface->size_of_border_halfedges() << " border halfedges " 
		 << ClippedCGALSurface->size_of_vertices() << " vertices " << endl;
	int ncompremoved = ClippedCGALSurface->keep_largest_connected_components(1);
	cout << "Removing " << ncompremoved << " non connected components" << endl;
	cout << "The polyhedron has " << ClippedCGALSurface->size_of_facets() << " facets " 
		 << ClippedCGALSurface->size_of_halfedges() << " halfedges " << 
		ClippedCGALSurface->size_of_border_halfedges() << " border halfedges " 
		 << ClippedCGALSurface->size_of_vertices() << " vertices " << endl;

	while(!this->ClippedCGALSurface->is_closed()){
		for (j = ClippedCGALSurface->border_halfedges_begin(); j != ClippedCGALSurface->halfedges_end(); ++j){
			// We itterate over all border half edges. Half of them are opposite border edegs and thus not 
			// real borders so test this first. 
			// it.next() it the next border edge along the hole. This might not be the same as ++it
			k = j->next();
			l = k->next();
			m = l->next();
			if (j->is_border() && l->is_border() && k->is_border()){
				//First find size of hole and make sure that this is simple. i.e.
				//No two different halfedges points to the same vertex. 
				//If this is the case we delete one of them and start over.
				Halfedge_iterator tempit = k;
				Halfedge_iterator tempit2;
				int sizehole = 1;
				bool Simplehole = true;
				while(tempit != j){
					for(tempit2 = j; tempit2 != tempit ; tempit2=tempit2->next() ){
						if (tempit2->vertex() == tempit->vertex()){
							Simplehole = false;
							ClippedCGALSurface->erase_facet(tempit2->opposite());
							break; //remove one facet and start over.
						}
					}
					if(!Simplehole){
						break; //ugly Break inermost while loop.
					}
					tempit = tempit->next();
					++sizehole;
				}

				if (Simplehole){
					//cout << "Hole has " << sizehole << endl;
					if (j != m){ //more than 3 edges in hole. Have to subdivide
						newedge = ClippedCGALSurface->add_facet_to_border(j,l);
						//cout << "Filling " << j->vertex()->point() <<  " , " << k->vertex()->point() << " to " << newedge->vertex()->point() << endl;
					}
					else{
						//cout << "Closing " << j->vertex()->point() << " to " << k->vertex()->point() << endl;
						newedge = ClippedCGALSurface->fill_hole(j);
					}
					// now find the iolet type from neighbors.
					tempit = newedge;
					bool start = true;
					std::vector<size_t> neighborIds;
					while(tempit != newedge || start){
						start = false;
						if (!tempit->opposite()->is_border()){
							neighborIds.push_back(tempit->opposite()->facet()->id());
						}
						tempit = tempit->next();
					}
					std::vector<size_t>::iterator max = std::max_element(neighborIds.begin(), neighborIds.end());
					std::vector<size_t>::iterator min = std::min_element(neighborIds.begin(), neighborIds.end());
					if (*max != *min){ // if max is min they are all the same.
						throw GenerationErrorMessage("Could not determin IOlet id of inserted facet.");
					}
					else{
						newedge->facet()->id() = *max;
					}
					break; //we have to normalize the border and restart the forloop since 
					// filling with add_facet_to_border invalidated the order of border/non border edges. 
				}
				else {
					//cout << "Could not fill since hole is not simple, deleted connected facet instead" << endl;
					break;
				}
			}
		}
		ClippedCGALSurface->normalize_border();
	}
}