FlowEngine 8.011
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"
37#include "OrthophotoInterface.h"
43
44#include <string>
45#include <cstring>
46#include <memory>
47#include <iostream>
48
49namespace FlowEngine
50{
53 extern "C" FLE_DLL const char *GetResultMessage( Result inResult );
54
55 namespace Detail
56 {
57 template< typename T >
58 struct Destroyer;
59
61 template< >
62 struct Destroyer< SettingsInterface >
63 {
65 static void destroy( SettingsInterface *settings )
66 {
67 DestroySettings( settings );
68 }
69 };
70
72 template< >
73 struct Destroyer< CameraInterface >
74 {
76 static void destroy( CameraInterface *camera )
77 {
78 DestroyCamera( camera );
79 }
80 };
81
83 template< >
84 struct Destroyer< CameraCalibrationInterface >
85 {
87 static void destroy( CameraCalibrationInterface *calib )
88 {
90 }
91 };
92
94 template< >
95 struct Destroyer< CamerasLoaderInterface >
96 {
97 static void destroy( CamerasLoaderInterface *camerasLoader )
98 {
99 DestroyCamerasLoader( camerasLoader );
100 }
101 };
102
104 template< >
105 struct Destroyer< SparsePointCloudInterface >
106 {
108 static void destroy( SparsePointCloudInterface *pointCloud )
109 {
110 DestroySparsePointCloud( pointCloud );
111 }
112 };
113
115 template< >
116 struct Destroyer< StereoPointCloudInterface >
117 {
119 static void destroy( StereoPointCloudInterface *pointCloud )
120 {
121 DestroyStereoPointCloud( pointCloud );
122 }
123 };
124
126 template< >
127 struct Destroyer< StereoMeshInterface >
128 {
130 static void destroy( StereoMeshInterface *mesh )
131 {
132 DestroyStereoMesh( mesh );
133 }
134 };
135
137 template< >
138 struct Destroyer< StereoTexturedMeshInterface >
139 {
140 static void destroy( StereoTexturedMeshInterface *texturedMesh )
141 {
142 DestroyStereoTexturedMesh( texturedMesh );
143 }
144 };
145
147 template< >
148 struct Destroyer< WorkspaceLoaderInterface >
149 {
151 static void destroy( WorkspaceLoaderInterface *workspaceLoader )
152 {
153 DestroyWorkspaceLoader( workspaceLoader );
154 }
155 };
156
158 template< >
159 struct Destroyer< WorkspaceSaverInterface >
160 {
162 static void destroy( WorkspaceSaverInterface *workspaceSaver )
163 {
164 DestroyWorkspaceSaver( workspaceSaver );
165 }
166 };
167
169 template< >
170 struct Destroyer< ControlPointConstraintInterface >
171 {
173 static void destroy( ControlPointConstraintInterface *controlPoint )
174 {
175 DestroyControlPointConstraint( controlPoint );
176 }
177 };
178
180 template< >
181 struct Destroyer< BoundingBoxInterface >
182 {
184 static void destroy( BoundingBoxInterface *bb )
185 {
186 DestroyBoundingBox( bb );
187 }
188 };
189
191 template< >
192 struct Destroyer< OrthophotoInterface >
193 {
195 static void destroy( OrthophotoInterface *op )
196 {
197 DestroyOrthophoto( op );
198 }
199 };
200
202 template< >
203 struct Destroyer< ProjectedCoordinateSystemInterface >
204 {
206 static void destroy( ProjectedCoordinateSystemInterface *pcs )
207 {
209 }
210 };
211
213 template< >
214 struct Destroyer< CameraConstraintInterface >
215 {
217 static void destroy( CameraConstraintInterface *cc )
218 {
220 }
221 };
222
224 template< >
225 struct Destroyer< DynamicBufferInterface >
226 {
228 static void destroy( DynamicBufferInterface *ptr )
229 {
231 }
232 };
233
235 template< >
236 struct Destroyer< LicenseInfoInterface >
237 {
239 static void destroy( LicenseInfoInterface *ptr )
240 {
241 DestroyLicenseInfo( ptr );
242 }
243 };
244
246 template< >
247 struct Destroyer< DistanceConstraintInterface >
248 {
250 static void destroy( DistanceConstraintInterface *ptr )
251 {
253 }
254 };
255
257 template< >
258 struct Destroyer< CameraGroupManagerInterface >
259 {
261 static void destroy( CameraGroupManagerInterface *ptr )
262 {
264 }
265 };
266
267 template< typename T >
268 class UniquePtr final
269 {
270 public:
271
272 UniquePtr() = default;
273
274 UniquePtr( T *object )
275 : mObject( object )
276 { }
277
278 UniquePtr( UniquePtr &&other )
279 : mObject( other.release() )
280 { }
281
282 UniquePtr &operator =( UniquePtr &&other )
283 {
284 if ( this != &other )
285 {
286 reset( other.release() );
287 }
288
289 return *this;
290 }
291
292 ~UniquePtr()
293 {
294 reset();
295 }
296
297 public:
298
299 explicit operator bool() const
300 {
301 return mObject != nullptr;
302 }
303
304 T *operator ->()
305 {
306 return mObject;
307 }
308
309 const T *operator ->() const
310 {
311 return mObject;
312 }
313
314 T &operator *()
315 {
316 return *mObject;
317 }
318
319 const T &operator *() const
320 {
321 return *mObject;
322 }
323
324 operator T *() const
325 {
326 return mObject;
327 }
328
329 public:
330
331 T *get() const
332 {
333 return mObject;
334 }
335
336 void reset( T *object = nullptr )
337 {
338 if ( mObject )
339 Detail::Destroyer< T >::destroy( mObject );
340
341 mObject = object;
342 }
343
344 T *release()
345 {
346 auto temp = mObject;
347 mObject = nullptr;
348 return temp;
349 }
350
351 private:
352
353 T *mObject = nullptr;
354 };
355 } // Detail namespace
356
358 template< typename T >
359 struct Buffer< T * >
360 {
361 static_assert( std::is_same< CameraInterface, T >::value ||
362 std::is_same< CamerasLoaderInterface, T >::value ||
363 std::is_same< ControlPointConstraintInterface, T >::value ||
364 std::is_same< SparsePointCloudInterface, T >::value ||
365 std::is_same< StereoPointCloudInterface, T >::value ||
366 std::is_same< StereoMeshInterface, T >::value ||
367 std::is_same< StereoTexturedMeshInterface, T >::value ||
368 std::is_same< CameraConstraintInterface, T >::value ||
369 std::is_same< ProjectedCoordinateSystemInterface, T >::value ||
370 std::is_same< BoundingBoxInterface, T >::value ||
371 std::is_same< DistanceConstraintInterface, T >::value ||
372 std::is_same< OrthophotoInterface, T >::value ||
373 std::is_same< CameraGroupManagerInterface, T >::value,
374 "This kind of buffer can only be used with object classes" );
375
377 T **data = nullptr;
378
380 Size count = 0;
381
382 Buffer() = default;
383
385 Buffer( std::vector< T * > &v )
386 : data( v.empty() ? nullptr : v.data() )
387 , count( v.empty() ? 0 : v.size() )
388 {
389
390 }
391
393 Buffer( std::vector< Detail::UniquePtr< T > > &v )
394 : data( v.empty() ? nullptr : reinterpret_cast< T ** >( 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
408 template< typename T >
409 struct ConstBuffer< T * >
410 {
411 static_assert( std::is_same< CameraInterface, T >::value ||
412 std::is_same< CamerasLoaderInterface, T >::value ||
413 std::is_same< ControlPointConstraintInterface, T >::value ||
414 std::is_same< SparsePointCloudInterface, T >::value ||
415 std::is_same< StereoPointCloudInterface, T >::value ||
416 std::is_same< StereoMeshInterface, T >::value ||
417 std::is_same< StereoTexturedMeshInterface, T >::value ||
418 std::is_same< ProjectedCoordinateSystemInterface, T >::value ||
419 std::is_same< CameraConstraintInterface, T >::value ||
420 std::is_same< DistanceConstraintInterface, T >::value ||
421 std::is_same< BoundingBoxInterface, T >::value ||
422 std::is_same< OrthophotoInterface, T >::value ||
423 std::is_same< CameraGroupManagerInterface, T >::value,
424 "This kind of buffer can only be used with object classes" );
425
427 const T *const *data = nullptr;
428
430 Size count = 0;
431
432 ConstBuffer() = default;
433
435 ConstBuffer( const std::vector< T * > &v )
436 : data( v.empty() ? nullptr : v.data() )
437 , count( v.empty() ? 0 : v.size() )
438 {
439 static_assert( sizeof( Detail::UniquePtr< T > ) ==
440 sizeof( std::ptrdiff_t ), "" );
441 }
442
444 ConstBuffer( const std::vector< Detail::UniquePtr< T > > &v )
445 : data( v.empty() ? nullptr : reinterpret_cast< const T *const * >( v.data() ) )
446 , count( v.empty() ? 0 : v.size() )
447 {
448 static_assert( sizeof( Detail::UniquePtr< T > ) ==
449 sizeof( std::ptrdiff_t ), "" );
450 }
451
452 explicit operator bool() const
453 {
454 return data != nullptr;
455 }
456 };
457
460 {
462 void messageLogged( const char *nMessage )
463 {
464 // strip log type
465 const std::size_t len = std::strlen( nMessage );
466
467 if ( len > 3 && nMessage[ 0 ] == '[' && nMessage[ 2 ] == ']' )
468 nMessage = nMessage + 3;
469
470 if ( mFileStream )
471 {
472 ( *mFileStream ) << nMessage;
473 mFileStream->flush();
474 }
475
476 std::cout << nMessage;
477 std::cout.flush();
478 }
479
481 std::ostream *mFileStream = nullptr;
482 };
483
486 {
488 void start( const char *nWindowTitle, bool nShowGlobalProgress, bool nShowCancelButton )
489 {
490
491 }
492
494 void finish()
495 {
496
497 }
498
500 void resetTicks( unsigned int nTicks, const char *nLoadingText )
501 {
502
503 }
504
506 void resetGlobalTicks( unsigned int nGlobalTicks, const char *nLoadingText )
507 {
508
509 }
510
512 void update()
513 {
514
515 }
516
519 {
520
521 }
522 };
523
525 using UniqueCameraPtr = Detail::UniquePtr< CameraInterface >;
526
528 using UniqueCameraCalibrationPtr = Detail::UniquePtr< CameraCalibrationInterface >;
529
531 using UniqueCamerasLoaderPtr = Detail::UniquePtr< CamerasLoaderInterface >;
532
534 using UniqueSparsePointCloudPtr = Detail::UniquePtr< SparsePointCloudInterface >;
535
537 using UniqueStereoPointCloudPtr = Detail::UniquePtr< StereoPointCloudInterface >;
538
540 using UniqueStereoMeshPtr = Detail::UniquePtr< StereoMeshInterface >;
541
543 using UniqueStereoTexturedMeshPtr = Detail::UniquePtr< StereoTexturedMeshInterface >;
544
546 using UniqueSettingsPtr = Detail::UniquePtr< SettingsInterface >;
547
549 using UniqueBoundingBoxPtr = Detail::UniquePtr< BoundingBoxInterface >;
550
552 using UniqueWorkspaceSaverPtr = Detail::UniquePtr< WorkspaceSaverInterface >;
553
555 using UniqueWorkspaceLoaderPtr = Detail::UniquePtr< WorkspaceLoaderInterface >;
556
558 using UniqueControlPointConstraintPtr = Detail::UniquePtr< ControlPointConstraintInterface >;
559
561 using UniqueOrthophotoPtr = Detail::UniquePtr< OrthophotoInterface >;
562
564 using UniqueProjectedCoordinateSystemPtr = Detail::UniquePtr< ProjectedCoordinateSystemInterface >;
565
567 using UniqueCameraConstraintPtr = Detail::UniquePtr< CameraConstraintInterface >;
568
570 using UniqueDynamicBufferPtr = Detail::UniquePtr< DynamicBufferInterface >;
571
573 using UniqueLicenseInfoPtr = Detail::UniquePtr< LicenseInfoInterface >;
574
576 using UniqueDistanceConstraintPtr = Detail::UniquePtr< DistanceConstraintInterface >;
577
579 using UniqueCameraGroupManagerPtr = Detail::UniquePtr< CameraGroupManagerInterface >;
580
597 extern "C" FLE_DLL
598 Result SampleEpipolarLine( const CameraInterface &referenceCamera,
599 const Point2 &referencePoint,
600 const CameraInterface &targetCamera,
601 int sampleCount,
602 Buffer< Point2 > inOutPoints );
603
605 extern "C" FLE_DLL
608 Buffer< int > inOutRatings );
609}
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:570
Detail::UniquePtr< OrthophotoInterface > UniqueOrthophotoPtr
Automatically manages the lifetime of a Orthophoto object.
Definition: Utilities.h:561
void DestroyStereoTexturedMesh(StereoTexturedMeshInterface *stereoTexturedMesh)
Definition: StereoTexturedMeshInterface.cpp:32
void DestroyStereoPointCloud(StereoPointCloudInterface *stereoPointCloud)
Definition: StereoPointCloudInterface.cpp:32
void DestroyWorkspaceSaver(WorkspaceSaverInterface *workspaceSaver)
Definition: WorkspaceSaverInterface.cpp:32
FLE_DLL void DestroyCameraGroupManager(CameraGroupManagerInterface *cameraGroupManager)
Definition: CameraGroupManagerInterface.cpp:30
Detail::UniquePtr< CameraConstraintInterface > UniqueCameraConstraintPtr
Automatically manages the lifetime of a CameraConstraint object.
Definition: Utilities.h:567
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:543
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:552
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:531
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:555
Detail::UniquePtr< CameraCalibrationInterface > UniqueCameraCalibrationPtr
Automatically manages the lifetime of a Camera calibration object.
Definition: Utilities.h:528
Detail::UniquePtr< StereoPointCloudInterface > UniqueStereoPointCloudPtr
Automatically manages the lifetime of a Stereo Point cloud object.
Definition: Utilities.h:537
Detail::UniquePtr< LicenseInfoInterface > UniqueLicenseInfoPtr
Automatically manages the lifetime of a LicenseInfo object.
Definition: Utilities.h:573
Detail::UniquePtr< BoundingBoxInterface > UniqueBoundingBoxPtr
Automatically manages the lifetime of a Bounding box object.
Definition: Utilities.h:549
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:558
void DestroyLicenseInfo(LicenseInfoInterface *buf)
Definition: LicenseInfoInterface.cpp:32
void DestroyCamera(CameraInterface *camera)
Definition: CameraInterface.cpp:32
Detail::UniquePtr< CameraGroupManagerInterface > UniqueCameraGroupManagerPtr
Automatically manages the lifetime of a CameraGroupManager object.
Definition: Utilities.h:579
Detail::UniquePtr< StereoMeshInterface > UniqueStereoMeshPtr
Automatically manages the lifetime of a Stereo mesh object.
Definition: Utilities.h:540
Detail::UniquePtr< SparsePointCloudInterface > UniqueSparsePointCloudPtr
Automatically manages the lifetime of a Sparse Point Cloud object.
Definition: Utilities.h:534
void DestroyCameraCalibration(CameraCalibrationInterface *cameraCalibration)
Definition: CameraCalibrationInterface.cpp:32
Detail::UniquePtr< ProjectedCoordinateSystemInterface > UniqueProjectedCoordinateSystemPtr
Automatically manages the lifetime of a ProjectedCoordinateSystem object.
Definition: Utilities.h:564
void DestroyDistanceConstraint(DistanceConstraintInterface *distance)
Definition: DistanceConstraintInterface.cpp:32
void DestroyControlPointConstraint(ControlPointConstraintInterface *controlPoint)
Definition: ControlPointConstraintInterface.cpp:32
std::size_t Size
Size type.
Definition: CommonDef.h:103
Detail::UniquePtr< DistanceConstraintInterface > UniqueDistanceConstraintPtr
Automatically manages the lifetime of a DistanceConstraint object.
Definition: Utilities.h:576
Detail::UniquePtr< SettingsInterface > UniqueSettingsPtr
Automatically manages the lifetime of a Settings object.
Definition: Utilities.h:546
Detail::UniquePtr< CameraInterface > UniqueCameraPtr
Automatically manages the lifetime of a Camera object.
Definition: Utilities.h:525
Result
Enumerates possible results generated by FlowEngine.
Definition: CommonDef.h:45
Buffer(std::vector< T * > &v)
Constructor from std::vector.
Definition: Utilities.h:385
Buffer(std::vector< Detail::UniquePtr< T > > &v)
Constructor from std::vector of unique pointers.
Definition: Utilities.h:393
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< T * > &v)
Conversion from std::vector.
Definition: Utilities.h:435
ConstBuffer(const std::vector< Detail::UniquePtr< T > > &v)
Conversion from std::vector of unique pointers.
Definition: Utilities.h:444
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:460
std::ostream * mFileStream
Pointer to an optional file stream.
Definition: Utilities.h:481
void messageLogged(const char *nMessage)
Send to stdout and optionally on a file stream.
Definition: Utilities.h:462
Bound 2 values together.
Definition: CommonDef.h:506
a 2 dimensional point
Definition: CommonDef.h:388
Simple/Empty progress bar class.
Definition: Utilities.h:486
void resetGlobalTicks(unsigned int nGlobalTicks, const char *nLoadingText)
Set global progress bar ticks (if any) and reset the counter to 0.
Definition: Utilities.h:506
void start(const char *nWindowTitle, bool nShowGlobalProgress, bool nShowCancelButton)
Show the progress bar.
Definition: Utilities.h:488
void resetTicks(unsigned int nTicks, const char *nLoadingText)
Set progress bar ticks and reset the counter to 0.
Definition: Utilities.h:500
void update()
Progress the loading bar - Add + 1 Tick.
Definition: Utilities.h:512
void finish()
Hide the loading bar.
Definition: Utilities.h:494
void updateGlobal()
Progress the global progress bar - Add + 1 Tick.
Definition: Utilities.h:518