File: ccDrawableObject.h

package info (click to toggle)
cloudcompare 2.10.1-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 55,916 kB
  • sloc: cpp: 219,837; ansic: 29,944; makefile: 67; sh: 45
file content (287 lines) | stat: -rw-r--r-- 10,359 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
//##########################################################################
//#                                                                        #
//#                              CLOUDCOMPARE                              #
//#                                                                        #
//#  This program is free software; you can redistribute it and/or modify  #
//#  it under the terms of the GNU General Public License as published by  #
//#  the Free Software Foundation; version 2 or later of the License.      #
//#                                                                        #
//#  This program is distributed in the hope that it will be useful,       #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          #
//#  GNU General Public License for more details.                          #
//#                                                                        #
//#          COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI)             #
//#                                                                        #
//##########################################################################

#ifndef CC_DRAWABLE_OBJECT_HEADER
#define CC_DRAWABLE_OBJECT_HEADER

//Local
#include "ccGLDrawContext.h"

//CCLib
#include <CCGeom.h>


class ccGenericGLDisplay;

//! Simple (clipping) plane equation
struct ccClipPlane
{
	Tuple4Tpl<double> equation;
};
using ccClipPlaneSet = std::vector<ccClipPlane>;

//! Generic interface for (3D) drawable entities
class QCC_DB_LIB_API ccDrawableObject
{
public:

	//! Default constructor
	ccDrawableObject();
	//! Copy constructor
	ccDrawableObject(const ccDrawableObject& object);
	
	virtual ~ccDrawableObject() = default;

public:  //drawing and drawing options

	//! Draws entity and its children
	virtual void draw(CC_DRAW_CONTEXT& context) = 0;

	//! Returns whether entity is visible or not
	inline virtual bool isVisible() const { return m_visible; }
	//! Sets entity visibility
	inline virtual void setVisible(bool state) { m_visible = state; }
	//! Toggles visibility
	inline virtual void toggleVisibility() { setVisible(!isVisible()); }

	//! Returns whether visibilty is locked or not
	inline virtual bool isVisiblityLocked() const { return m_lockedVisibility; }
	//! Locks/unlocks visibilty
	/** If visibility is locked, the user won't be able to modify it
		(via the properties tree for instance).
	**/
	inline virtual void lockVisibility(bool state) { m_lockedVisibility = state; }

	//! Returns whether entity is selected or not
	inline virtual bool isSelected() const { return m_selected; }
	//! Selects/unselects entity
	inline virtual void setSelected(bool state) { m_selected = state; }

	//! Returns main OpenGL parameters for this entity
	/** These parameters are deduced from the visiblity states
		of its different features (points, normals, etc.).
		\param params a glDrawParams structure
	**/
	virtual void getDrawingParameters(glDrawParams& params) const;

	//! Returns whether colors are enabled or not
	inline virtual bool hasColors() const  { return false; }
	//! Returns whether colors are shown or not
	inline virtual bool colorsShown() const { return m_colorsDisplayed; }
	//! Sets colors visibility
	inline virtual void showColors(bool state) { m_colorsDisplayed = state; }
	//! Toggles colors display state
	inline virtual void toggleColors() { showColors(!colorsShown()); }

	//! Returns whether normals are enabled or not
	inline virtual bool hasNormals() const  { return false; }
	//! Returns whether normals are shown or not
	inline virtual bool normalsShown() const { return m_normalsDisplayed; }
	//! Sets normals visibility
	inline virtual void showNormals(bool state) { m_normalsDisplayed = state; }
	//! Toggles normals display state
	inline virtual void toggleNormals() { showNormals(!normalsShown()); }

public: //scalar fields

	//! Returns whether an active scalar field is available or not
	inline virtual bool hasDisplayedScalarField() const { return false; }

	//! Returns whether one or more scalar fields are instantiated
	/** WARNING: doesn't mean a scalar field is currently displayed
		(see ccDrawableObject::hasDisplayedScalarField).
	**/
	inline virtual bool hasScalarFields() const  { return false; }

	//! Sets active scalarfield visibility
	inline virtual void showSF(bool state) { m_sfDisplayed = state; }

	//! Toggles SF display state
	inline virtual void toggleSF() { showSF(!sfShown()); }

	//! Returns whether active scalar field is visible
	inline virtual bool sfShown() const { return m_sfDisplayed; }

public: //(Mesh) materials

	//! Toggles material display state
	virtual void toggleMaterials() {} //does nothing by default!

public: //Name display in 3D

	//! Sets whether name should be displayed in 3D
	inline virtual void showNameIn3D(bool state) { m_showNameIn3D = state; }

	//! Returns whether name is displayed in 3D or not
	inline virtual bool nameShownIn3D() const { return m_showNameIn3D; }

	//! Toggles name in 3D display state
	inline virtual void toggleShowName() { showNameIn3D(!nameShownIn3D()); }

public: //Temporary color

	//! Returns whether colors are currently overridden by a temporary (unique) color
	/** See ccDrawableObject::setTempColor.
	**/
	inline virtual bool isColorOverriden() const { return m_colorIsOverriden; }

