1 #ifndef CGAL_SCENE_SURFACE_MESH_ITEM_H
2 #define CGAL_SCENE_SURFACE_MESH_ITEM_H
3 //Defines the precision of the positions (for performance/precision sake)
4 #define CGAL_GL_DATA GL_FLOAT
5 #define cgal_gl_data float
6 #define CGAL_IS_FLOAT 1
7 
8 #include "Scene_surface_mesh_item_config.h"
9 #include <CGAL/Three/Scene_zoomable_item_interface.h>
10 #include <CGAL/Three/Scene_print_item_interface.h>
11 #include <CGAL/Three/Scene_item_with_properties.h>
12 
13 #ifndef Q_MOC_RUN
14 #include "SMesh_type.h"
15 #endif
16 
17 #include <CGAL/Three/Scene_item.h>
18 #include <CGAL/Three/Scene_item_rendering_helper.h>
19 #include <CGAL/Three/Viewer_interface.h>
20 
21 #ifndef Q_MOC_RUN
22 #include <vector>
23 #include <boost/scoped_ptr.hpp>
24 #include <boost/array.hpp>
25 #endif
26 
27 #include <QColor>
28 
29 #include "properties.h"
30 
31 
32 class QSlider;
33 struct Scene_surface_mesh_item_priv;
34 class SCENE_SURFACE_MESH_ITEM_EXPORT Scene_surface_mesh_item
35     : public CGAL::Three::Scene_item_rendering_helper,
36     public CGAL::Three::Scene_item_with_properties,
37     public CGAL::Three::Scene_zoomable_item_interface,
38     public CGAL::Three::Scene_print_item_interface{
39   Q_INTERFACES(CGAL::Three::Scene_print_item_interface)
40   Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PrintInterface/1.0")
41   Q_OBJECT
42   Q_INTERFACES(CGAL::Three::Scene_zoomable_item_interface)
43   Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.ZoomInterface/1.0")
44 public:
45   typedef SMesh Face_graph;
46   typedef SMesh::Property_map<vertex_descriptor,int> Vertex_selection_map;
47   typedef SMesh::Property_map<face_descriptor,int> Face_selection_map;
48   Scene_surface_mesh_item();
49   // Takes ownership of the argument.
50   Scene_surface_mesh_item(SMesh*);
51   Scene_surface_mesh_item(SMesh);
52   Scene_surface_mesh_item(const Scene_surface_mesh_item& other);
53 
54   ~Scene_surface_mesh_item();
55 
56 
57   Scene_surface_mesh_item* clone() const Q_DECL_OVERRIDE;
58   void draw(CGAL::Three::Viewer_interface *) const Q_DECL_OVERRIDE;
59   void drawEdges(CGAL::Three::Viewer_interface *) const Q_DECL_OVERRIDE;
60   void drawPoints(CGAL::Three::Viewer_interface *) const Q_DECL_OVERRIDE;
61 
62   bool supportsRenderingMode(RenderingMode m) const Q_DECL_OVERRIDE;
isFinite()63   bool isFinite() const Q_DECL_OVERRIDE { return true; }
64   bool isEmpty() const Q_DECL_OVERRIDE;
65   Bbox bbox() const Q_DECL_OVERRIDE;
66   QString toolTip() const Q_DECL_OVERRIDE;
67   void copyProperties(Scene_item *) Q_DECL_OVERRIDE;
68 
69   QMenu* contextMenu() Q_DECL_OVERRIDE;
70 
71   void setItemIsMulticolor(bool);
72   //to be called before invalidate() to enable or disable the recomputation
73   //of the colors_ vector to scale on min_patch value.
74   // For example, the Mesh_segmentation_plugin computes the colors_
75   // vector itself, so it must set recompute_colors to false to avoid
76   // having it ovewritten
77   // in the code of this item.
78   void computeItemColorVectorAutomatically(bool);
79   bool isItemMulticolor();
80   bool hasPatchIds();
81   Vertex_selection_map vertex_selection_map();
82   Face_selection_map face_selection_map();
83 
84   std::vector<QColor>& color_vector();
85   void show_feature_edges(bool);
86   SMesh* polyhedron();
87   const SMesh* polyhedron() const;
88 
face_graph()89   Face_graph*       face_graph() { return polyhedron(); }
face_graph()90   const Face_graph* face_graph() const { return polyhedron(); }
91 
92   // Gets PLY comments (empty if mesh not originated from PLY input)
93   std::string& comments();
94   const std::string& comments() const;
95 
96   void invalidate_aabb_tree();
97   void invalidateOpenGLBuffers()Q_DECL_OVERRIDE;
98   void invalidate(Gl_data_names name);
99 
100 
101   void compute_bbox()const Q_DECL_OVERRIDE;
102   void standard_constructor(SMesh *sm);
103   bool save(std::ostream& out) const;
104   bool save_obj(std::ostream& out) const;
105   bool load_obj(std::istream& in);
106   //statistics
107   enum STATS {
108     NB_VERTICES = 0,
109     HAS_NM_VERTICES,
110     NB_CONNECTED_COMPOS,
111     NB_BORDER_EDGES,
112     IS_PURE_TRIANGLE,
113     IS_PURE_QUAD,
114     NB_DEGENERATED_FACES,
115     HOLES,
116     AREA,
117     VOLUME,
118     SELFINTER,
119     NB_FACETS,
120     MIN_AREA,
121     MAX_AREA,
122     MED_AREA,
123     MEAN_AREA,
124     MIN_ALTITUDE,
125     MIN_ASPECT_RATIO,
126     MAX_ASPECT_RATIO,
127     MEAN_ASPECT_RATIO,
128     GENUS,
129     NB_EDGES,
130     MIN_LENGTH,
131     MAX_LENGTH,
132     MID_LENGTH,
133     MEAN_LENGTH,
134     NB_NULL_LENGTH,
135     MIN_ANGLE,
136     MAX_ANGLE,
137     MEAN_ANGLE
138   };
139 
has_stats()140   bool has_stats()const Q_DECL_OVERRIDE{return true;}
141   QString computeStats(int type)Q_DECL_OVERRIDE;
142   CGAL::Three::Scene_item::Header_data header() const Q_DECL_OVERRIDE;
143   //zoomable interface
144   void zoomToPosition(const QPoint &point, CGAL::Three::Viewer_interface *)const Q_DECL_OVERRIDE;
145  //print_interface
146   void printPrimitiveId(QPoint point, CGAL::Three::Viewer_interface*viewer)Q_DECL_OVERRIDE;
147   bool printVertexIds()const Q_DECL_OVERRIDE;
148   bool printEdgeIds()const Q_DECL_OVERRIDE;
149   bool printFaceIds()const Q_DECL_OVERRIDE;
150   void printAllIds() Q_DECL_OVERRIDE;
151   bool shouldDisplayIds(CGAL::Three::Scene_item *current_item) const Q_DECL_OVERRIDE;
152   bool testDisplayId(double x, double y, double z, CGAL::Three::Viewer_interface*)const Q_DECL_OVERRIDE;
153   float alpha() const Q_DECL_OVERRIDE;
154   void setAlpha(int alpha) Q_DECL_OVERRIDE;
155   QSlider* alphaSlider();
156   void computeElements() const Q_DECL_OVERRIDE;
157   void initializeBuffers(CGAL::Three::Viewer_interface*)const Q_DECL_OVERRIDE;
158   void updateVertex(vertex_descriptor vh);
159   void fill_flat_vertex_map();
160   void updateIds(vertex_descriptor vh);
161 Q_SIGNALS:
162   void item_is_about_to_be_changed();
163   void selection_done();
164   void selected_vertex(void*);
165   void selected_facet(void*);
166   void selected_edge(void*);
167   void selected_halfedge(void*);
168 
169 
170 public Q_SLOTS:
171   void itemAboutToBeDestroyed(Scene_item *) Q_DECL_OVERRIDE;
172   virtual void selection_changed(bool) Q_DECL_OVERRIDE;
173   void select(double orig_x,
174               double orig_y,
175               double orig_z,
176               double dir_x,
177               double dir_y,
178               double dir_z) Q_DECL_OVERRIDE;
179   bool intersect_face(double orig_x,
180                       double orig_y,
181                       double orig_z,
182                       double dir_x,
183                       double dir_y,
184                       double dir_z,
185                       const face_descriptor &f);
186   void resetColors();
187   void showVertices(bool);
188   void showEdges(bool);
189   void showFaces(bool);
190   void showPrimitives(bool);
191   void zoomToId();
192 protected:
193   friend struct Scene_surface_mesh_item_priv;
194   Scene_surface_mesh_item_priv* d;
195 };
196 
197 #endif /* CGAL_SCENE_SURFACE_MESH_ITEM_H */
198