mirror of https://github.com/CGAL/cgal
Join_and_split_polyhedra_plugin works with both Polyhedron and Surface_mesh.
This commit is contained in:
parent
d87dc4473d
commit
4ccf71779e
|
|
@ -39,6 +39,10 @@ target_link_libraries(inside_out_plugin scene_polyhedron_item scene_polygon_soup
|
|||
polyhedron_demo_plugin(join_and_split_polyhedra_plugin Join_and_split_polyhedra_plugin)
|
||||
target_link_libraries(join_and_split_polyhedra_plugin scene_polyhedron_item scene_polyhedron_selection_item)
|
||||
|
||||
polyhedron_demo_plugin(join_and_split_sm_plugin Join_and_split_polyhedra_plugin)
|
||||
target_link_libraries(join_and_split_sm_plugin scene_surface_mesh_item scene_surface_mesh_selection_item)
|
||||
target_compile_definitions(join_and_split_sm_plugin PUBLIC "-DUSE_SURFACE_MESH")
|
||||
|
||||
qt5_wrap_ui( Mean_curvature_flow_skeleton_pluginUI_FILES Mean_curvature_flow_skeleton_plugin.ui)
|
||||
polyhedron_demo_plugin(mean_curvature_flow_skeleton_plugin Mean_curvature_flow_skeleton_plugin ${Mean_curvature_flow_skeleton_pluginUI_FILES})
|
||||
target_link_libraries(mean_curvature_flow_skeleton_plugin
|
||||
|
|
|
|||
|
|
@ -2,8 +2,14 @@
|
|||
#include <QMessageBox>
|
||||
#include <QMainWindow>
|
||||
#include "Kernel_type.h"
|
||||
#ifdef USE_SURFACE_MESH
|
||||
#include "Scene_surface_mesh_item.h"
|
||||
#include <CGAL/Mesh_3/properties_Surface_mesh.h>
|
||||
#else
|
||||
#include "Polyhedron_type.h"
|
||||
#include "Scene_polyhedron_item.h"
|
||||
#include <CGAL/Mesh_3/properties_Polyhedron_3.h>
|
||||
#endif
|
||||
#include "Scene_polyhedron_selection_item.h"
|
||||
#include "Scene_polylines_item.h"
|
||||
#include "Messages_interface.h"
|
||||
|
|
@ -12,8 +18,10 @@
|
|||
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
|
||||
|
||||
#include <CGAL/Polyhedron_copy_3.h>
|
||||
#include <CGAL/boost/graph/Face_filtered_graph.h>
|
||||
#include <CGAL/Polygon_mesh_processing/connected_components.h>
|
||||
#include <CGAL/internal/corefinement/connected_components.h>
|
||||
|
||||
#include <CGAL/boost/graph/copy_face_graph.h>
|
||||
|
||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||
#include <CGAL/property_map.h>
|
||||
|
|
@ -22,6 +30,13 @@
|
|||
#include <boost/function_output_iterator.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include "Color_map.h"
|
||||
|
||||
#ifdef USE_SURFACE_MESH
|
||||
typedef Scene_surface_mesh_item Scene_facegraph_item;
|
||||
#else
|
||||
typedef Scene_polyhedron_item Scene_facegraph_item;
|
||||
#endif
|
||||
typedef Scene_facegraph_item::Face_graph FaceGraph;
|
||||
using namespace CGAL::Three;
|
||||
class Polyhedron_demo_join_and_split_polyhedra_plugin:
|
||||
public QObject,
|
||||
|
|
@ -60,7 +75,7 @@ public:
|
|||
{
|
||||
Q_FOREACH(int index, scene->selectionIndices())
|
||||
{
|
||||
if (qobject_cast<Scene_polyhedron_item*>(scene->item(index)))
|
||||
if (qobject_cast<Scene_facegraph_item*>(scene->item(index)))
|
||||
return true;
|
||||
else if (a == actionColorConnectedComponents
|
||||
&& qobject_cast<Scene_polyhedron_selection_item*>(scene->item(index)))
|
||||
|
|
@ -82,9 +97,9 @@ private :
|
|||
void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionJoinPolyhedra_triggered()
|
||||
{
|
||||
CGAL::Three::Scene_interface::Item_id mainSelectionIndex
|
||||
= scene->mainSelectionIndex();
|
||||
Scene_polyhedron_item* mainSelectionItem
|
||||
= qobject_cast<Scene_polyhedron_item*>(scene->item(mainSelectionIndex));
|
||||
= scene->selectionIndices().first();
|
||||
Scene_facegraph_item* mainSelectionItem
|
||||
= qobject_cast<Scene_facegraph_item*>(scene->item(mainSelectionIndex));
|
||||
if(!mainSelectionItem)
|
||||
{
|
||||
std::cerr<<"No selected polyhedron_item"<<std::endl;
|
||||
|
|
@ -95,14 +110,12 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionJoinPolyhedra_tri
|
|||
if (index == mainSelectionIndex)
|
||||
continue;
|
||||
|
||||
Scene_polyhedron_item* item =
|
||||
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
|
||||
Scene_facegraph_item* item =
|
||||
qobject_cast<Scene_facegraph_item*>(scene->item(index));
|
||||
if(item)
|
||||
{
|
||||
indices_to_remove.push_front(index);
|
||||
CGAL::Polyhedron_copy_3<Polyhedron, Polyhedron::HalfedgeDS, false>
|
||||
modifier( *(item->polyhedron()) );
|
||||
mainSelectionItem->polyhedron()->delegate(modifier);
|
||||
CGAL::copy_face_graph(*item->polyhedron(), *mainSelectionItem->polyhedron());
|
||||
}
|
||||
else
|
||||
std::cerr<<"No selected polyhedron_item"<<std::endl;
|
||||
|
|
@ -118,28 +131,40 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionJoinPolyhedra_tri
|
|||
}
|
||||
|
||||
struct Polyhedron_appender{
|
||||
Polyhedron_appender(std::list<Polyhedron*>& new_polyhedra):
|
||||
Polyhedron_appender(std::list<FaceGraph*>& new_polyhedra):
|
||||
m_new_polyhedra(new_polyhedra) {}
|
||||
void operator()(const Polyhedron& p){
|
||||
m_new_polyhedra.push_back( new Polyhedron(p) );
|
||||
void operator()(const FaceGraph& p){
|
||||
m_new_polyhedra.push_back( new FaceGraph(p) );
|
||||
}
|
||||
std::list<Polyhedron*>& m_new_polyhedra;
|
||||
std::list<FaceGraph*>& m_new_polyhedra;
|
||||
};
|
||||
|
||||
void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionSplitPolyhedra_triggered()
|
||||
{
|
||||
Q_FOREACH(int index, scene->selectionIndices()) {
|
||||
colors_.clear();
|
||||
Scene_polyhedron_item* item =
|
||||
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
|
||||
Scene_facegraph_item* item =
|
||||
qobject_cast<Scene_facegraph_item*>(scene->item(index));
|
||||
if(item)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
std::list<Polyhedron*> new_polyhedra;
|
||||
CGAL::internal::corefinement::extract_connected_components(
|
||||
*item->polyhedron(),
|
||||
boost::make_function_output_iterator(Polyhedron_appender(new_polyhedra))
|
||||
);
|
||||
std::list<FaceGraph*> new_polyhedra;
|
||||
typedef typename boost::property_map<FaceGraph,CGAL::face_patch_id_t<int> >::type PatchIDMap;
|
||||
PatchIDMap pidmap = get(CGAL::face_patch_id_t<int>(), *item->face_graph());
|
||||
int nb_patches = CGAL::Polygon_mesh_processing::connected_components(*item->face_graph(),
|
||||
pidmap);
|
||||
|
||||
|
||||
for(int i=0; i<nb_patches; ++i)
|
||||
{
|
||||
//std::vector<int> pids;
|
||||
//pids.push_back(i);
|
||||
CGAL::Face_filtered_graph<FaceGraph> filter_graph(*item->face_graph(), i, pidmap);
|
||||
FaceGraph* new_graph = new FaceGraph();
|
||||
CGAL::copy_face_graph(filter_graph, *new_graph);
|
||||
new_polyhedra.push_back(new_graph);
|
||||
}
|
||||
|
||||
|
||||
if (new_polyhedra.size()==1)
|
||||
{
|
||||
|
|
@ -150,13 +175,15 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionSplitPolyhedra_tr
|
|||
}
|
||||
|
||||
int cc=0;
|
||||
|
||||
compute_color_map(item->color(), item->isItemMulticolor() ? static_cast<unsigned int>(new_polyhedra.size()) : 1,
|
||||
std::back_inserter(colors_));
|
||||
|
||||
Scene_group_item *group = new Scene_group_item("CC");
|
||||
scene->addItem(group);
|
||||
BOOST_FOREACH(Polyhedron* polyhedron_ptr, new_polyhedra)
|
||||
BOOST_FOREACH(FaceGraph* polyhedron_ptr, new_polyhedra)
|
||||
{
|
||||
Scene_polyhedron_item* new_item=new Scene_polyhedron_item(polyhedron_ptr);
|
||||
Scene_facegraph_item* new_item=new Scene_facegraph_item(polyhedron_ptr);
|
||||
new_item->setName(tr("%1 - CC %2").arg(item->name()).arg(cc));
|
||||
new_item->setColor(colors_[item->isItemMulticolor()? cc : 0]);
|
||||
++cc;
|
||||
|
|
@ -189,21 +216,20 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionColorConnectedCom
|
|||
// wait cursor
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
std::set<Scene_polyhedron_item*> to_skip;
|
||||
std::set<Scene_facegraph_item*> to_skip;
|
||||
|
||||
Q_FOREACH(int index, scene->selectionIndices())
|
||||
{
|
||||
Scene_polyhedron_item* item =
|
||||
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
|
||||
Scene_facegraph_item* item =
|
||||
qobject_cast<Scene_facegraph_item*>(scene->item(index));
|
||||
if(item && to_skip.find(item) == to_skip.end())
|
||||
{
|
||||
item->setItemIsMulticolor(true);
|
||||
Polyhedron_cc_marker marker;
|
||||
CGAL::internal::corefinement::mark_connected_components(
|
||||
*item->polyhedron(),
|
||||
CGAL::internal::corefinement::Dummy_true(),
|
||||
marker
|
||||
);
|
||||
typedef typename boost::property_map<FaceGraph,CGAL::face_patch_id_t<int> >::type PatchIDMap;
|
||||
PatchIDMap pidmap = get(CGAL::face_patch_id_t<int>(), *item->face_graph());
|
||||
CGAL::Polygon_mesh_processing::connected_components(*item->face_graph(),
|
||||
pidmap);
|
||||
|
||||
item->invalidateOpenGLBuffers();
|
||||
scene->itemChanged(item);
|
||||
}
|
||||
|
|
@ -215,18 +241,21 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionColorConnectedCom
|
|||
if (selection_item)
|
||||
{
|
||||
namespace PMP = CGAL::Polygon_mesh_processing;
|
||||
typedef boost::graph_traits<Polyhedron>::face_descriptor face_descriptor;
|
||||
typedef boost::graph_traits<FaceGraph>::face_descriptor face_descriptor;
|
||||
|
||||
selection_item->polyhedron_item()->setItemIsMulticolor(true);
|
||||
#ifndef USE_SURFACE_MESH
|
||||
selection_item->polyhedron_item()->set_color_vector_read_only(false);
|
||||
#endif
|
||||
FaceGraph& pmesh = *(selection_item->polyhedron());
|
||||
|
||||
const Polyhedron& pmesh = *(selection_item->polyhedron());
|
||||
|
||||
boost::property_map<Polyhedron, boost::face_external_index_t>::type fim
|
||||
= get(boost::face_external_index, pmesh);
|
||||
boost::property_map<FaceGraph, boost::face_index_t>::type fim
|
||||
= get(boost::face_index, pmesh);
|
||||
boost::vector_property_map<int,
|
||||
boost::property_map<Polyhedron, boost::face_external_index_t>::type>
|
||||
boost::property_map<FaceGraph, boost::face_index_t>::type>
|
||||
fccmap(fim);
|
||||
boost::property_map<FaceGraph, CGAL::face_patch_id_t<int> >::type pid
|
||||
= get(CGAL::face_patch_id_t<int>(), pmesh);
|
||||
|
||||
std::cout << "color CC" << std::endl;
|
||||
|
||||
|
|
@ -236,7 +265,9 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionColorConnectedCom
|
|||
.face_index_map(fim));
|
||||
|
||||
BOOST_FOREACH(face_descriptor f, faces(pmesh))
|
||||
f->set_patch_id(fccmap[f]);
|
||||
{
|
||||
put(pid, f, fccmap[f]);
|
||||
}
|
||||
|
||||
to_skip.insert(selection_item->polyhedron_item());
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include <CGAL/boost/graph/selection.h>
|
||||
#include <CGAL/Polygon_mesh_processing/connected_components.h>
|
||||
#include <CGAL/Polygon_mesh_processing/border.h>
|
||||
#include <CGAL/iterator.h>
|
||||
|
||||
#include <CGAL/Polygon_2.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -1114,7 +1114,10 @@ bool Scene_surface_mesh_item::intersect_face(double orig_x,
|
|||
void Scene_surface_mesh_item::setItemIsMulticolor(bool b)
|
||||
{
|
||||
if(b)
|
||||
{
|
||||
d->fpatch_id_map = d->smesh_->add_property_map<face_descriptor,int>("f:patch_id").first;
|
||||
d->has_fcolors = true;
|
||||
}
|
||||
else if(d->smesh_->property_map<face_descriptor,int>("f:patch_id").second)
|
||||
{
|
||||
d->fpatch_id_map = d->smesh_->property_map<face_descriptor,int>("f:patch_id").first;
|
||||
|
|
@ -1132,3 +1135,8 @@ void Scene_surface_mesh_item::show_feature_edges(bool b)
|
|||
}
|
||||
d->has_feature_edges = b;
|
||||
}
|
||||
|
||||
bool Scene_surface_mesh_item::isItemMulticolor()
|
||||
{
|
||||
return d->has_fcolors;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ public:
|
|||
void update_vertex_indices(){}
|
||||
void update_halfedge_indices(){}
|
||||
void update_facet_indices(){}
|
||||
bool isItemMulticolor();
|
||||
Vertex_selection_map vertex_selection_map();
|
||||
Face_selection_map face_selection_map();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue