source: trunk/vizservers/nanovis/Volume.cpp @ 829

Last change on this file since 829 was 776, checked in by vrinside, 17 years ago

Add 3D surface plot and grid rendering

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