source: nanovis/branches/1.1/Volume.cpp @ 4890

Last change on this file since 4890 was 4889, checked in by ldelgass, 9 years ago

Merge r3611:3618 from trunk

  • Property svn:eol-style set to native
File size: 3.9 KB
RevLine 
[2798]1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
[835]2/*
3 * ----------------------------------------------------------------------
4 * Volume.cpp: 3d volume class
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
[3502]10 *  Copyright (c) 2004-2013  HUBzero Foundation, LLC
[835]11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
[1053]16#include <memory.h>
[835]17#include <assert.h>
[3492]18#include <float.h>
[2844]19
[3492]20#include <vrmath/Vector4f.h>
21#include <vrmath/Matrix4x4d.h>
22
[835]23#include "Volume.h"
[884]24#include "Trace.h"
[835]25
[4889]26using namespace nv;
[3492]27using namespace vrmath;
28
[2877]29bool Volume::updatePending = false;
[932]30double Volume::valueMin = 0.0;
31double Volume::valueMax = 1.0;
[835]32
[2816]33Volume::Volume(float x, float y, float z,
[3362]34               int w, int h, int d,
[2844]35               int n, float *data,
[2877]36               double v0, double v1, double nonZeroMin) :
[3362]37    _id(0),
38    _width(w),
39    _height(h),
40    _depth(d),
[4612]41    _transferFunc(NULL),
[3362]42    _ambient(0.6f),
43    _diffuse(0.4f),
44    _specular(0.3f),
45    _specularExp(90.0f),
46    _lightTwoSide(false),
47    _opacityScale(0.5f),
[2844]48    _data(NULL),
[2877]49    _numComponents(n),
50    _nonZeroMin(nonZeroMin),
[4818]51    _cutplanesVisible(true),
[2844]52    _tex(NULL),
53    _location(x, y, z),
[2877]54    _numSlices(512),
[1478]55    _enabled(true),
[2877]56    _dataEnabled(true),
57    _outlineEnabled(true),
58    _volumeType(CUBIC),
59    _isosurface(0)
[835]60{
[3452]61    TRACE("Enter: %dx%dx%d", _width, _height, _depth);
[3362]62
[3492]63    _outlineColor[0] = _outlineColor[1] = _outlineColor[2] = 1.0f;
64
[3362]65    _tex = new Texture3D(_width, _height, _depth, GL_FLOAT, GL_LINEAR, n);
66    int fcount = _width * _height * _depth * _numComponents;
[900]67    _data = new float[fcount];
[1429]68    if (data != NULL) {
[3452]69        TRACE("data is copied");
[900]70        memcpy(_data, data, fcount * sizeof(float));
[1478]71        _tex->initialize(_data);
[932]72    } else {
[3452]73        TRACE("data is null");
[3362]74        memset(_data, 0, sizeof(_width * _height * _depth * _numComponents *
[932]75                                sizeof(float)));
[1478]76        _tex->initialize(_data);
[884]77    }
78
[3362]79    _id = _tex->id();
[2816]80
[2932]81    wAxis.setRange(v0, v1);
[929]82
[835]83    //Add cut planes. We create 3 default cut planes facing x, y, z directions.
84    //The default location of cut plane is in the middle of the data.
[1478]85    _plane.clear();
[2877]86    addCutplane(1, 0.5f);
87    addCutplane(2, 0.5f);
88    addCutplane(3, 0.5f);
[2816]89
[3452]90    TRACE("Leave");
[835]91}
92
93Volume::~Volume()
[3362]94{
[3452]95    TRACE("Enter");
[884]96
97    delete [] _data;
[2816]98    delete _tex;
[835]99}
[3492]100
101void Volume::getWorldSpaceBounds(Vector3f& bboxMin, Vector3f& bboxMax) const
102{
103    Vector3f scale = getPhysicalScaling();
104
105    Matrix4x4d mat;
106    mat.makeTranslation(_location);
107    Matrix4x4d mat2;
108    mat2.makeScale(scale);
109
110    mat.multiply(mat2);
111
112    bboxMin.set(FLT_MAX, FLT_MAX, FLT_MAX);
113    bboxMax.set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
114
115    Vector3f modelMin(0, 0, 0);
116    Vector3f modelMax(1, 1, 1);
117
118    Vector4f bvert[8];
119    bvert[0] = Vector4f(modelMin.x, modelMin.y, modelMin.z, 1);
120    bvert[1] = Vector4f(modelMax.x, modelMin.y, modelMin.z, 1);
121    bvert[2] = Vector4f(modelMin.x, modelMax.y, modelMin.z, 1);
122    bvert[3] = Vector4f(modelMin.x, modelMin.y, modelMax.z, 1);
123    bvert[4] = Vector4f(modelMax.x, modelMax.y, modelMin.z, 1);
124    bvert[5] = Vector4f(modelMax.x, modelMin.y, modelMax.z, 1);
125    bvert[6] = Vector4f(modelMin.x, modelMax.y, modelMax.z, 1);
126    bvert[7] = Vector4f(modelMax.x, modelMax.y, modelMax.z, 1);
127
128    for (int i = 0; i < 8; i++) {
129        Vector4f worldVert = mat.transform(bvert[i]);
130        if (worldVert.x < bboxMin.x) bboxMin.x = worldVert.x;
131        if (worldVert.x > bboxMax.x) bboxMax.x = worldVert.x;
132        if (worldVert.y < bboxMin.y) bboxMin.y = worldVert.y;
133        if (worldVert.y > bboxMax.y) bboxMax.y = worldVert.y;
134        if (worldVert.z < bboxMin.z) bboxMin.z = worldVert.z;
135        if (worldVert.z > bboxMax.z) bboxMax.z = worldVert.z;
136    }
137}
Note: See TracBrowser for help on using the repository browser.