-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Shape_detection: Add a way to pass input normal to faces #8638
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
Open
sloriot
wants to merge
16
commits into
CGAL:master
Choose a base branch
from
sloriot:SD_RG_face_normal_map
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1fb933e
add a way to pass input normal to faces
sloriot aaf81af
correctly use the variable
sloriot a82629d
add a new region type and sorting type meant to be used to expend fro…
sloriot a2b77a2
tmp commit so that we can easily test in the demo
sloriot e817be7
fix bugs + add a robust version of the inside region predicate
sloriot e538d5e
keep on the certified version
sloriot 51e4b9a
pass on doc
soesau 18f4e24
modified CHANGES.md
soesau b176ed4
Merge branch 'master' into SD_RG_face_normal_map
soesau 019c0a5
integrating reviews
soesau 4d39793
Merge branch 'master' into SD_RG_face_normal_map
soesau 7e2b312
merge fix
soesau 737c050
extend example to cover Plane_face_region and Face_area_sorting
soesau 7c3103c
added missing typename
soesau 977348f
move ++idx outside the for loop
janetournois b2db06f
Add 'Line_segment_region' and 'Segment_length_sorting'
MaelRL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Face_area_sorting.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,193 @@ | ||||||
// Copyright (c) 2024-2025 GeometryFactory (France). | ||||||
// All rights reserved. | ||||||
// | ||||||
// This file is part of CGAL (www.cgal.org). | ||||||
// | ||||||
// $URL$ | ||||||
// $Id$ | ||||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial | ||||||
// | ||||||
// | ||||||
// Author(s) : Sébastien Loriot | ||||||
// | ||||||
|
||||||
|
||||||
#ifndef CGAL_SHAPE_DETECTION_REGION_GROWING_POLYGON_MESH_FACE_AREA_SORTING_H | ||||||
#define CGAL_SHAPE_DETECTION_REGION_GROWING_POLYGON_MESH_FACE_AREA_SORTING_H | ||||||
|
||||||
#include <CGAL/license/Shape_detection.h> | ||||||
#include <CGAL/Shape_detection/Region_growing/internal/utils.h> | ||||||
|
||||||
namespace CGAL { | ||||||
namespace Shape_detection { | ||||||
namespace Polygon_mesh { | ||||||
|
||||||
/*! | ||||||
\ingroup PkgShapeDetectionRGOnMesh | ||||||
|
||||||
\brief Sorting of polygon mesh faces with respect to their area. | ||||||
|
||||||
`Items` of faces in a polygon mesh are sorted in descending order of area. | ||||||
|
||||||
\tparam GeomTraits | ||||||
a model of `Kernel` | ||||||
|
||||||
\tparam PolygonMesh | ||||||
a model of `FaceListGraph` | ||||||
|
||||||
\tparam VertexToPointMap | ||||||
a model of `ReadablePropertyMap` whose key type is the vertex type of a polygon mesh and | ||||||
value type is `Kernel::Point_3` | ||||||
*/ | ||||||
template< | ||||||
typename GeomTraits, | ||||||
typename PolygonMesh, | ||||||
typename VertexToPointMap = typename boost::property_map<PolygonMesh, CGAL::vertex_point_t>::const_type> | ||||||
class Face_area_sorting | ||||||
{ | ||||||
using vertex_descriptor = typename boost::graph_traits<PolygonMesh>::vertex_descriptor; | ||||||
using face_descriptor = typename boost::graph_traits<PolygonMesh>::face_descriptor; | ||||||
using halfedge_descriptor = typename boost::graph_traits<PolygonMesh>::halfedge_descriptor; | ||||||
using FT = typename GeomTraits::FT; | ||||||
|
||||||
public: | ||||||
/// \name Types | ||||||
/// @{ | ||||||
|
||||||
/// Item type. | ||||||
using Item = typename boost::graph_traits<PolygonMesh>::face_descriptor; | ||||||
|
||||||
/// Seed range. | ||||||
using Seed_range = std::vector<Item>; | ||||||
|
||||||
/// @} | ||||||
|
||||||
/// \name Initialization | ||||||
/// @{ | ||||||
|
||||||
/*! | ||||||
\brief initializes all internal data structures. | ||||||
|
||||||
\tparam NamedParameters | ||||||
a sequence of \ref bgl_namedparameters "Named Parameters" | ||||||
|
||||||
\param pmesh | ||||||
an instance of `PolygonMesh` that represents a polygon mesh | ||||||
|
||||||
\param np | ||||||
a sequence of \ref bgl_namedparameters "Named Parameters" | ||||||
among the ones listed below | ||||||
|
||||||
\cgalNamedParamsBegin | ||||||
\cgalParamNBegin{vertex_point_map} | ||||||
\cgalParamDescription{an instance of `VertexToPointMap` that maps a polygon mesh | ||||||
vertex to `Kernel::Point_3`} | ||||||
\cgalParamDefault{`boost::get(CGAL::vertex_point, pmesh)`} | ||||||
\cgalParamNEnd | ||||||
\cgalParamNBegin{geom_traits} | ||||||
\cgalParamDescription{an instance of `GeomTraits`} | ||||||
\cgalParamDefault{`GeomTraits()`} | ||||||
\cgalParamNEnd | ||||||
\cgalNamedParamsEnd | ||||||
|
||||||
\pre `faces(pmesh).size() > 0` | ||||||
*/ | ||||||
template<typename CGAL_NP_TEMPLATE_PARAMETERS> | ||||||
Face_area_sorting( | ||||||
const PolygonMesh& pmesh, | ||||||
const CGAL_NP_CLASS& np = parameters::default_values()) | ||||||
: m_face_graph(pmesh) | ||||||
, m_vpm(parameters::choose_parameter(parameters::get_parameter(np, internal_np::vertex_point), | ||||||
get_const_property_map(CGAL::vertex_point, pmesh))) | ||||||
, m_traits(parameters::choose_parameter<GeomTraits>(parameters::get_parameter(np, internal_np::geom_traits))) | ||||||
{ | ||||||
CGAL_precondition(faces(pmesh).size() > 0); | ||||||
|
||||||
m_ordered.resize(faces(pmesh).size()); | ||||||
|
||||||
std::size_t index = 0; | ||||||
for (Item item : faces(pmesh)) | ||||||
m_ordered[index++] = item; | ||||||
m_scores.resize(m_ordered.size(), 0.); | ||||||
} | ||||||
|
||||||
/// @} | ||||||
|
||||||
/// \name Sorting | ||||||
/// @{ | ||||||
|
||||||
/*! | ||||||
\brief sorts `Items` of input faces. | ||||||
*/ | ||||||
void sort() { | ||||||
compute_scores(); | ||||||
CGAL_precondition(m_scores.size() > 0); | ||||||
|
||||||
auto cmp = [this](const std::size_t i, const std::size_t j) | ||||||
{ | ||||||
CGAL_precondition(i < m_scores.size()); | ||||||
CGAL_precondition(j < m_scores.size()); | ||||||
return m_scores[i] > m_scores[j]; | ||||||
}; | ||||||
std::vector<std::size_t> order(m_ordered.size()); | ||||||
std::iota(order.begin(), order.end(), 0); | ||||||
std::sort(order.begin(), order.end(), cmp); | ||||||
|
||||||
std::vector<Item> tmp(m_ordered.size()); | ||||||
for (std::size_t i = 0; i < m_ordered.size(); i++) | ||||||
tmp[i] = m_ordered[order[i]]; | ||||||
|
||||||
m_ordered.swap(tmp); | ||||||
} | ||||||
/// @} | ||||||
|
||||||
/// \name Access | ||||||
/// @{ | ||||||
|
||||||
/*! | ||||||
\brief returns an instance of `Seed_range` to access the ordered `Items` | ||||||
of input faces. | ||||||
*/ | ||||||
const Seed_range &ordered() { | ||||||
return m_ordered; | ||||||
} | ||||||
/// @} | ||||||
|
||||||
private: | ||||||
const PolygonMesh& m_face_graph; | ||||||
VertexToPointMap m_vpm; | ||||||
const GeomTraits m_traits; | ||||||
Seed_range m_ordered; | ||||||
std::vector<FT> m_scores; | ||||||
|
||||||
void compute_scores() | ||||||
{ | ||||||
auto squared_area = m_traits.compute_squared_area_3_object(); | ||||||
std::size_t idx = 0; | ||||||
for (Item item : m_ordered) | ||||||
{ | ||||||
halfedge_descriptor hd = halfedge(item, m_face_graph); | ||||||
std::vector<typename GeomTraits::Point_3> pts; | ||||||
|
||||||
for (vertex_descriptor v : vertices_around_face(hd,m_face_graph)) | ||||||
pts.push_back( get(m_vpm, v) ); | ||||||
|
||||||
if (pts.size()==3) | ||||||
m_scores[idx++] = approximate_sqrt(squared_area(pts[0], pts[1], pts[2])); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mael is right, sorting squared areas will give us the same result |
||||||
else | ||||||
{ | ||||||
std::vector<typename GeomTraits::Triangle_3> triangles; | ||||||
internal::triangulate_face<GeomTraits>(pts, triangles); | ||||||
for (const typename GeomTraits::Triangle_3& tr : triangles) | ||||||
m_scores[idx++] += approximate_sqrt(squared_area(tr[0], tr[1], tr[2])); | ||||||
} | ||||||
} | ||||||
} | ||||||
}; | ||||||
|
||||||
} // namespace Polygon_mesh | ||||||
} // namespace Shape_detection | ||||||
} // namespace CGAL | ||||||
|
||||||
#endif // CGAL_SHAPE_DETECTION_REGION_GROWING_POLYGON_MESH_FACE_AREA_SORTING_H | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.