/*============================================================================= NOTE: THIS FILE IS A HANDMADE WRAPPER FOR THE ManagedITK PROJECT. Project: ManagedITK Program: Insight Segmentation & Registration Toolkit Module: itkManagedPoint.cxx Language: C++/CLI Author: Dan Mueller Date: $Date: 2008-03-09 19:29:02 +0100 (Sun, 09 Mar 2008) $ Revision: $Revision: 8 $ Portions of this code are covered under the ITK and VTK copyright. See http://www.itk.org/HTML/Copyright.htm for details. See http://www.kitware.com/VTKCopyright.htm for details. Copyright (c) 2008 Queensland University of Technology (QUT) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================================================*/ #pragma once #pragma warning( disable : 4635 ) // Disable warnings about XML doc comments #ifndef __itkManagedPoint_cxx #define __itkManagedPoint_cxx // Use some managed namespaces #using #using using namespace System; using namespace System::IO; using namespace System::Reflection; using namespace System::ComponentModel; using namespace System::Diagnostics; // Some Managed ITK inludes #include "itkManagedArray.cxx" #include "itkManagedVector.cxx" namespace itk { #define itkPointValueType System::Double /// ///This class is a managed replacement for itk::Point. /// /// ///An Point represents an n-Dimensional geometric point in physical space. /// public ref class itkPoint : itkArray { public: ///Constructor taking the data values as a params array. ///The variable length data array. The dimension will be initialised as data.Length. itkPoint ( ... array^ data ) : itkArray( data ) { } ///Constructor taking the number of dimensions for the array. ///The data values are initialised as zero. ///The dimensionality of the array to initialise. itkPoint( unsigned int dimension ) : itkArray( dimension ) { } ///Constructor taking another array. ///Another array to clone the data from. itkPoint ( itkPoint^ other) : itkArray( other->Data ) { } /// ///Compares the given Object to this. ///They are equal if they have the same dimensionality AND data. /// ///The object to test. ///true AND the objects are equal OR false AND the objects are not equal. virtual bool Equals(Object^ obj) override { // Check if input object is null if ( obj == nullptr ) return false; // Cast itkPoint^ right = safe_cast< itkPoint^ >(obj); if ( right != nullptr ) { // Check number of dimensions are the same if (this->Dimension != right->Dimension) return false; // Check data at each location is the the same bool result = true; for (unsigned int i = 0; i < this->Dimension; i++) result &= (this[i] == right[i]); return result; } return false; } /// ///Compares two itkPoint objects. ///They are equal if they have the same dimensionality AND data. /// /// /// ///true AND the objects are equal OR false AND the objects are not equal. static bool operator ==(itkPoint^ lhs, itkPoint^ rhs) { if ( Object::ReferenceEquals(lhs, rhs) ) return true; else if ( Object::ReferenceEquals(lhs, nullptr) ) return false; else if ( Object::ReferenceEquals(rhs, nullptr) ) return false; else return lhs->Equals(rhs); } /// ///Compares two itkPoint objects. ///They are not equal if they do not have the same dimensionality OR ///do not have the same data. /// /// ///true AND the objects are not equal OR false AND the objects are equal. virtual bool operator !=(itkPoint^ rhs) { return !(this == rhs); } ///Performs an element-wise addition. /// /// ///A new itkVector instance with data as the element-wise addition. static itkVector^ operator+(itkPoint^ lhs, itkPoint^ rhs) { if ( lhs == nullptr || rhs == nullptr ) throw gcnew ArgumentNullException("Can not operate on nullptr objects."); else { itkVector^ result = gcnew itkVector( lhs->Dimension ); for (unsigned int i = 0; i < result->Dimension; i++) result[i] = lhs[i] + rhs[i]; return result; } } ///Performs an element-wise subtraction. /// /// ///A new itkVector instance with data as the element-wise subtraction. static itkVector^ operator-(itkPoint^ lhs, itkPoint^ rhs) { if ( lhs == nullptr || rhs == nullptr ) throw gcnew ArgumentNullException("Can not operate on nullptr objects."); else { itkVector^ result = gcnew itkVector( lhs->Dimension ); for (unsigned int i = 0; i < result->Dimension; i++) result[i] = lhs[i] - rhs[i]; return result; } } ///Move the point in the direction of the given vector. /// /// ///A new itkPoint instance with each data element offset by the vector element. static itkPoint^ operator+(itkPoint^ lhs, itkVector^ rhs) { if ( lhs == nullptr || rhs == nullptr ) throw gcnew ArgumentNullException("Can not operate on nullptr objects."); else { itkPoint^ result = gcnew itkPoint( lhs->Dimension ); for (unsigned int i = 0; i < result->Dimension; i++) result[i] = lhs[i] + rhs[i]; return result; } } ///Move the point in the opposite direction of the given vector. /// /// ///A new itkPoint instance with each data element offset by the vector element. static itkPoint^ operator-(itkPoint^ lhs, itkVector^ rhs) { if ( lhs == nullptr || rhs == nullptr ) throw gcnew ArgumentNullException("Can not operate on nullptr objects."); else { itkPoint^ result = gcnew itkPoint( lhs->Dimension ); for (unsigned int i = 0; i < result->Dimension; i++) result[i] = lhs[i] - rhs[i]; return result; } } ///Computes the squared Euclidean distance from this to the given point. ///The other point used in the calculation. ///The squared Euclidean distance from this to the given point. virtual double SquaredEuclideanDistanceTo(itkPoint^ point) { double sum = 0.0; for (unsigned int i=0; iLength; i++ ) { double difference = this[i] - point[i]; sum += (difference * difference); } return sum; } ///Computes the distance from this to the given point. ///The other point used in the calculation. ///The Euclidean distance from this to the given point. virtual double EuclideanDistanceTo(itkPoint^ point) { return Math::Sqrt(this->SquaredEuclideanDistanceTo(point) ); } }; // end ref class } // end namespace itk #endif