	//! Returns current temporary (unique) color
	inline virtual const ccColor::Rgb& getTempColor() const { return m_tempColor; }

	//! Sets current temporary (unique)
	/** \param col rgb color
		\param autoActivate auto activates temporary color
	**/
	virtual void setTempColor(const ccColor::Rgb& col, bool autoActivate = true);

	//! Set temporary color activation state
	inline virtual void enableTempColor(bool state) { m_colorIsOverriden = state; }

public: //associated display management

	//! Unlinks entity from a GL display (only if it belongs to it of course)
	virtual void removeFromDisplay(const ccGenericGLDisplay* win);

	//! Sets associated GL display
	virtual void setDisplay(ccGenericGLDisplay* win);

	//! Returns associated GL display
	inline virtual ccGenericGLDisplay* getDisplay() const { return m_currentDisplay; }

	//! Redraws associated GL display
	virtual void redrawDisplay();

	//! Sets associated GL display 'refreshable' before global refresh
	/** Only tagged displays will be refreshed when ccGenericGLDisplay::refresh
		is called (see also MainWindow::RefreshAllGLWindow,
		MainWindow::refreshAll and ccDrawableObject::refreshDisplay).
	**/
	virtual void prepareDisplayForRefresh();

	//! Refreshes associated GL display
	/** See ccGenericGLDisplay::refresh. The display will only be updated
		if it has been 'prepared for refresh' (see prepareDisplayForRefresh).
	**/
	virtual void refreshDisplay(bool only2D = false);

public: //Transformation matrix management (for display only)

	//! Associates entity with a GL transformation (rotation + translation)
	/** \warning FOR DISPLAY PURPOSE ONLY (i.e. should only be temporary)
		If the associated GL transformation is enabled (see
		ccDrawableObject::enableGLTransformation), it will
		be applied before displaying this entity.
		However it will not be taken into account by any CCLib algorithm
		(distance computation, etc.) for instance.
		Note: GL transformation is automatically enabled.
	**/
	virtual void setGLTransformation(const ccGLMatrix& trans);

	//! Enables/disables associated GL transformation
	/** See ccDrawableObject::setGLTransformation.
	**/
	virtual void enableGLTransformation(bool state);

	//! Returns whether a GL transformation is enabled or not
	inline virtual bool isGLTransEnabled() const { return m_glTransEnabled; }

	//! Returns associated GL transformation
	/** See ccDrawableObject::setGLTransformation.
	**/
	inline virtual const ccGLMatrix& getGLTransformation() const { return m_glTrans; }

	//! Resets associated GL transformation
	/** GL transformation is reset to identity.
		Note: GL transformation is automatically disabled.
		See ccDrawableObject::setGLTransformation.
	**/
	virtual void resetGLTransformation();

	//! Mutliplies (left) current GL transformation by a rotation matrix
	/** 'GLtrans = M * GLtrans'
		Note: GL transformation is automatically enabled.
		See ccDrawableObject::setGLTransformation.
	**/
	virtual void rotateGL(const ccGLMatrix& rotMat);

	//! Translates current GL transformation by a rotation matrix
	/** 'GLtrans = GLtrans + T'
		Note: GL transformation is automatically enabled.
		See ccDrawableObject::setGLTransformation.
	**/
	virtual void translateGL(const CCVector3& trans);

public: //clipping planes

	//! Removes all clipping planes (if any)
	virtual void removeAllClipPlanes() { m_clipPlanes.resize(0); }

	//! Registers a new clipping plane
	/** \return false if the planes couldn't be added (not enough memory)
	**/
	virtual bool addClipPlanes(const ccClipPlane& plane);

	//! Enables or disables clipping planes (OpenGL)
	/** \warning If enabling the clipping planes, be sure to call this method AFTER the modelview matrix has been set.
	**/
	virtual void toggleClipPlanes(CC_DRAW_CONTEXT& context, bool enable);

protected: //members

	//! Specifies whether the object is visible or not
	/** Note: this does not influence the children visibility
	**/
	bool m_visible;

	//! Specifies whether the object is selected or not
	bool m_selected;

	//! Specifies whether the visibility can be changed by user or not
	bool m_lockedVisibility;

	//! Specifies whether colors should be displayed
	bool m_colorsDisplayed;
	//! Specifies whether normals should be displayed
	bool m_normalsDisplayed;
	//! Specifies whether scalar field should be displayed
	bool m_sfDisplayed;

	//! Temporary (unique) color
	ccColor::Rgb m_tempColor;
	//! Temporary (unique) color activation state
	bool m_colorIsOverriden;

	//! Current GL transformation
	/** See ccDrawableObject::setGLTransformation.
	**/
	ccGLMatrix m_glTrans;
	//! Current GL transformation activation state
	/** See ccDrawableObject::setGLTransformation.
	**/
	bool m_glTransEnabled;

	//! Whether name is displayed in 3D or not
	bool m_showNameIn3D;

	//! Currently associated GL display
	ccGenericGLDisplay* m_currentDisplay;

	//! Active clipping planes (used for display only)
	ccClipPlaneSet m_clipPlanes;
};

#endif //CC_DRAWABLE_OBJECT_HEADER