aimsdata  5.0.5
Neuroimaging data handling
bundles.h
Go to the documentation of this file.
1 /* Copyright (c) 1995-2005 CEA
2  *
3  * This software and supporting documentation were developed by
4  * CEA/DSV/SHFJ
5  * 4 place du General Leclerc
6  * 91401 Orsay cedex
7  * France
8  *
9  * This software is governed by the CeCILL license version 2 under
10  * French law and abiding by the rules of distribution of free software.
11  * You can use, modify and/or redistribute the software under the
12  * terms of the CeCILL license version 2 as circulated by CEA, CNRS
13  * and INRIA at the following URL "http://www.cecill.info".
14  *
15  * As a counterpart to the access to the source code and rights to copy,
16  * modify and redistribute granted by the license, users are provided only
17  * with a limited warranty and the software's author, the holder of the
18  * economic rights, and the successive licensors have only limited
19  * liability.
20  *
21  * In this respect, the user's attention is drawn to the risks associated
22  * with loading, using, modifying and/or developing or reproducing the
23  * software by the user in light of its specific status of free software,
24  * that may mean that it is complicated to manipulate, and that also
25  * therefore means that it is reserved for developers and experienced
26  * professionals having in-depth computer knowledge. Users are therefore
27  * encouraged to load and test the software's suitability as regards their
28  * requirements in conditions enabling the security of their systems and/or
29  * data to be ensured and, more generally, to use and operate it in the
30  * same conditions as regards security.
31  *
32  * The fact that you are presently reading this means that you have had
33  * knowledge of the CeCILL license version 2 and that you accept its terms.
34  */
35 
36 #ifndef AIMS_FIBERS_BUNDLES_H
37 #define AIMS_FIBERS_BUNDLES_H
38 
39 #include <aims/curve/curve.h>
40 #include <aims/mesh/surface.h>
41 #include <aims/vector/vector.h>
42 #include <aims/resampling/motion.h>
43 #include <aims/io/motionR.h>
44 #include <aims/roi/roiIterator.h>
45 #include <graph/graph/graph.h>
46 #include <cartobase/smart/rcptr.h>
49 #include <fstream>
50 #include <vector>
51 #include <map>
52 #include <string>
53 
54 
55 namespace aims
56 {
57 
58 
59  //----------//
60  // Bundle //
61 //----------//
62 
63 class Bundle : public std::vector< aims::Polyline >
64 {
65 };
66 
67 
68  //-----------//
69  // Bundles //
70 //-----------//
71 
72 class Bundles : public std::map< std::string, Bundle >
73 {
74 };
75 
76 
77  //------------------------------------------------//
78  // Froward classes, smart pointers and typedefs //
79 //------------------------------------------------//
80 
81 class Bundle;
82 class BundleListener;
84 
88 
90 
91 
92  //-------------//
93  // FiberInfo //
94 //-------------//
95 
96 class FiberInfo
97 {
98 public:
99 
100  inline FiberInfo();
101  inline FiberInfo( int id );
102  inline int id() const;
103 
104 protected:
105 
106  int _id;
107 };
108 
109 
110  //--------------//
111  // BundleInfo //
112 //--------------//
113 
115 {
116 public:
117 
118  inline BundleInfo();
119  inline BundleInfo( const std::string &name );
120  inline BundleInfo( int id );
121  inline BundleInfo( int id, const std::string &name );
122  inline int id() const;
123  inline std::string name() const;
124 
125 protected:
126 
127  int _id;
128  std::string _name;
129 };
130 
131 
132  //------------------//
133  // BundleListener //
134 //------------------//
135 
153 {
154 protected:
155 
156  friend class BundleProducer;
157 
158  virtual void bundleStarted( const BundleProducer &, const BundleInfo & ) ;
159  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
160  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
161  const FiberInfo & );
162  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
163  const FiberInfo & );
164  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
165  const FiberInfo &, const FiberPoint & );
166  virtual void noMoreBundle( const BundleProducer & );
167 
168 public:
169  virtual ~BundleListener();
170 };
171 
172 
173  //------------------//
174  // BundleProducer //
175 //------------------//
176 
186 {
187 public:
188 
189  void addBundleListener( BundleListener & );
190 
191 protected:
192 
193  void startBundle( const BundleInfo & );
194  void terminateBundle( const BundleInfo & );
195  void startFiber( const BundleInfo &, const FiberInfo & );
196  void terminateFiber( const BundleInfo &, const FiberInfo & );
197  void addFiberPoint( const BundleInfo &, const FiberInfo &,
198  const FiberPoint & );
199  void noMoreBundle();
200 
201 private:
202 
203  typedef std::vector< BundleListener * > BundleListenerList;
204  BundleListenerList _bundleListeners;
205 };
206 
207 
208 
209  //----------------//
210  // BundleWriter //
211 //----------------//
212 
213 // WARNING : This class should be a real writer in aimsdata but I prefer to
214 // keep it here until the format is a bit more stable.
215 
222 class BundleWriter : public virtual BundleListener, public carto::PropertySet
223 {
224 public:
225 
226  BundleWriter();
228  void setFileString( const std::string &fileName );
229  virtual ~BundleWriter();
230 
231  typedef std::vector< FiberPoint > FiberPoints;
232 
233  virtual void bundleStarted( const BundleProducer &, const BundleInfo & );
234  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
235  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
236  const FiberInfo & );
237  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
238  const FiberInfo & );
239  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
240  const FiberInfo &, const FiberPoint & );
241  virtual void noMoreBundle( const BundleProducer & );
242  virtual void checkStreams();
243  virtual void addFiber( const BundleProducer &, const BundleInfo &,
244  const FiberInfo &, FiberPoint*, int &);
245 
246 protected:
247  int _ascii;
248  std::string _fileName;
250  std::ofstream _dataFile;
253  FiberPoints _fiberPoints;
254 };
255 
256 
257 
258  //----------------//
259  // BundleReader //
260 //----------------//
261 
262 // WARNING : This class should be a real writer in aimsdata but I prefer to
263 // keep it here until the format is a bit more stable.
264 
273 {
274 public:
275 
276  BundleReader( const std::string &fileName );
277  virtual ~BundleReader();
278 
281  void read();
282  virtual carto::Object readHeader();
283  static std::set<std::string> supportedFormats();
284  static std::set<std::string> formatExtensions(
285  const std::string & format = "ALL" );
286 
287 protected:
288 
289  virtual void bundleStarted( const BundleProducer &, const BundleInfo & );
290  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
291  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
292  const FiberInfo & );
293  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
294  const FiberInfo & );
295  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
296  const FiberInfo &, const FiberPoint & );
297  virtual void noMoreBundle( const BundleProducer & );
298 
299 private:
300 
301  std::string _fileName;
302 };
303 
304 
305  //----------------------//
306  // BundleFormatReader //
307 //----------------------//
308 
309 // WARNING : This class should be a real writer in aimsdata but I prefer to
310 // keep it here until the format is a bit more stable.
311 
315 {
316 public:
317 
319  virtual ~BundleFormatReader();
320 
321  virtual void read() = 0;
322  virtual carto::Object readHeader();
323 
324 private:
325 
326  std::string _fileName;
327 };
328 
329 
335 {
336 public:
337 
338  ConnectomistBundlesReader( const std::string &fileName );
339  virtual ~ConnectomistBundlesReader();
340 
341  virtual void read();
342  virtual carto::Object readHeader();
343 
344 private:
345 
346  std::string _fileName;
347 };
348 
349 
350  //-----------------//
351  // BundleToGraph //
352 //-----------------//
353 
363  virtual public carto::PropertySet
364 {
365 public:
366 
367  BundleToGraph();
368  BundleToGraph( Graph & );
369  virtual ~BundleToGraph();
370 
371  inline const carto::rc_ptr< Graph > &getGraph() const;
372 
373 protected:
374 
375  virtual void bundleStarted( const BundleProducer &, const BundleInfo & );
376  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
377  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
378  const FiberInfo & );
379  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
380  const FiberInfo & );
381  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
382  const FiberInfo &, const FiberPoint & );
383  virtual void noMoreBundle( const BundleProducer & );
384  virtual void parametersValueChanged();
385  void parameterChangedSlot( const carto::Object &, const std::string &,
386  const carto::Object & );
387  void shuffleBundle();
388 
392  float _width;
394  std::vector< Point2df > _section;
395  std::vector<int> _boundingbox_min;
396  std::vector<int> _boundingbox_max;
400 
406 };
407 
408 
409 
410  //-----------------------//
411  // BundleToGraphWriter //
412 //-----------------------//
413 
415 {
416 public:
417 
418  inline virtual ~BundleToGraphWriter();
419 
420  void setFileString( const std::string & );
421 
422 protected:
423 
424  virtual void noMoreBundle( const BundleProducer & );
425 
426 private:
427 
428  std::string _fileName;
429 };
430 
431 
432  //------------------//
433  // BundleROISplit //
434 //------------------//
435 
437 {
438 public:
439 
441  bool keepOriginalBundle = false );
442  virtual ~BundleROISplit();
443 
444 protected:
445 
446  virtual void bundleStarted( const BundleProducer &, const BundleInfo & );
447  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
448  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
449  const FiberInfo & );
450  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
451  const FiberInfo & );
452  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
453  const FiberInfo &, const FiberPoint & );
454  virtual void noMoreBundle( const BundleProducer & );
455 
456 private:
457 
459 
460  typedef std::vector< FiberPoint > FiberPoints;
461  typedef std::vector< FiberPoints > Fibers;
462 
463  std::map< std::string, std::map< std::pair<int,int>, Fibers > >
464  _result;
465 
466  int _currentLabel;
467  int _lastLabel;
468  FiberPoints _currentPoints;
469  bool _keepOriginalBundle;
470 };
471 
472 
473 
474  //-------------------//
475  // BundleROISelect //
476 //-------------------//
477 
479 {
480 public:
481 
483  const std::string &,
484  float defaultROIMinimumOverlap = 0 );
485  virtual ~BundleROISelect();
486 
487 protected:
488 
489  virtual void bundleStarted( const BundleProducer &, const BundleInfo & );
490  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
491  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
492  const FiberInfo & );
493  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
494  const FiberInfo & );
495  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
496  const FiberInfo &, const FiberPoint & );
497  virtual void noMoreBundle( const BundleProducer & );
498 
499 private:
500 
502 
503  typedef std::vector< FiberPoint > FiberPoints;
504 
505  std::vector< uint32_t > _crossedROI;
506  FiberPoints _currentPoints;
507  std::map< std::string, std::vector< FiberPoints > > _result;
508 
509  struct SelectionRule
510  {
511  std::string name;
512  uint32_t min, max;
513  std::vector< bool > mustBeCrossed;
514  };
515  std::vector< SelectionRule > _selectionRules;
516  float _defaultROIMinimumOverlap;
517 };
518 
519 
520 
521  //----------------//
522  // BundleMotion //
523 //----------------//
524 
526 {
527 public:
528 
529  BundleMotion( const std::string & );
530  BundleMotion( const Motion & );
531  virtual ~BundleMotion();
532 
533 protected:
534 
535  virtual void bundleStarted( const BundleProducer &, const BundleInfo & );
536  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
537  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
538  const FiberInfo & );
539  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
540  const FiberInfo & );
541  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
542  const FiberInfo &, const FiberPoint & );
543  virtual void noMoreBundle( const BundleProducer & );
544 
545 private:
546 
547  Motion _motion;
548 };
549 
550 
551  //------------------//
552  // CurveSelection //
553 //------------------//
554 
556 {
557 public:
558 
559  CurveSelection( const double &minimumLength );
560  virtual ~CurveSelection();
561 
562 protected:
563 
564  typedef std::vector< FiberPoint > FiberPoints;
565 
566  virtual void bundleStarted( const BundleProducer &, const BundleInfo & );
567  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
568  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
569  const FiberInfo & );
570  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
571  const FiberInfo & );
572  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
573  const FiberInfo &, const FiberPoint & );
574  virtual void noMoreBundle( const BundleProducer & );
575 
576 private:
577 
578  double _minimumLength;
579  double _currentLength;
580  FiberPoints _currentPoints;
581 };
582 
583 
584  //--------------------//
585  // CurveOrientation //
586 //--------------------//
587 
589 {
590 public:
591 
593  virtual ~CurveOrientation();
594 
595 protected:
596 
597  typedef std::vector< FiberPoint > FiberPoints;
598 
599  virtual void bundleStarted( const BundleProducer &, const BundleInfo & );
600  virtual void bundleTerminated( const BundleProducer &, const BundleInfo & );
601  virtual void fiberStarted( const BundleProducer &, const BundleInfo &,
602  const FiberInfo & );
603  virtual void fiberTerminated( const BundleProducer &, const BundleInfo &,
604  const FiberInfo & );
605  virtual void newFiberPoint( const BundleProducer &, const BundleInfo &,
606  const FiberInfo &, const FiberPoint & );
607  virtual void noMoreBundle( const BundleProducer & );
608 
609 private:
610 
611  FiberPoint _beginSum;
613  FiberPoints _currentPoints;
614 };
615 
616 
617 
618 
619  //-------------//
620  // FiberInfo //
621 //-------------//
622 
623 //-----------------------------------------------------------------------------
625 {}
626 
627 
628 //-----------------------------------------------------------------------------
629 inline FiberInfo::FiberInfo( int id ) :
630  _id( id )
631 {}
632 
633 
634 //-----------------------------------------------------------------------------
635 inline int FiberInfo::id() const
636 {
637  return _id;
638 }
639 
640 
641 
642  //--------------//
643  // BundleInfo //
644 //--------------//
645 
646 //-----------------------------------------------------------------------------
648 {}
649 
650 
651 //-----------------------------------------------------------------------------
652 inline BundleInfo::BundleInfo( const std::string &name ) :
653  _name( name )
654 {}
655 
656 
657 //-----------------------------------------------------------------------------
658 inline BundleInfo::BundleInfo( int id ) :
659  _id( id )
660 {}
661 
662 
663 //-----------------------------------------------------------------------------
664 inline BundleInfo::BundleInfo( int id, const std::string &name ) :
665  _id( id ), _name( name )
666 {}
667 
668 
669 //-----------------------------------------------------------------------------
670 inline std::string BundleInfo::name() const
671 {
672  return _name;
673 }
674 
675 
676 //-----------------------------------------------------------------------------
677 inline int BundleInfo::id() const
678 {
679  return _id;
680 }
681 
682 
683 
684  //-----------------//
685  // BundleToGraph //
686 //-----------------//
687 
688 //-----------------------------------------------------------------------------
690 {
691  return _rcptrMeshResult;
692 }
693 
694 
695  //-----------------------//
696  // BundleToGraphWriter //
697 //-----------------------//
698 
699 //-----------------------------------------------------------------------------
701 {
702 }
703 
704 } // namespace comist
705 
706 #endif // ifndef AIMS_FIBERS_BUNDLES_H
std::string _name
Definition: bundles.h:128
carto::rc_ptr< AimsSurfaceTriangle > _currentMesh
Definition: bundles.h:403
float _minimumLength
Definition: bundles.h:391
std::vector< FiberPoint > FiberPoints
Definition: bundles.h:597
std::string name() const
Definition: bundles.h:670
Graph * _meshResult
Definition: bundles.h:389
std::vector< FiberPoint > FiberPoints
Definition: bundles.h:231
Reads a bundles file, and emits events while walking through its data.
Definition: bundles.h:272
Serial processing of bundles.
Definition: bundles.h:152
T max(const Volume< T > &vol)
carto::rc_ptr< AimsTimeSurface< 2, Void > > _currentLines
Definition: bundles.h:404
bool _normalsAsFiberStartPos
Definition: bundles.h:397
std::vector< Fiber > Fibers
Definition: bundleRegroup.h:51
Point3df _relatveFiberStartPos
Definition: bundles.h:398
The class for EcatSino data write operation.
Definition: border.h:44
carto::rc_ptr< Graph > _rcptrMeshResult
Definition: bundles.h:390
std::vector< int > _boundingbox_max
Definition: bundles.h:396
carto::rc_ptr< BundleListener > RBundleListener
Definition: bundles.h:86
virtual ~BundleToGraphWriter()
Definition: bundles.h:700
Connectomist .bundles format reader.
Definition: bundles.h:334
std::ofstream _dataFile
Definition: bundles.h:250
T min(const Volume< T > &vol)
Vertex * _currentVertex
Definition: bundles.h:401
float Scalar_t
Definition: curve.h:54
int _firstFiberInBundle
Definition: bundles.h:251
const carto::rc_ptr< Graph > & getGraph() const
Definition: bundles.h:689
bool _autoFiberStartPos
Definition: bundles.h:399
Virtual base class for bundles/fibers file formats support.
Definition: bundles.h:314
std::vector< Point2df > _section
Definition: bundles.h:394
Serial processing of bundles.
Definition: bundles.h:185
std::string _fileName
Definition: bundles.h:248
size_t _current_fibers_count
Definition: bundles.h:405
FiberPoints _fiberPoints
Definition: bundles.h:253
int id() const
Definition: bundles.h:677
std::vector< FiberPoint > FiberPoints
Definition: bundles.h:564
int _writtenFibersCount
Definition: bundles.h:252
int id() const
Definition: bundles.h:635
aims::Polyline _currentCurve
Definition: bundles.h:402
Writes bundles information to a bundles file.
Definition: bundles.h:222
carto::rc_ptr< BundleProducer > RBundleProducer
Definition: bundles.h:87
int _numPointsInMeshSection
Definition: bundles.h:393
carto::rc_ptr< Bundle > RBundle
Definition: bundles.h:83
carto::Object _header
Definition: bundles.h:249
Affine 3D transformation.
Bundles structure building as a Graph.
Definition: bundles.h:362
aims::Polyline::Point_t FiberPoint
Definition: bundles.h:89
std::vector< int > _boundingbox_min
Definition: bundles.h:395