Constrained_triangulation_plus_2 may crashed when insert_vertex_in_constraint called!

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Constrained_triangulation_plus_2 may crashed when insert_vertex_in_constraint called!

JWANG
hi all, I found Constrained_triangulation_plus_2 may crashed when insert_vertex_in_constraint called
my codes:

#include <CGAL/basic.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_hierarchy_2.h>
#include <CGAL/Constrained_triangulation_plus_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Exact_predicates_tag ITAG;
typedef CGAL::Triangulation_vertex_base_2<K> TVBB;
typedef CGAL::Triangulation_hierarchy_vertex_base_2<TVBB> TVB;
typedef CGAL::Constrained_triangulation_face_base_2<K> TFB;
typedef CGAL::Triangulation_data_structure_2<TVB, TFB> TDS;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, ITAG> CDT;
typedef CGAL::Triangulation_hierarchy_2<CDT> CDTH;
typedef CGAL::Constrained_triangulation_plus_2<CDTH> CDTP;

typedef CGAL::Polygon_2<K> Polygon_2;
typedef CDTP::Point  Point_2;
typedef CDTP::Vertex_handle Vertex_handle;
typedef CDTP::Constraint_id Constraint_id;
typedef CDTP::Constraint_iterator Constraint_iterator;
typedef CDTP::Vertices_in_constraint_iterator Vertices_in_constraint_iterator;

#include "vector4.hpp"
#include "Matrix4.hpp"
#include "Math.hpp"
int main() {
 Polygon_2 polygon;
 polygon.push_back(Point_2(0.00000000000000000, 71.289788474561647));
 polygon.push_back(Point_2(42.553236484178342, 71.993132446252275));
 polygon.push_back(Point_2(43.293765253096353, 0.70334397174883634));
 polygon.push_back(Point_2(0.74052876897621900, 0.00000000000000000));
 polygon.push_back(Point_2(0.00000000000000000, 71.289788474561647));

 Point_2 p1(21.520543956896290, 71.645492202660535);
 Point_2 p2(22.262916839332320, 0.35573420871514827);
 Point_2 p3(21.520543956896290, 71.645492202660535);
 CDTP cdtp;
 Constraint_id id = cdtp.insert_constraint(polygon.vertices_begin(), polygon.vertices_end(), false);
 int todo = 1;
 for (Constraint_iterator cid = cdtp.constraints_begin(); cid != cdtp.constraints_end(); cid++) {
  Vertices_in_constraint_iterator vb = cdtp.vertices_in_constraint_begin(*cid);
  if (vb == cdtp.vertices_in_constraint_end(*cid)) continue;
  Vertex_handle P = *vb; vb++;
  if (vb == cdtp.vertices_in_constraint_end(*cid)) continue;
  
  for (; vb != cdtp.vertices_in_constraint_end(*cid); vb++) {
   Vertex_handle Q = *vb;
   if (todo)
   {
    //Vertex_handle W = cdtp.insert(Point_2(p1.x(),p1.y()));
    Vertex_handle W = cdtp.insert(p1);
    vb = cdtp.insert_vertex_in_constraint(*cid, vb, W);
    P = Q;
    vb++;
    todo = 0;
   }

   //std::cout << P->point().x() << " " << P->point().y();// << " " << Q->point().x() << " " << Q->point().y() << std::endl;
  }
 }
    return 0;
}

I use Visual Studio 2015(update3) + CGAL-4.7(static library)
something wrong?

thanks for your help!

WangJin




 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Constrained_triangulation_plus_2 may crashed when insert_vertex_in_constraint called!

Sebastien Loriot (GeometryFactory)
Note that you are iterating over constrained edges and in the same loop
you modify the set
of constrained edges. This is invalidating the iterator you are using.

Sebastien.

On 04/27/2017 08:54 AM, 王进 wrote:

