ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ScalarFieldWrappers.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 // ##########################################################################
11 // # #
12 // # ACLOUDVIEWER PLUGIN: q3DMASC #
13 // # #
14 // # This program is free software; you can redistribute it and/or modify #
15 // # it under the terms of the GNU General Public License as published by #
16 // # the Free Software Foundation; version 2 or later of the License. #
17 // # #
18 // # This program is distributed in the hope that it will be useful, #
19 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 // # GNU General Public License for more details. #
22 // # #
23 // # COPYRIGHT: Dimitri Lague / CNRS / UEB #
24 // # #
25 // ##########################################################################
26 
27 // qCC_db
28 #include <ecvPointCloud.h>
29 // CCLib
30 #include <ScalarField.h>
31 
32 // Qt
33 #include <QSharedPointer>
34 
36 public:
37  virtual ~IScalarFieldWrapper() {}
38  using Shared = QSharedPointer<IScalarFieldWrapper>;
39  virtual double pointValue(unsigned index) const = 0;
40  virtual bool isValid() const = 0;
41  virtual QString getName() const = 0;
42  virtual size_t size() const = 0;
43 };
44 
46 public:
48 
49  virtual inline double pointValue(unsigned index) const override {
50  return m_sf->at(index);
51  }
52  virtual inline bool isValid() const { return m_sf != nullptr; }
53  virtual inline QString getName() const { return m_sf->getName(); }
54  virtual size_t size() const override { return m_sf->size(); }
55 
56 protected:
58 };
59 
61 public:
64  QString name)
65  : m_sfp(sfp), m_sfq(sfq), m_name(name) {}
66 
67  virtual inline double pointValue(unsigned index) const override {
68  ScalarType p = m_sfp->getValue(index);
69  ScalarType q = m_sfq->getValue(index);
70  ScalarType ratio =
71  (std::abs(q) > std::numeric_limits<ScalarType>::epsilon()
72  ? p / q
73  : NAN_VALUE);
74  return ratio;
75  }
76  virtual inline bool isValid() const {
77  return (m_sfp != nullptr && m_sfq != nullptr);
78  }
79  virtual inline QString getName() const { return m_name; }
80  virtual inline size_t size() const override {
81  return std::min(m_sfp->size(), m_sfq->size());
82  }
83 
84 protected:
86  QString m_name;
87 };
88 
90 public:
91  enum Mode { Dip = 0, DipDir = 1 };
92 
94  : m_cloud(cloud), m_mode(mode) {}
95 
96  virtual double pointValue(unsigned index) const override {
97  const CCVector3& N = m_cloud->getPointNormal(index);
98  PointCoordinateType dip_deg, dipDir_deg;
99  ccNormalVectors::ConvertNormalToDipAndDipDir(N, dip_deg, dipDir_deg);
100  return (m_mode == Dip ? dip_deg : dipDir_deg);
101  }
102  virtual inline bool isValid() const {
103  return m_cloud != nullptr && m_cloud->hasNormals();
104  }
105  virtual inline QString getName() const {
106  static const char s_names[][14] = {"Norm dip", "Norm dip dir."};
107  return s_names[m_mode];
108  }
109  virtual inline size_t size() const override { return m_cloud->size(); }
110 
111 protected:
114 };
115 
117 public:
118  enum Dim { DimX = 0, DimY = 1, DimZ = 2 };
119 
121  : m_cloud(cloud), m_dim(dim) {}
122 
123  virtual inline double pointValue(unsigned index) const override {
124  return m_cloud->getPoint(index)->u[m_dim];
125  }
126  virtual inline bool isValid() const { return m_cloud != nullptr; }
127  virtual inline QString getName() const {
128  static const char s_names[][5] = {"DimX", "DimY", "DimZ"};
129  return s_names[m_dim];
130  }
131  virtual inline size_t size() const override { return m_cloud->size(); }
132 
133 protected:
136 };
137 
139 public:
140  enum Band { Red = 0, Green = 1, Blue = 2 };
141 
143  : m_cloud(cloud), m_band(band) {}
144 
145  virtual inline double pointValue(unsigned index) const override {
146  return m_cloud->getPointColor(index).rgb[m_band];
147  }
148  virtual inline bool isValid() const {
149  return m_cloud != nullptr && m_cloud->hasColors();
150  }
151  virtual inline QString getName() const {
152  static const char s_names[][6] = {"Red", "Green", "Blue"};
153  return s_names[m_band];
154  }
155  virtual inline size_t size() const override { return m_cloud->size(); }
156 
157 protected:
160 };
constexpr ScalarType NAN_VALUE
NaN as a ScalarType value.
Definition: CVConst.h:76
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
std::string name
ColorScalarFieldWrapper(const ccPointCloud *cloud, Band band)
virtual bool isValid() const
const ccPointCloud * m_cloud
virtual size_t size() const override
virtual QString getName() const
virtual double pointValue(unsigned index) const override
const ccPointCloud * m_cloud
virtual double pointValue(unsigned index) const override
virtual size_t size() const override
virtual bool isValid() const
virtual QString getName() const
DimScalarFieldWrapper(const ccPointCloud *cloud, Dim dim)
virtual QString getName() const =0
virtual size_t size() const =0
QSharedPointer< IScalarFieldWrapper > Shared
virtual double pointValue(unsigned index) const =0
virtual bool isValid() const =0
virtual size_t size() const override
virtual QString getName() const
NormDipAndDipDirFieldWrapper(const ccPointCloud *cloud, Mode mode)
virtual double pointValue(unsigned index) const override
virtual size_t size() const override
ScalarFieldRatioWrapper(cloudViewer::ScalarField *sfp, cloudViewer::ScalarField *sfq, QString name)
virtual QString getName() const
cloudViewer::ScalarField * m_sfp
virtual double pointValue(unsigned index) const override
virtual bool isValid() const
cloudViewer::ScalarField * m_sfq
virtual bool isValid() const
cloudViewer::ScalarField * m_sf
virtual size_t size() const override
virtual QString getName() const
ScalarFieldWrapper(cloudViewer::ScalarField *sf)
virtual double pointValue(unsigned index) const override
Type u[3]
Definition: CVGeom.h:139
static void ConvertNormalToDipAndDipDir(const CCVector3 &N, PointCoordinateType &dip_deg, PointCoordinateType &dipDir_deg)
Converts a normal vector to geological 'dip direction & dip' parameters.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool hasNormals() const override
Returns whether normals are enabled or not.
bool hasColors() const override
Returns whether colors are enabled or not.
const ecvColor::Rgb & getPointColor(unsigned pointIndex) const override
Returns color corresponding to a given point.
const CCVector3 & getPointNormal(unsigned pointIndex) const override
Returns normal corresponding to a given point.
unsigned size() const override
Definition: PointCloudTpl.h:38
const CCVector3 * getPoint(unsigned index) const override
A simple scalar field (to be associated to a point cloud)
Definition: ScalarField.h:25
ScalarType & getValue(std::size_t index)
Definition: ScalarField.h:92
const char * getName() const
Returns scalar field name.
Definition: ScalarField.h:43
int min(int a, int b)
Definition: cutil_math.h:53
__host__ __device__ int2 abs(int2 v)
Definition: cutil_math.h:1267