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
00031 #include <sbpl_arm_planner/bresenham.h>
00032
00033 void get_bresenham3d_parameters(int p1x, int p1y, int p1z, int p2x, int p2y, int p2z, bresenham3d_param_t *params)
00034 {
00035 params->X1=p1x;
00036 params->Y1=p1y;
00037 params->Z1=p1z;
00038 params->X2=p2x;
00039 params->Y2=p2y;
00040 params->Z2=p2z;
00041
00042 params->XIndex = params->X1;
00043 params->YIndex = params->Y1;
00044 params->ZIndex = params->Z1;
00045
00046 params->dx = fabs((double)(p2x-p1x));
00047 params->dy = fabs((double)(p2y-p1y));
00048 params->dz = fabs((double)(p2z-p1z));
00049 params->dx2 = params->dx << 1;
00050 params->dy2 = params->dy << 1;
00051 params->dz2 = params->dz << 1;
00052
00053
00054 if((double)(p2x-p1x) < 0)
00055 params->IncX = -1;
00056 else
00057 params->IncX = 1;
00058
00059 if((double)(p2y-p1y) < 0)
00060 params->IncY = -1;
00061 else
00062 params->IncY = 1;
00063
00064 if((double)(p2z-p1z) < 0)
00065 params->IncZ = -1;
00066 else
00067 params->IncZ = 1;
00068
00069
00070 if(params->dx >= params->dy && params->dx >= params->dz)
00071 {
00072 params->UsingXYZIndex = 0;
00073 params->err1 = params->dy2 - params->dx;
00074 params->err2 = params->dz2 - params->dx;
00075 }
00076 else if(params->dy >= params->dx && params->dy >= params->dz)
00077 {
00078 params->UsingXYZIndex = 1;
00079 params->err1 = params->dx2 - params->dy;
00080 params->err2 = params->dz2 - params->dy;
00081 }
00082 else
00083 {
00084 params->UsingXYZIndex = 2;
00085 params->err1 = params->dy2 - params->dz;
00086 params->err2 = params->dx2 - params->dz;
00087 }
00088 }
00089
00090
00091 void get_current_point3d(bresenham3d_param_t *params, int *x, int *y, int *z)
00092 {
00093 *x = params->XIndex;
00094 *y = params->YIndex;
00095 *z = params->ZIndex;
00096 }
00097
00098
00099 int get_next_point3d(bresenham3d_param_t *params)
00100 {
00101
00102 if (params->XIndex == params->X2 && params->YIndex == params->Y2 && params->ZIndex == params->Z2)
00103 {
00104
00105 return 0;
00106 }
00107
00108 if (params->UsingXYZIndex == 0)
00109 {
00110 if (params->err1 > 0) {
00111 params->YIndex += params->IncY;
00112 params->err1 -= params->dx2;
00113 }
00114 if (params->err2 > 0) {
00115 params->ZIndex += params->IncZ;
00116 params->err2 -= params->dx2;
00117 }
00118 params->err1 += params->dy2;
00119 params->err2 += params->dz2;
00120 params->XIndex += params->IncX;
00121 }
00122 else if(params->UsingXYZIndex == 1)
00123 {
00124 if (params->err1 > 0) {
00125 params->XIndex += params->IncX;
00126 params->err1 -= params->dy2;
00127 }
00128 if (params->err2 > 0) {
00129 params->ZIndex += params->IncZ;
00130 params->err2 -= params->dy2;
00131 }
00132 params->err1 += params->dx2;
00133 params->err2 += params->dz2;
00134 params->YIndex += params->IncY;
00135 }
00136 else
00137 {
00138 if (params->err1 > 0) {
00139 params->YIndex += params->IncY;
00140 params->err1 -= params->dz2;
00141 }
00142 if (params->err2 > 0) {
00143 params->XIndex += params->IncX;
00144 params->err2 -= params->dz2;
00145 }
00146 params->err1 += params->dy2;
00147 params->err2 += params->dx2;
00148 params->ZIndex += params->IncZ;
00149 }
00150 return 1;
00151 }
00152