Line |
Branch |
Exec |
Source |
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 <gepetto/viewer/config-osg.h> |
21 |
|
|
#include <gepetto/viewer/fwd.h> |
22 |
|
|
#include <gepetto/viewer/transform-writer.h> |
23 |
|
|
|
24 |
|
|
#include <OpenThreads/Mutex> |
25 |
|
|
#include <OpenThreads/ScopedLock> |
26 |
|
|
|
27 |
|
|
namespace gepetto { |
28 |
|
|
namespace viewer { |
29 |
|
|
|
30 |
|
|
typedef OpenThreads::Mutex Mutex; |
31 |
|
|
typedef OpenThreads::ScopedLock<Mutex> ScopedLock; |
32 |
|
|
|
33 |
|
|
DEF_CLASS_SMART_PTR(WindowsManager) |
34 |
|
|
|
35 |
|
|
struct NodeConfiguration : Configuration { |
36 |
|
|
NodePtr_t node; |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
struct BlenderFrameCapture { |
40 |
|
|
typedef std::vector<NodePtr_t> Nodes_t; |
41 |
|
|
osg::ref_ptr<TransformWriterVisitor> writer_visitor_; |
42 |
|
|
Nodes_t nodes_; |
43 |
|
|
BlenderFrameCapture(); |
44 |
|
|
void captureFrame(); |
45 |
|
|
}; |
46 |
|
|
|
47 |
|
|
/// Manage a set of windows that may share 3D objects. |
48 |
|
|
class WindowsManager { |
49 |
|
|
public: |
50 |
|
|
// Typedef for position and color values. |
51 |
|
|
typedef osg::Vec3f::value_type value_type; |
52 |
|
|
typedef osgVector4 Color_t; |
53 |
|
|
typedef ::osg::Vec3ArrayRefPtr Vec3ArrayPtr_t; |
54 |
|
|
typedef ::osg::Vec4ArrayRefPtr Vec4ArrayPtr_t; |
55 |
|
|
typedef std::string WindowID; |
56 |
|
|
|
57 |
|
|
private: |
58 |
|
|
typedef std::map<WindowID, WindowManagerPtr_t> WindowManagerMap_t; |
59 |
|
|
WindowManagerMap_t windowManagers_; |
60 |
|
|
std::map<std::string, NodePtr_t> nodes_; |
61 |
|
|
std::map<std::string, GroupNodePtr_t> groupNodes_; |
62 |
|
|
std::map<std::string, RoadmapViewerPtr_t> roadmapNodes_; |
63 |
|
|
Mutex osgFrameMtx_; |
64 |
|
|
BlenderFrameCapture blenderCapture_; |
65 |
|
|
|
66 |
|
|
static osgVector4 getColor(const std::string& colorName); |
67 |
|
|
static std::string parentName(const std::string& name); |
68 |
|
|
static VisibilityMode getVisibility(const std::string& visibilityName); |
69 |
|
|
static WireFrameMode getWire(const std::string& wireName); |
70 |
|
|
static LightingMode getLight(const std::string& lightName); |
71 |
|
|
NodePtr_t find(const std::string name, |
72 |
|
|
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: |
78 |
|
|
/** |
79 |
|
|
\brief Default constructor |
80 |
|
|
*/ |
81 |
|
|
WindowsManager(); |
82 |
|
|
WindowID addWindow(std::string winName, WindowManagerPtr_t newWindow); |
83 |
|
|
|
84 |
|
|
typedef std::vector<NodeConfiguration> NodeConfigurations_t; |
85 |
|
|
Mutex configListMtx_; |
86 |
|
|
NodeConfigurations_t newNodeConfigurations_; |
87 |
|
|
bool autoCaptureTransform_; |
88 |
|
|
void refreshConfigs(const NodeConfigurations_t& configs); |
89 |
|
|
|
90 |
|
|
template <typename Iterator, typename NodeContainer_t> |
91 |
|
|
std::size_t getNodes(const Iterator& begin, const Iterator& end, |
92 |
|
|
NodeContainer_t& nodes); |
93 |
|
|
|
94 |
|
|
/// Warning, the mutex should be locked before and unlocked after this |
95 |
|
|
/// opertations. |
96 |
|
|
void addNode(const std::string& nodeName, NodePtr_t node, |
97 |
|
|
bool guessParent = false); |
98 |
|
|
virtual void addNode(const std::string& nodeName, NodePtr_t node, |
99 |
|
|
GroupNodePtr_t parent); |
100 |
|
|
void addGroup(const std::string& groupName, GroupNodePtr_t group, |
101 |
|
|
bool guessParent = false); |
102 |
|
|
virtual void addGroup(const std::string& groupName, GroupNodePtr_t group, |
103 |
|
|
GroupNodePtr_t parent); |
104 |
|
|
|
105 |
|
|
public: |
106 |
|
|
static WindowsManagerPtr_t create(); |
107 |
|
|
|
108 |
|
✗ |
virtual ~WindowsManager() {}; |
109 |
|
|
|
110 |
|
|
virtual std::vector<std::string> getNodeList(); |
111 |
|
|
virtual std::vector<std::string> getGroupNodeList(const std::string& group); |
112 |
|
|
virtual std::vector<std::string> getSceneList(); |
113 |
|
|
virtual std::vector<std::string> getWindowList(); |
114 |
|
|
|
115 |
|
|
/// Return the mutex to be locked before modifying the scene. |
116 |
|
✗ |
Mutex& osgFrameMutex() { return osgFrameMtx_; } |
117 |
|
|
|
118 |
|
|
virtual WindowID getWindowID(const std::string& windowName); |
119 |
|
|
|
120 |
|
|
virtual void createScene(const std::string& sceneName); |
121 |
|
|
virtual void createSceneWithFloor(const std::string& sceneName); |
122 |
|
|
virtual bool addSceneToWindow(const std::string& sceneName, |
123 |
|
|
const WindowID windowId); |
124 |
|
|
|
125 |
|
|
virtual bool attachCameraToNode(const std::string& nodeName, |
126 |
|
|
const WindowID windowId); |
127 |
|
|
virtual bool detachCamera(const WindowID windowId); |
128 |
|
|
|
129 |
|
|
virtual bool nodeExists(const std::string& name); |
130 |
|
|
|
131 |
|
|
virtual bool addFloor(const std::string& floorName); |
132 |
|
|
|
133 |
|
|
/// Add a box in the scene |
134 |
|
|
/// \param boxName name of the box, |
135 |
|
|
/// \param boxSize1, boxSize2, boxSize3 lengths of the box along |
136 |
|
|
/// axes x, y, z, |
137 |
|
|
/// \param color the color of the box. |
138 |
|
|
virtual bool addBox(const std::string& boxName, const float& boxSize1, |
139 |
|
|
const float& boxSize2, const float& boxSize3, |
140 |
|
|
const Color_t& color); |
141 |
|
|
|
142 |
|
|
virtual bool addCapsule(const std::string& capsuleName, float radius, |
143 |
|
|
float height, const Color_t& color); |
144 |
|
|
|
145 |
|
|
virtual bool addArrow(const std::string& arrowName, const float radius, |
146 |
|
|
const float length, const Color_t& color); |
147 |
|
|
|
148 |
|
|
virtual bool addRod(const std::string& rodName, const Color_t& color, |
149 |
|
|
const float radius, const float length, short maxCapsule); |
150 |
|
|
|
151 |
|
|
virtual bool resizeCapsule(const std::string& capsuleName, float newHeight); |
152 |
|
|
virtual bool resizeArrow(const std::string& arrowName, float newRadius, |
153 |
|
|
float newLength); |
154 |
|
|
|
155 |
|
|
virtual bool addMesh(const std::string& meshName, |
156 |
|
|
const std::string& meshPath); |
157 |
|
|
/// See LeafNodeCollada::removeLightSources() |
158 |
|
|
virtual void removeLightSources(const std::string& meshName); |
159 |
|
|
|
160 |
|
|
virtual bool addCone(const std::string& coneName, float radius, float height, |
161 |
|
|
const Color_t& color); |
162 |
|
|
|
163 |
|
|
virtual bool addCylinder(const std::string& cylinderName, float radius, |
164 |
|
|
float height, const Color_t& color); |
165 |
|
|
|
166 |
|
|
virtual bool addSphere(const std::string& sphereName, float radius, |
167 |
|
|
const Color_t& color); |
168 |
|
|
|
169 |
|
|
virtual bool addLight(const std::string& lightName, const WindowID wid, |
170 |
|
|
float radius, const Color_t& color); |
171 |
|
|
|
172 |
|
|
virtual bool addLine(const std::string& lineName, const osgVector3& pos1, |
173 |
|
|
const osgVector3& pos2, const Color_t& color); |
174 |
|
|
virtual bool setLineStartPoint(const std::string& lineName, |
175 |
|
|
const osgVector3& pos1); |
176 |
|
|
virtual bool setLineEndPoint(const std::string& lineName, |
177 |
|
|
const osgVector3& pos2); |
178 |
|
|
virtual bool setLineExtremalPoints(const std::string& lineName, |
179 |
|
|
const osgVector3& pos1, |
180 |
|
|
const osgVector3& pos2); |
181 |
|
|
|
182 |
|
|
virtual bool addCurve(const std::string& curveName, const Vec3ArrayPtr_t& pos, |
183 |
|
|
const Color_t& color); |
184 |
|
|
|
185 |
|
|
virtual bool setCurvePoints(const std::string& curveName, |
186 |
|
|
const Vec3ArrayPtr_t& pos); |
187 |
|
|
virtual bool setCurveColors(const std::string& curveName, |
188 |
|
|
const Vec4ArrayPtr_t& colors); |
189 |
|
|
|
190 |
|
|
/// \param mode See LeafNodeLine::setMode for possible values |
191 |
|
|
virtual bool setCurveMode(const std::string& curveName, const GLenum mode); |
192 |
|
|
virtual bool setCurvePointsSubset(const std::string& curveName, |
193 |
|
|
const int first, const std::size_t count); |
194 |
|
|
virtual bool setCurveLineWidth(const std::string& curveName, |
195 |
|
|
const float& width); |
196 |
|
|
|
197 |
|
|
virtual bool addSquareFace(const std::string& faceName, |
198 |
|
|
const osgVector3& pos1, const osgVector3& pos2, |
199 |
|
|
const osgVector3& pos3, const osgVector3& pos4, |
200 |
|
|
const Color_t& color); |
201 |
|
|
virtual bool setTexture(const std::string& nodeName, |
202 |
|
|
const std::string& filename); |
203 |
|
|
virtual bool addTriangleFace(const std::string& faceName, |
204 |
|
|
const osgVector3& pos1, const osgVector3& pos2, |
205 |
|
|
const osgVector3& pos3, const Color_t& color); |
206 |
|
|
virtual bool addXYZaxis(const std::string& nodeName, const Color_t& color, |
207 |
|
|
float radius, float sizeAxis); |
208 |
|
|
|
209 |
|
|
virtual bool createRoadmap(const std::string& name, const Color_t& colorNode, |
210 |
|
|
float radius, float sizeAxis, |
211 |
|
|
const Color_t& colorEdge); |
212 |
|
|
|
213 |
|
|
virtual bool addEdgeToRoadmap(const std::string& nameRoadmap, |
214 |
|
|
const osgVector3& posFrom, |
215 |
|
|
const osgVector3& posTo); |
216 |
|
|
|
217 |
|
|
virtual bool addNodeToRoadmap(const std::string& nameRoadmap, |
218 |
|
|
const Configuration& configuration); |
219 |
|
|
|
220 |
|
|
virtual bool addURDF(const std::string& urdfName, |
221 |
|
|
const std::string& urdfPath); |
222 |
|
|
/// \deprecated Argument urdfPackagePathCorba is ignored. |
223 |
|
|
virtual bool addURDF(const std::string& urdfName, const std::string& urdfPath, |
224 |
|
|
const std::string& urdfPackagePath); |
225 |
|
|
|
226 |
|
|
virtual bool addUrdfCollision(const std::string& urdfName, |
227 |
|
|
const std::string& urdfPath); |
228 |
|
|
/// \deprecated Argument urdfPackagePathCorba is ignored. |
229 |
|
|
virtual bool addUrdfCollision(const std::string& urdfName, |
230 |
|
|
const std::string& urdfPath, |
231 |
|
|
const std::string& urdfPackagePath); |
232 |
|
|
|
233 |
|
|
virtual void addUrdfObjects(const std::string& urdfName, |
234 |
|
|
const std::string& urdfPath, bool visual); |
235 |
|
|
/// \deprecated Argument urdfPackagePathCorba is ignored. |
236 |
|
|
virtual void addUrdfObjects(const std::string& urdfName, |
237 |
|
|
const std::string& urdfPath, |
238 |
|
|
const std::string& urdfPackagePath, bool visual); |
239 |
|
|
|
240 |
|
|
virtual bool createGroup(const std::string& groupName); |
241 |
|
|
virtual bool addToGroup(const std::string& nodeName, |
242 |
|
|
const std::string& groupName); |
243 |
|
|
virtual bool removeFromGroup(const std::string& nodeName, |
244 |
|
|
const std::string& groupName); |
245 |
|
|
virtual bool deleteNode(const std::string& nodeName, bool all); |
246 |
|
|
|
247 |
|
|
virtual bool removeObjectFromCache(const std::string& nodeName); |
248 |
|
|
virtual bool applyConfiguration(const std::string& nodeName, |
249 |
|
|
const Configuration& configuration); |
250 |
|
|
virtual bool applyConfigurations( |
251 |
|
|
const std::vector<std::string>& nodeName, |
252 |
|
|
const std::vector<Configuration>& configuration); |
253 |
|
|
|
254 |
|
|
virtual bool addLandmark(const std::string& nodeName, float size); |
255 |
|
|
virtual bool deleteLandmark(const std::string& nodeName); |
256 |
|
|
|
257 |
|
|
virtual Configuration getStaticTransform(const std::string& nodeName) const; |
258 |
|
|
virtual bool setStaticTransform(const std::string& nodeName, |
259 |
|
|
const Configuration& transform); |
260 |
|
|
|
261 |
|
|
virtual bool setVisibility(const std::string& nodeName, |
262 |
|
|
const std::string& visibilityMode); |
263 |
|
|
virtual bool setScale(const std::string& nodeName, const osgVector3& scale); |
264 |
|
|
virtual bool setScale(const std::string& nodeName, const float& scale); |
265 |
|
|
virtual bool setScale(const std::string& nodeName, |
266 |
|
|
const int& scalePercentage); |
267 |
|
|
virtual bool setColor(const std::string& nodeName, const Color_t& color); |
268 |
|
|
virtual bool setWireFrameMode(const std::string& nodeName, |
269 |
|
|
const std::string& wireFrameMode); |
270 |
|
|
virtual bool setLightingMode(const std::string& nodeName, |
271 |
|
|
const std::string& lightingMode); |
272 |
|
|
virtual bool setHighlight(const std::string& nodeName, int state); |
273 |
|
|
virtual bool setAlpha(const std::string& nodeName, const float& alpha); |
274 |
|
|
virtual bool setAlpha(const std::string& nodeName, |
275 |
|
|
const int& alphaPercentage); |
276 |
|
|
|
277 |
|
|
virtual bool setCaptureTransform(const std::string& filename, |
278 |
|
|
const std::vector<std::string>& nodename); |
279 |
|
|
virtual void captureTransformOnRefresh(bool autoCapture); |
280 |
|
|
virtual void captureTransform(); |
281 |
|
|
virtual bool writeBlenderScript(const std::string& filename, |
282 |
|
|
const std::vector<std::string>& nodename); |
283 |
|
|
virtual bool writeNodeFile(const std::string& nodename, |
284 |
|
|
const std::string& filename); |
285 |
|
|
virtual bool writeWindowFile(const WindowID windowId, |
286 |
|
|
const std::string& filename); |
287 |
|
|
virtual bool setBackgroundColor1(const WindowID windowId, |
288 |
|
|
const Color_t& color); |
289 |
|
|
virtual bool setBackgroundColor2(const WindowID windowId, |
290 |
|
|
const Color_t& color); |
291 |
|
|
virtual Configuration getCameraTransform(const WindowID windowId); |
292 |
|
|
virtual bool setCameraTransform(const WindowID windowId, |
293 |
|
|
const Configuration& configuration); |
294 |
|
|
virtual bool setCameraToBestFit(const WindowID windowId); |
295 |
|
|
|
296 |
|
|
virtual std::vector<std::string> getPropertyNames( |
297 |
|
|
const std::string& nodeName) const; |
298 |
|
|
virtual std::vector<std::string> getPropertyTypes( |
299 |
|
|
const std::string& nodeName) const; |
300 |
|
|
|
301 |
|
|
template <typename Property_t> |
302 |
|
|
Property_t getProperty(const std::string& nodeName, |
303 |
|
|
const std::string& propName) const; |
304 |
|
|
template <typename Property_t> |
305 |
|
|
void setProperty(const std::string& nodeName, const std::string& propName, |
306 |
|
|
const Property_t& value); |
307 |
|
|
|
308 |
|
|
virtual std::string getStringProperty(const std::string& nodeName, |
309 |
|
|
const std::string& propName) const; |
310 |
|
|
virtual void setStringProperty(const std::string& nodeName, |
311 |
|
|
const std::string& propName, |
312 |
|
|
const std::string& value); |
313 |
|
|
virtual osgVector2 getVector2Property(const std::string& nodeName, |
314 |
|
|
const std::string& propName) const; |
315 |
|
|
virtual void setVector2Property(const std::string& nodeName, |
316 |
|
|
const std::string& propName, |
317 |
|
|
const osgVector2& value); |
318 |
|
|
virtual osgVector3 getVector3Property(const std::string& nodeName, |
319 |
|
|
const std::string& propName) const; |
320 |
|
|
virtual void setVector3Property(const std::string& nodeName, |
321 |
|
|
const std::string& propName, |
322 |
|
|
const osgVector3& value); |
323 |
|
|
virtual osgVector4 getColorProperty(const std::string& nodeName, |
324 |
|
|
const std::string& propName) const; |
325 |
|
|
virtual void setColorProperty(const std::string& nodeName, |
326 |
|
|
const std::string& propName, |
327 |
|
|
const osgVector4& value); |
328 |
|
|
virtual float getFloatProperty(const std::string& nodeName, |
329 |
|
|
const std::string& propName) const; |
330 |
|
|
virtual void setFloatProperty(const std::string& nodeName, |
331 |
|
|
const std::string& propName, |
332 |
|
|
const float& value); |
333 |
|
|
virtual bool getBoolProperty(const std::string& nodeName, |
334 |
|
|
const std::string& propName) const; |
335 |
|
|
virtual void setBoolProperty(const std::string& nodeName, |
336 |
|
|
const std::string& propName, const bool& value); |
337 |
|
|
virtual int getIntProperty(const std::string& nodeName, |
338 |
|
|
const std::string& propName) const; |
339 |
|
|
virtual void setIntProperty(const std::string& nodeName, |
340 |
|
|
const std::string& propName, const int& value); |
341 |
|
|
virtual void callVoidProperty(const std::string& nodeName, |
342 |
|
|
const std::string& propName); |
343 |
|
|
|
344 |
|
|
WindowManagerPtr_t getWindowManager(const WindowID wid, |
345 |
|
|
bool throwIfDoesntExist = false) const; |
346 |
|
|
GroupNodePtr_t getGroup(const std::string groupName, |
347 |
|
|
bool throwIfDoesntExist = false) const; |
348 |
|
|
NodePtr_t getNode(const std::string& nodeName, |
349 |
|
|
bool throwIfDoesntExist = false) const; |
350 |
|
|
Configuration getNodeGlobalTransform(const std::string nodeName) const; |
351 |
|
|
}; |
352 |
|
|
} /* namespace viewer */ |
353 |
|
|
} /* namespace gepetto */ |
354 |
|
|
|
355 |
|
|
#endif /* GEPETTO_VIEWER_WINDOWMANAGERS_HH */ |
356 |
|
|
|