Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Humble #5

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions include/lvr2/algorithm/GeometryAlgorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ void calcVertexRoughnessAndHeightDifferences(
template<typename BaseVecT>
DenseEdgeMap<float> calcVertexDistances(const BaseMesh<BaseVecT>& 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<typename BaseVecT>
DenseVertexMap<float> calcBorderCosts(const BaseMesh<BaseVecT>& mesh, double border_cost = 1.0);


/**
* @brief Dijkstra's algorithm
*
Expand Down
57 changes: 57 additions & 0 deletions include/lvr2/algorithm/GeometryAlgorithms.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,63 @@ DenseEdgeMap<float> calcVertexDistances(const BaseMesh<BaseVecT> &mesh)
return distances;
}


template <typename BaseVecT>
DenseVertexMap<float> calcBorderCosts(
const BaseMesh<BaseVecT> &mesh,
double border_cost)
{
DenseVertexMap<float> 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:
Expand Down
39 changes: 39 additions & 0 deletions src/tools/lvr2_hdf5_mesh_tool/HDF5MeshTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,45 @@ int main( int argc, char ** argv )
{
std::cout << timestamp << "Height differences already included." << std::endl;
}


// border costs
DenseVertexMap<float> borderCosts;
boost::optional<DenseVertexMap<float>> borderCostsOpt;
if (readFromHdf5)
{
borderCostsOpt = hdf5In.getDenseAttributeMap<DenseVertexMap<float>>("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<DenseVertexMap<float>>(
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
{
Expand Down
1 change: 1 addition & 0 deletions src/tools/lvr2_hdf5_mesh_tool/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Options::Options(int argc, char** argv) : m_descr("Supported options")
("meshName,m", value<string>()->default_value("mesh"), "The name of the mesh to write")
("edgeCollapse,e", value<size_t>()->default_value(0), "Edge collapse reduction algorithm, the number of edges to collapse.")
("localRadius,r", value<float>()->default_value(0.3), "The local radius used for roughness and height differences computation.")
("borderVertexCost,b", value<float>()->default_value(1.0), "Setting the each vertex on the border of the mesh to this value (seperate 'border' layer)")
;


Expand Down
4 changes: 3 additions & 1 deletion src/tools/lvr2_hdf5_mesh_tool/Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Options {
string getMeshName() const { return m_variables["meshName"].as<string>();}
size_t getEdgeCollapseNum() const { return m_variables["edgeCollapse"].as<size_t >();}
float getLocalRadius() const { return m_variables["localRadius"].as<float>();}
float getBorderVertexCost() const { return m_variables["borderVertexCost"].as<float>();}
private:
/// The internally used variable map
variables_map m_variables;
Expand All @@ -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_ */
Loading