Esempio n. 1
0
void TMesh::PrintMeshTopo()
{
    cout<<"vertex top"<<endl;
    for(unsigned int i = 0; i < v_count(); i ++) {
        cout<<"vertex "<<i<<": "<<vertex(i).coord()<<endl;
        cout<<"\t incident vertex: ";
        for(unsigned int vit = 0; vit < vertex(i).n_verts(); vit ++)
            cout<<"\t"<<vertex(i).vert(vit)<<" ";
        cout<<endl;
        cout<<"\t incident triangle: ";
        for(unsigned int fit = 0; fit < vertex(i).n_facets(); fit ++)
            cout<<"\t"<<vertex(i).facet(fit)<<" ";
        cout<<endl;

    }
    cout<<endl;

    cout<<"triangle top"<<endl;
    for(unsigned int i = 0; i < f_count(); i ++) {
        cout<<"triangle "<<i<<endl;

        cout<<"\t vert: ";
        for(int j = 0; j < 3; j ++)
            cout<<"\t"<<facet(i).vert(j)<<" ";
        cout<<endl;

        cout<<"\t adj_facet: ";
        for(int j = 0; j < 3; j ++)
            cout<<"\t"<<facet(i).facet(j)<<" ";
        cout<<endl;
    }
    cout<<endl;
}
Esempio n. 2
0
bool TMesh::CheckMeshTopo()
{
    //check facet topo
    bool good = true;
    for(unsigned int i = 0; i < f_count(); i ++) {
        for(int j = 0; j < 3; j ++) {
            int fid = facet(i).facet(j);
            if(fid < 0) continue;
            int findex = facet(fid).findex(facet(i).vert((j + 1) % 3), facet(i).vert((j + 2) % 3));
            if(findex < 0) {
                cerr<<"mesh topo check error!"<<endl;
                cerr<<"fid: "<<i<<" eid: "<<" fid_adj: "<<fid<<endl;

                good = false;
            }
            //assert(findex >= 0);
        }
    }

    //check vertex topo
    for(unsigned int i = 0; i < v_count(); i ++) {
        for(unsigned int j = 0; j < vertex(i).n_facets(); j ++) {
            unsigned int fid = vertex(i).facet(j);
            int vindex = facet(fid).index(i);

            if(vindex < 0) {
                cerr<<"mesh topo check error!"<<endl;
                cerr<< "vid: "<<i<<" fid: "<<fid<<endl;

                good = false;
            }

            //assert(vindex >= 0);
        }

        for(unsigned int j = 0; j < vertex(i).n_verts(); j ++) {
            unsigned int vid = vertex(i).vert(j);
            int vindex = vertex(vid).index(i);
            if(vindex < 0) {
                cerr<<"mesh topo check error!"<<endl;
                cerr<<"vid: "<<i<<" vid: "<<vid<<endl;

                good = false;
            }
            //assert(vindex >= 0);
        }
    }

    if(!good) {
        cerr<<"Warning: the input mesh is not a manifold, which MAY crash the successive computation."<<endl;
    }
    return true;
}
Esempio n. 3
0
//================================================================
//begin: off file outpur function
//================================================================
void TMesh::OutMeshOffFile(char *filename)
{
    FILE *fp;
    if( (fp = fopen(filename, "w")) == NULL ) {
        std::cout<<"Failed to open file!"<<std::endl;
        return;
    }
    fprintf(fp, "LIST\n");
    fprintf(fp, "appearance {linewidth 7}\n");
    fprintf(fp, "{\n");
    fprintf(fp, "OFF\n");

    fprintf(fp, "%d %d 0\n", v_count(), f_count());
    for(unsigned int i = 0; i < v_count(); i ++) {
        fprintf(fp, "%f %f %f\n", (vertex(i).coord())(0), (vertex(i).coord())(1), (vertex(i).coord())(2));
    }
    for(unsigned int i = 0; i < f_count(); i ++) {

        if(  vertex(facet(i).vert(0)).check_flag(VTMESH_FLAG_SELECTED)
                && vertex(facet(i).vert(1)).check_flag(VTMESH_FLAG_SELECTED)
                && vertex(facet(i).vert(2)).check_flag(VTMESH_FLAG_SELECTED))
            fprintf(fp, "3 %d %d %d 0.2 0.2 0.2 1\n", facet(i).vert(0), facet(i).vert(1), facet(i).vert(2));
        else
            fprintf(fp, "3 %d %d %d 1 1 1 1\n", facet(i).vert(0), facet(i).vert(1), facet(i).vert(2));
    }
    fprintf(fp, "}\n");

    fclose(fp);
}
Esempio n. 4
0
void osgToy::FacetingVisitor::apply(osg::Geode& geode)
{
    for(unsigned int i = 0; i < geode.getNumDrawables(); i++ )
    {
        osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
        if (geom) facet(*geom);
    }
}
Esempio n. 5
0
std::string CLogger::now()
{
    std::stringstream dateStream;
    boost::posix_time::time_facet* facet(new boost::posix_time::time_facet());
    facet->format("%Y/%m/%d %H:%M:%S");
    dateStream.imbue(std::locale(std::locale::classic(), facet));
    dateStream << currentTime::Provider().now();
    return dateStream.str();
}
Esempio n. 6
0
/*
--------------------------------------------------------------------------------
------ FacetComplex class functions -----------------------------------------------
--------------------------------------------------------------------------------
*/
  FacetComplex::FacetComplex(const PolyRing& /*P*/, const PolyList& PL)
   {
     //      facet f_tmp;
//      vector<long> v(NumIndets(P));
      for (PolyList::const_iterator it=PL.begin(); it!=PL.end();++it)
      {
        //        exponents(v,LPP(*it));
        //	f_tmp=facet(v);
        //	myInsert(f_tmp);
        myInsert(facet(LPP(*it)));
      }
    }//FacetComplex
