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 <assert.h>
|
---|
17 | #include "Volume.h"
|
---|
18 |
|
---|
19 |
|
---|
20 | Volume::Volume(float x, float y, float z,
|
---|
21 | int w, int h, int d, float s,
|
---|
22 | int n, float* data, double v0, double v1):
|
---|
23 | width(w),
|
---|
24 | height(h),
|
---|
25 | depth(d),
|
---|
26 | size(s),
|
---|
27 | n_components(n),
|
---|
28 | vmin(v0),
|
---|
29 | vmax(v1),
|
---|
30 | enabled(true),
|
---|
31 | n_slice(256), // default value
|
---|
32 | specular(6.), // default value
|
---|
33 | diffuse(3.), // default value
|
---|
34 | opacity_scale(10.), // default value
|
---|
35 | data_enabled(true), // default value
|
---|
36 | outline_enabled(true), // default value
|
---|
37 | outline_color(1.,1.,1.), // default value
|
---|
38 | volume_type(CUBIC) //by default, is a cubic volume
|
---|
39 | {
|
---|
40 |
|
---|
41 | tex = new Texture3D(w, h, d, NVIS_FLOAT, NVIS_LINEAR_INTERP, n);
|
---|
42 | tex->initialize(data);
|
---|
43 | id = tex->id;
|
---|
44 |
|
---|
45 | aspect_ratio_width = s*tex->aspect_ratio_width;
|
---|
46 | aspect_ratio_height = s*tex->aspect_ratio_height;
|
---|
47 | aspect_ratio_depth = s*tex->aspect_ratio_depth;
|
---|
48 |
|
---|
49 | location = Vector3(x,y,z);
|
---|
50 |
|
---|
51 | //Add cut planes. We create 3 default cut planes facing x, y, z directions.
|
---|
52 | //The default location of cut plane is in the middle of the data.
|
---|
53 | plane.clear();
|
---|
54 | plane.push_back(CutPlane(1, 0.5));
|
---|
55 | plane.push_back(CutPlane(2, 0.5));
|
---|
56 | plane.push_back(CutPlane(3, 0.5));
|
---|
57 |
|
---|
58 | //initialize the labels
|
---|
59 | label[0] = "X Label";
|
---|
60 | label[1] = "Y Label";
|
---|
61 | label[2] = "Z Label";
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | Volume::~Volume(){ delete tex; }
|
---|
66 |
|
---|
67 |
|
---|
68 | void Volume::enable() { enabled = true; }
|
---|
69 | void Volume::disable() { enabled = false; }
|
---|
70 | void Volume::move(Vector3 _loc) { location = _loc; }
|
---|
71 | bool Volume::is_enabled() { return enabled; }
|
---|
72 | Vector3* Volume::get_location() { return &location; }
|
---|
73 |
|
---|
74 |
|
---|
75 | int Volume::add_cutplane(int _orientation, float _location){
|
---|
76 | plane.push_back(CutPlane(1, 0.5));
|
---|
77 | return plane.size() - 1;
|
---|
78 | }
|
---|
79 |
|
---|
80 | void Volume::enable_cutplane(int index){
|
---|
81 | assert(index < plane.size());
|
---|
82 | plane[index].enabled = true;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void Volume::disable_cutplane(int index){
|
---|
86 | assert(index < plane.size());
|
---|
87 | plane[index].enabled = false;
|
---|
88 | }
|
---|
89 |
|
---|
90 | void Volume::move_cutplane(int index, float location){
|
---|
91 | assert(index < plane.size());
|
---|
92 | plane[index].offset = location;
|
---|
93 | }
|
---|
94 |
|
---|
95 | CutPlane* Volume::get_cutplane(int index){
|
---|
96 | assert(index < plane.size());
|
---|
97 | return &plane[index];
|
---|
98 | }
|
---|
99 |
|
---|
100 | int Volume::get_cutplane_count(){
|
---|
101 | return plane.size();
|
---|
102 | }
|
---|
103 |
|
---|
104 | bool Volume::cutplane_is_enabled(int index){
|
---|
105 | assert(index < plane.size());
|
---|
106 | return plane[index].enabled;
|
---|
107 | }
|
---|
108 |
|
---|
109 | void Volume::set_n_slice(int n) { n_slice = n; }
|
---|
110 | int Volume::get_n_slice() { return n_slice; }
|
---|
111 |
|
---|
112 | void Volume::set_size(float s) {
|
---|
113 | size = s;
|
---|
114 | aspect_ratio_width = s*tex->aspect_ratio_width;
|
---|
115 | aspect_ratio_height = s*tex->aspect_ratio_height;
|
---|
116 | aspect_ratio_depth = s*tex->aspect_ratio_depth;
|
---|
117 | }
|
---|
118 |
|
---|
119 | float Volume::get_specular() { return specular; }
|
---|
120 | float Volume::get_diffuse() { return diffuse; }
|
---|
121 | float Volume::get_opacity_scale() { return opacity_scale; }
|
---|
122 | void Volume::set_specular(float s) { specular = s; }
|
---|
123 | void Volume::set_diffuse(float d) { diffuse = d; }
|
---|
124 | void Volume::set_opacity_scale(float s) { opacity_scale = s; }
|
---|
125 |
|
---|
126 | void Volume::enable_data() { data_enabled = true; }
|
---|
127 | void Volume::disable_data() { data_enabled = false; }
|
---|
128 | bool Volume::data_is_enabled() { return data_enabled; }
|
---|
129 |
|
---|
130 | void Volume::enable_outline() { outline_enabled = true; }
|
---|
131 | void Volume::disable_outline() { outline_enabled = false; }
|
---|
132 | bool Volume::outline_is_enabled() { return outline_enabled; }
|
---|
133 | void Volume::set_outline_color(float *rgb) {
|
---|
134 | outline_color = Color(rgb[0],rgb[1],rgb[2]);
|
---|
135 | }
|
---|
136 | void Volume::get_outline_color(float *rgb) {
|
---|
137 | outline_color.GetRGB(rgb);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void Volume::set_label(int axis, char* txt){
|
---|
141 | label[axis] = txt;
|
---|
142 | }
|
---|