DoorVisual.cpp
Go to the documentation of this file.
1 /*
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2013-2015, Timm Linder, Social Robotics Lab, University of Freiburg
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * * Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #include <rviz/mesh_loader.h>
32 #include <ros/console.h>
33 #include <ros/package.h>
34 
35 #include <OgreSceneManager.h>
36 #include <OgreSubEntity.h>
37 #include <OgreMaterialManager.h>
38 #include <OgreTextureManager.h>
39 #include <OgreTechnique.h>
40 #include <OgreAnimation.h>
41 
43 
44 
45 namespace fs = boost::filesystem;
46 
47 namespace tuw_object_rviz {
48 
49 /*
50  * Generic Person Visual
51  */
53  m_sceneManager(args.sceneManager)
54 {
56  m_sceneNode = args.parentNode->createChildSceneNode();
57 
58  Ogre::Vector3 scale(1,1,1);
59  m_sceneNode->setScale(scale);
60  R_do = Ogre::Matrix3(1,0,0,
61  0,1,0,
62  0,0,1);
63 }
64 
66  m_sceneManager->destroySceneNode(m_sceneNode->getName());
67 };
68 
69 void DoorVisual::setPosition(const Ogre::Vector3& position) {
70  m_sceneNode->setPosition(position);
71 }
72 
73 const Ogre::Vector3& DoorVisual::getPosition() const {
74  return m_sceneNode->getPosition();
75 }
76 
77 void DoorVisual::setOrientation(const Ogre::Quaternion& orientation) {
78  m_sceneNode->setOrientation(orientation);
79 }
80 
81 const Ogre::Quaternion& DoorVisual::getOrientation() const {
82  return m_sceneNode->getOrientation();
83 }
84 
85 void DoorVisual::setScalingFactor(double scalingFactor) {
86  m_sceneNode->setScale(scalingFactor, scalingFactor, scalingFactor);
87 }
88 
89 void DoorVisual::setVisible(bool visible) {
90  m_sceneNode->setVisible(visible, true);
91 }
92 
93 Ogre::SceneNode* DoorVisual::getParentSceneNode() {
94  return m_parentSceneNode;
95 }
96 
98 {
99  m_height = height;
100 }
101 
103 {
104  m_width = width;
105 }
106 
107 void DoorVisual::setOpeningAngle(double oangle, bool clockwise)
108 {
109  m_oangle = oangle;
111  double c;
112  double s;
113  if (clockwise) {
114  c = cos(-oangle);
115  s = sin(-oangle);
116  } else {
117  c = cos(oangle);
118  s = sin(oangle);
119  }
120  R_do = Ogre::Matrix3(c,-s,0,
121  s,c,0,
122  0,0,1);
123 }
124 
126 {
127  return R_do;
128 }
129 
130 void DoorVisual::update(float deltaTime) {}
131 
132 /*
133  * CylinderDoorVisual
134  */
135 //CylinderDoorVisual::CylinderDoorVisual(const DoorVisualDefaultArgs& args) : DoorVisual(args)
136 //{
137 // m_bodyShape = new rviz::Shape(rviz::Shape::Cylinder, args.sceneManager, m_sceneNode);
138 // m_headShape = new rviz::Shape(rviz::Shape::Sphere, args.sceneManager, m_sceneNode);
139 
140 // const float headDiameter = 0.4;
141 // const float totalHeight = getHeight();
142 // const float cylinderHeight = totalHeight - headDiameter;
143 
144 // m_bodyShape->setScale(Ogre::Vector3(headDiameter, headDiameter, cylinderHeight));
145 // m_headShape->setScale(Ogre::Vector3(headDiameter, headDiameter, headDiameter));
146 
147 // m_bodyShape->setPosition(Ogre::Vector3(0, 0, cylinderHeight / 2 - totalHeight / 2));
148 // m_headShape->setPosition(Ogre::Vector3(0, 0, totalHeight / 2 - headDiameter / 2 ));
149 //}
150 
151 //CylinderDoorVisual::~CylinderDoorVisual() {
152 // delete m_bodyShape;
153 // delete m_headShape;
154 //}
155 
156 //void CylinderDoorVisual::setColor(const Ogre::ColourValue& c) {
157 // m_bodyShape->setColor(c);
158 // m_headShape->setColor(c);
159 // m_color = c;
160 //}
161 
162 //Ogre::ColourValue& CylinderDoorVisual::getColor()
163 //{
164 // return m_color;
165 //}
166 
167 //double CylinderDoorVisual::getHeight() {
168 // return 1.75;
169 //}
170 
171 /*
172  * Bounding Box Visual
173  */
174 
175 BoundingBoxDoorVisual::BoundingBoxDoorVisual ( const DoorVisualDefaultArgs& args, double height, double width, double scalingFactor ) : DoorVisual(args)
176 {
177  m_width = width; m_height = height; m_scalingFactor = scalingFactor; m_lineWidth = 0.03;
178  m_wireframe = NULL;
179  m_baseframe = NULL;
180  m_thickness = 0.1;
182 }
183 
185  delete m_wireframe;
186  delete m_baseframe;
187  m_wireframe = NULL;
188  m_baseframe = NULL;
189 }
190 
191 void BoundingBoxDoorVisual::setColor(const Ogre::ColourValue& c) {
192  m_wireframe->setColor(c.r, c.g, c.b, c.a);
193  m_color = c;
194 }
195 
197 {
198  return m_color;
199 }
200 
202  return m_height;
203 }
204 
205 void BoundingBoxDoorVisual::setLineWidth(double lineWidth) {
206  m_wireframe->setLineWidth(lineWidth);
207 }
208 
210  delete m_wireframe;
212 
216 
217  double w = m_width, h = m_height;
218  Ogre::Vector3 bottomLeft(0, -w, 0), bottomRight(0, 0, 0), topLeft(0, -w, h), topRight(0, 0, h);
219  Ogre::Vector3 rear(m_thickness, 0, 0);
220 
221  // Front quad
222  m_wireframe->addPoint(bottomLeft); m_wireframe->addPoint(bottomRight);
223  m_wireframe->newLine(); m_wireframe->addPoint(bottomRight); m_wireframe->addPoint(topRight);
224  m_wireframe->newLine(); m_wireframe->addPoint(topRight); m_wireframe->addPoint(topLeft);
225  m_wireframe->newLine(); m_wireframe->addPoint(topLeft); m_wireframe->addPoint(bottomLeft);
226 
227  // Rear quad
228  m_wireframe->newLine(); m_wireframe->addPoint(bottomLeft + rear); m_wireframe->addPoint(bottomRight + rear);
229  m_wireframe->newLine(); m_wireframe->addPoint(bottomRight + rear); m_wireframe->addPoint(topRight + rear);
230  m_wireframe->newLine(); m_wireframe->addPoint(topRight + rear); m_wireframe->addPoint(topLeft + rear);
231  m_wireframe->newLine(); m_wireframe->addPoint(topLeft + rear); m_wireframe->addPoint(bottomLeft + rear);
232 
233  // Four connecting lines between front and rear
234  m_wireframe->newLine(); m_wireframe->addPoint(bottomLeft); m_wireframe->addPoint(bottomLeft + rear);
235  m_wireframe->newLine(); m_wireframe->addPoint(bottomRight); m_wireframe->addPoint(bottomRight + rear);
236  m_wireframe->newLine(); m_wireframe->addPoint(topRight); m_wireframe->addPoint(topRight + rear);
237  m_wireframe->newLine(); m_wireframe->addPoint(topLeft); m_wireframe->addPoint(topLeft + rear);
238 
239  m_wireframe->setPosition(Ogre::Vector3(0, 0, 0));
240 // Ogre::Quaternion orientation;
241 // orientation.FromRotationMatrix(R_do);
242 // m_wireframe->setOrientation(orientation);
243 }
244 
246  delete m_baseframe;
247 
251  m_baseframe->setPosition(Ogre::Vector3(0,0,0));
252  Ogre::Vector3 offset = Ogre::Vector3(0,-m_width,0);
253  double factor = 5.0 * M_PI/180.0;
254  double lines_per_angle = ceil(m_oangle / factor);
255  double angle_dec = 0;
256  m_baseframe->setNumLines(static_cast<int>(lines_per_angle));
257  int sign = m_clockwise == true ? 1 : -1;
258  for (int i=0; i < lines_per_angle; i++) {
259  Ogre::Vector3 start_v = offset;
260  Ogre::Vector3 end_v = offset;
261  double s_theta = sin(sign * angle_dec);
262  double c_theta = cos(sign * angle_dec);
263  Ogre::Matrix3 R_start = Ogre::Matrix3(c_theta,-s_theta,0,
264  s_theta,c_theta,0,
265  0, 0, 1);
266  angle_dec += factor;
267  s_theta = sin(sign * angle_dec);
268  c_theta = cos(sign * angle_dec);
269  Ogre::Matrix3 R_end = Ogre::Matrix3(c_theta,-s_theta,0,
270  s_theta,c_theta,0,
271  0, 0, 1);
272  start_v = R_start * start_v;
273  end_v = R_end * end_v;
274  m_baseframe->addPoint(start_v);
275  m_baseframe->addPoint(end_v);
276  m_baseframe->newLine();
277  }
278 }
279 
280 /*
281  * Mesh Person Visual
282  */
283 
284 //MeshDoorVisual::MeshDoorVisual(const DoorVisualDefaultArgs& args) : DoorVisual(args), entity_(NULL), m_animationState(NULL), m_walkingSpeed(1.0)
285 //{
286 // m_childSceneNode = m_sceneNode->createChildSceneNode();
287 // m_childSceneNode->setVisible(false);
288 
289 // std::string meshResource = "package://" ROS_PACKAGE_NAME "/media/animated_walking_man.mesh";
290 
291 // /// This is required to load referenced skeletons from package:// path
292 // fs::path model_path(meshResource);
293 // fs::path parent_path(model_path.parent_path());
294 
295 // Ogre::ResourceLoadingListener *newListener = new RosPackagePathResourceLoadingListener(parent_path),
296 // *oldListener = Ogre::ResourceGroupManager::getSingleton().getLoadingListener();
297 
298 // Ogre::ResourceGroupManager::getSingleton().setLoadingListener(newListener);
299 // bool loadFailed = rviz::loadMeshFromResource(meshResource).isNull();
300 // Ogre::ResourceGroupManager::getSingleton().setLoadingListener(oldListener);
301 
302 // delete newListener;
303 
304 
305 // // Create scene entity
306 // static size_t count = 0;
307 // std::stringstream ss;
308 // ss << "mesh_person_visual" << count++;
309 // std::string id = ss.str();
310 
311 // entity_ = m_sceneManager->createEntity(id, meshResource);
312 // m_childSceneNode->attachObject(entity_);
313 
314 // // set up animation
315 // setAnimationState("");
316 
317 // // set up material
318 // ss << "Material";
319 // Ogre::MaterialPtr default_material = Ogre::MaterialManager::getSingleton().create( ss.str(), "rviz" );
320 // default_material->setReceiveShadows(false);
321 // default_material->getTechnique(0)->setLightingEnabled(true);
322 // default_material->getTechnique(0)->setAmbient( 0.5, 0.5, 0.5 );
323 // materials_.insert( default_material );
324 // entity_->setMaterial( default_material );
325 
326 // // set position
327 // Ogre::Quaternion quat1; quat1.FromAngleAxis(Ogre::Degree(90), Ogre::Vector3(0,1,0));
328 // Ogre::Quaternion quat2; quat2.FromAngleAxis(Ogre::Degree(90), Ogre::Vector3(0,0,1));
329 // m_childSceneNode->setOrientation(quat1 * quat2);
330 
331 // double scaleFactor = 0.243 * 1.75;
332 // m_childSceneNode->setScale(Ogre::Vector3(scaleFactor, scaleFactor, scaleFactor));
333 // m_childSceneNode->setPosition(Ogre::Vector3(0, 0, -1));
334 
335 // m_childSceneNode->setVisible(true);
336 //}
337 
338 //MeshDoorVisual::~MeshDoorVisual() {
339 // m_sceneManager->destroyEntity( entity_ );
340 
341 // // destroy all the materials we've created
342 // std::set<Ogre::MaterialPtr>::iterator it;
343 // for ( it = materials_.begin(); it!=materials_.end(); it++ )
344 // {
345 // Ogre::MaterialPtr material = *it;
346 // if (!material.isNull())
347 // {
348 // material->unload();
349 // Ogre::MaterialManager::getSingleton().remove(material->getName());
350 // }
351 // }
352 // materials_.clear();
353 
354 // m_sceneManager->destroySceneNode(m_childSceneNode->getName());
355 //}
356 
357 //void MeshDoorVisual::setColor(const Ogre::ColourValue& c) {
358 
359 // m_color = c;
360 
361 // Ogre::SceneBlendType blending;
362 // bool depth_write;
363 
364 // if ( c.a < 0.9998 )
365 // {
366 // blending = Ogre::SBT_TRANSPARENT_ALPHA;
367 // depth_write = false;
368 // }
369 // else
370 // {
371 // blending = Ogre::SBT_REPLACE;
372 // depth_write = true;
373 // }
374 
375 // std::set<Ogre::MaterialPtr>::iterator it;
376 // for( it = materials_.begin(); it != materials_.end(); it++ )
377 // {
378 // Ogre::Technique* technique = (*it)->getTechnique( 0 );
379 
380 // technique->setAmbient( c.r*0.5, c.g*0.5, c.b*0.5 );
381 // technique->setDiffuse( c.r, c.g, c.b, c.a );
382 // technique->setSceneBlending( blending );
383 // technique->setDepthWriteEnabled( depth_write );
384 // technique->setLightingEnabled( true );
385 // }
386 //}
387 
388 //Ogre::ColourValue& MeshDoorVisual::getColor()
389 //{
390 // return m_color;
391 //}
392 
393 //void MeshDoorVisual::setAnimationState(const std::string& nameOfAnimationState) {
394 // Ogre::AnimationStateSet *animationStates = entity_->getAllAnimationStates();
395 // if(animationStates != NULL)
396 // {
397 // Ogre::AnimationStateIterator animationsIterator = animationStates->getAnimationStateIterator();
398 // while (animationsIterator.hasMoreElements())
399 // {
400 // Ogre::AnimationState *animationState = animationsIterator.getNext();
401 // if(animationState->getAnimationName() == nameOfAnimationState || nameOfAnimationState.empty()) {
402 // animationState->setLoop(true);
403 // animationState->setEnabled(true);
404 // m_animationState = animationState;
405 // return;
406 // }
407 // }
408 
409 // // Not found. Set first animation state then.
410 // ROS_WARN_STREAM_ONCE("Person mesh animation state " << nameOfAnimationState << " does not exist in mesh!");
411 // setAnimationState("");
412 // }
413 //}
414 
415 //void MeshDoorVisual::setWalkingSpeed(float walkingSpeed) {
416 // m_walkingSpeed = walkingSpeed;
417 //}
418 
419 
420 //void MeshDoorVisual::update(float deltaTime) {
421 // if(m_animationState) {
422 // m_animationState->addTime(0.7 * deltaTime * m_walkingSpeed);
423 // }
424 //}
425 
426 
427 } // end of namespace spencer_tracking_rviz_plugin
#define NULL
Ogre::SceneManager * m_sceneManager
Definition: DoorVisual.h:77
virtual void setScalingFactor(double scalingFactor)
Definition: DoorVisual.cpp:85
virtual void setOpeningAngle(double oangle, bool clockwise)
Definition: DoorVisual.cpp:107
void addPoint(const Ogre::Vector3 &point)
Ogre::SceneNode * m_parentSceneNode
Definition: DoorVisual.h:78
XmlRpcServer s
void setVisible(bool visible)
Definition: DoorVisual.cpp:89
virtual Ogre::Matrix3 getRotationMat()
Definition: DoorVisual.cpp:125
virtual void setHeight(double height)
Definition: DoorVisual.cpp:97
DoorVisual(const DoorVisualDefaultArgs &args)
Definition: DoorVisual.cpp:52
virtual void setWidth(double width)
Definition: DoorVisual.cpp:102
virtual void update(float deltaTime)
Definition: DoorVisual.cpp:130
const Ogre::Vector3 & getPosition() const
Definition: DoorVisual.cpp:73
virtual void setPosition(const Ogre::Vector3 &position)
rviz::BillboardLine * m_baseframe
Definition: DoorVisual.h:110
virtual void setColor(float r, float g, float b, float a)
Ogre::SceneNode * m_sceneNode
Definition: DoorVisual.h:78
rviz::BillboardLine * m_wireframe
Definition: DoorVisual.h:109
virtual void setColor(const Ogre::ColourValue &c)
Definition: DoorVisual.cpp:191
virtual void setLineWidth(double lineWidth)
Definition: DoorVisual.cpp:205
void setNumLines(uint32_t num)
void setMaxPointsPerLine(uint32_t max)
TFSIMD_FORCE_INLINE const tfScalar & w() const
void setPosition(const Ogre::Vector3 &position)
Definition: DoorVisual.cpp:69
const Ogre::Quaternion & getOrientation() const
Definition: DoorVisual.cpp:81
Ogre::ColourValue m_color
Definition: DoorVisual.h:79
void setOrientation(const Ogre::Quaternion &orientation)
Definition: DoorVisual.cpp:77
Ogre::SceneNode * getParentSceneNode()
Definition: DoorVisual.cpp:93
BoundingBoxDoorVisual(const DoorVisualDefaultArgs &args, double height=1.75, double width=0.6, double scalingFactor=1.0)
Definition: DoorVisual.cpp:175
virtual Ogre::ColourValue & getColor()
Definition: DoorVisual.cpp:196
void setLineWidth(float width)
Base class for all person visualization types.
Definition: DoorVisual.h:40


tuw_object_rviz
Author(s): Florian Beck
autogenerated on Mon Jun 10 2019 15:40:17