ITK
4.1.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 __itkValarrayImageContainer_h 00019 #define __itkValarrayImageContainer_h 00020 00021 #include "itkObject.h" 00022 #include "itkObjectFactory.h" 00023 00024 #include <utility> 00025 #include <valarray> 00026 00027 namespace itk 00028 { 00047 template< 00048 typename TElementIdentifier, 00049 typename TElement 00050 > 00051 class ValarrayImageContainer: 00052 public Object, 00053 private std::valarray< TElement > 00054 { 00055 public: 00057 typedef ValarrayImageContainer Self; 00058 typedef Object Superclass; 00059 typedef SmartPointer< Self > Pointer; 00060 typedef SmartPointer< const Self > ConstPointer; 00061 00063 typedef TElementIdentifier ElementIdentifier; 00064 typedef TElement Element; 00065 private: 00066 00068 typedef std::valarray< Element > ValarrayType; 00069 protected: 00070 00075 ValarrayImageContainer(): 00076 ValarrayType() {} 00077 ValarrayImageContainer(unsigned long n): 00078 ValarrayType(n) {} 00079 ValarrayImageContainer(unsigned long n, const Element & x): 00080 ValarrayType(n, x) {} 00081 ValarrayImageContainer(const Self & r): 00082 ValarrayType(r) {} 00083 public: 00084 00086 itkNewMacro(Self); 00087 00089 itkTypeMacro(ValarrayImageContainer, Object); 00090 00092 TElement & operator[](const ElementIdentifier id) 00093 { return this->ValarrayType::operator[](id); } 00094 00096 const TElement & operator[](const ElementIdentifier id) const 00097 { return this->ValarrayType::operator[](id); } 00098 00101 TElement * GetBufferPointer() 00102 { 00103 if ( this->Size() > 0 ) 00104 { 00105 return & ( this->ValarrayType::operator[](0) ); 00106 } 00107 else 00108 { 00109 return NULL; 00110 } 00111 } 00113 00115 unsigned long Size(void) const 00116 { return static_cast< unsigned long >( this->ValarrayType::size() ); } 00117 00122 void Reserve(ElementIdentifier num) 00123 { this->ValarrayType::resize(num); } 00124 00128 void Squeeze(void) 00129 { this->ValarrayType::resize( this->ValarrayType::size() ); } 00130 00132 void Initialize(void) 00133 { this->ValarrayType::resize(0); } 00134 00136 void Fill(const TElement & value) 00137 { this->ValarrayType::operator=(value); } 00138 public: 00139 00143 virtual void PrintSelf(std::ostream & os, Indent indent) const 00144 { 00145 Object::PrintSelf(os, indent); 00146 // Print out the pointer to bulk data memory. We use const_cast<> to 00147 // cast away the constness so we can call GetBufferPointer() 00148 os << indent << "Pointer: " 00149 << const_cast< ValarrayImageContainer * >( this )->GetBufferPointer() 00150 << std::endl; 00152 00153 os << indent << "Size: " << this->Size() << std::endl; 00154 } 00155 }; 00156 } // end namespace itk 00157 00158 #endif 00159