ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvDrawableObject.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // LOCAL
11 #include "ecvDrawContext.h"
12 #include "ecvGLMatrix.h"
13 
14 // CV_CORE_LIB
15 #include <CVGeom.h>
16 
18 struct ccClipPlane {
20 };
21 using ccClipPlaneSet = std::vector<ccClipPlane>;
22 
25 public:
30 
31  virtual ~ccDrawableObject() = default;
32 
33 public: // drawing and drawing options
35  virtual void draw(CC_DRAW_CONTEXT& context) = 0;
36 
38  inline virtual bool isVisible() const { return m_visible; }
40  inline virtual void setVisible(bool state) { m_visible = state; }
41 
43  inline virtual void toggleVisibility() { setVisible(!isVisible()); }
44 
46  inline virtual bool isRedraw() const { return m_modelRedraw; }
48  inline virtual void setRedraw(bool state) { m_modelRedraw = state; }
50  inline virtual void setForceRedraw(bool state) { m_forceRedraw = state; }
51 
52  inline virtual void setFixedId(bool state) { m_fixedId = state; }
53  inline virtual bool isFixedId() { return m_fixedId; }
54 
56  inline virtual bool isVisibilityLocked() const {
57  return m_lockedVisibility;
58  }
60 
63  inline virtual void lockVisibility(bool state) {
64  m_lockedVisibility = state;
65  }
66 
68  inline virtual bool isSelected() const { return m_selected; }
70  inline virtual void setSelected(bool state) { m_selected = state; }
71 
73 
78 
80  inline virtual bool hasColors() const { return false; }
82  inline virtual bool colorsShown() const { return m_colorsDisplayed; }
84  inline virtual void showColors(bool state) { m_colorsDisplayed = state; }
86  inline virtual void toggleColors() { showColors(!colorsShown()); }
87 
89  inline virtual bool hasNormals() const { return false; }
91  inline virtual bool normalsShown() const { return m_normalsDisplayed; }
93  inline virtual void showNormals(bool state) { m_normalsDisplayed = state; }
95  inline virtual void toggleNormals() { showNormals(!normalsShown()); }
96 
97 public: // scalar fields
99  inline virtual bool hasDisplayedScalarField() const { return false; }
100 
102 
105  inline virtual bool hasScalarFields() const { return false; }
106 
108  inline virtual void showSF(bool state) {
109  m_sfDisplayed = state;
110  setRedraw(state);
111  }
112 
114  inline virtual void toggleSF() { showSF(!sfShown()); }
115 
117  inline virtual bool sfShown() const { return m_sfDisplayed; }
118 
119 public: //(Mesh) materials
121  virtual void toggleMaterials() {} // does nothing by default!
122 
123 public: // Name display in 3D
125  inline virtual void showNameIn3D(bool state) { m_showNameIn3D = state; }
126 
128  inline virtual bool nameShownIn3D() const { return m_showNameIn3D; }
129 
131  inline virtual void toggleShowName() { showNameIn3D(!nameShownIn3D()); }
132 
133 public: // Temporary color
136 
138  inline virtual bool isColorOverridden() const {
139  return m_colorIsOverridden;
140  }
141 
143  inline virtual const ecvColor::Rgb& getTempColor() const {
144  return m_tempColor;
145  }
146 
148 
151  virtual void setTempColor(const ecvColor::Rgb& col,
152  bool autoActivate = true);
153 
155  inline virtual void enableTempColor(bool state) {
156  m_colorIsOverridden = state;
157  }
158 
159  // Get opacity
160  inline virtual float getOpacity() const { return m_opacity; }
161 
163  inline virtual void setOpacity(float opacity) {
164  m_opacity = opacity;
165  setRedraw(false);
166  }
167 
168 public: // Transformation matrix management (for display only)
170 
178  virtual void setGLTransformation(const ccGLMatrix& trans);
179 
181 
183  virtual void enableGLTransformation(bool state);
184 
186  inline virtual bool isGLTransEnabled() const { return m_glTransEnabled; }
187 
189 
191  inline virtual const ccGLMatrix& getGLTransformation() const {
192  return m_glTrans;
193  }
194 
196 
200  virtual void resetGLTransformation();
201 
203 
207  virtual void rotateGL(const ccGLMatrix& rotMat);
208 
210 
214  virtual void translateGL(const CCVector3& trans);
215 
216 public: // clipping planes
218  virtual void removeAllClipPlanes() { m_clipPlanes.resize(0); }
219 
221 
223  virtual bool addClipPlanes(const ccClipPlane& plane);
224 
226 
229  virtual void toggleClipPlanes(CC_DRAW_CONTEXT& context, bool enable);
230 
231 public: // push and pop display state
233  struct DisplayState {
236 
237  using Shared = QSharedPointer<DisplayState>;
238 
239  bool visible = false;
240  bool colorsDisplayed = false;
241  bool normalsDisplayed = false;
242  bool sfDisplayed = false;
243  bool colorIsOverridden = false;
244  bool showNameIn3D = false;
245  };
246 
248  virtual bool pushDisplayState();
249 
251  virtual void popDisplayState(bool apply = true);
252 
254  virtual void applyDisplayState(const DisplayState& state);
255 
256 protected: // members
257  bool m_fixedId;
260  float m_opacity;
261 
263 
265  bool m_visible;
266 
269 
272 
279 
284 
286 
290 
293 
298 
301 
303  std::vector<DisplayState::Shared> m_displayStateStack;
304 };
#define CV_DB_LIB_API
Definition: CV_db.h:15
cmdLineReadable * params[]
Generic interface for (3D) drawable entities.
virtual void translateGL(const CCVector3 &trans)
Translates current GL transformation by a rotation matrix.
virtual void toggleVisibility()
Toggles visibility.
virtual bool colorsShown() const
Returns whether colors are shown or not.
bool m_sfDisplayed
Specifies whether scalar field should be displayed.
virtual float getOpacity() const
virtual bool isVisible() const
Returns whether entity is visible or not.
virtual void setTempColor(const ecvColor::Rgb &col, bool autoActivate=true)
Sets current temporary (unique)
virtual bool isVisibilityLocked() const
Returns whether visibility is locked or not.
virtual bool hasDisplayedScalarField() const
Returns whether an active scalar field is available or not.
bool m_colorsDisplayed
Specifies whether colors should be displayed.
virtual void applyDisplayState(const DisplayState &state)
Applies a display state.
virtual void toggleNormals()
Toggles normals display state.
virtual bool hasColors() const
Returns whether colors are enabled or not.
virtual void lockVisibility(bool state)
Locks/unlocks visibility.
virtual void enableGLTransformation(bool state)
Enables/disables associated GL transformation.
virtual void setVisible(bool state)
Sets entity visibility.
virtual bool sfShown() const
Returns whether active scalar field is visible.
virtual bool isFixedId()
bool m_visible
Specifies whether the object is visible or not.
virtual bool isGLTransEnabled() const
Returns whether a GL transformation is enabled or not.
virtual bool normalsShown() const
Returns whether normals are shown or not.
virtual const ccGLMatrix & getGLTransformation() const
Returns associated GL transformation.
virtual bool pushDisplayState()
Pushes the current display state.
virtual void toggleClipPlanes(CC_DRAW_CONTEXT &context, bool enable)
Enables or disables clipping planes (OpenGL)
virtual bool hasNormals() const
Returns whether normals are enabled or not.
bool m_glTransEnabled
Current GL transformation activation state.
virtual void setRedraw(bool state)
Sets entity redraw mode.
virtual bool isColorOverridden() const
virtual void toggleSF()
Toggles SF display state.
ccGLMatrix m_glTrans
Current GL transformation.
virtual void getDrawingParameters(glDrawParams &params) const
Returns main OpenGL parameters for this entity.
virtual void toggleMaterials()
Toggles material display state.
virtual void toggleColors()
Toggles colors display state.
virtual bool isSelected() const
Returns whether entity is selected or not.
virtual void setFixedId(bool state)
bool m_selected
Specifies whether the object is selected or not.
virtual void toggleShowName()
Toggles name in 3D display state.
virtual void showNameIn3D(bool state)
Sets whether name should be displayed in 3D.
CCVector3d m_nameIn3DPos
Last 2D position of the '3D' name.
virtual bool nameShownIn3D() const
Returns whether name is displayed in 3D or not.
virtual void enableTempColor(bool state)
Set temporary color activation state.
virtual void removeAllClipPlanes()
Removes all clipping planes (if any)
virtual void showNormals(bool state)
Sets normals visibility.
bool m_lockedVisibility
Specifies whether the visibility can be changed by user or not.
virtual bool isRedraw() const
Returns whether entity is to be redraw.
std::vector< DisplayState::Shared > m_displayStateStack
The stack of pushed display states.
virtual void popDisplayState(bool apply=true)
Pops the last pushed display state.
bool m_showNameIn3D
Whether name is displayed in 3D or not.
ccDrawableObject()
Default constructor.
virtual void showColors(bool state)
Sets colors visibility.
virtual void showSF(bool state)
Sets active scalarfield visibility.
virtual void setForceRedraw(bool state)
Sets force redraw.
virtual const ecvColor::Rgb & getTempColor() const
Returns current temporary (unique) color.
virtual void setOpacity(float opacity)
Set opacity activation state.
virtual void rotateGL(const ccGLMatrix &rotMat)
Multiplies (left) current GL transformation by a rotation matrix.
bool m_colorIsOverridden
Temporary (unique) color activation state.
virtual bool hasScalarFields() const
Returns whether one or more scalar fields are instantiated.
virtual void draw(CC_DRAW_CONTEXT &context)=0
Draws entity and its children.
virtual bool addClipPlanes(const ccClipPlane &plane)
Registers a new clipping plane.
bool m_normalsDisplayed
Specifies whether normals should be displayed.
virtual void resetGLTransformation()
Resets associated GL transformation.
virtual void setGLTransformation(const ccGLMatrix &trans)
Associates entity with a GL transformation (rotation + translation)
ccClipPlaneSet m_clipPlanes
Active clipping planes (used for display only)
ecvColor::Rgb m_tempColor
Temporary (unique) color.
virtual ~ccDrawableObject()=default
virtual void setSelected(bool state)
Selects/Unselects entity.
ccDrawableObject(const ccDrawableObject &object)
Copy constructor.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
RGB color structure.
Definition: ecvColorTypes.h:49
std::vector< ccClipPlane > ccClipPlaneSet
ImGuiContext * context
Definition: Window.cpp:76
Simple (clipping) plane equation.
Tuple4Tpl< double > equation
DisplayState(const ccDrawableObject &dobj)
QSharedPointer< DisplayState > Shared
Display context.
Display parameters of a 3D entity.