1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestMinIntensityRendering.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkCamera.h"
16 #include "vtkFiniteDifferenceGradientEstimator.h"
17 #include "vtkImageClip.h"
18 #include "vtkPiecewiseFunction.h"
19 #include "vtkRenderWindow.h"
20 #include "vtkRenderWindowInteractor.h"
21 #include "vtkRenderer.h"
22 #include "vtkStructuredPoints.h"
23 #include "vtkStructuredPointsReader.h"
24 #include "vtkVolume.h"
25 #include "vtkVolumeProperty.h"
26 #include "vtkFixedPointVolumeRayCastMapper.h"
27 #include "vtkColorTransferFunction.h"
28 
29 #include "vtkTestUtilities.h"
30 #include "vtkRegressionTestImage.h"
31 #include "vtkDebugLeaks.h"
32 
TestMinIntensityRendering(int argc,char * argv[])33 int TestMinIntensityRendering( int argc, char *argv[] )
34 {
35 
36   // Create the renderers, render window, and interactor
37   vtkRenderWindow *renWin = vtkRenderWindow::New();
38   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
39   iren->SetRenderWindow(renWin);
40   vtkRenderer *ren = vtkRenderer::New();
41   renWin->AddRenderer(ren);
42 
43   // Read the data from a vtk file
44   char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/ironProt.vtk");
45   vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
46   reader->SetFileName(fname);
47   reader->Update();
48   delete [] fname;
49 
50   // Create a transfer function mapping scalar value to opacity
51   vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
52   oTFun->AddSegment(0, 1.0, 256, 0.1);
53 
54   vtkColorTransferFunction *cTFun = vtkColorTransferFunction::New();
55   cTFun->AddRGBPoint(   0, 1.0, 1.0, 1.0 );
56   cTFun->AddRGBPoint( 255, 1.0, 1.0, 1.0 );
57 
58   // Need to crop to actually see minimum intensity
59   vtkImageClip *clip = vtkImageClip::New();
60   clip->SetInputConnection( reader->GetOutputPort() );
61   clip->SetOutputWholeExtent(0,66,0,66,30,37);
62   clip->ClipDataOn();
63 
64   vtkVolumeProperty *property = vtkVolumeProperty::New();
65   property->SetScalarOpacity(oTFun);
66   property->SetColor(cTFun);
67   property->SetInterpolationTypeToLinear();
68 
69   vtkFixedPointVolumeRayCastMapper *mapper = vtkFixedPointVolumeRayCastMapper::New();
70   mapper->SetBlendModeToMinimumIntensity();
71   mapper->SetInputConnection( clip->GetOutputPort() );
72 
73   vtkVolume *volume = vtkVolume::New();
74   volume->SetMapper(mapper);
75   volume->SetProperty(property);
76 
77 
78   ren->AddViewProp(volume);
79 
80   renWin->Render();
81   int retVal = vtkRegressionTestImageThreshold( renWin, 70 );
82 
83   if ( retVal == vtkRegressionTester::DO_INTERACTOR)
84     {
85     iren->Start();
86     }
87 
88   volume->Delete();
89   mapper->Delete();
90   property->Delete();
91   clip->Delete();
92   cTFun->Delete();
93   oTFun->Delete();
94   reader->Delete();
95   renWin->Delete();
96   iren->Delete();
97   ren->Delete();
98 
99 
100   return !retVal;
101 
102 }
103 
104 
105 
106 
107 
108 
109