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 __itkWatershedSegmentTreeGenerator_h 00019 #define __itkWatershedSegmentTreeGenerator_h 00020 00021 #include "itkWatershedSegmentTable.h" 00022 #include "itkWatershedSegmentTree.h" 00023 #include "itkEquivalencyTable.h" 00024 00025 #include <algorithm> 00026 #include <utility> 00027 00028 namespace itk 00029 { 00030 namespace watershed 00031 { 00077 template< class TScalarType > 00078 class ITK_EXPORT SegmentTreeGenerator:public ProcessObject 00079 { 00080 public: 00081 00083 typedef SegmentTreeGenerator Self; 00084 typedef ProcessObject Superclass; 00085 typedef SmartPointer< Self > Pointer; 00086 typedef SmartPointer< const Self > ConstPointer; 00087 itkNewMacro(Self); 00088 itkTypeMacro(WatershedSegmentTreeGenerator, ProcessObject); 00090 00092 typedef TScalarType ScalarType; 00093 typedef SegmentTable< ScalarType > SegmentTableType; 00094 typedef SegmentTree< ScalarType > SegmentTreeType; 00095 typedef EquivalencyTable EquivalencyTableType; 00096 typedef OneWayEquivalencyTable OneWayEquivalencyTableType; 00097 typedef DataObject::Pointer DataObjectPointer; 00098 00100 typedef typename SegmentTableType::Pointer SegmentTableTypePointer; 00101 typedef typename OneWayEquivalencyTableType::Pointer OneWayEquivalencyTableTypePointer; 00102 typedef typename SegmentTreeType::Pointer SegmentTreeTypePointer; 00103 00105 SegmentTableType * GetInputSegmentTable() 00106 { 00107 return static_cast< SegmentTableType * >( this->ProcessObject::GetInput(0) ); 00108 } 00109 00110 void SetInputSegmentTable(SegmentTableType *st) 00111 { 00112 // Reset the highest calculated flood level if we are given a 00113 // different input image. 00114 if ( st != this->GetInput(0) ) 00115 { 00116 m_HighestCalculatedFloodLevel = 0.0; 00117 } 00118 this->ProcessObject::SetNthInput(0, st); 00119 } 00120 00124 void SetInputEquivalencyTable(EquivalencyTableType *eq) 00125 { 00126 this->ProcessObject::SetNthInput(1, eq); 00127 } 00128 00129 EquivalencyTableType * GetInputEquivalencyTable() 00130 { 00131 return 00132 static_cast< EquivalencyTableType * >( this->ProcessObject::GetInput(1) ); 00133 } 00134 00136 SegmentTreeType * GetOutputSegmentTree() 00137 { 00138 return static_cast< SegmentTreeType * > 00139 ( this->ProcessObject::GetOutput(0) ); 00140 } 00141 00143 void GenerateData(); 00144 00149 itkSetMacro(Merge, bool); 00150 itkGetConstMacro(Merge, bool); 00152 00158 void SetFloodLevel(double); 00159 00160 itkGetConstMacro(FloodLevel, double); 00161 00165 itkSetMacro(HighestCalculatedFloodLevel, double); 00166 itkGetConstMacro(HighestCalculatedFloodLevel, double); 00168 00174 itkSetMacro(ConsumeInput, bool); 00175 itkGetConstMacro(ConsumeInput, bool); 00177 00180 static void MergeSegments(SegmentTableTypePointer, 00181 OneWayEquivalencyTableTypePointer, 00182 const IdentifierType, 00183 const IdentifierType); 00184 00187 static void PruneMergeSegments(SegmentTableTypePointer, 00188 OneWayEquivalencyTableTypePointer, 00189 const IdentifierType, 00190 const IdentifierType, 00191 ScalarType); 00192 00194 typedef ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType; 00195 using Superclass::MakeOutput; 00196 virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx); 00197 00198 protected: 00199 SegmentTreeGenerator(); 00200 virtual ~SegmentTreeGenerator() {} 00201 SegmentTreeGenerator(const Self &) {} 00202 void operator=(const Self &) {} 00203 void PrintSelf(std::ostream & os, Indent indent) const; 00204 00207 void CompileMergeList(SegmentTableTypePointer, SegmentTreeTypePointer); 00208 00211 void ExtractMergeHierarchy(SegmentTableTypePointer, SegmentTreeTypePointer); 00212 00213 void MergeEquivalencies(); 00214 00216 void GenerateOutputRequestedRegion(DataObject *output); 00217 00218 void GenerateInputRequestedRegion(); 00219 00220 private: 00221 bool m_Merge; 00222 double m_FloodLevel; 00223 bool m_ConsumeInput; 00224 00225 typedef itksys::hash_map< IdentifierType, bool, 00226 itksys::hash< IdentifierType > > HashMapType; 00227 00228 OneWayEquivalencyTableType::Pointer m_MergedSegmentsTable; 00229 00234 double m_HighestCalculatedFloodLevel; 00235 }; 00236 } // end namespace watershed 00237 } // end namespace itk 00238 00239 #ifndef ITK_MANUAL_INSTANTIATION 00240 #include "itkWatershedSegmentTreeGenerator.hxx" 00241 #endif 00242 00243 #endif 00244