Skip to content

Commit 48ee51e

Browse files
committed
Remove CRTP for HashTSDF class
1 parent 8f82ccc commit 48ee51e

File tree

2 files changed

+61
-146
lines changed

2 files changed

+61
-146
lines changed

modules/rgbd/src/hash_tsdf.cpp

+19-20
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ static inline float tsdfToFloat(TsdfType num)
3737
return float(num) * (-1.f / 128.f);
3838
}
3939

40-
template<typename Derived>
41-
HashTSDFVolume<Derived>::HashTSDFVolume(float _voxelSize, Matx44f _pose, float _raycastStepFactor, float _truncDist,
40+
HashTSDFVolume::HashTSDFVolume(float _voxelSize, const Matx44f& _pose, float _raycastStepFactor, float _truncDist,
4241
int _maxWeight, float _truncateThreshold, int _volumeUnitRes, bool _zFirstMemOrder)
4342
: Volume(_voxelSize, _pose, _raycastStepFactor),
4443
maxWeight(_maxWeight),
@@ -50,26 +49,26 @@ HashTSDFVolume<Derived>::HashTSDFVolume(float _voxelSize, Matx44f _pose, float _
5049
truncDist = std::max(_truncDist, 4.0f * voxelSize);
5150
}
5251

53-
HashTSDFVolumeCPU::HashTSDFVolumeCPU(float _voxelSize, Matx44f _pose, float _raycastStepFactor, float _truncDist,
52+
HashTSDFVolumeCPU::HashTSDFVolumeCPU(float _voxelSize, const Matx44f& _pose, float _raycastStepFactor, float _truncDist,
5453
int _maxWeight, float _truncateThreshold, int _volumeUnitRes, bool _zFirstMemOrder)
55-
: Base(_voxelSize, _pose, _raycastStepFactor, _truncDist, _maxWeight, _truncateThreshold, _volumeUnitRes,
54+
:HashTSDFVolume(_voxelSize, _pose, _raycastStepFactor, _truncDist, _maxWeight, _truncateThreshold, _volumeUnitRes,
5655
_zFirstMemOrder)
5756
{
5857
}
5958

6059
HashTSDFVolumeCPU::HashTSDFVolumeCPU(const VolumeParams& _params, bool _zFirstMemOrder)
61-
: Base(_params.voxelSize, _params.pose.matrix, _params.raycastStepFactor, _params.tsdfTruncDist, _params.maxWeight,
60+
: HashTSDFVolume(_params.voxelSize, _params.pose.matrix, _params.raycastStepFactor, _params.tsdfTruncDist, _params.maxWeight,
6261
_params.depthTruncThreshold, _params.unitResolution, _zFirstMemOrder)
6362
{
6463
}
6564
// zero volume, leave rest params the same
66-
void HashTSDFVolumeCPU::reset_()
65+
void HashTSDFVolumeCPU::reset()
6766
{
6867
CV_TRACE_FUNCTION();
6968
volumeUnits.clear();
7069
}
7170

72-
void HashTSDFVolumeCPU::integrate_(InputArray _depth, float depthFactor, const Matx44f& cameraPose, const Intr& intrinsics, const int frameId)
71+
void HashTSDFVolumeCPU::integrate(InputArray _depth, float depthFactor, const Matx44f& cameraPose, const Intr& intrinsics, const int frameId)
7372
{
7473
CV_TRACE_FUNCTION();
7574

@@ -201,30 +200,30 @@ void HashTSDFVolumeCPU::integrate_(InputArray _depth, float depthFactor, const M
201200
});
202201
}
203202

204-
cv::Vec3i HashTSDFVolumeCPU::volumeToVolumeUnitIdx_(const cv::Point3f& p) const
203+
cv::Vec3i HashTSDFVolumeCPU::volumeToVolumeUnitIdx(const cv::Point3f& p) const
205204
{
206205
return cv::Vec3i(cvFloor(p.x / volumeUnitSize), cvFloor(p.y / volumeUnitSize),
207206
cvFloor(p.z / volumeUnitSize));
208207
}
209208

210-
cv::Point3f HashTSDFVolumeCPU::volumeUnitIdxToVolume_(const cv::Vec3i& volumeUnitIdx) const
209+
cv::Point3f HashTSDFVolumeCPU::volumeUnitIdxToVolume(const cv::Vec3i& volumeUnitIdx) const
211210
{
212211
return cv::Point3f(volumeUnitIdx[0] * volumeUnitSize, volumeUnitIdx[1] * volumeUnitSize,
213212
volumeUnitIdx[2] * volumeUnitSize);
214213
}
215214

216-
cv::Point3f HashTSDFVolumeCPU::voxelCoordToVolume_(const cv::Vec3i& voxelIdx) const
215+
cv::Point3f HashTSDFVolumeCPU::voxelCoordToVolume(const cv::Vec3i& voxelIdx) const
217216
{
218217
return cv::Point3f(voxelIdx[0] * voxelSize, voxelIdx[1] * voxelSize, voxelIdx[2] * voxelSize);
219218
}
220219

221-
cv::Vec3i HashTSDFVolumeCPU::volumeToVoxelCoord_(const cv::Point3f& point) const
220+
cv::Vec3i HashTSDFVolumeCPU::volumeToVoxelCoord(const cv::Point3f& point) const
222221
{
223222
return cv::Vec3i(cvFloor(point.x * voxelSizeInv), cvFloor(point.y * voxelSizeInv),
224223
cvFloor(point.z * voxelSizeInv));
225224
}
226225

227-
TsdfVoxel HashTSDFVolumeCPU::at_(const Vec3i& volumeIdx) const
226+
TsdfVoxel HashTSDFVolumeCPU::at(const Vec3i& volumeIdx) const
228227
{
229228
Vec3i volumeUnitIdx = Vec3i(cvFloor(volumeIdx[0] / volumeUnitResolution),
230229
cvFloor(volumeIdx[1] / volumeUnitResolution),
@@ -248,7 +247,7 @@ TsdfVoxel HashTSDFVolumeCPU::at_(const Vec3i& volumeIdx) const
248247
return volumeUnit->at(volUnitLocalIdx);
249248
}
250249

251-
TsdfVoxel HashTSDFVolumeCPU::at_(const Point3f& point) const
250+
TsdfVoxel HashTSDFVolumeCPU::at(const Point3f& point) const
252251
{
253252
Vec3i volumeUnitIdx = volumeToVolumeUnitIdx(point);
254253
VolumeUnitMap::const_iterator it = volumeUnits.find(volumeUnitIdx);
@@ -338,7 +337,7 @@ inline float interpolate(float tx, float ty, float tz, float vx[8])
338337
}
339338
#endif
340339

341-
float HashTSDFVolumeCPU::interpolateVoxelPoint_(const Point3f& point) const
340+
float HashTSDFVolumeCPU::interpolateVoxelPoint(const Point3f& point) const
342341
{
343342
const Vec3i neighbourCoords[] = { {0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1},
344343
{1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1} };
@@ -383,13 +382,13 @@ float HashTSDFVolumeCPU::interpolateVoxelPoint_(const Point3f& point) const
383382
return interpolate(tx, ty, tz, vx);
384383
}
385384

386-
inline float HashTSDFVolumeCPU::interpolateVoxel_(const cv::Point3f& point) const
385+
inline float HashTSDFVolumeCPU::interpolateVoxel(const cv::Point3f& point) const
387386
{
388387
return interpolateVoxelPoint(point * voxelSizeInv);
389388
}
390389

391390

392-
Point3f HashTSDFVolumeCPU::getNormalVoxel_(const Point3f &point) const
391+
Point3f HashTSDFVolumeCPU::getNormalVoxel(const Point3f &point) const
393392
{
394393
Vec3f normal = Vec3f(0, 0, 0);
395394

@@ -638,7 +637,7 @@ struct HashRaycastInvoker : ParallelLoopBody
638637
const Intr::Reprojector reproj;
639638
};
640639

641-
void HashTSDFVolumeCPU::raycast_(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize,
640+
void HashTSDFVolumeCPU::raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize,
642641
OutputArray _points, OutputArray _normals) const
643642
{
644643
CV_TRACE_FUNCTION();
@@ -719,7 +718,7 @@ struct HashFetchPointsNormalsInvoker : ParallelLoopBody
719718
mutable Mutex mutex;
720719
};
721720

722-
void HashTSDFVolumeCPU::fetchPointsNormals_(OutputArray _points, OutputArray _normals) const
721+
void HashTSDFVolumeCPU::fetchPointsNormals(OutputArray _points, OutputArray _normals) const
723722
{
724723
CV_TRACE_FUNCTION();
725724

@@ -756,7 +755,7 @@ void HashTSDFVolumeCPU::fetchPointsNormals_(OutputArray _points, OutputArray _no
756755
}
757756
}
758757

759-
void HashTSDFVolumeCPU::fetchNormals_(InputArray _points, OutputArray _normals) const
758+
void HashTSDFVolumeCPU::fetchNormals(InputArray _points, OutputArray _normals) const
760759
{
761760
CV_TRACE_FUNCTION();
762761

@@ -785,7 +784,7 @@ void HashTSDFVolumeCPU::fetchNormals_(InputArray _points, OutputArray _normals)
785784
}
786785
}
787786

788-
int HashTSDFVolumeCPU::getVisibleBlocks_(int currFrameId, int frameThreshold) const
787+
int HashTSDFVolumeCPU::getVisibleBlocks(int currFrameId, int frameThreshold) const
789788
{
790789
int numVisibleBlocks = 0;
791790
//! TODO: Iterate over map parallely?

modules/rgbd/src/hash_tsdf.hpp

+42-126
Original file line numberDiff line numberDiff line change
@@ -15,109 +15,6 @@ namespace cv
1515
{
1616
namespace kinfu
1717
{
18-
template<typename Derived>
19-
class HashTSDFVolume : public Volume
20-
{
21-
public:
22-
virtual ~HashTSDFVolume() = default;
23-
24-
virtual void reset() override
25-
{
26-
Derived* derived = static_cast<Derived*>(this);
27-
derived->reset_();
28-
}
29-
30-
virtual void integrate(InputArray _depth, float depthFactor, const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
31-
const int frameId = 0) override
32-
{
33-
Derived* derived = static_cast<Derived*>(this);
34-
derived->integrate_(_depth, depthFactor, cameraPose, intrinsics, frameId);
35-
}
36-
virtual void raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize, OutputArray points,
37-
OutputArray normals) const override
38-
{
39-
const Derived* derived = static_cast<const Derived*>(this);
40-
derived->raycast_(cameraPose, intrinsics, frameSize, points, normals);
41-
}
42-
virtual void fetchNormals(InputArray points, OutputArray _normals) const override
43-
{
44-
const Derived* derived = static_cast<const Derived*>(this);
45-
derived->fetchNormals_(points, _normals);
46-
}
47-
virtual void fetchPointsNormals(OutputArray points, OutputArray normals) const override
48-
{
49-
const Derived* derived = static_cast<const Derived*>(this);
50-
derived->fetchPointsNormals_(points, normals);
51-
}
52-
inline size_t getTotalVolumeUnits() const { return static_cast<const Derived*>(this)->getTotalVolumeUnits_(); }
53-
inline int getVisibleBlocks(int currFrameId, int frameThreshold) const
54-
{
55-
return static_cast<const Derived*>(this)->getVisibleBlocks_(currFrameId, frameThreshold);
56-
}
57-
58-
inline TsdfVoxel at(const Vec3i& volumeIdx) const
59-
{
60-
const Derived* derived = static_cast<const Derived*>(this);
61-
return derived->at_(volumeIdx);
62-
}
63-
//! Return the voxel given the point in volume coordinate system i.e., (metric scale 1 unit =
64-
//! 1m)
65-
inline TsdfVoxel at(const Point3f& point) const
66-
{
67-
const Derived* derived = static_cast<const Derived*>(this);
68-
return derived->at_(point);
69-
}
70-
71-
inline float interpolateVoxelPoint(const Point3f& point) const
72-
{
73-
const Derived* derived = static_cast<const Derived*>(this);
74-
return derived->interpolateVoxelPoint_(point);
75-
}
76-
77-
inline float interpolateVoxel_(const cv::Point3f& point) const
78-
{
79-
const Derived* derived = static_cast<const Derived*>(this);
80-
return derived->interpolateVoxel_(point);
81-
}
82-
inline Point3f getNormalVoxel(const Point3f& point) const
83-
{
84-
const Derived* derived = static_cast<const Derived*>(this);
85-
return derived->getNormalVoxel_(point);
86-
}
87-
88-
//! Utility functions for coordinate transformations
89-
inline Vec3i volumeToVolumeUnitIdx(const Point3f& point) const
90-
{
91-
return static_cast<const Derived*>(this)->volumeToVolumeUnitIdx_(point);
92-
}
93-
inline Point3f volumeUnitIdxToVolume(const Vec3i& volumeUnitIdx) const
94-
{
95-
return static_cast<const Derived*>(this)->volumeUnitIdxToVolume_(volumeUnitIdx);
96-
}
97-
98-
inline Point3f voxelCoordToVolume(const Vec3i& voxelIdx) const
99-
{
100-
return static_cast<const Derived*>(this)->voxelCoordToVolume_(voxelIdx);
101-
}
102-
inline Vec3i volumeToVoxelCoord(const Point3f& point) const { return static_cast<const Derived*>(this)->volumeToVoxelCoord_(point); }
103-
104-
public:
105-
int maxWeight;
106-
float truncDist;
107-
float truncateThreshold;
108-
int volumeUnitResolution;
109-
float volumeUnitSize;
110-
bool zFirstMemOrder;
111-
112-
protected:
113-
//! dimension in voxels, size in meters
114-
//! Use fixed volume cuboid
115-
//! Can be only called by derived class
116-
HashTSDFVolume(float _voxelSize, Matx44f _pose, float _raycastStepFactor, float _truncDist, int _maxWeight,
117-
float _truncateThreshold, int _volumeUnitRes, bool zFirstMemOrder = true);
118-
friend Derived;
119-
};
120-
12118
struct VolumeUnit
12219
{
12320
VolumeUnit() : pVolume(nullptr){};
@@ -146,60 +43,79 @@ struct tsdf_hash
14643
typedef std::unordered_set<Vec3i, tsdf_hash> VolumeUnitIndexSet;
14744
typedef std::unordered_map<Vec3i, VolumeUnit, tsdf_hash> VolumeUnitMap;
14845

149-
class HashTSDFVolumeCPU : public HashTSDFVolume<HashTSDFVolumeCPU>
46+
class HashTSDFVolume : public Volume
47+
{
48+
public:
49+
// dimension in voxels, size in meters
50+
//! Use fixed volume cuboid
51+
HashTSDFVolume(float _voxelSize, const Matx44f& _pose, float _raycastStepFactor, float _truncDist,
52+
int _maxWeight, float _truncateThreshold, int _volumeUnitRes,
53+
bool zFirstMemOrder = true);
54+
55+
virtual ~HashTSDFVolume() = default;
56+
57+
public:
58+
int maxWeight;
59+
float truncDist;
60+
float truncateThreshold;
61+
int volumeUnitResolution;
62+
float volumeUnitSize;
63+
bool zFirstMemOrder;
64+
};
65+
66+
class HashTSDFVolumeCPU : public HashTSDFVolume
15067
{
151-
typedef HashTSDFVolume<HashTSDFVolumeCPU> Base;
15268

15369
public:
15470
// dimension in voxels, size in meters
155-
HashTSDFVolumeCPU(float _voxelSize, Matx44f _pose, float _raycastStepFactor, float _truncDist, int _maxWeight,
71+
HashTSDFVolumeCPU(float _voxelSize, const Matx44f& _pose, float _raycastStepFactor, float _truncDist, int _maxWeight,
15672
float _truncateThreshold, int _volumeUnitRes, bool zFirstMemOrder = true);
15773

15874
HashTSDFVolumeCPU(const VolumeParams& _volumeParams, bool zFirstMemOrder = true);
15975

160-
void integrate_(InputArray _depth, float depthFactor, const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
161-
const int frameId = 0);
162-
void raycast_(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize, OutputArray points,
163-
OutputArray normals) const;
76+
void integrate(InputArray _depth, float depthFactor, const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
77+
const int frameId = 0) override;
78+
void raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize, OutputArray points,
79+
OutputArray normals) const override;
16480

165-
void fetchNormals_(InputArray points, OutputArray _normals) const;
166-
void fetchPointsNormals_(OutputArray points, OutputArray normals) const;
81+
void fetchNormals(InputArray points, OutputArray _normals) const override;
82+
void fetchPointsNormals(OutputArray points, OutputArray normals) const override;
16783

168-
void reset_();
169-
size_t getTotalVolumeUnits_() const { return volumeUnits.size(); }
170-
int getVisibleBlocks_(int currFrameId, int frameThreshold) const;
84+
void reset() override;
85+
size_t getTotalVolumeUnits() const { return volumeUnits.size(); }
86+
int getVisibleBlocks(int currFrameId, int frameThreshold) const;
17187

17288
//! Return the voxel given the voxel index in the universal volume (1 unit = 1 voxel_length)
173-
TsdfVoxel at_(const Vec3i& volumeIdx) const;
89+
TsdfVoxel at(const Vec3i& volumeIdx) const;
17490

17591
//! Return the voxel given the point in volume coordinate system i.e., (metric scale 1 unit =
17692
//! 1m)
177-
TsdfVoxel at_(const Point3f& point) const;
93+
TsdfVoxel at(const Point3f& point) const;
17894

179-
float interpolateVoxelPoint_(const Point3f& point) const;
180-
float interpolateVoxel_(const cv::Point3f& point) const;
181-
Point3f getNormalVoxel_(const cv::Point3f& p) const;
95+
float interpolateVoxelPoint(const Point3f& point) const;
96+
float interpolateVoxel(const cv::Point3f& point) const;
97+
Point3f getNormalVoxel(const cv::Point3f& p) const;
18298

18399
//! Utility functions for coordinate transformations
184-
Vec3i volumeToVolumeUnitIdx_(const Point3f& point) const;
185-
Point3f volumeUnitIdxToVolume_(const Vec3i& volumeUnitIdx) const;
100+
Vec3i volumeToVolumeUnitIdx(const Point3f& point) const;
101+
Point3f volumeUnitIdxToVolume(const Vec3i& volumeUnitIdx) const;
186102

187-
Point3f voxelCoordToVolume_(const Vec3i& voxelIdx) const;
188-
Vec3i volumeToVoxelCoord_(const Point3f& point) const;
103+
Point3f voxelCoordToVolume(const Vec3i& voxelIdx) const;
104+
Vec3i volumeToVoxelCoord(const Point3f& point) const;
189105

190106
public:
191107
//! Hashtable of individual smaller volume units
192108
VolumeUnitMap volumeUnits;
193109
};
194110

195111
template<typename T>
196-
Ptr<HashTSDFVolume<T>> makeHashTSDFVolume(const VolumeParams& _volumeParams)
112+
Ptr<HashTSDFVolume> makeHashTSDFVolume(const VolumeParams& _volumeParams)
197113
{
198114
return makePtr<T>(_volumeParams);
199115
}
200116

201117
template<typename T>
202-
Ptr<HashTSDFVolume<T>> makeHashTSDFVolume(float _voxelSize, Matx44f _pose, float _raycastStepFactor, float _truncDist,
118+
Ptr<HashTSDFVolume> makeHashTSDFVolume(float _voxelSize, Matx44f _pose, float _raycastStepFactor, float _truncDist,
203119
int _maxWeight, float truncateThreshold, int volumeUnitResolution = 16)
204120
{
205121
return makePtr<T>(_voxelSize, _pose, _raycastStepFactor, _truncDist, _maxWeight, truncateThreshold,

0 commit comments

Comments
 (0)