Ejemplo n.º 1
0
int main()
{
    const int D = 5;   // we work in Euclidean 5-space
    const int N = 100; // we will insert 100 points
    // - - - - - - - - - - - - - - - - - - - - - - - - STEP 1
    CGAL::Random_points_in_cube_d<Triangulation::Point> rand_it(D, 1.0);
    std::vector<Triangulation::Point> points;
    CGAL::cpp11::copy_n(rand_it, N, std::back_inserter(points));

    Triangulation t(D);                      // create triangulation
    CGAL_assertion(t.empty());
    t.insert(points.begin(), points.end());  // compute triangulation
    CGAL_assertion( t.is_valid() );
    // - - - - - - - - - - - - - - - - - - - - - - - - STEP 2
    typedef Triangulation::Face Face;
    typedef std::vector<Face> Faces;
    Faces edges;
    std::back_insert_iterator<Faces> out(edges);
    t.tds().incident_faces(t.infinite_vertex(), 1, out);  
    // collect faces of dimension 1 (edges) incident to the infinite vertex
    std::cout << "There are " << edges.size() 
              << " vertices on the convex hull." << std::endl;

#include "triangulation1.cpp" // See below
#include "triangulation2.cpp"

    return 0;
}
Ejemplo n.º 2
0
int incorrect_input(std::string error = "")
{
  std::cerr << "Incorrect input file.\n"
	    << "  " << error << "\n";
  std::cerr << "So far: " << vertices.size() << " vertices, "
	    << faces.size() << " faces\n";
  return EXIT_FAILURE;
}
Ejemplo n.º 3
0
 void print()
 {
     std::cout << "MeshData:: " << std::endl << "Vertices : " << std::endl;
     for (int i = 0; i < m_Vertices.size(); i++)
     {
         std::cout << i << ": " << m_Vertices[i] << std::endl;
     }
     std::cout << "Indices & Normals : " << std::endl;
     for (int i = 0; i < m_Faces.size(); i++)
     {
         std::cout << i << ": " << m_Faces[i] << "\t n:" << m_Normals[i] << std::endl;
     }
 };
Ejemplo n.º 4
0
void MDAL::DriverFlo2D::createMesh( const std::vector<CellCenter> &cells, double half_cell_size )
{
  // Create all Faces from cell centers.
  // Vertexs must be also created, they are not stored in FLO-2D files
  // try to reuse Vertexs already created for other Faces by usage of unique_Vertexs set.
  Faces faces;
  Vertices vertices;
  std::map<Vertex, size_t, VertexCompare> unique_vertices; //vertex -> id
  size_t vertex_idx = 0;

  for ( size_t i = 0; i < cells.size(); ++i )
  {
    Face e( 4 );

    for ( size_t position = 0; position < 4; ++position )
    {
      Vertex n = createVertex( position, half_cell_size, cells[i] );
      const auto iter = unique_vertices.find( n );
      if ( iter == unique_vertices.end() )
      {
        unique_vertices[n] = vertex_idx;
        vertices.push_back( n );
        e[position] = vertex_idx;
        ++vertex_idx;
      }
      else
      {
        e[position] = iter->second;
      }
    }

    faces.push_back( e );
  }

  mMesh.reset(
    new MemoryMesh(
      name(),
      vertices.size(),
      faces.size(),
      4, //maximum quads
      computeExtent( vertices ),
      mDatFileName
    )
  );
  mMesh->faces = faces;
  mMesh->vertices = vertices;
}
Ejemplo n.º 5
0
    void writeToLog(Logging::Log* plog)
    {
        std::stringstream logmessage;

        using std::endl;
        using std::cout;

        logmessage << "MeshData:: " << std::endl << "Vertices : " << std::endl;
        for (int i = 0; i < m_Vertices.size(); i++)
        {
            logmessage << i << ": " << m_Vertices[i] << endl;
        }
        logmessage << "Indices & Normals : " << endl;
        for (int i = 0; i < m_Faces.size(); i++)
        {
            logmessage << i << ": " << m_Faces[i] << "\t n:" << m_Normals[i] << std::endl;
        }
        plog->logMessage(logmessage.str());
    };
