ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvRasterGrid.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 "CV_db.h"
12 #include "ecvBBox.h"
13 
14 // system
15 #include <limits>
16 
18 class ccPointCloud;
19 class ecvProgressDialog;
20 
25  : h(std::numeric_limits<double>::quiet_NaN()),
26  avgHeight(0),
27  stdDevHeight(0),
28  minHeight(0),
29  maxHeight(0),
30  nbPoints(0),
31  pointIndex(0),
32  color(0, 0, 0) {}
33 
35  double h;
37  double avgHeight;
39  double stdDevHeight;
45  unsigned nbPoints;
47  unsigned pointIndex;
50 };
51 
55  ccRasterGrid();
56 
58  virtual ~ccRasterGrid();
59 
61  static bool ComputeGridSize(unsigned char Z,
62  const ccBBox& box,
63  double gridStep,
64  unsigned& width,
65  unsigned& height);
66 
68  bool init(unsigned w,
69  unsigned h,
70  double gridStep,
71  const CCVector3d& minCorner);
72 
74  void clear();
76  void reset();
77 
91  };
92 
94  static QString GetDefaultFieldName(ExportableFields field);
95 
97  ccPointCloud* convertToCloud(
98  const std::vector<ExportableFields>& exportedFields,
99  bool interpolateSF,
100  bool interpolateColors,
101  bool resampleInputCloudXY,
102  bool resampleInputCloudZ, // only considered if
103  // resampleInputCloudXY is true!
104  ccGenericPointCloud* inputCloud,
105  unsigned char Z,
106  const ccBBox& box,
107  bool fillEmptyCells,
108  double emptyCellsHeight,
109  bool exportToOriginalCS) const;
110 
113  PROJ_MINIMUM_VALUE = 0,
114  PROJ_AVERAGE_VALUE = 1,
115  PROJ_MAXIMUM_VALUE = 2,
116  PROJ_MEDIAN_VALUE = 3,
117  PROJ_INVERSE_VAR_VALUE = 4,
118  INVALID_PROJECTION_TYPE = 255,
119  };
120 
122  enum class InterpolationType { NONE = 0, DELAUNAY = 1 };
123 
125 
129  bool fillWith(ccGenericPointCloud* cloud,
130  unsigned char projectionDimension,
131  ProjectionType projectionType,
132  bool interpolateEmptyCells,
133  ProjectionType sfInterpolation = INVALID_PROJECTION_TYPE,
134  ecvProgressDialog* progressDialog = nullptr);
135 
138  LEAVE_EMPTY = 0,
139  FILL_MINIMUM_HEIGHT = 1,
140  FILL_MAXIMUM_HEIGHT = 2,
141  FILL_CUSTOM_HEIGHT = 3,
142  FILL_AVERAGE_HEIGHT = 4,
143  INTERPOLATE_DELAUNAY = 5,
144  KRIGING = 6,
145  };
146 
149  static InterpolationType InterpolationTypeFromEmptyCellFillOption(
150  EmptyCellFillOption option);
151 
153  void fillEmptyCells(EmptyCellFillOption fillEmptyCellsStrategy,
154  double customCellHeight = 0);
155 
157  unsigned updateNonEmptyCellCount();
158 
160  void updateCellStats();
161 
163  inline void setValid(bool state) { valid = state; }
165  inline bool isValid() const { return valid; }
166 
168  std::pair<int, int> computeCellPos(const CCVector3& P,
169  unsigned char X,
170  unsigned char Y) const {
171  CCVector3d relativePos = CCVector3d::fromArray(P.u) - minCorner;
172 
173  // DGM: we use the 'PixelIsArea' convention
174  int i = static_cast<int>((relativePos.u[X] / gridStep + 0.5));
175  int j = static_cast<int>((relativePos.u[Y] / gridStep + 0.5));
176 
177  return {i, j};
178  }
179 
182  int j,
183  unsigned char X,
184  unsigned char Y) const {
185  return {minCorner.u[X] + (i + 0.5) * gridStep,
186  minCorner.u[Y] + (j + 0.5) * gridStep};
187  }
188 
190  using Row = std::vector<ccRasterCell>;
191 
193  std::vector<Row> rows;
194 
196  using SF = std::vector<double>;
197 
199  std::vector<SF> scalarFields;
200 
202  unsigned width;
204  unsigned height;
206  double gridStep;
209 
211  double minHeight;
213  double maxHeight;
215  double meanHeight;
219  unsigned validCellCount;
220 
222  bool hasColors;
223 
225  bool valid;
226 };
ccRasterCell::maxHeight
PointCoordinateType maxHeight
Max height value.
Definition: ecvRasterGrid.h:43
ccRasterGrid::PER_CELL_VALUE
@ PER_CELL_VALUE
Definition: ecvRasterGrid.h:80
ccRasterCell::h
double h
Height value.
Definition: ecvRasterGrid.h:35
ccRasterCell::pointIndex
unsigned pointIndex
Nearest point index (if any)
Definition: ecvRasterGrid.h:47
ccEntityAction::interpolateColors
bool interpolateColors(const ccHObject::Container &selectedEntities, QWidget *parent)
Interpolate colors from on entity and transfer them to another one.
Definition: ecvEntityAction.cpp:292
ccRasterGrid::PER_CELL_MIN_VALUE
@ PER_CELL_MIN_VALUE
Definition: ecvRasterGrid.h:82
ccBBox
Bounding box structure.
Definition: ecvBBox.h:25
ecvBBox.h
ccRasterGrid::rows
std::vector< Row > rows
All cells.
Definition: ecvRasterGrid.h:193
ccPointCloud
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Definition: ecvPointCloud.h:146
ccRasterGrid::PER_CELL_VALUE_RANGE
@ PER_CELL_VALUE_RANGE
Definition: ecvRasterGrid.h:86
ccRasterCell::stdDevHeight
double stdDevHeight
Height std.dev.
Definition: ecvRasterGrid.h:39
ccRasterGrid::PER_CELL_MAX_VALUE
@ PER_CELL_MAX_VALUE
Definition: ecvRasterGrid.h:83
ccRasterGrid::InterpolationType
InterpolationType
Types of interpolation.
Definition: ecvRasterGrid.h:122
ccRasterGrid
Raster grid type.
Definition: ecvRasterGrid.h:53
ccRasterCell
Raster grid cell.
Definition: ecvRasterGrid.h:22
color
math::float4 color
Definition: LineSetBuffers.cpp:46
ccRasterGrid::computeCellCenter
CCVector2d computeCellCenter(int i, int j, unsigned char X, unsigned char Y) const
Computes the position of the center of a given cell.
Definition: ecvRasterGrid.h:181
ccRasterCell::ccRasterCell
ccRasterCell()
Default constructor.
Definition: ecvRasterGrid.h:24
width
int width
Definition: FileIOFactory.cpp:142
Vector2Tpl< double >
ccRasterCell::avgHeight
double avgHeight
Average height value.
Definition: ecvRasterGrid.h:37
height
int height
Definition: FileIOFactory.cpp:143
ccGenericPointCloud
A 3D cloud interface with associated features (color, normals, octree, etc.)
Definition: ecvGenericPointCloud.h:45
ccRasterGrid::PER_CELL_PERCENTILE_VALUE
@ PER_CELL_PERCENTILE_VALUE
Definition: ecvRasterGrid.h:88
ccRasterCell::color
CCVector3d color
Color.
Definition: ecvRasterGrid.h:49
ccRasterGrid::minHeight
double minHeight
Min height (computed on the NON-EMPTY or INTERPOLATED cells)
Definition: ecvRasterGrid.h:211
Vector3Tpl< double >
ccRasterGrid::computeCellPos
std::pair< int, int > computeCellPos(const CCVector3 &P, unsigned char X, unsigned char Y) const
Computes the position of the cell that includes a given point.
Definition: ecvRasterGrid.h:168
ccRasterGrid::validCellCount
unsigned validCellCount
Number of VALID cells.
Definition: ecvRasterGrid.h:219
ccRasterGrid::scalarFields
std::vector< SF > scalarFields
Associated scalar fields.
Definition: ecvRasterGrid.h:199
ccRasterGrid::hasColors
bool hasColors
Whether the (average) colors are available or not.
Definition: ecvRasterGrid.h:222
ccRasterGrid::minCorner
CCVector3d minCorner
Min corner (3D)
Definition: ecvRasterGrid.h:208
ecvProgressDialog
Graphical progress indicator (thread-safe)
Definition: ecvProgressDialog.h:27
ccRasterCell::minHeight
PointCoordinateType minHeight
Min height value.
Definition: ecvRasterGrid.h:41
ccRasterGrid::PER_CELL_COUNT
@ PER_CELL_COUNT
Definition: ecvRasterGrid.h:81
ccRasterGrid::height
unsigned height
Number of rows.
Definition: ecvRasterGrid.h:204
ccRasterGrid::valid
bool valid
Whether the grid is valid/up-to-date.
Definition: ecvRasterGrid.h:225
ccRasterGrid::EmptyCellFillOption
EmptyCellFillOption
Option for handling empty cells.
Definition: ecvRasterGrid.h:137
ccRasterGrid::maxHeight
double maxHeight
Max height (computed on the NON-EMPTY or INTERPOLATED cells)
Definition: ecvRasterGrid.h:213
ccRasterGrid::ExportableFields
ExportableFields
Exportable fields.
Definition: ecvRasterGrid.h:79
ccRasterCell::nbPoints
unsigned nbPoints
Number of points projected in this cell.
Definition: ecvRasterGrid.h:45
ccRasterGrid::setValid
void setValid(bool state)
Sets valid.
Definition: ecvRasterGrid.h:163
CV_db.h
ccRasterGrid::Row
std::vector< ccRasterCell > Row
Row.
Definition: ecvRasterGrid.h:190
ccRasterGrid::PER_CELL_MEDIAN_VALUE
@ PER_CELL_MEDIAN_VALUE
Definition: ecvRasterGrid.h:87
ccRasterGrid::nonEmptyCellCount
unsigned nonEmptyCellCount
Number of NON-EMPTY cells.
Definition: ecvRasterGrid.h:217
ccRasterGrid::PER_CELL_UNIQUE_COUNT_VALUE
@ PER_CELL_UNIQUE_COUNT_VALUE
Definition: ecvRasterGrid.h:89
std
Definition: Eigen.h:85
ccRasterGrid::isValid
bool isValid() const
Returns whether the grid is 'valid' or not.
Definition: ecvRasterGrid.h:165
ccRasterGrid::PER_CELL_AVG_VALUE
@ PER_CELL_AVG_VALUE
Definition: ecvRasterGrid.h:84
ccRasterGrid::gridStep
double gridStep
Grid step ('pixel' size)
Definition: ecvRasterGrid.h:206
ccRasterGrid::PER_CELL_INVALID
@ PER_CELL_INVALID
Definition: ecvRasterGrid.h:90
CV_DB_LIB_API
#define CV_DB_LIB_API
Definition: CV_db.h:15
ccRasterGrid::PER_CELL_VALUE_STD_DEV
@ PER_CELL_VALUE_STD_DEV
Definition: ecvRasterGrid.h:85
X
void * X
Definition: SmallVector.cpp:45
PointCoordinateType
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
Tuple3Tpl::u
Type u[3]
Definition: CVGeom.h:139
Vector3Tpl< double >::fromArray
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
ccRasterGrid::SF
std::vector< double > SF
Scalar field.
Definition: ecvRasterGrid.h:196
ccRasterGrid::ProjectionType
ProjectionType
Types of projection.
Definition: ecvRasterGrid.h:112
ccRasterGrid::meanHeight
double meanHeight
Average height (computed on the NON-EMPTY or INTERPOLATED cells)
Definition: ecvRasterGrid.h:215
ccRasterGrid::width
unsigned width
Number of columns.
Definition: ecvRasterGrid.h:202