campvis.i 12.4 KB
Newer Older
1
%module campvis
2
%include factory.i
3
%include std_string.i
4
%import "ext/cgt/bindings/cgt.i"
5
%include "ext/sigslot/sigslot.i"
6
%{
7
8
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/imagedata.h"
9
#include "core/properties/allproperties.h"
10
#include "core/pipeline/abstractprocessor.h"
11
12
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/pipeline/visualizationprocessor.h"
13
14
#include "core/classification/tfgeometry1d.h"
#include "core/classification/geometry1dtransferfunction.h"
15
16
17
%}


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
%inline {
static const char* const SOURCE_DIR = CAMPVIS_SOURCE_DIR;

// Template specialisations and instantiations required to get signals to work in Lua
namespace sigslot {
    template<>
    struct LuaConnectionArgTraits<campvis::AbstractProcessor*> {
        static const char* const typeName;
    };

    const char* const LuaConnectionArgTraits<campvis::AbstractProcessor*>::typeName = "campvis::AbstractProcessor *";
}
}


%template(sigslot_signal1_AbstractProcessor) sigslot::signal1<campvis::AbstractProcessor*>;


36
namespace campvis {
37
38

    class AbstractProperty {
39
    public:
40
        AbstractProperty(const std::string& name, const std::string& title);
41
        virtual ~AbstractProperty();
42

43
44
        virtual void init();
        virtual void deinit();
45

46
47
        const std::string& getName() const;
        const std::string& getTitle() const;
48

49
50
51
52
        bool isVisible() const;
        void setVisible(bool isVisible);

        virtual void addSharedProperty(AbstractProperty* prop);
53
    };
54

55
56
57
58
59
60
61
62
63
64
    class ButtonProperty : public AbstractProperty {
    public:
        ButtonProperty(const std::string& name, const std::string& title);
        virtual ~ButtonProperty();

        void click();

        sigslot::signal0 s_clicked;
    };

65
66
    template<typename T>
    class GenericProperty : public AbstractProperty {
67
    public:
68
        GenericProperty(const std::string& name, const std::string& title, const T& value);
69
70
71
72
        virtual ~GenericProperty();

        const T& getValue() const;
        virtual void setValue(const T& value);
73
74
    };

75
76
77
    %template(BoolProperty) GenericProperty<bool>;
    typedef GenericProperty<bool> BoolProperty;

78
79
80
    %template(StringProperty) GenericProperty<std::string>;
    typedef GenericProperty<std::string> StringProperty;

81
82
    /* DataNameProperty */

83
84
85
86
87
88
89
90
    class DataNameProperty : public StringProperty {
    public:
        enum DataAccessInfo {
            READ,
            WRITE
        };

        DataNameProperty(const std::string& name, const std::string& title, const std::string& value,
91
                         DataAccessInfo access);
92
93
94
        virtual ~DataNameProperty();
    };

95
    /* NumericProperty */
96
97

    template<typename T>
98
    class NumericProperty : public GenericProperty<T> {
99
100
101
102
103
104
105
    public:
        NumericProperty(
            const std::string& name,
            const std::string& title,
            const T& value,
            const T& minValue,
            const T& maxValue,
106
            const T& stepValue = T(1));
107
108
109
110

        virtual ~NumericProperty();
    };

111
112
113
114
    %template(IntGenericProperty) GenericProperty< int >;
    %template(IntProperty) NumericProperty< int >;
    typedef NumericProperty< int > IntProperty;

115
116
117
    %template(Ivec2GenericProperty) GenericProperty< cgt::Vector2<int> >;
    %template(IVec2Property) NumericProperty< cgt::Vector2<int> >;
    typedef NumericProperty< cgt::Vector2<int> > IVec2Property;
118

119
120
121
122
123
124
125
126
127
128
    %template(Ivec3GenericProperty) GenericProperty< cgt::Vector3<int> >;
    %template(IVec3Property) NumericProperty< cgt::Vector3<int> >;
    typedef NumericProperty< cgt::Vector3<int> > IVec3Property;

    %template(Ivec4GenericProperty) GenericProperty< cgt::Vector4<int> >;
    %template(IVec4Property) NumericProperty< cgt::Vector4<int> >;
    typedef NumericProperty< cgt::Vector4<int> > IVec4Property;



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    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),
151
            const DecimalsType& decimals = DecimalsType(3));
