ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccSNECloud.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 "ccSNECloud.h"
9 
10 #include <ecvDisplayTools.h>
11 #include <ecvScalarField.h>
12 
13 // #include <ccColorRampShader.h>
14 // pass ctors straight to ccPointCloud
16 
18  // copy points, normals and scalar fields from obj.
19  *this += obj;
20 
21  // set name
22  setName(obj->getName());
23 
24  // update metadata
26 }
27 
29  // add metadata tag defining the ccCompass class type
30  QVariantMap* map = new QVariantMap();
31  map->insert("ccCompassType", "SNECloud");
32  setMetaData(*map, true);
33 }
34 
35 // returns true if object is a lineation
37  if (object->hasMetaData("ccCompassType")) {
38  return object->getMetaData("ccCompassType")
39  .toString()
40  .contains("SNECloud");
41  }
42  return false;
43 }
44 
46  if (!MACRO_Foreground(context)) // 2D foreground only
47  return; // do nothing
48 
49  // draw point cloud
51 
52  // draw normal vectors
53  if (MACRO_Draw3D(context)) {
54  if (size() == 0) // no points -> bail!
55  return;
56 
57  // get the set of OpenGL functions (version 2.1)
58  if (ecvDisplayTools::GetCurrentScreen() == nullptr) {
59  assert(false);
60  return;
61  }
62 
63  // get camera info
64  ccGLCameraParameters camera;
66  const ecvViewportParameters& viewportParams =
68 
69  // get point size for drawing
70  float pSize = context.defaultPointSize;
71  /*glFunc->glGetFloatv(GL_POINT_SIZE, &pSize);*/
72 
73  // setup
74  if (pSize != 0) {
75  // glFunc->glPushAttrib(GL_LINE_BIT);
76  // glFunc->glLineWidth(static_cast<GLfloat>(pSize));
77  context.defaultLineWidth = pSize;
78  }
79 
80  // glFunc->glMatrixMode(GL_MODELVIEW);
81  // glFunc->glPushMatrix();
82  // glFunc->glEnable(GL_BLEND);
83 
84  // get normal vector properties
85  int thickID = getScalarFieldIndexByName("Thickness");
86  if (thickID == -1) // if no thickness defined, try for "spacing"
87  {
88  thickID = getScalarFieldIndexByName("Spacing");
89  }
90 
91  // draw normals
92  // glFunc->glBegin(GL_LINES);
93  for (unsigned p = 0; p < size(); p++) {
94  // skip out-of-range points
95  if (m_currentDisplayedScalarField != nullptr) {
99  ->getValue(p))) {
100  continue;
101  }
102  }
103  }
104 
105  // skip hidden points
107  if (m_pointsVisibility[p] != POINT_VISIBLE &&
108  !m_pointsVisibility.empty()) {
109  continue; // skip this point
110  }
111  }
112 
113  // push color
114  if (m_currentDisplayedScalarField != nullptr) {
115  const ecvColor::Rgb* col =
118  const ecvColor::Rgba col4(col->r, col->g, col->b, 200);
119  // glFunc->glColor4ubv(col4.rgba);
120  } else {
121  const ecvColor::Rgba col4(200, 200, 200, 200);
122  // glFunc->glColor4ubv(col4.rgba);
123  }
124 
125  // get length from thickness (if defined)
126  float length = 1.0;
127  if (thickID != -1) {
128  length = getScalarField(thickID)->getValue(p);
129  }
130 
131  // calculate start and end points of normal vector
132  const CCVector3 start = *getPoint(p);
133  CCVector3 end = start + (getPointNormal(p) * length);
134 
135  // push line to opengl
136  // ccGL::Vertex3v(glFunc, start.u);
137  // ccGL::Vertex3v(glFunc, end.u);
138  }
139  // glFunc->glEnd();
140 
141  // cleanup
142  // if (pSize != 0) {
143  // glFunc->glPopAttrib();
144  // }
145  // glFunc->glPopMatrix();
146  }
147 }
constexpr unsigned char POINT_VISIBLE
Definition: CVConst.h:92
VisibilityTableType m_pointsVisibility
Per-point visibility table.
virtual bool isVisibilityTableInstantiated() const
Returns whether the visibility array is allocated or not.
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
void setMetaData(const QString &key, const QVariant &data)
Sets a meta-data element.
bool hasMetaData(const QString &key) const
Returns whether a meta-data element with the given key exists or not.
virtual void setName(const QString &name)
Sets object name.
Definition: ecvObject.h:75
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
ccScalarField * m_currentDisplayedScalarField
Currently displayed scalar field.
const CCVector3 & getPointNormal(unsigned pointIndex) const override
Returns normal corresponding to a given point.
static bool isSNECloud(ccHObject *obj)
Definition: ccSNECloud.cpp:36
virtual void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
Definition: ccSNECloud.cpp:45
void updateMetadata()
Definition: ccSNECloud.cpp:28
bool isInRange(ScalarType val) const
Returns whether a value is inside range or not.
const Range & displayRange() const
Access to the range of displayed values.
const ecvColor::Rgb * getColor(ScalarType value) const
bool areNaNValuesShownInGrey() const
Returns whether NaN values are displayed in gray or hidden.
int getScalarFieldIndexByName(const char *name) const
Returns the index of a scalar field represented by its name.
ScalarField * getScalarField(int index) const
Returns a pointer to a specific scalar field.
unsigned size() const override
Returns the number of points.
Definition: PointCloudTpl.h:38
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
ScalarType & getValue(std::size_t index)
Definition: ScalarField.h:92
RGB color structure.
Definition: ecvColorTypes.h:49
RGBA color structure.
static void GetGLCameraParameters(ccGLCameraParameters &params)
Returns the current OpenGL camera parameters.
static const ecvViewportParameters & GetViewportParameters()
static QWidget * GetCurrentScreen()
Standard parameters for GL displays/viewports.
__host__ __device__ float length(float2 v)
Definition: cutil_math.h:1162
#define MACRO_Draw3D(context)
#define MACRO_Foreground(context)
ImGuiContext * context
Definition: Window.cpp:76
OpenGL camera parameters.
Display context.