DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkSpatiallyDenseSparseVectorImage.hxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Spatially Dense Sparse Vector Image
4 
5  Copyright (c) Pew-Thian Yap. All rights reserved.
6  See http://www.unc.edu/~ptyap/ for details.
7 
8  This software is distributed WITHOUT ANY WARRANTY; without even
9  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10  PURPOSE. See the above copyright notices for more information.
11 
12  =========================================================================*/
13 
14 #ifndef _itkSpatiallyDenseSparseVectorImage_hxx
15 #define _itkSpatiallyDenseSparseVectorImage_hxx
16 
18 #include "itkProcessObject.h"
19 
20 namespace itk
21 {
22 
23 template<class TValueType, unsigned int VImageDimension, typename TKeyType>
26 {
27  m_Container = PixelContainer::New();
28  m_FillBufferValue.SetSize(0);
29 }
30 
31 template<class TValueType, unsigned int VImageDimension, typename TKeyType>
32 void
34 ::Allocate(bool UseDefaultConstructor)
35 {
36  SizeValueType num;
37  this->ComputeOffsetTable();
38  num = this->GetOffsetTable()[VImageDimension];
39 
40  m_Container->Reserve(num, UseDefaultConstructor);
41 }
42 
43 template<class TValueType, unsigned int VImageDimension, typename TKeyType>
44 void
47 {
48  //
49  // We don't modify ourselves because the "ReleaseData" methods depend upon
50  // no modification when initialized.
51  //
52 
53  // Call the superclass which should initialize the BufferedRegion ivar.
54  Superclass::Initialize();
55 
56  // Replace the handle to the container. This is the safest thing to do,
57  // since the same container can be shared by multiple images (e.g.
58  // Grafted outputs and in place filters).
59  m_Container = PixelContainer::New();
60 }
61 
62 template<class TValueType, unsigned int VImageDimension, typename TKeyType>
63 void
65 ::FillBuffer(const PixelType& value)
66 {
67  m_FillBufferValue = value;
68 
69  const SizeValueType numberOfPixels =
70  this->GetBufferedRegion().GetNumberOfPixels();
71 
72  for (SizeValueType i=0; i<numberOfPixels; i++)
73  {
74  (*m_Container)[i].Clear();
75  }
76 }
77 
78 template<class TValueType, unsigned int VImageDimension, typename TKeyType>
79 void
82 {
83  if (m_Container != container)
84  {
85  m_Container = container;
86  this->Modified();
87  }
88 }
89 
90 
91 template<class TValueType, unsigned int VImageDimension, typename TKeyType>
92 void
94 ::Graft(const DataObject *data)
95 {
96  // call the superclass' implementation
97  Superclass::Graft( data );
98 
99  if ( data )
100  {
101  // Attempt to cast data to an Image
102  const Self *imgData;
103 
104  try
105  {
106  imgData = dynamic_cast< const Self *>( data );
107  }
108  catch( ... )
109  {
110  return;
111  }
112 
113  // Copy from SpatiallyDenseSparseVectorImage< TPixel, VImageDimension >
114  if ( imgData )
115  {
116  // Now copy anything remaining that is needed
117  this->SetPixelContainer( const_cast< PixelContainer *>
118  (imgData->GetPixelContainer()) );
119  }
120  else
121  {
122  // pointer could not be cast back down
123  itkExceptionMacro( << "itk::SpatiallyDenseSparseVectorImage::Graft() cannot cast "
124  << typeid(data).name() << " to "
125  << typeid(const Self *).name() );
126  }
127  }
128 }
129 
130 template< class TValueType, unsigned int VImageDimension, typename TKeyType >
131 unsigned int
134 {
135  return this->m_VectorLength;
136 }
137 
138 template< class TValueType, unsigned int VImageDimension, typename TKeyType >
139 void
142 {
143  this->SetVectorLength( static_cast< VectorLengthType >( n ) );
144  if ( m_FillBufferValue.GetNumberOfElements() == 0 )
145  {
146  m_FillBufferValue.SetSize(n);
147  m_FillBufferValue.Fill(0);
148  }
149 }
150 
151 template<class TValueType, unsigned int VImageDimension, typename TKeyType>
152 void
154 ::PrintSelf(std::ostream& os, Indent indent) const
155 {
156  Superclass::PrintSelf(os,indent);
157  os << indent << "PixelContainer: " << std::endl;
158  m_Container->Print(os, indent.GetNextIndent());
159 // m_Origin and m_Spacing are printed in the Superclass
160 }
161 
162 } // end namespace itk
163 
164 #endif
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
ImportImageContainer< SizeValueType, InternalPixelType > PixelContainer
void ComputeOffsetTable(const std::vector< int > &size, std::vector< int > &offsetTable, const int storedWay)
Definition: utlCore.h:1915
virtual void Graft(const DataObject *data) ITK_OVERRIDE
virtual void SetNumberOfComponentsPerPixel(unsigned int n) ITK_OVERRIDE
void Allocate(bool UseDefaultConstructor=false) ITK_OVERRIDE
An n-dimensional vector image with a sparse memory model.
virtual unsigned int GetNumberOfComponentsPerPixel() const ITK_OVERRIDE