In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

pipelineresultimagetest.cpp 6.92 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 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//      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

29 30
#include "cgt/filesystem.h"
#include "cgt/opengljobprocessor.h"
31 32 33 34

#include "core/datastructures/datacontainer.h"
#include "core/datastructures/renderdata.h"
#include "core/pipeline/abstractpipeline.h"
35
#include "core/pipeline/pipelinefactory.h"
36
#include "core/properties/allproperties.h"
37
#include "core/tools/stringutils.h"
38 39

#include "modules/devil/processors/devilimagewriter.h"
40
#include "modules/base/processors/trackballcameraprovider.h"
41 42 43 44 45

using namespace campvis;


/**
46
 * Test class for creating test images for visual regression test
47 48 49 50 51 52 53 54 55
 */

class PipelineWriteResultImageTest : public ::testing::Test {
protected:
    PipelineWriteResultImageTest() 
        : _dataContainer("Test Container")
        , _pipeline(nullptr)
        , _wroteFile(false)
    {
56
        _basePath = "visregtests/";
57 58
        if ( ! cgt::FileSystem::dirExists(_basePath)) {
            cgt::FileSystem::createDirectory(_basePath);
59 60
        }
        _basePath = "visregtests/testruns/";
61 62
        if ( ! cgt::FileSystem::dirExists(_basePath)) {
            cgt::FileSystem::createDirectory(_basePath);
63
        }
64
        std::vector<std::string> filelist = cgt::FileSystem::listSubDirectories(_basePath, true);
65
        std::string caseNo = "1/";
66
        cgt::FileSystem::createDirectoryRecursive(_basePath+ caseNo);
67
        _basePath += caseNo;
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    }

    ~PipelineWriteResultImageTest() {
        delete _pipeline;
    }

    virtual void SetUp() {
    }

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

    void init() {
        // create pipeline
86
        _pipeline = PipelineFactory::getRef().createPipeline(_pipelineName, _dataContainer);
87 88 89

        if (! _pipeline)
            FAIL();
90
        ASSERT_TRUE(_pipeline != nullptr);
91 92 93

        if (_pipeline != nullptr) {
            // setup pipeline
94
            _pipeline->setCanvas(GLJobProc.getContext());
95 96
            _pipeline->init();
            _pipeline->setEnabled(true);
97
            _pipeline->setRenderTargetSize(cgt::ivec2(1024, 1024));
98 99 100 101 102 103

            // invalidate each processor
            std::vector<AbstractProcessor*> processors = _pipeline->getProcessors();
            for (size_t i = 0; i < processors.size(); ++i) {
                processors[i]->invalidate(AbstractProcessor::INVALID_RESULT);
            }
104
        }
105 106 107
        else {
            FAIL() << "Could not instantiate pipeline '" << _pipelineName << "'";
        }
108
    }
109

110 111
    void execute() {
        if (_pipeline != nullptr) {
112 113
            sigslot::signal_manager::getRef().waitForSignalQueueFlushed();

114 115
            for (size_t i = 0; i < _pipeline->getProcessors().size(); ++i)
                _pipeline->executePipeline();
116 117 118 119

            // write result image
            _imageWriter.p_inputImage.setValue(_pipeline->getRenderTargetID());
            _imageWriter.p_url.setValue(_fileName);
120
            _imageWriter.invalidate(AbstractProcessor::INVALID_RESULT);
121 122
            _imageWriter.process(_dataContainer);

123
            _wroteFile = cgt::FileSystem::fileExists(_fileName);
124 125

            sigslot::signal_manager::getRef().waitForSignalQueueFlushed();
126 127 128 129 130 131
        }
    }

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

    DataContainer _dataContainer;
    AbstractPipeline* _pipeline;
    DevilImageWriter _imageWriter;

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

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

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

TEST_F(PipelineWriteResultImageTest, SliceVis) {
    _pipelineName = "SliceVis";
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    _fileName = _basePath + "slicevis.png";
    init();
    execute();
    EXPECT_TRUE(_wroteFile);
}

TEST_F(PipelineWriteResultImageTest, AdvancedUsVis) {
    _pipelineName = "AdvancedUsVis";
    _fileName = _basePath + "advancedusvis.png";
    init();
    execute();
    EXPECT_TRUE(_wroteFile);
}

TEST_F(PipelineWriteResultImageTest, VectorFieldDemo) {
    _pipelineName = "VectorFieldDemo";
    _fileName = _basePath + "vectorfielddemo.png";
    init();

180 181 182 183
    if (! _pipeline)
        return;

    execute();
184 185
    AbstractProperty* p = _pipeline->getProperty("SliceNuber");
    if (IntProperty* tester = dynamic_cast<IntProperty*>(p)) {
186
        tester->setValue(64);
187 188
    }
    execute();
189

190 191 192 193 194 195 196 197
    EXPECT_TRUE(_wroteFile);
}

TEST_F(PipelineWriteResultImageTest, DVRVis) {
    _pipelineName = "DVRVis";
    _fileName = _basePath + "dvrvis.png";
    init();

198 199 200 201
    if (! _pipeline)
        return;

    execute();
202 203 204 205 206 207 208
    auto properties = _pipeline->getProcessors();
    for (auto it = properties.begin(); it != properties.end(); ++it) {
        if (TrackballCameraProvider* tcp = dynamic_cast<TrackballCameraProvider*>(*it)) {
            tcp->p_position.setValue(cgt::vec3(417.f, 44.5f, -112.5f));
            tcp->p_focus.setValue(cgt::vec3(91.f, 91.f, 80.f));
            tcp->p_upVector.setValue(cgt::vec3(-0.487f, 0.142f, -0.861f));
        }
209 210 211 212 213 214 215 216 217
    }
    execute();

    EXPECT_TRUE(_wroteFile);
}

TEST_F(PipelineWriteResultImageTest, TensorDemo) {
    _pipelineName = "TensorDemo";
    _fileName = _basePath + "tensordemo.png";
218
    init();
219

220 221 222 223
    if (! _pipeline)
        return;

    execute();
224 225 226 227 228 229
    AbstractProperty* p = _pipeline->getProperty("SliceNuber");
    if (IntProperty* tester = dynamic_cast<IntProperty*>(p)) {
        tester->setValue(6);
    }
    execute();

230 231 232 233
    EXPECT_TRUE(_wroteFile);
}

#endif
234