Ejemplo n.º 6
0
void generateTriangles(const unsigned xdiv,
					   const unsigned ydiv,
					   Faces& faces)
{
	const unsigned xpts(xdiv + 1); // number of points in x
	const unsigned NF(2 * xdiv * ydiv); // total number of faces

	faces.reserve(NF);

	for(unsigned y(0); y != ydiv; ++y)
		for(unsigned x(0); x != xdiv; ++x) {
			const unsigned a(y * xpts + x);
			const unsigned b(a + 1);
			const unsigned c(b + xdiv);
			const unsigned d(c + 1);

			faces.push_back(Trig(a, b, d));
			faces.push_back(Trig(a, d, c));
		}

	assert(faces.size() == NF);
}
Ejemplo n.º 7
0
void draw(const int tex,
		  const Mesh& mesh,
		  const Mesh& tc,
		  const Faces& faces)
{
	assert(tex != 0);
	assert(not mesh.empty());
	assert(mesh.size() == tc.size());
	assert(not faces.empty());

	const cgl::BindTexture2D bind(tex);

	glTexCoordPointer(2, GL_FLOAT, 0, &tc.front().x);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, &mesh.front().x);
	glEnableClientState(GL_VERTEX_ARRAY);

	glDrawElements(GL_TRIANGLES, faces.size() * 3,
				   GL_UNSIGNED_INT, &faces.front().a);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Ejemplo n.º 8
