geometryrendererdemo.cpp 6.09 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
// 
// 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 "geometryrendererdemo.h"

27
#include "cgt/texturereadertga.h"
28

29
#include "core/datastructures/imagedata.h"
30
#include "core/datastructures/imagerepresentationgl.h"
31
32
33
34
35
36
37
38
39
40

#include "core/classification/geometry1dtransferfunction.h"
#include "core/classification/tfgeometry1d.h"

#include "core/datastructures/geometrydatafactory.h"

namespace campvis {

    GeometryRendererDemo::GeometryRendererDemo(DataContainer* dc)
        : AutoEvaluationPipeline(dc)
41
        , _tcp(&_canvasSize)
42
        , _lsp()
43
        , _geometryReader()
44
45
        , _lvRenderer(&_canvasSize)
        , _teapotRenderer(&_canvasSize)
46
47
48
        , _cubeRenderer(&_canvasSize)
        , _compositor1(&_canvasSize)
        , _compositor2(&_canvasSize)
49
    {
50
        addEventListenerToBack(&_tcp);
51

52
        addProcessor(&_tcp);
53
        addProcessor(&_lsp);
54
        addProcessor(&_geometryReader);
55
56
        addProcessor(&_teapotRenderer);
        addProcessor(&_lvRenderer);
57
58
59
        addProcessor(&_cubeRenderer);
        addProcessor(&_compositor1);
        addProcessor(&_compositor2);
60
61
62
    }

    GeometryRendererDemo::~GeometryRendererDemo() {
63
        _geometryReader.s_validated.disconnect(this);
64
65
66
67
    }

    void GeometryRendererDemo::init() {
        AutoEvaluationPipeline::init();
68

69
        // load textureData from file
70
71
        cgt::TextureReaderTga trt;
        cgt::Texture* campTexture = trt.loadTexture(ShdrMgr.completePath("/modules/vis/sampledata/camplogo.tga"), cgt::Texture::LINEAR);
72
73
74
75
        ImageData* textureData = new ImageData(2, campTexture->getDimensions(), campTexture->getNumChannels());
        ImageRepresentationGL::create(textureData, campTexture);
        getDataContainer().addData("CampTexture", textureData);

76
        // connect slots
77
78
        _geometryReader.s_validated.connect(this, &GeometryRendererDemo::onProcessorValidated);

79
80
        // create Teapot
        MultiIndexedGeometry* teapot = GeometryDataFactory::createTeapot();
81
        teapot->applyTransformationToVertices(cgt::mat4::createTranslation(cgt::vec3(5.f, 10.f, 5.f)) * cgt::mat4::createScale(cgt::vec3(16.f)));
82
        getDataContainer().addData("teapot", teapot);
83
84

        // create cube
85
        MeshGeometry* cube = GeometryDataFactory::createCube(cgt::Bounds(cgt::vec3(7.f), cgt::vec3(9.f)), cgt::Bounds(cgt::vec3(0.f), cgt::vec3(1.f)));
86
        getDataContainer().addData("cube", cube);
87
88

        // setup pipeline
89
        _geometryReader.p_url.setValue(ShdrMgr.completePath("/modules/vis/sampledata/left_ventricle_mesh.vtk"));
90
91
        _geometryReader.p_targetImageID.setValue("reader.output");

92
93
94
        _lvRenderer.p_geometryID.setValue("reader.output");
        _lvRenderer.p_renderTargetID.setValue("lv.render");
        _lvRenderer.p_renderMode.selectById("triangles");
95
        _lvRenderer.p_solidColor.setValue(cgt::vec4(0.8f, 0.f, 0.f, .9f));
96
97
98
99
100

        _teapotRenderer.p_geometryID.setValue("teapot");
        _teapotRenderer.p_renderTargetID.setValue("teapot.render");
        _teapotRenderer.p_renderMode.selectById("trianglestrip");
        _teapotRenderer.p_showWireframe.setValue(false);
101
        _teapotRenderer.p_solidColor.setValue(cgt::vec4(1.f, 0.5f, 0.f, 1.f));
102
103
104
    
        _cubeRenderer.p_geometryID.setValue("cube");
        _cubeRenderer.p_renderTargetID.setValue("cube.render");
105
        _cubeRenderer.p_renderMode.selectById("trianglefan");
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
        _cubeRenderer.p_showWireframe.setValue(false);
        _cubeRenderer.p_textureID.setValue("CampTexture");
        _cubeRenderer.p_coloringMode.selectByOption(GeometryRenderer::TEXTURE_COLOR);

        _compositor1.p_firstImageId.setValue("lv.render");
        _compositor1.p_secondImageId.setValue("teapot.render");
        _compositor1.p_compositingMethod.selectById("depth");
        _compositor1.p_targetImageId.setValue("combine1");
        _compositor1.p_enableBackground.setValue(false);

        _compositor2.p_firstImageId.setValue("combine1");
        _compositor2.p_secondImageId.setValue("cube.render");
        _compositor2.p_compositingMethod.selectById("depth");
        _compositor2.p_targetImageId.setValue("combine2");

        _renderTargetID.setValue("combine2");
122
123
124
125
126
127
128
129
130
131
    }

    void GeometryRendererDemo::deinit() {
        _geometryReader.s_validated.disconnect(this);
        AutoEvaluationPipeline::deinit();
    }

    void GeometryRendererDemo::onProcessorValidated(AbstractProcessor* processor) {
        if (processor == &_geometryReader) {
            // update camera
132
133
            ScopedTypedData<IHasWorldBounds> lv(*_data, _geometryReader.p_targetImageID.getValue());
            ScopedTypedData<IHasWorldBounds> teapot(*_data, "teapot");
134
            ScopedTypedData<IHasWorldBounds> cube(*_data, "cube");
135
            if (lv != 0 && teapot != 0) {
136
                cgt::Bounds unionBounds;
137
138
                unionBounds.addVolume(lv->getWorldBounds());
                unionBounds.addVolume(teapot->getWorldBounds());
139
                unionBounds.addVolume(cube->getWorldBounds());
140

141
                _tcp.reinitializeCamera(unionBounds);
142
143
144
145
146
            }
        }
    }


147
}