OpenWalnut  1.5.0dev
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 <memory>
29 #include <shared_mutex>
30 #include <vector>
31 
32 #include <boost/thread.hpp>
33 #include <boost/thread/thread.hpp>
34 #include <osg/Drawable>
35 
36 
37 
38 /**
39  * Class implements an osg::Drawable that paints fiber representations either using lines or tubes
40  */
41 class WFiberDrawable: public osg::Drawable // NOLINT
42 {
43 public:
44  /**
45  * The constructor here does nothing. One thing that may be necessary is
46  * disabling display lists. This can be done by calling
47  * setSupportsDisplayList (false);
48  * Display lists should be disabled for 'Drawable's that can change over
49  * time (that is, the vertices drawn change from time to time).
50  */
52 
53  /**
54  * I can't say much about the methods below, but OSG seems to expect
55  * that we implement them.
56  *
57  * \param pg
58  * \param copyop
59  */
60  WFiberDrawable( const WFiberDrawable& pg, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY );
61 
62  /**
63  * See osg documentation for this.
64  *
65  * \return the cloned object
66  */
67  virtual osg::Object* cloneType() const;
68 
69  /**
70  * clones it
71  *
72  * \param copyop copy operation. See osg doc for details
73  * \return the cloned object
74  */
75  virtual osg::Object* clone( const osg::CopyOp& copyop ) const;
76 
77  /**
78  * Real work is done here. THERE IS A VERY IMPORTANT THING TO NOTE HERE:
79  * the \ref drawImplementation method receives an state as
80  * parameter. This can be used to change the OpenGL state, but changing
81  * the OpenGL state here is something to be avoided as much as possible.
82  * Do this *only* if it is *absolutely* necessary to make your rendering
83  * algorithm work. The "right" (most efficient and flexible) way to change
84  * the OpenGL state in OSG is by attaching 'StateSet's to 'Node's and
85  * 'Drawable's.
86  * That said, the example below shows how to change the OpenGL state in
87  * these rare cases in which it is necessary. But always keep in mind:
88  * *Change the OpenGL state only if strictly necessary*.
89  *
90  * \param renderInfo the render info object. See osg doc for details
91  */
92  virtual void drawImplementation( osg::RenderInfo& renderInfo ) const; //NOLINT
93 
94  /**
95  * toggles drawing of tubes
96  *
97  * \param flag
98  */
99  void setUseTubes( bool flag );
100 
101  using osg::Drawable::setBound;
102 
103  /**
104  * setter
105  * \param bitField selected fibers to draw
106  */
107  void setBitfield( std::shared_ptr< std::vector< bool > > bitField );
108 
109  /**
110  * setter
111  * \param idx
112  */
113  void setStartIndexes( std::shared_ptr< std::vector< size_t > > idx );
114 
115  /**
116  * setter
117  * \param ppl
118  */
119  void setPointsPerLine( std::shared_ptr< std::vector< size_t > > ppl );
120 
121  /**
122  * setter
123  * \param verts
124  */
125  void setVerts( std::shared_ptr< std::vector< float > > verts );
126 
127  /**
128  * setter
129  * \param tangents
130  */
131  void setTangents( std::shared_ptr< std::vector< float > > tangents );
132 
133  /**
134  * setter
135  * \param color
136  */
137  void setColor( std::shared_ptr< std::vector< float > > color );
138 
139 protected:
140 private:
141  /**
142  * Draw fibers as ordinary lines.
143  *
144  * \param renderInfo
145  */
146  void drawFibers( osg::RenderInfo& renderInfo ) const; //NOLINT
147 
148  /**
149  * Draw fibers as fake tubes.
150  */
151  void drawTubes() const;
152 
153  std::shared_mutex m_recalcLock; //!< lock
154 
155  bool m_useTubes; //!< flag
156 
157  std::shared_ptr< std::vector< bool > > m_active; //!< pointer to the bitfield of active fibers
158 
159  std::shared_ptr< std::vector< size_t > > m_startIndexes; //!< pointer to the field of line start indexes
160  std::shared_ptr< std::vector< size_t > > m_pointsPerLine; //!< pointer to the field of points per line
161  std::shared_ptr< std::vector< float > > m_verts; //!< pointer to the field of vertexes
162  std::shared_ptr< std::vector< float > > m_tangents; //!< pointer to the field of line tangents
163  std::shared_ptr< std::vector< float > > m_colors; //!< pointer to the field of colors per vertex
164 };
165 
166 inline void WFiberDrawable::setUseTubes( bool flag )
167 {
168  m_useTubes = flag;
169 }
170 
171 inline void WFiberDrawable::setBitfield( std::shared_ptr< std::vector< bool > > bitField )
172 {
173  m_active = bitField;
174 }
175 
176 inline void WFiberDrawable::setStartIndexes( std::shared_ptr< std::vector< size_t > > idx )
177 {
178  m_startIndexes = idx;
179 }
180 
181 inline void WFiberDrawable::setPointsPerLine( std::shared_ptr< std::vector< size_t > > ppl )
182 {
183  m_pointsPerLine = ppl;
184 }
185 
186 inline void WFiberDrawable::setVerts( std::shared_ptr< std::vector< float > > verts )
187 {
188  m_verts = verts;
189 }
190 
191 inline void WFiberDrawable::setTangents( std::shared_ptr< std::vector< float > > tangents )
192 {
193  m_tangents = tangents;
194 }
195 
196 inline void WFiberDrawable::setColor( std::shared_ptr< std::vector< float > > color )
197 {
198  m_colors = color;
199 }
200 
201 #endif // WFIBERDRAWABLE_H
Class implements an osg::Drawable that paints fiber representations either using lines or tubes.
std::shared_ptr< std::vector< float > > m_verts
pointer to the field of vertexes
void setBitfield(std::shared_ptr< std::vector< bool > > bitField)
setter
WFiberDrawable()
The constructor here does nothing.
void setColor(std::shared_ptr< std::vector< float > > color)
setter
std::shared_ptr< std::vector< size_t > > m_pointsPerLine
pointer to the field of points per line
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
Real work is done here.
void setUseTubes(bool flag)
toggles drawing of tubes
std::shared_ptr< std::vector< float > > m_tangents
pointer to the field of line tangents
virtual osg::Object * clone(const osg::CopyOp &copyop) const
clones it
std::shared_mutex m_recalcLock
lock
std::shared_ptr< std::vector< bool > > m_active
pointer to the bitfield of active fibers
virtual osg::Object * cloneType() const
See osg documentation for this.
std::shared_ptr< std::vector< size_t > > m_startIndexes
pointer to the field of line start indexes
void setPointsPerLine(std::shared_ptr< std::vector< size_t > > ppl)
setter
void setTangents(std::shared_ptr< std::vector< float > > tangents)
setter
std::shared_ptr< std::vector< float > > m_colors
pointer to the field of colors per vertex
void drawTubes() const
Draw fibers as fake tubes.
bool m_useTubes
flag
void setVerts(std::shared_ptr< std::vector< float > > verts)
setter
void setStartIndexes(std::shared_ptr< std::vector< size_t > > idx)
setter
void drawFibers(osg::RenderInfo &renderInfo) const
Draw fibers as ordinary lines.