vectorfielddemo.cpp 6.57 KB
Newer Older
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
6
7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================

#include "vectorfielddemo.h"

#include "tgt/event/keyevent.h"

#include "core/classification/geometry1dtransferfunction.h"
#include "core/classification/tfgeometry1d.h"
31
#include "core/datastructures/imagedata.h"
32
33
34

namespace campvis {

35
36
37
38
39
    static const GenericOption<std::string> viewSelectionOptions[2] = {
        GenericOption<std::string>("arrows", "Arrows"),
        GenericOption<std::string>("particles", "Particle Simulation"),
    };

40
41
    VectorFieldDemo::VectorFieldDemo(DataContainer* dc)
        : AutoEvaluationPipeline(dc)
42
        , _lsp()
43
        , _imageReader()
44
        , _vectorFieldReader()
45
        , _pfr(&_canvasSize)
46
47
48
49
        , _vectorFieldRenderer(&_canvasSize)
        , _sliceRenderer(&_canvasSize)
        , _rtc(&_canvasSize)
        , p_camera("Camera", "Camera", tgt::Camera())
50
        , p_sliceNumber("SliceNuber", "Slice Number", 0, 0, 1024)
51
52
        , p_viewSelection("ViewSelection", "Select 3D View", viewSelectionOptions, 2)
        , p_time("Time", "Time", 0, 0, 100)
53
54
55
        , _trackballEH(0)

    {
56
57
        addProperty(p_camera);
        addProperty(p_sliceNumber);
58
59
        addProperty(p_viewSelection);
        addProperty(p_time);
60
61
62
63

        _trackballEH = new TrackballNavigationEventListener(&p_camera, &_canvasSize);
        addEventListenerToBack(_trackballEH);

64
        addProcessor(&_lsp);
65
        addProcessor(&_imageReader);
66
        addProcessor(&_vectorFieldReader);
67
        addProcessor(&_pfr);
68
69
70
71
72
73
74
75
76
77
78
79
        addProcessor(&_vectorFieldRenderer);
        addProcessor(&_sliceRenderer);
        addProcessor(&_rtc);
    }

    VectorFieldDemo::~VectorFieldDemo() {
    }

    void VectorFieldDemo::init() {
        AutoEvaluationPipeline::init();

        p_camera.addSharedProperty(&_vectorFieldRenderer.p_camera);
80
        p_camera.addSharedProperty(&_pfr.p_camera);
81
82
83
84
85
        p_camera.addSharedProperty(&_sliceRenderer.p_camera);

        p_sliceNumber.addSharedProperty(&_vectorFieldRenderer.p_sliceNumber);
        p_sliceNumber.addSharedProperty(&_sliceRenderer.p_sliceNumber);

86
        _imageReader.p_url.setValue(CAMPVIS_SOURCE_DIR "/modules/vectorfield/sampledata/rec1_2D_comp.mhd");
87
88
89
90
        
        _imageReader.p_targetImageID.setValue("reader.output");
        _imageReader.p_targetImageID.addSharedProperty(&_sliceRenderer.p_sourceImageID);
        _imageReader.s_validated.connect(this, &VectorFieldDemo::onProcessorValidated);
91

92
93
        _vectorFieldReader.p_url.setValue(CAMPVIS_SOURCE_DIR "/modules/vectorfield/sampledata/result_vec.mhd");
        _vectorFieldReader.p_targetImageID.setValue("vectors");
94
        _vectorFieldReader.p_targetImageID.addSharedProperty(&_pfr.p_inputVectors);
95
        _vectorFieldReader.p_targetImageID.addSharedProperty(&_vectorFieldRenderer.p_inputVectors);
96

97
        _vectorFieldRenderer.p_renderOutput.setValue("arrows");
98
99
100
101
102
103
104
105
        _vectorFieldRenderer.p_arrowSize.setValue(0.03f);
        _vectorFieldRenderer.p_lenThresholdMin.setValue(100.f);
        _vectorFieldRenderer.p_flowProfile1.setValue(0.4716088614374652f);
        _vectorFieldRenderer.p_flowProfile2.setValue(0.0638348311845516f);
        _vectorFieldRenderer.p_flowProfile3.setValue(0.1713471562960614f);
        _vectorFieldRenderer.p_flowProfile4.setValue(0.1019371804834016f);
        _vectorFieldRenderer.p_lenThresholdMax.setValue(400.f);
        _vectorFieldRenderer.p_sliceOrientation.setValue(3);
106

107
108
109
110
111
112
113
        _pfr.p_lenThresholdMin.setValue(100.f);
        _pfr.p_flowProfile1.setValue(0.4716088614374652f);
        _pfr.p_flowProfile2.setValue(0.0638348311845516f);
        _pfr.p_flowProfile3.setValue(0.1713471562960614f);
        _pfr.p_flowProfile4.setValue(0.1019371804834016f);
        _pfr.p_lenThresholdMax.setValue(400.f);
        _pfr.p_renderOutput.setValue("particles");
114
        _pfr.setEnabled(false);
115

Oliver Zettinig's avatar
Oliver Zettinig committed
116
        Geometry1DTransferFunction* tf = new Geometry1DTransferFunction(128, tgt::vec2(0.f, 1.f));
117
        tf->addGeometry(TFGeometry1D::createQuad(tgt::vec2(0.f, 1.f), tgt::col4(0, 0, 0, 255), tgt::col4(255, 255, 255, 255)));
118
119
120
        _sliceRenderer.p_transferFunction.replaceTF(tf);
        _sliceRenderer.p_targetImageID.setValue("slice");

121
122
        _rtc.p_firstImageId.setValue("arrows");
        _rtc.p_secondImageId.setValue("slice");
123
124
125
126
        _rtc.p_compositingMethod.selectById("depth");
        _rtc.p_targetImageId.setValue("composed");

        _renderTargetID.setValue("composed");
127
128
129

        p_time.addSharedProperty(&_vectorFieldRenderer.p_Time);
        p_time.addSharedProperty(&_pfr.p_Time);
130
131
132
    }

    void VectorFieldDemo::onProcessorValidated(AbstractProcessor* processor) {
133
        if (processor == &_imageReader) {
134
            // update camera
135
            ScopedTypedData<ImageData> img(*_data, _sliceRenderer.p_sourceImageID.getValue());
136
137
            if (img) {
                _trackballEH->reinitializeCamera(img);
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
                p_sliceNumber.setMaxValue(static_cast<int>(img->getSize().z));
            }
        }
    }

    void VectorFieldDemo::onPropertyChanged(const AbstractProperty* prop) {
        if (prop == &p_viewSelection) {
            if (p_viewSelection.getOptionValue() == "arrows") {
                _rtc.p_firstImageId.setValue("arrows");
                _vectorFieldRenderer.setEnabled(true);
                _pfr.setEnabled(false);
            }
            else if (p_viewSelection.getOptionValue() == "particles") {
                _rtc.p_firstImageId.setValue("particles");
                _vectorFieldRenderer.setEnabled(false);
                _pfr.setEnabled(true);
154
155
            }
        }
156
157
158
    }

}