KrisLibrary  1.0.0
TSDFReconstruction.h
1 #ifndef TSDF_RECONSTRUCTION_H
2 #define TSDF_RECONSTRUCTION_H
3 
4 #include "MultiVolumeGrid.h"
5 #include "SparseVolumeGrid.h"
6 #include <KrisLibrary/meshing/PointCloud.h>
7 #include <KrisLibrary/meshing/TriMesh.h>
8 #include <KrisLibrary/GLdraw/GeometryAppearance.h>
9 #include <KrisLibrary/utils/threadutils.h>
10 #include <map>
11 
12 namespace Geometry {
13 
15 {
16 public:
17  ICPParameters();
18 
19  //input parameters
20  int maxIters;
21  int subsample;
22  bool pointToPlane;
23  Real colorWeight;
24  Real percentileOutliers;
25  Real rmseThreshold,rmseChangeThreshold;
26 
27  //output parameters
28  int numIters;
29  RigidTransform Tcamera;
30  Vector standardError;
31  Real rmseDistance,rmseColor;
32  int numInliers;
33  std::vector<std::pair<Vector3,Vector3> > correspondences;
34 };
35 
42 {
43 public:
44  DenseTSDFReconstruction(const AABB3D& volume,const IntTriple& res,Real truncationDistance=0.1);
46  void SetTruncationDistance(Real truncationDistance);
53  void Register(const Meshing::PointCloud3D& pc,const RigidTransform& Tcamera_est,ICPParameters& params);
55  void Fuse(const RigidTransform& Tcamera,const Meshing::PointCloud3D& pc,Real weight=1.0);
57  void ExtractMesh(Meshing::TriMesh& mesh);
59  void ExtractMesh(Meshing::TriMesh& mesh,GLDraw::GeometryAppearance& app);
61  void ExtractMesh(const AABB3D& roi,Meshing::TriMesh& mesh);
63  void ExtractMesh(const AABB3D& roi,Meshing::TriMesh& mesh,GLDraw::GeometryAppearance& app);
65  void GetColor(const Vector3& point,float* color) const;
67  void ClearPoint(const Vector3& p,Real dist=0,Real weight=1.0);
69  void ClearBox(const Vector3& bmin,const Vector3& bmax,Real weight=1.0);
71  size_t MemoryUsage() const;
72 
76  Real depthStddev0,depthStddev1;
80  bool colored;
82  std::vector<int> auxiliaryAttributes;
83 
84  struct VoxelInfo
85  {
86  unsigned char rgb[3];
87  float occupancy;
88  float weight,surfaceWeight;
89  int lastID;
90  };
91 
93  MultiVolumeGrid auxiliary;
94  Array3D<VoxelInfo> info;
95  int scanID;
96  Meshing::TriMesh currentMesh;
97  int currentMeshID;
98 };
99 
100 
108 {
109 public:
110  SparseTSDFReconstruction(const Vector3& cellSize,Real truncationDistance=0.1);
118  void Register(const Meshing::PointCloud3D& pc,const RigidTransform& Tcamera_est,ICPParameters& params);
120  void Fuse(const RigidTransform& Tcamera,const Meshing::PointCloud3D& pc,Real weight=1.0);
122  void ExtractMesh(Meshing::TriMesh& mesh);
124  void ExtractMesh(Meshing::TriMesh& mesh,GLDraw::GeometryAppearance& app);
126  void ExtractMesh(const AABB3D& roi,Meshing::TriMesh& mesh);
128  void ExtractMesh(const AABB3D& roi,Meshing::TriMesh& mesh,GLDraw::GeometryAppearance& app);
130  void GetColor(const Vector3& point,float* color) const;
132  void ClearPoint(const Vector3& p,Real dist=0,Real weight=1.0);
134  void ClearBox(const Vector3& bmin,const Vector3& bmax,Real weight=1.0);
136  size_t MemoryUsage() const;
137 
138  void StartThreads();
139  void StopThreads();
140 
144  Real depthStddev0,depthStddev1;
148  bool colored;
150  std::vector<int> auxiliaryAttributes;
153 
154  SparseVolumeGrid tsdf;
155  //Indices into ths sparse tsdf's channels (automatically set up on first scan)
156  int depthChannel,weightChannel,ageChannel,rgbChannel,surfaceWeightChannel,auxiliaryChannelStart;
157  int scanID;
158  std::map<int,int> blockLastTouched;
159 
160  //for multithreading
161  std::vector<Thread> threads;
162  std::vector<void*> threadData;
163  Mutex lock;
164 };
165 
166 } //namespace Geometry
167 
168 #endif
A lightweight integer 3-tuple class.
Definition: IntTriple.h:9
bool colored
If true, the TSDF will be colored (as long as the first point cloud is colored) (default true) ...
Definition: TSDFReconstruction.h:148
Real depthStddev0
The standard deviation of a depth value is assumed to be depthStddev0 + d*depthStddev1 (defaults 0...
Definition: TSDFReconstruction.h:76
A class for coloring, texturing, and drawing meshes in OpenGL.
Definition: GeometryAppearance.h:53
A 3D vector class.
Definition: math3d/primitives.h:136
A 3D array over a sparse, axis aligned 3D volume. Has a similar interface as VolumeGrid, but uses a hash grid data structure to achieve better performance in large grids with infinite domain.
Definition: SparseVolumeGrid.h:20
A 3D point cloud class.
Definition: PointCloud.h:50
A 3D axis-aligned bounding box.
Definition: AABB3D.h:13
A rigid-body transformation.
Definition: math3d/primitives.h:820
bool colored
If true, the TSDF will be colored (as long as the first point cloud is colored) (default true) ...
Definition: TSDFReconstruction.h:80
Real forgettingRate
The rate at which voxel data is forgotten due to age e^-(forgettingRate*age) (default 0) ...
Definition: TSDFReconstruction.h:78
std::vector< int > auxiliaryAttributes
These indices are added from a PointCloud&#39;s attributes to the auxilary volume grid (default empty) ...
Definition: TSDFReconstruction.h:150
Performs a kinect-fusion-like sparse TSDF reconstruction. A hash grid is used to build multiple TSDFs...
Definition: TSDFReconstruction.h:107
int numThreads
Number of threads to use (default 1)
Definition: TSDFReconstruction.h:152
Real depthStddev0
The standard deviation of a depth value is assumed to be depthStddev0 + d*depthStddev1 (defaults 0...
Definition: TSDFReconstruction.h:144
A basic triangle mesh.
Definition: TriMesh.h:41
Real truncationDistance
The max truncation distance (default 0.1)
Definition: TSDFReconstruction.h:74
Definition: TSDFReconstruction.h:14
Definition: TSDFReconstruction.h:84
std::vector< int > auxiliaryAttributes
These indices are added from a PointCloud&#39;s attributes to the auxilary volume grid (default empty) ...
Definition: TSDFReconstruction.h:82
A 3D array over an axis-aligned 3D volume, containing one or more channels.
Definition: MultiVolumeGrid.h:20
Definition: threadutils.h:70
Performs a kinect-fusion-like dense TSDF reconstruction.
Definition: TSDFReconstruction.h:41
A three-dimensional m x n x parray.
Definition: array3d.h:31
Real truncationDistance
The max truncation distance (default 0.1)
Definition: TSDFReconstruction.h:142
Contains all definitions in the Geometry package.
Definition: AnyGeometry.cpp:26
Real forgettingRate
The rate at which voxel data is forgotten due to age e^-(forgettingRate*age) (default 0) ...
Definition: TSDFReconstruction.h:146