00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #ifndef MITK_DATATREEFILTERFUNCTOINS_H_INCLUDED 00019 #define MITK_DATATREEFILTERFUNCTOINS_H_INCLUDED 00020 00021 #include <mitkDataNode.h> 00022 #include "MitkExtExports.h" 00023 00024 #include <mitkProperties.h> 00025 #include <mitkDataStorage.h> 00026 00027 namespace mitk 00028 { 00029 class DataNode; 00030 00037 class MitkExt_EXPORT DataTreeFilterFunction 00038 { 00039 public: 00040 virtual ~DataTreeFilterFunction() {} 00041 virtual bool operator()(DataNode*) const; 00042 virtual bool NodeMatches(DataNode*) const = 0; 00043 virtual DataTreeFilterFunction* Clone() const = 0; 00044 }; 00045 00053 template <class T> 00054 class IsBaseDataType : public DataTreeFilterFunction 00055 { 00056 public: 00057 virtual bool NodeMatches(DataNode* node) const 00058 { 00059 return ( node != NULL && node->GetData() && dynamic_cast<T*>(node->GetData()) ); 00060 } 00061 00062 virtual DataTreeFilterFunction* Clone() const 00063 { 00064 return new IsBaseDataType<T>(); 00065 } 00066 00067 virtual ~IsBaseDataType() {} 00068 }; 00069 00077 template <class T> 00078 class IsBaseDataTypeWithProperty : public DataTreeFilterFunction 00079 { 00080 public: 00081 00082 IsBaseDataTypeWithProperty(const char* propertyName) 00083 :m_PropertyName(propertyName) 00084 { 00085 } 00086 00087 virtual bool NodeMatches(DataNode* node) const 00088 { 00089 return ( node != NULL && node->GetData() // node is not NULL, and node->GetData is also not NULL 00090 && dynamic_cast<T*>(node->GetData() ) // data is of a certain type 00091 && ( node->GetProperty(m_PropertyName.c_str())!= NULL // there is a certain property 00092 ) 00093 ); 00094 } 00095 00096 virtual DataTreeFilterFunction* Clone() const 00097 { 00098 return new IsBaseDataTypeWithProperty<T>(m_PropertyName.c_str()); 00099 } 00100 00101 virtual ~IsBaseDataTypeWithProperty() {} 00102 00103 private: 00104 00105 std::string m_PropertyName; 00106 }; 00107 00115 template <class T> 00116 class IsBaseDataTypeWithBoolProperty : public DataTreeFilterFunction 00117 { 00118 public: 00119 00120 IsBaseDataTypeWithBoolProperty(const char* propertyName) 00121 :m_PropertyName(propertyName) 00122 { 00123 } 00124 00125 virtual bool NodeMatches(DataNode* node) const 00126 { 00127 bool propVal(false); 00128 return ( node != NULL && node->GetData() // node is not NULL, and node->GetData is also not NULL 00129 && dynamic_cast<T*>( node->GetData() ) // data is of a certain type 00130 && node->GetPropertyValue(m_PropertyName.c_str(), propVal) // there is a certain BoolProperty 00131 && propVal 00132 ); 00133 } 00134 00135 virtual DataTreeFilterFunction* Clone() const 00136 { 00137 return new IsBaseDataTypeWithBoolProperty<T>(m_PropertyName.c_str()); 00138 } 00139 00140 virtual ~IsBaseDataTypeWithBoolProperty() {} 00141 00142 private: 00143 00144 std::string m_PropertyName; 00145 }; 00146 00147 00155 template <class T> 00156 class IsBaseDataTypeWithoutProperty : public DataTreeFilterFunction 00157 { 00158 public: 00159 00160 IsBaseDataTypeWithoutProperty(const char* propertyName) 00161 :m_PropertyName(propertyName) 00162 { 00163 } 00164 00165 virtual bool NodeMatches(DataNode* node) const 00166 { 00167 bool propVal(false); 00168 bool propertyExists(false); 00169 00170 if (node) 00171 propertyExists = node->GetPropertyValue(m_PropertyName.c_str(), propVal ); 00172 00173 return ( node != NULL && node->GetData() // node is not NULL, and node->GetData is also not NULL 00174 && dynamic_cast<T*>(node->GetData() ) // data is of a certain type 00175 && ( !propertyExists || !propVal )); // the property does not exist, OR its value is false 00176 } 00177 00178 virtual DataTreeFilterFunction* Clone() const 00179 { 00180 return new IsBaseDataTypeWithoutProperty<T>(m_PropertyName.c_str()); 00181 } 00182 00183 virtual ~IsBaseDataTypeWithoutProperty() {} 00184 00185 private: 00186 00187 std::string m_PropertyName; 00188 }; 00189 00190 00191 // some default filters in mitk:: namespace for use by clients of mitk::DataTreeFilter 00192 00200 class MitkExt_EXPORT IsDataNode : public DataTreeFilterFunction 00201 { 00202 public: 00203 virtual ~IsDataNode() {} 00204 virtual bool NodeMatches(DataNode*) const; 00205 virtual DataTreeFilterFunction* Clone() const; 00206 }; 00207 00215 class MitkExt_EXPORT IsGoodDataNode : public DataTreeFilterFunction 00216 { 00217 public: 00218 virtual ~IsGoodDataNode() {} 00219 virtual bool NodeMatches(DataNode*) const; 00220 virtual DataTreeFilterFunction* Clone() const; 00221 }; 00222 00230 class MitkExt_EXPORT IsInResultSet : public DataTreeFilterFunction 00231 { 00232 public: 00233 IsInResultSet( std::set<const DataNode*> rs ) 00234 :m_ResultSet(rs) 00235 { 00236 } 00237 00238 IsInResultSet(const DataStorage::SetOfObjects* rs) 00239 { 00240 if (rs) 00241 { 00242 for (DataStorage::SetOfObjects::const_iterator iter = rs->begin(); 00243 iter != rs->end(); 00244 ++iter) 00245 { 00246 m_ResultSet.insert( iter->GetPointer() ); 00247 } 00248 } 00249 } 00250 00251 virtual ~IsInResultSet() {} 00252 virtual bool NodeMatches(DataNode*) const; 00253 virtual DataTreeFilterFunction* Clone() const; 00254 protected: 00255 //DataStorage::SetOfObjects::ConstPointer m_ResultSet; 00256 std::set<const DataNode*> m_ResultSet; 00257 }; 00258 00266 template <unsigned int DIM> 00267 class IsImageWithDimensionAndWithoutProperty : public DataTreeFilterFunction 00268 { 00269 public: 00270 00271 IsImageWithDimensionAndWithoutProperty(const char* propertyName) 00272 :m_PropertyName(propertyName) 00273 { 00274 } 00275 00276 virtual bool NodeMatches(DataNode* node) const 00277 { 00278 return ( node != NULL && node->GetData() // node is not NULL, and node->GetData is also not NULL 00279 && dynamic_cast<mitk::Image*>(node->GetData() ) // data is an image 00280 && (dynamic_cast<mitk::Image*>(node->GetData() )->GetDimension() == DIM) 00281 && ( node->GetProperty(m_PropertyName.c_str()) == NULL // there is a certain property 00282 ) 00283 ); 00284 } 00285 00286 virtual DataTreeFilterFunction* Clone() const 00287 { 00288 return new IsImageWithDimensionAndWithoutProperty<DIM>(m_PropertyName.c_str()); 00289 } 00290 00291 virtual ~IsImageWithDimensionAndWithoutProperty() {} 00292 00293 private: 00294 00295 std::string m_PropertyName; 00296 }; 00297 00305 template <unsigned int DIM> 00306 class IsImageWithMinimumDimension : public DataTreeFilterFunction 00307 { 00308 public: 00309 00310 virtual bool NodeMatches(DataNode* node) const 00311 { 00312 return ( node != NULL && node->GetData() // node is not NULL, and node->GetData is also not NULL 00313 && dynamic_cast<mitk::Image*>(node->GetData() ) // data is an image 00314 && (dynamic_cast<mitk::Image*>(node->GetData() )->GetDimension() >= DIM) 00315 ); 00316 } 00317 00318 virtual DataTreeFilterFunction* Clone() const 00319 { 00320 return new IsImageWithMinimumDimension<DIM>(); 00321 } 00322 00323 virtual ~IsImageWithMinimumDimension() {} 00324 }; 00325 00326 } // namespace mitk 00327 00328 #endif 00329 // vi: textwidth=90 00330 00331