Changeset 2853 for trunk/packages/vizservers/nanovis
- Timestamp:
- Mar 14, 2012 1:14:22 AM (12 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/ScreenSnapper.cpp
r2822 r2853 18 18 19 19 #include <memory.h> 20 #include <assert.h> 21 22 #include "ScreenSnapper.h" 20 23 #include "Trace.h" 21 #include <assert.h>22 #include "ScreenSnapper.h"23 24 24 25 ScreenSnapper::ScreenSnapper(int w, int h, GLuint type, 25 26 int channel_per_pixel) 26 27 { 27 28 width = w; … … 60 61 case GL_FLOAT: 61 62 elemSize = sizeof(float); 62 63 break; 63 64 case GL_UNSIGNED_BYTE: 64 65 elemSize = sizeof(unsigned char); 65 66 break; 66 67 default: 67 68 68 assert(0); 69 break; 69 70 } 70 71 unsigned int size; … … 100 101 } else if (n_channels_per_pixel==4) { 101 102 TRACE("(%f %f %f %f) ", ((float*)data)[4*i], 102 103 103 ((float*)data)[4*i+1], 104 ((float*)data)[4*i+2], 104 105 ((float*)data)[4*i+3]); 105 106 } -
trunk/packages/vizservers/nanovis/ScreenSnapper.h
r2798 r2853 16 16 * ====================================================================== 17 17 */ 18 #ifndef SCREEN_SNAPPER_H 19 #define SCREEN_SNAPPER_H 18 20 19 #ifndef _SCREEN_SNAPPER_H_ 20 #define _SCREEN_SNAPPER_H_ 21 #include <stdio.h> 22 23 #include <GL/glew.h> 21 24 22 25 #include "define.h" 23 #include <GL/gl.h>24 #include <stdio.h>25 26 26 27 27 class ScreenSnapper 28 28 { 29 29 public: 30 int width, height; //size of the screen 31 GLuint data_type; //data type: GL_FLOAT or GL_UNSIGNED_BYTE 32 int n_channels_per_pixel; //RGB(3) or RGBA(4) 33 34 void* data; //storage array for the captured image. This array is "flat". 35 //It stores pixels in the order from lower-left corner to upper-right corner. 36 //[rgb][rgb][rgb]... or [rgba][rgba][rgba]... 30 ScreenSnapper(int width, int height, GLuint type, int channel_per_pixel); 31 ~ScreenSnapper(); 37 32 38 ScreenSnapper(int width, int height, GLuint type, int channel_per_pixel); 39 ~ScreenSnapper();33 /// set every byte in the data array to c 34 void reset(char c); 40 35 41 void reset(char c); //set every byte in the data array to c 42 void capture(); 43 void print(); 36 void capture(); 37 38 void print(); 39 40 int width; ///< width of the screen 41 int height; ///< height of the screen 42 GLuint data_type; ///< GL_FLOAT or GL_UNSIGNED_BYTE 43 int n_channels_per_pixel; ///< RGB(3) or RGBA(4) 44 45 /** 46 * storage array for the captured image. This array is "flat". 47 * It stores pixels in the order from lower-left corner to 48 * upper-right corner. 49 * [rgb][rgb][rgb]... or [rgba][rgba][rgba]... 50 */ 51 void *data; 44 52 }; 45 53 -
trunk/packages/vizservers/nanovis/VolumeInterpolator.cpp
r2798 r2853 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #include "VolumeInterpolator.h"3 #include "Volume.h"4 2 #include <string.h> 5 3 #include <memory.h> 6 #include "Vector3.h"7 4 #include <time.h> 8 5 #include <sys/time.h> 9 6 #include <math.h> 10 7 #include <stdlib.h> 8 9 #include "VolumeInterpolator.h" 10 #include "Volume.h" 11 #include "Vector3.h" 11 12 #include "Trace.h" 12 13 … … 20 21 _referenceOfVolume(0) 21 22 { 22 /*empty*/23 23 } 24 24 … … 43 43 } 44 44 45 Volume *VolumeInterpolator::update(float fraction)45 Volume *VolumeInterpolator::update(float fraction) 46 46 { 47 47 int key1, key2; … … 54 54 _volume->tex()->update(_volume->data()); 55 55 } else { 56 float *data1 = _volumes[key1]->data();57 float *data2 = _volumes[key2]->data();58 float *result = _volume->data();56 float *data1 = _volumes[key1]->data(); 57 float *data2 = _volumes[key2]->data(); 58 float *result = _volume->data(); 59 59 60 60 Vector3 normal1, normal2, normal; … … 75 75 _volume->tex()->update(_volume->data()); 76 76 } 77 77 78 78 return _volume; 79 79 } 80 80 81 void 82 VolumeInterpolator::computeKeys(float fraction, int count, float *interp,83 int * key1, int*key2)81 void 82 VolumeInterpolator::computeKeys(float fraction, int count, float *interp, 83 int *key1, int *key2) 84 84 { 85 85 int limit = (int) count - 1; … … 92 92 } else { 93 93 int n; 94 for (n = 0; n < limit; n++){94 for (n = 0; n < limit; n++){ 95 95 if (fraction >= (n / (count - 1.0f)) && 96 96 fraction < ((n+1)/(count-1.0f))) { … … 98 98 } 99 99 } 100 100 101 101 TRACE("n = %d count = %d\n", n, count); 102 if (n >= limit) {102 if (n >= limit) { 103 103 *key1 = *key2 = limit; 104 104 *interp = 0.0f; 105 106 105 } else { 107 106 *key1 = n; … … 113 112 } 114 113 115 void 114 void 116 115 VolumeInterpolator::clearAll() 117 116 { … … 119 118 } 120 119 121 void 122 VolumeInterpolator::addVolume(Volume *refPtr)120 void 121 VolumeInterpolator::addVolume(Volume *refPtr) 123 122 { 124 123 if (_volumes.size() != 0) { … … 130 129 return; 131 130 } 132 133 131 } else { 134 132 _dataCount = refPtr->width * refPtr->height * refPtr->depth; … … 164 162 } 165 163 166 Volume *VolumeInterpolator::getVolume()164 Volume *VolumeInterpolator::getVolume() 167 165 { 168 166 return _volume; 169 167 //return _volumes[0]; 170 168 } 171 -
trunk/packages/vizservers/nanovis/VolumeInterpolator.h
r2798 r2853 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #ifndef __VOLUME_INTERPOLATOR_H__ 3 #define __VOLUME_INTERPOLATOR_H__ 2 #ifndef VOLUME_INTERPOLATOR_H 3 #define VOLUME_INTERPOLATOR_H 4 5 #include <vector> 4 6 5 7 #include "Volume.h" 6 8 7 #include <vector> 9 class VolumeInterpolator 10 { 11 public : 12 VolumeInterpolator(); 8 13 9 class VolumeInterpolator { 10 Volume* _volume; 14 void addVolume(Volume *vol); 15 16 void clearAll(); 17 18 void start(); 19 20 Volume *update(float fraction); 21 22 void stop(); 23 24 void computeKeys(float fraction, int count, float *interp, int *key1, int *key2); 25 26 bool is_started() const; 27 28 double getInterval() const; 29 30 double getStartTime() const; 31 32 unsigned int getReferenceVolumeID() const; 33 34 Volume *getVolume(); 35 36 private: 37 Volume *_volume; 11 38 12 39 std::vector<Volume*> _volumes; … … 19 46 unsigned int _referenceOfVolume; 20 47 double _start_time; 21 22 public :23 VolumeInterpolator();24 void addVolume(Volume* vol);25 void clearAll();26 27 void start();28 Volume* update(float fraction);29 void stop();30 void computeKeys(float fraction, int count, float* interp, int* key1, int* key2);31 bool is_started() const;32 double getInterval() const;33 double getStartTime() const;34 unsigned int getReferenceVolumeID() const;35 Volume* getVolume();36 48 }; 37 49 … … 56 68 } 57 69 58 //inline Volume* VolumeInterpolator::getVolume()59 //{60 // return _volume;61 // //return _volumes[0];62 //}63 70 #endif 64 71 -
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r2822 r2853 111 111 ani_tf = ani_vol->transferFunction(); 112 112 #endif 113 113 TRACE("VOLUME INTERPOLATOR IS STARTED ----------------------------"); 114 114 } 115 115 // Determine the volumes that are to be rendered. … … 118 118 Tcl_HashSearch iter; 119 119 for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL; 120 121 122 120 hPtr = Tcl_NextHashEntry(&iter)) { 121 Volume* volPtr; 122 volPtr = (Volume *)Tcl_GetHashValue(hPtr); 123 123 if (!volPtr->visible()) { 124 continue; 125 126 127 128 129 130 131 132 124 continue; // Skip this volume 125 } 126 // BE CAREFUL: Set the number of slices to something slightly 127 // different for each volume. If we have identical volumes at exactly 128 // the same position with exactly the same number of slices, the 129 // second volume will overwrite the first, so the first won't appear 130 // at all. 131 volumes.push_back(volPtr); 132 volPtr->n_slices(256 - volumes.size()); 133 133 } 134 134 135 135 //two dimension pointer array 136 ConvexPolygon *** polys = new ConvexPolygon**[volumes.size()];136 ConvexPolygon ***polys = new ConvexPolygon**[volumes.size()]; 137 137 //number of actual slices for each volume 138 size_t *actual_slices = new size_t[volumes.size()];138 size_t *actual_slices = new size_t[volumes.size()]; 139 139 140 140 TRACE("start loop %d\n", volumes.size()); 141 141 for (size_t i = 0; i < volumes.size(); i++) { 142 Volume* volPtr; 143 142 Volume *volPtr = volumes[i]; 144 143 polys[i] = NULL; 145 144 actual_slices[i] = 0; 146 volPtr = volumes[i];147 145 148 146 int n_slices = volPtr->n_slices(); 149 147 if (volPtr->isosurface()) { 150 151 152 148 // double the number of slices 149 n_slices <<= 1; 150 } 153 151 154 152 //volume start location … … 165 163 double zNear, zFar; 166 164 167 165 //initialize volume plane with world coordinates 168 166 Plane volume_planes[6]; 169 167 volume_planes[0].set_coeffs( 1, 0, 0, -x0); … … 174 172 volume_planes[5].set_coeffs( 0, 0, -1, z0+1); 175 173 176 174 //get modelview matrix with no translation 177 175 glPushMatrix(); 178 176 glScalef(volPtr->aspect_ratio_width, 179 180 177 volPtr->aspect_ratio_height, 178 volPtr->aspect_ratio_depth); 181 179 182 180 glEnable(GL_DEPTH_TEST); … … 190 188 glPopMatrix(); 191 189 192 190 //get modelview matrix with translation 193 191 glPushMatrix(); 194 192 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z); 195 193 glScalef(volPtr->aspect_ratio_width, 196 197 194 volPtr->aspect_ratio_height, 195 volPtr->aspect_ratio_depth); 198 196 GLfloat mv_trans[16]; 199 197 glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans); … … 202 200 model_view_trans_inverse = model_view_trans.inverse(); 203 201 204 205 202 //draw volume bounding box with translation (the correct location in 203 //space) 206 204 if (volPtr->outline()) { 207 205 float olcolor[3]; 208 206 volPtr->get_outline_color(olcolor); 209 207 draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 210 211 208 (double)olcolor[0], (double)olcolor[1], (double)olcolor[2], 209 1.5); 212 210 } 213 211 glPopMatrix(); … … 217 215 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z); 218 216 if(volPtr->outline()) { 219 217 //draw_label(i); 220 218 } 221 219 glPopMatrix(); 222 220 223 221 //transform volume_planes to eye coordinates. 224 222 for (size_t j = 0; j < 6; j++) { 225 223 volume_planes[j].transform(model_view_no_trans); 226 224 } 227 225 get_near_far_z(mv_no_trans, zNear, zFar); 228 226 229 230 float z_step = fabs(zNear-zFar)/n_slices; 227 //compute actual rendering slices 228 float z_step = fabs(zNear-zFar)/n_slices; 231 229 size_t n_actual_slices; 232 230 … … 245 243 Vector4 vert4 = (Vector4(+10, -10, -0.5, 1)); 246 244 247 // Render cutplanes first with depth test enabled. They will mark the 248 // image with their depth values. Then we render other volume slices. 249 // These volume slices will be occluded correctly by the cutplanes and 250 // vice versa. 251 252 ConvexPolygon static_poly; 253 for (int j = 0; j < volPtr->get_cutplane_count(); j++) { 254 if (!volPtr->cutplane_is_enabled(j)) { 255 continue; 256 } 257 float offset = volPtr->get_cutplane(j)->offset; 258 int axis = volPtr->get_cutplane(j)->orient; 259 260 if (axis == 3) { 261 vert1 = Vector4(-10, -10, offset, 1); 262 vert2 = Vector4(-10, +10, offset, 1); 263 vert3 = Vector4(+10, +10, offset, 1); 264 vert4 = Vector4(+10, -10, offset, 1); 265 //continue; 266 } else if (axis == 1) { 267 vert1 = Vector4(offset, -10, -10, 1); 268 vert2 = Vector4(offset, +10, -10, 1); 269 vert3 = Vector4(offset, +10, +10, 1); 270 vert4 = Vector4(offset, -10, +10, 1); 271 //continue; 272 } else if (axis == 2) { 273 vert1 = Vector4(-10, offset, -10, 1); 274 vert2 = Vector4(+10, offset, -10, 1); 275 vert3 = Vector4(+10, offset, +10, 1); 276 vert4 = Vector4(-10, offset, +10, 1); 277 //continue; 278 } 279 280 vert1 = model_view_no_trans.transform(vert1); 281 vert2 = model_view_no_trans.transform(vert2); 282 vert3 = model_view_no_trans.transform(vert3); 283 vert4 = model_view_no_trans.transform(vert4); 284 285 ConvexPolygon* p = &static_poly; 286 p->vertices.clear(); 287 288 p->append_vertex(vert1); 289 p->append_vertex(vert2); 290 p->append_vertex(vert3); 291 p->append_vertex(vert4); 292 293 for (size_t k = 0; k < 6; k++) { 294 p->clip(volume_planes[k], true); 295 } 296 297 p->transform(model_view_no_trans_inverse); 298 p->transform(model_view_trans); 299 300 glPushMatrix(); 301 glScalef(volPtr->aspect_ratio_width, volPtr->aspect_ratio_height, 302 volPtr->aspect_ratio_depth); 303 304 activate_volume_shader(volPtr, true); 305 glPopMatrix(); 306 307 glEnable(GL_DEPTH_TEST); 308 glDisable(GL_BLEND); 309 310 glBegin(GL_POLYGON); 311 p->Emit(true); 312 glEnd(); 313 glDisable(GL_DEPTH_TEST); 314 315 deactivate_volume_shader(); 316 } //done cutplanes 317 318 //Now do volume rendering 245 // Render cutplanes first with depth test enabled. They will mark the 246 // image with their depth values. Then we render other volume slices. 247 // These volume slices will be occluded correctly by the cutplanes and 248 // vice versa. 249 250 ConvexPolygon static_poly; 251 for (int j = 0; j < volPtr->get_cutplane_count(); j++) { 252 if (!volPtr->cutplane_is_enabled(j)) { 253 continue; 254 } 255 float offset = volPtr->get_cutplane(j)->offset; 256 int axis = volPtr->get_cutplane(j)->orient; 257 258 if (axis == 3) { 259 vert1 = Vector4(-10, -10, offset, 1); 260 vert2 = Vector4(-10, +10, offset, 1); 261 vert3 = Vector4(+10, +10, offset, 1); 262 vert4 = Vector4(+10, -10, offset, 1); 263 //continue; 264 } else if (axis == 1) { 265 vert1 = Vector4(offset, -10, -10, 1); 266 vert2 = Vector4(offset, +10, -10, 1); 267 vert3 = Vector4(offset, +10, +10, 1); 268 vert4 = Vector4(offset, -10, +10, 1); 269 //continue; 270 } else if (axis == 2) { 271 vert1 = Vector4(-10, offset, -10, 1); 272 vert2 = Vector4(+10, offset, -10, 1); 273 vert3 = Vector4(+10, offset, +10, 1); 274 vert4 = Vector4(-10, offset, +10, 1); 275 //continue; 276 } 277 278 vert1 = model_view_no_trans.transform(vert1); 279 vert2 = model_view_no_trans.transform(vert2); 280 vert3 = model_view_no_trans.transform(vert3); 281 vert4 = model_view_no_trans.transform(vert4); 282 283 ConvexPolygon *p = &static_poly; 284 p->vertices.clear(); 285 286 p->append_vertex(vert1); 287 p->append_vertex(vert2); 288 p->append_vertex(vert3); 289 p->append_vertex(vert4); 290 291 for (size_t k = 0; k < 6; k++) { 292 p->clip(volume_planes[k], true); 293 } 294 295 p->transform(model_view_no_trans_inverse); 296 p->transform(model_view_trans); 297 298 glPushMatrix(); 299 glScalef(volPtr->aspect_ratio_width, 300 volPtr->aspect_ratio_height, 301 volPtr->aspect_ratio_depth); 302 303 activate_volume_shader(volPtr, true); 304 glPopMatrix(); 305 306 glEnable(GL_DEPTH_TEST); 307 glDisable(GL_BLEND); 308 309 glBegin(GL_POLYGON); 310 p->Emit(true); 311 glEnd(); 312 glDisable(GL_DEPTH_TEST); 313 314 deactivate_volume_shader(); 315 } //done cutplanes 316 317 //Now do volume rendering 319 318 320 319 vert1 = (Vector4(-10, -10, -0.5, 1)); … … 325 324 size_t counter = 0; 326 325 327 326 //transform slices and store them 328 327 float slice_z; 329 328 for (size_t j = 0; j < n_actual_slices; j++) { 330 slice_z = zFar + j * z_step;//back to front329 slice_z = zFar + j * z_step; //back to front 331 330 332 331 ConvexPolygon *poly = new ConvexPolygon(); … … 349 348 350 349 for (size_t k = 0; k < 6; k++) { 351 352 350 poly->clip(volume_planes[k], true); 351 } 353 352 354 353 poly->transform(model_view_no_trans_inverse); … … 356 355 357 356 if (poly->vertices.size() >= 3) 358 357 total_rendered_slices++; 359 358 } 360 359 } //iterate all volumes … … 364 363 // farthest to the closest. This step is critical for correct blending 365 364 366 SortElement * slices = (SortElement*)367 365 SortElement *slices = (SortElement *) 366 malloc(sizeof(SortElement) * total_rendered_slices); 368 367 369 368 size_t counter = 0; … … 385 384 386 385 for (size_t i = 0; i < total_rendered_slices; i++) { 387 Volume* volPtr;386 Volume *volPtr = NULL; 388 387 389 388 int volume_index = slices[i].volume_id; 390 389 int slice_index = slices[i].slice_id; 391 ConvexPolygon* cur = polys[volume_index][slice_index]; 392 393 volPtr = volumes[volume_index]; 390 ConvexPolygon *cur = polys[volume_index][slice_index]; 391 392 volPtr = volumes[volume_index]; 393 394 394 glPushMatrix(); 395 395 glScalef(volPtr->aspect_ratio_width, volPtr->aspect_ratio_height, 396 396 volPtr->aspect_ratio_depth); 397 397 398 398 #ifdef notdef 399 400 399 TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d\n", 400 volPtr->name(), volPtr, slice_index, volume_index); 401 401 #endif 402 402 activate_volume_shader(volPtr, false); … … 429 429 void 430 430 VolumeRenderer::draw_bounding_box(float x0, float y0, float z0, 431 432 433 431 float x1, float y1, float z1, 432 float r, float g, float b, 433 float line_width) 434 434 { 435 435 glPushMatrix(); … … 443 443 glBegin(GL_LINE_LOOP); 444 444 { 445 446 447 448 445 glVertex3d(x0, y0, z0); 446 glVertex3d(x1, y0, z0); 447 glVertex3d(x1, y1, z0); 448 glVertex3d(x0, y1, z0); 449 449 } 450 450 glEnd(); … … 452 452 glBegin(GL_LINE_LOOP); 453 453 { 454 455 456 457 454 glVertex3d(x0, y0, z1); 455 glVertex3d(x1, y0, z1); 456 glVertex3d(x1, y1, z1); 457 glVertex3d(x0, y1, z1); 458 458 } 459 459 glEnd(); 460 460 461 461 glBegin(GL_LINE_LOOP); 462 462 { 463 464 465 466 463 glVertex3d(x0, y0, z0); 464 glVertex3d(x0, y0, z1); 465 glVertex3d(x0, y1, z1); 466 glVertex3d(x0, y1, z0); 467 467 } 468 468 glEnd(); … … 470 470 glBegin(GL_LINE_LOOP); 471 471 { 472 473 474 475 472 glVertex3d(x1, y0, z0); 473 glVertex3d(x1, y0, z1); 474 glVertex3d(x1, y1, z1); 475 glVertex3d(x1, y1, z0); 476 476 } 477 477 glEnd(); … … 485 485 486 486 if (NanoVis::fonts != NULL) { 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 487 double mv[16], prjm[16]; 488 int viewport[4]; 489 double wx, wy, wz; 490 double dx, dy, dz; 491 492 glGetDoublev(GL_MODELVIEW_MATRIX, mv); 493 glGetDoublev(GL_PROJECTION_MATRIX, prjm); 494 glGetIntegerv(GL_VIEWPORT, viewport); 495 496 NanoVis::fonts->begin(); 497 dx = x1 - x0; 498 dy = y1 - y0; 499 dz = z1 - z0; 500 if (gluProject((x0 + x1) * 0.5, y0, z0, mv, prjm, viewport, 501 &wx, &wy, &wz)) { 502 char buff[20]; 503 double min, max; 504 505 NanoVis::grid->xAxis.GetDataLimits(min, max); 506 glLoadIdentity(); 507 glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f); 508 const char *units; 509 units = NanoVis::grid->xAxis.GetUnits(); 510 sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units); 511 NanoVis::fonts->draw(buff); 512 } 513 if (gluProject(x0, (y0 + y1) * 0.5, z0, mv, prjm, viewport, & 514 wx, &wy, &wz)) { 515 char buff[20]; 516 double min, max; 517 518 NanoVis::grid->yAxis.GetDataLimits(min, max); 519 glLoadIdentity(); 520 glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f); 521 const char *units; 522 units = NanoVis::grid->yAxis.GetUnits(); 523 sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units); 524 NanoVis::fonts->draw(buff); 525 } 526 if (gluProject(x0, y0, (z0 + z1) * 0.5, mv, prjm, viewport, 527 &wx, &wy, &wz)) { 528 glLoadIdentity(); 529 glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f); 530 531 double min, max; 532 NanoVis::grid->zAxis.GetDataLimits(min, max); 533 const char *units; 534 units = NanoVis::grid->zAxis.GetUnits(); 535 char buff[20]; 536 sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units); 537 NanoVis::fonts->draw(buff); 538 } 539 NanoVis::fonts->end(); 540 540 }; 541 541 #endif … … 553 553 TransferFunction *tfPtr = volPtr->transferFunction(); 554 554 if (volPtr->volume_type() == Volume::CUBIC) { 555 555 _regularVolumeShader->bind(tfPtr->id(), volPtr, slice_mode); 556 556 } else if (volPtr->volume_type() == Volume::ZINCBLENDE) { 557 557 _zincBlendeShader->bind(tfPtr->id(), volPtr, slice_mode); 558 558 } 559 559 } … … 602 602 603 603 bool 604 VolumeRenderer::init_font(const char *filename)604 VolumeRenderer::init_font(const char *filename) 605 605 { 606 606 FILE *f; … … 617 617 f = fopen(filename, "rb"); 618 618 if (f == NULL) { 619 620 619 ERROR("can't open font file \"%s\"\n", filename); 620 return false; 621 621 } 622 622 623 623 if (fread(&bfType, sizeof(short int), 1, f) != 1) { 624 625 626 624 ERROR("can't read %lu bytes from font file \"%s\"\n", 625 (unsigned long)sizeof(short int), filename); 626 goto error; 627 627 } 628 628 629 629 /* check if file is a bitmap */ 630 630 if (bfType != 19778) { 631 632 631 ERROR("not a bmp file.\n"); 632 goto error; 633 633 } 634 634 … … 639 639 /* get the position of the actual bitmap data */ 640 640 if (fread(&bfOffBits, sizeof(int), 1, f) != 1) { 641 642 641 ERROR("error reading file.\n"); 642 goto error; 643 643 } 644 644 //TRACE("Data at Offset: %ld\n", bfOffBits); … … 649 649 /* get the width of the bitmap */ 650 650 if (fread(&width, sizeof(int), 1, f) != 1) { 651 652 651 ERROR("error reading file.\n"); 652 goto error; 653 653 } 654 654 //TRACE("Width of Bitmap: %d\n", texture->width); … … 656 656 /* get the height of the bitmap */ 657 657 if (fread(&height, sizeof(int), 1, f) != 1) { 658 659 658 ERROR("error reading file.\n"); 659 goto error; 660 660 } 661 661 //TRACE("Height of Bitmap: %d\n", texture->height); … … 663 663 /* get the number of planes (must be set to 1) */ 664 664 if (fread(&biPlanes, sizeof(short int), 1, f) != 1) { 665 666 665 ERROR("error reading file.\n"); 666 goto error; 667 667 } 668 668 if (biPlanes != 1) { 669 670 669 ERROR("number of Planes not 1!\n"); 670 goto error; 671 671 } 672 672 673 673 /* get the number of bits per pixel */ 674 674 if (fread(&biBitCount, sizeof(short int), 1, f) != 1) { 675 676 675 ERROR("error reading file.\n"); 676 goto error; 677 677 } 678 678 679 679 //TRACE("Bits per Pixel: %d\n", biBitCount); 680 680 if (biBitCount != 24) { 681 682 681 ERROR("Bits per Pixel not 24\n"); 682 goto error; 683 683 } 684 684 … … 687 687 data = (unsigned char*) malloc(biSizeImage); 688 688 if (data == NULL) { 689 690 689 ERROR("Can't allocate memory for image\n"); 690 goto error; 691 691 } 692 692 … … 694 694 fseek(f, bfOffBits, SEEK_SET); 695 695 if (fread(data, biSizeImage, 1, f) != 1) { 696 697 696 ERROR("Error loading file!\n"); 697 goto error; 698 698 } 699 699 fclose(f); … … 709 709 unsigned char* data_with_alpha; 710 710 data_with_alpha = (unsigned char*) 711 711 malloc(width*height*4*sizeof(unsigned char)); 712 712 for (int i = 0; i < height; i++) { 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 713 for (int j = 0; j < width; j++) { 714 unsigned char r, g, b, a; 715 r = data[3*(i*width+j)]; 716 g = data[3*(i*width+j)+1]; 717 b = data[3*(i*width+j)+2]; 718 719 if (r==0 && g==0 && b==0) 720 a = 0; 721 else 722 a = 255; 723 724 data_with_alpha[4*(i*width+j)] = r; 725 data_with_alpha[4*(i*width+j) + 1] = g; 726 data_with_alpha[4*(i*width+j) + 2] = b; 727 data_with_alpha[4*(i*width+j) + 3] = a; 728 } 729 729 } 730 730 free(data); … … 763 763 764 764 glTranslatef(.5*vol->aspect_ratio_width, vol->aspect_ratio_height, 765 765 -0.1*vol->aspect_ratio_depth); 766 766 glRotatef(180, 0, 0, 1); 767 767 glRotatef(90, 1, 0, 0); … … 769 769 glScalef(0.0008, 0.0008, 0.0008); 770 770 for (int i = 0; i < length; i++) { 771 772 771 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[0].c_str()[i]); 772 glTranslatef(0.04, 0., 0.); 773 773 } 774 774 glPopMatrix(); … … 783 783 glScalef(0.0008, 0.0008, 0.0008); 784 784 for (int i = 0; i < length; i++) { 785 786 785 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[1].c_str()[i]); 786 glTranslatef(0.04, 0., 0.); 787 787 } 788 788 glPopMatrix(); … … 796 796 glScalef(0.0008, 0.0008, 0.0008); 797 797 for (int i = 0; i < length; i++) { 798 799 798 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[2].c_str()[i]); 799 glTranslatef(0.04, 0., 0.); 800 800 } 801 801 glPopMatrix(); -
trunk/packages/vizservers/nanovis/VolumeRenderer.h
r2822 r2853 14 14 * ====================================================================== 15 15 */ 16 17 16 #ifndef _VOLUME_RENDERER_H_ 18 17 #define _VOLUME_RENDERER_H_ … … 30 29 class VolumeRenderer 31 30 { 32 friend class NanoVis;33 34 private:35 VolumeInterpolator* _volumeInterpolator;36 37 bool slice_mode; //!<- enable cut planes38 bool volume_mode; //!<- enable full volume rendering39 40 /**41 * shader parameters for rendering a single cubic volume42 */43 NvRegularVolumeShader* _regularVolumeShader;44 45 /**46 * Shader parameters for rendering a single zincblende orbital. A47 * simulation contains S, P, D and SS, total of 4 orbitals. A full48 * rendering requires 4 zincblende orbital volumes. A zincblende orbital49 * volume is decomposed into two "interlocking" cubic volumes and passed50 * to the shader. We render each orbital with its own independent51 * transfer functions then blend the result.52 *53 * The engine is already capable of rendering multiple volumes and combine54 * them. Thus, we just invoke this shader on S, P, D and SS orbitals with55 * different transfor functions. The result is a multi-orbital rendering.56 * This is equivalent to rendering 4 unrelated data sets occupying the57 * same space.58 */59 NvZincBlendeVolumeShader* _zincBlendeShader;60 61 /**62 * standard vertex shader63 */64 NvStdVertexShader* _stdVertexShader;65 66 //standard vertex shader parameters67 CGprogram m_vert_std_vprog;68 CGparameter m_mvp_vert_std_param;69 CGparameter m_mvi_vert_std_param;70 GLuint font_base; // The base of the font display list.71 GLuint font_texture; //the id of the font texture72 73 void init_shaders();74 75 void activate_volume_shader(Volume* vol, bool slice_mode);76 77 void deactivate_volume_shader();78 79 //draw bounding box80 void draw_bounding_box(float x0, float y0, float z0,81 float x1, float y1, float z1,82 float r, float g, float b, float line_width);83 84 void get_near_far_z(const Mat4x4& mv, double& zNear, double& zFar);85 86 bool init_font(const char* filename);87 88 void glPrint(char* string, int set); //there are two sets of font in the89 //texture. 0, 190 91 void draw_label(Volume* vol); //draw label using bitmap texture92 // the texture.93 94 void build_font(); // Register the location of each alphabet in95 96 31 public: 97 32 VolumeRenderer(); … … 99 34 ~VolumeRenderer(); 100 35 101 void render_all(); //render all enabled volumes; 36 /// render all enabled volumes 37 void render_all(); 102 38 103 39 void specular(float val); … … 105 41 void diffuse(float val); 106 42 107 void set_slice_mode(bool val) //control independently. 43 /// control independently 44 void set_slice_mode(bool val) 108 45 { 109 46 slice_mode = val; … … 115 52 } 116 53 117 void switch_slice_mode() //switch_cutplane_mode 54 /// switch_cutplane_mode 55 void switch_slice_mode() 118 56 { 119 57 slice_mode = (!slice_mode); … … 142 80 void stopVolumeAnimation() 143 81 { 144 82 _volumeInterpolator->stop(); 145 83 } 146 84 147 85 VolumeInterpolator* getVolumeInterpolator() 148 86 { 149 87 return _volumeInterpolator; 150 88 } 89 90 friend class NanoVis; 91 92 private: 93 void init_shaders(); 94 95 void activate_volume_shader(Volume *vol, bool slice_mode); 96 97 void deactivate_volume_shader(); 98 99 void draw_bounding_box(float x0, float y0, float z0, 100 float x1, float y1, float z1, 101 float r, float g, float b, float line_width); 102 103 void get_near_far_z(const Mat4x4& mv, double& zNear, double& zFar); 104 105 bool init_font(const char *filename); 106 107 /// there are two sets of font in the texture. 0, 1 108 void glPrint(char *string, int set); 109 110 /// draw label using bitmap texture 111 void draw_label(Volume *vol); 112 113 /// Register the location of each alphabet in 114 void build_font(); 115 116 VolumeInterpolator *_volumeInterpolator; 117 118 bool slice_mode; ///< enable cut planes 119 bool volume_mode; ///< enable full volume rendering 120 121 /** 122 * shader parameters for rendering a single cubic volume 123 */ 124 NvRegularVolumeShader *_regularVolumeShader; 125 126 /** 127 * Shader parameters for rendering a single zincblende orbital. A 128 * simulation contains S, P, D and SS, total of 4 orbitals. A full 129 * rendering requires 4 zincblende orbital volumes. A zincblende orbital 130 * volume is decomposed into two "interlocking" cubic volumes and passed 131 * to the shader. We render each orbital with its own independent 132 * transfer functions then blend the result. 133 * 134 * The engine is already capable of rendering multiple volumes and combine 135 * them. Thus, we just invoke this shader on S, P, D and SS orbitals with 136 * different transfor functions. The result is a multi-orbital rendering. 137 * This is equivalent to rendering 4 unrelated data sets occupying the 138 * same space. 139 */ 140 NvZincBlendeVolumeShader *_zincBlendeShader; 141 142 /** 143 * standard vertex shader 144 */ 145 NvStdVertexShader *_stdVertexShader; 146 147 //standard vertex shader parameters 148 CGprogram m_vert_std_vprog; 149 CGparameter m_mvp_vert_std_param; 150 CGparameter m_mvi_vert_std_param; 151 GLuint font_base; // The base of the font display list. 152 GLuint font_texture; //the id of the font texture 151 153 }; 152 154 153 #endif /*_VOLUME_RENDERER_H_*/155 #endif -
trunk/packages/vizservers/nanovis/dxReader.h
r2846 r2853 2 2 #ifndef DXREADER_H 3 3 #define DXREADER_H 4 5 #include <iostream> 4 6 5 7 namespace Rappture { -
trunk/packages/vizservers/nanovis/vrmath/vrQuaternion.cpp
r2840 r2853 8 8 #include <cstdlib> 9 9 #include <cmath> 10 #include <float.h> 11 10 12 #include <vrmath/vrQuaternion.h> 11 13 #include <vrmath/vrRotation.h> 12 14 #include <vrmath/vrLinmath.h> 13 15 #include <vrmath/vrVector3f.h> 14 #include <float.h>15 16 16 17 #ifndef PI
Note: See TracChangeset
for help on using the changeset viewer.