VTK  9.4.20241225
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
21VTK_ABI_NAMESPACE_BEGIN
22
23// starting point in viewport coordinate. X = Y = 30
24static constexpr int START_POINT = 30;
25static constexpr int END_POINT = 270;
26
31{
32public:
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->LabelMappers[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();
66 vtkPoints* points = axis->GetTickPositions();
67
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//------------------------------------------------------------------------------
82inline 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);
97 renderer->GetActiveCamera()->ParallelProjectionOn();
98
99 window->SetSize(300, 300);
100 window->AddRenderer(renderer);
101 window->Render();
102}
103
104VTK_ABI_NAMESPACE_END
105#endif
static constexpr int END_POINT
bool CompareTicksPosition(vtkAxisActor2D *axis, vtkRenderWindow *window, vtkPoints *expectedPoints)
Compare the provided vtkPoints with TickPositions from axis.
static constexpr int START_POINT
void SetupPipeline(vtkAxisActor2D *axis, vtkRenderWindow *window)
Mock vtkAxisActor2D to access inner member for comparison.
bool CompareLabelMapperString(const std::vector< std::string > &strings)
static vtkAxisActor2DMock * New()
Create an axis with tick marks and labels.
virtual void SetPoint1(double x[2])
Specify the position of the first point defining the axis.
vtkPoints * GetTickPositions()
Return the positions of ticks along the axis.
vtkTextMapper ** LabelMappers
virtual void SetPoint2(double x[2])
Specify the position of the second point defining the axis.
Allocate and hold a VTK object.
Definition vtkNew.h:167
represent and manipulate 3D points
Definition vtkPoints.h:139
vtkIdType GetNumberOfPoints() const
Return number of points in array.
Definition vtkPoints.h:231
create a window for renderers to draw into
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.
2D text annotation
virtual char * GetInput()
The input text string to the mapper.
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)