point_cloud.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "point_cloud.h"
31 #include <ros/assert.h>
32 
33 #include <OgreSceneManager.h>
34 #include <OgreSceneNode.h>
35 #include <OgreVector3.h>
36 #include <OgreQuaternion.h>
37 #include <OgreManualObject.h>
38 #include <OgreMaterialManager.h>
39 #include <OgreBillboardSet.h>
40 #include <OgreBillboard.h>
41 #include <OgreTexture.h>
42 #include <OgreTextureManager.h>
43 #include <OgreSharedPtr.h>
44 #include <OgreTechnique.h>
45 #include <OgreCamera.h>
46 
47 #include <sstream>
48 
51 
52 #define VERTEX_BUFFER_CAPACITY (36 * 1024 * 10)
53 
54 namespace rviz
55 {
56 
57 static float g_point_vertices[3] =
58 {
59  0.0f, 0.0f, 0.0f
60 };
61 
62 static float g_billboard_vertices[6*3] =
63 {
64  -0.5f, 0.5f, 0.0f,
65  -0.5f, -0.5f, 0.0f,
66  0.5f, 0.5f, 0.0f,
67  0.5f, 0.5f, 0.0f,
68  -0.5f, -0.5f, 0.0f,
69  0.5f, -0.5f, 0.0f,
70 };
71 
72 static float g_billboard_sphere_vertices[3*3] =
73 {
74  0.0f, 1.0f, 0.0f,
75  -0.866025404f, -0.5f, 0.0f,
76  0.866025404f, -0.5f, 0.0f,
77 };
78 
79 static float g_box_vertices[6*6*3] =
80 {
81  // front
82  -0.5f, 0.5f, -0.5f,
83  -0.5f, -0.5f, -0.5f,
84  0.5f, 0.5f, -0.5f,
85  0.5f, 0.5f, -0.5f,
86  -0.5f, -0.5f, -0.5f,
87  0.5f, -0.5f, -0.5f,
88 
89  // back
90  -0.5f, 0.5f, 0.5f,
91  0.5f, 0.5f, 0.5f,
92  -0.5f, -0.5f, 0.5f,
93  0.5f, 0.5f, 0.5f,
94  0.5f, -0.5f, 0.5f,
95  -0.5f, -0.5f, 0.5f,
96 
97  // right
98  0.5, 0.5, 0.5,
99  0.5, 0.5, -0.5,
100  0.5, -0.5, 0.5,
101  0.5, 0.5, -0.5,
102  0.5, -0.5, -0.5,
103  0.5, -0.5, 0.5,
104 
105  // left
106  -0.5, 0.5, 0.5,
107  -0.5, -0.5, 0.5,
108  -0.5, 0.5, -0.5,
109  -0.5, 0.5, -0.5,
110  -0.5, -0.5, 0.5,
111  -0.5, -0.5, -0.5,
112 
113  // top
114  -0.5, 0.5, -0.5,
115  0.5, 0.5, -0.5,
116  -0.5, 0.5, 0.5,
117  0.5, 0.5, -0.5,
118  0.5, 0.5, 0.5,
119  -0.5, 0.5, 0.5,
120 
121  // bottom
122  -0.5, -0.5, -0.5,
123  -0.5, -0.5, 0.5,
124  0.5, -0.5, -0.5,
125  0.5, -0.5, -0.5,
126  -0.5, -0.5, 0.5,
127  0.5, -0.5, 0.5,
128 };
129 
130 Ogre::String PointCloud::sm_Type = "PointCloud";
131 
133 : bounding_radius_( 0.0f )
134 , point_count_( 0 )
135 , common_direction_( Ogre::Vector3::NEGATIVE_UNIT_Z )
136 , common_up_vector_( Ogre::Vector3::UNIT_Y )
137 , color_by_index_(false)
138 , current_mode_supports_geometry_shader_(false)
139 {
140  std::stringstream ss;
141  static int count = 0;
142  ss << "PointCloudMaterial" << count++;
143  point_material_ = Ogre::MaterialManager::getSingleton().getByName("rviz/PointCloudPoint");
144  square_material_ = Ogre::MaterialManager::getSingleton().getByName("rviz/PointCloudSquare");
145  flat_square_material_ = Ogre::MaterialManager::getSingleton().getByName("rviz/PointCloudFlatSquare");
146  sphere_material_ = Ogre::MaterialManager::getSingleton().getByName("rviz/PointCloudSphere");
147  tile_material_ = Ogre::MaterialManager::getSingleton().getByName("rviz/PointCloudTile");
148  box_material_ = Ogre::MaterialManager::getSingleton().getByName("rviz/PointCloudBox");
149 
150  point_material_ = Ogre::MaterialPtr(point_material_)->clone(ss.str() + "Point");
151  square_material_ = Ogre::MaterialPtr(square_material_)->clone(ss.str() + "Square");
152  flat_square_material_ = Ogre::MaterialPtr(flat_square_material_)->clone(ss.str() + "FlatSquare");
153  sphere_material_ = Ogre::MaterialPtr(sphere_material_)->clone(ss.str() + "Sphere");
154  tile_material_ = Ogre::MaterialPtr(tile_material_)->clone(ss.str() + "Tiles");
155  box_material_ = Ogre::MaterialPtr(box_material_)->clone(ss.str() + "Box");
156 
157  point_material_->load();
158  square_material_->load();
159  flat_square_material_->load();
160  sphere_material_->load();
161  tile_material_->load();
162  box_material_->load();
163 
164  setAlpha( 1.0f );
166  setDimensions(0.01f, 0.01f, 0.01f);
167 
168  clear();
169 }
170 
171 static void removeMaterial(Ogre::MaterialPtr& material)
172 {
173  Ogre::ResourcePtr resource(material);
174  Ogre::MaterialManager::getSingleton().remove(resource);
175 }
176 
178 {
179  clear();
180 
181  point_material_->unload();
182  square_material_->unload();
183  flat_square_material_->unload();
184  sphere_material_->unload();
185  tile_material_->unload();
186  box_material_->unload();
187 
194 }
195 
196 const Ogre::AxisAlignedBox& PointCloud::getBoundingBox() const
197 {
198  return bounding_box_;
199 }
200 
202 {
203  return bounding_radius_;
204 }
205 
206 void PointCloud::getWorldTransforms(Ogre::Matrix4* xform) const
207 {
208  *xform = _getParentNodeFullTransform();
209 }
210 
212 {
213  point_count_ = 0;
214  bounding_box_.setNull();
215  bounding_radius_ = 0.0f;
216 
217  if (getParentSceneNode())
218  {
219  V_PointCloudRenderable::iterator it = renderables_.begin();
220  V_PointCloudRenderable::iterator end = renderables_.end();
221  for (; it != end; ++it)
222  {
223  getParentSceneNode()->detachObject(it->get());
224  }
225  getParentSceneNode()->needUpdate();
226  }
227 
228  renderables_.clear();
229 }
230 
232 {
233  if (point_count_ == 0)
234  {
235  return;
236  }
237 
238  V_Point points;
239  points.swap(points_);
240  uint32_t count = point_count_;
241 
242  clear();
243 
244  addPoints(&points.front(), count);
245 }
246 
248 {
249  color_by_index_ = set;
250  regenerateAll();
251 }
252 
253 void PointCloud::setHighlightColor( float r, float g, float b )
254 {
255  Ogre::Vector4 highlight( r, g, b, 0.0f );
256 
257  V_PointCloudRenderable::iterator it = renderables_.begin();
258  V_PointCloudRenderable::iterator end = renderables_.end();
259  for (; it != end; ++it)
260  {
261  (*it)->setCustomParameter(HIGHLIGHT_PARAMETER, highlight);
262  }
263 }
264 
266 {
267  render_mode_ = mode;
268 
269  if (mode == RM_POINTS)
270  {
271  current_material_ = Ogre::MaterialPtr(point_material_);
272  }
273  else if (mode == RM_SQUARES)
274  {
275  current_material_ = Ogre::MaterialPtr(square_material_);
276  }
277  else if (mode == RM_FLAT_SQUARES)
278  {
279  current_material_ = Ogre::MaterialPtr(flat_square_material_);
280  }
281  else if (mode == RM_SPHERES)
282  {
283  current_material_ = Ogre::MaterialPtr(sphere_material_);
284  }
285  else if (mode == RM_TILES)
286  {
287  current_material_ = Ogre::MaterialPtr(tile_material_);
288  }
289  else if (mode == RM_BOXES)
290  {
291  current_material_ = Ogre::MaterialPtr(box_material_);
292  }
293 
294  current_material_->load();
295 
296  //ROS_INFO("Best technique [%s] [gp=%s]", current_material_->getBestTechnique()->getName().c_str(), current_material_->getBestTechnique()->getPass(0)->getGeometryProgramName().c_str());
297 
298  bool geom_support_changed = false;
299  Ogre::Technique* best = current_material_->getBestTechnique();
300  if (best)
301  {
302  if (current_material_->getBestTechnique()->getName() == "gp")
303  {
305  {
306  geom_support_changed = true;
307  }
308 
310 
311  //ROS_INFO("Using geometry shader");
312  }
313  else
314  {
316  {
317  geom_support_changed = true;
318  }
319 
321  }
322  }
323  else
324  {
325  geom_support_changed = true;
327 
328  ROS_ERROR("No techniques available for material [%s]", current_material_->getName().c_str());
329  }
330 
331  if (geom_support_changed)
332  {
333  renderables_.clear();
334  }
335 
336  V_PointCloudRenderable::iterator it = renderables_.begin();
337  V_PointCloudRenderable::iterator end = renderables_.end();
338  for (; it != end; ++it)
339  {
340  (*it)->setMaterial(current_material_->getName());
341  }
342 
343  regenerateAll();
344 }
345 
346 void PointCloud::setDimensions(float width, float height, float depth)
347 {
348  width_ = width;
349  height_ = height;
350  depth_ = depth;
351 
352  Ogre::Vector4 size(width_, height_, depth_, 0.0f);
353 
354  V_PointCloudRenderable::iterator it = renderables_.begin();
355  V_PointCloudRenderable::iterator end = renderables_.end();
356  for (; it != end; ++it)
357  {
358  (*it)->setCustomParameter(SIZE_PARAMETER, size);
359  }
360 }
361 
362 void PointCloud::setAutoSize(bool auto_size)
363 {
364  V_PointCloudRenderable::iterator it = renderables_.begin();
365  V_PointCloudRenderable::iterator end = renderables_.end();
366  for (; it != end; ++it)
367  {
368  (*it)->setCustomParameter(AUTO_SIZE_PARAMETER, Ogre::Vector4(auto_size));
369  }
370 }
371 
372 void PointCloud::setCommonDirection(const Ogre::Vector3& vec)
373 {
374  common_direction_ = vec;
375 
376  V_PointCloudRenderable::iterator it = renderables_.begin();
377  V_PointCloudRenderable::iterator end = renderables_.end();
378  for (; it != end; ++it)
379  {
380  (*it)->setCustomParameter(NORMAL_PARAMETER, Ogre::Vector4(vec));
381  }
382 }
383 
384 void PointCloud::setCommonUpVector(const Ogre::Vector3& vec)
385 {
386  common_up_vector_ = vec;
387 
388  V_PointCloudRenderable::iterator it = renderables_.begin();
389  V_PointCloudRenderable::iterator end = renderables_.end();
390  for (; it != end; ++it)
391  {
392  (*it)->setCustomParameter(UP_PARAMETER, Ogre::Vector4(vec));
393  }
394 }
395 
396 void setAlphaBlending(const Ogre::MaterialPtr& mat)
397 {
398  if (mat->getBestTechnique())
399  {
400  mat->getBestTechnique()->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
401  mat->getBestTechnique()->setDepthWriteEnabled( false );
402  }
403 }
404 
405 void setReplace(const Ogre::MaterialPtr& mat)
406 {
407  if (mat->getBestTechnique())
408  {
409  mat->getBestTechnique()->setSceneBlending( Ogre::SBT_REPLACE );
410  mat->getBestTechnique()->setDepthWriteEnabled( true );
411  }
412 }
413 
414 void PointCloud::setAlpha(float alpha, bool per_point_alpha)
415 {
416  alpha_ = alpha;
417 
418  if ( alpha < 0.9998 || per_point_alpha )
419  {
426  }
427  else
428  {
435  }
436 
437  Ogre::Vector4 alpha4(alpha_, alpha_, alpha_, alpha_);
438  V_PointCloudRenderable::iterator it = renderables_.begin();
439  V_PointCloudRenderable::iterator end = renderables_.end();
440  for (; it != end; ++it)
441  {
442  (*it)->setCustomParameter(ALPHA_PARAMETER, alpha4);
443  }
444 }
445 
446 void PointCloud::addPoints(Point* points, uint32_t num_points)
447 {
448  if (num_points == 0)
449  {
450  return;
451  }
452  Ogre::Root* root = Ogre::Root::getSingletonPtr();
453 
454  if ( points_.size() < point_count_ + num_points )
455  {
456  points_.resize( point_count_ + num_points );
457  }
458 
459  Point* begin = &points_.front() + point_count_;
460  memcpy( begin, points, sizeof( Point ) * num_points );
461 
462  uint32_t vpp = getVerticesPerPoint();
463  Ogre::RenderOperation::OperationType op_type;
465  {
466  op_type = Ogre::RenderOperation::OT_POINT_LIST;
467  }
468  else
469  {
470  if (render_mode_ == RM_POINTS)
471  {
472  op_type = Ogre::RenderOperation::OT_POINT_LIST;
473  }
474  else
475  {
476  op_type = Ogre::RenderOperation::OT_TRIANGLE_LIST;
477  }
478  }
479 
480  float* vertices = 0;
482  {
483  vertices = g_point_vertices;
484  }
485  else
486  {
487  if (render_mode_ == RM_POINTS)
488  {
489  vertices = g_point_vertices;
490  }
491  else if (render_mode_ == RM_SQUARES)
492  {
493  vertices = g_billboard_vertices;
494  }
495  else if (render_mode_ == RM_FLAT_SQUARES)
496  {
497  vertices = g_billboard_vertices;
498  }
499  else if (render_mode_ == RM_SPHERES)
500  {
501  vertices = g_billboard_sphere_vertices;
502  }
503  else if (render_mode_ == RM_TILES)
504  {
505  vertices = g_billboard_vertices;
506  }
507  else if (render_mode_ == RM_BOXES)
508  {
509  vertices = g_box_vertices;
510  }
511  }
512 
514  Ogre::HardwareVertexBufferSharedPtr vbuf;
515  void* vdata = 0;
516  Ogre::RenderOperation* op = 0;
517  float* fptr = 0;
518 
519  Ogre::AxisAlignedBox aabb;
520  aabb.setNull();
521  uint32_t current_vertex_count = 0;
522  bounding_radius_ = 0.0f;
523  uint32_t vertex_size = 0;
524  uint32_t buffer_size = 0;
525  for (uint32_t current_point = 0; current_point < num_points; ++current_point)
526  {
527  // if we didn't create a renderable yet,
528  // or we've reached the vertex limit for the current renderable,
529  // create a new one.
530  while (!rend || current_vertex_count >= buffer_size)
531  {
532  if (rend)
533  {
534  ROS_ASSERT(current_vertex_count == buffer_size);
535 
536  op->vertexData->vertexCount = rend->getBuffer()->getNumVertices() - op->vertexData->vertexStart;
537  ROS_ASSERT(op->vertexData->vertexCount + op->vertexData->vertexStart <= rend->getBuffer()->getNumVertices());
538  vbuf->unlock();
539  rend->setBoundingBox(aabb);
540  bounding_box_.merge(aabb);
541  }
542 
543  buffer_size = std::min<int>( VERTEX_BUFFER_CAPACITY, (num_points - current_point)*vpp );
544 
545  rend = createRenderable( buffer_size );
546  vbuf = rend->getBuffer();
547  vdata = vbuf->lock(Ogre::HardwareBuffer::HBL_NO_OVERWRITE);
548 
549  op = rend->getRenderOperation();
550  op->operationType = op_type;
551  current_vertex_count = 0;
552 
553  vertex_size = op->vertexData->vertexDeclaration->getVertexSize(0);
554  fptr = (float*)((uint8_t*)vdata);
555 
556  aabb.setNull();
557  }
558 
559  const Point& p = points[current_point];
560 
561  uint32_t color;
562 
563  if (color_by_index_)
564  {
565  // convert to ColourValue, so we can then convert to the rendersystem-specific color type
566  color = (current_point + point_count_ + 1);
567  Ogre::ColourValue c;
568  c.a = 1.0f;
569  c.r = ((color >> 16) & 0xff) / 255.0f;
570  c.g = ((color >> 8) & 0xff) / 255.0f;
571  c.b = (color & 0xff) / 255.0f;
572  root->convertColourValue(c, &color);
573  }
574  else
575  {
576  root->convertColourValue( p.color, &color );
577  }
578 
579  aabb.merge(p.position);
580  bounding_radius_ = std::max( bounding_radius_, p.position.squaredLength() );
581 
582  float x = p.position.x;
583  float y = p.position.y;
584  float z = p.position.z;
585 
586  for (uint32_t j = 0; j < vpp; ++j, ++current_vertex_count)
587  {
588  *fptr++ = x;
589  *fptr++ = y;
590  *fptr++ = z;
591 
593  {
594  *fptr++ = vertices[(j*3)];
595  *fptr++ = vertices[(j*3) + 1];
596  *fptr++ = vertices[(j*3) + 2];
597  }
598 
599  uint32_t* iptr = (uint32_t*)fptr;
600  *iptr = color;
601  ++fptr;
602 
603  ROS_ASSERT((uint8_t*)fptr <= (uint8_t*)vdata + rend->getBuffer()->getNumVertices() * vertex_size);
604  }
605  }
606 
607  op->vertexData->vertexCount = current_vertex_count - op->vertexData->vertexStart;
608  rend->setBoundingBox(aabb);
609  bounding_box_.merge(aabb);
610  ROS_ASSERT(op->vertexData->vertexCount + op->vertexData->vertexStart <= rend->getBuffer()->getNumVertices());
611 
612  vbuf->unlock();
613 
614  point_count_ += num_points;
615 
617 
618  if (getParentSceneNode())
619  {
620  getParentSceneNode()->needUpdate();
621  }
622 }
623 
624 void PointCloud::popPoints(uint32_t num_points)
625 {
626  uint32_t vpp = getVerticesPerPoint();
627 
628  ROS_ASSERT(num_points <= point_count_);
629  points_.erase(points_.begin(), points_.begin() + num_points);
630 
631  point_count_ -= num_points;
632 
633  // Now clear out popped points
634  uint32_t popped_count = 0;
635  while (popped_count < num_points * vpp)
636  {
637  PointCloudRenderablePtr rend = renderables_.front();
638  Ogre::RenderOperation* op = rend->getRenderOperation();
639 
640  uint32_t popped = std::min((size_t)(num_points * vpp - popped_count), op->vertexData->vertexCount);
641  op->vertexData->vertexStart += popped;
642  op->vertexData->vertexCount -= popped;
643 
644  popped_count += popped;
645 
646  if (op->vertexData->vertexCount == 0)
647  {
648  renderables_.erase(renderables_.begin(), renderables_.begin() + 1);
649 
650  op->vertexData->vertexStart = 0;
651  renderables_.push_back(rend);
652  }
653  }
654  ROS_ASSERT(popped_count == num_points * vpp);
655 
656  // reset bounds
657  bounding_box_.setNull();
658  bounding_radius_ = 0.0f;
659  for (uint32_t i = 0; i < point_count_; ++i)
660  {
661  Point& p = points_[i];
662  bounding_box_.merge(p.position);
663  bounding_radius_ = std::max(bounding_radius_, p.position.squaredLength());
664  }
665 
667 
668  if (getParentSceneNode())
669  {
670  getParentSceneNode()->needUpdate();
671  }
672 }
673 
675 {
676  while (!renderables_.empty())
677  {
679  Ogre::RenderOperation* op = rend->getRenderOperation();
680  if (op->vertexData->vertexCount == 0)
681  {
682  renderables_.pop_back();
683  }
684  else
685  {
686  break;
687  }
688  }
689 }
690 
691 void PointCloud::_notifyCurrentCamera(Ogre::Camera* camera)
692 {
693  MovableObject::_notifyCurrentCamera( camera );
694 }
695 
696 void PointCloud::_updateRenderQueue(Ogre::RenderQueue* queue)
697 {
698  V_PointCloudRenderable::iterator it = renderables_.begin();
699  V_PointCloudRenderable::iterator end = renderables_.end();
700  for (; it != end; ++it)
701  {
702  queue->addRenderable((*it).get());
703  }
704 }
705 
706 void PointCloud::_notifyAttached(Ogre::Node *parent, bool isTagPoint)
707 {
708  MovableObject::_notifyAttached(parent, isTagPoint);
709 }
710 
712 {
714  {
715  return 1;
716  }
717 
718  if (render_mode_ == RM_POINTS)
719  {
720  return 1;
721  }
722 
723  if (render_mode_ == RM_SQUARES)
724  {
725  return 6;
726  }
727 
729  {
730  return 6;
731  }
732 
733  if (render_mode_ == RM_TILES)
734  {
735  return 6;
736  }
737 
738  if (render_mode_ == RM_SPHERES)
739  {
740  return 3;
741  }
742 
743  if (render_mode_ == RM_BOXES)
744  {
745  return 36;
746  }
747 
748  return 1;
749 }
750 
751 void PointCloud::setPickColor(const Ogre::ColourValue& color)
752 {
753  pick_color_ = color;
754  Ogre::Vector4 pick_col(pick_color_.r, pick_color_.g, pick_color_.b, pick_color_.a);
755 
756  V_PointCloudRenderable::iterator it = renderables_.begin();
757  V_PointCloudRenderable::iterator end = renderables_.end();
758  for (; it != end; ++it)
759  {
760  (*it)->setCustomParameter(PICK_COLOR_PARAMETER, pick_col);
761  }
762  getUserObjectBindings().setUserAny( "pick_handle", Ogre::Any( colorToHandle( color )));
763 }
764 
766 {
768  rend->setMaterial(current_material_->getName());
769  Ogre::Vector4 size(width_, height_, depth_, 0.0f);
770  Ogre::Vector4 alpha(alpha_, 0.0f, 0.0f, 0.0f);
771  Ogre::Vector4 highlight(0.0f, 0.0f, 0.0f, 0.0f);
772  Ogre::Vector4 pick_col(pick_color_.r, pick_color_.g, pick_color_.b, pick_color_.a);
773  rend->setCustomParameter(SIZE_PARAMETER, size);
774  rend->setCustomParameter(ALPHA_PARAMETER, alpha);
775  rend->setCustomParameter(HIGHLIGHT_PARAMETER, highlight);
776  rend->setCustomParameter(PICK_COLOR_PARAMETER, pick_col);
777  rend->setCustomParameter(NORMAL_PARAMETER, Ogre::Vector4(common_direction_));
778  rend->setCustomParameter(UP_PARAMETER, Ogre::Vector4(common_up_vector_));
779  if (getParentSceneNode())
780  {
781  getParentSceneNode()->attachObject(rend.get());
782  }
783  renderables_.push_back(rend);
784 
785  return rend;
786 }
787 
788 #if (OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 6)
789 void PointCloud::visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables)
790 {
791 
792 }
793 #endif
794 
795 
799 
800 PointCloudRenderable::PointCloudRenderable(PointCloud* parent, int num_points, bool use_tex_coords)
801 : parent_(parent)
802 {
803  // Initialize render operation
804  mRenderOp.operationType = Ogre::RenderOperation::OT_POINT_LIST;
805  mRenderOp.useIndexes = false;
806  mRenderOp.vertexData = new Ogre::VertexData;
807  mRenderOp.vertexData->vertexStart = 0;
808  mRenderOp.vertexData->vertexCount = 0;
809 
810  Ogre::VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
811  size_t offset = 0;
812 
813  decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
814  offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
815 
816  if (use_tex_coords)
817  {
818  decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_TEXTURE_COORDINATES, 0);
819  offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
820  }
821 
822  decl->addElement(0, offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
823 
824  Ogre::HardwareVertexBufferSharedPtr vbuf =
825  Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
826  mRenderOp.vertexData->vertexDeclaration->getVertexSize(0),
827  num_points,
828  Ogre::HardwareBuffer::HBU_DYNAMIC);
829 
830  // Bind buffer
831  mRenderOp.vertexData->vertexBufferBinding->setBinding(0, vbuf);
832 }
833 
835 {
836  delete mRenderOp.vertexData;
837  delete mRenderOp.indexData;
838 }
839 
840 Ogre::HardwareVertexBufferSharedPtr PointCloudRenderable::getBuffer()
841 {
842  return mRenderOp.vertexData->vertexBufferBinding->getBuffer(0);
843 }
844 
846 {
847  SimpleRenderable::_notifyCurrentCamera( camera );
848 }
849 
851 {
852  return Ogre::Math::Sqrt(std::max(mBox.getMaximum().squaredLength(), mBox.getMinimum().squaredLength()));
853 }
854 
855 Ogre::Real PointCloudRenderable::getSquaredViewDepth(const Ogre::Camera* cam) const
856 {
857  Ogre::Vector3 vMin, vMax, vMid, vDist;
858  vMin = mBox.getMinimum();
859  vMax = mBox.getMaximum();
860  vMid = ((vMax - vMin) * 0.5) + vMin;
861  vDist = cam->getDerivedPosition() - vMid;
862 
863  return vDist.squaredLength();
864 }
865 
866 void PointCloudRenderable::getWorldTransforms(Ogre::Matrix4* xform) const
867 {
868  parent_->getWorldTransforms(xform);
869 }
870 
871 const Ogre::LightList& PointCloudRenderable::getLights() const
872 {
873  return parent_->queryLights();
874 }
875 
876 } // namespace rviz
#define ALPHA_PARAMETER
void addPoints(Point *points, uint32_t num_points)
Add points to this point cloud.
float width_
width
Definition: point_cloud.h:211
virtual const Ogre::LightList & getLights() const
Ogre::MaterialPtr current_material_
Definition: point_cloud.h:223
root
Ogre::MaterialPtr sphere_material_
Definition: point_cloud.h:220
std::vector< Point > V_Point
Definition: point_cloud.h:206
void setAlphaBlending(const Ogre::MaterialPtr &mat)
void setRenderMode(RenderMode mode)
Set what type of rendering primitives should be used, currently points, billboards and boxes are supp...
f
#define AUTO_SIZE_PARAMETER
uint32_t point_count_
The number of points currently in points_.
Definition: point_cloud.h:208
void setPickColor(const Ogre::ColourValue &color)
virtual void _updateRenderQueue(Ogre::RenderQueue *queue)
Ogre::HardwareVertexBufferSharedPtr getBuffer()
#define NORMAL_PARAMETER
static float g_box_vertices[6 *6 *3]
Definition: point_cloud.cpp:79
void setColorByIndex(bool set)
virtual void _notifyCurrentCamera(Ogre::Camera *camera)
Ogre::AxisAlignedBox bounding_box_
The bounding box of this point cloud.
Definition: point_cloud.h:203
Ogre::MaterialPtr flat_square_material_
Definition: point_cloud.h:219
void popPoints(uint32_t num_points)
Remove a number of points from this point cloud.
float depth_
depth
Definition: point_cloud.h:213
V_Point points_
The list of points we&#39;re displaying. Allocates to a high-water-mark.
Definition: point_cloud.h:207
TFSIMD_FORCE_INLINE const tfScalar & y() const
Ogre::MaterialPtr square_material_
Definition: point_cloud.h:218
Ogre::Vector3 common_direction_
See Ogre::BillboardSet::setCommonDirection.
Definition: point_cloud.h:214
virtual void _notifyCurrentCamera(Ogre::Camera *camera)
#define SIZE_PARAMETER
#define VERTEX_BUFFER_CAPACITY
Definition: point_cloud.cpp:52
void setCommonUpVector(const Ogre::Vector3 &vec)
See Ogre::BillboardSet::setCommonUpVector.
bool current_mode_supports_geometry_shader_
Definition: point_cloud.h:230
virtual void getWorldTransforms(Ogre::Matrix4 *xform) const
Ogre::MaterialPtr tile_material_
Definition: point_cloud.h:221
#define HIGHLIGHT_PARAMETER
TFSIMD_FORCE_INLINE Vector3()
Representation of a point, with x/y/z position and r/g/b color.
Definition: point_cloud.h:123
void setDimensions(float width, float height, float depth)
Set the dimensions of the billboards used to render each point.
virtual void _notifyAttached(Ogre::Node *parent, bool isTagPoint=false)
Ogre::Vector3 position
Definition: point_cloud.h:130
virtual float getBoundingRadius() const
virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera *cam) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
RenderMode render_mode_
Definition: point_cloud.h:210
void setAlpha(float alpha, bool per_point_alpha=false)
void clear()
Clear all the points.
Ogre::MaterialPtr box_material_
Definition: point_cloud.h:222
virtual Ogre::Real getBoundingRadius(void) const
#define PICK_COLOR_PARAMETER
float bounding_radius_
The bounding radius of this point cloud.
Definition: point_cloud.h:204
TFSIMD_FORCE_INLINE const tfScalar & z() const
void setReplace(const Ogre::MaterialPtr &mat)
static void removeMaterial(Ogre::MaterialPtr &material)
uint32_t colorToHandle(Ogre::PixelFormat fmt, uint32_t col)
Definition: forwards.h:68
static float g_billboard_vertices[6 *3]
Definition: point_cloud.cpp:62
Ogre::ColourValue color
Definition: point_cloud.h:131
Ogre::ColourValue pick_color_
Definition: point_cloud.h:231
uint32_t getVerticesPerPoint()
void setHighlightColor(float r, float g, float b)
A visual representation of a set of points.
Definition: point_cloud.h:98
V_PointCloudRenderable renderables_
Definition: point_cloud.h:228
PointCloudRenderable(PointCloud *parent, int num_points, bool use_tex_coords)
Ogre::MaterialPtr point_material_
Definition: point_cloud.h:217
float height_
height
Definition: point_cloud.h:212
void setCommonDirection(const Ogre::Vector3 &vec)
See Ogre::BillboardSet::setCommonDirection.
Ogre::Vector3 common_up_vector_
See Ogre::BillboardSet::setCommonUpVector.
Definition: point_cloud.h:215
static float g_point_vertices[3]
Definition: point_cloud.cpp:57
#define ROS_ASSERT(cond)
static float g_billboard_sphere_vertices[3 *3]
Definition: point_cloud.cpp:72
#define ROS_ERROR(...)
static Ogre::String sm_Type
The "renderable type" used by Ogre.
Definition: point_cloud.h:233
void setAutoSize(bool auto_size)
virtual void getWorldTransforms(Ogre::Matrix4 *xform) const
PointCloudRenderablePtr createRenderable(int num_points)
virtual const Ogre::AxisAlignedBox & getBoundingBox() const
#define UP_PARAMETER
void shrinkRenderables()


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51