diff --git a/README.md b/README.md index 44c861ea..7157ff2d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ localization. ## Step 0: Get the source code from our Github repository: -https://github.com/uos/lvr2 - humble branch +https://github.com/uos/lvr2 - develop ## Linux (Ubuntu 18.04, 20.04, 22.04) diff --git a/include/lvr2/algorithm/GeometryAlgorithms.hpp b/include/lvr2/algorithm/GeometryAlgorithms.hpp index 1fe6dbcc..9b37f0f4 100644 --- a/include/lvr2/algorithm/GeometryAlgorithms.hpp +++ b/include/lvr2/algorithm/GeometryAlgorithms.hpp @@ -199,6 +199,18 @@ void calcVertexRoughnessAndHeightDifferences( template DenseEdgeMap calcVertexDistances(const BaseMesh& mesh); + +/** + * @brief Computes / set costs for each border vertex to predefined value + * + * @param mesh The mesh containing the vertices and edges of interest + * @param border_cost Predefined value to set the border vertices to. Defaults to 1.0 + * @return The dense edge map with the border cost values + */ +template +DenseVertexMap calcBorderCosts(const BaseMesh& mesh, double border_cost = 1.0); + + /** * @brief Dijkstra's algorithm * diff --git a/include/lvr2/algorithm/GeometryAlgorithms.tcc b/include/lvr2/algorithm/GeometryAlgorithms.tcc index b897dfcc..610c128e 100644 --- a/include/lvr2/algorithm/GeometryAlgorithms.tcc +++ b/include/lvr2/algorithm/GeometryAlgorithms.tcc @@ -491,6 +491,63 @@ DenseEdgeMap calcVertexDistances(const BaseMesh &mesh) return distances; } + +template +DenseVertexMap calcBorderCosts( + const BaseMesh &mesh, + double border_cost) +{ + DenseVertexMap borderCosts; + borderCosts.reserve(mesh.nextVertexIndex()); + + // Output + string msg = timestamp.getElapsedTime() + "Computing border weights..."; + ProgressBar progress(mesh.numVertices(), msg); + ++progress; + + // Calculate height difference for each vertex + #pragma omp parallel for + for (size_t i = 0; i < mesh.nextVertexIndex(); i++) + { + auto vH = VertexHandle(i); + if (!mesh.containsVertex(vH)) + { + continue; + } + + bool is_border_vertex = false; + for(auto edge : mesh.getEdgesOfVertex(vH)) + { + if(mesh.isBorderEdge(edge)) + { + is_border_vertex = true; + // it's a border vertex. stop searching. early finish + break; + } + } + + // Calculate the final border weight + #pragma omp critical + { + if(is_border_vertex) + { + borderCosts.insert(vH, border_cost); + } else { + borderCosts.insert(vH, 0.0); + } + + ++progress; + } + } + + if(!timestamp.isQuiet()) + { + std::cout << std::endl; + } + + return borderCosts; +} + class CompareDist { public: diff --git a/src/tools/lvr2_hdf5_mesh_tool/HDF5MeshTool.cpp b/src/tools/lvr2_hdf5_mesh_tool/HDF5MeshTool.cpp index 7151084b..91ce1775 100644 --- a/src/tools/lvr2_hdf5_mesh_tool/HDF5MeshTool.cpp +++ b/src/tools/lvr2_hdf5_mesh_tool/HDF5MeshTool.cpp @@ -416,6 +416,45 @@ int main( int argc, char ** argv ) { std::cout << timestamp << "Height differences already included." << std::endl; } + + + // border costs + DenseVertexMap borderCosts; + boost::optional> borderCostsOpt; + if (readFromHdf5) + { + borderCostsOpt = hdf5In.getDenseAttributeMap>("border"); + } + if (borderCostsOpt) + { + std::cout << timestamp << "Using existing border costs..." << std::endl; + borderCosts = *borderCostsOpt; + } + else + { + std::cout << timestamp << "Computing border costs ... Setting border vertex costs to " + << options.getBorderVertexCost() << " ..." << std::endl; + borderCosts = calcBorderCosts(hem, 1.0); + } + if (!borderCostsOpt || !writeToHdf5Input) + { + std::cout << timestamp << "Adding border costs..." << std::endl; + bool addedBorderCosts = hdf5.addDenseAttributeMap>( + hem, borderCosts, "border"); + if (addedBorderCosts) + { + std::cout << timestamp << "successfully added border costs." << std::endl; + } + else + { + std::cout << timestamp << "could not add border costs!" << std::endl; + } + } + else + { + std::cout << timestamp << "Border costs already included." << std::endl; + } + } else { diff --git a/src/tools/lvr2_hdf5_mesh_tool/Options.cpp b/src/tools/lvr2_hdf5_mesh_tool/Options.cpp index 79a02062..eae1cc88 100644 --- a/src/tools/lvr2_hdf5_mesh_tool/Options.cpp +++ b/src/tools/lvr2_hdf5_mesh_tool/Options.cpp @@ -42,6 +42,7 @@ Options::Options(int argc, char** argv) : m_descr("Supported options") ("meshName,m", value()->default_value("mesh"), "The name of the mesh to write") ("edgeCollapse,e", value()->default_value(0), "Edge collapse reduction algorithm, the number of edges to collapse.") ("localRadius,r", value()->default_value(0.3), "The local radius used for roughness and height differences computation.") + ("borderVertexCost,b", value()->default_value(1.0), "Setting the each vertex on the border of the mesh to this value (seperate 'border' layer)") ; diff --git a/src/tools/lvr2_hdf5_mesh_tool/Options.hpp b/src/tools/lvr2_hdf5_mesh_tool/Options.hpp index e43052f8..ec26b5ff 100644 --- a/src/tools/lvr2_hdf5_mesh_tool/Options.hpp +++ b/src/tools/lvr2_hdf5_mesh_tool/Options.hpp @@ -64,6 +64,7 @@ class Options { string getMeshName() const { return m_variables["meshName"].as();} size_t getEdgeCollapseNum() const { return m_variables["edgeCollapse"].as();} float getLocalRadius() const { return m_variables["localRadius"].as();} + float getBorderVertexCost() const { return m_variables["borderVertexCost"].as();} private: /// The internally used variable map variables_map m_variables; @@ -86,10 +87,11 @@ inline ostream& operator<<(ostream& os, const Options &o) cout << "##### Mesh name \t\t: " << o.getMeshName() << endl; cout << "##### Edge collapse num \t\t: " << o.getEdgeCollapseNum() << endl; cout << "##### Local Radius \t\t: " << o.getLocalRadius() << endl; + cout << "##### Border Vertex Cost \t\t: " << o.getBorderVertexCost() << endl; return os; } -} // namespace reconstruct +} // namespace hdf5meshtool #endif /* OPTIONS_H_ */