-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Isotropic remeshing: add example with custom dummy sizing #7873
Merged
lrineau
merged 6 commits into
CGAL:master
from
sloriot:PMP-improve_sizing_concept_and_new_ex
Dec 11, 2023
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
730bbba
add an example with a dummy custom sizing field
sloriot 37fb95b
improve concept
sloriot fe32ee5
at Eigen dependency
sloriot dc04e5b
use doxygen macro
sloriot 7aab407
add user friendly use case
sloriot 9695579
typo
sloriot 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 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 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
101 changes: 101 additions & 0 deletions
101
...ssing/examples/Polygon_mesh_processing/isotropic_remeshing_with_custom_sizing_example.cpp
This file contains 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,101 @@ | ||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> | ||
#include <CGAL/Surface_mesh.h> | ||
#include <CGAL/Polygon_mesh_processing/remesh.h> | ||
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h> | ||
#include <CGAL/Polygon_mesh_processing/bbox.h> | ||
|
||
#include <fstream> | ||
|
||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; | ||
typedef CGAL::Surface_mesh<K::Point_3> Mesh; | ||
|
||
namespace PMP = CGAL::Polygon_mesh_processing; | ||
|
||
// a sizing fied that is increasing the size of edge along the y-axis | ||
// starting at a minimum size at y-max and ending at a maximum size at | ||
// y-min, with a linear interpolation of sizes in between the two extreme | ||
// sizing values | ||
struct My_sizing_field | ||
{ | ||
double min_size, max_size; | ||
double ymin, ymax; | ||
|
||
My_sizing_field(double min_size, double max_size, double ymin, double ymax) | ||
: min_size(min_size) | ||
, max_size(max_size) | ||
, ymin(ymin) | ||
, ymax(ymax) | ||
{} | ||
|
||
double at(K::Point_3 p) const | ||
{ | ||
double y=p.y(); | ||
return CGAL::square( (y-ymin)/(ymax-ymin) * (min_size - max_size) + max_size ); | ||
} | ||
double at(const Mesh::Vertex_index v, const Mesh& mesh) const { return at(mesh.point(v)); } | ||
|
||
std::optional<double> is_too_long(const Mesh::Vertex_index va, | ||
const Mesh::Vertex_index vb, | ||
const Mesh& mesh) const | ||
{ | ||
// TODO: no mesh as parameters? | ||
K::Point_3 mp = CGAL::midpoint(mesh.point(va), mesh.point(vb)); | ||
double sql_at = at(mp); | ||
double sql = CGAL::squared_distance(mesh.point(va), mesh.point(vb)); | ||
if (sql > sql_at) | ||
return sql / sql_at; | ||
return std::nullopt; | ||
} | ||
|
||
std::optional<double> is_too_short(const Mesh::Halfedge_index h, | ||
const Mesh& mesh) const | ||
{ | ||
K::Point_3 mp = CGAL::midpoint(mesh.point(source(h, mesh)), mesh.point(target(h, mesh))); | ||
double sql_at = at(mp); | ||
double sql = CGAL::squared_distance(mesh.point(source(h, mesh)), mesh.point(target(h, mesh))); | ||
if (sql < sql_at) | ||
return sql / sql_at; | ||
return std::nullopt; | ||
} | ||
|
||
K::Point_3 split_placement(const Mesh::Halfedge_index h, | ||
const Mesh& mesh) const | ||
{ | ||
return CGAL::midpoint(mesh.point(source(h, mesh)), mesh.point(target(h, mesh))); | ||
} | ||
|
||
void register_split_vertex(const Mesh::Vertex_index, const Mesh&) {} | ||
}; | ||
|
||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/elk.off"); | ||
|
||
Mesh mesh; | ||
if (!PMP::IO::read_polygon_mesh(filename, mesh) || !CGAL::is_triangle_mesh(mesh)) { | ||
std::cerr << "Not a valid input file." << std::endl; | ||
return 1; | ||
} | ||
|
||
std::cout << "Start remeshing of " << filename | ||
<< " (" << num_faces(mesh) << " faces)..." << std::endl; | ||
|
||
CGAL::Bbox_3 bb = PMP::bbox(mesh); | ||
My_sizing_field sizing_field(0.1, 30, bb.ymin(), bb.ymax()); | ||
unsigned int nb_iter = 5; | ||
|
||
PMP::isotropic_remeshing( | ||
faces(mesh), | ||
sizing_field, | ||
mesh, | ||
CGAL::parameters::number_of_iterations(nb_iter) | ||
.number_of_relaxation_steps(3) | ||
); | ||
|
||
CGAL::IO::write_polygon_mesh("custom_remesh_out.off", mesh, CGAL::parameters::stream_precision(17)); | ||
|
||
std::cout << "Remeshing done." << std::endl; | ||
|
||
return 0; | ||
} |
This file contains 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 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we mention that the sizing field at
v
may have to be updated?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sizing field class does register it and does what it needs to do. Uniform_sizing is not using it and neither does the custom example. Something like, "can be used to updated pre-computed sizing" can be added if you want to insist on that point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think that it is important to say it. If there is nothing to update, then it's easy. Otherwise it's good to know that it is here that the user should do it.