1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18 /*=========================================================================
19 *
20 * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21 *
22 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23 *
24 * For complete copyright, license and disclaimer of warranty information
25 * please refer to the NOTICE file at the top of the ITK source tree.
26 *
27 *=========================================================================*/
28 #ifndef itkSpecialCoordinatesImage_hxx
29 #define itkSpecialCoordinatesImage_hxx
30 #include "itkSpecialCoordinatesImage.h"
31 #include "itkProcessObject.h"
32
33 namespace itk
34 {
35
36 template< typename TPixel, unsigned int VImageDimension >
37 SpecialCoordinatesImage< TPixel, VImageDimension >
SpecialCoordinatesImage()38 ::SpecialCoordinatesImage()
39 {
40 m_Buffer = PixelContainer::New();
41 }
42
43 template< typename TPixel, unsigned int VImageDimension >
44 void
45 SpecialCoordinatesImage< TPixel, VImageDimension >
Allocate(bool initialize)46 ::Allocate(bool initialize)
47 {
48 SizeValueType num;
49
50 this->ComputeOffsetTable();
51 num = static_cast<SizeValueType>(this->GetOffsetTable()[VImageDimension]);
52
53 m_Buffer->Reserve(num,initialize);
54 }
55
56 template< typename TPixel, unsigned int VImageDimension >
57 void
58 SpecialCoordinatesImage< TPixel, VImageDimension >
Initialize()59 ::Initialize()
60 {
61 //
62 // We don't modify ourselves because the "ReleaseData" methods depend upon
63 // no modification when initialized.
64 //
65
66 // Call the superclass which should initialize the BufferedRegion ivar.
67 Superclass::Initialize();
68
69 // Replace the handle to the buffer. This is the safest thing to do,
70 // since the same container can be shared by multiple images (e.g.
71 // Grafted outputs and in place filters).
72 m_Buffer = PixelContainer::New();
73 }
74
75 template< typename TPixel, unsigned int VImageDimension >
76 void
77 SpecialCoordinatesImage< TPixel, VImageDimension >
FillBuffer(const TPixel & value)78 ::FillBuffer(const TPixel & value)
79 {
80 const SizeValueType numberOfPixels =
81 this->GetBufferedRegion().GetNumberOfPixels();
82
83 for ( unsigned int i = 0; i < numberOfPixels; i++ )
84 {
85 ( *m_Buffer )[i] = value;
86 }
87 }
88
89 template< typename TPixel, unsigned int VImageDimension >
90 void
91 SpecialCoordinatesImage< TPixel, VImageDimension >
SetPixelContainer(PixelContainer * container)92 ::SetPixelContainer(PixelContainer *container)
93 {
94 if ( m_Buffer != container )
95 {
96 m_Buffer = container;
97 this->Modified();
98 }
99 }
100
101 template< typename TPixel, unsigned int VImageDimension >
102 void
103 SpecialCoordinatesImage< TPixel, VImageDimension >
PrintSelf(std::ostream & os,Indent indent) const104 ::PrintSelf(std::ostream & os, Indent indent) const
105 {
106 Superclass::PrintSelf(os, indent);
107
108 os << indent << "PixelContainer: " << std::endl;
109 m_Buffer->Print( os, indent.GetNextIndent() );
110
111 // m_Origin and m_Spacing are printed in the Superclass
112 }
113 } // end namespace itk
114
115 #endif
116