42 #include "PlanePlugin.hh" 49 #include <ACG/Scenegraph/LineNode.hh> 51 const char *PLANE =
"CreatePlaneNode";
52 const char *PLANE_RESIZE =
"PlaneResize";
60 createPlane_(nullptr),
61 planeNodeAction_(nullptr),
75 emit registerKey(Qt::Key_Escape, Qt::NoModifier,
"Cancel Plane",
true);
86 emit addPickMode(PLANE);
88 emit addPickMode(PLANE_RESIZE);
94 connect(
createPlane_, SIGNAL(updateViewProxy()),
this, SIGNAL(updateView()));
97 QToolBar *toolbar =
new QToolBar(
"Plane Toolbar");
103 OpenFlipper::Options::dirSeparator() +
109 emit addToolbar(toolbar);
175 auto rayPlaneIntersection = [](
ACG::Vec3d const &origin,
178 double &alpha,
double &beta) ->
bool {
188 constexpr
double EPSILON = std::numeric_limits<double>::epsilon() * 1e2;
189 if (det > -EPSILON && det < EPSILON) {
190 std::cerr <<
"det within eps!" << std::endl;
195 alpha = (tvec | pvec) * inv_det;
197 beta = (dir | qvec) * inv_det;
202 if (alpha < 0.0 || alpha > 1.0)
204 if (beta < 0.0 || alpha + beta > 1.0)
214 switch (_event->type()) {
215 case QEvent::MouseButtonPress: {
217 size_t node_idx, target_idx;
219 _event->pos(), node_idx, target_idx,
229 QPoint position = _event->pos();
241 const auto center =
curPlane_->plane().position;
242 const auto xdir =
curPlane_->plane().xDirection / 2.;
243 const auto ydir =
curPlane_->plane().yDirection / 2.;
244 const auto p0 = center + xdir + ydir;
245 const auto p1 = center + xdir - ydir;
246 const auto p2 = center - xdir - ydir;
247 double u = -1, v = -1, w = -1;
264 case QEvent::MouseMove: {
268 QPoint position = _event->pos();
286 viewCoord[0], viewCoord[1], origin, dir);
287 double u = -3.1415926539, v = -3.1415926539;
288 const auto center = plane.position;
289 const auto xdir = plane.xDirection / 2.;
290 const auto ydir = plane.yDirection / 2.;
291 const auto p0 =
ACG::Vec3d{center + xdir + ydir};
292 const auto p1 =
ACG::Vec3d{center + xdir - ydir};
293 const auto p2 =
ACG::Vec3d{center - xdir - ydir};
299 rayPlaneIntersection(origin, dir, p0, p1, p2, u, v);
300 const auto w = 1. - (u + v);
310 const auto worldSpaceUpdate = (wCurrMousePos - wMouseDownPosition) / 2.;
315 const auto distClickOrigin = wMouseDownPosition;
318 auto scale = (worldSpaceUpdate + distClickOrigin) / distClickOrigin;
321 const auto xscale = scale[0] * plane.xDirection.
length();
322 const auto yscale = scale[1] * plane.yDirection.
length();
328 plane.position += worldSpaceUpdate;
336 emit log(
LOGERR, tr(
"COULD NOT UPDATE OBJECT"));
341 case QEvent::MouseButtonRelease: {
379 if (obj ==
nullptr) {
380 emit log(
LOGERR,
"Unable to get object");
403 if (getIntersectionParams(*obj, center, radius)) {
404 radius = 1.5 * radius;
407 currentPlane->plane().
setPlane(center, normal);
408 currentPlane->plane().
setSize(2.0 * radius, 2.0 * radius);
411 std::cerr <<
"unable to get intersection params" << std::endl;
412 currentPlane->plane().
setPlane(point, normal);
431 std::vector<ACG::Vec3d> linePoints;
440 TriMesh::EdgeHandle eh =
getCuttedEdge(*mesh, normal, point);
445 TriMesh::FaceHandle fh = mesh->face_handle(mesh->halfedge_handle(eh, 0));
448 fh = mesh->face_handle(mesh->halfedge_handle(eh, 1));
460 PolyMesh::EdgeHandle eh =
getCuttedEdge(*mesh, normal, point);
465 PolyMesh::FaceHandle fh = mesh->face_handle(mesh->halfedge_handle(eh, 0));
468 fh = mesh->face_handle(mesh->halfedge_handle(eh, 1));
474 if (linePoints.empty())
479 for (uint i = 0; i < linePoints.size(); i++)
480 _center += linePoints[i];
482 _center /= (double)linePoints.size();
486 for (uint i = 0; i < linePoints.size(); i++) {
487 double dist = (_center - linePoints[i]).norm();
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
ACG::Vec3d wMouseDownPosition_
additional information
#define DATA_TRIANGLE_MESH
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void slotMouseEvent(QMouseEvent *_event)
a mouse event occured
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
ACG::Vec3d wCurrMousePos_
additional information
void initializePlugin()
Initialize the plugin.
QtPlaneSelect * createPlane_
additional information
MeshT::EdgeHandle getCuttedEdge(MeshT &_mesh, ACG::Vec3d &_planeNormal, ACG::Vec3d &_planePoint)
get an edge of the mesh that is cut by the plane
bool dragging_
additional information
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
void show()
Show node: set status to Active.
PlaneNode * planeNode()
Get the scenegraph Node.
void slotCreatePlaneTriggered()
Create a plane node when position/normal have been drawn.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
std::vector< ACG::Vec3d > getIntersectionPoints(MeshT *_mesh, uint _fh, ACG::Vec3d _planeNormal, ACG::Vec3d _planePoint, bool &_closed)
get the points from the intersection between mesh and plane
QAction * planeNodeAction_
additional information
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
bool dataType(DataType _type) const
void setDescriptions()
set scripting slot descriptions
PlaneObject * curPlane_
additional information
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Viewer::ActionMode actionMode()
Get the current Action mode.
pick any of the prior targets (should be implemented for all nodes)
double sceneRadius()
Returns the current scene radius from the active examiner widget.
int pickedCorner_
additional information
void slotMouseEvent(QMouseEvent *_event)
const std::string pickMode()
Get the current Picking mode.
int lastObjId_
additional information
PlaneObject * planeObject(BaseObjectData *_object)
Cast an BaseObject to a PlaneObject if possible.
ACG::Vec3d viewDirection_
additional information
void setSize(double _xDirection, double _yDirection)
Set plane size.
void viewing_ray(int _x, int _y, Vec3d &_origin, Vec3d &_direction) const
auto length() const -> decltype(std::declval< VectorT< S, DIM >>().norm())
compute squared euclidean norm
void slotKeyReleaseEvent(QKeyEvent *_event)
a keyRelease event occured
void slotPickModeChanged(const std::string &_mode)
the pickMode changed
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void pluginsInitialized()
Second initialization phase.
PlanePlugin()
Constructor.
int context_height() const
get gl context height
void slotCreatePlaneNode()
Plane Node Button.
Plane origPlane_
additional information
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
VectorT< double, 3 > Vec3d
ACG::GLState & glState()
Get the glState of the Viewer.