Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkSurfaceVtkMapper3DTexturedSphereTest.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 // MITK
19 #include "mitkTestingMacros.h"
22 #include <mitkSurface.h>
23 
24 // VTK
25 #include <mitkIOUtil.h>
26 #include <vtkFloatArray.h>
27 #include <vtkPointData.h>
28 #include <vtkPolyData.h>
29 #include <vtkRegressionTestImage.h>
30 #include <vtkSphereSource.h>
31 #include <vtkTextureMapToSphere.h>
32 
39 int mitkSurfaceVtkMapper3DTexturedSphereTest(int argc, char *argv[])
40 {
41  // load all arguments into a datastorage, take last argument as reference rendering
42  // setup a renderwindow of fixed size X*Y
43  // render the datastorage
44  // compare rendering to reference image
45  MITK_TEST_BEGIN("mitkSurfaceVtkMapper3DTexturedSphereTest")
46 
47  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
48  // This is a test for a 3D surface, thus we need to set the mapper ID to 3D
50 
51  //######## Exmaple code begin ########
52  // Generate a sphere in order to map texture on it
53  vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
54  sphere->SetThetaResolution(12);
55  sphere->SetPhiResolution(12);
56  sphere->SetRadius(50.0); // just to make it huge
57  sphere->SetCenter(50, 0, 0); // just to center the sphere in the screen
58 
59  // taken from VTK example: http://www.vtk.org/Wiki/VTK/Examples/Python/Visualization/SphereTexture
60  vtkSmartPointer<vtkTextureMapToSphere> mapToSphere = vtkSmartPointer<vtkTextureMapToSphere>::New();
61  mapToSphere->SetInputConnection(sphere->GetOutputPort());
62  mapToSphere->PreventSeamOn();
63 
64  // get the texture image from the helper's data storage
65  mitk::Image::Pointer textureImage = static_cast<mitk::Image *>(
66  renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))->GetData());
67 
68  // Generate MITK surface
69  mitk::Surface::Pointer surfaceToPutTextureOn = mitk::Surface::New();
70  surfaceToPutTextureOn->SetVtkPolyData(static_cast<vtkPolyData *>(mapToSphere->GetOutput()));
71  // Generate a node
73  surfaceNode->SetData(surfaceToPutTextureOn);
74  // Make a Property and add to the node
76  surfaceNode->SetProperty("Surface.Texture", textureProperty);
77  // add to data storage
78  renderingHelper.AddNodeToStorage(surfaceNode);
79  //######## Exmaple code end ########
80 
81  // use this to generate a reference screenshot or save the file:
82  bool generateReferenceScreenshot = false;
83  if (generateReferenceScreenshot)
84  {
85  renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png");
86  }
87 
88  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
89  MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 50.0) == true,
90  "CompareRenderWindowAgainstReference test result positive?");
91 
92  MITK_TEST_END();
93 }
void SetMapperID(mitk::BaseRenderer::StandardMapperSlot id)
SetMapperID Change between Standard2D and 3D mappers.
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
void SaveReferenceScreenShot(std::string fileName)
SaveReferenceScreenShot Convenience method to save a reference screen shot.
bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold=10.0)
CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal ...
static Pointer New()
#define MITK_TEST_CONDITION(COND, MSG)
Image class for storing images.
Definition: mitkImage.h:76
int mitkSurfaceVtkMapper3DTexturedSphereTest(int argc, char *argv[])
mitkSurfaceVtkMapper3DTexturedSphereTest This test puts a texture onto a sphere. It is a nice example...
mitk::DataStorage::Pointer GetDataStorage()
Returns the datastorage, in order to modify the data inside a rendering test.
static Pointer New(const char *_arg)
void AddNodeToStorage(mitk::DataNode::Pointer node)
AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering...
and MITK_TEST_END()
static Pointer New()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.