ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkAttributeLabelObject.h
Go to the documentation of this file.
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 __itkAttributeLabelObject_h
00019 #define __itkAttributeLabelObject_h
00020 
00021 #include "itkLabelObject.h"
00022 #include "itkLabelMap.h"
00023 
00024 namespace itk
00025 {
00026 
00027 
00028 namespace Functor {
00029 
00030 template< class TLabelObject >
00031 class ITK_EXPORT AttributeLabelObjectAccessor
00032 {
00033 public:
00034   typedef TLabelObject                                 LabelObjectType;
00035   typedef typename LabelObjectType::AttributeValueType AttributeValueType;
00036 
00037   inline const AttributeValueType operator()( const LabelObjectType * labelObject )
00038     {
00039     return labelObject->GetAttribute();
00040     }
00041 
00042   inline void operator()( LabelObjectType * labelObject, AttributeValueType value )
00043     {
00044     labelObject->SetAttribute( value );
00045     }
00046 };
00047 
00048 }
00049 
00050 
00069 template < class TLabel, unsigned int VImageDimension, class TAttributeValue >
00070 class ITK_EXPORT AttributeLabelObject : public LabelObject< TLabel, VImageDimension >
00071 {
00072 public:
00074   typedef AttributeLabelObject                   Self;
00075   typedef LabelObject< TLabel, VImageDimension > Superclass;
00076   typedef SmartPointer<Self>                     Pointer;
00077    typedef typename Superclass::LabelObjectType  LabelObjectType;
00078   typedef SmartPointer<const Self>               ConstPointer;
00079   typedef WeakPointer<const Self>                ConstWeakPointer;
00080 
00082   itkNewMacro(Self);
00083 
00085   itkTypeMacro(AttributeLabelObject, LabelObject);
00086 
00087   typedef LabelMap< Self > LabelMapType;
00088 
00089   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00090 
00091   typedef typename Superclass::IndexType IndexType;
00092 
00093   typedef TLabel LabelType;
00094 
00095   typedef typename Superclass::LineType LineType;
00096 
00097   typedef typename Superclass::LengthType LengthType;
00098 
00099   typedef TAttributeValue AttributeValueType;
00100 
00101   void SetAttribute( const AttributeValueType & v )
00102     {
00103     m_Attribute = v;
00104     }
00105 
00106   const AttributeValueType & GetAttribute() const
00107     {
00108     return m_Attribute;
00109     }
00110 
00111   AttributeValueType GetAttribute()
00112     {
00113     return m_Attribute;
00114     }
00115 
00116 
00117   virtual void CopyAttributesFrom( const LabelObjectType * lo )
00118     {
00119     Superclass::CopyAttributesFrom( lo );
00120 
00121     // copy the data of the current type if possible
00122     const Self * src = dynamic_cast<const Self *>( lo );
00123     if( src == NULL )
00124       {
00125       return;
00126       }
00127     m_Attribute = src->m_Attribute;
00128     }
00129 
00130 protected:
00131   AttributeLabelObject()
00132     {
00133     // how to initialize the attribute ?
00134     }
00135 
00136 
00137   void PrintSelf(std::ostream& os, Indent indent) const
00138     {
00139     Superclass::PrintSelf( os, indent );
00140 
00141     os << indent << "Attribute: " << m_Attribute << std::endl;
00142     }
00143 
00144 private:
00145   AttributeLabelObject(const Self&); //purposely not implemented
00146   void operator=(const Self&); //purposely not implemented
00147 
00148   AttributeValueType m_Attribute;
00149 
00150 
00151 };
00152 
00153 } // end namespace itk
00154 
00155 #endif
00156