Changeset 4904 for nanovis/branches/1.1/VolumeRenderer.cpp
 Timestamp:
 Dec 22, 2014, 7:18:59 AM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

nanovis/branches/1.1/VolumeRenderer.cpp
r4889 r4904 54 54 { 55 55 _cutplaneShader = new Shader(); 56 _cutplaneShader>loadVertexProgram("cutplane_vp.cg" , "main");57 _cutplaneShader>loadFragmentProgram("cutplane_fp.cg" , "main");56 _cutplaneShader>loadVertexProgram("cutplane_vp.cg"); 57 _cutplaneShader>loadFragmentProgram("cutplane_fp.cg"); 58 58 59 59 //standard vertex program … … 67 67 //A sim has S, P, D, SS orbitals. thus a full rendering requires 4 zincblende orbital volumes. 68 68 //A zincblende orbital volume is decomposed into 2 "interlocking" cubic 4component volumes and passed to the shader. 69 //We render each orbital with aindependent transfer functions then blend the result.69 //We render each orbital with independent transfer functions then blend the result. 70 70 // 71 71 //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on … … 143 143 } 144 144 145 //volume start location 146 Vector3f volPos = volume>location(); 147 Vector3f volScaling = volume>getPhysicalScaling(); 145 // Get any additional transforms on Volume 146 Vector3f volPos = volume>getPosition(); 147 Vector3f volScale = volume>getPhysicalScaling(); 148 // Get world coords of volume bbox 149 double x0 = 0; 150 double y0 = 0; 151 double z0 = 0; 152 double x1 = x0 + 1; 153 double y1 = y0 + 1; 154 double z1 = z0 + 1; 155 156 Matrix4x4d model_view_no_trans, model_view_trans; 157 Matrix4x4d model_view_no_trans_inverse, model_view_trans_inverse; 158 159 //initialize volume plane with world coordinates 160 nv::Plane volume_planes[6]; 161 volume_planes[0].setCoeffs( 1, 0, 0, x0); 162 volume_planes[1].setCoeffs(1, 0, 0, x1); 163 volume_planes[2].setCoeffs( 0, 1, 0, y0); 164 volume_planes[3].setCoeffs( 0, 1, 0, y1); 165 volume_planes[4].setCoeffs( 0, 0, 1, z0); 166 volume_planes[5].setCoeffs( 0, 0, 1, z1); 148 167 149 168 TRACE("VOL POS: %g %g %g", 150 169 volPos.x, volPos.y, volPos.z); 151 170 TRACE("VOL SCALE: %g %g %g", 152 volScaling.x, volScaling.y, volScaling.z); 153 154 double x0 = 0; 155 double y0 = 0; 156 double z0 = 0; 157 158 Matrix4x4d model_view_no_trans, model_view_trans; 159 Matrix4x4d model_view_no_trans_inverse, model_view_trans_inverse; 160 161 //initialize volume plane with world coordinates 162 nv::Plane volume_planes[6]; 163 volume_planes[0].setCoeffs( 1, 0, 0, x0); 164 volume_planes[1].setCoeffs(1, 0, 0, x0+1); 165 volume_planes[2].setCoeffs( 0, 1, 0, y0); 166 volume_planes[3].setCoeffs( 0, 1, 0, y0+1); 167 volume_planes[4].setCoeffs( 0, 0, 1, z0); 168 volume_planes[5].setCoeffs( 0, 0, 1, z0+1); 171 volScale.x, volScale.y, volScale.z); 169 172 170 173 //get modelview matrix with no translation 171 174 glPushMatrix(); 172 glScalef(volScal ing.x, volScaling.y, volScaling.z);175 glScalef(volScale.x, volScale.y, volScale.z); 173 176 174 177 glEnable(GL_DEPTH_TEST); … … 185 188 glPushMatrix(); 186 189 glTranslatef(volPos.x, volPos.y, volPos.z); 187 glScalef(volScal ing.x, volScaling.y, volScaling.z);190 glScalef(volScale.x, volScale.y, volScale.z); 188 191 189 192 GLdouble mv_trans[16]; … … 200 203 float olcolor[3]; 201 204 volume>getOutlineColor(olcolor); 202 drawBoundingBox(x0, y0, z0, x 0+1, y0+1, z0+1,203 (double)olcolor[0], (double)olcolor[1], (double)olcolor[2],204 1.5);205 drawBoundingBox(x0, y0, z0, x1, y1, z1, 206 olcolor[0], olcolor[1], olcolor[2], 207 1.5); 205 208 } 206 209 glPopMatrix(); … … 212 215 volume_planes[j].transform(model_view_no_trans); 213 216 } 214 double eyeMinX, eyeMaxX, eyeMinY, eyeMaxY, zNear, zFar; 217 double eyeMinX, eyeMaxX, eyeMinY, eyeMaxY; 218 double zNear, zFar; 215 219 getEyeSpaceBounds(model_view_no_trans, 216 220 eyeMinX, eyeMaxX, … … 249 253 continue; 250 254 } 255 Vector4f texcoord1, texcoord2, texcoord3, texcoord4; 251 256 float offset = volume>getCutplane(j)>offset; 252 257 int axis = volume>getCutplane(j)>orient; 253 258 254 259 switch (axis) { 255 case 1:260 case CutPlane::X_AXIS: // YZ plane 256 261 vert1 = Vector4f(offset, 0, 0, 1); 257 262 vert2 = Vector4f(offset, 1, 0, 1); 258 263 vert3 = Vector4f(offset, 1, 1, 1); 259 264 vert4 = Vector4f(offset, 0, 1, 1); 265 texcoord1 = Vector4f(offset, 0, 0, 1); 266 texcoord2 = Vector4f(offset, 1, 0, 1); 267 texcoord3 = Vector4f(offset, 1, 1, 1); 268 texcoord4 = Vector4f(offset, 0, 1, 1); 260 269 break; 261 case 2:270 case CutPlane::Y_AXIS: // XZ plane 262 271 vert1 = Vector4f(0, offset, 0, 1); 263 272 vert2 = Vector4f(1, offset, 0, 1); 264 273 vert3 = Vector4f(1, offset, 1, 1); 265 274 vert4 = Vector4f(0, offset, 1, 1); 275 texcoord1 = Vector4f(0, offset, 0, 1); 276 texcoord2 = Vector4f(1, offset, 0, 1); 277 texcoord3 = Vector4f(1, offset, 1, 1); 278 texcoord4 = Vector4f(0, offset, 1, 1); 266 279 break; 267 case 3:280 case CutPlane::Z_AXIS: // XY plane 268 281 default: 269 282 vert1 = Vector4f(0, 0, offset, 1); … … 271 284 vert3 = Vector4f(1, 1, offset, 1); 272 285 vert4 = Vector4f(0, 1, offset, 1); 286 texcoord1 = Vector4f(0, 0, offset, 1); 287 texcoord2 = Vector4f(1, 0, offset, 1); 288 texcoord3 = Vector4f(1, 1, offset, 1); 289 texcoord4 = Vector4f(0, 1, offset, 1); 273 290 break; 274 291 } 275 276 Vector4f texcoord1 = vert1;277 Vector4f texcoord2 = vert2;278 Vector4f texcoord3 = vert3;279 Vector4f texcoord4 = vert4;280 292 281 293 _cutplaneShader>bind(); … … 285 297 glPushMatrix(); 286 298 glTranslatef(volPos.x, volPos.y, volPos.z); 287 glScalef(volScal ing.x, volScaling.y, volScaling.z);299 glScalef(volScale.x, volScale.y, volScale.z); 288 300 _cutplaneShader>setGLStateMatrixVPParameter("modelViewProjMatrix", 289 301 Shader::MODELVIEW_PROJECTION_MATRIX); … … 384 396 385 397 for (size_t i = 0; i < total_rendered_slices; i++) { 386 Volume *volume = NULL; 387 388 int volume_index = slices[i].volumeId; 389 int slice_index = slices[i].sliceId; 390 ConvexPolygon *currentSlice = polys[volume_index][slice_index]; 391 float z_step = z_steps[volume_index]; 392 393 volume = volumes[volume_index]; 394 395 Vector3f volScaling = volume>getPhysicalScaling(); 398 int volIdx = slices[i].volumeId; 399 int sliceIdx = slices[i].sliceId; 400 ConvexPolygon *currentSlice = polys[volIdx][sliceIdx]; 401 402 Volume *volume = volumes[volIdx]; 403 Vector3f volScale = volume>getPhysicalScaling(); 396 404 397 405 glPushMatrix(); 398 glScalef(volScaling.x, volScaling.y, volScaling.z); 399 406 glScalef(volScale.x, volScale.y, volScale.z); 407 408 float z_step = z_steps[volIdx]; 400 409 // FIXME: compute viewdependent volume sample distance 401 double avgSampleDistance = 1.0 / pow(volume>width() * volScal ing.x *402 volume>height() * volScal ing.y *403 volume>depth() * volScal ing.z, 1.0/3.0);410 double avgSampleDistance = 1.0 / pow(volume>width() * volScale.x * 411 volume>height() * volScale.y * 412 volume>depth() * volScale.z, 1.0/3.0); 404 413 float sampleRatio = z_step / avgSampleDistance; 405 414 406 415 #ifdef notdef 407 416 TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d z_step=%g avgSD=%g", 408 volume>name(), volume, slice _index, volume_index, z_step, avgSampleDistance);417 volume>name(), volume, sliceIdx, volIdx, z_step, avgSampleDistance); 409 418 #endif 410 419 activateVolumeShader(volume, false, sampleRatio); … … 439 448 float x1, float y1, float z1, 440 449 float r, float g, float b, 441 float line _width)450 float lineWidth) 442 451 { 443 452 glPushAttrib(GL_ENABLE_BIT); … … 451 460 452 461 glColor4d(r, g, b, 1.0); 453 glLineWidth(line _width);462 glLineWidth(lineWidth); 454 463 455 464 glBegin(GL_LINE_LOOP); … … 494 503 495 504 void 496 VolumeRenderer::activateVolumeShader(Volume *volume, bool sliceMode, 505 VolumeRenderer::activateVolumeShader(Volume *volume, 506 bool sliceMode, 497 507 float sampleRatio) 498 508 {
Note: See TracChangeset
for help on using the changeset viewer.