Skip to content
Open
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
46 changes: 46 additions & 0 deletions include/geode/mesh/helpers/mesh_statistics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <geode/mesh/common.hpp>

namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMesh );
ALIAS_2D_AND_3D( SurfaceMesh );
} // namespace geode

namespace geode
{
struct MeshStatistics
{
double min_edge_size{ std::numeric_limits< double >::max() };
double mean_edge_size{ 0. };
double max_edge_size{ std::numeric_limits< double >::min() };
};

template < index_t dimension >
[[nodiscard]] MeshStatistics compute_surface_metrics(
const SurfaceMesh< dimension >& mesh );
} // namespace geode
2 changes: 2 additions & 0 deletions src/geode/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ add_geode_library(
"helpers/euclidean_distance_transform.cpp"
"helpers/gradient_computation.cpp"
"helpers/hausdorff_distance.cpp"
"helpers/mesh_statistics.cpp"
"helpers/rasterize.cpp"
"helpers/ray_tracing.cpp"
"helpers/grid_point_function.cpp"
Expand Down Expand Up @@ -252,6 +253,7 @@ add_geode_library(
"helpers/generic_edged_curve_accessor.hpp"
"helpers/hausdorff_distance.hpp"
"helpers/nnsearch_mesh.hpp"
"helpers/mesh_statistics.hpp"
"helpers/rasterize.hpp"
"helpers/ray_tracing.hpp"
"helpers/grid_point_function.hpp"
Expand Down
74 changes: 74 additions & 0 deletions src/geode/mesh/helpers/mesh_statistics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#include <geode/mesh/helpers/mesh_statistics.hpp>

#include <geode/basic/range.hpp>

#include <geode/mesh/core/surface_mesh.hpp>

namespace
{
} // namespace

namespace geode
{
template < index_t dimension >
[[nodiscard]] MeshStatistics compute_surface_metrics(
const SurfaceMesh< dimension >& mesh )
{
MeshStatistics result;
index_t nb_edges{ 0 };
for( const auto polygon_id : Range{ mesh.nb_polygons() } )
{
for( const auto edge_id :
LRange{ mesh.nb_polygon_edges( polygon_id ) } )
{
const PolygonEdge polygon_edge{ polygon_id, edge_id };
if( const auto adjacent =
mesh.polygon_adjacent( polygon_edge ) )
{
if( adjacent.value() < polygon_id )
{
continue;
}
}
const auto length = mesh.edge_length( polygon_edge );
result.max_edge_size = std::max( result.max_edge_size, length );
result.min_edge_size = std::min( result.min_edge_size, length );
result.mean_edge_size += length;
nb_edges++;
}
}
if( nb_edges != 0 )
{
result.mean_edge_size /= nb_edges;
}
return result;
}

template MeshStatistics compute_surface_metrics< 2 >(
const SurfaceMesh< 2 >& );
template MeshStatistics compute_surface_metrics< 3 >(
const SurfaceMesh< 3 >& );
} // namespace geode
Loading