Changeset 2973


Ignore:
Timestamp:
Apr 17, 2012 12:55:28 AM (10 years ago)
Author:
ldelgass
Message:

Fix clipping bug in nanovis volume renderer. Use computed eye space bounds of
transformed volume bounding box to initialize view-aligned quads before
clipping. Previously an arbitrary eye-space bound was used, and this was too
small for long volumes like nanowires in omennanowire.

Location:
trunk/packages/vizservers/nanovis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/VolumeRenderer.cpp

    r2972 r2973  
    1818#include <time.h>
    1919#include <sys/time.h>
     20#include <float.h>
    2021
    2122#include <vector>
     
    163164        Mat4x4 model_view_no_trans_inverse, model_view_trans_inverse;
    164165
    165         double zNear, zFar;
    166 
    167166        //initialize volume plane with world coordinates
    168167        Plane volume_planes[6];
     
    225224            volume_planes[j].transform(model_view_no_trans);
    226225        }
    227         getNearFarZ(mv_no_trans, zNear, zFar);
     226        double eyeMinX, eyeMaxX, eyeMinY, eyeMaxY, zNear, zFar;
     227        getEyeSpaceBounds(model_view_no_trans,
     228                          eyeMinX, eyeMaxX,
     229                          eyeMinY, eyeMaxY,
     230                          zNear, zFar);
    228231
    229232        //compute actual rendering slices
     
    240243        actual_slices[i] = n_actual_slices;
    241244
     245        // These are object coordinates
    242246        Vector4 vert1 = (Vector4(-10, -10, -0.5, 1));
    243247        Vector4 vert2 = (Vector4(-10, +10, -0.5, 1));
     
    319323        //Now do volume rendering
    320324
    321         vert1 = (Vector4(-10, -10, -0.5, 1));
    322         vert2 = (Vector4(-10, +10, -0.5, 1));
    323         vert3 = (Vector4(+10, +10, -0.5, 1));
    324         vert4 = (Vector4(+10, -10, -0.5, 1));
     325        // Initialize view-aligned quads with eye space bounds of
     326        // volume
     327        vert1 = (Vector4(eyeMinX, eyeMinY, -0.5, 1));
     328        vert2 = (Vector4(eyeMaxX, eyeMinY, -0.5, 1));
     329        vert3 = (Vector4(eyeMaxX, eyeMaxY, -0.5, 1));
     330        vert4 = (Vector4(eyeMinX, eyeMaxY, -0.5, 1));
    325331
    326332        size_t counter = 0;
     
    338344            poly->setId(i);
    339345
    340             //Setting Z-coordinate
     346            // Set eye space Z-coordinate of slice
    341347            vert1.z = slice_z;
    342348            vert2.z = slice_z;
     
    572578}
    573579
    574 void VolumeRenderer::getNearFarZ(const Mat4x4& mv, double& zNear, double& zFar)
     580void VolumeRenderer::getEyeSpaceBounds(const Mat4x4& mv,
     581                                       double& xMin, double& xMax,
     582                                       double& yMin, double& yMax,
     583                                       double& zNear, double& zFar)
    575584{
    576585    double x0 = 0;
     
    582591
    583592    double zMin, zMax;
    584     zMin =  10000;
    585     zMax = -10000;
     593    xMin = DBL_MAX;
     594    xMax = -DBL_MAX;
     595    yMin = DBL_MAX;
     596    yMax = -DBL_MAX;
     597    zMin = DBL_MAX;
     598    zMax = -DBL_MAX;
    586599
    587600    double vertex[8][4];
     
    597610
    598611    for (int i = 0; i < 8; i++) {
    599         Vector4 tmp = mv.transform(Vector4(vertex[i][0], vertex[i][1], vertex[i][2], vertex[i][3]));
    600         tmp.perspectiveDivide();
    601         vertex[i][2] = tmp.z;
    602         if (vertex[i][2] < zMin) zMin = vertex[i][2];
    603         if (vertex[i][2] > zMax) zMax = vertex[i][2];
     612        Vector4 eyeVert = mv.transform(Vector4(vertex[i][0],
     613                                               vertex[i][1],
     614                                               vertex[i][2],
     615                                               vertex[i][3]));
     616        if (eyeVert.x < xMin) xMin = eyeVert.x;
     617        if (eyeVert.x > xMax) xMax = eyeVert.x;
     618        if (eyeVert.y < yMin) yMin = eyeVert.y;
     619        if (eyeVert.y > yMax) yMax = eyeVert.y;
     620        if (eyeVert.z < zMin) zMin = eyeVert.z;
     621        if (eyeVert.z > zMax) zMax = eyeVert.z;
    604622    }
    605623
  • trunk/packages/vizservers/nanovis/VolumeRenderer.h

    r2968 r2973  
    100100                         float r, float g, float b, float line_width);
    101101
    102     void getNearFarZ(const Mat4x4& mv, double& zNear, double& zFar);
     102    void getEyeSpaceBounds(const Mat4x4& mv,
     103                           double& xMin, double& xMax,
     104                           double& yMin, double& yMax,
     105                           double& zNear, double& zFar);
    103106
    104107    bool initFont(const char *filename);
Note: See TracChangeset for help on using the changeset viewer.