OpenWalnut  1.5.0dev
WDataSetFibers.cpp
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 #include <algorithm>
26 #include <memory>
27 #include <numeric>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include "../common/WBoundingBox.h"
33 #include "../common/WColor.h"
34 #include "../common/WLogger.h"
35 #include "../common/WPredicateHelper.h"
36 #include "../common/WPropertyHelper.h"
37 #include "../common/datastructures/WFiber.h"
38 #include "../graphicsEngine/WGEUtils.h"
39 #include "WCreateColorArraysThread.h"
40 #include "WDataSet.h"
41 #include "WDataSetFibers.h"
42 #include "exceptions/WDHNoSuchDataSet.h"
43 
44 // prototype instance as singleton
45 std::shared_ptr< WPrototyped > WDataSetFibers::m_prototype = std::shared_ptr< WPrototyped >();
46 
47 static bool checkBelowTwo( size_t number )
48 {
49  return number < 2;
50 }
51 
53  : WDataSet()
54 {
55  // default constructor used by the prototype mechanism
56 }
57 
59  WDataSetFibers::IndexArray lineStartIndexes,
60  WDataSetFibers::LengthArray lineLengths,
61  WDataSetFibers::IndexArray verticesReverse,
62  WBoundingBox boundingBox )
63  : WDataSet(),
64  m_vertices( vertices ),
65  m_lineStartIndexes( lineStartIndexes ),
66  m_lineLengths( lineLengths ),
67  m_verticesReverse( verticesReverse ),
68  m_bb( boundingBox )
69 {
70  WAssert( m_vertices->size() % 3 == 0, "Invalid vertex array." );
71  WAssert( std::find_if( m_lineLengths->begin(), m_lineLengths->end(), checkBelowTwo ) == m_lineLengths->end(), "Invalid line lengths." );
72 
73  init();
74 }
75 
77  WDataSetFibers::IndexArray lineStartIndexes,
78  WDataSetFibers::LengthArray lineLengths,
79  WDataSetFibers::IndexArray verticesReverse )
80  : WDataSet(),
81  m_vertices( vertices ),
82  m_lineStartIndexes( lineStartIndexes ),
83  m_lineLengths( lineLengths ),
84  m_verticesReverse( verticesReverse )
85 {
86  WAssert( m_vertices->size() % 3 == 0, "Invalid vertex array." );
87  WAssert( std::find_if( m_lineLengths->begin(), m_lineLengths->end(), checkBelowTwo ) == m_lineLengths->end(), "Invalid line lengths." );
88 
89  // determine bounding box
90  for( size_t i = 0; i < vertices->size()/3; ++i )
91  {
92  m_bb.expandBy( (*vertices)[ 3 * i + 0 ], (*vertices)[ 3 * i + 1 ], (*vertices)[ 3 * i + 2 ] );
93  }
94  // remaining initilisation
95  init();
96 }
97 
99  WDataSetFibers::IndexArray lineStartIndexes,
100  WDataSetFibers::LengthArray lineLengths,
101  WDataSetFibers::IndexArray verticesReverse,
102  WBoundingBox boundingBox,
103  WDataSetFibers::VertexParemeterArray vertexParameters )
104  : WDataSet(),
105  m_vertices( vertices ),
106  m_lineStartIndexes( lineStartIndexes ),
107  m_lineLengths( lineLengths ),
108  m_verticesReverse( verticesReverse ),
109  m_bb( boundingBox ),
110  m_vertexParameters( 1, vertexParameters )
111 {
112  WAssert( m_vertices->size() % 3 == 0, "Invalid vertex array." );
113  WAssert( std::find_if( m_lineLengths->begin(), m_lineLengths->end(), checkBelowTwo ) == m_lineLengths->end(), "Invalid line lengths." );
114 
115  init();
116 }
117 
119  WDataSetFibers::IndexArray lineStartIndexes,
120  WDataSetFibers::LengthArray lineLengths,
121  WDataSetFibers::IndexArray verticesReverse,
122  WDataSetFibers::VertexParemeterArray vertexParameters )
123  : WDataSet(),
124  m_vertices( vertices ),
125  m_lineStartIndexes( lineStartIndexes ),
126  m_lineLengths( lineLengths ),
127  m_verticesReverse( verticesReverse ),
128  m_vertexParameters( 1, vertexParameters )
129 {
130  WAssert( m_vertices->size() % 3 == 0, "Invalid vertex array." );
131  WAssert( std::find_if( m_lineLengths->begin(), m_lineLengths->end(), checkBelowTwo ) == m_lineLengths->end(), "Invalid line lengths." );
132 
133  // determine bounding box
134  for( size_t i = 0; i < vertices->size()/3; ++i )
135  {
136  m_bb.expandBy( (*vertices)[ 3 * i + 0 ], (*vertices)[ 3 * i + 1 ], (*vertices)[ 3 * i + 2 ] );
137  }
138  // remaining initilisation
139  init();
140 }
141 
143 {
144  size_t size = m_vertices->size();
145  m_tangents = std::shared_ptr< std::vector< float > >( new std::vector<float>( size ) );
146 
147  std::shared_ptr< std::vector< float > > globalColors( new std::vector<float>( size ) );
148  std::shared_ptr< std::vector< float > > localColors( new std::vector<float>( size ) );
149  std::shared_ptr< std::vector< float > > customColors( new std::vector<float>( size ) );
150 
151  // TODO(all): use the new WThreadedJobs functionality
153  m_lineLengths, globalColors, localColors, m_tangents );
155  m_lineLengths, globalColors, localColors, m_tangents );
157  m_lineLengths, globalColors, localColors, m_tangents );
159  m_lineLengths, globalColors, localColors, m_tangents );
160  t1->run();
161  t2->run();
162  t3->run();
163  t4->run();
164 
165  t1->wait();
166  t2->wait();
167  t3->wait();
168  t4->wait();
169 
170  delete t1;
171  delete t2;
172  delete t3;
173  delete t4;
174 
175  // add both arrays to m_colors
176  m_colors = std::shared_ptr< WItemSelection >( new WItemSelection() );
177  m_colors->push_back( std::shared_ptr< WItemSelectionItem >(
178  new ColorScheme( "Global Color", "Colors direction by using start and end vertex per fiber.", NULL, globalColors, ColorScheme::RGB )
179  )
180  );
181  m_colors->push_back( std::shared_ptr< WItemSelectionItem >(
182  new ColorScheme( "Local Color", "Colors direction by using start and end vertex per segment.", NULL, localColors, ColorScheme::RGB )
183  )
184  );
185 
186  for( size_t i = 0; i < size; ++i )
187  {
188  ( *customColors )[i] = ( *globalColors )[i];
189  }
190  m_colors->push_back( std::shared_ptr< WItemSelectionItem >(
191  new ColorScheme( "Custom Color", "Colors copied from the global colors, will be used for bundle coloring.",
192  NULL, customColors, ColorScheme::RGB )
193  )
194  );
195 
196  // the colors can be selected by properties
197  m_colorProp = m_properties->addProperty( "Color Scheme", "Determines the coloring scheme to use for this data.", m_colors->getSelectorFirst() );
200  m_infoProperties->addProperty( "#Fibers", "The number of fibers", static_cast< WPVBaseTypes::PV_INT >( m_lineLengths->size() ) );
201  m_infoProperties->addProperty( "#Vertices", "The number of vertices", static_cast< WPVBaseTypes::PV_INT >( m_vertices->size() ) );
202 }
203 
205 {
206  return false;
207 }
208 
209 size_t WDataSetFibers::size() const
210 {
211  return m_lineStartIndexes->size();
212 }
213 
214 const std::string WDataSetFibers::getName() const
215 {
216  return "WDataSetFibers";
217 }
218 
219 const std::string WDataSetFibers::getDescription() const
220 {
221  return "Contains tracked fiber data.";
222 }
223 
224 std::shared_ptr< WPrototyped > WDataSetFibers::getPrototype()
225 {
226  if( !m_prototype )
227  {
228  m_prototype = std::shared_ptr< WPrototyped >( new WDataSetFibers() );
229  }
230 
231  return m_prototype;
232 }
233 
235 {
236  return m_vertices;
237 }
238 
240 {
241  return std::accumulate( m_lineLengths->begin(), m_lineLengths->end(), 0 );
242 }
243 
245 {
246  return m_lineStartIndexes;
247 }
248 
250 {
251  return m_lineLengths;
252 }
253 
255 {
256  return m_verticesReverse;
257 }
258 
260 {
261  return m_tangents;
262 }
263 
264 void WDataSetFibers::addColorScheme( WDataSetFibers::ColorArray colors, std::string name, std::string description )
265 {
267 
268  // number of verts is needed to distinguish color mode.
269  size_t verts = m_vertices->size() / 3;
270  WAssert( verts != 0, "If there is color there has to be vertices!" );
271 
272  size_t cols = colors->size();
273  if( cols / verts == 3 )
274  {
275  mode = ColorScheme::RGB;
276  }
277  else if( cols / verts == 4 )
278  {
279  mode = ColorScheme::RGBA;
280  }
281 
282  m_colors->push_back( std::shared_ptr< WItemSelectionItem >(
283  new ColorScheme( name, description, NULL, colors, mode )
284  )
285  );
286 }
287 
289 {
290  // this is nearly the same like std::remove_if
291  WItemSelection::WriteTicket l = m_colors->getWriteTicket();
292 
293  WItemSelection::Iterator i = l->get().begin();
294  while( i != l->get().end() )
295  {
296  if( std::static_pointer_cast< const ColorScheme >( *i )->getColor() == colors )
297  {
298  i = l->get().erase( i );
299  }
300  else
301  {
302  ++i;
303  }
304  }
305 }
306 
308 {
309  // this is nearly the same as std::replace_if
310  WItemSelection::WriteTicket l = m_colors->getWriteTicket();
311  for( WItemSelection::Iterator i = l->get().begin(); i != l->get().end(); ++i )
312  {
313  std::shared_ptr< ColorScheme > ci = std::static_pointer_cast< ColorScheme >( *i );
314  if( ci->getColor() == oldColors )
315  {
316  ci->setColor( newColors );
317  }
318  }
319 }
320 
321 const std::shared_ptr< WDataSetFibers::ColorScheme > WDataSetFibers::getColorScheme( std::string name ) const
322 {
323  WItemSelection::ReadTicket l = m_colors->getReadTicket();
324  WItemSelection::ConstIterator i = std::find_if( l->get().begin(), l->get().end(),
325  WPredicateHelper::Name< std::shared_ptr< WItemSelectionItem > >( name )
326  );
327  if( i == l->get().end() )
328  {
329  throw WDHNoSuchDataSet( std::string( "Color scheme with specified name could not be found." ) );
330  }
331 
332  return std::static_pointer_cast< ColorScheme >( *i );
333 }
334 
336 {
337  m_colorProp->set( m_colors->getSelector( idx ) );
338 }
339 
340 const std::shared_ptr< WDataSetFibers::ColorScheme > WDataSetFibers::getColorScheme( size_t idx ) const
341 {
342  WItemSelection::ReadTicket l = m_colors->getReadTicket();
343  return std::static_pointer_cast< ColorScheme >( l->get()[ idx ] );
344 }
345 
346 const std::shared_ptr< WDataSetFibers::ColorScheme > WDataSetFibers::getColorScheme() const
347 {
348  return std::static_pointer_cast< ColorScheme >( m_colorProp->get().at( 0 ) );
349 }
350 
351 const WPropSelection WDataSetFibers::getColorSchemeProperty() const
352 {
353  return m_colorProp;
354 }
355 
357 {
358  if( m_vertexParameters.empty() )
359  {
360  return NULL;
361  }
362  return m_vertexParameters[ parameterIndex ];
363 }
364 
365 void WDataSetFibers::setVertexParameters( std::vector< WDataSetFibers::VertexParemeterArray > parameters )
366 {
367  m_vertexParameters = parameters;
368 }
369 
371 {
372  return m_lineParameters[ parameterIndex ];
373 }
374 
375 void WDataSetFibers::setLineParameters( std::vector< WDataSetFibers::LineParemeterArray > parameters )
376 {
377  m_lineParameters = parameters;
378 }
379 
380 WPosition WDataSetFibers::getPosition( size_t fiber, size_t vertex ) const
381 {
382  size_t index = m_lineStartIndexes->at( fiber ) * 3;
383  index += vertex * 3;
384  return WPosition( m_vertices->at( index ), m_vertices->at( index + 1 ), m_vertices->at( index + 2 ) );
385 }
386 
387 std::size_t WDataSetFibers::getLengthOfLine( std::size_t fiber ) const
388 {
389  return m_lineLengths->at( fiber );
390 }
391 
392 std::size_t WDataSetFibers::getStartIndex( std::size_t fiber ) const
393 {
394  return m_lineStartIndexes->at( fiber );
395 }
396 
397 WPosition WDataSetFibers::getTangent( size_t fiber, size_t vertex ) const
398 {
399  WPosition point = getPosition( fiber, vertex );
400  WPosition tangent;
401 
402  if( vertex == 0 ) // first point
403  {
404  WPosition pointNext = getPosition( fiber, vertex + 1 );
405  tangent = point - pointNext;
406  }
407  else if( vertex == m_lineLengths->at( fiber ) - 1 ) // last point
408  {
409  WPosition pointBefore = getPosition( fiber, vertex - 1 );
410  tangent = pointBefore - point;
411  }
412  else // somewhere in between
413  {
414  WPosition pointBefore = getPosition( fiber, vertex - 1 );
415  WPosition pointNext = getPosition( fiber, vertex + 1 );
416  tangent = pointBefore - pointNext;
417  }
418 
419  return normalize( tangent );
420 }
421 
423 {
424  return m_bb;
425 }
426 
427 WFiber WDataSetFibers::operator[]( size_t numTract ) const
428 {
429  WAssert( numTract < m_lineLengths->size(), "WDataSetFibers: out of bounds - invalid tract number requested." );
430  WFiber result;
431  result.reserve( ( *m_lineLengths )[ numTract ] );
432  size_t vIdx = ( *m_lineStartIndexes )[ numTract ] * 3;
433  for( size_t vertexNum = 0; vertexNum < ( *m_lineLengths )[ numTract ]; ++vertexNum )
434  {
435  result.push_back( WPosition( ( *m_vertices )[vIdx], ( *m_vertices )[vIdx + 1], ( *m_vertices )[vIdx + 2] ) );
436  vIdx += 3;
437  }
438  return result;
439 }
440 
442 {
443  return WFiberIterator( this, 0 );
444 }
445 
447 {
448  return WFiberIterator( this, m_lineLengths->size() );
449 }
450 
452 {
453  return WIteratorRange< WFiberIterator >( WFiberIterator( this, 0 ), WFiberIterator( this, m_lineLengths->size() ) );
454 }
455 
457  : m_fibers( NULL ),
458  m_index( 0 )
459 {
460 }
461 
462 WFiberIterator::WFiberIterator( WDataSetFibers const* fibers, std::size_t idx )
463  : m_fibers( fibers ),
464  m_index( idx )
465 {
466 }
467 
469  : m_fibers( iter.m_fibers ),
470  m_index( iter.m_index )
471 {
472 }
473 
475 {
476 }
477 
479 {
480  if( this == &iter )
481  {
482  return *this;
483  }
484 
485  m_fibers = iter.m_fibers;
486  m_index = iter.m_index;
487 
488  return *this;
489 }
490 
492 {
493  ++m_index;
494  return *this;
495 }
496 
498 {
500  ++m_index;
501  return t;
502 }
503 
505 {
506  --m_index;
507  return *this;
508 }
509 
511 {
513  --m_index;
514  return t;
515 }
516 
518 {
519  return WFiberIterator( m_fibers, m_index + n );
520 }
521 
523 {
524  return WFiberIterator( m_fibers, m_index - n );
525 }
526 
528 {
529  return m_fibers == rhs.m_fibers && m_index == rhs.m_index;
530 }
531 
533 {
534  return !( this->operator==( rhs ) );
535 }
536 
537 WIteratorRangeUnpacker< WFiberIterator > WFiberIterator::operator,( WFiberIterator& other ) // NOLINT non-const ref and space intended
538 {
539  return WIteratorRangeUnpacker< WFiberIterator >( *this, other );
540 }
541 
542 WFiberIterator::operator bool() const
543 {
544  return m_fibers != NULL && m_index < numPoints();
545 }
546 
547 std::size_t WFiberIterator::numPoints() const
548 {
549  WAssert( m_index < m_fibers->size(), "" );
550 
551  return m_fibers->getLengthOfLine( m_index );
552 }
553 
555 {
556  return WFiberPointsIterator( m_fibers, m_index, 0 );
557 }
558 
560 {
561  WAssert( numPoints() != 0, "" );
562 
564 }
565 
567 {
568  return WFiberPointsIterator( m_fibers, m_index, 0, true );
569 }
570 
572 {
573  WAssert( numPoints() != 0, "" );
574 
575  return WFiberPointsIterator( m_fibers, m_index, numPoints(), true );
576 }
577 
579 {
580  WAssert( numPoints() != 0, "" );
581 
584 }
585 
587 {
588  WAssert( numPoints() != 0, "" );
589 
592 }
593 
595 {
597 }
598 
600 {
601  WAssert( numPoints() != 0, "" );
602 
604 }
605 
607 {
608  return WFiberSegmentsIterator( m_fibers, m_index, 0, true );
609 }
610 
612 {
613  WAssert( numPoints() != 0, "" );
614 
615  return WFiberSegmentsIterator( m_fibers, m_index, numPoints() - 1, true );
616 }
617 
619 {
620  WAssert( numPoints() != 0, "" );
621 
624 }
625 
627 {
628  WAssert( numPoints() != 0, "" );
629 
632 }
633 
635 {
636  return m_fibers->getStartIndex( m_index );
637 }
638 
639 std::size_t WFiberIterator::getIndex() const
640 {
641  return m_index;
642 }
643 
645 {
646  double length = 0.0;
647  WFiberSegmentsIterator si, se;
648  for( ( si, se ) = this->segments(); si != se; ++si )
649  {
650  length += si.length();
651  }
652  return length;
653 }
654 
656  : m_fibers( NULL ),
657  m_fiberIndex( 0 ),
658  m_index( 0 ),
659  m_reverse( false )
660 {
661 }
662 
663 WFiberPointsIterator::WFiberPointsIterator( WDataSetFibers const* fibers, std::size_t fbIdx, std::size_t idx, bool reverse )
664  : m_fibers( fibers ),
665  m_fiberIndex( fbIdx ),
666  m_index( idx ),
667  m_reverse( reverse )
668 {
669 }
670 
672  : m_fibers( iter.m_fibers ),
673  m_fiberIndex( iter.m_fiberIndex ),
674  m_index( iter.m_index ),
675  m_reverse( iter.m_reverse )
676 {
677 }
678 
680 {
681 }
682 
684 {
685  if( this == &iter )
686  {
687  return *this;
688  }
689 
690  m_fibers = iter.m_fibers;
691  m_fiberIndex = iter.m_fiberIndex;
692  m_index = iter.m_index;
693  m_reverse = iter.m_reverse;
694 
695  return *this;
696 }
697 
699 {
700  ++m_index;
701  return *this;
702 }
703 
705 {
707  ++m_index;
708  return t;
709 }
710 
712 {
713  --m_index;
714  return *this;
715 }
716 
718 {
720  --m_index;
721  return t;
722 }
723 
725 {
727 }
728 
730 {
732 }
733 
735 {
736  WAssert( m_fibers, "" );
737  WAssert( m_fiberIndex < m_fibers->size(), "Index must be smaller than the number of fibers!" );
738  WAssert( m_index < m_fibers->getLengthOfLine( m_fiberIndex ), "Point index must be smaller than the number of points!" );
739 
740  std::size_t i = m_index;
741  if( m_reverse )
742  {
743  i = m_fibers->getLengthOfLine( m_fiberIndex ) - i - 1;
744  }
745  return m_fibers->getStartIndex( m_fiberIndex ) + i;
746 }
747 
749 {
750  if( m_reverse )
751  {
753  }
755 }
756 
758 {
759  if( m_reverse != rhs.m_reverse )
760  {
761  wlog::warn( "FiberPointsIterator" ) << "Comparing a reverse and a normal iterator!";
762  }
763 
764  return m_fibers == rhs.m_fibers && m_fiberIndex == rhs.m_fiberIndex && m_index == rhs.m_index && m_reverse == rhs.m_reverse;
765 }
766 
768 {
769  return !( this->operator==( rhs ) );
770 }
771 
773 {
774  return WIteratorRangeUnpacker< WFiberPointsIterator >( *this, other );
775 }
776 
777 WFiberPointsIterator::operator bool() const
778 {
779  return m_fibers != NULL && m_fiberIndex < m_fibers->size() && m_index < m_fibers->getLengthOfLine( m_fiberIndex );
780 }
781 
782 double WFiberPointsIterator::getParameter( double def, size_t parameterIndex ) const
783 {
784  // TODO(reichenbach): change this to avoid the copy of a shared_ptr
785  if( m_fibers->getVertexParameters( parameterIndex ) )
786  {
787  return m_fibers->getVertexParameters( parameterIndex )->operator[]( getBaseIndex() );
788  }
789  return def;
790 }
791 
793 {
794  if( m_reverse )
797 }
798 
799 WColor WFiberPointsIterator::getColor( const std::shared_ptr< WDataSetFibers::ColorScheme > scheme ) const
800 {
801  std::size_t v = getBaseIndex();
802  WColor ret;
803  switch( scheme->getMode() )
804  {
806  {
807  double r = scheme->getColor()->operator[]( 1 * v + 0 );
808  ret.set( r, r, r, 1.0 );
809  }
810  break;
812  {
813  double r = scheme->getColor()->operator[]( 3 * v + 0 );
814  double g = scheme->getColor()->operator[]( 3 * v + 1 );
815  double b = scheme->getColor()->operator[]( 3 * v + 2 );
816  ret.set( r, g, b, 1.0 );
817  }
818  break;
820  {
821  double r = scheme->getColor()->operator[]( 4 * v + 0 );
822  double g = scheme->getColor()->operator[]( 4 * v + 1 );
823  double b = scheme->getColor()->operator[]( 4 * v + 2 );
824  double a = scheme->getColor()->operator[]( 4 * v + 3 );
825  ret.set( r, g, b, a );
826  }
827  break;
828  default:
829  ret.set( 1.0, 1.0, 1.0, 1.0 );
830  break;
831  }
832  return ret;
833 }
834 
836 {
837  return getColor( m_fibers->getColorScheme() );
838 }
839 
840 WColor WFiberPointsIterator::getColor( std::size_t idx ) const
841 {
842  return getColor( m_fibers->getColorScheme( idx ) );
843 }
844 
845 WColor WFiberPointsIterator::getColor( std::string name ) const
846 {
847  return getColor( m_fibers->getColorScheme( name ) );
848 }
849 
851  : m_fibers( NULL ),
852  m_fiberIndex( 0 ),
853  m_index( 0 ),
854  m_reverse( false )
855 {
856 }
857 
858 WFiberSegmentsIterator::WFiberSegmentsIterator( WDataSetFibers const* fibers, std::size_t fbIdx, std::size_t idx, bool reverse )
859  : m_fibers( fibers ),
860  m_fiberIndex( fbIdx ),
861  m_index( idx ),
862  m_reverse( reverse )
863 {
864 }
865 
867  : m_fibers( iter.m_fibers ),
868  m_fiberIndex( iter.m_fiberIndex ),
869  m_index( iter.m_index ),
870  m_reverse( iter.m_reverse )
871 {
872 }
873 
875 {
876 }
877 
879 {
880  if( this == &iter )
881  {
882  return *this;
883  }
884 
885  m_fibers = iter.m_fibers;
886  m_fiberIndex = iter.m_fiberIndex;
887  m_index = iter.m_index;
888  m_reverse = iter.m_reverse;
889 
890  return *this;
891 }
892 
894 {
895  ++m_index;
896  return *this;
897 }
898 
900 {
902  ++m_index;
903  return t;
904 }
905 
907 {
908  --m_index;
909  return *this;
910 }
911 
913 {
915  --m_index;
916  return t;
917 }
918 
920 {
921  if( m_reverse != rhs.m_reverse )
922  {
923  wlog::warn( "WFiberSegmentsIterator" ) << "Comparing a reverse and a normal iterator!";
924  }
925 
926  return m_fibers == rhs.m_fibers && m_fiberIndex == rhs.m_fiberIndex && m_index == rhs.m_index && m_reverse == rhs.m_reverse;
927 }
928 
930 {
931  return !( this->operator==( rhs ) );
932 }
933 
935 {
937 }
938 
939 WFiberSegmentsIterator::operator bool() const
940 {
941  return m_fibers != NULL && m_fiberIndex < m_fibers->size() && m_index < m_fibers->getLengthOfLine( m_fiberIndex ) - 1;
942 }
943 
945 {
947 }
948 
950 {
952 }
953 
955 {
957  return osg::Vec3( 0.0, 0.0, 0.0 );
958 
959  return *end() - *start();
960 }
961 
963 {
964  return distance( *start(), *end() );
965 }
void expandBy(const WBoundingBoxImpl< VT > &bb)
Expands this bounding box to include the given bounding box.
Definition: WBoundingBox.h:240
Thread for computing directional color coding of fibers.
Should be thrown when an invalid index is used to get a WDataSet from the WSubject.
Item used in the selection below also containing color info.
ColorMode
different kinds of color arrays can be used in this class.
@ GRAY
gray value per vertex
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.
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.
LengthArray getLineLengths() const
Return the number of vertices for all lines.
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.
const std::shared_ptr< ColorScheme > getColorScheme(std::string name) const
Get the color scheme with the specified name.
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.
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
std::shared_ptr< WProperties > m_infoProperties
The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION".
Definition: WDataSet.h:181
std::shared_ptr< WProperties > m_properties
The property object for the dataset.
Definition: WDataSet.h:174
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
A class containing a list of named items.
A temporary used to unpack an iterator range into two iterators.
A range of iterators.
void reserve(size_type new_capacity)
Wrapper around std::vector member function.
Definition: WMixinVector.h:227
void push_back(const value_type &value)
Wrapper around std::vector member function.
Definition: WMixinVector.h:457
This only is a 3d double vector.
This class tests against the getName() method of the instances of type T.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:65
std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
Definition: WSharedObject.h:70
S::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
S::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
virtual void run()
Run thread.
void wait(bool requestFinish=false)
Wait for the thread to be finished.
int32_t PV_INT
base type used for every WPVInt
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
WStreamedLogger warn(const std::string &source)
Logging a warning message.
Definition: WLogger.h:309