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 __itkLabelObjectAccessors_h 00019 #define __itkLabelObjectAccessors_h 00020 00021 #include "itkMacro.h" 00022 00023 /* 00024 * 00025 * This code was contributed in the Insight Journal paper: 00026 * "Label object representation and manipulation with ITK" 00027 * by Lehmann G. 00028 * http://hdl.handle.net/1926/584 00029 * http://www.insight-journal.org/browse/publication/176 00030 * 00031 */ 00032 00033 namespace itk 00034 { 00035 namespace Functor 00036 { 00037 template< class TLabelObject > 00038 class ITK_EXPORT LabelLabelObjectAccessor 00039 { 00040 public: 00041 typedef TLabelObject LabelObjectType; 00042 typedef typename LabelObjectType::LabelType AttributeValueType; 00043 00044 inline AttributeValueType operator()(const LabelObjectType *labelObject) const 00045 { 00046 return labelObject->GetLabel(); 00047 } 00048 }; 00049 00050 template< class TLabelObject > 00051 class ITK_EXPORT NumberOfLinesLabelObjectAccessor 00052 { 00053 public: 00054 typedef TLabelObject LabelObjectType; 00055 typedef int AttributeValueType; 00056 00057 inline AttributeValueType operator()(const LabelObjectType *labelObject) const 00058 { 00059 return labelObject->GetNumberOfLines(); 00060 } 00061 }; 00062 00063 template< class TLabelObject, class TAttributeAccessor > 00064 class LabelObjectComparator 00065 { 00066 public: 00067 typedef TLabelObject LabelObjectType; 00068 typedef TAttributeAccessor AttributeAccessorType; 00069 bool operator()(const LabelObjectType *a, const LabelObjectType *b) const 00070 { 00071 return m_Accessor(a) > m_Accessor(b); 00072 } 00073 00074 LabelObjectComparator() {} 00075 LabelObjectComparator(LabelObjectComparator const & from) 00076 { 00077 m_Accessor = from.m_Accessor; 00078 } 00079 00080 private: 00081 AttributeAccessorType m_Accessor; 00082 }; 00083 00084 template< class TLabelObject, class TAttributeAccessor > 00085 class LabelObjectReverseComparator 00086 { 00087 public: 00088 typedef TLabelObject LabelObjectType; 00089 typedef TAttributeAccessor AttributeAccessorType; 00090 bool operator()(const LabelObjectType *a, const LabelObjectType *b) const 00091 { 00092 return m_Accessor(a) < m_Accessor(b); 00093 } 00094 00095 LabelObjectReverseComparator() {} 00096 LabelObjectReverseComparator(LabelObjectReverseComparator const & from) 00097 { 00098 m_Accessor = from.m_Accessor; 00099 } 00100 00101 private: 00102 AttributeAccessorType m_Accessor; 00103 }; 00104 } 00105 } // end namespace itk 00106 00107 #endif 00108