campvis.i 8.17 KB
Newer Older
1
%module campvis
2
%include factory.i
3
%include std_string.i
4
%import "ext/tgt/bindings/tgt.i"
5
6
7
%{
#include "core/properties/genericproperty.h"
#include "core/properties/numericproperty.h"
8
#include "core/properties/floatingpointproperty.h"
9
#include "core/properties/datanameproperty.h"
10
#include "core/properties/transferfunctionproperty.h"
11
#include "core/pipeline/abstractprocessor.h"
12
13
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/pipeline/visualizationprocessor.h"
14
15
#include "core/classification/tfgeometry1d.h"
#include "core/classification/geometry1dtransferfunction.h"
16
17
18
19
%}


namespace campvis {
20
21

    class AbstractProperty {
22
    public:
23
24
25
        AbstractProperty(const std::string& name, const std::string& title,
                         int invalidationLevel = AbstractProcessor::INVALID_RESULT);
        virtual ~AbstractProperty();
26

27
28
        virtual void init();
        virtual void deinit();
29

30
31
        const std::string& getName() const;
        const std::string& getTitle() const;
32

33
34
        int getInvalidationLevel() const;
        void setInvalidationLevel(int il);
35

36
37
38
39
        bool isVisible() const;
        void setVisible(bool isVisible);

        virtual void addSharedProperty(AbstractProperty* prop);
40
    };
41

42
43
    template<typename T>
    class GenericProperty : public AbstractProperty {
44
    public:
45
46
47
48
49
50
        GenericProperty(const std::string& name, const std::string& title, const T& value,
                        int invalidationLevel = AbstractProcessor::INVALID_RESULT);
        virtual ~GenericProperty();

        const T& getValue() const;
        virtual void setValue(const T& value);
51
52
    };

53
54
55
    %template(StringProperty) GenericProperty<std::string>;
    typedef GenericProperty<std::string> StringProperty;

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
    class DataNameProperty : public StringProperty {
    public:
        enum DataAccessInfo {
            READ,
            WRITE
        };

        DataNameProperty(const std::string& name, const std::string& title, const std::string& value,
                         DataAccessInfo access, int invalidationLevel = AbstractProcessor::INVALID_RESULT);
        virtual ~DataNameProperty();
    };

    class DataContainer {
    public:
        DataContainer(const std::string& name);
        ~DataContainer();
    };

    template<typename T>
75
    class NumericProperty : public GenericProperty<T> {
76
77
78
79
80
81
82
83
84
85
86
87
88
    public:
        NumericProperty(
            const std::string& name,
            const std::string& title,
            const T& value,
            const T& minValue,
            const T& maxValue,
            const T& stepValue = T(1),
            int invalidationLevel = AbstractProcessor::INVALID_RESULT);

        virtual ~NumericProperty();
    };

89
    %template(Ivec2GenericProperty) GenericProperty< tgt::Vector2<int> >;
90
91
    %template(IVec2Property) NumericProperty< tgt::Vector2<int> >;
    typedef NumericProperty< tgt::Vector2<int> > IVec2Property;
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

    template<typename T>
    struct FloatingPointPropertyTraits {};

    template<>
    struct FloatingPointPropertyTraits<float> {
        typedef int DecimalsType;
    };

    %template() FloatingPointPropertyTraits<float>;

    template<typename T>
    class FloatingPointProperty : public NumericProperty<T> {
    public:
        typedef typename FloatingPointPropertyTraits<T>::DecimalsType DecimalsType;

        FloatingPointProperty(
            const std::string& name,
            const std::string& title,
            const T& value,
            const T& minValue,
            const T& maxValue,
            const T& stepValue = T(0.01f),
            const DecimalsType& decimals = DecimalsType(3),
            int invalidationLevel = AbstractProcessor::INVALID_RESULT);

        virtual ~FloatingPointProperty();
    };

    %template(FloatGenericProperty) GenericProperty<float>;
    %template(FloatNumericProperty) NumericProperty<float>;
    %template(FloatProperty) FloatingPointProperty<float>;
    typedef FloatingPointProperty< float > FloatProperty;

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
    /* AbstractProcessor */

    class AbstractProcessor {
    public:
        enum InvalidationLevel {
            VALID               = 0,
            INVALID_RESULT      = 1 << 0,
            INVALID_SHADER      = 1 << 1,
            INVALID_PROPERTIES  = 1 << 2,
            FIRST_FREE_TO_USE_INVALIDATION_LEVEL = 1 << 3
        };

