From dd8aed4f72acce44c577b3d160d1106344696330 Mon Sep 17 00:00:00 2001 From: Alexander Mock Date: Tue, 10 Dec 2024 18:45:45 +0100 Subject: [PATCH] cleanup --- .../reconstruction/AdaptiveKSearchSurface.hpp | 2 +- .../reconstruction/AdaptiveKSearchSurface.tcc | 10 ---- include/lvr2/reconstruction/FastBox.hpp | 23 +++++--- include/lvr2/reconstruction/FastBox.tcc | 56 ++++++++++--------- .../reconstruction/FastReconstruction.tcc | 26 +++++---- include/lvr2/reconstruction/PointsetGrid.tcc | 6 +- src/tools/lvr2_reconstruct/Main.cpp | 14 +++-- 7 files changed, 76 insertions(+), 61 deletions(-) diff --git a/include/lvr2/reconstruction/AdaptiveKSearchSurface.hpp b/include/lvr2/reconstruction/AdaptiveKSearchSurface.hpp index a5332fad1..23a55c59d 100644 --- a/include/lvr2/reconstruction/AdaptiveKSearchSurface.hpp +++ b/include/lvr2/reconstruction/AdaptiveKSearchSurface.hpp @@ -128,7 +128,7 @@ class AdaptiveKSearchSurface : public PointsetSurface * This Constructor can be used, if only the method "calcPlaneRANSACfromPoints" * is required */ - AdaptiveKSearchSurface(); + AdaptiveKSearchSurface() = delete; /** * @brief Destructor diff --git a/include/lvr2/reconstruction/AdaptiveKSearchSurface.tcc b/include/lvr2/reconstruction/AdaptiveKSearchSurface.tcc index 810ea2959..c8fe4cf0a 100644 --- a/include/lvr2/reconstruction/AdaptiveKSearchSurface.tcc +++ b/include/lvr2/reconstruction/AdaptiveKSearchSurface.tcc @@ -53,15 +53,6 @@ namespace lvr2 { -template -AdaptiveKSearchSurface::AdaptiveKSearchSurface() - : m_calcMethod(0) -{ - this->setKi(10); - this->setKn(10); - this->setKd(10); -} - template AdaptiveKSearchSurface::AdaptiveKSearchSurface( PointBufferPtr buffer, @@ -97,7 +88,6 @@ AdaptiveKSearchSurface::AdaptiveKSearchSurface( //panic_unimplemented("posefile handling"); parseScanPoses(posefile); } - } template diff --git a/include/lvr2/reconstruction/FastBox.hpp b/include/lvr2/reconstruction/FastBox.hpp index 3c217ba66..03988af0f 100644 --- a/include/lvr2/reconstruction/FastBox.hpp +++ b/include/lvr2/reconstruction/FastBox.hpp @@ -125,13 +125,13 @@ class FastBox */ virtual void getSurface( BaseMesh& mesh, - vector>& query_points, - uint &globalIndex + const std::vector>& query_points, + uint& globalIndex ); virtual void getSurface( BaseMesh& mesh, - vector>& query_points, + const std::vector>& query_points, uint& globalIndex, BoundingBox& bb, vector& duplicates, @@ -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::epsilon()) return true; @@ -167,7 +167,12 @@ class FastBox /** * @brief Calculated the index for the MC table */ - int getIndex(vector>& query_points); + int getIndex(const std::vector>& query_points) const; + + /** + * @brief Returns if the box is valid or not + */ + bool isInvalid(const std::vector>& query_points) const; /** * @brief Calculated the 12 possible intersections between @@ -177,7 +182,7 @@ 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 @@ -185,7 +190,7 @@ class FastBox * @param corners The cell corners * @param query_points The query points of the grid */ - void getCorners(BaseVecT corners[], vector>& query_points); + void getCorners(BaseVecT corners[], const std::vector>& query_points) const; /** * @brief Calculates the distance value for the eight cell corners. @@ -193,7 +198,7 @@ class FastBox * @param distances The distance values * @param query_points The query points of the grid */ - void getDistances(float distances[], vector>& query_points); + void getDistances(float distances[], const std::vector>& query_points) const; /*** * @brief Interpolates the intersection between x1 and x1. @@ -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& bb) const; diff --git a/include/lvr2/reconstruction/FastBox.tcc b/include/lvr2/reconstruction/FastBox.tcc index 1bff41555..0198eb9a3 100644 --- a/include/lvr2/reconstruction/FastBox.tcc +++ b/include/lvr2/reconstruction/FastBox.tcc @@ -32,6 +32,7 @@ * Author: Thomas Wiemann */ +#include namespace lvr2 { @@ -82,7 +83,7 @@ uint FastBox::getVertex(int index) template void FastBox::getCorners(BaseVecT corners[], - vector > &qp) + const std::vector > &qp) const { // Get the box corner positions from the query point array for(int i = 0; i < 8; i++) @@ -93,7 +94,7 @@ void FastBox::getCorners(BaseVecT corners[], template void FastBox::getDistances(float distances[], - vector > &qp) + const std::vector > &qp) const { // Get the distance values from the query point array // for the corners of the current box @@ -104,7 +105,7 @@ void FastBox::getDistances(float distances[], } template -int FastBox::getIndex(vector > &qp) +int FastBox::getIndex(const std::vector > &qp) const { // Determine the MC-Table index for the current corner configuration int index = 0; @@ -116,7 +117,20 @@ int FastBox::getIndex(vector > &qp) } template -float FastBox::calcIntersection(float x1, float x2, float d1, float d2) +bool FastBox::isInvalid(const std::vector > &qp) const +{ + for (int i = 0; i < 8; i++) + { + if (qp[m_vertices[i]].m_invalid) + { + return true; + } + } + return false; +} + +template +float FastBox::calcIntersection(float x1, float x2, float d1, float d2) const { // Calculate the surface intersection using linear interpolation @@ -144,9 +158,9 @@ float FastBox::calcIntersection(float x1, float x2, float d1, float d2 } template -void FastBox::getIntersections(BaseVecT* corners, - float* distance, - BaseVecT* positions) +void FastBox::getIntersections(const BaseVecT* corners, + float* distance, + BaseVecT* positions) const { float intersection; @@ -169,7 +183,6 @@ void FastBox::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); @@ -188,37 +201,30 @@ void FastBox::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 void FastBox::getSurface( BaseMesh& mesh, - vector>& qp, - uint &globalIndex -) + const std::vector>& 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) @@ -266,7 +272,7 @@ void FastBox::getSurface( template void FastBox::getSurface( BaseMesh& mesh, - vector>& qp, + const std::vector>& qp, uint &globalIndex, BoundingBox& bb, vector& duplicates, diff --git a/include/lvr2/reconstruction/FastReconstruction.tcc b/include/lvr2/reconstruction/FastReconstruction.tcc index 8f4f6434a..6b28f3a24 100644 --- a/include/lvr2/reconstruction/FastReconstruction.tcc +++ b/include/lvr2/reconstruction/FastReconstruction.tcc @@ -45,28 +45,34 @@ FastReconstruction::FastReconstruction(shared_ptr -void FastReconstruction::getMesh(BaseMesh &mesh) +void FastReconstruction::getMesh(BaseMesh& 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 traits; + std::cout << "Mesh: " << mesh.numVertices() << ", " << mesh.numFaces() << std::endl; + + BoxTraits 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()) { @@ -149,19 +155,19 @@ void FastReconstruction::getMesh(BaseMesh &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 *box = reinterpret_cast *>(cell); box->optimizePlanarFaces(mesh, 5); - ++monitor; + // ++monitor; } } } diff --git a/include/lvr2/reconstruction/PointsetGrid.tcc b/include/lvr2/reconstruction/PointsetGrid.tcc index 14329d3d0..a1ee5269b 100644 --- a/include/lvr2/reconstruction/PointsetGrid.tcc +++ b/include/lvr2/reconstruction/PointsetGrid.tcc @@ -131,7 +131,11 @@ void PointsetGrid::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 { diff --git a/src/tools/lvr2_reconstruct/Main.cpp b/src/tools/lvr2_reconstruct/Main.cpp index 3adf2b988..70ef132dd 100644 --- a/src/tools/lvr2_reconstruct/Main.cpp +++ b/src/tools/lvr2_reconstruct/Main.cpp @@ -412,7 +412,7 @@ std::pair, unique_ptr>> 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" ) @@ -430,9 +430,11 @@ std::pair, unique_ptr>> useVoxelsize, options.extrude() ); + grid->calcDistanceValues(); - auto reconstruction = make_unique>>(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>>(grid); + return std::make_pair(grid, std::move(reconstruction)); } else if(decompositionType == "PMC") { @@ -445,8 +447,9 @@ std::pair, unique_ptr>> options.extrude() ); grid->calcDistanceValues(); - auto reconstruction = make_unique>>(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>>(grid); + return std::make_pair(grid, std::move(reconstruction)); } // else if(decompositionType == "DMC") // { @@ -485,6 +488,7 @@ std::pair, unique_ptr>> 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); }