diff --git a/Core/Code/DataManagement/mitkAnnotationProperty.cpp b/Core/Code/DataManagement/mitkAnnotationProperty.cpp index 9ac73e5d9f..0ce2f6eb60 100644 --- a/Core/Code/DataManagement/mitkAnnotationProperty.cpp +++ b/Core/Code/DataManagement/mitkAnnotationProperty.cpp @@ -1,106 +1,124 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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; } +mitk::AnnotationProperty::AnnotationProperty(const mitk::AnnotationProperty& other) + : BaseProperty(other) + , m_Label(other.m_Label) + , m_Position(other.m_Position) +{ +} const mitk::Point3D &mitk::AnnotationProperty::GetPosition() const { return m_Position; } void mitk::AnnotationProperty::SetPosition( const mitk::Point3D &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(); } + +mitk::AnnotationProperty::Pointer mitk::AnnotationProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::AnnotationProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkAnnotationProperty.h b/Core/Code/DataManagement/mitkAnnotationProperty.h index b3f14b332f..73ecab4daa 100644 --- a/Core/Code/DataManagement/mitkAnnotationProperty.h +++ b/Core/Code/DataManagement/mitkAnnotationProperty.h @@ -1,86 +1,93 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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); + 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 ); + Pointer Clone() const; + 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); } \ + using BaseProperty::operator =; 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 ); + AnnotationProperty(const AnnotationProperty& other); + private: // purposely not implemented - AnnotationProperty(const AnnotationProperty&); AnnotationProperty& operator=(const AnnotationProperty&); + itk::LightObject::Pointer InternalClone() const; + 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 c135493c57..abc07dc500 100644 --- a/Core/Code/DataManagement/mitkBaseProperty.cpp +++ b/Core/Code/DataManagement/mitkBaseProperty.cpp @@ -1,61 +1,66 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkBaseProperty.h" mitk::BaseProperty::BaseProperty() { } +mitk::BaseProperty::BaseProperty(const mitk::BaseProperty&) + : itk::Object() +{ +} + mitk::BaseProperty::~BaseProperty() { } std::string mitk::BaseProperty::GetValueAsString() const { return std::string("n/a"); } mitk::BaseProperty& mitk::BaseProperty::operator=(const BaseProperty& rhs) { AssignProperty(rhs); return *this; } bool mitk::BaseProperty::AssignProperty(const BaseProperty& rhs) { if (this == &rhs) return true; // no self assignment - const char* t1 = typeid(this).name(); - const char* t2 = typeid(&rhs).name(); - - std::string s1(t1); - std::string s2(t2); - if (typeid(*this) == typeid(rhs) && Assign(rhs)) { this->Modified(); return true; } return false; } +mitk::BaseProperty::Pointer mitk::BaseProperty::Clone() const +{ + Pointer result = dynamic_cast(this->InternalClone().GetPointer()); + return result; +} + 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 d42ced312a..f88ca0e912 100644 --- a/Core/Code/DataManagement/mitkBaseProperty.h +++ b/Core/Code/DataManagement/mitkBaseProperty.h @@ -1,101 +1,106 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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); + mitkClassMacro(BaseProperty,itk::Object) + + Pointer Clone() const; /*! @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; /*! @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; protected: BaseProperty(); + BaseProperty(const BaseProperty& other); 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; + + virtual itk::LightObject::Pointer InternalClone() const = 0; }; } // namespace mitk #endif /* BASEPROPERTY_H_HEADER_INCLUDED_C1F4DF54 */ diff --git a/Core/Code/DataManagement/mitkClippingProperty.cpp b/Core/Code/DataManagement/mitkClippingProperty.cpp index 56c7168a22..74d6c22c5b 100644 --- a/Core/Code/DataManagement/mitkClippingProperty.cpp +++ b/Core/Code/DataManagement/mitkClippingProperty.cpp @@ -1,111 +1,131 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkClippingProperty.h" namespace mitk { ClippingProperty::ClippingProperty() : m_ClippingEnabled( false ) { } +ClippingProperty::ClippingProperty(const ClippingProperty& other) + : BaseProperty(other) + , m_ClippingEnabled(other.m_ClippingEnabled) + , m_Origin(other.m_Origin) + , m_Normal(other.m_Normal) +{ +} 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 ) { if (m_ClippingEnabled != enabled) { m_ClippingEnabled = enabled; this->Modified(); } } const Point3D &ClippingProperty::GetOrigin() const { return m_Origin; } void ClippingProperty::SetOrigin( const Point3D &origin ) { if (m_Origin != origin) { m_Origin = origin; this->Modified(); } } const Vector3D &ClippingProperty::GetNormal() const { return m_Normal; } void ClippingProperty::SetNormal( const Vector3D &normal ) { if (m_Normal != normal) { m_Normal = normal; this->Modified(); } } bool ClippingProperty::IsEqual( const BaseProperty &property ) const { 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->GetClippingEnabled() << this->GetOrigin() << this->GetNormal(); return myStr.str(); } + +ClippingProperty::Pointer ClippingProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer ClippingProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} + + } // namespace diff --git a/Core/Code/DataManagement/mitkClippingProperty.h b/Core/Code/DataManagement/mitkClippingProperty.h index 6486131a33..29a848117f 100644 --- a/Core/Code/DataManagement/mitkClippingProperty.h +++ b/Core/Code/DataManagement/mitkClippingProperty.h @@ -1,93 +1,97 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKCLIPPINGPROPERTY_H_HEADER_INCLUDED #define MITKCLIPPINGPROPERTY_H_HEADER_INCLUDED #include #include "mitkBaseProperty.h" #include "mitkVector.h" #include #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * \brief Property for clipping datasets; currently only * clipping planes are possible * \ingroup DataManagement */ class MITK_CORE_EXPORT ClippingProperty : public BaseProperty { public: - mitkClassMacro(ClippingProperty, BaseProperty); + mitkClassMacro(ClippingProperty, BaseProperty) typedef std::string ValueType; itkNewMacro( ClippingProperty ); mitkNewMacro2Param( ClippingProperty, const Point3D &, const Vector3D & ); + Pointer Clone() const; + 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 ClippingProperty& other); ClippingProperty( const Point3D &origin, const Vector3D &normal ); private: // purposely not implemented - ClippingProperty(const ClippingProperty&); ClippingProperty& operator=(const ClippingProperty&); virtual bool IsEqual(const BaseProperty& property) const; virtual bool Assign(const BaseProperty& property); + virtual itk::LightObject::Pointer InternalClone() const; + }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif /* MITKCLIPPINGPROPERTY_H_HEADER_INCLUDED */ diff --git a/Core/Code/DataManagement/mitkColorProperty.cpp b/Core/Code/DataManagement/mitkColorProperty.cpp index 62ee0b7a6c..ca48514c96 100644 --- a/Core/Code/DataManagement/mitkColorProperty.cpp +++ b/Core/Code/DataManagement/mitkColorProperty.cpp @@ -1,87 +1,105 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkColorProperty.h" mitk::ColorProperty::ColorProperty() : m_Color() { } +mitk::ColorProperty::ColorProperty(const mitk::ColorProperty& other) + : BaseProperty(other) + , m_Color(other.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::IsEqual(const BaseProperty& property) const { return this->m_Color == static_cast(property).m_Color; } bool mitk::ColorProperty::Assign(const BaseProperty& property) { 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 ) { 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(); } + +mitk::ColorProperty::Pointer mitk::ColorProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::ColorProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkColorProperty.h b/Core/Code/DataManagement/mitkColorProperty.h index 2d8501f18d..2b89db9844 100644 --- a/Core/Code/DataManagement/mitkColorProperty.h +++ b/Core/Code/DataManagement/mitkColorProperty.h @@ -1,93 +1,98 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKCOLORPROPERTY_H_HEADER_INCLUDED_C17953D1 #define MITKCOLORPROPERTY_H_HEADER_INCLUDED_C17953D1 #include #include "mitkBaseProperty.h" #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif //##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 ColorProperty& other); + ColorProperty(const float red, const float green, const float blue); ColorProperty(const float color[3]); ColorProperty(const mitk::Color & color); public: - mitkClassMacro(ColorProperty, BaseProperty); + mitkClassMacro(ColorProperty, BaseProperty) itkNewMacro(ColorProperty); mitkNewMacro1Param(ColorProperty, const float*); mitkNewMacro1Param(ColorProperty, const mitk::Color&); mitkNewMacro3Param(ColorProperty, const float, const float, const float); + Pointer Clone() const; + 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 itk::LightObject::Pointer InternalClone() const; + virtual bool IsEqual(const BaseProperty& property) const; virtual bool Assign(const BaseProperty & property); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif /* MITKCOLORPROPERTY_H_HEADER_INCLUDED_C17953D1 */ diff --git a/Core/Code/DataManagement/mitkEnumerationProperty.cpp b/Core/Code/DataManagement/mitkEnumerationProperty.cpp index 413b1ae05e..7abecbdb2f 100644 --- a/Core/Code/DataManagement/mitkEnumerationProperty.cpp +++ b/Core/Code/DataManagement/mitkEnumerationProperty.cpp @@ -1,195 +1,211 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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; } +mitk::EnumerationProperty::EnumerationProperty(const EnumerationProperty& other) + : BaseProperty(other) + , m_CurrentValue(other.m_CurrentValue) +{ +} 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 ]; } +mitk::EnumerationProperty::Pointer mitk::EnumerationProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::EnumerationProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkEnumerationProperty.h b/Core/Code/DataManagement/mitkEnumerationProperty.h index 3300983bf9..f5b1dfa974 100644 --- a/Core/Code/DataManagement/mitkEnumerationProperty.h +++ b/Core/Code/DataManagement/mitkEnumerationProperty.h @@ -1,225 +1,230 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_ENUMERATION_PROPERTY__H_ #define _MITK_ENUMERATION_PROPERTY__H_ #include "mitkBaseProperty.h" #include #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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; + Pointer Clone() const; + /** * 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; 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(); + EnumerationProperty(const EnumerationProperty&); + virtual bool IsEqual( const BaseProperty& property ) const; virtual bool Assign( const BaseProperty& property ); private: // purposely not implemented - EnumerationProperty(const EnumerationProperty&); EnumerationProperty& operator=(const EnumerationProperty&); + itk::LightObject::Pointer InternalClone() const; + IdType m_CurrentValue; typedef std::map IdMapForClassNameContainerType; typedef std::map StringMapForClassNameContainerType; static IdMapForClassNameContainerType s_IdMapForClassName; static StringMapForClassNameContainerType s_StringMapForClassName; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace #endif diff --git a/Core/Code/DataManagement/mitkGenericProperty.h b/Core/Code/DataManagement/mitkGenericProperty.h index d1afe3b5fd..4f867e0880 100644 --- a/Core/Code/DataManagement/mitkGenericProperty.h +++ b/Core/Code/DataManagement/mitkGenericProperty.h @@ -1,127 +1,156 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE #define MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE #include #include #include #include "mitkVector.h" #include #include "mitkBaseProperty.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /*! @ 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 MITK_EXPORT GenericProperty : public BaseProperty { public: mitkClassMacro(GenericProperty, BaseProperty); mitkNewMacro1Param(GenericProperty, T); typedef T ValueType; + Pointer Clone() const + { + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; + } + itkSetMacro(Value,T); itkGetConstMacro(Value,T); virtual std::string GetValueAsString() const { std::stringstream myStr; myStr << GetValue() ; return myStr.str(); } using BaseProperty::operator=; protected: GenericProperty() {} GenericProperty(T x) : m_Value(x) {} + GenericProperty(const GenericProperty& other) + : BaseProperty(other) + , m_Value(other.m_Value) + {} + T m_Value; private: // purposely not implemented - GenericProperty(const GenericProperty&); GenericProperty& operator=(const GenericProperty&); + virtual itk::LightObject::Pointer InternalClone() const + { + itk::LightObject::Pointer result(new Self(*this)); + return result; + } + 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; } }; #ifdef _MSC_VER # pragma warning(pop) #endif } // 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 subclass of GenericProperty * @param Type the value type of the GenericProperty * @param Export the export macro for DLL usage */ #define mitkDeclareGenericProperty(PropertyName,Type,Export) \ class Export PropertyName: public GenericProperty< Type > \ { \ public: \ mitkClassMacro(PropertyName, GenericProperty< Type >); \ itkNewMacro(PropertyName); \ mitkNewMacro1Param(PropertyName, Type); \ + Pointer Clone() const; \ using BaseProperty::operator=; \ protected: \ PropertyName(); \ + PropertyName(const PropertyName&); \ PropertyName(Type x); \ +private: \ + itk::LightObject::Pointer InternalClone() const; \ }; -#define mitkDefineGenericProperty(PropertyName,Type,DefaultValue) \ - mitk::PropertyName::PropertyName() : Superclass(DefaultValue) { } \ - mitk::PropertyName::PropertyName(Type x) : Superclass(x) {} +#define mitkDefineGenericProperty(PropertyName,Type,DefaultValue) \ + mitk::PropertyName::PropertyName() : Superclass(DefaultValue) { } \ + mitk::PropertyName::PropertyName(const PropertyName& other) : GenericProperty< Type >(other) {} \ + mitk::PropertyName::PropertyName(Type x) : Superclass(x) {} \ + mitk::PropertyName::Pointer mitk::PropertyName::Clone() const { \ + Pointer result = static_cast(this->InternalClone().GetPointer()); \ + return result; \ + } \ + itk::LightObject::Pointer mitk::PropertyName::InternalClone() const { \ + itk::LightObject::Pointer result(new Self(*this)); \ + return result; \ + } \ #endif /* MITKGENERICPROPERTY_H_HEADER_INCLUDED_C1061CEE */ diff --git a/Core/Code/DataManagement/mitkGroupTagProperty.cpp b/Core/Code/DataManagement/mitkGroupTagProperty.cpp index a6e6dd9f5a..6b78c083fb 100644 --- a/Core/Code/DataManagement/mitkGroupTagProperty.cpp +++ b/Core/Code/DataManagement/mitkGroupTagProperty.cpp @@ -1,35 +1,52 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkGroupTagProperty.h" mitk::GroupTagProperty::GroupTagProperty() : mitk::BaseProperty() { } +mitk::GroupTagProperty::GroupTagProperty(const GroupTagProperty& other) + : mitk::BaseProperty(other) +{ +} + bool mitk::GroupTagProperty::IsEqual(const BaseProperty& /*property*/) const { // if other property is also a GroupTagProperty, then it is equal to us, because tags have no value themselves return true; } bool mitk::GroupTagProperty::Assign(const BaseProperty& /*property*/) { return true; } + +mitk::GroupTagProperty::Pointer mitk::GroupTagProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::GroupTagProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkGroupTagProperty.h b/Core/Code/DataManagement/mitkGroupTagProperty.h index e97229e76b..2bb258642e 100644 --- a/Core/Code/DataManagement/mitkGroupTagProperty.h +++ b/Core/Code/DataManagement/mitkGroupTagProperty.h @@ -1,67 +1,71 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef GROUPTAGPROPERTY_H_HEADER_INCLUDED_C1F4DF54 #define GROUPTAGPROPERTY_H_HEADER_INCLUDED_C1F4DF54 #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /*! @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); + Pointer Clone() const; + using BaseProperty::operator=; protected: GroupTagProperty(); + GroupTagProperty(const GroupTagProperty&); private: // purposely not implemented - GroupTagProperty(const GroupTagProperty&); GroupTagProperty& operator=(const GroupTagProperty&); + itk::LightObject::Pointer InternalClone() const; + virtual bool IsEqual(const BaseProperty& property) const; virtual bool Assign(const BaseProperty& property); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif /* GROUPTAGPROPERTY_H_HEADER_INCLUDED_C1F4DF54 */ diff --git a/Core/Code/DataManagement/mitkLevelWindowProperty.cpp b/Core/Code/DataManagement/mitkLevelWindowProperty.cpp index 74d686d470..63d687bc71 100755 --- a/Core/Code/DataManagement/mitkLevelWindowProperty.cpp +++ b/Core/Code/DataManagement/mitkLevelWindowProperty.cpp @@ -1,74 +1,92 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkLevelWindowProperty.h" mitk::LevelWindowProperty::LevelWindowProperty() { } +mitk::LevelWindowProperty::LevelWindowProperty(const mitk::LevelWindowProperty& other) + : BaseProperty(other) + , m_LevWin(other.m_LevWin) +{ +} + 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(); } + +mitk::LevelWindowProperty::Pointer mitk::LevelWindowProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::LevelWindowProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkLevelWindowProperty.h b/Core/Code/DataManagement/mitkLevelWindowProperty.h index 28e5e97237..00d665e8b5 100755 --- a/Core/Code/DataManagement/mitkLevelWindowProperty.h +++ b/Core/Code/DataManagement/mitkLevelWindowProperty.h @@ -1,84 +1,89 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKLEVELWINDOWPROPERTY_H_HEADER_INCLUDED_C10EEAA8 #define MITKLEVELWINDOWPROPERTY_H_HEADER_INCLUDED_C10EEAA8 #include "mitkBaseProperty.h" #include "mitkLevelWindow.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif //##Documentation //## @brief Property for level/window data //## //## @ingroup DataManagement class MITK_CORE_EXPORT LevelWindowProperty : public BaseProperty { protected: LevelWindow m_LevWin; LevelWindowProperty(); + LevelWindowProperty(const LevelWindowProperty& other); + LevelWindowProperty(const mitk::LevelWindow &levWin); public: mitkClassMacro(LevelWindowProperty, BaseProperty); itkNewMacro(LevelWindowProperty); mitkNewMacro1Param(LevelWindowProperty, const mitk::LevelWindow&); typedef LevelWindow ValueType; + Pointer Clone() const; + 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&); + itk::LightObject::Pointer InternalClone() const; + virtual bool IsEqual(const BaseProperty& property) const; virtual bool Assign(const BaseProperty& property); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif /* MITKLEVELWINDOWPROPERTY_H_HEADER_INCLUDED_C10EEAA8 */ diff --git a/Core/Code/DataManagement/mitkLookupTable.cpp b/Core/Code/DataManagement/mitkLookupTable.cpp index 48131e65ba..3e08d0f8ec 100644 --- a/Core/Code/DataManagement/mitkLookupTable.cpp +++ b/Core/Code/DataManagement/mitkLookupTable.cpp @@ -1,297 +1,315 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkLookupTable.h" #include #include #include mitk::LookupTable::LookupTable() { m_LookupTable = vtkLookupTable::New(); this->SetRequestedRegionToLargestPossibleRegion(); } +mitk::LookupTable::LookupTable(const LookupTable& other) + : itk::DataObject() + , m_LookupTable(vtkLookupTable::New()) +{ + m_LookupTable->DeepCopy(other.m_LookupTable); +} 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++) { //double v0_1 = m_LookupTable->GetTableValue(i)[0]; double v0_2 = olut->GetTableValue(i)[0]; //double v1_1 = m_LookupTable->GetTableValue(i)[1]; double v1_2 = olut->GetTableValue(i)[1]; //double v2_1 = m_LookupTable->GetTableValue(i)[2]; double v2_2 = olut->GetTableValue(i)[2]; //double v3_1 = m_LookupTable->GetTableValue(i)[3]; double v3_2 = olut->GetTableValue(i)[3]; 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()); } + +mitk::LookupTable::Pointer mitk::LookupTable::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::LookupTable::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkLookupTable.h b/Core/Code/DataManagement/mitkLookupTable.h index 02124bd09d..d489310eb6 100644 --- a/Core/Code/DataManagement/mitkLookupTable.h +++ b/Core/Code/DataManagement/mitkLookupTable.h @@ -1,134 +1,139 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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 ); + Pointer Clone() const; + /** * @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; + LookupTable(const LookupTable& other); + vtkLookupTable* m_LookupTable; private: + virtual itk::LightObject::Pointer InternalClone() const; }; } // namespace mitk #endif /* LookupTable_H_HEADER_INCLUDED_C1EBD53D */ diff --git a/Core/Code/DataManagement/mitkModalityProperty.cpp b/Core/Code/DataManagement/mitkModalityProperty.cpp index a7387d5992..b5047d0027 100644 --- a/Core/Code/DataManagement/mitkModalityProperty.cpp +++ b/Core/Code/DataManagement/mitkModalityProperty.cpp @@ -1,70 +1,80 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkModalityProperty.h" mitk::ModalityProperty::ModalityProperty() { AddEnumerationTypes(); } mitk::ModalityProperty::ModalityProperty( const IdType& value ) { AddEnumerationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ) ; } else { SetValue( 0 ); } } mitk::ModalityProperty::ModalityProperty( const std::string& value ) { AddEnumerationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( "undefined" ); } } mitk::ModalityProperty::~ModalityProperty() { } void mitk::ModalityProperty::AddEnumerationTypes() { IdType newId = static_cast(EnumerationProperty::Size()); AddEnum( "undefined", newId++ ); AddEnum( "CR", newId++ ); // computer radiography AddEnum( "CT", newId++ ); // computed tomography AddEnum( "MR", newId++ ); // magnetic resonance AddEnum( "NM", newId++ ); // nuclear medicine AddEnum( "US", newId++ ); // ultrasound AddEnum( "Color Doppler", newId++ ); // ultrasound AddEnum( "Power Doppler", newId++ ); // ultrasound } +mitk::ModalityProperty::Pointer mitk::ModalityProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} +itk::LightObject::Pointer mitk::ModalityProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkModalityProperty.h b/Core/Code/DataManagement/mitkModalityProperty.h index b2d4f2cda3..df2d5f01b4 100644 --- a/Core/Code/DataManagement/mitkModalityProperty.h +++ b/Core/Code/DataManagement/mitkModalityProperty.h @@ -1,71 +1,74 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkModalityProperty_h_Included #define mitkModalityProperty_h_Included #include #include "mitkEnumerationProperty.h" #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** \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&); + Pointer Clone() const; + 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&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace #endif diff --git a/Core/Code/DataManagement/mitkPlaneOrientationProperty.cpp b/Core/Code/DataManagement/mitkPlaneOrientationProperty.cpp index dd5b1436c6..80f39ecec6 100644 --- a/Core/Code/DataManagement/mitkPlaneOrientationProperty.cpp +++ b/Core/Code/DataManagement/mitkPlaneOrientationProperty.cpp @@ -1,96 +1,107 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkPlaneOrientationProperty.h" namespace mitk { PlaneOrientationProperty::PlaneOrientationProperty( ) { this->AddDecorationTypes(); this->SetValue( static_cast( PLANE_DECORATION_NONE ) ); } PlaneOrientationProperty::PlaneOrientationProperty( const IdType& value ) { this->AddDecorationTypes(); if ( this->IsValidEnumerationValue( value ) ) { this->SetValue( value ) ; } else { this->SetValue( static_cast( PLANE_DECORATION_NONE ) ); } } PlaneOrientationProperty::PlaneOrientationProperty( const std::string& value ) { this->AddDecorationTypes(); if ( this->IsValidEnumerationValue( value ) ) { this->SetValue( value ); } else { this->SetValue( static_cast( PLANE_DECORATION_NONE ) ); } } int PlaneOrientationProperty::GetPlaneDecoration() { return static_cast( this->GetValueAsId() ); } void PlaneOrientationProperty::SetPlaneDecorationToNone() { this->SetValue( static_cast( PLANE_DECORATION_NONE ) ); } void PlaneOrientationProperty::SetPlaneDecorationToPositiveOrientation() { this->SetValue( static_cast( PLANE_DECORATION_POSITIVE_ORIENTATION ) ); } void PlaneOrientationProperty::SetPlaneDecorationToNegativeOrientation() { this->SetValue( static_cast( PLANE_DECORATION_NEGATIVE_ORIENTATION ) ); } void PlaneOrientationProperty::AddDecorationTypes() { this->AddEnum( "No plane decoration", static_cast( PLANE_DECORATION_NONE ) ); this->AddEnum( "Arrows in positive direction", static_cast( PLANE_DECORATION_POSITIVE_ORIENTATION ) ); this->AddEnum( "Arrows in negative direction", static_cast( PLANE_DECORATION_NEGATIVE_ORIENTATION ) ); } bool PlaneOrientationProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } +PlaneOrientationProperty::Pointer PlaneOrientationProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer PlaneOrientationProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} } // namespace diff --git a/Core/Code/DataManagement/mitkPlaneOrientationProperty.h b/Core/Code/DataManagement/mitkPlaneOrientationProperty.h index 8a9453a63f..3c13cc4782 100644 --- a/Core/Code/DataManagement/mitkPlaneOrientationProperty.h +++ b/Core/Code/DataManagement/mitkPlaneOrientationProperty.h @@ -1,129 +1,132 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITK_PLANE_DECORATION_PROPERTY__H #define MITK_PLANE_DECORATION_PROPERTY__H #include "mitkEnumerationProperty.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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&); + Pointer Clone() const; + 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&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkPropertyList.cpp b/Core/Code/DataManagement/mitkPropertyList.cpp index b980cdaced..0bad64951d 100644 --- a/Core/Code/DataManagement/mitkPropertyList.cpp +++ b/Core/Code/DataManagement/mitkPropertyList.cpp @@ -1,280 +1,291 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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; } if (it->second->AssignProperty(*property)) { // The assignment was successfull this->Modified(); } else { 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; } return; } //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(const mitk::PropertyList& other) + : itk::Object() +{ + for (PropertyMap::const_iterator i = other.m_Properties.begin(); + i != other.m_Properties.end(); ++i) + { + m_Properties.insert(std::make_pair(i->first, i->second->Clone())); + } +} + 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 mitk::PropertyList::Clone() const { - mitk::PropertyList::Pointer newPropertyList = PropertyList::New(); - - // copy the map - newPropertyList->m_Properties = m_Properties; - - return newPropertyList.GetPointer(); + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; } void mitk::PropertyList::Clear() { PropertyMap::iterator it = m_Properties.begin(), end = m_Properties.end(); while(it!=end) { it->second = NULL; ++it; } m_Properties.clear(); } +itk::LightObject::Pointer mitk::PropertyList::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} 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/mitkPropertyList.h b/Core/Code/DataManagement/mitkPropertyList.h index add2dd6763..40a2a1029f 100644 --- a/Core/Code/DataManagement/mitkPropertyList.h +++ b/Core/Code/DataManagement/mitkPropertyList.h @@ -1,207 +1,212 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D #define PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D #include #include "mitkBaseProperty.h" #include "mitkGenericProperty.h" #include "mitkUIDGenerator.h" #include #include #include namespace mitk { class XMLWriter; /** * @brief Key-value list holding instances of BaseProperty * * This list is meant to hold an arbitrary list of "properties", * which should describe the object associated with this list. * * Usually you will use PropertyList as part of a DataNode * object - in this context the properties describe the data object * held by the DataNode (e.g. whether the object is rendered at * all, which color is used for rendering, what name should be * displayed for the object, etc.) * * The values in the list are not fixed, you may introduce any kind * of property that seems useful - all you have to do is inherit * from BaseProperty. * * The list is organized as a key-value pairs, i.e. * * \li "name" : pointer to a StringProperty * \li "visible" : pointer to a BoolProperty * \li "color" : pointer to a ColorProperty * \li "volume" : pointer to a FloatProperty * * Please see the documentation of SetProperty and ReplaceProperty for two * quite different semantics. Normally SetProperty is what you want - this * method will try to change the value of an existing property and will * not allow you to replace e.g. a ColorProperty with an IntProperty. * * @ingroup DataManagement */ class MITK_CORE_EXPORT PropertyList : public itk::Object { public: - mitkClassMacro(PropertyList, itk::Object); + mitkClassMacro(PropertyList, itk::Object) /** * Method for creation through the object factory. */ - itkNewMacro(Self); + itkNewMacro(Self) + + Pointer Clone() const; /** * Map structure to hold the properties: the map key is a string, * the value consists of the actual property object (BaseProperty). */ typedef std::map< std::string, BaseProperty::Pointer> PropertyMap; typedef std::pair< std::string, BaseProperty::Pointer> PropertyMapElementType; /** * @brief Get a property by its name. */ mitk::BaseProperty* GetProperty(const std::string& propertyKey) const; /** * @brief Set a property in the list/map by value. * * The actual OBJECT holding the value of the property is not replaced, but its value * is modified to match that of @a property. To really replace the object holding the * property - which would make sense if you want to change the type (bool, string) of the property * - call ReplaceProperty. */ void SetProperty(const std::string& propertyKey, BaseProperty* property); /** * @brief Set a property object in the list/map by reference. * * The actual OBJECT holding the value of the property is replaced by this function. * This is useful if you want to change the type of the property, like from BoolProperty to StringProperty. * Another use is to share one and the same property object among several ProperyList/DataNode objects, which * makes them appear synchronized. */ void ReplaceProperty(const std::string& propertyKey, BaseProperty* property); /** * @brief Set a property object in the list/map by reference. */ void ConcatenatePropertyList(PropertyList *pList, bool replace = false); //##Documentation //## @brief Convenience access method for GenericProperty properties //## (T being the type of the second parameter) //## @return @a true property was found template bool GetPropertyValue(const char* propertyKey, T & value) const { GenericProperty* gp= dynamic_cast*>(GetProperty(propertyKey)); if ( gp != NULL ) { value = gp->GetValue(); return true; } return false; } /** * @brief Convenience method to access the value of a BoolProperty */ bool GetBoolProperty(const char* propertyKey, bool& boolValue) const; /** * @brief Convenience method to set the value of a BoolProperty */ void SetBoolProperty( const char* propertyKey, bool boolValue); /** * @brief Convenience method to access the value of an IntProperty */ bool GetIntProperty(const char* propertyKey, int &intValue) const; /** * @brief Convenience method to set the value of an IntProperty */ void SetIntProperty(const char* propertyKey, int intValue); /** * @brief Convenience method to access the value of a FloatProperty */ bool GetFloatProperty(const char* propertyKey, float &floatValue) const; /** * @brief Convenience method to set the value of a FloatProperty */ void SetFloatProperty( const char* propertyKey, float floatValue); /** * @brief Convenience method to access the value of a StringProperty */ bool GetStringProperty(const char* propertyKey, std::string& stringValue) const; /** * @brief Convenience method to set the value of a StringProperty */ void SetStringProperty( const char* propertyKey, const char* stringValue); /** * @brief Get the timestamp of the last change of the map or the last change of one of * the properties store in the list (whichever is later). */ virtual unsigned long GetMTime() const; /** * @brief Remove a property from the list/map. */ bool DeleteProperty(const std::string& propertyKey); const PropertyMap* GetMap() const { return &m_Properties; } bool IsEmpty() const { return m_Properties.empty(); } - virtual Pointer Clone(); - virtual void Clear(); protected: PropertyList(); + PropertyList(const PropertyList& other); virtual ~PropertyList(); /** * @brief Map of properties. */ PropertyMap m_Properties; + private: + + virtual itk::LightObject::Pointer InternalClone() const; + }; } // namespace mitk #endif /* PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D */ diff --git a/Core/Code/DataManagement/mitkRenderingModeProperty.cpp b/Core/Code/DataManagement/mitkRenderingModeProperty.cpp index 6766fedde9..99377a60d0 100644 --- a/Core/Code/DataManagement/mitkRenderingModeProperty.cpp +++ b/Core/Code/DataManagement/mitkRenderingModeProperty.cpp @@ -1,65 +1,77 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkRenderingModeProperty.h" mitk::RenderingModeProperty::RenderingModeProperty( ) { this->AddRenderingModes(); this->SetValue( LEVELWINDOW_COLOR ); } mitk::RenderingModeProperty::RenderingModeProperty( const IdType& value ) { this->AddRenderingModes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ) ; } else MITK_WARN << "Warning: invalid image rendering mode"; } mitk::RenderingModeProperty::RenderingModeProperty( const std::string& value ) { this->AddRenderingModes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ); } else MITK_WARN << "Invalid image rendering mode"; } int mitk::RenderingModeProperty::GetRenderingMode() { return static_cast( this->GetValueAsId() ); } void mitk::RenderingModeProperty::AddRenderingModes() { AddEnum( "LevelWindow_Color", LEVELWINDOW_COLOR ); AddEnum( "LookupTable_LevelWindow_Color", LOOKUPTABLE_LEVELWINDOW_COLOR ); AddEnum( "ColorTransferFunction_LevelWindow_Color", COLORTRANSFERFUNCTION_LEVELWINDOW_COLOR ); AddEnum( "LookupTable_Color", LOOKUPTABLE_COLOR ); AddEnum( "ColorTransferFunction_Color", COLORTRANSFERFUNCTION_COLOR ); } bool mitk::RenderingModeProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } + +mitk::RenderingModeProperty::Pointer mitk::RenderingModeProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::RenderingModeProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkRenderingModeProperty.h b/Core/Code/DataManagement/mitkRenderingModeProperty.h index ac11f0ab16..50f7dda154 100644 --- a/Core/Code/DataManagement/mitkRenderingModeProperty.h +++ b/Core/Code/DataManagement/mitkRenderingModeProperty.h @@ -1,114 +1,117 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_RENDERING_MODE_PROPERTY__H_ #define _MITK_RENDERING_MODE_PROPERTY__H_ #include "mitkEnumerationProperty.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * Encapsulates the enumeration for rendering modes. Valid values are: * \li LEVELWINDOW_COLOR: Level window and color will be applied to the image. * \li LOOKUPTABLE_LEVELWINDOW_COLOR: A lookup table, level window and color will be applied to the image. * \li COLORTRANSFERFUNCTION_LEVELWINDOW_COLOR: A colortransferfunction, level window and color will be applied to the image. * \li LOOKUPTABLE_COLOR: A lookup table and color will be applied to the image. * \li COLORTRANSFERFUNCTION_COLOR: A colortransferfunction and color will be applied to the image. * * The order is given by the names (e.g. LOOKUPTABLE_COLOR applies first a lookup table and next a color). * Currently, there is no GUI (in mitkWorkbench) support for controlling lookup tables or transfer functions. * This has to be done by the programmer. Color and level window are controled by color widget and level window slider. * Currently, the color is always applied. We do not set the color to white, if the user changes the mode. We assume * that users who change the mode know that a previously set color will still be applied (on top of the mode). */ class MITK_CORE_EXPORT RenderingModeProperty : public EnumerationProperty { public: mitkClassMacro( RenderingModeProperty, EnumerationProperty ); itkNewMacro(RenderingModeProperty); mitkNewMacro1Param(RenderingModeProperty, const IdType&); mitkNewMacro1Param(RenderingModeProperty, const std::string&); + Pointer Clone() const; + enum ImageRenderingMode { LEVELWINDOW_COLOR = 0, LOOKUPTABLE_LEVELWINDOW_COLOR = 1, COLORTRANSFERFUNCTION_LEVELWINDOW_COLOR = 2, LOOKUPTABLE_COLOR = 3, COLORTRANSFERFUNCTION_COLOR = 4 // Default = LEVELWINDOW_COLOR; }; /** * Returns the current rendering mode */ virtual int GetRenderingMode(); using BaseProperty::operator=; protected: /** Sets rendering type to default (VTK_RAY_CAST_COMPOSITE_FUNCTION). */ RenderingModeProperty( ); /** * Constructor. Sets rendering type to the given value. */ RenderingModeProperty( const IdType& value ); /** * Constructor. Sets rendering type to the given value. */ RenderingModeProperty( 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 default enumeration types. */ virtual void AddRenderingModes(); private: // purposely not implemented - RenderingModeProperty(const RenderingModeProperty&); RenderingModeProperty& operator=(const RenderingModeProperty&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkResliceMethodProperty.cpp b/Core/Code/DataManagement/mitkResliceMethodProperty.cpp index 6493c044ac..052683cce0 100644 --- a/Core/Code/DataManagement/mitkResliceMethodProperty.cpp +++ b/Core/Code/DataManagement/mitkResliceMethodProperty.cpp @@ -1,46 +1,57 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkResliceMethodProperty.h" mitk::ResliceMethodProperty::ResliceMethodProperty( ) { AddThickSlicesTypes(); SetValue( (IdType)0 ); } mitk::ResliceMethodProperty::ResliceMethodProperty( const IdType& value ) { AddThickSlicesTypes(); if ( IsValidEnumerationValue( value ) ) SetValue( value ); } mitk::ResliceMethodProperty::ResliceMethodProperty( const std::string& value ) { AddThickSlicesTypes(); if ( IsValidEnumerationValue( value ) ) SetValue( value ); } void mitk::ResliceMethodProperty::AddThickSlicesTypes() { AddEnum( "disabled", (IdType) 0 ); AddEnum( "mip", (IdType) 1 ); AddEnum( "sum", (IdType) 2 ); AddEnum( "weighted", (IdType) 3 ); } +mitk::ResliceMethodProperty::Pointer mitk::ResliceMethodProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::ResliceMethodProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkResliceMethodProperty.h b/Core/Code/DataManagement/mitkResliceMethodProperty.h index e711489b78..eb7ea26b78 100644 --- a/Core/Code/DataManagement/mitkResliceMethodProperty.h +++ b/Core/Code/DataManagement/mitkResliceMethodProperty.h @@ -1,67 +1,70 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __MITKRESLICEMETHODENUMPROPERTY_H #define __MITKRESLICEMETHODENUMPROPERTY_H #include "mitkEnumerationProperty.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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&); + Pointer Clone() const; + using BaseProperty::operator=; protected: ResliceMethodProperty( ); ResliceMethodProperty( const IdType& value ); ResliceMethodProperty( const std::string& value ); void AddThickSlicesTypes(); private: // purposely not implemented - ResliceMethodProperty(const ResliceMethodProperty&); ResliceMethodProperty& operator=(const ResliceMethodProperty&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // 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 e1d00c44e3..6e042c910b 100644 --- a/Core/Code/DataManagement/mitkShaderProperty.cpp +++ b/Core/Code/DataManagement/mitkShaderProperty.cpp @@ -1,110 +1,126 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkShaderProperty.h" #include "mitkCoreServices.h" #include "mitkIShaderRepository.h" #include #include mitk::ShaderProperty::ShaderProperty( ) { AddShaderTypes(); SetShader( (IdType)0 ); } +mitk::ShaderProperty::ShaderProperty(const ShaderProperty& other) + : mitk::EnumerationProperty(other) + , shaderList(other.shaderList) +{ +} + 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" ); IShaderRepository* shaderRepo = CoreServices::GetShaderRepository(); if (shaderRepo == NULL) return; std::list l = shaderRepo->GetShaders(); std::list::const_iterator i = l.begin(); while( i != l.end() ) { AddEnum( (*i)->GetName() ); 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; } +mitk::ShaderProperty::Pointer mitk::ShaderProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} +itk::LightObject::Pointer mitk::ShaderProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkShaderProperty.h b/Core/Code/DataManagement/mitkShaderProperty.h index c56fba7d24..eadc0a6874 100644 --- a/Core/Code/DataManagement/mitkShaderProperty.h +++ b/Core/Code/DataManagement/mitkShaderProperty.h @@ -1,115 +1,120 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __MITKSHADERENUMPROPERTY_H #define __MITKSHADERENUMPROPERTY_H #include "mitkEnumerationProperty.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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&); + Pointer Clone() const; + /** * 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); using BaseProperty::operator=; protected: std::list shaderList; /** * Constructor. Sets the representation to a default value of surface(2) */ ShaderProperty( ); + ShaderProperty(const ShaderProperty& other); + /** * \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 itk::LightObject::Pointer InternalClone() const; + virtual bool Assign(const BaseProperty &property); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // 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 d2a8dfb68f..d666cb4667 100644 --- a/Core/Code/DataManagement/mitkSmartPointerProperty.cpp +++ b/Core/Code/DataManagement/mitkSmartPointerProperty.cpp @@ -1,130 +1,148 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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 ); } +mitk::SmartPointerProperty::SmartPointerProperty(const SmartPointerProperty& other) + : BaseProperty(other) + , m_SmartPointer(other.m_SmartPointer) +{ +} + 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"); } + +mitk::SmartPointerProperty::Pointer mitk::SmartPointerProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::SmartPointerProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkSmartPointerProperty.h b/Core/Code/DataManagement/mitkSmartPointerProperty.h index 4ace39ae7f..20ac955bd7 100644 --- a/Core/Code/DataManagement/mitkSmartPointerProperty.h +++ b/Core/Code/DataManagement/mitkSmartPointerProperty.h @@ -1,105 +1,109 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKSMARTPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 #define MITKSMARTPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 #include #include "mitkBaseProperty.h" #include "mitkUIDGenerator.h" #include #include #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif //##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; + Pointer Clone() const; + 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; 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); + SmartPointerProperty(const SmartPointerProperty&); itk::Object::Pointer m_SmartPointer; private: // purposely not implemented - SmartPointerProperty(const SmartPointerProperty&); SmartPointerProperty& operator=(const SmartPointerProperty&); + itk::LightObject::Pointer InternalClone() const; + 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; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif /* MITKSMARTPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 */ diff --git a/Core/Code/DataManagement/mitkStringProperty.cpp b/Core/Code/DataManagement/mitkStringProperty.cpp index c1f12b9c47..d1fea19b12 100644 --- a/Core/Code/DataManagement/mitkStringProperty.cpp +++ b/Core/Code/DataManagement/mitkStringProperty.cpp @@ -1,48 +1,65 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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 ) { +} +mitk::StringProperty::StringProperty(const StringProperty& other) + : BaseProperty(other) + , m_Value(other.m_Value) +{ } bool mitk::StringProperty::IsEqual(const BaseProperty& property ) const { return this->m_Value == static_cast(property).m_Value; } bool mitk::StringProperty::Assign(const BaseProperty& property ) { this->m_Value = static_cast(property).m_Value; return true; } std::string mitk::StringProperty::GetValueAsString() const { return m_Value; } + +mitk::StringProperty::Pointer mitk::StringProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::StringProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkStringProperty.h b/Core/Code/DataManagement/mitkStringProperty.h index 0941014ed1..13586216c1 100644 --- a/Core/Code/DataManagement/mitkStringProperty.h +++ b/Core/Code/DataManagement/mitkStringProperty.h @@ -1,80 +1,85 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKSTRINGPROPERTY_H_HEADER_INCLUDED_C1C02491 #define MITKSTRINGPROPERTY_H_HEADER_INCLUDED_C1C02491 #include #include #include "mitkBaseProperty.h" #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * @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 ); + StringProperty(const StringProperty&); + public: mitkClassMacro(StringProperty, BaseProperty); typedef std::string ValueType; itkNewMacro(StringProperty); mitkNewMacro1Param(StringProperty, const char*); mitkNewMacro1Param(StringProperty, const std::string&) + Pointer Clone() const; + itkGetStringMacro(Value); itkSetStringMacro(Value); virtual std::string GetValueAsString() const; static const char* PATH; using BaseProperty::operator=; private: // purposely not implemented - StringProperty(const StringProperty&); StringProperty& operator=(const StringProperty&); + itk::LightObject::Pointer InternalClone() const; + virtual bool IsEqual(const BaseProperty& property ) const; virtual bool Assign(const BaseProperty& property ); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkTransferFunction.cpp b/Core/Code/DataManagement/mitkTransferFunction.cpp index d125847124..c0d5324523 100644 --- a/Core/Code/DataManagement/mitkTransferFunction.cpp +++ b/Core/Code/DataManagement/mitkTransferFunction.cpp @@ -1,309 +1,338 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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(const TransferFunction& other) + : itk::Object() + , m_ScalarOpacityFunction(other.m_ScalarOpacityFunction.New()) + , m_GradientOpacityFunction(other.m_GradientOpacityFunction.New()) + , m_ColorTransferFunction(other.m_ColorTransferFunction.New()) + , m_Min(other.m_Min) + , m_Max(other.m_Max) + , m_Histogram(other.m_Histogram) + , m_ScalarOpacityPoints(other.m_ScalarOpacityPoints) + , m_GradientOpacityPoints(other.m_GradientOpacityPoints) + , m_RGBPoints(other.m_RGBPoints) +{ + m_ScalarOpacityFunction->DeepCopy(other.m_ScalarOpacityFunction); + m_GradientOpacityFunction->DeepCopy(other.m_GradientOpacityFunction); + m_ColorTransferFunction->DeepCopy(other.m_ColorTransferFunction); +} + 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); } 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; } +mitk::TransferFunction::Pointer mitk::TransferFunction::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::TransferFunction::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} + }// namespace diff --git a/Core/Code/DataManagement/mitkTransferFunction.h b/Core/Code/DataManagement/mitkTransferFunction.h index 7b34a4b385..37b1682809 100644 --- a/Core/Code/DataManagement/mitkTransferFunction.h +++ b/Core/Code/DataManagement/mitkTransferFunction.h @@ -1,195 +1,201 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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); + Pointer Clone() const; + /** \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*); itkSetMacro(ColorTransferFunction,vtkSmartPointer); /** \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(); + TransferFunction(const TransferFunction& other); + + virtual itk::LightObject::Pointer InternalClone() const; + 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 fe7328c2c9..f600f319f5 100644 --- a/Core/Code/DataManagement/mitkTransferFunctionProperty.cpp +++ b/Core/Code/DataManagement/mitkTransferFunctionProperty.cpp @@ -1,49 +1,67 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTransferFunctionProperty.h" namespace mitk { bool TransferFunctionProperty::IsEqual(const BaseProperty& property) const { return *(this->m_Value) == *(static_cast(property).m_Value); } bool TransferFunctionProperty::Assign(const BaseProperty& property) { this->m_Value = static_cast(property).m_Value; return true; } std::string TransferFunctionProperty::GetValueAsString() const { std::stringstream myStr; myStr << GetValue(); return myStr.str(); } TransferFunctionProperty::TransferFunctionProperty() : BaseProperty() {} +TransferFunctionProperty::TransferFunctionProperty(const TransferFunctionProperty& other) + : BaseProperty(other) + , m_Value(other.m_Value->Clone()) +{ +} + TransferFunctionProperty::TransferFunctionProperty( mitk::TransferFunction::Pointer value ) : BaseProperty(), m_Value( value ) {} +TransferFunctionProperty::Pointer TransferFunctionProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer TransferFunctionProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} + } // namespace mitk diff --git a/Core/Code/DataManagement/mitkTransferFunctionProperty.h b/Core/Code/DataManagement/mitkTransferFunctionProperty.h index 59a613942e..982ee6cf63 100644 --- a/Core/Code/DataManagement/mitkTransferFunctionProperty.h +++ b/Core/Code/DataManagement/mitkTransferFunctionProperty.h @@ -1,73 +1,77 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKTRANFERFUNCTIONPROPERTY_H_HEADER_INCLUDED #define MITKTRANFERFUNCTIONPROPERTY_H_HEADER_INCLUDED #include "mitkBaseProperty.h" #include "mitkTransferFunction.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif class MITK_CORE_EXPORT TransferFunctionProperty : public BaseProperty { public: typedef mitk::TransferFunction::Pointer ValueType; mitkClassMacro(TransferFunctionProperty, BaseProperty); itkNewMacro(TransferFunctionProperty); mitkNewMacro1Param(TransferFunctionProperty, mitk::TransferFunction::Pointer); + Pointer Clone() const; + itkSetMacro(Value, mitk::TransferFunction::Pointer ); itkGetConstMacro(Value, mitk::TransferFunction::Pointer ); std::string GetValueAsString() const; using BaseProperty::operator=; protected: mitk::TransferFunction::Pointer m_Value; TransferFunctionProperty(); + TransferFunctionProperty(const TransferFunctionProperty& other); TransferFunctionProperty( mitk::TransferFunction::Pointer value ); private: // purposely not implemented - TransferFunctionProperty(const TransferFunctionProperty&); TransferFunctionProperty& operator=(const TransferFunctionProperty&); + itk::LightObject::Pointer InternalClone() const; + virtual bool IsEqual(const BaseProperty& property) const; virtual bool Assign(const BaseProperty& property); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif /* MITKTRANFERFUNCTIONPROPERTY_H_HEADER_INCLUDED */ diff --git a/Core/Code/DataManagement/mitkVtkInterpolationProperty.cpp b/Core/Code/DataManagement/mitkVtkInterpolationProperty.cpp index 70d23493d2..660a054b6a 100644 --- a/Core/Code/DataManagement/mitkVtkInterpolationProperty.cpp +++ b/Core/Code/DataManagement/mitkVtkInterpolationProperty.cpp @@ -1,91 +1,103 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkVtkInterpolationProperty.h" mitk::VtkInterpolationProperty::VtkInterpolationProperty( ) { AddInterpolationTypes(); SetValue( static_cast( VTK_GOURAUD ) ); } mitk::VtkInterpolationProperty::VtkInterpolationProperty( const IdType& value ) { AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ) ; } else { SetValue( static_cast( VTK_GOURAUD ) ); } } mitk::VtkInterpolationProperty::VtkInterpolationProperty( const std::string& value ) { AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( static_cast( VTK_GOURAUD ) ); } } int mitk::VtkInterpolationProperty::GetVtkInterpolation() { return static_cast( GetValueAsId() ); } void mitk::VtkInterpolationProperty::SetInterpolationToFlat() { SetValue( static_cast( VTK_FLAT ) ); } void mitk::VtkInterpolationProperty::SetInterpolationToGouraud() { SetValue( static_cast( VTK_GOURAUD ) ); } void mitk::VtkInterpolationProperty::SetInterpolationToPhong() { SetValue( static_cast( VTK_PHONG ) ); } void mitk::VtkInterpolationProperty::AddInterpolationTypes() { AddEnum( "Flat", static_cast( VTK_FLAT ) ); AddEnum( "Gouraud", static_cast( VTK_GOURAUD ) ); AddEnum( "Phong", static_cast( VTK_PHONG ) ); } bool mitk::VtkInterpolationProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } + +mitk::VtkInterpolationProperty::Pointer mitk::VtkInterpolationProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::VtkInterpolationProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkVtkInterpolationProperty.h b/Core/Code/DataManagement/mitkVtkInterpolationProperty.h index a474fff29e..acd1d0db44 100644 --- a/Core/Code/DataManagement/mitkVtkInterpolationProperty.h +++ b/Core/Code/DataManagement/mitkVtkInterpolationProperty.h @@ -1,119 +1,122 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_VTK_INTERPOLATION_PROPERTY__H_ #define _MITK_VTK_INTERPOLATION_PROPERTY__H_ #include "mitkEnumerationProperty.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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&); + Pointer Clone() const; + /** * 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&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkVtkRepresentationProperty.cpp b/Core/Code/DataManagement/mitkVtkRepresentationProperty.cpp index 038bdc943a..637a5d00c3 100644 --- a/Core/Code/DataManagement/mitkVtkRepresentationProperty.cpp +++ b/Core/Code/DataManagement/mitkVtkRepresentationProperty.cpp @@ -1,90 +1,102 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkVtkRepresentationProperty.h" mitk::VtkRepresentationProperty::VtkRepresentationProperty( ) { AddRepresentationTypes(); SetValue( static_cast( VTK_SURFACE ) ); } mitk::VtkRepresentationProperty::VtkRepresentationProperty( const IdType& value ) { AddRepresentationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( static_cast( VTK_SURFACE ) ); } } mitk::VtkRepresentationProperty::VtkRepresentationProperty( const std::string& value ) { AddRepresentationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( static_cast( VTK_SURFACE ) ); } } int mitk::VtkRepresentationProperty::GetVtkRepresentation() { return static_cast( GetValueAsId() ); } void mitk::VtkRepresentationProperty::SetRepresentationToPoints() { SetValue( static_cast( VTK_POINTS ) ); } void mitk::VtkRepresentationProperty::SetRepresentationToWireframe() { SetValue( static_cast( VTK_WIREFRAME ) ); } void mitk::VtkRepresentationProperty::SetRepresentationToSurface() { SetValue( static_cast( VTK_SURFACE ) ); } void mitk::VtkRepresentationProperty::AddRepresentationTypes() { AddEnum( "Points", static_cast( VTK_POINTS ) ); AddEnum( "Wireframe", static_cast( VTK_WIREFRAME ) ); AddEnum( "Surface", static_cast( VTK_SURFACE ) ); } bool mitk::VtkRepresentationProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } + +mitk::VtkRepresentationProperty::Pointer mitk::VtkRepresentationProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::VtkRepresentationProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkVtkRepresentationProperty.h b/Core/Code/DataManagement/mitkVtkRepresentationProperty.h index 08e835d0f4..9b5ef1fda6 100644 --- a/Core/Code/DataManagement/mitkVtkRepresentationProperty.h +++ b/Core/Code/DataManagement/mitkVtkRepresentationProperty.h @@ -1,118 +1,121 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_VTK_REPRESENTATION_PROPERTY__H_ #define _MITK_VTK_REPRESENTATION_PROPERTY__H_ #include "mitkEnumerationProperty.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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&); + Pointer Clone() const; + /** * 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(); 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&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.cpp b/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.cpp index 36aa9d2bcb..d13b914500 100644 --- a/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.cpp +++ b/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.cpp @@ -1,91 +1,103 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkVtkResliceInterpolationProperty.h" mitk::VtkResliceInterpolationProperty::VtkResliceInterpolationProperty( ) { this->AddInterpolationTypes(); this->SetValue( static_cast( VTK_RESLICE_NEAREST ) ); } mitk::VtkResliceInterpolationProperty::VtkResliceInterpolationProperty( const IdType& value ) { this->AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ) ; } else { this->SetValue( static_cast( VTK_RESLICE_NEAREST ) ); } } mitk::VtkResliceInterpolationProperty::VtkResliceInterpolationProperty( const std::string& value ) { this->AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ); } else { this->SetValue( static_cast( VTK_RESLICE_NEAREST ) ); } } int mitk::VtkResliceInterpolationProperty::GetInterpolation() { return static_cast( this->GetValueAsId() ); } void mitk::VtkResliceInterpolationProperty::SetInterpolationToNearest() { this->SetValue( static_cast( VTK_RESLICE_NEAREST ) ); } void mitk::VtkResliceInterpolationProperty::SetInterpolationToLinear() { this->SetValue( static_cast( VTK_RESLICE_LINEAR ) ); } void mitk::VtkResliceInterpolationProperty::SetInterpolationToCubic() { this->SetValue( static_cast( VTK_RESLICE_CUBIC ) ); } void mitk::VtkResliceInterpolationProperty::AddInterpolationTypes() { AddEnum( "Nearest", static_cast( VTK_RESLICE_NEAREST ) ); AddEnum( "Linear", static_cast( VTK_RESLICE_LINEAR ) ); AddEnum( "Cubic", static_cast( VTK_RESLICE_CUBIC ) ); } bool mitk::VtkResliceInterpolationProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } + +mitk::VtkResliceInterpolationProperty::Pointer mitk::VtkResliceInterpolationProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::VtkResliceInterpolationProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.h b/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.h index d11003fdff..7f6b678653 100644 --- a/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.h +++ b/Core/Code/DataManagement/mitkVtkResliceInterpolationProperty.h @@ -1,115 +1,118 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_VTK_RESLICE_INTERPOLATION_PROPERTY__H_ #define _MITK_VTK_RESLICE_INTERPOLATION_PROPERTY__H_ #include "mitkEnumerationProperty.h" #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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&); + Pointer Clone() const; + /** * 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&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkVtkScalarModeProperty.cpp b/Core/Code/DataManagement/mitkVtkScalarModeProperty.cpp index 5842164d42..8fe199efc5 100644 --- a/Core/Code/DataManagement/mitkVtkScalarModeProperty.cpp +++ b/Core/Code/DataManagement/mitkVtkScalarModeProperty.cpp @@ -1,94 +1,106 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkVtkScalarModeProperty.h" mitk::VtkScalarModeProperty::VtkScalarModeProperty( ) { AddInterpolationTypes(); SetScalarModeToDefault(); } mitk::VtkScalarModeProperty::VtkScalarModeProperty( const IdType& value ) { AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ) ; } else { SetScalarModeToDefault(); } } mitk::VtkScalarModeProperty::VtkScalarModeProperty( const std::string& value ) { AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetScalarModeToDefault(); } } int mitk::VtkScalarModeProperty::GetVtkScalarMode() { return static_cast( GetValueAsId() ); } void mitk::VtkScalarModeProperty::SetScalarModeToDefault() { SetValue( static_cast( VTK_SCALAR_MODE_DEFAULT ) ); } void mitk::VtkScalarModeProperty::SetScalarModeToPointData() { SetValue( static_cast( VTK_SCALAR_MODE_USE_POINT_DATA ) ); } void mitk::VtkScalarModeProperty::SetScalarModeToCellData() { SetValue( static_cast( VTK_SCALAR_MODE_USE_CELL_DATA ) ); } void mitk::VtkScalarModeProperty::SetScalarModeToPointFieldData() { SetValue( static_cast( VTK_SCALAR_MODE_USE_POINT_FIELD_DATA ) ); } void mitk::VtkScalarModeProperty::SetScalarModeToCellFieldData() { SetValue( static_cast( VTK_SCALAR_MODE_USE_CELL_FIELD_DATA ) ); } void mitk::VtkScalarModeProperty::AddInterpolationTypes() { AddEnum( "Default", static_cast( VTK_SCALAR_MODE_DEFAULT ) ); AddEnum( "PointData", static_cast( VTK_SCALAR_MODE_USE_POINT_DATA ) ); AddEnum( "CellData", static_cast( VTK_SCALAR_MODE_USE_CELL_DATA ) ); AddEnum( "PointFieldData", static_cast( VTK_SCALAR_MODE_USE_POINT_FIELD_DATA ) ); AddEnum( "CellFieldData", static_cast( VTK_SCALAR_MODE_USE_CELL_FIELD_DATA ) ); } bool mitk::VtkScalarModeProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } + +mitk::VtkScalarModeProperty::Pointer mitk::VtkScalarModeProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::VtkScalarModeProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkVtkScalarModeProperty.h b/Core/Code/DataManagement/mitkVtkScalarModeProperty.h index 54b3a570d7..983eda1082 100644 --- a/Core/Code/DataManagement/mitkVtkScalarModeProperty.h +++ b/Core/Code/DataManagement/mitkVtkScalarModeProperty.h @@ -1,117 +1,120 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_VTK_SCALARMODE_PROPERTY__H_ #define _MITK_VTK_SCALARMODE_PROPERTY__H_ #include "mitkEnumerationProperty.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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&); + Pointer Clone() const; + /** * 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&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // end of namespace mitk #endif //_MITK_VTK_SCALARMODE_PROPERTY__H_ diff --git a/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.cpp b/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.cpp index fc2e1abeb2..2abfcf8d6b 100644 --- a/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.cpp +++ b/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.cpp @@ -1,78 +1,90 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkVtkVolumeRenderingProperty.h" mitk::VtkVolumeRenderingProperty::VtkVolumeRenderingProperty( ) { this->AddRenderingTypes(); this->SetValue( static_cast( VTK_RAY_CAST_COMPOSITE_FUNCTION ) ); } mitk::VtkVolumeRenderingProperty::VtkVolumeRenderingProperty( const IdType& value ) { this->AddRenderingTypes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ) ; } else MITK_INFO << "Warning: invalid rendering configuration" << std::endl; } mitk::VtkVolumeRenderingProperty::VtkVolumeRenderingProperty( const std::string& value ) { this->AddRenderingTypes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ); } else MITK_INFO << "Warning: invalid rendering configuration" << std::endl; } int mitk::VtkVolumeRenderingProperty::GetRenderingType() { return static_cast( this->GetValueAsId() ); } void mitk::VtkVolumeRenderingProperty::SetRenderingTypeToMIP() { this->SetValue( static_cast( VTK_VOLUME_RAY_CAST_MIP_FUNCTION ) ); } void mitk::VtkVolumeRenderingProperty::SetRenderingTypeToComposite() { this->SetValue( static_cast( VTK_RAY_CAST_COMPOSITE_FUNCTION ) ); } void mitk::VtkVolumeRenderingProperty::AddRenderingTypes() { AddEnum( "MIP", static_cast( VTK_VOLUME_RAY_CAST_MIP_FUNCTION ) ); AddEnum( "COMPOSITE", static_cast (VTK_RAY_CAST_COMPOSITE_FUNCTION)); } bool mitk::VtkVolumeRenderingProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } + +mitk::VtkVolumeRenderingProperty::Pointer mitk::VtkVolumeRenderingProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::VtkVolumeRenderingProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.h b/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.h index 4afb9ec1e1..debf2787d6 100644 --- a/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.h +++ b/Core/Code/DataManagement/mitkVtkVolumeRenderingProperty.h @@ -1,111 +1,114 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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 { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** * 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&); + Pointer Clone() const; + /** * 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&); + + itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // end of namespace mitk #endif diff --git a/Core/Code/DataManagement/mitkWeakPointerProperty.cpp b/Core/Code/DataManagement/mitkWeakPointerProperty.cpp index 77b487ccd4..d505bb129e 100644 --- a/Core/Code/DataManagement/mitkWeakPointerProperty.cpp +++ b/Core/Code/DataManagement/mitkWeakPointerProperty.cpp @@ -1,68 +1,86 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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) { } +mitk::WeakPointerProperty::WeakPointerProperty(const WeakPointerProperty& other) + : mitk::BaseProperty(other) + , m_WeakPointer(other.m_WeakPointer) +{ +} + mitk::WeakPointerProperty::~WeakPointerProperty() { } std::string mitk::WeakPointerProperty::GetValueAsString() const { std::stringstream ss; ss << m_WeakPointer.GetPointer(); return ss.str(); } 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()); } + +mitk::WeakPointerProperty::Pointer mitk::WeakPointerProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::WeakPointerProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/DataManagement/mitkWeakPointerProperty.h b/Core/Code/DataManagement/mitkWeakPointerProperty.h index c06e66e393..1b5e222800 100644 --- a/Core/Code/DataManagement/mitkWeakPointerProperty.h +++ b/Core/Code/DataManagement/mitkWeakPointerProperty.h @@ -1,80 +1,85 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKWEAKPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 #define MITKWEAKPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 #include #include "mitkBaseProperty.h" #include "itkWeakPointer.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif //##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*); + Pointer Clone() const; + virtual ~WeakPointerProperty(); 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(const WeakPointerProperty&); + WeakPointerProperty(itk::Object* pointer = 0); private: // purposely not implemented - WeakPointerProperty(const WeakPointerProperty&); WeakPointerProperty& operator=(const WeakPointerProperty&); + itk::LightObject::Pointer InternalClone() const; + virtual bool IsEqual(const BaseProperty& property) const; virtual bool Assign(const BaseProperty& property); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif /* MITKWEAKPOINTERPROPERTY_H_HEADER_INCLUDED_C126B791 */ diff --git a/Core/Code/IO/mitkLookupTableProperty.cpp b/Core/Code/IO/mitkLookupTableProperty.cpp index 12da81ee75..e3dbd846c8 100755 --- a/Core/Code/IO/mitkLookupTableProperty.cpp +++ b/Core/Code/IO/mitkLookupTableProperty.cpp @@ -1,68 +1,86 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkLookupTableProperty.h" mitk::LookupTableProperty::LookupTableProperty() { } +mitk::LookupTableProperty::LookupTableProperty(const LookupTableProperty& other) + : mitk::BaseProperty(other) + , m_LookupTable(other.m_LookupTable) +{ +} + mitk::LookupTableProperty::LookupTableProperty(const mitk::LookupTable::Pointer lut) { this->SetLookupTable(lut); } bool mitk::LookupTableProperty::IsEqual(const BaseProperty& property) const { return *(this->m_LookupTable) == *(static_cast(property).m_LookupTable); } bool mitk::LookupTableProperty::Assign(const BaseProperty& property) { this->m_LookupTable = static_cast(property).m_LookupTable; return true; } std::string mitk::LookupTableProperty::GetValueAsString() const { 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); } + +mitk::LookupTableProperty::Pointer mitk::LookupTableProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::LookupTableProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Core/Code/IO/mitkLookupTableProperty.h b/Core/Code/IO/mitkLookupTableProperty.h index 5301c19240..73ed35ac0f 100755 --- a/Core/Code/IO/mitkLookupTableProperty.h +++ b/Core/Code/IO/mitkLookupTableProperty.h @@ -1,84 +1,89 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKLookupTablePROPERTY_H_HEADER_INCLUDED_C10EEAA8 #define MITKLookupTablePROPERTY_H_HEADER_INCLUDED_C10EEAA8 #include #include "mitkBaseProperty.h" #include "mitkLookupTable.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif //##Documentation //## @brief Property for LookupTable data //## //## @ingroup DataManagement class MITK_CORE_EXPORT LookupTableProperty : public BaseProperty { protected: LookupTable::Pointer m_LookupTable; LookupTableProperty(); + LookupTableProperty(const LookupTableProperty&); + LookupTableProperty(const mitk::LookupTable::Pointer lut); public: typedef LookupTable::Pointer ValueType; mitkClassMacro(LookupTableProperty, BaseProperty); itkNewMacro(LookupTableProperty); mitkNewMacro1Param(LookupTableProperty, const mitk::LookupTable::Pointer); + Pointer Clone() const; + 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&); + itk::LightObject::Pointer InternalClone() const; + virtual bool IsEqual(const BaseProperty& property) const; virtual bool Assign(const BaseProperty& property); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif /* MITKLookupTablePROPERTY_H_HEADER_INCLUDED_C10EEAA8 */ diff --git a/Core/Code/Testing/mitkPropertyTest.cpp b/Core/Code/Testing/mitkPropertyTest.cpp index d72da3c11a..409dfc78e2 100644 --- a/Core/Code/Testing/mitkPropertyTest.cpp +++ b/Core/Code/Testing/mitkPropertyTest.cpp @@ -1,375 +1,385 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #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 TestPropCloning(T prop) +{ + T prop2 = prop->Clone(); + MITK_TEST_CONDITION_REQUIRED(prop.GetPointer() != prop2.GetPointer(), "Test clone pointer") + MITK_TEST_CONDITION_REQUIRED(*prop == *prop2, "Test equality of the clone") +} + 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); + TestPropCloning(prop); + 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.1f, 2.34f, "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(); lut1->GetVtkLookupTable()->SetTableValue(0, 0.2, 0.3, 0.4); mitk::LookupTable::Pointer lut2 = mitk::LookupTable::New(); lut2->GetVtkLookupTable()->SetTableValue(0, 0.2, 0.4, 0.4); 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/CameraCalibration/mitkCameraIntrinsics.cpp b/Modules/CameraCalibration/mitkCameraIntrinsics.cpp index ea4a8491d8..895fc24211 100644 --- a/Modules/CameraCalibration/mitkCameraIntrinsics.cpp +++ b/Modules/CameraCalibration/mitkCameraIntrinsics.cpp @@ -1,503 +1,514 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkCameraIntrinsics.h" #include #include #include mitk::CameraIntrinsics::CameraIntrinsics() : m_Valid(false), m_Mutex(itk::FastMutexLock::New()) { m_CameraMatrix = cv::Mat::zeros(3, 3, cv::DataType::type); m_CameraMatrix.at(2,2) = 1.0; m_DistorsionCoeffs = cv::Mat::zeros(1, 5, cv::DataType::type); } +mitk::CameraIntrinsics::CameraIntrinsics(const CameraIntrinsics& other) + : itk::Object() + , mitk::XMLSerializable() +{ + this->Copy(&other); +} + mitk::CameraIntrinsics::~CameraIntrinsics() { } bool mitk::CameraIntrinsics::Equals( const CameraIntrinsics* other ) const { return other->GetDistorsionCoeffsAsPoint4D()== this->GetDistorsionCoeffsAsPoint4D() && other->GetFocalPoint()== this->GetFocalPoint() && other->GetPrincipalPoint() == this->GetPrincipalPoint(); } void mitk::CameraIntrinsics::Copy(const CameraIntrinsics* other) { this->SetIntrinsics( other->GetCameraMatrix().clone() , other->GetDistorsionCoeffs().clone() ); this->SetValid(other->m_Valid); } bool mitk::CameraIntrinsics::IsValid() const { itk::MutexLockHolder lock(*m_Mutex); return m_Valid; } -mitk::CameraIntrinsics::Pointer mitk::CameraIntrinsics::Clone() const -{ - mitk::CameraIntrinsics::Pointer copy = mitk::CameraIntrinsics::New(); - copy->SetIntrinsics( this->GetCameraMatrix(), this->GetDistorsionCoeffs() ); - copy->SetValid(this->IsValid()); - return copy; -} - vnl_matrix_fixed mitk::CameraIntrinsics::GetVnlCameraMatrix() const { vnl_matrix_fixed mat; mat.set_identity(); { itk::MutexLockHolder lock(*m_Mutex); mat(0,0) = m_CameraMatrix.at(0,0); mat(1,1) = m_CameraMatrix.at(1,1); mat(0,2) = m_CameraMatrix.at(0,2); mat(1,2) = m_CameraMatrix.at(1,2); } return mat; } void mitk::CameraIntrinsics::SetCameraMatrix( const vnl_matrix_fixed& _CameraMatrix ) { itk::MutexLockHolder lock(*m_Mutex); m_CameraMatrix.at(0,0) = _CameraMatrix(0,0); m_CameraMatrix.at(1,1) = _CameraMatrix(1,1); m_CameraMatrix.at(0,2) = _CameraMatrix(0,2); m_CameraMatrix.at(1,2) = _CameraMatrix(1,2); } vnl_matrix_fixed mitk::CameraIntrinsics::GetVnlCameraMatrix3x4() const { vnl_matrix_fixed mat; mat.fill(0); mat.update( this->GetVnlCameraMatrix().as_matrix() ); return mat; } void mitk::CameraIntrinsics::SetIntrinsics( const cv::Mat& _CameraMatrix , const cv::Mat& _DistorsionCoeffs) { { itk::MutexLockHolder lock(*m_Mutex); if( _CameraMatrix.cols != 3 || _CameraMatrix.rows != 3) throw std::invalid_argument("Wrong format of camera matrix. Should be 3x3" " double."); endoAssertMsg( (_DistorsionCoeffs.cols == 5) && _DistorsionCoeffs.rows == 1, "Wrong format of distorsion coefficients" " vector. Should be 5x1 double."); m_CameraMatrix = _CameraMatrix.clone(); m_DistorsionCoeffs = _DistorsionCoeffs.clone(); m_Valid = true; } this->Modified(); } void mitk::CameraIntrinsics::SetIntrinsics( const mitk::Point3D& focalPoint, const mitk::Point3D& principalPoint, const mitk::Point4D& distortionCoefficients) { { itk::MutexLockHolder lock(*m_Mutex); m_CameraMatrix.at(0,0) = focalPoint[0]; m_CameraMatrix.at(1,1) = focalPoint[1]; m_CameraMatrix.at(0,2) = principalPoint[0]; m_CameraMatrix.at(1,2) = principalPoint[1]; m_DistorsionCoeffs.at(0,0) = distortionCoefficients[0]; m_DistorsionCoeffs.at(0,1) = distortionCoefficients[1]; m_DistorsionCoeffs.at(0,2) = distortionCoefficients[2]; m_DistorsionCoeffs.at(0,3) = distortionCoefficients[3]; } this->Modified(); } void mitk::CameraIntrinsics::SetFocalLength( double x, double y ) { { itk::MutexLockHolder lock(*m_Mutex); m_CameraMatrix.at(0,0) = x; m_CameraMatrix.at(1,1) = y; } this->Modified(); } void mitk::CameraIntrinsics::SetPrincipalPoint( double x, double y ) { { itk::MutexLockHolder lock(*m_Mutex); m_CameraMatrix.at(0,2) = x; m_CameraMatrix.at(1,2) = y; } this->Modified(); } void mitk::CameraIntrinsics::SetDistorsionCoeffs( double k1, double k2, double p1, double p2 ) { { itk::MutexLockHolder lock(*m_Mutex); m_DistorsionCoeffs.at(0,0) = k1; m_DistorsionCoeffs.at(0,1) = k2; m_DistorsionCoeffs.at(0,2) = p1; m_DistorsionCoeffs.at(0,3) = p2; } this->Modified(); } cv::Mat mitk::CameraIntrinsics::GetCameraMatrix() const { itk::MutexLockHolder lock(*m_Mutex); return m_CameraMatrix.clone(); // return a copy of this small matrix } cv::Mat mitk::CameraIntrinsics::GetDistorsionCoeffs() const { itk::MutexLockHolder lock(*m_Mutex); return m_DistorsionCoeffs.clone(); // return a copy of this small matrix } cv::Mat mitk::CameraIntrinsics::GetDistorsionCoeffs() { const CameraIntrinsics* intrinsics = this; return intrinsics->GetDistorsionCoeffs(); } std::string mitk::CameraIntrinsics::ToString() const { itk::MutexLockHolder lock(*m_Mutex); std::ostringstream s; s.precision(12); const cv::Mat& CameraMatrix = m_CameraMatrix; const cv::Mat& DistorsionCoeffs = m_DistorsionCoeffs; s.str(""); s << this->GetNameOfClass() << ": "; s << "fx = " << CameraMatrix.at(0,0); s << ", fy = " << CameraMatrix.at(1,1); s << ", cx = " << CameraMatrix.at(0,2); s << ", cy = " << CameraMatrix.at(1,2); s << ", k1 = " << DistorsionCoeffs.at(0,0); s << ", k2 = " << DistorsionCoeffs.at(0,1); s << ", p1 = " << DistorsionCoeffs.at(0,2); s << ", p2 = " << DistorsionCoeffs.at(0,3); //s << ", k3 = " << DistorsionCoeffs.at(0,4); return s.str(); } void mitk::CameraIntrinsics::ToXML(TiXmlElement* elem) const { itk::MutexLockHolder lock(*m_Mutex); elem->SetValue(this->GetNameOfClass()); std::ostringstream s; s.precision(12); const cv::Mat& CameraMatrix = m_CameraMatrix; s.str(""); s << CameraMatrix.at(0,0); elem->SetAttribute( "fx", s.str() ); s.str(""); s << CameraMatrix.at(1,1); elem->SetAttribute( "fy", s.str() ); s.str(""); s << CameraMatrix.at(0,2); elem->SetAttribute( "cx", s.str() ); s.str(""); s << CameraMatrix.at(1,2); elem->SetAttribute( "cy", s.str() ); const cv::Mat& DistorsionCoeffs = m_DistorsionCoeffs; s.str(""); s << DistorsionCoeffs.at(0,0); elem->SetAttribute( "k1", s.str() ); s.str(""); s << DistorsionCoeffs.at(0,1); elem->SetAttribute( "k2", s.str() ); s.str(""); s << DistorsionCoeffs.at(0,2); elem->SetAttribute( "p1", s.str() ); s.str(""); s << DistorsionCoeffs.at(0,3); elem->SetAttribute( "p2", s.str() ); elem->SetAttribute("Valid", m_Valid); //s.str(""); s << DistorsionCoeffs.at(4,0); //elem->SetAttribute( "k3", s.str() ); } void mitk::CameraIntrinsics::FromGMLCalibrationXML(TiXmlElement* elem) { assert( elem ); assert( elem->ValueStr() == "results" ); cv::Mat CameraMatrix = cv::Mat::zeros(3, 3, cv::DataType::type); CameraMatrix.at(2,2) = 1.0; cv::Mat DistorsionCoeffs = cv::Mat::zeros(1, 5, cv::DataType::type); TiXmlElement* focus_lenXElem = elem->FirstChildElement("focus_lenX"); endoAssert( focus_lenXElem != 0 ); CameraMatrix.at(0,0) = atof( focus_lenXElem->GetText() ); TiXmlElement* focus_lenYElem = elem->FirstChildElement("focus_lenY"); endoAssert( focus_lenYElem != 0 ); CameraMatrix.at(1,1) = atof( focus_lenYElem->GetText() ); TiXmlElement* PrincipalXElem = elem->FirstChildElement("PrincipalX"); endoAssert( PrincipalXElem != 0 ); CameraMatrix.at(0,2) = atof( PrincipalXElem->GetText() ); TiXmlElement* PrincipalYElem = elem->FirstChildElement("PrincipalY"); endoAssert( PrincipalYElem != 0 ); CameraMatrix.at(1,2) = atof( PrincipalYElem->GetText() ); // DISTORSION COEFFS TiXmlElement* Dist1Elem = elem->FirstChildElement("Dist1"); endoAssert( Dist1Elem != 0 ); DistorsionCoeffs.at(0,0) = atof( Dist1Elem->GetText() ); TiXmlElement* Dist2Elem = elem->FirstChildElement("Dist2"); endoAssert( Dist2Elem != 0 ); DistorsionCoeffs.at(0,1) = atof( Dist2Elem->GetText() ); TiXmlElement* Dist3Elem = elem->FirstChildElement("Dist3"); endoAssert( Dist3Elem != 0 ); DistorsionCoeffs.at(0,2) = atof( Dist3Elem->GetText() ); TiXmlElement* Dist4Elem = elem->FirstChildElement("Dist4"); endoAssert( Dist4Elem != 0 ); DistorsionCoeffs.at(0,3) = atof( Dist4Elem->GetText() ); int valid = 0; elem->QueryIntAttribute("Valid", &valid); { itk::MutexLockHolder lock(*m_Mutex); m_Valid = static_cast(valid); m_CameraMatrix = CameraMatrix; m_DistorsionCoeffs = DistorsionCoeffs; } this->Modified(); } void mitk::CameraIntrinsics::FromXML(TiXmlElement* elem) { endoAssert ( elem ); MITK_DEBUG << elem->Value(); std::string filename; if(elem->QueryStringAttribute("file", &filename) == TIXML_SUCCESS) { this->FromXMLFile(filename); return; } else if(strcmp(elem->Value(), "CalibrationProject") == 0) { this->FromGMLCalibrationXML(elem->FirstChildElement("results")); return; } assert ( elem ); if(strcmp(elem->Value(), this->GetNameOfClass()) != 0) elem = elem->FirstChildElement(this->GetNameOfClass()); std::ostringstream err; // CAMERA MATRIX cv::Mat CameraMatrix = cv::Mat::zeros(3, 3, cv::DataType::type); CameraMatrix.at(2,2) = 1.0; float val = 0.0f; if(elem->QueryFloatAttribute("fx", &val) == TIXML_SUCCESS) CameraMatrix.at(0,0) = val; else err << "fx, "; if(elem->QueryFloatAttribute("fy", &val) == TIXML_SUCCESS) CameraMatrix.at(1,1) = val; else err << "fy, "; if(elem->QueryFloatAttribute("cx", &val) == TIXML_SUCCESS) CameraMatrix.at(0,2) = val; else err << "cx, "; if(elem->QueryFloatAttribute("cy", &val) == TIXML_SUCCESS) CameraMatrix.at(1,2) = val; else err << "cy, "; // DISTORSION COEFFS endodebug( "creating DistorsionCoeffs from XML file") cv::Mat DistorsionCoeffs = cv::Mat::zeros(1, 5, cv::DataType::type); if(elem->QueryFloatAttribute("k1", &val) == TIXML_SUCCESS) DistorsionCoeffs.at(0,0) = val; else err << "k1, "; if(elem->QueryFloatAttribute("k2", &val) == TIXML_SUCCESS) DistorsionCoeffs.at(0,1) = val; else err << "k2, "; if(elem->QueryFloatAttribute("p1", &val) == TIXML_SUCCESS) DistorsionCoeffs.at(0,2) = val; else err << "p1, "; if(elem->QueryFloatAttribute("p2", &val) == TIXML_SUCCESS) DistorsionCoeffs.at(0,3) = val; else err << "p2, "; DistorsionCoeffs.at(0,4) = 0.0; /*if(elem->QueryFloatAttribute("k3", &val) == TIXML_SUCCESS) DistorsionCoeffs.at(4,0) = val; else err << "k3, ";*/ std::string errorStr = err.str(); int errLength = errorStr.length(); if(errLength > 0) { errorStr = errorStr.substr(0, errLength-2); errorStr.append(" not found"); throw std::invalid_argument(err.str()); } int valid = 0; elem->QueryIntAttribute("Valid", &valid); { itk::MutexLockHolder lock(*m_Mutex); m_Valid = static_cast(valid); m_CameraMatrix = CameraMatrix; m_DistorsionCoeffs = DistorsionCoeffs; } this->Modified(); } double mitk::CameraIntrinsics::GetFocalLengthX() const { itk::MutexLockHolder lock(*m_Mutex); double FocalLengthX = m_CameraMatrix.at(0,0); return FocalLengthX; } double mitk::CameraIntrinsics::GetFocalLengthY() const { itk::MutexLockHolder lock(*m_Mutex); double FocalLengthY = m_CameraMatrix.at(1,1);; return FocalLengthY; } double mitk::CameraIntrinsics::GetPrincipalPointX() const { itk::MutexLockHolder lock(*m_Mutex); double PrincipalPointX = m_CameraMatrix.at(0,2); return PrincipalPointX; } double mitk::CameraIntrinsics::GetPrincipalPointY() const { itk::MutexLockHolder lock(*m_Mutex); double PrincipalPointY = m_CameraMatrix.at(1,2); return PrincipalPointY; } mitk::Point4D mitk::CameraIntrinsics::GetDistorsionCoeffsAsPoint4D() const { itk::MutexLockHolder lock(*m_Mutex); mitk::Point4D coeffs; coeffs[0] = m_DistorsionCoeffs.at(0,0); coeffs[1] = m_DistorsionCoeffs.at(0,1); coeffs[2] = m_DistorsionCoeffs.at(0,2); coeffs[3] = m_DistorsionCoeffs.at(0,3); return coeffs; } mitk::Point3D mitk::CameraIntrinsics::GetFocalPoint() const { mitk::Point3D p; p[0] = this->GetFocalLengthX(); p[1] = this->GetFocalLengthY(); p[2] = 0; return p; } mitk::Point3D mitk::CameraIntrinsics::GetPrincipalPoint() const { mitk::Point3D p; p[0] = this->GetPrincipalPointX(); p[1] = this->GetPrincipalPointY(); p[2] = 0; return p; } vnl_vector_fixed mitk::CameraIntrinsics::GetFocalPointAsVnlVector() const { vnl_vector_fixed vec; vec[0] = this->GetFocalLengthX(); vec[1] = this->GetFocalLengthY(); return vec; } vnl_vector_fixed mitk::CameraIntrinsics::GetPrincipalPointAsVnlVector() const { vnl_vector_fixed vec; vec[0] = this->GetPrincipalPointX(); vec[1] = this->GetPrincipalPointY(); return vec; } std::ostream& operator<< (std::ostream& os, mitk::CameraIntrinsics::Pointer p) { os << p->ToString(); return os; } std::string mitk::CameraIntrinsics::GetString() { return this->ToString(); } std::string mitk::CameraIntrinsics::ToOctaveString( const std::string& varName) { std::ostringstream s; s << varName << " = [" << this->GetFocalLengthX() << " 0 " << this->GetPrincipalPointX() << "; 0 " << this->GetFocalLengthY() << " " << this->GetPrincipalPointY() << ";" << " 0 0 1 ];"; return s.str(); } void mitk::CameraIntrinsics::SetValid( bool valid ) { itk::MutexLockHolder lock(*m_Mutex); m_Valid = valid; } + +mitk::CameraIntrinsics::Pointer mitk::CameraIntrinsics::Clone() const +{ + Pointer result = dynamic_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::CameraIntrinsics::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Modules/CameraCalibration/mitkCameraIntrinsics.h b/Modules/CameraCalibration/mitkCameraIntrinsics.h index 83b59b442d..4c6e3acc5a 100644 --- a/Modules/CameraCalibration/mitkCameraIntrinsics.h +++ b/Modules/CameraCalibration/mitkCameraIntrinsics.h @@ -1,138 +1,144 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkCameraIntrinsics_h #define mitkCameraIntrinsics_h #include #include #include #include #include #include #include "mitkXMLSerializable.h" #include int mitkCameraIntrinsicsTest(int argc, char* argv[]); namespace mitk { /// /// \brief class representing camera intrinsics and related functions /// class mitkCameraCalibration_EXPORT CameraIntrinsics: virtual public itk::Object, virtual public mitk::XMLSerializable { public: /// /// for testing purposes /// friend int mitkCameraIntrinsicsTest(int argc, char* argv[]); /// /// smartpointer typedefs /// mitkClassMacro(CameraIntrinsics, itk::Object); /// /// the static new function /// itkFactorylessNewMacro(Self); /// /// make a clone of this intrinsics /// Pointer Clone() const; /// /// copy information from other to this /// void Copy(const CameraIntrinsics* other); /// /// checks two intrinsics for equality /// bool Equals( const CameraIntrinsics* other ) const; /// /// \return the intrinsic parameter matrix as a 3x3 vnl matrix /// vnl_matrix_fixed GetVnlCameraMatrix() const; /// /// \return the intrinsic parameter matrix as a 3x4 vnl matrix /// (the last column only containing zeros) /// vnl_matrix_fixed GetVnlCameraMatrix3x4() const; /// /// \return true if the intrinsics are set (some plausibility checks /// may be done here) /// bool IsValid() const; void SetValid(bool valid); cv::Mat GetCameraMatrix() const; cv::Mat GetDistorsionCoeffs(); cv::Mat GetDistorsionCoeffs() const; void ToXML(TiXmlElement* elem) const; std::string ToString() const; std::string GetString(); double GetFocalLengthX() const; double GetFocalLengthY() const; double GetPrincipalPointX() const; double GetPrincipalPointY() const; mitk::Point4D GetDistorsionCoeffsAsPoint4D() const; mitk::Point3D GetFocalPoint() const; mitk::Point3D GetPrincipalPoint() const; vnl_vector_fixed GetFocalPointAsVnlVector() const; vnl_vector_fixed GetPrincipalPointAsVnlVector() const; /// /// set a new camera matrix utilizing a vnl matrix /// void SetCameraMatrix( const vnl_matrix_fixed& _CameraMatrix ); void SetIntrinsics( const cv::Mat& _CameraMatrix , const cv::Mat& _DistorsionCoeffs); void SetFocalLength( double x, double y ); void SetPrincipalPoint( double x, double y ); void SetDistorsionCoeffs( double k1, double k2, double p1, double p2 ); void SetIntrinsics( const mitk::Point3D& focalPoint, const mitk::Point3D& principalPoint, const mitk::Point4D& distortionCoefficients); void FromXML(TiXmlElement* elem); void FromGMLCalibrationXML(TiXmlElement* elem); std::string ToOctaveString(const std::string& varName="CameraIntrinsics"); virtual ~CameraIntrinsics(); protected: CameraIntrinsics(); + CameraIntrinsics(const CameraIntrinsics& other); + cv::Mat m_CameraMatrix; cv::Mat m_DistorsionCoeffs; bool m_Valid; itk::FastMutexLock::Pointer m_Mutex; + + private: + + virtual itk::LightObject::Pointer InternalClone() const; }; } // namespace mitk mitkCameraCalibration_EXPORT std::ostream& operator<< (std::ostream& os, mitk::CameraIntrinsics::Pointer p); #endif // mitkCameraIntrinsics_h diff --git a/Modules/CameraCalibration/mitkCameraIntrinsicsProperty.cpp b/Modules/CameraCalibration/mitkCameraIntrinsicsProperty.cpp index 262ec809c2..fb9aefcd13 100644 --- a/Modules/CameraCalibration/mitkCameraIntrinsicsProperty.cpp +++ b/Modules/CameraCalibration/mitkCameraIntrinsicsProperty.cpp @@ -1,50 +1,68 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkCameraIntrinsicsProperty.h" namespace mitk { bool CameraIntrinsicsProperty::IsEqual(const BaseProperty& property) const { return this->m_Value->Equals(static_cast(property).m_Value.GetPointer()); } bool CameraIntrinsicsProperty::Assign(const BaseProperty& property) { this->m_Value = static_cast(property).m_Value; return true; } std::string CameraIntrinsicsProperty::GetValueAsString() const { std::stringstream myStr; myStr << GetValue(); return myStr.str(); } CameraIntrinsicsProperty::CameraIntrinsicsProperty() : BaseProperty() {} +CameraIntrinsicsProperty::CameraIntrinsicsProperty(const CameraIntrinsicsProperty& other) + : BaseProperty(other) +{ + +} + CameraIntrinsicsProperty::CameraIntrinsicsProperty( mitk::CameraIntrinsics::Pointer value ) : BaseProperty(), m_Value( value ) {} +CameraIntrinsicsProperty::Pointer CameraIntrinsicsProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer CameraIntrinsicsProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} + } // namespace mitk diff --git a/Modules/CameraCalibration/mitkCameraIntrinsicsProperty.h b/Modules/CameraCalibration/mitkCameraIntrinsicsProperty.h index ed795bd194..44baecdb4f 100644 --- a/Modules/CameraCalibration/mitkCameraIntrinsicsProperty.h +++ b/Modules/CameraCalibration/mitkCameraIntrinsicsProperty.h @@ -1,72 +1,77 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKCAMERAINTRINSICSPROPERTY_H #define MITKCAMERAINTRINSICSPROPERTY_H #include "mitkBaseProperty.h" #include "mitkCameraIntrinsics.h" namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif class mitkCameraCalibration_EXPORT CameraIntrinsicsProperty : public BaseProperty { public: typedef mitk::CameraIntrinsics::Pointer ValueType; mitkClassMacro(CameraIntrinsicsProperty, BaseProperty); itkNewMacro(CameraIntrinsicsProperty); mitkNewMacro1Param(CameraIntrinsicsProperty, mitk::CameraIntrinsics::Pointer); + Pointer Clone() const; + itkSetMacro(Value, mitk::CameraIntrinsics::Pointer ); itkGetConstMacro(Value, mitk::CameraIntrinsics::Pointer ); std::string GetValueAsString() const; using BaseProperty::operator=; protected: mitk::CameraIntrinsics::Pointer m_Value; CameraIntrinsicsProperty(); + CameraIntrinsicsProperty(const CameraIntrinsicsProperty&); + CameraIntrinsicsProperty( mitk::CameraIntrinsics::Pointer value ); private: // purposely not implemented - CameraIntrinsicsProperty(const CameraIntrinsicsProperty&); CameraIntrinsicsProperty& operator=(const CameraIntrinsicsProperty&); + virtual itk::LightObject::Pointer InternalClone() const; + virtual bool IsEqual(const BaseProperty& property) const; virtual bool Assign(const BaseProperty& property); }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace mitk #endif // MITKCAMERAINTRINSICSPROPERTY_H diff --git a/Modules/MitkExt/DataManagement/mitkGridRepresentationProperty.cpp b/Modules/MitkExt/DataManagement/mitkGridRepresentationProperty.cpp index 9b75baa4da..f0018e2c22 100644 --- a/Modules/MitkExt/DataManagement/mitkGridRepresentationProperty.cpp +++ b/Modules/MitkExt/DataManagement/mitkGridRepresentationProperty.cpp @@ -1,91 +1,109 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkGridRepresentationProperty.h" mitk::GridRepresentationProperty::GridRepresentationProperty( ) { AddRepresentationTypes(); SetValue( WIREFRAME ); } +mitk::GridRepresentationProperty::GridRepresentationProperty(const mitk::GridRepresentationProperty& other) + : mitk::EnumerationProperty(other) +{ +} + + mitk::GridRepresentationProperty::GridRepresentationProperty( const IdType& value ) { AddRepresentationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( WIREFRAME ); } } mitk::GridRepresentationProperty::GridRepresentationProperty( const std::string& value ) { AddRepresentationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( WIREFRAME ); } } void mitk::GridRepresentationProperty::SetRepresentationToPoints() { SetValue( POINTS ); } void mitk::GridRepresentationProperty::SetRepresentationToWireframe() { SetValue( WIREFRAME ); } void mitk::GridRepresentationProperty::SetRepresentationToSurface() { SetValue( SURFACE ); } void mitk::GridRepresentationProperty::SetRepresentationToWireframeSurface() { //SetValue( WIREFRAME_SURFACE ); } void mitk::GridRepresentationProperty::AddRepresentationTypes() { AddEnum( "Points", POINTS ); AddEnum( "Wireframe", WIREFRAME ); AddEnum( "Surface", SURFACE ); //AddEnum( "WireframeSurface", WIREFRAME_SURFACE ); } bool mitk::GridRepresentationProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } + +mitk::GridRepresentationProperty::Pointer mitk::GridRepresentationProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::GridRepresentationProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Modules/MitkExt/DataManagement/mitkGridRepresentationProperty.h b/Modules/MitkExt/DataManagement/mitkGridRepresentationProperty.h index 836bb9e181..bb89f68295 100644 --- a/Modules/MitkExt/DataManagement/mitkGridRepresentationProperty.h +++ b/Modules/MitkExt/DataManagement/mitkGridRepresentationProperty.h @@ -1,106 +1,114 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_GRID_REPRESENTATION_PROPERTY__H_ #define _MITK_GRID_REPRESENTATION_PROPERTY__H_ #include "mitkEnumerationProperty.h" #include "MitkExtExports.h" namespace mitk { /** * Extends the enumeration prop mitkEnumerationPropery. Adds the value * (constant / Id / string representation): *
    *
  • POINTS / 0 / Points
  • *
  • WIREFRAME / 1 / Wireframe
  • *
  • SURFACE / 2 / Surface
  • *
  • WIREFRAME_SURFACE / 3 / WireframeSurface
  • *
