FlowEngine 7.517
Photogrammetry Software Development Kit
Loading...
Searching...
No Matches
Utilities.h
Go to the documentation of this file.
1/*
2 *
3 * C@@o ____ _____ __ _
4 * oC8@@@@@@@o |___ \| __ \ / _| |
5 * o@@@@@@@@@@@@O __) | | | | |_| | _____ __
6 * O@O 8@@@@@@@@@O |__ <| | | | _| |/ _ \ \ /\ / /
7 * o@@@@@@@O OOOOOCo ___) | |__| | | | | (_) \ V V /
8 * C@@@@@@@@@@@@Oo |____/|_____/|_| |_|\___/ \_/\_/
9 * o8@@@@@@@@@@@@@@@@8OOCCCC
10 * oO@@@@@@@@@@@@@@@@@@@o 3Dflow s.r.l. - www.3dflow.net
11 * oO8@@@@@@@@@@@@o Copyright 2022
12 * oO88@@@@@@@@8OCo All Rights Reserved
13 * O@@@@@@@@@@@@@@@@@@@@@@@@@8OCCoooooooCCo
14 * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O
15 * @@@Oo oO8@@@@@@@@@@@@@@@@8
16 *
17 */
18
19#pragma once
20
21#include "CommonDef.h"
24#include "CameraInterface.h"
26#include "SettingsInterface.h"
30#include "StereoMeshInterface.h"
36#include "OrthophotoInterface.h"
42
43#include <string>
44#include <cstring>
45#include <memory>
46#include <iostream>
47
48namespace FlowEngine
49{
52 extern "C" FLE_DLL const char *GetResultMessage( Result inResult );
53
54 namespace Detail
55 {
56 template< typename T >
57 struct Destroyer;
58
60 template< >
61 struct Destroyer< SettingsInterface >
62 {
64 static void destroy( SettingsInterface *settings )
65 {
66 DestroySettings( settings );
67 }
68 };
69
71 template< >
72 struct Destroyer< CameraInterface >
73 {
75 static void destroy( CameraInterface *camera )
76 {
77 DestroyCamera( camera );
78 }
79 };
80
82 template< >
83 struct Destroyer< CameraCalibrationInterface >
84 {
86 static void destroy( CameraCalibrationInterface *calib )
87 {
89 }
90 };
91
93 template< >
94 struct Destroyer< CamerasLoaderInterface >
95 {
96 static void destroy( CamerasLoaderInterface *camerasLoader )
97 {
98 DestroyCamerasLoader( camerasLoader );
99 }
100 };
101
103 template< >
104 struct Destroyer< SparsePointCloudInterface >
105 {
107 static void destroy( SparsePointCloudInterface *pointCloud )
108 {
109 DestroySparsePointCloud( pointCloud );
110 }
111 };
112
114 template< >
115 struct Destroyer< StereoPointCloudInterface >
116 {
118 static void destroy( StereoPointCloudInterface *pointCloud )
119 {
120 DestroyStereoPointCloud( pointCloud );
121 }
122 };
123
125 template< >
126 struct Destroyer< StereoMeshInterface >
127 {
129 static void destroy( StereoMeshInterface *mesh )
130 {
131 DestroyStereoMesh( mesh );
132 }
133 };
134
136 template< >
137 struct Destroyer< StereoTexturedMeshInterface >
138 {
139 static void destroy( StereoTexturedMeshInterface *texturedMesh )
140 {
141 DestroyStereoTexturedMesh( texturedMesh );
142 }
143 };
144
146 template< >
147 struct Destroyer< WorkspaceLoaderInterface >
148 {
150 static void destroy( WorkspaceLoaderInterface *workspaceLoader )
151 {
152 DestroyWorkspaceLoader( workspaceLoader );
153 }
154 };
155
157 template< >
158 struct Destroyer< WorkspaceSaverInterface >
159 {
161 static void destroy( WorkspaceSaverInterface *workspaceSaver )
162 {
163 DestroyWorkspaceSaver( workspaceSaver );
164 }
165 };
166
168 template< >
169 struct Destroyer< ControlPointConstraintInterface >
170 {
172 static void destroy( ControlPointConstraintInterface *controlPoint )
173 {
174 DestroyControlPointConstraint( controlPoint );
175 }
176 };
177
179 template< >
180 struct Destroyer< BoundingBoxInterface >
181 {
183 static void destroy( BoundingBoxInterface *bb )
184 {
185 DestroyBoundingBox( bb );
186 }
187 };
188
190 template< >
191 struct Destroyer< OrthophotoInterface >
192 {
194 static void destroy( OrthophotoInterface *op )
195 {
196 DestroyOrthophoto( op );
197 }
198 };
199
201 template< >
202 struct Destroyer< ProjectedCoordinateSystemInterface >
203 {
205 static void destroy( ProjectedCoordinateSystemInterface *pcs )
206 {
208 }
209 };
210
212 template< >
213 struct Destroyer< CameraConstraintInterface >
214 {
216 static void destroy( CameraConstraintInterface *cc )
217 {
219 }
220 };
221
223 template< >
224 struct Destroyer< DynamicBufferInterface >
225 {
227 static void destroy( DynamicBufferInterface *ptr )
228 {
230 }
231 };
232
234 template< >
235 struct Destroyer< LicenseInfoInterface >
236 {
238 static void destroy( LicenseInfoInterface *ptr )
239 {
240 DestroyLicenseInfo( ptr );
241 }
242 };
243
244 template< typename T >
245 class UniquePtr final
246 {
247 public:
248
249 UniquePtr() = default;
250
251 UniquePtr( T *object )
252 : mObject( object )
253 { }
254
255 UniquePtr( UniquePtr &&other )
256 : mObject( other.release() )
257 { }
258
259 UniquePtr &operator =( UniquePtr &&other )
260 {
261 if ( this != &other )
262 {
263 reset( other.release() );
264 }
265
266 return *this;
267 }
268
269 ~UniquePtr()
270 {
271 reset();
272 }
273
274 public:
275
276 explicit operator bool() const
277 {
278 return mObject != nullptr;
279 }
280
281 T *operator ->()
282 {
283 return mObject;
284 }
285
286 const T *operator ->() const
287 {
288 return mObject;
289 }
290
291 T &operator *()
292 {
293 return *mObject;
294 }
295
296 const T &operator *() const
297 {
298 return *mObject;
299 }
300
301 public:
302
303 T *get() const
304 {
305 return mObject;
306 }
307
308 void reset( T *object = nullptr )
309 {
310 if ( mObject )
311 Detail::Destroyer< T >::destroy( mObject );
312
313 mObject = object;
314 }
315
316 T *release()
317 {
318 auto temp = mObject;
319 mObject = nullptr;
320 return temp;
321 }
322
323 private:
324
325 T *mObject = nullptr;
326 };
327 } // Detail namespace
328
330 template< typename T >
331 struct Buffer< T * >
332 {
333 static_assert( std::is_same< CameraInterface, T >::value ||
334 std::is_same< CamerasLoaderInterface, T >::value ||
335 std::is_same< ControlPointConstraintInterface, T >::value ||
336 std::is_same< SparsePointCloudInterface, T >::value ||
337 std::is_same< StereoPointCloudInterface, T >::value ||
338 std::is_same< StereoMeshInterface, T >::value ||
339 std::is_same< StereoTexturedMeshInterface, T >::value ||
340 std::is_same< CameraConstraintInterface, T >::value ||
341 std::is_same< ProjectedCoordinateSystemInterface, T >::value ||
342 std::is_same< BoundingBoxInterface, T >::value,
343 "This kind of buffer can only be used with object classes" );
344
346 T **data = nullptr;
347
349 Size count = 0;
350
351 Buffer() = default;
352
354 Buffer( std::vector< Detail::UniquePtr< T > > &v )
355 : data( v.empty() ? nullptr : reinterpret_cast< T ** >( v.data() ) )
356 , count( v.empty() ? 0 : v.size() )
357 {
358 static_assert( sizeof( Detail::UniquePtr< T > ) ==
359 sizeof( std::ptrdiff_t ), "" );
360 }
361
362 explicit operator bool() const
363 {
364 return data != nullptr;
365 }
366 };
367
369 template< typename T >
370 struct ConstBuffer< T * >
371 {
372 static_assert( std::is_same< CameraInterface, T >::value ||
373 std::is_same< CamerasLoaderInterface, T >::value ||
374 std::is_same< ControlPointConstraintInterface, T >::value ||
375 std::is_same< SparsePointCloudInterface, T >::value ||
376 std::is_same< StereoPointCloudInterface, T >::value ||
377 std::is_same< StereoMeshInterface, T >::value ||
378 std::is_same< StereoTexturedMeshInterface, T >::value ||
379 std::is_same< ProjectedCoordinateSystemInterface, T >::value ||
380 std::is_same< CameraConstraintInterface, T >::value ||
381 std::is_same< BoundingBoxInterface, T >::value,
382 "This kind of buffer can only be used with object classes" );
383
385 const T *const *data = nullptr;
386
388 Size count = 0;
389
390 ConstBuffer() = default;
391
393 ConstBuffer( const std::vector< Detail::UniquePtr< T > > &v )
394 : data( v.empty() ? nullptr : reinterpret_cast< const T *const * >( v.data() ) )
395 , count( v.empty() ? 0 : v.size() )
396 {
397 static_assert( sizeof( Detail::UniquePtr< T > ) ==
398 sizeof( std::ptrdiff_t ), "" );
399 }
400
401 explicit operator bool() const
402 {
403 return data != nullptr;
404 }
405 };
406
409 {
411 void messageLogged( const char *nMessage )
412 {
413 // strip log type
414 const std::size_t len = std::strlen( nMessage );
415
416 if ( len > 3 && nMessage[ 0 ] == '[' && nMessage[ 2 ] == ']' )
417 nMessage = nMessage + 3;
418
419 if ( mFileStream )
420 {
421 ( *mFileStream ) << nMessage;
422 mFileStream->flush();
423 }
424
425 std::cout << nMessage;
426 std::cout.flush();
427 }
428
430 std::ostream *mFileStream = nullptr;
431 };
432
435 {
437 void start( const char *nWindowTitle, bool nShowGlobalProgress, bool nShowCancelButton )
438 {
439
440 }
441
443 void finish()
444 {
445
446 }
447
449 void resetTicks( unsigned int nTicks, const char *nLoadingText )
450 {
451
452 }
453
455 void resetGlobalTicks( unsigned int nGlobalTicks, const char *nLoadingText )
456 {
457
458 }
459
461 void update()
462 {
463
464 }
465
468 {
469
470 }
471 };
472
474 using UniqueCameraPtr = Detail::UniquePtr< CameraInterface >;
475
477 using UniqueCameraCalibrationPtr = Detail::UniquePtr< CameraCalibrationInterface >;
478
480 using UniqueCamerasLoaderPtr = Detail::UniquePtr< CamerasLoaderInterface >;
481
483 using UniqueSparsePointCloudPtr = Detail::UniquePtr< SparsePointCloudInterface >;
484
486 using UniqueStereoPointCloudPtr = Detail::UniquePtr< StereoPointCloudInterface >;
487
489 using UniqueStereoMeshPtr = Detail::UniquePtr< StereoMeshInterface >;
490
492 using UniqueStereoTexturedMeshPtr = Detail::UniquePtr< StereoTexturedMeshInterface >;
493
495 using UniqueSettingsPtr = Detail::UniquePtr< SettingsInterface >;
496
498 using UniqueBoundingBoxPtr = Detail::UniquePtr< BoundingBoxInterface >;
499
501 using UniqueWorkspaceSaverPtr = Detail::UniquePtr< WorkspaceSaverInterface >;
502
504 using UniqueWorkspaceLoaderPtr = Detail::UniquePtr< WorkspaceLoaderInterface >;
505
507 using UniqueControlPointConstraintPtr = Detail::UniquePtr< ControlPointConstraintInterface >;
508
510 using UniqueOrthophotoPtr = Detail::UniquePtr< OrthophotoInterface >;
511
513 using UniqueProjectedCoordinateSystemPtr = Detail::UniquePtr< ProjectedCoordinateSystemInterface >;
514
516 using UniqueCameraConstraintPtr = Detail::UniquePtr< CameraConstraintInterface >;
517
519 using UniqueDynamicBufferPtr = Detail::UniquePtr< DynamicBufferInterface >;
520
522 using UniqueLicenseInfoPtr = Detail::UniquePtr< LicenseInfoInterface >;
523
540 extern "C" FLE_DLL
541 Result SampleEpipolarLine( const CameraInterface &referenceCamera,
542 const Point2 &referencePoint,
543 const CameraInterface &targetCamera,
544 int sampleCount,
545 Buffer< Point2 > inOutPoints );
546
548 extern "C" FLE_DLL
551 Buffer< int > inOutRatings );
552}
Stores a camera object to feed the Structure from Motion parameters.
Definition: CameraInterface.h:38
Pure virtual Log Listener interface.
Definition: LogListenerInterface.h:41
Pure virtual Progress Bar interface.
Definition: ProgressBarInterface.h:32
Definition: BoundingBoxInterface.cpp:26
void DestroyDynamicBuffer(DynamicBufferInterface *buf)
Definition: DynamicBufferInterface.cpp:32
void DestroyOrthophoto(OrthophotoInterface *orthophoto)
Definition: OrthophotoInterface.cpp:32
void DestroyProjectedCoordinateSystem(ProjectedCoordinateSystemInterface *pcs)
Definition: ProjectedCoordinateSystemInterface.cpp:32
Detail::UniquePtr< DynamicBufferInterface > UniqueDynamicBufferPtr
Automatically manages the lifetime of a DynamicBuffer object.
Definition: Utilities.h:519
Detail::UniquePtr< OrthophotoInterface > UniqueOrthophotoPtr
Automatically manages the lifetime of a Orthophoto object.
Definition: Utilities.h:510
void DestroyStereoTexturedMesh(StereoTexturedMeshInterface *stereoTexturedMesh)
Definition: StereoTexturedMeshInterface.cpp:32
void DestroyStereoPointCloud(StereoPointCloudInterface *stereoPointCloud)
Definition: StereoPointCloudInterface.cpp:32
void DestroyWorkspaceSaver(WorkspaceSaverInterface *workspaceSaver)
Definition: WorkspaceSaverInterface.cpp:32
Detail::UniquePtr< CameraConstraintInterface > UniqueCameraConstraintPtr
Automatically manages the lifetime of a CameraConstraint object.
Definition: Utilities.h:516
Result SampleEpipolarLine(const CameraInterface &referenceCamera, const Point2 &referencePoint, const CameraInterface &targetCamera, int sampleCount, Buffer< Point2 > inOutPoints)
Definition: Utilities.cpp:208
Detail::UniquePtr< StereoTexturedMeshInterface > UniqueStereoTexturedMeshPtr
Automatically manages the lifetime of a Stereo textured mesh object.
Definition: Utilities.h:492
void DestroyBoundingBox(BoundingBoxInterface *boundingBox)
Definition: BoundingBoxInterface.cpp:32
void DestroySettings(SettingsInterface *settings)
Definition: SettingsInterface.cpp:32
void DestroyWorkspaceLoader(WorkspaceLoaderInterface *workspaceLoader)
Definition: WorkspaceLoaderInterface.cpp:32
Result ComputeCamerasRating(Buffer< CameraInterface * > cameras, Buffer< Pair< CameraInterface *, Point2 > > selectedPoints, Buffer< int > inOutRatings)
Compute camera ratings based on point visibility.
Definition: Utilities.cpp:313
Detail::UniquePtr< WorkspaceSaverInterface > UniqueWorkspaceSaverPtr
Automatically manages the lifetime of a Workspace Saver object.
Definition: Utilities.h:501
void DestroyCamerasLoader(CamerasLoaderInterface *CamerasLoader)
Definition: CamerasLoaderInterface.cpp:32
const char * GetResultMessage(Result inResult)
Definition: Utilities.cpp:157
Detail::UniquePtr< CamerasLoaderInterface > UniqueCamerasLoaderPtr
Automatically manages the lifetime of a CamerasLoader object.
Definition: Utilities.h:480
void DestroyStereoMesh(StereoMeshInterface *stereoMesh)
Definition: StereoMeshInterface.cpp:32
void DestroyCameraConstraint(CameraConstraintInterface *cameraConstraint)
Definition: CameraConstraintInterface.cpp:32
Detail::UniquePtr< WorkspaceLoaderInterface > UniqueWorkspaceLoaderPtr
Automatically manages the lifetime of a Workspace Loader object.
Definition: Utilities.h:504
Detail::UniquePtr< CameraCalibrationInterface > UniqueCameraCalibrationPtr
Automatically manages the lifetime of a Camera calibration object.
Definition: Utilities.h:477
Detail::UniquePtr< StereoPointCloudInterface > UniqueStereoPointCloudPtr
Automatically manages the lifetime of a Stereo Point cloud object.
Definition: Utilities.h:486
Detail::UniquePtr< LicenseInfoInterface > UniqueLicenseInfoPtr
Automatically manages the lifetime of a LicenseInfo object.
Definition: Utilities.h:522
Detail::UniquePtr< BoundingBoxInterface > UniqueBoundingBoxPtr
Automatically manages the lifetime of a Bounding box object.
Definition: Utilities.h:498
void DestroySparsePointCloud(SparsePointCloudInterface *boundingBox)
Definition: SparsePointCloudInterface.cpp:32
Detail::UniquePtr< ControlPointConstraintInterface > UniqueControlPointConstraintPtr
Automatically manages the lifetime of a Control Point Constraint object.
Definition: Utilities.h:507
void DestroyLicenseInfo(LicenseInfoInterface *buf)
Definition: LicenseInfoInterface.cpp:32
void DestroyCamera(CameraInterface *camera)
Definition: CameraInterface.cpp:32
Detail::UniquePtr< StereoMeshInterface > UniqueStereoMeshPtr
Automatically manages the lifetime of a Stereo mesh object.
Definition: Utilities.h:489
Detail::UniquePtr< SparsePointCloudInterface > UniqueSparsePointCloudPtr
Automatically manages the lifetime of a Sparse Point Cloud object.
Definition: Utilities.h:483
void DestroyCameraCalibration(CameraCalibrationInterface *cameraCalibration)
Definition: CameraCalibrationInterface.cpp:32
Detail::UniquePtr< ProjectedCoordinateSystemInterface > UniqueProjectedCoordinateSystemPtr
Automatically manages the lifetime of a ProjectedCoordinateSystem object.
Definition: Utilities.h:513
void DestroyControlPointConstraint(ControlPointConstraintInterface *controlPoint)
Definition: ControlPointConstraintInterface.cpp:32
std::size_t Size
Size type.
Definition: CommonDef.h:103
Detail::UniquePtr< SettingsInterface > UniqueSettingsPtr
Automatically manages the lifetime of a Settings object.
Definition: Utilities.h:495
Detail::UniquePtr< CameraInterface > UniqueCameraPtr
Automatically manages the lifetime of a Camera object.
Definition: Utilities.h:474
Result
Enumerates possible results generated by FlowEngine.
Definition: CommonDef.h:45
Buffer(std::vector< Detail::UniquePtr< T > > &v)
Constructor from std::vector.
Definition: Utilities.h:354
Holds a (mutable) non_owning pointer and a size Used to marshal memory buffers as arguments in a safe...
Definition: CommonDef.h:118
ConstBuffer(const std::vector< Detail::UniquePtr< T > > &v)
Conversion from std::vector.
Definition: Utilities.h:393
Holds a (non mutable) non_owning pointer and a count Used to marshal memory buffers as arguments in a...
Definition: CommonDef.h:191
Simple log listener class.
Definition: Utilities.h:409
std::ostream * mFileStream
Pointer to an optional file stream.
Definition: Utilities.h:430
void messageLogged(const char *nMessage)
Send to stdout and optionally on a file stream.
Definition: Utilities.h:411
Bound 2 values together.
Definition: CommonDef.h:506
a 2 dimensional point
Definition: CommonDef.h:388
Simple/Empty progress bar class.
Definition: Utilities.h:435
void resetGlobalTicks(unsigned int nGlobalTicks, const char *nLoadingText)
Set global progress bar ticks (if any) and reset the counter to 0.
Definition: Utilities.h:455
void start(const char *nWindowTitle, bool nShowGlobalProgress, bool nShowCancelButton)
Show the progress bar.
Definition: Utilities.h:437
void resetTicks(unsigned int nTicks, const char *nLoadingText)
Set progress bar ticks and reset the counter to 0.
Definition: Utilities.h:449
void update()
Progress the loading bar - Add + 1 Tick.
Definition: Utilities.h:461
void finish()
Hide the loading bar.
Definition: Utilities.h:443
void updateGlobal()
Progress the global progress bar - Add + 1 Tick.
Definition: Utilities.h:467