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 00019 #ifndef DATATREENODE_H_HEADER_INCLUDED_C1E14338 00020 #define DATATREENODE_H_HEADER_INCLUDED_C1E14338 00021 00022 #include "mitkImageSource.h" 00023 #include "mitkBaseData.h" 00024 //#include "mitkMapper.h" 00025 #include "mitkInteractor.h" 00026 00027 #ifdef MBI_NO_STD_NAMESPACE 00028 #define MBI_STD 00029 #include <iostream.h> 00030 #include <fstream.h> 00031 #else 00032 #define MBI_STD std 00033 #include <iostream> 00034 #include <fstream> 00035 #endif 00036 00037 #include "mitkStringProperty.h" 00038 #include "mitkColorProperty.h" 00039 #include "mitkPropertyList.h" 00040 //#include "mitkMapper.h" 00041 00042 #include <map> 00043 #include <set> 00044 #include "mitkLevelWindow.h" 00045 00046 class vtkLinearTransform; 00047 00048 namespace mitk { 00049 00050 class BaseRenderer; 00051 class Mapper; 00052 00053 00054 //##Documentation 00055 //## @brief Class for nodes of the DataTree 00056 //## 00057 //## Contains the data (instance of BaseData), a list of mappers, which can 00058 //## draw the data, a transform (vtkTransform) and a list of properties 00059 //## (PropertyList). 00060 //## @ingroup DataManagement 00061 //## 00062 //## @todo clean up all the GetProperty methods. There are too many different flavours... Can most probably be reduced to <tt>bool GetProperty<type>(type&)</tt> 00063 //## 00064 //## @warning Change in semantics of SetProperty() since Aug 25th 2006. Check your usage of this method if you do 00065 //## more with properties than just call <tt>SetProperty( "key", new SomeProperty("value") )</tt>. 00066 class MITK_CORE_EXPORT DataNode : public itk::DataObject 00067 { 00068 public: 00069 00070 typedef mitk::Geometry3D::Pointer Geometry3DPointer; 00071 typedef std::vector< itk::SmartPointer< Mapper > > MapperVector; 00072 typedef std::map<const mitk::BaseRenderer*,mitk::PropertyList::Pointer> MapOfPropertyLists; 00073 typedef std::set<std::string> GroupTagList; 00074 00075 mitkClassMacro(DataNode, itk::DataObject); 00076 00077 itkNewMacro(Self); 00078 00079 mitk::Mapper* GetMapper(MapperSlotId id) const; 00080 //##Documentation 00081 //## @brief Get the data object (instance of BaseData, e.g., an Image) 00082 //## managed by this DataNode 00083 BaseData* GetData() const; 00084 //##Documentation 00085 //## @brief Get the transformation applied prior to displaying the data as 00086 //## a vtkTransform 00087 //## \deprecated use GetData()->GetGeometry()->GetVtkTransform() instead 00088 vtkLinearTransform* GetVtkTransform(int t=0) const; 00089 //##Documentation 00090 //## @brief Get the Interactor 00091 Interactor* GetInteractor() const; 00092 //##Documentation 00093 //## @brief Set the data object (instance of BaseData, e.g., an Image) 00094 //## managed by this DataNode 00095 //## @warning the actor-mode of the vtkInteractor does not work any more, if the transform of the 00096 //## data-tree-node is connected to the transform of the basedata via vtkTransform->SetInput. 00097 virtual void SetData(mitk::BaseData* baseData); 00098 //##Documentation 00099 //## @brief Set the Interactor 00100 virtual void SetInteractor(Interactor* interactor); 00101 00102 mitk::DataNode& operator=(const DataNode& right); 00103 00104 mitk::DataNode& operator=(BaseData* right); 00105 virtual void SetMapper(MapperSlotId id, mitk::Mapper* mapper); 00106 virtual void UpdateOutputInformation(); 00107 00108 virtual void SetRequestedRegionToLargestPossibleRegion(); 00109 00110 virtual bool RequestedRegionIsOutsideOfTheBufferedRegion(); 00111 00112 virtual bool VerifyRequestedRegion(); 00113 00114 virtual void SetRequestedRegion(itk::DataObject *data); 00115 00116 virtual void CopyInformation(const itk::DataObject *data); 00117 00118 //##Documentation 00119 //## @brief Set the property (instance of BaseProperty) with key @a propertyKey in the PropertyList 00120 //## of the @a renderer (if NULL, use BaseRenderer-independent PropertyList). This is set-by-value. 00121 //## 00122 //## @warning Change in semantics since Aug 25th 2006. Check your usage of this method if you do 00123 //## more with properties than just call <tt>SetProperty( "key", new SomeProperty("value") )</tt>. 00124 //## 00125 //## @sa GetProperty 00126 //## @sa m_PropertyList 00127 //## @sa m_MapOfPropertyLists 00128 void SetProperty(const char *propertyKey, BaseProperty* property, const mitk::BaseRenderer* renderer = NULL); 00129 00130 //##Documentation 00131 //## @brief Replace the property (instance of BaseProperty) with key @a propertyKey in the PropertyList 00132 //## of the @a renderer (if NULL, use BaseRenderer-independent PropertyList). This is set-by-reference. 00133 //## 00134 //## If @a renderer is @a NULL the property is set in the BaseRenderer-independent 00135 //## PropertyList of this DataNode. 00136 //## @sa GetProperty 00137 //## @sa m_PropertyList 00138 //## @sa m_MapOfPropertyLists 00139 void ReplaceProperty(const char *propertyKey, BaseProperty* property, const mitk::BaseRenderer* renderer = NULL); 00140 00141 //##Documentation 00142 //## @brief Add the property (instance of BaseProperty) if it does 00143 //## not exist (or always if \a overwrite is \a true) 00144 //## with key @a propertyKey in the PropertyList 00145 //## of the @a renderer (if NULL, use BaseRenderer-independent 00146 //## PropertyList). This is set-by-value. 00147 //## 00148 //## For \a overwrite == \a false the property is \em not changed 00149 //## if it already exists. For \a overwrite == \a true the method 00150 //## is identical to SetProperty. 00151 //## 00152 //## @sa SetProperty 00153 //## @sa GetProperty 00154 //## @sa m_PropertyList 00155 //## @sa m_MapOfPropertyLists 00156 void AddProperty(const char *propertyKey, BaseProperty* property, const mitk::BaseRenderer* renderer = NULL, bool overwrite = false); 00157 00158 //##Documentation 00159 //## @brief Get the PropertyList of the @a renderer. If @a renderer is @a 00160 //## NULL, the BaseRenderer-independent PropertyList of this DataNode 00161 //## is returned. 00162 //## @sa GetProperty 00163 //## @sa m_PropertyList 00164 //## @sa m_MapOfPropertyLists 00165 mitk::PropertyList* GetPropertyList(const mitk::BaseRenderer* renderer = NULL) const; 00166 00167 //##Documentation 00168 //## @brief Add values from another PropertyList. 00169 //## 00170 //## Overwrites values in m_PropertyList only when possible (i.e. when types are compatible). 00171 //## If you want to allow for object type changes (replacing a "visible":BoolProperty with "visible":IntProperty, 00172 //## set the @param replace. 00173 //## 00174 //## @param replace true: if @param pList contains a property "visible" of type ColorProperty and our m_PropertyList also has a "visible" property of a different type (e.g. BoolProperty), change the type, i.e. replace the objects behind the pointer. 00175 //## 00176 //## @sa SetProperty 00177 //## @sa ReplaceProperty 00178 //## @sa m_PropertyList 00179 void ConcatenatePropertyList(PropertyList* pList, bool replace = false); 00180 00181 //##Documentation 00182 //## @brief Get the property (instance of BaseProperty) with key @a propertyKey from the PropertyList 00183 //## of the @a renderer, if available there, otherwise use the BaseRenderer-independent PropertyList. 00184 //## 00185 //## If @a renderer is @a NULL or the @a propertyKey cannot be found 00186 //## in the PropertyList specific to @a renderer or is disabled there, the BaseRenderer-independent 00187 //## PropertyList of this DataNode is queried. 00188 //## @sa GetPropertyList 00189 //## @sa m_PropertyList 00190 //## @sa m_MapOfPropertyLists 00191 mitk::BaseProperty* GetProperty(const char *propertyKey, const mitk::BaseRenderer* renderer = NULL) const; 00192 00193 //##Documentation 00194 //## @brief Get the property of type T with key @a propertyKey from the PropertyList 00195 //## of the @a renderer, if available there, otherwise use the BaseRenderer-independent PropertyList. 00196 //## 00197 //## If @a renderer is @a NULL or the @a propertyKey cannot be found 00198 //## in the PropertyList specific to @a renderer or is disabled there, the BaseRenderer-independent 00199 //## PropertyList of this DataNode is queried. 00200 //## @sa GetPropertyList 00201 //## @sa m_PropertyList 00202 //## @sa m_MapOfPropertyLists 00203 template <typename T> 00204 bool GetProperty(itk::SmartPointer<T> &property, const char *propertyKey, const mitk::BaseRenderer* renderer = NULL) const 00205 { 00206 property = dynamic_cast<T *>(GetProperty(propertyKey, renderer)); 00207 return property.IsNotNull(); 00208 } 00209 00210 //##Documentation 00211 //## @brief Get the property of type T with key @a propertyKey from the PropertyList 00212 //## of the @a renderer, if available there, otherwise use the BaseRenderer-independent PropertyList. 00213 //## 00214 //## If @a renderer is @a NULL or the @a propertyKey cannot be found 00215 //## in the PropertyList specific to @a renderer or is disabled there, the BaseRenderer-independent 00216 //## PropertyList of this DataNode is queried. 00217 //## @sa GetPropertyList 00218 //## @sa m_PropertyList 00219 //## @sa m_MapOfPropertyLists 00220 template <typename T> 00221 bool GetProperty(T* &property, const char *propertyKey, const mitk::BaseRenderer* renderer = NULL) const 00222 { 00223 property = dynamic_cast<T *>(GetProperty(propertyKey, renderer)); 00224 return property!=NULL; 00225 } 00226 00227 //##Documentation 00228 //## @brief Convenience access method for GenericProperty<T> properties 00229 //## (T being the type of the second parameter) 00230 //## @return @a true property was found 00231 template <typename T> 00232 bool GetPropertyValue(const char* propertyKey, T & value, mitk::BaseRenderer* renderer=NULL) const 00233 #ifdef _MSC_VER 00234 { 00235 GenericProperty<T>* gp= dynamic_cast<GenericProperty<T>*>(GetProperty(propertyKey, renderer)); 00236 if ( gp != NULL ) 00237 { 00238 value = gp->GetValue(); 00239 return true; 00240 } 00241 return false; 00242 } 00243 #else 00244 ; 00245 #endif 00246 00247 // @brief Get a set of all group tags from this node's property list 00248 GroupTagList GetGroupTags() const; 00249 00250 //##Documentation 00251 //## @brief Convenience access method for bool properties (instances of 00252 //## BoolProperty) 00253 //## @return @a true property was found 00254 bool GetBoolProperty(const char* propertyKey, bool &boolValue, mitk::BaseRenderer* renderer = NULL) const; 00255 00256 //##Documentation 00257 //## @brief Convenience access method for int properties (instances of 00258 //## IntProperty) 00259 //## @return @a true property was found 00260 bool GetIntProperty(const char* propertyKey, int &intValue, mitk::BaseRenderer* renderer=NULL) const; 00261 00262 //##Documentation 00263 //## @brief Convenience access method for float properties (instances of 00264 //## FloatProperty) 00265 //## @return @a true property was found 00266 bool GetFloatProperty(const char* propertyKey, float &floatValue, mitk::BaseRenderer* renderer = NULL) const; 00267 00268 //##Documentation 00269 //## @brief Convenience access method for string properties (instances of 00270 //## StringProperty) 00271 //## @return @a true property was found 00272 bool GetStringProperty(const char* propertyKey, std::string& string, mitk::BaseRenderer* renderer = NULL) const; 00273 00274 //##Documentation 00275 //## @brief Convenience access method for color properties (instances of 00276 //## ColorProperty) 00277 //## @return @a true property was found 00278 bool GetColor(float rgb[3], mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "color") const; 00279 00280 //##Documentation 00281 //## @brief Convenience access method for level-window properties (instances of 00282 //## LevelWindowProperty) 00283 //## @return @a true property was found 00284 bool GetLevelWindow(mitk::LevelWindow &levelWindow, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "levelwindow") const; 00285 00286 //## 00287 //##Documentation 00288 //## @brief set the node as selected 00289 void SetSelected(bool selected, mitk::BaseRenderer* renderer=NULL); 00290 00291 //## 00292 //##Documentation 00293 //## @brief set the node as selected 00294 //## @return @a true node is selected 00295 bool IsSelected(mitk::BaseRenderer* renderer=NULL); 00296 00297 //##Documentation 00298 //## @brief Convenience access method for accessing the name of an object (instance of 00299 //## StringProperty with property-key "name") 00300 //## @return @a true property was found 00301 bool GetName(std::string& nodeName, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "name") const 00302 { 00303 return GetStringProperty(propertyKey, nodeName, renderer); 00304 } 00305 00306 //##Documentation 00307 //## @brief Extra convenience access method for accessing the name of an object (instance of 00308 //## StringProperty with property-key "name"). 00309 //## 00310 //## This method does not take the renderer specific 00311 //## propertylists into account, because the name of an object should never be renderer specific. 00312 //## @returns a std::string with the name of the object (content of "name" Property). 00313 //## If there is no "name" Property, an empty string will be returned. 00314 virtual std::string GetName() const 00315 { 00316 mitk::StringProperty* sp = dynamic_cast<mitk::StringProperty*>(this->GetProperty("name")); 00317 if (sp == NULL) 00318 return ""; 00319 return sp->GetValue(); 00320 } 00321 00322 //##Documentation 00323 //## @brief Extra convenience access method to set the name of an object. 00324 //## 00325 //## The name will be stored in the non-renderer-specific PropertyList in a StringProperty named "name". 00326 virtual void SetName( const char* name) 00327 { 00328 if (name == NULL) 00329 return; 00330 this->SetProperty("name", StringProperty::New(name)); 00331 } 00332 //##Documentation 00333 //## @brief Extra convenience access method to set the name of an object. 00334 //## 00335 //## The name will be stored in the non-renderer-specific PropertyList in a StringProperty named "name". 00336 virtual void SetName( const std::string name) 00337 { 00338 this->SetName(name.c_str()); 00339 } 00340 00341 //##Documentation 00342 //## @brief Convenience access method for visibility properties (instances 00343 //## of BoolProperty with property-key "visible") 00344 //## @return @a true property was found 00345 //## @sa IsVisible 00346 bool GetVisibility(bool &visible, mitk::BaseRenderer* renderer, const char* propertyKey = "visible") const 00347 { 00348 return GetBoolProperty(propertyKey, visible, renderer); 00349 } 00350 00351 //##Documentation 00352 //## @brief Convenience access method for opacity properties (instances of 00353 //## FloatProperty) 00354 //## @return @a true property was found 00355 bool GetOpacity(float &opacity, mitk::BaseRenderer* renderer, const char* propertyKey = "opacity") const; 00356 00357 //##Documentation 00358 //## @brief Convenience access method for boolean properties (instances 00359 //## of BoolProperty). Return value is the value of the property. If the property is 00360 //## not found, the value of @a defaultIsOn is returned. 00361 //## 00362 //## Thus, the return value has a different meaning than in the 00363 //## GetBoolProperty method! 00364 //## @sa GetBoolProperty 00365 bool IsOn(const char* propertyKey, mitk::BaseRenderer* renderer, bool defaultIsOn = true) const 00366 { 00367 if(propertyKey==NULL) 00368 return defaultIsOn; 00369 GetBoolProperty(propertyKey, defaultIsOn, renderer); 00370 return defaultIsOn; 00371 } 00372 00373 //##Documentation 00374 //## @brief Convenience access method for visibility properties (instances 00375 //## of BoolProperty). Return value is the visibility. Default is 00376 //## visible==true, i.e., true is returned even if the property (@a 00377 //## propertyKey) is not found. 00378 //## 00379 //## Thus, the return value has a different meaning than in the 00380 //## GetVisibility method! 00381 //## @sa GetVisibility 00382 //## @sa IsOn 00383 bool IsVisible(mitk::BaseRenderer* renderer, const char* propertyKey = "visible", bool defaultIsOn = true) const 00384 { 00385 return IsOn(propertyKey, renderer, defaultIsOn); 00386 } 00387 00388 //##Documentation 00389 //## @brief Convenience method for setting color properties (instances of 00390 //## ColorProperty) 00391 void SetColor(const mitk::Color &color, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "color"); 00392 //##Documentation 00393 //## @brief Convenience method for setting color properties (instances of 00394 //## ColorProperty) 00395 void SetColor(float red, float green, float blue, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "color"); 00396 //##Documentation 00397 //## @brief Convenience method for setting color properties (instances of 00398 //## ColorProperty) 00399 void SetColor(const float rgb[3], mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "color"); 00400 00401 //##Documentation 00402 //## @brief Convenience method for setting visibility properties (instances 00403 //## of BoolProperty) 00404 //## @param visible If set to true, the data will be rendered. If false, the render will skip this data. 00405 //## @param renderer Specify a renderer if the visibility shall be specific to a renderer 00406 //## @param propertykey Can be used to specify a user defined name of the visibility propery. 00407 void SetVisibility(bool visible, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "visible"); 00408 00409 //##Documentation 00410 //## @brief Convenience method for setting opacity properties (instances of 00411 //## FloatProperty) 00412 void SetOpacity(float opacity, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "opacity"); 00413 00414 //##Documentation 00415 //## @brief Convenience method for setting level-window properties 00416 //## (instances of LevelWindowProperty) 00417 void SetLevelWindow(mitk::LevelWindow levelWindow, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "levelwindow"); 00418 00419 //##Documentation 00420 //## @brief Convenience method for setting int properties (instances of 00421 //## IntProperty) 00422 void SetIntProperty(const char* propertyKey, int intValue, mitk::BaseRenderer* renderer=NULL); 00423 00424 //##Documentation 00425 //## @brief Convenience method for setting int properties (instances of 00426 //## IntProperty) 00427 void SetBoolProperty(const char* propertyKey, bool boolValue, mitk::BaseRenderer* renderer=NULL); 00428 00429 //##Documentation 00430 //## @brief Convenience method for setting int properties (instances of 00431 //## IntProperty) 00432 void SetFloatProperty(const char* propertyKey, float floatValue, mitk::BaseRenderer* renderer=NULL); 00433 00434 //##Documentation 00435 //## @brief Convenience method for setting int properties (instances of 00436 //## IntProperty) 00437 void SetStringProperty(const char* propertyKey, const char* string, mitk::BaseRenderer* renderer=NULL); 00438 00439 //##Documentation 00440 //## @brief Get the timestamp of the last change of the contents of this node or 00441 //## the referenced BaseData. 00442 virtual unsigned long GetMTime() const; 00443 00444 //##Documentation 00445 //## @brief Get the timestamp of the last change of the reference to the 00446 //## BaseData. 00447 unsigned long GetDataReferenceChangedTime() const 00448 { 00449 return m_DataReferenceChangedTime.GetMTime(); 00450 } 00451 00452 //##Documentation 00453 //## @brief Adds or removes the associated interactor to mitk::GLobalInteraction. 00454 //## 00455 virtual void SetInteractorEnabled( const bool& enabled ); 00456 00457 //##Documentation 00458 //## @brief Adds the interactor to mitk::GlobalInteraction 00459 //## 00460 virtual void EnableInteractor(); 00461 00462 //##Documentation 00463 //## @brief Removes the Interactor from mitk::GlobalInteraction 00464 //## 00465 virtual void DisableInteractor(); 00466 00467 //##Documentation 00468 //## @brief Tests, if the interactor is already added to mitk::GlobalInteraction 00469 //## 00470 virtual bool IsInteractorEnabled() const; 00471 00472 protected: 00473 DataNode(); 00474 00475 virtual ~DataNode(); 00476 00477 //## 00478 //## Invoked when the property list was modified. Calls Modified() of the DataNode 00479 virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event); 00480 00481 //##Documentation 00482 //## @brief Mapper-slots 00483 mutable MapperVector m_Mappers; 00484 00485 //##Documentation 00486 //## @brief The data object (instance of BaseData, e.g., an Image) managed 00487 //## by this DataNode 00488 BaseData::Pointer m_Data; 00489 00490 //##Documentation 00491 //## @brief BaseRenderer-independent PropertyList 00492 //## 00493 //## Properties herein can be overwritten specifically for each BaseRenderer 00494 //## by the BaseRenderer-specific properties defined in m_MapOfPropertyLists. 00495 PropertyList::Pointer m_PropertyList; 00496 00497 //##Documentation 00498 //## @brief Map associating each BaseRenderer with its own PropertyList 00499 mutable MapOfPropertyLists m_MapOfPropertyLists; 00500 00501 //##Documentation 00502 //## @brief Interactor, that handles the Interaction 00503 Interactor::Pointer m_Interactor; 00504 00505 //##Documentation 00506 //## @brief Timestamp of the last change of m_Data 00507 itk::TimeStamp m_DataReferenceChangedTime; 00508 00509 unsigned long m_PropertyListModifiedObserverTag; 00510 }; 00511 00512 00513 #if (_MSC_VER > 1200) || !defined(_MSC_VER) 00514 MITK_CORE_EXPORT MBI_STD::istream& operator>>( MBI_STD::istream& i, DataNode::Pointer& dtn ); 00515 00516 MITK_CORE_EXPORT MBI_STD::ostream& operator<<( MBI_STD::ostream& o, DataNode::Pointer& dtn); 00517 #endif 00518 } // namespace mitk 00519 00520 #if ((defined(_MSC_VER)) && (_MSC_VER <= 1200)) 00521 MITK_CORE_EXPORT MBI_STD::istream& operator>>( MBI_STD::istream& i, mitk::DataNode::Pointer& dtn ); 00522 00523 MITK_CORE_EXPORT MBI_STD::ostream& operator<<( MBI_STD::ostream& o, mitk::DataNode::Pointer& dtn); 00524 #endif 00525 00526 00527 #endif /* DATATREENODE_H_HEADER_INCLUDED_C1E14338 */ 00528 00529