VTK  9.7.1
InteractorStyleTestUtils.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-License-Identifier: BSD-3-Clause
3 
4 #include "vtkCameraManipulator.h"
5 #include "vtkJoystickFly.h"
7 
8 #include <array>
9 #include <cmath>
10 #include <iostream>
11 
12 inline bool assertTuplesEqual(const std::array<double, 3>& expected,
13  const std::array<double, 3>& actual, const char* name, double tolerance = 1e-5)
14 {
15  bool success = true;
16  for (int i = 0; i < 3; i++)
17  {
18  if (std::abs(expected[i] - actual[i]) > tolerance)
19  {
20  std::cerr << "Mismatch in " << name << "[" << i << "] Expected: " << expected[i]
21  << ", Actual: " << actual[i] << std::endl;
22  success = false;
23  }
24  }
25  return success;
26 }
27 
29 {
30  int FramesSinceLeftButtonDown = 0;
31  int ReleaseLeftButtonAfterFrameCount = -1;
32 
33 public:
35  vtkJoystickFlyObserver() = default;
36  ~vtkJoystickFlyObserver() override = default;
38 
39  int GetFramesSinceLeftButtonDown() const { return this->FramesSinceLeftButtonDown; }
40  void ReleaseLeftButtonAfter(int frameCount)
41  {
42  this->ReleaseLeftButtonAfterFrameCount = frameCount;
43  }
44 
45  void Execute(vtkObject* vtkNotUsed(caller), unsigned long eventId, void* callData) override
46  {
48  {
49  return;
50  }
51  if (auto* interactor =
52  vtkRenderWindowInteractor::SafeDownCast(static_cast<vtkObjectBase*>(callData)))
53  {
54  this->FramesSinceLeftButtonDown++;
55  if (this->ReleaseLeftButtonAfterFrameCount > 0 &&
56  this->FramesSinceLeftButtonDown >= this->ReleaseLeftButtonAfterFrameCount)
57  {
58  interactor->InvokeEvent(vtkCommand::LeftButtonReleaseEvent);
59  }
60  interactor->ProcessEvents();
61  }
62  }
63 };
void Execute(vtkObject *caller, unsigned long eventId, void *callData) override
All derived classes of vtkCommand must implement this method.
abstract base class for most VTK objects
Definition: vtkObject.h:52
static vtkRenderWindowInteractor * SafeDownCast(vtkObjectBase *o)
~vtkJoystickFlyObserver() override=default
bool assertTuplesEqual(const std::array< double, 3 > &expected, const std::array< double, 3 > &actual, const char *name, double tolerance=1e-5)
superclass for callback/observer methods
Definition: vtkCommand.h:384
static vtkJoystickFlyObserver * New()
vtkJoystickFlyObserver()=default
void ReleaseLeftButtonAfter(int frameCount)