Go to the documentation of this file.00001 #pragma init (register_c_pointcloud_message_converter)
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <unistd.h>
00005 #include <string.h>
00006 #include <math.h>
00007 #include <sys/time.h>
00008 #include "eus.h"
00009
00010 extern pointer ___roseus_c_util();
00011 static register_roseus_c_util()
00012 { add_module_initializer("___roseus_c_util", ___roseus_c_util);}
00013
00014 #define colsize(p) (intval(p->c.ary.dim[1]))
00015 #define rowsize(p) (intval(p->c.ary.dim[0]))
00016 #define ismatrix(p) ((isarray(p) && \
00017 p->c.ary.rank==makeint(2) && \
00018 elmtypeof(p->c.ary.entity)==ELM_FLOAT))
00019 #define ckvsize(a,b) ((a->c.vec.size==b->c.vec.size)?vecsize(a):(int)error(E_VECINDEX))
00020
00021 pointer CONV_MSG2_PC (ctx,n,argv)
00022 register context *ctx;
00023 int n;
00024 register pointer argv[];
00025 {
00026 numunion nu;
00027 int i, nanflag;
00028 int step, size, bufsize;
00029 int pos_x, pos_y, pos_z;
00030 int pos_nx, pos_ny, pos_nz;
00031 int pos_rgb;
00032 eusfloat_t *mat, *nmat, *cmat;
00033 char *data;
00034
00035
00036
00037 ckarg(14);
00038
00039 if ((!ismatrix(argv[3])) && NIL != argv[3]) {
00040 error(E_TYPEMISMATCH);
00041 }
00042 if ((!ismatrix(argv[7])) && NIL != argv[7]) {
00043 error(E_TYPEMISMATCH);
00044 }
00045 if ((!ismatrix(argv[11])) && NIL != argv[11]) {
00046 error(E_TYPEMISMATCH);
00047 }
00048
00049 if (!isstring(argv[0])) error(E_TYPEMISMATCH);
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 step = ckintval(argv[1]);
00061 size = ckintval(argv[2]);
00062
00063 nanflag = ckintval(argv[13]);
00064
00065 data = argv[0]->c.str.chars;
00066 if ( NIL != argv[3] ) {
00067 mat = argv[3]->c.ary.entity->c.fvec.fv;
00068 pos_x = ckintval(argv[4]);
00069 pos_y = ckintval(argv[5]);
00070 pos_z = ckintval(argv[6]);
00071 } else {
00072 mat = NULL;
00073 }
00074 if ( NIL != argv[7] ) {
00075 nmat = argv[7]->c.ary.entity->c.fvec.fv;
00076 pos_nx = ckintval(argv[8]);
00077 pos_ny = ckintval(argv[9]);
00078 pos_nz = ckintval(argv[10]);
00079 } else {
00080 nmat = NULL;
00081 }
00082 if ( NIL != argv[11] ) {
00083 cmat = argv[11]->c.ary.entity->c.fvec.fv;
00084 pos_rgb = ckintval(argv[12]);
00085 } else {
00086 cmat = NULL;
00087 }
00088
00089 for( i = 0; i < size; i++, data += step ) {
00090 if (mat != NULL) {
00091 *mat++ = ( *((float *)(data + pos_x)) ) * 1000.0;
00092 *mat++ = ( *((float *)(data + pos_y)) ) * 1000.0;
00093 *mat++ = ( *((float *)(data + pos_z)) ) * 1000.0;
00094 }
00095 if (nmat != NULL) {
00096 *nmat++ = *((float *)(data + pos_nx));
00097 *nmat++ = *((float *)(data + pos_ny));
00098 *nmat++ = *((float *)(data + pos_nz));
00099 }
00100 if (cmat != NULL) {
00101 int rgb = *((int *) (data + pos_rgb));
00102 *cmat++ = ( ((rgb >> 16) & 0x000000FF) / 255.0 );
00103 *cmat++ = ( ((rgb >> 8) & 0x000000FF) / 255.0 );
00104 *cmat++ = ( (rgb & 0x000000FF) / 255.0 );
00105 }
00106 }
00107
00108 if (nanflag > 0) {
00109
00110 if ( mat != NULL ) { mat--; }
00111 if ( cmat != NULL ) { cmat--; }
00112 for( i = 0; i < size; i++ ) {
00113 if ( mat != NULL ) {
00114 if ( isnan(*mat) ) {
00115 *mat-- = 0.0;
00116 *mat-- = 0.0;
00117 *mat-- = 0.0;
00118 } else {
00119 mat -= 3;
00120 }
00121 }
00122 if ( cmat != NULL ) {
00123 if ( isnan(*cmat) ) {
00124 *cmat-- = 0.0;
00125 *cmat-- = 0.0;
00126 *cmat-- = 0.0;
00127 } else {
00128 cmat -= 3;
00129 }
00130 }
00131 }
00132 }
00133
00134 return NIL;
00135 }
00136
00137 pointer CONV_PC_MSG2 (ctx,n,argv)
00138 register context *ctx;
00139 int n;
00140 register pointer argv[];
00141 {
00142 numunion nu;
00143 int i, step, size;
00144 eusfloat_t *mat, *nmat, *cmat;
00145 char *data;
00146
00147
00148 ckarg(6);
00149
00150 if (!isstring(argv[0])) error(E_TYPEMISMATCH);
00151
00152 if ((!ismatrix(argv[3])) && NIL != argv[3]) {
00153 error(E_TYPEMISMATCH);
00154 }
00155 if ((!ismatrix(argv[4])) && NIL != argv[4]) {
00156 error(E_TYPEMISMATCH);
00157 }
00158 if ((!ismatrix(argv[5])) && NIL != argv[5]) {
00159 error(E_TYPEMISMATCH);
00160 }
00161
00162 size = ckintval(argv[1]);
00163 step = ckintval(argv[2]);
00164
00165 data = argv[0]->c.str.chars;
00166
00167 if ( NIL != argv[3] ) {
00168 mat = argv[3]->c.ary.entity->c.fvec.fv;
00169 } else {
00170 mat = NULL;
00171 }
00172 if ( NIL != argv[4] ) {
00173 cmat = argv[4]->c.ary.entity->c.fvec.fv;
00174 } else {
00175 cmat = NULL;
00176 }
00177 if ( NIL != argv[5] ) {
00178 nmat = argv[5]->c.ary.entity->c.fvec.fv;
00179 } else {
00180 nmat = NULL;
00181 }
00182
00183 for( i = 0; i < size; i++, data += step ) {
00184 float *tmp = (float *)data;
00185 if (mat != NULL) {
00186 *tmp++ = (*mat++) * 0.001;
00187 *tmp++ = (*mat++) * 0.001;
00188 *tmp++ = (*mat++) * 0.001;
00189 }
00190 if (cmat != NULL) {
00191 int r = (floor ((*cmat++) * 255));
00192 int g = (floor ((*cmat++) * 255));
00193 int b = (floor ((*cmat++) * 255));
00194
00195 *((int *)tmp) = ((r & 0x000000FF) << 16) | ((g & 0x000000FF) << 8) | (b & 0x000000FF);
00196 tmp++;
00197 }
00198 if (nmat != NULL) {
00199 *tmp++ = *nmat++;
00200 *tmp++ = *nmat++;
00201 *tmp++ = *nmat++;
00202 *tmp++ = 0.0;
00203 }
00204 }
00205
00206 return NIL;
00207 }
00208
00209 pointer ___roseus_c_util(ctx,n, argv, env)
00210 register context *ctx;int n;pointer *argv;pointer env;
00211 {
00212 defun(ctx,"CONVERT-MSG2-POINTCLOUD", argv[0], CONV_MSG2_PC);
00213 defun(ctx,"CONVERT-POINTCLOUD-MSG2", argv[0], CONV_PC_MSG2);
00214 }
00215