00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 #ifndef RVIZ_INTERACTION_TOOLS_POINT_CLOUD_H 00031 #define RVIZ_INTERACTION_TOOLS_POINT_CLOUD_H 00032 00033 #include <OGRE/OgreSimpleRenderable.h> 00034 #include <OGRE/OgreMovableObject.h> 00035 #include <OGRE/OgreString.h> 00036 #include <OGRE/OgreAxisAlignedBox.h> 00037 #include <OGRE/OgreVector3.h> 00038 #include <OGRE/OgreMaterial.h> 00039 #include <OGRE/OgreColourValue.h> 00040 #include <OGRE/OgreRoot.h> 00041 #include <OGRE/OgreHardwareBufferManager.h> 00042 00043 #include <stdint.h> 00044 00045 #include <vector> 00046 00047 #include <boost/shared_ptr.hpp> 00048 00049 namespace Ogre 00050 { 00051 class SceneManager; 00052 class ManualObject; 00053 class SceneNode; 00054 class RenderQueue; 00055 class Camera; 00056 class RenderSystem; 00057 class Matrix4; 00058 } 00059 00060 namespace rviz_interaction_tools 00061 { 00062 00063 class PointCloud; 00064 class PointCloudRenderable : public Ogre::SimpleRenderable 00065 { 00066 public: 00067 PointCloudRenderable(PointCloud* parent, bool use_tex_coords); 00068 ~PointCloudRenderable(); 00069 00070 Ogre::RenderOperation* getRenderOperation() { return &mRenderOp; } 00071 Ogre::HardwareVertexBufferSharedPtr getBuffer(); 00072 00073 virtual Ogre::Real getBoundingRadius(void) const; 00074 virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const; 00075 virtual void _notifyCurrentCamera(Ogre::Camera* camera); 00076 virtual void getWorldTransforms(Ogre::Matrix4* xform) const; 00077 virtual const Ogre::LightList& getLights() const; 00078 virtual void _updateRenderQueue(Ogre::RenderQueue* queue); 00079 00080 private: 00081 Ogre::MaterialPtr material_; 00082 PointCloud* parent_; 00083 }; 00084 00085 typedef boost::shared_ptr<PointCloudRenderable> PointCloudRenderablePtr; 00086 typedef std::vector<PointCloudRenderablePtr> V_PointCloudRenderable; 00087 00098 class PointCloud : public Ogre::MovableObject 00099 { 00100 public: 00101 00102 PointCloud(); 00103 ~PointCloud(); 00104 00108 void clear(); 00109 00114 struct Point 00115 { 00116 inline void setColor(float r, float g, float b) 00117 { 00118 Ogre::Root* root = Ogre::Root::getSingletonPtr(); 00119 root->convertColourValue(Ogre::ColourValue(r, g, b), &color); 00120 } 00121 00122 float x; 00123 float y; 00124 float z; 00125 uint32_t color; 00126 }; 00127 00134 void addPoints( Point* points, uint32_t num_points ); 00135 00136 void setMaterial( const Ogre::String& material_name ); 00137 00138 virtual void setRenderQueueGroup( Ogre::uint8 queueID ); 00139 00140 //ogre interface implementation 00141 virtual const Ogre::String& getMovableType() const { return sm_Type; } 00142 virtual const Ogre::AxisAlignedBox& getBoundingBox() const; 00143 virtual float getBoundingRadius() const; 00144 virtual void getWorldTransforms( Ogre::Matrix4* xform ) const; 00145 virtual void _updateRenderQueue( Ogre::RenderQueue* queue ); 00146 virtual void _notifyCurrentCamera( Ogre::Camera* camera ); 00147 virtual void _notifyAttached(Ogre::Node *parent, bool isTagPoint=false); 00148 #if (OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 6) 00149 virtual void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables); 00150 #endif 00151 00152 private: 00153 00154 uint32_t getVerticesPerPoint(); 00155 PointCloudRenderablePtr getOrCreateRenderable(); 00156 void regenerateAll(); 00157 void shrinkRenderables(); 00158 00159 Ogre::AxisAlignedBox bounding_box_; 00160 float bounding_radius_; 00161 00162 typedef std::vector<Point> V_Point; 00163 V_Point points_; 00164 uint32_t point_count_; 00165 00166 Ogre::MaterialPtr current_material_; 00167 00168 V_PointCloudRenderable renderables_; 00169 00170 bool current_mode_supports_geometry_shader_; 00171 00172 static Ogre::String sm_Type; 00173 }; 00174 00175 } // namespace ogre_tools 00176 00177 #endif