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 | |
---|
17 | #include <memory.h> |
---|
18 | #include <assert.h> |
---|
19 | #include "Volume.h" |
---|
20 | #include "Trace.h" |
---|
21 | |
---|
22 | bool Volume::update_pending = false; |
---|
23 | double Volume::valueMin = 0.0; |
---|
24 | double Volume::valueMax = 1.0; |
---|
25 | |
---|
26 | Volume::Volume( |
---|
27 | float x, float y, float z, |
---|
28 | int w, int h, int d, float s, |
---|
29 | int n, float* data, double v0, double v1, double nz_min): |
---|
30 | _tfPtr(NULL), |
---|
31 | _specular(6.), // default value |
---|
32 | _diffuse(3.), // default value |
---|
33 | _opacity_scale(10.), // default value |
---|
34 | _name(NULL), |
---|
35 | _n_components(n), |
---|
36 | _nonzero_min(nz_min), |
---|
37 | _pointsetIndex(-1), |
---|
38 | _n_slices(512), // default value |
---|
39 | _enabled(true), |
---|
40 | //n_slice(256), // default value |
---|
41 | _data_enabled(true), // default value |
---|
42 | _outline_enabled(true), // default value |
---|
43 | _outline_color(1.,1.,1.), // default value |
---|
44 | _volume_type(CUBIC), //by default, is a cubic volume |
---|
45 | _iso_surface(0), |
---|
46 | width(w), |
---|
47 | height(h), |
---|
48 | depth(d), |
---|
49 | size(s) |
---|
50 | { |
---|
51 | _tex = new Texture3D(w, h, d, GL_FLOAT, GL_LINEAR, n); |
---|
52 | int fcount = width * height * depth * _n_components; |
---|
53 | _data = new float[fcount]; |
---|
54 | if (data != NULL) { |
---|
55 | TRACE("data is copied\n"); |
---|
56 | memcpy(_data, data, fcount * sizeof(float)); |
---|
57 | _tex->initialize(_data); |
---|
58 | } else { |
---|
59 | TRACE("data is null\n"); |
---|
60 | memset(_data, 0, sizeof(width * height * depth * _n_components * |
---|
61 | sizeof(float))); |
---|
62 | _tex->initialize(_data); |
---|
63 | } |
---|
64 | |
---|
65 | id = _tex->id; |
---|
66 | |
---|
67 | wAxis.SetRange(v0, v1); |
---|
68 | |
---|
69 | // VOLUME |
---|
70 | aspect_ratio_width = s * _tex->aspect_ratio_width; |
---|
71 | aspect_ratio_height = s * _tex->aspect_ratio_height; |
---|
72 | aspect_ratio_depth = s * _tex->aspect_ratio_depth; |
---|
73 | |
---|
74 | _location = Vector3(x,y,z); |
---|
75 | |
---|
76 | //Add cut planes. We create 3 default cut planes facing x, y, z directions. |
---|
77 | //The default location of cut plane is in the middle of the data. |
---|
78 | _plane.clear(); |
---|
79 | _plane.push_back(CutPlane(1, 0.5)); |
---|
80 | _plane.push_back(CutPlane(2, 0.5)); |
---|
81 | _plane.push_back(CutPlane(3, 0.5)); |
---|
82 | |
---|
83 | //initialize the labels |
---|
84 | label[0] = "X Label"; |
---|
85 | label[1] = "Y Label"; |
---|
86 | label[2] = "Z Label"; |
---|
87 | |
---|
88 | TRACE("End -- Volume constructor\n"); |
---|
89 | } |
---|
90 | |
---|
91 | Volume::~Volume() |
---|
92 | { |
---|
93 | if (_pointsetIndex != -1) |
---|
94 | { |
---|
95 | // TBD... |
---|
96 | } |
---|
97 | |
---|
98 | delete [] _data; |
---|
99 | |
---|
100 | delete _tex; |
---|
101 | } |
---|