TTK
Loading...
Searching...
No Matches
ttkCinemaDarkroomCamera.cpp
Go to the documentation of this file.
2
3#include <vtkCamera.h>
4#include <vtkDoubleArray.h>
5#include <vtkInformation.h>
6#include <vtkIntArray.h>
7#include <vtkObjectFactory.h>
8#include <vtkPointData.h>
9#include <vtkUnstructuredGrid.h>
10
11// #include <pqActiveObjects.h>
12// #include <vtkSMRenderViewProxy.h>
13
14#include <vtkPythonInterpreter.h>
15
16#include <ttkUtils.h>
17
19
21 this->setDebugMsgPrefix("CinemaDarkroomCamera");
22
23 this->SetNumberOfInputPorts(0);
24 this->SetNumberOfOutputPorts(1);
25}
26
28
30 return 0;
31}
32
34 vtkInformation *info) {
35 if(port == 0) {
36 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
37 return 1;
38 }
39 return 0;
40}
41
43 ttk::Timer timer;
44 this->printMsg(
45 "Updating Camera Parameters", 0, 0, 1, ttk::debug::LineMode::REPLACE);
46
47 std::string const code(R"(
48from paraview.simple import GetActiveView
49from paraview.simple import FindSource
50
51self = FindSource("TTKDarkroomCamera1")
52
53view = GetActiveView()
54if view and self:
55 self.Position = view.CameraPosition
56 self.Up = view.CameraViewUp
57 self.FocalPoint = view.CameraFocalPoint
58)");
59
60 vtkPythonInterpreter::RunSimpleString(code.data());
61
62 // auto& activeObjects = pqActiveObjects::instance();
63
64 // auto view = activeObjects.activeView();
65 // if(!view){
66 // this->printErr("Unable to retrieve active view.");
67 // return 0;
68 // }
69
70 // auto proxy = dynamic_cast<vtkSMRenderViewProxy*>(view->getViewProxy());
71 // if(!proxy) {
72 // this->printErr("Unable to cast to vtkSMRenderViewProxy.");
73 // return 0;
74 // }
75
76 // auto camera = proxy->GetActiveCamera();
77
78 // this->SetUp( camera->GetViewUp() );
79 // this->SetFocalPoint( camera->GetFocalPoint() );
80 // this->SetPosition( camera->GetPosition() );
81
82 this->printMsg("Updating Camera Parameters", 1, timer.getElapsedTime(), 1);
83
84 this->Modified();
85
86 return 1;
87}
88
90 vtkInformation *ttkNotUsed(request),
91 vtkInformationVector **ttkNotUsed(inputVector),
92 vtkInformationVector *outputVector) {
93
94 ttk::Timer timer;
95 this->printMsg("Generating Camera", 0, 0, 1, ttk::debug::LineMode::REPLACE);
96
97 auto output = vtkUnstructuredGrid::GetData(outputVector);
98
99 // Points
100 {
101 auto points = vtkSmartPointer<vtkPoints>::New();
102 points->InsertNextPoint(this->Position);
103 output->SetPoints(points);
104 }
105
106 // Cells
107 {
109 auto offsetArray = vtkSmartPointer<vtkIntArray>::New();
110 {
111 offsetArray->SetNumberOfTuples(2);
112 auto offsetArrayData
113 = static_cast<int *>(ttkUtils::GetVoidPointer(offsetArray));
114 offsetArrayData[0] = 0;
115 offsetArrayData[1] = 1;
116 }
117
118 auto connectivityArray = vtkSmartPointer<vtkIntArray>::New();
119 {
120 connectivityArray->SetNumberOfTuples(1);
121 auto connectivityArrayData
122 = static_cast<int *>(ttkUtils::GetVoidPointer(connectivityArray));
123 connectivityArrayData[0] = 0;
124 }
125
126 cells->SetData(offsetArray, connectivityArray);
127 output->SetCells(VTK_VERTEX, cells);
128 }
129
130 // Point Data
131 auto generateArray
132 = [](vtkPointData *pd, const std::string &name, const double *data) {
134 array->SetName(name.data());
135 array->SetNumberOfComponents(3);
136 array->SetNumberOfTuples(1);
137 auto arrayData = static_cast<double *>(ttkUtils::GetVoidPointer(array));
138 arrayData[0] = data[0];
139 arrayData[1] = data[1];
140 arrayData[2] = data[2];
141 pd->AddArray(array);
142 };
143 auto pd = output->GetPointData();
144 generateArray(pd, "CamUp", this->Up);
145 generateArray(pd, "CamFocalPoint", this->FocalPoint);
146
147 this->printMsg("Generating Camera", 1, timer.getElapsedTime(), 1);
148
149 return 1;
150}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
This source generates a Cinema Darkroom Camera.
int FillOutputPortInformation(int port, vtkInformation *info) override
~ttkCinemaDarkroomCamera() override
int FillInputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Definition ttkUtils.cpp:226
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
double getElapsedTime()
Definition Timer.h:15
vtkStandardNewMacro(ttkCinemaDarkroomCamera)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)