mirror of https://github.com/CGAL/cgal
De-activate inclusion test and make both items movable.
This commit is contained in:
parent
680191dccd
commit
2823f46f98
|
|
@ -39,8 +39,8 @@ public:
|
|||
const int indexB = scene->selectionBindex();
|
||||
return qobject_cast<Scene_surface_mesh_item*>(scene->item(indexA))
|
||||
&& qobject_cast<Scene_surface_mesh_item*>(scene->item(indexB))
|
||||
&& fixed_item == NULL
|
||||
&& moving_item == NULL;
|
||||
&& base_item == NULL
|
||||
&& query_item == NULL;
|
||||
}
|
||||
|
||||
QList<QAction*> actions() const Q_DECL_OVERRIDE
|
||||
|
|
@ -62,8 +62,8 @@ public:
|
|||
}
|
||||
t1 = 0;
|
||||
t2 = 0;
|
||||
moving_item = 0;
|
||||
fixed_item = 0;
|
||||
query_item = 0;
|
||||
base_item = 0;
|
||||
}
|
||||
private Q_SLOTS:
|
||||
void start()
|
||||
|
|
@ -75,14 +75,14 @@ private Q_SLOTS:
|
|||
Scene_surface_mesh_item* itemB = qobject_cast<Scene_surface_mesh_item*>(scene->item(indexB));
|
||||
connect(itemA, &Scene_surface_mesh_item::aboutToBeDestroyed,
|
||||
[this](){
|
||||
if(moving_item)
|
||||
scene->erase(scene->item_id(moving_item));
|
||||
if(query_item)
|
||||
scene->erase(scene->item_id(query_item));
|
||||
cleanup();
|
||||
});
|
||||
connect(itemB, &Scene_surface_mesh_item::aboutToBeDestroyed,
|
||||
[this](){
|
||||
if(moving_item)
|
||||
scene->erase(scene->item_id(moving_item));
|
||||
if(query_item)
|
||||
scene->erase(scene->item_id(query_item));
|
||||
cleanup();
|
||||
});
|
||||
|
||||
|
|
@ -95,21 +95,31 @@ private Q_SLOTS:
|
|||
(itemB->bbox().min(1) + itemB->bbox().max(1))/2.0,
|
||||
(itemB->bbox().min(2) + itemB->bbox().max(2))/2.0);
|
||||
|
||||
moving_item = new Scene_movable_sm_item(pos,tm2,"");
|
||||
connect(moving_item, &Scene_surface_mesh_item::aboutToBeDestroyed,
|
||||
query_item = new Scene_movable_sm_item(pos,tm2,"");
|
||||
connect(query_item, &Scene_surface_mesh_item::aboutToBeDestroyed,
|
||||
[this](){
|
||||
cleanup();
|
||||
});
|
||||
fixed_item = itemA;
|
||||
connect(moving_item->manipulatedFrame(), &CGAL::qglviewer::ManipulatedFrame::modified,
|
||||
connect(query_item->manipulatedFrame(), &CGAL::qglviewer::ManipulatedFrame::modified,
|
||||
this, &DoTreesIntersectplugin::update_trees);
|
||||
moving_item->setRenderingMode(Flat);
|
||||
moving_item->setName(itemB->name());
|
||||
query_item->setRenderingMode(Flat);
|
||||
query_item->setName(itemB->name());
|
||||
itemB->setVisible(false);
|
||||
itemA->setRenderingMode(Wireframe);
|
||||
scene->addItem(moving_item);
|
||||
itemA->setVisible(false);
|
||||
scene->setSelectedItem(scene->addItem(query_item));
|
||||
base_item = new Scene_movable_sm_item(pos,tm,"");
|
||||
connect(base_item, &Scene_surface_mesh_item::aboutToBeDestroyed,
|
||||
[this](){
|
||||
cleanup();
|
||||
});
|
||||
connect(base_item->manipulatedFrame(), &CGAL::qglviewer::ManipulatedFrame::modified,
|
||||
this, &DoTreesIntersectplugin::update_trees);
|
||||
base_item->setRenderingMode(Wireframe);
|
||||
base_item->setName(itemA->name());
|
||||
scene->addItem(base_item);
|
||||
update_trees();
|
||||
moving_item->redraw();
|
||||
query_item->redraw();
|
||||
base_item->redraw();
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
public Q_SLOTS:
|
||||
|
|
@ -117,40 +127,60 @@ public Q_SLOTS:
|
|||
{
|
||||
CGAL::Three::Viewer_interface* viewer = static_cast<CGAL::Three::Viewer_interface*>(
|
||||
CGAL::QGLViewer::QGLViewerPool().first());
|
||||
const double* matrix = moving_item->manipulatedFrame()->matrix();
|
||||
moving_item->setFMatrix(matrix);
|
||||
EPICK::Aff_transformation_3 translation(CGAL::TRANSLATION, -EPICK::Vector_3(moving_item->center().x,
|
||||
moving_item->center().y,
|
||||
moving_item->center().z));
|
||||
EPICK::Aff_transformation_3 rota(
|
||||
matrix[0], matrix[4], matrix[8],matrix[12],
|
||||
matrix[1], matrix[5], matrix[9],matrix[13],
|
||||
matrix[2], matrix[6], matrix[10],matrix[14]);
|
||||
EPICK::Aff_transformation_3 transfo =
|
||||
rota*translation;
|
||||
t2->traits().set_transformation(transfo);
|
||||
|
||||
const double* matrixB = base_item->manipulatedFrame()->matrix();
|
||||
base_item->setFMatrix(matrixB);
|
||||
EPICK::Aff_transformation_3 translationB(CGAL::TRANSLATION, -EPICK::Vector_3(base_item->center().x,
|
||||
base_item->center().y,
|
||||
base_item->center().z));
|
||||
EPICK::Aff_transformation_3 rotaB(
|
||||
matrixB[0], matrixB[4], matrixB[8],matrixB[12],
|
||||
matrixB[1], matrixB[5], matrixB[9],matrixB[13],
|
||||
matrixB[2], matrixB[6], matrixB[10],matrixB[14]);
|
||||
EPICK::Aff_transformation_3 transfoB =
|
||||
rotaB*translationB;
|
||||
t1->traits().set_transformation(transfoB);
|
||||
|
||||
const double* matrixA = query_item->manipulatedFrame()->matrix();
|
||||
query_item->setFMatrix(matrixA);
|
||||
EPICK::Aff_transformation_3 translationA(CGAL::TRANSLATION, -EPICK::Vector_3(query_item->center().x,
|
||||
query_item->center().y,
|
||||
query_item->center().z));
|
||||
EPICK::Aff_transformation_3 rotaA(
|
||||
matrixA[0], matrixA[4], matrixA[8],matrixA[12],
|
||||
matrixA[1], matrixA[5], matrixA[9],matrixA[13],
|
||||
matrixA[2], matrixA[6], matrixA[10],matrixA[14]);
|
||||
EPICK::Aff_transformation_3 transfoA =
|
||||
rotaA*translationA;
|
||||
t2->traits().set_transformation(transfoA);
|
||||
if(t2->do_intersect(*t1))
|
||||
moving_item->setColor(QColor(Qt::red));
|
||||
query_item->setColor(QColor(Qt::red));
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
typedef boost::property_map<SMesh, CGAL::vertex_point_t>::type VPM;
|
||||
VPM vpm2 = get(CGAL::vertex_point, *moving_item->getFaceGraph());
|
||||
VPM vpm2 = get(CGAL::vertex_point, *query_item->getFaceGraph());
|
||||
CGAL::Side_of_triangle_mesh<SMesh, EPICK,
|
||||
VPM, Tree> sotm1(*t1);
|
||||
if(sotm1((transfo).transform(vpm2[*moving_item->getFaceGraph()->vertices().begin()])) != CGAL::ON_UNBOUNDED_SIDE)
|
||||
if(sotm1((transfoA).transform(vpm2[*query_item->getFaceGraph()->vertices().begin()])) != CGAL::ON_UNBOUNDED_SIDE)
|
||||
{
|
||||
moving_item->setColor(QColor(Qt::blue));
|
||||
query_item->setColor(QColor(Qt::blue));
|
||||
}
|
||||
else
|
||||
{
|
||||
CGAL::Side_of_triangle_mesh<SMesh, EPICK,
|
||||
VPM, Tree> sotm2(*t2);
|
||||
if(sotm2(fixed_item->face_graph()->point(*fixed_item->face_graph()->vertices().begin())) != CGAL::ON_UNBOUNDED_SIDE)
|
||||
moving_item->setColor(QColor(Qt::blue));
|
||||
if(sotm2(base_item->face_graph()->point(*base_item->face_graph()->vertices().begin())) != CGAL::ON_UNBOUNDED_SIDE)
|
||||
query_item->setColor(QColor(Qt::blue));
|
||||
else
|
||||
moving_item->setColor(QColor(Qt::green));
|
||||
#endif
|
||||
query_item->setColor(QColor(Qt::green));
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
viewer->update();
|
||||
}
|
||||
|
||||
|
|
@ -162,8 +192,8 @@ public Q_SLOTS:
|
|||
if(t2)
|
||||
delete t2;
|
||||
t2 = NULL;
|
||||
moving_item = NULL;
|
||||
fixed_item = NULL;
|
||||
query_item = NULL;
|
||||
base_item = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -172,7 +202,7 @@ private:
|
|||
CGAL::Three::Scene_interface* scene;
|
||||
QMainWindow* mw;
|
||||
Tree *t1, *t2;
|
||||
Scene_movable_sm_item* moving_item;
|
||||
Scene_surface_mesh_item* fixed_item;
|
||||
Scene_movable_sm_item* query_item;
|
||||
Scene_movable_sm_item* base_item;
|
||||
};
|
||||
#include "Do_trees_intersect_plugin.moc"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <CGAL/Three/Viewer_interface.h>
|
||||
#include <CGAL/Buffer_for_vao.h>
|
||||
#include <CGAL/Three/Triangle_container.h>
|
||||
#include <CGAL/Three/Edge_container.h>
|
||||
typedef CGAL::Three::Triangle_container Tri;
|
||||
typedef CGAL::Three::Viewer_interface VI;
|
||||
struct Scene_movable_sm_item_priv
|
||||
|
|
@ -20,6 +21,8 @@ struct Scene_movable_sm_item_priv
|
|||
frame->setPosition(pos+offset);
|
||||
item->setTriangleContainer(0, new Triangle_container(VI::PROGRAM_WITH_LIGHT,
|
||||
false));
|
||||
item->setEdgeContainer(0, new Edge_container(VI::PROGRAM_NO_SELECTION,
|
||||
false));
|
||||
}
|
||||
~Scene_movable_sm_item_priv()
|
||||
{
|
||||
|
|
@ -46,6 +49,8 @@ struct Scene_movable_sm_item_priv
|
|||
mutable QOpenGLShaderProgram *program;
|
||||
mutable std::vector<float> flat_normals;
|
||||
mutable std::vector<float> flat_vertices;
|
||||
mutable std::vector<float> edges_vertices;
|
||||
|
||||
};
|
||||
|
||||
Scene_movable_sm_item::Scene_movable_sm_item(const CGAL::qglviewer::Vec& pos, SMesh* sm,
|
||||
|
|
@ -59,10 +64,14 @@ void Scene_movable_sm_item_priv::initialize_buffers(CGAL::Three::Viewer_interfac
|
|||
{
|
||||
item->getTriangleContainer(0)->initializeBuffers(viewer);
|
||||
item->getTriangleContainer(0)->setFlatDataSize(flat_vertices.size());
|
||||
item->getEdgeContainer(0)->initializeBuffers(viewer);
|
||||
item->getEdgeContainer(0)->setFlatDataSize(edges_vertices.size());
|
||||
flat_vertices.resize(0);
|
||||
flat_normals .resize(0);
|
||||
edges_vertices.resize(0);
|
||||
flat_vertices.shrink_to_fit();
|
||||
flat_normals.shrink_to_fit();
|
||||
edges_vertices.shrink_to_fit();
|
||||
|
||||
item->are_buffers_filled = true;
|
||||
}
|
||||
|
|
@ -82,9 +91,12 @@ void Scene_movable_sm_item_priv::compute_elements() const
|
|||
facegraph->points();
|
||||
typedef boost::graph_traits<SMesh>::face_descriptor face_descriptor;
|
||||
typedef boost::graph_traits<SMesh>::halfedge_descriptor halfedge_descriptor;
|
||||
typedef boost::graph_traits<SMesh>::edge_descriptor edge_descriptor;
|
||||
typedef CGAL::Buffer_for_vao<float, unsigned int> CPF;
|
||||
flat_vertices.clear();
|
||||
flat_normals.clear();
|
||||
edges_vertices.clear();
|
||||
//faces
|
||||
BOOST_FOREACH(face_descriptor fd, faces(*facegraph))
|
||||
{
|
||||
BOOST_FOREACH(halfedge_descriptor hd, halfedges_around_face(halfedge(fd, *facegraph),*facegraph))
|
||||
|
|
@ -98,12 +110,29 @@ void Scene_movable_sm_item_priv::compute_elements() const
|
|||
CPF::add_normal_in_buffer(n, flat_normals);
|
||||
}
|
||||
}
|
||||
//edges
|
||||
BOOST_FOREACH(edge_descriptor ed, edges(*facegraph))
|
||||
{
|
||||
Point p = positions[source(ed, *facegraph)] + offset;
|
||||
EPICK::Point_3 pc(p.x() - center_.x,
|
||||
p.y() - center_.y,
|
||||
p.z() - center_.z);
|
||||
CPF::add_point_in_buffer(pc, edges_vertices);
|
||||
p = positions[target(ed, *facegraph)] + offset;
|
||||
pc=EPICK::Point_3(p.x() - center_.x,
|
||||
p.y() - center_.y,
|
||||
p.z() - center_.z);
|
||||
CPF::add_point_in_buffer(pc, edges_vertices);
|
||||
}
|
||||
|
||||
|
||||
|
||||
item->getTriangleContainer(0)->allocate(Tri::Flat_vertices, flat_vertices.data(),
|
||||
static_cast<int>(flat_vertices.size()*sizeof(float)));
|
||||
item->getTriangleContainer(0)->allocate(Tri::Flat_normals, flat_normals.data(),
|
||||
static_cast<int>(flat_normals.size()*sizeof(float)));
|
||||
item->getEdgeContainer(0)->allocate(Tri::Flat_vertices, edges_vertices.data(),
|
||||
static_cast<int>(edges_vertices.size()*sizeof(float)));
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +153,18 @@ void Scene_movable_sm_item::draw(CGAL::Three::Viewer_interface* viewer) const
|
|||
getTriangleContainer(0)->draw(viewer, true);
|
||||
}
|
||||
|
||||
void Scene_movable_sm_item::drawEdges(CGAL::Three::Viewer_interface* viewer) const
|
||||
{
|
||||
if(!isInit() && viewer->context()->isValid())
|
||||
initGL();
|
||||
if(!are_buffers_filled)
|
||||
d->initialize_buffers(viewer);
|
||||
getEdgeContainer(0)->setColor(Qt::black);
|
||||
getEdgeContainer(0)->setFrameMatrix(d->f_matrix);
|
||||
|
||||
getEdgeContainer(0)->draw(viewer, true);
|
||||
}
|
||||
|
||||
QString Scene_movable_sm_item::toolTip() const {
|
||||
return QObject::tr("<p>Manipulatable representation of <b>%1</b></p>"
|
||||
"<p>Keep <b>Ctrl</b> pressed and use the arcball to define an affine transformation.<br />")
|
||||
|
|
|
|||
|
|
@ -34,12 +34,14 @@ public:
|
|||
Scene_item* clone() const{return NULL;}
|
||||
QString toolTip() const;
|
||||
void draw(CGAL::Three::Viewer_interface *) const;
|
||||
void drawEdges(CGAL::Three::Viewer_interface *) const;
|
||||
void compute_bbox() const;
|
||||
~Scene_movable_sm_item();
|
||||
bool manipulatable() const { return true;}
|
||||
ManipulatedFrame* manipulatedFrame();
|
||||
const CGAL::qglviewer::Vec& center() const;
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return m==Flat ; }
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return m==Flat
|
||||
|| m==Wireframe; }
|
||||
virtual void invalidateOpenGLBuffers();
|
||||
void setFMatrix(const GLdouble matrix[16]);
|
||||
void computeElements() const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue