VTK  9.7.1
TestAxisActor2DInternal.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 #ifndef TestAxisActor2DInternal_h
4 #define TestAxisActor2DInternal_h
5 
6 #include "vtkTestUtilities.h"
7 
8 #include "vtkAxisActor2D.h"
9 #include "vtkCamera.h"
10 #include "vtkNew.h"
11 #include "vtkNumberToString.h"
12 #include "vtkPolyDataMapper.h"
13 #include "vtkProperty2D.h"
14 #include "vtkRenderWindow.h"
16 #include "vtkRenderer.h"
17 #include "vtkSphereSource.h"
18 #include "vtkTextMapper.h"
19 #include "vtkTextProperty.h"
20 
21 VTK_ABI_NAMESPACE_BEGIN
22 
23 // starting point in viewport coordinate. X = Y = 30
24 static constexpr int START_POINT = 30;
25 static constexpr int END_POINT = 270;
26 
31 {
32 public:
35 
36  bool CompareLabelMapperString(const std::vector<std::string>& strings)
37  {
38  int nbOfLabels = this->NumberOfLabelsBuilt;
39  if (nbOfLabels != static_cast<int>(strings.size()))
40  {
41  vtkErrorMacro(
42  "Wrong number of labels strings: has " << nbOfLabels << " instead of " << strings.size());
43  return false;
44  }
45  for (int index = 0; index < nbOfLabels; index++)
46  {
47  vtkTextMapper* mapper = this->GetLabelMappers()[index];
48  std::string label = mapper->GetInput();
49  if (label != strings[index])
50  {
51  vtkErrorMacro("Wrong label: <" << label << "> instead of <" << strings[index] << ">");
52  return false;
53  }
54  }
55  return true;
56  }
57 };
58 
63  vtkAxisActor2D* axis, vtkRenderWindow* window, vtkPoints* expectedPoints)
64 {
65  window->Render();
67 
68  vtkNew<vtkPolyData> ticks;
69  ticks->SetPoints(points);
70  if (ticks->GetNumberOfPoints() == 0 && expectedPoints->GetNumberOfPoints() == 0)
71  {
72  // ComparePoints raises error with empty vtkPoints, shortcuts it.
73  return true;
74  }
75 
76  vtkNew<vtkPolyData> expectedTicks;
77  expectedTicks->SetPoints(expectedPoints);
78  return vtkTestUtilities::ComparePoints(ticks, expectedTicks);
79 }
80 
81 //------------------------------------------------------------------------------
82 inline void SetupPipeline(vtkAxisActor2D* axis, vtkRenderWindow* window)
83 {
84  // create a diagonal in render view, with some margins
85  axis->SetPoint1(0.1, 0.1);
86  axis->SetPoint2(0.9, 0.9);
87 
88  vtkNew<vtkSphereSource> sphereSource;
89  vtkNew<vtkPolyDataMapper> sphereMapper;
90  sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
91  vtkNew<vtkActor> sphereActor;
92  sphereActor->SetMapper(sphereMapper);
93 
94  vtkNew<vtkRenderer> renderer;
95  renderer->AddActor(axis);
96  renderer->AddActor(sphereActor);
98 
99  window->SetSize(300, 300);
100  window->AddRenderer(renderer);
101  window->Render();
102 }
103 
104 VTK_ABI_NAMESPACE_END
105 #endif
void AddActor(vtkProp *p)
Add/Remove different types of props to the renderer.
vtkIdType GetNumberOfPoints() override
See vtkDataSet for additional information.
Definition: vtkPointSet.h:285
static vtkAxisActor2DMock * New()
static constexpr int END_POINT
vtkAlgorithmOutput * GetOutputPort(int index)
Get a proxy object corresponding to the given output port of this algorithm.
vtkPoints * GetTickPositions()
Return the positions of ticks along the axis.
virtual void SetPoints(vtkPoints *)
Specify point array to define point coordinates.
void SetupPipeline(vtkAxisActor2D *axis, vtkRenderWindow *window)
Create an axis with tick marks and labels.
bool CompareTicksPosition(vtkAxisActor2D *axis, vtkRenderWindow *window, vtkPoints *expectedPoints)
Compare the provided vtkPoints with TickPositions from axis.
virtual void AddRenderer(vtkRenderer *)
Add a renderer to the list of renderers.
void Render() override
Ask each renderer owned by this RenderWindow to render its image and synchronize this process...
virtual char * GetInput()
The input text string to the mapper.
vtkCamera * GetActiveCamera()
Get the current camera.
2D text annotation
Definition: vtkTextMapper.h:39
virtual void SetSize(int width, int height)
Set the size (width and height) of the rendering window in screen coordinates (in pixels)...
#define VTK_STANDARD_NEW_BODY(thisClass)
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
virtual void SetPoint2(double x[2])
Specify the position of the second point defining the axis.
virtual void ParallelProjectionOn()
Set/Get the value of the ParallelProjection instance variable.
virtual void SetPoint1(double x[2])
Specify the position of the first point defining the axis.
vtkIdType GetNumberOfPoints() const
Return number of points in array.
Definition: vtkPoints.h:129
create a window for renderers to draw into
static constexpr int START_POINT
bool CompareLabelMapperString(const std::vector< std::string > &strings)
virtual void SetMapper(vtkMapper *)
This is the method that is used to connect an actor to the end of a visualization pipeline...
Mock vtkAxisActor2D to access inner member for comparison.
virtual std::vector< vtkSmartPointer< vtkTextMapper > > GetLabelMappers()
Get the label mappers.
represent and manipulate 3D points
Definition: vtkPoints.h:30