OpenWalnut  1.4.0
WFiberDrawable.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WFIBERDRAWABLE_H
26 #define WFIBERDRAWABLE_H
27 
28 #include <vector>
29 
30 #ifndef Q_MOC_RUN
31 #include <boost/shared_ptr.hpp>
32 #endif
33 #ifndef Q_MOC_RUN
34 #include <boost/thread.hpp>
35 #endif
36 #ifndef Q_MOC_RUN
37 #include <boost/thread/thread.hpp>
38 #endif
39 
40 #include <osg/Drawable>
41 
42 
43 
44 /**
45  * Class implements an osg::Drawable that paints fiber representations either using lines or tubes
46  */
47 class WFiberDrawable: public osg::Drawable // NOLINT
48 {
49 public:
50  /**
51  * The constructor here does nothing. One thing that may be necessary is
52  * disabling display lists. This can be done by calling
53  * setSupportsDisplayList (false);
54  * Display lists should be disabled for 'Drawable's that can change over
55  * time (that is, the vertices drawn change from time to time).
56  */
58 
59  /**
60  * I can't say much about the methods below, but OSG seems to expect
61  * that we implement them.
62  *
63  * \param pg
64  * \param copyop
65  */
66  WFiberDrawable( const WFiberDrawable& pg, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY );
67 
68  /**
69  * See osg documentation for this.
70  *
71  * \return the cloned object
72  */
73  virtual osg::Object* cloneType() const;
74 
75  /**
76  * clones it
77  *
78  * \param copyop copy operation. See osg doc for details
79  * \return the cloned object
80  */
81  virtual osg::Object* clone( const osg::CopyOp& copyop ) const;
82 
83  /**
84  * Real work is done here. THERE IS A VERY IMPORTANT THING TO NOTE HERE:
85  * the \ref drawImplementation method receives an state as
86  * parameter. This can be used to change the OpenGL state, but changing
87  * the OpenGL state here is something to be avoided as much as possible.
88  * Do this *only* if it is *absolutely* necessary to make your rendering
89  * algorithm work. The "right" (most efficient and flexible) way to change
90  * the OpenGL state in OSG is by attaching 'StateSet's to 'Node's and
91  * 'Drawable's.
92  * That said, the example below shows how to change the OpenGL state in
93  * these rare cases in which it is necessary. But always keep in mind:
94  * *Change the OpenGL state only if strictly necessary*.
95  *
96  * \param renderInfo the render info object. See osg doc for details
97  */
98  virtual void drawImplementation( osg::RenderInfo& renderInfo ) const; //NOLINT
99 
100  /**
101  * toggles drawing of tubes
102  *
103  * \param flag
104  */
105  void setUseTubes( bool flag );
106 
107  using osg::Drawable::setBound;
108 
109  /**
110  * setter
111  * \param bitField selected fibers to draw
112  */
113  void setBitfield( boost::shared_ptr< std::vector< bool > > bitField );
114 
115  /**
116  * setter
117  * \param idx
118  */
119  void setStartIndexes( boost::shared_ptr< std::vector< size_t > > idx );
120 
121  /**
122  * setter
123  * \param ppl
124  */
125  void setPointsPerLine( boost::shared_ptr< std::vector< size_t > > ppl );
126 
127  /**
128  * setter
129  * \param verts
130  */
131  void setVerts( boost::shared_ptr< std::vector< float > > verts );
132 
133  /**
134  * setter
135  * \param tangents
136  */
137  void setTangents( boost::shared_ptr< std::vector< float > > tangents );
138 
139  /**
140  * setter
141  * \param color
142  */
143  void setColor( boost::shared_ptr< std::vector< float > > color );
144 
145 protected:
146 private:
147  /**
148  * Draw fibers as ordinary lines.
149  *
150  * \param renderInfo
151  */
152  void drawFibers( osg::RenderInfo& renderInfo ) const; //NOLINT
153 
154  /**
155  * Draw fibers as fake tubes.
156  */
157  void drawTubes() const;
158 
159  boost::shared_mutex m_recalcLock; //!< lock
160 
161  bool m_useTubes; //!< flag
162 
163  boost::shared_ptr< std::vector< bool > > m_active; //!< pointer to the bitfield of active fibers
164 
165  boost::shared_ptr< std::vector< size_t > > m_startIndexes; //!< pointer to the field of line start indexes
166  boost::shared_ptr< std::vector< size_t > > m_pointsPerLine; //!< pointer to the field of points per line
167  boost::shared_ptr< std::vector< float > > m_verts; //!< pointer to the field of vertexes
168  boost::shared_ptr< std::vector< float > > m_tangents; //!< pointer to the field of line tangents
169  boost::shared_ptr< std::vector< float > > m_colors; //!< pointer to the field of colors per vertex
170 };
171 
172 inline void WFiberDrawable::setUseTubes( bool flag )
173 {
174  m_useTubes = flag;
175 }
176 
177 inline void WFiberDrawable::setBitfield( boost::shared_ptr< std::vector< bool > > bitField )
178 {
179  m_active = bitField;
180 }
181 
182 inline void WFiberDrawable::setStartIndexes( boost::shared_ptr< std::vector< size_t > > idx )
183 {
184  m_startIndexes = idx;
185 }
186 
187 inline void WFiberDrawable::setPointsPerLine( boost::shared_ptr< std::vector< size_t > > ppl )
188 {
189  m_pointsPerLine = ppl;
190 }
191 
192 inline void WFiberDrawable::setVerts( boost::shared_ptr< std::vector< float > > verts )
193 {
194  m_verts = verts;
195 }
196 
197 inline void WFiberDrawable::setTangents( boost::shared_ptr< std::vector< float > > tangents )
198 {
199  m_tangents = tangents;
200 }
201 
202 inline void WFiberDrawable::setColor( boost::shared_ptr< std::vector< float > > color )
203 {
204  m_colors = color;
205 }
206 
207 #endif // WFIBERDRAWABLE_H
virtual osg::Object * clone(const osg::CopyOp &copyop) const
clones it
void drawTubes() const
Draw fibers as fake tubes.
Class implements an osg::Drawable that paints fiber representations either using lines or tubes...
boost::shared_ptr< std::vector< size_t > > m_pointsPerLine
pointer to the field of points per line
void setUseTubes(bool flag)
toggles drawing of tubes
void setPointsPerLine(boost::shared_ptr< std::vector< size_t > > ppl)
setter
void setTangents(boost::shared_ptr< std::vector< float > > tangents)
setter
boost::shared_ptr< std::vector< float > > m_tangents
pointer to the field of line tangents
void setBitfield(boost::shared_ptr< std::vector< bool > > bitField)
setter
boost::shared_mutex m_recalcLock
lock
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
Real work is done here.
boost::shared_ptr< std::vector< float > > m_verts
pointer to the field of vertexes
void setColor(boost::shared_ptr< std::vector< float > > color)
setter
WFiberDrawable()
The constructor here does nothing.
boost::shared_ptr< std::vector< size_t > > m_startIndexes
pointer to the field of line start indexes
virtual osg::Object * cloneType() const
See osg documentation for this.
void setVerts(boost::shared_ptr< std::vector< float > > verts)
setter
bool m_useTubes
flag
boost::shared_ptr< std::vector< bool > > m_active
pointer to the bitfield of active fibers
void drawFibers(osg::RenderInfo &renderInfo) const
Draw fibers as ordinary lines.
boost::shared_ptr< std::vector< float > > m_colors
pointer to the field of colors per vertex
void setStartIndexes(boost::shared_ptr< std::vector< size_t > > idx)
setter