> hi all, I found Constrained_triangulation_plus_2 may crashed when
> insert_vertex_in_constraint called
> my codes:
>
> #include <CGAL/basic.h>
> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
> #include <CGAL/Constrained_Delaunay_triangulation_2.h>
> #include <CGAL/Triangulation_hierarchy_2.h>
> #include <CGAL/Constrained_triangulation_plus_2.h>
> typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
> typedef CGAL::Exact_predicates_tag ITAG;
> typedef CGAL::Triangulation_vertex_base_2<K> TVBB;
> typedef CGAL::Triangulation_hierarchy_vertex_base_2<TVBB> TVB;
> typedef CGAL::Constrained_triangulation_face_base_2<K> TFB;
> typedef CGAL::Triangulation_data_structure_2<TVB, TFB> TDS;
> typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, ITAG> CDT;
> typedef CGAL::Triangulation_hierarchy_2<CDT> CDTH;
> typedef CGAL::Constrained_triangulation_plus_2<CDTH> CDTP;
>
> typedef CGAL::Polygon_2<K> Polygon_2;
> typedef CDTP::Point  Point_2;
> typedef CDTP::Vertex_handle Vertex_handle;
> typedef CDTP::Constraint_id Constraint_id;
> typedef CDTP::Constraint_iterator Constraint_iterator;
> typedef CDTP::Vertices_in_constraint_iterator
> Vertices_in_constraint_iterator;
>
> #include "vector4.hpp"
> #include "Matrix4.hpp"
> #include "Math.hpp"
> int main() {
>  Polygon_2 polygon;
>  polygon.push_back(Point_2(0.00000000000000000, 71.289788474561647));
>  polygon.push_back(Point_2(42.553236484178342, 71.993132446252275));
>  polygon.push_back(Point_2(43.293765253096353, 0.70334397174883634));
>  polygon.push_back(Point_2(0.74052876897621900, 0.00000000000000000));
>  polygon.push_back(Point_2(0.00000000000000000, 71.289788474561647));
>
>  Point_2 p1(21.520543956896290, 71.645492202660535);
>  Point_2 p2(22.262916839332320, 0.35573420871514827);
>  Point_2 p3(21.520543956896290, 71.645492202660535);
>  CDTP cdtp;
>  Constraint_id id = cdtp.insert_constraint(polygon.vertices_begin(),
> polygon.vertices_end(), false);
>  int todo = 1;
>  for (Constraint_iterator cid = cdtp.constraints_begin(); cid !=
> cdtp.constraints_end(); cid++) {
>   Vertices_in_constraint_iterator vb =
> cdtp.vertices_in_constraint_begin(*cid);
>   if (vb == cdtp.vertices_in_constraint_end(*cid)) continue;
>   Vertex_handle P = *vb; vb++;
>   if (vb == cdtp.vertices_in_constraint_end(*cid)) continue;
>
>   for (; vb != cdtp.vertices_in_constraint_end(*cid); vb++) {
>    Vertex_handle Q = *vb;
>    if (todo)
>    {
>     //Vertex_handle W = cdtp.insert(Point_2(p1.x(),p1.y()));
>     Vertex_handle W = cdtp.insert(p1);
>     vb = cdtp.insert_vertex_in_constraint(*cid, vb, W);
>     P = Q;
>     vb++;
>     todo = 0;
>    }
>
>    //std::cout << P->point().x() << " " << P->point().y();// << " " <<
> Q->point().x() << " " << Q->point().y() << std::endl;
>   }
>  }
>     return 0;
> }
>
> I use Visual Studio 2015(update3) + CGAL-4.7(static library)
> something wrong?
>
> thanks for your help!
>
> WangJin
>
>
>
>
>
>


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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re:[cgal-discuss] Constrained_triangulation_plus_2 may crashed when insert_vertex_in_constraint called!

JWANG
hi Sebastien, thanks for your replay!

in the documentation 

  // Inserts vh before pos
  // Returns an iterator pointing on the newly inserted vertex
  // Writes the modified faces to out
  template <class OutputIterator>
  Vertices_in_constraint_iterator
  insert_vertex_in_constraint(Constraint_id cid, Vertices_in_constraint_iterator pos, 
     Vertex_handle vh, OutputIterator out)
  { ...}

this operation is same as stl list insert operation,the follow code had handled iterator to keep validated

vb = cdtp.insert_vertex_in_constraint(*cid, vb, W);
vb++;
and the example  procedure is not everytime crashed,maybe 5-10% chance.

WangJin


