$search
00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2011, Robert Bosch LLC. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Robert Bosch nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 *********************************************************************/ 00036 #include <limits.h> 00037 #include <iomanip> 00038 #include <iostream> 00039 #include <sstream> 00040 00041 #include "vlr/displayGL.h" 00042 00043 namespace vlr { 00044 00045 template<class T> 00046 bool DisplayGL::internalPaint3d() { 00047 // static const float third = 0.333333333333333334; 00048 00049 T* data = static_cast<Image<T>*> (imgBuf)->data(); 00050 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00051 glBegin(GL_TRIANGLE_STRIP); 00052 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00053 uint32_t pos = y2 * imgBuf->paddedWidth() + x; 00054 float xf = (float) x; 00055 float yf = (float) y; 00056 00057 float val = (float) data[pos] * heightScale_; 00058 // float rval=(float)data[pos]; 00059 // float gval=(float)data[pos]; 00060 // float bval=(float)data[pos]; 00061 // glColor3f(rval, gval, bval); 00062 glColor3f(val, val, val); 00063 glVertex3f(xf, yf, val); 00064 00065 val = (float) data[pos - imgBuf->paddedWidth()] * heightScale_; 00066 glColor3f(val, val, val); 00067 glVertex3f(xf, yf + 1, val); 00068 00069 val = (float) data[pos + 1] * heightScale_; 00070 glColor3f(val, val, val); 00071 glVertex3f(xf + 1, yf, val); 00072 00073 val = (float) data[pos - imgBuf->paddedWidth() + 1] * heightScale_; 00074 glColor3f(val, val, val); 00075 glVertex3f(xf + 1, yf + 1, val); 00076 } 00077 glEnd(); 00078 } 00079 00080 return true; 00081 } 00082 00083 template<> 00084 bool DisplayGL::internalPaint3d<uint8_t>() { 00085 uint8_t* data = static_cast<Image<uint8_t>*> (imgBuf)->data(); 00086 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00087 glBegin(GL_TRIANGLE_STRIP); 00088 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00089 uint32_t pos = slice_offset_ + y2 * imgBuf->paddedWidth() + x; 00090 00091 uint8_t val = data[pos]*heightScale_; 00092 glColor3f(color_map_red_[val], color_map_green_[val], color_map_blue_[val]); 00093 glVertex3i((int32_t) x, (int32_t) y, (int32_t) val); 00094 00095 val = data[pos - imgBuf->paddedWidth()]*heightScale_; 00096 glColor3f(color_map_red_[val], color_map_green_[val], color_map_blue_[val]); 00097 glVertex3i(x, y + 1, (int32_t) val); 00098 00099 val = data[pos + 1]*heightScale_; 00100 glColor3f(color_map_red_[val], color_map_green_[val], color_map_blue_[val]); 00101 glVertex3i(x + 1, y, (int32_t) val); 00102 00103 val = data[pos - imgBuf->paddedWidth() + 1]*heightScale_; 00104 glColor3f(color_map_red_[val], color_map_green_[val], color_map_blue_[val]); 00105 glVertex3i(x + 1, y + 1, (int32_t) val); 00106 } 00107 glEnd(); 00108 } 00109 00110 return true; 00111 } 00112 00113 template<> 00114 bool DisplayGL::internalPaint3d<uint16_t>() { 00115 uint16_t* data = static_cast<Image<uint16_t>*> (imgBuf)->data(); 00116 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00117 glBegin(GL_TRIANGLE_STRIP); 00118 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00119 uint32_t pos = slice_offset_ + y2 * imgBuf->paddedWidth() + x; 00120 00121 float xf = (float) x; 00122 float yf = (float) y; 00123 00124 float val = (float) data[pos]; 00125 uint8_t index = (uint8_t)(val/USHRT_MAX*UCHAR_MAX); 00126 00127 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00128 glVertex3f(xf, yf, val*heightScale_); 00129 00130 val = data[pos - imgBuf->paddedWidth()]; 00131 index = (uint8_t)(val/USHRT_MAX*UCHAR_MAX); 00132 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00133 glVertex3f(xf, yf + 1, val*heightScale_); 00134 00135 val = data[pos + 1]; 00136 index = (uint8_t)(val/USHRT_MAX*UCHAR_MAX); 00137 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00138 glVertex3f(xf + 1, yf, val*heightScale_); 00139 00140 val = data[pos - imgBuf->paddedWidth() + 1]; 00141 index = (uint8_t)(val/USHRT_MAX*UCHAR_MAX); 00142 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00143 glVertex3f(xf + 1, yf + 1, val*heightScale_); 00144 } 00145 glEnd(); 00146 } 00147 00148 return true; 00149 } 00150 00151 template<> 00152 bool DisplayGL::internalPaint3d<int16_t>() { 00153 int16_t* data = static_cast<Image<int16_t>*> (imgBuf)->data(); 00154 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00155 glBegin(GL_TRIANGLE_STRIP); 00156 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00157 uint32_t pos = slice_offset_ + y2 * imgBuf->paddedWidth() + x; 00158 00159 float xf = (float) x; 00160 float yf = (float) y; 00161 00162 float val = (float) data[pos]; 00163 uint8_t index = (uint8_t)((val+32768)/USHRT_MAX*UCHAR_MAX); 00164 00165 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00166 glVertex3f(xf, yf, val*heightScale_); 00167 00168 val = data[pos - imgBuf->paddedWidth()]; 00169 index = (uint8_t)((val+32768)/USHRT_MAX*UCHAR_MAX); 00170 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00171 glVertex3f(xf, yf + 1, val*heightScale_); 00172 00173 val = data[pos + 1]; 00174 index = (uint8_t)((val+32768)/USHRT_MAX*UCHAR_MAX); 00175 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00176 glVertex3f(xf + 1, yf, val*heightScale_); 00177 00178 val = data[pos - imgBuf->paddedWidth() + 1]; 00179 index = (uint8_t)((val+32768)/USHRT_MAX*UCHAR_MAX); 00180 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00181 glVertex3f(xf + 1, yf + 1, val*heightScale_); 00182 } 00183 glEnd(); 00184 } 00185 00186 return true; 00187 } 00188 00189 template<> 00190 bool DisplayGL::internalPaint3d<float>() { 00191 float* data = static_cast<Image<float>*> (imgBuf)->data(); 00192 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00193 glBegin(GL_TRIANGLE_STRIP); 00194 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00195 uint32_t pos = y2 * imgBuf->paddedWidth() + x; 00196 float xf = (float) x; 00197 float yf = (float) y; 00198 00199 float val = (float) data[pos]; 00200 uint8_t index = (uint8_t)(val*UCHAR_MAX); 00201 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00202 glVertex3f(xf, yf, val*heightScale_); 00203 00204 val = (float) data[pos - imgBuf->paddedWidth()]; 00205 index = (uint8_t)(val*UCHAR_MAX); 00206 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00207 glVertex3f(xf, yf + 1, val*heightScale_); 00208 00209 val = (float) data[pos + 1]; 00210 index = (uint8_t)(val*UCHAR_MAX); 00211 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00212 glVertex3f(xf + 1, yf, val*heightScale_); 00213 00214 val = (float) data[pos - imgBuf->paddedWidth() + 1]; 00215 index = (uint8_t)(val*UCHAR_MAX); 00216 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00217 glVertex3f(xf + 1, yf + 1, val*heightScale_); 00218 } 00219 glEnd(); 00220 } 00221 00222 return true; 00223 } 00224 00225 template<> 00226 bool DisplayGL::internalPaint3d<double>() { 00227 double* data = static_cast<Image<double>*> (imgBuf)->data(); 00228 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00229 glBegin(GL_TRIANGLE_STRIP); 00230 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00231 uint32_t pos = y2 * imgBuf->paddedWidth() + x; 00232 float xf = (float) x; 00233 float yf = (float) y; 00234 00235 double val = (double) data[pos] * heightScale_; 00236 uint8_t index = (uint8_t)(val*UCHAR_MAX); 00237 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00238 glVertex3f(xf, yf, val); 00239 00240 val = (double) data[pos - imgBuf->paddedWidth()] * heightScale_; 00241 index = (uint8_t)(val*UCHAR_MAX); 00242 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00243 glVertex3f(xf, yf + 1, val); 00244 00245 val = (double) data[pos + 1] * heightScale_; 00246 index = (uint8_t)(val*UCHAR_MAX); 00247 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00248 glVertex3f(xf + 1, yf, val); 00249 00250 val = (double) data[pos - imgBuf->paddedWidth() + 1] * heightScale_; 00251 index = (uint8_t)(val*UCHAR_MAX); 00252 glColor3f(color_map_red_[index], color_map_green_[index], color_map_blue_[index]); 00253 glVertex3f(xf + 1, yf + 1, val); 00254 } 00255 glEnd(); 00256 } 00257 00258 return true; 00259 } 00260 00261 template<class T> 00262 bool DisplayGL::internalPaint3dRGB() { 00263 T* data = static_cast<Image<T>*> (imgBuf)->data(); 00264 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00265 glBegin(GL_TRIANGLE_STRIP); 00266 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00267 uint32_t pos = 3 * (y2 * imgBuf->paddedWidth() + x); 00268 float xf = (float) x; 00269 float yf = (float) y; 00270 00271 float rval = (float) data[pos]; 00272 float gval = (float) data[pos + 1]; 00273 float bval = (float) data[pos + 2]; 00274 // float val = rval; 00275 float val = third * (rval + gval + bval); 00276 glColor3f(rval, gval, bval); 00277 glVertex3f(xf, yf, val); 00278 00279 rval = (float) data[pos - 3 * imgBuf->paddedWidth()]; 00280 gval = (float) data[pos - 3 * imgBuf->paddedWidth() + 1]; 00281 bval = (float) data[pos - 3 * imgBuf->paddedWidth() + 2]; 00282 // val = rval; 00283 val = third * (rval + gval + bval); 00284 glColor3f(rval, gval, bval); 00285 glVertex3f(xf, yf + 1, val); 00286 00287 rval = (float) data[pos + 3]; 00288 gval = (float) data[pos + 3 + 1]; 00289 bval = (float) data[pos + 3 + 2]; 00290 // val = rval; 00291 val = third * (rval + gval + bval); 00292 glColor3f(rval, gval, bval); 00293 glVertex3f(xf + 1, yf, val); 00294 00295 rval = (float) data[pos - 3 * imgBuf->paddedWidth() + 3]; 00296 gval = (float) data[pos - 3 * imgBuf->paddedWidth() + 3 + 1]; 00297 bval = (float) data[pos - 3 * imgBuf->paddedWidth() + 3 + 2]; 00298 // val = rval; 00299 val = third * (rval + gval + bval); 00300 glColor3f(rval, gval, bval); 00301 glVertex3f(xf + 1, yf + 1, val); 00302 } 00303 glEnd(); 00304 } 00305 00306 return true; 00307 } 00308 00309 template<> bool DisplayGL::internalPaint3dRGB<uint8_t>() { 00310 uint8_t* data = static_cast<Image<uint8_t>*> (imgBuf)->data(); 00311 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00312 glBegin(GL_TRIANGLE_STRIP); 00313 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00314 uint32_t pos = 3 * (y2 * imgBuf->paddedWidth() + x); 00315 00316 uint8_t rval = data[pos]; 00317 uint8_t gval = data[pos + 1]; 00318 uint8_t bval = data[pos + 2]; 00319 // uint8_t val = rval; 00320 uint8_t val = third * (rval + gval + bval); 00321 glColor3ub(rval, gval, bval); 00322 glVertex3i((int32_t) x, (int32_t) y, (int32_t) val); 00323 00324 rval = data[pos - 3 * imgBuf->paddedWidth()]; 00325 gval = data[pos - 3 * imgBuf->paddedWidth() + 1]; 00326 bval = data[pos - 3 * imgBuf->paddedWidth() + 2]; 00327 // val = rval; 00328 val = third * (rval + gval + bval); 00329 glColor3ub(rval, gval, bval); 00330 glVertex3i((int32_t) x, (int32_t) y + 1, (int32_t) val); 00331 00332 rval = data[pos + 3]; 00333 gval = data[pos + 3 + 1]; 00334 bval = data[pos + 3 + 2]; 00335 // val = rval; 00336 val = third * (rval + gval + bval); 00337 glColor3ub(rval, gval, bval); 00338 glVertex3i((int32_t) x + 1, (int32_t) y, (int32_t) val); 00339 00340 rval = data[pos - 3 * imgBuf->paddedWidth() + 3]; 00341 gval = data[pos - 3 * imgBuf->paddedWidth() + 3 + 1]; 00342 bval = data[pos - 3 * imgBuf->paddedWidth() + 3 + 2]; 00343 // val = rval; 00344 val = third * (rval + gval + bval); 00345 glColor3ub(rval, gval, bval); 00346 glVertex3i((int32_t) x + 1, (int32_t) y + 1, (int32_t) val); 00347 } 00348 glEnd(); 00349 } 00350 00351 return true; 00352 } 00353 00354 template<class T, class TT> 00355 bool DisplayGL::internalPaint3dTexture() { 00356 T* data = static_cast<Image<T>*> (imgBuf)->data(); 00357 TT* texData = static_cast<Image<TT>*> (texBuf)->data(); 00358 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00359 glBegin(GL_TRIANGLE_STRIP); 00360 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00361 uint32_t pos = y2 * imgBuf->paddedWidth() + x; 00362 float xf = (float) x; 00363 float yf = (float) y; 00364 00365 float tval = (float) texData[pos]; 00366 float val = (float) data[pos]; 00367 glColor3f(tval, tval, tval); 00368 glVertex3f(xf, yf, val*heightScale_); 00369 00370 tval = (float) texData[pos - imgBuf->paddedWidth()]; 00371 val = (float) data[pos - imgBuf->paddedWidth()]; 00372 glColor3f(tval, tval, tval); 00373 glVertex3f(xf, yf + 1, val*heightScale_); 00374 00375 tval = (float) texData[pos + 1]; 00376 val = (float) data[pos + 1]; 00377 glColor3f(tval, tval, tval); 00378 glVertex3f(xf + 1, yf, val*heightScale_); 00379 00380 tval = (float) texData[pos - imgBuf->paddedWidth() + 1]; 00381 val = (float) data[pos - imgBuf->paddedWidth() + 1]; 00382 glColor3f(tval, tval, tval); 00383 glVertex3f(xf + 1, yf + 1, val*heightScale_); 00384 } 00385 glEnd(); 00386 } 00387 00388 return true; 00389 } 00390 00391 template<class T, class TT> 00392 bool DisplayGL::internalPaint3dTextureRGB() { 00393 T* data = static_cast<Image<T>*> (imgBuf)->data(); 00394 TT* texData = static_cast<Image<TT>*> (texBuf)->data(); 00395 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00396 glBegin(GL_TRIANGLE_STRIP); 00397 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00398 uint32_t texPos = 3 * (y2 * texBuf->paddedWidth() + x); 00399 uint32_t pos = y2 * imgBuf->paddedWidth() + x; 00400 float xf = (float) x; 00401 float yf = (float) y; 00402 00403 float rval = (float) texData[texPos]; 00404 float gval = (float) texData[texPos + 1]; 00405 float bval = (float) texData[texPos + 2]; 00406 float val = (float) data[pos]; 00407 glColor3f(rval, gval, bval); 00408 glVertex3f(xf, yf, val); 00409 00410 rval = (float) texData[texPos - 3 * texBuf->paddedWidth()]; 00411 gval = (float) texData[texPos - 3 * texBuf->paddedWidth() + 1]; 00412 bval = (float) texData[texPos - 3 * texBuf->paddedWidth() + 2]; 00413 val = (float) data[pos - imgBuf->paddedWidth()]; 00414 glColor3f(rval, gval, bval); 00415 glVertex3f(xf, yf + 1, val); 00416 00417 rval = (float) texData[texPos + 3]; 00418 gval = (float) texData[texPos + 3 + 1]; 00419 bval = (float) texData[texPos + 3 + 2]; 00420 val = (float) data[pos + 1]; 00421 glColor3f(rval, gval, bval); 00422 glVertex3f(xf + 1, yf, val); 00423 00424 rval = (float) texData[texPos - 3 * texBuf->paddedWidth() + 3]; 00425 gval = (float) texData[texPos - 3 * texBuf->paddedWidth() + 3 + 1]; 00426 bval = (float) texData[texPos - 3 * texBuf->paddedWidth() + 3 + 2]; 00427 val = (float) data[pos - imgBuf->paddedWidth() + 1]; 00428 glColor3f(rval, gval, bval); 00429 glVertex3f(xf + 1, yf + 1, val); 00430 } 00431 glEnd(); 00432 } 00433 00434 return true; 00435 } 00436 00437 template<> 00438 bool DisplayGL::internalPaint3dTextureRGB<uint8_t, uint8_t>() { 00439 uint8_t* data = static_cast<Image<uint8_t>*> (imgBuf)->data(); 00440 uint8_t* texData = static_cast<Image<uint8_t>*> (texBuf)->data(); 00441 for (uint32_t y = 0, y2 = imgBuf->height() - 1; y < imgBuf->height() - 1; y++, y2--) { 00442 glBegin(GL_TRIANGLE_STRIP); 00443 for (uint32_t x = 0; x < imgBuf->width() - 1; x += 2) { 00444 uint32_t texPos = 3 * (y2 * texBuf->paddedWidth() + x); 00445 uint32_t pos = y2 * imgBuf->paddedWidth() + x; 00446 00447 uint8_t rval = texData[texPos]; 00448 uint8_t gval = texData[texPos + 1]; 00449 uint8_t bval = texData[texPos + 2]; 00450 uint8_t val = data[pos]; 00451 glColor3ub(rval, gval, bval); 00452 glVertex3i((int32_t) x, (int32_t) y, (int32_t) val); 00453 00454 rval = texData[texPos - 3 * texBuf->paddedWidth()]; 00455 gval = texData[texPos - 3 * texBuf->paddedWidth() + 1]; 00456 bval = texData[texPos - 3 * texBuf->paddedWidth() + 2]; 00457 val = data[pos - imgBuf->paddedWidth()]; 00458 glColor3ub(rval, gval, bval); 00459 glVertex3i((int32_t) x, (int32_t) y + 1, (int32_t) val); 00460 00461 rval = texData[texPos + 3]; 00462 gval = texData[texPos + 3 + 1]; 00463 bval = texData[texPos + 3 + 2]; 00464 val = data[pos + 1]; 00465 glColor3ub(rval, gval, bval); 00466 glVertex3i((int32_t) x + 1, (int32_t) y, (int32_t) val); 00467 00468 rval = texData[texPos - 3 * texBuf->paddedWidth() + 3]; 00469 gval = texData[texPos - 3 * texBuf->paddedWidth() + 3 + 1]; 00470 bval = texData[texPos - 3 * texBuf->paddedWidth() + 3 + 2]; 00471 val = data[pos - imgBuf->paddedWidth() + 1]; 00472 glColor3ub(rval, gval, bval); 00473 glVertex3i((int32_t) x + 1, (int32_t) y + 1, (int32_t) val); 00474 } 00475 glEnd(); 00476 } 00477 00478 return true; 00479 } 00480 00481 // template <> bool DisplayGL::internalPaint3d<ImageBase::complex>() 00482 // { 00483 // return false; 00484 // } 00485 // template <> bool DisplayGL::internalPaint3d<ImageBase::dcomplex>() 00486 // { 00487 // return false; 00488 // } 00489 00490 00491 void DisplayGL::internalPaint3d() { 00492 activate3DMode(); 00493 glTranslatef(-0.5 * ((float) width()), -0.5 * ((float) height()), 0); // unsigned sucks... 00494 00495 // printf("- 1 - %s: EC: %i\n", __FUNCTION__, glGetError()); 00496 showGridXY = true; 00497 showGridXZ = true; 00498 showGridYZ = true; 00499 float zPos = 0, yPos = 0, xPos = 0; 00500 00501 if (showGridXY) { 00502 drawGridXY(zPos); 00503 } 00504 if (showGridXZ) { 00505 drawGridXZ(yPos); 00506 } 00507 if (showGridYZ) { 00508 drawGridYZ(xPos); 00509 } 00510 00511 // glColor4f(1, 0, 0, 1);//0.75); 00512 glColor4f(1.0, 1.0, 1.0, 1.0); 00513 if (imgBuf) { 00514 // TODO: Texture and data can have different types... 00515 if (useTexture && texBuf && texBuf->colorSpace() == ImageBase::CS_RGB_C) { 00516 glEnable(GL_TEXTURE_2D); 00517 //glEnable(GL_TEXTURE_RECTANGLE_ARB); 00518 glBindTexture(texType, imgTexture); 00519 switch(data_type_) { 00520 case TYPE_UCHAR: 00521 internalPaint3dTextureRGB<uint8_t, uint8_t> (); 00522 break; 00523 00524 case TYPE_CHAR: 00525 internalPaint3dTextureRGB<int8_t, int8_t> (); 00526 break; 00527 00528 case TYPE_USHORT: 00529 internalPaint3dTextureRGB<uint16_t, uint16_t> (); 00530 break; 00531 00532 case TYPE_SHORT: 00533 internalPaint3dTextureRGB<int16_t, int16_t> (); 00534 break; 00535 00536 case TYPE_UINT: 00537 internalPaint3dTextureRGB<uint32_t, uint32_t> (); 00538 break; 00539 00540 case TYPE_INT: 00541 internalPaint3dTextureRGB<int32_t, int32_t> (); 00542 break; 00543 00544 case TYPE_FLOAT: 00545 internalPaint3dTextureRGB<float, float> (); 00546 break; 00547 00548 case TYPE_DOUBLE: 00549 // internalPaint3dTextureRGB<double, double> (); 00550 internalPaint3dTextureRGB<float, float> (); // TODO: Make double work?!? 00551 break; 00552 } 00553 00554 glDisable(GL_TEXTURE_2D); 00555 glDisable(GL_TEXTURE_RECTANGLE_ARB); 00556 } 00557 else if (imgBuf->colorSpace() == ImageBase::CS_RGB_C) { 00558 switch(data_type_) { 00559 case TYPE_UCHAR: 00560 internalPaint3dRGB<uint8_t> (); 00561 break; 00562 00563 case TYPE_CHAR: 00564 internalPaint3dRGB<int8_t> (); 00565 break; 00566 00567 case TYPE_USHORT: 00568 internalPaint3dRGB<uint16_t> (); 00569 break; 00570 00571 case TYPE_SHORT: 00572 internalPaint3dRGB<int16_t> (); 00573 break; 00574 00575 case TYPE_UINT: 00576 internalPaint3dRGB<uint32_t> (); 00577 break; 00578 00579 case TYPE_INT: 00580 internalPaint3dRGB<int32_t> (); 00581 break; 00582 00583 case TYPE_FLOAT: 00584 internalPaint3dRGB<float> (); 00585 break; 00586 00587 case TYPE_DOUBLE: 00588 internalPaint3dRGB<float> (); // TODO: Make double work?!? 00589 // internalPaint3dRGB<double> (); 00590 break; 00591 } 00592 } 00593 else if (useTexture && texBuf && texBuf->colorSpace() == ImageBase::CS_GRAY) { 00594 switch(data_type_) { 00595 case TYPE_UCHAR: 00596 internalPaint3dTexture<uint8_t, uint8_t> (); 00597 break; 00598 00599 case TYPE_CHAR: 00600 internalPaint3dTexture<int8_t, int8_t> (); 00601 break; 00602 00603 case TYPE_USHORT: 00604 internalPaint3dTexture<uint16_t, uint16_t> (); 00605 break; 00606 00607 case TYPE_SHORT: 00608 internalPaint3dTexture<int16_t, int16_t> (); 00609 break; 00610 00611 case TYPE_UINT: 00612 internalPaint3dTexture<uint32_t, uint32_t> (); 00613 break; 00614 00615 case TYPE_INT: 00616 internalPaint3dTexture<int32_t, int32_t> (); 00617 break; 00618 00619 case TYPE_FLOAT: 00620 internalPaint3dTexture<float, float> (); 00621 break; 00622 00623 case TYPE_DOUBLE: 00624 // internalPaint3dTextureRGB<double, double> (); 00625 internalPaint3dTexture<float, float> (); // TODO: Make double work?!? 00626 break; 00627 } 00628 } 00629 else { 00630 // printf("- 3b - %s: EC: %i\n", __FUNCTION__, glGetError()); 00631 switch(data_type_) { 00632 case TYPE_UCHAR: 00633 internalPaint3d<uint8_t> (); 00634 break; 00635 00636 case TYPE_CHAR: 00637 internalPaint3d<int8_t> (); 00638 break; 00639 00640 case TYPE_USHORT: 00641 internalPaint3d<uint16_t> (); 00642 break; 00643 00644 case TYPE_SHORT: 00645 internalPaint3d<int16_t> (); 00646 break; 00647 00648 case TYPE_UINT: 00649 internalPaint3d<uint32_t> (); 00650 break; 00651 00652 case TYPE_INT: 00653 internalPaint3d<int32_t> (); 00654 break; 00655 00656 case TYPE_FLOAT: 00657 internalPaint3d<float> (); 00658 break; 00659 00660 case TYPE_DOUBLE: 00661 // internalPaint3d<double> (); 00662 internalPaint3d<float> (); // TODO: Make double work?!? 00663 break; 00664 } 00665 } 00666 // drawTags3D(); 00667 drawCustomTags3d(); 00668 } 00669 } 00670 00671 void DisplayGL::drawGridXY(float zPos) { 00672 float grid_x, grid_y; 00673 float xMin = 0; 00674 float xMax = (imgBuf ? imgBuf->width() : width()); 00675 float yMin = 0; 00676 float yMax = (imgBuf ? imgBuf->height() : height()); 00677 float xStep = (xMax - xMin) / 10; 00678 float yStep = (yMax - yMin) / 10; 00679 00680 glLineWidth(0.5); 00681 glEnable(GL_BLEND); 00682 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00683 00684 glEnable(GL_LINE_SMOOTH); 00685 // glColor3f(0.4, 0.4, 0.4); 00686 glColor3f(1.0, 0, 0); 00687 glBegin(GL_LINES); 00688 for (grid_x = xMin; grid_x <= xMax; grid_x += xStep) { 00689 glVertex3f(grid_x, yMin, zPos); 00690 glVertex3f(grid_x, yMax, zPos); 00691 } 00692 for (grid_y = yMin; grid_y <= yMax; grid_y += yStep) { 00693 glVertex3f(xMin, grid_y, zPos); 00694 glVertex3f(xMax, grid_y, zPos); 00695 } 00696 glEnd(); 00697 00698 std::stringstream label; 00699 double x_offset=10; 00700 double y_offset=16; 00701 for (grid_x = xMin; grid_x <= xMax; grid_x += xStep) { 00702 label.str(""); 00703 label << std::fixed << std::setprecision(3) << grid_x; 00704 fr.drawString2D(label.str(), float(grid_x+x_offset), float(yMax + y_offset)); 00705 } 00706 00707 00708 glDisable(GL_LINE_SMOOTH); 00709 glDisable(GL_BLEND); 00710 } 00711 00712 void DisplayGL::drawGridXZ(float yPos) { 00713 float grid_x, grid_z; 00714 float xMin = 0; 00715 float xMax = (imgBuf ? imgBuf->width() : width()); 00716 float zMin = 0, zMax = 500; 00717 float xStep = (xMax - xMin) / 10; 00718 float zStep = (zMax - zMin) / 10; 00719 00720 glLineWidth(0.5); 00721 glEnable(GL_BLEND); 00722 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00723 00724 glEnable(GL_LINE_SMOOTH); 00725 // glColor3f(0.4, 0.4, 0.4); 00726 glColor3f(1.0, 0, 0); 00727 glBegin(GL_LINES); 00728 for (grid_x = xMin; grid_x <= xMax; grid_x += xStep) { 00729 glVertex3f(grid_x, yPos, zMin); 00730 glVertex3f(grid_x, yPos, zMax); 00731 } 00732 for (grid_z = zMin; grid_z <= zMax; grid_z += zStep) { 00733 glVertex3f(xMin, yPos, grid_z); 00734 glVertex3f(xMax, yPos, grid_z); 00735 } 00736 glEnd(); 00737 00738 glDisable(GL_LINE_SMOOTH); 00739 glDisable(GL_BLEND); 00740 } 00741 00742 void DisplayGL::drawGridYZ(float xPos) { 00743 if (xPos) { 00744 } 00745 } 00746 00747 } // namespace vlr