Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "cmtkIntersection.h"
00034
00035 #include <Base/cmtkMathUtil.h>
00036
00037 namespace
00038 cmtk
00039 {
00040
00043
00044 int
00045 Intersection::IntersectX
00046 ( Types::Coordinate& fromFactor, Types::Coordinate& toFactor,
00047 const Vector3D& offset, const Vector3D& dX,
00048 const Types::Coordinate Size[3], const Types::Coordinate initFromFactor,
00049 const Types::Coordinate initToFactor, const int lowerClosed,
00050 const int upperClosed )
00051 {
00052 fromFactor = initFromFactor;
00053 toFactor = initToFactor;
00054
00055 for ( int dim=0; dim<3; ++dim )
00056 {
00057 if ( dX[dim] > 0 )
00058 {
00059 fromFactor = std::max( fromFactor, -offset[dim] / dX[dim] );
00060 toFactor = std::min( toFactor, (Size[dim] - offset[dim]) / dX[dim] );
00061 }
00062 else
00063 if ( dX[dim] < 0 )
00064 {
00065 fromFactor = std::max( fromFactor, (Size[dim] - offset[dim]) / dX[dim] );
00066 toFactor = std::min( toFactor, -offset[dim] / dX[dim] );
00067 }
00068 else
00069 {
00070 if ( (offset[dim] < 0) ||
00071 ( (offset[dim] == 0) && lowerClosed ) ||
00072 (offset[dim] > Size[dim]) ||
00073 ( (offset[dim] == Size[dim]) && upperClosed ) )
00074 {
00075 fromFactor = toFactor = 0;
00076 return 0;
00077 }
00078 }
00079 }
00080 return !( fromFactor > toFactor );
00081 }
00082
00083 int
00084 Intersection::IntersectY
00085 ( Types::Coordinate& fromFactor, Types::Coordinate& toFactor,
00086 const Vector3D& offset, const Vector3D& dX,
00087 const Vector3D& dY, const Types::Coordinate Size[3],
00088 const Types::Coordinate initFromFactor, const Types::Coordinate initToFactor )
00089 {
00090 fromFactor = initFromFactor;
00091 toFactor = initToFactor;
00092
00093 for ( int dim=0; dim<3; ++dim )
00094 {
00095 const Types::Coordinate axmin = std::min<Types::Coordinate>( 0, dX[dim] );
00096 const Types::Coordinate axmax = std::max<Types::Coordinate>( 0, dX[dim] );
00097
00098 if ( dY[dim] > 0 )
00099 {
00100 fromFactor = std::max( fromFactor, - (offset[dim]+axmax) / dY[dim] );
00101 toFactor = std::min( toFactor, (Size[dim] - (offset[dim]+axmin)) / dY[dim] );
00102 }
00103 else
00104 if ( dY[dim] < 0 )
00105 {
00106 fromFactor = std::max( fromFactor, (Size[dim] - (offset[dim]+axmin)) / dY[dim] );
00107 toFactor = std::min( toFactor, - (offset[dim]+axmax) / dY[dim] );
00108 }
00109 else
00110 {
00111 if ( (axmax + offset[dim] < 0) || (axmin + offset[dim] > Size[dim]) )
00112 {
00113 fromFactor = toFactor = 0;
00114 return 0;
00115 }
00116 }
00117 }
00118 return !( fromFactor > toFactor );
00119 }
00120
00121 int
00122 Intersection::IntersectZ
00123 ( Types::Coordinate& fromFactor, Types::Coordinate& toFactor,
00124 const Vector3D& offset, const Vector3D& dX,
00125 const Vector3D& dY, const Vector3D& dZ,
00126 const Types::Coordinate Size[3], const Types::Coordinate initFromFactor,
00127 const Types::Coordinate initToFactor )
00128 {
00129 fromFactor = initFromFactor;
00130 toFactor = initToFactor;
00131
00132 for ( int dim=0; dim<3; ++dim )
00133 {
00134 const Types::Coordinate axmin = std::min<Types::Coordinate>( 0, dX[dim] );
00135 const Types::Coordinate axmax = std::max<Types::Coordinate>( 0, dX[dim] );
00136 const Types::Coordinate bymin = std::min<Types::Coordinate>( 0, dY[dim] );
00137 const Types::Coordinate bymax = std::max<Types::Coordinate>( 0, dY[dim] );
00138
00139 if ( dZ[dim] > 0 )
00140 {
00141 fromFactor = std::max( fromFactor, - (offset[dim]+axmax+bymax) / dZ[dim] );
00142 toFactor = std::min( toFactor, (Size[dim] - (offset[dim]+axmin+bymin)) / dZ[dim] );
00143 }
00144 else
00145 if ( dZ[dim] < 0 )
00146 {
00147 fromFactor = std::max( fromFactor, (Size[dim] - (offset[dim]+axmin+bymin)) / dZ[dim] );
00148 toFactor = std::min( toFactor, - (offset[dim]+axmax+bymax) / dZ[dim] );
00149 }
00150 else
00151 {
00152 if ( (axmax + bymax + offset[dim] < 0) || (axmin + bymin + offset[dim] > Size[dim]) )
00153 {
00154 fromFactor = toFactor = 0;
00155 return 0;
00156 }
00157 }
00158 }
00159 return !( fromFactor > toFactor );
00160 }
00161
00162 }