diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index a0babc2eefe..dadb300ac6d 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -268,11 +268,12 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) target_link_libraries(scene_surface_mesh_selection_item scene_surface_mesh_item_decorator scene_sm_item_k_ring_selection) target_compile_definitions(scene_surface_mesh_selection_item PUBLIC "-DUSE_SURFACE_MESH" ) - add_item(scene_polyhedron_shortest_path_item Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp) - - + add_item(scene_polyhedron_shortest_path_item Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp) target_link_libraries(scene_polyhedron_shortest_path_item scene_polyhedron_item_decorator scene_polyhedron_item scene_polylines_item) + add_item(scene_sm_shortest_path_item Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp) + target_link_libraries(scene_sm_shortest_path_item scene_surface_mesh_item_decorator scene_surface_mesh_item scene_polylines_item) + if(EIGEN3_FOUND ) qt5_wrap_ui( editionUI_FILES Plugins/Surface_mesh_deformation/Deform_mesh.ui ) add_item(scene_textured_polyhedron_item Scene_textured_polyhedron_item.cpp texture.cpp) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/CMakeLists.txt index c69293c41a7..898b24167ef 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/CMakeLists.txt @@ -26,4 +26,8 @@ target_link_libraries(remeshing_plugin scene_polyhedron_item scene_polygon_soup_ qt5_wrap_ui( shortestPathUI_FILES Shortest_path_widget.ui ) polyhedron_demo_plugin(shortest_path_plugin Shortest_path_plugin ${shortestPathUI_FILES}) -target_link_libraries(shortest_path_plugin scene_polyhedron_item scene_polylines_item scene_polyhedron_selection_item scene_polyhedron_shortest_path_item scene_basic_objects) +target_link_libraries(shortest_path_plugin scene_polyhedron_item scene_polyhedron_shortest_path_item scene_basic_objects) + +polyhedron_demo_plugin(shortest_path_sm_plugin Shortest_path_plugin ${shortestPathUI_FILES}) +target_link_libraries(shortest_path_sm_plugin scene_surface_mesh_item scene_sm_shortest_path_item scene_basic_objects) +target_compile_definitions(shortest_path_sm_plugin PUBLIC "-DUSE_SURFACE_MESH" ) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp index abc8fa36132..94d3c6ca2ca 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp @@ -14,16 +14,16 @@ struct Scene_polyhedron_shortest_path_item_priv { typedef CGAL::Three::Scene_interface::Bbox Bbox; - typedef boost::property_map::type VertexPointMap; + typedef boost::property_map::type VertexPointMap; - typedef boost::graph_traits GraphTraits; + typedef boost::graph_traits GraphTraits; typedef GraphTraits::face_descriptor face_descriptor; typedef GraphTraits::face_iterator face_iterator; - typedef CGAL::Surface_mesh_shortest_path_traits Surface_mesh_shortest_path_traits; + typedef CGAL::Surface_mesh_shortest_path_traits Surface_mesh_shortest_path_traits; typedef CGAL::Surface_mesh_shortest_path Surface_mesh_shortest_path; typedef Surface_mesh_shortest_path::Face_location Face_location; - typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; + typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; typedef CGAL::AABB_traits AABB_face_graph_traits; typedef CGAL::AABB_tree AABB_face_graph_tree; @@ -104,7 +104,7 @@ Scene_polyhedron_shortest_path_item::Scene_polyhedron_shortest_path_item() d = new Scene_polyhedron_shortest_path_item_priv(this); } -Scene_polyhedron_shortest_path_item::Scene_polyhedron_shortest_path_item(Scene_polyhedron_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow) +Scene_polyhedron_shortest_path_item::Scene_polyhedron_shortest_path_item(Scene_face_graph_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow) :Scene_polyhedron_item_decorator(polyhedronItem, false) { d = new Scene_polyhedron_shortest_path_item_priv(this); initialize(polyhedronItem, sceneInterface, messages, mainWindow); @@ -405,8 +405,10 @@ bool Scene_polyhedron_shortest_path_item_priv::run_point_select(const Ray_3& ray } else { + boost::property_map::type fimap + = get(CGAL::face_index, *item->polyhedron()); m_messages->information(QObject::tr("Shortest Paths: Selected Face: %1; Barycentric coordinates: %2 %3 %4") - .arg(faceLocation.first->id()) + .arg(get(fimap, faceLocation.first)) .arg(double(faceLocation.second[0])) .arg(double(faceLocation.second[1])) .arg(double(faceLocation.second[2]))); @@ -515,7 +517,7 @@ bool Scene_polyhedron_shortest_path_item::load(const std::string& file_name) return true; } -bool Scene_polyhedron_shortest_path_item::deferred_load(Scene_polyhedron_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow) +bool Scene_polyhedron_shortest_path_item::deferred_load(Scene_face_graph_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow) { initialize(polyhedronItem, sceneInterface, messages, mainWindow); @@ -560,7 +562,8 @@ bool Scene_polyhedron_shortest_path_item::deferred_load(Scene_polyhedron_item* p bool Scene_polyhedron_shortest_path_item::save(const std::string& file_name) const { std::ofstream out(file_name.c_str()); - + boost::property_map::type fimap + = get(CGAL::face_index, *polyhedron()); if (!out) { return false; @@ -568,14 +571,13 @@ bool Scene_polyhedron_shortest_path_item::save(const std::string& file_name) con for(Surface_mesh_shortest_path::Source_point_iterator it = d->m_shortestPaths->source_points_begin(); it != d->m_shortestPaths->source_points_end(); ++it) { - // std::cout << "Output face location: " << it->first->id() << " , " << it->second << std::endl; - out << it->first->id() << " " << it->second[0] << " " << it->second[1] << " " << it->second[3] << std::endl; + out << get(fimap, it->first) << " " << it->second[0] << " " << it->second[1] << " " << it->second[3] << std::endl; } return true; } -void Scene_polyhedron_shortest_path_item::initialize(Scene_polyhedron_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow) +void Scene_polyhedron_shortest_path_item::initialize(Scene_face_graph_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow) { d->m_mainWindow = mainWindow; d->m_messages = messages; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.h b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.h index a942a39b4b2..8d0646829d1 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.h +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.h @@ -6,7 +6,7 @@ #include #include "Messages_interface.h" -#include "Polyhedron_type.h" +//#include "Polyhedron_type.h" #include "Kernel_type.h" #include "opengl_tools.h" @@ -41,16 +41,16 @@ class SCENE_POLYHEDRON_SHORTEST_PATH_ITEM_EXPORT Scene_polyhedron_shortest_path_ public: typedef CGAL::Three::Scene_interface::Bbox Bbox; - typedef boost::property_map::type VertexPointMap; + typedef boost::property_map::type VertexPointMap; - typedef boost::graph_traits GraphTraits; + typedef boost::graph_traits GraphTraits; typedef GraphTraits::face_descriptor face_descriptor; typedef GraphTraits::face_iterator face_iterator; - typedef CGAL::Surface_mesh_shortest_path_traits Surface_mesh_shortest_path_traits; + typedef CGAL::Surface_mesh_shortest_path_traits Surface_mesh_shortest_path_traits; typedef CGAL::Surface_mesh_shortest_path Surface_mesh_shortest_path; typedef Surface_mesh_shortest_path::Face_location Face_location; - typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; + typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; typedef CGAL::AABB_traits AABB_face_graph_traits; typedef CGAL::AABB_tree AABB_face_graph_tree; @@ -77,7 +77,7 @@ public: public: Scene_polyhedron_shortest_path_item(); - Scene_polyhedron_shortest_path_item(Scene_polyhedron_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow); + Scene_polyhedron_shortest_path_item(Scene_face_graph_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow); ~Scene_polyhedron_shortest_path_item(); void set_selection_mode(Selection_mode mode); @@ -93,12 +93,12 @@ public: virtual Scene_polyhedron_shortest_path_item* clone() const; - bool deferred_load(Scene_polyhedron_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow); + bool deferred_load(Scene_face_graph_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow); virtual bool load(const std::string& file_name); virtual bool save(const std::string& file_name) const; protected: - void initialize(Scene_polyhedron_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow); + void initialize(Scene_face_graph_item* polyhedronItem, CGAL::Three::Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow); void deinitialize(); virtual bool isFinite() const; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Shortest_path_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Shortest_path_plugin.cpp index 3a65a49c8be..8dc72ffd85e 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Shortest_path_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Shortest_path_plugin.cpp @@ -2,11 +2,14 @@ #include #include -#include "Messages_interface.h" +#ifdef USE_SURFACE_MESH +#include "Scene_surface_mesh_item.h" +#else #include "Scene_polyhedron_item.h" -#include "Scene_polylines_item.h" -#include "Scene_polyhedron_selection_item.h" +#endif + #include "Scene_polyhedron_shortest_path_item.h" +#include "Messages_interface.h" #include "Polyhedron_type.h" #include "Scene.h" #include "ui_Shortest_path_widget.h" @@ -23,6 +26,14 @@ #include #include #include + +#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::FaceGraph FaceGraph; + using namespace CGAL::Three; class Polyhedron_demo_shortest_path_plugin : public QObject, @@ -33,12 +44,12 @@ class Polyhedron_demo_shortest_path_plugin : Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") private: - typedef boost::property_map::type VertexIndexMap; - typedef boost::property_map::type HalfedgeIndexMap; - typedef boost::property_map::type FaceIndexMap; - typedef boost::property_map::type VertexPointMap; + typedef boost::property_map::type VertexIndexMap; + typedef boost::property_map::type HalfedgeIndexMap; + typedef boost::property_map::type FaceIndexMap; + typedef boost::property_map::type VertexPointMap; - typedef CGAL::Surface_mesh_shortest_path_traits Surface_mesh_shortest_path_traits; + typedef CGAL::Surface_mesh_shortest_path_traits Surface_mesh_shortest_path_traits; typedef CGAL::Surface_mesh_shortest_path Surface_mesh_shortest_path; struct ShortestPathsPointsVisitor @@ -58,7 +69,7 @@ private: } }; - typedef std::map Shortest_paths_map; + typedef std::map Shortest_paths_map; public: @@ -69,7 +80,7 @@ public: bool applicable(QAction*) const { - return qobject_cast(scene->item(scene->mainSelectionIndex())); + return qobject_cast(scene->item(scene->mainSelectionIndex())); } void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface* messages) @@ -110,7 +121,7 @@ private: Scene_polyhedron_shortest_path_item::Selection_mode get_selection_mode() const; Scene_polyhedron_shortest_path_item::Primitives_mode get_primitives_mode() const; - void check_and_set_ids(Polyhedron* polyhedron); + void check_and_set_ids(FaceGraph* polyhedron); public Q_SLOTS: void on_actionMakeShortestPaths_triggered(); @@ -141,7 +152,7 @@ Scene_polyhedron_shortest_path_item::Primitives_mode Polyhedron_demo_shortest_pa void Polyhedron_demo_shortest_path_plugin::item_about_to_be_destroyed(CGAL::Three::Scene_item* sceneItem) { // if polyhedron item - Scene_polyhedron_item* polyhedronItem = qobject_cast(sceneItem); + Scene_facegraph_item* polyhedronItem = qobject_cast(sceneItem); if(polyhedronItem) { Shortest_paths_map::iterator found = m_shortestPathsMap.find(polyhedronItem); @@ -158,7 +169,7 @@ void Polyhedron_demo_shortest_path_plugin::item_about_to_be_destroyed(CGAL::Thre Scene_polyhedron_shortest_path_item* shortestPathItem = qobject_cast(sceneItem); if(shortestPathItem) { - Scene_polyhedron_item* polyhedronItem = shortestPathItem->polyhedron_item(); + Scene_facegraph_item* polyhedronItem = shortestPathItem->polyhedron_item(); Shortest_paths_map::iterator found = m_shortestPathsMap.find(polyhedronItem); if (found != m_shortestPathsMap.end()) @@ -179,7 +190,7 @@ void Polyhedron_demo_shortest_path_plugin::new_item(int itemIndex) if(item->polyhedron_item() == NULL) { - Scene_polyhedron_item* polyhedronItem = getSelectedItem(); + Scene_facegraph_item* polyhedronItem = getSelectedItem(); if(!polyhedronItem) { @@ -223,7 +234,7 @@ void Polyhedron_demo_shortest_path_plugin::new_item(int itemIndex) void Polyhedron_demo_shortest_path_plugin::on_actionMakeShortestPaths_triggered() { - Scene_polyhedron_item* polyhedronItem = getSelectedItem(); + Scene_facegraph_item* polyhedronItem = getSelectedItem(); if (polyhedronItem) { if (m_shortestPathsMap.find(polyhedronItem) == m_shortestPathsMap.end()) @@ -269,45 +280,67 @@ void Polyhedron_demo_shortest_path_plugin::on_Primitives_type_combo_box_changed( } } -void Polyhedron_demo_shortest_path_plugin::check_and_set_ids(Polyhedron* polyhedron) +void Polyhedron_demo_shortest_path_plugin::check_and_set_ids(FaceGraph* polyhedron) { - Polyhedron::Vertex_iterator testVertex1 = polyhedron->vertices_begin(); - Polyhedron::Vertex_iterator testVertex2 = ++polyhedron->vertices_begin(); + typedef boost::graph_traits::vertex_iterator vertex_iterator; + typedef boost::graph_traits::halfedge_iterator halfedge_iterator; + typedef boost::graph_traits::face_iterator face_iterator; - if(testVertex1->id() == testVertex2->id()) + boost::property_map::type vimap + = get(boost::vertex_index, *polyhedron); + + vertex_iterator testVertex1 = vertices(*polyhedron).begin(); + vertex_iterator testVertex2 = ++vertices(*polyhedron).begin(); + if(get(vimap, *testVertex1) == get(vimap, *testVertex2)) { +#ifdef USE_SURFACE_MESH + polyhedron->collect_garbage(); +#else std::size_t vertexId = 0; - for(Polyhedron::Vertex_iterator currentVertex = polyhedron->vertices_begin(); + for(vertex_iterator currentVertex = polyhedron->vertices_begin(); currentVertex != polyhedron->vertices_end(); ++currentVertex, ++vertexId) { currentVertex->id() = vertexId; } +#endif } + boost::property_map::type himap + = get(boost::halfedge_index, *polyhedron); - Polyhedron::Halfedge_iterator testHalfedge1 = polyhedron->halfedges_begin(); - Polyhedron::Halfedge_iterator testHalfedge2 = ++polyhedron->halfedges_begin(); + halfedge_iterator testHalfedge1 = halfedges(*polyhedron).begin(); + halfedge_iterator testHalfedge2 = ++halfedges(*polyhedron).begin(); - if (testHalfedge1->id() == testHalfedge2->id()) + if (get(himap, *testHalfedge1) == get(himap, *testHalfedge2)) { +#ifdef USE_SURFACE_MESH + polyhedron->collect_garbage(); +#else std::size_t halfedgeId = 0; - for(Polyhedron::Halfedge_iterator currentHalfedge = polyhedron->halfedges_begin(); + for(halfedge_iterator currentHalfedge = polyhedron->halfedges_begin(); currentHalfedge != polyhedron->halfedges_end(); ++currentHalfedge, ++halfedgeId) { currentHalfedge->id() = halfedgeId; } +#endif } - Polyhedron::Facet_iterator testFacet1 = polyhedron->facets_begin(); - Polyhedron::Facet_iterator testFacet2 = ++polyhedron->facets_begin(); + face_iterator testFacet1 = faces(*polyhedron).begin(); + face_iterator testFacet2 = ++faces(*polyhedron).begin(); + boost::property_map::type fimap + = get(boost::face_index, *polyhedron); - if (testFacet1->id() == testFacet2->id()) + if (get(fimap, *testFacet1) == get(fimap, *testFacet2)) { +#ifdef USE_SURFACE_MESH + polyhedron->collect_garbage(); +#else std::size_t facetId = 0; - for(Polyhedron::Facet_iterator currentFacet = polyhedron->facets_begin(); + for(face_iterator currentFacet = polyhedron->facets_begin(); currentFacet != polyhedron->facets_end(); ++currentFacet, ++facetId) { currentFacet->id() = facetId; } +#endif } }