Debian Codegraph @

plugins/core/Standard/qSRA/include/distanceMapGenerationTool.h

raw
1 //##########################################################################
2 //# #
3 //# CLOUDCOMPARE PLUGIN: qSRA #
4 //# #
5 //# This program is free software; you can redistribute it and/or modify #
6 //# it under the terms of the GNU General Public License as published by #
7 //# the Free Software Foundation; version 2 or later of the License. #
8 //# #
9 //# This program is distributed in the hope that it will be useful, #
10 //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
11 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12 //# GNU General Public License for more details. #
13 //# #
14 //# COPYRIGHT: EDF #
15 //# #
16 //##########################################################################
17
18 #ifndef QSRA_DISTANCE_MAP_GENERATION_TOOL_HEADER
19 #define QSRA_DISTANCE_MAP_GENERATION_TOOL_HEADER
20
21 //Qt
22 #include <QSharedPointer>
23 #include <QImage>
24
25 //CCCoreLib
26 #include <CCGeom.h>
27
28 //qCC_db
29 #include <ccColorScale.h>
30 #include <ccGLMatrix.h>
31
32 //system
33 #include <vector>
34
35 class ccPointCloud;
36 class ccMesh;
37 class ccPolyline;
38 class ccScalarField;
39 class ccMainAppInterface;
40
41 //Default radial distance scalar field name
42 const char RADIAL_DIST_SF_NAME[] = "Radial distance";
43 //Default radii scalar field name
44 const char RADII_SF_NAME[] = "Radius";
45
46 //! Distance map generation tool (surface of revolution)
47 class DistanceMapGenerationTool
48 {
49 public:
50
51 struct ProfileMetaData
52 {
53 ProfileMetaData()
54 : revolDim(2)
55 , origin(0, 0, 0)
56 , heightShift(0)
57 , hasAxis(false)
58 , axis(0, 0, 1)
59 {}
60
61 ccGLMatrix computeCloudToSurfaceOriginTrans() const;
62 ccGLMatrix computeCloudToProfileOriginTrans() const;
63
64 int revolDim; //!< revolution axis (X=0, Y=1, Z=2)
65 CCVector3 origin; //!< origin of the surface of revolution
66 PointCoordinateType heightShift; //!< virtual shift of the profile coordinates along the revolution axis and relative to the origin
67 bool hasAxis; //!< whether a custom revolution axis has been defined or not
68 CCVector3 axis; //!< custom revolution axis
69 };
70
71 //! Returns the whole set of meta-data associated to a given polyline/profile
72 /** \return whether the profile is valid or not
73 **/
74 static bool GetPoylineMetaData(const ccPolyline* polyline, ProfileMetaData& data);
75
76 //! Sets the origin of a given polyline/profile
77 /** The revolution axis is associated to a specific meta-data.
78 **/
79 static void SetPoylineOrigin(ccPolyline* polyline, const CCVector3& origin);
80
81 //! Returns the origin associated to a given polyline/profile
82 /** Requires the right meta-data to be set (see SetPoylineOrigin).
83 \return whether an origin is defined or not
84 **/
85 static bool GetPoylineOrigin(const ccPolyline* polyline, CCVector3& origin);
86
87 //! Sets the revolution dimension of a given polyline
88 /** The revolution dimension is associated to a specific meta-data.
89 **/
90 static void SetPoylineRevolDim(ccPolyline* polyline, int revolDim);
91
92 //! Returns the revolution 'dimension' associated to a given profile (polyline)
93 /** Requires the right meta-data to be set (see SetPoylineRevolDim).
94 \return 0 (X), 1 (Y), 2 (Z) or -1 if no revolution dimension is defined
95 **/
96 static int GetPoylineRevolDim(const ccPolyline* polyline);
97
98 //! Sets the revolution axis of a given polyline
99 /** The revolution axis is associated to a specific meta-data.
100 **/
101 static void SetPoylineAxis(ccPolyline* polyline, const CCVector3& axis);
102
103 //! Returns the revolution axis associated to a given profile (polyline)
104 /** Requires the right meta-data to be set (see SetPoylineAxis).
105 \return whether an axis is defined or not
106 **/
107 static bool GetPoylineAxis(const ccPolyline* polyline, CCVector3& axis);
108
109 //! Sets the profile 'height shift' (i.e. along the revolution axis)
110 /** This information is associated to a specific meta-data.
111 **/
112 static void SetPolylineHeightShift(ccPolyline* polyline, PointCoordinateType heightShift);
113
114 //! Returns the profile 'height shift' (i.e. along the revolution axis)
115 /** Requires the right meta-data to be set (see SetPolylineHeightShift).
116 \return whether a height shift is defined or not
117 **/
118 static bool GetPolylineHeightShift(const ccPolyline* polyline, PointCoordinateType& heightShift);
119
120 //! Computes radial distance between cloud and a profile
121 static bool ComputeRadialDist( ccPointCloud* cloud,
122 ccPolyline* profile,
123 bool storeRadiiAsSF = false,
124 ccMainAppInterface* app = nullptr);
125
126 //! "Distance" map cell
127 struct MapCell
128 {
129 //! Default constructor
130 MapCell()
131 : value(0)
132 , count(0)
133 {}
134
135 //! Value
136 double value;
137 //! Number of values projected in this cell (for average computation)
138 unsigned count;
139 };
140
141 //! "Distance" map
142 class Map : public std::vector<MapCell>
143 {
144 public:
145 Map()
146 : xSteps(0)
147 , xMin(0.0)
148 , xMax(0.0)
149 , xStep(1.0)
150 , ySteps(0)
151 , yMin(0.0)
152 , yMax(0.0)
153 , yStep(1.0)
154 , conical(false)
155 , minVal(0.0)
156 , maxVal(0.0)
157 , counterclockwise(false)
158 , conicalSpanRatio(0)
159 {}
160
161 unsigned xSteps;
162 double xMin;
163 double xMax;
164 double xStep;
165
166 unsigned ySteps;
167 double yMin;
168 double yMax;
169 double yStep;
170
171 //conical (true) or cylindrical (false) projection
172 bool conical;
173
174 //min and max values
175 double minVal;
176 double maxVal;
177
178 //! Motion direction
179 /** Counter-clockwise (true) or clockwise (false)
180 **/
181 bool counterclockwise;
182
183 //! Spanning ratio
184 /** (for conical projection only) **/
185 double conicalSpanRatio;
186 };
187
188 //! Grid filling strategy
189 enum FillStrategyType { FILL_STRAT_MIN_DIST = 0,
190 FILL_STRAT_AVG_DIST = 1,
191 FILL_STRAT_MAX_DIST = 2,
192 INVALID_STRATEGY_TYPE = 255,
193 };
194
195 //! Option for handling empty cells
196 enum EmptyCellFillOption { LEAVE_EMPTY = 0,
197 FILL_WITH_ZERO = 1,
198 FILL_INTERPOLATE = 2,
199 };
200
201 //! Projects a cloud (scalar field) on a revolution surface to generate a 2D map
202 /** Projection can be either cylindrical or spherical.
203 Warning: for cylindrical projection, the 2D map 'height' will be expressed
204 relatively to the 'revolutionOrigin' and not the cloud's (implicit) origin.
205 **/
206 static QSharedPointer<Map> CreateMap( ccPointCloud* cloud,
207 ccScalarField* sf,
208 const ccGLMatrix& cloudToSurface, //e.g. translation to the revolution origin
209 unsigned char revolutionAxisDim,
210 double angStep_rad,
211 double yStep,
212 double yMin,
213 double yMax,
214 bool conical,
215 bool counterclockwise,
216 FillStrategyType fillStrategy,
217 EmptyCellFillOption emptyCellfillOption,
218 ccMainAppInterface* app = nullptr);
219
220
221 //! Creates a conical projection (textured) mesh
222 static ccMesh* ConvertConicalMapToMesh( const QSharedPointer<Map>& map,
223 bool counterclockwise,
224 QImage mapTexture = QImage());
225
226
227 //! Returns the constant 'n' factor of a Lambert conform conical projection with two intersecting parallels
228 static double ConicalProjectN(double phi1, double phi2);
229
230 //! Projects a given latitude with a Lambert conform conical projection with two intersecting parallels
231 static double ConicalProject(double phi, double phi1, double n);
232
233 //! Converts a point cloud coordinates to "cylindrical" ones (in place)
234 static bool ConvertCloudToCylindrical( ccPointCloud* cloud,
235 const ccGLMatrix& cloudToSurface, //e.g. translation to the revolution origin
236 unsigned char revolutionAxisDim,
237 bool counterclockwise = false);
238
239 //! Converts a point cloud coordinates to "conical" ones (in place)
240 /** See ProjectPointOnCone.
241 **/
242 static bool ConvertCloudToConical( ccPointCloud* cloud,
243 const ccGLMatrix& cloudToSurface, //e.g. translation to the revolution origin
244 unsigned char revolutionAxisDim,
245 double latMin_rad,
246 double latMax_rad,
247 double conicalSpanRatio = 1.0,
248 bool counterclockwise = false);
249
250 //! Projects a (longitude,r) couple to a 2D map
251 /** For computing 'nProj' see ConicalProjectN.
252 **/
253 static CCVector3 ProjectPointOnCone( double lon_rad,
254 double lat_rad,
255 double latMin_rad,
256 double nProj,
257 bool counterclockwise);
258
259 //! Computes min and max latitudes of a point cloud (relatively to an axis and an 'origin')
260 static bool ComputeMinAndMaxLatitude_rad( ccPointCloud* cloud,
261 double& minLat_rad,
262 double& maxLat_rad,
263 const ccGLMatrix& cloudToSurfaceOrigin, //e.g. translation to the revolution origin
264 unsigned char revolutionAxisDim);
265
266 //! Saves a map as a CSV matrix
267 static bool SaveMapAsCSVMatrix( const QSharedPointer<Map>& map,
268 QString filename,
269 QString xUnit,
270 QString yUnit,
271 double xConversionFactor = 1.0,
272 double yConversionFactor = 1.0,
273 ccMainAppInterface* app = nullptr);
274
275 //! Converts map to a QImage
276 static QImage ConvertMapToImage( const QSharedPointer<Map>& map,
277 ccColorScale::Shared colorScale,
278 unsigned colorScaleSteps = ccColorScale::MAX_STEPS);
279
280 //! Converts map to a point cloud
281 static ccPointCloud* ConvertMapToCloud( const QSharedPointer<Map>& map,
282 ccPolyline* profile,
283 double baseRadius = 1.0,
284 bool keepNaNPoints = true);
285
286 //! Converts profile to a (textured) mesh
287 static ccMesh* ConvertProfileToMesh(ccPolyline* profile,
288 const ccGLMatrix& cloudToProfile, //e.g. translation to the profile origin
289 bool counterclockwise,
290 unsigned angularSteps = 36,
291 QImage mapTexture = QImage());
292
293 //! Various "measures" that can be computed with the map (surfacces, volumes)
294 struct Measures
295 {
296 double total;
297 double theoretical;
298 double positive;
299 double negative;
300
301 Measures() : total(0), theoretical(0), positive(0), negative(0) {}
302 };
303
304 //! Computes various surfaces and volumes (see Surfaces & Volumes structures)
305 /** Warning: the 'positive' resp. 'negative' volumes coorespond to differences
306 of volumes (i.e the volume that is exterior resp. interori to the theoretical
307 profile). However, the 'positive' resp. 'negative' surfaces correspond to the
308 surface of all the elements that have a positive resp. negative deviation.
309 **/
310 static bool ComputeSurfacesAndVolumes( const QSharedPointer<Map>& map,
311 ccPolyline* profile,
312 Measures& surfaces,
313 Measures& volumes);
314 };
315
316 #endif //QSRA_DISTANCE_MAP_GENERATION_TOOL_HEADER
317