@@ -24,6 +24,7 @@ typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3;
2424
2525// Mesh Criteria
2626typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
27+ typedef Mesh_criteria::Edge_criteria Edge_criteria;
2728typedef Mesh_criteria::Facet_criteria Facet_criteria;
2829typedef Mesh_criteria::Cell_criteria Cell_criteria;
2930
@@ -54,12 +55,23 @@ generate_mesh(
5455 const bool odt,
5556 const bool perturb,
5657 const bool exude,
57- const double edge_size,
58+ //
59+ const double edge_size_value,
60+ const std::shared_ptr<pygalmesh::SizingFieldBase> & edge_size_field,
61+ //
5862 const double facet_angle,
59- const double facet_size,
60- const double facet_distance,
63+ //
64+ const double facet_size_value,
65+ const std::shared_ptr<pygalmesh::SizingFieldBase> & facet_size_field,
66+ //
67+ const double facet_distance_value,
68+ const std::shared_ptr<pygalmesh::SizingFieldBase> & facet_distance_field,
69+ //
6170 const double cell_radius_edge_ratio,
62- const double cell_size,
71+ //
72+ const double cell_size_value,
73+ const std::shared_ptr<pygalmesh::SizingFieldBase> & cell_size_field,
74+ //
6375 const bool verbose,
6476 const int seed
6577 )
@@ -81,26 +93,73 @@ generate_mesh(
8193 K::Sphere_3 (CGAL::ORIGIN, bounding_sphere_radius2)
8294 );
8395
96+ // cgal_domain.detect_features();
97+
8498 const auto native_features = translate_feature_edges (domain->get_features ());
8599 cgal_domain.add_features (native_features.begin (), native_features.end ());
86100
87101 const auto polylines = translate_feature_edges (feature_edges);
88102 cgal_domain.add_features (polylines.begin (), polylines.end ());
89103
90- Mesh_criteria criteria (
91- CGAL::parameters::edge_size=edge_size,
92- CGAL::parameters::facet_angle=facet_angle,
93- CGAL::parameters::facet_size=facet_size,
94- CGAL::parameters::facet_distance=facet_distance,
95- CGAL::parameters::cell_radius_edge_ratio=cell_radius_edge_ratio,
96- CGAL::parameters::cell_size=cell_size
97- );
98-
99- // Mesh generation
104+ // perhaps there's a more elegant solution here
105+ // see <https://github.com/CGAL/cgal/issues/4145>
100106 if (!verbose) {
101107 // suppress output
102108 std::cerr.setstate (std::ios_base::failbit);
103109 }
110+
111+ // Build the float/field values according to
112+ // <https://github.com/CGAL/cgal/issues/5044#issuecomment-705526982>.
113+
114+ // nested ternary operator
115+ const auto facet_criteria = facet_size_field ? (
116+ facet_distance_field ?
117+ Facet_criteria (
118+ facet_angle,
119+ [&](K::Point_3 p, const int , const Mesh_domain::Index&) {
120+ return facet_size_field->eval ({p.x (), p.y (), p.z ()});
121+ },
122+ [&](K::Point_3 p, const int , const Mesh_domain::Index&) {
123+ return facet_distance_field->eval ({p.x (), p.y (), p.z ()});
124+ }
125+ ) : Facet_criteria (
126+ facet_angle,
127+ [&](K::Point_3 p, const int , const Mesh_domain::Index&) {
128+ return facet_size_field->eval ({p.x (), p.y (), p.z ()});
129+ },
130+ facet_distance_value
131+ )
132+ ) : (
133+ facet_distance_field ?
134+ Facet_criteria (
135+ facet_angle,
136+ facet_size_value,
137+ [&](K::Point_3 p, const int , const Mesh_domain::Index&) {
138+ return facet_distance_field->eval ({p.x (), p.y (), p.z ()});
139+ }
140+ ) : Facet_criteria (
141+ facet_angle,
142+ facet_size_value,
143+ facet_distance_value
144+ )
145+ );
146+
147+ const auto edge_criteria = edge_size_field ?
148+ Edge_criteria (
149+ [&](K::Point_3 p, const int , const Mesh_domain::Index&) {
150+ return edge_size_field->eval ({p.x (), p.y (), p.z ()});
151+ }) : Edge_criteria (edge_size_value);
152+
153+ const auto cell_criteria = cell_size_field ?
154+ Cell_criteria (
155+ cell_radius_edge_ratio,
156+ [&](K::Point_3 p, const int , const Mesh_domain::Index&) {
157+ return cell_size_field->eval ({p.x (), p.y (), p.z ()});
158+ }) : Cell_criteria (cell_radius_edge_ratio, cell_size_value);
159+
160+ const auto criteria = Mesh_criteria (edge_criteria, facet_criteria, cell_criteria);
161+
162+ // Mesh generation
104163 C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(
105164 cgal_domain,
106165 criteria,
@@ -121,115 +180,4 @@ generate_mesh(
121180 return ;
122181}
123182
124- void
125- generate_with_sizing_field (
126- const std::shared_ptr<pygalmesh::DomainBase> & domain,
127- const std::string & outfile,
128- const std::vector<std::vector<std::array<double , 3 >>> & feature_edges,
129- const double bounding_sphere_radius,
130- const bool lloyd,
131- const bool odt,
132- const bool perturb,
133- const bool exude,
134- const double edge_size,
135- const double facet_angle,
136- const double facet_size,
137- const double facet_distance,
138- const double cell_radius_edge_ratio,
139- const std::shared_ptr<pygalmesh::SizingFieldBase> & cell_size,
140- const bool verbose,
141- const int seed
142- )
143- {
144- CGAL::get_default_random () = CGAL::Random (seed);
145-
146- const double bounding_sphere_radius2 = bounding_sphere_radius > 0 ?
147- bounding_sphere_radius*bounding_sphere_radius :
148- // some wiggle room
149- 1.01 * domain->get_bounding_sphere_squared_radius ();
150-
151- // wrap domain
152- const auto d = [&](K::Point_3 p) {
153- return domain->eval ({p.x (), p.y (), p.z ()});
154- };
155-
156- Mesh_domain cgal_domain = Mesh_domain::create_implicit_mesh_domain (
157- d,
158- K::Sphere_3 (CGAL::ORIGIN, bounding_sphere_radius2)
159- );
160-
161- // cgal_domain.detect_features();
162-
163- const auto native_features = translate_feature_edges (domain->get_features ());
164- cgal_domain.add_features (native_features.begin (), native_features.end ());
165-
166- const auto polylines = translate_feature_edges (feature_edges);
167- cgal_domain.add_features (polylines.begin (), polylines.end ());
168-
169- // perhaps there's a more elegant solution here
170- // see <https://github.com/CGAL/cgal/issues/4145>
171- if (!verbose) {
172- // suppress output
173- std::cerr.setstate (std::ios_base::failbit);
174- }
175- if (cell_size) {
176- const auto size = [&](K::Point_3 p, const int , const Mesh_domain::Index&) {
177- return cell_size->eval ({p.x (), p.y (), p.z ()});
178- };
179- auto criteria = Mesh_criteria (
180- CGAL::parameters::edge_size=edge_size,
181- CGAL::parameters::facet_angle=facet_angle,
182- CGAL::parameters::facet_size=facet_size,
183- CGAL::parameters::facet_distance=facet_distance,
184- CGAL::parameters::cell_radius_edge_ratio=cell_radius_edge_ratio,
185- CGAL::parameters::cell_size=size
186- );
187-
188- // Mesh generation
189- C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(
190- cgal_domain,
191- criteria,
192- lloyd ? CGAL::parameters::lloyd () : CGAL::parameters::no_lloyd (),
193- odt ? CGAL::parameters::odt () : CGAL::parameters::no_odt (),
194- perturb ? CGAL::parameters::perturb () : CGAL::parameters::no_perturb (),
195- exude ? CGAL::parameters::exude () : CGAL::parameters::no_exude ()
196- );
197- if (!verbose) {
198- std::cerr.clear ();
199- }
200-
201- // Output
202- std::ofstream medit_file (outfile);
203- c3t3.output_to_medit (medit_file);
204- medit_file.close ();
205- } else {
206- auto criteria = Mesh_criteria (
207- CGAL::parameters::edge_size=edge_size,
208- CGAL::parameters::facet_angle=facet_angle,
209- CGAL::parameters::facet_size=facet_size,
210- CGAL::parameters::facet_distance=facet_distance,
211- CGAL::parameters::cell_radius_edge_ratio=cell_radius_edge_ratio
212- );
213-
214- // Mesh generation
215- C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(
216- cgal_domain,
217- criteria,
218- lloyd ? CGAL::parameters::lloyd () : CGAL::parameters::no_lloyd (),
219- odt ? CGAL::parameters::odt () : CGAL::parameters::no_odt (),
220- perturb ? CGAL::parameters::perturb () : CGAL::parameters::no_perturb (),
221- exude ? CGAL::parameters::exude () : CGAL::parameters::no_exude ()
222- );
223- if (!verbose) {
224- std::cerr.clear ();
225- }
226-
227- // Output
228- std::ofstream medit_file (outfile);
229- c3t3.output_to_medit (medit_file);
230- medit_file.close ();
231- }
232- return ;
233- }
234-
235183} // namespace pygalmesh
0 commit comments