diff --git a/Core/Code/DataManagement/mitkAnnotationProperty.cpp b/Core/Code/DataManagement/mitkAnnotationProperty.cpp index 8c35f10ae3..6fd1622acc 100644 --- a/Core/Code/DataManagement/mitkAnnotationProperty.cpp +++ b/Core/Code/DataManagement/mitkAnnotationProperty.cpp @@ -1,96 +1,107 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-04-14 19:45:53 +0200 (Mo, 14 Apr 2008) $ Version: $Revision: 14081 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkAnnotationProperty.h" mitk::AnnotationProperty::AnnotationProperty() { } mitk::AnnotationProperty::AnnotationProperty( const char *label, const Point3D &position ) : m_Label( "" ), m_Position( position ) { if ( label != NULL ) { m_Label = label; } } mitk::AnnotationProperty::AnnotationProperty( const std::string &label, const Point3D &position ) : m_Label( label ), m_Position( position ) { } mitk::AnnotationProperty::AnnotationProperty( const char *label, ScalarType x, ScalarType y, ScalarType z ) : m_Label( "" ) { if ( label != NULL ) { m_Label = label; } m_Position[0] = x; m_Position[1] = y; m_Position[2] = z; } mitk::AnnotationProperty::AnnotationProperty( const std::string &label, ScalarType x, ScalarType y, ScalarType z ) : m_Label( label ) { m_Position[0] = x; m_Position[1] = y; m_Position[2] = z; } const mitk::Point3D &mitk::AnnotationProperty::GetPosition() const { return m_Position; } void mitk::AnnotationProperty::SetPosition( const mitk::Point3D &position ) { - m_Position = position; + if (m_Position != position) + { + m_Position = position; + this->Modified(); + } } bool mitk::AnnotationProperty::IsEqual( const BaseProperty &property ) const { return ( (this->m_Label == static_cast(property).m_Label ) && (this->m_Position == static_cast(property).m_Position ) ); } +bool mitk::AnnotationProperty::Assign( const BaseProperty &property ) +{ + this->m_Label = static_cast(property).m_Label; + this->m_Position = static_cast(property).m_Position; + return true; +} + std::string mitk::AnnotationProperty::GetValueAsString() const { std::stringstream myStr; myStr << this->GetLabel() << this->GetPosition(); return myStr.str(); } diff --git a/Core/Code/DataManagement/mitkAnnotationProperty.h b/Core/Code/DataManagement/mitkAnnotationProperty.h index 863a2b6079..82c9de37b2 100644 --- a/Core/Code/DataManagement/mitkAnnotationProperty.h +++ b/Core/Code/DataManagement/mitkAnnotationProperty.h @@ -1,82 +1,87 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-04-14 19:45:53 +0200 (Mo, 14 Apr 2008) $ Version: $Revision: 14081 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKANNOTATIONPROPERTY_H_HEADER_INCLUDED #define MITKANNOTATIONPROPERTY_H_HEADER_INCLUDED #include #include "mitkBaseProperty.h" #include "mitkVector.h" #include #include namespace mitk { /** * \brief Property for annotations * \ingroup DataManagement */ class MITK_CORE_EXPORT AnnotationProperty : public BaseProperty { public: mitkClassMacro(AnnotationProperty, BaseProperty); typedef std::string ValueType; itkNewMacro( AnnotationProperty ); mitkNewMacro2Param( AnnotationProperty, const char *, const Point3D & ); mitkNewMacro2Param( AnnotationProperty, const std::string &, const Point3D & ); mitkNewMacro4Param( AnnotationProperty, const char *, ScalarType, ScalarType, ScalarType ); mitkNewMacro4Param( AnnotationProperty, const std::string &, ScalarType, ScalarType, ScalarType ); itkGetStringMacro( Label ); itkSetStringMacro( Label ); const Point3D &GetPosition() const; void SetPosition( const Point3D &position ); virtual std::string GetValueAsString() const; virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } \ protected: std::string m_Label; Point3D m_Position; AnnotationProperty(); AnnotationProperty( const char *label, const Point3D &position ); AnnotationProperty( const std::string &label, const Point3D &position ); AnnotationProperty( const char *label, ScalarType x, ScalarType y, ScalarType z ); AnnotationProperty( const std::string &label, ScalarType x, ScalarType y, ScalarType z ); private: - virtual bool IsEqual(const BaseProperty& property ) const; + // purposely not implemented + AnnotationProperty(const AnnotationProperty&); + AnnotationProperty& operator=(const AnnotationProperty&); + + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty & property); }; } // namespace mitk #endif /* MITKANNOTATIONPROPERTY_H_HEADER_INCLUDED */ diff --git a/Core/Code/DataManagement/mitkBaseProperty.cpp b/Core/Code/DataManagement/mitkBaseProperty.cpp index aa8fd9ec62..da02b1cd3a 100644 --- a/Core/Code/DataManagement/mitkBaseProperty.cpp +++ b/Core/Code/DataManagement/mitkBaseProperty.cpp @@ -1,56 +1,62 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkBaseProperty.h" mitk::BaseProperty::BaseProperty() { } mitk::BaseProperty::~BaseProperty() { } std::string mitk::BaseProperty::GetValueAsString() const { return std::string("n/a"); } -bool mitk::BaseProperty::Assignable( const BaseProperty& ) const +mitk::BaseProperty& mitk::BaseProperty::operator=(const BaseProperty& rhs) { - return false; + AssignProperty(rhs); + return *this; } -/*! - To be implemented more meaningful by subclasses. This version just accepts the assignment - of BaseProperty objects to others, but the assignment has NO MEANING, values are not changed at all! - */ -mitk::BaseProperty& mitk::BaseProperty::operator=(const BaseProperty& rhs) +bool mitk::BaseProperty::AssignProperty(const BaseProperty& rhs) { - if (this == &rhs) return *this; // no self assignment + if (this == &rhs) return true; // no self assignment - // place meaningful copy code here (nothing possible with BaseProeprties) + const char* t1 = typeid(this).name(); + const char* t2 = typeid(&rhs).name(); - return *this; + std::string s1(t1); + std::string s2(t2); + + if (typeid(*this) == typeid(rhs) && Assign(rhs)) + { + this->Modified(); + return true; + } + return false; } bool mitk::BaseProperty::operator==(const BaseProperty& property) const { return (typeid(*this) == typeid(property) && IsEqual(property)); } diff --git a/Core/Code/DataManagement/mitkBaseProperty.h b/Core/Code/DataManagement/mitkBaseProperty.h index 927129981e..c0365ec1e0 100644 --- a/Core/Code/DataManagement/mitkBaseProperty.h +++ b/Core/Code/DataManagement/mitkBaseProperty.h @@ -1,83 +1,102 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef BASEPROPERTY_H_HEADER_INCLUDED_C1F4DF54 #define BASEPROPERTY_H_HEADER_INCLUDED_C1F4DF54 #include #include #include #include namespace mitk { /*! \brief Abstract base class for properties \ingroup DataManagement Base class for properties. Properties are arbitrary additional information (to define a new type of information you have to define a subclass of BaseProperty) that can be added to a PropertyList. Concrete subclasses of BaseProperty should define Set-/Get-methods to assess the property value, which should be stored by value (not by reference). Subclasses must implement an operator==(const BaseProperty& property), which is used by PropertyList to check whether a property has been changed. */ class MITK_CORE_EXPORT BaseProperty : public itk::Object { public: mitkClassMacro(BaseProperty,itk::Object); /*! @brief Subclasses must implement IsEqual(const BaseProperty&) to support comparison. operator== which is used by PropertyList to check whether a property has been changed. */ bool operator==(const BaseProperty& property) const; - virtual BaseProperty& operator=(const BaseProperty& property); + /*! @brief Assigns property to this BaseProperty instance. + + Subclasses must implement Assign(const BaseProperty&) and call the superclass + Assign method for proper handling of polymorphic assignments. The assignment + operator of the subclass should be disabled and the baseclass operator should + be made visible using "using" statements. + */ + BaseProperty& operator=(const BaseProperty& property); + + /*! @brief Assigns property to this BaseProperty instance. + + This method is identical to the assignment operator, except for the return type. + It allows to directly check if the assignemnt was successfull. + */ + bool AssignProperty(const BaseProperty & property); virtual std::string GetValueAsString() const; - - /*! - Should be implemented by subclasses to indicate whether they can accept the parameter - as the right-hand-side argument of an assignment. This test will most probably include - some dynamic_cast. - */ - virtual bool Assignable(const BaseProperty& ) const; protected: BaseProperty(); virtual ~BaseProperty(); private: + /*! Override this method in subclasses to implement a meaningful comparison. The property argument is guaranteed to be castable to the type of the implementing subclass. */ virtual bool IsEqual(const BaseProperty& property) const = 0; + + /*! + Override this method in subclasses to implement a meaningful assignment. The property + argument is guaranteed to be castable to the type of the implementing subclass. + + @warning This is not yet exception aware/safe and if this method returns false, + this property's state might be undefined. + + @return True if the argument could be assigned to this property. + */ + virtual bool Assign(const BaseProperty& ) = 0; }; } // namespace mitk #endif /* BASEPROPERTY_H_HEADER_INCLUDED_C1F4DF54 */ diff --git a/Core/Code/DataManagement/mitkClippingProperty.cpp b/Core/Code/DataManagement/mitkClippingProperty.cpp index d4e07041c7..779d0502b0 100644 --- a/Core/Code/DataManagement/mitkClippingProperty.cpp +++ b/Core/Code/DataManagement/mitkClippingProperty.cpp @@ -1,91 +1,112 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-04-14 19:45:53 +0200 (Mo, 14 Apr 2008) $ Version: $Revision: 14081 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkClippingProperty.h" namespace mitk { ClippingProperty::ClippingProperty() : m_ClippingEnabled( false ) { } ClippingProperty::ClippingProperty( const Point3D &origin, const Vector3D &normal ) : m_ClippingEnabled( true ), m_Origin( origin ), m_Normal( normal ) { } bool ClippingProperty::GetClippingEnabled() const { return m_ClippingEnabled; } void ClippingProperty::SetClippingEnabled( bool enabled ) { - m_ClippingEnabled = enabled; + if (m_ClippingEnabled != enabled) + { + m_ClippingEnabled = enabled; + this->Modified(); + } } const Point3D &ClippingProperty::GetOrigin() const { return m_Origin; } void ClippingProperty::SetOrigin( const Point3D &origin ) { - m_Origin = origin; + if (m_Origin != origin) + { + m_Origin = origin; + this->Modified(); + } } const Vector3D &ClippingProperty::GetNormal() const { return m_Normal; } void ClippingProperty::SetNormal( const Vector3D &normal ) { - m_Normal = normal; + if (m_Normal != normal) + { + m_Normal = normal; + this->Modified(); + } } bool ClippingProperty::IsEqual( const BaseProperty &property ) const { - return ( (this->m_Origin == static_cast(property).m_Origin ) - && (this->m_Normal == static_cast(property).m_Normal ) ); + return ((this->m_ClippingEnabled == static_cast(property).m_ClippingEnabled) && + (this->m_Origin == static_cast(property).m_Origin ) && + (this->m_Normal == static_cast(property).m_Normal ) ); +} + +bool ClippingProperty::Assign( const BaseProperty &property ) +{ + this->m_ClippingEnabled = static_cast(property).m_ClippingEnabled; + this->m_Origin = static_cast(property).m_Origin; + this->m_Normal = static_cast(property).m_Normal; + return true; } std::string ClippingProperty::GetValueAsString() const { std::stringstream myStr; - myStr << this->GetOrigin() << this->GetNormal(); + myStr << this->GetClippingEnabled() << this->GetOrigin() << this->GetNormal(); return myStr.str(); } } // namespace diff --git a/Core/Code/DataManagement/mitkClippingProperty.h b/Core/Code/DataManagement/mitkClippingProperty.h index 31884fe57d..15eb5ff31a 100644 --- a/Core/Code/DataManagement/mitkClippingProperty.h +++ b/Core/Code/DataManagement/mitkClippingProperty.h @@ -1,80 +1,85 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-04-14 19:45:53 +0200 (Mo, 14 Apr 2008) $ Version: $Revision: 14081 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKCLIPPINGPROPERTY_H_HEADER_INCLUDED #define MITKCLIPPINGPROPERTY_H_HEADER_INCLUDED #include #include "mitkBaseProperty.h" #include "mitkVector.h" #include #include namespace mitk { /** * \brief Property for clipping datasets; currently only * clipping planes are possible * \ingroup DataManagement */ class MITK_CORE_EXPORT ClippingProperty : public BaseProperty { public: mitkClassMacro(ClippingProperty, BaseProperty); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } typedef std::string ValueType; itkNewMacro( ClippingProperty ); mitkNewMacro2Param( ClippingProperty, const Point3D &, const Vector3D & ); bool GetClippingEnabled() const; void SetClippingEnabled( bool enabled ); const Point3D &GetOrigin() const; void SetOrigin( const Point3D &origin ); const Vector3D &GetNormal() const; void SetNormal( const Vector3D &normal ); virtual std::string GetValueAsString() const; + using BaseProperty::operator =; protected: bool m_ClippingEnabled; Point3D m_Origin; Vector3D m_Normal; ClippingProperty(); ClippingProperty( const Point3D &origin, const Vector3D &normal ); private: - virtual bool IsEqual(const BaseProperty& property ) const; + // purposely not implemented + ClippingProperty(const ClippingProperty&); + ClippingProperty& operator=(const ClippingProperty&); + + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty& property); }; } // namespace mitk #endif /* MITKCLIPPINGPROPERTY_H_HEADER_INCLUDED */ diff --git a/Core/Code/DataManagement/mitkColorProperty.cpp b/Core/Code/DataManagement/mitkColorProperty.cpp index 6d1353091e..14ce2f7ec0 100644 --- a/Core/Code/DataManagement/mitkColorProperty.cpp +++ b/Core/Code/DataManagement/mitkColorProperty.cpp @@ -1,110 +1,88 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include "mitkColorProperty.h" mitk::ColorProperty::ColorProperty() : m_Color() { } mitk::ColorProperty::ColorProperty(const float color[3]) : m_Color(color) { } mitk::ColorProperty::ColorProperty(const float red, const float green, const float blue) { m_Color.Set(red, green, blue); } mitk::ColorProperty::ColorProperty(const mitk::Color & color) : m_Color(color) { } -bool mitk::ColorProperty::Assignable(const mitk::BaseProperty& other) const +bool mitk::ColorProperty::IsEqual(const BaseProperty& property) const { - try - { - dynamic_cast(other); // dear compiler, please don't optimize this away! - return true; - } - catch (std::bad_cast) - { - } - return false; + return this->m_Color == static_cast(property).m_Color; } -mitk::BaseProperty& mitk::ColorProperty::operator=(const mitk::BaseProperty& other) +bool mitk::ColorProperty::Assign(const BaseProperty& property) { - try - { - const Self& otherProp( dynamic_cast(other) ); - - if (this->m_Color != otherProp.m_Color) - { - this->m_Color = otherProp.m_Color; - this->Modified(); - } - } - catch (std::bad_cast) - { - // nothing to do then - } - - return *this; - } - - -bool mitk::ColorProperty::IsEqual(const BaseProperty& property) const -{ - return this->m_Color == static_cast(property).m_Color; + this->m_Color = static_cast(property).m_Color; + return true; } const mitk::Color & mitk::ColorProperty::GetColor() const { return m_Color; } void mitk::ColorProperty::SetColor(const mitk::Color & color ) { if(m_Color!=color) { m_Color = color; Modified(); } } +void mitk::ColorProperty::SetValue(const mitk::Color & color ) +{ + SetColor(color); +} + void mitk::ColorProperty::SetColor( float red, float green, float blue ) { - m_Color.Set(red, green, blue); + float tmp[3] = { red, green, blue }; + SetColor(mitk::Color(tmp)); } std::string mitk::ColorProperty::GetValueAsString() const { std::stringstream myStr; myStr.imbue(std::locale::classic()); myStr << GetValue() ; return myStr.str(); } const mitk::Color & mitk::ColorProperty::GetValue() const { return GetColor(); } diff --git a/Core/Code/DataManagement/mitkColorProperty.h b/Core/Code/DataManagement/mitkColorProperty.h index fe37ce7144..311da9e436 100644 --- a/Core/Code/DataManagement/mitkColorProperty.h +++ b/Core/Code/DataManagement/mitkColorProperty.h @@ -1,78 +1,85 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKCOLORPROPERTY_H_HEADER_INCLUDED_C17953D1 #define MITKCOLORPROPERTY_H_HEADER_INCLUDED_C17953D1 #include #include "mitkBaseProperty.h" #include namespace mitk { //##Documentation //## @brief Standard RGB color typedef (float) //## //## Standard RGB color typedef to get rid of template argument (float). //## @ingroup Property typedef itk::RGBPixel< float > Color; //##Documentation //## @brief RGB color property //## //## @ingroup DataManagement class MITK_CORE_EXPORT ColorProperty : public BaseProperty { protected: mitk::Color m_Color; ColorProperty(); ColorProperty(const float red, const float green, const float blue); ColorProperty(const float color[3]); ColorProperty(const mitk::Color & color); public: mitkClassMacro(ColorProperty, BaseProperty); itkNewMacro(ColorProperty); mitkNewMacro1Param(ColorProperty, const float*); mitkNewMacro1Param(ColorProperty, const mitk::Color&); mitkNewMacro3Param(ColorProperty, const float, const float, const float); - - virtual bool Assignable(const BaseProperty& other) const; - virtual BaseProperty& operator=(const BaseProperty& other); + + typedef mitk::Color ValueType; const mitk::Color & GetColor() const; const mitk::Color & GetValue() const; std::string GetValueAsString() const; void SetColor(const mitk::Color & color ); + void SetValue(const mitk::Color & color ); void SetColor( float red, float green, float blue ); + using BaseProperty::operator=; + private: + // purposely not implemented + ColorProperty(const ColorProperty&); + ColorProperty& operator=(const ColorProperty&); + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty & property); }; } // namespace mitk #endif /* MITKCOLORPROPERTY_H_HEADER_INCLUDED_C17953D1 */ diff --git a/Core/Code/DataManagement/mitkEnumerationProperty.cpp b/Core/Code/DataManagement/mitkEnumerationProperty.cpp index f45845c89a..4cdcc2dbfd 100644 --- a/Core/Code/DataManagement/mitkEnumerationProperty.cpp +++ b/Core/Code/DataManagement/mitkEnumerationProperty.cpp @@ -1,185 +1,196 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkEnumerationProperty.h" #include // static map members of EnumerationProperty. These Maps point to per-classname-maps of ID <-> String. Accessed by GetEnumIds() and GetEnumString(). mitk::EnumerationProperty::IdMapForClassNameContainerType mitk::EnumerationProperty::s_IdMapForClassName; mitk::EnumerationProperty::StringMapForClassNameContainerType mitk::EnumerationProperty::s_StringMapForClassName; mitk::EnumerationProperty::EnumerationProperty() { m_CurrentValue = 0; } bool mitk::EnumerationProperty::AddEnum( const std::string& name, const IdType& id ) { if ( ( ! IsValidEnumerationValue( name ) ) && ( ! IsValidEnumerationValue( id ) ) ) { GetEnumIds().insert( std::make_pair( id, name ) ); GetEnumStrings().insert( std::make_pair( name, id ) ); return true; } else { return false; } } bool mitk::EnumerationProperty::SetValue( const std::string& name ) { if ( IsValidEnumerationValue( name ) ) { m_CurrentValue = GetEnumId( name ); Modified(); return true; } else { return false; } } bool mitk::EnumerationProperty::SetValue( const IdType& id ) { if ( IsValidEnumerationValue( id ) ) { m_CurrentValue = id; Modified(); return true; } else { return false; } } mitk::EnumerationProperty::IdType mitk::EnumerationProperty::GetValueAsId() const { return m_CurrentValue; } std::string mitk::EnumerationProperty::GetValueAsString() const { return GetEnumString( m_CurrentValue ); } void mitk::EnumerationProperty::Clear() { GetEnumIds().clear(); GetEnumStrings().clear(); m_CurrentValue = 0; } mitk::EnumerationProperty::EnumIdsContainerType::size_type mitk::EnumerationProperty::Size() const { return GetEnumIds().size(); } mitk::EnumerationProperty::EnumConstIterator mitk::EnumerationProperty::Begin() const { return GetEnumIds().begin(); } mitk::EnumerationProperty::EnumConstIterator mitk::EnumerationProperty::End() const { return GetEnumIds().end(); } std::string mitk::EnumerationProperty::GetEnumString( const IdType& id ) const { if ( IsValidEnumerationValue( id ) ) { return GetEnumIds().find( id )->second; } else { return "invalid enum id or enums empty"; } } mitk::EnumerationProperty::IdType mitk::EnumerationProperty::GetEnumId( const std::string& name ) const { if ( IsValidEnumerationValue( name ) ) { return GetEnumStrings().find( name )->second; } else { return 0; } } bool mitk::EnumerationProperty::IsEqual( const BaseProperty& property ) const { const Self& other = static_cast(property); return this->Size() == other.Size() && this->GetValueAsId() == other.GetValueAsId() && std::equal( this->Begin(), this->End(), other.Begin() ); } +bool mitk::EnumerationProperty::Assign( const BaseProperty& property ) +{ + const Self& other = static_cast(property); + this->GetEnumIds() = other.GetEnumIds(); + this->GetEnumStrings() = other.GetEnumStrings(); + this->m_CurrentValue = other.m_CurrentValue; + this->Size() == other.Size() && this->GetValueAsId() == other.GetValueAsId() && + std::equal( this->Begin(), this->End(), other.Begin() ); + return true; +} + bool mitk::EnumerationProperty::IsValidEnumerationValue( const IdType& val ) const { return ( GetEnumIds().find( val ) != GetEnumIds().end() ); } bool mitk::EnumerationProperty::IsValidEnumerationValue( const std::string& val ) const { return ( GetEnumStrings().find( val ) != GetEnumStrings().end() ); } mitk::EnumerationProperty::EnumIdsContainerType& mitk::EnumerationProperty::GetEnumIds() { std::string className = this->GetNameOfClass(); // virtual! return s_IdMapForClassName[ className ]; } const mitk::EnumerationProperty::EnumIdsContainerType& mitk::EnumerationProperty::GetEnumIds() const { std::string className = this->GetNameOfClass(); // virtual! return s_IdMapForClassName[ className ]; } mitk::EnumerationProperty::EnumStringsContainerType& mitk::EnumerationProperty::GetEnumStrings() { std::string className = this->GetNameOfClass(); // virtual! return s_StringMapForClassName[ className ]; } const mitk::EnumerationProperty::EnumStringsContainerType& mitk::EnumerationProperty::GetEnumStrings() const { std::string className = this->GetNameOfClass(); // virtual! return s_StringMapForClassName[ className ]; } diff --git a/Core/Code/DataManagement/mitkEnumerationProperty.h b/Core/Code/DataManagement/mitkEnumerationProperty.h index 7351960ace..b567e796eb 100644 --- a/Core/Code/DataManagement/mitkEnumerationProperty.h +++ b/Core/Code/DataManagement/mitkEnumerationProperty.h @@ -1,216 +1,218 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITK_ENUMERATION_PROPERTY__H_ #define _MITK_ENUMERATION_PROPERTY__H_ #include "mitkBaseProperty.h" #include #include namespace mitk { /** * This class may be used to store properties similar to enumeration values. * Each enumeration value is identified via a string representation and a * id. Note, that both string representation and id MUST be unique. This is checked * when inserting a new enumeration value. Please note that you have to add valid * enumeration values before you may use the Get/SetValue methods. * * To use the class enumeration property you have 2 choices: * * 1. Directly use the class and add your possible enumeration values via * AddEnum(name, id). NOte that the ids do not have to be in any order, they * just have to be unique. The current value is set via SetValue(...) and * retrieved via GetValueAsId() or GetValueAsString(). * 2. Create a subclass, which adds the possible enumeration values in its * constructor and maybe adds some additional convenience functions to * set/get the value. NOte that you should override AddEnum(...) as protected * so that the user may not add additional invalid enumeration values. * As example see mitk::VtkRepresentationProperty or mitk::VtkInterpolationProperty * * @ingroup DataManagement */ class MITK_CORE_EXPORT EnumerationProperty : public BaseProperty { public: mitkClassMacro( EnumerationProperty, BaseProperty ); itkNewMacro(EnumerationProperty); /** * Represents the unique id which is asigned to each enumeration value */ typedef unsigned int IdType; /** * Type used to store a mapping from enumeration id to enumeration string/ * description */ typedef std::map EnumIdsContainerType; /** * Type used to store a mapping from enumeration string/description to * enumeration id */ typedef std::map EnumStringsContainerType; /** * Type used for iterators over all defined enumeration values. */ typedef EnumIdsContainerType::const_iterator EnumConstIterator; /** * Adds an enumeration value into the enumeration. The name and id provided * must be unique. This is checked while adding the new enumeration value. * If it is not unique, false is returned. If addition was successful, true * is returned. * @param name the unique string representation of the enumeration value * @param id the unique integer representation of the enumeration value * @returns true, if the name/id combination was successfully added to the * enumeration values or true otherwise */ virtual bool AddEnum( const std::string& name, const IdType& id ); /** * Sets the current value of the enumeration * @param name the string representation of the enumeration value to set * @returns true if the value was successfully set (i.e. it was valid), or * false, if the name provided is incalid. */ virtual bool SetValue( const std::string& name ); /** * Sets the current value of the enumeration * @param id the integer representation of the enumeration value to set * @returns true if the value was successfully set (i.e. it was valid), or * false, if the id provided is invalid. */ virtual bool SetValue( const IdType& id ); /** * Returns the id of the current enumeration value. If it was not yet set, * the return value is unspecified */ virtual IdType GetValueAsId() const; /** * Returns the string representation of the current enumeration value. If it * was not yet set, the return value is unspecified */ virtual std::string GetValueAsString() const; /** * Clears all possible enumeration values and the current enumeration value. */ virtual void Clear(); /** * Determines the number of enumeration values which have been added via * AddEnum(...). * @returns the number of enumeration values associated with this Enumeration * Property */ virtual EnumIdsContainerType::size_type Size() const; /** * Provides access to the set of known enumeration values. The string representation * may be accessed via iterator->second, the id may be access via iterator->first * @returns an iterator over all enumeration values. */ virtual EnumConstIterator Begin() const; /** * Specifies the end of the range of the known enumeration values. * @returns an iterator pointing past the last known element of the possible * enumeration values. */ virtual EnumConstIterator End() const; /** * Returns the string representation for the given id. * @param id the id for which the string representation should be determined * if id is invalid, the return value is unspecified. * @returns the string representation of the given enumeration value */ virtual std::string GetEnumString( const IdType& id ) const; /** * Returns the integer representation for the given string. * @param name the enumeration name for which the integer representation should be determined * if the name is invalid, the return value is unspecified. * @returns the integer representation of the given enumeration value */ virtual IdType GetEnumId( const std::string& name ) const; /** * Determines if a given integer representation of an enumeration value * is valid or not * @param val the integer value to check * @returns true if the given value is valid or false otherwise */ virtual bool IsValidEnumerationValue( const IdType& val ) const; /** * Determines if a given string representation of an enumeration value * is valid or not * @param val the string to check * @returns true if the given value is valid or false otherwise */ virtual bool IsValidEnumerationValue( const std::string& val ) const; - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } const EnumIdsContainerType& GetEnumIds() const; const EnumStringsContainerType& GetEnumStrings() const; EnumIdsContainerType& GetEnumIds(); EnumStringsContainerType& GetEnumStrings(); + + using BaseProperty::operator=; protected: /** * Default constructor. The current value of the enumeration is undefined. */ EnumerationProperty(); -private: - virtual bool IsEqual( const BaseProperty& property ) const; + virtual bool Assign( const BaseProperty& property ); - IdType m_CurrentValue; +private: - EnumIdsContainerType m_EnumIds; + // purposely not implemented + EnumerationProperty(const EnumerationProperty&); + EnumerationProperty& operator=(const EnumerationProperty&); - EnumStringsContainerType m_EnumStrings; + IdType m_CurrentValue; typedef std::map IdMapForClassNameContainerType; typedef std::map StringMapForClassNameContainerType; static IdMapForClassNameContainerType s_IdMapForClassName; static StringMapForClassNameContainerType s_StringMapForClassName; }; } // namespace #endif diff --git a/Core/Code/DataManagement/mitkGenericLookupTable.h b/Core/Code/DataManagement/mitkGenericLookupTable.h index 1023a0708d..bed91d26a5 100644 --- a/Core/Code/DataManagement/mitkGenericLookupTable.h +++ b/Core/Code/DataManagement/mitkGenericLookupTable.h @@ -1,150 +1,162 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-06-24 19:37:48 +0200 (Di, 24 Jun 2008) $ Version: $Revision: 14641 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKGENERICLOOKUPTABLE_H_HEADER_INCLUDED_C1061CEE #define MITKGENERICLOOKUPTABLE_H_HEADER_INCLUDED_C1061CEE #include #include #include #include #include #include "mitkVector.h" #include namespace mitk { /** * @brief Template class for generating lookup-tables * * This class template can be instantiated for all classes/internal types that fulfills * these requirements: * - an operator<< so that the properties value can be put into a std::stringstream * - an operator== so that two properties can be checked for equality * * The main purpose of this class is to be used in conjunction with * GenericLookupTableProperty. This enables passing of arbitrary lookup * tables to mappers to configure the rendering process. */ template class GenericLookupTable { public: typedef unsigned int IdentifierType; typedef T ValueType; typedef std::map< IdentifierType, ValueType > LookupTableType; typedef GenericLookupTable Self; GenericLookupTable() {} virtual ~GenericLookupTable() { } virtual const char *GetNameOfClass() const { return "GenericLookupTable"; } void SetTableValue( IdentifierType id, ValueType value ) { m_LookupTable[id] = value; } bool ValueExists(IdentifierType id) const { typename LookupTableType::const_iterator it = m_LookupTable.find(id); return (it != m_LookupTable.end()); } ValueType GetTableValue( IdentifierType id ) const { typename LookupTableType::const_iterator it = m_LookupTable.find(id); if (it != m_LookupTable.end()) return it->second; else throw std::range_error("id does not exist in the lookup table"); } const LookupTableType& GetLookupTable() const { return m_LookupTable; } bool operator==( const Self& lookupTable ) const { return (m_LookupTable == lookupTable.m_LookupTable); } bool operator!=( const Self& lookupTable ) const { return !(m_LookupTable == lookupTable.m_LookupTable); } virtual Self& operator=(const Self& other) // \TODO: this needs to be unit tested! { if ( this == &other ) { return *this; } else { m_LookupTable.clear(); m_LookupTable = other.m_LookupTable; return *this; } } protected: LookupTableType m_LookupTable; }; } // namespace mitk /** * Generates a specialized subclass of mitk::GenericLookupTable. * This way, GetNameOfClass() returns the value provided by LookupTableName. * Please see mitkProperties.h for examples. * @param LookupTableName the name of the instantiation of GenericLookupTable * @param Type the value type of the GenericLookupTable */ #define mitkSpecializeGenericLookupTable(LookupTableName,Type) \ class MITK_CORE_EXPORT LookupTableName: public GenericLookupTable< Type > \ { \ public: \ typedef LookupTableName Self; \ typedef GenericLookupTable< Type > Superclass; \ virtual const char *GetNameOfClass() const \ {return #LookupTableName;} \ LookupTableName() {} \ virtual Superclass& operator=(const Superclass& other) { return Superclass::operator=(other); } \ virtual ~LookupTableName() {} \ }; \ MITK_CORE_EXPORT std::ostream& operator<<(std::ostream& stream, const LookupTableName& /*l*/); /** * Generates the ostream << operator for the lookuptable. This definition * of a global function must be in a cpp file, therefore it is split from the * class declaration macro mitkSpecializeGenericLookupTable. */ #define mitkSpecializeGenericLookupTableOperator(LookupTableName) \ -std::ostream& mitk::operator<<(std::ostream& stream, const LookupTableName& /*l*/) \ +std::ostream& mitk::operator<<(std::ostream& stream, const LookupTableName& l) \ { \ - return stream; \ + typedef typename LookupTableName::LookupTableType::const_iterator IterType; \ + IterType e = l.GetLookupTable().end(); \ + IterType b = l.GetLookupTable().begin(); \ + stream << "["; \ + for (IterType i = b; i != e; ++i) \ + { \ + if (i != b) \ + { \ + stream << ", "; \ + } \ + stream << i->first << " -> " << i->second; \ + } \ + return stream << "]"; \ }; #endif diff --git a/Core/Code/DataManagement/mitkGenericProperty.h b/Core/Code/DataManagement/mitkGenericProperty.h index 5da251b791..b06430e7ed 100644 --- a/Core/Code/DataManagement/mitkGenericProperty.h +++ b/Core/Code/DataManagement/mitkGenericProperty.h @@ -1,134 +1,119 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE #define MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE #include #include #include #include "mitkVector.h" #include #include "mitkBaseProperty.h" namespace mitk { /*! @ brief Template class for generating properties for int, float, bool, etc. This class template can be instantiated for all classes/internal types that fulfills these requirements: - an operator<< so that the properties value can be put into a std::stringstream - an operator== so that two properties can be checked for equality Note: you must use the macro mitkSpecializeGenericProperty to provide specializations for concrete types (e.g. BoolProperty). Please see mitkProperties.h for examples. If you don't use the mitkSpecializeGenericProperty Macro, GetNameOfClass() returns a wrong name. */ template -class GenericProperty : public BaseProperty +class MITK_EXPORT GenericProperty : public BaseProperty { public: mitkClassMacro(GenericProperty, BaseProperty); mitkNewMacro1Param(GenericProperty, T); typedef T ValueType; itkSetMacro(Value,T); itkGetConstMacro(Value,T); virtual std::string GetValueAsString() const { std::stringstream myStr; myStr << GetValue() ; return myStr.str(); } - - virtual bool Assignable(const BaseProperty& other) const - { - try - { - dynamic_cast(other); // dear compiler, please don't optimize this away! - return true; - } - catch (std::bad_cast) - { - } - return false; - } - virtual BaseProperty& operator=(const BaseProperty& other) - { - try - { - const Self& otherProp( dynamic_cast(other) ); - - if (this->m_Value != otherProp.m_Value) - { - this->m_Value = otherProp.m_Value; - this->Modified(); - } - } - catch (std::bad_cast) - { - // nothing to do then - } - - return *this; - } + using BaseProperty::operator=; protected: GenericProperty() {} GenericProperty(T x) : m_Value(x) {} T m_Value; private: + // purposely not implemented + GenericProperty(const GenericProperty&); + GenericProperty& operator=(const GenericProperty&); + virtual bool IsEqual(const BaseProperty& other) const { return (this->m_Value == static_cast(other).m_Value); } + + virtual bool Assign(const BaseProperty& other) + { + this->m_Value = static_cast(other).m_Value; + return true; + } }; } // namespace mitk /** * Generates a specialized subclass of mitk::GenericProperty. * This way, GetNameOfClass() returns the value provided by PropertyName. * Please see mitkProperties.h for examples. - * @param PropertyName the name of the instantiation of GenericProperty + * @param PropertyName the name of the subclass of GenericProperty * @param Type the value type of the GenericProperty + * @param Export the export macro for DLL usage */ -#define mitkSpecializeGenericProperty(PropertyName,Type,DefaultValue) \ -class MITK_EXPORT PropertyName: public GenericProperty< Type > \ -{ \ -public: \ - mitkClassMacro(PropertyName, GenericProperty< Type >); \ - itkNewMacro(PropertyName); \ - mitkNewMacro1Param(PropertyName, Type); \ -protected: \ - PropertyName() { m_Value = DefaultValue; } \ - PropertyName(Type x) : GenericProperty(x) {} \ +#define mitkDeclareGenericProperty(PropertyName,Type,Export) \ +class Export PropertyName: public GenericProperty< Type > \ +{ \ +public: \ + mitkClassMacro(PropertyName, GenericProperty< Type >); \ + itkNewMacro(PropertyName); \ + mitkNewMacro1Param(PropertyName, Type); \ + using BaseProperty::operator=; \ +protected: \ + PropertyName(); \ + PropertyName(Type x); \ }; +#define mitkDefineGenericProperty(PropertyName,Type,DefaultValue) \ + mitk::PropertyName::PropertyName() : Superclass(DefaultValue) { } \ + mitk::PropertyName::PropertyName(Type x) : Superclass(x) {} + #endif /* MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE */ diff --git a/Core/Code/DataManagement/mitkGroupTagProperty.cpp b/Core/Code/DataManagement/mitkGroupTagProperty.cpp index 0a885f1243..d1656bec9d 100644 --- a/Core/Code/DataManagement/mitkGroupTagProperty.cpp +++ b/Core/Code/DataManagement/mitkGroupTagProperty.cpp @@ -1,50 +1,36 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkGroupTagProperty.h" mitk::GroupTagProperty::GroupTagProperty() : mitk::BaseProperty() { } - -/*! - Should be implemented by subclasses to indicate whether they can accept the parameter - as the right-hand-side argument of an assignment. This test will most probably include - some dynamic_cast. - */ -bool mitk::GroupTagProperty::Assignable(const BaseProperty& other) const +bool mitk::GroupTagProperty::IsEqual(const BaseProperty& property) const { - try - { - dynamic_cast(other); // dear compiler, please don't optimize this away! - return true; - } - catch (std::bad_cast) - { - } - return false; + // if other property is also a GroupTagProperty, then it is equal to us, because tags have no value themselves + return true; } -bool mitk::GroupTagProperty::IsEqual(const BaseProperty& property) const +bool mitk::GroupTagProperty::Assign(const BaseProperty& property) { - // if other property is also a GroupTagProperty, then it is equal to us, because tags have no value themselves return true; } diff --git a/Core/Code/DataManagement/mitkGroupTagProperty.h b/Core/Code/DataManagement/mitkGroupTagProperty.h index cd97498aa5..cdd3c8d30c 100644 --- a/Core/Code/DataManagement/mitkGroupTagProperty.h +++ b/Core/Code/DataManagement/mitkGroupTagProperty.h @@ -1,55 +1,59 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef GROUPTAGPROPERTY_H_HEADER_INCLUDED_C1F4DF54 #define GROUPTAGPROPERTY_H_HEADER_INCLUDED_C1F4DF54 #include namespace mitk { /*! @brief Property class that has no value. @ingroup DataManagement The GroupTag property is used to tag a datatree node to show, that it is member of a group of datatree nodes. This can be used to build groups of datatreenodes without the need to contain them in a specific hiearchic order in the datatree */ class MITK_CORE_EXPORT GroupTagProperty : public BaseProperty { public: mitkClassMacro(GroupTagProperty, BaseProperty); itkNewMacro(GroupTagProperty); - virtual bool Assignable(const BaseProperty& other) const; - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - + using BaseProperty::operator=; + protected: GroupTagProperty(); private: + // purposely not implemented + GroupTagProperty(const GroupTagProperty&); + GroupTagProperty& operator=(const GroupTagProperty&); + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty& property); }; } // namespace mitk #endif /* GROUPTAGPROPERTY_H_HEADER_INCLUDED_C1F4DF54 */ diff --git a/Core/Code/DataManagement/mitkLevelWindowProperty.cpp b/Core/Code/DataManagement/mitkLevelWindowProperty.cpp index 9a24ab849b..7c014991aa 100755 --- a/Core/Code/DataManagement/mitkLevelWindowProperty.cpp +++ b/Core/Code/DataManagement/mitkLevelWindowProperty.cpp @@ -1,59 +1,75 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkLevelWindowProperty.h" mitk::LevelWindowProperty::LevelWindowProperty() { } mitk::LevelWindowProperty::LevelWindowProperty(const mitk::LevelWindow &levWin) { SetLevelWindow(levWin); } mitk::LevelWindowProperty::~LevelWindowProperty() { } bool mitk::LevelWindowProperty::IsEqual(const BaseProperty& property) const { return this->m_LevWin == static_cast(property).m_LevWin; } +bool mitk::LevelWindowProperty::Assign(const BaseProperty& property) +{ + this->m_LevWin = static_cast(property).m_LevWin; + return true; +} + const mitk::LevelWindow & mitk::LevelWindowProperty::GetLevelWindow() const { return m_LevWin; } +const mitk::LevelWindow & mitk::LevelWindowProperty::GetValue() const +{ + return GetLevelWindow(); +} + void mitk::LevelWindowProperty::SetLevelWindow(const mitk::LevelWindow &levWin) { if(m_LevWin != levWin) { m_LevWin = levWin; Modified(); } } +void mitk::LevelWindowProperty::SetValue(const ValueType& levWin) +{ + SetLevelWindow(levWin); +} + std::string mitk::LevelWindowProperty::GetValueAsString() const { std::stringstream myStr; myStr << "L:" << m_LevWin.GetLevel() << " W:" << m_LevWin.GetWindow(); return myStr.str(); } diff --git a/Core/Code/DataManagement/mitkLevelWindowProperty.h b/Core/Code/DataManagement/mitkLevelWindowProperty.h index a9f8c6e968..db23f5216f 100755 --- a/Core/Code/DataManagement/mitkLevelWindowProperty.h +++ b/Core/Code/DataManagement/mitkLevelWindowProperty.h @@ -1,67 +1,76 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKLEVELWINDOWPROPERTY_H_HEADER_INCLUDED_C10EEAA8 #define MITKLEVELWINDOWPROPERTY_H_HEADER_INCLUDED_C10EEAA8 #include "mitkBaseProperty.h" #include "mitkLevelWindow.h" namespace mitk { //##Documentation //## @brief Property for level/window data //## //## @ingroup DataManagement class MITK_CORE_EXPORT LevelWindowProperty : public BaseProperty { protected: LevelWindow m_LevWin; LevelWindowProperty(); LevelWindowProperty(const mitk::LevelWindow &levWin); public: mitkClassMacro(LevelWindowProperty, BaseProperty); itkNewMacro(LevelWindowProperty); mitkNewMacro1Param(LevelWindowProperty, const mitk::LevelWindow&); - virtual ~LevelWindowProperty(); + typedef LevelWindow ValueType; - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } + virtual ~LevelWindowProperty(); const mitk::LevelWindow & GetLevelWindow() const; + const mitk::LevelWindow & GetValue() const; void SetLevelWindow(const LevelWindow &levWin); + void SetValue(const ValueType& levWin); virtual std::string GetValueAsString() const; + using BaseProperty::operator=; + private: + // purposely not implemented + LevelWindowProperty(const LevelWindowProperty&); + LevelWindowProperty& operator=(const LevelWindowProperty&); + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty& property); }; } // namespace mitk #endif /* MITKLEVELWINDOWPROPERTY_H_HEADER_INCLUDED_C10EEAA8 */ diff --git a/Core/Code/DataManagement/mitkLookupTable.cpp b/Core/Code/DataManagement/mitkLookupTable.cpp index f9065a98be..c8d9f5dfb9 100644 --- a/Core/Code/DataManagement/mitkLookupTable.cpp +++ b/Core/Code/DataManagement/mitkLookupTable.cpp @@ -1,288 +1,294 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkLookupTable.h" #include #include #include mitk::LookupTable::LookupTable() { m_LookupTable = vtkLookupTable::New(); this->SetRequestedRegionToLargestPossibleRegion(); } mitk::LookupTable::~LookupTable() { if ( m_LookupTable ) { m_LookupTable->Delete(); m_LookupTable = NULL; } } void mitk::LookupTable::SetVtkLookupTable( vtkLookupTable* lut ) { if(m_LookupTable == lut) { return; } if(m_LookupTable) { m_LookupTable->UnRegister(NULL); m_LookupTable = NULL; } if(lut) { lut->Register(NULL); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::ChangeOpacityForAll( float opacity ) { int noValues = m_LookupTable->GetNumberOfTableValues (); vtkFloatingPointType rgba[ 4 ]; for ( int i = 0;i < noValues;i++ ) { m_LookupTable->GetTableValue ( i, rgba ); rgba[ 3 ] = opacity; m_LookupTable->SetTableValue ( i, rgba ); } this->Modified(); // need to call modiefied, since LookupTableProperty seems to be unchanged so no widget-updat is executed } void mitk::LookupTable::ChangeOpacity(int index, float opacity ) { int noValues = m_LookupTable->GetNumberOfTableValues (); if (index>noValues) { MITK_INFO << "could not change opacity. index exceed size of lut ... " << std::endl; return; } vtkFloatingPointType rgba[ 4 ]; m_LookupTable->GetTableValue ( index, rgba ); rgba[ 3 ] = opacity; m_LookupTable->SetTableValue ( index, rgba ); this->Modified(); // need to call modiefied, since LookupTableProperty seems to be unchanged so no widget-updat is executed } vtkLookupTable* mitk::LookupTable::GetVtkLookupTable() const { return m_LookupTable; }; mitk::LookupTable::RawLookupTableType * mitk::LookupTable::GetRawLookupTable() const { if (m_LookupTable==NULL) MITK_INFO << "uuups..." << std::endl; return m_LookupTable->GetPointer( 0 ); }; /*! * \brief equality operator inplementation */ bool mitk::LookupTable::operator==( const mitk::LookupTable& other ) const { if ( m_LookupTable == other.GetVtkLookupTable()) return true; vtkLookupTable* olut = other.GetVtkLookupTable(); if (olut == NULL) return false; bool equal = (m_LookupTable->GetNumberOfColors() == olut->GetNumberOfColors()) && (m_LookupTable->GetTableRange()[0] == olut->GetTableRange()[0]) && (m_LookupTable->GetTableRange()[1] == olut->GetTableRange()[1]) && (m_LookupTable->GetHueRange()[0] == olut->GetHueRange()[0]) && (m_LookupTable->GetHueRange()[1] == olut->GetHueRange()[1]) && (m_LookupTable->GetSaturationRange()[0] == olut->GetSaturationRange()[0]) && (m_LookupTable->GetSaturationRange()[1] == olut->GetSaturationRange()[1]) && (m_LookupTable->GetValueRange()[0] == olut->GetValueRange()[0]) && (m_LookupTable->GetValueRange()[1] == olut->GetValueRange()[1]) && (m_LookupTable->GetAlphaRange()[0] == olut->GetAlphaRange()[0]) && (m_LookupTable->GetAlphaRange()[1] == olut->GetAlphaRange()[1]) && (m_LookupTable->GetRamp() == olut->GetRamp()) && (m_LookupTable->GetScale() == olut->GetScale()) && (m_LookupTable->GetAlpha() == olut->GetAlpha()) && (m_LookupTable->GetTable()->GetNumberOfTuples() == olut->GetTable()->GetNumberOfTuples()); if (equal == false) return false; //for (vtkIdType i=0; i < m_LookupTable->GetTable()->GetNumberOfTuples(); i++) //{ // if (m_LookupTable->GetTable()->GetTuple(i) != olut->GetTable()->GetTuple(i)) // return false; //} for (vtkIdType i=0; i < m_LookupTable->GetNumberOfTableValues(); i++) { bool tvequal = (m_LookupTable->GetTableValue(i)[0] == olut->GetTableValue(i)[0]) && (m_LookupTable->GetTableValue(i)[1] == olut->GetTableValue(i)[1]) && (m_LookupTable->GetTableValue(i)[2] == olut->GetTableValue(i)[2]) && (m_LookupTable->GetTableValue(i)[3] == olut->GetTableValue(i)[3]); if (tvequal == false) return false; } return true; } /*! * \brief un-equality operator implementation */ bool mitk::LookupTable::operator!=( const mitk::LookupTable& other ) const { return !(*this == other); } /*! * \brief assignment operator implementation */ mitk::LookupTable& mitk::LookupTable::operator=( const mitk::LookupTable& LookupTable ) { if ( this == &LookupTable ) { return * this; } else { m_LookupTable = LookupTable.GetVtkLookupTable(); return *this; } } void mitk::LookupTable::UpdateOutputInformation( ) { if ( this->GetSource( ) ) { this->GetSource( ) ->UpdateOutputInformation( ); } } void mitk::LookupTable::SetRequestedRegionToLargestPossibleRegion( ) {} bool mitk::LookupTable::RequestedRegionIsOutsideOfTheBufferedRegion( ) { return false; } bool mitk::LookupTable::VerifyRequestedRegion( ) { //normally we should check if the requested region lies within the //largest possible region. Since for lookup-tables we assume, that the //requested region is always the largest possible region, we can always //return true! return true; } void mitk::LookupTable::SetRequestedRegion( itk::DataObject *) { //not implemented, since we always want to have the RequestedRegion //to be set to LargestPossibleRegion } void mitk::LookupTable::CreateColorTransferFunction(vtkColorTransferFunction*& colorFunction) { if(colorFunction==NULL) colorFunction = vtkColorTransferFunction::New(); mitk::LookupTable::RawLookupTableType *rgba = GetRawLookupTable(); int i, num_of_values=m_LookupTable->GetNumberOfTableValues(); vtkFloatingPointType *cols; vtkFloatingPointType *colsHead; colsHead=cols=(vtkFloatingPointType *)malloc(sizeof(vtkFloatingPointType)*num_of_values*3); for(i=0;iBuildFunctionFromTable(m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values-1, colsHead); free(colsHead); } void mitk::LookupTable::CreateOpacityTransferFunction(vtkPiecewiseFunction*& opacityFunction) { if(opacityFunction==NULL) opacityFunction = vtkPiecewiseFunction::New(); mitk::LookupTable::RawLookupTableType *rgba = GetRawLookupTable(); int i, num_of_values=m_LookupTable->GetNumberOfTableValues(); vtkFloatingPointType *alphas; vtkFloatingPointType *alphasHead; alphasHead=alphas=(vtkFloatingPointType*)malloc(sizeof(vtkFloatingPointType)*num_of_values); rgba+=3; for(i=0;iBuildFunctionFromTable(m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values-1, alphasHead); free(alphasHead); } void mitk::LookupTable::CreateGradientTransferFunction(vtkPiecewiseFunction*& gradientFunction) { if(gradientFunction==NULL) gradientFunction = vtkPiecewiseFunction::New(); mitk::LookupTable::RawLookupTableType *rgba = GetRawLookupTable(); int i, num_of_values=m_LookupTable->GetNumberOfTableValues(); vtkFloatingPointType *alphas; vtkFloatingPointType *alphasHead; alphasHead=alphas=(vtkFloatingPointType*)malloc(sizeof(vtkFloatingPointType)*num_of_values); rgba+=3; for(i=0;iBuildFunctionFromTable(m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values-1, alphasHead); free(alphasHead); } + +void mitk::LookupTable::PrintSelf(std::ostream &os, itk::Indent indent) const +{ + os << indent; + m_LookupTable->PrintHeader(os, vtkIndent()); +} diff --git a/Core/Code/DataManagement/mitkLookupTable.h b/Core/Code/DataManagement/mitkLookupTable.h index a39a35583a..d3be30a1b8 100644 --- a/Core/Code/DataManagement/mitkLookupTable.h +++ b/Core/Code/DataManagement/mitkLookupTable.h @@ -1,133 +1,135 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKLookupTable_H_HEADER_INCLUDED_C1EBD53D #define MITKLookupTable_H_HEADER_INCLUDED_C1EBD53D #include #include #include "vtkLookupTable.h" #include #include class vtkColorTransferFunction; class vtkPiecewiseFunction; namespace mitk { //## //##Documentation //## @brief LookupTable containing a vtkLookupTable //## @ingroup Data //## class MITK_CORE_EXPORT LookupTable : public itk::DataObject { public: /** *@brief Some convenient typedefs. */ typedef unsigned char RawLookupTableType; mitkClassMacro( LookupTable, itk::DataObject ); itkNewMacro( Self ); /** * @returns the associated vtkLookupTable */ virtual vtkLookupTable* GetVtkLookupTable() const; virtual RawLookupTableType * GetRawLookupTable() const; virtual void SetVtkLookupTable( vtkLookupTable* lut ); virtual void ChangeOpacityForAll( float opacity ); virtual void ChangeOpacity(int index, float opacity ); /*! * \brief equality operator implementation */ virtual bool operator==( const mitk::LookupTable& LookupTable ) const; /*! * \brief non equality operator implementation */ virtual bool operator!=( const LookupTable& LookupTable ) const; /*! * \brief implementation necessary because operator made * private in itk::Object */ virtual LookupTable& operator=( const LookupTable& LookupTable ); /** * Updates the output information of the current object by calling * updateOutputInformation of the data objects source object. */ virtual void UpdateOutputInformation( ); /** * Sets the requested Region to the largest possible region. * This method is not implemented, since this is the default * behaviour of the itk pipeline and we do not support the * requested-region mechanism for lookup-tables */ virtual void SetRequestedRegionToLargestPossibleRegion( ); /** * Checks, if the requested region lies outside of the buffered region by * calling verifyRequestedRegion(). */ virtual bool RequestedRegionIsOutsideOfTheBufferedRegion( ); /** * Checks if the requested region is completely contained in * the buffered region. Since we always want to process the lookup * table as a whole, this method always returns true */ virtual bool VerifyRequestedRegion( ); /** * This method has no effect for lookup tables, since we do * not support the region-mechanism */ virtual void SetRequestedRegion( itk::DataObject *data ); LookupTable(); virtual ~LookupTable(); void CreateColorTransferFunction(vtkColorTransferFunction*& colorFunction); void CreateOpacityTransferFunction(vtkPiecewiseFunction*& opacityFunction); void CreateGradientTransferFunction(vtkPiecewiseFunction*& gradientFunction); protected: + void PrintSelf(std::ostream &os, itk::Indent indent) const; + vtkLookupTable* m_LookupTable; private: }; } // namespace mitk #endif /* LookupTable_H_HEADER_INCLUDED_C1EBD53D */ diff --git a/Core/Code/DataManagement/mitkModalityProperty.h b/Core/Code/DataManagement/mitkModalityProperty.h index 650027473c..8d1d358275 100644 --- a/Core/Code/DataManagement/mitkModalityProperty.h +++ b/Core/Code/DataManagement/mitkModalityProperty.h @@ -1,57 +1,63 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-15 10:46:54 +0200 (Fr, 15 Mai 2009) $ Version: $Revision: 17272 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef mitkModalityProperty_h_Included #define mitkModalityProperty_h_Included #include #include "mitkEnumerationProperty.h" #include namespace mitk { /** \brief Enumerates all known modalities \ingroup DataManagement */ class MITK_CORE_EXPORT ModalityProperty : public EnumerationProperty { public: mitkClassMacro(ModalityProperty, EnumerationProperty); itkNewMacro(ModalityProperty); mitkNewMacro1Param(ModalityProperty, const IdType&); mitkNewMacro1Param(ModalityProperty, const std::string&); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } + using BaseProperty::operator=; protected: ModalityProperty(); ModalityProperty( const IdType& value ); ModalityProperty( const std::string& value ); virtual ~ModalityProperty(); virtual void AddEnumerationTypes(); + + private: + + // purposely not implemented + ModalityProperty(const ModalityProperty&); + const ModalityProperty& operator=(const ModalityProperty&); }; } // namespace #endif diff --git a/Core/Code/DataManagement/mitkPlaneOrientationProperty.h b/Core/Code/DataManagement/mitkPlaneOrientationProperty.h index b8d88db95c..f0a048ca86 100644 --- a/Core/Code/DataManagement/mitkPlaneOrientationProperty.h +++ b/Core/Code/DataManagement/mitkPlaneOrientationProperty.h @@ -1,115 +1,121 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-04-14 19:45:53 +0200 (Mo, 14 Apr 2008) $ Version: $Revision: 14081 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITK_PLANE_DECORATION_PROPERTY__H #define MITK_PLANE_DECORATION_PROPERTY__H #include "mitkEnumerationProperty.h" namespace mitk { /** * Property which controls whether 2D line representation of a PlaneGeometry * should have small arrows at both ends to indicate the orientation of * the plane, and whether the arrows should be oriented in the direction of * the plane's normal or against it. * * Valid values of the enumeration property are * - PLANE_DECORATION_NONE (no arrows) * - PLANE_DECORATION_POSITIVE_ORIENTATION (arrows pointing upwards) * - PLANE_DECORATION_NEGATIVE_ORIENTATION (arrows pointing downwards) * * See also mitk::Geometry2DDataMapper2D::DrawOrientationArrow() */ class MITK_CORE_EXPORT PlaneOrientationProperty : public EnumerationProperty { public: mitkClassMacro( PlaneOrientationProperty, EnumerationProperty ); itkNewMacro(PlaneOrientationProperty); mitkNewMacro1Param(PlaneOrientationProperty, const IdType&); mitkNewMacro1Param(PlaneOrientationProperty, const std::string&); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - enum { PLANE_DECORATION_NONE, PLANE_DECORATION_POSITIVE_ORIENTATION, PLANE_DECORATION_NEGATIVE_ORIENTATION }; /** * Returns the state of plane decoration. */ virtual int GetPlaneDecoration(); /** * Sets the decoration type to no decoration. */ virtual void SetPlaneDecorationToNone(); /** * Sets the decoration type to arrows in positive plane direction. */ virtual void SetPlaneDecorationToPositiveOrientation(); /** * Sets the decoration type to arrows in negative plane direction. */ virtual void SetPlaneDecorationToNegativeOrientation(); + + using BaseProperty::operator=; protected: /** * Constructor. Sets the decoration type to none. */ PlaneOrientationProperty( ); /** * Constructor. Sets the decoration type to the given value. If it is not * valid, the interpolation is set to none */ PlaneOrientationProperty( const IdType &value ); /** * Constructor. Sets the decoration type to the given value. If it is not * valid, the representation is set to none */ PlaneOrientationProperty( const std::string &value ); /** * this function is overridden as protected, so that the user may not add * additional invalid types. */ virtual bool AddEnum( const std::string &name, const IdType &id ); /** * Adds the standard enumeration types with corresponding strings. */ virtual void AddDecorationTypes(); + +private: + + // purposely not implemented + PlaneOrientationProperty(const PlaneOrientationProperty&); + PlaneOrientationProperty& operator=(const PlaneOrientationProperty&); }; } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkProperties.cpp b/Core/Code/DataManagement/mitkProperties.cpp index 48915d79d5..11577cb3a3 100644 --- a/Core/Code/DataManagement/mitkProperties.cpp +++ b/Core/Code/DataManagement/mitkProperties.cpp @@ -1,32 +1,40 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkProperties.h" -template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty >; -template class mitk::GenericProperty; - -template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty; +mitkDefineGenericProperty(BoolProperty,bool,false); + +mitkDefineGenericProperty(IntProperty,int,0); + +mitkDefineGenericProperty(FloatProperty,float,0.0f); + +mitkDefineGenericProperty(DoubleProperty,double,0.0); + +mitkDefineGenericProperty(Vector3DProperty,Vector3D,Vector3D(0.0f)); + +mitkDefineGenericProperty(Point3dProperty,Point3D,Point3D::BaseArray::Filled(0.0f).GetDataPointer() ); + +mitkDefineGenericProperty(Point4dProperty,Point4D,Point4D::BaseArray::Filled(0.0f).GetDataPointer() ); + +mitkDefineGenericProperty(Point3iProperty,Point3I,Point3I::BaseArray::Filled(0).GetDataPointer() ); + +mitkDefineGenericProperty(FloatLookupTableProperty, FloatLookupTable, FloatLookupTable()); +mitkDefineGenericProperty(BoolLookupTableProperty, BoolLookupTable, BoolLookupTable()); +mitkDefineGenericProperty(IntLookupTableProperty, IntLookupTable, IntLookupTable()); +mitkDefineGenericProperty(StringLookupTableProperty, StringLookupTable, StringLookupTable()); diff --git a/Core/Code/DataManagement/mitkProperties.h b/Core/Code/DataManagement/mitkProperties.h index f2d1cb62a3..2c66d595f8 100644 --- a/Core/Code/DataManagement/mitkProperties.h +++ b/Core/Code/DataManagement/mitkProperties.h @@ -1,53 +1,53 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKPROPERTIES_H_HEADER_INCLUDED #define MITKPROPERTIES_H_HEADER_INCLUDED #include "mitkGenericProperty.h" #include "mitkVector.h" #include "mitkLookupTables.h" namespace mitk { - mitkSpecializeGenericProperty(BoolProperty,bool,false); + mitkDeclareGenericProperty(BoolProperty,bool,MITK_CORE_EXPORT); - mitkSpecializeGenericProperty(IntProperty,int,0); + mitkDeclareGenericProperty(IntProperty,int,MITK_CORE_EXPORT); - mitkSpecializeGenericProperty(FloatProperty,float,0.0f); + mitkDeclareGenericProperty(FloatProperty,float,MITK_CORE_EXPORT); - mitkSpecializeGenericProperty(DoubleProperty,double,0.0); + mitkDeclareGenericProperty(DoubleProperty,double,MITK_CORE_EXPORT); - mitkSpecializeGenericProperty(Vector3DProperty,Vector3D,Vector3D(0.0f)); + mitkDeclareGenericProperty(Vector3DProperty,Vector3D,MITK_CORE_EXPORT); - mitkSpecializeGenericProperty(Point3dProperty,Point3D,Point3D::BaseArray::Filled(0.0f).GetDataPointer() ); + mitkDeclareGenericProperty(Point3dProperty,Point3D,MITK_CORE_EXPORT); - mitkSpecializeGenericProperty(Point4dProperty,Point4D,Point4D::BaseArray::Filled(0.0f).GetDataPointer() ); + mitkDeclareGenericProperty(Point4dProperty,Point4D,MITK_CORE_EXPORT); - mitkSpecializeGenericProperty(Point3iProperty,Point3I,Point3I::BaseArray::Filled(0).GetDataPointer() ); + mitkDeclareGenericProperty(Point3iProperty,Point3I,MITK_CORE_EXPORT); - mitkSpecializeGenericProperty(FloatLookupTableProperty, FloatLookupTable, FloatLookupTable()); - mitkSpecializeGenericProperty(BoolLookupTableProperty, BoolLookupTable, BoolLookupTable()); - mitkSpecializeGenericProperty(IntLookupTableProperty, IntLookupTable, IntLookupTable()); - mitkSpecializeGenericProperty(StringLookupTableProperty, StringLookupTable, StringLookupTable()); + mitkDeclareGenericProperty(FloatLookupTableProperty, FloatLookupTable,MITK_CORE_EXPORT); + mitkDeclareGenericProperty(BoolLookupTableProperty, BoolLookupTable,MITK_CORE_EXPORT); + mitkDeclareGenericProperty(IntLookupTableProperty, IntLookupTable,MITK_CORE_EXPORT); + mitkDeclareGenericProperty(StringLookupTableProperty, StringLookupTable,MITK_CORE_EXPORT); /** * \warning If you add more specialization of GenericProperty, you must also add these to the * templated GetPropertyValue() method in mitkPropertyList.cpp! */ } // namespace mitk #endif /* MITKPROPERTIES_H_HEADER_INCLUDED */ diff --git a/Core/Code/DataManagement/mitkPropertyList.cpp b/Core/Code/DataManagement/mitkPropertyList.cpp index eb2dd84d4d..5ccbcb0e5b 100644 --- a/Core/Code/DataManagement/mitkPropertyList.cpp +++ b/Core/Code/DataManagement/mitkPropertyList.cpp @@ -1,293 +1,281 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkPropertyList.h" #include "mitkProperties.h" #include "mitkStringProperty.h" #include "mitkVector.h" mitk::BaseProperty* mitk::PropertyList::GetProperty(const std::string& propertyKey) const { PropertyMap::const_iterator it; it=m_Properties.find( propertyKey ); if(it!=m_Properties.end()) return it->second; else return NULL; } void mitk::PropertyList::SetProperty(const std::string& propertyKey, BaseProperty* property) { if (!property) return; //make sure that BaseProperty*, which may have just been created and never been //assigned to a SmartPointer, is registered/unregistered properly. If we do not //do that, it will a) not deleted in case it is identical to the old one or //b) possibly deleted when temporarily added to a smartpointer somewhere below. BaseProperty::Pointer tmpSmartPointerToProperty = property; PropertyMap::iterator it( m_Properties.find( propertyKey ) ); // Is a property with key @a propertyKey contained in the list? if( it != m_Properties.end() ) { // yes //is the property contained in the list identical to the new one? if( it->second->operator==(*property) ) { // yes? do nothing and return. return; } - // compatible? then use operator= to assign value - if (it->second->Assignable( *property )) + if (it->second->AssignProperty(*property)) { - bool changed = (it->second->GetValueAsString() != property->GetValueAsString()); - *(static_cast(it->second.GetPointer())) = *property; - // muellerm,20.10: added modified event - if(changed) - this->Modified(); - return; + // The assignment was successfull + this->Modified(); } - - if ( typeid( *(it->second.GetPointer()) ) != typeid( *property ) ) + else { - // Accept only if the two types are matching. For replacing, use - // ReplaceProperty. - MITK_ERROR << "In " __FILE__ ", l." << __LINE__ - << ": Trying to set existing property to a property with different type." - << " Use ReplaceProperty() instead." - << std::endl; - return; + MITK_ERROR << "In " __FILE__ ", l." << __LINE__ + << ": Trying to set existing property " << it->first << " of type " << it->second->GetNameOfClass() + << " to a property with different type " << property->GetNameOfClass() << "." + << " Use ReplaceProperty() instead." + << std::endl; } - - // If types are identical, but the property has no operator= (s.a.), - // overwrite the pointer. - it->second = property; return; } - //no? add/replace it. + //no? add it. PropertyMapElementType newProp; newProp.first = propertyKey; newProp.second = property; m_Properties.insert ( newProp ); this->Modified(); } void mitk::PropertyList::ReplaceProperty(const std::string& propertyKey, BaseProperty* property) { if (!property) return; PropertyMap::iterator it( m_Properties.find( propertyKey ) ); // Is a property with key @a propertyKey contained in the list? if( it != m_Properties.end() ) { it->second=NULL; m_Properties.erase(it); } //no? add/replace it. PropertyMapElementType newProp; newProp.first = propertyKey; newProp.second = property; m_Properties.insert ( newProp ); Modified(); } mitk::PropertyList::PropertyList() { } mitk::PropertyList::~PropertyList() { Clear(); } /** * Consider the list as changed when any of the properties has changed recently. */ unsigned long mitk::PropertyList::GetMTime() const { for ( PropertyMap::const_iterator it = m_Properties.begin() ; it != m_Properties.end(); ++it ) { if( it->second.IsNull() ) { itkWarningMacro(<< "Property '" << it->first <<"' contains nothing (NULL)."); continue; } if( Superclass::GetMTime() < it->second->GetMTime() ) { Modified(); break; } } return Superclass::GetMTime(); } bool mitk::PropertyList::DeleteProperty(const std::string& propertyKey) { PropertyMap::iterator it; it=m_Properties.find( propertyKey ); if(it!=m_Properties.end()) { it->second=NULL; m_Properties.erase(it); Modified(); return true; } return false; } mitk::PropertyList::Pointer mitk::PropertyList::Clone() { mitk::PropertyList::Pointer newPropertyList = PropertyList::New(); // copy the map newPropertyList->m_Properties = m_Properties; return newPropertyList.GetPointer(); } void mitk::PropertyList::Clear() { PropertyMap::iterator it = m_Properties.begin(), end = m_Properties.end(); while(it!=end) { it->second = NULL; ++it; } m_Properties.clear(); } void mitk::PropertyList::ConcatenatePropertyList(PropertyList *pList, bool replace) { if (pList) { const PropertyMap* propertyMap = pList->GetMap(); for ( PropertyMap::const_iterator iter = propertyMap->begin(); // m_PropertyList is created in the constructor, so we don't check it here iter != propertyMap->end(); ++iter ) { const std::string key = iter->first; BaseProperty* value = iter->second; if (replace) { ReplaceProperty( key.c_str(), value ); } else { SetProperty( key.c_str(), value ); } } } } bool mitk::PropertyList::GetBoolProperty(const char* propertyKey, bool& boolValue) const { BoolProperty *gp = dynamic_cast( GetProperty(propertyKey) ); if ( gp != NULL ) { boolValue = gp->GetValue(); return true; } return false; // Templated Method does not work on Macs //return GetPropertyValue(propertyKey, boolValue); } bool mitk::PropertyList::GetIntProperty(const char* propertyKey, int &intValue) const { IntProperty *gp = dynamic_cast( GetProperty(propertyKey) ); if ( gp != NULL ) { intValue = gp->GetValue(); return true; } return false; // Templated Method does not work on Macs //return GetPropertyValue(propertyKey, intValue); } bool mitk::PropertyList::GetFloatProperty(const char* propertyKey, float &floatValue) const { FloatProperty *gp = dynamic_cast( GetProperty(propertyKey) ); if ( gp != NULL ) { floatValue = gp->GetValue(); return true; } return false; // Templated Method does not work on Macs //return GetPropertyValue(propertyKey, floatValue); } bool mitk::PropertyList::GetStringProperty(const char* propertyKey, std::string& stringValue) const { StringProperty* sp= dynamic_cast(GetProperty(propertyKey)); if ( sp != NULL ) { stringValue = sp->GetValue(); return true; } return false; } void mitk::PropertyList::SetIntProperty(const char* propertyKey, int intValue) { SetProperty(propertyKey, mitk::IntProperty::New(intValue)); } void mitk::PropertyList::SetBoolProperty( const char* propertyKey, bool boolValue) { SetProperty(propertyKey, mitk::BoolProperty::New(boolValue)); } void mitk::PropertyList::SetFloatProperty( const char* propertyKey, float floatValue) { SetProperty(propertyKey, mitk::FloatProperty::New(floatValue)); } void mitk::PropertyList::SetStringProperty( const char* propertyKey, const char* stringValue) { SetProperty(propertyKey, mitk::StringProperty::New(stringValue)); } diff --git a/Core/Code/DataManagement/mitkResliceMethodProperty.h b/Core/Code/DataManagement/mitkResliceMethodProperty.h index e858ec8b22..dff56b7d65 100644 --- a/Core/Code/DataManagement/mitkResliceMethodProperty.h +++ b/Core/Code/DataManagement/mitkResliceMethodProperty.h @@ -1,53 +1,59 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-04-14 19:45:53 +0200 (Mo, 14 Apr 2008) $ Version: $Revision: 14081 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __MITKRESLICEMETHODENUMPROPERTY_H #define __MITKRESLICEMETHODENUMPROPERTY_H #include "mitkEnumerationProperty.h" namespace mitk { /** * Encapsulates the thick slices method enumeration */ class MITK_CORE_EXPORT ResliceMethodProperty : public EnumerationProperty { public: mitkClassMacro( ResliceMethodProperty, EnumerationProperty ); itkNewMacro(ResliceMethodProperty); mitkNewMacro1Param(ResliceMethodProperty, const IdType&); - mitkNewMacro1Param(ResliceMethodProperty, const std::string&); + mitkNewMacro1Param(ResliceMethodProperty, const std::string&); + + using BaseProperty::operator=; - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - protected: ResliceMethodProperty( ); ResliceMethodProperty( const IdType& value ); ResliceMethodProperty( const std::string& value ); void AddThickSlicesTypes(); + +private: + + // purposely not implemented + ResliceMethodProperty(const ResliceMethodProperty&); + ResliceMethodProperty& operator=(const ResliceMethodProperty&); }; } // end of namespace mitk #endif //_MITK_VTK_SCALARMODE_PROPERTY__H_ diff --git a/Core/Code/DataManagement/mitkShaderProperty.cpp b/Core/Code/DataManagement/mitkShaderProperty.cpp index 884d9ac92f..45585c30af 100644 --- a/Core/Code/DataManagement/mitkShaderProperty.cpp +++ b/Core/Code/DataManagement/mitkShaderProperty.cpp @@ -1,100 +1,107 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2007-12-11 14:46:19 +0100 (Di, 11 Dez 2007) $ Version: $Revision: 13129 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include "mitkShaderProperty.h" #include "mitkShaderRepository.h" #include #include mitk::ShaderProperty::ShaderProperty( ) { AddShaderTypes(); SetShader( (IdType)0 ); } mitk::ShaderProperty::ShaderProperty( const IdType& value ) { AddShaderTypes(); SetShader(value); } mitk::ShaderProperty::ShaderProperty( const std::string& value ) { AddShaderTypes(); SetShader(value); } void mitk::ShaderProperty::SetShader( const IdType& value ) { if ( IsValidEnumerationValue( value ) ) SetValue( value ); else SetValue( (IdType)0 ); } void mitk::ShaderProperty::SetShader( const std::string& value ) { if ( IsValidEnumerationValue( value ) ) SetValue( value ); else SetValue( (IdType)0 ); } mitk::EnumerationProperty::IdType mitk::ShaderProperty::GetShaderId() { return GetValueAsId(); } std::string mitk::ShaderProperty::GetShaderName() { return GetValueAsString(); } void mitk::ShaderProperty::AddShaderTypes() { AddEnum( "fixed" ); std::list *l = mitk::ShaderRepository::GetGlobalShaderRepository()->GetShaders(); std::list::const_iterator i = l->begin(); while( i != l->end() ) { AddEnum( (*i)->name ); i++; } } bool mitk::ShaderProperty::AddEnum( const std::string& name ,const IdType& /*id*/) { Element e; e.name=name; bool success=Superclass::AddEnum( e.name, (IdType)shaderList.size() ); shaderList.push_back(e); return success; } +bool mitk::ShaderProperty::Assign(const BaseProperty &property) +{ + Superclass::Assign(property); + this->shaderList = static_cast(property).shaderList; + return true; +} + diff --git a/Core/Code/DataManagement/mitkShaderProperty.h b/Core/Code/DataManagement/mitkShaderProperty.h index 5438935d66..a62695895d 100644 --- a/Core/Code/DataManagement/mitkShaderProperty.h +++ b/Core/Code/DataManagement/mitkShaderProperty.h @@ -1,103 +1,107 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-04-14 19:45:53 +0200 (Mo, 14 Apr 2008) $ Version: $Revision: 14081 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __MITKSHADERENUMPROPERTY_H #define __MITKSHADERENUMPROPERTY_H #include "mitkEnumerationProperty.h" namespace mitk { /** * Encapsulates the shader enumeration */ class MITK_CORE_EXPORT ShaderProperty : public EnumerationProperty { public: class Element { public: std::string name; }; mitkClassMacro( ShaderProperty, EnumerationProperty ); itkNewMacro(ShaderProperty); mitkNewMacro1Param(ShaderProperty, const IdType&); mitkNewMacro1Param(ShaderProperty, const std::string&); /** * Returns the current scalar mode value as defined by VTK constants. * @returns the current scalar mode as VTK constant. */ IdType GetShaderId(); std::string GetShaderName(); void SetShader(const IdType& i); void SetShader(const std::string& i); - - virtual BaseProperty& operator=(const BaseProperty& other) - { - shaderList = dynamic_cast(other).shaderList; - return Superclass::operator=(other); - } + + using BaseProperty::operator=; protected: std::list shaderList; /** * Constructor. Sets the representation to a default value of surface(2) */ ShaderProperty( ); /** * \brief Sets the scalar mode to the given value. If it is not * valid, the scalar mode is set to default (0). * @param value the integer representation of the scalar mode */ ShaderProperty( const IdType& value ); /** * \brief Sets the scalar mode to the given value. If it is not * valid, the representation is set to default (0). * @param value the string representation of the scalar mode */ ShaderProperty( const std::string& value ); /** * this function is overridden as protected, so that the user may not add * additional invalid scalar mode types. */ bool AddEnum( const std::string& name, const IdType& id = 0); /** * Adds the enumeration types as defined by vtk to the list of known * enumeration values. */ void AddShaderTypes(); + +private: + + // purposely not implemented + ShaderProperty(const ShaderProperty&); + ShaderProperty& operator=(const ShaderProperty&); + + virtual bool Assign(const BaseProperty &property); }; } // end of namespace mitk #endif //_MITK_VTK_SCALARMODE_PROPERTY__H_ diff --git a/Core/Code/DataManagement/mitkSmartPointerProperty.cpp b/Core/Code/DataManagement/mitkSmartPointerProperty.cpp index 90a8ebfefa..637623ce60 100644 --- a/Core/Code/DataManagement/mitkSmartPointerProperty.cpp +++ b/Core/Code/DataManagement/mitkSmartPointerProperty.cpp @@ -1,149 +1,131 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkSmartPointerProperty.h" mitk::SmartPointerProperty::ReferenceCountMapType mitk::SmartPointerProperty::m_ReferenceCount; mitk::SmartPointerProperty::ReferencesUIDMapType mitk::SmartPointerProperty::m_ReferencesUID; mitk::SmartPointerProperty::ReadInSmartPointersMapType mitk::SmartPointerProperty::m_ReadInInstances; mitk::SmartPointerProperty::ReadInTargetsMapType mitk::SmartPointerProperty::m_ReadInTargets; mitk::UIDGenerator mitk::SmartPointerProperty::m_UIDGenerator("POINTER_"); void mitk::SmartPointerProperty::PostProcessXMLReading() { for (ReadInSmartPointersMapType::iterator iter = m_ReadInInstances.begin(); iter != m_ReadInInstances.end(); ++iter) { if ( m_ReadInTargets.find(iter->second) != m_ReadInTargets.end() ) { iter->first->SetSmartPointer( m_ReadInTargets[ iter->second ] ); } } m_ReadInInstances.clear(); } /// \return The number of SmartPointerProperties that point to @param object unsigned int mitk::SmartPointerProperty::GetReferenceCountFor(itk::Object* object) { if ( m_ReferenceCount.find(object) != m_ReferenceCount.end() ) { return m_ReferenceCount[object]; } else { return 0; } } void mitk::SmartPointerProperty::RegisterPointerTarget(itk::Object* object, const std::string uid) { m_ReadInTargets[uid] = object; } std::string mitk::SmartPointerProperty::GetReferenceUIDFor(itk::Object* object) { if ( m_ReferencesUID.find(object) != m_ReferencesUID.end() ) { return m_ReferencesUID[object]; } else { return std::string("invalid"); } } bool mitk::SmartPointerProperty::IsEqual(const BaseProperty& property) const { return this->m_SmartPointer == static_cast(property).m_SmartPointer; } +bool mitk::SmartPointerProperty::Assign(const BaseProperty& property) +{ + this->m_SmartPointer = static_cast(property).m_SmartPointer; + return true; +} + mitk::SmartPointerProperty::SmartPointerProperty(itk::Object* pointer) { SetSmartPointer( pointer ); } itk::Object::Pointer mitk::SmartPointerProperty::GetSmartPointer() const { return m_SmartPointer; } +itk::Object::Pointer mitk::SmartPointerProperty::GetValue() const +{ + return this->GetSmartPointer(); +} + void mitk::SmartPointerProperty::SetSmartPointer(itk::Object* pointer) { if(m_SmartPointer.GetPointer() != pointer) { // keep track of referenced objects if ( m_SmartPointer.GetPointer() && --m_ReferenceCount[m_SmartPointer.GetPointer()] == 0 ) // if there is no reference left, delete entry { m_ReferenceCount.erase( m_SmartPointer.GetPointer() ); m_ReferencesUID.erase( m_SmartPointer.GetPointer() ); } if ( pointer && ++m_ReferenceCount[pointer] == 1 ) // first reference --> generate UID { m_ReferencesUID[pointer] = m_UIDGenerator.GetUID(); } // change pointer m_SmartPointer = pointer; Modified(); } } +void mitk::SmartPointerProperty::SetValue(const ValueType & value) +{ + this->SetSmartPointer(value.GetPointer()); +} + std::string mitk::SmartPointerProperty::GetValueAsString() const { if ( m_SmartPointer.IsNotNull() ) return m_ReferencesUID[ m_SmartPointer.GetPointer() ]; else return std::string("NULL"); } - -bool mitk::SmartPointerProperty::Assignable(const BaseProperty& other) const -{ - try - { - dynamic_cast(other); // dear compiler, please don't optimize this away! - return true; - } - catch (std::bad_cast) - { - } - return false; -} - -mitk::BaseProperty& mitk::SmartPointerProperty::operator=(const BaseProperty& other) -{ - try - { - const Self& otherProp( dynamic_cast(other) ); - - if (this->m_SmartPointer != otherProp.m_SmartPointer) - { - this->m_SmartPointer = otherProp.m_SmartPointer; - this->Modified(); - } - } - catch (std::bad_cast) - { - // nothing to do then - } - - return *this; -} - diff --git a/Core/Code/DataManagement/mitkSmartPointerProperty.h b/Core/Code/DataManagement/mitkSmartPointerProperty.h index 58a1b0142e..900af29de5 100644 --- a/Core/Code/DataManagement/mitkSmartPointerProperty.h +++ b/Core/Code/DataManagement/mitkSmartPointerProperty.h @@ -1,91 +1,97 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKSMARTPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 #define MITKSMARTPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 #include #include "mitkBaseProperty.h" #include "mitkUIDGenerator.h" #include #include #include namespace mitk { //##Documentation //## @brief Property containing a smart-pointer //## @ingroup DataManagement class MITK_CORE_EXPORT SmartPointerProperty : public BaseProperty { public: mitkClassMacro(SmartPointerProperty, BaseProperty); itkNewMacro(SmartPointerProperty); mitkNewMacro1Param(SmartPointerProperty, itk::Object*); + typedef itk::Object::Pointer ValueType; + itk::Object::Pointer GetSmartPointer() const; + ValueType GetValue() const; void SetSmartPointer(itk::Object*); + void SetValue(const ValueType&); /// mainly for XML output virtual std::string GetValueAsString() const; - virtual bool Assignable(const BaseProperty&) const; - - virtual BaseProperty& operator=(const BaseProperty& property); - static void PostProcessXMLReading(); /// Return the number of SmartPointerProperties that reference the object given as parameter static unsigned int GetReferenceCountFor(itk::Object*); static std::string GetReferenceUIDFor(itk::Object*); static void RegisterPointerTarget(itk::Object*, const std::string uid); + using BaseProperty::operator=; protected: SmartPointerProperty(itk::Object* = NULL); itk::Object::Pointer m_SmartPointer; private: + // purposely not implemented + SmartPointerProperty(const SmartPointerProperty&); + SmartPointerProperty& operator=(const SmartPointerProperty&); + virtual bool IsEqual(const BaseProperty&) const; + virtual bool Assign(const BaseProperty&); typedef std::map ReferenceCountMapType; typedef std::map ReferencesUIDMapType; typedef std::map ReadInSmartPointersMapType; typedef std::map ReadInTargetsMapType; /// for each itk::Object* count how many SmartPointerProperties point to it static ReferenceCountMapType m_ReferenceCount; static ReferencesUIDMapType m_ReferencesUID; static ReadInSmartPointersMapType m_ReadInInstances; static ReadInTargetsMapType m_ReadInTargets; /// to generate unique IDs for the objects pointed at (during XML writing) static UIDGenerator m_UIDGenerator; }; } // namespace mitk #endif /* MITKSMARTPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 */ diff --git a/Core/Code/DataManagement/mitkStringProperty.cpp b/Core/Code/DataManagement/mitkStringProperty.cpp index d47f00bdbc..a86f8035f2 100644 --- a/Core/Code/DataManagement/mitkStringProperty.cpp +++ b/Core/Code/DataManagement/mitkStringProperty.cpp @@ -1,78 +1,49 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkStringProperty.h" const char* mitk::StringProperty::PATH = "path"; mitk::StringProperty::StringProperty( const char* string ) : m_Value() { if ( string ) m_Value = string; } mitk::StringProperty::StringProperty( const std::string& s ) : m_Value( s ) { } bool mitk::StringProperty::IsEqual(const BaseProperty& property ) const { return this->m_Value == static_cast(property).m_Value; } -std::string mitk::StringProperty::GetValueAsString() const -{ - return m_Value; -} - -bool mitk::StringProperty::Assignable(const BaseProperty& other) const +bool mitk::StringProperty::Assign(const BaseProperty& property ) { - try - { - dynamic_cast(other); // dear compiler, please don't optimize this away! - return true; - } - catch (std::bad_cast) - { - } - return false; + this->m_Value = static_cast(property).m_Value; + return true; } -mitk::BaseProperty& mitk::StringProperty::operator=(const BaseProperty& other) +std::string mitk::StringProperty::GetValueAsString() const { - try - { - const Self& otherProp( dynamic_cast(other) ); - - if (this->m_Value != otherProp.m_Value) - { - this->m_Value = otherProp.m_Value; - this->Modified(); - } - } - catch (std::bad_cast) - { - // nothing to do then - } - - return *this; + return m_Value; } - - diff --git a/Core/Code/DataManagement/mitkStringProperty.h b/Core/Code/DataManagement/mitkStringProperty.h index 69fc3d21e7..5be7d3cc7a 100644 --- a/Core/Code/DataManagement/mitkStringProperty.h +++ b/Core/Code/DataManagement/mitkStringProperty.h @@ -1,69 +1,72 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKSTRINGPROPERTY_H_HEADER_INCLUDED_C1C02491 #define MITKSTRINGPROPERTY_H_HEADER_INCLUDED_C1C02491 #include #include #include "mitkBaseProperty.h" #include namespace mitk { /** * @brief Property for strings * @ingroup DataManagement */ class MITK_CORE_EXPORT StringProperty : public BaseProperty { protected: std::string m_Value; StringProperty( const char* string = 0 ); StringProperty( const std::string& s ); public: mitkClassMacro(StringProperty, BaseProperty); typedef std::string ValueType; itkNewMacro(StringProperty); mitkNewMacro1Param(StringProperty, const char*); mitkNewMacro1Param(StringProperty, const std::string&) itkGetStringMacro(Value); itkSetStringMacro(Value); virtual std::string GetValueAsString() const; - - bool Assignable(const BaseProperty& other) const; - virtual BaseProperty& operator=(const BaseProperty& other); static const char* PATH; + using BaseProperty::operator=; + private: + // purposely not implemented + StringProperty(const StringProperty&); + StringProperty& operator=(const StringProperty&); virtual bool IsEqual(const BaseProperty& property ) const; + virtual bool Assign(const BaseProperty& property ); }; } // namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkTransferFunction.cpp b/Core/Code/DataManagement/mitkTransferFunction.cpp index 90f0dc1def..0f46aec249 100644 --- a/Core/Code/DataManagement/mitkTransferFunction.cpp +++ b/Core/Code/DataManagement/mitkTransferFunction.cpp @@ -1,298 +1,310 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkTransferFunction.h" #include "mitkImageToItk.h" #include "mitkHistogramGenerator.h" #include #include namespace mitk { TransferFunction::TransferFunction() { m_ScalarOpacityFunction = vtkSmartPointer::New(); m_ColorTransferFunction = vtkSmartPointer::New(); m_GradientOpacityFunction = vtkSmartPointer::New(); m_ScalarOpacityFunction->Initialize(); m_ScalarOpacityFunction->AddPoint(0,1); m_GradientOpacityFunction->Initialize(); m_GradientOpacityFunction->AddPoint(0,1); m_ColorTransferFunction->RemoveAllPoints(); m_ColorTransferFunction->SetColorSpaceToHSV(); m_ColorTransferFunction->AddRGBPoint(0,1,1,1); } TransferFunction::~TransferFunction() { } bool TransferFunction::operator==(Self& other) { if ((m_Min != other.m_Min) || (m_Max != other.m_Max)) return false; bool sizes = (m_ScalarOpacityFunction->GetSize() == other.m_ScalarOpacityFunction->GetSize()) && (m_GradientOpacityFunction->GetSize() == other.m_GradientOpacityFunction->GetSize()) && (m_ColorTransferFunction->GetSize() == other.m_ColorTransferFunction->GetSize()); if (sizes == false) return false; for (int i = 0; i < m_ScalarOpacityFunction->GetSize(); i++ ) { double myVal[4]; double otherVal[4]; m_ScalarOpacityFunction->GetNodeValue(i, myVal); other.m_ScalarOpacityFunction->GetNodeValue(i, otherVal); bool equal = (myVal[0] == otherVal[0]) && (myVal[1] == otherVal[1]) && (myVal[2] == otherVal[2]) && (myVal[3] == otherVal[3]); if (equal == false) return false; } for (int i = 0; i < m_GradientOpacityFunction->GetSize(); i++ ) { double myVal[4]; double otherVal[4]; m_GradientOpacityFunction->GetNodeValue(i, myVal); other.m_GradientOpacityFunction->GetNodeValue(i, otherVal); bool equal = (myVal[0] == otherVal[0]) && (myVal[1] == otherVal[1]) && (myVal[2] == otherVal[2]) && (myVal[3] == otherVal[3]); if (equal == false) return false; } for (int i = 0; i < m_ColorTransferFunction->GetSize(); i++ ) { double myVal[6]; double otherVal[6]; m_ColorTransferFunction->GetNodeValue(i, myVal); other.m_ColorTransferFunction->GetNodeValue(i, otherVal); bool equal = (myVal[0] == otherVal[0]) // X && (myVal[1] == otherVal[1]) // R && (myVal[2] == otherVal[2]) // G && (myVal[3] == otherVal[3]) // B && (myVal[4] == otherVal[4]) // midpoint && (myVal[5] == otherVal[5]); // sharpness if (equal == false) return false; } return true; } void TransferFunction::SetScalarOpacityPoints(TransferFunction::ControlPoints points) { m_ScalarOpacityFunction->RemoveAllPoints(); for(unsigned int i=0; i<=points.size()-1;i++) { this->AddScalarOpacityPoint(points[i].first, points[i].second); } } void TransferFunction::SetGradientOpacityPoints(TransferFunction::ControlPoints points) { m_GradientOpacityFunction->RemoveAllPoints(); for(unsigned int i=0; i<=points.size()-1;i++) { this->AddGradientOpacityPoint(points[i].first, points[i].second); } } void TransferFunction::SetRGBPoints(TransferFunction::RGBControlPoints rgbpoints) { m_ColorTransferFunction->RemoveAllPoints(); for(unsigned int i=0; i<=rgbpoints.size()-1;i++) { this->AddRGBPoint(rgbpoints[i].first, rgbpoints[i].second[0], rgbpoints[i].second[1], rgbpoints[i].second[2]); } } void TransferFunction::AddScalarOpacityPoint(double x, double value) { m_ScalarOpacityFunction->AddPoint(x, value); } void TransferFunction::AddGradientOpacityPoint(double x, double value) { m_GradientOpacityFunction->AddPoint(x, value); } void TransferFunction::AddRGBPoint(double x, double r, double g, double b) { m_ColorTransferFunction->AddRGBPoint(x, r, g, b); } TransferFunction::ControlPoints &TransferFunction::GetScalarOpacityPoints() { // Retrieve data points from VTK transfer function and store them in a vector m_ScalarOpacityPoints.clear(); vtkFloatingPointType *data = m_ScalarOpacityFunction->GetDataPointer(); for ( int i = 0; i < m_ScalarOpacityFunction->GetSize(); ++i ) { m_ScalarOpacityPoints.push_back( std::make_pair( data[i*2], data[i*2+1] )); } return m_ScalarOpacityPoints; } TransferFunction::ControlPoints &TransferFunction::GetGradientOpacityPoints() { // Retrieve data points from VTK transfer function and store them in a vector m_GradientOpacityPoints.clear(); vtkFloatingPointType *data = m_GradientOpacityFunction->GetDataPointer(); for ( int i = 0; i < m_GradientOpacityFunction->GetSize(); ++i ) { m_GradientOpacityPoints.push_back( std::make_pair( data[i*2], data[i*2+1] )); } return m_GradientOpacityPoints; } TransferFunction::RGBControlPoints &TransferFunction::GetRGBPoints() { // Retrieve data points from VTK transfer function and store them in a vector m_RGBPoints.clear(); vtkFloatingPointType *data = m_ColorTransferFunction->GetDataPointer(); for ( int i = 0; i < m_ColorTransferFunction->GetSize(); ++i ) { double rgb[] = { data[i*4+1], data[i*4+2], data[i*4+3] }; m_RGBPoints.push_back( std::make_pair( data[i*4], rgb )); } return m_RGBPoints; } int TransferFunction::RemoveScalarOpacityPoint(double x) { return m_ScalarOpacityFunction->RemovePoint(x); } int TransferFunction::RemoveGradientOpacityPoint(double x) { return m_GradientOpacityFunction->RemovePoint(x); } int TransferFunction::RemoveRGBPoint(double x) { return m_ColorTransferFunction->RemovePoint(x); } void TransferFunction::ClearScalarOpacityPoints() { m_ScalarOpacityFunction->RemoveAllPoints(); } void TransferFunction::ClearGradientOpacityPoints() { m_GradientOpacityFunction->RemoveAllPoints(); } void TransferFunction::ClearRGBPoints() { m_ColorTransferFunction->RemoveAllPoints(); } void TransferFunction::InitializeByItkHistogram( const itk::Statistics::Histogram* histogram) { m_Histogram = histogram; m_Min = (int)GetHistogram()->GetBinMin(0,0); m_Max = (int)GetHistogram()->GetBinMax(0, GetHistogram()->Size()-1); /* m_ScalarOpacityFunction->Initialize(); m_ScalarOpacityFunction->AddPoint(m_Min,0.0); m_ScalarOpacityFunction->AddPoint(0.0,0.0); m_ScalarOpacityFunction->AddPoint(m_Max,1.0); m_GradientOpacityFunction->Initialize(); m_GradientOpacityFunction->AddPoint(m_Min,0.0); m_GradientOpacityFunction->AddPoint(0.0,1.0); m_GradientOpacityFunction->AddPoint((m_Max*0.125),1.0); m_GradientOpacityFunction->AddPoint((m_Max*0.2),1.0); m_GradientOpacityFunction->AddPoint((m_Max*0.25),1.0); m_GradientOpacityFunction->AddPoint(m_Max,1.0); m_ColorTransferFunction->RemoveAllPoints(); m_ColorTransferFunction->AddRGBPoint(m_Min,1,0,0); m_ColorTransferFunction->AddRGBPoint(m_Max,1,1,0); m_ColorTransferFunction->SetColorSpaceToHSV(); MITK_INFO << "min/max in tf-c'tor:" << m_Min << "/" << m_Max << std::endl; */ } void TransferFunction::InitializeByMitkImage( const Image * image ) { HistogramGenerator::Pointer histGen= HistogramGenerator::New(); histGen->SetImage(image); histGen->SetSize(256); histGen->ComputeHistogram(); m_Histogram = histGen->GetHistogram(); m_Min = (int)GetHistogram()->GetBinMin(0,0); m_Max = (int)GetHistogram()->GetBinMax(0, GetHistogram()->Size()-1); m_ScalarOpacityFunction->Initialize(); m_ScalarOpacityFunction->AddPoint(m_Min,0.0); m_ScalarOpacityFunction->AddPoint(0.0,0.0); m_ScalarOpacityFunction->AddPoint(m_Max,1.0); m_GradientOpacityFunction->Initialize(); m_GradientOpacityFunction->AddPoint(m_Min,0.0); m_GradientOpacityFunction->AddPoint(0.0,1.0); m_GradientOpacityFunction->AddPoint((m_Max*0.125),1.0); m_GradientOpacityFunction->AddPoint((m_Max*0.2),1.0); m_GradientOpacityFunction->AddPoint((m_Max*0.25),1.0); m_GradientOpacityFunction->AddPoint(m_Max,1.0); m_ColorTransferFunction->RemoveAllPoints(); m_ColorTransferFunction->AddRGBPoint(m_Min,1,0,0); m_ColorTransferFunction->AddRGBPoint(m_Max,1,1,0); m_ColorTransferFunction->SetColorSpaceToHSV(); //MITK_INFO << "min/max in tf-c'tor:" << m_Min << "/" << m_Max << std::endl; } void TransferFunction::InitializeHistogram( const Image * image ) { HistogramGenerator::Pointer histGen= HistogramGenerator::New(); histGen->SetImage(image); histGen->SetSize(256); histGen->ComputeHistogram(); m_Histogram = histGen->GetHistogram(); m_Min = (int)GetHistogram()->GetBinMin(0,0); m_Max = (int)GetHistogram()->GetBinMax(0, GetHistogram()->Size()-1); } -}// namespace \ No newline at end of file + +void TransferFunction::PrintSelf(std::ostream &os, itk::Indent indent) const +{ + os << indent << "ScalarOpacity: "; + m_ScalarOpacityFunction->PrintHeader(os, vtkIndent()); + os << indent << "GradientOpacity: "; + m_GradientOpacityFunction->PrintHeader(os, vtkIndent()); + os << indent << "ColorTransfer: "; + m_ColorTransferFunction->PrintHeader(os, vtkIndent()); + os << indent << "Min: " << m_Min << ", Max: " << m_Max << std::endl; +} + +}// namespace diff --git a/Core/Code/DataManagement/mitkTransferFunction.h b/Core/Code/DataManagement/mitkTransferFunction.h index 295344a797..91a3261a6f 100644 --- a/Core/Code/DataManagement/mitkTransferFunction.h +++ b/Core/Code/DataManagement/mitkTransferFunction.h @@ -1,193 +1,195 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITK_TRANSFER_FUNCTION_H_HEADER_INCLUDED #define MITK_TRANSFER_FUNCTION_H_HEADER_INCLUDED #include "mitkHistogramGenerator.h" #include #include "mitkImage.h" #include #include #include #include #include #include #include #include #include namespace mitk { /** * \brief Wrapper class for VTK scalar opacity, gradient opacity, and color * transfer functions. * * Holds a copy of each of the three standard VTK transfer functions (scalar * opacity, gradient opacity, color) and provides an interface for manipulating * their control points. Each original function can be retrieved by a Get() * method. * * NOTE: Currently, transfer function initialization based on histograms or * computed-tomography-presets is also provided by this class, but will likely * be separated into a specific initializer class. */ class MITK_CORE_EXPORT TransferFunction : public itk::Object { public: typedef std::vector > ControlPoints; typedef std::vector > > RGBControlPoints; mitkClassMacro(TransferFunction, itk::DataObject); itkNewMacro(Self); /** \brief Get/Set min/max of transfer function range for initialization. */ itkSetMacro(Min,int); /** \brief Get/Set min/max of transfer function range for initialization. */ itkSetMacro(Max,int); /** \brief Get/Set min/max of transfer function range for initialization. */ itkGetMacro(Min,int); /** \brief Get/Set min/max of transfer function range for initialization. */ itkGetMacro(Max,int); /** \brief Get/Set wrapped vtk transfer function. */ itkGetMacro(ScalarOpacityFunction,vtkPiecewiseFunction*); /** \brief Get/Set wrapped vtk transfer function. */ itkGetMacro(GradientOpacityFunction,vtkPiecewiseFunction*); /** \brief Get/Set wrapped vtk transfer function. */ itkGetMacro(ColorTransferFunction,vtkColorTransferFunction*); /** \brief Get histogram used for transfer function initialization. */ itkGetConstObjectMacro(Histogram,HistogramGenerator::HistogramType); /** \brief Initialize transfer function based on the histogram of an mitk::Image. */ void InitializeByMitkImage(const mitk::Image* image); /** \brief Initialize transfer function based on the specified histogram. */ void InitializeByItkHistogram(const itk::Statistics::Histogram* histogram); /** \brief Initialize the internal histogram and min/max range based on the * specified mitk::Image. */ void InitializeHistogram( const mitk::Image* image ); /** \brief Insert control points and values into the scalar opacity transfer * function. */ void SetScalarOpacityPoints(TransferFunction::ControlPoints points); /** \brief Insert control points and values into the gradient opacity transfer * function. */ void SetGradientOpacityPoints(TransferFunction::ControlPoints points); /** \brief Insert control points and RGB values into the color transfer * function. */ void SetRGBPoints(TransferFunction::RGBControlPoints rgbpoints); /** \brief Add a single control point to the scalar opacity transfer function. */ void AddScalarOpacityPoint(double x, double value); /** \brief Add a single control point to the gradient opacity transfer function. */ void AddGradientOpacityPoint(double x, double value); /** \brief Add a single control point to the color opacity transfer function. */ void AddRGBPoint(double x, double r, double g, double b); /** \brief Get a copy of the scalar opacity transfer function control-points. */ TransferFunction::ControlPoints &GetScalarOpacityPoints(); /** \brief Get a copy of the gradient opacity transfer function control-points. */ TransferFunction::ControlPoints &GetGradientOpacityPoints(); /** \brief Get a copy of the color transfer function control-points. */ TransferFunction::RGBControlPoints &GetRGBPoints(); /** \brief Remove the specified control point from the scalar opacity transfer * function. */ int RemoveScalarOpacityPoint(double x); /** \brief Remove the specified control point from the gradient opacity transfer * function. */ int RemoveGradientOpacityPoint(double x); /** \brief Remove the specified control point from the color transfer function. */ int RemoveRGBPoint(double x); /** \brief Removes all control points from the scalar opacity transfer function. */ void ClearScalarOpacityPoints(); /** \brief Removes all control points from the gradient opacity transfer * function. */ void ClearGradientOpacityPoints(); /** \brief Removes all control points from the color transfer function. */ void ClearRGBPoints(); bool operator==(Self& other); protected: TransferFunction(); virtual ~TransferFunction(); - + + void PrintSelf(std::ostream &os, itk::Indent indent) const; + /** Wrapped VTK scalar opacity transfer function */ vtkSmartPointer m_ScalarOpacityFunction; /** Wrapped VTK gradient opacity transfer function */ vtkSmartPointer m_GradientOpacityFunction; /** Wrapped VTK color transfer function */ vtkSmartPointer m_ColorTransferFunction; /** Current range of transfer function (used for initialization) */ int m_Min; /** Current range of transfer function (used for initialization) */ int m_Max; /** Specified or calculated histogram (used for initialization) */ mitk::HistogramGenerator::HistogramType::ConstPointer m_Histogram; private: /** Temporary STL style copy of VTK internal control points */ TransferFunction::ControlPoints m_ScalarOpacityPoints; /** Temporary STL style copy of VTK internal control points */ TransferFunction::ControlPoints m_GradientOpacityPoints; /** Temporary STL style copy of VTK internal control points */ TransferFunction::RGBControlPoints m_RGBPoints; }; } #endif /* MITK_TRANSFER_FUNCTION_H_HEADER_INCLUDED */ diff --git a/Core/Code/DataManagement/mitkTransferFunctionProperty.cpp b/Core/Code/DataManagement/mitkTransferFunctionProperty.cpp index 217af15cdf..f2cbca7289 100644 --- a/Core/Code/DataManagement/mitkTransferFunctionProperty.cpp +++ b/Core/Code/DataManagement/mitkTransferFunctionProperty.cpp @@ -1,49 +1,50 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkTransferFunctionProperty.h" namespace mitk { bool TransferFunctionProperty::IsEqual(const BaseProperty& property) const { return *(this->m_Value) == *(static_cast(property).m_Value); } -BaseProperty& TransferFunctionProperty::operator=(const BaseProperty& other) +bool TransferFunctionProperty::Assign(const BaseProperty& property) { - return Superclass::operator=(other); + this->m_Value = static_cast(property).m_Value; + return true; } std::string TransferFunctionProperty::GetValueAsString() const { std::stringstream myStr; - myStr << GetValue() ; + myStr << GetValue(); return myStr.str(); } TransferFunctionProperty::TransferFunctionProperty() : BaseProperty() {} TransferFunctionProperty::TransferFunctionProperty( mitk::TransferFunction::Pointer value ) : BaseProperty(), m_Value( value ) {} } // namespace mitk diff --git a/Core/Code/DataManagement/mitkTransferFunctionProperty.h b/Core/Code/DataManagement/mitkTransferFunctionProperty.h index 5ba77cb66f..3645f3fc45 100644 --- a/Core/Code/DataManagement/mitkTransferFunctionProperty.h +++ b/Core/Code/DataManagement/mitkTransferFunctionProperty.h @@ -1,57 +1,65 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKTRANFERFUNCTIONPROPERTY_H_HEADER_INCLUDED #define MITKTRANFERFUNCTIONPROPERTY_H_HEADER_INCLUDED #include "mitkBaseProperty.h" #include "mitkTransferFunction.h" namespace mitk { class MITK_CORE_EXPORT TransferFunctionProperty : public BaseProperty { public: + + typedef mitk::TransferFunction::Pointer ValueType; + mitkClassMacro(TransferFunctionProperty, BaseProperty); itkNewMacro(TransferFunctionProperty); mitkNewMacro1Param(TransferFunctionProperty, mitk::TransferFunction::Pointer); itkSetMacro(Value, mitk::TransferFunction::Pointer ); itkGetConstMacro(Value, mitk::TransferFunction::Pointer ); - virtual BaseProperty& operator=(const BaseProperty& other); - std::string GetValueAsString() const; + using BaseProperty::operator=; + protected: mitk::TransferFunction::Pointer m_Value; TransferFunctionProperty(); TransferFunctionProperty( mitk::TransferFunction::Pointer value ); private: + // purposely not implemented + TransferFunctionProperty(const TransferFunctionProperty&); + TransferFunctionProperty& operator=(const TransferFunctionProperty&); + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty& property); }; } // namespace mitk #endif /* MITKTRANFERFUNCTIONPROPERTY_H_HEADER_INCLUDED */ diff --git a/Core/Code/DataManagement/mitkVtkInterpolationProperty.h b/Core/Code/DataManagement/mitkVtkInterpolationProperty.h index 60e8b5757c..5929c200c6 100644 --- a/Core/Code/DataManagement/mitkVtkInterpolationProperty.h +++ b/Core/Code/DataManagement/mitkVtkInterpolationProperty.h @@ -1,105 +1,111 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITK_VTK_INTERPOLATION_PROPERTY__H_ #define _MITK_VTK_INTERPOLATION_PROPERTY__H_ #include "mitkEnumerationProperty.h" namespace mitk { /** * Encapsulates the enumeration vtkInterpolation. Valid values are * (VTK constant/Id/string representation): * VTK_FLAT/0/Flat, VTK_GOURAUD/1/Gouraud, VTK_PHONG/2/Phong * Default is the Gouraud interpolation */ class MITK_CORE_EXPORT VtkInterpolationProperty : public EnumerationProperty { public: mitkClassMacro( VtkInterpolationProperty, EnumerationProperty ); itkNewMacro(VtkInterpolationProperty); mitkNewMacro1Param(VtkInterpolationProperty, const IdType&); mitkNewMacro1Param(VtkInterpolationProperty, const std::string&); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - /** * Returns the current interpolation value as defined by VTK constants. * @returns the current interpolation as VTK constant. */ virtual int GetVtkInterpolation(); /** * Sets the interpolation type to VTK_FLAT. */ virtual void SetInterpolationToFlat(); /** * Sets the interpolation type to VTK_WIREFRAME. */ virtual void SetInterpolationToGouraud(); /** * Sets the interpolation type to VTK_SURFACE. */ virtual void SetInterpolationToPhong(); + + using BaseProperty::operator=; protected: /** * Constructor. Sets the representation to a default value of surface(2) */ VtkInterpolationProperty( ); /** * Constructor. Sets the interpolation to the given value. If it is not * valid, the interpolation is set to gouraud(1) * @param value the integer representation of the interpolation */ VtkInterpolationProperty( const IdType& value ); /** * Constructor. Sets the interpolation to the given value. If it is not * valid, the representation is set to gouraud(1) * @param value the string representation of the interpolation */ VtkInterpolationProperty( const std::string& value ); /** * this function is overridden as protected, so that the user may not add * additional invalid interpolation types. */ virtual bool AddEnum( const std::string& name, const IdType& id ); /** * Adds the enumeration types as defined by vtk to the list of known * enumeration values. */ virtual void AddInterpolationTypes(); + +private: + + // purposely not implemented + VtkInterpolationProperty(const VtkInterpolationProperty&); + VtkInterpolationProperty& operator=(const VtkInterpolationProperty&); }; } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkVtkRepresentationProperty.h b/Core/Code/DataManagement/mitkVtkRepresentationProperty.h index eacc4a8e96..70a3a0bb9e 100644 --- a/Core/Code/DataManagement/mitkVtkRepresentationProperty.h +++ b/Core/Code/DataManagement/mitkVtkRepresentationProperty.h @@ -1,103 +1,109 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITK_VTK_REPRESENTATION_PROPERTY__H_ #define _MITK_VTK_REPRESENTATION_PROPERTY__H_ #include "mitkEnumerationProperty.h" namespace mitk { /** * Encapsulates the enumeration vtkRepresentation. Valid values are * (VTK constant/Id/string representation): * VTK_POINTS/0/Points, VTK_WIREFRAME/1/Wireframe, VTK_SURFACE/2/Surface * Default is the Surface representation */ class MITK_CORE_EXPORT VtkRepresentationProperty : public EnumerationProperty { public: mitkClassMacro( VtkRepresentationProperty, EnumerationProperty ); itkNewMacro(VtkRepresentationProperty); mitkNewMacro1Param(VtkRepresentationProperty, const IdType&); mitkNewMacro1Param(VtkRepresentationProperty, const std::string&); /** * Returns the current representation value as defined by VTK constants. * @returns the current representation as VTK constant. */ virtual int GetVtkRepresentation(); /** * Sets the representation type to VTK_POINTS. */ virtual void SetRepresentationToPoints(); /** * Sets the representation type to VTK_WIREFRAME. */ virtual void SetRepresentationToWireframe(); /** * Sets the representation type to VTK_SURFACE. */ virtual void SetRepresentationToSurface(); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } + using BaseProperty::operator=; protected: /** * Constructor. Sets the representation to a default value of Surface(2) */ VtkRepresentationProperty( ); /** * Constructor. Sets the representation to the given value. If it is not * valid, the representation is set to Surface(2) * @param value the integer representation of the representation */ VtkRepresentationProperty( const IdType& value ); /** * Constructor. Sets the representation to the given value. If it is not * valid, the representation is set to Surface(2) * @param value the string representation of the representation */ VtkRepresentationProperty( const std::string& value ); /** * this function is overridden as protected, so that the user may not add * additional invalid representation types. */ virtual bool AddEnum( const std::string& name, const IdType& id ); /** * Adds the enumeration types as defined by vtk to the list of known * enumeration values. */ virtual void AddRepresentationTypes(); + +private: + + // purposely not implemented + VtkRepresentationProperty(const VtkRepresentationProperty&); + VtkRepresentationProperty& operator=(const VtkRepresentationProperty&); }; } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.h b/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.h index 4ee164c299..28583e0c9d 100644 --- a/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.h +++ b/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.h @@ -1,101 +1,107 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITK_VTK_RESLICE_INTERPOLATION_PROPERTY__H_ #define _MITK_VTK_RESLICE_INTERPOLATION_PROPERTY__H_ #include "mitkEnumerationProperty.h" #include namespace mitk { /** * Encapsulates the enumeration for reslice interpolation. Valid values are * (VTK constant/Id/string representation): * VTK_RESLICE_NEAREST, VTK_RESLICE_LINEAR, VTK_RESLICE_CUBIC * Default is VTK_RESLICE_NEAREST */ class MITK_CORE_EXPORT VtkResliceInterpolationProperty : public EnumerationProperty { public: mitkClassMacro( VtkResliceInterpolationProperty, EnumerationProperty ); itkNewMacro(VtkResliceInterpolationProperty); mitkNewMacro1Param(VtkResliceInterpolationProperty, const IdType&); mitkNewMacro1Param(VtkResliceInterpolationProperty, const std::string&); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - /** * Returns the current interpolation value as defined by VTK constants. */ virtual int GetInterpolation(); /** * Sets the interpolation type to VTK_RESLICE_NEAREST. */ virtual void SetInterpolationToNearest(); /** * Sets the interpolation type to VTK_RESLICE_LINEAR. */ virtual void SetInterpolationToLinear(); /** * Sets the interpolation type to VTK_RESLICE_CUBIC. */ virtual void SetInterpolationToCubic(); + + using BaseProperty::operator=; protected: /** Sets reslice interpolation mode to default (VTK_RESLICE_NEAREST). */ VtkResliceInterpolationProperty( ); /** * Constructor. Sets reslice interpolation to the given value. */ VtkResliceInterpolationProperty( const IdType& value ); /** * Constructor. Sets reslice interpolation to the given value. */ VtkResliceInterpolationProperty( const std::string& value ); /** * this function is overridden as protected, so that the user may not add * additional invalid interpolation types. */ virtual bool AddEnum( const std::string& name, const IdType& id ); /** * Adds the enumeration types as defined by vtk to the list of known * enumeration values. */ virtual void AddInterpolationTypes(); + +private: + + // purposely not implemented + VtkResliceInterpolationProperty(const VtkResliceInterpolationProperty&); + VtkResliceInterpolationProperty& operator=(const VtkResliceInterpolationProperty&); }; } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkVtkScalarModeProperty.h b/Core/Code/DataManagement/mitkVtkScalarModeProperty.h index 9daac9822f..ad14415ca5 100644 --- a/Core/Code/DataManagement/mitkVtkScalarModeProperty.h +++ b/Core/Code/DataManagement/mitkVtkScalarModeProperty.h @@ -1,103 +1,109 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITK_VTK_SCALARMODE_PROPERTY__H_ #define _MITK_VTK_SCALARMODE_PROPERTY__H_ #include "mitkEnumerationProperty.h" namespace mitk { /** * Encapsulates the enumeration vtkInterpolation. Valid values are * (VTK constant/Id/string representation): * \li VTK_SCALAR_MODE_DEFAULT/0/Default, * \li VTK_SCALAR_MODE_USE_POINT_DATA/1/PointData, * \li VTK_SCALAR_MODE_USE_CELL_DATA/2/CellData * \li VTK_SCALAR_MODE_USE_POINT_FIELD_DATA/3/PointFieldData * \li VTK_SCALAR_MODE_USE_CELL_FIELD_DATA/4/CellFieldData */ class MITK_CORE_EXPORT VtkScalarModeProperty : public EnumerationProperty { public: mitkClassMacro( VtkScalarModeProperty, EnumerationProperty ); itkNewMacro(VtkScalarModeProperty); mitkNewMacro1Param(VtkScalarModeProperty, const IdType&); mitkNewMacro1Param(VtkScalarModeProperty, const std::string&); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - /** * Returns the current scalar mode value as defined by VTK constants. * @returns the current scalar mode as VTK constant. */ virtual int GetVtkScalarMode(); virtual void SetScalarModeToDefault(); virtual void SetScalarModeToPointData(); virtual void SetScalarModeToCellData(); virtual void SetScalarModeToPointFieldData(); virtual void SetScalarModeToCellFieldData(); + + using BaseProperty::operator=; protected: /** * Constructor. Sets the representation to a default value of surface(2) */ VtkScalarModeProperty( ); /** * \brief Sets the scalar mode to the given value. If it is not * valid, the scalar mode is set to default (0). * @param value the integer representation of the scalar mode */ VtkScalarModeProperty( const IdType& value ); /** * \brief Sets the scalar mode to the given value. If it is not * valid, the representation is set to default (0). * @param value the string representation of the scalar mode */ VtkScalarModeProperty( const std::string& value ); /** * this function is overridden as protected, so that the user may not add * additional invalid scalar mode types. */ virtual bool AddEnum( const std::string& name, const IdType& id ); /** * Adds the enumeration types as defined by vtk to the list of known * enumeration values. */ virtual void AddInterpolationTypes(); + +private: + + // purposely not implemented + VtkScalarModeProperty(const VtkScalarModeProperty&); + VtkScalarModeProperty& operator=(const VtkScalarModeProperty&); }; } // end of namespace mitk #endif //_MITK_VTK_SCALARMODE_PROPERTY__H_ diff --git a/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.h b/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.h index b7838cfc89..7882fa37d0 100644 --- a/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.h +++ b/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.h @@ -1,97 +1,103 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITK_VTK_VOLUME_RENDERING_PROPERTY__H_ #define _MITK_VTK_VOLUME_RENDERING_PROPERTY__H_ #include "mitkEnumerationProperty.h" #define VTK_RAY_CAST_COMPOSITE_FUNCTION 1 #define VTK_VOLUME_RAY_CAST_MIP_FUNCTION 2 namespace mitk { /** * Encapsulates the enumeration for volume rendering. Valid values are * (VTK constant/Id/string representation): * VTK_VOLUME_RAY_CAST_MIP_FUNCTION * VTK_RAY_CAST_COMPOSITE_FUNCTION * Default is NULL */ class MITK_CORE_EXPORT VtkVolumeRenderingProperty : public EnumerationProperty { public: mitkClassMacro( VtkVolumeRenderingProperty, EnumerationProperty ); itkNewMacro(VtkVolumeRenderingProperty); mitkNewMacro1Param(VtkVolumeRenderingProperty, const IdType&); mitkNewMacro1Param(VtkVolumeRenderingProperty, const std::string&); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - /** * Returns the current volume rendering type */ virtual int GetRenderingType(); /** * Sets the rendering type to VTK_VOLUME_RAY_CAST_MIP_FUNCTION */ virtual void SetRenderingTypeToMIP(); /** * Sets the rendering type to VTK_RAY_CAST_COMPOSITE_FUNCTION */ virtual void SetRenderingTypeToComposite(); + using BaseProperty::operator=; + protected: /** Sets rendering type to default (VTK_RAY_CAST_COMPOSITE_FUNCTION). */ VtkVolumeRenderingProperty( ); /** * Constructor. Sets rendering type to the given value. */ VtkVolumeRenderingProperty( const IdType& value ); /** * Constructor. Sets rendering type to the given value. */ VtkVolumeRenderingProperty( const std::string& value ); /** * this function is overridden as protected, so that the user may not add * additional invalid rendering types. */ virtual bool AddEnum( const std::string& name, const IdType& id ); /** * Adds the enumeration types as defined by vtk to the list of known * enumeration values. */ virtual void AddRenderingTypes(); + +private: + + // purposely not implemented + VtkVolumeRenderingProperty(const VtkVolumeRenderingProperty&); + VtkVolumeRenderingProperty& operator=(const VtkVolumeRenderingProperty&); }; } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkWeakPointerProperty.cpp b/Core/Code/DataManagement/mitkWeakPointerProperty.cpp index 9f8918afaf..9e3696b4ae 100644 --- a/Core/Code/DataManagement/mitkWeakPointerProperty.cpp +++ b/Core/Code/DataManagement/mitkWeakPointerProperty.cpp @@ -1,50 +1,69 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkWeakPointerProperty.h" bool mitk::WeakPointerProperty::IsEqual(const BaseProperty& property) const { return this->m_WeakPointer == static_cast(property).m_WeakPointer; } +bool mitk::WeakPointerProperty::Assign(const BaseProperty& property) +{ + this->m_WeakPointer = static_cast(property).m_WeakPointer; + return true; +} + mitk::WeakPointerProperty::WeakPointerProperty(itk::Object* pointer) : m_WeakPointer(pointer) { - Modified(); } mitk::WeakPointerProperty::~WeakPointerProperty() { } +std::string mitk::WeakPointerProperty::GetValueAsString() const +{ + std::stringstream ss; + ss << m_WeakPointer.GetPointer(); + return ss.str(); +} -itk::Object::Pointer mitk::WeakPointerProperty::GetWeakPointer() const +mitk::WeakPointerProperty::ValueType mitk::WeakPointerProperty::GetWeakPointer() const { return m_WeakPointer.GetPointer(); } - +mitk::WeakPointerProperty::ValueType mitk::WeakPointerProperty::GetValue() const +{ + return GetWeakPointer(); +} void mitk::WeakPointerProperty::SetWeakPointer(itk::Object* pointer) { if(m_WeakPointer.GetPointer() != pointer) { m_WeakPointer = pointer; Modified(); } } + +void mitk::WeakPointerProperty::SetValue(const ValueType &value) +{ + SetWeakPointer(value.GetPointer()); +} diff --git a/Core/Code/DataManagement/mitkWeakPointerProperty.h b/Core/Code/DataManagement/mitkWeakPointerProperty.h index d7b88c2d3e..453074b3e5 100644 --- a/Core/Code/DataManagement/mitkWeakPointerProperty.h +++ b/Core/Code/DataManagement/mitkWeakPointerProperty.h @@ -1,59 +1,72 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKWEAKPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 #define MITKWEAKPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 #include #include "mitkBaseProperty.h" #include "itkWeakPointer.h" namespace mitk { //##Documentation //## @brief Property containing a smart-pointer //## //## @ingroup DataManagement class MITK_CORE_EXPORT WeakPointerProperty : public BaseProperty { public: mitkClassMacro(WeakPointerProperty, BaseProperty); + itkNewMacro(WeakPointerProperty); mitkNewMacro1Param(WeakPointerProperty, itk::Object*); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - virtual ~WeakPointerProperty(); - itk::Object::Pointer GetWeakPointer() const; + typedef itk::WeakPointer ValueType; + + ValueType GetWeakPointer() const; + ValueType GetValue() const; void SetWeakPointer(itk::Object* pointer); + void SetValue(const ValueType& value); + + virtual std::string GetValueAsString() const; + + using BaseProperty::operator=; + protected: itk::WeakPointer m_WeakPointer; - WeakPointerProperty(itk::Object* pointer); + WeakPointerProperty(itk::Object* pointer = 0); private: + // purposely not implemented + WeakPointerProperty(const WeakPointerProperty&); + WeakPointerProperty& operator=(const WeakPointerProperty&); + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty& property); }; } // namespace mitk #endif /* MITKWEAKPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 */ diff --git a/Core/Code/IO/mitkLookupTableProperty.cpp b/Core/Code/IO/mitkLookupTableProperty.cpp index c841b0df41..d6e4c640d5 100755 --- a/Core/Code/IO/mitkLookupTableProperty.cpp +++ b/Core/Code/IO/mitkLookupTableProperty.cpp @@ -1,55 +1,69 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkLookupTableProperty.h" mitk::LookupTableProperty::LookupTableProperty() { } mitk::LookupTableProperty::LookupTableProperty(const mitk::LookupTable::Pointer lut) { this->SetLookupTable(lut); } -//mitk::LookupTableProperty::LookupTableProperty(const mitk::LookupTable &aLookupTable) -//{ -// SetLookupTable(aLookupTable); -//} +bool mitk::LookupTableProperty::IsEqual(const BaseProperty& property) const +{ + return *(this->m_LookupTable) == *(static_cast(property).m_LookupTable); +} -mitk::LookupTableProperty::~LookupTableProperty() +bool mitk::LookupTableProperty::Assign(const BaseProperty& property) { + this->m_LookupTable = static_cast(property).m_LookupTable; + return true; } -bool mitk::LookupTableProperty::IsEqual(const BaseProperty& property) const +std::string mitk::LookupTableProperty::GetValueAsString() const { - return *(this->m_LookupTable) == *(static_cast(property).m_LookupTable); + std::stringstream ss; + ss << m_LookupTable; + return ss.str(); +} + +mitk::LookupTableProperty::ValueType mitk::LookupTableProperty::GetValue() const +{ + return m_LookupTable; } void mitk::LookupTableProperty::SetLookupTable(const mitk::LookupTable::Pointer aLookupTable) { // MITK_INFO << "setting LUT property ... " << std::endl; if((m_LookupTable != aLookupTable) || (*m_LookupTable != *aLookupTable)) { m_LookupTable = aLookupTable; Modified(); } // MITK_INFO << "setting LUT property OK! " << std::endl; } + +void mitk::LookupTableProperty::SetValue(const ValueType & value) +{ + SetLookupTable(value); +} diff --git a/Core/Code/IO/mitkLookupTableProperty.h b/Core/Code/IO/mitkLookupTableProperty.h index f173c6eb17..a76223083c 100755 --- a/Core/Code/IO/mitkLookupTableProperty.h +++ b/Core/Code/IO/mitkLookupTableProperty.h @@ -1,68 +1,76 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKLookupTablePROPERTY_H_HEADER_INCLUDED_C10EEAA8 #define MITKLookupTablePROPERTY_H_HEADER_INCLUDED_C10EEAA8 #include #include "mitkBaseProperty.h" #include "mitkLookupTable.h" namespace mitk { //##Documentation //## @brief Property for LookupTable data //## //## @ingroup DataManagement class MITK_CORE_EXPORT LookupTableProperty : public BaseProperty { protected: LookupTable::Pointer m_LookupTable; LookupTableProperty(); LookupTableProperty(const mitk::LookupTable::Pointer lut); - // LookupTableProperty(const mitk::LookupTable& aLookupTable); - public: + + typedef LookupTable::Pointer ValueType; + mitkClassMacro(LookupTableProperty, BaseProperty); itkNewMacro(LookupTableProperty); mitkNewMacro1Param(LookupTableProperty, const mitk::LookupTable::Pointer); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } - - virtual ~LookupTableProperty(); - itkGetObjectMacro(LookupTable, LookupTable ); + ValueType GetValue() const; void SetLookupTable(const mitk::LookupTable::Pointer aLookupTable); + void SetValue(const ValueType&); + + virtual std::string GetValueAsString() const; + + using BaseProperty::operator=; private: + // purposely not implemented + LookupTableProperty(const LookupTableProperty&); + LookupTableProperty& operator=(const LookupTableProperty&); + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty& property); }; } // namespace mitk #endif /* MITKLookupTablePROPERTY_H_HEADER_INCLUDED_C10EEAA8 */ diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index 21114146e6..7a11434d55 100644 --- a/Core/Code/Testing/files.cmake +++ b/Core/Code/Testing/files.cmake @@ -1,117 +1,118 @@ # tests with no extra command line parameter SET(MODULE_TESTS mitkAccessByItkTest.cpp mitkCoreObjectFactoryTest.cpp mitkPointSetWriterTest.cpp mitkMaterialTest.cpp mitkActionTest.cpp mitkEnumerationPropertyTest.cpp mitkEventTest.cpp mitkFocusManagerTest.cpp mitkGenericPropertyTest.cpp mitkGeometry3DTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkGlobalInteractionTest.cpp mitkImageDataItemTest.cpp #mitkImageMapper2DTest.cpp mitkImageGeneratorTest.cpp mitkBaseDataTest.cpp #mitkImageToItkTest.cpp mitkInstantiateAccessFunctionTest.cpp mitkInteractorTest.cpp mitkITKThreadingTest.cpp mitkLDAPFilterTest.cpp # mitkLevelWindowManagerTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp mitkModuleTest.cpp #mitkPipelineSmartPointerCorrectnessTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetTest.cpp mitkPointSetInteractorTest.cpp + mitkPropertyTest.cpp mitkPropertyListTest.cpp #mitkRegistrationBaseTest.cpp #mitkSegmentationInterpolationTest.cpp mitkServiceListenerTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkStateMachineTest.cpp mitkStateTest.cpp mitkSurfaceTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeSlicedGeometryTest.cpp mitkTransitionTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp #mitkAbstractTransformGeometryTest.cpp #mitkPicFileIOTest.cpp mitkStepperTest.cpp itkTotalVariationDenoisingImageFilterTest.cpp mitkRenderingManagerTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateSourceTest.cpp mitkVectorTest.cpp mitkClippedSurfaceBoundsCalculatorTest.cpp ) # test with image filename as an extra command line parameter SET(MODULE_IMAGE_TESTS mitkSurfaceVtkWriterTest.cpp mitkPicFileWriterTest.cpp #mitkImageSliceSelectorTest.cpp mitkImageTimeSelectorTest.cpp mitkPicFileReaderTest.cpp # mitkVtkPropRendererTest.cpp mitkDataNodeFactoryTest.cpp #mitkSTLFileReaderTest.cpp ) # list of images for which the tests are run SET(MODULE_TESTIMAGES US4DCyl.pic.gz Pic3D.pic.gz Pic2DplusT.pic.gz BallBinary30x30x30.pic.gz binary.stl ball.stl ) SET(MODULE_CUSTOM_TESTS #mitkLabeledImageToSurfaceFilterTest.cpp #mitkExternalToolsTest.cpp mitkDataStorageTest.cpp mitkDataNodeTest.cpp mitkDicomSeriesReaderTest.cpp mitkDICOMLocaleTest.cpp mitkEventMapperTest.cpp mitkNodeDependentPointSetInteractorTest.cpp mitkStateMachineFactoryTest.cpp mitkPointSetLocaleTest.cpp mitkImageTest.cpp mitkImageWriterTest.cpp ) # Create an artificial module initializing class for # the mitkServiceListenerTest.cpp SET(module_name_orig ${MODULE_NAME}) SET(module_libname_orig ${MODULE_LIBNAME}) SET(MODULE_NAME "${MODULE_NAME}TestDriver") SET(MODULE_LIBNAME "") SET(MODULE_DEPENDS_STR "Mitk") SET(MODULE_PACKAGE_DEPENDS_STR "") SET(MODULE_VERSION "0.1.0") SET(MODULE_QT_BOOL "false") SET(testdriver_init_file "${CMAKE_CURRENT_BINARY_DIR}/MitkTestDriver_init.cpp") CONFIGURE_FILE("${MITK_SOURCE_DIR}/CMake/mitkModuleInit.cpp" ${testdriver_init_file} @ONLY) SET(TEST_CPP_FILES ${testdriver_init_file}) SET(MODULE_NAME ${module_name_orig}) SET(MODULE_LIBNAME ${module_libname_orig}) diff --git a/Core/Code/Testing/mitkGenericPropertyTest.cpp b/Core/Code/Testing/mitkGenericPropertyTest.cpp index daa0d9cdeb..b2829eb5c3 100644 --- a/Core/Code/Testing/mitkGenericPropertyTest.cpp +++ b/Core/Code/Testing/mitkGenericPropertyTest.cpp @@ -1,110 +1,110 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkTestingMacros.h" #include "mitkGenericProperty.h" #include "mitkStringProperty.h" #include "mitkProperties.h" #include "mitkVector.h" #include #include // call with testValue1 != testValue2 template int TestGenericPropertyForDataType(typename T::ValueType testValue1, typename T::ValueType testValue2, std::string testValue1AsString, std::string testValue2AsString, std::string type) { std::cout << "Testing mitk::GenericProperty<" << type << ">(" << testValue1AsString << ", " << testValue2AsString << ") \n"; typename T::Pointer prop(T::New()); typename T::Pointer prop2(T::New(testValue1)); typename T::Pointer prop3(T::New(testValue2)); unsigned long tBefore = prop->GetMTime(); prop->SetValue(testValue1); unsigned long tAfter = prop->GetMTime(); prop->SetValue(testValue1); unsigned long tAfterAll = prop->GetMTime(); MITK_TEST_CONDITION_REQUIRED(prop->GetValue() == testValue1 && prop->GetValueAsString() == testValue1AsString,"Testing SetValue") MITK_TEST_CONDITION_REQUIRED((*prop == *prop2),"Testing equality operator (operator==)"); prop->SetValue(testValue2); unsigned long tAfterEverything = prop->GetMTime(); std::cout << " Testing MTime correctness when changing property value: "; if (tBefore >= tAfter || tAfterAll != tAfter || tAfterEverything <= tAfterAll) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; prop->SetValue(testValue1); - std::cout << " Testing assignment operator (operator=): "; - *prop = *prop3; + std::cout << " Testing Assignment: "; + prop->AssignProperty(*prop3); if ( (! (*prop == *prop3)) || (*prop == *prop2) ) { std::cout << " [FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; std::cout << std::endl; return EXIT_SUCCESS; } int mitkGenericPropertyTest(int /*argc*/, char* /*argv*/[]) { MITK_TEST_BEGIN(GenericPropertyTest) // testing for some different data types TestGenericPropertyForDataType(1, 2, "1", "2", "int"); TestGenericPropertyForDataType(true, false, "1", "0", "bool"); TestGenericPropertyForDataType(1.0, -1.0, "1", "-1", "float"); TestGenericPropertyForDataType(1.0, -1.0, "1", "-1", "double"); TestGenericPropertyForDataType(std::string("eins"), std::string("zwei"), std::string("eins"), std::string("zwei"), "std::string"); { mitk::Point3D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; mitk::Point3D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0; TestGenericPropertyForDataType( p1, p2, "[2, 3, 4]", "[-1, 2, 3]", "mitk::Point3D"); } { mitk::Point4D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; p1[3] =-2.0; mitk::Point4D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0; p2[3] = 5.0; TestGenericPropertyForDataType( p1, p2, "[2, 3, 4, -2]", "[-1, 2, 3, 5]", "mitk::Point4D"); } /* THIS won't compile because of the interface of XMLWriter... that should be reworked perhaps { mitk::Vector2D p1; p1[0] = 2.0; p1[1] = 3.0; mitk::Vector2D p2; p2[0] =-1.0; p2[1] = 2.0; TestGenericPropertyForDataType( p1, p2, "[2, 3]", "[-1, 2]", "mitk::Vector2D"); } */ { mitk::Vector3D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; mitk::Vector3D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0; TestGenericPropertyForDataType( p1, p2, "[2, 3, 4]", "[-1, 2, 3]", "mitk::Vector3D"); } MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkPropertyTest.cpp b/Core/Code/Testing/mitkPropertyTest.cpp new file mode 100644 index 0000000000..f4973d96d6 --- /dev/null +++ b/Core/Code/Testing/mitkPropertyTest.cpp @@ -0,0 +1,374 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision$ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "mitkTestingMacros.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct PropertyModifiedListener +{ + typedef itk::SimpleMemberCommand CmdType; + + PropertyModifiedListener() : m_Modified(false), m_Cmd(CmdType::New()) + { + m_Cmd->SetCallbackFunction(this, &PropertyModifiedListener::Modified); + } + + void Modified() + { + m_Modified = true; + } + + bool Pop() + { + bool b = m_Modified; + m_Modified = false; + return b; + } + + bool m_Modified; + CmdType::Pointer m_Cmd; +}; + +template +void TestPropInequality(T prop, T prop2) +{ + mitk::BaseProperty::Pointer baseProp2(prop2.GetPointer()); + MITK_TEST_CONDITION_REQUIRED(!(*prop == *prop2), "Test inequality 1"); + MITK_TEST_CONDITION_REQUIRED(!(*prop == *baseProp2), "Test polymorphic inequality 1"); + MITK_TEST_CONDITION_REQUIRED(!(*baseProp2 == *prop), "Test polymorphic inequality 2"); +} + +template +void TestPropAssignment(T prop, T prop2, const std::string& strProp) +{ + PropertyModifiedListener l; + unsigned long tag = prop->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); + + mitk::BaseProperty::Pointer baseProp2(prop2.GetPointer()); + *prop = *baseProp2; + MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified event"); + std::string msg = std::string("Test assignment [") + prop->GetValueAsString() + " == " + strProp + "]"; + MITK_TEST_CONDITION_REQUIRED(prop->GetValueAsString() == strProp, msg); + MITK_TEST_CONDITION_REQUIRED(*prop == *prop2, "Test equality"); + MITK_TEST_CONDITION_REQUIRED(*prop == *baseProp2, "Test equality"); + MITK_TEST_CONDITION_REQUIRED(*baseProp2 == *prop, "Test polymorphic equality"); + + prop->RemoveObserver(tag); +} + +template +void TestPropPolymorphicAssignment(T prop, T prop2, const std::string& strProp) +{ + mitk::BaseProperty::Pointer baseProp(prop.GetPointer()); + + PropertyModifiedListener l; + unsigned long tag = baseProp->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); + + *baseProp = *prop2; + MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified event"); + std::string msg = std::string("Test polymorphic assignment [") + baseProp->GetValueAsString() + " == " + strProp + "]"; + MITK_TEST_CONDITION_REQUIRED(baseProp->GetValueAsString() == strProp, msg); + MITK_TEST_CONDITION_REQUIRED(*prop == *prop2, "Test equality"); + MITK_TEST_CONDITION_REQUIRED(*prop2 == *baseProp, "Test equality"); + MITK_TEST_CONDITION_REQUIRED(*baseProp == *prop2, "Test polymorphic equality"); + + baseProp->RemoveObserver(tag); +} + +template +void TestProperty(const typename T::ValueType& v1, const typename T::ValueType& v2, + const std::string& strV1, const std::string& strV2) +{ + PropertyModifiedListener l; + + typename T::Pointer prop = T::New(v1); + MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); + + MITK_TEST_CONDITION_REQUIRED(prop->GetValue() == v1, "Test constructor"); + std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + strV1 + "]"; + MITK_TEST_CONDITION_REQUIRED(prop->GetValueAsString() == strV1, msg); + + typename T::Pointer prop2 = T::New(); + prop2->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); + MITK_TEST_CONDITION_REQUIRED(!l.m_Modified, "Test modified"); + prop2->SetValue(v2); + MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); + MITK_TEST_CONDITION_REQUIRED(prop2->GetValue() == v2, "Test SetValue()"); + + prop2->SetValue(v2); + MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); + + TestPropInequality(prop, prop2); + TestPropAssignment(prop, prop2, strV2); + + prop->SetValue(v1); + TestPropPolymorphicAssignment(prop2, prop, strV1); +} + +void TestGenericProperties() +{ + TestProperty(false, true, "0", "1"); + TestProperty(3, 5, "3", "5"); + TestProperty(0.3f, -23.5f, "0.3", "-23.5"); + TestProperty(64.1d, 2.34d, "64.1", "2.34"); + + { + mitk::Vector3D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; + mitk::Vector3D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0; + TestProperty(p1, p2, "[2, 3, 4]", "[-1, 2, 3]"); + } + + { + mitk::Point3D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; + mitk::Point3D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0; + TestProperty( p1, p2, "[2, 3, 4]", "[-1, 2, 3]"); + } + + { + mitk::Point4D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; p1[3] =-2.0; + mitk::Point4D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0; p2[3] = 5.0; + TestProperty(p1, p2, "[2, 3, 4, -2]", "[-1, 2, 3, 5]"); + } + + { + mitk::Point3I p1; p1[0] = 2; p1[1] = 3; p1[2] = 4; + mitk::Point3I p2; p2[0] = 8; p2[1] = 7; p2[2] = 6; + TestProperty(p1, p2, "[2, 3, 4]", "[8, 7, 6]"); + } + + { + mitk::FloatLookupTable lut1; + lut1.SetTableValue(1, 0.3f); + lut1.SetTableValue(4, 323.7f); + + mitk::FloatLookupTable lut2; + lut2.SetTableValue(6, -0.3f); + lut2.SetTableValue(2, 25.7f); + + TestProperty(lut1, lut2, "[1 -> 0.3, 4 -> 323.7]", "[2 -> 25.7, 6 -> -0.3]"); + } + + { + mitk::BoolLookupTable lut1; + lut1.SetTableValue(3, false); + lut1.SetTableValue(5, true); + + mitk::BoolLookupTable lut2; + lut2.SetTableValue(1, false); + lut2.SetTableValue(2, false); + TestProperty(lut1, lut2, "[3 -> 0, 5 -> 1]", "[1 -> 0, 2 -> 0]"); + } + + { + mitk::IntLookupTable lut1; + lut1.SetTableValue(5, -12); + lut1.SetTableValue(7, 3); + + mitk::IntLookupTable lut2; + lut2.SetTableValue(4, -6); + lut2.SetTableValue(8, -45); + + TestProperty(lut1, lut2, "[5 -> -12, 7 -> 3]", "[4 -> -6, 8 -> -45]"); + } + + { + mitk::StringLookupTable lut1; + lut1.SetTableValue(0, "a"); + lut1.SetTableValue(2, "b"); + + mitk::StringLookupTable lut2; + lut2.SetTableValue(0, "a"); + lut2.SetTableValue(2, "c"); + + TestProperty(lut1, lut2, "[0 -> a, 2 -> b]", "[0 -> a, 2 -> c]"); + } +} + +void TestAnnotationProperty() +{ + PropertyModifiedListener l; + + std::string label1("Label1"); + mitk::Point3D point1; point1[0] = 3; point1[1] = 5; point1[2] = -4; + std::string str1 = "Label1[3, 5, -4]"; + + std::string label2("Label2"); + mitk::Point3D point2; point2[0] = -2; point2[1] = 8; point2[2] = -4; + std::string str2 = "Label2[-2, 8, -4]"; + + mitk::AnnotationProperty::Pointer prop = mitk::AnnotationProperty::New(label1, point1); + MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); + + MITK_TEST_CONDITION_REQUIRED(prop->GetLabel() == label1 && prop->GetPosition() == point1, "Test constructor"); + std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + str1 + "]"; + MITK_TEST_CONDITION_REQUIRED(prop->GetValueAsString() == str1, msg); + + mitk::AnnotationProperty::Pointer prop2 = mitk::AnnotationProperty::New(); + prop2->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); + MITK_TEST_CONDITION_REQUIRED(!l.m_Modified, "Test not modified"); + prop2->SetLabel(label2); + MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); + prop2->SetPosition(point2); + MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); + MITK_TEST_CONDITION_REQUIRED(prop2->GetLabel() == label2 && prop2->GetPosition() == point2, "Test Setter"); + + prop2->SetLabel(label2); + MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); + prop2->SetPosition(point2); + MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); + + TestPropInequality(prop, prop2); + TestPropAssignment(prop, prop2, str2); + + prop->SetLabel(label1); + prop->SetPosition(point1); + TestPropPolymorphicAssignment(prop2, prop, str1); +} + +void TestClippingProperty() +{ + PropertyModifiedListener l; + + bool enabled1 = true; + mitk::Point3D point1; point1[0] = 3; point1[1] = 5; point1[2] = -4; + mitk::Vector3D vec1; vec1[0] = 0; vec1[1] = 2; vec1[2] = -1; + std::string str1 = "1[3, 5, -4][0, 2, -1]"; + + bool enabled2 = false; + mitk::Point3D point2; point2[0] = -2; point2[1] = 8; point2[2] = -4; + mitk::Vector3D vec2; vec2[0] = 0; vec2[1] = 2; vec2[2] = 4; + std::string str2 = "0[-2, 8, -4][0, 2, 4]"; + + mitk::ClippingProperty::Pointer prop = mitk::ClippingProperty::New(point1, vec1); + MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); + + MITK_TEST_CONDITION_REQUIRED(prop->GetClippingEnabled() == enabled1 && prop->GetOrigin() == point1 && prop->GetNormal() == vec1, "Test constructor"); + std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + str1 + "]"; + MITK_TEST_CONDITION_REQUIRED(prop->GetValueAsString() == str1, msg); + + mitk::ClippingProperty::Pointer prop2 = mitk::ClippingProperty::New(); + prop2->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); + MITK_TEST_CONDITION_REQUIRED(!l.m_Modified, "Test not modified"); + prop2->SetClippingEnabled(enabled2); + MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test not modified"); + prop2->SetOrigin(point2); + MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); + prop2->SetNormal(vec2); + MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); + + MITK_TEST_CONDITION_REQUIRED(prop2->GetClippingEnabled() == enabled2 && prop2->GetOrigin() == point2 && prop2->GetNormal() == vec2, "Test Setter"); + + prop2->SetClippingEnabled(enabled2); + MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); + prop2->SetOrigin(point2); + MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); + prop2->SetNormal(vec2); + MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); + + TestPropInequality(prop, prop2); + TestPropAssignment(prop, prop2, str2); + + prop->SetClippingEnabled(enabled1); + prop->SetOrigin(point1); + prop->SetNormal(vec1); + TestPropPolymorphicAssignment(prop2, prop, str1); +} + +int mitkPropertyTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("Testing MITK Properties") + + TestGenericProperties(); + + TestAnnotationProperty(); + TestClippingProperty(); + + mitk::Color c1; c1[0] = 0.2; c1[1] = 0.6; c1[2] = 0.8; + mitk::Color c2; c2[0] = 0.2; c2[1] = 0.4; c2[2] = 0.1; + TestProperty(c1, c2, "0.2 0.6 0.8", "0.2 0.4 0.1"); + + mitk::LevelWindow lw1(50, 100); + mitk::LevelWindow lw2(120, 30); + TestProperty(lw1, lw2, "L:50 W:100", "L:120 W:30"); + + { + itk::Object::Pointer sp1 = itk::Object::New(); + itk::Object::Pointer sp2 = itk::Object::New(); + // to generate the UIDs, we set the smartpointers + mitk::SmartPointerProperty::Pointer spp1 = mitk::SmartPointerProperty::New(sp1.GetPointer()); + mitk::SmartPointerProperty::Pointer spp2 = mitk::SmartPointerProperty::New(sp2.GetPointer()); + + TestProperty(sp1, sp2, spp1->GetReferenceUIDFor(sp1), spp2->GetReferenceUIDFor(sp2)); + } + + TestProperty("1", "2", "1", "2"); + + { + mitk::TransferFunction::Pointer tf1 = mitk::TransferFunction::New(); + mitk::TransferFunction::Pointer tf2 = mitk::TransferFunction::New(); + tf2->AddScalarOpacityPoint(0.4, 0.8); + std::stringstream ss; + ss << tf1; + std::string strTF1 = ss.str(); + ss.str(""); + ss << tf2; + std::string strTF2 = ss.str(); + TestProperty(tf1, tf2, strTF1, strTF2); + } + + { + itk::Object::Pointer sp1 = itk::Object::New(); + itk::Object::Pointer sp2 = itk::Object::New(); + mitk::WeakPointerProperty::ValueType wp1 = sp1.GetPointer(); + mitk::WeakPointerProperty::ValueType wp2 = sp2.GetPointer(); + std::stringstream ss; + ss << sp1.GetPointer(); + std::string str1 = ss.str(); + ss.str(""); + ss << sp2.GetPointer(); + std::string str2 = ss.str(); + + TestProperty(wp1, wp2, str1, str2); + } + + { + mitk::LookupTable::Pointer lut1 = mitk::LookupTable::New(); + mitk::LookupTable::Pointer lut2 = mitk::LookupTable::New(); + std::stringstream ss; + ss << lut1; + std::string strLUT1 = ss.str(); + ss.str(""); + ss << lut2; + std::string strLUT2 = ss.str(); + TestProperty(lut1, lut2, strLUT1, strLUT2); + } + + MITK_TEST_END() +} diff --git a/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.h b/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.h index 0109569fe0..19ab92f1c7 100644 --- a/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.h +++ b/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.h @@ -1,61 +1,68 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef mitkOrganTypeProperty_h_Included #define mitkOrganTypeProperty_h_Included #include "mitkCommon.h" #include "MitkExtExports.h" #include "mitkEnumerationProperty.h" #include namespace mitk { /** \brief Enumerates all known organs :-) \sa QmitkInteractiveSegmentation \ingroup ToolManagerEtAl \ingroup DataManagement Last contributor $Author$ */ class MitkExt_EXPORT OrganTypeProperty : public EnumerationProperty { public: mitkClassMacro(OrganTypeProperty, EnumerationProperty); itkNewMacro(OrganTypeProperty); mitkNewMacro1Param(OrganTypeProperty, const IdType&); mitkNewMacro1Param(OrganTypeProperty, const std::string&); - virtual BaseProperty& operator=(const BaseProperty& other) { return Superclass::operator=(other); } + + using BaseProperty::operator=; protected: OrganTypeProperty(); OrganTypeProperty( const IdType& value ); OrganTypeProperty( const std::string& value ); virtual ~OrganTypeProperty(); virtual void AddEnumerationTypes(); + + private: + + // purposely not implemented + OrganTypeProperty(const OrganTypeProperty&); + OrganTypeProperty& operator=(const OrganTypeProperty&); }; } // namespace #endif