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
00031 #include <sbpl_interface/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 void get_current_point3d(bresenham3d_param_t *params, int *x, int *y, int *z)
00091 {
00092 *x = params->XIndex;
00093 *y = params->YIndex;
00094 *z = params->ZIndex;
00095 }
00096
00097 int get_next_point3d(bresenham3d_param_t *params)
00098 {
00099
00100 if (params->XIndex == params->X2 && params->YIndex == params->Y2 && params->ZIndex == params->Z2)
00101 return 0;
00102
00103 if (params->UsingXYZIndex == 0)
00104 {
00105 if (params->err1 > 0) {
00106 params->YIndex += params->IncY;
00107 params->err1 -= params->dx2;
00108 }
00109 if (params->err2 > 0) {
00110 params->ZIndex += params->IncZ;
00111 params->err2 -= params->dx2;
00112 }
00113 params->err1 += params->dy2;
00114 params->err2 += params->dz2;
00115 params->XIndex += params->IncX;
00116 }
00117 else if(params->UsingXYZIndex == 1)
00118 {
00119 if (params->err1 > 0) {
00120 params->XIndex += params->IncX;
00121 params->err1 -= params->dy2;
00122 }
00123 if (params->err2 > 0) {
00124 params->ZIndex += params->IncZ;
00125 params->err2 -= params->dy2;
00126 }
00127 params->err1 += params->dx2;
00128 params->err2 += params->dz2;
00129 params->YIndex += params->IncY;
00130 }
00131 else
00132 {
00133 if (params->err1 > 0) {
00134 params->YIndex += params->IncY;
00135 params->err1 -= params->dz2;
00136 }
00137 if (params->err2 > 0) {
00138 params->XIndex += params->IncX;
00139 params->err2 -= params->dz2;
00140 }
00141 params->err1 += params->dy2;
00142 params->err2 += params->dx2;
00143 params->ZIndex += params->IncZ;
00144 }
00145 return 1;
00146 }