OpenWalnut  1.5.0dev
WDataSetFibers.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 WDATASETFIBERS_H
26 #define WDATASETFIBERS_H
27 
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 #include <boost/tuple/tuple.hpp>
34 
35 #include "../common/WBoundingBox.h"
36 #include "../common/WDefines.h" // for deprecated
37 #include "../common/WProperties.h"
38 #include "../common/math/linearAlgebra/WPosition.h"
39 #include "WDataSet.h"
40 #include "WIteratorRange.h"
41 
42 // forward declarations
43 class WFiber;
44 
45 class WFiberIterator;
46 
48 
50 
51 /**
52  * Represents a simple set of WFibers.
53  */
54 class WDataSetFibers : public WDataSet // NOLINT
55 {
56 public:
57  // some type alias for the used arrays.
58  /**
59  * Pointer to dataset.
60  */
61  typedef std::shared_ptr< WDataSetFibers > SPtr;
62 
63  /**
64  * Pointer to const dataset.
65  */
66  typedef std::shared_ptr< const WDataSetFibers > ConstSPtr;
67 
68  /**
69  * List of vertex coordinates in term of components of vertices.
70  */
71  typedef std::shared_ptr< std::vector< float > > VertexArray;
72 
73  /**
74  * Index list indexing fibers in VertexArray in terms of vertex numbers.
75  */
76  typedef std::shared_ptr< std::vector< size_t > > IndexArray;
77 
78  /**
79  * Lengths of fibers in terms of vertices.
80  */
81  typedef std::shared_ptr< std::vector< size_t > > LengthArray;
82 
83  /**
84  * Tangents at each vertex in VertexArray.
85  */
86  typedef std::shared_ptr< std::vector< float > > TangentArray;
87 
88  /**
89  * Colors for each vertex in VertexArray.
90  */
91  typedef std::shared_ptr< std::vector< float > > ColorArray;
92 
93  /**
94  * Parameter storage for each vertex.
95  */
96  typedef std::shared_ptr< std::vector< double > > VertexParemeterArray;
97 
98  /**
99  * Parameter storage for each line.
100  */
101  typedef std::shared_ptr< std::vector< double > > LineParemeterArray;
102 
103  /**
104  * Iterator to go through the fibers.
105  */
107 
108  /**
109  * Const iterator to go through fibers. As the WFiberIterators does not allow any modifications per-se, the const iterator and the standard
110  * iterator are the same.
111  */
113 
114  /**
115  * Item used in the selection below also containing color info.
116  */
118  {
119  friend class WDataSetFibers; //!< Grant access for its outer class
120  public:
121  /**
122  * different kinds of color arrays can be used in this class. This enum defines their possible types.
123  */
124  typedef enum
125  {
126  GRAY = 1, //!< gray value per vertex
127  RGB = 3, //!< rgb per vertex
128  RGBA = 4 //!< rgba per vertex
129  }
130  ColorMode;
131 
132  /**
133  * Constructor. Creates new item.
134  *
135  * \param name name, name of item.
136  * \param description description of item. Can be empty.
137  * \param icon icon, can be NULL
138  * \param color the color array of this item.
139  * \param mode the mode of the color array. This defines whether the colors are luminance, RGB or RGBA
140  */
141  ColorScheme( std::string name, std::string description, const char** icon, ColorArray color, ColorMode mode = RGB ):
142  WItemSelectionItem( name, description, icon ),
143  m_color( color ),
144  m_mode( mode )
145  {
146  };
147 
148  /**
149  * Get the color.
150  *
151  * \return the color array.
152  */
154  {
155  return m_color;
156  };
157 
158  /**
159  * Returns the mode of the color scheme.
160  *
161  * \return the mode.
162  */
164  {
165  return m_mode;
166  };
167 
168  protected:
169  /**
170  * Sets the color array for this item.
171  *
172  * \param color the color to set.
173  * \param mode the mode of the color array. This defines whether the colors are luminance, RGB or RGBA
174  */
175  void setColor( ColorArray color, ColorMode mode = RGB )
176  {
177  m_color = color;
178  m_mode = mode;
179  };
180 
181  private:
182  /**
183  * The color array associated with the item.
184  */
186 
187  /**
188  * Coloring mode.
189  */
191  };
192 
193  /**
194  * Constructs a new set of fibers.
195  *
196  * \param vertices the vertices of the fibers, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
197  * \param lineStartIndexes the index in which the fiber start (index of the 3D-vertex, not the index of the float in the vertices vector)
198  * \param lineLengths how many vertices belong to a fiber
199  * \param verticesReverse stores for each vertex the index of the corresponding fiber
200  * \param boundingBox The bounding box of the fibers (first minimum, second maximum).
201  */
202  WDataSetFibers( std::shared_ptr< std::vector< float > >vertices,
203  std::shared_ptr< std::vector< size_t > > lineStartIndexes,
204  std::shared_ptr< std::vector< size_t > > lineLengths,
205  std::shared_ptr< std::vector< size_t > > verticesReverse,
206  WBoundingBox boundingBox );
207 
208  /**
209  * Constructs a new set of fibers. This constructor determines the bounding box by using the coordinates of the vertices.
210  *
211  * \param vertices the vertices of the fibers, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
212  * \param lineStartIndexes the index in which the fiber start (index of the 3D-vertex, not the index of the float in the vertices vector)
213  * \param lineLengths how many vertices belong to a fiber
214  * \param verticesReverse stores for each vertex the index of the corresponding fiber
215  */
216  WDataSetFibers( std::shared_ptr< std::vector< float > >vertices,
217  std::shared_ptr< std::vector< size_t > > lineStartIndexes,
218  std::shared_ptr< std::vector< size_t > > lineLengths,
219  std::shared_ptr< std::vector< size_t > > verticesReverse );
220 
221  /**
222  * Constructs a new set of fibers.
223  *
224  * \param vertices the vertices of the fibers, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
225  * \param lineStartIndexes the index in which the fiber start (index of the 3D-vertex, not the index of the float in the vertices vector)
226  * \param lineLengths how many vertices belong to a fiber
227  * \param verticesReverse stores for each vertex the index of the corresponding fiber
228  * \param boundingBox The bounding box of the fibers (first minimum, second maximum).
229  * \param vertexParameters optional per-vertex scalar.
230  */
231  WDataSetFibers( std::shared_ptr< std::vector< float > >vertices,
232  std::shared_ptr< std::vector< size_t > > lineStartIndexes,
233  std::shared_ptr< std::vector< size_t > > lineLengths,
234  std::shared_ptr< std::vector< size_t > > verticesReverse,
235  WBoundingBox boundingBox,
236  VertexParemeterArray vertexParameters );
237 
238  /**
239  * Constructs a new set of fibers. This constructor determines the bounding box by using the coordinates of the vertices.
240  *
241  * \param vertices the vertices of the fibers, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
242  * \param lineStartIndexes the index in which the fiber start (index of the 3D-vertex, not the index of the float in the vertices vector)
243  * \param lineLengths how many vertices belong to a fiber
244  * \param verticesReverse stores for each vertex the index of the corresponding fiber
245  * \param vertexParameters optional per-vertex scalar.
246  */
247  WDataSetFibers( std::shared_ptr< std::vector< float > >vertices,
248  std::shared_ptr< std::vector< size_t > > lineStartIndexes,
249  std::shared_ptr< std::vector< size_t > > lineLengths,
250  std::shared_ptr< std::vector< size_t > > verticesReverse,
251  VertexParemeterArray vertexParameters );
252 
253  /**
254  * Constructs a new set of tracts. The constructed instance is not usable but needed for prototype mechanism.
255  */
256  WDataSetFibers();
257 
258  /**
259  * Get number of tracts in this data set.
260  * \return number of fibers
261  */
262  size_t size() const;
263 
264  /**
265  * Determines whether this dataset can be used as a texture.
266  *
267  * \return true if usable as texture.
268  */
269  virtual bool isTexture() const;
270 
271  /**
272  * Gets the name of this prototype.
273  *
274  * \return the name.
275  */
276  virtual const std::string getName() const;
277 
278  /**
279  * Gets the description for this prototype.
280  *
281  * \return the description
282  */
283  virtual const std::string getDescription() const;
284 
285  /**
286  * Returns a prototype instantiated with the true type of the deriving class.
287  *
288  * \return the prototype.
289  */
290  static std::shared_ptr< WPrototyped > getPrototype();
291 
292  /**
293  * Getter for the lines' vertices
294  * \return The vertices of the lines
295  */
296  VertexArray getVertices() const;
297 
298  /**
299  * Getter for the total number of vertices over all lines
300  * \return Overall number of vertices
301  */
302  size_t getNbVertices() const;
303 
304  /**
305  * Return the indices that indicate at which vertex ID each line begins in the vertex array.
306  * \return The start indices of the lines
307  */
309 
310  /**
311  * Return the number of vertices for all lines.
312  * \return The numbers of all lines' vertices
313  */
314  LengthArray getLineLengths() const;
315 
316  /**
317  * Returns a reverse lookup table that allow do find out which vertex belongs to which line.
318  * \return Lookup table from vertices to lines.
319  */
321 
322  /**
323  * Returns an array containing the tangents of the fibers at the vertices.
324  * \return The tangents of the fibers.
325  */
326  TangentArray getTangents() const;
327 
328  /**
329  * Get the parameter values for each vertex. Same indexing as vertices. Used to store additional scalar values for each vertex.
330  *
331  * \return the array. Can be NULL.
332  *
333  * \param parameterIndex there can be multiple parameters. The index defines the index of the parameter array to get. Default is 0.
334  */
335  VertexParemeterArray getVertexParameters( size_t parameterIndex = 0 ) const;
336 
337  /**
338  * Set the given array of parameters to be the vertex parameters of this fiber dataset.
339  *
340  * \param parameters the list of parameters. Can be an empty vector to remove parameters.
341  */
342  void setVertexParameters( std::vector< VertexParemeterArray > parameters );
343 
344  /**
345  * Get the parameter values for each line. Same indexing as lines. Used to store additional scalar values for each line.
346  *
347  * \return the array. Can be NULL.
348  *
349  * \param parameterIndex there can be multiple parameters. The index defines the index of the parameter array to get. Default is 0.
350  */
351  LineParemeterArray getLineParameters( size_t parameterIndex = 0 ) const;
352 
353  /**
354  * Set an array to be the list of line parameters.
355  *
356  * \param parameters the list of parameters. Can be an empty vector to remove parameters.
357  */
358  void setLineParameters( std::vector< LineParemeterArray > parameters );
359 
360  /**
361  * This method adds a new color scheme to the list of available colors. The color scheme needs to have a name and description to allow the
362  * user to identify which color has which meaning. If the specified color array already exists, only an update is triggered and the name and
363  * description is ignored. It detects the type of colors by its size.
364  *
365  * \param colors the color array. Needs to have exactly getVertices()->size() items.
366  * \param name name of the color scheme. Should be a telling name.
367  * \param description description. How calculated and so on.
368  */
369  void addColorScheme( WDataSetFibers::ColorArray colors, std::string name, std::string description );
370 
371  /**
372  * This method removes the specified color scheme from the list and triggers an update.
373  *
374  * \param colors the color array.
375  */
377 
378  /**
379  * Replaces the specified old color scheme by the new color scheme. If the old color scheme did not exist, nothing happens.
380  *
381  * \param oldColors old colors to remove
382  * \param newColors new colors to set
383  */
385 
386  /**
387  * Get the color scheme with the specified name. If it is not found, an exception gets thrown.
388  *
389  * \param name the name of the color scheme
390  *
391  * \return the color scheme
392  * \throw WDHNoSuchDataSet if the name could not be found.
393  */
394  const std::shared_ptr< ColorScheme > getColorScheme( std::string name ) const;
395 
396  /**
397  * Get the color scheme with the specified ID. If the index is invalid, an exception gets thrown.
398  *
399  * \param idx the index
400  *
401  * \return the color scheme
402  */
403  const std::shared_ptr< ColorScheme > getColorScheme( size_t idx ) const;
404 
405  /**
406  * Sets the selected color scheme.
407  *
408  * \param idx the index
409  */
410  void setSelectedColorScheme( size_t idx );
411 
412  /**
413  * Convenience method returning the currently selected scheme. This is a comfortable alternative to using the color scheme selection
414  * property.
415  *
416  * \return the current active color scheme
417  */
418  const std::shared_ptr< ColorScheme > getColorScheme() const;
419 
420  /**
421  * Returns the property controlling the color scheme selection.
422  *
423  * \return the property.
424  */
425  const WPropSelection getColorSchemeProperty() const;
426 
427  /**
428  * returns the position in space for a vertex of a given fiber
429  *
430  * \param fiber Index of fiber
431  * \param vertex Index of vertex in fiber.
432  *
433  * \return Position of the given vertex of the also given fiber
434  */
435  WPosition getPosition( size_t fiber, size_t vertex ) const;
436 
437  /**
438  * calculates the tangent for a point on the fiber
439  *
440  * \param fiber Index of fiber
441  * \param vertex Index of vertex in fiber
442  *
443  * \return Tangent of the given vertex of the also given fiber
444  */
445  WPosition getTangent( size_t fiber, size_t vertex ) const;
446 
447  /**
448  * Returns the number of points for a given fiber.
449  *
450  * \param fiber The index of the fiber.
451  *
452  * \return The number of points of the fiber.
453  */
454  std::size_t getLengthOfLine( std::size_t fiber ) const;
455 
456  /**
457  * Get the index of the first vertex of a given fiber.
458  * This is used to find the three components 3 * start, 3 * start + 1
459  * and 3 * start + 2 of the first vertex in the vertices vector.
460  *
461  * \param fiber The fiber to find the start index for.
462  *
463  * \return The start index.
464  */
465  std::size_t getStartIndex( std::size_t fiber ) const;
466 
467  /**
468  * Get the bounding box.
469  * \return The bounding box of all lines.
470  */
472 
473  /**
474  * Constructs a WFiber out of the given tract number.
475  *
476  * \param numTract Number of the tract to generate a WFiber object for
477  *
478  * \return The WFiber object. Attention: copy by value!
479  */
480  WFiber operator[]( size_t numTract ) const;
481 
482  /**
483  * Returns an iterator to the first fiber of the dataset. The iterator does not allow any modification of the data.
484  * DEPRECATED: Use fibers().begin() or iterator range syntax instead.
485  *
486  * \return An iterator to the first fiber.
487  */
489 
490  /**
491  * Returns an iterator pointing beyond the last fiber. The iterator does not allow any modification of the data.
492  * DEPRECATED: Use fibers().end() or iterator range syntax instead.
493  *
494  * \return An iterator pointing beyond the last fiber.
495  */
497 
498  /**
499  * Creates a range of iterators that allows for forward iteration of the fibers in this dataset.
500  * If the current iterator is not valid, behaviour is undefined. The end iterator of the returned range
501  * is the first invalid iterator after the last fiber.
502  *
503  * \return The full range from begin to end.
504  */
506 
507 protected:
508  /**
509  * The prototype as singleton.
510  */
511  static std::shared_ptr< WPrototyped > m_prototype;
512 
513 private:
514  /**
515  * This does the common initialisation of the constructors.
516  */
517  void init();
518 
519  /**
520  * Point vector for all fibers
521  */
523 
524  /**
525  * Point vector for tangents at each vertex, used for fake tubes
526  */
528 
529  /**
530  * An array of color arrays. The first two elements are: 0: global color, 1: local color
531  */
532  std::shared_ptr< WItemSelection > m_colors;
533 
534  /**
535  * Property keeping track of the active color in m_colors.
536  */
537  WPropSelection m_colorProp;
538 
539  /**
540  * Line vector that contains the start index of its first point for each line.
541  * \warning The index returned cannot be used in the vertices array until
542  * the number of components for each point is multiplied.
543  */
545 
546  /**
547  * Line vector that contains the number of vertices for each line
548  */
550 
551  /**
552  * Reverse lookup table for which point belongs to which fiber
553  */
555 
556  /**
557  * Axis aligned bounding box for all tract-vertices of this dataset.
558  */
560 
561  /**
562  * Parameter array. Used to store additional scalar values for each vertex. Multiple parameter arrays allowed.
563  */
564  std::vector< VertexParemeterArray > m_vertexParameters;
565 
566  /**
567  * Parameter array. Used to store additional scalar values for each line. Multiple parameter arrays allowed.
568  */
569  std::vector< LineParemeterArray > m_lineParameters;
570 };
571 
572 /**
573  * \class WFiberIterator
574  *
575  * \brief An iterator for fibers of a fiber dataset.
576  *
577  * This class iterates fibers of a fiber dataset.
578  *
579  * There are two ways to use the iterator. First:
580  *
581  * \code{.cpp}
582  * for( WFiberIterator fi = some_fiber_data_set_pointer->fibers().begin();
583  * fi != some_fiber_data_set_pointer->fibers().end(); ++fi )
584  * {
585  * ...
586  * }
587  * \endcode
588  *
589  * Second:
590  *
591  * \code{.cpp}
592  * WFiberIterator fi, fe;
593  * for( ( fi, fe ) = some_fiber_data_set_pointer->fibers(); fi != fe; ++fi )
594  * {
595  * ...
596  * }
597  * \endcode
598  *
599  * Use the provided points() and segments() functions to iterate the points or segments of
600  * the current fiber. You can also check whether an iterator points to a valid fiber by:
601  *
602  * \code{.cpp}
603  * if( iterator )
604  * {
605  * ...
606  * }
607  * \endcode
608  */
610 {
611 public:
612  /**
613  * Constructor. Creates an invalid iterator pointing nowhere.
614  */
615  WFiberIterator();
616 
617  /**
618  * Constructor. Creates an iterator for a specific fiber dataset.
619  *
620  * \param fibers A pointer to the fiber data.
621  * \param idx The index of the fiber to point to.
622  */
623  WFiberIterator( WDataSetFibers const* fibers, std::size_t idx );
624 
625  /**
626  * Copy constructor.
627  *
628  * \param iter The iterator to copy from.
629  */
630  WFiberIterator( WFiberIterator const& iter ); // NOLINT explicit
631 
632  /**
633  * Destructor.
634  */
635  ~WFiberIterator();
636 
637  /**
638  * Copy operator.
639  *
640  * \param iter The iterator to copy from.
641  *
642  * \return *this
643  */
644  WFiberIterator& operator= ( WFiberIterator const& iter );
645 
646  /**
647  * Increment operator. Makes the iterator point to the next fiber.
648  *
649  * \return The incremented iterator.
650  */
652 
653  /**
654  * Decrement operator. Makes the iterator point to the previous fiber.
655  *
656  * \return The decremented iterator.
657  */
659 
660  /**
661  * Increment operator. Makes the iterator point to the next fiber.
662  *
663  * \return The iterator before incrementing.
664  */
666 
667  /**
668  * Decrement operator. Makes the iterator point to the previous fiber.
669  *
670  * \return The iterator before decrementing.
671  */
673 
674  /**
675  * Plus operator. Increments the iterator \param n times.
676  *
677  * \return The iterator on the new place.
678  */
679  WFiberIterator operator+ ( size_t n ) const;
680 
681  /**
682  * Minus operator. Decrements the iterator \param n times.
683  *
684  * \return The iterator on the new place.
685  */
686  WFiberIterator operator- ( size_t n ) const;
687 
688  /**
689  * Compare to another fiber iterator.
690  *
691  * \param rhs The second fiber iterator.
692  *
693  * \return true, iff the two iterators point to the same fiber of the same fiber dataset.
694  */
695  bool operator == ( WFiberIterator const& rhs ) const;
696 
697  /**
698  * Compare to another fiber iterator.
699  *
700  * \param rhs The second fiber iterator.
701  *
702  * \return false, iff the two iterators point to the same fiber of the same fiber dataset.
703  */
704  bool operator != ( WFiberIterator const& rhs ) const;
705 
706  /**
707  * Creates a temporary object that is used to unpack an iterator range to two iterators.
708  * The first of these target iterators is *this, the second is the parameter of the operator.
709  *
710  * \param other The iterator to assign the end iterator of the range to.
711  * \return The unpacker to assign a range to.
712  */
713  WIteratorRangeUnpacker< WFiberIterator > operator,( WFiberIterator& other ); // NOLINT non-const ref and space intended
714 
715  /**
716  * Converts to a bool that indicates whether the current iterator is valid, i.e. it points to a valid fiber
717  * and it is safe to access point or segments.
718  */
719  operator bool() const;
720 
721  /**
722  * Creates a point iterator for forward iteration, pointing to the first point of the fiber.
723  * DEPRECATED: Use the iterator range syntax instead.
724  *
725  * \return A point iterator pointing to the first point.
726  */
728 
729  /**
730  * Creates a point iterator for forward iteration, pointing beyond the last point of the fiber.
731  * DEPRECATED: Use the iterator range syntax instead.
732  *
733  * \return A point iterator pointing beyond the last point.
734  */
736 
737  /**
738  * Creates a point iterator for backward iteration, pointing to the last point of the fiber.
739  * DEPRECATED: Use the iterator range syntax instead.
740  *
741  * \return A point iterator pointing to the last point.
742  */
744 
745  /**
746  * Creates a point iterator for backward iteration, pointing beyond the first point of the fiber.
747  * DEPRECATED: Use the iterator range syntax instead.
748  *
749  * \return A point iterator pointing beyond the first point.
750  */
752 
753  /**
754  * Creates a range of iterators that allows for forward iteration of the points of the fiber
755  * this iterator currently points to. If the current iterator is not valid, behaviour is undefined.
756  * The end iterator of the returned range is the first invalid iterator after the last point.
757  *
758  * \return The full range from begin to end.
759  */
761 
762  /**
763  * Creates a range of iterators that allows for reverse iteration of the points of the fiber
764  * this iterator currently points to. If the current iterator is not valid, behaviour is undefined.
765  * The end iterator of the returned range is the first invalid iterator before the first point.
766  *
767  * \return The full range from begin to end, points in reverse order starting with the last.
768  */
770 
771  /**
772  * Returns a forward iterator to the first segment.
773  * DEPRECATED: Use the iterator range syntax instead.
774  *
775  * \return A forward iterator to the first segment.
776  */
778 
779  /**
780  * Returns a forward iterator to the invalid segment after the last (i.e. an end iterator).
781  * DEPRECATED: Use the iterator range syntax instead.
782  *
783  * \return A forward end iterator.
784  */
786 
787  /**
788  * Returns a backward iterator to the last segment.
789  * DEPRECATED: Use the iterator range syntax instead.
790  *
791  * \return A backward iterator to the last segment.
792  */
794 
795  /**
796  * Returns a backward iterator to the invalid segment before the first (i.e. an end iterator).
797  * DEPRECATED: Use the iterator range syntax instead.
798  *
799  * \return A backward end iterator.
800  */
802 
803  /**
804  * Creates a range of iterators that allows for forward iteration of the segments of the fiber
805  * this iterator currently points to. If the current iterator is not valid, behaviour is undefined.
806  * The end iterator of the returned range is the first invalid iterator after the last segment.
807  * Note that there is one segment less than there are points.
808  *
809  * \return The full range from begin to end.
810  */
812 
813  /**
814  * Creates a range of iterators that allows for reverse iteration of the segments of the fiber
815  * this iterator currently points to. If the current iterator is not valid, behaviour is undefined.
816  * The end iterator of the returned range is the first invalid iterator before the first segments.
817  * Note that there is one segment less than there are points. Additionally, note that the points
818  * returned by the start() and end() methods are also reversed, i.e. not only are the segments
819  * traversed in reverse order, but they are also oriented in the opposite direction.
820  *
821  * \return The full range from begin to end, segments in reverse order starting with the last.
822  */
824 
825  /**
826  * Returns the number of points of the current fiber.
827  *
828  * \return The number of points.
829  */
830  std::size_t numPoints() const;
831 
832  /**
833  * Get the index in the point array where the points data starts for this line. You can use \ref numPoints to know how much data to read
834  * from the vertex array.
835  *
836  * \note You should avoid using these indices as can use the iterators to query the data. But it might get handy in some situations,
837  * where raw data processing is needed.
838  *
839  * \return the start index.
840  */
841  std::size_t getLineStartIndex() const;
842 
843  /**
844  * Get the index of the line.
845  *
846  * \note You should avoid using these indices as can use the iterators to query the data. But it might get handy in some situations,
847  * where raw data processing is needed.
848  *
849  * \return the index.
850  */
851  std::size_t getIndex() const;
852 
853 
854  /**
855  * The length of the line.
856  *
857  * \note This is the actual length of the line, not the number of points.
858  * \note The length is actually calculated. So it has O(n) running time.
859  *
860  * \return line length.
861  */
862  double getFiberLength() const;
863 
864 private:
865  //! The pointer to the fibers.
867 
868  //! The current index in the fiber data.
869  std::size_t m_index;
870 };
871 
872 /**
873  * \class WFiberPointsIterator
874  *
875  * \brief An iterator for iterating the points of a fiber.
876  *
877  * Allows for both forward and backward iteration of points.
878  *
879  * There are two ways to use the iterator. First:
880  *
881  * \code{.cpp}
882  * for( WFiberPointsIterator pi = some_fiber_iterator.points().begin();
883  * pi != some_fiber_iterator.points().end(); ++pi )
884  * {
885  * ...
886  * }
887  * \endcode
888  *
889  * Second:
890  *
891  * \code{.cpp}
892  * WFiberPointsIterator pi, pe;
893  * for( ( pi, pe ) = some_fiber_iterator.points(); pi != pe; ++pi )
894  * {
895  * ...
896  * }
897  * \endcode
898  *
899  * Dereferencing the iterator provides the 3D position of the point. Other information can be
900  * gained via the various member functions.
901  *
902  * You can check whether an iterator points to a valid point of a fiber by:
903  *
904  * \code{.cpp}
905  * if( iterator )
906  * {
907  * ...
908  * }
909  * \endcode
910  */
912 {
913 public:
914  /**
915  * Default contructor. Creates an invalid iterator.
916  */
918 
919  /**
920  * Constructor. Creates an iterator pointing to a certain point of a fiber.
921  *
922  * \param fibers The pointer to the fiber data.
923  * \param fbIdx The index of the fiber in the fiber dataset.
924  * \param idx The index of the point of the current fiber.
925  * \param reverse Whether to iterate backwards.
926  */
927  WFiberPointsIterator( WDataSetFibers const* fibers, std::size_t fbIdx, std::size_t idx, bool reverse = false );
928 
929  /**
930  * Copy constructor.
931  *
932  * \param iter The iterator to copy from.
933  */
934  WFiberPointsIterator( WFiberPointsIterator const& iter ); //NOLINT explicit
935 
936  /**
937  * Destructor.
938  */
940 
941  /**
942  * Copy operator.
943  *
944  * \param iter The iterator to copy from.
945  *
946  * \return *this
947  */
949 
950  /**
951  * Increment operator. Makes the iterator point to the next point.
952  *
953  * \return The incremented iterator.
954  */
956 
957  /**
958  * Decrement operator. Makes the iterator point to the previous point.
959  *3
960  * \return The decremented iterator.
961  */
963 
964  /**
965  * Increment operator. Makes the iterator point to the next point.
966  *
967  * \return The iterator before incrementing.
968  */
970 
971  /**
972  * Decrement operator. Makes the iterator point to the previous point.
973  *
974  * \return The iterator before decrementing.
975  */
977 
978  /**
979  * Plus operator. Increments the iterator \param n times.
980  *
981  * \return The iterator on the new place.
982  */
983  WFiberPointsIterator operator+ ( size_t n );
984 
985  /**
986  * Minus operator. Decrements the iterator \param n times.
987  *
988  * \return The iterator on the new place.
989  */
990  WFiberPointsIterator operator- ( size_t n );
991 
992  /**
993  * Compare to another point iterator.
994  *
995  * \param rhs The second point iterator.
996  *
997  * \return true, iff the two iterators point to the same point of the same fiber.
998  */
999  bool operator== ( WFiberPointsIterator const& rhs ) const;
1000 
1001  /**
1002  * Compare to another point iterator.
1003  *
1004  * \param rhs The second point iterator.
1005  *
1006  * \return false, iff the two iterators point to the same point of the same fiber.
1007  */
1008  bool operator!= ( WFiberPointsIterator const& rhs ) const;
1009 
1010  /**
1011  * Creates a temporary object that is used to unpack an iterator range to two iterators.
1012  * The first of these target iterators is *this, the second is the parameter of the operator.
1013  *
1014  * \param other The iterator to assign the end iterator of the range to.
1015  * \return The unpacker to assign a range to.
1016  */
1017  WIteratorRangeUnpacker< WFiberPointsIterator > operator,( WFiberPointsIterator& other ); // NOLINT non-const ref and space intended
1018 
1019  /**
1020  * Converts to a bool that indicates whether the current iterator is valid, i.e. it points to a valid point
1021  * and it is safe to dereference or use functions such as getTangent().
1022  */
1023  operator bool() const;
1024 
1025  /**
1026  * Returns the coordinates of the point currently pointed to.
1027  *
1028  * \return The current coordinates.
1029  */
1030  WPosition operator* () const;
1031 
1032  /**
1033  * Returns the parameter specified in the vertex parameter array of the dataset. If no such array was set, the specified default will be
1034  * returned.
1035  *
1036  * \param def the default value which will be returned if no vertex parameter array was defined.
1037  * \param parameterIndex the parameter to get.
1038  *
1039  * \return the value or the specified default
1040  */
1041  double getParameter( double def = 0.0, size_t parameterIndex = 0 ) const;
1042 
1043  /**
1044  * The tangent of the point.
1045  *
1046  * \return the tangent
1047  */
1048  WPosition getTangent() const;
1049 
1050  /**
1051  * Return the color of the point.
1052  *
1053  * \return the color.
1054  */
1055  WColor getColor() const;
1056 
1057  /**
1058  * Return the color of the point.
1059  *
1060  * \param idx the index of the colorscheme to use.
1061  *
1062  * \throw WDHNoSuchDataSet if the colorscheme does not exist.
1063  *
1064  * \return the color.
1065  */
1066  WColor getColor( std::size_t idx ) const;
1067 
1068  /**
1069  * Return the color of the point.
1070  *
1071  * \param name the name of the colorscheme to use.
1072  *
1073  * \throw WDHNoSuchDataSet if the colorscheme does not exist.
1074  *
1075  * \return the color.
1076  */
1077  WColor getColor( std::string name ) const;
1078 
1079  /**
1080  * Return the color of the point.
1081  *
1082  * \param scheme the colorscheme to use.
1083  *
1084  * \throw WDHNoSuchDataSet if the colorscheme does not exist.
1085  *
1086  * \return the color.
1087  */
1088  WColor getColor( const std::shared_ptr< WDataSetFibers::ColorScheme > scheme ) const;
1089 
1090 protected:
1091  /**
1092  * Calculates the index of this point in the dataset arrays. But be aware that this index works vertex-wise. This mens, getting the y
1093  * coordinate of the vertex in the dataset vertex array, use 3 * getBaseIndex() + 1. This depends on the type of array you like to query.
1094  *
1095  * \note this function properly handles the case when walking in reverse direction.
1096  *
1097  * \return the base index, vertex-wise.
1098  */
1099  std::size_t getBaseIndex() const;
1100 
1101 private:
1102  //! The pointer to the fibers.
1104 
1105  //! The index of the fiber.
1106  std::size_t m_fiberIndex;
1107 
1108  //! The index of the current point.
1109  std::size_t m_index;
1110 
1111  //! Whether to iterate backwards.
1113 };
1114 
1115 /**
1116  * \class WFiberSegmentsIterator
1117  *
1118  * \brief An iterator for iterating the segments of a fiber.
1119  *
1120  * Allows for both forward and backward iteration of segments.
1121  *
1122  * There are two ways to use the iterator. First:
1123  *
1124  * \code{.cpp}
1125  * for( WFiberSegmentsIterator si = some_fiber_iterator.segments().begin();
1126  * si != some_fiber_iterator.segments().end(); ++si )
1127  * {
1128  * ...
1129  * }
1130  * \endcode
1131  *
1132  * Second:
1133  *
1134  * \code{.cpp}
1135  * WFiberSegmentsIterator si, se;
1136  * for( ( si, se ) = some_fiber_iterator.segments(); si != se; ++si )
1137  * {
1138  * ...
1139  * }
1140  * \endcode
1141  *
1142  * Iterators to the start and end points of the segment can be gained using the start() and end()
1143  * methods respectively. Note that for iterators set for reverse iteration, the start and end points are switched.
1144  *
1145  * You can check whether an iterator points to a valid segment of a fiber by:
1146  *
1147  * \code{.cpp}
1148  * if( iterator )
1149  * {
1150  * ...
1151  * }
1152  * \endcode
1153  */
1155 {
1156 public:
1157  /**
1158  * Default contructor. Creates an invalid iterator.
1159  */
1161 
1162  /**
1163  * Constructor. Creates an iterator pointing to a certain segment of a fiber.
1164  *
1165  * \param fibers The pointer to the fiber data.
1166  * \param fbIdx The index of the fiber in the fiber dataset.
1167  * \param idx The index of the starting point of the segment of the current fiber.
1168  * \param reverse Whether to iterate backwards.
1169  */
1170  WFiberSegmentsIterator( WDataSetFibers const* fibers, std::size_t fbIdx, std::size_t idx, bool reverse = false );
1171 
1172  /**
1173  * Copy constructor.
1174  *
1175  * \param iter The iterator to copy from.
1176  */
1177  WFiberSegmentsIterator( WFiberSegmentsIterator const& iter ); //NOLINT explicit
1178 
1179  /**
1180  * Destructor.
1181  */
1183 
1184  /**
1185  * Copy operator.
1186  *
1187  * \param iter The iterator to copy from.
1188  *
1189  * \return *this
1190  */
1192 
1193  /**
1194  * Increment operator. Makes the iterator point to the next segment.
1195  *
1196  * \return The incremented iterator.
1197  */
1199 
1200  /**
1201  * Decrement operator. Makes the iterator point to the previous segment.
1202  *3
1203  * \return The decremented iterator.
1204  */
1206 
1207  /**
1208  * Increment operator. Makes the iterator point to the next segment.
1209  *
1210  * \return The iterator before incrementing.
1211  */
1213 
1214  /**
1215  * Decrement operator. Makes the iterator point to the previous segment.
1216  *
1217  * \return The iterator before decrementing.
1218  */
1220 
1221  /**
1222  * Compare to another segment iterator.
1223  *
1224  * \param rhs The second segment iterator.
1225  *
1226  * \return true, iff the two iterators point to the same segment of the same fiber and have the same directions.
1227  */
1228  bool operator== ( WFiberSegmentsIterator const& rhs ) const;
1229 
1230  /**
1231  * Compare to another segment iterator.
1232  *
1233  * \param rhs The second segment iterator.
1234  *
1235  * \return false, iff the two iterators point to the same segment of the same fiber and have the same directions.
1236  */
1237  bool operator!= ( WFiberSegmentsIterator const& rhs ) const;
1238 
1239  /**
1240  * Creates a temporary object that is used to unpack an iterator range to two iterators.
1241  * The first of these target iterators is *this, the second is the parameter of the operator.
1242  *
1243  * \param other The iterator to assign the end iterator of the range to.
1244  * \return The unpacker to assign a range to.
1245  */
1246  WIteratorRangeUnpacker< WFiberSegmentsIterator > operator,( WFiberSegmentsIterator& other ); // NOLINT non-const ref and space intended
1247 
1248  /**
1249  * Converts to a bool that indicates whether the current iterator is valid, i.e. it points to a valid segment
1250  * and it is safe to use functions such as start().
1251  */
1252  operator bool() const;
1253 
1254  /**
1255  * Returns an iterator to the starting point of the segment.
1256  *
1257  * \return An iterator to the starting point of the segment.
1258  */
1259  WFiberPointsIterator start() const;
1260 
1261  /**
1262  * Returns an iterator to the end point of the segment.
1263  *
1264  * \return An iterator to the end point of the segment.
1265  */
1266  WFiberPointsIterator end() const;
1267 
1268  /**
1269  * Returns the vector from the starting point position to the end point position.
1270  *
1271  * \return *end() - *start()
1272  */
1273  osg::Vec3 direction() const;
1274 
1275  /**
1276  * Returns the length of the segment.
1277  *
1278  * \return segment length
1279  */
1280  double length() const;
1281 
1282 private:
1283  //! The pointer to the fibers.
1285 
1286  //! The index of the fiber.
1287  std::size_t m_fiberIndex;
1288 
1289  //! The index of the current point.
1290  std::size_t m_index;
1291 
1292  //! Whether to iterate backwards.
1294 };
1295 
1296 #endif // WDATASETFIBERS_H
Item used in the selection below also containing color info.
ColorMode m_mode
Coloring mode.
void setColor(ColorArray color, ColorMode mode=RGB)
Sets the color array for this item.
ColorArray m_color
The color array associated with the item.
ColorScheme(std::string name, std::string description, const char **icon, ColorArray color, ColorMode mode=RGB)
Constructor.
ColorMode
different kinds of color arrays can be used in this class.
@ GRAY
gray value per vertex
ColorArray getColor() const
Get the color.
ColorMode getMode() const
Returns the mode of the color scheme.
Represents a simple set of WFibers.
std::size_t getStartIndex(std::size_t fiber) const
Get the index of the first vertex of a given fiber.
void addColorScheme(WDataSetFibers::ColorArray colors, std::string name, std::string description)
This method adds a new color scheme to the list of available colors.
WPosition getTangent(size_t fiber, size_t vertex) const
calculates the tangent for a point on the fiber
std::shared_ptr< std::vector< size_t > > IndexArray
Index list indexing fibers in VertexArray in terms of vertex numbers.
std::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
void replaceColorScheme(WDataSetFibers::ColorArray oldColors, WDataSetFibers::ColorArray newColors)
Replaces the specified old color scheme by the new color scheme.
WPosition getPosition(size_t fiber, size_t vertex) const
returns the position in space for a vertex of a given fiber
void removeColorScheme(WDataSetFibers::ColorArray colors)
This method removes the specified color scheme from the list and triggers an update.
void setLineParameters(std::vector< LineParemeterArray > parameters)
Set an array to be the list of line parameters.
LineParemeterArray getLineParameters(size_t parameterIndex=0) const
Get the parameter values for each line.
TangentArray getTangents() const
Returns an array containing the tangents of the fibers at the vertices.
VertexParemeterArray getVertexParameters(size_t parameterIndex=0) const
Get the parameter values for each vertex.
VertexArray getVertices() const
Getter for the lines' vertices.
void init()
This does the common initialisation of the constructors.
WFiberIterator const_iterator
Const iterator to go through fibers.
std::shared_ptr< std::vector< float > > TangentArray
Tangents at each vertex in VertexArray.
size_t size() const
Get number of tracts in this data set.
std::shared_ptr< std::vector< size_t > > LengthArray
Lengths of fibers in terms of vertices.
std::shared_ptr< const WDataSetFibers > ConstSPtr
Pointer to const dataset.
LengthArray getLineLengths() const
Return the number of vertices for all lines.
std::shared_ptr< WDataSetFibers > SPtr
Pointer to dataset.
std::shared_ptr< std::vector< double > > VertexParemeterArray
Parameter storage for each vertex.
std::vector< LineParemeterArray > m_lineParameters
Parameter array.
WFiber operator[](size_t numTract) const
Constructs a WFiber out of the given tract number.
const WPropSelection getColorSchemeProperty() const
Returns the property controlling the color scheme selection.
std::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
IndexArray getLineStartIndexes() const
Return the indices that indicate at which vertex ID each line begins in the vertex array.
OW_API_DEPRECATED const_iterator end() const
Returns an iterator pointing beyond the last fiber.
std::vector< VertexParemeterArray > m_vertexParameters
Parameter array.
LengthArray m_lineLengths
Line vector that contains the number of vertices for each line.
IndexArray getVerticesReverse() const
Returns a reverse lookup table that allow do find out which vertex belongs to which line.
const std::shared_ptr< ColorScheme > getColorScheme() const
Convenience method returning the currently selected scheme.
WBoundingBox getBoundingBox() const
Get the bounding box.
IndexArray m_verticesReverse
Reverse lookup table for which point belongs to which fiber.
TangentArray m_tangents
Point vector for tangents at each vertex, used for fake tubes.
void setSelectedColorScheme(size_t idx)
Sets the selected color scheme.
WBoundingBox m_bb
Axis aligned bounding box for all tract-vertices of this dataset.
std::size_t getLengthOfLine(std::size_t fiber) const
Returns the number of points for a given fiber.
WDataSetFibers()
Constructs a new set of tracts.
WIteratorRange< WFiberIterator > fibers() const
Creates a range of iterators that allows for forward iteration of the fibers in this dataset.
virtual const std::string getName() const
Gets the name of this prototype.
size_t getNbVertices() const
Getter for the total number of vertices over all lines.
void setVertexParameters(std::vector< VertexParemeterArray > parameters)
Set the given array of parameters to be the vertex parameters of this fiber dataset.
virtual const std::string getDescription() const
Gets the description for this prototype.
std::shared_ptr< WItemSelection > m_colors
An array of color arrays.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
std::shared_ptr< std::vector< double > > LineParemeterArray
Parameter storage for each line.
OW_API_DEPRECATED const_iterator begin() const
Returns an iterator to the first fiber of the dataset.
IndexArray m_lineStartIndexes
Line vector that contains the start index of its first point for each line.
WFiberIterator iterator
Iterator to go through the fibers.
VertexArray m_vertices
Point vector for all fibers.
WPropSelection m_colorProp
Property keeping track of the active color in m_colors.
virtual bool isTexture() const
Determines whether this dataset can be used as a texture.
Base class for all data set types.
Definition: WDataSet.h:50
An iterator for fibers of a fiber dataset.
WFiberIterator operator-(size_t n) const
Minus operator.
OW_API_DEPRECATED WFiberPointsIterator begin()
Creates a point iterator for forward iteration, pointing to the first point of the fiber.
OW_API_DEPRECATED WFiberPointsIterator end()
Creates a point iterator for forward iteration, pointing beyond the last point of the fiber.
bool operator==(WFiberIterator const &rhs) const
Compare to another fiber iterator.
~WFiberIterator()
Destructor.
std::size_t numPoints() const
Returns the number of points of the current fiber.
OW_API_DEPRECATED WFiberSegmentsIterator srend()
Returns a backward iterator to the invalid segment before the first (i.e.
WIteratorRange< WFiberPointsIterator > pointsReverse() const
Creates a range of iterators that allows for reverse iteration of the points of the fiber this iterat...
WFiberIterator & operator=(WFiberIterator const &iter)
Copy operator.
std::size_t m_index
The current index in the fiber data.
OW_API_DEPRECATED WFiberPointsIterator rend()
Creates a point iterator for backward iteration, pointing beyond the first point of the fiber.
WIteratorRange< WFiberSegmentsIterator > segmentsReverse() const
Creates a range of iterators that allows for reverse iteration of the segments of the fiber this iter...
WIteratorRange< WFiberSegmentsIterator > segments() const
Creates a range of iterators that allows for forward iteration of the segments of the fiber this iter...
WIteratorRange< WFiberPointsIterator > points() const
Creates a range of iterators that allows for forward iteration of the points of the fiber this iterat...
std::size_t getLineStartIndex() const
Get the index in the point array where the points data starts for this line.
OW_API_DEPRECATED WFiberSegmentsIterator sbegin()
Returns a forward iterator to the first segment.
bool operator!=(WFiberIterator const &rhs) const
Compare to another fiber iterator.
WIteratorRangeUnpacker< WFiberIterator > operator,(WFiberIterator &other)
Creates a temporary object that is used to unpack an iterator range to two iterators.
OW_API_DEPRECATED WFiberSegmentsIterator send()
Returns a forward iterator to the invalid segment after the last (i.e.
double getFiberLength() const
The length of the line.
WDataSetFibers const * m_fibers
The pointer to the fibers.
WFiberIterator()
Constructor.
OW_API_DEPRECATED WFiberPointsIterator rbegin()
Creates a point iterator for backward iteration, pointing to the last point of the fiber.
WFiberIterator & operator++()
Increment operator.
WFiberIterator operator+(size_t n) const
Plus operator.
OW_API_DEPRECATED WFiberSegmentsIterator srbegin()
Returns a backward iterator to the last segment.
std::size_t getIndex() const
Get the index of the line.
WFiberIterator & operator--()
Decrement operator.
An iterator for iterating the points of a fiber.
bool m_reverse
Whether to iterate backwards.
WFiberPointsIterator operator+(size_t n)
Plus operator.
bool operator==(WFiberPointsIterator const &rhs) const
Compare to another point iterator.
std::size_t m_index
The index of the current point.
WPosition getTangent() const
The tangent of the point.
WFiberPointsIterator operator-(size_t n)
Minus operator.
WIteratorRangeUnpacker< WFiberPointsIterator > operator,(WFiberPointsIterator &other)
Creates a temporary object that is used to unpack an iterator range to two iterators.
WColor getColor() const
Return the color of the point.
WPosition operator*() const
Returns the coordinates of the point currently pointed to.
WFiberPointsIterator & operator=(WFiberPointsIterator const &iter)
Copy operator.
std::size_t m_fiberIndex
The index of the fiber.
bool operator!=(WFiberPointsIterator const &rhs) const
Compare to another point iterator.
std::size_t getBaseIndex() const
Calculates the index of this point in the dataset arrays.
WFiberPointsIterator & operator--()
Decrement operator.
WFiberPointsIterator & operator++()
Increment operator.
WFiberPointsIterator()
Default contructor.
double getParameter(double def=0.0, size_t parameterIndex=0) const
Returns the parameter specified in the vertex parameter array of the dataset.
~WFiberPointsIterator()
Destructor.
WDataSetFibers const * m_fibers
The pointer to the fibers.
An iterator for iterating the segments of a fiber.
WFiberPointsIterator start() const
Returns an iterator to the starting point of the segment.
WFiberSegmentsIterator & operator++()
Increment operator.
bool m_reverse
Whether to iterate backwards.
osg::Vec3 direction() const
Returns the vector from the starting point position to the end point position.
std::size_t m_index
The index of the current point.
WFiberSegmentsIterator()
Default contructor.
WFiberSegmentsIterator & operator--()
Decrement operator.
WIteratorRangeUnpacker< WFiberSegmentsIterator > operator,(WFiberSegmentsIterator &other)
Creates a temporary object that is used to unpack an iterator range to two iterators.
std::size_t m_fiberIndex
The index of the fiber.
double length() const
Returns the length of the segment.
~WFiberSegmentsIterator()
Destructor.
WFiberPointsIterator end() const
Returns an iterator to the end point of the segment.
bool operator!=(WFiberSegmentsIterator const &rhs) const
Compare to another segment iterator.
WFiberSegmentsIterator & operator=(WFiberSegmentsIterator const &iter)
Copy operator.
bool operator==(WFiberSegmentsIterator const &rhs) const
Compare to another segment iterator.
WDataSetFibers const * m_fibers
The pointer to the fibers.
Represents a neural pathway.
Definition: WFiber.h:40
Class for keeping a single named item in a WItemSelection.
A temporary used to unpack an iterator range into two iterators.
A range of iterators.
This only is a 3d double vector.
#define OW_API_DEPRECATED
In order to mark functions for the compiler as deprecated we need to put this before each deprecated ...
Definition: WDefines.h:44