1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
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 | * |
---|
10 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
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 | */ |
---|
16 | #include <memory.h> |
---|
17 | #include <assert.h> |
---|
18 | #include <float.h> |
---|
19 | |
---|
20 | #include <vrmath/Vector4f.h> |
---|
21 | #include <vrmath/Matrix4x4d.h> |
---|
22 | |
---|
23 | #include "Volume.h" |
---|
24 | #include "Trace.h" |
---|
25 | |
---|
26 | using namespace nv; |
---|
27 | using namespace vrmath; |
---|
28 | |
---|
29 | bool Volume::updatePending = false; |
---|
30 | double Volume::valueMin = 0.0; |
---|
31 | double Volume::valueMax = 1.0; |
---|
32 | |
---|
33 | Volume::Volume(int width, int height, int depth, |
---|
34 | int numComponents, float *data, |
---|
35 | double vmin, double vmax, double nonZeroMin) : |
---|
36 | _id(0), |
---|
37 | _width(width), |
---|
38 | _height(height), |
---|
39 | _depth(depth), |
---|
40 | _transferFunc(NULL), |
---|
41 | _ambient(0.6f), |
---|
42 | _diffuse(0.4f), |
---|
43 | _specular(0.3f), |
---|
44 | _specularExp(90.0f), |
---|
45 | _lightTwoSide(false), |
---|
46 | _opacityScale(0.5f), |
---|
47 | _data(NULL), |
---|
48 | _numComponents(numComponents), |
---|
49 | _nonZeroMin(nonZeroMin), |
---|
50 | _cutplanesVisible(true), |
---|
51 | _tex(NULL), |
---|
52 | _position(0, 0, 0), |
---|
53 | _scale(1, 1, 1), |
---|
54 | _numSlices(512), |
---|
55 | _enabled(true), |
---|
56 | _dataEnabled(true), |
---|
57 | _outlineEnabled(true), |
---|
58 | _volumeType(CUBIC), |
---|
59 | _isosurface(0) |
---|
60 | { |
---|
61 | TRACE("Enter: %dx%dx%d", _width, _height, _depth); |
---|
62 | |
---|
63 | _outlineColor[0] = _outlineColor[1] = _outlineColor[2] = 1.0f; |
---|
64 | |
---|
65 | _tex = new Texture3D(_width, _height, _depth, GL_FLOAT, GL_LINEAR, _numComponents); |
---|
66 | int fcount = _width * _height * _depth * _numComponents; |
---|
67 | _data = new float[fcount]; |
---|
68 | memcpy(_data, data, fcount * sizeof(float)); |
---|
69 | _tex->initialize(_data); |
---|
70 | |
---|
71 | _id = _tex->id(); |
---|
72 | |
---|
73 | wAxis.setRange(vmin, vmax); |
---|
74 | |
---|
75 | //Add cut planes. We create 3 default cut planes facing x, y, z directions. |
---|
76 | //The default location of cut plane is in the middle of the data. |
---|
77 | _plane.clear(); |
---|
78 | addCutplane(CutPlane::X_AXIS, 0.5f); |
---|
79 | addCutplane(CutPlane::Y_AXIS, 0.5f); |
---|
80 | addCutplane(CutPlane::Z_AXIS, 0.5f); |
---|
81 | |
---|
82 | TRACE("Leave"); |
---|
83 | } |
---|
84 | |
---|
85 | Volume::~Volume() |
---|
86 | { |
---|
87 | TRACE("Enter"); |
---|
88 | |
---|
89 | delete [] _data; |
---|
90 | delete _tex; |
---|
91 | } |
---|
92 | |
---|
93 | void Volume::setData(float *data, double vmin, double vmax, double nonZeroMin) |
---|
94 | { |
---|
95 | int fcount = _width * _height * _depth * _numComponents; |
---|
96 | memcpy(_data, data, fcount * sizeof(float)); |
---|
97 | _tex->update(_data); |
---|
98 | wAxis.setRange(vmin, vmax); |
---|
99 | _nonZeroMin = nonZeroMin; |
---|
100 | updatePending = true; |
---|
101 | } |
---|
102 | |
---|
103 | void Volume::getBounds(Vector3f& bboxMin, Vector3f& bboxMax) const |
---|
104 | { |
---|
105 | bboxMin.set(xAxis.min(), yAxis.min(), zAxis.min()); |
---|
106 | bboxMax.set(xAxis.max(), yAxis.max(), zAxis.max()); |
---|
107 | } |
---|