* Added PipelineResultImageTest case to run pipelines and write their rendering results to PNGs.

* Updated DevilImageWriter, added property to make writing depth images optional.
parent 80693730
......@@ -46,10 +46,12 @@ namespace campvis {
DevilImageWriter::DevilImageWriter()
: AbstractProcessor()
, p_inputImage("InputImage", "Input Image ID", "DevilImageWriter.input", DataNameProperty::READ)
, p_url("url", "Image URL", "", StringProperty::SAVE_FILENAME)
, p_url("Url", "Image URL", "", StringProperty::SAVE_FILENAME)
, p_writeDepthImage("WriteDepthImage", "Write Depth Image", false)
{
addProperty(p_inputImage);
addProperty(p_url);
addProperty(p_writeDepthImage);
}
DevilImageWriter::~DevilImageWriter() {
......@@ -64,7 +66,7 @@ namespace campvis {
std::string filebase = tgt::FileSystem::fullBaseName(filename);
if (extension.empty()) {
LINFO("Filename has no extension, defaulting to .PNG.");
extension = ".png";
extension = "png";
}
for (size_t i = 0; i < image->getNumColorTextures(); ++i) {
......@@ -75,16 +77,16 @@ namespace campvis {
}
WeaklyTypedPointer wtp = id->getWeaklyTypedPointer();
writeIlImage(wtp, id->getSize().xy(), filebase + ".color" + ((image->getNumColorTextures() > 1) ? StringUtils::toString(i) : "") + extension);
writeIlImage(wtp, id->getSize().xy(), filebase + ((image->getNumColorTextures() > 1) ? StringUtils::toString(i) : "") + "." + extension);
}
if (image->hasDepthTexture()) {
if (p_writeDepthImage.getValue() && image->hasDepthTexture()) {
const ImageRepresentationLocal* id = image->getDepthTexture()->getRepresentation<ImageRepresentationLocal>(true);
if (id == 0) {
LERROR("Could not download depth texture from RenderData, skipping.");
}
else {
WeaklyTypedPointer wtp = id->getWeaklyTypedPointer();
writeIlImage(wtp, id->getSize().xy(), filebase + ".depth" + extension);
writeIlImage(wtp, id->getSize().xy(), filebase + ".depth." + extension);
}
}
}
......@@ -106,12 +108,13 @@ namespace campvis {
ILboolean success = ilSaveImage(filename.c_str());
ilDeleteImages(1, &img);
if (success != IL_NO_ERROR) {
if (! success) {
ILenum errorcode;
while ((errorcode = ilGetError()) != IL_NO_ERROR) {
LERROR("Error while writing '" << filename << "': "<< iluErrorString(errorcode));
}
}
}
}
\ No newline at end of file
......@@ -70,6 +70,7 @@ namespace campvis {
DataNameProperty p_inputImage; ///< image ID for image to write
StringProperty p_url; ///< URL for file to write
BoolProperty p_writeDepthImage; ///< Flag whether to save also depth image
protected:
/// \see AbstractProcessor::updateResult
......
......@@ -11,6 +11,7 @@ FILE(GLOB TestCampvisSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
core/properties/*.cpp
core/tools/*.cpp
core/pipeline/*.cpp
modules/*.cpp
)
# Summary of tuple support for Microsoft Visual Studio:
......
// ================================================================================================
//
// 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"
#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)
{
}
~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;
DataContainer _dataContainer;
AbstractPipeline* _pipeline;
DevilImageWriter _imageWriter;
bool _wroteFile;
};
TEST_F(PipelineWriteResultImageTest, VolumeExplorerDemo) {
_pipelineName = "VolumeExplorerDemo";
_fileName = "volumeexplorerdemo.png";
init();
execute();
EXPECT_TRUE(_wroteFile);
}
TEST_F(PipelineWriteResultImageTest, GeometryRendererDemo) {
_pipelineName = "GeometryRendererDemo";
_fileName = "geometryrendererdemo.png";
init();
execute();
EXPECT_TRUE(_wroteFile);
}
TEST_F(PipelineWriteResultImageTest, SliceVis) {
_pipelineName = "SliceVis";
_fileName = "slicevis.png";
init();
execute();
EXPECT_TRUE(_wroteFile);
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment