FlowEngine 9.000
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"
44
45#include <string>
46#include <cstring>
47#include <memory>
48#include <iostream>
49
50namespace FlowEngine
51{
54 extern "C" FLE_DLL const char *GetResultMessage( Result inResult );
55
56 namespace Detail
57 {
58 template< typename T >
59 struct Destroyer;
60
62 template< >
63 struct Destroyer< SettingsInterface >
64 {
66 static void destroy( SettingsInterface *settings )
67 {
68 DestroySettings( settings );
69 }
70 };
71
73 template< >
74 struct Destroyer< CameraInterface >
75 {
77 static void destroy( CameraInterface *camera )
78 {
79 DestroyCamera( camera );
80 }
81 };
82
84 template< >
85 struct Destroyer< CameraCalibrationInterface >
86 {
88 static void destroy( CameraCalibrationInterface *calib )
89 {
91 }
92 };
93
95 template< >
96 struct Destroyer< CamerasLoaderInterface >
97 {
98 static void destroy( CamerasLoaderInterface *camerasLoader )
99 {
100 DestroyCamerasLoader( camerasLoader );
101 }
102 };
103
105 template< >
106 struct Destroyer< SparsePointCloudInterface >
107 {
109 static void destroy( SparsePointCloudInterface *pointCloud )
110 {
111 DestroySparsePointCloud( pointCloud );
112 }
113 };
114
116 template< >
117 struct Destroyer< StereoPointCloudInterface >
118 {
120 static void destroy( StereoPointCloudInterface *pointCloud )
121 {
122 DestroyStereoPointCloud( pointCloud );
123 }
124 };
125
127 template< >
128 struct Destroyer< StereoMeshInterface >
129 {
131 static void destroy( StereoMeshInterface *mesh )
132 {
133 DestroyStereoMesh( mesh );
134 }
135 };
136
138 template< >
139 struct Destroyer< StereoTexturedMeshInterface >
140 {
141 static void destroy( StereoTexturedMeshInterface *texturedMesh )
142 {
143 DestroyStereoTexturedMesh( texturedMesh );
144 }
145 };
146
148 template< >
149 struct Destroyer< WorkspaceLoaderInterface >
150 {
152 static void destroy( WorkspaceLoaderInterface *workspaceLoader )
153 {
154 DestroyWorkspaceLoader( workspaceLoader );
155 }
156 };
157
159 template< >
160 struct Destroyer< WorkspaceSaverInterface >
161 {
163 static void destroy( WorkspaceSaverInterface *workspaceSaver )
164 {
165 DestroyWorkspaceSaver( workspaceSaver );
166 }
167 };
168
170 template< >
171 struct Destroyer< ControlPointConstraintInterface >
172 {
174 static void destroy( ControlPointConstraintInterface *controlPoint )
175 {
176 DestroyControlPointConstraint( controlPoint );
177 }
178 };
179
181 template< >
182 struct Destroyer< BoundingBoxInterface >
183 {
185 static void destroy( BoundingBoxInterface *bb )
186 {
187 DestroyBoundingBox( bb );
188 }
189 };
190
192 template< >
193 struct Destroyer< OrthophotoInterface >
194 {
196 static void destroy( OrthophotoInterface *op )
197 {
198 DestroyOrthophoto( op );
199 }
200 };
201
203 template< >
204 struct Destroyer< ProjectedCoordinateSystemInterface >
205 {
207 static void destroy( ProjectedCoordinateSystemInterface *pcs )
208 {
210 }
211 };
212
214 template< >
215 struct Destroyer< CameraConstraintInterface >
216 {
218 static void destroy( CameraConstraintInterface *cc )
219 {
221 }
222 };
223
225 template< >
226 struct Destroyer< DynamicBufferInterface >
227 {
229 static void destroy( DynamicBufferInterface *ptr )
230 {
232 }
233 };
234
236 template< >
237 struct Destroyer< LicenseInfoInterface >
238 {
240 static void destroy( LicenseInfoInterface *ptr )
241 {
242 DestroyLicenseInfo( ptr );
243 }
244 };
245
247 template< >
248 struct Destroyer< DistanceConstraintInterface >
249 {
251 static void destroy( DistanceConstraintInterface *ptr )
252 {
254 }
255 };
256
258 template< >
259 struct Destroyer< CameraGroupManagerInterface >
260 {
262 static void destroy( CameraGroupManagerInterface *ptr )
263 {
265 }
266 };
267
269 template< >
270 struct Destroyer< GaussianSplatsInterface >
271 {
273 static void destroy( GaussianSplatsInterface *ptr )
274 {
276 }
277 };
278
279 template< typename T >
280 class UniquePtr final
281 {
282 public:
283
284 UniquePtr() = default;
285
286 UniquePtr( T *object )
287 : mObject( object )
288 { }
289
290 UniquePtr( UniquePtr &&other )
291 : mObject( other.release() )
292 { }
293
294 UniquePtr &operator =( UniquePtr &&other )
295 {
296 if ( this != &other )
297 {
298 reset( other.release() );
299 }
300
301 return *this;
302 }
303
304 ~UniquePtr()
305 {
306 reset();
307 }
308
309 public:
310
311 explicit operator bool() const
312 {
313 return mObject != nullptr;
314 }
315
316 T *operator ->()
317 {
318 return mObject;
319 }
320
321 const T *operator ->() const
322 {
323 return mObject;
324 }
325
326 T &operator *()
327 {
328 return *mObject;
329 }
330
331 const T &operator *() const
332 {
333 return *mObject;
334 }
335
336 operator T *() const
337 {
338 return mObject;
339 }
340
341 public:
342
343 T *get() const
344 {
345 return mObject;
346 }
347
348 void reset( T *object = nullptr )
349 {
350 if ( mObject )
351 Detail::Destroyer< T >::destroy( mObject );
352
353 mObject = object;
354 }
355
356 T *release()
357 {
358 auto temp = mObject;
359 mObject = nullptr;
360 return temp;
361 }
362
363 private:
364
365 T *mObject = nullptr;
366 };
367 } // Detail namespace
368
370 template< typename T >
371 struct Buffer< T * >
372 {
373 static_assert( std::is_same< CameraInterface, T >::value ||
374 std::is_same< CamerasLoaderInterface, T >::value ||
375 std::is_same< ControlPointConstraintInterface, T >::value ||
376 std::is_same< SparsePointCloudInterface, T >::value ||
377 std::is_same< StereoPointCloudInterface, T >::value ||
378 std::is_same< StereoMeshInterface, T >::value ||
379 std::is_same< StereoTexturedMeshInterface, T >::value ||
380 std::is_same< CameraConstraintInterface, T >::value ||
381 std::is_same< ProjectedCoordinateSystemInterface, T >::value ||
382 std::is_same< BoundingBoxInterface, T >::value ||
383 std::is_same< DistanceConstraintInterface, T >::value ||
384 std::is_same< OrthophotoInterface, T >::value ||
385 std::is_same< GaussianSplatsInterface, T >::value ||
386 std::is_same< CameraGroupManagerInterface, T >::value,
387 "This kind of buffer can only be used with object classes" );
388
390 T **data = nullptr;
391
393 Size count = 0;
394
395 Buffer() = default;
396
398 Buffer( std::vector< T * > &v )
399 : data( v.empty() ? nullptr : v.data() )
400 , count( v.empty() ? 0 : v.size() )
401 {
402
403 }
404
406 Buffer( std::vector< Detail::UniquePtr< T > > &v )
407 : data( v.empty() ? nullptr : reinterpret_cast< T ** >( v.data() ) )
408 , count( v.empty() ? 0 : v.size() )
409 {
410 static_assert( sizeof( Detail::UniquePtr< T > ) ==
411 sizeof( std::ptrdiff_t ), "" );
412 }
413
414 explicit operator bool() const
415 {
416 return data != nullptr;
417 }
418 };
419
421 template< typename T >
422 struct ConstBuffer< T * >
423 {
424 static_assert( std::is_same< CameraInterface, T >::value ||
425 std::is_same< CamerasLoaderInterface, T >::value ||
426 std::is_same< ControlPointConstraintInterface, T >::value ||
427 std::is_same< SparsePointCloudInterface, T >::value ||
428 std::is_same< StereoPointCloudInterface, T >::value ||
429 std::is_same< StereoMeshInterface, T >::value ||
430 std::is_same< StereoTexturedMeshInterface, T >::value ||
431 std::is_same< ProjectedCoordinateSystemInterface, T >::value ||
432 std::is_same< CameraConstraintInterface, T >::value ||
433 std::is_same< DistanceConstraintInterface, T >::value ||
434 std::is_same< BoundingBoxInterface, T >::value ||
435 std::is_same< OrthophotoInterface, T >::value ||
436 std::is_same< GaussianSplatsInterface, T >::value ||
437 std::is_same< CameraGroupManagerInterface, T >::value,
438 "This kind of buffer can only be used with object classes" );
439
441 const T *const *data = nullptr;
442
444 Size count = 0;
445
446 ConstBuffer() = default;
447
449 ConstBuffer( const std::vector< T * > &v )
450 : data( v.empty() ? nullptr : v.data() )
451 , count( v.empty() ? 0 : v.size() )
452 {
453 static_assert( sizeof( Detail::UniquePtr< T > ) ==
454 sizeof( std::ptrdiff_t ), "" );
455 }
456
458 ConstBuffer( const std::vector< Detail::UniquePtr< T > > &v )
459 : data( v.empty() ? nullptr : reinterpret_cast< const T *const * >( v.data() ) )
460 , count( v.empty() ? 0 : v.size() )
461 {
462 static_assert( sizeof( Detail::UniquePtr< T > ) ==
463 sizeof( std::ptrdiff_t ), "" );
464 }
465
466 explicit operator bool() const
467 {
468 return data != nullptr;
469 }
470 };
471
474 {
476 void messageLogged( const char *nMessage )
477 {
478 // strip log type
479 const std::size_t len = std::strlen( nMessage );
480
481 if ( len > 3 && nMessage[ 0 ] == '[' && nMessage[ 2 ] == ']' )
482 nMessage = nMessage + 3;
483
484 if ( mFileStream )
485 {
486 ( *mFileStream ) << nMessage;
487 mFileStream->flush();
488 }
489
490 std::cout << nMessage;
491 std::cout.flush();
492 }
493
495 std::ostream *mFileStream = nullptr;
496 };
497
500 {
502 void start( const char *nWindowTitle, bool nShowGlobalProgress, bool nShowCancelButton )
503 {
504
505 }
506
508 void finish()
509 {
510
511 }
512
514 void resetTicks( unsigned int nTicks, const char *nLoadingText )
515 {
516
517 }
518
520 void resetGlobalTicks( unsigned int nGlobalTicks, const char *nLoadingText )
521 {
522
523 }
524
526 void update()
527 {
528
529 }
530
533 {
534
535 }
536 };
537
539 using UniqueCameraPtr = Detail::UniquePtr< CameraInterface >;
540
542 using UniqueCameraCalibrationPtr = Detail::UniquePtr< CameraCalibrationInterface >;
543
545 using UniqueCamerasLoaderPtr = Detail::UniquePtr< CamerasLoaderInterface >;
546
548 using UniqueSparsePointCloudPtr = Detail::UniquePtr< SparsePointCloudInterface >;
549
551 using UniqueStereoPointCloudPtr = Detail::UniquePtr< StereoPointCloudInterface >;
552
554 using UniqueStereoMeshPtr = Detail::UniquePtr< StereoMeshInterface >;
555
557 using UniqueStereoTexturedMeshPtr = Detail::UniquePtr< StereoTexturedMeshInterface >;
558
560 using UniqueSettingsPtr = Detail::UniquePtr< SettingsInterface >;
561
563 using UniqueBoundingBoxPtr = Detail::UniquePtr< BoundingBoxInterface >;
564
566 using UniqueWorkspaceSaverPtr = Detail::UniquePtr< WorkspaceSaverInterface >;
567
569 using UniqueWorkspaceLoaderPtr = Detail::UniquePtr< WorkspaceLoaderInterface >;
570
572 using UniqueControlPointConstraintPtr = Detail::UniquePtr< ControlPointConstraintInterface >;
573
575 using UniqueOrthophotoPtr = Detail::UniquePtr< OrthophotoInterface >;
576
578 using UniqueProjectedCoordinateSystemPtr = Detail::UniquePtr< ProjectedCoordinateSystemInterface >;
579
581 using UniqueCameraConstraintPtr = Detail::UniquePtr< CameraConstraintInterface >;
582
584 using UniqueDynamicBufferPtr = Detail::UniquePtr< DynamicBufferInterface >;
585
587 using UniqueLicenseInfoPtr = Detail::UniquePtr< LicenseInfoInterface >;
588
590 using UniqueDistanceConstraintPtr = Detail::UniquePtr< DistanceConstraintInterface >;
591
593 using UniqueCameraGroupManagerPtr = Detail::UniquePtr< CameraGroupManagerInterface >;
594
596 using UniqueGaussianSplatsPtr = Detail::UniquePtr< GaussianSplatsInterface >;
597
614 extern "C" FLE_DLL
615 Result SampleEpipolarLine( const CameraInterface &referenceCamera,
616 const Point2 &referencePoint,
617 const CameraInterface &targetCamera,
618 int sampleCount,
619 Buffer< Point2 > inOutPoints );
620
622 extern "C" FLE_DLL
625 Buffer< int > inOutRatings );
626}
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:584
Detail::UniquePtr< OrthophotoInterface > UniqueOrthophotoPtr
Automatically manages the lifetime of a Orthophoto object.
Definition: Utilities.h:575
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:581
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:557
void DestroyBoundingBox(BoundingBoxInterface *boundingBox)
Definition: BoundingBoxInterface.cpp:32
void DestroySettings(SettingsInterface *settings)
Definition: SettingsInterface.cpp:32
Detail::UniquePtr< GaussianSplatsInterface > UniqueGaussianSplatsPtr
Automatically manages the lifetime of a GaussianSplats object.
Definition: Utilities.h:596
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:566
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:545
void DestroyStereoMesh(StereoMeshInterface *stereoMesh)
Definition: StereoMeshInterface.cpp:32
void DestroyGaussianSplats(GaussianSplatsInterface *gaussianSplats)
Definition: GaussianSplatsInterface.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:569
Detail::UniquePtr< CameraCalibrationInterface > UniqueCameraCalibrationPtr
Automatically manages the lifetime of a Camera calibration object.
Definition: Utilities.h:542
Detail::UniquePtr< StereoPointCloudInterface > UniqueStereoPointCloudPtr
Automatically manages the lifetime of a Stereo Point cloud object.
Definition: Utilities.h:551
Detail::UniquePtr< LicenseInfoInterface > UniqueLicenseInfoPtr
Automatically manages the lifetime of a LicenseInfo object.
Definition: Utilities.h:587
Detail::UniquePtr< BoundingBoxInterface > UniqueBoundingBoxPtr
Automatically manages the lifetime of a Bounding box object.
Definition: Utilities.h:563
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:572
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:593
Detail::UniquePtr< StereoMeshInterface > UniqueStereoMeshPtr
Automatically manages the lifetime of a Stereo mesh object.
Definition: Utilities.h:554
Detail::UniquePtr< SparsePointCloudInterface > UniqueSparsePointCloudPtr
Automatically manages the lifetime of a Sparse Point Cloud object.
Definition: Utilities.h:548
void DestroyCameraCalibration(CameraCalibrationInterface *cameraCalibration)
Definition: CameraCalibrationInterface.cpp:32
Detail::UniquePtr< ProjectedCoordinateSystemInterface > UniqueProjectedCoordinateSystemPtr
Automatically manages the lifetime of a ProjectedCoordinateSystem object.
Definition: Utilities.h:578
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:106
Detail::UniquePtr< DistanceConstraintInterface > UniqueDistanceConstraintPtr
Automatically manages the lifetime of a DistanceConstraint object.
Definition: Utilities.h:590
Detail::UniquePtr< SettingsInterface > UniqueSettingsPtr
Automatically manages the lifetime of a Settings object.
Definition: Utilities.h:560
Detail::UniquePtr< CameraInterface > UniqueCameraPtr
Automatically manages the lifetime of a Camera object.
Definition: Utilities.h:539
Result
Enumerates possible results generated by FlowEngine.
Definition: CommonDef.h:48
Buffer(std::vector< T * > &v)
Constructor from std::vector.
Definition: Utilities.h:398
Buffer(std::vector< Detail::UniquePtr< T > > &v)
Constructor from std::vector of unique pointers.
Definition: Utilities.h:406
Holds a (mutable) non_owning pointer and a size Used to marshal memory buffers as arguments in a safe...
Definition: CommonDef.h:127
ConstBuffer(const std::vector< T * > &v)
Conversion from std::vector.
Definition: Utilities.h:449
ConstBuffer(const std::vector< Detail::UniquePtr< T > > &v)
Conversion from std::vector of unique pointers.
Definition: Utilities.h:458
Holds a (non mutable) non_owning pointer and a count Used to marshal memory buffers as arguments in a...
Definition: CommonDef.h:200
Simple log listener class.
Definition: Utilities.h:474
std::ostream * mFileStream
Pointer to an optional file stream.
Definition: Utilities.h:495
void messageLogged(const char *nMessage)
Send to stdout and optionally on a file stream.
Definition: Utilities.h:476
Bound 2 values together.
Definition: CommonDef.h:596
a 2 dimensional point
Definition: CommonDef.h:472
Simple/Empty progress bar class.
Definition: Utilities.h:500
void resetGlobalTicks(unsigned int nGlobalTicks, const char *nLoadingText)
Set global progress bar ticks (if any) and reset the counter to 0.
Definition: Utilities.h:520
void start(const char *nWindowTitle, bool nShowGlobalProgress, bool nShowCancelButton)
Show the progress bar.
Definition: Utilities.h:502
void resetTicks(unsigned int nTicks, const char *nLoadingText)
Set progress bar ticks and reset the counter to 0.
Definition: Utilities.h:514
void update()
Progress the loading bar - Add + 1 Tick.
Definition: Utilities.h:526
void finish()
Hide the loading bar.
Definition: Utilities.h:508
void updateGlobal()
Progress the global progress bar - Add + 1 Tick.
Definition: Utilities.h:532