OGS
VtkPointsSource.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "VtkPointsSource.h"
5
6#include <vtkCellArray.h>
7#include <vtkCellData.h>
8#include <vtkInformation.h>
9#include <vtkInformationVector.h>
10#include <vtkObjectFactory.h>
11#include <vtkPointData.h>
12#include <vtkPoints.h>
13#include <vtkPolyData.h>
14#include <vtkProperty.h>
15#include <vtkSmartPointer.h>
16#include <vtkStreamingDemandDrivenPipeline.h>
17
19#include "BaseLib/Logging.h"
20
22
24{
25 _removable = false; // From VtkAlgorithmProperties
26 this->SetNumberOfInputPorts(0);
27
29 GetProperties()->SetColor(c[0] / 255.0, c[1] / 255.0, c[2] / 255.0);
30}
31
32void VtkPointsSource::PrintSelf(ostream& os, vtkIndent indent)
33{
34 this->Superclass::PrintSelf(os, indent);
35
36 if (_points->empty())
37 {
38 return;
39 }
40
41 os << indent << "== VtkPointsSource =="
42 << "\n";
43
44 int i = 0;
45 for (auto point : *_points)
46 {
47 os << indent << "Point " << i << " (" << (*point)[0] << ", "
48 << (*point)[1] << ", " << (*point)[2] << ")\n";
49 i++;
50 }
51}
52
53int VtkPointsSource::RequestData(vtkInformation* request,
54 vtkInformationVector** inputVector,
55 vtkInformationVector* outputVector)
56{
57 (void)request;
58 (void)inputVector;
59
60 if (!_points)
61 {
62 return 0;
63 }
64 int numPoints = _points->size();
65 if (numPoints == 0)
66 {
67 ERR("VtkPointsSource::RequestData(): Size of point vector is 0");
68 return 0;
69 }
70
71 vtkSmartPointer<vtkInformation> outInfo =
72 outputVector->GetInformationObject(0);
73 vtkSmartPointer<vtkPolyData> output =
74 vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
75
76 vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
77 vtkSmartPointer<vtkCellArray> newVerts =
78 vtkSmartPointer<vtkCellArray>::New();
79 newPoints->SetNumberOfPoints(numPoints);
80 newVerts->Allocate(numPoints);
81
82 vtkSmartPointer<vtkIntArray> pointIDs = vtkSmartPointer<vtkIntArray>::New();
83 pointIDs->SetNumberOfComponents(1);
84 pointIDs->SetNumberOfValues(numPoints);
85 pointIDs->SetName("PointIDs");
86
87 if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) >
88 0)
89 {
90 return 1;
91 }
92
93 // Generate points and vertices
94 unsigned i = 0;
95 for (auto point : *_points)
96 {
97 double coords[3] = {(*point)[0], (*point)[1], (*point)[2]};
98 newPoints->SetPoint(i, coords);
99 newVerts->InsertNextCell(1);
100 newVerts->InsertCellPoint(i);
101
102 pointIDs->SetValue(i, i);
103 i++;
104 }
105
106 output->SetPoints(newPoints);
107 output->SetVerts(newVerts);
108 output->GetCellData()->AddArray(pointIDs);
109 output->GetCellData()->SetActiveAttribute("PointIDs",
110 vtkDataSetAttributes::SCALARS);
111
112 return 1;
113}
114
115int VtkPointsSource::RequestInformation(vtkInformation* /*request*/,
116 vtkInformationVector** /*inputVector*/,
117 vtkInformationVector* /*outputVector*/)
118{
119 return 1;
120}
121
122void VtkPointsSource::SetUserProperty(QString name, QVariant value)
123{
124 Q_UNUSED(name);
125 Q_UNUSED(value);
126}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
vtkStandardNewMacro(VtkPointsSource)
vtkProperty * GetProperties() const
Returns the vtk properties.
VtkPointsSource is a VTK source object for the visualization of point data. As a vtkPolyDataAlgorithm...
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Computes the polygonal data object.
void SetUserProperty(QString name, QVariant value) override
Sets a user property. This should be implemented by subclasses.
const std::vector< GeoLib::Point * > * _points
The points to visualize.
void PrintSelf(ostream &os, vtkIndent indent) override
Prints its data on a stream.
int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Color getRandomColor()
Returns a random RGB colour.
Definition Color.cpp:18
std::array< unsigned char, 4 > Color
Definition Color.h:12