Ignore:
Timestamp:
Mar 13, 2013, 9:57:03 AM (12 years ago)
Author:
ldelgass
Message:

Fix camera reset for nanovis. Includes refactoring of vector/matrix classes
in nanovis to consolidate into vrmath library. Also add preliminary canonical
view control to clients for testing.

File:
1 edited

Legend:

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

    r3476 r3492  
    1414#include <RpFieldPrism3D.h>
    1515#include <RpOutcome.h>
     16
     17#include <vrmath/Vector3f.h>
     18#include <vrmath/Vector4f.h>
     19#include <vrmath/Matrix4x4d.h>
    1620
    1721#include "nvconf.h"
     
    3842#define RELPOS 0
    3943#define ABSPOS 1
     44
     45using namespace vrmath;
    4046
    4147static Rappture::SwitchParseProc AxisSwitchProc;
     
    170176{
    171177    _rendererPtr->setPos(FlowCmd::GetRelativePosition(&_sv.position));
    172     _rendererPtr->setColor(Vector4(_sv.color.r, _sv.color.g, _sv.color.b,
    173                                    _sv.color.a));
     178    _rendererPtr->setColor(Vector4f(_sv.color.r, _sv.color.g, _sv.color.b,
     179                                    _sv.color.a));
    174180    _rendererPtr->particleSize(_sv.particleSize);
    175181    _rendererPtr->setAxis(_sv.position.axis);
     
    192198}
    193199
     200void
     201FlowBox::getWorldSpaceBounds(Vector3f& bboxMin,
     202                             Vector3f& bboxMax,
     203                             const Volume *vol) const
     204{
     205    bboxMin.set(FLT_MAX, FLT_MAX, FLT_MAX);
     206    bboxMax.set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
     207
     208    Vector3f origin = vol->location();
     209    Vector3f scale = vol->getPhysicalScaling();
     210
     211    Matrix4x4d mat;
     212    mat.makeTranslation(origin);
     213    Matrix4x4d mat2;
     214    mat2.makeScale(scale);
     215
     216    mat.multiply(mat2);
     217
     218    Vector3f min, max;
     219    min.x = vol->xAxis.min();
     220    min.y = vol->yAxis.min();
     221    min.z = vol->zAxis.min();
     222    max.x = vol->xAxis.max();
     223    max.y = vol->yAxis.max();
     224    max.z = vol->zAxis.max();
     225
     226    float x0, y0, z0, x1, y1, z1;
     227    x0 = y0 = z0 = 0.0f;
     228    x1 = y1 = z1 = 0.0f;
     229    if (max.x > min.x) {
     230        x0 = (_sv.corner1.x - min.x) / (max.x - min.x);
     231        x1 = (_sv.corner2.x - min.x) / (max.x - min.x);
     232    }
     233    if (max.y > min.y) {
     234        y0 = (_sv.corner1.y - min.y) / (max.y - min.y);
     235        y1 = (_sv.corner2.y - min.y) / (max.y - min.y);
     236    }
     237    if (max.z > min.z) {
     238        z0 = (_sv.corner1.z - min.z) / (max.z - min.z);
     239        z1 = (_sv.corner2.z - min.z) / (max.z - min.z);
     240    }
     241
     242    TRACE("Box model bounds: (%g,%g,%g) - (%g,%g,%g)", x0, y0, z0, x1, y1, z1);
     243
     244    Vector3f modelMin(x0, y0, z0);
     245    Vector3f modelMax(x1, y1, z1);
     246
     247    Vector4f bvert[8];
     248    bvert[0] = Vector4f(modelMin.x, modelMin.y, modelMin.z, 1);
     249    bvert[1] = Vector4f(modelMax.x, modelMin.y, modelMin.z, 1);
     250    bvert[2] = Vector4f(modelMin.x, modelMax.y, modelMin.z, 1);
     251    bvert[3] = Vector4f(modelMin.x, modelMin.y, modelMax.z, 1);
     252    bvert[4] = Vector4f(modelMax.x, modelMax.y, modelMin.z, 1);
     253    bvert[5] = Vector4f(modelMax.x, modelMin.y, modelMax.z, 1);
     254    bvert[6] = Vector4f(modelMin.x, modelMax.y, modelMax.z, 1);
     255    bvert[7] = Vector4f(modelMax.x, modelMax.y, modelMax.z, 1);
     256
     257    for (int i = 0; i < 8; i++) {
     258        Vector4f worldVert = mat.transform(bvert[i]);
     259        if (worldVert.x < bboxMin.x) bboxMin.x = worldVert.x;
     260        if (worldVert.x > bboxMax.x) bboxMax.x = worldVert.x;
     261        if (worldVert.y < bboxMin.y) bboxMin.y = worldVert.y;
     262        if (worldVert.y > bboxMax.y) bboxMax.y = worldVert.y;
     263        if (worldVert.z < bboxMin.z) bboxMin.z = worldVert.z;
     264        if (worldVert.z > bboxMax.z) bboxMax.z = worldVert.z;
     265    }
     266
     267    TRACE("Box world bounds: (%g,%g,%g) - (%g,%g,%g)",
     268          bboxMin.x, bboxMin.y, bboxMin.z,
     269          bboxMax.x, bboxMax.y, bboxMax.z);
     270}
     271
    194272void
    195 FlowBox::Render(Volume *volPtr)
     273FlowBox::Render(Volume *vol)
    196274{
    197275    TRACE("Rendering box %s", _name);
     
    206284    glPushMatrix();
    207285
    208     Vector3 origin = volPtr->location();
     286    Vector3f origin = vol->location();
    209287    glTranslatef(origin.x, origin.y, origin.z);
    210288
    211     Vector3 scale = volPtr->getPhysicalScaling();
    212     glScaled(scale.x, scale.y, scale.z);
    213 
    214     Vector3 min, max;
    215     min.x = volPtr->xAxis.min();
    216     min.y = volPtr->yAxis.min();
    217     min.z = volPtr->zAxis.min();
    218     max.x = volPtr->xAxis.max();
    219     max.y = volPtr->yAxis.max();
    220     max.z = volPtr->zAxis.max();
     289    Vector3f scale = vol->getPhysicalScaling();
     290    glScalef(scale.x, scale.y, scale.z);
     291
     292    Vector3f min, max;
     293    min.x = vol->xAxis.min();
     294    min.y = vol->yAxis.min();
     295    min.z = vol->zAxis.min();
     296    max.x = vol->xAxis.max();
     297    max.y = vol->yAxis.max();
     298    max.z = vol->zAxis.max();
    221299
    222300    TRACE("box is %g,%g %g,%g %g,%g",
     
    557635    }
    558636
    559     Vector3 scale = volPtr->getPhysicalScaling();
    560     Vector3 location = _volPtr->location();
     637    Vector3f scale = volPtr->getPhysicalScaling();
     638    Vector3f location = _volPtr->location();
    561639
    562640    _fieldPtr->setVectorField(_volPtr,
     
    688766    volPtr->visible(_sv.showVolume);
    689767
    690     Vector3 volScaling = volPtr->getPhysicalScaling();
    691     float dx0 = -0.5 * volScaling.x;
    692     float dy0 = -0.5 * volScaling.y;
    693     float dz0 = -0.5 * volScaling.z;
    694     volPtr->location(Vector3(dx0, dy0, dz0));
     768    Vector3f volScaling = volPtr->getPhysicalScaling();
     769    Vector3f loc(volScaling);
     770    loc *= -0.5;
     771    volPtr->location(loc);
    695772
    696773    Volume::updatePending = true;
     
    10131090{
    10141091    flags &= ~MAP_FLOWS;
    1015     TRACE("MapFlows");
     1092    TRACE("Enter");
    10161093
    10171094    /*
     
    10571134        }
    10581135    }
     1136
    10591137    TRACE("MapFlows magMin=%g magMax=%g", NanoVis::magMin, NanoVis::magMax);
    10601138
     
    10791157    AdvectFlows();
    10801158    return true;
     1159}
     1160
     1161void
     1162NanoVis::GetFlowBounds(Vector3f& min,
     1163                       Vector3f& max,
     1164                       bool onlyVisible)
     1165{
     1166    TRACE("Enter");
     1167
     1168    min.set(FLT_MAX, FLT_MAX, FLT_MAX);
     1169    max.set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
     1170
     1171    FlowCmd *flow;
     1172    FlowIterator iter;
     1173    for (flow = FirstFlow(&iter); flow != NULL;
     1174         flow = NextFlow(&iter)) {
     1175        if (onlyVisible && !flow->visible())
     1176            continue;
     1177 #if 0  // Using volume bounds instead of these
     1178        if (flow->isDataLoaded()) {
     1179            Vector3f umin, umax;
     1180            Rappture::Unirect3d *unirect = flow->data();
     1181            unirect->getWorldSpaceBounds(umin, umax);
     1182            if (min.x > umin.x) {
     1183                min.x = umin.x;
     1184            }
     1185            if (max.x < umax.x) {
     1186                max.x = umax.x;
     1187            }
     1188            if (min.y > umin.y) {
     1189                min.y = umin.y;
     1190            }
     1191            if (max.y < umax.y) {
     1192                max.y = umax.y;
     1193            }
     1194            if (min.z > umin.z) {
     1195                min.z = umin.z;
     1196            }
     1197            if (max.z < umax.z) {
     1198                max.z = umax.z;
     1199            }
     1200        }
     1201#endif
     1202        FlowBox *box;
     1203        FlowBoxIterator iter;
     1204        for (box = flow->FirstBox(&iter); box != NULL;
     1205             box = flow->NextBox(&iter)) {
     1206            TRACE("found box %s", box->name());
     1207            if (!onlyVisible || box->visible()) {
     1208                Vector3f fbmin, fbmax;
     1209                box->getWorldSpaceBounds(fbmin, fbmax,
     1210                                         flow->getVolume());
     1211                if (min.x > fbmin.x) {
     1212                    min.x = fbmin.x;
     1213                }
     1214                if (max.x < fbmax.x) {
     1215                    max.x = fbmax.x;
     1216                }
     1217                if (min.y > fbmin.y) {
     1218                    min.y = fbmin.y;
     1219                }
     1220                if (max.y < fbmax.y) {
     1221                    max.y = fbmax.y;
     1222                }
     1223                if (min.z > fbmin.z) {
     1224                    min.z = fbmin.z;
     1225                }
     1226                if (max.z < fbmax.z) {
     1227                    max.z = fbmax.z;
     1228                }
     1229            }
     1230        }
     1231    }
    10811232}
    10821233
Note: See TracChangeset for help on using the changeset viewer.