1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestCubeAxesWithGridlines.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 // .SECTION Thanks
16 // This test was written by Philippe Pebay, Kitware SAS 2011
17
18 #include "vtkBYUReader.h"
19 #include "vtkCamera.h"
20 #include "vtkCubeAxesActor.h"
21 #include "vtkLight.h"
22 #include "vtkLODActor.h"
23 #include "vtkNew.h"
24 #include "vtkOutlineFilter.h"
25 #include "vtkPolyDataMapper.h"
26 #include "vtkPolyDataNormals.h"
27 #include "vtkProperty.h"
28 #include "vtkRegressionTestImage.h"
29 #include "vtkRenderer.h"
30 #include "vtkRenderWindow.h"
31 #include "vtkRenderWindowInteractor.h"
32 #include "vtkSmartPointer.h"
33 #include "vtkTestUtilities.h"
34 #include "vtkTextProperty.h"
35
36 //----------------------------------------------------------------------------
TestCubeAxesWithGridLines(int argc,char * argv[])37 int TestCubeAxesWithGridLines( int argc, char * argv [] )
38 {
39 vtkNew<vtkBYUReader> fohe;
40 char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/teapot.g");
41 fohe->SetGeometryFileName(fname);
42 delete [] fname;
43
44 vtkNew<vtkPolyDataNormals> normals;
45 normals->SetInputConnection(fohe->GetOutputPort());
46
47 vtkNew<vtkPolyDataMapper> foheMapper;
48 foheMapper->SetInputConnection(normals->GetOutputPort());
49
50 vtkNew<vtkLODActor> foheActor;
51 foheActor->SetMapper(foheMapper.GetPointer());
52 foheActor->GetProperty()->SetDiffuseColor(0.7, 0.3, 0.0);
53
54 vtkNew<vtkOutlineFilter> outline;
55 outline->SetInputConnection(normals->GetOutputPort());
56
57 vtkNew<vtkPolyDataMapper> mapOutline;
58 mapOutline->SetInputConnection(outline->GetOutputPort());
59
60 vtkNew<vtkActor> outlineActor;
61 outlineActor->SetMapper(mapOutline.GetPointer());
62 outlineActor->GetProperty()->SetColor(0.0 ,0.0 ,0.0);
63
64 vtkNew<vtkCamera> camera;
65 camera->SetClippingRange(1.0, 100.0);
66 camera->SetFocalPoint(0.9, 1.0, 0.0);
67 camera->SetPosition(11.63, 6.0, 10.77);
68
69 vtkNew<vtkLight> light;
70 light->SetFocalPoint(0.21406, 1.5, 0.0);
71 light->SetPosition(8.3761, 4.94858, 4.12505);
72
73 vtkNew<vtkRenderer> ren2;
74 ren2->SetActiveCamera(camera.GetPointer());
75 ren2->AddLight(light.GetPointer());
76
77 vtkNew<vtkRenderWindow> renWin;
78 renWin->SetMultiSamples(0);
79 renWin->AddRenderer(ren2.GetPointer());
80 renWin->SetWindowName("Cube Axes with Outer Grid Lines");
81 renWin->SetSize(600, 600);
82 renWin->SetMultiSamples(0);
83
84 vtkNew<vtkRenderWindowInteractor> iren;
85 iren->SetRenderWindow(renWin.GetPointer());
86
87 ren2->AddViewProp(foheActor.GetPointer());
88 ren2->AddViewProp(outlineActor.GetPointer());
89 ren2->SetGradientBackground( true );
90 ren2->SetBackground(.1,.1,.1);
91 ren2->SetBackground2(.8,.8,.8);
92
93 normals->Update();
94
95 vtkNew<vtkCubeAxesActor> axes2;
96 axes2->SetBounds(normals->GetOutput()->GetBounds());
97 axes2->SetXAxisRange(20, 300);
98 axes2->SetYAxisRange(-0.01, 0.01);
99 axes2->SetCamera(ren2->GetActiveCamera());
100 axes2->SetXLabelFormat("%6.1f");
101 axes2->SetYLabelFormat("%6.1f");
102 axes2->SetZLabelFormat("%6.1f");
103 axes2->SetScreenSize(15.0);
104 axes2->SetFlyModeToClosestTriad();
105 axes2->SetCornerOffset(0.0);
106
107 // Draw all (outer) grid lines
108 axes2->SetDrawXGridlines(1);
109 axes2->SetDrawYGridlines(1);
110 axes2->SetDrawZGridlines(1);
111
112 // Use red color for X axis
113 axes2->GetXAxesLinesProperty()->SetColor(1., 0., 0.);
114 axes2->GetTitleTextProperty(0)->SetColor(1., 0., 0.);
115 axes2->GetLabelTextProperty(0)->SetColor(1., 0., 0.);
116
117 // Use green color for Y axis
118 axes2->GetYAxesLinesProperty()->SetColor(0., 1., 0.);
119 axes2->GetTitleTextProperty(1)->SetColor(0., 1., 0.);
120 axes2->GetLabelTextProperty(1)->SetColor(0., 1., 0.);
121
122 // Use blue color for Z axis
123 axes2->GetZAxesLinesProperty()->SetColor(0., 0., 1.);
124 axes2->GetTitleTextProperty(2)->SetColor(0., 0., 1.);
125 axes2->GetLabelTextProperty(2)->SetColor(0., 0., 1.);
126
127 // Use olive color for gridlines
128 axes2->GetXAxesGridlinesProperty()->SetColor(.23, .37, .17);
129 axes2->GetYAxesGridlinesProperty()->SetColor(.23, .37, .17);
130 axes2->GetZAxesGridlinesProperty()->SetColor(.23, .37, .17);
131
132 ren2->AddViewProp(axes2.GetPointer());
133 renWin->Render();
134
135 int retVal = vtkRegressionTestImage( renWin.GetPointer() );
136 if ( retVal == vtkRegressionTester::DO_INTERACTOR)
137 {
138 iren->Start();
139 }
140
141 return !retVal;
142 }
143