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-2006 Purdue Research Foundation |
---|
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 | |
---|
19 | #include "Volume.h" |
---|
20 | #include "Trace.h" |
---|
21 | |
---|
22 | bool Volume::updatePending = false; |
---|
23 | double Volume::valueMin = 0.0; |
---|
24 | double Volume::valueMax = 1.0; |
---|
25 | |
---|
26 | Volume::Volume(float x, float y, float z, |
---|
27 | int w, int h, int d, float s, |
---|
28 | int n, float *data, |
---|
29 | double v0, double v1, double nonZeroMin) : |
---|
30 | aspectRatioWidth(1), |
---|
31 | aspectRatioHeight(1), |
---|
32 | aspectRatioDepth(1), |
---|
33 | id(0), |
---|
34 | width(w), |
---|
35 | height(h), |
---|
36 | depth(d), |
---|
37 | size(s), |
---|
38 | pointsetIndex(-1), |
---|
39 | _tfPtr(NULL), |
---|
40 | _specular(6.), |
---|
41 | _diffuse(3.), |
---|
42 | _opacityScale(10.), |
---|
43 | _name(NULL), |
---|
44 | _data(NULL), |
---|
45 | _numComponents(n), |
---|
46 | _nonZeroMin(nonZeroMin), |
---|
47 | _tex(NULL), |
---|
48 | _location(x, y, z), |
---|
49 | _numSlices(512), |
---|
50 | _enabled(true), |
---|
51 | _dataEnabled(true), |
---|
52 | _outlineEnabled(true), |
---|
53 | _outlineColor(1., 1., 1.), |
---|
54 | _volumeType(CUBIC), |
---|
55 | _isosurface(0) |
---|
56 | { |
---|
57 | _tex = new Texture3D(w, h, d, GL_FLOAT, GL_LINEAR, n); |
---|
58 | int fcount = width * height * depth * _numComponents; |
---|
59 | _data = new float[fcount]; |
---|
60 | if (data != NULL) { |
---|
61 | TRACE("data is copied\n"); |
---|
62 | memcpy(_data, data, fcount * sizeof(float)); |
---|
63 | _tex->initialize(_data); |
---|
64 | } else { |
---|
65 | TRACE("data is null\n"); |
---|
66 | memset(_data, 0, sizeof(width * height * depth * _numComponents * |
---|
67 | sizeof(float))); |
---|
68 | _tex->initialize(_data); |
---|
69 | } |
---|
70 | |
---|
71 | id = _tex->id(); |
---|
72 | |
---|
73 | wAxis.setRange(v0, v1); |
---|
74 | |
---|
75 | // VOLUME |
---|
76 | aspectRatioWidth = s * _tex->aspectRatioWidth(); |
---|
77 | aspectRatioHeight = s * _tex->aspectRatioHeight(); |
---|
78 | aspectRatioDepth = s * _tex->aspectRatioDepth(); |
---|
79 | |
---|
80 | //Add cut planes. We create 3 default cut planes facing x, y, z directions. |
---|
81 | //The default location of cut plane is in the middle of the data. |
---|
82 | _plane.clear(); |
---|
83 | addCutplane(1, 0.5f); |
---|
84 | addCutplane(2, 0.5f); |
---|
85 | addCutplane(3, 0.5f); |
---|
86 | |
---|
87 | TRACE("End -- Volume constructor\n"); |
---|
88 | } |
---|
89 | |
---|
90 | Volume::~Volume() |
---|
91 | { |
---|
92 | if (pointsetIndex != -1) { |
---|
93 | // TBD... |
---|
94 | } |
---|
95 | |
---|
96 | delete [] _data; |
---|
97 | delete _tex; |
---|
98 | } |
---|