ITK
4.0.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkVectorImage_h 00019 #define __itkVectorImage_h 00020 00021 #include "itkImageRegion.h" 00022 #include "itkImportImageContainer.h" 00023 #include "itkDefaultVectorPixelAccessor.h" 00024 #include "itkDefaultVectorPixelAccessorFunctor.h" 00025 #include "itkVectorImageNeighborhoodAccessorFunctor.h" 00026 #include "itkWeakPointer.h" 00027 00028 namespace itk 00029 { 00081 template< class TPixel, unsigned int VImageDimension = 3 > 00082 class ITK_EXPORT VectorImage: 00083 public ImageBase< VImageDimension > 00084 { 00085 public: 00087 typedef VectorImage Self; 00088 typedef ImageBase< VImageDimension > Superclass; 00089 typedef SmartPointer< Self > Pointer; 00090 typedef SmartPointer< const Self > ConstPointer; 00091 typedef WeakPointer< const Self > ConstWeakPointer; 00092 00094 itkNewMacro(Self); 00095 00097 itkTypeMacro(VectorImage, ImageBase); 00098 00103 typedef VariableLengthVector< TPixel > PixelType; 00104 00108 typedef TPixel InternalPixelType; 00109 00111 typedef PixelType ValueType; 00112 00113 typedef InternalPixelType IOPixelType; 00114 00117 typedef DefaultVectorPixelAccessor< InternalPixelType > AccessorType; 00118 00121 typedef DefaultVectorPixelAccessorFunctor< Self > AccessorFunctorType; 00122 00125 typedef VectorImageNeighborhoodAccessorFunctor< 00126 Self > NeighborhoodAccessorFunctorType; 00127 00132 itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension); 00133 00135 typedef typename Superclass::IndexType IndexType; 00136 typedef typename Superclass::IndexValueType IndexValueType; 00137 00139 typedef typename Superclass::OffsetType OffsetType; 00140 00142 typedef typename Superclass::SizeType SizeType; 00143 00145 typedef ImportImageContainer< SizeValueType, InternalPixelType > PixelContainer; 00146 00148 typedef typename Superclass::DirectionType DirectionType; 00149 00152 typedef typename Superclass::RegionType RegionType; 00153 00156 typedef typename Superclass::SpacingType SpacingType; 00157 00160 typedef typename Superclass::PointType PointType; 00161 00163 typedef typename PixelContainer::Pointer PixelContainerPointer; 00164 typedef typename PixelContainer::ConstPointer PixelContainerConstPointer; 00165 00167 typedef typename Superclass::OffsetValueType OffsetValueType; 00168 00169 typedef unsigned int VectorLengthType; 00170 00173 void Allocate(); 00174 00178 void SetRegions(RegionType region) 00179 { 00180 this->SetLargestPossibleRegion(region); 00181 this->SetBufferedRegion(region); 00182 this->SetRequestedRegion(region); 00183 } 00185 00186 void SetRegions(SizeType size) 00187 { 00188 RegionType region; region.SetSize(size); 00189 00190 this->SetLargestPossibleRegion(region); 00191 this->SetBufferedRegion(region); 00192 this->SetRequestedRegion(region); 00193 } 00194 00197 virtual void Initialize(); 00198 00201 void FillBuffer(const PixelType & value); 00202 00208 void SetPixel(const IndexType & index, const PixelType & value) 00209 { 00210 OffsetValueType offset = m_VectorLength * this->ComputeOffset(index); 00211 00212 for ( VectorLengthType i = 0; i < m_VectorLength; i++ ) 00213 { 00214 ( *m_Buffer )[offset + i] = value[i]; 00215 } 00216 } 00217 00223 const PixelType GetPixel(const IndexType & index) const 00224 { 00225 OffsetValueType offset = m_VectorLength * this->ComputeOffset(index); 00226 PixelType p(&( ( *m_Buffer )[offset] ), m_VectorLength); 00227 00228 return p; 00229 } 00230 00235 PixelType GetPixel(const IndexType & index) 00236 { 00237 OffsetValueType offset = m_VectorLength * this->ComputeOffset(index); 00238 PixelType p(&( ( *m_Buffer )[offset] ), m_VectorLength); 00239 00240 return p; 00241 } 00242 00248 PixelType operator[](const IndexType & index) { return this->GetPixel(index); } 00249 00255 PixelType operator[](const IndexType & index) const { return this->GetPixel(index); } 00256 00259 InternalPixelType * GetBufferPointer() 00260 { 00261 return m_Buffer ? m_Buffer->GetBufferPointer() : 0; 00262 } 00263 const InternalPixelType * GetBufferPointer() const 00264 { 00265 return m_Buffer ? m_Buffer->GetBufferPointer() : 0; 00266 } 00268 00270 PixelContainer * GetPixelContainer() { return m_Buffer.GetPointer(); } 00271 00273 const PixelContainer * GetPixelContainer() const { return m_Buffer.GetPointer(); } 00274 00277 void SetPixelContainer(PixelContainer *container); 00278 00289 virtual void Graft(const DataObject *data); 00290 00292 AccessorType GetPixelAccessor(void) { return AccessorType(m_VectorLength); } 00293 00295 const AccessorType GetPixelAccessor(void) const { return AccessorType(m_VectorLength); } 00296 00298 NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() 00299 { 00300 return NeighborhoodAccessorFunctorType(m_VectorLength); 00301 } 00302 00304 const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const 00305 { 00306 return NeighborhoodAccessorFunctorType(m_VectorLength); 00307 } 00308 00310 itkSetMacro(VectorLength, VectorLengthType); 00311 itkGetConstReferenceMacro(VectorLength, VectorLengthType); 00313 00315 virtual unsigned int GetNumberOfComponentsPerPixel() const; 00316 00317 virtual void SetNumberOfComponentsPerPixel(unsigned int n); 00318 00319 protected: 00320 VectorImage(); 00321 void PrintSelf(std::ostream & os, Indent indent) const; 00322 00323 virtual ~VectorImage() {} 00324 private: 00325 VectorImage(const Self &); // purposely not implementated 00326 void operator=(const Self &); //purposely not implemented 00327 00329 VectorLengthType m_VectorLength; 00330 00332 PixelContainerPointer m_Buffer; 00333 }; 00334 } // end namespace itk 00335 00336 // Define instantiation macro for this template. 00337 #define ITK_TEMPLATE_VectorImage(_, EXPORT, TypeX, TypeY) \ 00338 namespace itk \ 00339 { \ 00340 _( 2 ( class EXPORT VectorImage< ITK_TEMPLATE_2 TypeX > ) ) \ 00341 namespace Templates \ 00342 { \ 00343 typedef VectorImage< ITK_TEMPLATE_2 TypeX > VectorImage##TypeY; \ 00344 } \ 00345 } 00346 00347 #if ITK_TEMPLATE_EXPLICIT 00348 #include "Templates/itkVectorImage+-.h" 00349 #endif 00350 00351 #if ITK_TEMPLATE_TXX 00352 #include "itkVectorImage.hxx" 00353 #endif 00354 00355 #endif 00356