source: trunk/packages/vizservers/vtkvis/Image.cpp @ 4026

Last change on this file since 4026 was 3991, checked in by ldelgass, 11 years ago

Add debugging of window/level

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2004-2013  HUBzero Foundation, LLC
4 *
5 * Author: Leif Delgass <ldelgass@purdue.edu>
6 */
7
8#include <vtkSmartPointer.h>
9#include <vtkImageData.h>
10#include <vtkImageActor.h>
11#include <vtkImageSlice.h>
12#include <vtkImageProperty.h>
13#include <vtkImageMapper3D.h>
14#include <vtkImageResliceMapper.h>
15#include <vtkLookupTable.h>
16
17#include "Image.h"
18#include "Trace.h"
19
20using namespace VtkVis;
21
22#define USE_RESLICE_MAPPER
23
24Image::Image() :
25    GraphicsObject(),
26    _colorMap(NULL)
27{
28}
29
30Image::~Image()
31{
32    TRACE("Deleting Image");
33}
34
35void Image::initProp()
36{
37    if (_prop == NULL) {
38#ifdef USE_RESLICE_MAPPER
39        _prop = vtkSmartPointer<vtkImageSlice>::New();
40#else
41        _prop = vtkSmartPointer<vtkImageActor>::New();
42#endif
43        vtkImageProperty *property = getImageProperty();
44        property->SetInterpolationTypeToLinear();
45        property->SetBackingColor(_color[0], _color[1], _color[2]);
46        property->BackingOff();
47        if (_dataSet != NULL)
48            _opacity = _dataSet->getOpacity();
49        property->SetOpacity(_opacity);
50
51        if (_dataSet != NULL)
52            setVisibility(_dataSet->getVisibility());
53    }
54}
55
56void Image::update()
57{
58    if (_dataSet == NULL)
59        return;
60
61    TRACE("DataSet: %s", _dataSet->getName().c_str());
62
63    vtkDataSet *ds = _dataSet->getVtkDataSet();
64    vtkImageData *imageData = vtkImageData::SafeDownCast(ds);
65
66    if (imageData == NULL) {
67        ERROR("DataSet is not an image.");
68        return;
69    }
70
71    initProp();
72
73    vtkImageActor *actor = getImageActor();
74    vtkImageMapper3D *mapper = getImageMapper();
75    if (mapper == NULL) {
76        TRACE("Creating mapper");
77        vtkSmartPointer<vtkImageResliceMapper> newMapper = vtkSmartPointer<vtkImageResliceMapper>::New();
78        getImageSlice()->SetMapper(newMapper);
79        mapper = getImageMapper();
80        assert(mapper != NULL);
81    }
82    if (actor != NULL) {
83        TRACE("Have actor");
84        actor->SetInputData(imageData);
85        actor->InterpolateOn();
86    } else {
87        TRACE("No actor");
88        mapper->SetInputData(imageData);
89    }
90
91    mapper->SliceAtFocalPointOn();
92    mapper->SliceFacesCameraOn();
93
94    vtkImageResliceMapper *resliceMapper = getImageResliceMapper();
95    if (resliceMapper) {
96        TRACE("Mapper is a vtkImageResliceMapper");
97        resliceMapper->AutoAdjustImageQualityOff();
98        resliceMapper->ResampleToScreenPixelsOff();
99    } else {
100        TRACE("Mapper is a %s", mapper->GetClassName());
101    }
102
103    mapper->Update();
104
105    TRACE("Window: %g Level: %g", getWindow(), getLevel());
106}
107
108void Image::setColor(float color[3])
109{
110    GraphicsObject::setColor(color);
111
112    if (getImageProperty() != NULL) {
113        getImageProperty()->SetBackingColor(color[0], color[1], color[2]);
114    }
115}
116
117/**
118 * \brief Associate a colormap lookup table with the DataSet
119 */
120void Image::setColorMap(ColorMap *cmap)
121{
122    if (cmap == NULL) {
123        _colorMap = NULL;
124        _lut = NULL;
125        if (getImageProperty() != NULL) {
126            getImageProperty()->SetLookupTable(NULL);
127        }
128        return;
129    }
130
131    _colorMap = cmap;
132 
133    if (_lut == NULL) {
134        _lut = vtkSmartPointer<vtkLookupTable>::New();
135        if (getImageProperty() != NULL) {
136            getImageProperty()->UseLookupTableScalarRangeOn();
137            getImageProperty()->SetLookupTable(_lut);
138        }
139        _lut->DeepCopy(cmap->getLookupTable());
140        _lut->SetRange(_dataRange);
141    } else {
142        double range[2];
143        _lut->GetTableRange(range);
144        _lut->DeepCopy(cmap->getLookupTable());
145        _lut->SetRange(range);
146        _lut->Modified();
147    }
148}
149
150void Image::setClippingPlanes(vtkPlaneCollection *planes)
151{
152    vtkImageMapper3D *mapper = getImageMapper();
153    if (mapper != NULL) {
154        mapper->SetClippingPlanes(planes);
155    }
156}
Note: See TracBrowser for help on using the repository browser.