source: vtkvis/trunk/DataSet.h

Last change on this file was 6378, checked in by ldelgass, 8 years ago

add DataSet::setData method that takes an XML reader

  • 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-2012  HUBzero Foundation, LLC
4 *
5 * Author: Leif Delgass <ldelgass@purdue.edu>
6 */
7
8#ifndef VTKVIS_DATASET_H
9#define VTKVIS_DATASET_H
10
11#include <vtkSmartPointer.h>
12#include <vtkDataSet.h>
13#include <vtkDataSetReader.h>
14#include <vtkXMLReader.h>
15#include <vtkAlgorithmOutput.h>
16#include <vtkTrivialProducer.h>
17
18#include <string>
19#include <vector>
20
21#include "Types.h"
22#include "Trace.h"
23
24namespace VtkVis {
25
26/**
27 * \brief VTK DataSet wrapper
28 */
29class DataSet {
30public:
31    /**
32     * These enum values intentionally match vtkDataObject::FieldAssociations
33     * and vtkDataObject::AttributeTypes
34     */
35    enum DataAttributeType {
36        POINT_DATA,
37        CELL_DATA,
38        FIELD_DATA
39    };
40    DataSet(const std::string& name);
41    virtual ~DataSet();
42
43    void writeDataFile(const char *filename);
44
45    bool setDataFile(const char *filename);
46
47    bool setData(char *data, int nbytes);
48
49    bool setData(vtkDataSetReader *reader);
50
51    bool setData(vtkXMLReader *reader);
52
53    bool setData(vtkDataSet *ds);
54
55    vtkDataSet *copyData(vtkDataSet *ds);
56
57    int numDimensions() const;
58
59    bool is2D(PrincipalPlane *plane = NULL, double *offset = NULL) const;
60
61    PrincipalPlane principalPlane() const;
62
63    bool isCloud() const;
64
65    const std::string& getName() const;
66
67    vtkDataSet *getVtkDataSet();
68
69    vtkAlgorithmOutput *getProducerPort()
70    {
71        if (_producer == NULL) {
72            _producer = vtkSmartPointer<vtkTrivialProducer>::New();
73            _producer->SetOutput(_dataSet);
74        }
75        return _producer->GetOutputPort();
76    }
77
78    const char *getVtkType() const;
79
80    bool setActiveScalars(const char *name);
81
82    const char *getActiveScalarsName() const;
83
84    DataAttributeType getActiveScalarsType() const;
85
86    bool setActiveVectors(const char *name);
87
88    const char *getActiveVectorsName() const;
89
90    DataAttributeType getActiveVectorsType() const;
91
92    bool hasField(const char *fieldName) const
93    {
94        return getFieldInfo(fieldName, NULL, NULL);
95    }
96
97    bool hasField(const char *fieldName, DataAttributeType type) const
98    {
99        return getFieldInfo(fieldName, type, NULL);
100    }
101
102    bool getFieldInfo(const char *fieldName, DataAttributeType *type, int *numComponents) const;
103
104    bool getFieldInfo(const char *fieldName, DataAttributeType type, int *numComponents) const;
105
106    void getFieldNames(std::vector<std::string>& names,
107                       DataAttributeType type, int numComponents = -1) const;
108
109    bool getDataRange(double minmax[2], const char *fieldName,
110                      DataAttributeType type, int component = -1) const;
111
112    void getScalarRange(double minmax[2]) const;
113
114    void getVectorRange(double minmax[2], int component = -1) const;
115
116    void getBounds(double bounds[6]) const;
117
118    void getCellSizeRange(double minmax[2], double *average);
119
120    bool getScalarValue(double x, double y, double z, double *value) const;
121
122    bool getVectorValue(double x, double y, double z, double vector[3]) const;
123
124    void setOpacity(double opacity);
125
126    /**
127     * \brief Get the opacity setting for the DataSet
128     *
129     * This method is used for record-keeping.  The renderer controls
130     * the visibility of related graphics objects.
131     */
132    inline double getOpacity()
133    {
134        return _opacity;
135    }
136
137    void setVisibility(bool state);
138
139    bool getVisibility() const;
140
141    static void getCellSizeRange(vtkDataSet *dataSet, double minmax[2], double *average);
142
143    static void print(vtkDataSet *ds);
144
145private:
146    DataSet();
147
148    void setDefaultArrays();
149    void print() const;
150
151    std::string _name;
152    vtkSmartPointer<vtkDataSet> _dataSet;
153    vtkSmartPointer<vtkTrivialProducer> _producer;
154    bool _visible;
155    double _opacity;
156    double _cellSizeRange[2];
157    double _cellSizeAverage;
158};
159
160}
161
162#endif
Note: See TracBrowser for help on using the repository browser.