-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add a function to create a LCC from a tet soup #9618
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
6
commits into
CGAL:main
Choose a base branch
from
sloriot:tetsoup_to_lcc
base: main
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| @INCLUDE = ${CGAL_DOC_PACKAGE_DEFAULTS} | ||
|
|
||
| PROJECT_NAME = "CGAL ${CGAL_DOC_VERSION} - Linear Cell Complex" | ||
| INPUT += ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/tetrahedron_soup_to_lcc.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
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
38 changes: 38 additions & 0 deletions
38
Linear_cell_complex/examples/Linear_cell_complex/tetsoup_to_lcc.cpp
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,38 @@ | ||
| #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> | ||
| #include <CGAL/Linear_cell_complex_for_combinatorial_map.h> | ||
| #include <CGAL/tetrahedron_soup_to_lcc.h> | ||
| #include <CGAL/draw_linear_cell_complex.h> | ||
| #include <array> | ||
|
|
||
| #include <CGAL/IO/MEDIT.h> | ||
|
|
||
| using LCC = CGAL::Linear_cell_complex_for_combinatorial_map<3, 3>; | ||
| using Point_3 = CGAL::Exact_predicates_inexact_constructions_kernel::Point_3; | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/elephant.mesh"); | ||
|
|
||
| std::vector<Point_3> points; | ||
| std::vector<std::array<std::size_t,4>> tetras; | ||
| std::vector<int> subdomains; | ||
| std::ifstream in(filename); | ||
| if(!in) | ||
| { | ||
| std::cerr << "Cannot open " << filename << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| CGAL::IO::read_MEDIT(in, points, tetras, subdomains); | ||
|
|
||
| //filter out subdomain 0 | ||
| std::vector<std::array<std::size_t,4>> filtered_tetras; | ||
| for (std::size_t i=0; i<tetras.size(); ++i) | ||
| if (subdomains[i]!=0) | ||
| filtered_tetras.push_back(tetras[i]); | ||
|
|
||
| LCC lcc; | ||
| CGAL::tetrahedron_soup_to_lcc(points, filtered_tetras, lcc); | ||
|
|
||
| CGAL::draw(lcc); | ||
| } |
125 changes: 125 additions & 0 deletions
125
Linear_cell_complex/include/CGAL/tetrahedron_soup_to_lcc.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,125 @@ | ||
| // Copyright (c) 2026 CNRS and LIRIS' Establishments (France). | ||
| // All rights reserved. | ||
| // | ||
| // This file is part of CGAL (www.cgal.org) | ||
| // | ||
| // $URL$ | ||
| // $Id$ | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial | ||
| // | ||
| // Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr> | ||
| // Sebastien Loriot <sebastien.loriot@cgal.org> | ||
| // | ||
|
|
||
| #ifndef CGAL_TETRAHEDRON_SOUP_TO_LCC_H | ||
| #define CGAL_TETRAHEDRON_SOUP_TO_LCC_H | ||
|
|
||
| #include <boost/container_hash/hash.hpp> | ||
| #include <vector> | ||
| #include <array> | ||
| #include <unordered_map> | ||
| #include <algorithm> | ||
|
|
||
| namespace CGAL | ||
| { | ||
| /** | ||
| * @ingroup PkgLinearCellComplexConstructions | ||
| * | ||
| * \brief imports a 3D tetrahedron soup into a linear cell complex. | ||
| * | ||
| * Creates a 3D linear cell complex in `lcc` from a set of points and a range | ||
| * of tetrahedra defined by indices into `points`. The topological 3-combinatorial | ||
| * map is constructed by sewing adjacent 3-volumes (tetrahedra) along matching 2-faces. | ||
| * | ||
| * @tparam LCC a model of the `LinearCellComplex` concept. | ||
| * @tparam PointRange a model of `RandomAccessContainer` with `Point_3` as value type, being compatible with the point type of LCC. | ||
| * @tparam TetrahedronRange a model of `ConstRange` where each element is a container of 4 point indices, accessible using `operator[](int)`. | ||
| * | ||
| * @param points range of 3D points. | ||
| * @param tetrahedra range of tetrahedra, where each tetrahedron is represented by 4 indices corresponding to entries in `points`. | ||
| * @param lcc the target linear cell complex. | ||
| * | ||
| * @return a descriptor to a dart of the created complex, or `LCC::null_descriptor` if the input is empty. | ||
| * | ||
| * @pre `LCC::dimension >= 3` and `LCC::ambient_dimension == 3`. | ||
| * @pre Indices in `tetrahedra` must be valid 0-based indices into `points`. | ||
| * | ||
| * @sa `CGAL::triangulation_3_to_lcc()` | ||
| */ | ||
| template <class LCC, class PointRange, class TetrahedronRange> | ||
| typename LCC::Dart_descriptor | ||
| tetrahedron_soup_to_lcc(const PointRange& points, | ||
| const TetrahedronRange& tetrahedra, | ||
| LCC& lcc) | ||
| { | ||
| static_assert( LCC::dimension>=3 && LCC::ambient_dimension==3 ); | ||
|
|
||
| if (points.empty() || tetrahedra.empty()) | ||
| return LCC::null_descriptor; | ||
|
|
||
| using Dart_descriptor = typename LCC::Dart_descriptor; | ||
|
|
||
| std::vector<typename LCC::Vertex_attribute_descriptor> vertices; | ||
| vertices.reserve(points.size()); | ||
| for(const auto& pt : points) | ||
| vertices.push_back(lcc.create_vertex_attribute(pt)); | ||
|
|
||
| struct Array_hasher | ||
| { | ||
| std::size_t operator()(const std::array<std::size_t, 3>& a) const | ||
| { | ||
| std::size_t seed = 0; | ||
| boost::hash_combine(seed, a[0]); | ||
|
afabri marked this conversation as resolved.
|
||
| boost::hash_combine(seed, a[1]); | ||
| boost::hash_combine(seed, a[2]); | ||
|
|
||
| return seed; | ||
| } | ||
| }; | ||
|
|
||
| std::unordered_map< std::array<std::size_t, 3>, Dart_descriptor, Array_hasher> face_map; | ||
|
|
||
| Dart_descriptor dart = LCC::null_descriptor; | ||
| for (const auto& t : tetrahedra) | ||
| { | ||
| Dart_descriptor res = lcc.make_tetrahedron(vertices[t[0]], | ||
| vertices[t[1]], | ||
| vertices[t[2]], | ||
| vertices[t[3]]); | ||
|
|
||
| if (dart==LCC::null_descriptor) dart = res; | ||
|
|
||
| for (int i=0; i<4; ++i) | ||
| { | ||
| Dart_descriptor curr= LCC::null_descriptor; | ||
| switch (i) | ||
| { | ||
| case 0: curr = lcc.template opposite<2>(lcc.next(res)); break; | ||
| case 1: curr = lcc.template opposite<2>(lcc.previous(res)); break; | ||
| case 2: curr = lcc.template opposite<2>(res); break; | ||
| default: curr = res; break; | ||
| } | ||
|
|
||
| std::array<std::size_t, 3> f{t[(i+1)%4],t[(i+2)%4],t[(i+3)%4]}; | ||
| std::sort(f.begin(), f.end()); | ||
| auto insert_res = face_map.emplace(f, curr); | ||
| if (!insert_res.second) | ||
| { | ||
| Dart_descriptor curr2=insert_res.first->second; | ||
| while (lcc.vertex_attribute(curr2) != | ||
| lcc.vertex_attribute(lcc.other_extremity(curr)) ) | ||
| { | ||
| curr2 = lcc.next(curr2); | ||
| } | ||
| lcc.template topo_sew<3>(curr, lcc.other_orientation(curr2)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| CGAL_assertion(dart!=LCC::null_descriptor); | ||
| return dart; | ||
| } | ||
| } // end of CGAL namespace | ||
|
|
||
|
|
||
| #endif // CGAL_TETRAHEDRON_SOUP_TO_LCC_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
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.