LiTe
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ttessel.h
Go to the documentation of this file.
1 /* Line Tessellation (LiTe) library
2  |||Development version
3  Authors: Katarzyna Adamczyk and Kiên Kiêu.
4  |||Copyright INRA 2006-yyyy.
5  Interdeposit Certification: IDDN.FR.001.030007.000.R.P.2015.000.31235
6  License: GPL v3. */
7 
10 /******************************************************************************/
11 /* LINE BASED TESSELLATION CLASS - DECLARATIONS */
12 /******************************************************************************/
13 
14 /******************************************************************************/
15 /* INCLUDES */
16 /******************************************************************************/
17 
18 // Define shorter names to please linker (g++)
19 //#include "short_names.h"
20 //#include <cotime>
21 #include <iostream>
22 #include <CGAL/Cartesian.h>
23 #include <CGAL/Gmpq.h>
24 /* Calcul exact pour +,-,*,/. On peut sauvegarder la tessellation dans
25 un fichier texte sans perte de précision. Par contre, la racine carréen'est implémentée.*/ #include <CGAL/Lazy_exact_nt.h> #include <CGAL/Linear_algebraCd.h> #include <CGAL/double.h> #include <CGAL/Arr_segment_traits_2.h> #include <CGAL/Arr_default_dcel.h> #include <CGAL/Arrangement_2.h> #include <CGAL/IO/Arr_iostream.h> #include <CGAL/Arr_walk_along_line_point_location.h> #include <CGAL/Arr_naive_point_location.h> #include <CGAL/Polygon_2.h> #include <CGAL/Polygon_2_algorithms.h> #include <CGAL/intersections.h> #include <CGAL/Bbox_2.h> #include <CGAL/Random.h> // Two following headers required for clip_segment_by_convex_polygon #include <CGAL/Extended_cartesian.h> #include <CGAL/Nef_polyhedron_2.h> /******************************************************************************/ /* TYPE DEFINITIONS AND FORWARD CLASS DECLARATIONS */ /******************************************************************************/ /** \typedef NT * \brief The CGAL numeric type used for exact computations in LiTe*/ typedef CGAL::Lazy_exact_nt<CGAL::Gmpq> NT; /** \typedef Kernel * \brief The CGAL type of coordinates used in LiTe*/ typedef CGAL::Cartesian<NT> Kernel; /** \typedef Traits * \brief The CGAL arrangement traits class used for representing * tessellations*/ typedef CGAL::Arr_segment_traits_2<Kernel> Traits; /** \typedef Vector * \brief The CGAL class used for representing vectors*/ typedef CGAL::Vector_2<Kernel> Vector; /** \typedef Point2 * \brief CGAL class representing a point from a tessellation*/ typedef Traits::Point_2 Point2; /** \typedef Segment * \brief CGAL class representing a line segment from a tessellation*/ typedef Traits::Segment_2 Segment; /** \typedef Curve * \brief CGAL class representing a curve (line segment) from * a tessellation*/ typedef Traits::X_monotone_curve_2 Curve; /** typedef \brief CGAL class representing a rectangle with horizontal * and vertical sides*/ typedef CGAL::Iso_rectangle_2<Kernel> Rectangle; /** \typedef Line * \brief CGAL class representing an infinite line*/ typedef CGAL::Line_2<Kernel> Line; /** \typedef Rayon * \brief CGAL class representing a half-line*/ typedef CGAL::Ray_2<Kernel> Rayon; /** \typedef Direction * \brief CGAL class representing a direction in the plane*/ typedef CGAL::Direction_2<Kernel> Direction; /** \typedef Transformation * \brief CGAL class representing an affine transformation*/ typedef CGAL::Aff_transformation_2<Kernel> Transformation; /** \typedef Polygon * \brief CGAL class representing a polygon*/ typedef CGAL::Polygon_2<Kernel> Polygon; /** \typedef Points * \brief Class representing a series of points*/ typedef std::vector<Point2> Points; /** \typedef LA * \brief Class used for basic linear algebra * * This class is used in particular for some computations on * matrices.*/ typedef CGAL::Linear_algebraCd<double> LA; /** \typedef FVector * \brief Class used for representing a vector (in the linear algebra * sense)*/ typedef LA::Vector FVector; /** \typedef FMatrix * \brief Class used for representing a matrix */ typedef LA::Matrix FMatrix; class LineTes_halfedge; // forward declaration /** \typedef Dcel * \brief Class used as a template parameter for the Arrangement class * * Use of non-standard halfedges (class LineTes_halfedge)*/ typedef CGAL::Arr_dcel_base<CGAL::Arr_vertex_base<Point2>, LineTes_halfedge, CGAL::Arr_face_base> Dcel; /** \typedef Arrangement * \brief Class representing a tessellation*/ typedef CGAL::Arrangement_2<Traits,Dcel> Arrangement; /** \typedef Size * \brief Number type used for indexing tessellation features*/ typedef Dcel::Size Size; /** \brief LiTe random generator * * LiTe implements several stochastic algorihtms where this * generator is used.*/ extern CGAL::Random *rnd; // variable globale // definition that prevent type expansion in the documentation generated by Rcpp class Polygons : public std::vector<Polygon> {}; /******************************************************************************/ /* DÉFINITION DE LA CLASSE LineTes */ /******************************************************************************/ /** \brief Polygonal tessellation of a bounded rectangular domain * * This class inherits from the Arrangement_2 class provided by * CGAL. Its main feature concerns the so-called segments. A segment * is defined as a maximal subset of edges that are aligned and * connected. The %LineTes class is of interest for tessellations with * segments that consist of more than one edge. */ class LineTes : public Arrangement { public: /** \brief Segment in a line tessellation * * In a line tessellation represented by a LineTes object, a segment * is defined as a maximal subset of edges that are aligned and * connected. A %Segment object is mainly a Halfedge_handle referring * to an edge lying on the segment. */ class Seg { public: Seg(); Seg(Halfedge_handle); Halfedge_handle halfedges_start(); Halfedge_handle halfedges_end(); Size number_of_edges(); bool number_of_edges_is_greater_than(unsigned int); Point2 pointSource(); Point2 pointTarget(); Points list_of_points(); /** \brief Return the halfedge handle identifying the segment*/ inline Halfedge_handle get_halfedge_handle(){return e;} void set_halfedge_handle(Halfedge_handle); void print(bool endsOnly=false); private: Halfedge_handle e; Size or_idx; }; /** \typedef Seg_handle * \brief Pointer to a Seg object*/ typedef Seg* Seg_handle; /** \brief List of Seg objects * * This class is intended mainly for representing all segments in a * LineTes object. For representing only a subset of segments, use * thee Seg_sublist class instead. */ class Seg_list : public std::vector<Seg_handle> { public: /** \brief Add a segment at the end of the segment list */ inline void add(Seg_handle s) { push_back(s);} /** \brief Delete a Seg object and remove it from the segment list. * * \param s : handle of the segment to be suppressed. * * Yield a warning and return false if the input segment is not * found in the list. */ inline bool suppress(Seg_handle s){ iterator ou_s = std::find(begin(),end(),s); if (ou_s==end()) { std::clog << "LineTes::Seg_list::suppress : item to suppress not found" << std::endl; return false; } erase(ou_s); delete s; return true; } }; /** \brief Sublist of Seg objects * * To be used for storing e.g. a sublist of segments of a given type. */ class Seg_sublist : public std::vector<Seg_handle> { public: /** \brief Add a segment at the end of the segment list */ inline void add(Seg_handle s) { push_back(s);} /** \brief Remove a segment from the segment list. * * \param s : handle of the segment to be suppressed. * * Yield a warning and return false if the input segment is not * found in the list. */ inline bool suppress(Seg_handle s ){ iterator ou_s = std::find(begin(),end(),s); if (ou_s==end()) { std::clog << "LineTes::Seg_sublist::suppress : item to suppress not found" << std::endl; return false; } erase(ou_s); return true; } }; /** \typedef Seg_list_iterator * \brief Iterator for accessing segments in a list*/ typedef Seg_list::iterator Seg_list_iterator; /** \typedef Seg_sublist_iterator * \brief Iterator for accessing segments in a sublist of segments*/ typedef Seg_sublist::iterator Seg_sublist_iterator; LineTes(); virtual void insert_window(Rectangle); virtual void insert_window(Polygon&); Halfedge_handle split_from_edge(Halfedge_handle, Point2, Halfedge_handle, Point2); Halfedge_handle split_from_vertex(Vertex_handle, Halfedge_handle, Point2); Face_handle suppress_edge(Halfedge_handle); void clear(); /** \brief Return an iterator pointing to the beginning of the list of * tessellation segments */ inline Seg_list_iterator segments_begin(){return all_segments.begin();} /** \brief Return an iterator pointing to the end of the list of * tessellation segments */ inline Seg_list_iterator segments_end(){return all_segments.end();} /** \brief Return the total number of segments * * Boundary and internal segments are included */ inline Size number_of_segments(){return all_segments.size();} bool is_valid(bool verbose=false); bool check_all_segments(bool verbose=false); bool check_segment(Seg_handle s, bool verbose=false); bool check_all_halfedges(bool verbose=false); bool check_halfedge(LineTes::Halfedge_handle e, bool verbose=false); bool halfedge_exists(LineTes::Halfedge_handle); bool check_halfedge_neighbours(LineTes::Halfedge_handle e, bool verbose=false); bool check_halfedge_prev_hf(LineTes::Halfedge_handle e, bool verbose=false); bool check_halfedge_next_hf(LineTes::Halfedge_handle e, bool verbose=false); bool check_halfedge_segment(LineTes::Halfedge_handle e, bool verbose=false); bool check_halfedge_dir(LineTes::Halfedge_handle e, bool verbose=false); void print_all_segments(bool endsOnly=false); /** \brief Return the domain that is tessellated */ inline Polygon get_window(){return window;} Size number_of_window_edges(); double get_window_perimeter(); int is_on_boundary(Halfedge_handle); /** \brief Test whether a segment lies on the domain boundary * * \param s : a handle to the segment to be tested */ inline bool is_on_boundary(Seg_handle s){return is_on_boundary(s->get_halfedge_handle())>0;} Seg_handle insert_segment(Segment); void remove_ivertices(Size imax=0, bool verbose=false); void remove_lvertices(Size imax=0, bool verbose=false); bool is_a_T_tessellation(bool verbose=false, std::ostream& out=std::clog); void write(std::ostream&); void read(std::istream&); private: Polygon window; Seg_list all_segments; Halfedge_handle split_edge(Halfedge_handle,X_monotone_curve_2, X_monotone_curve_2); Halfedge_handle merge_edge(Halfedge_handle, Halfedge_handle, X_monotone_curve_2); Halfedge_handle add_edge(X_monotone_curve_2,Vertex_handle, Vertex_handle); Face_handle remove_edge(Halfedge_handle); }; /* Variables globales declarées avant leur utilisation */ /** \brief Null value for a LineTes halfedge handle*/ extern LineTes::Halfedge_handle NULL_HALFEDGE_HANDLE; /** \brief Null value for a LineTes face handle*/ extern LineTes::Face_handle NULL_FACE_HANDLE; /** \brief Null value for a LineTes segment handle*/ extern LineTes::Seg_handle NULL_SEG_HANDLE; /******************************************************************************/ /* DÉFINITION DE LA CLASSE LineTes_halfedge */ /******************************************************************************/ /** \brief Halfedge class used by the LineTes class * * The LineTes_halfedge class derives from the CGAL class * Arr_halfedge_base. Several attributes related to segments have been * added. * * A segment represented by a LineTes::Seg object is identified by one * of its halfedge. It is therefore oriented and its orientation is * determined by the orientation of its identifying halfedge. */ class LineTes_halfedge : public CGAL::Arr_halfedge_base<Curve> { public: LineTes_halfedge(); /** \brief Return previous halfedge along the segment */ inline LineTes::Halfedge_handle get_prev_hf() {return prev_hf;} /** \brief Return next halfedge along the segment */ inline LineTes::Halfedge_handle get_next_hf() {return next_hf;} /** \brief Test halfedge direction against the segment direction * \return true if the halfedge and the segment have the same direction, * false if they are opposite. */ inline bool get_dir() {return dir;} /** \brief Return the halfedge length */ inline double get_length() {return length;} /** \brief Return a handle of the segment containing the halfedge */ inline LineTes::Seg_handle get_segment() {return segment_ptr;} /** \brief Return a handle of the segment containing the halfedge * \note Redondant method. Is it really used? */ inline LineTes::Seg_handle segment(){return segment_ptr;} void set_length(); /** \brief Set the length attribute of an halfedge */ inline void set_length(double l) {length=l;} void set_prev_hf(LineTes::Halfedge_handle); void set_next_hf(LineTes::Halfedge_handle); void set_dir(); void set_dir(bool d); /** \brief Define the segment containing the halfedge */ inline void set_segment(LineTes::Seg_handle s){ segment_ptr = s;} /** \brief Test whether a halfedge starting a segment is also ending the * segment * \pre the halfedge handle should not be null. */ inline bool is_one_edge_segment(){ return next_hf==NULL_HALFEDGE_HANDLE; } private: double length; LineTes::Halfedge_handle next_hf; LineTes::Halfedge_handle prev_hf; bool dir; LineTes::Seg_handle segment_ptr; }; /******************************************************************************/ /* DEFINITIONS RELATED TO I/L-VERTEX PROCESSING */ /******************************************************************************/ /** \brief Data about removal of an I-vertex * * An I-vertex in a line tessellation may be removed either by removing its * incident edge or by lengthening it until it meets another tessellation * edge. */ struct IVertex { LineTes::Vertex_handle v; ///< handle of the I-vertex LineTes::Halfedge_handle e; ///< incident halfedge LineTes::Halfedge_handle esplit; ///< halfedge split by lengthening Point2 p; ///< location of new vertex added by lengthening double changed_length; ///< smallest length variation bool shorten; ///< true if smallest length variation due to shortening }; /** \brief Comparison of I-vertices based on length variation * \param v1 : data related to the first I-vertex. * \param v2 : data related to the second I-vertex. * \return true if first I-vertex removal induces a length change smaller than * the second I-vertex removal. */ inline bool compare_ivertices(IVertex v1,IVertex v2) { return v1.changed_length<v2.changed_length; } /******************************************************************************/ /* DEFINITION OF STRUCTURE ModList */ /******************************************************************************/ /** \brief Representation of a modification to be applied to a line tessellation * * The modification is represented by lists of deleted and new vertices, edges, * faces and segments. */ struct ModList { std::vector<Point2> del_vertices; ///< list of deleted vertices std::vector<Point2> add_vertices; ///< list of new vertices std::vector<Segment> del_edges; ///< list of deleted edges std::vector<Segment> add_edges; ///< list of new edges std::vector<Polygon> del_faces; ///< list of deleted faces std::vector<Polygon> add_faces; ///< list of new faces std::vector<std::vector<Point2> > del_segs; ///< list of deleted segments std::vector<std::vector<Point2> > add_segs; ///< list of new segments }; /******************************************************************************/ /* DEFINITION OF CLASS TTessel */ /******************************************************************************/ /** \brief Dynamic T-tessellation * * Possible updates are splits, merges and flips. */ class TTessel : public LineTes { public: /** \brief Abstract class representing a modification of a T-tessellation * * Concrete derived classes must implement the computation of * elements of the T-tessellation that are modified by the * modification. */ class Modification { public: virtual ModList modified_elements() ; }; /** \brief A split that can be applied to a T-tessellation * * A split is the division of a face by a line segment. * * A split is represented by a halfedge bounding the face to be * split, a relative position (between 0 and 1) along that halfedge * and an angle greater than zero and smaller than pi. The splitting * segment starts at the point lying on the halfedge at the given * relative position and makes the given angle with the halfedge. * * A split has several effects on tessellation elements: * - Two edges bounding the split face are split. * - Two vertices along these two edges are created. * - The split face is replaced by two faces. * - A new non-blocking segment is created. */ class Split : public Modification { public: Split(); Split(Halfedge_handle, double=.5,double=CGAL_PI/2); virtual ModList modified_elements(); /** \brief Return a handle to one of the split edges * * The other split edge can be accessed using Split::get_e2.*/ inline Halfedge_handle get_e1(){return e1;} /** \brief Get the location of the new vertex on one of the new edge * * The new vertex lies on the new edge returned by Split::get_e1*/ inline Point2 get_p1(){return p1;} /** \brief Return a handle to one of the split edges * * The other split edge can be accessed using Split::get_e1.*/ inline Halfedge_handle get_e2(){return e2;} /** \brief Get the location of the new vertex on one of the new edge * * The new vertex lies on the new edge returned by Split::get_e2*/ inline Point2 get_p2(){return p2;} bool is_valid(); private: Halfedge_handle e1; // Split edge Halfedge_handle e2; // Split edge Point2 p1; // New point on e1 Point2 p2; // New point on e2 }; /** \brief A merge that can be applied to a T-tessellation * * A merge is the removal of a non-blocking segment. The two faces * on both sides of the removed segment are merged. * * A merge is represented by the (half)edge to be removed. * * A merge has several effects on tessellation elements: * - Two vertices are removed. * - Two pairs of edges are merged. * - Two faces are replaced by a single one. * - A non-blocking segment is removed. * - The status (blocking or not) of segments incident to * the removed segment may change. */ class Merge : public Modification { public: Merge(); Merge(Halfedge_handle); virtual ModList modified_elements(); /** \brief Return a handle to the suppressed edge*/ inline Halfedge_handle get_e(){return e;} bool is_valid(); private: Halfedge_handle e; inline Halfedge_handle e1(){return e->twin()->next();} inline Halfedge_handle e2(){return e->next();} inline Point2 p1(){return e->source()->point();} inline Point2 p2(){return e->target()->point();} }; /** \brief A flip that can be applied to a T-tessellation * * A flip is represented by the halfedge at the end of a blocking * segment that is removed. */ class Flip : public Modification { public: Flip(); Flip(Halfedge_handle); virtual ModList modified_elements(); /** \brief Return a handle to the suppressed edge*/ inline Halfedge_handle get_e1(){return e1;} /** \brief Return a handle to the split edge*/ inline Halfedge_handle get_e2(){return e2;} /** \brief Return a handle to the new vertex*/ inline Point2 get_p2(){return p2;} private: Halfedge_handle e1; // Suppressed edge Halfedge_handle e2; // Split edge Point2 p2; // New vertex }; /** \typedef Split_list * \brief A list of splits*/ typedef std::vector<Split> Split_list; /** \typedef Merge_list * \brief A list of merges*/ typedef std::vector<Merge> Merge_list; /** \typedef Flip_list * \brief A list of flips*/ typedef std::vector<Flip> Flip_list; /** \typedef Split_list_iterator * \brief Iterator for accessing splits in a list*/ typedef Split_list::iterator Split_list_iterator; /** \typedef Merge_list_iterator * \brief Iterator for accessing merges in a list*/ typedef Merge_list::iterator Merge_list_iterator; /** \typedef Flip_list_iterator * \brief Iterator for accessing flips in a list*/ typedef Flip_list::iterator Flip_list_iterator; TTessel(); TTessel(LineTes&); virtual void insert_window(Rectangle); virtual void insert_window(Polygon&); Halfedge_handle update(Split); Face_handle update(Merge); Halfedge_handle update(Flip); void clear(); bool is_valid(bool verbose=false); Split propose_split(); Merge propose_merge(); Flip propose_flip(); Split_list split_sample(Size); Split_list poisson_splits(double); Merge_list all_merges(); Flip_list all_flips(); Size number_of_blocking_segments(); Size number_of_non_blocking_segments(); Seg_sublist_iterator blocking_segments_begin(); Seg_sublist_iterator blocking_segments_end(); Seg_sublist_iterator non_blocking_segments_begin(); Seg_sublist_iterator non_blocking_segments_end(); /** \brief Sum of all halfedge lengths * * The sum of halfedge lengths is equal to the sum of cell perimeters. */ inline double get_total_internal_length(){return int_length;} Polygons all_faces(); void print_blocking_segments(); void print_non_blocking_segments(); void printRCALI(std::ostream&); private: Seg_sublist blocking_segments; Seg_sublist non_blocking_segments; double int_length; Halfedge_handle random_halfedge(); inline double total_internal_length(){ /* Return the total length of halfedges bounding an internal face. */ return int_length; } Halfedge_handle length_weighted_random_halfedge(); Halfedge_handle alt_length_weighted_random_halfedge(); std::vector<Halfedge_handle> alt_length_weighted_random_halfedge(unsigned int); }; /******************************************************************************/ /* DEFINITION OF STRUCTURE CatItems */ /******************************************************************************/ /** \struct CatItems * \brief Storage structure for categorized items * * Item categories: vertices, edges, faces and segs. */ template <typename T> struct CatItems { std::vector<T> vertices; ///< a vector of T objects std::vector<T> edges; ///< a vector of T objects std::vector<T> faces; ///< a vector of T objects std::vector<T> segs; ///< a vector of T objects const CatItems<T>& operator+=(const CatItems<T> &); const CatItems<T>& operator-=(const CatItems<T> &); bool IsEmpty(); }; template <typename T> const CatItems<T> operator+(const CatItems<T> &, const CatItems<T> &); template <typename T> const CatItems<T> operator*(const double &, const CatItems<T> &); template <typename T> const CatItems<T> operator-(const CatItems<T> &, const CatItems<T> &); template <typename T> const CatItems<T> operator*(const CatItems<T> &, const CatItems<T> &); /** \brief Increment operator for CatItems objects */ template<typename T> const CatItems<T>& CatItems<T>::operator+=(const CatItems<T> &incr) { *this = (*this)+incr; return *this; } /** \brief Decrement operator for CatItems objects */ template<typename T> const CatItems<T>& CatItems<T>::operator-=(const CatItems<T> &decr) { *this += -1.0*decr; return *this; } /** \brief Addition operator for CatItems objects */ template<typename T> const CatItems<T> operator+(const CatItems<T> &x1, const CatItems<T> &x2) { CatItems<T> res = CatItems<T>(x1); for(unsigned int i=0; i!= x2.vertices.size(); i++) { res.vertices[i] += x2.vertices[i]; } for(unsigned int i=0; i!= x2.edges.size(); i++) { res.edges[i] += x2.edges[i]; } for(unsigned int i=0; i!= x2.faces.size(); i++) { res.faces[i] += x2.faces[i]; } for(unsigned int i=0; i!= x2.segs.size(); i++) { res.segs[i] += x2.segs[i]; } return res; } /** \brief Product of a CatItems object with a scalar */ template<typename T> const CatItems<T> operator*(const double &scalar, const CatItems<T> &x) { CatItems<T> res = CatItems<T>(x); for(unsigned int i=0; i!= x.vertices.size(); i++) { res.vertices[i] = scalar*res.vertices[i]; } for(unsigned int i=0; i!= x.edges.size(); i++) { res.edges[i] = scalar*res.edges[i]; } for(unsigned int i=0; i!= x.faces.size(); i++) { res.faces[i] = scalar*res.faces[i]; } for(unsigned int i=0; i!= x.segs.size(); i++) { res.segs[i] = scalar*res.segs[i]; } return res; } /** \brief Subtraction of two CatItems objects */ template<typename T> const CatItems<T> operator-(const CatItems<T>& x1, const CatItems<T>& x2) { CatItems<T> res = x1+(-1.0*x2); return res; } /** \brief Term by term product of CatItems objects */ template<typename T> const CatItems<T> operator*(const CatItems<T> &x1, const CatItems<T> &x2) { CatItems<T> res = CatItems<T>(x1); for(unsigned int i=0; i!= x2.vertices.size(); i++) { res.vertices[i] *= x2.vertices[i]; } for(unsigned int i=0; i!= x2.edges.size(); i++) { res.edges[i] *= x2.edges[i]; } for(unsigned int i=0; i!= x2.faces.size(); i++) { res.faces[i] *= x2.faces[i]; } for(unsigned int i=0; i!= x2.segs.size(); i++) { res.segs[i] *= x2.segs[i]; } return res; } /** \typedef CatVector * \brief Storage structure for vector of doubles associated with categories * vertices, edges, faces or segs.*/ typedef CatItems<double> CatVector; void fill(CatVector&,FVector&); // Don't know how to specify standard user-defined conversion for CatVector :-( std::vector<double> asVectorOfDoubles(const CatVector&); FVector asFVector(const CatVector&); std::ostream& operator<<(std::ostream &, const CatVector &); double sum(const CatVector &); /** \typedef CatMatrix * \brief Storage structure for matrices (vector of vectors) of doubles * associated with categories vertices, edges, faces or segs.*/ typedef CatItems<CatVector> CatMatrix; FMatrix asFMatrix(const CatMatrix&); CatMatrix outer(const CatVector &, const CatVector &); /******************************************************************************/ /* DEFINITION OF STRUCTURE Features */ /******************************************************************************/ /** \brief Set of vertex, edge, face and segment features*/ struct Features { std::vector<double (*)(Point2,TTessel*)> vertices;///< vertex features (vector of functions) std::vector<double (*)(Segment,TTessel*)> edges;///< edge features std::vector<double (*)(Polygon,TTessel*)> faces;///< face featuress std::vector<double (*)(std::vector<Point2>,TTessel*)> segs;///< segment features }; /******************************************************************************/ /* DEFINITION OF CLASS Energy */ /******************************************************************************/ /** \brief Energy of a Gibbsian random T-tessellation * * The energy must have the following form: * \f[ * \sum_i \theta_i \phi_i(T) * \f] * where the \f$\theta_i\f$'s are real-valued parameters and the * \f$\phi_i\f$'s are statistics of the type * \f[ * \phi_i(T) = \sum_x f_i(x) * \f] * where the sum runs over all vertices, or all edges, or all faces, or all * segments of the T-tessellation. */ class Energy{ public: Energy(); /** \brief Return the pointer to the associated TTessel object */ inline TTessel* get_ttessel(){return ttes;} /** \brief Return the current value of the energy for the associated T-tessellation */ inline double get_value(){return value;} /** \brief Return the theta parameter */ inline CatVector get_theta(){return theta;} /** \brief Set the theta parameter */ inline void set_theta(CatVector par){theta = par;} /** \brief Increment the current value of the energy */ inline void add_value(double delta){value +=delta;} /** Associate the model with a T-tessellation */ void set_ttessel(TTessel*); double variation(TTessel::Modification&); CatVector statistic_variation(TTessel::Modification&); void add_theta_vertices(double); void add_theta_edges(double); void add_theta_faces(double); void add_theta_segs(double); void del_theta_vertices(); void del_theta_edges(); void del_theta_faces(); void del_theta_segs(); void add_features_vertices(double (*)(Point2,TTessel*)); void add_features_edges(double (*)(Segment,TTessel*)); void add_features_faces(double (*)(Polygon,TTessel*) ); void add_features_segs(double (*)(std::vector<Point2>,TTessel*) ); void del_features_vertices(); void del_features_edges(); void del_features_faces(); void del_features_segs(); private: TTessel* ttes; CatVector theta; Features features; double value; }; /******************************************************************************/ /* DEFINITION OF STRUCTURE ModifCounts */ /******************************************************************************/ /** \brief Data summarizing changes occuring through SMF iterations*/ struct ModifCounts { int proposed_S; ///< number of proposed splits int accepted_S; ///< number of accepted splits int proposed_M; ///< number of proposed merges int accepted_M; ///< number of accepted merges int proposed_F; ///< number of proposed flips int accepted_F; ///< number of accepted flips }; /******************************************************************************/ /* DEFINITION OF CLASS SMFChain */ /******************************************************************************/ /** \brief Markovian T-tessellation * * Updates are splits, merges and flips. Transitions ruled according a Metropolis-Hastings-Green construction. */ class SMFChain { public: SMFChain() {}; SMFChain(Energy *,double, double); /** \brief Set the energy function of the model to be simulated */ inline void set_energy(Energy *e) {engy = e;}; /** \brief Get the energy function of the model to be simulated */ inline Energy* get_energy() {return engy;}; void set_smf_prob(double,double); /** \enum ModType * \brief Types of modifications applicable to a T-tessellation*/ enum ModType { SPLIT = 1,///< split (of a face) MERGE ,///< merge (of two faces separated by a non-blocking segment) FLIP ///< a segment is shortened, another one is lengthened }; ModType propose_modif_type(); double Hasting_ratio(TTessel::Split&,double*); double Hasting_ratio(TTessel::Merge&,double*); double Hasting_ratio(TTessel::Flip&,double*); ModifCounts step(unsigned long int=1); private: Energy *engy; double p_split; double p_merge; double p_flip; double p_split_merge; }; /******************************************************************************/ /* DEFINITION OF CLASS PseudoLikDiscrete */ /******************************************************************************/ /** \brief Discrete approximation of the log-pseudolikelihood of a Gibbsian T-tessellation * * The Gibbs model to be considered is stored in a private data member as an * Energy object. The pseudolikelihood involves an integral over the space * of splits that can be applied to the observed T-tessellation. The discrete * approximation consists in replacing the integral by a discrete sum computed * on a sample of dummy splits. Dummy splits are drawn independently and * uniformly. */ class PseudoLikDiscrete { public: PseudoLikDiscrete() {}; PseudoLikDiscrete(Energy*); /** \brief Get the Energy data member */ inline Energy* GetEnergy() {return engy;}; /** \brief Set the Energy data member */ inline void SetEnergy(Energy *e) {engy = e;}; void AddSplits(Size); void AddGivenSplit(TTessel::Split); // only for debugging? /** \brief Return the split term of the discrete approximation of * the log-pseudolikelihood*/ inline std::vector<CatVector> GetSplitStatistics() {return stat_splits;}; /** \brief Return the flip term of the discrete approximation of * the log-pseudolikelihood*/ inline std::vector<CatVector> GetFlipStatistics() {return stat_flips;}; void ClearSplits(); double GetValue(CatVector); CatVector GetGradient(CatVector); CatMatrix GetHessian(CatVector); friend std::ostream& operator<<(std::ostream &, const PseudoLikDiscrete &); private: // data members Energy *engy; CatVector sum_stat_merges; CatVector sum_stat_flips; std::vector<CatVector> stat_splits; std::vector<CatVector> stat_flips; // method members }; /******************************************************************************/ /* DEFINITION OF CLASS PLInferenceNOIS */ /******************************************************************************/ /** \brief Pseudo-likelihood inference of a Gibsian T-tessellation with alternate updates * * Numerical maximization of the pseudo-likelihood. Each step consists of a * double update. First, dummy splits are added to the discrete approximation * of the pseudo-likelihood (see class PseudoLikDiscrete). Second, the current * parameter estimate is updated according to Newton's method based on the * Hessian of the approximated pseudo-likelihood. */ class PLInferenceNOIS : public PseudoLikDiscrete{ public: PLInferenceNOIS(Energy*,bool=false,double=1.0); /** \brief Return step size used in Newton's method */ inline double GetStepSize() {return stepsize;}; /** \brief Set step size used in Newton's method */ inline void SetStepSize(double lambda) { stepsize = lambda;}; void Step(unsigned int=1); CatVector GetEstimate(); unsigned int Run(double=0.05, unsigned int=100); /** \brief Return all intermediate parameter estimates */ inline std::vector<CatVector> GetEstimates() {return estimates;}; /** \brief Return all intermediate log-pseudolikelihood values */ inline std::vector<double> GetValues() {return values;}; private: double stepsize; /** Stepsize to be used for Newton's method.*/ CatVector previous_theta; /** Estimate at previous step. Data * used for computing the step size.*/ double previous_lpl; /** Log-pseudolikelihood at previous step. * Data used for the stopping criterion. */ bool store_path; /** If true, intermediate estimates and * values of the log-pseudolikelihood are * stored.*/ std::vector<CatVector> estimates; /** For storing intermediate estimates.*/ std::vector<double> values; /** For storing intermediate values of the * log-pseudolikelihood.*/ }; /******************************************************************************/ /* FUNCTION DECLARATIONS */ /******************************************************************************/ bool are_aligned(Point2 p, Point2 q, Point2 r, bool verbose=false); Segment clip_segment_by_convex_polygon(Segment, Polygon); double precompute_lengthening(Arrangement::Halfedge_handle, Arrangement::Halfedge_handle*, Point2*); bool exist_halfedge(LineTes&,LineTes::Halfedge_handle); LineTes::Halfedge_handle compute_prev_hf(LineTes::Halfedge_handle); LineTes::Halfedge_handle compute_next_hf(LineTes::Halfedge_handle); void set_junction(LineTes::Halfedge_handle,LineTes::Halfedge_handle); LineTes::Halfedge_handle find_halfedge(LineTes&,Point2,Point2); bool is_a_T_vertex(LineTes::Vertex_handle, bool verbose=false); unsigned long int number_of_internal_vertices(TTessel&); Polygon face2poly(TTessel::Face_handle); /** \defgroup features Features of T-tessellations * * Functions that can be used by Energy objects for defining a Gibbs model * of T-tessellation. %Features are measured on vertices, edges, faces * or segments.*/ double face_number(Polygon,TTessel*); double face_area_2(Polygon,TTessel*); double face_sum_of_angles(Polygon,TTessel*); double face_shape(Polygon,TTessel*); double angle_between_vectors(Vector v1,Vector v2); double edge_length(Segment,TTessel*); double is_point_inside_window(Point2, LineTes*); double is_point_inside_window(Point2, TTessel*); double seg_number(std::vector<Point2>,TTessel*); double is_segment_internal(std::vector<Point2>,TTessel*); /** \brief Return -1 * * \param s : a tessellation segment as a vector of its 2 ends. * \param t : the tessellation to be considered. * * Silly function that can be used by an Energy object for specifying * minus the number of segment as a tessellation feature.*/ inline double minus_is_segment_internal(std::vector<Point2> s, TTessel* t){ return -is_segment_internal(s,t);} double min_angle(Polygon, TTessel*); double sum_of_faces_squared_areas(TTessel*); double sum_of_min_angles(TTessel*); double sum_of_angles_obt(TTessel*); double segment_size_2(std::vector<Point2>,TTessel*); double sum_of_segment_squared_sizes(TTessel* t); /* FONCTIONS POUR CHRONOMETRER */ //inline std::clock_t tic(void){return std::clock();} //inline std::clock_t toc(std::clock_t start){return std::clock()-start;} //inline double ticks2sec(std::clock_t nticks){return 1.0*nticks/CLOCKS_PER_SEC;}
26 n'est implémentée.*/
27 #include <CGAL/Lazy_exact_nt.h>
28 #include <CGAL/Linear_algebraCd.h>
29 #include <CGAL/double.h>
30 #include <CGAL/Arr_segment_traits_2.h>
31 #include <CGAL/Arr_default_dcel.h>
32 #include <CGAL/Arrangement_2.h>
33 #include <CGAL/IO/Arr_iostream.h>
34 #include <CGAL/Arr_walk_along_line_point_location.h>
35 #include <CGAL/Arr_naive_point_location.h>
36 #include <CGAL/Polygon_2.h>
37 #include <CGAL/Polygon_2_algorithms.h>
38 #include <CGAL/intersections.h>
39 #include <CGAL/Bbox_2.h>
40 #include <CGAL/Random.h>
41 // Two following headers required for clip_segment_by_convex_polygon
42 #include <CGAL/Extended_cartesian.h>
43 #include <CGAL/Nef_polyhedron_2.h>
44 
45 
46 
47 /******************************************************************************/
48 /* TYPE DEFINITIONS AND FORWARD CLASS DECLARATIONS */
49 /******************************************************************************/
52 typedef CGAL::Lazy_exact_nt<CGAL::Gmpq> NT;
55 typedef CGAL::Cartesian<NT> Kernel;
59 typedef CGAL::Arr_segment_traits_2<Kernel> Traits;
62 typedef CGAL::Vector_2<Kernel> Vector;
65 typedef Traits::Point_2 Point2;
68 typedef Traits::Segment_2 Segment;
72 typedef Traits::X_monotone_curve_2 Curve;
75 typedef CGAL::Iso_rectangle_2<Kernel> Rectangle;
78 typedef CGAL::Line_2<Kernel> Line;
81 typedef CGAL::Ray_2<Kernel> Rayon;
84 typedef CGAL::Direction_2<Kernel> Direction;
87 typedef CGAL::Aff_transformation_2<Kernel> Transformation;
90 typedef CGAL::Polygon_2<Kernel> Polygon;
93 typedef std::vector<Point2> Points;
99 typedef CGAL::Linear_algebraCd<double> LA;
106 typedef LA::Matrix FMatrix;
107 
108 class LineTes_halfedge; // forward declaration
109 
114 typedef CGAL::Arr_dcel_base<CGAL::Arr_vertex_base<Point2>,
116  CGAL::Arr_face_base> Dcel;
119 typedef CGAL::Arrangement_2<Traits,Dcel> Arrangement;
122 typedef Dcel::Size Size;
123 
128 extern CGAL::Random *rnd; // variable globale
129 
130 // definition that prevent type expansion in the documentation generated by Rcpp
131 class Polygons : public std::vector<Polygon> {};
132 
133 /******************************************************************************/
134 /* DÉFINITION DE LA CLASSE LineTes */
135 /******************************************************************************/
136 
146 class LineTes : public Arrangement {
147 
148  public:
149 
157  class Seg {
158  public:
159  Seg();
160  Seg(Halfedge_handle);
161  Halfedge_handle halfedges_start();
162  Halfedge_handle halfedges_end();
164  bool number_of_edges_is_greater_than(unsigned int);
169  inline Halfedge_handle get_halfedge_handle(){return e;}
170  void set_halfedge_handle(Halfedge_handle);
171  void print(bool endsOnly=false);
172  private:
173  Halfedge_handle e;
174  Size or_idx;
175  };
176 
179  typedef Seg* Seg_handle;
180 
187  class Seg_list : public std::vector<Seg_handle> {
188  public:
190  inline void add(Seg_handle s) { push_back(s);}
197  inline bool suppress(Seg_handle s){
198  iterator ou_s = std::find(begin(),end(),s);
199  if (ou_s==end()) {
200  std::clog << "LineTes::Seg_list::suppress : item to suppress not found"
201  << std::endl;
202  return false;
203  }
204  erase(ou_s);
205  delete s;
206  return true;
207  }
208  };
213  class Seg_sublist : public std::vector<Seg_handle> {
214  public:
216  inline void add(Seg_handle s) { push_back(s);}
223  inline bool suppress(Seg_handle s ){
224  iterator ou_s = std::find(begin(),end(),s);
225  if (ou_s==end()) {
226  std::clog << "LineTes::Seg_sublist::suppress : item to suppress not found"
227  << std::endl;
228  return false;
229  }
230  erase(ou_s);
231  return true;
232  }
233  };
236  typedef Seg_list::iterator Seg_list_iterator;
239  typedef Seg_sublist::iterator Seg_sublist_iterator;
240 
241  LineTes();
242 
243  virtual void insert_window(Rectangle);
244  virtual void insert_window(Polygon&);
245  Halfedge_handle split_from_edge(Halfedge_handle, Point2,
246  Halfedge_handle, Point2);
247  Halfedge_handle split_from_vertex(Vertex_handle, Halfedge_handle,
248  Point2);
249  Face_handle suppress_edge(Halfedge_handle);
250  void clear();
254  inline Seg_list_iterator segments_begin(){return all_segments.begin();}
258  inline Seg_list_iterator segments_end(){return all_segments.end();}
263  inline Size number_of_segments(){return all_segments.size();}
264  bool is_valid(bool verbose=false);
265  bool check_all_segments(bool verbose=false);
266  bool check_segment(Seg_handle s, bool verbose=false);
267  bool check_all_halfedges(bool verbose=false);
268  bool check_halfedge(LineTes::Halfedge_handle e,
269  bool verbose=false);
270  bool halfedge_exists(LineTes::Halfedge_handle);
271  bool check_halfedge_neighbours(LineTes::Halfedge_handle e,
272  bool verbose=false);
273  bool check_halfedge_prev_hf(LineTes::Halfedge_handle e,
274  bool verbose=false);
275  bool check_halfedge_next_hf(LineTes::Halfedge_handle e,
276  bool verbose=false);
277  bool check_halfedge_segment(LineTes::Halfedge_handle e,
278  bool verbose=false);
279  bool check_halfedge_dir(LineTes::Halfedge_handle e,
280  bool verbose=false);
281  void print_all_segments(bool endsOnly=false);
284  inline Polygon get_window(){return window;}
286  double get_window_perimeter();
287  int is_on_boundary(Halfedge_handle);
294  void remove_ivertices(Size imax=0,
295  bool verbose=false);
296  void remove_lvertices(Size imax=0,
297  bool verbose=false);
298  bool is_a_T_tessellation(bool verbose=false,
299  std::ostream& out=std::clog);
300  void write(std::ostream&);
301  void read(std::istream&);
302 
303 private:
304  Polygon window;
305  Seg_list all_segments;
306  Halfedge_handle split_edge(Halfedge_handle,X_monotone_curve_2,
307  X_monotone_curve_2);
308  Halfedge_handle merge_edge(Halfedge_handle, Halfedge_handle,
309  X_monotone_curve_2);
310  Halfedge_handle add_edge(X_monotone_curve_2,Vertex_handle,
311  Vertex_handle);
312  Face_handle remove_edge(Halfedge_handle);
313 };
314 
315 /* Variables globales declarées avant leur utilisation */
316 
318 extern LineTes::Halfedge_handle NULL_HALFEDGE_HANDLE;
320 extern LineTes::Face_handle NULL_FACE_HANDLE;
323 
324 /******************************************************************************/
325 /* DÉFINITION DE LA CLASSE LineTes_halfedge */
326 /******************************************************************************/
327 
338 class LineTes_halfedge : public CGAL::Arr_halfedge_base<Curve> {
339 public:
343  inline LineTes::Halfedge_handle get_prev_hf() {return prev_hf;}
346  inline LineTes::Halfedge_handle get_next_hf() {return next_hf;}
351  inline bool get_dir() {return dir;}
354  inline double get_length() {return length;}
357  inline LineTes::Seg_handle get_segment() {return segment_ptr;}
361  inline LineTes::Seg_handle segment(){return segment_ptr;}
362  void set_length();
365  inline void set_length(double l) {length=l;}
366  void set_prev_hf(LineTes::Halfedge_handle);
367  void set_next_hf(LineTes::Halfedge_handle);
368  void set_dir();
369  void set_dir(bool d);
373  segment_ptr = s;}
378  inline bool is_one_edge_segment(){
379  return next_hf==NULL_HALFEDGE_HANDLE;
380  }
381  private:
382  double length;
383  LineTes::Halfedge_handle next_hf;
384  LineTes::Halfedge_handle prev_hf;
385  bool dir;
386  LineTes::Seg_handle segment_ptr;
387 };
388 
389 /******************************************************************************/
390 /* DEFINITIONS RELATED TO I/L-VERTEX PROCESSING */
391 /******************************************************************************/
398 struct IVertex {
399  LineTes::Vertex_handle v;
400  LineTes::Halfedge_handle e;
401  LineTes::Halfedge_handle esplit;
403  double changed_length;
404  bool shorten;
405 };
412 inline bool compare_ivertices(IVertex v1,IVertex v2) {
413  return v1.changed_length<v2.changed_length;
414 }
415 
416 
417 /******************************************************************************/
418 /* DEFINITION OF STRUCTURE ModList */
419 /******************************************************************************/
420 
426 struct ModList {
427  std::vector<Point2> del_vertices;
428  std::vector<Point2> add_vertices;
429  std::vector<Segment> del_edges;
430  std::vector<Segment> add_edges;
431  std::vector<Polygon> del_faces;
432  std::vector<Polygon> add_faces;
433  std::vector<std::vector<Point2> > del_segs;
434  std::vector<std::vector<Point2> > add_segs;
435 };
436 
437 /******************************************************************************/
438 /* DEFINITION OF CLASS TTessel */
439 /******************************************************************************/
440 
445 class TTessel : public LineTes {
446 
447 public:
454  class Modification {
455  public:
456  virtual ModList modified_elements() ;
457  };
474  class Split : public Modification {
475  public:
476  Split();
477  Split(Halfedge_handle, double=.5,double=CGAL_PI/2);
478  virtual ModList modified_elements();
482  inline Halfedge_handle get_e1(){return e1;}
486  inline Point2 get_p1(){return p1;}
490  inline Halfedge_handle get_e2(){return e2;}
494  inline Point2 get_p2(){return p2;}
495  bool is_valid();
496  private:
497  Halfedge_handle e1; // Split edge
498  Halfedge_handle e2; // Split edge
499  Point2 p1; // New point on e1
500  Point2 p2; // New point on e2
501  };
517  class Merge : public Modification {
518  public:
519  Merge();
520  Merge(Halfedge_handle);
521  virtual ModList modified_elements();
523  inline Halfedge_handle get_e(){return e;}
524  bool is_valid();
525  private:
526  Halfedge_handle e;
527  inline Halfedge_handle e1(){return e->twin()->next();}
528  inline Halfedge_handle e2(){return e->next();}
529  inline Point2 p1(){return e->source()->point();}
530  inline Point2 p2(){return e->target()->point();}
531 
532  };
538  class Flip : public Modification {
539  public:
540  Flip();
541  Flip(Halfedge_handle);
542  virtual ModList modified_elements();
544  inline Halfedge_handle get_e1(){return e1;}
546  inline Halfedge_handle get_e2(){return e2;}
548  inline Point2 get_p2(){return p2;}
549  private:
550  Halfedge_handle e1; // Suppressed edge
551  Halfedge_handle e2; // Split edge
552  Point2 p2; // New vertex
553  };
554 
557  typedef std::vector<Split> Split_list;
560  typedef std::vector<Merge> Merge_list;
563  typedef std::vector<Flip> Flip_list;
566  typedef Split_list::iterator Split_list_iterator;
569  typedef Merge_list::iterator Merge_list_iterator;
572  typedef Flip_list::iterator Flip_list_iterator;
573 
574  TTessel();
575  TTessel(LineTes&);
576  virtual void insert_window(Rectangle);
577  virtual void insert_window(Polygon&);
578  Halfedge_handle update(Split);
579  Face_handle update(Merge);
580  Halfedge_handle update(Flip);
581  void clear();
582  bool is_valid(bool verbose=false);
585  Flip propose_flip();
587  Split_list poisson_splits(double);
600  inline double get_total_internal_length(){return int_length;}
604  void printRCALI(std::ostream&);
605 private:
606  Seg_sublist blocking_segments;
607  Seg_sublist non_blocking_segments;
608  double int_length;
609  Halfedge_handle random_halfedge();
610  inline double total_internal_length(){
611  /* Return the total length of halfedges bounding an internal face. */
612  return int_length;
613  }
614  Halfedge_handle length_weighted_random_halfedge();
615  Halfedge_handle alt_length_weighted_random_halfedge();
616  std::vector<Halfedge_handle> alt_length_weighted_random_halfedge(unsigned int);
617 };
618 
619 /******************************************************************************/
620 /* DEFINITION OF STRUCTURE CatItems */
621 /******************************************************************************/
622 
628 template <typename T>
629 struct CatItems {
630  std::vector<T> vertices;
631  std::vector<T> edges;
632  std::vector<T> faces;
633  std::vector<T> segs;
634  const CatItems<T>& operator+=(const CatItems<T> &);
635  const CatItems<T>& operator-=(const CatItems<T> &);
636  bool IsEmpty();
637 };
638 template <typename T>
639 const CatItems<T> operator+(const CatItems<T> &, const CatItems<T> &);
640 template <typename T>
641 const CatItems<T> operator*(const double &, const CatItems<T> &);
642 template <typename T>
643 const CatItems<T> operator-(const CatItems<T> &, const CatItems<T> &);
644 template <typename T>
645 const CatItems<T> operator*(const CatItems<T> &, const CatItems<T> &);
646 
649 template<typename T>
651  *this = (*this)+incr;
652  return *this;
653 }
654 
657 template<typename T>
659  *this += -1.0*decr;
660  return *this;
661 }
662 
665 template<typename T>
667  const CatItems<T> &x2) {
668  CatItems<T> res = CatItems<T>(x1);
669  for(unsigned int i=0; i!= x2.vertices.size(); i++) {
670  res.vertices[i] += x2.vertices[i];
671  }
672  for(unsigned int i=0; i!= x2.edges.size(); i++) {
673  res.edges[i] += x2.edges[i];
674  }
675  for(unsigned int i=0; i!= x2.faces.size(); i++) {
676  res.faces[i] += x2.faces[i];
677  }
678  for(unsigned int i=0; i!= x2.segs.size(); i++) {
679  res.segs[i] += x2.segs[i];
680  }
681  return res;
682 }
683 
686 template<typename T>
687 const CatItems<T> operator*(const double &scalar, const CatItems<T> &x) {
688  CatItems<T> res = CatItems<T>(x);
689  for(unsigned int i=0; i!= x.vertices.size(); i++) {
690  res.vertices[i] = scalar*res.vertices[i];
691  }
692  for(unsigned int i=0; i!= x.edges.size(); i++) {
693  res.edges[i] = scalar*res.edges[i];
694  }
695  for(unsigned int i=0; i!= x.faces.size(); i++) {
696  res.faces[i] = scalar*res.faces[i];
697  }
698  for(unsigned int i=0; i!= x.segs.size(); i++) {
699  res.segs[i] = scalar*res.segs[i];
700  }
701  return res;
702 }
703 
706 template<typename T>
707 const CatItems<T> operator-(const CatItems<T>& x1, const CatItems<T>& x2) {
708  CatItems<T> res = x1+(-1.0*x2);
709  return res;
710 }
711 
714 template<typename T>
716  const CatItems<T> &x2) {
717  CatItems<T> res = CatItems<T>(x1);
718  for(unsigned int i=0; i!= x2.vertices.size(); i++) {
719  res.vertices[i] *= x2.vertices[i];
720  }
721  for(unsigned int i=0; i!= x2.edges.size(); i++) {
722  res.edges[i] *= x2.edges[i];
723  }
724  for(unsigned int i=0; i!= x2.faces.size(); i++) {
725  res.faces[i] *= x2.faces[i];
726  }
727  for(unsigned int i=0; i!= x2.segs.size(); i++) {
728  res.segs[i] *= x2.segs[i];
729  }
730  return res;
731 }
732 
737 void fill(CatVector&,FVector&);
738 // Don't know how to specify standard user-defined conversion for CatVector :-(
739 std::vector<double> asVectorOfDoubles(const CatVector&);
740 FVector asFVector(const CatVector&);
741 std::ostream& operator<<(std::ostream &, const CatVector &);
742 double sum(const CatVector &);
747 FMatrix asFMatrix(const CatMatrix&);
748 CatMatrix outer(const CatVector &, const CatVector &);
749 
750 /******************************************************************************/
751 /* DEFINITION OF STRUCTURE Features */
752 /******************************************************************************/
754 struct Features {
755  std::vector<double (*)(Point2,TTessel*)> vertices;
756  std::vector<double (*)(Segment,TTessel*)> edges;
757  std::vector<double (*)(Polygon,TTessel*)> faces;
758  std::vector<double (*)(std::vector<Point2>,TTessel*)> segs;
759 };
760 
761 
762 
763 /******************************************************************************/
764 /* DEFINITION OF CLASS Energy */
765 /******************************************************************************/
766 
781 class Energy{
782 
783 public:
784 
785  Energy();
787  inline TTessel* get_ttessel(){return ttes;}
790  inline double get_value(){return value;}
792  inline CatVector get_theta(){return theta;}
794  inline void set_theta(CatVector par){theta = par;}
796  inline void add_value(double delta){value +=delta;}
798  void set_ttessel(TTessel*);
801  void add_theta_vertices(double);
802  void add_theta_edges(double);
803  void add_theta_faces(double);
804  void add_theta_segs(double);
805  void del_theta_vertices();
806  void del_theta_edges();
807  void del_theta_faces();
808  void del_theta_segs();
809  void add_features_vertices(double (*)(Point2,TTessel*));
810  void add_features_edges(double (*)(Segment,TTessel*));
811  void add_features_faces(double (*)(Polygon,TTessel*) );
812  void add_features_segs(double (*)(std::vector<Point2>,TTessel*) );
813  void del_features_vertices();
814  void del_features_edges();
815  void del_features_faces();
816  void del_features_segs();
817 
818 private:
819  TTessel* ttes;
820  CatVector theta;
821  Features features;
822  double value;
823 };
824 
825 
826 /******************************************************************************/
827 /* DEFINITION OF STRUCTURE ModifCounts */
828 /******************************************************************************/
830 struct ModifCounts {
837 };
838 
839 
840 
841 /******************************************************************************/
842 /* DEFINITION OF CLASS SMFChain */
843 /******************************************************************************/
844 
849 class SMFChain {
850 public:
851  SMFChain() {};
852  SMFChain(Energy *,double, double);
855  inline void set_energy(Energy *e) {engy = e;};
858  inline Energy* get_energy() {return engy;};
859  void set_smf_prob(double,double);
862  enum ModType {
863  SPLIT = 1,
866  };
868  double Hasting_ratio(TTessel::Split&,double*);
869  double Hasting_ratio(TTessel::Merge&,double*);
870  double Hasting_ratio(TTessel::Flip&,double*);
871  ModifCounts step(unsigned long int=1);
872 private:
873  Energy *engy;
874  double p_split;
875  double p_merge;
876  double p_flip;
877  double p_split_merge;
878 };
879 
880 /******************************************************************************/
881 /* DEFINITION OF CLASS PseudoLikDiscrete */
882 /******************************************************************************/
893  public:
894  PseudoLikDiscrete() {};
898  inline Energy* GetEnergy() {return engy;};
901  inline void SetEnergy(Energy *e) {engy = e;};
902  void AddSplits(Size);
903  void AddGivenSplit(TTessel::Split); // only for debugging?
906  inline std::vector<CatVector> GetSplitStatistics() {return stat_splits;};
909  inline std::vector<CatVector> GetFlipStatistics() {return stat_flips;};
910  void ClearSplits();
911  double GetValue(CatVector);
912  CatVector GetGradient(CatVector);
913  CatMatrix GetHessian(CatVector);
914  friend std::ostream& operator<<(std::ostream &, const PseudoLikDiscrete &);
915  private:
916  // data members
917  Energy *engy;
918  CatVector sum_stat_merges;
919  CatVector sum_stat_flips;
920  std::vector<CatVector> stat_splits;
921  std::vector<CatVector> stat_flips;
922  // method members
923 };
924 
925 /******************************************************************************/
926 /* DEFINITION OF CLASS PLInferenceNOIS */
927 /******************************************************************************/
928 
938  public:
939  PLInferenceNOIS(Energy*,bool=false,double=1.0);
941  inline double GetStepSize() {return stepsize;};
943  inline void SetStepSize(double lambda) { stepsize = lambda;};
944  void Step(unsigned int=1);
945  CatVector GetEstimate();
946  unsigned int Run(double=0.05, unsigned int=100);
949  inline std::vector<CatVector> GetEstimates() {return estimates;};
952  inline std::vector<double> GetValues() {return values;};
953  private:
954  double stepsize;
955  CatVector previous_theta;
957  double previous_lpl;
960  bool store_path;
963  std::vector<CatVector> estimates;
964  std::vector<double> values;
966 };
967 
968 /******************************************************************************/
969 /* FUNCTION DECLARATIONS */
970 /******************************************************************************/
971 
972 bool are_aligned(Point2 p, Point2 q, Point2 r,
973  bool verbose=false);
975 double precompute_lengthening(Arrangement::Halfedge_handle,
976  Arrangement::Halfedge_handle*,
977  Point2*);
978 bool exist_halfedge(LineTes&,LineTes::Halfedge_handle);
979 LineTes::Halfedge_handle compute_prev_hf(LineTes::Halfedge_handle);
980 LineTes::Halfedge_handle compute_next_hf(LineTes::Halfedge_handle);
981 void set_junction(LineTes::Halfedge_handle,LineTes::Halfedge_handle);
982 LineTes::Halfedge_handle find_halfedge(LineTes&,Point2,Point2);
983 bool is_a_T_vertex(LineTes::Vertex_handle,
984  bool verbose=false);
985 unsigned long int number_of_internal_vertices(TTessel&);
986 Polygon face2poly(TTessel::Face_handle);
992 double face_number(Polygon,TTessel*);
993 double face_area_2(Polygon,TTessel*);
995 double face_shape(Polygon,TTessel*);
996 double angle_between_vectors(Vector v1,Vector v2);
997 double edge_length(Segment,TTessel*);
1000 double seg_number(std::vector<Point2>,TTessel*);
1001 double is_segment_internal(std::vector<Point2>,TTessel*);
1009 inline double minus_is_segment_internal(std::vector<Point2> s,
1010  TTessel* t){
1011  return -is_segment_internal(s,t);}
1012 double min_angle(Polygon, TTessel*);
1014 double sum_of_min_angles(TTessel*);
1015 double sum_of_angles_obt(TTessel*);
1016 double segment_size_2(std::vector<Point2>,TTessel*);
1018 
1019 /* FONCTIONS POUR CHRONOMETRER */
1020 //inline std::clock_t tic(void){return std::clock();}
1021 //inline std::clock_t toc(std::clock_t start){return std::clock()-start;}
1022 //inline double ticks2sec(std::clock_t nticks){return 1.0*nticks/CLOCKS_PER_SEC;}
Markovian T-tessellation.
Definition: ttessel.h:849
Split()
Default constructor that creates an empty Split object.
Definition: ttessel.cpp:1889
void set_segment(LineTes::Seg_handle s)
Define the segment containing the halfedge.
Definition: ttessel.h:372
void read(std::istream &)
Read a LineTes object from an input stream.
Definition: ttessel.cpp:1205
CatVector GetEstimate()
Access to the current parameter estimate.
Definition: ttessel.cpp:3265
void del_features_segs()
Remove all segment features from the energy formula.
Definition: ttessel.cpp:2848
Halfedge_handle get_e()
Return a handle to the suppressed edge.
Definition: ttessel.h:523
bool get_dir()
Test halfedge direction against the segment direction.
Definition: ttessel.h:351
LineTes::Halfedge_handle e
incident halfedge
Definition: ttessel.h:400
std::vector< double(*)(Point2, TTessel *)> vertices
vertex features (vector of functions)
Definition: ttessel.h:755
Representation of a modification to be applied to a line tessellation.
Definition: ttessel.h:426
Polygon get_window()
Return the domain that is tessellated.
Definition: ttessel.h:284
Storage structure for categorized items.
Definition: ttessel.h:629
LineTes::Halfedge_handle get_next_hf()
Return next halfedge along the segment.
Definition: ttessel.h:346
double GetValue(CatVector)
Return log-pseudo-likelihood value.
Definition: ttessel.cpp:3126
std::vector< double > GetValues()
Return all intermediate log-pseudolikelihood values.
Definition: ttessel.h:952
double get_window_perimeter()
Return the perimeter of the tessellated domain.
Definition: ttessel.cpp:477
std::vector< T > edges
a vector of T objects
Definition: ttessel.h:631
Segment in a line tessellation.
Definition: ttessel.h:157
bool is_valid()
Check a split is valid.
Definition: ttessel.cpp:2054
void print(bool endsOnly=false)
Print on standard output the segment points.
Definition: ttessel.cpp:791
bool is_valid(bool verbose=false)
Check whether the LineTes object is valid.
Definition: ttessel.cpp:239
bool are_aligned(Point2 p, Point2 q, Point2 r, bool verbose=false)
Test whether three points are aligned.
Definition: ttessel.cpp:3313
void AddGivenSplit(TTessel::Split)
Add a given dummy split.
Definition: ttessel.cpp:3110
Halfedge_handle split_from_vertex(Vertex_handle, Halfedge_handle, Point2)
Split a tessellation cell from a vertex to an edge.
Definition: ttessel.cpp:153
std::vector< CatVector > GetEstimates()
Return all intermediate parameter estimates.
Definition: ttessel.h:949
bool is_valid(bool verbose=false)
Check validity of a T-tessellation param verbose : if true, details are sent to std::clog. Default to false.
Definition: ttessel.cpp:1532
std::vector< Point2 > del_vertices
list of deleted vertices
Definition: ttessel.h:427
Split_list split_sample(Size)
Return a random sample of splits.
Definition: ttessel.cpp:1594
double angle_between_vectors(Vector v1, Vector v2)
Return the angle between two planar vectors.
Definition: ttessel.cpp:3758
Halfedge_handle get_e2()
Return a handle to the split edge.
Definition: ttessel.h:546
Halfedge_handle get_e2()
Return a handle to one of the split edges.
Definition: ttessel.h:490
Halfedge_handle halfedges_end()
Return the halfedge handle ending the segment.
Definition: ttessel.cpp:716
double face_sum_of_angles(Polygon, TTessel *)
Measure the deviation of a T-tessellation face from a rectangle.
Definition: ttessel.cpp:3788
bool is_valid()
Check a merge is valid.
Definition: ttessel.cpp:2219
Flip propose_flip()
Propose a flip applicable to the T-tessellation.
Definition: ttessel.cpp:1577
Seg_sublist_iterator blocking_segments_end()
Return an iterator pointing to the past-the-end internal blocking segment.
Definition: ttessel.cpp:1677
Pseudo-likelihood inference of a Gibsian T-tessellation with alternate updates.
Definition: ttessel.h:937
CatItems< CatVector > CatMatrix
Storage structure for matrices (vector of vectors) of doubles associated with categories vertices...
Definition: ttessel.h:746
TTessel * get_ttessel()
Return the pointer to the associated TTessel object.
Definition: ttessel.h:787
Dcel::Size Size
Number type used for indexing tessellation features.
Definition: ttessel.h:122
double precompute_lengthening(Arrangement::Halfedge_handle, Arrangement::Halfedge_handle *, Point2 *)
Predict added length when lengthening an edge in an arrangement.
Definition: ttessel.cpp:3373
std::vector< Segment > add_edges
list of new edges
Definition: ttessel.h:430
Traits::Segment_2 Segment
CGAL class representing a line segment from a tessellation.
Definition: ttessel.h:68
double minus_is_segment_internal(std::vector< Point2 > s, TTessel *t)
Return -1.
Definition: ttessel.h:1009
Sublist of Seg objects.
Definition: ttessel.h:213
FMatrix asFMatrix(const CatMatrix &)
Generate a FMatrix object from a CatMatrix object.
Definition: ttessel.cpp:2569
Point2 get_p1()
Get the location of the new vertex on one of the new edge.
Definition: ttessel.h:486
List of Seg objects.
Definition: ttessel.h:187
Merge_list::iterator Merge_list_iterator
Iterator for accessing merges in a list.
Definition: ttessel.h:569
bool is_on_boundary(Seg_handle s)
Test whether a segment lies on the domain boundary.
Definition: ttessel.h:292
void print_blocking_segments()
Print on standard output all blocking segments.
Definition: ttessel.cpp:1727
void AddSplits(Size)
Increment the sample of dummy splits.
Definition: ttessel.cpp:3095
a segment is shortened, another one is lengthened
Definition: ttessel.h:865
void SetStepSize(double lambda)
Set step size used in Newton's method.
Definition: ttessel.h:943
std::vector< Polygon > del_faces
list of deleted faces
Definition: ttessel.h:431
merge (of two faces separated by a non-blocking segment)
Definition: ttessel.h:864
Seg_sublist::iterator Seg_sublist_iterator
Iterator for accessing segments in a sublist of segments.
Definition: ttessel.h:239
Flip_list::iterator Flip_list_iterator
Iterator for accessing flips in a list.
Definition: ttessel.h:572
std::vector< Flip > Flip_list
A list of flips.
Definition: ttessel.h:563
void del_features_edges()
Remove all edge features from the energy formula.
Definition: ttessel.cpp:2840
void set_prev_hf(LineTes::Halfedge_handle)
Set the previous halfedge along the segment.
Definition: ttessel.cpp:1289
Point2 p
location of new vertex added by lengthening
Definition: ttessel.h:402
CGAL::Line_2< Kernel > Line
CGAL class representing an infinite line.
Definition: ttessel.h:78
std::vector< std::vector< Point2 > > del_segs
list of deleted segments
Definition: ttessel.h:433
void print_non_blocking_segments()
Print on standard output all non-blocking segments.
Definition: ttessel.cpp:1736
double segment_size_2(std::vector< Point2 >, TTessel *)
Return the squared number of edges on a segment of a T-tessellation.
Definition: ttessel.cpp:3918
Flip_list all_flips()
Return all possible flips.
Definition: ttessel.cpp:1645
A split that can be applied to a T-tessellation.
Definition: ttessel.h:474
Set of vertex, edge, face and segment features.
Definition: ttessel.h:754
Split propose_split()
Propose a split applicable to the T-tessellation.
Definition: ttessel.cpp:1566
void remove_lvertices(Size imax=0, bool verbose=false)
Remove all L-vertices from a line tessellation.
Definition: ttessel.cpp:1059
ModifCounts step(unsigned long int=1)
Proceed to update(s) of the SMF chain.
Definition: ttessel.cpp:3003
int proposed_S
number of proposed splits
Definition: ttessel.h:831
LineTes::Halfedge_handle compute_next_hf(LineTes::Halfedge_handle)
Compute the next halfedge along a segment.
Definition: ttessel.cpp:3459
void set_halfedge_handle(Halfedge_handle)
Set the halfedge handle identifying a segment.
Definition: ttessel.cpp:752
Point2 pointSource()
Return the point starting the segment.
Definition: ttessel.cpp:765
Size number_of_segments()
Return the total number of segments.
Definition: ttessel.h:263
CGAL::Vector_2< Kernel > Vector
The CGAL class used for representing vectors.
Definition: ttessel.h:62
void del_theta_edges()
Remove all theta components associated with edge features.
Definition: ttessel.cpp:2788
void del_theta_faces()
Remove all theta components associated with face features.
Definition: ttessel.cpp:2792
bool check_all_halfedges(bool verbose=false)
Check all halfedges of a line tessellation.
Definition: ttessel.cpp:280
std::vector< Point2 > Points
Class representing a series of points.
Definition: ttessel.h:93
Merge propose_merge()
Propose a merge applicable to the T-tessellation.
Definition: ttessel.cpp:1571
double edge_length(Segment, TTessel *)
Return the length of an internal T-tessellation segment.
Definition: ttessel.cpp:3667
void del_features_faces()
Remove all face features from the energy formula.
Definition: ttessel.cpp:2844
std::vector< Point2 > add_vertices
list of new vertices
Definition: ttessel.h:428
void add_theta_edges(double)
Add a theta component for a edge feature in the energy formula.
Definition: ttessel.cpp:2768
Halfedge_handle get_halfedge_handle()
Return the halfedge handle identifying the segment.
Definition: ttessel.h:169
Discrete approximation of the log-pseudolikelihood of a Gibbsian T-tessellation.
Definition: ttessel.h:892
std::vector< Polygon > add_faces
list of new faces
Definition: ttessel.h:432
void set_ttessel(TTessel *)
Define the T-tessellation whose energy is to be monitored.
Definition: ttessel.cpp:2608
CGAL::Arr_dcel_base< CGAL::Arr_vertex_base< Point2 >, LineTes_halfedge, CGAL::Arr_face_base > Dcel
Class used as a template parameter for the Arrangement class.
Definition: ttessel.h:116
Energy * get_energy()
Get the energy function of the model to be simulated.
Definition: ttessel.h:858
std::vector< double(*)(Segment, TTessel *)> edges
edge features
Definition: ttessel.h:756
bool compare_ivertices(IVertex v1, IVertex v2)
Comparison of I-vertices based on length variation.
Definition: ttessel.h:412
void set_length()
Update the length attribute of a halfedge.
Definition: ttessel.cpp:1278
double GetStepSize()
Return step size used in Newton's method.
Definition: ttessel.h:941
Seg_sublist_iterator blocking_segments_begin()
Return an iterator pointing to the first internal blocking segment.
Definition: ttessel.cpp:1671
void del_theta_segs()
Remove all theta components associated with segment features.
Definition: ttessel.cpp:2796
double seg_number(std::vector< Point2 >, TTessel *)
Return 1.
Definition: ttessel.cpp:3683
Size number_of_window_edges()
Return the number of sides of the tessellated domain.
Definition: ttessel.cpp:472
Seg_list_iterator segments_end()
Return an iterator pointing to the end of the list of tessellation segments.
Definition: ttessel.h:258
Size number_of_blocking_segments()
Return the number of internal blocking segments.
Definition: ttessel.cpp:1660
void print_all_segments(bool endsOnly=false)
Print on standard output the segment points.
Definition: ttessel.cpp:488
Dynamic T-tessellation.
Definition: ttessel.h:445
bool check_halfedge_segment(LineTes::Halfedge_handle e, bool verbose=false)
Check the segment attribute of a halfedge.
Definition: ttessel.cpp:421
double get_value()
Return the current value of the energy for the associated T-tessellation.
Definition: ttessel.h:790
std::vector< std::vector< Point2 > > add_segs
list of new segments
Definition: ttessel.h:434
void set_smf_prob(double, double)
Set the probabilities of proposing a split and a merge.
Definition: ttessel.cpp:2880
void set_length(double l)
Set the length attribute of an halfedge.
Definition: ttessel.h:365
Seg_sublist_iterator non_blocking_segments_end()
Return an iterator pointing to the past-the-end internal non-blocking segment.
Definition: ttessel.cpp:1689
LineTes::Halfedge_handle find_halfedge(LineTes &, Point2, Point2)
Find a tessellation halfedge ending at two given points.
Definition: ttessel.cpp:3532
unsigned int Run(double=0.05, unsigned int=100)
Iterate the estimation algorithm until convergence.
Definition: ttessel.cpp:3283
void add_theta_faces(double)
Add a theta component for a face feature in the energy formula.
Definition: ttessel.cpp:2774
TTessel()
Empty constructor.
Definition: ttessel.cpp:1328
std::vector< T > vertices
a vector of T objects
Definition: ttessel.h:630
Halfedge class used by the LineTes class.
Definition: ttessel.h:338
const CatItems< T > operator+(const CatItems< T > &, const CatItems< T > &)
Addition operator for CatItems objects.
Definition: ttessel.h:666
int proposed_M
number of proposed merges
Definition: ttessel.h:833
LineTes::Face_handle NULL_FACE_HANDLE
Null value for a LineTes face handle.
Definition: ttessel.cpp:20
CatVector get_theta()
Return the theta parameter.
Definition: ttessel.h:792
void del_theta_vertices()
Remove all theta components associated with vertex features.
Definition: ttessel.cpp:2784
double get_total_internal_length()
Sum of all halfedge lengths.
Definition: ttessel.h:600
std::vector< T > faces
a vector of T objects
Definition: ttessel.h:632
void del_features_vertices()
Remove all vertex features from the energy formula.
Definition: ttessel.cpp:2836
const CatItems< T > operator*(const double &, const CatItems< T > &)
Product of a CatItems object with a scalar.
Definition: ttessel.h:687
void add_theta_vertices(double)
Add a theta component for a vertex feature in the energy formula.
Definition: ttessel.cpp:2762
CGAL::Aff_transformation_2< Kernel > Transformation
CGAL class representing an affine transformation.
Definition: ttessel.h:87
double get_length()
Return the halfedge length.
Definition: ttessel.h:354
bool check_halfedge_next_hf(LineTes::Halfedge_handle e, bool verbose=false)
Check the next neighbour of a halfedge along its segment.
Definition: ttessel.cpp:410
void set_theta(CatVector par)
Set the theta parameter.
Definition: ttessel.h:794
Face_handle suppress_edge(Halfedge_handle)
Suppress an edge from the tessellation.
Definition: ttessel.cpp:186
virtual void insert_window(Rectangle)
Define the rectangular domain delimiting the tessellation.
Definition: ttessel.cpp:41
CGAL::Random * rnd
LiTe random generator.
Definition: ttessel.cpp:21
void write(std::ostream &)
Write a LineTes object to an output stream.
Definition: ttessel.cpp:1181
bool check_all_segments(bool verbose=false)
Test whether all segments of a tessellation are valid.
Definition: ttessel.cpp:259
Split_list::iterator Split_list_iterator
Iterator for accessing splits in a list.
Definition: ttessel.h:566
std::vector< double(*)(std::vector< Point2 >, TTessel *)> segs
segment features
Definition: ttessel.h:758
unsigned long int number_of_internal_vertices(TTessel &)
Return the total number of internal vertices.
Definition: ttessel.cpp:3632
void fill(CatVector &, FVector &)
Fill a CatVector object with the elements of a FVector object.
Definition: ttessel.cpp:2486
A merge that can be applied to a T-tessellation.
Definition: ttessel.h:517
Definition: ttessel.h:131
ModType
Types of modifications applicable to a T-tessellation.
Definition: ttessel.h:862
ModType propose_modif_type()
Draw a type of modification (split or merge or flip)
Definition: ttessel.cpp:2889
void Step(unsigned int=1)
Proceed to several iterations of the estimation algorithm.
Definition: ttessel.cpp:3227
bool check_halfedge(LineTes::Halfedge_handle e, bool verbose=false)
Test whether a halfedge is valid.
Definition: ttessel.cpp:322
double sum_of_min_angles(TTessel *)
Return the sum of smallest angles on all faces of a T-tessellation.
Definition: ttessel.cpp:3881
split (of a face)
Definition: ttessel.h:863
Point2 get_p2()
Get the location of the new vertex on one of the new edge.
Definition: ttessel.h:494
Energy * GetEnergy()
Get the Energy data member.
Definition: ttessel.h:898
Polygon face2poly(TTessel::Face_handle)
Returns a Polygon object representing a face of the tessellation.
Definition: ttessel.cpp:3815
virtual ModList modified_elements()
Return the list of tessellation elements that are modified.
Definition: ttessel.cpp:1877
int accepted_S
number of accepted splits
Definition: ttessel.h:832
Polygons all_faces()
Return all faces of the tessellation as polygons.
Definition: ttessel.cpp:1695
virtual ModList modified_elements()
Return the list of tessellation elements modified by a flip.
Definition: ttessel.cpp:2290
void set_dir()
Update the direction attribute of a halfedge.
Definition: ttessel.cpp:1299
Point2 get_p2()
Return a handle to the new vertex.
Definition: ttessel.h:548
double sum_of_angles_obt(TTessel *)
Return the sum of obtuse angles on all faces of a T-tessellation.
Definition: ttessel.cpp:3896
void clear()
Clear a tessellation.
Definition: ttessel.cpp:226
Seg_sublist_iterator non_blocking_segments_begin()
Return an iterator pointing to the first internal non-blocking segment.
Definition: ttessel.cpp:1683
CatMatrix outer(const CatVector &, const CatVector &)
Outer product of two CatVector objects.
Definition: ttessel.cpp:2584
PLInferenceNOIS(Energy *, bool=false, double=1.0)
Generate a PLInferenceNOIS object.
Definition: ttessel.cpp:3211
const CatItems< T > operator-(const CatItems< T > &, const CatItems< T > &)
Subtraction of two CatItems objects.
Definition: ttessel.h:707
double is_point_inside_window(Point2, LineTes *)
Test whether a point is in the interior of the tessellated domain.
Definition: ttessel.cpp:3651
void printRCALI(std::ostream &)
Print the tessellation in a format supported by califlopp.
Definition: ttessel.cpp:1823
LineTes()
Empty LineTes constructor.
Definition: ttessel.cpp:33
Energy of a Gibbsian random T-tessellation.
Definition: ttessel.h:781
CGAL::Iso_rectangle_2< Kernel > Rectangle
CGAL class representing a rectangle with horizontal and vertical sides.
Definition: ttessel.h:75
Halfedge_handle get_e1()
Return a handle to one of the split edges.
Definition: ttessel.h:482
LineTes::Seg_handle segment()
Return a handle of the segment containing the halfedge.
Definition: ttessel.h:361
void add_features_faces(double(*)(Polygon, TTessel *))
Add a face feature in the energy formula.
Definition: ttessel.cpp:2823
bool suppress(Seg_handle s)
Delete a Seg object and remove it from the segment list.
Definition: ttessel.h:197
std::vector< Merge > Merge_list
A list of merges.
Definition: ttessel.h:560
Abstract class representing a modification of a T-tessellation.
Definition: ttessel.h:454
double min_angle(Polygon, TTessel *)
Return the smallest angle in a tessellation face.
Definition: ttessel.cpp:3843
bool suppress(Seg_handle s)
Remove a segment from the segment list.
Definition: ttessel.h:223
CGAL::Lazy_exact_nt< CGAL::Gmpq > NT
The CGAL numeric type used for exact computations in LiTe.
Definition: ttessel.h:52
LineTes::Seg_handle get_segment()
Return a handle of the segment containing the halfedge.
Definition: ttessel.h:357
int accepted_F
number of accepted flips
Definition: ttessel.h:836
std::vector< double(*)(Polygon, TTessel *)> faces
face featuress
Definition: ttessel.h:757
Split_list poisson_splits(double)
Return a Poisson sample of splits.
Definition: ttessel.cpp:1615
virtual ModList modified_elements()
Compute the elements of a T-tessellation that are modified by a merge.
Definition: ttessel.cpp:2113
bool check_halfedge_prev_hf(LineTes::Halfedge_handle e, bool verbose=false)
Check the previous neighbour of a halfedge along its segment.
Definition: ttessel.cpp:365
Merge_list all_merges()
Return all possible merges.
Definition: ttessel.cpp:1633
Size number_of_non_blocking_segments()
Return the number of internal non-blocking segments.
Definition: ttessel.cpp:1665
Seg_list::iterator Seg_list_iterator
Iterator for accessing segments in a list.
Definition: ttessel.h:236
LineTes::Halfedge_handle esplit
halfedge split by lengthening
Definition: ttessel.h:401
int accepted_M
number of accepted merges
Definition: ttessel.h:834
bool check_segment(Seg_handle s, bool verbose=false)
Test whether a segment of a tessellation is valid.
Definition: ttessel.cpp:303
void add_features_segs(double(*)(std::vector< Point2 >, TTessel *))
Add a segment feature in the energy formula.
Definition: ttessel.cpp:2832
double face_number(Polygon, TTessel *)
Return 1.
Definition: ttessel.cpp:3722
std::ostream & operator<<(std::ostream &, const CatVector &)
Print a CatVector to an output stream.
Definition: ttessel.cpp:2520
double changed_length
smallest length variation
Definition: ttessel.h:403
int proposed_F
number of proposed flips
Definition: ttessel.h:835
CatVector statistic_variation(TTessel::Modification &)
Compute the statistic variation.
Definition: ttessel.cpp:2660
Seg * Seg_handle
Pointer to a Seg object.
Definition: ttessel.h:179
void ClearSplits()
Remove all dummy splits.
Definition: ttessel.cpp:3117
CGAL::Cartesian< NT > Kernel
The CGAL type of coordinates used in LiTe.
Definition: ttessel.h:55
std::vector< T > segs
a vector of T objects
Definition: ttessel.h:633
friend std::ostream & operator<<(std::ostream &, const PseudoLikDiscrete &)
Send T-tessellation pseudolikelihood data to an output stream.
Definition: ttessel.cpp:3188
Points list_of_points()
Return the list of vertices (as points) lying along the segment.
Definition: ttessel.cpp:775
Flip()
Default constructor that returns an empty Flip object.
Definition: ttessel.cpp:2235
bool is_one_edge_segment()
Test whether a halfedge starting a segment is also ending the segment.
Definition: ttessel.h:378
LineTes::Halfedge_handle NULL_HALFEDGE_HANDLE
Null value for a LineTes halfedge handle.
Definition: ttessel.cpp:18
virtual void insert_window(Rectangle)
Define the rectangular domain to be tessellated.
Definition: ttessel.cpp:1366
CGAL::Arrangement_2< Traits, Dcel > Arrangement
Class representing a tessellation.
Definition: ttessel.h:119
Seg_list_iterator segments_begin()
Return an iterator pointing to the beginning of the list of tessellation segments.
Definition: ttessel.h:254
Size number_of_edges()
Return the number of edges along the segment.
Definition: ttessel.cpp:724
bool is_a_T_vertex(LineTes::Vertex_handle, bool verbose=false)
Test whether a vertex of a line tessellation is a T-vertex.
Definition: ttessel.cpp:3579
std::vector< Segment > del_edges
list of deleted edges
Definition: ttessel.h:429
const CatItems< T > & operator-=(const CatItems< T > &)
Decrement operator for CatItems objects.
Definition: ttessel.h:658
Halfedge_handle update(Split)
Split a T-tessellation.
Definition: ttessel.cpp:1392
void SetEnergy(Energy *e)
Set the Energy data member.
Definition: ttessel.h:901
Point2 pointTarget()
Return the point ending the segment.
Definition: ttessel.cpp:770
std::vector< double > asVectorOfDoubles(const CatVector &)
Generate a vector of doubles from a CatVector object.
Definition: ttessel.cpp:2499
LA::Matrix FMatrix
Class used for representing a matrix.
Definition: ttessel.h:106
LineTes::Halfedge_handle compute_prev_hf(LineTes::Halfedge_handle)
Compute the previous halfedge along a segment.
Definition: ttessel.cpp:3430
bool number_of_edges_is_greater_than(unsigned int)
Test on the number of edges of the segment.
Definition: ttessel.cpp:735
void set_next_hf(LineTes::Halfedge_handle)
Set the next halfedge along the segment.
Definition: ttessel.cpp:1284
bool halfedge_exists(LineTes::Halfedge_handle)
Test whether a halfedge handle is indeed a halfedge handle of a tessellation.
Definition: ttessel.cpp:341
void add_theta_segs(double)
Add a theta component for a segment feature in the energy formula.
Definition: ttessel.cpp:2780
A flip that can be applied to a T-tessellation.
Definition: ttessel.h:538
CGAL::Polygon_2< Kernel > Polygon
CGAL class representing a polygon.
Definition: ttessel.h:90
LineTes::Seg_handle NULL_SEG_HANDLE
Null value for a LineTes segment handle.
Definition: ttessel.cpp:19
void add(Seg_handle s)
Add a segment at the end of the segment list.
Definition: ttessel.h:216
void add_value(double delta)
Increment the current value of the energy.
Definition: ttessel.h:796
double is_segment_internal(std::vector< Point2 >, TTessel *)
Test whether a segment of a T-tessellation is internal.
Definition: ttessel.cpp:3698
void set_junction(LineTes::Halfedge_handle, LineTes::Halfedge_handle)
Set neighbour relationships between two halfedges.
Definition: ttessel.cpp:3486
CatVector GetGradient(CatVector)
Return pseudo-likelihood gradient.
Definition: ttessel.cpp:3151
LineTes_halfedge()
Basic constructor.
Definition: ttessel.cpp:1270
bool exist_halfedge(LineTes &, LineTes::Halfedge_handle)
Test whether a halfedge handle is valid.
Definition: ttessel.cpp:3516
void add(Seg_handle s)
Add a segment at the end of the segment list.
Definition: ttessel.h:190
Data summarizing changes occuring through SMF iterations.
Definition: ttessel.h:830
LineTes::Vertex_handle v
handle of the I-vertex
Definition: ttessel.h:399
Merge()
Default constructor that generates an empty Merge object.
Definition: ttessel.cpp:2106
CGAL::Ray_2< Kernel > Rayon
CGAL class representing a half-line.
Definition: ttessel.h:81
CGAL::Arr_segment_traits_2< Kernel > Traits
The CGAL arrangement traits class used for representing tessellations.
Definition: ttessel.h:59
virtual ModList modified_elements()
Compute elements of a T-tessellation that are modified by a split.
Definition: ttessel.cpp:1954
LineTes::Halfedge_handle get_prev_hf()
Return previous halfedge along the segment.
Definition: ttessel.h:343
CGAL::Direction_2< Kernel > Direction
CGAL class representing a direction in the plane.
Definition: ttessel.h:84
void clear()
Empty the T-tessellation.
Definition: ttessel.cpp:1517
void add_features_vertices(double(*)(Point2, TTessel *))
Add a vertex feature in the energy formula.
Definition: ttessel.cpp:2805
CGAL::Linear_algebraCd< double > LA
Class used for basic linear algebra.
Definition: ttessel.h:99
Seg()
Empty constructor.
Definition: ttessel.cpp:699
const CatItems< T > & operator+=(const CatItems< T > &)
Increment operator for CatItems objects.
Definition: ttessel.h:650
Data about removal of an I-vertex.
Definition: ttessel.h:398
std::vector< CatVector > GetSplitStatistics()
Return the split term of the discrete approximation of the log-pseudolikelihood.
Definition: ttessel.h:906
Traits::Point_2 Point2
CGAL class representing a point from a tessellation.
Definition: ttessel.h:65
double face_area_2(Polygon, TTessel *)
Return the squared face area of a tessellation face.
Definition: ttessel.cpp:3731
Segment clip_segment_by_convex_polygon(Segment, Polygon)
Clip a segment by a convex polygon.
Definition: ttessel.cpp:3342
void add_features_edges(double(*)(Segment, TTessel *))
Add an edge feature in the energy formula.
Definition: ttessel.cpp:2814
double variation(TTessel::Modification &)
Compute the energy variation.
Definition: ttessel.cpp:2740
Halfedge_handle split_from_edge(Halfedge_handle, Point2, Halfedge_handle, Point2)
Split a tessellation cell from an edge to another one.
Definition: ttessel.cpp:129
Halfedge_handle get_e1()
Return a handle to the suppressed edge.
Definition: ttessel.h:544
Seg_handle insert_segment(Segment)
Insert a new line segment in a line tessellation.
Definition: ttessel.cpp:815
double sum_of_faces_squared_areas(TTessel *)
Return the sum of squared areas of all faces of a T-tessellation.
Definition: ttessel.cpp:3866
double sum_of_segment_squared_sizes(TTessel *t)
Return the sum of squared numbers of edges on all segments of a T-tessellation.
Definition: ttessel.cpp:3934
Polygonal tessellation of a bounded rectangular domain.
Definition: ttessel.h:146
void remove_ivertices(Size imax=0, bool verbose=false)
Remove all I-vertices from a line tessellation.
Definition: ttessel.cpp:920
std::vector< CatVector > GetFlipStatistics()
Return the flip term of the discrete approximation of the log-pseudolikelihood.
Definition: ttessel.h:909
double Hasting_ratio(TTessel::Split &, double *)
Compute the Hastings ratio for a given split.
Definition: ttessel.cpp:2904
CatItems< double > CatVector
Storage structure for vector of doubles associated with categories vertices, edges, faces or segs.
Definition: ttessel.h:736
FVector asFVector(const CatVector &)
Generate a FVector object from CatVector object.
Definition: ttessel.cpp:2513
double sum(const CatVector &)
Compute the sum of components of a CatVector object.
Definition: ttessel.cpp:2550
Traits::X_monotone_curve_2 Curve
CGAL class representing a curve (line segment) from a tessellation.
Definition: ttessel.h:72
bool is_a_T_tessellation(bool verbose=false, std::ostream &out=std::clog)
Test whether a line tessellation is a T-tessellation.
Definition: ttessel.cpp:1143
int is_on_boundary(Halfedge_handle)
Test whether a halfedge lies along the domain boundary.
Definition: ttessel.cpp:500
std::vector< Split > Split_list
A list of splits.
Definition: ttessel.h:557
bool shorten
true if smallest length variation due to shortening
Definition: ttessel.h:404
Halfedge_handle halfedges_start()
Return the halfedge handle starting the segment.
Definition: ttessel.cpp:708
void set_energy(Energy *e)
Set the energy function of the model to be simulated.
Definition: ttessel.h:855
LA::Vector FVector
Class used for representing a vector (in the linear algebra sense)
Definition: ttessel.h:103
bool IsEmpty()
Test whether a CatItems object is empty.
Definition: ttessel.cpp:2471
CatMatrix GetHessian(CatVector)
Return the Hessian of the log-pseudolikelihood.
Definition: ttessel.cpp:3172
bool check_halfedge_dir(LineTes::Halfedge_handle e, bool verbose=false)
Check the direction attribute of a halfedge.
Definition: ttessel.cpp:458
bool check_halfedge_neighbours(LineTes::Halfedge_handle e, bool verbose=false)
Check the neighbours of a halfedge along its segment.
Definition: ttessel.cpp:355
double face_shape(Polygon, TTessel *)
Definition: ttessel.cpp:3749