Пример #1
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() );
}
Пример #2
0
void test(const int d, const string & type)
{
    // we must write 'typename' below, because we are in a template-function,
    // so the parser has no way to know that TDS contains sub-types, before
    // instanciating the function.
    typedef typename TDS::Vertex_handle Vertex_handle;
    typedef typename TDS::Vertex_iterator Vertex_iterator;
    typedef typename TDS::Full_cell_handle Full_cell_handle;
    typedef typename TDS::Face Face;
    typedef typename TDS::Facet Facet;
    typedef typename TDS::Facet_iterator Facet_iterator;

    TDS tds(d);
    cout << "\nChecking Tds of (" << type << ") dimension "
        << tds.maximal_dimension();
    assert(tds.empty());
    vector<Vertex_handle> vhs;
    vhs.push_back(tds.insert_increase_dimension());
    assert( tds.is_valid() );
    size_t nb_verts = 1;
    for( int i = 0; i <= d; ++i )
    {
        vhs.push_back(tds.insert_increase_dimension(vhs[0]));
        ++nb_verts;
        
        assert(i == tds.current_dimension());
        assert(!tds.is_vertex(Vertex_handle()));
        assert(!tds.is_full_cell(Full_cell_handle()));
        assert(tds.is_vertex(vhs[i]));
        assert(tds.is_full_cell(vhs[i]->full_cell()));

        if( tds.current_dimension() > 0 )
        {
            //int nbs = tds.number_of_full_cells();
            tds.insert_in_full_cell(tds.full_cell(vhs[i+1]));
            ++nb_verts;
            //assert((size_t)(nbs+tds.current_dimension())==tds.number_of_full_cells());
        }
        assert( tds.is_valid() );
    }
    assert((nb_verts == tds.number_of_vertices()));

    if( d > 1 )
    {
        // insert in hole
        std::vector<Full_cell_handle> simps;
        simps.push_back(tds.full_cells_begin());
        simps.push_back(tds.neighbor(simps[0],0));
        tds.insert_in_hole(simps.begin(), simps.end(), Facet(simps[0],1));
    }

   // TEST Faces enumeration
    typedef std::vector<Face> Faces;
    Faces faces;
    for( Vertex_iterator vit = tds.vertices_begin(); vit != tds.vertices_end(); ++vit )
    {
        for( int d = 1; d < tds.current_dimension() - 1; ++d )
        {
            //cout << '\n' << d << "-dimensional faces adjacent to " << &(*vit)
            //      << " ( current dimension is " << tds.current_dimension() << " )";
            faces.clear();
            std::back_insert_iterator<Faces> out(faces);
            tds.incident_faces(vit, d, out);
            typename Faces::iterator fit = faces.begin();
            while( fit != faces.end() )
            {
                //cout << '\n';
                //for( int i = 0; i <= d; ++i )
                //    cout << ' ' << &(*fit->vertex(i));
                ++fit;
            }
        }
    }

    // TEST Finite iterators
    if( tds.current_dimension() > 0 )
    {
        Facet_iterator fit = tds.facets_begin();
        size_t nbfft(0);
        while( fit != tds.facets_end() )
            ++fit, ++nbfft;
        cout << '\n' << tds.number_of_full_cells() << " full cells, ";
        cout << ' ' << nbfft << " facets.";
    }
 
    // TEST File I/O
    std::ofstream fo((string("output-tds-")+type).c_str());
    if( d % 2 )
        CGAL::set_binary_mode(fo);
    fo << tds;
    fo.close();

    std::ifstream fi((string("output-tds-")+type).c_str());
    if( d % 2 )
        CGAL::set_binary_mode(fi);
    TDS input_tds(d);
    fi >> input_tds;
    fi.close();

    // TEST Copy Constructor
    TDS tds2(tds);
    assert( tds2.is_valid() );
    assert( tds.current_dimension() == tds2.current_dimension() );
    assert( tds.maximal_dimension() == tds2.maximal_dimension() );
    assert( tds.number_of_vertices() == tds2.number_of_vertices() );
    assert( tds.number_of_full_cells() == tds2.number_of_full_cells() );

    // CLEAR
    tds.clear();
    assert(-2==tds.current_dimension());
    assert(tds.empty());
    assert( tds.is_valid() );
}