Пример #1
0
void Scene::compute_elements(int mode)
{
    pos_points.resize(0);
    pos_lines.resize(0);
    pos_poly.resize(0);
    pos_cut_segments.resize(0);
    tex_map.resize(0);
    pos_grid.resize(66);
    pos_plane.resize(18);
    float diag = .6f * float(bbox_diag());
    //The Points
    {
        std::list<Point>::iterator pit;
        for(pit = m_points.begin(); pit != m_points.end(); pit++)
        {
            const Point& p = *pit;
            pos_points.push_back(p.x());
            pos_points.push_back(p.y());
            pos_points.push_back(p.z());
        }
    }
    //The Segements
    {
        std::list<Segment>::iterator sit;
        for(sit = m_segments.begin(); sit != m_segments.end(); sit++)
        {
            const Segment& s = *sit;
            const Point& p = s.source();
            const Point& q = s.target();

            pos_lines.push_back(p.x());
            pos_lines.push_back(p.y());
            pos_lines.push_back(p.z());

            pos_lines.push_back(q.x());
            pos_lines.push_back(q.y());
            pos_lines.push_back(q.z());
        }
    }
    //The Polygon's edges
    {
        Polyhedron::Edge_iterator he;
        for(he = m_pPolyhedron->edges_begin();
            he != m_pPolyhedron->edges_end();
            he++)
        {
            const Point& a = he->vertex()->point();
            const Point& b = he->opposite()->vertex()->point();
            pos_poly.push_back(a.x());
            pos_poly.push_back(a.y());
            pos_poly.push_back(a.z());

            pos_poly.push_back(b.x());
            pos_poly.push_back(b.y());
            pos_poly.push_back(b.z());
        }
    }
    //The cutting segments
    {
        for ( std::vector<Segment>::const_iterator csit = m_cut_segments.begin(),
              end = m_cut_segments.end() ; csit != end ; ++csit )
        {
            const Point& a = csit->source();
            const Point& b = csit->target();

            pos_cut_segments.push_back(a.x());
            pos_cut_segments.push_back(a.y());
            pos_cut_segments.push_back(a.z());

            pos_cut_segments.push_back(b.x());
            pos_cut_segments.push_back(b.y());
            pos_cut_segments.push_back(b.z());
        }
    }
    //The cutting plane
    {

        pos_plane[0]= -diag; pos_plane[1]=-diag; pos_plane[2]=0.0;
        pos_plane[3]= -diag; pos_plane[4]= diag; pos_plane[5]=0.;
        pos_plane[6]=  diag; pos_plane[7]= diag; pos_plane[8]=0.;
        pos_plane[9]= -diag; pos_plane[10]= -diag; pos_plane[11]=0.;
        pos_plane[12]= diag;    pos_plane[13]= diag; pos_plane[14]= 0.;
        pos_plane[15]= diag;    pos_plane[16]= -diag; pos_plane[17]= 0.;

        //UV Mapping
        tex_map.push_back(-0.11f);
        tex_map.push_back(-0.11f);

        tex_map.push_back(-0.11f);
        tex_map.push_back(1.11f);

        tex_map.push_back(1.11f);
        tex_map.push_back(1.11f);

        tex_map.push_back(-0.11f);
        tex_map.push_back(-0.11f);

        tex_map.push_back(1.11f);
        tex_map.push_back(1.11f);

        tex_map.push_back(1.11f);
        tex_map.push_back(-0.11f);





    }
    //The grid
    {
        float z = 0;
        float x = (2 * diag)/10.0;
        float y = (2 * diag)/10.0;
        for(int u = 0; u < 11; u++)
        {

            pos_grid.push_back(-diag + x* u);
            pos_grid.push_back(-diag);
            pos_grid.push_back(z);

            pos_grid.push_back(-diag + x* u);
            pos_grid.push_back(diag);
            pos_grid.push_back(z);
        }
        for(int v=0; v<11; v++)
        {

            pos_grid.push_back(-diag);
            pos_grid.push_back(-diag + v * y);
            pos_grid.push_back(z);

            pos_grid.push_back(diag);
            pos_grid.push_back(-diag + v * y);
            pos_grid.push_back(z);

        }

    }
    //The texture
    switch(mode)
    {
    case _SIGNED:
        for( int i=0 ; i < texture->getWidth(); i++ )
        {
            for( int j=0 ; j < texture->getHeight() ; j++)
            {
                compute_texture(i,j,m_red_ramp,m_blue_ramp);
            }
        }
        break;
    case _UNSIGNED:
        for( int i=0 ; i < texture->getWidth(); i++ )
        {
            for( int j=0 ; j < texture->getHeight() ; j++)
            {
                compute_texture(i,j,m_thermal_ramp,m_thermal_ramp);
            }
        }
        break;}
    sampler_location = tex_rendering_program.attributeLocation("texture");
}
// a helper method for running different iterators
void running_iterators( Polyhedron& P) {
    if ( P.size_of_facets() == 0)
        return;

    std::size_t nv = P.size_of_vertices();

    std::cout << "The number of vertices in the Polyhedron: " << nv << std::endl;
    std::cout << "The number of facets in the Polyhedron: " << P.size_of_facets() << std::endl;
    std::cout << "The number of half edges in the Polyhedron: " << P.size_of_halfedges() << std::endl;

    std::cout << std:: endl;

    Polyhedron::Vertex_iterator last_v = P.vertices_end();
    -- last_v;  // the last of the old vertices

    Polyhedron::Edge_iterator last_e = P.edges_end();
    -- last_e;  // the last of the old edges

    Polyhedron::Facet_iterator last_f = P.facets_end();
    -- last_f;  // the last of the old facets

    int k = 0;
    Polyhedron::Facet_iterator f = P.facets_begin();

    do {
    	std::cout << "Printing a facet index: " << k++ <<  std::endl;

    	f->halfedge();

    } while ( f++ != last_f);

    std::cout  << std::endl;

    // -------------------------------------------------
    // traverse the vertices
    // -------------------------------------------------

    std::cout << "Printing the vertex indices: " << std::endl;

     int n=0;
     for (Polyhedron::Vertex_iterator vi = P.vertices_begin(); vi != P.vertices_end(); ++vi)
     {
    	 Kernel::Point_3 p;
    	 p = vi->point();
    	 std::cout << "Vertex index: "  << n++ << std::endl;
    	 std::cout << "p.x() = "  << p.x() << std::endl;
    	 std::cout << "p.y() = "  << p.y() << std::endl;
    	 std::cout << "p.z() = "  << p.z() << std::endl;

     }

     std::cout  << std::endl;

     // -------------------------------------------------
     // traverse the edges
     // -------------------------------------------------

     std::cout << "Iterating over the edges.... " << std::endl;

     n=0;
     for (Polyhedron::Edge_iterator ei = P.edges_begin(); ei != P.edges_end(); ++ei)
     {
    	 ei->next();
    	 Kernel::Point_3 p;
    	 p =  ei->vertex()->point();
    	 std::cout << "For edge index: " << n++ << std::endl;
    	 std::cout << "p.x() = "  << p.x() << std::endl;
		 std::cout << "p.y() = "  << p.y() << std::endl;
		 std::cout << "p.z() = "  << p.z() << std::endl;

     }
     std::cout  << std::endl;

	 // -----------------------------------------------
	 // Do something else with the edge iterators
	 // -----------------------------------------------

    Polyhedron::Edge_iterator e = P.edges_begin();
    ++ last_e; // make it the past-the-end position again

    while ( e != last_e) {
    	Polyhedron::Halfedge_handle h = e;
        ++e;
    };

    CGAL_postcondition( P.is_valid());
}