KWStyle - itkVectorImage.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkVectorImage.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:49 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 =========================================================================*/
20 DEF #ifndef _itkVectorImage_txx
21 DEF #define _itkVectorImage_txx
22 #include "itkVectorImage.h"
23 #include "itkProcessObject.h"
24
25 namespace itk
26 {
27
28 /**
29  *
30  */
31 template<class TPixel, unsigned int VImageDimension>
32 VectorImage<TPixel, VImageDimension>
33 ::VectorImage() 
34 IND ******: m_VectorLength( 0 )
35 {
36   m_Buffer = PixelContainer::New();
37 }
38
39
40 //----------------------------------------------------------------------------
41 template<class TPixel, unsigned int VImageDimension>
42 void 
43 VectorImage<TPixel, VImageDimension>
44 ::Allocate()
45 {
46   if ( m_VectorLength == 0 )
47     {
48     itkExceptionMacro( << "Cannot allocate VectorImage with VectorLength = 0");
49     }
50   
51   unsigned long num;
52   this->ComputeOffsetTable();
53   num = this->GetOffsetTable()[VImageDimension];
54   
55   m_Buffer->Reserve(num * m_VectorLength);
56 }
57
58 template<class TPixel, unsigned int VImageDimension>
59 void 
60 VectorImage<TPixel, VImageDimension>
61 ::Initialize()
62 {
63   //
64   // We don't modify ourselves because the "ReleaseData" methods depend upon
65   // no modification when initialized.
66   //
67
68   // Call the superclass which should initialize the BufferedRegion ivar.
69   Superclass::Initialize();
70
71   // Replace the handle to the buffer. This is the safest thing to do,
72   // since the same container can be shared by multiple images (e.g.
73   // Grafted outputs and in place filters).
74   m_Buffer = PixelContainer::New();
75 }
76
77
78 template<class TPixel, unsigned int VImageDimension>
79 void 
80 VectorImage<TPixel, VImageDimension>
81 ::FillBuffer(const PixelType& value)
82 {
83   const unsigned long numberOfPixels =
84 IND ****this->GetBufferedRegion().GetNumberOfPixels();
85
86   unsigned long ctr = 0;
87   for(unsigned int i=0; i<numberOfPixels; i++) 
88     {
89     for( VectorLengthType j=0; j<m_VectorLength; j++ )
90       {
91       (*m_Buffer)[ctr++] = value[j];
92       }
93     }
94 }
95
96 template<class TPixel, unsigned int VImageDimension>
97 void 
98 VectorImage<TPixel, VImageDimension>
99 ::SetPixelContainer(PixelContainer *container)
100 {
101   if (m_Buffer != container)
102     {
103     m_Buffer = container;
104     this->Modified();
105     }
106 }
107     
108 //----------------------------------------------------------------------------
109 template<class TPixel, unsigned int VImageDimension>
110 void 
111 VectorImage<TPixel, VImageDimension>
112 ::Graft(const DataObject *data)
113 {
114   // call the superclass' implementation
115   Superclass::Graft( data );
116
117   if ( data )
118     {
119     // Attempt to cast data to an Image
120     const Self *imgData;
121
122     try
123       {
124       imgData = dynamic_cast< const Self *>( data );
125       }
126     catch( ... )
127       {
128       return;
129       }
130
131     // Copy from VectorImage< TPixel, dim >
132     if ( imgData )
133       {
134       // Now copy anything remaining that is needed
135       this->SetPixelContainer( const_cast< PixelContainer *>
136                                     (imgData->GetPixelContainer()) );
137       }
138     else 
139       {
140       // pointer could not be cast back down
141       itkExceptionMacro( << "itk::VectorImage::Graft() cannot cast "
142                          << typeid(data).name() << " to "
143                          << typeid(const Self *).name() );
144       }
145     }
146 }
147
148 //----------------------------------------------------------------------------
149 template<class TPixel, unsigned int VImageDimension>
150 unsigned int  
151 VectorImage<TPixel, VImageDimension>
152 ::GetNumberOfComponentsPerPixel() const
153 {
154   return this->m_VectorLength;
155 }
156   
157 //----------------------------------------------------------------------------
158 template<class TPixel, unsigned int VImageDimension>
159 void
160 VectorImage<TPixel, VImageDimension>
161 ::SetNumberOfComponentsPerPixel( unsigned int n )
162 {
163   this->SetVectorLength( static_cast< VectorLengthType >(n) );
164 }
165
166 /**
167  *
168  */
169 template<class TPixel, unsigned int VImageDimension>
170 void 
171 VectorImage<TPixel, VImageDimension>
172 ::PrintSelf(std::ostream& os, Indent indent) const
173 {
174   Superclass::PrintSelf(os,indent);
175   
176   os << indent << "VectorLength: " << m_VectorLength << std::endl;
177   os << indent << "PixelContainer: " << std::endl;
178   m_Buffer->Print(os, indent.GetNextIndent());
179
180 IND // m_Origin and m_Spacing are printed in the Superclass
181 }
182 // end namespace itk
183
184 #endif
185

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:52PM
© Kitware Inc.