TrafficConeVisual.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 }
61 
63  m_sceneManager->destroySceneNode(m_sceneNode->getName());
64 };
65 
66 void TrafficConeVisual::setPosition(const Ogre::Vector3& position) {
67  m_sceneNode->setPosition(position);
68 }
69 
70 const Ogre::Vector3& TrafficConeVisual::getPosition() const {
71  return m_sceneNode->getPosition();
72 }
73 
74 void TrafficConeVisual::setOrientation(const Ogre::Quaternion& orientation) {
75  m_sceneNode->setOrientation(orientation);
76 }
77 
78 const Ogre::Quaternion& TrafficConeVisual::getOrientation() const {
79  return m_sceneNode->getOrientation();
80 }
81 
82 void TrafficConeVisual::setScalingFactor(double scalingFactor) {
83  m_sceneNode->setScale(scalingFactor, scalingFactor, scalingFactor);
84 }
85 
86 void TrafficConeVisual::setVisible(bool visible) {
87  m_sceneNode->setVisible(visible, true);
88 }
89 
91  return m_parentSceneNode;
92 }
93 
95 {
96  m_height = height;
97 }
98 
99 void TrafficConeVisual::setRadius(double radius)
100 {
101  m_radius = radius;
102 }
103 
104 void TrafficConeVisual::update(float deltaTime) {}
105 
106 /*
107  * CylinderTrafficConeVisual
108  */
109 //CylinderTrafficConeVisual::CylinderTrafficConeVisual(const TrafficConeVisualDefaultArgs& args) : TrafficConeVisual(args)
110 //{
111 // m_bodyShape = new rviz::Shape(rviz::Shape::Cylinder, args.sceneManager, m_sceneNode);
112 // m_headShape = new rviz::Shape(rviz::Shape::Sphere, args.sceneManager, m_sceneNode);
113 
114 // const float headDiameter = 0.4;
115 // const float totalHeight = getHeight();
116 // const float cylinderHeight = totalHeight - headDiameter;
117 
118 // m_bodyShape->setScale(Ogre::Vector3(headDiameter, headDiameter, cylinderHeight));
119 // m_headShape->setScale(Ogre::Vector3(headDiameter, headDiameter, headDiameter));
120 
121 // m_bodyShape->setPosition(Ogre::Vector3(0, 0, cylinderHeight / 2 - totalHeight / 2));
122 // m_headShape->setPosition(Ogre::Vector3(0, 0, totalHeight / 2 - headDiameter / 2 ));
123 //}
124 
125 //CylinderTrafficConeVisual::~CylinderTrafficConeVisual() {
126 // delete m_bodyShape;
127 // delete m_headShape;
128 //}
129 
130 //void CylinderTrafficConeVisual::setColor(const Ogre::ColourValue& c) {
131 // m_bodyShape->setColor(c);
132 // m_headShape->setColor(c);
133 // m_color = c;
134 //}
135 
136 //Ogre::ColourValue& CylinderTrafficConeVisual::getColor()
137 //{
138 // return m_color;
139 //}
140 
141 //double CylinderTrafficConeVisual::getHeight() {
142 // return 1.75;
143 //}
144 
145 /*
146  * Bounding Box Visual
147  */
148 
150 {
151  m_height = height;
152  m_radius = radius;
154 
155  m_bodyShape->setScale(Ogre::Vector3(radius,height,radius));
156  m_bodyShape->setPosition(Ogre::Vector3(0,0,0));
157  m_bodyShape->setColor(1.0,1.0,0.0,1.0);
158 }
159 
161  delete m_bodyShape;
162 }
163 
164 void TrafficConeVisualImpl::setColor(const Ogre::ColourValue& c) {
165  m_bodyShape->setColor(c.r, c.g, c.b, c.a);
166  m_color = c;
167 }
168 
170 {
171  return m_color;
172 }
173 
175  return m_height;
176 }
177 
179 {
181  m_height = height;
182  m_bodyShape->setScale(Ogre::Vector3(m_radius,height,m_radius));
183 }
184 
186 {
188  m_radius = radius;
189  m_bodyShape->setScale(Ogre::Vector3(radius,m_height,radius));
190 }
191 
192 void TrafficConeVisualImpl::update(float deltaTime)
193 {
194  //TrafficConeVisual::update(deltaTime);
195  //m_bodyShape->setScale(Ogre::Vector3());
196 }
197 
198 //void TrafficConeVisualImpl::generateWireframe() {
199 // delete m_wireframe;
200 // m_wireframe = new rviz::BillboardLine(m_sceneManager, m_sceneNode);
201 
202 // m_wireframe->setLineWidth(m_lineWidth);
203 // m_wireframe->setMaxPointsPerLine(2);
204 // m_wireframe->setNumLines(12);
205 
206 // double w = m_width, h = m_height;
207 // Ogre::Vector3 bottomLeft(0, -w, 0), bottomRight(0, 0, 0), topLeft(0, -w, h), topRight(0, 0, h);
208 // Ogre::Vector3 rear(m_thickness, 0, 0);
209 
210 // // Front quad
211 // m_wireframe->addPoint(bottomLeft); m_wireframe->addPoint(bottomRight);
212 // m_wireframe->newLine(); m_wireframe->addPoint(bottomRight); m_wireframe->addPoint(topRight);
213 // m_wireframe->newLine(); m_wireframe->addPoint(topRight); m_wireframe->addPoint(topLeft);
214 // m_wireframe->newLine(); m_wireframe->addPoint(topLeft); m_wireframe->addPoint(bottomLeft);
215 
216 // // Rear quad
217 // m_wireframe->newLine(); m_wireframe->addPoint(bottomLeft + rear); m_wireframe->addPoint(bottomRight + rear);
218 // m_wireframe->newLine(); m_wireframe->addPoint(bottomRight + rear); m_wireframe->addPoint(topRight + rear);
219 // m_wireframe->newLine(); m_wireframe->addPoint(topRight + rear); m_wireframe->addPoint(topLeft + rear);
220 // m_wireframe->newLine(); m_wireframe->addPoint(topLeft + rear); m_wireframe->addPoint(bottomLeft + rear);
221 
222 // // Four connecting lines between front and rear
223 // m_wireframe->newLine(); m_wireframe->addPoint(bottomLeft); m_wireframe->addPoint(bottomLeft + rear);
224 // m_wireframe->newLine(); m_wireframe->addPoint(bottomRight); m_wireframe->addPoint(bottomRight + rear);
225 // m_wireframe->newLine(); m_wireframe->addPoint(topRight); m_wireframe->addPoint(topRight + rear);
226 // m_wireframe->newLine(); m_wireframe->addPoint(topLeft); m_wireframe->addPoint(topLeft + rear);
227 
228 // m_wireframe->setPosition(Ogre::Vector3(0, 0, -h/2.0));
229 //}
230 
231 /*
232  * Mesh Person Visual
233  */
234 
235 //MeshTrafficConeVisual::MeshTrafficConeVisual(const TrafficConeVisualDefaultArgs& args) : TrafficConeVisual(args), entity_(NULL), m_animationState(NULL), m_walkingSpeed(1.0)
236 //{
237 // m_childSceneNode = m_sceneNode->createChildSceneNode();
238 // m_childSceneNode->setVisible(false);
239 
240 // std::string meshResource = "package://" ROS_PACKAGE_NAME "/media/animated_walking_man.mesh";
241 
242 // /// This is required to load referenced skeletons from package:// path
243 // fs::path model_path(meshResource);
244 // fs::path parent_path(model_path.parent_path());
245 
246 // Ogre::ResourceLoadingListener *newListener = new RosPackagePathResourceLoadingListener(parent_path),
247 // *oldListener = Ogre::ResourceGroupManager::getSingleton().getLoadingListener();
248 
249 // Ogre::ResourceGroupManager::getSingleton().setLoadingListener(newListener);
250 // bool loadFailed = rviz::loadMeshFromResource(meshResource).isNull();
251 // Ogre::ResourceGroupManager::getSingleton().setLoadingListener(oldListener);
252 
253 // delete newListener;
254 
255 
256 // // Create scene entity
257 // static size_t count = 0;
258 // std::stringstream ss;
259 // ss << "mesh_person_visual" << count++;
260 // std::string id = ss.str();
261 
262 // entity_ = m_sceneManager->createEntity(id, meshResource);
263 // m_childSceneNode->attachObject(entity_);
264 
265 // // set up animation
266 // setAnimationState("");
267 
268 // // set up material
269 // ss << "Material";
270 // Ogre::MaterialPtr default_material = Ogre::MaterialManager::getSingleton().create( ss.str(), "rviz" );
271 // default_material->setReceiveShadows(false);
272 // default_material->getTechnique(0)->setLightingEnabled(true);
273 // default_material->getTechnique(0)->setAmbient( 0.5, 0.5, 0.5 );
274 // materials_.insert( default_material );
275 // entity_->setMaterial( default_material );
276 
277 // // set position
278 // Ogre::Quaternion quat1; quat1.FromAngleAxis(Ogre::Degree(90), Ogre::Vector3(0,1,0));
279 // Ogre::Quaternion quat2; quat2.FromAngleAxis(Ogre::Degree(90), Ogre::Vector3(0,0,1));
280 // m_childSceneNode->setOrientation(quat1 * quat2);
281 
282 // double scaleFactor = 0.243 * 1.75;
283 // m_childSceneNode->setScale(Ogre::Vector3(scaleFactor, scaleFactor, scaleFactor));
284 // m_childSceneNode->setPosition(Ogre::Vector3(0, 0, -1));
285 
286 // m_childSceneNode->setVisible(true);
287 //}
288 
289 //MeshTrafficConeVisual::~MeshTrafficConeVisual() {
290 // m_sceneManager->destroyEntity( entity_ );
291 
292 // // destroy all the materials we've created
293 // std::set<Ogre::MaterialPtr>::iterator it;
294 // for ( it = materials_.begin(); it!=materials_.end(); it++ )
295 // {
296 // Ogre::MaterialPtr material = *it;
297 // if (!material.isNull())
298 // {
299 // material->unload();
300 // Ogre::MaterialManager::getSingleton().remove(material->getName());
301 // }
302 // }
303 // materials_.clear();
304 
305 // m_sceneManager->destroySceneNode(m_childSceneNode->getName());
306 //}
307 
308 //void MeshTrafficConeVisual::setColor(const Ogre::ColourValue& c) {
309 
310 // m_color = c;
311 
312 // Ogre::SceneBlendType blending;
313 // bool depth_write;
314 
315 // if ( c.a < 0.9998 )
316 // {
317 // blending = Ogre::SBT_TRANSPARENT_ALPHA;
318 // depth_write = false;
319 // }
320 // else
321 // {
322 // blending = Ogre::SBT_REPLACE;
323 // depth_write = true;
324 // }
325 
326 // std::set<Ogre::MaterialPtr>::iterator it;
327 // for( it = materials_.begin(); it != materials_.end(); it++ )
328 // {
329 // Ogre::Technique* technique = (*it)->getTechnique( 0 );
330 
331 // technique->setAmbient( c.r*0.5, c.g*0.5, c.b*0.5 );
332 // technique->setDiffuse( c.r, c.g, c.b, c.a );
333 // technique->setSceneBlending( blending );
334 // technique->setDepthWriteEnabled( depth_write );
335 // technique->setLightingEnabled( true );
336 // }
337 //}
338 
339 //Ogre::ColourValue& MeshTrafficConeVisual::getColor()
340 //{
341 // return m_color;
342 //}
343 
344 //void MeshTrafficConeVisual::setAnimationState(const std::string& nameOfAnimationState) {
345 // Ogre::AnimationStateSet *animationStates = entity_->getAllAnimationStates();
346 // if(animationStates != NULL)
347 // {
348 // Ogre::AnimationStateIterator animationsIterator = animationStates->getAnimationStateIterator();
349 // while (animationsIterator.hasMoreElements())
350 // {
351 // Ogre::AnimationState *animationState = animationsIterator.getNext();
352 // if(animationState->getAnimationName() == nameOfAnimationState || nameOfAnimationState.empty()) {
353 // animationState->setLoop(true);
354 // animationState->setEnabled(true);
355 // m_animationState = animationState;
356 // return;
357 // }
358 // }
359 
360 // // Not found. Set first animation state then.
361 // ROS_WARN_STREAM_ONCE("Person mesh animation state " << nameOfAnimationState << " does not exist in mesh!");
362 // setAnimationState("");
363 // }
364 //}
365 
366 //void MeshTrafficConeVisual::setWalkingSpeed(float walkingSpeed) {
367 // m_walkingSpeed = walkingSpeed;
368 //}
369 
370 
371 //void MeshTrafficConeVisual::update(float deltaTime) {
372 // if(m_animationState) {
373 // m_animationState->addTime(0.7 * deltaTime * m_walkingSpeed);
374 // }
375 //}
376 
377 
378 } // end of namespace spencer_tracking_rviz_plugin
Base class for all person visualization types.
virtual void update(float deltaTime)
virtual void setColor(const Ogre::ColourValue &c)
TrafficConeVisual(const TrafficConeVisualDefaultArgs &args)
virtual void setColor(float r, float g, float b, float a)
virtual void setPosition(const Ogre::Vector3 &position)
virtual void setScalingFactor(double scalingFactor)
virtual void setHeight(double height)
virtual Ogre::ColourValue & getColor()
virtual void update(float deltaTime)
void setPosition(const Ogre::Vector3 &position)
const Ogre::Vector3 & getPosition() const
void setOrientation(const Ogre::Quaternion &orientation)
virtual void setRadius(double radius)
TrafficConeVisualImpl(const TrafficConeVisualDefaultArgs &args, double height=1.75, double radius=0.6)
const Ogre::Quaternion & getOrientation() const
virtual void setScale(const Ogre::Vector3 &scale)


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