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

Last change on this file since 3935 was 3773, checked in by ldelgass, 11 years ago

Add Text3D,Image class files. Not yet integrated.

  • Property svn:eol-style set to native
File size: 2.7 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 <vtkImageProperty.h>
12#include <vtkImageMapper3D.h>
13#include <vtkLookupTable.h>
14
15#include "Image.h"
16#include "Trace.h"
17
18using namespace VtkVis;
19
20Image::Image() :
21    GraphicsObject(),
22    _colorMap(NULL)
23{
24}
25
26Image::~Image()
27{
28    TRACE("Deleting Image");
29}
30
31void Image::initProp()
32{
33    if (_prop == NULL) {
34        _prop = vtkSmartPointer<vtkImageActor>::New();
35        vtkImageProperty *property = getImageProperty();
36        property->SetInterpolationTypeToLinear();
37        property->SetBackingColor(_color[0], _color[1], _color[2]);
38        property->BackingOff();
39        if (_dataSet != NULL)
40            _opacity = _dataSet->getOpacity();
41        property->SetOpacity(_opacity);
42
43        if (_dataSet != NULL)
44            setVisibility(_dataSet->getVisibility());
45    }
46}
47
48void Image::update()
49{
50    if (_dataSet == NULL)
51        return;
52
53    TRACE("DataSet: %s", _dataSet->getName().c_str());
54
55    vtkDataSet *ds = _dataSet->getVtkDataSet();
56    vtkImageData *imageData = vtkImageData::SafeDownCast(ds);
57
58    if (imageData == NULL) {
59        ERROR("DataSet is not an image.");
60        return;
61    }
62
63    initProp();
64
65    vtkImageActor *actor = getImageActor();
66    actor->SetInputData(imageData);
67    actor->InterpolateOn();
68
69    vtkImageMapper3D *mapper = getImageMapper();
70    mapper->Update();
71}
72
73void Image::setColor(float color[3])
74{
75    GraphicsObject::setColor(color);
76
77    if (getImageProperty() != NULL) {
78        getImageProperty()->SetBackingColor(color[0], color[1], color[2]);
79    }
80}
81
82/**
83 * \brief Associate a colormap lookup table with the DataSet
84 */
85void Image::setColorMap(ColorMap *cmap)
86{
87    if (cmap == NULL) {
88        _colorMap = NULL;
89        _lut = NULL;
90        if (getImageProperty() != NULL) {
91            getImageProperty()->SetLookupTable(NULL);
92        }
93        return;
94    }
95
96    _colorMap = cmap;
97 
98    if (_lut == NULL) {
99        _lut = vtkSmartPointer<vtkLookupTable>::New();
100        if (getImageProperty() != NULL) {
101            getImageProperty()->UseLookupTableScalarRangeOn();
102            getImageProperty()->SetLookupTable(_lut);
103        }
104        _lut->DeepCopy(cmap->getLookupTable());
105        _lut->SetRange(_dataRange);
106    } else {
107        double range[2];
108        _lut->GetTableRange(range);
109        _lut->DeepCopy(cmap->getLookupTable());
110        _lut->SetRange(range);
111        _lut->Modified();
112    }
113}
114
115void Image::setClippingPlanes(vtkPlaneCollection *planes)
116{
117    vtkImageMapper3D *mapper = getImageMapper();
118    if (mapper != NULL) {
119        mapper->SetClippingPlanes(planes);
120    }
121}
Note: See TracBrowser for help on using the repository browser.