diff --git a/Modules/ToFProcessing/mitkToFProcessingCommon.cpp b/Modules/ToFProcessing/mitkToFProcessingCommon.cpp index 8066bd3692..aadda2efb2 100644 --- a/Modules/ToFProcessing/mitkToFProcessingCommon.cpp +++ b/Modules/ToFProcessing/mitkToFProcessingCommon.cpp @@ -1,66 +1,66 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkToFProcessingCommon.h" namespace mitk { + ToFProcessingCommon::ToFPoint3D ToFProcessingCommon::IndexToCartesianCoordinates(unsigned int i, unsigned int j, ToFScalarType distance, ToFScalarType focalLength, + ToFScalarType interPixelDistanceX, ToFScalarType interPixelDistanceY, + ToFScalarType principalPointX, ToFScalarType principalPointY) + { + ToFPoint3D cartesianCoordinates; -ToFProcessingCommon::ToFPoint3D ToFProcessingCommon::IndexToCartesianCoordinates(unsigned int i, unsigned int j, ToFScalarType distance, ToFScalarType focalLength, - ToFPoint2D interPixelDistance, ToFPoint2D principalPoint) -{ - ToFPoint3D cartesianCoordinates; - - // calculate image coordinates in mm; - ToFScalarType imageX = (( i - principalPoint[0] ) * interPixelDistance[0]); - ToFScalarType imageY = (( j - principalPoint[1] ) * interPixelDistance[1]); + // calculate image coordinates in mm; + ToFScalarType imageX = (( i - principalPointX ) * interPixelDistanceX); + ToFScalarType imageY = (( j - principalPointY ) * interPixelDistanceY); - //distance from pinhole to pixel - ToFScalarType d = sqrt(imageX*imageX + imageY*imageY + focalLength*focalLength); + //distance from pinhole to pixel + ToFScalarType d = sqrt(imageX*imageX + imageY*imageY + focalLength*focalLength); - cartesianCoordinates[0] = (distance-d)*imageX / d; //Strahlensatz: x / imageX = (distance-d) / d - cartesianCoordinates[1] = (distance-d)*imageY / d; //Strahlensatz: y / imageY = (distance-d) / d - cartesianCoordinates[2] = ((distance*focalLength) / d) - focalLength; //Strahlensatz: z+f / f = distance / d. + cartesianCoordinates[0] = (distance-d)*imageX / d; //Strahlensatz: x / imageX = (distance-d) / d + cartesianCoordinates[1] = (distance-d)*imageY / d; //Strahlensatz: y / imageY = (distance-d) / d + cartesianCoordinates[2] = ((distance*focalLength) / d) - focalLength; //Strahlensatz: z+f / f = distance / d. - return cartesianCoordinates; -} + return cartesianCoordinates; + } -ToFProcessingCommon::ToFPoint3D ToFProcessingCommon::CartesianToIndexCoordinates(ToFPoint3D cartesianPoint, ToFScalarType focalLength, - ToFPoint2D interPixelDistance, ToFPoint2D principalPoint, bool calculateDistance) -{ - ToFPoint3D indexCoordinatesAndDistanceValue; + ToFProcessingCommon::ToFPoint3D ToFProcessingCommon::CartesianToIndexCoordinates(ToFScalarType cartesianPointX, ToFScalarType cartesianPointY,ToFScalarType cartesianPointZ, + ToFScalarType focalLength, ToFScalarType interPixelDistanceX, ToFScalarType interPixelDistanceY, + ToFScalarType principalPointX, ToFScalarType principalPointY, bool calculateDistance) + { + ToFPoint3D indexCoordinatesAndDistanceValue; - ToFScalarType imageX = focalLength/cartesianPoint[2] * cartesianPoint[0]; - ToFScalarType imageY = focalLength/cartesianPoint[2] * cartesianPoint[1]; + ToFScalarType imageX = focalLength/cartesianPointZ * cartesianPointX; + ToFScalarType imageY = focalLength/cartesianPointZ * cartesianPointY; - indexCoordinatesAndDistanceValue[0] = imageX/interPixelDistance[0] + principalPoint[0]; - indexCoordinatesAndDistanceValue[1] = imageY/interPixelDistance[1] + principalPoint[1]; + indexCoordinatesAndDistanceValue[0] = imageX/interPixelDistanceX + principalPointX; + indexCoordinatesAndDistanceValue[1] = imageY/interPixelDistanceY + principalPointY; - ToFScalarType d = sqrt(imageX*imageX + imageY*imageY + focalLength*focalLength); + ToFScalarType d = sqrt(imageX*imageX + imageY*imageY + focalLength*focalLength); - if (calculateDistance) - { - indexCoordinatesAndDistanceValue[2] = d*(cartesianPoint[2]+focalLength) / focalLength; - } - else - { - indexCoordinatesAndDistanceValue[2] = 0.0; + if (calculateDistance) + { + indexCoordinatesAndDistanceValue[2] = d*(cartesianPointZ+focalLength) / focalLength; + } + else + { + indexCoordinatesAndDistanceValue[2] = 0.0; + } + return indexCoordinatesAndDistanceValue; } - return indexCoordinatesAndDistanceValue; -} - } diff --git a/Modules/ToFProcessing/mitkToFProcessingCommon.h b/Modules/ToFProcessing/mitkToFProcessingCommon.h index fee4162825..1283ea504c 100644 --- a/Modules/ToFProcessing/mitkToFProcessingCommon.h +++ b/Modules/ToFProcessing/mitkToFProcessingCommon.h @@ -1,93 +1,160 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKTOFPROCESSINGCOMMON_H #define MITKTOFPROCESSINGCOMMON_H #include "mitkToFProcessingExports.h" #include "mitkVector.h" #include namespace mitk { /** * @brief Helper class providing functions which are useful for multiple usage * * Currently the following methods are provided: * * * * @ingroup ToFProcessing */ class mitkToFProcessing_EXPORT ToFProcessingCommon { public: typedef double ToFScalarType; typedef itk::Point ToFPoint2D; typedef itk::Point ToFPoint3D; typedef itk::Vector ToFVector2D; typedef itk::Vector ToFVector3D; - /*! - \brief Convert index based distances to cartesian coordinates - \param i index in x direction of image plane - \param j index in y direction of image plane - \param distance distance value at given index in mm - \param focalLength focal length of optical system in mm (mostly obtained from camera calibration) - \param interPixelDistance distance between adjacent pixels in mm - \param principalPoint coordinates of principal point on image plane in pixel - \return cartesian coordinates for current index will be written here - */ + \brief Convert index based distances to cartesian coordinates + \param i index in x direction of image plane + \param j index in y direction of image plane + \param distance distance value at given index in mm + \param focalLength focal length of optical system in mm (mostly obtained from camera calibration) + \param interPixelDistanceX distance in x direction between adjacent pixels in mm + \param interPixelDistanceY distance in y direction between adjacent pixels in mm + \param principalPointX x coordinate of principal point on image plane in pixel + \param principalPointY y coordinate of principal point on image plane in pixel + \return cartesian coordinates for current index will be written here + */ static ToFPoint3D IndexToCartesianCoordinates(unsigned int i, unsigned int j, ToFScalarType distance, ToFScalarType focalLength, - ToFPoint2D interPixelDistance, ToFPoint2D principalPoint); + ToFScalarType interPixelDistanceX, ToFScalarType interPixelDistanceY, ToFScalarType principalPointX, ToFScalarType principalPointY); + /*! - \brief Convert index based distances to cartesian coordinates - \param index index coordinates - \param distance distance value at given index in mm - \param focalLength focal length of optical system (mostly obtained from camera calibration) - \param interPixelDistance distance between adjacent pixels in mm for x and y direction - \param principalPoint coordinates of principal point on image plane in pixel - \return cartesian coordinates for current index will be written here - */ + \brief Convert index based distances to cartesian coordinates + \param i index in x direction of image plane + \param j index in y direction of image plane + \param distance distance value at given index in mm + \param focalLength focal length of optical system in mm (mostly obtained from camera calibration) + \param interPixelDistance distance between adjacent pixels in mm + \param principalPoint coordinates of principal point on image plane in pixel + \return cartesian coordinates for current index will be written here + */ + inline static ToFPoint3D IndexToCartesianCoordinates(unsigned int i, unsigned int j, ToFScalarType distance, ToFScalarType focalLength, + ToFPoint2D interPixelDistance, ToFPoint2D principalPoint) + { + return IndexToCartesianCoordinates(i,j,distance,focalLength,interPixelDistance[0],interPixelDistance[1],principalPoint[0],principalPoint[1]); + } + /*! + \brief Convert index based distances to cartesian coordinates + \param index index coordinates + \param distance distance value at given index in mm + \param focalLength focal length of optical system (mostly obtained from camera calibration) + \param interPixelDistance distance between adjacent pixels in mm for x and y direction + \param principalPoint coordinates of principal point on image plane in pixel + \return cartesian coordinates for current index will be written here + */ inline static ToFPoint3D IndexToCartesianCoordinates(mitk::Index3D index, ToFScalarType distance, ToFScalarType focalLength, - ToFPoint2D interPixelDistance, ToFPoint2D principalPoint) + ToFPoint2D interPixelDistance, ToFPoint2D principalPoint) { return IndexToCartesianCoordinates(index[0],index[1],distance,focalLength,interPixelDistance,principalPoint); } + /*! + \brief Convenience method to convert index based distances to cartesian coordinates using array as input + \param i index in x direction of image plane + \param j index in y direction of image plane + \param distance distance value at given index in mm + \param focalLength focal length of optical system in mm (mostly obtained from camera calibration) + \param interPixelDistance distance between adjacent pixels in mm + \param principalPoint coordinates of principal point on image plane in pixel + \return cartesian coordinates for current index will be written here + */ + inline static ToFPoint3D IndexToCartesianCoordinates(unsigned int i, unsigned int j, ToFScalarType distance, ToFScalarType focalLength, + ToFScalarType interPixelDistance[2], ToFScalarType principalPoint[2]) + { + return IndexToCartesianCoordinates(i,j,distance,focalLength,interPixelDistance[0],interPixelDistance[1],principalPoint[0],principalPoint[1]); + } + /*! + \brief Convert index based distances to cartesian coordinates + \param cartesianPointX x coordinate of point (of a surface or point set) to convert in 3D coordinates + \param cartesianPointY y coordinate of point (of a surface or point set) to convert in 3D coordinates + \param cartesianPointZ z coordinate of point (of a surface or point set) to convert in 3D coordinates + \param focalLength focal length of optical system in mm (mostly obtained from camera calibration) + \param interPixelDistanceX distance in x direction between adjacent pixels in mm + \param interPixelDistanceY distance in y direction between adjacent pixels in mm + \param principalPointX x coordinate of principal point on image plane in pixel + \param principalPointY y coordinate of principal point on image plane in pixel + \param calculateDistance if this flag is set, the distance value is stored in the z position of the output otherwise z=0 + \return a ToFPoint3D. (int)ToFPoint3D[0]+0.5 and (int)ToFPoint3D[0]+0.5 will return the x and y index coordinates. ToFPoint3D[2] contains the distance value + */ + static ToFPoint3D CartesianToIndexCoordinates(ToFScalarType cartesianPointX, ToFScalarType cartesianPointY,ToFScalarType cartesianPointZ, + ToFScalarType focalLength, ToFScalarType interPixelDistanceX, ToFScalarType interPixelDistanceY, + ToFScalarType principalPointX, ToFScalarType principalPointY, bool calculateDistance=true); /*! - \brief Convert index based distances to cartesian coordinates - \param cartesianPoint point (of a surface or point set) to convert in 3D coordinates - \param distance distance value at given index in mm - \param focalLength focal length of optical system in mm (mostly obtained from camera calibration) - \param interPixelDistance distance between adjacent pixels in mm for x and y direction - \param principalPoint coordinates of principal point on image plane in pixel - \param calculateDistance if this flag is set, the distance value is stored in the z position of the output otherwise z=0 - \return a ToFPoint3D. (int)ToFPoint3D[0]+0.5 and (int)ToFPoint3D[0]+0.5 will return the x and y index coordinates. ToFPoint3D[2] contains the distance value - */ - static ToFPoint3D CartesianToIndexCoordinates(ToFPoint3D cartesianPoint, ToFScalarType focalLength, - ToFPoint2D interPixelDistance, ToFPoint2D principalPoint, bool calculateDistance=true); + \brief Convenience method to convert index based distances to cartesian coordinates using arrays + \param cartesianPoint point (of a surface or point set) to convert in 3D coordinates + \param focalLength focal length of optical system in mm (mostly obtained from camera calibration) + \param interPixelDistance distance between adjacent pixels in mm for x and y direction + \param principalPoint coordinates of principal point on image plane in pixel + \param calculateDistance if this flag is set, the distance value is stored in the z position of the output otherwise z=0 + \return a ToFPoint3D. (int)ToFPoint3D[0]+0.5 and (int)ToFPoint3D[0]+0.5 will return the x and y index coordinates. ToFPoint3D[2] contains the distance value + */ + inline static ToFPoint3D CartesianToIndexCoordinates(ToFScalarType cartesianPoint[3], ToFScalarType focalLength, + ToFScalarType interPixelDistance[2], ToFScalarType principalPoint[2], + bool calculateDistance=true) + { + return CartesianToIndexCoordinates(cartesianPoint[0],cartesianPoint[1],cartesianPoint[2],focalLength, + interPixelDistance[0],interPixelDistance[1],principalPoint[0],principalPoint[1],calculateDistance); + } + /*! + \brief Convert index based distances to cartesian coordinates + \param cartesianPoint point (of a surface or point set) to convert in 3D coordinates + \param focalLength focal length of optical system in mm (mostly obtained from camera calibration) + \param interPixelDistance distance between adjacent pixels in mm for x and y direction + \param principalPoint coordinates of principal point on image plane in pixel + \param calculateDistance if this flag is set, the distance value is stored in the z position of the output otherwise z=0 + \return a ToFPoint3D. (int)ToFPoint3D[0]+0.5 and (int)ToFPoint3D[0]+0.5 will return the x and y index coordinates. ToFPoint3D[2] contains the distance value + */ + inline static ToFPoint3D CartesianToIndexCoordinates(ToFPoint3D cartesianPoint, ToFScalarType focalLength, + ToFPoint2D interPixelDistance, ToFPoint2D principalPoint, bool calculateDistance=true) + { + return CartesianToIndexCoordinates(cartesianPoint[0],cartesianPoint[1],cartesianPoint[2],focalLength, + interPixelDistance[0],interPixelDistance[1],principalPoint[0],principalPoint[1],calculateDistance); + } }; } #endif