pipelineresultimagetest.cpp 5.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
// 
// 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 "gtest/gtest.h"

#ifdef CAMPVIS_HAS_MODULE_DEVIL

#include "tgt/filesystem.h"

#include "core/datastructures/datacontainer.h"
#include "core/datastructures/renderdata.h"
#include "core/pipeline/abstractpipeline.h"
#include "core/tools/opengljobprocessor.h"
35
#include "core/tools/stringutils.h"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

#include "modules/pipelinefactory.h"
#include "modules/devil/processors/devilimagewriter.h"

using namespace campvis;


/**
 * Test class for StringUtils.
 */

class PipelineWriteResultImageTest : public ::testing::Test {
protected:
    PipelineWriteResultImageTest() 
        : _dataContainer("Test Container")
        , _pipeline(nullptr)
        , _wroteFile(false)
    {
54
55
56
57
58
59
60
61
62
63
        _basePath = "visregtests/";
        if ( ! tgt::FileSystem::dirExists(_basePath)) {
            tgt::FileSystem::createDirectory(_basePath);
        }
        _basePath = "visregtests/testruns/";
        if ( ! tgt::FileSystem::dirExists(_basePath)) {
            tgt::FileSystem::createDirectory(_basePath);
        }
        std::vector<std::string> filelist = tgt::FileSystem::listSubDirectories(_basePath, true);
        std::string caseNo = "1/";
64
65
66
67
68
69
70
71
72
73
74
        //std::string testRunNo = "";
        //if (_prevNoCases++ == 0) {
        //    testRunNo = filelist.size() > 0 ? StringUtils::toString(StringUtils::fromString<int>(filelist[filelist.size()-1])+1) : "1";
        //    tgt::FileSystem::createDirectoryRecursive(_basePath+testRunNo+"/"+ caseNo);
        //}
        //else 
        //    testRunNo = filelist[filelist.size()-1];
        //
        //_basePath += testRunNo+"/"+caseNo;
        tgt::FileSystem::createDirectoryRecursive(_basePath+ caseNo);
        _basePath += caseNo;
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
127
128
129
130
    }

    ~PipelineWriteResultImageTest() {
        delete _pipeline;
    }

    virtual void SetUp() {
    }

    virtual void TearDown() {
        if (_pipeline != nullptr) {
            _pipeline->setEnabled(false);
            _pipeline->deinit();
        }
    }

    void init() {
        // create pipeline
        _pipeline = PipelineFactory::getRef().createPipeline(_pipelineName, &_dataContainer);

        if (_pipeline != nullptr) {
            // setup pipeline
            _pipeline->setCanvas(GLJobProc.iKnowWhatImDoingGetArbitraryContext());
            _pipeline->init();
            _pipeline->setEnabled(true);
            _pipeline->setRenderTargetSize(tgt::ivec2(1024, 1024));
        }
    }

    void execute() {
        if (_pipeline != nullptr) {
            // invalidate each processor
            std::vector<AbstractProcessor*> processors = _pipeline->getProcessors();
            for (size_t i = 0; i < processors.size(); ++i) {
                processors[i]->invalidate(AbstractProcessor::INVALID_RESULT);
            }

            // execute each processor (we do this n*n times, as we might have a complex dependency graph)
            for (size_t i = 0; i < processors.size(); ++i) {
                for (size_t i = 0; i < processors.size(); ++i) {
                    processors[i]->process(_dataContainer);
                }
            }

            // write result image
            _imageWriter.p_inputImage.setValue(_pipeline->getRenderTargetID());
            _imageWriter.p_url.setValue(_fileName);
            _imageWriter.process(_dataContainer);

            _wroteFile = tgt::FileSystem::fileExists(_fileName);
        }
    }

protected:
    std::string _pipelineName;
    std::string _fileName;
131
132
    std::string _basePath;
    static int _prevNoCases;
133
134
135
136
137
138
139

    DataContainer _dataContainer;
    AbstractPipeline* _pipeline;
    DevilImageWriter _imageWriter;

    bool _wroteFile;
};
140
int PipelineWriteResultImageTest::_prevNoCases = 0;
141
142
143

TEST_F(PipelineWriteResultImageTest, VolumeExplorerDemo) {
    _pipelineName = "VolumeExplorerDemo";
144
    _fileName = _basePath +"volumeexplorerdemo.png";
145
146
147
148
149
150
151
    init();
    execute();
    EXPECT_TRUE(_wroteFile);
}

TEST_F(PipelineWriteResultImageTest, GeometryRendererDemo) {
    _pipelineName = "GeometryRendererDemo";
152
    _fileName = _basePath +"geometryrendererdemo.png";
153
154
155
156
157
158
159
    init();
    execute();
    EXPECT_TRUE(_wroteFile);
}

TEST_F(PipelineWriteResultImageTest, SliceVis) {
    _pipelineName = "SliceVis";
160
    _fileName = _basePath +"slicevis.png";
161
162
163
164
165
166
    init();
    execute();
    EXPECT_TRUE(_wroteFile);
}

#endif