18 #include <vtkCellArray.h>
19 #include <vtkCellData.h>
20 #include <vtkInformation.h>
21 #include <vtkInformationVector.h>
22 #include <vtkObjectFactory.h>
23 #include <vtkPointData.h>
24 #include <vtkPoints.h>
25 #include <vtkPolyData.h>
26 #include <vtkProperty.h>
27 #include <vtkSmartPointer.h>
28 #include <vtkStreamingDemandDrivenPipeline.h>
39 this->SetNumberOfInputPorts(0);
49 this->Superclass::PrintSelf(os, indent);
58 os << indent <<
"== Polyline =="
60 int numPoints = polyline->getNumberOfPoints();
61 for (
int i = 0; i < numPoints; i++)
64 os << indent <<
"Point " << i <<
" (" << point[0] <<
", "
65 << point[1] <<
", " << point[2] <<
")\n";
71 vtkInformationVector** inputVector,
72 vtkInformationVector* outputVector)
83 ERR(
"VtkPolylineSource::RequestData(): Size of polyline vector is 0");
87 vtkSmartPointer<vtkInformation> outInfo =
88 outputVector->GetInformationObject(0);
89 vtkSmartPointer<vtkPolyData> output =
90 vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
92 vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
93 vtkSmartPointer<vtkCellArray> newLines =
94 vtkSmartPointer<vtkCellArray>::New();
99 if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) >
105 vtkSmartPointer<vtkIntArray> plyIDs = vtkSmartPointer<vtkIntArray>::New();
106 plyIDs->SetNumberOfComponents(1);
107 plyIDs->SetName(
"PolylineIDs");
109 unsigned lastMaxIndex(0);
110 const std::size_t nPolylines(
_polylines->size());
111 for (std::size_t j = 0; j < nPolylines; j++)
113 const int numPoints = (*_polylines)[j]->getNumberOfPoints();
114 const bool isClosed = (*_polylines)[j]->isClosed();
117 const int numVerts = (isClosed) ? numPoints - 1 : numPoints;
118 for (
int i = 0; i < numVerts; i++)
121 const double* coords = point->
getCoords();
122 newPoints->InsertNextPoint(coords);
126 newLines->InsertNextCell(numPoints);
127 plyIDs->InsertNextValue(j);
128 for (
int i = 0; i < numVerts; i++)
130 newLines->InsertCellPoint(i + lastMaxIndex);
135 newLines->InsertCellPoint(lastMaxIndex);
138 lastMaxIndex += numVerts;
141 output->SetPoints(newPoints);
142 output->SetLines(newLines);
143 output->GetCellData()->AddArray(plyIDs);
144 output->GetCellData()->SetActiveAttribute(
"PolylineIDs",
145 vtkDataSetAttributes::SCALARS);
153 vtkInformationVector** ,
154 vtkInformationVector* )
Definition of the Color class.
void ERR(char const *fmt, Args const &... args)
Definition of the PolyLine class.
vtkStandardNewMacro(VtkPolylinesSource)
Definition of the VtkPolylinesSource class.
const T * getCoords() const
vtkProperty * GetProperties() const
Returns the vtk properties.
VtkPolylinesSource is a VTK source object for the visualisation of polyline data. As a vtkPolyDataAlg...
int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
~VtkPolylinesSource() override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Computes the polygonal data object.
const std::vector< GeoLib::Polyline * > * _polylines
The polylines to visualize.
void SetUserProperty(QString name, QVariant value) override
Sets a user property. This should be implemented by subclasses.
void PrintSelf(ostream &os, vtkIndent indent) override
Prints its data on a stream.
std::array< unsigned char, 4 > Color
Color getRandomColor()
Returns a random RGB colour.