ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvDrawableObject.cpp
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 #include "ecvDrawableObject.h"
9 
10 #include "ecvDisplayTools.h"
11 
13  setOpacity(1.0);
14  setFixedId(false);
15  setRedraw(true);
16  setForceRedraw(false);
17  setVisible(true);
18  setSelected(false);
19  lockVisibility(false);
20  showColors(false);
21  showNormals(false);
22  showSF(false);
23  enableTempColor(false);
26  showNameIn3D(false);
27 }
28 
30  : m_fixedId(object.m_fixedId),
31  m_modelRedraw(object.m_modelRedraw),
32  m_forceRedraw(object.m_forceRedraw),
33  m_opacity(object.m_opacity),
34  m_visible(object.m_visible),
35  m_selected(object.m_selected),
36  m_lockedVisibility(object.m_lockedVisibility),
37  m_colorsDisplayed(object.m_colorsDisplayed),
38  m_normalsDisplayed(object.m_normalsDisplayed),
39  m_sfDisplayed(object.m_sfDisplayed),
40  m_tempColor(object.m_tempColor),
41  m_colorIsOverridden(object.m_colorIsOverridden),
42  m_glTrans(object.m_glTrans),
43  m_glTransEnabled(object.m_glTransEnabled),
44  m_showNameIn3D(object.m_showNameIn3D) {}
45 
47  m_glTransEnabled = state;
48  // if (ecvDisplayTools::GetCurrentScreen())
49  //{
50  // ecvDisplayTools::Deprecate3DLayer();
51  // }
52 }
53 
55  m_glTrans = trans;
57 }
58 
60  m_glTrans = rotMat * m_glTrans;
62 }
63 
65  m_glTrans += trans;
67 }
68 
72 }
73 
75  bool autoActivate /*=true*/) {
76  m_tempColor = col;
77 
78  if (autoActivate) enableTempColor(true);
79 }
80 
82  // color override
83  if (isColorOverridden()) {
84  params.showColors = true;
85  params.showNorms = hasNormals() && normalsShown() /*false*/;
86  params.showSF = false;
87  } else {
88  params.showNorms = hasNormals() && normalsShown();
89  params.showSF = hasDisplayedScalarField() && sfShown();
90  // colors are not displayed if scalar field is displayed
91  params.showColors = !params.showSF && hasColors() && colorsShown();
92  }
93 }
94 
96  try {
97  m_clipPlanes.push_back(plane);
98  } catch (const std::bad_alloc&) {
99  // not enough memory
100  return false;
101  }
102 
103  return true;
104 }
105 
107  if (m_clipPlanes.empty()) {
108  return;
109  }
110 
111  // get the set of OpenGL functions (version 2.1)
112  // QOpenGLFunctions_2_1* glFunc =
113  // context.glFunctions<QOpenGLFunctions_2_1>(); assert(glFunc != nullptr);
114 
115  // if (glFunc == nullptr)
116  // return;
117 
118  // GLint maxPlaneCount = 0;
119  // glFunc->glGetIntegerv(GL_MAX_CLIP_PLANES, &maxPlaneCount);
120 
121  // GLint planeCount = static_cast<GLint>(m_clipPlanes.size());
122  // if (planeCount > maxPlaneCount)
123  //{
124  // if (enable)
125  // {
126  // CVLog::Warning("[ccDrawableObject::enableClipPlanes] Clipping
127  // planes count exceeds the maximum supported number");
128  // }
129  // planeCount = maxPlaneCount;
130  // }
131  // for (GLint i=0; i < planeCount; ++i)
132  //{
133  // GLenum planeIndex = GL_CLIP_PLANE0 + i;
134  // if (enable)
135  // {
136  // glFunc->glClipPlane(planeIndex, m_clipPlanes[i].equation.u);
137  // glFunc->glEnable(planeIndex);
138  // }
139  // else
140  // {
141  // glFunc->glDisable(planeIndex);
142  // }
143  // }
144 }
145 
147  : visible(dobj.m_visible),
148  colorsDisplayed(dobj.m_colorsDisplayed),
149  normalsDisplayed(dobj.m_normalsDisplayed),
150  sfDisplayed(dobj.m_sfDisplayed),
151  colorIsOverridden(dobj.m_colorIsOverridden),
152  showNameIn3D(dobj.m_showNameIn3D) {}
153 
155  try {
156  m_displayStateStack.emplace_back(new DisplayState(*this));
157  } catch (const std::bad_alloc&) {
158  CVLog::Warning("Not enough memory to push the current display state");
159  return false;
160  }
161 
162  return true;
163 }
164 
165 void ccDrawableObject::popDisplayState(bool apply /*=true*/) {
166  if (!m_displayStateStack.empty()) {
167  const DisplayState::Shared state = m_displayStateStack.back();
168  if (state && apply) {
169  applyDisplayState(*state);
170  }
171  m_displayStateStack.pop_back();
172  }
173 }
174 
176  if (state.visible != m_visible) setVisible(state.visible);
177  if (state.colorsDisplayed != m_colorsDisplayed)
181  if (state.sfDisplayed != m_sfDisplayed) showSF(state.sfDisplayed);
185 }
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
Generic interface for (3D) drawable entities.
virtual bool colorsShown() const
Returns whether colors are shown or not.
virtual void setGLTransformation(const ccGLMatrix &trans)
Associates entity with a GL transformation (rotation + translation)
bool m_sfDisplayed
Specifies whether scalar field should be displayed.
virtual bool addClipPlanes(const ccClipPlane &plane)
Registers a new clipping plane.
virtual bool pushDisplayState()
Pushes the current display state.
virtual bool hasDisplayedScalarField() const
Returns whether an active scalar field is available or not.
bool m_colorsDisplayed
Specifies whether colors should be displayed.
virtual bool hasColors() const
Returns whether colors are enabled or not.
virtual void lockVisibility(bool state)
Locks/unlocks visibility.
virtual void setVisible(bool state)
Sets entity visibility.
virtual bool sfShown() const
Returns whether active scalar field is visible.
bool m_visible
Specifies whether the object is visible or not.
virtual void applyDisplayState(const DisplayState &state)
Applies a display state.
virtual void translateGL(const CCVector3 &trans)
Translates current GL transformation by a rotation matrix.
virtual bool normalsShown() const
Returns whether normals are shown or not.
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 setTempColor(const ecvColor::Rgb &col, bool autoActivate=true)
Sets current temporary (unique)
ccGLMatrix m_glTrans
Current GL transformation.
virtual void setFixedId(bool state)
virtual void showNameIn3D(bool state)
Sets whether name should be displayed in 3D.
virtual void enableTempColor(bool state)
Set temporary color activation state.
virtual void showNormals(bool state)
Sets normals visibility.
virtual void enableGLTransformation(bool state)
Enables/disables associated GL transformation.
std::vector< DisplayState::Shared > m_displayStateStack
The stack of pushed display states.
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 void setOpacity(float opacity)
Set opacity activation state.
virtual void rotateGL(const ccGLMatrix &rotMat)
Multiplies (left) current GL transformation by a rotation matrix.
virtual void resetGLTransformation()
Resets associated GL transformation.
bool m_colorIsOverridden
Temporary (unique) color activation state.
virtual void popDisplayState(bool apply=true)
Pops the last pushed display state.
bool m_normalsDisplayed
Specifies whether normals should be displayed.
virtual void getDrawingParameters(glDrawParams &params) const
Returns main OpenGL parameters for this entity.
ccClipPlaneSet m_clipPlanes
Active clipping planes (used for display only)
ecvColor::Rgb m_tempColor
Temporary (unique) color.
virtual void setSelected(bool state)
Selects/Unselects entity.
virtual void toIdentity()
Sets matrix to identity.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
RGB color structure.
Definition: ecvColorTypes.h:49
ImGuiContext * context
Definition: Window.cpp:76
constexpr Rgb white(MAX, MAX, MAX)
Simple (clipping) plane equation.
QSharedPointer< DisplayState > Shared
Display context.
Display parameters of a 3D entity.
bool showColors
Display colors.
bool showNorms
Display normals.
bool showSF
Display scalar field (prioritary on colors)