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

Add PMP::longest_edge() #6496

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ The page \ref bgl_namedparameters "Named Parameters" describes their usage.
- \link PMP_measure_grp `CGAL::Polygon_mesh_processing::area()` \endlink
- \link PMP_measure_grp `CGAL::Polygon_mesh_processing::volume()` \endlink
- \link PMP_measure_grp `CGAL::Polygon_mesh_processing::face_border_length()` \endlink
- \link PMP_measure_grp `CGAL::Polygon_mesh_processing::longest_edge()` \endlink
- \link PMP_measure_grp `CGAL::Polygon_mesh_processing::longest_border()` \endlink
- \link PMP_measure_grp `CGAL::Polygon_mesh_processing::centroid()` \endlink
- \link PMP_measure_grp `CGAL::Polygon_mesh_processing::match_faces()` \endlink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,75 @@ squared_edge_length(typename boost::graph_traits<PolygonMesh>::edge_descriptor e
return squared_edge_length(halfedge(e, pmesh), pmesh, np);
}

/**
* \ingroup PMP_measure_grp
*
* returns the longest edge of a given polygon mesh.
*
* @tparam PolygonMesh a model of `HalfedgeListGraph`
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
*
* @param pmesh the polygon mesh in which the longest edge is searched for
* @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
*
* \cgalNamedParamsBegin
* \cgalParamNBegin{vertex_point_map}
* \cgalParamDescription{a property map associating points to the vertices of `pmesh`}
* \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits<PolygonMesh>::%vertex_descriptor`
* as key type and `%Point_3` as value type}
* \cgalParamDefault{`boost::get(CGAL::vertex_point, pmesh)`}
* \cgalParamNEnd
*
* \cgalParamNBegin{geom_traits}
* \cgalParamDescription{an instance of a geometric traits class}
* \cgalParamType{a class model of `Kernel`}
* \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
* \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.}
* \cgalParamNEnd
* \cgalNamedParamsEnd
*
* @return the longest edge in `pmesh`. The return type is an `edge_descriptor`.
*
* @sa `squared_edge_length()`
*/

template<typename PolygonMesh,
typename NamedParameters = parameters::Default_named_parameters>
inline typename boost::graph_traits<PolygonMesh>::edge_descriptor
longest_edge(const PolygonMesh& pmesh, const NamedParameters& np = parameters::default_values()) {
typedef typename GetGeomTraits<PolygonMesh, NamedParameters>::type Geom_traits;

using parameters::choose_parameter;
using parameters::get_parameter;

typename GetVertexPointMap<PolygonMesh, NamedParameters>::const_type
vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
get_const_property_map(CGAL::vertex_point, pmesh));

Geom_traits gt = choose_parameter<Geom_traits>(get_parameter(np, internal_np::geom_traits));

auto edge_range = edges(pmesh);
MaelRL marked this conversation as resolved.
Show resolved Hide resolved

// if mesh has no edges
if (edge_range.begin() == edge_range.end())
return typename boost::graph_traits<PolygonMesh>::edge_descriptor();

auto edge_reference = std::max_element(edge_range.begin(), edge_range.end(), [&, vpm, pmesh](auto l, auto r) {
auto res = gt.compare_squared_distance_3_object()(
get(vpm, source((l), pmesh)),
get(vpm, target((l), pmesh)),
get(vpm, source((r), pmesh)),
get(vpm, target((r), pmesh)));
return res == SMALLER;
});

// if edge_reference is not derefrenceble
MaelRL marked this conversation as resolved.
Show resolved Hide resolved
if (edge_reference == edge_range.end())
return typename boost::graph_traits<PolygonMesh>::edge_descriptor();

return *edge_reference;
}

/**
* \ingroup PMP_measure_grp
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ void test_pmesh(const Mesh& pmesh)
std::cout << "mesh area (NP) = " << mesh_area_np << std::endl;
assert(mesh_area_np > 0);

edge_descriptor edge = PMP::longest_edge(pmesh);
if (edge == edge_descriptor())
{
std::cout << "mesh has no edges" << std::endl;
}
else
{
std::cout << "longest edge is at:" << get(CGAL::vertex_point, pmesh, source(edge, pmesh))
<< " -> " << get(CGAL::vertex_point, pmesh, target(edge, pmesh))<< ", length ="
<< PMP::edge_length(edge, pmesh) << std::endl;
}

std::pair<halfedge_descriptor, FT> res = PMP::longest_border(pmesh);
if(res.first == boost::graph_traits<Mesh>::null_halfedge()){
std::cout << "mesh has no border" << std::endl;
Expand Down