1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestGlyphSource2DResolution.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
16 // Description
17 // This tests the circle resolution parameter for vtkGlyphSource2D
18
19 #include "vtkActor2D.h"
20 #include "vtkFloatArray.h"
21 #include "vtkGlyph2D.h"
22 #include "vtkGlyphSource2D.h"
23 #include "vtkMinimalStandardRandomSequence.h"
24 #include "vtkNew.h"
25 #include "vtkPointData.h"
26 #include "vtkPoints.h"
27 #include "vtkPolyData.h"
28 #include "vtkPolyDataMapper2D.h"
29 #include "vtkRegressionTestImage.h"
30 #include "vtkRenderer.h"
31 #include "vtkRenderWindow.h"
32 #include "vtkRenderWindowInteractor.h"
33 #include "vtkTestUtilities.h"
34
TestGlyphSource2DResolution(int argc,char * argv[])35 int TestGlyphSource2DResolution(int argc, char* argv[])
36 {
37 cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
38
39 vtkNew<vtkPolyData> pd;
40 vtkNew<vtkPoints> pts;
41
42 vtkNew<vtkFloatArray> scalars;
43 vtkNew<vtkFloatArray> vectors;
44 vectors->SetNumberOfComponents(3);
45
46 pd->SetPoints(pts);
47 pd->GetPointData()->SetScalars(scalars);
48 pd->GetPointData()->SetVectors(vectors);
49
50 vtkNew<vtkMinimalStandardRandomSequence> randomSequence;
51 randomSequence->SetSeed(1);
52
53 int size = 400;
54
55 for (int i = 0; i < 100; ++i)
56 {
57 randomSequence->Next();
58 double x = randomSequence->GetValue()*size;
59 randomSequence->Next();
60 double y = randomSequence->GetValue()*size;
61 pts->InsertNextPoint(x,
62 y,
63 0.0);
64 randomSequence->Next();
65 scalars->InsertNextValue(5.0*randomSequence->GetValue());
66 randomSequence->Next();
67 double ihat = randomSequence->GetValue()*2-1;
68 randomSequence->Next();
69 double jhat = randomSequence->GetValue()*2-1;
70 vectors->InsertNextTuple3(ihat,
71 jhat,
72 0.0);
73 }
74
75 vtkNew<vtkGlyphSource2D> gs;
76 gs->SetGlyphTypeToCircle();
77 gs->SetScale(20);
78 gs->FilledOff();
79 gs->CrossOn();
80
81 vtkNew<vtkGlyphSource2D> gs1;
82 gs1->SetGlyphTypeToCircle();
83 gs1->SetResolution(24);
84 gs1->SetScale(30);
85 gs1->FilledOn();
86 gs1->CrossOff();
87
88 vtkNew<vtkGlyphSource2D> gs2;
89 gs2->SetGlyphTypeToCircle();
90 gs2->SetResolution(6);
91 gs2->SetScale(20);
92 gs2->FilledOn();
93 gs2->CrossOff();
94
95 vtkNew<vtkGlyphSource2D> gs3;
96 gs3->SetGlyphTypeToCircle();
97 gs3->SetResolution(5);
98 gs3->SetScale(30);
99 gs3->FilledOff();
100 gs3->CrossOn();
101
102 vtkNew<vtkGlyphSource2D> gs4;
103 gs4->SetGlyphTypeToCircle();
104 gs4->SetResolution(100);
105 gs4->SetScale(50);
106 gs4->FilledOff();
107 gs4->CrossOff();
108
109 vtkNew<vtkGlyph2D> glypher;
110 glypher->SetInputData(pd);
111 glypher->SetSourceConnection(0, gs->GetOutputPort());
112 glypher->SetSourceConnection(1, gs1->GetOutputPort());
113 glypher->SetSourceConnection(2, gs2->GetOutputPort());
114 glypher->SetSourceConnection(3, gs3->GetOutputPort());
115 glypher->SetSourceConnection(4, gs4->GetOutputPort());
116 glypher->SetIndexModeToScalar();
117 glypher->SetRange(0,5);
118 glypher->SetScaleModeToScaleByVector();
119
120 vtkNew<vtkPolyDataMapper2D> mapper;
121 mapper->SetInputConnection(glypher->GetOutputPort());
122 mapper->SetScalarRange(0, 5);
123
124 vtkNew<vtkActor2D> glyphActor;
125 glyphActor->SetMapper(mapper);
126
127 // Create the RenderWindow, Renderer
128 vtkNew<vtkRenderWindow> renWin;
129 renWin->SetMultiSamples(0);
130 vtkNew<vtkRenderWindowInteractor> iren;
131 iren->SetRenderWindow(renWin);
132
133 vtkNew<vtkRenderer> ren;
134 ren->AddActor2D(glyphActor);
135 ren->SetBackground(0.3, 0.3, 0.3);
136 ren->ResetCamera();
137
138 renWin->SetSize(size+1, size-1); //NPOT size
139 renWin->AddRenderer(ren);
140 renWin->Render();
141
142 iren->Initialize();
143
144 int retVal = vtkRegressionTestImage(renWin);
145 if (retVal == vtkRegressionTester::DO_INTERACTOR)
146 {
147 iren->Start();
148 }
149
150 return !retVal;
151 }
152