KWStyle - itkImage.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkImage.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:36 $
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 _itkImage_txx
21 DEF #define _itkImage_txx
22 #include "itkImage.h"
23 #include "itkProcessObject.h"
24
25 namespace itk
26 {
27
28 /**
29  *
30  */
31 template<class TPixel, unsigned int VImageDimension>
32 Image<TPixel, VImageDimension>
33 ::Image()
34 {
35   m_Buffer = PixelContainer::New();
36 }
37
38
39 //----------------------------------------------------------------------------
40 template<class TPixel, unsigned int VImageDimension>
41 void 
42 Image<TPixel, VImageDimension>
43 ::Allocate()
44 {
45   unsigned long num;
46
47   this->ComputeOffsetTable();
48   num = this->GetOffsetTable()[VImageDimension];
49   
50   m_Buffer->Reserve(num);
51 }
52
53 template<class TPixel, unsigned int VImageDimension>
54 void 
55 Image<TPixel, VImageDimension>
56 ::Initialize()
57 {
58   //
59   // We don't modify ourselves because the "ReleaseData" methods depend upon
60   // no modification when initialized.
61   //
62
63   // Call the superclass which should initialize the BufferedRegion ivar.
64   Superclass::Initialize();
65
66   // Replace the handle to the buffer. This is the safest thing to do,
67   // since the same container can be shared by multiple images (e.g.
68   // Grafted outputs and in place filters).
69   m_Buffer = PixelContainer::New();
70 }
71
72
73 template<class TPixel, unsigned int VImageDimension>
74 void 
75 Image<TPixel, VImageDimension>
76 ::FillBuffer (const TPixel& value)
77 {
78   const unsigned long numberOfPixels =
79 IND ****this->GetBufferedRegion().GetNumberOfPixels();
80
81   for(unsigned int i=0; i<numberOfPixels; i++) 
82     {
83     (*m_Buffer)[i] = value;
84     }
85 }
86
87 template<class TPixel, unsigned int VImageDimension>
88 void 
89 Image<TPixel, VImageDimension>
90 ::SetPixelContainer(PixelContainer *container)
91 {
92   if (m_Buffer != container)
93     {
94     m_Buffer = container;
95     this->Modified();
96     }
97 }
98     
99 //----------------------------------------------------------------------------
100 template<class TPixel, unsigned int VImageDimension>
101 void 
102 Image<TPixel, VImageDimension>
103 ::Graft(const DataObject *data)
104 {
105   // call the superclass' implementation
106   Superclass::Graft( data );
107
108   if ( data )
109     {
110     // Attempt to cast data to an Image
111     const Self * imgData;
112
113     try
114       {
115       imgData = dynamic_cast<const Self *>( data );
116       }
117     catch( ... )
118       {
119       return;
120       }
121
122
123     if ( imgData )
124       {
125       // Now copy anything remaining that is needed
126       this->SetPixelContainer( const_cast< PixelContainer * >
127                                   (imgData->GetPixelContainer()) );
128       }
129     else
130       {
131       // pointer could not be cast back down
132       itkExceptionMacro( << "itk::Image::Graft() cannot cast "
133                          << typeid(data).name() << " to "
134                          << typeid(const Self *).name() );
135       }
136     }
137 }
138
139
140 /**
141  *
142  */
143 template<class TPixel, unsigned int VImageDimension>
144 void 
145 Image<TPixel, VImageDimension>
146 ::PrintSelf(std::ostream& os, Indent indent) const
147 {
148   Superclass::PrintSelf(os,indent);
149   
150   os << indent << "PixelContainer: " << std::endl;
151   m_Buffer->Print(os, indent.GetNextIndent());
152
153 IND // m_Origin and m_Spacing are printed in the Superclass
154 }
155 // end namespace itk
156
157 #endif
158

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