42#include "PlanePlugin.hh"
49#include <ACG/Scenegraph/LineNode.hh>
51const char *PLANE =
"CreatePlaneNode";
52const char *PLANE_RESIZE =
"PlaneResize";
60 createPlane_(nullptr),
61 planeNodeAction_(nullptr),
75 emit registerKey(Qt::Key_Escape, Qt::NoModifier,
"Cancel Plane",
true);
76 emit registerKey(Qt::Key_Shift, Qt::NoModifier, tr(
"PP"),
true);
77 emit registerKey(Qt::Key_Shift, Qt::ShiftModifier, tr(
"PP"),
true);
78 emit registerKey(Qt::Key_Shift, Qt::ControlModifier | Qt::ShiftModifier, tr(
"PP"),
true);
89 emit addPickMode(PLANE);
91 emit addPickMode(PLANE_RESIZE);
97 connect(
createPlane_, SIGNAL(updateViewProxy()),
this, SIGNAL(updateView()));
100 QToolBar *toolbar =
new QToolBar(
"Plane Toolbar");
106 OpenFlipper::Options::dirSeparator() +
112 emit addToolbar(toolbar);
137 if (_event->key() == Qt::Key_Shift)
149 if (_event->key() == Qt::Key_Shift)
196 auto rayPlaneIntersection = [](
ACG::Vec3d const &origin,
199 double &alpha,
double &beta) ->
bool {
209 constexpr double EPSILON = std::numeric_limits<double>::epsilon() * 1e2;
210 if (det > -EPSILON && det < EPSILON) {
211 std::cerr <<
"det within eps!" << std::endl;
216 alpha = (tvec | pvec) * inv_det;
218 beta = (dir | qvec) * inv_det;
223 if (alpha < 0.0 || alpha > 1.0)
225 if (beta < 0.0 || alpha + beta > 1.0)
235 switch (_event->type()) {
236 case QEvent::MouseButtonPress: {
238 size_t node_idx, target_idx;
240 _event->pos(), node_idx, target_idx,
250 QPoint position = _event->pos();
261 const auto center =
curPlane_->plane().position;
262 const auto xdir =
curPlane_->plane().xDirection / 2.;
263 const auto ydir =
curPlane_->plane().yDirection / 2.;
264 const auto p0 = center + xdir + ydir;
265 const auto p1 = center + xdir - ydir;
266 const auto p2 = center - xdir - ydir;
267 double u = -1, v = -1, w = -1;
284 case QEvent::MouseMove: {
288 QPoint position = _event->pos();
306 viewCoord[0], viewCoord[1], origin, dir);
308 double u = -3.1415926539, v = -3.1415926539;
309 const auto center = plane.position;
310 const auto xdir = plane.xDirection / 2.;
311 const auto ydir = plane.yDirection / 2.;
312 const auto p0 =
ACG::Vec3d{center + xdir + ydir};
313 const auto p1 =
ACG::Vec3d{center + xdir - ydir};
314 const auto p2 =
ACG::Vec3d{center - xdir - ydir};
320 rayPlaneIntersection(origin, dir, p0, p1, p2, u, v);
321 const auto w = 1. - (u + v);
332 const auto center = plane.position;
333 const auto xdir = plane.xDirection / 2.;
334 const auto ydir = plane.yDirection / 2.;
337 wMouseDownPosition = (center - xdir - ydir);
340 wMouseDownPosition = center + xdir - ydir;
343 wMouseDownPosition = center + xdir + ydir;
346 wMouseDownPosition = center - xdir + ydir;
347 wMouseDownPosition -= plane.position;
353 const auto worldSpaceUpdate = (wCurrMousePos - wMouseDownPosition) / 2.;
356 const auto distClickOrigin = wMouseDownPosition;
359 auto scale = (worldSpaceUpdate + distClickOrigin) / distClickOrigin;
360 if (!std::isinf(scale[2]) && !std::isnan(scale[2]))
363 const auto xscale = scale[0] * plane.xDirection.
length();
364 const auto yscale = scale[1] * plane.yDirection.
length();
368 plane.position += worldSpaceUpdate;
375 const auto viewDiff = (viewCoord -
viewCoord_) / 1000;
376 const auto sign = (viewDiff[0] / std::fabs(viewDiff[0]));
377 plane.position += plane.normal * sign * viewDiff.
length();
385 const auto worldSpaceUpdate = (wCurrMousePos - wMouseDownPosition) / 2.;
386 plane.position += worldSpaceUpdate * 2;
396 emit log(
LOGERR, tr(
"COULD NOT UPDATE OBJECT"));
401 case QEvent::MouseButtonRelease: {
439 if (obj ==
nullptr) {
440 emit log(
LOGERR,
"Unable to get object");
463 if (getIntersectionParams(*obj, center, radius)) {
464 radius = 1.5 * radius;
467 currentPlane->plane().
setPlane(center, normal);
468 currentPlane->plane().
setSize(2.0 * radius, 2.0 * radius);
471 std::cerr <<
"unable to get intersection params" << std::endl;
472 currentPlane->plane().
setPlane(point, normal);
491 std::vector<ACG::Vec3d> linePoints;
508 fh = mesh->face_handle(mesh->halfedge_handle(eh, 1));
528 fh = mesh->face_handle(mesh->halfedge_handle(eh, 1));
534 if (linePoints.empty())
539 for (uint i = 0; i < linePoints.size(); i++)
540 _center += linePoints[i];
542 _center /= (double)linePoints.
size();
546 for (uint i = 0; i < linePoints.size(); i++) {
547 double dist = (_center - linePoints[i]).norm();
#define DATA_TRIANGLE_MESH
int context_height() const
get gl context height
void viewing_ray(int _x, int _y, Vec3d &_origin, Vec3d &_direction) const
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
void setSize(double _xDirection, double _yDirection)
Set plane size.
void show()
Show node: set status to Active.
bool dataType(DataType _type) const
Kernel::EdgeHandle EdgeHandle
Scalar type.
Kernel::FaceHandle FaceHandle
Scalar type.
static constexpr size_t size()
returns dimension of the vector
auto length() const -> decltype(std::declval< VectorT< S, DIM > >().norm())
compute squared euclidean norm
PlaneNode * planeNode()
Get the scenegraph Node.
bool dragging_
additional information
void slotCreatePlaneTriggered()
Create a plane node when position/normal have been drawn.
ACG::Vec3d viewCoord_
additional information
PlanePlugin()
Constructor.
PlaneObject * curPlane_
additional information
bool ortho_
additional information
ACG::Vec3d wCurrMousePos_
additional information
void slotKeyReleaseEvent(QKeyEvent *_event)
a keyRelease event occured
int pickedCorner_
additional information
QAction * planeNodeAction_
additional information
ACG::Vec3d wMouseDownPosition_
additional information
void slotPickModeChanged(const std::string &_mode)
the pickMode changed
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
MeshT::EdgeHandle getCuttedEdge(MeshT &_mesh, ACG::Vec3d &_planeNormal, ACG::Vec3d &_planePoint)
get an edge of the mesh that is cut by the plane
QtPlaneSelect * createPlane_
additional information
void setDescriptions()
set scripting slot descriptions
void slotCreatePlaneNode()
Plane Node Button.
Plane origPlane_
additional information
void slotKeyEvent(QKeyEvent *_event)
a key event occured
void initializePlugin()
Initialize the plugin.
int lastObjId_
additional information
void slotMouseEvent(QMouseEvent *_event)
a mouse event occured
ACG::Vec3d viewDirection_
additional information
void pluginsInitialized()
Second initialization phase.
void slotMouseEvent(QMouseEvent *_event)
ACG::GLState & glState()
Get the glState of the Viewer.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
VectorT< double, 3 > Vec3d
double sceneRadius()
Returns the current scene radius from the active examiner widget.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
PlaneObject * planeObject(BaseObjectData *_object)
Cast an BaseObject to a PlaneObject if possible.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
const std::string pickMode()
Get the current Picking mode.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Viewer::ActionMode actionMode()
Get the current Action mode.