1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Volume.cpp: 3d volume class |
---|
4 | * |
---|
5 | * ====================================================================== |
---|
6 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
7 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
8 | * |
---|
9 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
10 | * |
---|
11 | * See the file "license.terms" for information on usage and |
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | * ====================================================================== |
---|
14 | */ |
---|
15 | |
---|
16 | #include <memory.h> |
---|
17 | #include <assert.h> |
---|
18 | #include "Volume.h" |
---|
19 | #include "Trace.h" |
---|
20 | |
---|
21 | bool Volume::update_pending = false; |
---|
22 | double Volume::valueMin = 0.0; |
---|
23 | double Volume::valueMax = 1.0; |
---|
24 | |
---|
25 | Volume::Volume(float x, float y, float z, |
---|
26 | int w, int h, int d, float s, |
---|
27 | int n, float* data, double v0, double v1, double nz_min): |
---|
28 | width(w), |
---|
29 | height(h), |
---|
30 | depth(d), |
---|
31 | size(s), |
---|
32 | n_components(n), |
---|
33 | nonzero_min(nz_min), |
---|
34 | pointsetIndex(-1), |
---|
35 | enabled(true), |
---|
36 | //n_slice(256), // default value |
---|
37 | n_slice(512), // default value |
---|
38 | specular(6.), // default value |
---|
39 | diffuse(3.), // default value |
---|
40 | opacity_scale(10.), // 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 | { |
---|
47 | Trace("Volume constructor\n"); |
---|
48 | |
---|
49 | tex = new Texture3D(w, h, d, NVIS_FLOAT, NVIS_LINEAR_INTERP, n); |
---|
50 | int fcount = width * height * depth * n_components; |
---|
51 | _data = new float[fcount]; |
---|
52 | if (data) { |
---|
53 | Trace("data is copied\n"); |
---|
54 | memcpy(_data, data, fcount * sizeof(float)); |
---|
55 | tex->initialize(_data); |
---|
56 | } else { |
---|
57 | Trace("data is null\n"); |
---|
58 | memset(_data, 0, sizeof(width * height * depth * n_components * |
---|
59 | sizeof(float))); |
---|
60 | tex->initialize(_data); |
---|
61 | } |
---|
62 | |
---|
63 | id = tex->id; |
---|
64 | |
---|
65 | wAxis.SetRange(v0, v1); |
---|
66 | |
---|
67 | aspect_ratio_width = s*tex->aspect_ratio_width; |
---|
68 | aspect_ratio_height = s*tex->aspect_ratio_height; |
---|
69 | aspect_ratio_depth = s*tex->aspect_ratio_depth; |
---|
70 | |
---|
71 | location = Vector3(x,y,z); |
---|
72 | |
---|
73 | //Add cut planes. We create 3 default cut planes facing x, y, z directions. |
---|
74 | //The default location of cut plane is in the middle of the data. |
---|
75 | plane.clear(); |
---|
76 | plane.push_back(CutPlane(1, 0.5)); |
---|
77 | plane.push_back(CutPlane(2, 0.5)); |
---|
78 | plane.push_back(CutPlane(3, 0.5)); |
---|
79 | |
---|
80 | //initialize the labels |
---|
81 | label[0] = "X Label"; |
---|
82 | label[1] = "Y Label"; |
---|
83 | label[2] = "Z Label"; |
---|
84 | |
---|
85 | Trace("End -- Volume constructor\n"); |
---|
86 | } |
---|
87 | |
---|
88 | Volume::~Volume() |
---|
89 | { |
---|
90 | if (pointsetIndex != -1) |
---|
91 | { |
---|
92 | // TBD... |
---|
93 | } |
---|
94 | |
---|
95 | delete [] _data; |
---|
96 | |
---|
97 | delete tex; |
---|
98 | } |
---|