* Default is the Wireframe representation */ class MitkExt_EXPORT GridRepresentationProperty : public EnumerationProperty { public: enum RepresentationType {POINTS = 0, WIREFRAME = 1, SURFACE = 2}; //, WIREFRAME_SURFACE = 3}; mitkClassMacro( GridRepresentationProperty, EnumerationProperty ); itkNewMacro(GridRepresentationProperty); mitkNewMacro1Param(GridRepresentationProperty, const IdType& ); mitkNewMacro1Param(GridRepresentationProperty, const std::string& ); + Pointer Clone() const; + /** * Sets the representation type to POINTS. */ virtual void SetRepresentationToPoints(); /** * Sets the representation type to WIREFRAME. */ virtual void SetRepresentationToWireframe(); /** * Sets the representation type to SURFACE. */ virtual void SetRepresentationToSurface(); /** * Sets the representation type to WIREFRAME_SURFACE. */ virtual void SetRepresentationToWireframeSurface(); protected: /** * Constructor. Sets the representation to a default value of Wireframe(1) */ GridRepresentationProperty( ); + GridRepresentationProperty(const GridRepresentationProperty& other); + /** * Constructor. Sets the representation to the given value. If it is not * valid, the representation is set to Wireframe(1) * @param value the integer representation of the representation */ GridRepresentationProperty( const IdType& value ); /** * Constructor. Sets the representation to the given value. If it is not * valid, the representation is set to Wireframe(1) * @param value the string representation of the representation */ GridRepresentationProperty( 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: + + virtual itk::LightObject::Pointer InternalClone() const; }; } // end of namespace mitk #endif // _MITK_GRID_REPRESENTATION_PROPERTY__H_ diff --git a/Modules/MitkExt/DataManagement/mitkGridVolumeMapperProperty.cpp b/Modules/MitkExt/DataManagement/mitkGridVolumeMapperProperty.cpp index 902ae7c9ab..444acf833a 100644 --- a/Modules/MitkExt/DataManagement/mitkGridVolumeMapperProperty.cpp +++ b/Modules/MitkExt/DataManagement/mitkGridVolumeMapperProperty.cpp @@ -1,85 +1,97 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkGridVolumeMapperProperty.h" mitk::GridVolumeMapperProperty::GridVolumeMapperProperty( ) { AddRepresentationTypes(); SetValue( PT ); } mitk::GridVolumeMapperProperty::GridVolumeMapperProperty( const IdType& value ) { AddRepresentationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( PT ); } } mitk::GridVolumeMapperProperty::GridVolumeMapperProperty( const std::string& value ) { AddRepresentationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( PT ); } } void mitk::GridVolumeMapperProperty::SetVolumeMapperToPT() { SetValue( PT ); } void mitk::GridVolumeMapperProperty::SetVolumeMapperToZSweep() { SetValue( ZSWEEP ); } void mitk::GridVolumeMapperProperty::SetVolumeMapperToRayCast() { SetValue( RAYCAST ); } void mitk::GridVolumeMapperProperty::AddRepresentationTypes() { AddEnum( "Ray Cast", RAYCAST ); AddEnum( "Projected Tetrahedra", PT ); AddEnum( "ZSweep", ZSWEEP ); } bool mitk::GridVolumeMapperProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } + +mitk::GridVolumeMapperProperty::Pointer mitk::GridVolumeMapperProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::GridVolumeMapperProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Modules/MitkExt/DataManagement/mitkGridVolumeMapperProperty.h b/Modules/MitkExt/DataManagement/mitkGridVolumeMapperProperty.h index 21819d4886..21a9884a51 100644 --- a/Modules/MitkExt/DataManagement/mitkGridVolumeMapperProperty.h +++ b/Modules/MitkExt/DataManagement/mitkGridVolumeMapperProperty.h @@ -1,101 +1,107 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_GRID_VOLUME_MAPPER_PROPERTY__H_ #define _MITK_GRID_VOLUME_MAPPER_PROPERTY__H_ #include "mitkEnumerationProperty.h" #include "MitkExtExports.h" namespace mitk { /** * Extends the enumeration prop mitkEnumerationPropery. Adds the value * (constant/Id/string representation): * PT/0/Projected Tetrahedra, ZSWEEP/1/ZSweep, RAYCAST/2/Ray Cast * Default is the Wireframe representation */ class MitkExt_EXPORT GridVolumeMapperProperty : public EnumerationProperty { public: enum MapperType { RAYCAST = 0, PT = 1, ZSWEEP = 2 }; mitkClassMacro( GridVolumeMapperProperty, EnumerationProperty ); itkNewMacro(GridVolumeMapperProperty); mitkNewMacro1Param(GridVolumeMapperProperty, const IdType&); mitkNewMacro1Param(GridVolumeMapperProperty, const std::string&); + Pointer Clone() const; + /** * Sets the mapper to projected tetrahedra. */ virtual void SetVolumeMapperToPT(); /** * Sets the mapper to zsweep. */ virtual void SetVolumeMapperToZSweep(); /** * Sets the mapper to ray casting. */ virtual void SetVolumeMapperToRayCast(); protected: /** * Constructor. Sets the representation to a default value of Wireframe(1) */ GridVolumeMapperProperty( ); /** * Constructor. Sets the representation to the given value. If it is not * valid, the representation is set to Wireframe(1) * @param value the integer representation of the representation */ GridVolumeMapperProperty( const IdType& value ); /** * Constructor. Sets the representation to the given value. If it is not * valid, the representation is set to Wireframe(1) * @param value the string representation of the representation */ GridVolumeMapperProperty( 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: + + virtual itk::LightObject::Pointer InternalClone() const; }; } // end of namespace mitk #endif // _MITK_GRID_VOLUME_MAPPER_PROPERTY__H_ diff --git a/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.cpp b/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.cpp index 9c76744b97..c291630c84 100644 --- a/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.cpp +++ b/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.cpp @@ -1,115 +1,127 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkOrganTypeProperty.h" mitk::OrganTypeProperty::OrganTypeProperty() { AddEnumerationTypes(); } mitk::OrganTypeProperty::OrganTypeProperty( const IdType& value ) { AddEnumerationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ) ; } else { SetValue( 0 ); } } mitk::OrganTypeProperty::OrganTypeProperty( const std::string& value ) { AddEnumerationTypes(); if ( IsValidEnumerationValue( value ) ) { SetValue( value ); } else { SetValue( "undefined" ); } } mitk::OrganTypeProperty::~OrganTypeProperty() { } void mitk::OrganTypeProperty::AddEnumerationTypes() { IdType newId = static_cast(EnumerationProperty::Size()); // On changes, please also change mitk::DataNodeFactory::DefaultColorForOrgan() AddEnum( "undefined", newId++ ); AddEnum( "Ankle", newId++ ); AddEnum( "Appendix", newId++ ); AddEnum( "Blood vessels", newId++ ); AddEnum( "Bone", newId++ ); AddEnum( "Brain", newId++ ); AddEnum( "Bronchial tree", newId++ ); AddEnum( "Coccyx", newId++ ); AddEnum( "Colon", newId++ ); AddEnum( "Cyst", newId++ ); AddEnum( "Elbow", newId++ ); AddEnum( "Eye", newId++ ); AddEnum( "Fallopian tube", newId++ ); AddEnum( "Fat", newId++ ); AddEnum( "Gall bladder", newId++ ); AddEnum( "Hand", newId++ ); AddEnum( "Heart", newId++ ); AddEnum( "Hip", newId++ ); AddEnum( "Hippocampus", newId++ ); AddEnum( "Kidney", newId++ ); AddEnum( "Knee", newId++ ); AddEnum( "Larynx", newId++ ); AddEnum( "Liver", newId++ ); AddEnum( "Lung", newId++ ); AddEnum( "Lymph node", newId++ ); AddEnum( "Muscle", newId++ ); AddEnum( "Nerve", newId++ ); AddEnum( "Nose", newId++ ); AddEnum( "Oesophagus", newId++ ); AddEnum( "Ovaries", newId++ ); AddEnum( "Pancreas", newId++ ); AddEnum( "Pelvis", newId++ ); AddEnum( "Penis", newId++ ); AddEnum( "Pharynx", newId++ ); AddEnum( "Prostate", newId++ ); AddEnum( "Rectum", newId++ ); AddEnum( "Sacrum", newId++ ); AddEnum( "Seminal vesicle", newId++ ); AddEnum( "Shoulder", newId++ ); AddEnum( "Spinal cord", newId++ ); AddEnum( "Spleen", newId++ ); AddEnum( "Stomach", newId++ ); AddEnum( "Teeth", newId++ ); AddEnum( "Testicles", newId++ ); AddEnum( "Thyroid", newId++ ); AddEnum( "Tongue", newId++ ); AddEnum( "Tumor", newId++ ); AddEnum( "Urethra", newId++ ); AddEnum( "Urinary bladder", newId++ ); AddEnum( "Uterus", newId++ ); AddEnum( "Vagina", newId++ ); AddEnum( "Vertebra", newId++ ); AddEnum( "Wrist", newId++ ); } + +mitk::OrganTypeProperty::Pointer mitk::OrganTypeProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} + +itk::LightObject::Pointer mitk::OrganTypeProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.h b/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.h index 577f8d3e93..43f80890f2 100644 --- a/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.h +++ b/Modules/MitkExt/DataManagement/mitkOrganTypeProperty.h @@ -1,76 +1,79 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkOrganTypeProperty_h_Included #define mitkOrganTypeProperty_h_Included #include "mitkCommon.h" #include "MitkExtExports.h" #include "mitkEnumerationProperty.h" #include namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4522) #endif /** \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&); + Pointer Clone() const; + 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&); + + virtual itk::LightObject::Pointer InternalClone() const; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // namespace #endif diff --git a/Modules/PlanarFigure/DataManagement/mitkPlanarFigureControlPointStyleProperty.cpp b/Modules/PlanarFigure/DataManagement/mitkPlanarFigureControlPointStyleProperty.cpp index e844b808e5..e353c99895 100644 --- a/Modules/PlanarFigure/DataManagement/mitkPlanarFigureControlPointStyleProperty.cpp +++ b/Modules/PlanarFigure/DataManagement/mitkPlanarFigureControlPointStyleProperty.cpp @@ -1,75 +1,85 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkPlanarFigureControlPointStyleProperty.h" mitk::PlanarFigureControlPointStyleProperty::PlanarFigureControlPointStyleProperty( ) { this->AddEnumTypes(); this->SetValue( static_cast ( Square ) ); } mitk::PlanarFigureControlPointStyleProperty::PlanarFigureControlPointStyleProperty( const IdType &value ) { this->AddEnumTypes(); if ( this->IsValidEnumerationValue( value ) ) { this->SetValue( value ) ; } else { this->SetValue( static_cast ( Square ) ); } } mitk::PlanarFigureControlPointStyleProperty::PlanarFigureControlPointStyleProperty( const std::string &value ) { this->AddEnumTypes(); if ( this->IsValidEnumerationValue( value ) ) { this->SetValue( value ); } else { this->SetValue( static_cast( Square ) ); } } void mitk::PlanarFigureControlPointStyleProperty::AddEnumTypes() { this->AddEnum( "Square", static_cast( Square ) ); this->AddEnum( "Circle", static_cast( Circle ) ); } bool mitk::PlanarFigureControlPointStyleProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } mitk::PlanarFigureControlPointStyleProperty::Shape mitk::PlanarFigureControlPointStyleProperty::GetShape() { return static_cast( this->GetValueAsId() ); } void mitk::PlanarFigureControlPointStyleProperty::SetShape(mitk::PlanarFigureControlPointStyleProperty::Shape shape) { this->SetValue( static_cast( shape ) ); } +mitk::PlanarFigureControlPointStyleProperty::Pointer mitk::PlanarFigureControlPointStyleProperty::Clone() const +{ + Pointer result = static_cast(this->InternalClone().GetPointer()); + return result; +} +itk::LightObject::Pointer mitk::PlanarFigureControlPointStyleProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + return result; +} diff --git a/Modules/PlanarFigure/DataManagement/mitkPlanarFigureControlPointStyleProperty.h b/Modules/PlanarFigure/DataManagement/mitkPlanarFigureControlPointStyleProperty.h index bcbf8f1a98..320c57ec07 100644 --- a/Modules/PlanarFigure/DataManagement/mitkPlanarFigureControlPointStyleProperty.h +++ b/Modules/PlanarFigure/DataManagement/mitkPlanarFigureControlPointStyleProperty.h @@ -1,88 +1,97 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkPlanarFigureControlPointStyleProperty_h #define mitkPlanarFigureControlPointStyleProperty_h #include "mitkEnumerationProperty.h" #include "PlanarFigureExports.h" namespace mitk { /** * \brief Defines the rendering style of control points for PlanarFigure objects. * \sa mitk::PlanarFigureMapper2D * \ingroup DataManagement * * Used by PlanarFigureMapper2D to determine which of several control point shapes to use. * Currently this is basically the choice between squares and circles. If more options * are implemented, this class should be enhanced. * * After construction, the default shape is a square. * */ class PlanarFigure_EXPORT PlanarFigureControlPointStyleProperty : public EnumerationProperty { public: mitkClassMacro( PlanarFigureControlPointStyleProperty, EnumerationProperty ); itkNewMacro(PlanarFigureControlPointStyleProperty); mitkNewMacro1Param(PlanarFigureControlPointStyleProperty, const IdType&); mitkNewMacro1Param(PlanarFigureControlPointStyleProperty, const std::string&); + Pointer Clone() const; + typedef enum { Square, Circle } Shape; virtual Shape GetShape(); virtual void SetShape( Shape ); protected: PlanarFigureControlPointStyleProperty( ); PlanarFigureControlPointStyleProperty( const IdType &value ); /** * Constructor. Sets the decoration type to the given value. If it is not * valid, the representation is set to none */ PlanarFigureControlPointStyleProperty( 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 AddEnumTypes(); + +private: + + // purposely not implemented + PlanarFigureControlPointStyleProperty& operator=(const PlanarFigureControlPointStyleProperty&); + + virtual itk::LightObject::Pointer InternalClone() const; }; } // end of namespace mitk #endif