/*============================================================================= NOTE: THIS FILE IS A HANDMADE WRAPPER FOR THE ManagedITK PROJECT. Project: ManagedITK Program: Insight Segmentation & Registration Toolkit Module: itkManagedFlatStructuringElement.cxx Language: C++/CLI Author: Dan Mueller $Date$ $Revision$ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. Portions of this code are covered under the ITK and VTK copyright. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ #pragma once #pragma warning( disable : 4635 ) // Disable warnings about XML doc comments #ifndef __itkManagedFlatStructuringElement_cxx #define __itkManagedFlatStructuringElement_cxx // Use some managed namespaces #using #using using namespace System; using namespace System::IO; using namespace System::Reflection; using namespace System::Diagnostics; using namespace System::Collections::Generic; // Include some useful ManagedITK files #include "itkManagedInvalidWrappedTypeException.cxx" #include "itkManagedINativePointer.cxx" #include "itkManagedSize.cxx" namespace itk { /// ///This class is a managed wrapper around itk::FlatStructuringElement. /// public ref class itkFlatStructuringElement abstract: INativePointer { protected: String^ m_Type; itkSize^ m_Radius; itkFlatStructuringElement^ m_Instance; public: ///Create a box shaped structuring element of the given radius. static itkFlatStructuringElement^ Box( itkSize^ radius ) { itkFlatStructuringElement^ result = CreateInstance( "Box", gcnew array{radius} ); return result; } ///Create a ball shaped structuring element of the given radius. static itkFlatStructuringElement^ Ball( itkSize^ radius ) { itkFlatStructuringElement^ result = CreateInstance( "Ball", gcnew array{radius} ); return result; } /// ///Create an annulus (ring) structuring element of the given outer radius. ///The thickness defaults to 1, and the center pixel is excluded. /// static itkFlatStructuringElement^ Annulus( itkSize^ radius ) { itkFlatStructuringElement^ result = CreateInstance( "Annulus", gcnew array{radius} ); return result; } /// ///Create an annulus (ring) structuring element of the given outer radius. ///The thickness is as specified, and the center pixel is excluded. /// static itkFlatStructuringElement^ Annulus( itkSize^ radius, unsigned int thickness ) { itkFlatStructuringElement^ result = CreateInstance( "Annulus", gcnew array{radius, thickness} ); return result; } /// ///Create an annulus (ring) structuring element of the given outer radius. ///The thickness is as specified, and the center pixel is included or excluded as specified. /// static itkFlatStructuringElement^ Annulus( itkSize^ radius, unsigned int thickness, bool includeCenter ) { itkFlatStructuringElement^ result = CreateInstance( "Annulus", gcnew array{radius, thickness, includeCenter} ); return result; } ///Get a string representing the type instance of the structuring element. ///"FSE2", "FSE3". /// ///This object can be passed to the New() methods to specify the type of ///native itk object to create. /// property String^ MangledTypeString { virtual String^ get() { return "FSE" + this->m_Radius->Dimension.ToString(); } } /// ///Get/set the pointer to the native ITK object associated with ///this type instance. /// ///The pointer to the native ITK object. property virtual void* NativePointer { virtual void* get(){ return m_Instance->NativePointer; } virtual void set ( void* value){ m_Instance->NativePointer = value; } } /// ///Converts the structuring to a string representation in the following format: /// Type[radius] ///Example: Ball[2,2,2] /// ///A string representation of the structuring element. virtual String^ ToString() override { return m_Type + m_Radius->ToString(); } private: ///Creates the correct type instance of the underlying native itk::FlatStructuringElement. static itkFlatStructuringElement^ CreateInstance( String^ type, array^ args) { itkSize^ radius = safe_cast(args[0]); String^ nameInstanceType = "itk.itkFlatStructuringElement_" + radius->Dimension.ToString(); try { System::Type^ typeInstance = System::Reflection::Assembly::GetExecutingAssembly()->GetType(nameInstanceType); if (typeInstance == nullptr) throw gcnew NullReferenceException("The type '" + nameInstanceType + "' could not be found in " + System::Reflection::Assembly::GetExecutingAssembly()->GetName() ); System::Object^ objInstance = typeInstance->InvokeMember(type, System::Reflection::BindingFlags::InvokeMethod, System::Type::DefaultBinder, nullptr, args); if (objInstance == nullptr) throw gcnew NullReferenceException("Could not invoke the " + type + "() method for '" + nameInstanceType + "'."); return safe_cast(objInstance); } catch (Exception^ ex) { throw gcnew itkInvalidWrappedTypeException("Could not create an instance of '" + nameInstanceType + "'. The given type may not be supported or may be invalid.", ex); } } }; // end ref class } // end namespace itk #endif