ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
pointstopolydataconverter.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include <vtkDoubleArray.h>
11 #include <vtkPoints.h>
12 
13 #include "vtkutils.h"
14 
15 namespace VtkUtils {
16 
18  const QVector<Point3F>& points, const QVector<Tuple3ui>& vertices)
19  : m_points(points), m_vertices(vertices) {}
20 
22  if (m_points.isEmpty()) {
23  emit finished();
24  return;
25  }
26 
27  VtkUtils::vtkInitOnce(m_polyData);
28 
29  VTK_CREATE(vtkPoints, vtkpoints);
30  VTK_CREATE(vtkDoubleArray, scalarArray);
31  VTK_CREATE(vtkCellArray, cell_array);
32  scalarArray->SetName("scalar");
33 
34  int pointNum = static_cast<int>(m_points.size());
35  vtkpoints->SetNumberOfPoints(pointNum);
36 
37  for (int i = 0; i < pointNum; ++i) {
38  const Point3F& p3f = m_points.at(i);
39  vtkpoints->InsertPoint(i, p3f.x, p3f.y, p3f.z);
40  scalarArray->InsertTuple1(i, p3f.z); // z value as scalar
41  }
42 
43  for (int i = 0; i < m_vertices.size(); ++i) {
44  cell_array->InsertNextCell(3);
45  for (size_t j = 0; j < 3; j++)
46  cell_array->InsertCellPoint(m_vertices.at(i).u[j]);
47  }
48  if (!m_vertices.isEmpty()) {
49  m_polyData->SetPolys(cell_array);
50  }
51 
52  m_polyData->SetPoints(vtkpoints);
53  m_polyData->GetPointData()->SetScalars(scalarArray);
54 
55  emit finished();
56 }
57 
58 vtkPolyData* PointsToPolyDataConverter::polyData() const { return m_polyData; }
59 
60 } // namespace VtkUtils
int points
PointsToPolyDataConverter(const QVector< Point3F > &points, const QVector< Tuple3ui > &vertices=QVector< Tuple3ui >())
void vtkInitOnce(T **obj)
Definition: vtkutils.h:44
#define VTK_CREATE(type, name)