/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2014 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLPhysics/src/ICLPhysics/ManipulatablePaper.h ** ** Module : ICLPhysics ** ** Author : Christof Elbrechter, Matthias Esau ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #pragma once #include #include #include #include #include #include #include namespace icl{ namespace physics{ /// extension of the standard physical paper class class ICLPhysics_API ManipulatablePaper : public PhysicsPaper{ struct VertexAttractor : public SceneObject{ utils::Point idx; utils::Time time; geom::Vec startPos; bool oscillating; geom::Scene *scene; ManipulatablePaper *parent; VertexAttractor(geom::Scene *scene, utils::Point coords, bool oscillating, ManipulatablePaper *parent); ~VertexAttractor(); void apply(float streangth); }; /// Utility class for extra annotations, rendered in paper coordinates /** hack: if a and b are identical, the annotation defines a point annotation */ struct LineAnnotation : public SceneObject{ utils::Point32f a; utils::Point32f b; PhysicsPaper *parent; LineAnnotation(PhysicsPaper *paper, const utils::Point32f &a, const utils::Point32f &b, const geom::GeomColor &color); virtual void prepareForRendering(); }; struct DraggedPositionIndicator : public SceneObject{ DraggedPositionIndicator(ManipulatablePaper *parent); utils::Point32f p; ManipulatablePaper *parent; virtual void prepareForRendering(); }; std::vector nodes; typedef std::map AttractorMap; AttractorMap attractors; PhysicsWorld *world; geom::Scene *scene; utils::Mutex attractorMutex; utils::SmartPtr mouse; std::vector lines; DraggedPositionIndicator *draggedPositionIndicator; friend class ManipulatablePaperMouseHandler; bool showAllConstraints; public: /// create with given parameters ManipulatablePaper(PhysicsWorld *world, geom::Scene *scene, int W, int H, const geom::Vec *init, bool initByCorners, const core::Img8u *frontTexture=0, const core::Img8u *backTexture=0 ); /// get's current position of node at given coorndinats geom::Vec getPos(const utils::Point &idx); /// updates all cubes from the underlying paper void prepareForRendering(); /// adds a new attractor at given coordinates void addAttractor(utils::Point coords, bool oscillating=false); /// removes an attractor at given coordinates void removeAttractor(utils::Point coords); /// removes all current attractors void removeAllAttractors(); /// applies all attractors and optional mouse force void applyAllForces(float attractorForce, float mouseForce); /// creates a mouse handler using the internal scene qt::MouseHandler *createMouseHandler(int cameraIndex = 0); /// sets whether the handle cubes are visible void setCubesVisible(bool on); /// sets texture or shaded mode void setTextureVisible(bool on); /// adation to base class (colors the cubes) virtual void adaptRowStiffness(float val, int row); /// adation to base class (colors the cubes) virtual void adaptColStiffness(float val, int col); /// adation to base class (colors the cubes) virtual void adaptGlobalStiffness(float val); /// removes all line annotations void removeAllLineAnnoations(); /// adapts all constraints, that intersect the given 2D line (using the current camera) /** Actually, this function will just use the current camera position to create a PlaneEquation that is passed the parent PhysicsPaper::adaptStiffnessAlongIntersection method */ void adaptStiffnessAlongLine(const utils::Point32f &a, const utils::Point32f &b, float val); /// adds a line annotation (given in paper coordinats=; void addLineAnnotation(const utils::Point32f &a, const utils::Point32f &b, const geom::GeomColor &color=geom::GeomColor(255,100,0,255)); void removeAllAnnoations(); /// returns the paper position for a given 2D screen position or (-1,-1) if not found utils::Point32f getPaperCoordinates(const utils::Point32f &screenPosition2D); /// adds a highlight at given position void setDraggedPosition(const utils::Point32f &paperPos); /// import name for parent class using PhysicsPaper::getPaperCoordinates; /// sets whether contraints are visualized void setShowAllConstraints(bool show){ showAllConstraints = show; } /// returns whether constraints are shown bool getShowAllConstraints() const{ return showAllConstraints; } /// custom rendering for constraint visualization virtual void complexCustomRender(icl::geom::ShaderUtil *u); /// saves the current constraints virtual void saveCFG(const std::string &filename); /// loads current constraints virtual void loadCFG(const std::string &filename); struct Shadow : public geom::SceneObject{ Shadow(float zLevel, ManipulatablePaper *parent); virtual void customRender(); float zLevel; ManipulatablePaper *parent; }; utils::SmartPtr m_shadow; void addShadow(float zLevel){ if(m_shadow){ throw utils::ICLException("shadow cannot be added twice!"); } m_shadow = new Shadow(zLevel,this); addChild(m_shadow.get()); } }; } }