]> Creatis software - cpPlugins.git/blob - lib/cpInstances/BoundingBox.h
...
[cpPlugins.git] / lib / cpInstances / BoundingBox.h
1 #ifndef __cpInstances__BoundingBox__h__
2 #define __cpInstances__BoundingBox__h__
3
4 #include <cpInstances/cpInstancesBoundingBox_Export.h>
5 #include <vector>
6 #include <cpPlugins/BaseObjects/DataObject.h>
7 #include <vtkOutlineSource.h>
8 #include <vtkSmartPointer.h>
9
10 namespace cpInstances
11 {
12   /**
13    */
14   class cpInstancesBoundingBox_EXPORT BoundingBox
15     : public cpPlugins::BaseObjects::DataObject
16   {
17   public:
18     typedef BoundingBox                        Self;
19     typedef cpPlugins::BaseObjects::DataObject Superclass;
20     typedef itk::SmartPointer< Self >          Pointer;
21     typedef itk::SmartPointer< const Self >    ConstPointer;
22
23   public:
24     itkNewMacro( Self );
25     itkTypeMacro( BoundingBox, DataObject );
26     cpPlugins_Id_Macro( BoundingBox, Object );
27     cpPlugins_Compatibility_Macro;
28
29   public:
30     void SetDataObject( DataObject* o );
31
32     void Copy( Self* other );
33     void Blend( Self* other );
34
35     template< class _TPoint >
36     inline void SetMinimum( const _TPoint& p )
37       {
38         this->_SetPoint( 0, p );
39       }
40
41     template< class _TPoint >
42     inline void SetMaximum( const _TPoint& p )
43       {
44         this->_SetPoint( 1, p );
45       }
46
47     template< class _TPoint >
48     inline _TPoint GetMinimum( ) const
49       {
50         return( this->_GetPoint< _TPoint >( 0 ) );
51       }
52
53     template< class _TPoint >
54     inline _TPoint GetMaximum( ) const
55       {
56         return( this->_GetPoint< _TPoint >( 1 ) );
57       }
58
59   protected:
60     BoundingBox( );
61     virtual ~BoundingBox( );
62
63     void _UpdateVTK( );
64
65     template< class _TPoint >
66     inline void _SetPoint( unsigned int m, const _TPoint& p )
67       {
68         this->m_Points[ m ].clear( );
69         for( unsigned int d = 0; d < _TPoint::PointDimension; ++d )
70           this->m_Points[ m ].push_back( double( p[ d ] ) );
71         this->_UpdateVTK( );
72         this->Modified( );
73       }
74
75     template< class _TPoint >
76     inline _TPoint _GetPoint( unsigned int m ) const
77       {
78         unsigned int dim = this->m_Points[ m ].size( );
79         dim =
80           ( _TPoint::PointDimension < dim )? _TPoint::PointDimension: dim;
81         _TPoint p;
82         p.Fill( 0 );
83         for( unsigned int d = 0; d < dim; ++d )
84           p[ d ] = this->m_Points[ m ][ d ];
85         return( p );
86       }
87
88   private:
89     // Purposely not implemented
90     BoundingBox( const Self& );
91     Self& operator=( const Self& );
92
93   protected:
94     std::vector< double > m_Points[ 2 ];
95     vtkSmartPointer< vtkOutlineSource > m_Outline;
96   };
97
98 } // ecapseman
99
100 #endif // __cpInstances__BoundingBox__h__
101
102 // eof - $RCSfile$