1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestFinalColorWindowLevel.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 "vtkFixedPointVolumeRayCastMapper.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 "vtkColorTransferFunction.h"
27 
28 #include "vtkTestUtilities.h"
29 #include "vtkRegressionTestImage.h"
30 #include "vtkDebugLeaks.h"
31 
32 // Create an 8x7 grid of render windows in a renderer and render a volume
33 // using various techniques for testing purposes
TestFinalColorWindowLevel(int argc,char * argv[])34 int TestFinalColorWindowLevel( int argc, char *argv[] )
35 {
36 
37   // Create the renderers, render window, and interactor
38   vtkRenderWindow *renWin = vtkRenderWindow::New();
39   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
40   iren->SetRenderWindow(renWin);
41   vtkRenderer *ren = vtkRenderer::New();
42   renWin->AddRenderer(ren);
43 
44   // Read the data from a vtk file
45   char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/ironProt.vtk");
46   vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
47   reader->SetFileName(fname);
48   reader->Update();
49   delete [] fname;
50 
51   // Create a transfer function mapping scalar value to opacity
52   vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
53   oTFun->AddSegment(10, 0.0, 255, 0.3);
54 
55   // Create a transfer function mapping scalar value to color (color)
56   vtkColorTransferFunction *cTFun = vtkColorTransferFunction::New();
57   cTFun->AddRGBPoint(   0, 1.0, 0.0, 0.0 );
58   cTFun->AddRGBPoint(  64, 1.0, 1.0, 0.0 );
59   cTFun->AddRGBPoint( 128, 0.0, 1.0, 0.0 );
60   cTFun->AddRGBPoint( 192, 0.0, 1.0, 1.0 );
61   cTFun->AddRGBPoint( 255, 0.0, 0.0, 1.0 );
62 
63 
64   vtkVolumeProperty *property = vtkVolumeProperty::New();
65   property->SetShade(0);
66   property->SetAmbient(0.3);
67   property->SetDiffuse(1.0);
68   property->SetSpecular(0.2);
69   property->SetSpecularPower(50.0);
70   property->SetScalarOpacity(oTFun);
71   property->SetColor( cTFun );
72   property->SetInterpolationTypeToLinear();
73 
74   vtkFixedPointVolumeRayCastMapper *mapper = vtkFixedPointVolumeRayCastMapper::New();
75   mapper->SetInputConnection(reader->GetOutputPort());
76 
77   vtkVolume *volume = vtkVolume::New();
78   volume->SetProperty(property);
79   volume->SetMapper(mapper);
80   ren->AddViewProp(volume);
81 
82   ren->ResetCamera();
83   ren->GetActiveCamera()->Zoom(1.5);
84 
85   mapper->SetFinalColorWindow(.5);
86   mapper->SetFinalColorLevel(.75);
87 
88   renWin->Render();
89 
90   int retVal = vtkRegressionTestImageThreshold( renWin, 70 );
91 
92   // Interact with the data at 3 frames per second
93   iren->SetDesiredUpdateRate(3.0);
94   iren->SetStillUpdateRate(0.001);
95 
96   if ( retVal == vtkRegressionTester::DO_INTERACTOR)
97     {
98     iren->Start();
99     }
100 
101   // Clean up
102   reader->Delete();
103   oTFun->Delete();
104   cTFun->Delete();
105   property->Delete();
106   mapper->Delete();
107   volume->Delete();
108 
109   ren->Delete();
110   iren->Delete();
111   renWin->Delete();
112 
113   return !retVal;
114 }
115 
116 
117 
118