        const std::string getName() const = 0;
    };

142
143
144
145
146
147
148
149
150
    /* AbstractPipeline */

    class AbstractPipeline {
    public:
        AbstractPipeline(DataContainer* dc);
        virtual ~AbstractPipeline();

        virtual const std::string getName() const = 0;
    };
151

152
    /* AutoEvaluationPipeline */
153

154
    class AutoEvaluationPipeline : public AbstractPipeline {
155
156
    public:
        virtual void addProcessor(AbstractProcessor* processor);
157
158

        void addEventListenerToBack(tgt::EventListener* e);
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    };

    /* TFGeometry1D */

    %nodefaultctor TFGeometry1D;

    class TFGeometry1D {
    public:
        virtual ~TFGeometry1D();
        static TFGeometry1D* createQuad(const tgt::vec2& interval, const tgt::col4& leftColor, const tgt::vec4& rightColor);
    };

    /* AbstractTransferFunction */

    class AbstractTransferFunction {
    public:
        AbstractTransferFunction(const tgt::svec3& size, const tgt::vec2& intensityDomain = tgt::vec2(0.f, 1.f));
        virtual ~AbstractTransferFunction();

        virtual AbstractTransferFunction* clone() const = 0;
    };

    /* GenericGeometryTransferFunction */

    template<class T>
    class GenericGeometryTransferFunction : public AbstractTransferFunction {
    public:
        GenericGeometryTransferFunction(const tgt::vec3& size, const tgt::vec2& intensityDomain = tgt::vec2(0.f, 1.f));
        virtual ~GenericGeometryTransferFunction();

        void addGeometry(T* geometry);
    };

    /* Geometry1DTransferFunction */

    %template(GenericGeometryTransferFunction_TFGeometry1D) GenericGeometryTransferFunction<TFGeometry1D>;

    class Geometry1DTransferFunction : public GenericGeometryTransferFunction<TFGeometry1D> {
    public:
        Geometry1DTransferFunction(size_t size, const tgt::vec2& intensityDomain = tgt::vec2(0.f, 1.f));
        virtual ~Geometry1DTransferFunction();

        virtual Geometry1DTransferFunction* clone() const;
    };

    /* TransferFunctionProperty */

    class TransferFunctionProperty : public AbstractProperty {
    public:
        TransferFunctionProperty(const std::string& name, const std::string& title, AbstractTransferFunction* tf,
                                 int invalidationLevel = AbstractProcessor::INVALID_RESULT);
        virtual ~TransferFunctionProperty();

        AbstractTransferFunction* getTF();
        void replaceTF(AbstractTransferFunction* tf);
    };

    /* Downcast the return value of VisualizationProcessor::getProperty to appropriate subclass */
    %factory(AbstractProperty* campvis::VisualizationProcessor::getProperty,
             campvis::TransferFunctionProperty, campvis::DataNameProperty, campvis::StringProperty);

    /* VisualizationProcessor */

    class VisualizationProcessor : public AbstractProcessor {
    public:
        explicit VisualizationProcessor(IVec2Property* viewportSizeProp);
        ~VisualizationProcessor();

        AbstractProperty* getProperty(const std::string& name) const;
    };
229
}
230

231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
%inline {
static const char* const SOURCE_DIR = CAMPVIS_SOURCE_DIR;

namespace campvis {
    /*
     * Lua pipelines need to access certain protected properties of AbstractPipeline but can't
     * reference them directly as they don't actually inherit from any class. This subclass exposes
     * public getters for the properties in question. LuaPipeline instances can then be cast to
     * ExtendedAutoEvaluationPipeline to give Lua code access to these new methods.
     */
    class ExtendedAutoEvaluationPipeline : public AutoEvaluationPipeline {
    public:
        const IVec2Property& ExtendedAutoEvaluationPipeline::getCanvasSizeProperty() const {
            return _canvasSize;
        }

        const DataNameProperty& ExtendedAutoEvaluationPipeline::getRenderTargetIDProperty() const {
            return _renderTargetID;
        }
    };
}
}

254
255
256
257
258
259
260
261
262
%luacode {
  function campvis.newPipeline (o)
    o = o or {}   -- create object if user does not provide one
    setmetatable(o, {__index = instance})
    return o
  end

  print("Module campvis loaded")
}