OpenWalnut
1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WFIBERDRAWABLE_H 00026 #define WFIBERDRAWABLE_H 00027 00028 #include <vector> 00029 00030 #include <boost/shared_ptr.hpp> 00031 #include <boost/thread.hpp> 00032 #include <boost/thread/thread.hpp> 00033 00034 #include <osg/Drawable> 00035 #include <osg/ShapeDrawable> 00036 #include <osg/Group> 00037 00038 #include "WExportWGE.h" 00039 00040 /** 00041 * Class implements an osg::Drawable that paints fiber representations either using lines or tubes 00042 */ 00043 class WGE_EXPORT WFiberDrawable: public osg::Drawable // NOLINT 00044 { 00045 public: 00046 00047 /** 00048 * The constructor here does nothing. One thing that may be necessary is 00049 * disabling display lists. This can be done by calling 00050 * setSupportsDisplayList (false); 00051 * Display lists should be disabled for 'Drawable's that can change over 00052 * time (that is, the vertices drawn change from time to time). 00053 */ 00054 WFiberDrawable(); 00055 00056 /** 00057 * I can't say much about the methods below, but OSG seems to expect 00058 * that we implement them. 00059 * 00060 * \param pg 00061 * \param copyop 00062 */ 00063 WFiberDrawable( const WFiberDrawable& pg, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY ); 00064 00065 /** 00066 * See osg documentation for this. 00067 * 00068 * \return the cloned object 00069 */ 00070 virtual osg::Object* cloneType() const; 00071 00072 /** 00073 * clones it 00074 * 00075 * \param copyop copy operation. See osg doc for details 00076 * \return the cloned object 00077 */ 00078 virtual osg::Object* clone( const osg::CopyOp& copyop ) const; 00079 00080 /** 00081 * Real work is done here. THERE IS A VERY IMPORTANT THING TO NOTE HERE: 00082 * the \ref drawImplementation method receives an state as 00083 * parameter. This can be used to change the OpenGL state, but changing 00084 * the OpenGL state here is something to be avoided as much as possible. 00085 * Do this *only* if it is *absolutely* necessary to make your rendering 00086 * algorithm work. The "right" (most efficient and flexible) way to change 00087 * the OpenGL state in OSG is by attaching 'StateSet's to 'Node's and 00088 * 'Drawable's. 00089 * That said, the example below shows how to change the OpenGL state in 00090 * these rare cases in which it is necessary. But always keep in mind: 00091 * *Change the OpenGL state only if strictly necessary*. 00092 * 00093 * \param renderInfo the render info object. See osg doc for details 00094 */ 00095 virtual void drawImplementation( osg::RenderInfo& renderInfo ) const; //NOLINT 00096 00097 /** 00098 * toggles drawing of tubes 00099 * 00100 * \param flag 00101 */ 00102 void setUseTubes( bool flag ); 00103 00104 using osg::Drawable::setBound; 00105 00106 /** 00107 * setter 00108 * \param bitField selected fibers to draw 00109 */ 00110 void setBitfield( boost::shared_ptr< std::vector< bool > > bitField ); 00111 00112 /** 00113 * setter 00114 * \param idx 00115 */ 00116 void setStartIndexes( boost::shared_ptr< std::vector< size_t > > idx ); 00117 00118 /** 00119 * setter 00120 * \param ppl 00121 */ 00122 void setPointsPerLine( boost::shared_ptr< std::vector< size_t > > ppl ); 00123 00124 /** 00125 * setter 00126 * \param verts 00127 */ 00128 void setVerts( boost::shared_ptr< std::vector< float > > verts ); 00129 00130 /** 00131 * setter 00132 * \param tangents 00133 */ 00134 void setTangents( boost::shared_ptr< std::vector< float > > tangents ); 00135 00136 /** 00137 * setter 00138 * \param color 00139 */ 00140 void setColor( boost::shared_ptr< std::vector< float > > color ); 00141 00142 protected: 00143 private: 00144 /** 00145 * Draw fibers as ordinary lines. 00146 * 00147 * \param renderInfo 00148 */ 00149 void drawFibers( osg::RenderInfo& renderInfo ) const; //NOLINT 00150 00151 /** 00152 * Draw fibers as fake tubes. 00153 */ 00154 void drawTubes() const; 00155 00156 boost::shared_mutex m_recalcLock; //!< lock 00157 00158 bool m_useTubes; //!< flag 00159 00160 boost::shared_ptr< std::vector< bool > > m_active; //!< pointer to the bitfield of active fibers 00161 00162 boost::shared_ptr< std::vector< size_t > > m_startIndexes; //!< pointer to the field of line start indexes 00163 boost::shared_ptr< std::vector< size_t > > m_pointsPerLine; //!< pointer to the field of points per line 00164 boost::shared_ptr< std::vector< float > > m_verts; //!< pointer to the field of vertexes 00165 boost::shared_ptr< std::vector< float > > m_tangents; //!< pointer to the field of line tangents 00166 boost::shared_ptr< std::vector< float > > m_colors; //!< pointer to the field of colors per vertex 00167 }; 00168 00169 inline void WFiberDrawable::setUseTubes( bool flag ) 00170 { 00171 m_useTubes = flag; 00172 } 00173 00174 inline void WFiberDrawable::setBitfield( boost::shared_ptr< std::vector< bool > > bitField ) 00175 { 00176 m_active = bitField; 00177 } 00178 00179 inline void WFiberDrawable::setStartIndexes( boost::shared_ptr< std::vector< size_t > > idx ) 00180 { 00181 m_startIndexes = idx; 00182 } 00183 00184 inline void WFiberDrawable::setPointsPerLine( boost::shared_ptr< std::vector< size_t > > ppl ) 00185 { 00186 m_pointsPerLine = ppl; 00187 } 00188 00189 inline void WFiberDrawable::setVerts( boost::shared_ptr< std::vector< float > > verts ) 00190 { 00191 m_verts = verts; 00192 } 00193 00194 inline void WFiberDrawable::setTangents( boost::shared_ptr< std::vector< float > > tangents ) 00195 { 00196 m_tangents = tangents; 00197 } 00198 00199 inline void WFiberDrawable::setColor( boost::shared_ptr< std::vector< float > > color ) 00200 { 00201 m_colors = color; 00202 } 00203 00204 #endif // WFIBERDRAWABLE_H