Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amock committed Dec 10, 2024
1 parent 496dc61 commit dd8aed4
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 61 deletions.
2 changes: 1 addition & 1 deletion include/lvr2/reconstruction/AdaptiveKSearchSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AdaptiveKSearchSurface : public PointsetSurface<BaseVecT>
* This Constructor can be used, if only the method "calcPlaneRANSACfromPoints"
* is required
*/
AdaptiveKSearchSurface();
AdaptiveKSearchSurface() = delete;

/**
* @brief Destructor
Expand Down
10 changes: 0 additions & 10 deletions include/lvr2/reconstruction/AdaptiveKSearchSurface.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@
namespace lvr2
{

template<typename BaseVecT>
AdaptiveKSearchSurface<BaseVecT>::AdaptiveKSearchSurface()
: m_calcMethod(0)
{
this->setKi(10);
this->setKn(10);
this->setKd(10);
}

template<typename BaseVecT>
AdaptiveKSearchSurface<BaseVecT>::AdaptiveKSearchSurface(
PointBufferPtr buffer,
Expand Down Expand Up @@ -97,7 +88,6 @@ AdaptiveKSearchSurface<BaseVecT>::AdaptiveKSearchSurface(
//panic_unimplemented("posefile handling");
parseScanPoses(posefile);
}

}

template<typename BaseVecT>
Expand Down
23 changes: 14 additions & 9 deletions include/lvr2/reconstruction/FastBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ class FastBox
*/
virtual void getSurface(
BaseMesh<BaseVecT>& mesh,
vector<QueryPoint<BaseVecT>>& query_points,
uint &globalIndex
const std::vector<QueryPoint<BaseVecT>>& query_points,
uint& globalIndex
);

