diff --git a/Core/Code/Rendering/mitkRenderingTestHelper.cpp b/Core/Code/Rendering/mitkRenderingTestHelper.cpp index 50017f4df2..a6e86079e3 100644 --- a/Core/Code/Rendering/mitkRenderingTestHelper.cpp +++ b/Core/Code/Rendering/mitkRenderingTestHelper.cpp @@ -1,237 +1,237 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //VTK #include #include #include #include //MITK #include #include #include #include #include #include #include // include gl to read out properties #include #include //VTK Testing to compare the rendered image pixel-wise against a reference screen shot #include "vtkTesting.h" mitkRenderingTestHelper::mitkRenderingTestHelper(int width, int height) : m_AutomaticallyCloseRenderWindow(true) { this->Initialize(width, height); } mitkRenderingTestHelper::mitkRenderingTestHelper(int width, int height, int argc, char* argv[]) : m_AutomaticallyCloseRenderWindow(true) { this->Initialize(width, height); this->SetInputFileNames(argc, argv); } void mitkRenderingTestHelper::Initialize(int width, int height) { // Global interaction must(!) be initialized mitk::GlobalInteraction::GetInstance()->Initialize("global"); m_RenderWindow = mitk::RenderWindow::New(); m_DataStorage = mitk::StandaloneDataStorage::New(); m_RenderWindow->GetRenderer()->SetDataStorage(m_DataStorage); this->SetMapperIDToRender2D(); this->GetVtkRenderWindow()->SetSize( width, height ); m_RenderWindow->GetRenderer()->Resize( width, height); //Prints the glinfo after creation of the vtkrenderwindow, we always want to do this for debugging. this->PrintGLInfo(); } mitkRenderingTestHelper::~mitkRenderingTestHelper() { } void mitkRenderingTestHelper::PrintGLInfo() { GLint maxTextureSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);; MITK_INFO << "OpenGL Render Context Information: \n" << "- GL_VENDOR: "<< glGetString(GL_VENDOR) << "\n" << "- GL_RENDERER: "<< glGetString(GL_RENDERER) << "\n" << "- GL_VERSION: "<< glGetString(GL_VERSION) << "\n" << "- GL_MAX_TEXTURE_SIZE: "<< maxTextureSize << "\n" << "- GL_EXTENSIONS: "<< glGetString(GL_EXTENSIONS); } void mitkRenderingTestHelper::SetMapperID( mitk::BaseRenderer::StandardMapperSlot id) { m_RenderWindow->GetRenderer()->SetMapperID(id); } void mitkRenderingTestHelper::SetMapperIDToRender3D() { this->SetMapperID(mitk::BaseRenderer::Standard3D); } void mitkRenderingTestHelper::SetMapperIDToRender2D() { this->SetMapperID(mitk::BaseRenderer::Standard2D); } void mitkRenderingTestHelper::Render() { //if the datastorage is initialized and at least 1 image is loaded render it if(m_DataStorage.IsNotNull() || m_DataStorage->GetAll()->Size() >= 1 ) { - //perform global reinit: + //Prepare the VTK camera before rendering. m_RenderWindow->GetRenderer()->PrepareRender(); - //use this to actually show the iamge in a renderwindow this->GetVtkRenderWindow()->Render(); if(m_AutomaticallyCloseRenderWindow == false) { + //Use interaction to stop the test this->GetVtkRenderWindow()->GetInteractor()->Start(); } } else { MITK_ERROR << "No images loaded in data storage!"; } } -void mitkRenderingTestHelper::PrepareRender() -{ - //perform global reinit: - m_RenderWindow->GetRenderer()->PrepareRender(); -} - mitk::DataStorage::Pointer mitkRenderingTestHelper::GetDataStorage() { return m_DataStorage; } void mitkRenderingTestHelper::SetInputFileNames(int argc, char* argv[]) { - // parse parameters + //i is set 1, because 0 is the testname as string + //parse parameters for (int i = 1; i < argc; ++i) { //add everything to a list but -T and -V std::string tmp = argv[i]; if((tmp.compare("-T")) && (tmp.compare("-V"))) { this->AddToStorage(tmp); } else { break; } } } void mitkRenderingTestHelper::SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection) { mitk::BaseRenderer::GetInstance(m_RenderWindow->GetVtkRenderWindow())->GetSliceNavigationController()->SetDefaultViewDirection(viewDirection); mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()) ); } void mitkRenderingTestHelper::ReorientSlices(mitk::Point3D origin, mitk::Vector3D rotation) { mitk::SliceNavigationController::Pointer sliceNavigationController = mitk::BaseRenderer::GetInstance(m_RenderWindow->GetVtkRenderWindow())->GetSliceNavigationController(); sliceNavigationController->ReorientSlices(origin, rotation); } vtkRenderer* mitkRenderingTestHelper::GetVtkRenderer() { return m_RenderWindow->GetRenderer()->GetVtkRenderer(); } void mitkRenderingTestHelper::SetImageProperty(const char *propertyKey, mitk::BaseProperty* property ) { this->m_DataStorage->GetNode(mitk::NodePredicateDataType::New("Image"))->SetProperty(propertyKey, property); } vtkRenderWindow* mitkRenderingTestHelper::GetVtkRenderWindow() { return m_RenderWindow->GetVtkRenderWindow(); } bool mitkRenderingTestHelper::CompareRenderWindowAgainstReference(int argc, char* argv[], double threshold) { - this->PrepareRender(); + this->Render(); //retVal meanings: (see VTK/Rendering/vtkTesting.h) //0 = test failed //1 = test passed //2 = test not run //3 = something with vtkInteraction if(vtkTesting::Test(argc, argv, this->GetVtkRenderWindow(), threshold) == 1) return true; else return false; } //method to save a screenshot of the renderwindow (e.g. create a reference screenshot) void mitkRenderingTestHelper::SaveAsPNG(std::string fileName) { vtkSmartPointer renderer = this->GetVtkRenderer(); bool doubleBuffering( renderer->GetRenderWindow()->GetDoubleBuffer() ); renderer->GetRenderWindow()->DoubleBufferOff(); vtkSmartPointer magnifier = vtkSmartPointer::New(); magnifier->SetInput(renderer); magnifier->SetMagnification(1); vtkSmartPointer fileWriter = vtkSmartPointer::New(); fileWriter->SetInput(magnifier->GetOutput()); fileWriter->SetFileName(fileName.c_str()); fileWriter->Write(); renderer->GetRenderWindow()->SetDoubleBuffer(doubleBuffering); } +void mitkRenderingTestHelper::SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow) +{ + m_AutomaticallyCloseRenderWindow = automaticallyCloseRenderWindow; +} + void mitkRenderingTestHelper::SaveReferenceScreenShot(std::string fileName) { this->SaveAsPNG(fileName); } void mitkRenderingTestHelper::AddToStorage(const std::string &filename) { try { mitk::DataNode::Pointer node = mitk::IOUtil::LoadDataNode(filename); this->AddNodeToStorage(node); } catch ( itk::ExceptionObject & e ) { MITK_ERROR << "Failed loading test data '" << filename << "': " << e.what(); } } void mitkRenderingTestHelper::AddNodeToStorage(mitk::DataNode::Pointer node) { this->m_DataStorage->Add(node); mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()) ); } diff --git a/Core/Code/Rendering/mitkRenderingTestHelper.h b/Core/Code/Rendering/mitkRenderingTestHelper.h index 9c30224e25..f01bde6241 100644 --- a/Core/Code/Rendering/mitkRenderingTestHelper.h +++ b/Core/Code/Rendering/mitkRenderingTestHelper.h @@ -1,159 +1,168 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkRenderingTestHelper_h #define mitkRenderingTestHelper_h #include #include #include #include #include class vtkRenderWindow; class vtkRenderer; class MITK_CORE_EXPORT mitkRenderingTestHelper { public: /** @brief Generate a rendering test helper object including a render window of the size width * height (in pixel). @param argc Number of parameters. (here: Images) "Usage: [filename1 filenam2 -V referenceScreenshot (optional -T /directory/to/save/differenceImage)] - @param argv Given parameters. + @param argv Given parameters. If no data is inserted via commandline, you can add data + later via AddNodeToDataStorage(). **/ mitkRenderingTestHelper(int width, int height, int argc, char *argv[]); /** @brief Generate a rendering test helper object including a render window of the size width * height (in pixel).*/ mitkRenderingTestHelper(int width, int height); /** Default destructor */ ~mitkRenderingTestHelper(); /** @brief Getter for the vtkRenderer. **/ vtkRenderer* GetVtkRenderer(); /** @brief Getter for the vtkRenderWindow which should be used to call vtkRegressionTestImage. **/ vtkRenderWindow* GetVtkRenderWindow(); /** @brief Method can be used to save a screenshot (e.g. reference screenshot as a .png file. @param fileName The filename of the new screenshot (including path). **/ void SaveAsPNG(std::string fileName); /** * @brief SetStopRenderWindow Convenience method to make the renderwindow hold after rendering. Usefull for debugging. * @param flag Flag indicating whether the renderwindow should automatically close (false, default) or stay open (true). Usefull for debugging. */ void SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow); /** @brief This method set the property of the member datastorage - @param property Set a property for each image in the datastorage m_DataStorage. + @param property Set a property for each image in the datastorage m_DataStorage. If you want + to set the property for a single data node, use GetDataStorage() and set the property + yourself for the destinct node. **/ void SetImageProperty(const char *propertyKey, mitk::BaseProperty *property); /** @brief Set the view direction of the renderwindow (e.g. sagittal, coronal, axial) **/ void SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection); /** @brief Reorient the slice (e.g. rotation and translation like the swivel mode). **/ void ReorientSlices(mitk::Point3D origin, mitk::Vector3D rotation); /** @brief Render everything into an mitkRenderWindow. Call SetViewDirection() and SetProperty() before this method. **/ void Render(); - /** @brief Calls PrepareRender function of mitkRenderWindow - **/ - void PrepareRender(); /** @brief Returns the datastorage, in order to modify the data inside a rendering test. **/ mitk::DataStorage::Pointer GetDataStorage(); /** * @brief SetMapperID Change between Standard2D and 3D mappers. * @param id Enum mitk::BaseRenderer::StandardMapperSlot which defines the mapper. */ void SetMapperID(mitk::BaseRenderer::StandardMapperSlot id); /** * @brief AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering. * @param node The data you want to add. */ void AddNodeToStorage(mitk::DataNode::Pointer node); /** * @brief SetMapperIDToRender3D Convenience method to render in a 3D renderwindow. * @warning Does not add helper objects like the image planes to render images in 3D. */ void SetMapperIDToRender3D(); /** * @brief SetMapperIDToRender2D Convenience method to render in a 2D renderwindow. */ void SetMapperIDToRender2D(); /** * @brief SaveReferenceScreenShot Convenience method to save a reference screen shot. * @param fileName Path/to/save/the/png/file. */ void SaveReferenceScreenShot(std::string fileName); /** - * @brief CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal renderwindow against a reference screen shot + * @brief CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal renderwindow against a reference screen shot. + * + Usage of vtkTesting::Test: + vtkTesting::Test( argc, argv, vtkRenderWindow, threshold ) + Set a vtkRenderWindow containing the desired scene. This is automatically rendered. + vtkTesting::Test() automatically searches in argc and argv[] + for a path a valid image with -V. If the test failed with the + first image (foo.png) it checks if there are images of the form + foo_N.png (where N=1,2,3...) and compare against them. This allows for multiple + valid images. * @param argc Number of arguments. * @param argv Arguments must(!) contain the term "-V Path/To/Valid/Image.png" * @param threshold Allowed difference between two images. Default = 10.0 and was taken from VTK. * @return True if the images are equal regarding the threshold. False in all other cases. */ bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold = 10.0); protected: /** * @brief Initialize Internal method to initialize the renderwindow and set the datastorage. * @param width Height of renderwindow. * @param height Width of renderwindow. */ void Initialize(int width, int height); /** @brief Prints the opengl information, e.g. version, vendor and extensions, * This function can only be called after an opengl context is active. * It only prints the context after the vtkRenderwindow is fully initialized. **/ void PrintGLInfo(); /** @brief This method tries to load the given file into a member datastorage, in order to render it. @param fileName The filename of the file to be loaded (including path). **/ void AddToStorage(const std::string& filename); /** @brief This method tries to parse the given argv for files (e.g. images) and load them into a member datastorage, in order to render it. @param argc Number of parameters. @param argv Given parameters. **/ void SetInputFileNames(int argc, char *argv[]); mitk::RenderWindow::Pointer m_RenderWindow; //<< Contains the mitkRenderWindow into which the test renders the data mitk::DataStorage::Pointer m_DataStorage; //<< Contains the mitkDataStorage which contains the data to be rendered bool m_AutomaticallyCloseRenderWindow; //<< Flag indicating whether the renderwindow should automatically close (true, default) or stay open (false). Usefull for debugging. }; #endif diff --git a/Core/Code/Testing/mitkImageVtkMapper2DColorTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DColorTest.cpp index 3012ae6afd..2ce87c0e70 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DColorTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DColorTest.cpp @@ -1,76 +1,53 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //MITK #include "mitkTestingMacros.h" #include "mitkRenderingTestHelper.h" //VTK #include int mitkImageVtkMapper2DColorTest(int argc, char* argv[]) { - // load all arguments into a datastorage, take last argument as reference rendering - // setup a renderwindow of fixed size X*Y - // render the datastorage - // compare rendering to reference image - MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") - - // enough parameters? - if ( argc < 2 ) - { - MITK_TEST_OUTPUT( << "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile" ) - MITK_TEST_OUTPUT( << "Will render a central axial slice of all given files into outputfile" ) - exit( EXIT_SUCCESS ); - } - - mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); - //Set the opacity for all images - renderingHelper.SetImageProperty("color", mitk::ColorProperty::New(0.0f, 0.0f, 255.0f)); - //for now this test renders in sagittal view direction - renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); - renderingHelper.Render(); - - //#################### - //Use this to generate a reference screenshot or save the file. - //(Only in your local version of the test!) - if(false) - { - renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); - } - //#################### - - //### Usage of vtkRegressionTestImage: - //vtkRegressionTestImage( vtkRenderWindow ) - //Set a vtkRenderWindow containing the desired scene. - //vtkRegressionTestImage automatically searches in argc and argv[] - //for a path a valid image with -V. If the test failed with the - //first image (foo.png) check if there are images of the form - //foo_N.png (where N=1,2,3...) and compare against them. -// renderingHelper.PrepareRender(); -// int retVal = vtkRegressionTestImage( renderingHelper.GetVtkRenderWindow() ); - -// //retVal meanings: (see VTK/Rendering/vtkTesting.h) -// //0 = test failed -// //1 = test passed -// //2 = test not run -// //3 = something with vtkInteraction - MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive" ); - - MITK_TEST_END(); + // load all arguments into a datastorage, take last argument as reference rendering + // setup a renderwindow of fixed size X*Y + // render the datastorage + // compare rendering to reference image + MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") + + mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); + //Set the opacity for all images + renderingHelper.SetImageProperty("color", mitk::ColorProperty::New(0.0f, 0.0f, 255.0f)); + //for now this test renders in sagittal view direction + renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); + + //#################### + //Use this to generate a reference screenshot or save the file. + //(Only in your local version of the test!) + if(false) + { + renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); + } + //#################### + + //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper + MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" ); + + MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkImageVtkMapper2DLevelWindowTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DLevelWindowTest.cpp index da113a3356..ee59981e32 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DLevelWindowTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DLevelWindowTest.cpp @@ -1,81 +1,58 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //MITK #include "mitkTestingMacros.h" #include "mitkRenderingTestHelper.h" #include #include //VTK #include int mitkImageVtkMapper2DLevelWindowTest(int argc, char* argv[]) { - // load all arguments into a datastorage, take last argument as reference rendering - // setup a renderwindow of fixed size X*Y - // render the datastorage - // compare rendering to reference image - MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") - - // enough parameters? - if ( argc < 2 ) - { - MITK_TEST_OUTPUT( << "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile" ) - MITK_TEST_OUTPUT( << "Will render a central axial slice of all given files into outputfile" ) - exit( EXIT_SUCCESS ); - } - - mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); - //chose a level window: here we randomly chosen the blood preset. - mitk::LevelWindowPreset* levelWindowPreset = mitk::LevelWindowPreset::New(); - bool loadedPreset = levelWindowPreset->LoadPreset(); - MITK_TEST_CONDITION_REQUIRED(loadedPreset == true, "Testing if level window preset could be loaded"); - double level = levelWindowPreset->getLevel("Blood"); - double window = levelWindowPreset->getWindow("Blood"); - //apply level window to all images - renderingHelper.SetImageProperty("levelwindow", mitk::LevelWindowProperty::New(mitk::LevelWindow(level, window)) ); - //for now this test renders Sagittal - renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); - renderingHelper.Render(); - - //use this to generate a reference screenshot or save the file: - bool generateReferenceScreenshot = false; - if(generateReferenceScreenshot) - { - renderingHelper.SaveAsPNG("/home/kilgus/Pictures/RenderingTestData/output.png"); - } - - //### Usage of vtkRegressionTestImage: - //vtkRegressionTestImage( vtkRenderWindow ) - //Set a vtkRenderWindow containing the desired scene. - //vtkRegressionTestImage automatically searches in argc and argv[] - //for a path a valid image with -V. If the test failed with the - //first image (foo.png) check if there are images of the form - //foo_N.png (where N=1,2,3...) and compare against them. - renderingHelper.PrepareRender(); - int retVal = vtkRegressionTestImage( renderingHelper.GetVtkRenderWindow() ); - - //retVal meanings: (see VTK/Rendering/vtkTesting.h) - //0 = test failed - //1 = test passed - //2 = test not run - //3 = something with vtkInteraction - MITK_TEST_CONDITION( retVal == 1, "VTK test result positive" ); - - MITK_TEST_END(); + // load all arguments into a datastorage, take last argument as reference rendering + // setup a renderwindow of fixed size X*Y + // render the datastorage + // compare rendering to reference image + MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") + + mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); + //chose a level window: here we randomly chosen the blood preset. + mitk::LevelWindowPreset* levelWindowPreset = mitk::LevelWindowPreset::New(); + bool loadedPreset = levelWindowPreset->LoadPreset(); + MITK_TEST_CONDITION_REQUIRED(loadedPreset == true, "Testing if level window preset could be loaded"); + double level = levelWindowPreset->getLevel("Blood"); + double window = levelWindowPreset->getWindow("Blood"); + //apply level window to all images + renderingHelper.SetImageProperty("levelwindow", mitk::LevelWindowProperty::New(mitk::LevelWindow(level, window)) ); + //for now this test renders Sagittal + renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); + + //use this to generate a reference screenshot or save the file: + bool generateReferenceScreenshot = false; + if(generateReferenceScreenshot) + { + renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); + } + + //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper + MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" ); + + MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkImageVtkMapper2DOpacityTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DOpacityTest.cpp index 1cafc6de51..be59fe014a 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DOpacityTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DOpacityTest.cpp @@ -1,74 +1,51 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //MITK #include "mitkTestingMacros.h" #include "mitkRenderingTestHelper.h" //VTK #include int mitkImageVtkMapper2DOpacityTest(int argc, char* argv[]) { - // load all arguments into a datastorage, take last argument as reference rendering - // setup a renderwindow of fixed size X*Y - // render the datastorage - // compare rendering to reference image - MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") - - // enough parameters? - if ( argc < 2 ) - { - MITK_TEST_OUTPUT( << "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile" ) - MITK_TEST_OUTPUT( << "Will render a central axial slice of all given files into outputfile" ) - exit( EXIT_SUCCESS ); - } - - mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); - //Set the opacity for all images - renderingHelper.SetImageProperty("opacity", mitk::FloatProperty::New(0.5f)); - //for now this test renders in coronal view direction - renderingHelper.SetViewDirection(mitk::SliceNavigationController::Frontal); - renderingHelper.Render(); - - //use this to generate a reference screenshot or save the file: - bool generateReferenceScreenshot = false; - if(generateReferenceScreenshot) - { - renderingHelper.SaveAsPNG("/home/kilgus/Pictures/RenderingTestData/output.png"); - } - - //### Usage of vtkRegressionTestImage: - //vtkRegressionTestImage( vtkRenderWindow ) - //Set a vtkRenderWindow containing the desired scene. - //vtkRegressionTestImage automatically searches in argc and argv[] - //for a path a valid image with -V. If the test failed with the - //first image (foo.png) check if there are images of the form - //foo_N.png (where N=1,2,3...) and compare against them. - renderingHelper.PrepareRender(); - int retVal = vtkRegressionTestImage( renderingHelper.GetVtkRenderWindow() ); - - //retVal meanings: (see VTK/Rendering/vtkTesting.h) - //0 = test failed - //1 = test passed - //2 = test not run - //3 = something with vtkInteraction - MITK_TEST_CONDITION( retVal == 1, "VTK test result positive" ); - - MITK_TEST_END(); + // load all arguments into a datastorage, take last argument as reference rendering + // setup a renderwindow of fixed size X*Y + // render the datastorage + // compare rendering to reference image + MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") + + mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); + //Set the opacity for all images + renderingHelper.SetImageProperty("opacity", mitk::FloatProperty::New(0.5f)); + //for now this test renders in coronal view direction + renderingHelper.SetViewDirection(mitk::SliceNavigationController::Frontal); + + //use this to generate a reference screenshot or save the file: + bool generateReferenceScreenshot = false; + if(generateReferenceScreenshot) + { + renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); + } + + //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper + MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" ); + + MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkImageVtkMapper2DSwivelTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DSwivelTest.cpp index 58b356a3f6..b17e39356b 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DSwivelTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DSwivelTest.cpp @@ -1,89 +1,66 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //MITK #include "mitkTestingMacros.h" #include "mitkRenderingTestHelper.h" #include //VTK #include int mitkImageVtkMapper2DSwivelTest(int argc, char* argv[]) { - //load all arguments into a datastorage, take last argument as reference - //setup a renderwindow of fixed size X*Y - //render the datastorage - //compare rendering to reference image - MITK_TEST_BEGIN("mitkImageVtkMapper2DSwivelTest") - - // enough parameters? - if ( argc < 2 ) - { - MITK_TEST_OUTPUT( << "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile" ) - MITK_TEST_OUTPUT( << "Will render a central axial slice of all given files into outputfile" ) - exit( EXIT_SUCCESS ); - } - - mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); - //center point for rotation - mitk::Point3D centerPoint; - centerPoint.Fill(0.0f); - //vector for rotating the slice - mitk::Vector3D rotationVector; - rotationVector.SetElement(0, 0.2); - rotationVector.SetElement(1, 0.3); - rotationVector.SetElement(2, 0.5); - //sets a swivel direction for the image - - //new version of setting the center point: - mitk::Image::Pointer image = static_cast(renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))->GetData()); - - //get the center point of the image - centerPoint = image->GetGeometry()->GetCenter(); - - //rotate the image arround its own center - renderingHelper.ReorientSlices(centerPoint, rotationVector); - renderingHelper.Render(); - - //use this to generate a reference screenshot or save the file: - bool generateReferenceScreenshot = false; - if(generateReferenceScreenshot) - { - renderingHelper.SaveAsPNG("/media/hdd/thomasHdd/Pictures/RenderingTestData/pic3dSwivel640x480REF.png"); - } - - //### Usage of vtkRegressionTestImage: - //vtkRegressionTestImage( vtkRenderWindow ) - //Set a vtkRenderWindow containing the desired scene. - //vtkRegressionTestImage automatically searches in argc and argv[] - //for a path a valid image with -V. If the test failed with the - //first image (foo.png) check if there are images of the form - //foo_N.png (where N=1,2,3...) and compare against them. - renderingHelper.PrepareRender(); - int retVal = vtkRegressionTestImage( renderingHelper.GetVtkRenderWindow() ); - - //retVal meanings: (see VTK/Rendering/vtkTesting.h) - //0 = test failed - //1 = test passed - //2 = test not run - //3 = something with vtkInteraction - MITK_TEST_CONDITION( retVal == 1, "VTK test result positive" ); - - MITK_TEST_END(); + //load all arguments into a datastorage, take last argument as reference + //setup a renderwindow of fixed size X*Y + //render the datastorage + //compare rendering to reference image + MITK_TEST_BEGIN("mitkImageVtkMapper2DSwivelTest") + + mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); + //center point for rotation + mitk::Point3D centerPoint; + centerPoint.Fill(0.0f); + //vector for rotating the slice + mitk::Vector3D rotationVector; + rotationVector.SetElement(0, 0.2); + rotationVector.SetElement(1, 0.3); + rotationVector.SetElement(2, 0.5); + //sets a swivel direction for the image + + //new version of setting the center point: + mitk::Image::Pointer image = static_cast(renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))->GetData()); + + //get the center point of the image + centerPoint = image->GetGeometry()->GetCenter(); + + //rotate the image arround its own center + renderingHelper.ReorientSlices(centerPoint, rotationVector); + + //use this to generate a reference screenshot or save the file: + bool generateReferenceScreenshot = false; + if(generateReferenceScreenshot) + { + renderingHelper.SaveReferenceScreenShot("/media/hdd/thomasHdd/Pictures/RenderingTestData/pic3dSwivel640x480REF.png"); + } + + //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper + MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" ); + + MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkImageVtkMapper2DTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DTest.cpp index 5d155c1d67..aacce7ef4a 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DTest.cpp @@ -1,70 +1,47 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //MITK #include "mitkTestingMacros.h" #include "mitkRenderingTestHelper.h" //VTK #include int mitkImageVtkMapper2DTest(int argc, char* argv[]) { - // load all arguments into a datastorage, take last argument as reference rendering - // setup a renderwindow of fixed size X*Y - // render the datastorage - // compare rendering to reference image - MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") + // load all arguments into a datastorage, take last argument as reference rendering + // setup a renderwindow of fixed size X*Y + // render the datastorage + // compare rendering to reference image + MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") - // enough parameters? - if ( argc < 2 ) - { - MITK_TEST_OUTPUT( << "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile" ) - MITK_TEST_OUTPUT( << "Will render a central axial slice of all given files into outputfile" ) - exit( EXIT_SUCCESS ); - } + mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); - mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); - renderingHelper.Render(); + //use this to generate a reference screenshot or save the file: + bool generateReferenceScreenshot = false; + if(generateReferenceScreenshot) + { + renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); + } - //use this to generate a reference screenshot or save the file: - bool generateReferenceScreenshot = false; - if(generateReferenceScreenshot) - { - renderingHelper.SaveAsPNG("/home/kilgus/Pictures/RenderingTestData/output.png"); - } + //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper + MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" ); - //### Usage of vtkRegressionTestImage: - //vtkRegressionTestImage( vtkRenderWindow ) - //Set a vtkRenderWindow containing the desired scene. - //vtkRegressionTestImage automatically searches in argc and argv[] - //for a path a valid image with -V. If the test failed with the - //first image (foo.png) check if there are images of the form - //foo_N.png (where N=1,2,3...) and compare against them. - renderingHelper.PrepareRender(); - int retVal = vtkRegressionTestImage( renderingHelper.GetVtkRenderWindow() ); - - //retVal meanings: (see VTK/Rendering/vtkTesting.h) - //0 = test failed - //1 = test passed - //2 = test not run - //3 = something with vtkInteraction - MITK_TEST_CONDITION( retVal == 1, "VTK test result positive" ); - - MITK_TEST_END(); + MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkImageVtkMapper2DTransferFunctionTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DTransferFunctionTest.cpp index 6f5e720acb..dfa3f53280 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DTransferFunctionTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DTransferFunctionTest.cpp @@ -1,89 +1,63 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //MITK #include "mitkTestingMacros.h" #include "mitkRenderingTestHelper.h" //VTK #include #include #include #include int mitkImageVtkMapper2DTransferFunctionTest(int argc, char* argv[]) { - // load all arguments into a datastorage, take last argument as reference rendering - // setup a renderwindow of fixed size X*Y - // render the datastorage - // compare rendering to reference image - MITK_TEST_BEGIN("mitkImageVtkMapper2DTransferFunctionTest") - - // enough parameters? - if ( argc < 2 ) - { - MITK_TEST_OUTPUT( << "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile" ) - MITK_TEST_OUTPUT( << "Will render a central axial slice of all given files into outputfile" ) - exit( EXIT_SUCCESS ); - } - mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); - - //define an arbitrary colortransferfunction - vtkSmartPointer colorTransferFunction = vtkSmartPointer::New(); - colorTransferFunction->SetColorSpaceToRGB(); - colorTransferFunction->AddRGBPoint(0.0, 1, 0, 0); //black = red - colorTransferFunction->AddRGBPoint(127.5, 0, 1, 0); //grey = green - colorTransferFunction->AddRGBPoint(255.0, 0, 0, 1); //white = blue - mitk::TransferFunction::Pointer transferFucntion = mitk::TransferFunction::New(); - transferFucntion->SetColorTransferFunction( colorTransferFunction ); - - //set the rendering mode to use the transfer function - renderingHelper.SetImageProperty("Image Rendering.Mode", mitk::RenderingModeProperty::New(mitk::RenderingModeProperty::COLORTRANSFERFUNCTION_COLOR)); - //set the property for the image - renderingHelper.SetImageProperty("Image Rendering.Transfer Function", mitk::TransferFunctionProperty::New(transferFucntion)); - - renderingHelper.Render(); - - //use this to generate a reference screenshot or save the file: - bool generateReferenceScreenshot = false; - if(generateReferenceScreenshot) - { - renderingHelper.SaveAsPNG("/home/kilgus/Pictures/RenderingTestData/output.png"); - } - - renderingHelper.PrepareRender(); - //### Usage of vtkRegressionTestImage: - //vtkRegressionTestImage( vtkRenderWindow ) - //Set a vtkRenderWindow containing the desired scene. - //vtkRegressionTestImage automatically searches in argc and argv[] - //for a path a valid image with -V. If the test failed with the - //first image (foo.png) check if there are images of the form - //foo_N.png (where N=1,2,3...) and compare against them. - //Default tolerance for rendering tests is 10 (set by VTK). - //For this case, small artifacts in Windows occur and boundaries of the fonts, - //thus we double the default tolerance threshold and set it to 20. - int retVal = vtkTesting::Test(argc, argv, renderingHelper.GetVtkRenderWindow(), 20 ); - - //retVal meanings: (see VTK/Rendering/vtkTesting.h) - //0 = test failed - //1 = test passed - //2 = test not run - //3 = something with vtkInteraction - MITK_TEST_CONDITION( retVal == 1, "VTK test result positive" ); - - MITK_TEST_END(); + // load all arguments into a datastorage, take last argument as reference rendering + // setup a renderwindow of fixed size X*Y + // render the datastorage + // compare rendering to reference image + MITK_TEST_BEGIN("mitkImageVtkMapper2DTransferFunctionTest") + + mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); + + //define an arbitrary colortransferfunction + vtkSmartPointer colorTransferFunction = vtkSmartPointer::New(); + colorTransferFunction->SetColorSpaceToRGB(); + colorTransferFunction->AddRGBPoint(0.0, 1, 0, 0); //black = red + colorTransferFunction->AddRGBPoint(127.5, 0, 1, 0); //grey = green + colorTransferFunction->AddRGBPoint(255.0, 0, 0, 1); //white = blue + mitk::TransferFunction::Pointer transferFucntion = mitk::TransferFunction::New(); + transferFucntion->SetColorTransferFunction( colorTransferFunction ); + + //set the rendering mode to use the transfer function + renderingHelper.SetImageProperty("Image Rendering.Mode", mitk::RenderingModeProperty::New(mitk::RenderingModeProperty::COLORTRANSFERFUNCTION_COLOR)); + //set the property for the image + renderingHelper.SetImageProperty("Image Rendering.Transfer Function", mitk::TransferFunctionProperty::New(transferFucntion)); + + //use this to generate a reference screenshot or save the file: + bool generateReferenceScreenshot = false; + if(generateReferenceScreenshot) + { + renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); + } + + //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper + MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 20.0) == true, "CompareRenderWindowAgainstReference test result positive?" ); + + MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkSurfaceVtkMapper3DTest.cpp b/Core/Code/Testing/mitkSurfaceVtkMapper3DTest.cpp index c94526cdd3..be479ee684 100644 --- a/Core/Code/Testing/mitkSurfaceVtkMapper3DTest.cpp +++ b/Core/Code/Testing/mitkSurfaceVtkMapper3DTest.cpp @@ -1,129 +1,105 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //MITK #include "mitkTestingMacros.h" #include "mitkRenderingTestHelper.h" #include #include #include //VTK #include #include #include #include #include #include #include #include int mitkSurfaceVtkMapper3DTest(int argc, char* argv[]) { // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkSurfaceVtkMapper3DTest") - // enough parameters? - if ( argc < 2 ) - { - MITK_TEST_OUTPUT( << "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile" ) - MITK_TEST_OUTPUT( << "Will render a central axial slice of all given files into outputfile" ) - exit( EXIT_SUCCESS ); - } - mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); //3D rendering test, thus 3D mapper ID. renderingHelper.SetMapperID(mitk::BaseRenderer::Standard3D); vtkSmartPointer textureCoordinates = vtkSmartPointer::New(); textureCoordinates->SetNumberOfComponents(2); textureCoordinates->SetName("TextureCoordinates"); mitk::Image::Pointer textureImage = static_cast< mitk::Image* > ( renderingHelper.GetDataStorage()->GetNode( mitk::NodePredicateDataType::New("Image"))->GetData() ); //generate texture coordinates assuming that surface and texture can be mapped 1 to 1 unsigned int* dims = textureImage->GetDimensions(); for(unsigned int j = 0; j < dims[1]; ++j) { for(unsigned int i = 0; i < dims[0]; ++i) { int pixelID = i + j*dims[0]; float xNorm = (((float)i)/dims[0]); float yNorm = ((float)j)/dims[1]; textureCoordinates->InsertTuple2(pixelID, xNorm, yNorm); } } mitk::Surface::Pointer surfaceToPutTextureOn = static_cast< mitk::Surface* > ( renderingHelper.GetDataStorage()->GetNode( mitk::NodePredicateDataType::New("Surface"))->GetData() ); surfaceToPutTextureOn->GetVtkPolyData()->GetPointData()->SetTCoords(textureCoordinates); mitk::SmartPointerProperty::Pointer textureProperty = mitk::SmartPointerProperty::New(textureImage); renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Surface"))->SetProperty("Surface.Texture", textureProperty); //remove the image from the data storage in order to not disturb the world geometry //(only the surface geometry should be used for rendering) renderingHelper.GetDataStorage()->Remove( renderingHelper.GetDataStorage()->GetNode( mitk::NodePredicateDataType::New("Image")) ); //Perform reinit, because we removed data. mitk::RenderingManager::GetInstance()->InitializeViews( renderingHelper.GetDataStorage()->ComputeBoundingGeometry3D(renderingHelper.GetDataStorage()->GetAll()) ); //Find a nice camera position to view the surface from the front. //This has to be done after calling renderingHelper.Render(), //because it would overwrite the camera position with global reinit. //It is not necessary, but else the surface is ugly rendered from the side. mitk::Point3D surfaceCenter= surfaceToPutTextureOn->GetGeometry()->GetCenter(); vtkCamera* camera3d = renderingHelper.GetVtkRenderer()->GetActiveCamera(); //1m distance to camera should be a nice default value for most cameras camera3d->SetPosition(0,0,-1000); camera3d->SetViewUp(0,-1,0); camera3d->SetFocalPoint(0,0,surfaceCenter[2]); camera3d->SetViewAngle(40); // camera3d->SetClippingRange(1, 10000); renderingHelper.GetVtkRenderer()->ResetCamera(); - - renderingHelper.Render(); //use this to generate a reference screenshot or save the file: bool generateReferenceScreenshot = false; if(generateReferenceScreenshot) { - renderingHelper.SaveAsPNG("/home/kilgus/Pictures/RenderingTestData/output.png"); + renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); } - //### Usage of vtkRegressionTestImage: - //vtkRegressionTestImage( vtkRenderWindow ) - //Set a vtkRenderWindow containing the desired scene. - //vtkRegressionTestImage automatically searches in argc and argv[] - //for a path a valid image with -V. If the test failed with the - //first image (foo.png) check if there are images of the form - //foo_N.png (where N=1,2,3...) and compare against them. - renderingHelper.PrepareRender(); - int retVal = vtkRegressionTestImage( renderingHelper.GetVtkRenderWindow() ); - - //retVal meanings: (see VTK/Rendering/vtkTesting.h) - //0 = test failed - //1 = test passed - //2 = test not run - //3 = something with vtkInteraction - MITK_TEST_CONDITION( retVal == 1, "VTK test result positive" ); + //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper + MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" ); MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp b/Core/Code/Testing/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp index 2fd221aadc..5161978eaa 100644 --- a/Core/Code/Testing/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp +++ b/Core/Code/Testing/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp @@ -1,114 +1,90 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //MITK #include "mitkTestingMacros.h" #include "mitkRenderingTestHelper.h" #include #include #include //VTK #include #include #include #include #include #include #include /** * @brief mitkSurfaceVtkMapper3DTexturedSphereTest This test puts a texture onto a sphere. It is a nice example how to use VTK methods to generate texture coordinates for MITK surfaces. * @param argv Just any image serving as texture. */ int mitkSurfaceVtkMapper3DTexturedSphereTest(int argc, char* argv[]) { // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkSurfaceVtkMapper3DTexturedSphereTest") - // enough parameters? - if ( argc < 2 ) - { - MITK_TEST_OUTPUT( << "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile" ) - MITK_TEST_OUTPUT( << "Will render a central axial slice of all given files into outputfile" ) - exit( EXIT_SUCCESS ); - } - mitkRenderingTestHelper renderingHelper(640, 480, argc, argv); //This is a test for a 3D surface, thus we need to set the mapper ID to 3D renderingHelper.SetMapperID(mitk::BaseRenderer::Standard3D); //######## Exmaple code begin ######## //Generate a sphere in order to map texture on it vtkSmartPointer sphere = vtkSmartPointer::New(); sphere->SetThetaResolution(12); sphere->SetPhiResolution(12); sphere->SetRadius(50.0); //just to make it huge sphere->SetCenter(50,0,0); //just to center the sphere in the screen //taken from VTK example: http://www.vtk.org/Wiki/VTK/Examples/Python/Visualization/SphereTexture vtkSmartPointer mapToSphere = vtkSmartPointer::New(); mapToSphere->SetInputConnection(sphere->GetOutputPort()); mapToSphere->PreventSeamOn(); //get the texture image from the helper's data storage mitk::Image::Pointer textureImage = static_cast< mitk::Image* > ( renderingHelper.GetDataStorage()->GetNode( mitk::NodePredicateDataType::New("Image"))->GetData() ); //Generate MITK surface mitk::Surface::Pointer surfaceToPutTextureOn = mitk::Surface::New(); surfaceToPutTextureOn->SetVtkPolyData(static_cast(mapToSphere->GetOutput())); //Generate a node mitk::DataNode::Pointer surfaceNode = mitk::DataNode::New(); surfaceNode->SetData( surfaceToPutTextureOn ); //Make a Property and add to the node mitk::SmartPointerProperty::Pointer textureProperty = mitk::SmartPointerProperty::New(textureImage); surfaceNode->SetProperty("Surface.Texture", textureProperty); //add to data storage renderingHelper.AddNodeToStorage(surfaceNode); //######## Exmaple code end ######## - renderingHelper.Render(); - //use this to generate a reference screenshot or save the file: bool generateReferenceScreenshot = false; if(generateReferenceScreenshot) { - renderingHelper.SaveAsPNG("/home/kilgus/Pictures/RenderingTestData/output.png"); + renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); } - //### Usage of vtkRegressionTestImage: - //vtkRegressionTestImage( vtkRenderWindow ) - //Set a vtkRenderWindow containing the desired scene. - //vtkRegressionTestImage automatically searches in argc and argv[] - //for a path a valid image with -V. If the test failed with the - //first image (foo.png) check if there are images of the form - //foo_N.png (where N=1,2,3...) and compare against them. - renderingHelper.PrepareRender(); - int retVal = vtkRegressionTestImage( renderingHelper.GetVtkRenderWindow() ); - - //retVal meanings: (see VTK/Rendering/vtkTesting.h) - //0 = test failed - //1 = test passed - //2 = test not run - //3 = something with vtkInteraction - MITK_TEST_CONDITION( retVal == 1, "VTK test result positive" ); + //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper + MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 50.0) == true, "CompareRenderWindowAgainstReference test result positive?" ); MITK_TEST_END(); }