Shortest_path_item works with SM.

This commit is contained in:
Maxime Gimeno 2017-04-03 15:52:40 +02:00
parent fdbf7d167b
commit 515c15f9f2
5 changed files with 91 additions and 51 deletions

View File

@ -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)

View File

@ -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" )

View File

@ -14,16 +14,16 @@ struct Scene_polyhedron_shortest_path_item_priv
{
typedef CGAL::Three::Scene_interface::Bbox Bbox;
typedef boost::property_map<Polyhedron, CGAL::vertex_point_t>::type VertexPointMap;
typedef boost::property_map<Face_graph, CGAL::vertex_point_t>::type VertexPointMap;
typedef boost::graph_traits<Polyhedron> GraphTraits;
typedef boost::graph_traits<Face_graph> GraphTraits;
typedef GraphTraits::face_descriptor face_descriptor;
typedef GraphTraits::face_iterator face_iterator;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Polyhedron> Surface_mesh_shortest_path_traits;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Face_graph> Surface_mesh_shortest_path_traits;
typedef CGAL::Surface_mesh_shortest_path<Surface_mesh_shortest_path_traits> Surface_mesh_shortest_path;
typedef Surface_mesh_shortest_path::Face_location Face_location;
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron, VertexPointMap> AABB_face_graph_primitive;
typedef CGAL::AABB_face_graph_triangle_primitive<Face_graph, VertexPointMap> AABB_face_graph_primitive;
typedef CGAL::AABB_traits<Kernel, AABB_face_graph_primitive> AABB_face_graph_traits;
typedef CGAL::AABB_tree<AABB_face_graph_traits> 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<Face_graph, CGAL::face_index_t>::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<Face_graph, CGAL::face_index_t>::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;

View File

@ -6,7 +6,7 @@
#include <CGAL/Three/Scene_interface.h>
#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<Polyhedron, CGAL::vertex_point_t>::type VertexPointMap;
typedef boost::property_map<Face_graph, CGAL::vertex_point_t>::type VertexPointMap;
typedef boost::graph_traits<Polyhedron> GraphTraits;
typedef boost::graph_traits<Face_graph> GraphTraits;
typedef GraphTraits::face_descriptor face_descriptor;
typedef GraphTraits::face_iterator face_iterator;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Polyhedron> Surface_mesh_shortest_path_traits;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Face_graph> Surface_mesh_shortest_path_traits;
typedef CGAL::Surface_mesh_shortest_path<Surface_mesh_shortest_path_traits> Surface_mesh_shortest_path;
typedef Surface_mesh_shortest_path::Face_location Face_location;
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron, VertexPointMap> AABB_face_graph_primitive;
typedef CGAL::AABB_face_graph_triangle_primitive<Face_graph, VertexPointMap> AABB_face_graph_primitive;
typedef CGAL::AABB_traits<Kernel, AABB_face_graph_primitive> AABB_face_graph_traits;
typedef CGAL::AABB_tree<AABB_face_graph_traits> 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;

View File

@ -2,11 +2,14 @@
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
#include <CGAL/Three/Scene_group_item.h>
#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 <map>
#include <algorithm>
#include <vector>
#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<Polyhedron, boost::vertex_index_t>::type VertexIndexMap;
typedef boost::property_map<Polyhedron, CGAL::halfedge_index_t>::type HalfedgeIndexMap;
typedef boost::property_map<Polyhedron, CGAL::face_index_t>::type FaceIndexMap;
typedef boost::property_map<Polyhedron, CGAL::vertex_point_t>::type VertexPointMap;
typedef boost::property_map<FaceGraph, boost::vertex_index_t>::type VertexIndexMap;
typedef boost::property_map<FaceGraph, CGAL::halfedge_index_t>::type HalfedgeIndexMap;
typedef boost::property_map<FaceGraph, CGAL::face_index_t>::type FaceIndexMap;
typedef boost::property_map<FaceGraph, CGAL::vertex_point_t>::type VertexPointMap;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Polyhedron> Surface_mesh_shortest_path_traits;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, FaceGraph> Surface_mesh_shortest_path_traits;
typedef CGAL::Surface_mesh_shortest_path<Surface_mesh_shortest_path_traits, VertexIndexMap, HalfedgeIndexMap, FaceIndexMap, VertexPointMap> Surface_mesh_shortest_path;
struct ShortestPathsPointsVisitor
@ -58,7 +69,7 @@ private:
}
};
typedef std::map<Scene_polyhedron_item*, Scene_polyhedron_shortest_path_item* > Shortest_paths_map;
typedef std::map<Scene_facegraph_item*, Scene_polyhedron_shortest_path_item* > Shortest_paths_map;
public:
@ -69,7 +80,7 @@ public:
bool applicable(QAction*) const
{
return qobject_cast<Scene_polyhedron_item*>(scene->item(scene->mainSelectionIndex()));
return qobject_cast<Scene_facegraph_item*>(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<Scene_polyhedron_item*>(sceneItem);
Scene_facegraph_item* polyhedronItem = qobject_cast<Scene_facegraph_item*>(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<Scene_polyhedron_shortest_path_item*>(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_polyhedron_item>();
Scene_facegraph_item* polyhedronItem = getSelectedItem<Scene_facegraph_item>();
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_polyhedron_item>();
Scene_facegraph_item* polyhedronItem = getSelectedItem<Scene_facegraph_item>();
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<FaceGraph>::vertex_iterator vertex_iterator;
typedef boost::graph_traits<FaceGraph>::halfedge_iterator halfedge_iterator;
typedef boost::graph_traits<FaceGraph>::face_iterator face_iterator;
if(testVertex1->id() == testVertex2->id())
boost::property_map<Face_graph, boost::vertex_index_t>::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<Face_graph, boost::halfedge_index_t>::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<Face_graph, boost::face_index_t>::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
}
}