00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <assert.h>
00018 #include "CollisionDetectors\CD_LinearContinuous.h"
00019
00020 #include "Universe\Universe.h"
00021
00022
00023
00024 static const int maxSteps = 32;
00025 static const double cspaceResolution = 0.5;
00026
00027
00028
00029 CD_LinearContinuous::CD_LinearContinuous (const CD_LinearContinuous& right)
00030
00031
00032
00033 :
00034 CollisionDetectorBase( right ),
00035 CD_Linear( right )
00036
00037 {
00038
00039
00040 }
00041
00042 CD_LinearContinuous::CD_LinearContinuous (const Universe& universe)
00043
00044
00045
00046 :
00047 CollisionDetectorBase( universe ),
00048 CD_Linear( universe )
00049
00050 {
00051
00052
00053 }
00054
00055
00056 CD_LinearContinuous::~CD_LinearContinuous()
00057 {
00058
00059
00060 }
00061
00062 bool CD_LinearContinuous::IsCompletelyWithinObstacles(const Configuration& c1, const Configuration& c2)
00063 {
00064 return IsCompletelyWithinObstaclesNoWrapping( c1, c2 );
00065 }
00066
00067
00068 bool CD_LinearContinuous::IsInterferingLinear (const Configuration& c1, const Configuration& c2)
00069 {
00070 IncrementLinearStat();
00071 if ( useWrapping )
00072 {
00073 return IsInterferingLinearWrapping( c1, c2 );
00074 }
00075 else
00076 {
00077 return IsInterferingLinearNoWrapping( c1, c2 );
00078 }
00079 }
00080
00081 bool CD_LinearContinuous::IsCompletelyWithinObstaclesNoWrapping (const Configuration& c1, const Configuration& c2)
00082 {
00083
00084
00085
00086 Configuration offset = c2 - c1;
00087 int steps = offset.Magnitude()/cspaceResolution + 2;
00088 if (steps > maxSteps)
00089 steps = maxSteps;
00090 offset /= (steps-1);
00091 Configuration current = c1 ;
00092 for( int i = 0; i < steps; i++ )
00093 {
00094 if( !IsInterfering( current ) )
00095 {
00096 lastIntersection = current ;
00097 lastValid = lastIntersection - offset;
00098 return false ;
00099 }
00100 current += offset ;
00101 }
00102 lastValid = current;
00103 lastIntersection = current ;
00104 return true ;
00105 }
00106
00107 bool CD_LinearContinuous::IsCompletelyWithinObstaclesWrapping (const Configuration& c1, const Configuration& c2)
00108 {
00109 assert( false );
00110 return false;
00111 }
00112
00113
00114 bool CD_LinearContinuous::IsInterferingLinearNoWrapping (const Configuration& c1, const Configuration& c2)
00115 {
00116
00117
00118 Configuration offset = c2 - c1;
00119 int steps = offset.Magnitude()/cspaceResolution + 2;
00120 if (steps > maxSteps)
00121 steps = maxSteps;
00122 offset /= (steps-1);
00123 Configuration current = c1 ;
00124 for( int i = 0; i < steps; i++ )
00125 {
00126 if( IsInterfering( current ) )
00127 {
00128 lastIntersection = current ;
00129 lastValid = lastIntersection - offset;
00130 return true ;
00131 }
00132 current += offset ;
00133 }
00134 lastValid = current;
00135 lastIntersection = current ;
00136 return false ;
00137 }
00138
00139 bool CD_LinearContinuous::IsInterferingLinearWrapping (const Configuration& c1, const Configuration& c2)
00140 {
00141 assert( false );
00142 VectorN stepdisp = JointDisplacement( c1, c2 ) / ( maxSteps );
00143 Configuration current = c1;
00144
00145 int dof = c1.DOF();
00146
00147
00148 if( IsInterfering( current ) )
00149 {
00150 lastIntersection = current;
00151 return true;
00152 }
00153
00154
00155 for (int step = 0; step < maxSteps; step++ )
00156 {
00157
00158 current += stepdisp;
00159
00160
00161
00162 for (int i = 0; i < dof; i++)
00163 {
00164 double jmin = JointMin( i );
00165 double jmax = JointMax( i );
00166 if ( current[i] < jmin )
00167 {
00168 current[i] += (jmax - jmin);
00169 }
00170 else if ( current[i] > jmax )
00171 {
00172 current[i] -= (jmax - jmin);
00173 }
00174 }
00175
00176
00177 if( IsInterfering( current ) )
00178 {
00179 lastIntersection = current;
00180 return true;
00181 }
00182
00183 }
00184
00185
00186
00187
00188 return false;
00189
00190 }
00191
00192
00193
00194
00195
00196
00197