ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
pba.h
Go to the documentation of this file.
1 // File: pba.h
3 // Author: Changchang Wu (ccwu@cs.washington.edu)
4 // Description : interface of class ParallelBA, which has two
5 //implementations
6 // SparseBundleCU for CUDA-based version, and
7 // SparseBundleCPU<Float> for CPU multi-threading version
8 //
9 // Copyright (c) 2011 Changchang Wu (ccwu@cs.washington.edu)
10 // and the University of Washington at Seattle
11 //
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public
14 // License as published by the Free Software Foundation; either
15 // Version 3 of the License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // General Public License for more details.
21 //
23 
24 #ifndef PARALLEL_BA_H
25 #define PARALLEL_BA_H
26 
27 #if defined(_WIN32)
28 #ifdef PBA_DLL
29 #ifdef DLL_EXPORT
30 #define PBA_EXPORT __declspec(dllexport)
31 #else
32 #define PBA_EXPORT __declspec(dllimport)
33 #endif
34 #else
35 #define PBA_EXPORT
36 #endif
37 
38 #define PBA_EXPORT_EXTERN PBA_EXPORT
39 
40 #if _MSC_VER > 1000
41 #pragma once
42 #endif
43 #else
44 #define PBA_EXPORT
45 #define PBA_EXPORT_EXTERN extern "C"
46 #endif
47 
48 // filetype definitions for points and camera
49 #include "DataInterface.h"
50 #include "ConfigBA.h"
51 
52 namespace pba {
53 
54 class ParallelBA {
55  public:
56  enum StatusT {
63  };
64  enum DeviceT {
70  };
71  enum DistortionT {
72  PBA_MEASUREMENT_DISTORTION = -1, // single parameter, apply to measurements
73  PBA_NO_DISTORTION = 0, // no radial distortion
74  PBA_PROJECTION_DISTORTION = 1 // single parameter, apply to projectino
75  };
76  enum BundleModeT {
80  };
81 
82  private:
83  ParallelBA* _optimizer;
84 
85  public:
87  // methods for changing bundle adjustment settings
88  PBA_EXPORT virtual void ParseParam(int narg, char** argv); // indirect method
89  PBA_EXPORT virtual ConfigBA* GetInternalConfig(); // direct method
90  PBA_EXPORT virtual void SetFixedIntrinsics(
91  bool fixed); // call this for calibrated system
93  DistortionT type); // call this to enable radial distortion
94  PBA_EXPORT virtual void SetNextTimeBudget(
95  int seconds); //# of seconds for next run (0 = no limit)
96  PBA_EXPORT virtual void ReserveStorage(size_t ncam, size_t npt, size_t nproj);
97 
98  public:
99  // function name change; the old one is mapped as inline function
100  inline void SetFocalLengthFixed(bool fixed) { SetFixedIntrinsics(fixed); }
101  inline void ResetBundleStorage() {
102  ReserveStorage(0, 0, 0); /*Reset devide for CUDA*/
103  }
104 
105  public:
107  // optimizer interface, input and run
108  PBA_EXPORT virtual void SetCameraData(size_t ncam,
109  CameraT* cams); // set camera data
110  PBA_EXPORT virtual void SetPointData(size_t npoint,
111  Point3D* pts); // set 3D point data
112  PBA_EXPORT virtual void SetProjection(size_t nproj, const Point2D* imgpts,
113  const int* point_idx,
114  const int* cam_idx); // set projections
115  PBA_EXPORT virtual void SetNextBundleMode(
117  mode = BUNDLE_FULL); // mode of the next bundle adjustment call
118  PBA_EXPORT virtual int RunBundleAdjustment(); // start bundle adjustment,
119  // return number of successful
120  // LM iterations
121  public:
123  // Query optimzer runing status for Multi-threading
124  // Three functions below can be called from a differnt thread while bundle is
125  // running
126  PBA_EXPORT virtual float
127  GetMeanSquaredError(); // read back results during/after BA
128  PBA_EXPORT virtual void
129  AbortBundleAdjustment(); // tell bundle adjustment to abort ASAP
130  PBA_EXPORT virtual int
131  GetCurrentIteration(); // which iteration is it working on?
132  public:
134  const int num_threads = -1);
135  PBA_EXPORT void* operator new(size_t size);
136  PBA_EXPORT virtual ~ParallelBA();
137 
138  public:
140  // Future functions will be added to the end for compatiability with old
141  // version.
142  PBA_EXPORT virtual void SetFocalMask(const int* fmask, float weight = 1.0f);
143 };
144 
145 // function for dynamic loading of library
146 PBA_EXPORT_EXTERN ParallelBA* NewParallelBA(
148 typedef ParallelBA* (*NEWPARALLELBAPROC)(ParallelBA::DeviceT);
149 
151 // older versions do not have this function.
153 
154 } // namespace pba
155 
156 #endif
int size
char type
void ResetBundleStorage()
Definition: pba.h:101
@ STATUS_ALLOCATION_FAIL
Definition: pba.h:62
@ STATUS_CAMERA_MISSING
Definition: pba.h:58
@ STATUS_POINT_MISSING
Definition: pba.h:59
@ STATUS_SUCCESS
Definition: pba.h:57
@ STATUS_MEASURMENT_MISSING
Definition: pba.h:61
@ STATUS_PROJECTION_MISSING
Definition: pba.h:60
virtual int GetCurrentIteration()
Definition: pba.cpp:104
virtual void SetNextTimeBudget(int seconds)
Definition: pba.cpp:76
virtual void SetNextBundleMode(BundleModeT mode=BUNDLE_FULL)
Definition: pba.cpp:80
virtual void ReserveStorage(size_t ncam, size_t npt, size_t nproj)
Definition: pba.cpp:111
virtual ~ParallelBA()
Definition: pba.cpp:55
@ PBA_CUDA_DEVICE0
Definition: pba.h:69
@ PBA_CUDA_DEVICE_DEFAULT
Definition: pba.h:68
@ PBA_INVALID_DEVICE
Definition: pba.h:65
@ PBA_CPU_FLOAT
Definition: pba.h:67
@ PBA_CPU_DOUBLE
Definition: pba.h:66
virtual void ParseParam(int narg, char **argv)
Definition: pba.cpp:59
ParallelBA(DeviceT device=PBA_CUDA_DEVICE_DEFAULT, const int num_threads=-1)
Definition: pba.cpp:29
virtual void SetPointData(size_t npoint, Point3D *pts)
Definition: pba.cpp:88
virtual float GetMeanSquaredError()
Definition: pba.cpp:100
virtual void SetFocalMask(const int *fmask, float weight=1.0f)
Definition: pba.cpp:115
virtual void SetFixedIntrinsics(bool fixed)
Definition: pba.cpp:70
void SetFocalLengthFixed(bool fixed)
Definition: pba.h:100
virtual void EnableRadialDistortion(DistortionT type)
Definition: pba.cpp:73
virtual void AbortBundleAdjustment()
Definition: pba.cpp:107
@ PBA_MEASUREMENT_DISTORTION
Definition: pba.h:72
@ PBA_PROJECTION_DISTORTION
Definition: pba.h:74
@ PBA_NO_DISTORTION
Definition: pba.h:73
virtual void SetProjection(size_t nproj, const Point2D *imgpts, const int *point_idx, const int *cam_idx)
Definition: pba.cpp:92
@ BUNDLE_ONLY_STRUCTURE
Definition: pba.h:79
@ BUNDLE_FULL
Definition: pba.h:77
@ BUNDLE_ONLY_MOTION
Definition: pba.h:78
virtual int RunBundleAdjustment()
Definition: pba.cpp:96
virtual void SetCameraData(size_t ncam, CameraT *cams)
Definition: pba.cpp:84
Definition: ConfigBA.cpp:44
int ParallelBA_GetVersion()
Definition: pba.cpp:132
ParallelBA * NewParallelBA(ParallelBA::DeviceT device)
Definition: pba.cpp:128
#define PBA_EXPORT_EXTERN
Definition: pba.h:45
#define PBA_EXPORT
Definition: pba.h:44
#define seconds
Definition: rename.h:375