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 
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 };
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
#define CV_DB_LIB_API
Definition: CV_db.h:15
int width
int height
math::float4 color
void * X
Definition: SmallVector.cpp:45
Type u[3]
Definition: CVGeom.h:139
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
Bounding box structure.
Definition: ecvBBox.h:25
A 3D cloud interface with associated features (color, normals, octree, etc.)
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Graphical progress indicator (thread-safe)
bool interpolateColors(const ccHObject::Container &selectedEntities, QWidget *parent)
Interpolate colors from on entity and transfer them to another one.
Definition: Eigen.h:85
Raster grid cell.
Definition: ecvRasterGrid.h:22
double avgHeight
Average height value.
Definition: ecvRasterGrid.h:37
CCVector3d color
Color.
Definition: ecvRasterGrid.h:49
double h
Height value.
Definition: ecvRasterGrid.h:35
unsigned nbPoints
Number of points projected in this cell.
Definition: ecvRasterGrid.h:45
ccRasterCell()
Default constructor.
Definition: ecvRasterGrid.h:24
unsigned pointIndex
Nearest point index (if any)
Definition: ecvRasterGrid.h:47
PointCoordinateType maxHeight
Max height value.
Definition: ecvRasterGrid.h:43
PointCoordinateType minHeight
Min height value.
Definition: ecvRasterGrid.h:41
double stdDevHeight
Height std.dev.
Definition: ecvRasterGrid.h:39
Raster grid type.
Definition: ecvRasterGrid.h:53
InterpolationType
Types of interpolation.
ExportableFields
Exportable fields.
Definition: ecvRasterGrid.h:79
@ PER_CELL_UNIQUE_COUNT_VALUE
Definition: ecvRasterGrid.h:89
@ PER_CELL_PERCENTILE_VALUE
Definition: ecvRasterGrid.h:88
@ PER_CELL_VALUE_STD_DEV
Definition: ecvRasterGrid.h:85
CCVector2d computeCellCenter(int i, int j, unsigned char X, unsigned char Y) const
Computes the position of the center of a given cell.
unsigned validCellCount
Number of VALID cells.
unsigned nonEmptyCellCount
Number of NON-EMPTY cells.
void setValid(bool state)
Sets valid.
ProjectionType
Types of projection.
double gridStep
Grid step ('pixel' size)
std::vector< ccRasterCell > Row
Row.
unsigned height
Number of rows.
bool hasColors
Whether the (average) colors are available or not.
double meanHeight
Average height (computed on the NON-EMPTY or INTERPOLATED cells)
std::vector< double > SF
Scalar field.
std::vector< SF > scalarFields
Associated scalar fields.
CCVector3d minCorner
Min corner (3D)
std::vector< Row > rows
All cells.
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.
double maxHeight
Max height (computed on the NON-EMPTY or INTERPOLATED cells)
bool isValid() const
Returns whether the grid is 'valid' or not.
unsigned width
Number of columns.
EmptyCellFillOption
Option for handling empty cells.
static InterpolationType InterpolationTypeFromEmptyCellFillOption(EmptyCellFillOption option)
bool valid
Whether the grid is valid/up-to-date.
double minHeight
Min height (computed on the NON-EMPTY or INTERPOLATED cells)