Add a named_parameter to allow self-intersections for clip and split for planes and iso_cuboids

This commit is contained in:
Maxime Gimeno 2020-11-04 10:21:55 +01:00
parent c61b519058
commit 8b0ba4c786
5 changed files with 66 additions and 22 deletions

View File

@ -102,6 +102,7 @@ CGAL_add_named_parameter(halfedges_keeper_t, halfedges_keeper, halfedges_keeper)
CGAL_add_named_parameter(volume_threshold_t, volume_threshold, volume_threshold)
CGAL_add_named_parameter(dry_run_t, dry_run, dry_run)
CGAL_add_named_parameter(do_not_modify_t, do_not_modify, do_not_modify)
CGAL_add_named_parameter(allow_self_intersections_t, allow_self_intersections, allow_self_intersections)
// List of named parameters that we use in the package 'Surface Mesh Simplification'
CGAL_add_named_parameter(get_cost_policy_t, get_cost_policy, get_cost)

View File

@ -98,6 +98,7 @@ void test(const NamedParameters& np)
assert(get_parameter(np, CGAL::internal_np::halfedges_keeper).v == 62);
assert(get_parameter(np, CGAL::internal_np::do_simplify_border).v == 64);
assert(get_parameter(np, CGAL::internal_np::do_not_modify).v == 65);
assert(get_parameter(np, CGAL::internal_np::allow_self_intersections).v == 7538);
assert(get_parameter(np, CGAL::internal_np::maximum_number_of_faces).v == 78910);
// Named parameters that we use in the package 'Surface Mesh Simplification'
@ -186,6 +187,7 @@ void test(const NamedParameters& np)
check_same_type<55>(get_parameter(np, CGAL::internal_np::use_Delaunay_flips));
check_same_type<56>(get_parameter(np, CGAL::internal_np::use_safety_constraints));
check_same_type<65>(get_parameter(np, CGAL::internal_np::do_not_modify));
check_same_type<7538>(get_parameter(np, CGAL::internal_np::allow_self_intersections));
check_same_type<12340>(get_parameter(np, CGAL::internal_np::do_self_intersection_tests));
check_same_type<12341>(get_parameter(np, CGAL::internal_np::do_orientation_tests));
@ -356,6 +358,7 @@ int main()
.use_convex_hull(A<63>(63))
.do_simplify_border(A<64>(64))
.do_not_modify(A<65>(65))
.allow_self_intersections(A<7538>(7538))
.point_map(A<9000>(9000))
.query_point_map(A<9001>(9001))
.normal_map(A<9002>(9002))

View File

@ -669,6 +669,14 @@ clip(TriangleMesh& tm,
* \cgalParamDefault{`true`}
* \cgalParamNEnd
*
* \cgalParamNBegin{allow_self_intersections}
* \cgalParamDescription{If `true`, self-intersections are accepted for `tm`.}
* \cgalParamType{Boolean}
* \cgalParamDefault{`false`}
* \cgalParamExtra{If this option is set to `true`, `tm` is no longer required to be without self-intersection.
* Setting this option to `true` will automatically set `throw_on_self_intersection` to `false`
* and `clip_volume` to `false`.}
* \cgalParamNEnd
* \cgalNamedParamsEnd
*
* @return `true` if the output surface mesh is manifold.
@ -684,6 +692,10 @@ bool clip(TriangleMesh& tm,
#endif
const NamedParameters& np)
{
using parameters::get_parameter;
using parameters::choose_parameter;
namespace PMP = CGAL::Polygon_mesh_processing;
namespace params = PMP::parameters;
if(boost::begin(faces(tm))==boost::end(faces(tm))) return true;
CGAL::Bbox_3 bbox = ::CGAL::Polygon_mesh_processing::bbox(tm);
@ -707,7 +719,8 @@ bool clip(TriangleMesh& tm,
break;
}
return clip(tm, clipper, np, parameters::all_default());
const bool do_not_modify = choose_parameter(get_parameter(np, internal_np::allow_self_intersections), false);
return clip(tm, clipper, np, params::do_not_modify(do_not_modify));
}
/**
@ -758,6 +771,15 @@ bool clip(TriangleMesh& tm,
* \cgalParamType{Boolean}
* \cgalParamDefault{`true`}
* \cgalParamNEnd
*
* \cgalParamNBegin{allow_self_intersections}
* \cgalParamDescription{If `true`, self-intersections are accepted for `tm`.}
* \cgalParamType{Boolean}
* \cgalParamDefault{`false`}
* \cgalParamExtra{If this option is set to `true`, `tm` is no longer required to be without self-intersection.
* Setting this option to `true` will automatically set `throw_on_self_intersection` to `false`
* and `clip_volume` to `false`.}
* \cgalParamNEnd
* \cgalNamedParamsEnd
*
* @return `true` if the output surface mesh is manifold.
@ -773,6 +795,11 @@ bool clip(TriangleMesh& tm,
#endif
const NamedParameters& np)
{
using parameters::get_parameter;
using parameters::choose_parameter;
namespace PMP = CGAL::Polygon_mesh_processing;
namespace params = PMP::parameters;
if(boost::begin(faces(tm))==boost::end(faces(tm))) return true;
TriangleMesh clipper;
@ -781,7 +808,8 @@ bool clip(TriangleMesh& tm,
clipper);
triangulate_faces(clipper);
return clip(tm, clipper, np, parameters::all_default());
const bool do_not_modify = choose_parameter(get_parameter(np, internal_np::allow_self_intersections), false);
return clip(tm, clipper, np, params::do_not_modify(do_not_modify));
}
/*!
@ -914,6 +942,13 @@ void split(TriangleMesh& tm,
* \cgalParamDefault{`false`}
* \cgalParamNEnd
*
* \cgalParamNBegin{allow_self_intersections}
* \cgalParamDescription{If `true`, self-intersections are accepted for `tm`.}
* \cgalParamType{Boolean}
* \cgalParamDefault{`false`}
* \cgalParamExtra{If this option is set to `true`, `tm` is no longer required to be without self-intersection.
* Setting this option to `true` will automatically set `throw_on_self_intersection` to `false`.}
* \cgalParamNEnd
* \cgalNamedParamsEnd
*/
template <class TriangleMesh,
@ -943,7 +978,11 @@ void split(TriangleMesh& tm,
CGAL::Oriented_side os = PMP::internal::clip_to_bbox(plane, bbox, splitter, PMP::parameters::all_default());
if(os == CGAL::ON_ORIENTED_BOUNDARY)
return split(tm, splitter, np, params::all_default());
{
const bool do_not_modify = choose_parameter(get_parameter(np, internal_np::allow_self_intersections), false);
return split(tm, splitter, np, params::do_not_modify(do_not_modify));
}
//else nothing to do, no intersection.
}
@ -1004,6 +1043,15 @@ void split(TriangleMesh& tm,
* \cgalParamDefault{`true`}
* \cgalParamNEnd
*
* * \cgalParamNBegin{allow_self_intersections}
* \cgalParamDescription{If `true`, self-intersections are accepted for `tm`.}
* \cgalParamType{Boolean}
* \cgalParamDefault{`false`}
* \cgalParamExtra{If this option is set to `true`, `tm` is no longer required to be without self-intersection.
* Setting this option to `true` will automatically set `throw_on_self_intersection` to `false`
* and `clip_volume` to `false`.}
* \cgalParamNEnd
*
* \cgalNamedParamsEnd
*/
template <class TriangleMesh,
@ -1016,14 +1064,18 @@ void split(TriangleMesh& tm,
#endif
const NamedParameters& np)
{
using parameters::get_parameter;
using parameters::choose_parameter;
namespace PMP = CGAL::Polygon_mesh_processing;
namespace params = PMP::parameters;
TriangleMesh splitter;
make_hexahedron(iso_cuboid[0], iso_cuboid[1], iso_cuboid[2], iso_cuboid[3],
iso_cuboid[4], iso_cuboid[5], iso_cuboid[6], iso_cuboid[7],
splitter);
triangulate_faces(splitter);
split(tm, splitter, np, parameters::all_default());
const bool do_not_modify = choose_parameter(get_parameter(np, internal_np::allow_self_intersections), false);
return split(tm, splitter, np, params::do_not_modify(do_not_modify));
}
/// \cond SKIP_IN_MANUAL

View File

@ -178,11 +178,6 @@ public Q_SLOTS:
dock_widget->hide();
}
void on_clip_toggled(bool b)
{
ui_widget.do_not_modify_CheckBox->setEnabled(b);
}
void pop_widget()
{
ui_widget.clip_radioButton->toggle();
@ -208,9 +203,6 @@ public Q_SLOTS:
plane->setFlatMode();
plane->setName(tr("Clipping plane"));
connect(ui_widget.clip_radioButton, &QPushButton::toggled,
this, &Clip_polyhedron_plugin::on_clip_toggled);
connect(plane, SIGNAL(destroyed()),
this, SLOT(on_plane_destroyed()));
connect(ui_widget.flip_Button, SIGNAL(clicked()),
@ -267,7 +259,7 @@ public Q_SLOTS:
throw_on_self_intersection(true).
use_compact_clipper(
!ui_widget.coplanarCheckBox->isChecked())
.do_not_modify(ui_widget.do_not_modify_CheckBox->isChecked()));
.allow_self_intersections(ui_widget.do_not_modify_CheckBox->isChecked()));
}
}
catch(CGAL::Polygon_mesh_processing::Corefinement::Self_intersection_exception)
@ -286,7 +278,8 @@ public Q_SLOTS:
{
CGAL::Polygon_mesh_processing::split(*(sm_item->face_graph()),
plane->plane(),
CGAL::Polygon_mesh_processing::parameters::throw_on_self_intersection(true));
CGAL::Polygon_mesh_processing::parameters::throw_on_self_intersection(true)
.allow_self_intersections(ui_widget.do_not_modify_CheckBox->isChecked()));
}
}
catch(CGAL::Polygon_mesh_processing::Corefinement::Self_intersection_exception)
@ -313,11 +306,6 @@ public Q_SLOTS:
QMessageBox::warning(CGAL::Three::Three::mainWindow(), "", "There is a clipper already. If you want to change, please erase the current one.");
return;
}
disconnect(ui_widget.clip_radioButton, &QPushButton::toggled,
this, &Clip_polyhedron_plugin::on_clip_toggled);
ui_widget.do_not_modify_CheckBox->setEnabled(true);
Scene_surface_mesh_item* item = qobject_cast<Scene_surface_mesh_item*>(scene->item(scene->mainSelectionIndex()));
if(!item)
return;

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>353</width>
<width>386</width>
<height>231</height>
</rect>
</property>
@ -135,7 +135,7 @@ Only available in Split mode.</string>
<string>Allow the use of a self-intersected clipper, but prevent the closing of the result.</string>
</property>
<property name="text">
<string>Allow self-intersections in clipper</string>
<string>Allow self-intersections (not in clipper)</string>
</property>
</widget>
</item>