コード例 #1
0
  void edge_node(Halfedge_iterator eitr, Point& pt) {
    Point& p1 = eitr->vertex()->point();
    Point& p2 = eitr->opposite()->vertex()->point();
    Point& f1 = eitr->next()->vertex()->point();
    Point& f2 = eitr->opposite()->next()->vertex()->point();

    pt = Point((3*(p1[0]+p2[0])+f1[0]+f2[0])/8,
	       (3*(p1[1]+p2[1])+f1[1]+f2[1])/8,
	       (3*(p1[2]+p2[2])+f1[2]+f2[2])/8 );
  }
コード例 #2
0
Halfedge_handle DegradeAnObject::getHalfedgeBetweenTwoPoints(Point_3 p1, Point_3 p2, int index) {
	bool found = false;
	Halfedge_iterator hi = polys[index].halfedges_begin();
	while(!found) {
		if(p1 == hi->vertex()->point() && p2 == hi->opposite()->vertex()->point()) {
			found = true;
		}
		else {
			hi++;
		}
	}
	return hi;
}
コード例 #3
0
  void border_node(Halfedge_iterator eitr, Point& ept, Point& vpt) {
    Point& ep1 = eitr->vertex()->point();
    Point& ep2 = eitr->opposite()->vertex()->point();
    ept = Point((ep1[0]+ep2[0])/2, (ep1[1]+ep2[1])/2, (ep1[2]+ep2[2])/2);

    Halfedge_around_vertex_circulator vcir = eitr->vertex_begin();
    Point& vp1  = vcir->opposite()->vertex()->point();
    Point& vp0  = vcir->vertex()->point();
    Point& vp_1 = (--vcir)->opposite()->vertex()->point();
    vpt = Point((vp_1[0] + 6*vp0[0] + vp1[0])/8,
                (vp_1[1] + 6*vp0[1] + vp1[1])/8,
                (vp_1[2] + 6*vp0[2] + vp1[2])/8 );
  }
コード例 #4
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);
  }
}
コード例 #5
0
ファイル: dual.cpp プロジェクト: tohyongcheng/Paper3D
//------------------------------------------------------------------------------
//	Compute and store the results of dual graphs into appropriate variables
//
//  computeDual( mesh, whole, bary, mid ); 
//------------------------------------------------------------------------------
void computeDual( Polyhedron & poly, Graph & dual,
		  vector< Point3 > & bary, vector< Point3 > & mid )
{
    // initialize the array of face barycenters: refer to the point at which the gravitational forces exerted by 2 objects are equal

    bary.clear();
    bary.resize( poly.size_of_facets() );

    // initialize the dual graph with dual vertices
    dual.clear();
    int fid = 0;
    for ( Facet_iterator fi = poly.facets_begin(); fi != poly.facets_end(); ++fi ) {
	// add a vertex: each face equals to each dual vertex
	add_vertex( dual );
	bary[ fid++ ] = fi->center(); 
	// cerr << " Barycenter No. " << fid-1 << " : " << bary[ fid-1 ] << endl;
    }

    int size_of_edges = poly.size_of_halfedges() / 2; //redundant

    // initialize the array of midpoints
    mid.clear();
    mid.resize( size_of_edges );

    // initialize the array of lengths
    // length.clear();
    // length.resize( size_of_edges );

    // construct the connecitivity of the dual graph
    for ( Halfedge_iterator hi = poly.halfedges_begin(); hi != poly.halfedges_end(); ++hi ) {
	int origID = hi->facet()->id(); // the face
	int destID = hi->opposite()->facet()->id(); // the neighbor face
	Point3 origCoord = hi->vertex()->point();
	Point3 destCoord = hi->opposite()->vertex()->point();
	Vector3 dispVec = origCoord - destCoord;
	Point3 midCoord = destCoord + 0.5 * dispVec;
	// double curLength = sqrt( dispVec.squared_length() ); // the length between two connected vertices
#ifdef DEBUG
	cerr << origID << " -- " << destID << endl;
#endif	// DEBUG	
	
	if ( origID < destID )
		add_edge( origID, destID, hi->id(), dual );  
		
	mid[ hi->id() ] = midCoord;
	hi->mid() = hi->opposite()->mid() = midCoord;
	hi->weight() = hi->opposite()->weight() = 1.0;
    }
}
コード例 #6
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();
	}
}