rangetocoords.cpp
Go to the documentation of this file.
00001 /*
00002  * rangetocoords.cpp
00003  *
00004  *  cpp-port for seg comp c-sourcecode
00005  *  see ftp://figment.csee.usf.edu/pub/segmentation-comparison/range-to-coords.c
00006  */
00007 
00008 #include <structureColoring/segcomp/rangetocoords.h>
00009 #include <stdio.h>
00010 #include <math.h>
00011 
00012 #define UNDEFINED_PT    -1.0
00013 
00014 
00015 
00016 /*
00017 **      Convert Perceptron image to 3D cartesian coordinates.
00018 **
00019 **
00020 **                                   beta > 0
00021 **
00022 **                                       ^ y
00023 **                      alpha > 0        |        alpha < 0
00024 ** Seen from camera:              x <----|----                (z-axis points
00025 **                                                             out of camera)
00026 **
00027 **                                   beta < 0
00028 */
00029 //short int     *RangeImage;
00030 //double                *P[3];
00031 //int           ROWS,COLS;
00032 
00033 void ConvertPerceptronRangeToCartesian(short int* RangeImage, double *P[3], int ROWS, int COLS)
00034 {
00035 double          ra, r_0, r_1, r_2, r_3, h_1, h_2, dx, dy, dz;
00036 double          alpha, beta, alpha_0, beta_0;
00037                         /* alpha = Horizontal, beta = Vertical angle */
00038 double          gamma, theta;
00039 double          H,V,delta;
00040 int             r,c;
00041 
00042 h_1=3.0;                        /* dist (y) between rotating mirror axis
00043                                 ** and the parallel laser beam. */
00044 h_2=5.5;                        /* dist (y) between nodding mirror axis
00045                                 ** and rotating mirror laser intersection. */
00046 gamma=45.0*(M_PI/180.0);        /* slope of rotating mirror */
00047 theta=45.0*(M_PI/180.0);        /* slope of nodding mirror in mid position */
00048 alpha_0=beta_0=0.0;
00049 H=51.65;
00050 V=36.73;
00051 r_0=830.3;
00052 delta=0.20236;
00053 
00054 for (r=0; r<ROWS; r++)
00055   {
00056   for (c=0; c<COLS; c++)
00057     {
00058     alpha = alpha_0 + H*(255.5 - c)/512.0;
00059     alpha = alpha*M_PI/180.0;
00060     beta  = beta_0  + V*(255.5 - r)/512.0;
00061     beta  = beta*M_PI/180.0;
00062 
00063         /* (dx,dy,dz): where the laser leaves the nodding mirror */
00064 
00065     dz = -(h_1*(1.0-cos(alpha))/tan(gamma));/* Motion of the laser intersection
00066                                                point with the rotating mirror
00067                                                as a function of alpha. */
00068 
00069     dy = dz*tan(theta + 0.5*beta);  /* Vertical offset of nodding mirror
00070                                        intersection due to dz */
00071 
00072     dx = (h_2 + dy)*tan(alpha);     /* Horizontal offset of laser intersection
00073                                        point with nodding mirror due to alpha */
00074 
00075         /*
00076         ** R  : true range: laser light path length (laser travel) from
00077         **      laser emission point to target.
00078         ** ra : range value returned by camera.
00079         ** r_0: (standoff distance) length of laser ray to point for which r=0
00080         ** r_1: laser travel (z) from laserdiode to intersection with rotating
00081         **      mirror: r1 = d1 + dz
00082         ** r_2: laser travel (vector length) from rotating mirror
00083         **      to nodding mirror.
00084         ** r_3: laser travel (vector length) from nodding mirror to target.
00085         **
00086         ** Thus: R = r + r0 = r1 + r2 + r3
00087         */
00088 
00089     ra  = (double) RangeImage[r*COLS+c]; /* range returned by camera */
00090 
00091     r_1 = (dz - h_2)/delta;
00092     r_2 = sqrt(dx*dx + (h_2+dy)*(h_2+dy))/delta;
00093     r_3 = (ra + r_0 - (r_1 +r_2))*delta;
00094 
00095     P[0][r*COLS+c] = dx + r_3 * sin(alpha);
00096     P[1][r*COLS+c] = dy + r_3 * cos(alpha)*sin(beta);
00097     P[2][r*COLS+c] = dz + r_3 * cos(alpha)*cos(beta);
00098     }
00099   }
00100 }
00101 
00102 /*
00103  *      This routine converts an ABW range image to 3D cartesian coordinates.
00104  */
00105 void ConvertABWRangeToCartesian(const unsigned char* RangeImage, const int width, const int height, double* P[3], const int cal)
00106 {
00107         int r, c;
00108         double OFFSET;
00109         double SCAL;
00110         double F;
00111         double C;
00112 
00113         if (cal == 1) {
00114                 OFFSET = 785.410786;
00115                 SCAL = 0.773545;
00116                 F = -1610.981722;
00117                 C = 1.4508;
00118         } else {
00119                 OFFSET = 771.016866;
00120                 SCAL = 0.791686;
00121                 F = -1586.072821;
00122                 C = 1.4508;
00123         }
00124 
00125         for (r = 0; r < height; r++) {
00126                 for (c = 0; c < width; c++) {
00127                         size_t idx = r * width + c;
00128                         if (RangeImage[idx] == 0) {
00129                                 P[0][idx] = P[1][idx] = P[2][idx]
00130                                                 =UNDEFINED_PT;
00131                                 continue;
00132                         }
00133                         P[0][idx] = (double) (c - 255) * ((double) RangeImage[idx] / SCAL + OFFSET) / fabs(F);
00134                         P[1][idx] = (double) (-r + 255) / C * ((double) RangeImage[idx] / SCAL + OFFSET)
00135                                         / fabs(F);
00136                         P[2][idx] = (double) (255 - RangeImage[idx]) / SCAL;
00137                 }
00138         }
00139 }
00140 
00141 /*
00142  *      This routine converts a synthetic image created by `image-make'
00143  *      (used for the creating synthetic range images for the evaluation)
00144  *      into 3D cartesian coordinates.
00145  */
00146 void ConvertIMakeRangeToCartesian(unsigned char* RangeImage, double* P[3])
00147 {
00148 int             r,c;
00149 double          HORIZONTAL_FOV=60.0;
00150 double          VERTICAL_FOV=60.0;
00151 int             IMAGE_ROWS=512;
00152 int             IMAGE_COLS=512;
00153 double          RayX,RayY;
00154 
00155 for (r=0; r<512; r++)
00156   {
00157   for (c=0; c<512; c++)
00158     {
00159     if (RangeImage[r*512+c] == 0)
00160       {
00161       P[0][r*512+c]=P[1][r*512+c]=P[2][r*512+c]=UNDEFINED_PT;
00162       continue;
00163       }
00164         /* Compute angles (orthogonal-axis coordinate system) for pixel,
00165         ** located at the _center_ of the pixel */
00166     RayX=((-HORIZONTAL_FOV/2.0)+((double)r+0.5)*
00167                 (HORIZONTAL_FOV/(double)IMAGE_ROWS))*M_PI/180.0;
00168     RayY=((-VERTICAL_FOV/2.0)+((double)c+0.5)*
00169                 (VERTICAL_FOV/(double)IMAGE_COLS))*M_PI/180.0;
00170     P[2][r*512+c]=(double)RangeImage[r*512+c]/sqrt(1.0+
00171         (tan(RayY)*tan(RayY))+(tan(RayX)*tan(RayX)));
00172     P[1][r*512+c]=P[2][r*512+c]*tan(RayY);
00173     P[0][r*512+c]=P[2][r*512+c]*tan(RayX);
00174     }
00175   }
00176 }


structure_coloring_fkie
Author(s): Bastian Gaspers
autogenerated on Sun Jan 5 2014 11:38:09