0
void test(const int d, const string & type, const int N)
{
    // we must write 'typename' below, because we are in a template-function,
    // so the parser has no way to know that DC contains sub-types, before
    // instanciating the function.
    typedef typename DC::Full_cell_handle Full_cell_handle;
    typedef typename DC::Face Face;
    typedef typename DC::Point Point;
    typedef typename DC::Finite_full_cell_const_iterator Finite_full_cell_const_iterator;
    typedef typename DC::Finite_vertex_iterator Finite_vertex_iterator;

    typedef CGAL::Random_points_in_cube_d<Point> Random_points_iterator;

    DC pc(d);
    cerr << "\nBuilding Delaunay triangulation of (" << type << d << ") dimension with " << N << " points";
    assert(pc.empty());

    vector<Point> points;
    CGAL::Random rng;
    Random_points_iterator rand_it(d, 2.0, rng);
    //CGAL::cpp11::copy_n(rand_it, N, back_inserter(points));
    
    vector<int> coords(d);
    for( int i = 0; i < N; ++i )
    {
        for( int j = 0; j < d; ++j )
            coords[j] = rand() % 100000;
        points.push_back(Point(d, coords.begin(), coords.end()));
    }
    pc.insert(points.begin(),  points.end());
    cerr << "\nChecking topology and geometry...";
    assert( pc.is_valid() );

    cerr << "\nTraversing finite full_cells... ";
    size_t nbfs(0), nbis(0);
    Finite_full_cell_const_iterator fsit = pc.finite_full_cells_begin();
    while( fsit != pc.finite_full_cells_end() )
        ++fsit, ++nbfs;
    cerr << nbfs << " + ";
    vector<Full_cell_handle> infinite_full_cells;
    pc.tds().incident_full_cells(pc.infinite_vertex(), back_inserter(infinite_full_cells));
    nbis = infinite_full_cells.size();
    cerr << nbis << " = " << (nbis+nbfs)
    << " = " << pc.number_of_full_cells();
    cerr << "\nThe triangulation has current dimension " << pc.current_dimension();
    CGAL_assertion( pc.number_of_full_cells() == nbis+nbfs);

    cerr << "\nTraversing finite vertices... ";
    size_t nbfv(0);
    Finite_vertex_iterator fvit = pc.finite_vertices_begin();
    while( fvit != pc.finite_vertices_end() )
        ++fvit, ++nbfv;
    cerr << nbfv <<endl;

    // Count convex hull vertices:
    if( pc.maximal_dimension() > 1 )
    {
        typedef vector<Face> Faces;
        Faces edges;
        back_insert_iterator<Faces> out(edges);
        pc.tds().incident_faces(pc.infinite_vertex(), 1, out);
        cout << "\nThere are " << edges.size() << " vertices on the convex hull.";
        edges.clear();
    }
    else // pc.maximal_dimension() == 1
    {
        typedef vector<Full_cell_handle> Cells;
        Cells cells;
        back_insert_iterator<Cells> out(cells);
        pc.tds().incident_full_cells(pc.infinite_vertex(), out);
        cout << "\nThere are " << cells.size() << " vertices on the convex hull.";
        cells.clear();
    }

    // Remove all !
    cerr << "\nBefore removal: " << pc.number_of_vertices() << " vertices. After: ";
    random_shuffle(points.begin(),  points.end());
    pc.remove(points.begin(),  points.end());
    assert( pc.is_valid() );
    cerr << pc.number_of_vertices() << " vertices.";
    // assert( pc.empty() ); NOT YET !
    // CLEAR
    pc.clear();
    assert( -1 == pc.current_dimension() );
    assert( pc.empty() );
    assert( pc.is_valid() );
}
Ejemplo n.º 9
0
int main(int argc, char** argv)
{
  if(argc != 3)
    return usage(argv[0]);
  mark_tag vertex_index(1), vertex_x(2), vertex_y(3), vertex_z(4);

  sregex tface_re = bos >> *space >> "TFACE" >> *space >> eos;

  sregex vertex_re = bos >> *space >> "VRTX" 
			 >> +space >> (vertex_index=+_d)
			 >> +space >> (vertex_x=+(digit|'-'|'+'|'.'))
			 >> +space >> (vertex_y=+(digit|'-'|'+'|'.'))
			 >> +space >> (vertex_z=+(digit|'-'|'+'|'.'))
			 >> eos;

  sregex triangle_re = bos >> *space >> "TRGL"
			   >> +space >> (s1=+digit)
			   >> +space >> (s2=+digit)
			   >> +space >> (s3=+digit)
			   >> eos;
  sregex end_re = bos >> *space >> "END" >> *space >> eos;

  std::ifstream input(argv[1]);
  std::ofstream output(argv[2]);

  if(!input) {
    std::cerr << "Cannot read \"" << argv[1] << "\"!\n";
    return EXIT_FAILURE;
  }
  if(!output) {
    std::cerr << "Cannot write to \"" << argv[2] << "\"!\n";
    return EXIT_FAILURE;
  }

  std::string line;
  std::getline(input, line);
  smatch results;
  while(input && ! regex_match(line, tface_re)) // search line "TFACE"
  {
    std::getline(input, line);
  }
  std::getline(input, line);
  while(input && regex_match(line, results, vertex_re)) {
    vertices.push_back(boost::make_tuple(results[vertex_x],
					 results[vertex_y],
					 results[vertex_z]));
    std::getline(input, line);
  }
  while(input && regex_match(line, results, triangle_re)) {
    std::stringstream s;
    int i, j, k;
    s << results[1] << " " << results[2] << " " << results[3];
    s >> i >> j >> k;
    faces.push_back(boost::make_tuple(i, j, k));
    std::getline(input, line);
  }
  if(!input || !regex_match(line, end_re))
    return incorrect_input("premature end of file!");

  output << "OFF " << vertices.size() << " " << faces.size() << " " << "0\n";
  for(Vertices::const_iterator vit = vertices.begin(), vend = vertices.end();
      vit != vend; ++vit)
    output << boost::get<0>(*vit) << " "
	   << boost::get<1>(*vit) << " "
	   << boost::get<2>(*vit) << "\n";
  for(Faces::const_iterator fit = faces.begin(), fend = faces.end();
      fit != fend; ++fit)
    output << "3 " << boost::get<0>(*fit)
	   << " " << boost::get<1>(*fit)
	   << " " << boost::get<2>(*fit) << "\n";
  if(output)
    return EXIT_SUCCESS;
  else
    return EXIT_FAILURE;
};
Ejemplo n.º 10
0
int main(int argc,char *argv[]){
        if(argc<2){
                std::cerr<<
                        "usage: "<<argv[0]<<" input_file"<<std::endl;
                exit(-1);
        }
        std::fstream infile;
        Point p;
        size_t index=0;
        std::vector<Point> points;
#ifdef USE_HASHED_DETERMINANTS
        HD Pdets;
#endif
        infile.open(argv[1],std::fstream::in);
        int dim=0;
        while(infile>>p){
                dim=p.dimension();
#ifdef USE_HASHED_DETERMINANTS
                p.set_index(index++);
                p.set_hash(&Pdets);
#endif
                points.push_back(p);
#ifdef USE_HASHED_DETERMINANTS
                // now we have to add the point to the hash table
                std::vector<CGAL::Gmpq> column;
                for(size_t i=0;i<dim;++i)
                        column.push_back(p[i]);
                Pdets.add_column(column);
#endif
        }
        infile.close();
        clock_t elapsed_offline,elapsed_online;
        Triangulation triang_offline(dim),triang_online(dim);

        clock_t start=clock();
        //for(size_t i=0;i<points.size();++i)
        //        triang_offline.insert(points[i]);
        elapsed_offline=clock()-start;

        start=clock();
        triang_online.insert(points.begin(),points.end());
        elapsed_online=clock()-start;

        typedef Triangulation::Face Face;
        typedef std::vector<Face> Faces;
        Faces edges;
        std::back_insert_iterator<Faces> out(edges);
        triang_online.incident_faces(triang_online.infinite_vertex(),1,out);

        std::cerr<<dim<<'\t'<<
                points.size()<<'\t'<<
                //(double)elapsed_offline/CLOCKS_PER_SEC<<'\t'<<
                .0<<'\t'<<
                (double)elapsed_online/CLOCKS_PER_SEC<<'\t'<<
                edges.size()<<'\t'<<
#ifdef USE_HASHED_DETERMINANTS
                points[0].hash()->algorithm()<<
#else
                "no_hash"<<
#endif
                std::endl;
        //edges.clear();
        return 0;
}