00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkSpatialOrientationAdapter.h,v $ 00005 Language: C++ 00006 Date: $Date: 2007-12-24 16:46:28 $ 00007 Version: $Revision: 1.6 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 Portions of this code are covered under the VTK copyright. 00013 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. 00014 00015 This software is distributed WITHOUT ANY WARRANTY; without even 00016 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00017 PURPOSE. See the above copyright notices for more information. 00018 00019 =========================================================================*/ 00020 #ifndef __itkSpatialOrientationAdapter_h 00021 #define __itkSpatialOrientationAdapter_h 00022 #include "itkOrientationAdapter.h" 00023 #include "itkSpatialOrientation.h" 00024 #include "itkConceptChecking.h" 00025 00026 namespace itk 00027 { 00028 00029 // 00030 // Helper functions, better than Macros 00031 // 00032 namespace Function 00033 { 00034 00035 inline unsigned Max3(double x, double y, double z) 00036 { 00037 const double obliquityThresholdCosineValue = 0.001; 00038 00039 double absX = vnl_math_abs(x); 00040 double absY = vnl_math_abs(y); 00041 double absZ = vnl_math_abs(z); 00042 00043 if ( ( absX > obliquityThresholdCosineValue ) && ( absX > absY ) && ( absX > absZ )) 00044 { 00045 return 0; 00046 } 00047 else if ( ( absY > obliquityThresholdCosineValue ) && ( absY > absX ) && ( absY > absZ ) ) 00048 { 00049 return 1; 00050 } 00051 else if ( ( absZ > obliquityThresholdCosineValue ) && ( absZ > absX ) && ( absZ > absY ) ) 00052 { 00053 return 2; 00054 } 00055 // they must all be equal, so just say x 00056 return 0; 00057 } 00058 00059 inline int Sign(double x) 00060 { 00061 if(x < 0) 00062 { 00063 return -1; 00064 } 00065 return 1; 00066 } 00067 00068 } // namespace Function 00069 00070 00071 00075 class ITKCommon_EXPORT SpatialOrientationAdapter : 00076 public OrientationAdapterBase<SpatialOrientation::ValidCoordinateOrientationFlags,3> 00077 { 00078 public: 00080 typedef SpatialOrientationAdapter Self; 00081 00082 typedef OrientationAdapterBase<SpatialOrientation::ValidCoordinateOrientationFlags,3> 00083 SuperClass; 00084 00085 typedef SpatialOrientation::ValidCoordinateOrientationFlags OrientationType; 00086 00088 typedef SuperClass::DirectionType DirectionType; 00089 00091 SpatialOrientationAdapter() {}; 00092 00094 virtual OrientationType FromDirectionCosines(const DirectionType &Dir); 00095 00097 virtual DirectionType ToDirectionCosines(const OrientationType &Or); 00098 00099 }; 00100 00101 } // namespace itk 00102 00103 #endif // __itkSpatialOrientationAdapter_h 00104