sptr<Facet> DCEL3D::addFacet(sPoint i_P1, sPoint i_P2, sPoint i_P3)
{
    // Create facet
    sptr<Facet> facet(new Facet(i_P1, i_P2, i_P3, m_PtInside));

    // Add it to the list
    m_Facets.push_back(facet);

    // Link edges to facet
    facet->m_AnEdge->m_Facet = facet;
    facet->m_AnEdge->m_Next->m_Facet = facet;
    facet->m_AnEdge->m_Next->m_Next->m_Facet = facet;

    return facet;
} 
Esempio n. 8
0
////////////////////////////////////////////////////////////////////////////////////////
//Meshsize
//--------
//Estimate mesh size
//
void TMesh::MeshSize(double& maxs, double& mins, double& aves)
{
    maxs = -FLT_MAX;
    mins = FLT_MAX;
    aves = 0;
    for(unsigned int i = 0; i < f_count(); i ++) {
        for(unsigned int j = 0; j < 3; j ++) {
            int vid0 = facet(i).vert(j);
            int vid1 = facet(i).vert((j + 1) % 3);
            double length = dot(vertex(vid0).coord() - vertex(vid1).coord(), vertex(vid0).coord() - vertex(vid1).coord());
            length = sqrt(fabs(length));
            aves += length;
            if(maxs < length) {
                maxs = length;
            }
            if(mins > length) {
                mins = length;
            }
        }
    }
    aves /= 3 * f_count();

    cout<<"maxs: "<<maxs<<" mins: "<<mins<<" aves: "<<aves<<endl;
}
Esempio n. 9
0
        void to_stream(T const& value)
        {
            std::locale loc = m_Stream.getloc();
            if (!std::has_facet< FacetT >(loc))
            {
                // Add the formatting facet
                std::auto_ptr< FacetT > facet(new FacetT(m_Format.c_str()));
                m_Stream.imbue(std::locale(loc, facet.get()));
                facet.release();
                loc = m_Stream.getloc();
            }

            // Perform formatting
            std::ostreambuf_iterator< char_type > osb_it(m_Stream);
            std::use_facet< FacetT >(loc).put(osb_it, m_Stream, m_Stream.fill(), value);
        }
