source: trunk/packages/vizservers/vtkvis/RpPseudoColor.cpp @ 2100

Last change on this file since 2100 was 2100, checked in by ldelgass, 13 years ago

VTKVis server for 2D contour plots. Required modifications to vizservers build
to follow.

  • 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) 2011, Purdue Research Foundation
4 *
5 * Author: Leif Delgass <ldelgass@purdue.edu>
6 */
7
8#include <vtkDataSet.h>
9#include <vtkDataSetMapper.h>
10#include <vtkProperty.h>
11#include <vtkPointData.h>
12#include <vtkLookupTable.h>
13
14#include "RpPseudoColor.h"
15#include "Trace.h"
16
17using namespace Rappture::VtkVis;
18
19PseudoColor::PseudoColor() :
20    _dataSet(NULL),
21    _opacity(1.0)
22{
23}
24
25PseudoColor::~PseudoColor()
26{
27}
28
29/**
30 * \brief Specify input DataSet with scalars to colormap
31 *
32 * Currently the DataSet must be image data (2D uniform grid)
33 */
34void PseudoColor::setDataSet(DataSet *dataSet)
35{
36    _dataSet = dataSet;
37    update();
38}
39
40/**
41 * \brief Internal method to set up color mapper after a state change
42 */
43void PseudoColor::update()
44{
45    if (_dataSet == NULL)
46        return;
47
48    vtkDataSet *ds = _dataSet->getVtkDataSet();
49
50    double dataRange[2];
51    _dataSet->getDataRange(dataRange);
52
53    // Mapper, actor to render color-mapped data set
54    if (_dsMapper == NULL) {
55        _dsMapper = vtkSmartPointer<vtkDataSetMapper>::New();
56    }
57    _dsMapper->SetInput(ds);
58    _dsMapper->StaticOff();
59
60    vtkLookupTable *lut = ds->GetPointData()->GetScalars()->GetLookupTable();
61    TRACE("Data set scalars lookup table: %p\n", lut);
62    if (_lut == NULL) {
63        if (lut)
64            _lut = lut;
65        else
66            _lut = vtkSmartPointer<vtkLookupTable>::New();
67    } else {
68       
69    }
70    _lut->SetRange(dataRange);
71
72    _dsMapper->SetLookupTable(_lut);
73    _dsMapper->SetScalarRange(dataRange);
74    //_dsMapper->GetLookupTable()->SetRange(dataRange);
75    //_dsMapper->InterpolateScalarsBeforeMappingOn();
76
77    initActor();
78    _dsActor->SetMapper(_dsMapper);
79    //_dsActor->GetProperty()->SetRepresentationToWireframe();
80}
81
82/**
83 * \brief Get the VTK Actor for the colormap iamge
84 */
85vtkActor *PseudoColor::getActor()
86{
87    return _dsActor;
88}
89
90/**
91 * \brief Create and initialize a VTK actor to render the colormap image
92 */
93void PseudoColor::initActor()
94{
95    if (_dsActor == NULL) {
96        _dsActor = vtkSmartPointer<vtkActor>::New();
97        _dsActor->GetProperty()->SetOpacity(_opacity);
98    }
99}
100
101/**
102 * \brief Get the VTK colormap lookup table in use
103 */
104vtkLookupTable *PseudoColor::getLookupTable()
105{
106    return _lut;
107}
108
109/**
110 * \brief Associate a colormap lookup table with the DataSet
111 */
112void PseudoColor::setLookupTable(vtkLookupTable *lut)
113{
114    if (lut == NULL) {
115        _lut = vtkSmartPointer<vtkLookupTable>::New();
116    } else {
117        _lut = lut;
118    }
119
120    if (_dataSet != NULL) {
121        double dataRange[2];
122        _dataSet->getDataRange(dataRange);
123        _lut->SetRange(dataRange);
124
125        if (_dataSet->getVtkDataSet()->GetPointData()->GetScalars()->GetLookupTable()) {
126            TRACE("Change scalar table: %p %p\n",
127                  _dataSet->getVtkDataSet()->GetPointData()->GetScalars()->GetLookupTable(),
128                  _lut.GetPointer());
129            _dataSet->getVtkDataSet()->GetPointData()->GetScalars()->SetLookupTable(_lut);
130            TRACE("Scalar Table: %p\n", _dataSet->getVtkDataSet()->GetPointData()->GetScalars()->GetLookupTable());
131        }
132    }
133    if (_dsMapper != NULL) {
134        _dsMapper->SetLookupTable(_lut);
135    }
136}
137
138/**
139 * \brief Turn on/off rendering of this colormap image
140 */
141void PseudoColor::setVisibility(bool state)
142{
143    if (_dsActor != NULL) {
144        _dsActor->SetVisibility((state ? 1 : 0));
145    }
146}
147
148/**
149 * \brief Set opacity used to render the colormap image
150 */
151void PseudoColor::setOpacity(double opacity)
152{
153    _opacity = opacity;
154    if (_dsActor != NULL)
155        _dsActor->GetProperty()->SetOpacity(opacity);
156}
157
158/**
159 * \brief Set a group of world coordinate planes to clip rendering
160 */
161void PseudoColor::setClippingPlanes(vtkPlaneCollection *planes)
162{
163    if (_dsMapper != NULL)
164        _dsMapper->SetClippingPlanes(planes);
165}
Note: See TracBrowser for help on using the repository browser.