diff --git a/Core/Code/DataManagement/mitkPoint.h b/Core/Code/DataManagement/mitkPoint.h index 2e44ce7d86..336f551ae8 100644 --- a/Core/Code/DataManagement/mitkPoint.h +++ b/Core/Code/DataManagement/mitkPoint.h @@ -1,110 +1,99 @@ /*=================================================================== 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 MITKPOINT_H #define MITKPOINT_H #include #include "mitkTypeBasics.h" namespace mitk { //##Documentation //##@brief enumeration of the type a point can be enum PointSpecificationType { PTUNDEFINED = 0, PTSTART, PTCORNER, PTEDGE, PTEND }; template class Point : public itk::Point { public: /** Default constructor has nothing to do. */ Point() : itk::Point() {} /** Pass-through constructors for the Array base class. */ Point(const mitk::Point& r) : itk::Point(r) {} Point(const TCoordRep r[NPointDimension]):itk::Point(r) {} Point(const TCoordRep & v):itk::Point(v) {} Point(const itk::Point r) : itk::Point(r) {} /** Pass-through assignment operator for the Array base class. */ /** * Assignment Operator */ Point< TCoordRep, NPointDimension > & operator=(const Point & r) { itk::Point::operator=(r); return *this; } - /** Pass-through assignment operator for the Array base class. */ - /** - * Assignment Operator - */ - Point< TCoordRep, NPointDimension > & - operator=(const itk::FixedArray & r) - { - itk::FixedArray::operator=(r); - return *this; - } - /** * Assignment from a plain array */ Point< TCoordRep, NPointDimension > & operator=(const TCoordRep r[NPointDimension]) { itk::Point::operator=(r); return *this; } /** * Warning: Array must have same dimension as Point */ void CopyToArray(ScalarType array_p[NPointDimension]) const { for (int i = 0; i < this->GetPointDimension(); i++) { array_p[i] = this->GetElement(i); } } }; typedef Point Point2D; typedef Point Point3D; typedef Point Point4D; typedef Point Point2I; typedef Point Point3I; typedef Point Point4I; } // namespace mitk #endif /* MITKPOINT_H */ diff --git a/Core/Code/DataManagement/mitkTypeOperations.h b/Core/Code/DataManagement/mitkTypeOperations.h index 1a28b31d92..37f765d0a7 100644 --- a/Core/Code/DataManagement/mitkTypeOperations.h +++ b/Core/Code/DataManagement/mitkTypeOperations.h @@ -1,77 +1,81 @@ /*=================================================================== 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 MITKTYPEOPERATIONS_H_ #define MITKTYPEOPERATIONS_H_ #include #include "mitkExceptionMacro.h" namespace mitk { /** * This file provides convenience methods to add and subtract itk::FixedArrays and to multiply and divide itk::FixedArrays with scalars. * That means these methods apply to all types deriving from itk::FixedArray. * This can e.g. useful to add points and divide them by the number of added points to build an average. */ /** - * @brief implements sum = addend1 + addend2 - * Takes FixedArray so you sum all deriving classes like e.g. - * sum two points returning a point or - * sum a vector and a point, returning a vector. + * @brief implements sum = addend1 + addend2 for mitk::Point * - * @attention Please make sure, that you really want to add the types you specified. + * @attention Please make sure, that you really want to add mitk::Point s. * @attention E.g., summing two points does geometrically not make sense, which is why itk does * @attention not provide an operator+ for these types. * */ template< typename TCoordRep, unsigned int NPointDimension> - void add(itk::FixedArray& sum, - itk::FixedArray& addend1, itk::FixedArray& addend2) + mitk::Point operator+(mitk::Point& addend1, mitk::Point& addend2) { + mitk::Point sum; + for (typename itk::FixedArray::SizeType var = 0; var < NPointDimension; ++var) { sum[var] = addend1[var] + addend2[var]; } + + return sum; } /** - * @brief implements difference = minuend - subtrahend. + * @brief implements difference = minuend - subtrahend for mitk::Point. * - * result the result of the subtraction + * @return the result of the subtraction * @param minuend * @param subtrahend + * + * @attention Please make sure, that you really want to add mitk::Point s. + * @attention E.g., summing two points does geometrically not make sense, which is why itk does + * @attention not provide an operator+ for these types. */ template< typename TCoordRep, unsigned int NPointDimension> - itk::FixedArray sub(itk::FixedArray& minuend, itk::FixedArray& subtrahend) + mitk::Point operator-(mitk::Point& minuend, mitk::Point& subtrahend) { - itk::FixedArray difference; + mitk::Point difference; - for (typename itk::FixedArray::SizeType var = 0; var < NPointDimension; ++var) + for (typename mitk::Point::SizeType var = 0; var < NPointDimension; ++var) { difference[var] = minuend[var] - subtrahend[var]; } return difference; } } #endif /* MITKTYPEOPERATIONS_H_ */ diff --git a/Core/Code/Testing/mitkTypeOperationTest.cpp b/Core/Code/Testing/mitkTypeOperationTest.cpp index 3d9e8c24c1..c2d3986458 100644 --- a/Core/Code/Testing/mitkTypeOperationTest.cpp +++ b/Core/Code/Testing/mitkTypeOperationTest.cpp @@ -1,84 +1,83 @@ /*=================================================================== 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 "mitkPoint.h" #include "mitkTypeOperations.h" #include "mitkTypes.h" // for Equal method. TODO SW: Replace this once the Equal methods have their own header. #include using namespace mitk; static ScalarType bValues[3] = {14.123456, 10.2, 5.123456789}; static ScalarType cValues[3] = { 2.654321, 5.1, 2.543231111}; static Point3D a, b, c; static void Setup(void) { b = bValues; c = cValues; } template static void TestForValuesHelper(itk::FixedArray& result, ScalarType v0, ScalarType v1, ScalarType v2, std::string message, ScalarType eps = mitk::eps) { MITK_TEST_CONDITION_REQUIRED( Equal(result[0], v0, eps) && Equal(result[1], v1, eps) && Equal(result[2], v2, eps), message) } static void Test_Addition(void) { Setup(); - mitk::add(a, b, c); + a = b + c; TestForValuesHelper(a, 16.777777, 15.3, 7.6666879, "summation a = b + c correctly performed"); } static void Test_Substraction(void) { Setup(); - itk::FixedArray test; - a = mitk::sub(b, c); + a = b - c; TestForValuesHelper(a, 11.469135, 5.1, 2.580225678, "difference a = b - c correctly performed"); } int mitkTypeOperationTest(int /*argc*/ , char* /*argv*/[]) { // always start with this! MITK_TEST_BEGIN("TypeOperationTest") Test_Addition(); Test_Substraction(); MITK_TEST_END() }