Esempio n. 10
0
void CalculateNeighbourCells(        Complex2D&  G, 
			       const CellSet  &  cell_set,
			             FacetMap &  facet_map)
{

  typedef typename CellSet::CellIterator  SetCellIt;

  typedef typename FacetMap::iterator     MapIt;
  typedef grid_types<Complex2D>           gt;
  typedef typename gt::Cell               Cell;
  typedef typename gt::FacetOnCellIterator FacetOnCellIt;
  //  typedef typename gt::CellOnCellIterator CellNeighbourIt;
  
  friend_for_input gg(G); // gg == G + access to private routines
  
  typedef vtuple_2d<Complex2D> vtuple;
  SetCellIt c = cell_set.FirstCell();
  for(c= cell_set.FirstCell(); !c.IsDone(); ++c){
    Cell C(*c);
    FacetOnCellIt f(C.FirstFacet());
    for(; !f.IsDone();++f) {
      vtuple  facet(get_vertices(f));
      MapIt nb;
      if((nb = facet_map.find(facet)) != facet_map.end()){ 
        // facet found: nb has already been visited
        // do appropriate entries in the neighbourlists
        //  & remove facet from the map.
        FacetOnCellIt NbIt((*nb).second);
        gg.set_neighbour(f,    NbIt.TheCell());
        gg.set_neighbour(NbIt, f.   TheCell());
        //(int&)(*f._nb)      = G.handle(NbIt.TheCell()); // replace with call to
        //(int&)(*(NbIt._nb)) = G.handle(f.TheCell());    // internal fct of Complex2D
        facet_map.erase(nb);
      }
      else // 1st time this facet is encountered: add it to map
        facet_map[facet] = f ;
    } // for(f=C.FirstNeighbour();...
  } // for(c=FirstCell();...

  // all remaining map entries are on the boundary of cell_set
  // because they have been encountered exactly once.

}
Esempio n. 11
0
//--------------------------------------------------
//MarkNonManifoldness:
//----------------
//Check the non_manifoldness for each vertex and mark
//the vertex and all the incident facets if it is a
//non_manifold vertex.
//--------------------------------------------------
void TMesh::MarkNonManifoldness()
{
    unsigned int vid, fid, count;
    int ind, fid_circ, ind_circ, fid_pre;
    for(vid = 0; vid < v_count(); vid ++) {
        VTMesh vert = vertex(vid);
        if( vert.n_facets() == 0) continue;
        fid = vert.facet(0);
        ind = facet(fid).index(vid);
        assert(ind >= 0);

        facet(fid).set_flag(FTMESH_FLAG_VISITED);
        count = 1;

#define UMBRELLAWALK(vid, fid, fid_circ)                                    \
          fid_pre = fid;                                                    \
          while(fid_circ >= 0 && fid_circ != (int)fid){                     \
            if( facet(fid_circ).check_flag(FTMESH_FLAG_VISITED) ) break;    \
            facet(fid_circ).set_flag(FTMESH_FLAG_VISITED);                  \
            count ++;                                                       \
            ind_circ = facet(fid_circ).index(vid);                          \
            assert(ind_circ >= 0);                                          \
            if( fid_pre != facet(fid_circ).facet( (ind_circ + 1) % 3 ) ){   \
              fid_pre = fid_circ;                                           \
              fid_circ = facet(fid_circ).facet( (ind_circ + 1) % 3 );       \
            }                                                               \
            else{                                                           \
              fid_pre = fid_circ;                                           \
              fid_circ = facet(fid_circ).facet( (ind_circ + 2) % 3 );       \
            }                                                               \
          }

        fid_circ = facet(fid).facet( (ind + 1) % 3 );
        UMBRELLAWALK(vid, fid, fid_circ);

        fid_circ = facet(fid).facet( (ind + 2) % 3 );
        UMBRELLAWALK(vid, fid, fid_circ);

        //If the incident facets does not form an umbrella, then mark
        if( count < vert.n_facets() ) {
            vert.set_flag(VTMESH_FLAG_NMANIFOLD);
            for(unsigned int i = 0; i < vert.n_facets(); i ++)
                facet( vert.facet(i) ).un_set_flag(FTMESH_FLAG_NMANIFOLD);
        }

        //Unset FTMESH_FLAG_VISITED
        for(unsigned int i = 0; i < vert.n_facets(); i ++)
            facet( vert.facet(i) ).un_set_flag(FTMESH_FLAG_VISITED);
    }
}
static std::vector<SimpleEdge_3> getEdges(Polyhedron_3 P,
		std::map<int, int> &map)
{
	DEBUG_START;
	std::vector<bool> visited(P.size_of_halfedges());
	for (unsigned i = 0 ; i < visited.size(); ++i)
		visited[i] = false;
	std::cout << "getEdges: number of halfedges: " << P.size_of_halfedges()
		<< std::endl;

	std::vector<SimpleEdge_3> edges;
	P.initialize_indices();
	CGAL::Origin origin;

	for (auto &i : map)
		i.second = UNINITIALIZED_MAP_VALUE;

	for (auto I = P.halfedges_begin(), E = P.halfedges_end(); I != E; ++I)
	{
		if (visited[I->id])
			continue;
		SimpleEdge_3 edge;
		edge.A = I->vertex()->point() - origin;
		edge.B = I->opposite()->vertex()->point() - origin;
		edge.iForward = I->facet()->id;
		edge.iBackward = I->opposite()->facet()->id;
		// FIXME: Remember indices of planes, not planes themselves,
		// and fix structure for this.
		map[I->id] = map[I->opposite()->id] = edges.size();
		edges.push_back(edge);
		visited[I->id] = visited[I->opposite()->id] = true;
	}
	std::cout << "getEdges: number of edges: " << edges.size() << std::endl;
	ASSERT(edges.size() * 2 == P.size_of_halfedges());

	DEBUG_END;
	return edges;
}
std::set<int> findTangientPointPlanesIDs(
		Polyhedron_3 *polyhedron, Polyhedron_3::Vertex_iterator vertex,
		std::vector<int> index)
{
	DEBUG_START;
	auto circulatorFirst = vertex->vertex_begin();
	auto circulator = circulatorFirst;
	std::set<int> planesIDs;
	std::vector<int> planesIDsVector;
	do
	{
		int iFacet = circulator->facet()->id;
		if (iFacet > (int) polyhedron->size_of_facets())
		{
			ERROR_PRINT("%d > %ld", iFacet,
					polyhedron->size_of_facets());
			exit(EXIT_FAILURE);
		}
		planesIDs.insert(index[iFacet]);
		planesIDsVector.push_back(index[iFacet]);
		++circulator;
	} while (circulator != circulatorFirst);

	if (planesIDs.size() != 3)
	{
		ERROR_PRINT("%d != %d", (int) planesIDs.size(), 3);
		std::cerr << "Indices:";
		for (int i: planesIDsVector)
			std::cerr << " " << i;
		std::cerr << std::endl;
		std::cerr << "degree of vertex " << vertex->id << " is "
			<< vertex->degree() << std::endl;
		exit(EXIT_FAILURE);
	}
	DEBUG_END;
	return planesIDs;
}
Esempio n. 14
0
void TMesh::OutMeshOffFile(FILE *fp, double r, double g, double b, double a)
{
    if( fp == NULL ) {
        std::cout<<"Invalid FILE pointer"<<std::endl;
        return;
    }

    fprintf(fp, "{\n");
    fprintf(fp, "OFF\n");
    fprintf(fp, "%d %d 0\n", v_count(), f_count());
    for(unsigned int i = 0; i < v_count(); i ++) {
        fprintf(fp, "%f %f %f\n", (vertex(i).coord())(0), (vertex(i).coord())(1), (vertex(i).coord())(2));
    }
    for(unsigned int i = 0; i < f_count(); i ++) {
        if( facet(i).check_flag(FTMESH_FLAG_SELECT) )
            fprintf(fp, "3 %d %d %d 1 0 0 1\n", facet(i).vert(0), facet(i).vert(1), facet(i).vert(2));
        else
            fprintf(fp, "3 %d %d %d %f %f %f %f\n", facet(i).vert(0), facet(i).vert(1), facet(i).vert(2), r, g, b, a);
    }
    fprintf(fp, "}\n");
}
Esempio n. 15
0
//--------------------------------------------------
//OrientateFacets:
//----------------
//Orientate the facets so that all the manifold facets will have
//a consistent orientation
//--------------------------------------------------
void TMesh::OrientateFacets()
{
    unsigned int fid, f;
    queue<unsigned int> fid_queue;

    unsigned int max_nfacets, nfacets, fid_start;
    unsigned int vid1, vid2;
    int ind1, ind2;
    int fid_adj;

    //Find largest part of the surface which can be orientated.
    max_nfacets = 0;
    for(f = 0; f < f_count(); f ++) {
        if( facet(f).check_flag(FTMESH_FLAG_NMANIFOLD) ) continue;
        if( facet(f).check_flag(FTMESH_FLAG_VISITED) ) continue;

        fid_queue.push(f);
        facet(f).set_flag(FTMESH_FLAG_VISITED);

        nfacets = 0;
        while( !fid_queue.empty() ) {
            fid = fid_queue.front();
            fid_queue.pop();
            nfacets ++;
            for(int j = 0; j < 3; j ++) {
                fid_adj = facet(fid).facet(j);
                if(fid_adj < 0) continue;
                if( facet(fid_adj).check_flag(FTMESH_FLAG_NMANIFOLD) ) continue;
                if( facet(fid_adj).check_flag(FTMESH_FLAG_VISITED) ) continue;
                fid_queue.push(fid_adj);
                facet(fid_adj).set_flag(FTMESH_FLAG_VISITED);
            }
        }

        if( nfacets > max_nfacets ) {
            max_nfacets = nfacets;
            fid_start = f;
        }
    }
    //unset flags
    for(f = 0; f < f_count(); f ++)
        facet(f).un_set_flag(FTMESH_FLAG_VISITED);


    //orientate the facets
    fid_queue.push(fid_start);
    facet(fid_start).set_flag(FTMESH_FLAG_ORIENTATE);
    while( !fid_queue.empty()) {
        fid = fid_queue.front();
        fid_queue.pop();
        for(int j = 0; j < 3; j ++) {
            fid_adj = facet(fid).facet(j);
            if(fid_adj < 0) continue;
            if( facet(fid_adj).check_flag(FTMESH_FLAG_NMANIFOLD) ) continue;
            if( facet(fid_adj).check_flag(FTMESH_FLAG_ORIENTATE) ) continue;

            vid1 = facet(fid).vert( (j + 1) % 3 );
            vid2 = facet(fid).vert( (j + 2) % 3 );
            ind1 = facet(fid_adj).index(vid1);
            ind2 = facet(fid_adj).index(vid2);

            assert( ind1 >= 0 && ind2 >= 0 );

            //If the orientation of "fid" and "fid_adj" are consisitent
            if( (ind2 + 1) % 3 == ind1 ) {
                if( facet(fid).check_flag(FTMESH_FLAG_REVERSE) )
                    facet(fid_adj).set_flag(FTMESH_FLAG_REVERSE);
            }
            else { //Otherwise the orientation of "fid" and "fid_adj" are NOT consisitent
                assert( (ind1 + 1) % 3  == ind2 );
                if( !(facet(fid).check_flag(FTMESH_FLAG_REVERSE)) )
                    facet(fid_adj).set_flag(FTMESH_FLAG_REVERSE);
            }
            fid_queue.push(fid_adj);
            facet(fid_adj).set_flag(FTMESH_FLAG_ORIENTATE);
        }//for j
    }//while
}
Esempio n. 16
0
void TMesh::GenerateMeshTopo()
{
    unsigned int vid0, vid1, vid2;
    for(unsigned int i = 0; i < f_count(); i ++) {
        vid0 = facet(i).vert(0);
        vid1 = facet(i).vert(1);
        vid2 = facet(i).vert(2);
//    	cout<<i<<"th facet: vertices: "<<vid0<<" "<<vid1<<" "<<vid2<<endl;

        //generate the vertex topology
        vertex(vid0).add_facet(i);
        vertex(vid1).add_facet(i);
        vertex(vid2).add_facet(i);

        vertex(vid0).add_unique_vert(vid1);
        vertex(vid1).add_unique_vert(vid0);
        vertex(vid1).add_unique_vert(vid2);
        vertex(vid2).add_unique_vert(vid1);
        vertex(vid2).add_unique_vert(vid0);
        vertex(vid0).add_unique_vert(vid2);
    }
    //cerr<<"facet done"<<endl;

    for(unsigned int i = 0; i < f_count(); i ++)
    {
        //cout<<"fid: "<<i<<endl;

        //iterate over all facets
        for(int j = 0; j < 3; j ++) {
            //cout<<j<<"th vertex "<<endl;

            //edge vert(j) -- vert((j + 1) % 3)
            vid1 = facet(i).vert(j);
            vid2 = facet(i).vert((j + 1) % 3);
            //seach the adjacent triangle sharing edge (j + 2) % 3
            for(unsigned int fit = 0; fit < vertex(vid1).n_facets(); fit ++) {
                unsigned int fid = vertex(vid1).facet(fit);
                if(fid <= i) continue;

                //cout<<"connected facet: "<<fid<<endl;

                int i1, i2;
                if( (i2 = facet(fid).index(vid2)) == -1 ) continue;
                i1 = facet(fid).index(vid1);
                assert(i1 >= 0);

                if( facet(i).facet((j + 2) % 3) >= 0) {
                    cerr<<"non-manifold1: "<<i<<"--"<<fid<<" along edge: "<<vid1<<" "<<vid2<<endl;
                    continue;
                }

                for(int k = 0; k < 3; k ++) {
                    if(k != i1 && k != i2) {
                        if(facet(fid).facet(k) >= 0) {
                            cerr<<"non-manifold1: "<<i<<"--"<<fid<<" along edge: "<<vid1<<" "<<vid2<<endl;
                        }
                        else { //Only when both facets have not neighbouring facet along
                            //this edge can they be the neighbouring faect for each other.
                            facet(fid).set_facet(k, i);
                            facet(i).set_facet((j + 2) % 3, fid);
                        }
                        break;
                    }
                }//for k
            }//for fit
        }//for j
    }//for i
    //cout<<"topo done"<<endl;

    //set boundary flag
    //for particle
    for(unsigned int i = 0; i < f_count(); i ++) {
        for(int j = 0; j < 3; j ++) {
            if(facet(i).facet(j) >= 0) continue;

            facet(i).set_flag(FTMESH_FLAG_BOUNDARY);
            vertex( facet(i).vert((j + 1) % 3) ).set_flag(VTMESH_FLAG_BOUNDARY);
            vertex( facet(i).vert((j + 2) % 3) ).set_flag(VTMESH_FLAG_BOUNDARY);
        }
    }
    //Check whether the topology of the mesh is valid.
    CheckMeshTopo();
}