1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestPLYWriterAlpha.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 // .NAME Test of vtkPLYWriter with alpha.
16
17 #include "vtkElevationFilter.h"
18 #include "vtkLookupTable.h"
19 #include "vtkNew.h"
20 #include "vtkPLYReader.h"
21 #include "vtkPLYWriter.h"
22 #include "vtkPolyDataMapper.h"
23 #include "vtkRegressionTestImage.h"
24 #include "vtkRenderWindow.h"
25 #include "vtkRenderWindowInteractor.h"
26 #include "vtkRenderer.h"
27 #include "vtkSphereSource.h"
28 #include "vtkTestUtilities.h"
29
TestPLYWriterAlpha(int argc,char * argv[])30 int TestPLYWriterAlpha(int argc, char* argv[])
31 {
32 // Test temporary directory
33 char* tempDir =
34 vtkTestUtilities::GetArgOrEnvOrDefault("-T", argc, argv, "VTK_TEMP_DIR", "Testing/Temporary");
35 if (!tempDir)
36 {
37 std::cout << "Could not determine temporary directory.\n";
38 return EXIT_FAILURE;
39 }
40
41 std::string testDirectory = tempDir;
42 delete[] tempDir;
43
44 const std::string outputfile = testDirectory + std::string("/") + std::string("plyAlpha.ply");
45
46 vtkNew<vtkSphereSource> sphere;
47 sphere->SetPhiResolution(20);
48 sphere->SetThetaResolution(20);
49
50 vtkNew<vtkElevationFilter> elevation;
51 elevation->SetInputConnection(sphere->GetOutputPort());
52 elevation->SetLowPoint(-0.5, -0.5, -0.5);
53 elevation->SetHighPoint(0.5, 0.5, 0.5);
54
55 vtkNew<vtkLookupTable> lut;
56 lut->SetTableRange(0, 1);
57 lut->SetAlphaRange(0, 1.0);
58 lut->Build();
59
60 vtkNew<vtkPLYWriter> writer;
61 writer->SetFileName(outputfile.c_str());
62 writer->SetFileTypeToBinary();
63 writer->EnableAlphaOn();
64 writer->SetColorModeToDefault();
65 writer->SetArrayName("Elevation");
66 writer->SetLookupTable(lut);
67 writer->SetInputConnection(elevation->GetOutputPort());
68 writer->Write();
69
70 vtkNew<vtkPLYReader> reader;
71 reader->SetFileName(outputfile.c_str());
72
73 // Create a mapper.
74 vtkNew<vtkPolyDataMapper> mapper;
75 mapper->SetInputConnection(reader->GetOutputPort());
76 mapper->ScalarVisibilityOn();
77
78 // Create the actor.
79 vtkNew<vtkActor> actor;
80 actor->SetMapper(mapper);
81
82 // Basic visualisation.
83 vtkNew<vtkRenderWindow> renWin;
84 vtkNew<vtkRenderer> ren;
85 renWin->AddRenderer(ren);
86 vtkNew<vtkRenderWindowInteractor> iren;
87 iren->SetRenderWindow(renWin);
88
89 ren->AddActor(actor);
90 ren->SetBackground(0, 0, 0);
91 renWin->SetSize(300, 300);
92
93 // interact with data
94 renWin->Render();
95
96 int retVal = vtkRegressionTestImage(renWin);
97 if (retVal == vtkRegressionTester::DO_INTERACTOR)
98 {
99 iren->Start();
100 }
101 return !retVal;
102 }
103