Loading [MathJax]/extensions/tex2jax.js
OGS
VtkPointsSource.cpp
Go to the documentation of this file.
1 
15 #include "VtkPointsSource.h"
16 
17 #include <vtkCellArray.h>
18 #include <vtkCellData.h>
19 #include <vtkInformation.h>
20 #include <vtkInformationVector.h>
21 #include <vtkObjectFactory.h>
22 #include <vtkPointData.h>
23 #include <vtkPoints.h>
24 #include <vtkPolyData.h>
25 #include <vtkProperty.h>
26 #include <vtkSmartPointer.h>
27 #include <vtkStreamingDemandDrivenPipeline.h>
28 
30 #include "BaseLib/Logging.h"
31 
33 
35 {
36  _removable = false; // From VtkAlgorithmProperties
37  this->SetNumberOfInputPorts(0);
38 
40  GetProperties()->SetColor(c[0] / 255.0, c[1] / 255.0, c[2] / 255.0);
41 }
42 
43 void VtkPointsSource::PrintSelf(ostream& os, vtkIndent indent)
44 {
45  this->Superclass::PrintSelf(os, indent);
46 
47  if (_points->empty())
48  {
49  return;
50  }
51 
52  os << indent << "== VtkPointsSource =="
53  << "\n";
54 
55  int i = 0;
56  for (auto point : *_points)
57  {
58  os << indent << "Point " << i << " (" << (*point)[0] << ", "
59  << (*point)[1] << ", " << (*point)[2] << ")\n";
60  i++;
61  }
62 }
63 
64 int VtkPointsSource::RequestData(vtkInformation* request,
65  vtkInformationVector** inputVector,
66  vtkInformationVector* outputVector)
67 {
68  (void)request;
69  (void)inputVector;
70 
71  if (!_points)
72  {
73  return 0;
74  }
75  int numPoints = _points->size();
76  if (numPoints == 0)
77  {
78  ERR("VtkPointsSource::RequestData(): Size of point vector is 0");
79  return 0;
80  }
81 
82  vtkSmartPointer<vtkInformation> outInfo =
83  outputVector->GetInformationObject(0);
84  vtkSmartPointer<vtkPolyData> output =
85  vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
86 
87  vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
88  vtkSmartPointer<vtkCellArray> newVerts =
89  vtkSmartPointer<vtkCellArray>::New();
90  newPoints->SetNumberOfPoints(numPoints);
91  newVerts->Allocate(numPoints);
92 
93  vtkSmartPointer<vtkIntArray> pointIDs = vtkSmartPointer<vtkIntArray>::New();
94  pointIDs->SetNumberOfComponents(1);
95  pointIDs->SetNumberOfValues(numPoints);
96  pointIDs->SetName("PointIDs");
97 
98  if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) >
99  0)
100  {
101  return 1;
102  }
103 
104  // Generate points and vertices
105  unsigned i = 0;
106  for (auto point : *_points)
107  {
108  double coords[3] = {(*point)[0], (*point)[1], (*point)[2]};
109  newPoints->SetPoint(i, coords);
110  newVerts->InsertNextCell(1);
111  newVerts->InsertCellPoint(i);
112 
113  pointIDs->SetValue(i, i);
114  i++;
115  }
116 
117  output->SetPoints(newPoints);
118  output->SetVerts(newVerts);
119  output->GetCellData()->AddArray(pointIDs);
120  output->GetCellData()->SetActiveAttribute("PointIDs",
121  vtkDataSetAttributes::SCALARS);
122 
123  return 1;
124 }
125 
126 int VtkPointsSource::RequestInformation(vtkInformation* /*request*/,
127  vtkInformationVector** /*inputVector*/,
128  vtkInformationVector* /*outputVector*/)
129 {
130  return 1;
131 }
132 
133 void VtkPointsSource::SetUserProperty(QString name, QVariant value)
134 {
135  Q_UNUSED(name);
136  Q_UNUSED(value);
137 }
Definition of the Color class.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
vtkStandardNewMacro(VtkPointsSource)
Definition of the VtkPointsSource class.
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
std::array< unsigned char, 4 > Color
Definition: Color.h:24
Color getRandomColor()
Returns a random RGB colour.
Definition: Color.cpp:29