source: trunk/packages/vizservers/nanovis/Volume.cpp @ 1489

Last change on this file since 1489 was 1478, checked in by gah, 15 years ago

Fix volume management routines to handle deletion

File size: 2.8 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 <memory.h>
17#include <assert.h>
18#include "Volume.h"
19#include "Trace.h"
20
21bool Volume::update_pending = false;
22double Volume::valueMin = 0.0;
23double Volume::valueMax = 1.0;
24
25Volume::Volume(
26                float x, float y, float z,
27                int w, int h, int d, float s,
28                int n, float* data, double v0, double v1, double nz_min):
29    _tfPtr(NULL),
30    _specular(6.),              // default value
31    _diffuse(3.),               // default value
32    _opacity_scale(10.),        // default value
33    _n_components(n),
34    _nonzero_min(nz_min),
35    _pointsetIndex(-1),
36    _n_slices(512),             // default value
37    _enabled(true),
38    //n_slice(256),             // default value
39    _data_enabled(true),                // default value
40    _outline_enabled(true),     // default value
41    _outline_color(1.,1.,1.),   // default value
42    _volume_type(CUBIC),                //by default, is a cubic volume
43    _iso_surface(0),
44    width(w),
45    height(h),
46    depth(d),
47    size(s)
48{
49    _volumeDataID = -1;
50
51    _tex = new Texture3D(w, h, d, NVIS_FLOAT, NVIS_LINEAR_INTERP, 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
91Volume::~Volume()
92{
93    if (_pointsetIndex != -1)
94    {
95        // TBD...
96    }
97
98    delete [] _data;
99
100    delete _tex;
101}
Note: See TracBrowser for help on using the repository browser.