vectorfielddemo.cpp 6.42 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-2015, 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
// 
// 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"

27
#include "cgt/event/keyevent.h"
28
29
30

#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, getId())
42
        , _tcp(&_canvasSize)
43
        , _lsp()
44
        , _imageReader()
45
        , _vectorFieldReader()
46
        , _pfr(&_canvasSize)
47
48
49
        , _vectorFieldRenderer(&_canvasSize)
        , _sliceRenderer(&_canvasSize)
        , _rtc(&_canvasSize)
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
        addProperty(p_sliceNumber);
56
57
        addProperty(p_viewSelection);
        addProperty(p_time);
58

59
        addEventListenerToBack(&_tcp);
60

61
        addProcessor(&_tcp);
62
        addProcessor(&_lsp);
63
        addProcessor(&_imageReader);
64
        addProcessor(&_vectorFieldReader);
65
        addProcessor(&_pfr);
66
67
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_sliceNumber.addSharedProperty(&_vectorFieldRenderer.p_sliceNumber);
        p_sliceNumber.addSharedProperty(&_sliceRenderer.p_sliceNumber);

80
        _imageReader.p_url.setValue(CAMPVIS_SOURCE_DIR "/modules/vectorfield/sampledata/rec1_2D_comp.mhd");
81
82
83
        
        _imageReader.p_targetImageID.setValue("reader.output");
        _imageReader.p_targetImageID.addSharedProperty(&_sliceRenderer.p_sourceImageID);
84
        _imageReader.p_targetImageID.addSharedProperty(&_tcp.p_image);
85
        _imageReader.s_validated.connect(this, &VectorFieldDemo::onProcessorValidated);
86

87
88
        _vectorFieldReader.p_url.setValue(CAMPVIS_SOURCE_DIR "/modules/vectorfield/sampledata/result_vec.mhd");
        _vectorFieldReader.p_targetImageID.setValue("vectors");
89
        _vectorFieldReader.p_targetImageID.addSharedProperty(&_pfr.p_inputVectors);
90
        _vectorFieldReader.p_targetImageID.addSharedProperty(&_vectorFieldRenderer.p_inputVectors);
91

92
        _vectorFieldRenderer.p_renderOutput.setValue("arrows");
93
94
95
96
97
98
99
100
        _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);
101

102
103
104
105
106
107
108
        _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");
109
        _pfr.setEnabled(false);
110

111
112
        Geometry1DTransferFunction* tf = new Geometry1DTransferFunction(128, cgt::vec2(0.f, 1.f));
        tf->addGeometry(TFGeometry1D::createQuad(cgt::vec2(0.f, 1.f), cgt::col4(0, 0, 0, 255), cgt::col4(255, 255, 255, 255)));
113
114
115
        _sliceRenderer.p_transferFunction.replaceTF(tf);
        _sliceRenderer.p_targetImageID.setValue("slice");

116
117
        _rtc.p_firstImageId.setValue("arrows");
        _rtc.p_secondImageId.setValue("slice");
118
119
120
121
        _rtc.p_compositingMethod.selectById("depth");
        _rtc.p_targetImageId.setValue("composed");

        _renderTargetID.setValue("composed");
122
123
124

        p_time.addSharedProperty(&_vectorFieldRenderer.p_Time);
        p_time.addSharedProperty(&_pfr.p_Time);
125
126
    }

127
128
129
130
131
    void VectorFieldDemo::deinit() {
        _imageReader.s_validated.disconnect(this);
        AutoEvaluationPipeline::deinit();
    }

132
    void VectorFieldDemo::onProcessorValidated(AbstractProcessor* processor) {
133
        if (processor == &_imageReader) {
134
            // update camera
135
            ScopedTypedData<ImageData> img(*_dataContainer, _sliceRenderer.p_sourceImageID.getValue());
136
            if (img) {
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
                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);
153
154
            }
        }
155
156
157
    }

}