point_cloud.h
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 #ifndef OGRE_TOOLS_OGRE_POINT_CLOUD_H
31 #define OGRE_TOOLS_OGRE_POINT_CLOUD_H
32 
33 #include <OgreSimpleRenderable.h>
34 #include <OgreMovableObject.h>
35 #include <OgreString.h>
36 #include <OgreAxisAlignedBox.h>
37 #include <OgreVector3.h>
38 #include <OgreMaterial.h>
39 #include <OgreColourValue.h>
40 #include <OgreRoot.h>
41 #include <OgreHardwareBufferManager.h>
42 #include <OgreSharedPtr.h>
43 
44 #include <stdint.h>
45 
46 #include <vector>
47 
48 #include <boost/shared_ptr.hpp>
49 
50 namespace Ogre
51 {
52 class SceneManager;
53 class ManualObject;
54 class SceneNode;
55 class RenderQueue;
56 class Camera;
57 class RenderSystem;
58 class Matrix4;
59 }
60 
61 namespace rviz
62 {
63 
64 class PointCloud;
65 class PointCloudRenderable : public Ogre::SimpleRenderable
66 {
67 public:
68  PointCloudRenderable(PointCloud* parent, int num_points, bool use_tex_coords);
70 
71  Ogre::RenderOperation* getRenderOperation() { return &mRenderOp; }
72  Ogre::HardwareVertexBufferSharedPtr getBuffer();
73 
74  virtual Ogre::Real getBoundingRadius(void) const;
75  virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
76  virtual void _notifyCurrentCamera(Ogre::Camera* camera);
77  virtual unsigned short getNumWorldTransforms() const { return 1; }
78  virtual void getWorldTransforms(Ogre::Matrix4* xform) const;
79  virtual const Ogre::LightList& getLights() const;
80 
81 private:
82  Ogre::MaterialPtr material_;
84 };
86 typedef std::vector<PointCloudRenderablePtr> V_PointCloudRenderable;
87 
98 class PointCloud : public Ogre::MovableObject
99 {
100 public:
102  {
109  };
110 
111  PointCloud();
112  ~PointCloud();
113 
117  void clear();
118 
123  struct Point
124  {
125  inline void setColor(float r, float g, float b, float a=1.0)
126  {
127  color=Ogre::ColourValue(r, g, b, a);
128  }
129 
130  Ogre::Vector3 position;
131  Ogre::ColourValue color;
132  };
133 
140  void addPoints( Point* points, uint32_t num_points );
141 
146  void popPoints( uint32_t num_points );
147 
151  void setRenderMode(RenderMode mode);
158  void setDimensions( float width, float height, float depth );
159 
160  /*
161  * If set to true, the size of each point will be multiplied by it z component.
162  * (Used for depth image based point clouds)
163  */
164  void setAutoSize(bool auto_size);
165 
167  void setCommonDirection( const Ogre::Vector3& vec );
169  void setCommonUpVector( const Ogre::Vector3& vec );
170 
175  void setAlpha( float alpha, bool per_point_alpha = false );
176 
177  void setPickColor(const Ogre::ColourValue& color);
178  void setColorByIndex(bool set);
179 
180  void setHighlightColor( float r, float g, float b );
181 
182  virtual const Ogre::String& getMovableType() const { return sm_Type; }
183  virtual const Ogre::AxisAlignedBox& getBoundingBox() const;
184  virtual float getBoundingRadius() const;
185  virtual void getWorldTransforms( Ogre::Matrix4* xform ) const;
186  virtual unsigned short getNumWorldTransforms() const { return 1; }
187  virtual void _updateRenderQueue( Ogre::RenderQueue* queue );
188  virtual void _notifyCurrentCamera( Ogre::Camera* camera );
189  virtual void _notifyAttached(Ogre::Node *parent, bool isTagPoint=false);
190 #if (OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 6)
191  virtual void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables);
192 #endif
193 
194  virtual void setName ( const std::string& name ) { mName = name; }
195 
196 private:
197 
198  uint32_t getVerticesPerPoint();
199  PointCloudRenderablePtr createRenderable( int num_points );
200  void regenerateAll();
201  void shrinkRenderables();
202 
203  Ogre::AxisAlignedBox bounding_box_;
205 
206  typedef std::vector<Point> V_Point;
207  V_Point points_;
208  uint32_t point_count_;
209 
211  float width_;
212  float height_;
213  float depth_;
214  Ogre::Vector3 common_direction_;
215  Ogre::Vector3 common_up_vector_;
216 
217  Ogre::MaterialPtr point_material_;
218  Ogre::MaterialPtr square_material_;
219  Ogre::MaterialPtr flat_square_material_;
220  Ogre::MaterialPtr sphere_material_;
221  Ogre::MaterialPtr tile_material_;
222  Ogre::MaterialPtr box_material_;
223  Ogre::MaterialPtr current_material_;
224  float alpha_;
225 
227 
228  V_PointCloudRenderable renderables_;
229 
231  Ogre::ColourValue pick_color_;
232 
233  static Ogre::String sm_Type;
234 };
235 
236 } // namespace rviz
237 
238 #endif
float width_
width
Definition: point_cloud.h:211
virtual void setName(const std::string &name)
Definition: point_cloud.h:194
Ogre::MaterialPtr current_material_
Definition: point_cloud.h:223
Ogre::MaterialPtr sphere_material_
Definition: point_cloud.h:220
std::vector< Point > V_Point
Definition: point_cloud.h:206
Ogre::MaterialPtr material_
Definition: point_cloud.h:82
uint32_t point_count_
The number of points currently in points_.
Definition: point_cloud.h:208
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
float depth_
depth
Definition: point_cloud.h:213
boost::shared_ptr< PointCloudRenderable > PointCloudRenderablePtr
Definition: point_cloud.h:85
V_Point points_
The list of points we&#39;re displaying. Allocates to a high-water-mark.
Definition: point_cloud.h:207
Ogre::MaterialPtr square_material_
Definition: point_cloud.h:218
Ogre::Vector3 common_direction_
See Ogre::BillboardSet::setCommonDirection.
Definition: point_cloud.h:214
bool current_mode_supports_geometry_shader_
Definition: point_cloud.h:230
Ogre::MaterialPtr tile_material_
Definition: point_cloud.h:221
Representation of a point, with x/y/z position and r/g/b color.
Definition: point_cloud.h:123
Ogre::Vector3 position
Definition: point_cloud.h:130
Ogre::RenderOperation * getRenderOperation()
Definition: point_cloud.h:71
RenderMode render_mode_
Definition: point_cloud.h:210
std::vector< PointCloudRenderablePtr > V_PointCloudRenderable
Definition: point_cloud.h:86
Ogre::MaterialPtr box_material_
Definition: point_cloud.h:222
float bounding_radius_
The bounding radius of this point cloud.
Definition: point_cloud.h:204
Ogre::ColourValue color
Definition: point_cloud.h:131
Ogre::ColourValue pick_color_
Definition: point_cloud.h:231
virtual unsigned short getNumWorldTransforms() const
Definition: point_cloud.h:186
A visual representation of a set of points.
Definition: point_cloud.h:98
V_PointCloudRenderable renderables_
Definition: point_cloud.h:228
Ogre::MaterialPtr point_material_
Definition: point_cloud.h:217
float height_
height
Definition: point_cloud.h:212
Ogre::Vector3 common_up_vector_
See Ogre::BillboardSet::setCommonUpVector.
Definition: point_cloud.h:215
static Ogre::String sm_Type
The "renderable type" used by Ogre.
Definition: point_cloud.h:233
virtual unsigned short getNumWorldTransforms() const
Definition: point_cloud.h:77
void setColor(float r, float g, float b, float a=1.0)
Definition: point_cloud.h:125
virtual const Ogre::String & getMovableType() const
Definition: point_cloud.h:182


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:41