virtual void getSurface(
BaseMesh<BaseVecT>& mesh,
vector<QueryPoint<BaseVecT>>& query_points,
const std::vector<QueryPoint<BaseVecT>>& query_points,
uint& globalIndex,
BoundingBox<BaseVecT>& bb,
vector<unsigned int>& duplicates,
Expand All @@ -156,7 +156,7 @@ class FastBox
protected:


inline bool compareFloat(double num1, double num2)
inline bool compareFloat(double num1, double num2) const
{
if(fabs(num1 - num2) < std::numeric_limits<double>::epsilon())
return true;
Expand All @@ -167,7 +167,12 @@ class FastBox
/**
* @brief Calculated the index for the MC table
*/
int getIndex(vector<QueryPoint<BaseVecT>>& query_points);
int getIndex(const std::vector<QueryPoint<BaseVecT>>& query_points) const;

/**
* @brief Returns if the box is valid or not
*/
bool isInvalid(const std::vector<QueryPoint<BaseVecT>>& query_points) const;

/**
* @brief Calculated the 12 possible intersections between
Expand All @@ -177,23 +182,23 @@ class FastBox
* @param distance The corresponding distance value
* @param positions The interpolated intersections.
*/
void getIntersections(BaseVecT* corners, float* distance, BaseVecT* positions);
void getIntersections(const BaseVecT* corners, float* distance, BaseVecT* positions) const;

/**
* @brief Calculates the position of the eight cell corners
*
* @param corners The cell corners
* @param query_points The query points of the grid
*/
void getCorners(BaseVecT corners[], vector<QueryPoint<BaseVecT>>& query_points);
void getCorners(BaseVecT corners[], const std::vector<QueryPoint<BaseVecT>>& query_points) const;

/**
* @brief Calculates the distance value for the eight cell corners.
*
* @param distances The distance values
* @param query_points The query points of the grid
*/
void getDistances(float distances[], vector<QueryPoint<BaseVecT>>& query_points);
void getDistances(float distances[], const std::vector<QueryPoint<BaseVecT>>& query_points) const;

/***
* @brief Interpolates the intersection between x1 and x1.
Expand All @@ -204,7 +209,7 @@ class FastBox
* @param d2 The distance value for the second coordinate
* @return The interpolated distance.
*/
float calcIntersection(float x1, float x2, float d1, float d2);
float calcIntersection(float x1, float x2, float d1, float d2) const;

float distanceToBB(const BaseVecT& v, const BoundingBox<BaseVecT>& bb) const;

Expand Down
56 changes: 31 additions & 25 deletions include/lvr2/reconstruction/FastBox.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Author: Thomas Wiemann
*/

#include <vector>

namespace lvr2
{
Expand Down Expand Up @@ -82,7 +83,7 @@ uint FastBox<BaseVecT>::getVertex(int index)

template<typename BaseVecT>
void FastBox<BaseVecT>::getCorners(BaseVecT corners[],
vector<QueryPoint<BaseVecT> > &qp)
const std::vector<QueryPoint<BaseVecT> > &qp) const
{
// Get the box corner positions from the query point array
for(int i = 0; i < 8; i++)
Expand All @@ -93,7 +94,7 @@ void FastBox<BaseVecT>::getCorners(BaseVecT corners[],

template<typename BaseVecT>
void FastBox<BaseVecT>::getDistances(float distances[],
vector<QueryPoint<BaseVecT> > &qp)
const std::vector<QueryPoint<BaseVecT> > &qp) const
{
// Get the distance values from the query point array
// for the corners of the current box
Expand All @@ -104,7 +105,7 @@ void FastBox<BaseVecT>::getDistances(float distances[],
}

template<typename BaseVecT>
int FastBox<BaseVecT>::getIndex(vector<QueryPoint<BaseVecT> > &qp)
int FastBox<BaseVecT>::getIndex(const std::vector<QueryPoint<BaseVecT> > &qp) const
{
// Determine the MC-Table index for the current corner configuration
int index = 0;
Expand All @@ -116,7 +117,20 @@ int FastBox<BaseVecT>::getIndex(vector<QueryPoint<BaseVecT> > &qp)
}

template<typename BaseVecT>
float FastBox<BaseVecT>::calcIntersection(float x1, float x2, float d1, float d2)
bool FastBox<BaseVecT>::isInvalid(const std::vector<QueryPoint<BaseVecT> > &qp) const
{
for (int i = 0; i < 8; i++)
{
if (qp[m_vertices[i]].m_invalid)
{
return true;
}
}
return false;
}

template<typename BaseVecT>
float FastBox<BaseVecT>::calcIntersection(float x1, float x2, float d1, float d2) const
{

// Calculate the surface intersection using linear interpolation
Expand Down Expand Up @@ -144,9 +158,9 @@ float FastBox<BaseVecT>::calcIntersection(float x1, float x2, float d1, float d2
}

template<typename BaseVecT>
void FastBox<BaseVecT>::getIntersections(BaseVecT* corners,
float* distance,
BaseVecT* positions)
void FastBox<BaseVecT>::getIntersections(const BaseVecT* corners,
float* distance,
BaseVecT* positions) const
{
float intersection;

Expand All @@ -169,7 +183,6 @@ void FastBox<BaseVecT>::getIntersections(BaseVecT* corners,
intersection = calcIntersection(corners[5].y, corners[6].y, distance[5], distance[6]);
positions[5] = BaseVecT(corners[5].x, intersection, corners[5].z);


intersection = calcIntersection(corners[7].x, corners[6].x, distance[7], distance[6]);
positions[6] = BaseVecT(intersection, corners[6].y, corners[6].z);

Expand All @@ -188,37 +201,30 @@ void FastBox<BaseVecT>::getIntersections(BaseVecT* corners,

intersection = calcIntersection(corners[2].z, corners[6].z, distance[2], distance[6]);
positions[11] = BaseVecT(corners[2].x, corners[2].y, intersection);

}


template<typename BaseVecT>
void FastBox<BaseVecT>::getSurface(
BaseMesh<BaseVecT>& mesh,
vector<QueryPoint<BaseVecT>>& qp,
uint &globalIndex
)
const std::vector<QueryPoint<BaseVecT>>& qp,
uint& globalIndex)
{
// Do not create triangles for invalid boxes
if(isInvalid(qp))
{
return;
}

BaseVecT corners[8];
BaseVecT vertex_positions[12];

float distances[8];

getCorners(corners, qp);
getDistances(distances, qp);
getIntersections(corners, distances, vertex_positions);

int index = getIndex(qp);

// Do not create triangles for invalid boxes
for (int i = 0; i < 8; i++)
{
if (qp[m_vertices[i]].m_invalid)
{
return;
}
}

// Generate the local approximation surface according to the marching
// cubes table by Paul Burke.
for(int a = 0; MCTable[index][a] != -1; a+= 3)
Expand Down Expand Up @@ -266,7 +272,7 @@ void FastBox<BaseVecT>::getSurface(
template<typename BaseVecT>
void FastBox<BaseVecT>::getSurface(
BaseMesh<BaseVecT>& mesh,
vector<QueryPoint<BaseVecT>>& qp,
const std::vector<QueryPoint<BaseVecT>>& qp,
uint &globalIndex,
BoundingBox<BaseVecT>& bb,
vector<unsigned int>& duplicates,
Expand Down
26 changes: 16 additions & 10 deletions include/lvr2/reconstruction/FastReconstruction.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,34 @@ FastReconstruction<BaseVecT, BoxT>::FastReconstruction(shared_ptr<HashGrid<BaseV
}

template<typename BaseVecT, typename BoxT>
void FastReconstruction<BaseVecT, BoxT>::getMesh(BaseMesh<BaseVecT> &mesh)
void FastReconstruction<BaseVecT, BoxT>::getMesh(BaseMesh<BaseVecT>& mesh)
{
// Status message for mesh generation
lvr2::Monitor monitor(lvr2::LogLevel::info, "Creating mesh", m_grid->getNumberOfCells());
// lvr2::Monitor monitor(lvr2::LogLevel::info, "Creating mesh", m_grid->getNumberOfCells());

// Some pointers
BoxT* b;
// BoxT* b; // his is never used
unsigned int global_index = mesh.numVertices();
std::cout << "Using global index: " << global_index << std::endl;

// Iterate through cells and calculate local approximations
for(auto& [ _, cell ] : m_grid->getCells())
{
// std::cout << "Hello!" << std::endl;
cell->getSurface(mesh, m_grid->getQueryPoints(), global_index);
if(!timestamp.isQuiet())
++monitor;
// if(!timestamp.isQuiet())
// {
// ++monitor;
// }
}

BoxTraits<BoxT> traits;
std::cout << "Mesh: " << mesh.numVertices() << ", " << mesh.numFaces() << std::endl;

BoxTraits<BoxT> traits; // this is never set? so the rest will never be called?

if(traits.type == "SharpBox") // Perform edge flipping for extended marching cubes
{
lvr2::Monitor SFProgress(lvr2::LogLevel::info, "Flipping edges", this->m_grid->getNumberOfCells());
// lvr2::Monitor SFProgress(lvr2::LogLevel::info, "Flipping edges", this->m_grid->getNumberOfCells());
for(auto& [ _, cell ] : m_grid->getCells())
{

Expand Down Expand Up @@ -149,19 +155,19 @@ void FastReconstruction<BaseVecT, BoxT>::getMesh(BaseMesh<BaseVecT> &mesh)
}
}
}
++SFProgress;
// ++SFProgress;
}
}

if (traits.type == "BilinearFastBox")
{
lvr2::Monitor monitor(lvr2::LogLevel::info, "Optimizing plane contours", this->m_grid->getNumberOfCells());
// lvr2::Monitor monitor(lvr2::LogLevel::info, "Optimizing plane contours", this->m_grid->getNumberOfCells());
for (auto &[_, cell] : m_grid->getCells())
{
// F... type safety. According to traits object this is OK!
BilinearFastBox<BaseVecT> *box = reinterpret_cast<BilinearFastBox<BaseVecT> *>(cell);
box->optimizePlanarFaces(mesh, 5);
++monitor;
// ++monitor;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion include/lvr2/reconstruction/PointsetGrid.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ void PointsetGrid<BaseVecT, BoxT>::calcDistanceValues()
std::tie(projectedDistance, euklideanDistance) =
this->m_surface->distance(this->m_queryPoints[i].m_position);
// if (euklideanDistance > 10 * this->m_voxelsize)
if (euklideanDistance > 1.7320 * this->m_voxelsize)

// the mesh gets holes for if this value is set to something < 1.7320508075688772
// it stays consistent for everything > 1.7320508075688772, however, the runtime gets worse
// so: 1.75
if (euklideanDistance > 1.75 * this->m_voxelsize)
{
this->m_queryPoints[i].m_invalid = true;
} else {
Expand Down
14 changes: 9 additions & 5 deletions src/tools/lvr2_reconstruct/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ std::pair<shared_ptr<GridBase>, unique_ptr<FastReconstructionBase<Vec>>>
float resolution = useVoxelsize ? options.getVoxelsize() : options.getIntersections();

// Create a point set grid for reconstruction
string decompositionType = options.getDecomposition();
std::string decompositionType = options.getDecomposition();

// Fail safe check
if(decompositionType != "MT" && decompositionType != "MC" && decompositionType != "DMC" && decompositionType != "PMC" && decompositionType != "SF" )
Expand All @@ -430,9 +430,11 @@ std::pair<shared_ptr<GridBase>, unique_ptr<FastReconstructionBase<Vec>>>
useVoxelsize,
options.extrude()
);

grid->calcDistanceValues();
auto reconstruction = make_unique<FastReconstruction<Vec, FastBox<Vec>>>(grid);
return make_pair(grid, std::move(reconstruction));
lvr2::logout::get() << lvr2::info << "[LVR2 Reconstruct] Grid Cells: " << grid->getCells().size() << lvr2::endl;
auto reconstruction = std::make_unique<FastReconstruction<Vec, FastBox<Vec>>>(grid);
return std::make_pair(grid, std::move(reconstruction));
}
else if(decompositionType == "PMC")
{
Expand All @@ -445,8 +447,9 @@ std::pair<shared_ptr<GridBase>, unique_ptr<FastReconstructionBase<Vec>>>
options.extrude()
);
grid->calcDistanceValues();
auto reconstruction = make_unique<FastReconstruction<Vec, BilinearFastBox<Vec>>>(grid);
return make_pair(grid, std::move(reconstruction));
lvr2::logout::get() << lvr2::info << "[LVR2 Reconstruct] Grid Cells: " << grid->getCells().size() << lvr2::endl;
auto reconstruction = std::make_unique<FastReconstruction<Vec, BilinearFastBox<Vec>>>(grid);
return std::make_pair(grid, std::move(reconstruction));
}
// else if(decompositionType == "DMC")
// {
Expand Down Expand Up @@ -485,6 +488,7 @@ std::pair<shared_ptr<GridBase>, unique_ptr<FastReconstructionBase<Vec>>>
return make_pair(grid, std::move(reconstruction));
}

lvr2::logout::get() << lvr2::warning << "[LVR2 Reconstruct] Unsupported decomposition type " << decompositionType << "." << lvr2::endl;
return make_pair(nullptr, nullptr);
}

Expand Down

0 comments on commit dd8aed4

Please sign in to comment.