-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
Devel aux
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#include <assetloading/geometryfilter/DenseVoxelGrid.h> | ||
|
||
// *** CONSTRUCTION / DESTRUCTION *** // | ||
// ************************************ // | ||
DenseVoxelGrid::DenseVoxelGrid(size_t const maxNVoxels) : | ||
IVoxelGrid(maxNVoxels) | ||
{ | ||
voxels = new VoxelGridCell[maxNVoxels]; | ||
} | ||
|
||
|
||
// *** VOXEL GRID INTERFACE *** // | ||
// ****************************** // | ||
void DenseVoxelGrid::release(){ | ||
if(voxels != nullptr){ | ||
delete[] voxels; | ||
voxels = nullptr; | ||
} | ||
} | ||
|
||
|
||
bool DenseVoxelGrid::hasVoxel(size_t const key){ | ||
return voxels[key].voxel != nullptr; | ||
} | ||
|
||
Voxel* DenseVoxelGrid::getVoxel(size_t const key){ | ||
return voxels[key].voxel; | ||
} | ||
|
||
Voxel * DenseVoxelGrid::setVoxel( | ||
size_t const key, | ||
double const x, double const y, double const z, | ||
double halfVoxelSize | ||
){ | ||
VoxelGridCell &vgc = voxels[key]; | ||
vgc.voxel = new Voxel(x, y, z, halfVoxelSize); | ||
return vgc.voxel; | ||
} | ||
|
||
void DenseVoxelGrid::deleteVoxel(size_t const key){ | ||
Voxel *voxel = voxels[key].voxel; | ||
if(voxel == nullptr) return; | ||
delete voxel; | ||
voxels[key].voxel = nullptr; | ||
} | ||
|
||
Mat<double> * DenseVoxelGrid::getMatrix(size_t const key) const { | ||
return voxels[key].matrix; | ||
} | ||
|
||
Mat<double> & DenseVoxelGrid::getMatrixRef(size_t const key) const { | ||
return *voxels[key].matrix; | ||
} | ||
|
||
Mat<double> const & DenseVoxelGrid::getMatrixConstRef(size_t const key) const { | ||
return *voxels[key].matrix; | ||
} | ||
|
||
void DenseVoxelGrid::setMatrix(size_t const key, Mat<double> *mat){ | ||
VoxelGridCell &vgc = voxels[key]; | ||
if(vgc.matrix != nullptr) deleteMatrix(key); | ||
vgc.matrix = mat; | ||
} | ||
|
||
void DenseVoxelGrid::setNextMatrixCol( | ||
size_t const key, | ||
double const x, double const y, double const z | ||
) { | ||
VoxelGridCell &vgc = voxels[key]; | ||
size_t const startIdx = vgc.cursor*3; | ||
(*vgc.matrix)[startIdx] = x; | ||
(*vgc.matrix)[startIdx+1] = y; | ||
(*vgc.matrix)[startIdx+2] = z; | ||
++vgc.cursor; | ||
} | ||
|
||
void DenseVoxelGrid::deleteMatrix(size_t const key){ | ||
delete voxels[key].matrix; | ||
voxels[key].matrix = nullptr; | ||
} | ||
void DenseVoxelGrid::deleteMatrices(){ | ||
for(size_t i = 0 ; i < maxNVoxels ; ++i) deleteMatrix(i); | ||
} | ||
|
||
|
||
size_t DenseVoxelGrid::getCursor(size_t const key) const{ | ||
return voxels[key].cursor; | ||
} | ||
|
||
void DenseVoxelGrid::setCursor(size_t const key, size_t const cursor) { | ||
voxels[key].cursor = cursor; | ||
} | ||
|
||
void DenseVoxelGrid::incrementCursor(size_t const key){ | ||
++voxels[key].cursor; | ||
} | ||
|
||
double DenseVoxelGrid::getClosestPointDistance(size_t const key) const { | ||
return voxels[key].closestPointDistance; | ||
} | ||
void DenseVoxelGrid::setClosestPointDistance( | ||
size_t const key, double const distance | ||
) { | ||
voxels[key].closestPointDistance = distance; | ||
} | ||
|
||
|
||
// *** WHILE INTERFACE *** // | ||
// *************************** // | ||
void DenseVoxelGrid::whileLoopStart(){ | ||
for( | ||
whileLoopIter = 0 ; | ||
whileLoopIter < maxNVoxels && voxels[whileLoopIter].voxel == nullptr; | ||
++whileLoopIter | ||
); | ||
} | ||
|
||
bool DenseVoxelGrid::whileLoopHasNext(){ | ||
return whileLoopIter < maxNVoxels; | ||
} | ||
|
||
Voxel * DenseVoxelGrid::whileLoopNext(size_t *key){ | ||
// Obtain current voxel | ||
Voxel *voxel = voxels[whileLoopIter].voxel; | ||
// Obtain the matrix, if requested | ||
if(key != nullptr) *key = whileLoopIter; | ||
// Iterate to find next voxel, if any, and update whileLoopIter | ||
for( | ||
++whileLoopIter; | ||
whileLoopIter < maxNVoxels && voxels[whileLoopIter].voxel == nullptr; | ||
++whileLoopIter | ||
); | ||
// Return current voxel | ||
return voxel; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#pragma once | ||
|
||
#include <assetloading/geometryfilter/IVoxelGrid.h> | ||
|
||
/** | ||
* @author Alberto M. Esmoris Pena | ||
* @version 1.0 | ||
* | ||
* @brief Dense voxel grid implementation of IVoxelGrid. It uses the indices | ||
* of an array to represent the (key, value) pairs as (index, voxel). | ||
* | ||
* @see IVoxelGrid | ||
*/ | ||
class DenseVoxelGrid : public IVoxelGrid { | ||
protected: | ||
// *** ATTRIBUTES *** // | ||
// ********************** // | ||
/** | ||
* @brief Array of voxels. | ||
* @see VoxelGridCell | ||
* @see Voxel | ||
*/ | ||
VoxelGridCell *voxels; | ||
/** | ||
* @brief Used internally to track the current iteration of the while loop. | ||
*/ | ||
size_t whileLoopIter; | ||
|
||
public: | ||
// *** CONSTRUCTION / DESTRUCTION *** // | ||
// ************************************ // | ||
/** | ||
* @brief Constructor for a dense voxel grid. | ||
* @see IVoxelGrid::IVoxelGrid | ||
*/ | ||
DenseVoxelGrid(size_t const maxNVoxels); | ||
virtual ~DenseVoxelGrid() {release();} | ||
|
||
// *** VOXEL GRID INTERFACE *** // | ||
// ****************************** // | ||
/** | ||
* @see IVoxelGrid::release | ||
*/ | ||
void release() override; | ||
|
||
|
||
/** | ||
* @see IVoxelGrid::hasVoxel | ||
*/ | ||
bool hasVoxel(size_t const key) override; | ||
/** | ||
* @see IVoxelGrid::getVoxel | ||
*/ | ||
Voxel* getVoxel(size_t const key) override; | ||
/** | ||
* @see IVoxelGrid::setVoxel | ||
*/ | ||
Voxel * setVoxel( | ||
size_t const key, | ||
double const x, double const y, double const z, | ||
double halfVoxelSize | ||
) override; | ||
/** | ||
* @see IVoxelGrid::deleteVoxel | ||
*/ | ||
void deleteVoxel(size_t const key) override; | ||
|
||
|
||
/** | ||
* @see IVoxelGrid::getMatrix | ||
*/ | ||
Mat<double> * getMatrix(size_t const key) const override; | ||
/** | ||
* @see IVoxelGrid::getMatrixRef | ||
*/ | ||
Mat<double> & getMatrixRef(size_t const key) const override; | ||
/** | ||
* @see IVoxelGrid::getMatrixConstRef | ||
*/ | ||
Mat<double> const & getMatrixConstRef(size_t const key) const override; | ||
/** | ||
* @see IVoxelGrid::setMatrix | ||
*/ | ||
void setMatrix(size_t const key, Mat<double> *mat) override; | ||
/** | ||
* @see IVoxelGrid::setNextMatrixCol | ||
*/ | ||
void setNextMatrixCol( | ||
size_t const key, | ||
double const x, double const y, double const z | ||
) override; | ||
/** | ||
* @see IVoxelGrid::deleteMatrix | ||
*/ | ||
void deleteMatrix(size_t const key) override; | ||
/** | ||
* @see IVoxelGrid::deleteMatrices | ||
*/ | ||
void deleteMatrices() override; | ||
|
||
|
||
/** | ||
* @see IVoxelGrid::getCursor | ||
*/ | ||
size_t getCursor(size_t const key) const override; | ||
/** | ||
* @see IVoxelGrid::setCursor | ||
*/ | ||
void setCursor(size_t const key, size_t const cursor) override; | ||
/** | ||
* @see IVoxelGrid::incrementCursor | ||
*/ | ||
void incrementCursor(size_t const key) override; | ||
|
||
/** | ||
* @see IVoxelGird::getClosestPointDistance | ||
*/ | ||
double getClosestPointDistance(size_t const key) const override; | ||
/** | ||
* @see IVoxelGrid::setClosestPointDistance | ||
*/ | ||
void setClosestPointDistance( | ||
size_t const key, double const distance | ||
) override; | ||
|
||
|
||
// *** WHILE INTERFACE *** // | ||
// *************************** // | ||
/** | ||
* @see IVoxelGrid::whileLoopStart | ||
*/ | ||
void whileLoopStart() override; | ||
/** | ||
* @see IVoxelGrid::whileLoopHasNext | ||
*/ | ||
bool whileLoopHasNext() override; | ||
/** | ||
* @see IVoxelGrid::whileLoopNext | ||
*/ | ||
Voxel * whileLoopNext(size_t *key=nullptr) override; | ||
}; |