1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: $RCSfile: Cone.cxx,v $
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 //
16 // This example creates a polygonal model of a cone, and then renders it to
17 // the screen. It will rotate the cone 360 degrees and then exit. The basic
18 // setup of source -> mapper -> actor -> renderer -> renderwindow is
19 // typical of most VTK programs.
20 //
21
22 // First include the required header files for the VTK classes we are using.
23 #include "vtkActor.h"
24 #include "vtkCamera.h"
25 #include "vtkCellDataToPointData.h"
26 #include "vtkColorTransferFunction.h"
27 #include "vtkCompositeDataPipeline.h"
28 #include "vtkConeSource.h"
29 #include "vtkDataSetTriangleFilter.h"
30 #include "vtkMaskFields.h"
31 #include "vtkMergeFields.h"
32 #include "vtkProjectedAAHexahedraMapper.h"
33 #include "vtkPiecewiseFunction.h"
34 #include "vtkPolyDataMapper.h"
35 #include "vtkRenderWindowInteractor.h"
36 #include "vtkRenderWindow.h"
37 #include "vtkRenderer.h"
38 #include "vtkSplitField.h"
39 #include "vtkUnstructuredGridReader.h"
40 #include "vtkUnstructuredGrid.h"
41 #include "vtkVolumeProperty.h"
42 #include "vtkProjectedTetrahedraMapper.h"
43 #include "vtkTestUtilities.h"
44 #include "vtkRegressionTestImage.h"
45
46 #include "vtkSmartPointer.h"
47 #define VTK_CREATE(type, name) \
48 vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
49
TestProjectedHexahedra(int argc,char * argv[])50 int TestProjectedHexahedra(int argc,
51 char *argv[])
52 {
53 VTK_CREATE(vtkRenderer, ren1);
54 ren1->SetBackground( 0.0, 0.0, 0.0 );
55
56 //
57 // Finally we create the render window which will show up on the screen.
58 // We put our renderer into the render window using AddRenderer. We also
59 // set the size to be 300 pixels by 300.
60 //
61 VTK_CREATE(vtkRenderWindow, renWin);
62 renWin->AddRenderer( ren1 );
63 renWin->SetSize( 500, 500 );
64
65 vtkSmartPointer<vtkRenderWindowInteractor> iren=
66 vtkSmartPointer<vtkRenderWindowInteractor>::New();
67 iren->SetRenderWindow(renWin);
68
69 // Make sure we have a OpenGL context created before checking that
70 // the volume mapper is supported by OpenGL.
71 renWin->Render();
72
73 // Create the reader for the data
74 VTK_CREATE(vtkUnstructuredGridReader, reader);
75
76 char *cfname=vtkTestUtilities::ExpandDataFileName(argc,argv,"Data/hexa.vtk");
77 reader->SetFileName(cfname);
78 delete [] cfname;
79
80 // Create transfer mapping scalar value to opacity
81 VTK_CREATE(vtkPiecewiseFunction, opacityTransferFunction);
82 opacityTransferFunction->AddPoint(0.0, 0.0);
83
84 opacityTransferFunction->AddPoint(8.0, 2.0);
85
86 opacityTransferFunction->AddPoint(10.0, 1.5);
87
88 opacityTransferFunction->AddPoint(13.0, 1.0);
89
90 // Create transfer mapping scalar value to color
91 VTK_CREATE(vtkColorTransferFunction, colorTransferFunction);
92 colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
93
94 colorTransferFunction->AddRGBPoint(8.0, 1.0, 0.0, 0.0);
95
96 colorTransferFunction->AddRGBPoint(10.0, 0.0, 0.0, 1.0);
97
98 colorTransferFunction->AddRGBPoint(12.0, 0.0, 1.0, 0.0);
99
100 // The property describes how the data will look
101 VTK_CREATE(vtkVolumeProperty, volumeProperty);
102 volumeProperty->SetColor(colorTransferFunction);
103 volumeProperty->SetScalarOpacity(opacityTransferFunction);
104
105 // Make sure we have only tetrahedra.
106 VTK_CREATE(vtkDataSetTriangleFilter, trifilter);
107 trifilter->SetInputConnection(reader->GetOutputPort());
108
109 // The mapper knows how to render the data
110 VTK_CREATE(vtkProjectedTetrahedraMapper, volumeMapperTet);
111 volumeMapperTet->SetInputConnection(trifilter->GetOutputPort());
112
113 // The mapper knows how to render the data
114 VTK_CREATE(vtkProjectedAAHexahedraMapper, volumeMapperHex);
115 volumeMapperHex->SetInputConnection(reader->GetOutputPort());
116
117 // The volume holds the mapper and the property and can be used to
118 // position/orient the volume
119 VTK_CREATE(vtkVolume,volume);
120 #if 1
121 volume->SetMapper(volumeMapperHex);
122 #else
123 volume->SetMapper(volumeMapperTet);
124 #endif
125 volume->SetProperty(volumeProperty);
126
127 int valid=volumeMapperHex->IsRenderSupported(renWin);
128
129 int retVal;
130 if(valid)
131 {
132 iren->Initialize();
133 ren1->AddVolume(volume);
134 ren1->ResetCamera();
135 renWin->Render();
136
137 retVal = vtkTesting::Test(argc, argv, renWin, 75);
138 if (retVal == vtkRegressionTester::DO_INTERACTOR)
139 {
140 iren->Start();
141 }
142 }
143 else
144 {
145 retVal=vtkTesting::PASSED;
146 cout << "Required extensions not supported." << endl;
147 }
148
149 if ((retVal == vtkTesting::PASSED) || (retVal == vtkTesting::DO_INTERACTOR))
150 {
151 return 0;
152 }
153 else
154 {
155 return 1;
156 }
157 }
158
159
160