152
153
154
155
156
157
158
159
160

        virtual ~FloatingPointProperty();
    };

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

161
162
163
164
165
166
167
168
169
170
171
172
173
174
    %template(Vec2GenericProperty) GenericProperty< cgt::Vector2<float> >;
    %template(Vec2NumericProperty) NumericProperty< cgt::Vector2<float> >;
    %template(Vec2Property) FloatingPointProperty< cgt::Vector2<float> >;
    typedef FloatingPointProperty< cgt::Vector2<float> > Vec2Property;

    %template(Vec3GenericProperty) GenericProperty< cgt::Vector3<float> >;
    %template(Vec3NumericProperty) NumericProperty< cgt::Vector3<float> >;
    %template(Vec3Property) FloatingPointProperty< cgt::Vector3<float> >;
    typedef FloatingPointProperty< cgt::Vector3<float> > Vec3Property;

    %template(Vec4GenericProperty) GenericProperty< cgt::Vector4<float> >;
    %template(Vec4NumericProperty) NumericProperty< cgt::Vector4<float> >;
    %template(Vec4Property) FloatingPointProperty< cgt::Vector4<float> >;
    typedef FloatingPointProperty< cgt::Vector4<float> > Vec4Property;
175
176
177
178
179
180
181
    /* TFGeometry1D */

    %nodefaultctor TFGeometry1D;

    class TFGeometry1D {
    public:
        virtual ~TFGeometry1D();
182
        static TFGeometry1D* createQuad(const cgt::vec2& interval, const cgt::col4& leftColor, const cgt::vec4& rightColor);
183
184
185
186
187
188
    };

    /* AbstractTransferFunction */

    class AbstractTransferFunction {
    public:
189
        AbstractTransferFunction(const cgt::svec3& size, const cgt::vec2& intensityDomain = cgt::vec2(0.f, 1.f));
190
191
192
193
194
195
196
197
198
199
        virtual ~AbstractTransferFunction();

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

    /* GenericGeometryTransferFunction */

    template<class T>
    class GenericGeometryTransferFunction : public AbstractTransferFunction {
    public:
200
        GenericGeometryTransferFunction(const cgt::vec3& size, const cgt::vec2& intensityDomain = cgt::vec2(0.f, 1.f));
201
202
203
204
205
206
207
208
209
210
211
        virtual ~GenericGeometryTransferFunction();

        void addGeometry(T* geometry);
    };

    /* Geometry1DTransferFunction */

    %template(GenericGeometryTransferFunction_TFGeometry1D) GenericGeometryTransferFunction<TFGeometry1D>;

    class Geometry1DTransferFunction : public GenericGeometryTransferFunction<TFGeometry1D> {
    public:
212
        Geometry1DTransferFunction(size_t size, const cgt::vec2& intensityDomain = cgt::vec2(0.f, 1.f));
213
214
215
216
217
218
219
220
221
        virtual ~Geometry1DTransferFunction();

        virtual Geometry1DTransferFunction* clone() const;
    };

    /* TransferFunctionProperty */

    class TransferFunctionProperty : public AbstractProperty {
    public:
222
        TransferFunctionProperty(const std::string& name, const std::string& title, AbstractTransferFunction* tf);
223
224
225
226
227
228
        virtual ~TransferFunctionProperty();

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

229
230
231
232
233
234
235
    /* IHasWorldBounds */

    class IHasWorldBounds {
    public:
        IHasWorldBounds();
        virtual ~IHasWorldBounds();

236
        virtual cgt::Bounds getWorldBounds() const = 0;
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
    };

    /* AbstractData */

    class AbstractData {
    public:
        AbstractData();
        virtual ~AbstractData();

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

    /* ImageData */

    class ImageData : public AbstractData, public IHasWorldBounds {
    public:
253
        ImageData(size_t dimensionality, const cgt::svec3& size, size_t numChannels);
254
255
256
        virtual ~ImageData();

        virtual ImageData* clone() const;
257
        virtual cgt::Bounds getWorldBounds() const;
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
    };

    /* Downcast the return value of DataHandle::getData to appropriate subclass */
    %factory(AbstractData* campvis::DataHandle::getData, campvis::ImageData);

    /* DataHandle */

    class DataHandle {
    public:
        explicit DataHandle(AbstractData* data = 0);
        DataHandle(const DataHandle& rhs);
        DataHandle& operator=(const DataHandle& rhs);
        virtual ~DataHandle();

        const AbstractData* getData() const;
    };

    /* DataContainer */

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

        DataHandle addData(const std::string& name, AbstractData* data);
        void addDataHandle(const std::string& name, const DataHandle& dh);
        bool hasData(const std::string& name) const;
        DataHandle getData(const std::string& name) const;
        void removeData(const std::string& name);
        void clear();
288
289
290
291

        %immutable;
        sigslot::signal0 s_changed;
        %mutable;
292
293
294
295
    };

    /* Downcast the return value of HasPropertyCollection::getProperty to appropriate subclass */
    %factory(AbstractProperty* campvis::HasPropertyCollection::getProperty,
296
297
298
		     campvis::IntProperty, campvis::IVec2Property, campvis::IVec3Property, campvis::IVec4Property,
             campvis::FloatProperty, campvis::Vec2Property, campvis::Vec3Property, campvis::Vec4Property,
			 campvis::TransferFunctionProperty,
299
             campvis::DataNameProperty, campvis::StringProperty, campvis::ButtonProperty, campvis::BoolProperty);
300
301
302

    /* Downcast the return value of HasPropertyCollection::getNestedProperty to appropriate subclass */
    %factory(AbstractProperty* campvis::HasPropertyCollection::getNestedProperty,
303
304
305
		     campvis::IntProperty, campvis::IVec2Property, campvis::IVec3Property, campvis::IVec4Property,
             campvis::FloatProperty, campvis::Vec2Property, campvis::Vec3Property, campvis::Vec4Property,
			 campvis::TransferFunctionProperty,
306
             campvis::DataNameProperty, campvis::StringProperty, campvis::ButtonProperty, campvis::BoolProperty);
307
308
309
310
311
312
313
314

    /* HasPropertyCollection */

    class HasPropertyCollection  {
    public:
        HasPropertyCollection();
        virtual ~HasPropertyCollection() = 0;

315
316
        virtual void addProperty(AbstractProperty& prop);
        void removeProperty(AbstractProperty& prop);
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
        AbstractProperty* getProperty(const std::string& name) const;
        AbstractProperty* getNestedProperty(const std::string& name) const;
    };

    /* AbstractProcessor */

    class AbstractProcessor : public HasPropertyCollection {
    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;
334
335
        void addProperty(AbstractProperty& prop, int invalidationLevel);
        void setPropertyInvalidationLevel(AbstractProperty& prop, int invalidationLevel);
336

337
338
		void process(DataContainer& data);

339
340
341
        %immutable;
        sigslot::signal1<AbstractProcessor*> s_validated;
        %mutable;
342
343
344
345
346
347
348
349
350
351
352
353
354
    };

    /* AbstractPipeline */

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

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

        const DataContainer& getDataContainer() const;
        DataContainer& getDataContainer();
355
356
357
358

		virtual void addProcessor(AbstractProcessor* processor);
		virtual void executePipeline() = 0;
        AbstractProcessor* getProcessor(const std::string& name) const;
359
360
361
362
363
364
365
366
    };

    /* AutoEvaluationPipeline */

    class AutoEvaluationPipeline : public AbstractPipeline {
    public:
        virtual void addProcessor(AbstractProcessor* processor);

367
        void addEventListenerToBack(cgt::EventListener* e);
368
    };
369
370
371
372
373
374
375

    /* VisualizationProcessor */

    class VisualizationProcessor : public AbstractProcessor {
    public:
        explicit VisualizationProcessor(IVec2Property* viewportSizeProp);
        ~VisualizationProcessor();
376
    };
377
}
378

379

380
%luacode {
381
382
383
384
385
  function campvis.newPipeline (name, o)
    if not name then
      error("A name must be provided when creating a new pipeline!")
    end

386
387
388
389
390
391
392
    o = o or {}   -- create object if user does not provide one
    setmetatable(o, {__index = instance})
    return o
  end

  print("Module campvis loaded")
}