At 2017-04-27 15:15:05, "Sebastien Loriot (GeometryFactory)" <[hidden email]> wrote: >Note that you are iterating over constrained edges and in the same loop >you modify the set >of constrained edges. This is invalidating the iterator you are using. > >Sebastien. > >On 04/27/2017 08:54 AM, 王进 wrote: >> hi all, I found Constrained_triangulation_plus_2 may crashed when >> insert_vertex_in_constraint called >> my codes: >> >> #include <CGAL/basic.h> >> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> >> #include <CGAL/Constrained_Delaunay_triangulation_2.h> >> #include <CGAL/Triangulation_hierarchy_2.h> >> #include <CGAL/Constrained_triangulation_plus_2.h> >> typedef CGAL::Exact_predicates_inexact_constructions_kernel K; >> typedef CGAL::Exact_predicates_tag ITAG; >> typedef CGAL::Triangulation_vertex_base_2<K> TVBB; >> typedef CGAL::Triangulation_hierarchy_vertex_base_2<TVBB> TVB; >> typedef CGAL::Constrained_triangulation_face_base_2<K> TFB; >> typedef CGAL::Triangulation_data_structure_2<TVB, TFB> TDS; >> typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, ITAG> CDT; >> typedef CGAL::Triangulation_hierarchy_2<CDT> CDTH; >> typedef CGAL::Constrained_triangulation_plus_2<CDTH> CDTP; >> >> typedef CGAL::Polygon_2<K> Polygon_2; >> typedef CDTP::Point Point_2; >> typedef CDTP::Vertex_handle Vertex_handle; >> typedef CDTP::Constraint_id Constraint_id; >> typedef CDTP::Constraint_iterator Constraint_iterator; >> typedef CDTP::Vertices_in_constraint_iterator >> Vertices_in_constraint_iterator; >> >> #include "vector4.hpp" >> #include "Matrix4.hpp" >> #include "Math.hpp" >> int main() { >> Polygon_2 polygon; >> polygon.push_back(Point_2(0.00000000000000000, 71.289788474561647)); >> polygon.push_back(Point_2(42.553236484178342, 71.993132446252275)); >> polygon.push_back(Point_2(43.293765253096353, 0.70334397174883634)); >> polygon.push_back(Point_2(0.74052876897621900, 0.00000000000000000)); >> polygon.push_back(Point_2(0.00000000000000000, 71.289788474561647)); >> >> Point_2 p1(21.520543956896290, 71.645492202660535); >> Point_2 p2(22.262916839332320, 0.35573420871514827); >> Point_2 p3(21.520543956896290, 71.645492202660535); >> CDTP cdtp; >> Constraint_id id = cdtp.insert_constraint(polygon.vertices_begin(), >> polygon.vertices_end(), false); >> int todo = 1; >> for (Constraint_iterator cid = cdtp.constraints_begin(); cid != >> cdtp.constraints_end(); cid++) { >> Vertices_in_constraint_iterator vb = >> cdtp.vertices_in_constraint_begin(*cid); >> if (vb == cdtp.vertices_in_constraint_end(*cid)) continue; >> Vertex_handle P = *vb; vb++; >> if (vb == cdtp.vertices_in_constraint_end(*cid)) continue; >> >> for (; vb != cdtp.vertices_in_constraint_end(*cid); vb++) { >> Vertex_handle Q = *vb; >> if (todo) >> { >> //Vertex_handle W = cdtp.insert(Point_2(p1.x(),p1.y())); >> Vertex_handle W = cdtp.insert(p1); >> vb = cdtp.insert_vertex_in_constraint(*cid, vb, W); >> P = Q; >> vb++; >> todo = 0; >> } >> >> //std::cout << P->point().x() << " " << P->point().y();// << " " << >> Q->point().x() << " " << Q->point().y() << std::endl; >> } >> } >> return 0; >> } >> >> I use Visual Studio 2015(update3) + CGAL-4.7(static library) >> something wrong? >> >> thanks for your help! >> >> WangJin >> >> >> >> >> >> > > >-- >You are currently subscribed to cgal-discuss. >To unsubscribe or access the archives, go to >https://sympa.inria.fr/sympa/info/cgal-discuss > >


 

Loading...