diff --git a/CMakeExternals/MITKData.cmake b/CMakeExternals/MITKData.cmake index 78912eeac2..a01699470f 100644 --- a/CMakeExternals/MITKData.cmake +++ b/CMakeExternals/MITKData.cmake @@ -1,39 +1,39 @@ #----------------------------------------------------------------------------- # MITK Data #----------------------------------------------------------------------------- # Sanity checks if(DEFINED MITK_DATA_DIR AND NOT EXISTS ${MITK_DATA_DIR}) message(FATAL_ERROR "MITK_DATA_DIR variable is defined but corresponds to non-existing directory") endif() set(proj MITK-Data) set(proj_DEPENDENCIES) set(MITK-Data_DEPENDS ${proj}) if(BUILD_TESTING) - set(revision_tag 1a6c46e9) + set(revision_tag 55445f45) #if(${proj}_REVISION_TAG) # set(revision_tag ${${proj}_REVISION_TAG}) #endif() ExternalProject_Add(${proj} URL ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/MITK-Data_${revision_tag}.tar.gz UPDATE_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" DEPENDS ${proj_DEPENDENCIES} ) set(MITK_DATA_DIR ${ep_source_dir}/${proj}) else() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") endif(BUILD_TESTING) diff --git a/Core/Code/Rendering/mitkSurfaceVtkMapper3D.cpp b/Core/Code/Rendering/mitkSurfaceVtkMapper3D.cpp index 6205a1a825..5eb7fb4246 100644 --- a/Core/Code/Rendering/mitkSurfaceVtkMapper3D.cpp +++ b/Core/Code/Rendering/mitkSurfaceVtkMapper3D.cpp @@ -1,469 +1,503 @@ /*=================================================================== 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. ===================================================================*/ #include "mitkSurfaceVtkMapper3D.h" #include "mitkDataNode.h" #include "mitkProperties.h" #include "mitkColorProperty.h" #include "mitkLookupTableProperty.h" #include "mitkVtkRepresentationProperty.h" #include "mitkVtkInterpolationProperty.h" #include "mitkVtkScalarModeProperty.h" #include "mitkClippingProperty.h" +#include "mitkSmartPointerProperty.h" #include "mitkShaderProperty.h" #include "mitkShaderRepository.h" +#include +#include - +//VTK #include #include #include #include #include #include #include - +#include const mitk::Surface* mitk::SurfaceVtkMapper3D::GetInput() { - return static_cast ( GetData() ); + return static_cast ( GetData() ); } mitk::SurfaceVtkMapper3D::SurfaceVtkMapper3D() { - // m_Prop3D = vtkActor::New(); - m_GenerateNormals = false; + // m_Prop3D = vtkActor::New(); + m_GenerateNormals = false; } mitk::SurfaceVtkMapper3D::~SurfaceVtkMapper3D() { - // m_Prop3D->Delete(); + // m_Prop3D->Delete(); } void mitk::SurfaceVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer* renderer) { - LocalStorage *ls = m_LSH.GetLocalStorage(renderer); + LocalStorage *ls = m_LSH.GetLocalStorage(renderer); - bool visible = IsVisible(renderer); + bool visible = IsVisible(renderer); - if(visible==false) - { - ls->m_Actor->VisibilityOff(); - return; - } - - // - // set the input-object at time t for the mapper - // - mitk::Surface::Pointer input = const_cast< mitk::Surface* >( this->GetInput() ); - vtkPolyData * polydata = input->GetVtkPolyData( this->GetTimestep() ); - if(polydata == NULL) - { - ls->m_Actor->VisibilityOff(); - return; - } - - if ( m_GenerateNormals ) - { - ls->m_VtkPolyDataNormals->SetInput( polydata ); - ls->m_VtkPolyDataMapper->SetInput( ls->m_VtkPolyDataNormals->GetOutput() ); - } - else - { - ls->m_VtkPolyDataMapper->SetInput( polydata ); - } - - // - // apply properties read from the PropertyList - // - ApplyProperties(ls->m_Actor, renderer); - - if(visible) - ls->m_Actor->VisibilityOn(); + if(visible==false) + { + ls->m_Actor->VisibilityOff(); + return; + } + + // + // set the input-object at time t for the mapper + // + mitk::Surface::Pointer input = const_cast< mitk::Surface* >( this->GetInput() ); + vtkPolyData * polydata = input->GetVtkPolyData( this->GetTimestep() ); + if(polydata == NULL) + { + ls->m_Actor->VisibilityOff(); + return; + } + + if ( m_GenerateNormals ) + { + ls->m_VtkPolyDataNormals->SetInput( polydata ); + ls->m_VtkPolyDataMapper->SetInput( ls->m_VtkPolyDataNormals->GetOutput() ); + } + else + { + ls->m_VtkPolyDataMapper->SetInput( polydata ); + } + + // + // apply properties read from the PropertyList + // + ApplyProperties(ls->m_Actor, renderer); + + if(visible) + ls->m_Actor->VisibilityOn(); } void mitk::SurfaceVtkMapper3D::ResetMapper( BaseRenderer* renderer ) { - LocalStorage *ls = m_LSH.GetLocalStorage(renderer); - ls->m_Actor->VisibilityOff(); + LocalStorage *ls = m_LSH.GetLocalStorage(renderer); + ls->m_Actor->VisibilityOff(); } void mitk::SurfaceVtkMapper3D::ApplyMitkPropertiesToVtkProperty(mitk::DataNode *node, vtkProperty* property, mitk::BaseRenderer* renderer) { - // Backface culling - { - mitk::BoolProperty::Pointer p; - node->GetProperty(p, "Backface Culling", renderer); - bool useCulling = false; - if(p.IsNotNull()) - useCulling = p->GetValue(); - property->SetBackfaceCulling(useCulling); - } - - // Colors - { - double ambient [3] = { 0.5,0.5,0.0 }; - double diffuse [3] = { 0.5,0.5,0.0 }; - double specular[3] = { 1.0,1.0,1.0 }; - - float coeff_ambient = 0.5f; - float coeff_diffuse = 0.5f; - float coeff_specular= 0.5f; - float power_specular=10.0f; - - // Color + // Backface culling { - mitk::ColorProperty::Pointer p; - node->GetProperty(p, "color", renderer); - if(p.IsNotNull()) - { - mitk::Color c = p->GetColor(); - ambient[0]=c.GetRed(); ambient[1]=c.GetGreen(); ambient[2]=c.GetBlue(); - diffuse[0]=c.GetRed(); diffuse[1]=c.GetGreen(); diffuse[2]=c.GetBlue(); - // Setting specular color to the same, make physically no real sense, however vtk rendering slows down, if these colors are different. - specular[0]=c.GetRed(); specular[1]=c.GetGreen(); specular[2]=c.GetBlue(); - } + mitk::BoolProperty::Pointer p; + node->GetProperty(p, "Backface Culling", renderer); + bool useCulling = false; + if(p.IsNotNull()) + useCulling = p->GetValue(); + property->SetBackfaceCulling(useCulling); } - // Ambient + // Colors { - mitk::ColorProperty::Pointer p; - node->GetProperty(p, "material.ambientColor", renderer); - if(p.IsNotNull()) - { - mitk::Color c = p->GetColor(); - ambient[0]=c.GetRed(); ambient[1]=c.GetGreen(); ambient[2]=c.GetBlue(); - } + double ambient [3] = { 0.5,0.5,0.0 }; + double diffuse [3] = { 0.5,0.5,0.0 }; + double specular[3] = { 1.0,1.0,1.0 }; + + float coeff_ambient = 0.5f; + float coeff_diffuse = 0.5f; + float coeff_specular= 0.5f; + float power_specular=10.0f; + + // Color + { + mitk::ColorProperty::Pointer p; + node->GetProperty(p, "color", renderer); + if(p.IsNotNull()) + { + mitk::Color c = p->GetColor(); + ambient[0]=c.GetRed(); ambient[1]=c.GetGreen(); ambient[2]=c.GetBlue(); + diffuse[0]=c.GetRed(); diffuse[1]=c.GetGreen(); diffuse[2]=c.GetBlue(); + // Setting specular color to the same, make physically no real sense, however vtk rendering slows down, if these colors are different. + specular[0]=c.GetRed(); specular[1]=c.GetGreen(); specular[2]=c.GetBlue(); + } + } + + // Ambient + { + mitk::ColorProperty::Pointer p; + node->GetProperty(p, "material.ambientColor", renderer); + if(p.IsNotNull()) + { + mitk::Color c = p->GetColor(); + ambient[0]=c.GetRed(); ambient[1]=c.GetGreen(); ambient[2]=c.GetBlue(); + } + } + + // Diffuse + { + mitk::ColorProperty::Pointer p; + node->GetProperty(p, "material.diffuseColor", renderer); + if(p.IsNotNull()) + { + mitk::Color c = p->GetColor(); + diffuse[0]=c.GetRed(); diffuse[1]=c.GetGreen(); diffuse[2]=c.GetBlue(); + } + } + + // Specular + { + mitk::ColorProperty::Pointer p; + node->GetProperty(p, "material.specularColor", renderer); + if(p.IsNotNull()) + { + mitk::Color c = p->GetColor(); + specular[0]=c.GetRed(); specular[1]=c.GetGreen(); specular[2]=c.GetBlue(); + } + } + + // Ambient coeff + { + node->GetFloatProperty("material.ambientCoefficient", coeff_ambient, renderer); + } + + // Diffuse coeff + { + node->GetFloatProperty("material.diffuseCoefficient", coeff_diffuse, renderer); + } + + // Specular coeff + { + node->GetFloatProperty("material.specularCoefficient", coeff_specular, renderer); + } + + // Specular power + { + node->GetFloatProperty("material.specularPower", power_specular, renderer); + } + + property->SetAmbient( coeff_ambient ); + property->SetDiffuse( coeff_diffuse ); + property->SetSpecular( coeff_specular ); + property->SetSpecularPower( power_specular ); + + property->SetAmbientColor( ambient ); + property->SetDiffuseColor( diffuse ); + property->SetSpecularColor( specular ); } - // Diffuse + // Render mode { - mitk::ColorProperty::Pointer p; - node->GetProperty(p, "material.diffuseColor", renderer); - if(p.IsNotNull()) - { - mitk::Color c = p->GetColor(); - diffuse[0]=c.GetRed(); diffuse[1]=c.GetGreen(); diffuse[2]=c.GetBlue(); - } + // Opacity + { + float opacity = 1.0f; + if( node->GetOpacity(opacity,renderer) ) + property->SetOpacity( opacity ); + } + + // Wireframe line width + { + float lineWidth = 1; + node->GetFloatProperty("material.wireframeLineWidth", lineWidth, renderer); + property->SetLineWidth( lineWidth ); + } + + // Representation + { + mitk::VtkRepresentationProperty::Pointer p; + node->GetProperty(p, "material.representation", renderer); + if(p.IsNotNull()) + property->SetRepresentation( p->GetVtkRepresentation() ); + } + + // Interpolation + { + mitk::VtkInterpolationProperty::Pointer p; + node->GetProperty(p, "material.interpolation", renderer); + if(p.IsNotNull()) + property->SetInterpolation( p->GetVtkInterpolation() ); + } } +} + + - // Specular +void mitk::SurfaceVtkMapper3D::ApplyProperties(vtkActor* /*actor*/, mitk::BaseRenderer* renderer) +{ + LocalStorage *ls = m_LSH.GetLocalStorage(renderer); + + // Applying shading properties { - mitk::ColorProperty::Pointer p; - node->GetProperty(p, "material.specularColor", renderer); - if(p.IsNotNull()) - { - mitk::Color c = p->GetColor(); - specular[0]=c.GetRed(); specular[1]=c.GetGreen(); specular[2]=c.GetBlue(); - } + Superclass::ApplyProperties( ls->m_Actor, renderer ) ; + // VTK Properties + ApplyMitkPropertiesToVtkProperty( this->GetDataNode(), ls->m_Actor->GetProperty(), renderer ); + // Shaders + mitk::ShaderRepository::GetGlobalShaderRepository()->ApplyProperties(this->GetDataNode(),ls->m_Actor,renderer,ls->m_ShaderTimestampUpdate); } - // Ambient coeff + mitk::LookupTableProperty::Pointer lookupTableProp; + this->GetDataNode()->GetProperty(lookupTableProp, "LookupTable", renderer); + if (lookupTableProp.IsNotNull() ) { - node->GetFloatProperty("material.ambientCoefficient", coeff_ambient, renderer); + ls->m_VtkPolyDataMapper->SetLookupTable(lookupTableProp->GetLookupTable()->GetVtkLookupTable()); } - // Diffuse coeff + mitk::LevelWindow levelWindow; + if(this->GetDataNode()->GetLevelWindow(levelWindow, renderer, "levelWindow")) { - node->GetFloatProperty("material.diffuseCoefficient", coeff_diffuse, renderer); + ls->m_VtkPolyDataMapper->SetScalarRange(levelWindow.GetLowerWindowBound(),levelWindow.GetUpperWindowBound()); } + else + if(this->GetDataNode()->GetLevelWindow(levelWindow, renderer)) + { + ls->m_VtkPolyDataMapper->SetScalarRange(levelWindow.GetLowerWindowBound(),levelWindow.GetUpperWindowBound()); + } + + bool scalarVisibility = false; + this->GetDataNode()->GetBoolProperty("scalar visibility", scalarVisibility); + ls->m_VtkPolyDataMapper->SetScalarVisibility( (scalarVisibility ? 1 : 0) ); - // Specular coeff + if(scalarVisibility) { - node->GetFloatProperty("material.specularCoefficient", coeff_specular, renderer); + mitk::VtkScalarModeProperty* scalarMode; + if(this->GetDataNode()->GetProperty(scalarMode, "scalar mode", renderer)) + { + ls->m_VtkPolyDataMapper->SetScalarMode(scalarMode->GetVtkScalarMode()); + } + else + ls->m_VtkPolyDataMapper->SetScalarModeToDefault(); + + bool colorMode = false; + this->GetDataNode()->GetBoolProperty("color mode", colorMode); + ls->m_VtkPolyDataMapper->SetColorMode( (colorMode ? 1 : 0) ); + + float scalarsMin = 0; + if (dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMinimum")) != NULL) + scalarsMin = dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMinimum"))->GetValue(); + + float scalarsMax = 1.0; + if (dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMaximum")) != NULL) + scalarsMax = dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMaximum"))->GetValue(); + + ls->m_VtkPolyDataMapper->SetScalarRange(scalarsMin,scalarsMax); } - // Specular power + mitk::SmartPointerProperty::Pointer imagetextureProp; + imagetextureProp = dynamic_cast< mitk::SmartPointerProperty * >( + GetDataNode()->GetProperty("Surface.Texture", renderer)); + if(imagetextureProp.IsNotNull()) { - node->GetFloatProperty("material.specularPower", power_specular, renderer); + mitk::Image* miktTexture = dynamic_cast< mitk::Image* >( imagetextureProp->GetSmartPointer().GetPointer() ); + vtkSmartPointer vtkTxture = vtkSmartPointer::New(); + //Either select the first slice of a volume + if(miktTexture->GetDimension(2) > 1) + { + MITK_WARN << "3D Textures are not supported by VTK and MITK. The first slice of the volume will be used instead!"; + mitk::ImageSliceSelector::Pointer sliceselector = mitk::ImageSliceSelector::New(); + sliceselector->SetSliceNr(0); + sliceselector->SetChannelNr(0); + sliceselector->SetTimeNr(0); + sliceselector->SetInput(miktTexture); + sliceselector->Update(); + vtkTxture->SetInput(sliceselector->GetOutput()->GetVtkImageData()); + } + else //or just use the 2D image + { + vtkTxture->SetInput(miktTexture->GetVtkImageData()); + } + //pass the texture to the actor + ls->m_Actor->SetTexture(vtkTxture); + if(ls->m_VtkPolyDataMapper->GetInput()->GetPointData()->GetTCoords() == NULL) + { + MITK_ERROR << "Surface.Texture property was set, but there are no texture coordinates. Please provide texture coordinates for the vtkPolyData via vtkPolyData->GetPointData()->SetTCoords()."; + } } - property->SetAmbient( coeff_ambient ); - property->SetDiffuse( coeff_diffuse ); - property->SetSpecular( coeff_specular ); - property->SetSpecularPower( power_specular ); + // deprecated settings + bool deprecatedUseCellData = false; + this->GetDataNode()->GetBoolProperty("deprecated useCellDataForColouring", deprecatedUseCellData); - property->SetAmbientColor( ambient ); - property->SetDiffuseColor( diffuse ); - property->SetSpecularColor( specular ); - } + bool deprecatedUsePointData = false; + this->GetDataNode()->GetBoolProperty("deprecated usePointDataForColouring", deprecatedUsePointData); - // Render mode - { - // Opacity + if (deprecatedUseCellData) { - float opacity = 1.0f; - if( node->GetOpacity(opacity,renderer) ) - property->SetOpacity( opacity ); + ls->m_VtkPolyDataMapper->SetColorModeToDefault(); + ls->m_VtkPolyDataMapper->SetScalarRange(0,255); + ls->m_VtkPolyDataMapper->ScalarVisibilityOn(); + ls->m_VtkPolyDataMapper->SetScalarModeToUseCellData(); + ls->m_Actor->GetProperty()->SetSpecular (1); + ls->m_Actor->GetProperty()->SetSpecularPower (50); + ls->m_Actor->GetProperty()->SetInterpolationToPhong(); } - - // Wireframe line width + else if (deprecatedUsePointData) { - float lineWidth = 1; - node->GetFloatProperty("material.wireframeLineWidth", lineWidth, renderer); - property->SetLineWidth( lineWidth ); + float scalarsMin = 0; + if (dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMinimum")) != NULL) + scalarsMin = dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMinimum"))->GetValue(); + + float scalarsMax = 0.1; + if (dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMaximum")) != NULL) + scalarsMax = dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMaximum"))->GetValue(); + + ls->m_VtkPolyDataMapper->SetScalarRange(scalarsMin,scalarsMax); + ls->m_VtkPolyDataMapper->SetColorModeToMapScalars(); + ls->m_VtkPolyDataMapper->ScalarVisibilityOn(); + ls->m_Actor->GetProperty()->SetSpecular (1); + ls->m_Actor->GetProperty()->SetSpecularPower (50); + ls->m_Actor->GetProperty()->SetInterpolationToPhong(); } - // Representation + int deprecatedScalarMode = VTK_COLOR_MODE_DEFAULT; + if(this->GetDataNode()->GetIntProperty("deprecated scalar mode", deprecatedScalarMode, renderer)) { - mitk::VtkRepresentationProperty::Pointer p; - node->GetProperty(p, "material.representation", renderer); - if(p.IsNotNull()) - property->SetRepresentation( p->GetVtkRepresentation() ); + ls->m_VtkPolyDataMapper->SetScalarMode(deprecatedScalarMode); + ls->m_VtkPolyDataMapper->ScalarVisibilityOn(); + ls->m_Actor->GetProperty()->SetSpecular (1); + ls->m_Actor->GetProperty()->SetSpecularPower (50); + //m_Actor->GetProperty()->SetInterpolationToPhong(); } - // Interpolation - { - mitk::VtkInterpolationProperty::Pointer p; - node->GetProperty(p, "material.interpolation", renderer); - if(p.IsNotNull()) - property->SetInterpolation( p->GetVtkInterpolation() ); - } - } -} + // Check whether one or more ClippingProperty objects have been defined for + // this node. Check both renderer specific and global property lists, since + // properties in both should be considered. + const PropertyList::PropertyMap *rendererProperties = this->GetDataNode()->GetPropertyList( renderer )->GetMap(); + const PropertyList::PropertyMap *globalProperties = this->GetDataNode()->GetPropertyList( NULL )->GetMap(); + // Add clipping planes (if any) + ls->m_ClippingPlaneCollection->RemoveAllItems(); -void mitk::SurfaceVtkMapper3D::ApplyProperties(vtkActor* /*actor*/, mitk::BaseRenderer* renderer) -{ - LocalStorage *ls = m_LSH.GetLocalStorage(renderer); + PropertyList::PropertyMap::const_iterator it; + for ( it = rendererProperties->begin(); it != rendererProperties->end(); ++it ) + { + this->CheckForClippingProperty( renderer,(*it).second.GetPointer() ); + } - // Applying shading properties - { - Superclass::ApplyProperties( ls->m_Actor, renderer ) ; - // VTK Properties - ApplyMitkPropertiesToVtkProperty( this->GetDataNode(), ls->m_Actor->GetProperty(), renderer ); - // Shaders - mitk::ShaderRepository::GetGlobalShaderRepository()->ApplyProperties(this->GetDataNode(),ls->m_Actor,renderer,ls->m_ShaderTimestampUpdate); - } - - mitk::LookupTableProperty::Pointer lookupTableProp; - this->GetDataNode()->GetProperty(lookupTableProp, "LookupTable", renderer); - if (lookupTableProp.IsNotNull() ) - { - ls->m_VtkPolyDataMapper->SetLookupTable(lookupTableProp->GetLookupTable()->GetVtkLookupTable()); - } - - mitk::LevelWindow levelWindow; - if(this->GetDataNode()->GetLevelWindow(levelWindow, renderer, "levelWindow")) - { - ls->m_VtkPolyDataMapper->SetScalarRange(levelWindow.GetLowerWindowBound(),levelWindow.GetUpperWindowBound()); - } - else - if(this->GetDataNode()->GetLevelWindow(levelWindow, renderer)) - { - ls->m_VtkPolyDataMapper->SetScalarRange(levelWindow.GetLowerWindowBound(),levelWindow.GetUpperWindowBound()); - } - - bool scalarVisibility = false; - this->GetDataNode()->GetBoolProperty("scalar visibility", scalarVisibility); - ls->m_VtkPolyDataMapper->SetScalarVisibility( (scalarVisibility ? 1 : 0) ); - - if(scalarVisibility) - { - mitk::VtkScalarModeProperty* scalarMode; - if(this->GetDataNode()->GetProperty(scalarMode, "scalar mode", renderer)) + for ( it = globalProperties->begin(); it != globalProperties->end(); ++it ) + { + this->CheckForClippingProperty( renderer,(*it).second.GetPointer() ); + } + + if ( ls->m_ClippingPlaneCollection->GetNumberOfItems() > 0 ) { - ls->m_VtkPolyDataMapper->SetScalarMode(scalarMode->GetVtkScalarMode()); + ls->m_VtkPolyDataMapper->SetClippingPlanes( ls->m_ClippingPlaneCollection ); } else - ls->m_VtkPolyDataMapper->SetScalarModeToDefault(); - - bool colorMode = false; - this->GetDataNode()->GetBoolProperty("color mode", colorMode); - ls->m_VtkPolyDataMapper->SetColorMode( (colorMode ? 1 : 0) ); - - float scalarsMin = 0; - if (dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMinimum")) != NULL) - scalarsMin = dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMinimum"))->GetValue(); - - float scalarsMax = 1.0; - if (dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMaximum")) != NULL) - scalarsMax = dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMaximum"))->GetValue(); - - ls->m_VtkPolyDataMapper->SetScalarRange(scalarsMin,scalarsMax); - } - - // deprecated settings - bool deprecatedUseCellData = false; - this->GetDataNode()->GetBoolProperty("deprecated useCellDataForColouring", deprecatedUseCellData); - - bool deprecatedUsePointData = false; - this->GetDataNode()->GetBoolProperty("deprecated usePointDataForColouring", deprecatedUsePointData); - - if (deprecatedUseCellData) - { - ls->m_VtkPolyDataMapper->SetColorModeToDefault(); - ls->m_VtkPolyDataMapper->SetScalarRange(0,255); - ls->m_VtkPolyDataMapper->ScalarVisibilityOn(); - ls->m_VtkPolyDataMapper->SetScalarModeToUseCellData(); - ls->m_Actor->GetProperty()->SetSpecular (1); - ls->m_Actor->GetProperty()->SetSpecularPower (50); - ls->m_Actor->GetProperty()->SetInterpolationToPhong(); - } - else if (deprecatedUsePointData) - { - float scalarsMin = 0; - if (dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMinimum")) != NULL) - scalarsMin = dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMinimum"))->GetValue(); - - float scalarsMax = 0.1; - if (dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMaximum")) != NULL) - scalarsMax = dynamic_cast(this->GetDataNode()->GetProperty("ScalarsRangeMaximum"))->GetValue(); - - ls->m_VtkPolyDataMapper->SetScalarRange(scalarsMin,scalarsMax); - ls->m_VtkPolyDataMapper->SetColorModeToMapScalars(); - ls->m_VtkPolyDataMapper->ScalarVisibilityOn(); - ls->m_Actor->GetProperty()->SetSpecular (1); - ls->m_Actor->GetProperty()->SetSpecularPower (50); - ls->m_Actor->GetProperty()->SetInterpolationToPhong(); - } - - int deprecatedScalarMode = VTK_COLOR_MODE_DEFAULT; - if(this->GetDataNode()->GetIntProperty("deprecated scalar mode", deprecatedScalarMode, renderer)) - { - ls->m_VtkPolyDataMapper->SetScalarMode(deprecatedScalarMode); - ls->m_VtkPolyDataMapper->ScalarVisibilityOn(); - ls->m_Actor->GetProperty()->SetSpecular (1); - ls->m_Actor->GetProperty()->SetSpecularPower (50); - //m_Actor->GetProperty()->SetInterpolationToPhong(); - } - - - // Check whether one or more ClippingProperty objects have been defined for - // this node. Check both renderer specific and global property lists, since - // properties in both should be considered. - const PropertyList::PropertyMap *rendererProperties = this->GetDataNode()->GetPropertyList( renderer )->GetMap(); - const PropertyList::PropertyMap *globalProperties = this->GetDataNode()->GetPropertyList( NULL )->GetMap(); - - // Add clipping planes (if any) - ls->m_ClippingPlaneCollection->RemoveAllItems(); - - PropertyList::PropertyMap::const_iterator it; - for ( it = rendererProperties->begin(); it != rendererProperties->end(); ++it ) - { - this->CheckForClippingProperty( renderer,(*it).second.GetPointer() ); - } - - for ( it = globalProperties->begin(); it != globalProperties->end(); ++it ) - { - this->CheckForClippingProperty( renderer,(*it).second.GetPointer() ); - } - - if ( ls->m_ClippingPlaneCollection->GetNumberOfItems() > 0 ) - { - ls->m_VtkPolyDataMapper->SetClippingPlanes( ls->m_ClippingPlaneCollection ); - } - else - { - ls->m_VtkPolyDataMapper->RemoveAllClippingPlanes(); - } + { + ls->m_VtkPolyDataMapper->RemoveAllClippingPlanes(); + } } vtkProp *mitk::SurfaceVtkMapper3D::GetVtkProp(mitk::BaseRenderer *renderer) { - LocalStorage *ls = m_LSH.GetLocalStorage(renderer); - return ls->m_Actor; + LocalStorage *ls = m_LSH.GetLocalStorage(renderer); + return ls->m_Actor; } void mitk::SurfaceVtkMapper3D::CheckForClippingProperty( mitk::BaseRenderer* renderer, mitk::BaseProperty *property ) { - LocalStorage *ls = m_LSH.GetLocalStorage(renderer); -// m_Prop3D = ls->m_Actor; + LocalStorage *ls = m_LSH.GetLocalStorage(renderer); + // m_Prop3D = ls->m_Actor; - ClippingProperty *clippingProperty = dynamic_cast< ClippingProperty * >( property ); + ClippingProperty *clippingProperty = dynamic_cast< ClippingProperty * >( property ); - if ( (clippingProperty != NULL) - && (clippingProperty->GetClippingEnabled()) ) - { - const Point3D &origin = clippingProperty->GetOrigin(); - const Vector3D &normal = clippingProperty->GetNormal(); + if ( (clippingProperty != NULL) + && (clippingProperty->GetClippingEnabled()) ) + { + const Point3D &origin = clippingProperty->GetOrigin(); + const Vector3D &normal = clippingProperty->GetNormal(); - vtkPlane *clippingPlane = vtkPlane::New(); - clippingPlane->SetOrigin( origin[0], origin[1], origin[2] ); - clippingPlane->SetNormal( normal[0], normal[1], normal[2] ); + vtkPlane *clippingPlane = vtkPlane::New(); + clippingPlane->SetOrigin( origin[0], origin[1], origin[2] ); + clippingPlane->SetNormal( normal[0], normal[1], normal[2] ); - ls->m_ClippingPlaneCollection->AddItem( clippingPlane ); + ls->m_ClippingPlaneCollection->AddItem( clippingPlane ); - clippingPlane->UnRegister( NULL ); - } + clippingPlane->UnRegister( NULL ); + } } void mitk::SurfaceVtkMapper3D::SetDefaultPropertiesForVtkProperty(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) { - // Shading - { - node->AddProperty( "material.wireframeLineWidth", mitk::FloatProperty::New(1.0f) , renderer, overwrite ); - - node->AddProperty( "material.ambientCoefficient" , mitk::FloatProperty::New(0.05f) , renderer, overwrite ); - node->AddProperty( "material.diffuseCoefficient" , mitk::FloatProperty::New(0.9f) , renderer, overwrite ); - node->AddProperty( "material.specularCoefficient", mitk::FloatProperty::New(1.0f) , renderer, overwrite ); - node->AddProperty( "material.specularPower" , mitk::FloatProperty::New(16.0f) , renderer, overwrite ); - - //node->AddProperty( "material.ambientColor" , mitk::ColorProperty::New(1.0f,1.0f,1.0f), renderer, overwrite ); - //node->AddProperty( "material.diffuseColor" , mitk::ColorProperty::New(1.0f,1.0f,1.0f), renderer, overwrite ); - //node->AddProperty( "material.specularColor" , mitk::ColorProperty::New(1.0f,1.0f,1.0f), renderer, overwrite ); - - node->AddProperty( "material.representation" , mitk::VtkRepresentationProperty::New() , renderer, overwrite ); - node->AddProperty( "material.interpolation" , mitk::VtkInterpolationProperty::New() , renderer, overwrite ); - } - - // Shaders - { - mitk::ShaderRepository::GetGlobalShaderRepository()->AddDefaultProperties(node,renderer,overwrite); - } + // Shading + { + node->AddProperty( "material.wireframeLineWidth", mitk::FloatProperty::New(1.0f) , renderer, overwrite ); + + node->AddProperty( "material.ambientCoefficient" , mitk::FloatProperty::New(0.05f) , renderer, overwrite ); + node->AddProperty( "material.diffuseCoefficient" , mitk::FloatProperty::New(0.9f) , renderer, overwrite ); + node->AddProperty( "material.specularCoefficient", mitk::FloatProperty::New(1.0f) , renderer, overwrite ); + node->AddProperty( "material.specularPower" , mitk::FloatProperty::New(16.0f) , renderer, overwrite ); + + //node->AddProperty( "material.ambientColor" , mitk::ColorProperty::New(1.0f,1.0f,1.0f), renderer, overwrite ); + //node->AddProperty( "material.diffuseColor" , mitk::ColorProperty::New(1.0f,1.0f,1.0f), renderer, overwrite ); + //node->AddProperty( "material.specularColor" , mitk::ColorProperty::New(1.0f,1.0f,1.0f), renderer, overwrite ); + + node->AddProperty( "material.representation" , mitk::VtkRepresentationProperty::New() , renderer, overwrite ); + node->AddProperty( "material.interpolation" , mitk::VtkInterpolationProperty::New() , renderer, overwrite ); + } + + // Shaders + { + mitk::ShaderRepository::GetGlobalShaderRepository()->AddDefaultProperties(node,renderer,overwrite); + } } void mitk::SurfaceVtkMapper3D::SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) { - node->AddProperty( "color", mitk::ColorProperty::New(1.0f,1.0f,1.0f), renderer, overwrite ); - node->AddProperty( "opacity", mitk::FloatProperty::New(1.0), renderer, overwrite ); - - mitk::SurfaceVtkMapper3D::SetDefaultPropertiesForVtkProperty(node,renderer,overwrite); // Shading - - node->AddProperty( "scalar visibility", mitk::BoolProperty::New(false), renderer, overwrite ); - node->AddProperty( "color mode", mitk::BoolProperty::New(false), renderer, overwrite ); - node->AddProperty( "scalar mode", mitk::VtkScalarModeProperty::New(), renderer, overwrite ); - mitk::Surface::Pointer surface = dynamic_cast(node->GetData()); - if(surface.IsNotNull()) - { - if((surface->GetVtkPolyData() != 0) && (surface->GetVtkPolyData()->GetPointData() != NULL) && (surface->GetVtkPolyData()->GetPointData()->GetScalars() != 0)) + node->AddProperty( "color", mitk::ColorProperty::New(1.0f,1.0f,1.0f), renderer, overwrite ); + node->AddProperty( "opacity", mitk::FloatProperty::New(1.0), renderer, overwrite ); + + mitk::SurfaceVtkMapper3D::SetDefaultPropertiesForVtkProperty(node,renderer,overwrite); // Shading + + node->AddProperty( "scalar visibility", mitk::BoolProperty::New(false), renderer, overwrite ); + node->AddProperty( "color mode", mitk::BoolProperty::New(false), renderer, overwrite ); + node->AddProperty( "scalar mode", mitk::VtkScalarModeProperty::New(), renderer, overwrite ); + mitk::Surface::Pointer surface = dynamic_cast(node->GetData()); + if(surface.IsNotNull()) { - node->AddProperty( "scalar visibility", mitk::BoolProperty::New(true), renderer, overwrite ); - node->AddProperty( "color mode", mitk::BoolProperty::New(true), renderer, overwrite ); + if((surface->GetVtkPolyData() != 0) && (surface->GetVtkPolyData()->GetPointData() != NULL) && (surface->GetVtkPolyData()->GetPointData()->GetScalars() != 0)) + { + node->AddProperty( "scalar visibility", mitk::BoolProperty::New(true), renderer, overwrite ); + node->AddProperty( "color mode", mitk::BoolProperty::New(true), renderer, overwrite ); + } } - } - // Backface culling - node->AddProperty( "Backface Culling", mitk::BoolProperty::New(false), renderer, overwrite ); + // Backface culling + node->AddProperty( "Backface Culling", mitk::BoolProperty::New(false), renderer, overwrite ); - Superclass::SetDefaultProperties(node, renderer, overwrite); + Superclass::SetDefaultProperties(node, renderer, overwrite); } void mitk::SurfaceVtkMapper3D::SetImmediateModeRenderingOn(int /*on*/) { -/* + /* if (m_VtkPolyDataMapper != NULL) m_VtkPolyDataMapper->SetImmediateModeRendering(on); */ } diff --git a/Core/Code/Testing/CMakeLists.txt b/Core/Code/Testing/CMakeLists.txt index 68e4fef1dd..3ea5d76a6c 100644 --- a/Core/Code/Testing/CMakeLists.txt +++ b/Core/Code/Testing/CMakeLists.txt @@ -1,81 +1,94 @@ MITK_CREATE_MODULE_TESTS(LABELS MITK-Core) # MITK_INSTALL_TARGETS(EXECUTABLES MitkTestDriver) mitkAddCustomModuleTest(mitkDICOMLocaleTest_spacingOk_CT mitkDICOMLocaleTest ${MITK_DATA_DIR}/spacing-ok-ct.dcm) mitkAddCustomModuleTest(mitkDICOMLocaleTest_spacingOk_MR mitkDICOMLocaleTest ${MITK_DATA_DIR}/spacing-ok-mr.dcm) mitkAddCustomModuleTest(mitkDICOMLocaleTest_spacingOk_SC mitkDICOMLocaleTest ${MITK_DATA_DIR}/spacing-ok-sc.dcm) mitkAddCustomModuleTest(mitkEventMapperTest_Test1And2 mitkEventMapperTest ${MITK_DATA_DIR}/TestStateMachine1.xml ${MITK_DATA_DIR}/TestStateMachine2.xml) #mitkAddCustomModuleTest(mitkNodeDependentPointSetInteractorTest mitkNodeDependentPointSetInteractorTest ${MITK_DATA_DIR}/Pic3D.pic.gz ${MITK_DATA_DIR}/BallBinary30x30x30.pic.gz) mitkAddCustomModuleTest(mitkNodeDependentPointSetInteractorTest mitkNodeDependentPointSetInteractorTest ${MITK_DATA_DIR}/Pic3D.nrrd ${MITK_DATA_DIR}/BallBinary30x30x30.nrrd) mitkAddCustomModuleTest(mitkDataStorageTest_US4DCyl mitkDataStorageTest ${MITK_DATA_DIR}/US4DCyl.nrrd) mitkAddCustomModuleTest(mitkStateMachineFactoryTest_TestStateMachine1_2 mitkStateMachineFactoryTest ${MITK_DATA_DIR}/TestStateMachine1.xml ${MITK_DATA_DIR}/TestStateMachine2.xml) mitkAddCustomModuleTest(mitkDicomSeriesReaderTest_CTImage mitkDicomSeriesReaderTest ${MITK_DATA_DIR}/TinyCTAbdomen) mitkAddCustomModuleTest(mitkPointSetReaderTest mitkPointSetReaderTest ${MITK_DATA_DIR}/PointSetReaderTestData.mps) mitkAddCustomModuleTest(mitkImageTest_4DImageData mitkImageTest ${MITK_DATA_DIR}/US4DCyl.nrrd) mitkAddCustomModuleTest(mitkImageTest_2D+tImageData mitkImageTest ${MITK_DATA_DIR}/Pic2DplusT.nrrd) mitkAddCustomModuleTest(mitkImageTest_3DImageData mitkImageTest ${MITK_DATA_DIR}/Pic3D.nrrd) mitkAddCustomModuleTest(mitkImageTest_brainImage mitkImageTest ${MITK_DATA_DIR}/brain.mhd) #mitkAddCustomModuleTest(mitkImageTest_color2DImage mitkImageTest ${MITK_DATA_DIR}/NrrdWritingTestImage.jpg) mitkAddCustomModuleTest(mitkIOUtilTest mitkIOUtilTest #test for a randomly chosen Pic3D swivelled slice ${MITK_DATA_DIR}/Pic3D.nrrd ${MITK_DATA_DIR}/pointSet.mps ${MITK_DATA_DIR}/binary.stl ) if(WIN32 OR APPLE OR MITK_ENABLE_GUI_TESTING) ### since the rendering test's do not run in ubuntu, yet, we build them only for other systems or if the user explicitly sets the variable MITK_ENABLE_GUI_TESTING mitkAddCustomModuleTest(mitkImageVtkMapper2D_rgbaImage640x480 mitkImageVtkMapper2DTest ${MITK_DATA_DIR}/RenderingTestData/rgbaImage.png #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/rgbaImage640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3d640x480 mitkImageVtkMapper2DTest #test for standard Pic3D axial slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3d640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dColorBlue640x480 mitkImageVtkMapper2DColorTest #test for color property (=blue) Pic3D sagittal slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dColorBlue640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dLevelWindow640x480 mitkImageVtkMapper2DLevelWindowTest #test for levelwindow property (=blood) #Pic3D sagittal slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dLevelWindowBlood640x480REF.png #corresponding reference #screenshot ) #mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dOpacity640x480 mitkImageVtkMapper2DOpacityTest #test for opacity (=0.5) Pic3D coronal slice # ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage # -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dOpacity640x480REF.png #corresponding reference screenshot #) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dSwivel640x480 mitkImageVtkMapper2DSwivelTest #test for a randomly chosen Pic3D swivelled slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dSwivel640x480REF.png #corresponding reference screenshot ) +mitkAddCustomModuleTest(mitkSurfaceVtkMapper3DTest_TextureProperty mitkSurfaceVtkMapper3DTest + ${MITK_DATA_DIR}/ToF-Data/Kinect_LiverPhantom.vtp + ${MITK_DATA_DIR}/ToF-Data/Kinect_LiverPhantom_RGBImage.nrrd + -V + ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/texturedLiver640x480REF.png #corresponding reference screenshot +) + +mitkAddCustomModuleTest(mitkSurfaceVtkMapper3DTexturedSphereTest_Football mitkSurfaceVtkMapper3DTexturedSphereTest + ${MITK_DATA_DIR}/RenderingTestData/texture.jpg #input texture + -V + ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/texturedSphere640x480REF.png #corresponding reference screenshot +) + SET_PROPERTY(TEST mitkImageVtkMapper2D_rgbaImage640x480 mitkImageVtkMapper2D_pic3d640x480 mitkImageVtkMapper2D_pic3dColorBlue640x480 mitkImageVtkMapper2D_pic3dLevelWindow640x480 mitkImageVtkMapper2D_pic3dSwivel640x480 #mitkImageVtkMapper2D_pic3dOpacity640x480 PROPERTY RUN_SERIAL TRUE) endif() # see bug 9882 if(NOT APPLE) add_test(mitkPointSetLocaleTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkPointSetLocaleTest ${MITK_DATA_DIR}/pointSet.mps) set_property(TEST mitkPointSetLocaleTest PROPERTY LABELS MITK-Core) endif() add_test(mitkImageWriterTest_nrrdImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageWriterTest ${MITK_DATA_DIR}/NrrdWritingTestImage.jpg) add_test(mitkImageWriterTest_2DPNGImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageWriterTest ${MITK_DATA_DIR}/Png2D-bw.png) add_test(mitkImageWriterTest_rgbPNGImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageWriterTest ${MITK_DATA_DIR}/RenderingTestData/rgbImage.png) add_test(mitkImageWriterTest_rgbaPNGImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageWriterTest ${MITK_DATA_DIR}/RenderingTestData/rgbaImage.png) set_property(TEST mitkImageWriterTest_nrrdImage PROPERTY LABELS MITK-Core) set_property(TEST mitkImageWriterTest_2DPNGImage PROPERTY LABELS MITK-Core) set_property(TEST mitkImageWriterTest_rgbPNGImage PROPERTY LABELS MITK-Core) set_property(TEST mitkImageWriterTest_rgbaPNGImage PROPERTY LABELS MITK-Core) add_subdirectory(DICOMTesting) diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index 14f1662f30..3efce83274 100644 --- a/Core/Code/Testing/files.cmake +++ b/Core/Code/Testing/files.cmake @@ -1,120 +1,122 @@ # tests with no extra command line parameter set(MODULE_TESTS mitkAccessByItkTest.cpp mitkCoreObjectFactoryTest.cpp mitkMaterialTest.cpp mitkActionTest.cpp mitkEnumerationPropertyTest.cpp mitkEventTest.cpp mitkFocusManagerTest.cpp mitkGenericPropertyTest.cpp mitkGeometry3DTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkGlobalInteractionTest.cpp mitkImageDataItemTest.cpp #mitkImageMapper2DTest.cpp mitkImageGeneratorTest.cpp mitkBaseDataTest.cpp #mitkImageToItkTest.cpp mitkInstantiateAccessFunctionTest.cpp mitkInteractorTest.cpp mitkITKThreadingTest.cpp # mitkLevelWindowManagerTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp #mitkPipelineSmartPointerCorrectnessTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetTest.cpp mitkPointSetWriterTest.cpp mitkPointSetReaderTest.cpp mitkPointSetInteractorTest.cpp mitkPropertyTest.cpp mitkPropertyListTest.cpp #mitkRegistrationBaseTest.cpp #mitkSegmentationInterpolationTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkStateMachineTest.cpp mitkStateTest.cpp mitkSurfaceTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeSlicedGeometryTest.cpp mitkTransitionTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp #mitkAbstractTransformGeometryTest.cpp mitkStepperTest.cpp itkTotalVariationDenoisingImageFilterTest.cpp mitkRenderingManagerTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateSourceTest.cpp mitkVectorTest.cpp mitkClippedSurfaceBoundsCalculatorTest.cpp #QmitkRenderingTestHelper.cpp mitkExceptionTest.cpp mitkExtractSliceFilterTest.cpp mitkLogTest.cpp mitkImageDimensionConverterTest.cpp mitkLoggingAdapterTest.cpp ) # test with image filename as an extra command line parameter set(MODULE_IMAGE_TESTS mitkPlanePositionManagerTest.cpp mitkSurfaceVtkWriterTest.cpp #mitkImageSliceSelectorTest.cpp mitkImageTimeSelectorTest.cpp # mitkVtkPropRendererTest.cpp mitkDataNodeFactoryTest.cpp #mitkSTLFileReaderTest.cpp mitkImageAccessorTest.cpp ) # list of images for which the tests are run set(MODULE_TESTIMAGES # Pic-Factory no more available in Core, test images now in .nrrd format US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd binary.stl ball.stl ) set(MODULE_CUSTOM_TESTS #mitkLabeledImageToSurfaceFilterTest.cpp #mitkExternalToolsTest.cpp mitkDataStorageTest.cpp mitkDataNodeTest.cpp mitkDicomSeriesReaderTest.cpp mitkDICOMLocaleTest.cpp mitkEventMapperTest.cpp mitkNodeDependentPointSetInteractorTest.cpp mitkStateMachineFactoryTest.cpp mitkPointSetLocaleTest.cpp mitkImageTest.cpp mitkImageWriterTest.cpp mitkImageVtkMapper2DTest.cpp mitkImageVtkMapper2DLevelWindowTest.cpp mitkImageVtkMapper2DOpacityTest.cpp mitkImageVtkMapper2DColorTest.cpp mitkImageVtkMapper2DSwivelTest.cpp mitkIOUtilTest.cpp + mitkSurfaceVtkMapper3DTest + mitkSurfaceVtkMapper3DTexturedSphereTest.cpp ) # Create an artificial module initializing class for # the usServiceListenerTest.cpp usFunctionGenerateModuleInit(testdriver_init_file NAME ${MODULE_NAME}TestDriver DEPENDS "Mitk" VERSION "0.1.0" EXECUTABLE ) set(TEST_CPP_FILES ${testdriver_init_file} mitkRenderingTestHelper.cpp) diff --git a/Core/Code/Testing/mitkImageVtkMapper2DColorTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DColorTest.cpp index 69ea9ded02..14d11d2aad 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DColorTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DColorTest.cpp @@ -1,74 +1,74 @@ /*=================================================================== 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.SetProperty("use color", mitk::BoolProperty::New(true)); - renderingHelper.SetProperty("color", mitk::ColorProperty::New(0.0f, 0.0f, 255.0f)); + renderingHelper.SetImageProperty("use color", mitk::BoolProperty::New(true)); + 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: 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. 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(); } diff --git a/Core/Code/Testing/mitkImageVtkMapper2DLevelWindowTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DLevelWindowTest.cpp index 7b7adc44ac..411f29030c 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DLevelWindowTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DLevelWindowTest.cpp @@ -1,80 +1,80 @@ /*=================================================================== 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.SetProperty("levelwindow", mitk::LevelWindowProperty::New(mitk::LevelWindow(level, window)) ); + 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. 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(); } diff --git a/Core/Code/Testing/mitkImageVtkMapper2DOpacityTest.cpp b/Core/Code/Testing/mitkImageVtkMapper2DOpacityTest.cpp index 0222c2b9f1..d9482e9934 100644 --- a/Core/Code/Testing/mitkImageVtkMapper2DOpacityTest.cpp +++ b/Core/Code/Testing/mitkImageVtkMapper2DOpacityTest.cpp @@ -1,73 +1,73 @@ /*=================================================================== 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.SetProperty("opacity", mitk::FloatProperty::New(0.5f)); + 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. 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(); } diff --git a/Core/Code/Testing/mitkRenderingTestHelper.cpp b/Core/Code/Testing/mitkRenderingTestHelper.cpp index bd516e8418..175b5af89a 100644 --- a/Core/Code/Testing/mitkRenderingTestHelper.cpp +++ b/Core/Code/Testing/mitkRenderingTestHelper.cpp @@ -1,184 +1,180 @@ /*=================================================================== 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. ===================================================================*/ -#include "mitkRenderingTestHelper.h" -#include - +//VTK #include #include #include #include +//MITK +#include +#include #include #include #include #include +#include // include gl to read out properties #include #include mitkRenderingTestHelper::mitkRenderingTestHelper(int width, int height, int argc, char* argv[]) { // Global interaction must(!) be initialized mitk::GlobalInteraction::GetInstance()->Initialize("global"); m_DataStorage = mitk::StandaloneDataStorage::New(); m_RenderWindow = mitk::RenderWindow::New(); m_RenderWindow->GetRenderer()->SetDataStorage(m_DataStorage); m_RenderWindow->GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard2D); this->GetVtkRenderWindow()->SetSize( width, height ); m_RenderWindow->GetRenderer()->Resize( width, height); this->GetVtkRenderWindow()->DoubleBufferOff( ); this->SetInputFileNames(argc, argv); // prints the glinfo after creation of the vtkrenderwindow 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::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: + mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()) ); mitk::RenderingManager::GetInstance()->RequestUpdate(m_RenderWindow->GetVtkRenderWindow()); + m_RenderWindow->GetRenderer()->PrepareRender(); //use this to actually show the iamge in a renderwindow // this->GetVtkRenderWindow()->Render(); // this->GetVtkRenderWindow()->GetInteractor()->Start(); - } else { MITK_ERROR << "No images loaded in data storage!"; } } mitk::DataStorage::Pointer mitkRenderingTestHelper::GetDataStorage() { return m_DataStorage; } void mitkRenderingTestHelper::SetInputFileNames(int argc, char* argv[]) { // 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::SetProperty(const char *propertyKey, mitk::BaseProperty* property ) +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(); } //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.0); vtkSmartPointer fileWriter = vtkSmartPointer::New(); fileWriter->SetInput(magnifier->GetOutput()); fileWriter->SetFileName(fileName.c_str()); fileWriter->Write(); renderer->GetRenderWindow()->SetDoubleBuffer(doubleBuffering); } void mitkRenderingTestHelper::AddToStorage(const std::string &filename) { - mitk::DataNodeFactory::Pointer reader = mitk::DataNodeFactory::New(); try { - reader->SetFileName( filename ); - reader->Update(); - - if(reader->GetNumberOfOutputs()<1) - { - MITK_ERROR << "Could not find test data '" << filename << "'"; - } - - mitk::DataNode::Pointer node = reader->GetOutput( 0 ); + mitk::DataNode::Pointer node = mitk::IOUtil::LoadDataNode(filename); this->m_DataStorage->Add(node); } catch ( itk::ExceptionObject & e ) { MITK_ERROR << "Failed loading test data '" << filename << "': " << e.what(); } - - mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()) ); - } diff --git a/Core/Code/Testing/mitkRenderingTestHelper.h b/Core/Code/Testing/mitkRenderingTestHelper.h index c5a65b1452..5a159af471 100644 --- a/Core/Code/Testing/mitkRenderingTestHelper.h +++ b/Core/Code/Testing/mitkRenderingTestHelper.h @@ -1,98 +1,104 @@ /*=================================================================== 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 class vtkRenderWindow; class vtkRenderer; class 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. **/ mitkRenderingTestHelper(int width, int height, int argc, char *argv[]); ~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 This method set the property of the member datastorage @param property Set a property for each image in the datastorage m_DataStorage. **/ - void SetProperty(const char *propertyKey, mitk::BaseProperty *property); + 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 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); protected: /** @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 }; #endif diff --git a/Core/Code/Testing/mitkSurfaceVtkMapper3DTest.cpp b/Core/Code/Testing/mitkSurfaceVtkMapper3DTest.cpp new file mode 100644 index 0000000000..a981b11fdb --- /dev/null +++ b/Core/Code/Testing/mitkSurfaceVtkMapper3DTest.cpp @@ -0,0 +1,125 @@ +/*=================================================================== + +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); + + 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")) ); + + renderingHelper.SetMapperID(mitk::BaseRenderer::Standard3D); + renderingHelper.Render(); + + //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(); + + + //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. + 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(); +} diff --git a/Core/Code/Testing/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp b/Core/Code/Testing/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp new file mode 100644 index 0000000000..a1d061a46f --- /dev/null +++ b/Core/Code/Testing/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp @@ -0,0 +1,113 @@ +/*=================================================================== + +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); + + //######## 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.GetDataStorage()->Add(surfaceNode); + //######## Exmaple code end ######## + + //set renderwindow to 3D + renderingHelper.SetMapperID(mitk::BaseRenderer::Standard3D); + 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. + 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(); +}