Strange behavior of std::vector containing CGAL::Polyhedron_3<Traits>::Vertex pointers

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Strange behavior of std::vector containing CGAL::Polyhedron_3<Traits>::Vertex pointers

Koutsokeras Miltiadis
I'm experiencing some strange behavior while using an std::vector of
CGAL::Polyhedron_3<Traits>::Vertex  pointers.
While iterating through the container I watermark every element is
labeled with the value -1 or 1 and its 1-ring neighbors with value 2. In
every iteration labeling only the vertices that have a label equal to
zero, because a vertex can be a neighbor of a
previous thus it's already labeled with 2. The strange thing is that I
encounter vertices labeled with 1 or -1, although before the iteration
all vertices labels are initialized with zeros. In the example code
below I specify the condition that breaks. Can someone
please give me any tip about CGAL::Polyhedron_3<Traits>::Vertex pointers
and why this behavior happens?
 
Code:
       /**
        * Embeds the watermark to the primitive.
        */
        void embedWatermark(SpatialPrimitive& v, WatermarkPrimitive
watermark)
        {
#ifdef _DEBUG
            assert(v.m_label == 0);
#endif

            typedef typename SpatialPrimitive VertexType;
            typedef typename
VertexType::Halfedge_around_vertex_circulator Circ;
            typedef typename VertexType::Vertex_handle Vertex_handle;

            std::size_t neighbors_num = 0;

            // loop through neighbors
            Circ c = v.vertex_begin();
            Circ end = c;
            Vertex_handle neighbor;

            CGAL_For_all(c, end)
            {
                neighbor = c->opposite()->vertex();
                neighbors_num++;
                neighbor->m_label = 2;
            }

#ifdef _DEBUG
            assert(neighbors_num == v.vertex_degree());
#endif
            v.m_label = watermark;
        }



     /**
    * Watermarks a list of vertices usign a list of watermark samples.
    * @param chosen_verts List of vertices to watermark.
    * @param watermark_samples List of watermark samples.
    */
    void watermarkVertices(std::vector<Vertex *> chosen_verts,
std::vector<short> watermark_samples)
    {
#ifdef _DEBUG
        unsigned int chosen_vertices_size = chosen_verts.size(),
                        watermark_samples_size = watermark_samples.size();
        assert(chosen_vertices_size == watermark_samples_size);
#endif
        std::vector<Vertex *>::iterator vertex_it = chosen_verts.begin();
        std::vector<Vertex *>::const_iterator vertex_end =
chosen_verts.end();
        std::vector<short>::iterator sample_it = watermark_samples.begin();

        for(; vertex_it != vertex_end; ++vertex_it, ++sample_it)
        {
#ifdef _DEBUG
            *// this assertion fails after some iterations
            assert(((*vertex_it)->m_label == 0) ||
((*vertex_it)->m_label == 2));*
#endif
            if((*vertex_it)->m_label == 0)
            {
                embedWatermark(*(*vertex_it), *sample_it);
            }
        }
    }

--
Koutsokeras Miltiadis

Computational Intelligence Laboratory (http://www.iit.demokritos.gr/cil/)
Institute of Informatics and Telecommunications
National Center for Scientific Research "Demokritos"
P.O. BOX   60228
GR-153 10 Agia Paraskevi, Athens, Greece.

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss