mirror of https://github.com/CGAL/cgal
Make polyhedron_stitching_plugin work for Surface_mesh
This commit is contained in:
parent
c033e45c4f
commit
94d05c2af7
|
|
@ -61,7 +61,7 @@ polyhedron_demo_plugin(polyhedron_slicer_plugin Polyhedron_slicer_plugin ${polyh
|
||||||
target_link_libraries(polyhedron_slicer_plugin scene_polyhedron_item scene_surface_mesh_item scene_basic_objects scene_polylines_item)
|
target_link_libraries(polyhedron_slicer_plugin scene_polyhedron_item scene_surface_mesh_item scene_basic_objects scene_polylines_item)
|
||||||
|
|
||||||
polyhedron_demo_plugin(polyhedron_stitching_plugin Polyhedron_stitching_plugin)
|
polyhedron_demo_plugin(polyhedron_stitching_plugin Polyhedron_stitching_plugin)
|
||||||
target_link_libraries(polyhedron_stitching_plugin scene_polyhedron_item scene_polylines_item)
|
target_link_libraries(polyhedron_stitching_plugin scene_polyhedron_item scene_surface_mesh_item scene_polylines_item)
|
||||||
|
|
||||||
qt5_wrap_ui( selectionUI_FILES Selection_widget.ui)
|
qt5_wrap_ui( selectionUI_FILES Selection_widget.ui)
|
||||||
polyhedron_demo_plugin(selection_plugin Selection_plugin ${selectionUI_FILES})
|
polyhedron_demo_plugin(selection_plugin Selection_plugin ${selectionUI_FILES})
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "Kernel_type.h"
|
#include "Kernel_type.h"
|
||||||
#include "Polyhedron_type.h"
|
#include "Polyhedron_type.h"
|
||||||
#include "Scene_polyhedron_item.h"
|
#include "Scene_polyhedron_item.h"
|
||||||
|
#include "Scene_surface_mesh_item.h"
|
||||||
#include "Scene_polylines_item.h"
|
#include "Scene_polylines_item.h"
|
||||||
|
|
||||||
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
|
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
|
||||||
|
|
@ -62,12 +63,19 @@ public:
|
||||||
bool applicable(QAction*) const {
|
bool applicable(QAction*) const {
|
||||||
Q_FOREACH(int index, scene->selectionIndices())
|
Q_FOREACH(int index, scene->selectionIndices())
|
||||||
{
|
{
|
||||||
if ( qobject_cast<Scene_polyhedron_item*>(scene->item(index)) )
|
if ( qobject_cast<Scene_polyhedron_item*>(scene->item(index)) ||
|
||||||
|
qobject_cast<Scene_surface_mesh_item*>(scene->item(index)) )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Item>
|
||||||
|
void on_actionDetectBorders_triggered(Scene_interface::Item_id index);
|
||||||
|
|
||||||
|
template <typename Item>
|
||||||
|
void on_actionStitchBorders_triggered(Scene_interface::Item_id index);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void on_actionDetectBorders_triggered();
|
void on_actionDetectBorders_triggered();
|
||||||
void on_actionStitchBorders_triggered();
|
void on_actionStitchBorders_triggered();
|
||||||
|
|
@ -75,13 +83,14 @@ public Q_SLOTS:
|
||||||
}; // end Polyhedron_demo_polyhedron_stitching_plugin
|
}; // end Polyhedron_demo_polyhedron_stitching_plugin
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Poly>
|
||||||
struct Polyline_visitor
|
struct Polyline_visitor
|
||||||
{
|
{
|
||||||
Scene_polylines_item* new_item;
|
Scene_polylines_item* new_item;
|
||||||
|
typename boost::property_map<Poly, CGAL::vertex_point_t>::const_type vpm;
|
||||||
|
|
||||||
Polyline_visitor(Scene_polylines_item* new_item)
|
Polyline_visitor(const Poly& poly, Scene_polylines_item* new_item)
|
||||||
: new_item(new_item)
|
: new_item(new_item), vpm(get(CGAL::vertex_point,poly))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void start_new_polyline()
|
void start_new_polyline()
|
||||||
|
|
@ -89,79 +98,82 @@ struct Polyline_visitor
|
||||||
new_item->polylines.push_back( Scene_polylines_item::Polyline() );
|
new_item->polylines.push_back( Scene_polylines_item::Polyline() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_node(boost::graph_traits<Polyhedron>::vertex_descriptor vd)
|
void add_node(typename boost::graph_traits<Poly>::vertex_descriptor vd)
|
||||||
{
|
{
|
||||||
new_item->polylines.back().push_back(vd->point());
|
|
||||||
|
new_item->polylines.back().push_back(get(vpm,vd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void end_polyline(){}
|
void end_polyline(){}
|
||||||
};
|
};
|
||||||
|
|
||||||
void Polyhedron_demo_polyhedron_stitching_plugin::on_actionDetectBorders_triggered()
|
|
||||||
{
|
|
||||||
Q_FOREACH(int index, scene->selectionIndices())
|
|
||||||
{
|
|
||||||
Scene_polyhedron_item* item =
|
|
||||||
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
|
|
||||||
|
|
||||||
if(item)
|
template <typename Item>
|
||||||
|
void Polyhedron_demo_polyhedron_stitching_plugin::on_actionDetectBorders_triggered(Scene_interface::Item_id index)
|
||||||
|
{
|
||||||
|
typedef typename Item::FaceGraph FaceGraph;
|
||||||
|
Item* item = qobject_cast<Item*>(scene->item(index));
|
||||||
|
|
||||||
|
if(item)
|
||||||
{
|
{
|
||||||
Scene_polylines_item* new_item = new Scene_polylines_item();
|
Scene_polylines_item* new_item = new Scene_polylines_item();
|
||||||
|
|
||||||
Polyhedron* pMesh = item->polyhedron();
|
FaceGraph* pMesh = item->polyhedron();
|
||||||
pMesh->normalize_border();
|
normalize_border(*pMesh);
|
||||||
|
|
||||||
#if 0
|
|
||||||
for (Polyhedron::Halfedge_iterator
|
|
||||||
it=pMesh->border_halfedges_begin(), it_end=pMesh->halfedges_end();
|
|
||||||
it!=it_end; ++it)
|
|
||||||
{
|
|
||||||
if (!it->is_border()) continue;
|
|
||||||
/// \todo build cycles and graph with nodes of valence 2.
|
|
||||||
new_item->polylines.push_back( Scene_polylines_item::Polyline() );
|
|
||||||
new_item->polylines.back().push_back( it->opposite()->vertex()->point() );
|
|
||||||
new_item->polylines.back().push_back( it->vertex()->point() );
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
typedef boost::filtered_graph<Polyhedron,Is_border<Polyhedron>, Is_border<Polyhedron> > BorderGraph;
|
|
||||||
|
|
||||||
Is_border<Polyhedron> ib(*pMesh);
|
typedef boost::filtered_graph<FaceGraph,Is_border<FaceGraph>, Is_border<FaceGraph> > BorderGraph;
|
||||||
|
|
||||||
|
Is_border<FaceGraph> ib(*pMesh);
|
||||||
BorderGraph bg(*pMesh,ib,ib);
|
BorderGraph bg(*pMesh,ib,ib);
|
||||||
Polyline_visitor polyline_visitor(new_item);
|
Polyline_visitor<FaceGraph> polyline_visitor(*pMesh, new_item);
|
||||||
CGAL::split_graph_into_polylines( bg,
|
CGAL::split_graph_into_polylines( bg,
|
||||||
polyline_visitor,
|
polyline_visitor,
|
||||||
CGAL::internal::IsTerminalDefault() );
|
CGAL::internal::IsTerminalDefault() );
|
||||||
#endif
|
|
||||||
|
|
||||||
if (new_item->polylines.empty())
|
if (new_item->polylines.empty())
|
||||||
{
|
{
|
||||||
delete new_item;
|
delete new_item;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new_item->setName(tr("Boundary of %1").arg(item->name()));
|
new_item->setName(tr("Boundary of %1").arg(item->name()));
|
||||||
new_item->setColor(Qt::red);
|
new_item->setColor(Qt::red);
|
||||||
scene->addItem(new_item);
|
scene->addItem(new_item);
|
||||||
new_item->invalidateOpenGLBuffers();
|
new_item->invalidateOpenGLBuffers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Polyhedron_demo_polyhedron_stitching_plugin::on_actionDetectBorders_triggered()
|
||||||
|
{
|
||||||
|
Q_FOREACH(int index, scene->selectionIndices()){
|
||||||
|
on_actionDetectBorders_triggered<Scene_polyhedron_item>(index);
|
||||||
|
on_actionDetectBorders_triggered<Scene_surface_mesh_item>(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Item>
|
||||||
|
void Polyhedron_demo_polyhedron_stitching_plugin::on_actionStitchBorders_triggered(Scene_interface::Item_id index)
|
||||||
|
{
|
||||||
|
Item* item =
|
||||||
|
qobject_cast<Item*>(scene->item(index));
|
||||||
|
|
||||||
|
if(item){
|
||||||
|
typename Item::FaceGraph* pMesh = item->polyhedron();
|
||||||
|
CGAL::Polygon_mesh_processing::stitch_borders(*pMesh);
|
||||||
|
item->invalidateOpenGLBuffers();
|
||||||
|
scene->itemChanged(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Polyhedron_demo_polyhedron_stitching_plugin::on_actionStitchBorders_triggered()
|
void Polyhedron_demo_polyhedron_stitching_plugin::on_actionStitchBorders_triggered()
|
||||||
{
|
{
|
||||||
Q_FOREACH(int index, scene->selectionIndices())
|
Q_FOREACH(int index, scene->selectionIndices()){
|
||||||
{
|
on_actionStitchBorders_triggered<Scene_polyhedron_item>(index);
|
||||||
Scene_polyhedron_item* item =
|
on_actionStitchBorders_triggered<Scene_surface_mesh_item>(index);
|
||||||
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
|
|
||||||
|
|
||||||
if(item)
|
|
||||||
{
|
|
||||||
Polyhedron* pMesh = item->polyhedron();
|
|
||||||
CGAL::Polygon_mesh_processing::stitch_borders(*pMesh);
|
|
||||||
item->invalidateOpenGLBuffers();
|
|
||||||
scene->itemChanged(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "Polyhedron_stitching_plugin.moc"
|
#include "Polyhedron_stitching_plugin.moc"
|
||||||
|
|
|
||||||
|
|
@ -462,6 +462,13 @@ bool is_valid(const CGAL::Polyhedron_3<Gt,I,HDS,A>& p, bool verbose = false)
|
||||||
{
|
{
|
||||||
return p.is_valid(verbose);
|
return p.is_valid(verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Gt, class I, CGAL_HDS_PARAM_, class A>
|
||||||
|
void normalize_border(CGAL::Polyhedron_3<Gt,I,HDS,A>& p)
|
||||||
|
{
|
||||||
|
p.normalize_border();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CGAL
|
} // namespace CGAL
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -517,6 +517,10 @@ bool is_valid(const CGAL::Surface_mesh<P>& sm, bool verbose = false)
|
||||||
return sm.is_valid(verbose);
|
return sm.is_valid(verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename P>
|
||||||
|
void normalize_border(const CGAL::Surface_mesh<P>& sm)
|
||||||
|
{}
|
||||||
|
|
||||||
} // namespace CGAL
|
} // namespace CGAL
|
||||||
|
|
||||||
#endif // CGAL_BOOST_GRAPH_TRAITS_SURFACE_MESH_H
|
#endif // CGAL_BOOST_GRAPH_TRAITS_SURFACE_MESH_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue