windows-manager.h
Go to the documentation of this file.
1 // Copyright (c) 2014, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef GEPETTO_VIEWER_WINDOWMANAGERS_HH
18 #define GEPETTO_VIEWER_WINDOWMANAGERS_HH
19 
20 #include <OpenThreads/Mutex>
21 #include <OpenThreads/ScopedLock>
22 
23 #include <gepetto/viewer/fwd.h>
26 
27 namespace gepetto {
28 namespace viewer {
29 
31  typedef OpenThreads::ScopedLock<Mutex> ScopedLock;
32 
34 
37  };
38 
40  typedef std::vector<NodePtr_t> Nodes_t;
41  osg::ref_ptr < TransformWriterVisitor > writer_visitor_;
42  Nodes_t nodes_;
44  void captureFrame ();
45  };
46 
49  {
50  public:
51  // Typedef for position and color values.
52  typedef osg::Vec3f::value_type value_type;
54  typedef ::osg::Vec3ArrayRefPtr Vec3ArrayPtr_t;
55  typedef ::osg::Vec4ArrayRefPtr Vec4ArrayPtr_t;
56  typedef std::string WindowID;
57 
58  private:
59  typedef std::map <WindowID, WindowManagerPtr_t> WindowManagerMap_t;
60  WindowManagerMap_t windowManagers_;
61  std::map<std::string, NodePtr_t> nodes_;
62  std::map<std::string, GroupNodePtr_t> groupNodes_;
63  std::map<std::string, RoadmapViewerPtr_t> roadmapNodes_;
64  Mutex osgFrameMtx_;
65  BlenderFrameCapture blenderCapture_;
66 
67  static osgVector4 getColor(const std::string& colorName);
68  static std::string parentName(const std::string& name);
69  static VisibilityMode getVisibility(const std::string& visibilityName);
70  static WireFrameMode getWire(const std::string& wireName);
71  static LightingMode getLight(const std::string& lightName);
72  NodePtr_t find (const std::string name, GroupNodePtr_t group = GroupNodePtr_t());
73  void initParent(NodePtr_t node, GroupNodePtr_t parent);
74  bool loadUDRF(const std::string& urdfName, const std::string& urdfPath,
75  bool visual, bool linkFrame);
76 
77  protected:
81  WindowsManager ();
82  WindowID addWindow (std::string winName, WindowManagerPtr_t newWindow);
83 
84  typedef std::vector<NodeConfiguration> NodeConfigurations_t;
86  NodeConfigurations_t newNodeConfigurations_;
88  void refreshConfigs (const NodeConfigurations_t& configs);
89 
90  template <typename Iterator, typename NodeContainer_t>
91  std::size_t getNodes
92  (const Iterator& begin, const Iterator& end, NodeContainer_t& nodes);
93 
95  void addNode (const std::string& nodeName, NodePtr_t node, bool guessParent = false);
96  virtual void addNode (const std::string& nodeName, NodePtr_t node, GroupNodePtr_t parent);
97  void addGroup(const std::string& groupName, GroupNodePtr_t group, bool guessParent = false);
98  virtual void addGroup(const std::string& groupName, GroupNodePtr_t group, GroupNodePtr_t parent);
99 
100  public:
101  static WindowsManagerPtr_t create ();
102 
103  virtual ~WindowsManager () {};
104 
105  virtual std::vector<std::string> getNodeList();
106  virtual std::vector<std::string> getGroupNodeList(const std::string& group);
107  virtual std::vector<std::string> getSceneList();
108  virtual std::vector<std::string> getWindowList();
109 
111  Mutex& osgFrameMutex () {
112  return osgFrameMtx_;
113  }
114 
115  virtual WindowID getWindowID (const std::string& windowName);
116 
117  virtual void createScene(const std::string& sceneName);
118  virtual void createSceneWithFloor(const std::string& sceneName);
119  virtual bool addSceneToWindow(const std::string& sceneName, const WindowID windowId);
120 
121  virtual bool attachCameraToNode(const std::string& nodeName, const WindowID windowId);
122  virtual bool detachCamera(const WindowID windowId);
123 
124  virtual bool nodeExists (const std::string& name);
125 
126  virtual bool addFloor(const std::string& floorName);
127 
133  virtual bool addBox(const std::string& boxName, const float& boxSize1, const float& boxSize2, const float& boxSize3, const Color_t& color);
134 
135  virtual bool addCapsule(const std::string& capsuleName, float radius, float height, const Color_t& color);
136 
137  virtual bool addArrow (const std::string& arrowName,const float radius, const float length, const Color_t& color);
138 
139  virtual bool addRod (const std::string& rodName, const Color_t& color,const float radius,const float length, short maxCapsule);
140 
141  virtual bool resizeCapsule(const std::string& capsuleName, float newHeight);
142  virtual bool resizeArrow(const std::string& arrowName ,float newRadius, float newLength);
143 
144  virtual bool addMesh(const std::string& meshName, const std::string& meshPath);
146  virtual void removeLightSources(const std::string& meshName);
147 
148  virtual bool addCone(const std::string& coneName, float radius, float height, const Color_t& color);
149 
150  virtual bool addCylinder(const std::string& cylinderName, float radius, float height, const Color_t& color);
151 
152  virtual bool addSphere(const std::string& sphereName, float radius, const Color_t& color);
153 
154  virtual bool addLight(const std::string& lightName, const WindowID wid, float radius, const Color_t& color);
155 
156  virtual bool addLine(const std::string& lineName, const osgVector3& pos1, const osgVector3& pos2, const Color_t& color);
157  virtual bool setLineStartPoint(const std::string& lineName, const osgVector3& pos1);
158  virtual bool setLineEndPoint(const std::string& lineName, const osgVector3& pos2);
159  virtual bool setLineExtremalPoints(const std::string& lineName, const osgVector3& pos1, const osgVector3& pos2);
160 
161  virtual bool addCurve(const std::string& curveName, const Vec3ArrayPtr_t& pos, const Color_t& color);
162 
163  virtual bool setCurvePoints(const std::string& curveName, const Vec3ArrayPtr_t& pos);
164  virtual bool setCurveColors(const std::string& curveName, const Vec4ArrayPtr_t& colors);
165 
167  virtual bool setCurveMode (const std::string& curveName, const GLenum mode);
168  virtual bool setCurvePointsSubset (const std::string& curveName, const int first, const std::size_t count);
169  virtual bool setCurveLineWidth (const std::string& curveName, const float& width);
170 
171  virtual bool addSquareFace(const std::string& faceName, const osgVector3& pos1, const osgVector3& pos2, const osgVector3& pos3, const osgVector3& pos4, const Color_t& color);
172  virtual bool setTexture (const std::string& nodeName, const std::string& filename);
173  virtual bool addTriangleFace(const std::string& faceName, const osgVector3& pos1, const osgVector3& pos2, const osgVector3& pos3, const Color_t& color);
174  virtual bool addXYZaxis (const std::string& nodeName, const Color_t& color, float radius, float sizeAxis);
175 
176  virtual bool createRoadmap(const std::string& name,const Color_t& colorNode, float radius, float sizeAxis, const Color_t& colorEdge);
177 
178  virtual bool addEdgeToRoadmap(const std::string& nameRoadmap, const osgVector3& posFrom, const osgVector3& posTo);
179 
180  virtual bool addNodeToRoadmap(const std::string& nameRoadmap, const Configuration& configuration);
181 
182  virtual bool addURDF(const std::string& urdfName, const std::string& urdfPath);
184  virtual bool addURDF(const std::string& urdfName, const std::string& urdfPath, const std::string& urdfPackagePath);
185 
186  virtual bool addUrdfCollision (const std::string& urdfName,
187  const std::string& urdfPath) ;
189  virtual bool addUrdfCollision (const std::string& urdfName,
190  const std::string& urdfPath,
191  const std::string& urdfPackagePath) ;
192 
193  virtual void addUrdfObjects (const std::string& urdfName,
194  const std::string& urdfPath,
195  bool visual) ;
197  virtual void addUrdfObjects (const std::string& urdfName,
198  const std::string& urdfPath,
199  const std::string& urdfPackagePath,
200  bool visual) ;
201 
202  virtual bool createGroup(const std::string& groupName);
203  virtual bool addToGroup(const std::string& nodeName, const std::string& groupName);
204  virtual bool removeFromGroup (const std::string& nodeName, const std::string& groupName);
205  virtual bool deleteNode (const std::string& nodeName, bool all);
206 
207  virtual bool applyConfiguration(const std::string& nodeName, const Configuration& configuration);
208  virtual bool applyConfigurations(const std::vector<std::string>& nodeName, const std::vector<Configuration>& configuration);
209 
210  virtual bool addLandmark(const std::string& nodeName, float size);
211  virtual bool deleteLandmark(const std::string& nodeName);
212 
213  virtual Configuration getStaticTransform (const std::string& nodeName) const;
214  virtual bool setStaticTransform (const std::string& nodeName, const Configuration& transform);
215 
216  virtual bool setVisibility(const std::string& nodeName, const std::string& visibilityMode);
217  virtual bool setScale(const std::string& nodeName, const osgVector3& scale);
218  virtual bool setScale(const std::string& nodeName, const float& scale);
219  virtual bool setScale(const std::string& nodeName, const int& scalePercentage);
220  virtual bool setColor(const std::string& nodeName, const Color_t& color);
221  virtual bool setWireFrameMode(const std::string& nodeName, const std::string& wireFrameMode);
222  virtual bool setLightingMode(const std::string& nodeName, const std::string& lightingMode);
223  virtual bool setHighlight(const std::string& nodeName, int state);
224  virtual bool setAlpha(const std::string& nodeName, const float& alpha);
225  virtual bool setAlpha(const std::string& nodeName, const int& alphaPercentage);
226 
227  virtual bool setCaptureTransform (const std::string& filename, const std::vector<std::string>& nodename);
228  virtual void captureTransformOnRefresh (bool autoCapture);
229  virtual void captureTransform ();
230  virtual bool writeBlenderScript (const std::string& filename, const std::vector<std::string>& nodename);
231  virtual bool writeNodeFile (const std::string& nodename, const std::string& filename);
232  virtual bool writeWindowFile (const WindowID windowId, const std::string& filename);
233  virtual bool setBackgroundColor1(const WindowID windowId,const Color_t& color);
234  virtual bool setBackgroundColor2(const WindowID windowId,const Color_t& color);
235  virtual Configuration getCameraTransform(const WindowID windowId);
236  virtual bool setCameraTransform(const WindowID windowId, const Configuration &configuration);
237 
238  virtual std::vector<std::string> getPropertyNames(const std::string& nodeName) const;
239  virtual std::vector<std::string> getPropertyTypes(const std::string& nodeName) const;
240 
241  template <typename Property_t> Property_t getProperty (const std::string& nodeName, const std::string& propName) const;
242  template <typename Property_t> void setProperty (const std::string& nodeName, const std::string& propName, const Property_t& value);
243 
244  virtual std::string getStringProperty(const std::string& nodeName, const std::string& propName) const;
245  virtual void setStringProperty(const std::string& nodeName, const std::string& propName, const std::string& value);
246  virtual osgVector2 getVector2Property(const std::string& nodeName, const std::string& propName) const;
247  virtual void setVector2Property(const std::string& nodeName, const std::string& propName, const osgVector2& value);
248  virtual osgVector3 getVector3Property(const std::string& nodeName, const std::string& propName) const;
249  virtual void setVector3Property(const std::string& nodeName, const std::string& propName, const osgVector3& value);
250  virtual osgVector4 getColorProperty(const std::string& nodeName, const std::string& propName) const;
251  virtual void setColorProperty(const std::string& nodeName, const std::string& propName, const osgVector4& value);
252  virtual float getFloatProperty(const std::string& nodeName, const std::string& propName) const;
253  virtual void setFloatProperty(const std::string& nodeName, const std::string& propName, const float& value);
254  virtual bool getBoolProperty(const std::string& nodeName, const std::string& propName) const;
255  virtual void setBoolProperty(const std::string& nodeName, const std::string& propName, const bool& value);
256  virtual int getIntProperty(const std::string& nodeName, const std::string& propName) const;
257  virtual void setIntProperty(const std::string& nodeName, const std::string& propName, const int& value);
258  virtual void callVoidProperty(const std::string& nodeName, const std::string& propName);
259 
260  WindowManagerPtr_t getWindowManager (const WindowID wid, bool throwIfDoesntExist = false) const;
261  GroupNodePtr_t getGroup (const std::string groupName, bool throwIfDoesntExist = false) const;
262  NodePtr_t getNode (const std::string& nodeName, bool throwIfDoesntExist = false) const;
263  Configuration getNodeGlobalTransform(const std::string nodeName) const;
264  };
265 } /* namespace viewer */
266 } /* namespace gepetto */
267 
268 #endif /* GEPETTO_VIEWER_WINDOWMANAGERS_HH */
std::vector< NodeConfiguration > NodeConfigurations_t
Definition: windows-manager.h:84
viewer::WindowManagerPtr_t WindowManagerPtr_t
Definition: osgwidget.hh:40
NodePtr_t node
Definition: windows-manager.h:36
::osg::Vec3f osgVector3
Definition: config-osg.h:109
Mutex configListMtx_
Definition: windows-manager.h:85
::osg::Vec2f osgVector2
Definition: config-osg.h:108
::osg::Vec4f osgVector4
Definition: config-osg.h:110
VisibilityMode
Definition: config-osg.h:117
osg::Vec3f::value_type value_type
Definition: windows-manager.h:52
::osg::Vec4ArrayRefPtr Vec4ArrayPtr_t
Definition: windows-manager.h:55
Mutex & osgFrameMutex()
Return the mutex to be locked before modifying the scene.
Definition: windows-manager.h:111
Definition: windows-manager.h:35
OpenThreads::ScopedLock< Mutex > ScopedLock
Definition: windows-manager.h:31
std::string WindowID
Definition: windows-manager.h:56
viewer::NodePtr_t NodePtr_t
Definition: fwd.hh:47
Definition: action-search-bar.hh:27
osg::ref_ptr< TransformWriterVisitor > writer_visitor_
Definition: windows-manager.h:41
viewer::GroupNodePtr_t GroupNodePtr_t
Definition: fwd.hh:50
Nodes_t nodes_
Definition: windows-manager.h:42
Manage a set of windows that may share 3D objects.
Definition: windows-manager.h:48
::osg::Vec3ArrayRefPtr Vec3ArrayPtr_t
Definition: windows-manager.h:54
LightingMode
Definition: config-osg.h:124
Definition: config-osg.h:144
osgVector4 Color_t
Definition: windows-manager.h:53
bool autoCaptureTransform_
Definition: windows-manager.h:87
OpenThreads::Mutex Mutex
Definition: windows-manager.h:30
std::vector< NodePtr_t > Nodes_t
Definition: windows-manager.h:40
#define DEF_CLASS_SMART_PTR(className)
Definition: macros.h:50
Definition: windows-manager.h:39
NodeConfigurations_t newNodeConfigurations_
Definition: windows-manager.h:86
WireFrameMode
Definition: config-osg.h:130
viewer::shared_ptr< WindowsManager > WindowsManagerPtr_t
Definition: fwd.hh:55
virtual ~WindowsManager()
Definition: windows-manager.h:103