ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
vtkAnnotationBoxSource.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 <cmath>
11 
12 #include "vtkCellArray.h"
13 #include "vtkCellData.h"
14 #include "vtkFloatArray.h"
15 #include "vtkInformation.h"
16 #include "vtkInformationVector.h"
17 #include "vtkObjectFactory.h"
18 #include "vtkPointData.h"
19 #include "vtkPoints.h"
20 #include "vtkPolyData.h"
21 #include "vtkStreamingDemandDrivenPipeline.h"
22 
24 
26  this->SetNumberOfInputPorts(0);
27 }
28 
30  vtkInformation *vtkNotUsed(request),
31  vtkInformationVector **vtkNotUsed(inputVector),
32  vtkInformationVector *outputVector) {
33  // get the info object
34  vtkInformation *outInfo = outputVector->GetInformationObject(0);
35 
36  // get the ouptut
37  vtkPolyData *output = vtkPolyData::SafeDownCast(
38  outInfo->Get(vtkDataObject::DATA_OBJECT()));
39 
40  int numPolys = 6, numPts = 8;
41  vtkIdType pts[4], pts_[2];
42  vtkPoints *newPoints;
43  vtkCellArray *newPolys;
44  vtkCellArray *newLines;
45 
46  //
47  // Set things up; allocate memory
48  //
49  newPoints = vtkPoints::New(VTK_DOUBLE);
50  newPoints->SetNumberOfPoints(numPts);
51  double bounds[6] = {-0.5, 0.5, -0.5, 0.5, -0.5, 0.5};
52  newPoints->SetPoint(0, bounds[0], bounds[2], bounds[4]);
53  newPoints->SetPoint(1, bounds[1], bounds[2], bounds[4]);
54  newPoints->SetPoint(2, bounds[1], bounds[3], bounds[4]);
55  newPoints->SetPoint(3, bounds[0], bounds[3], bounds[4]);
56  newPoints->SetPoint(4, bounds[0], bounds[2], bounds[5]);
57  newPoints->SetPoint(5, bounds[1], bounds[2], bounds[5]);
58  newPoints->SetPoint(6, bounds[1], bounds[3], bounds[5]);
59  newPoints->SetPoint(7, bounds[0], bounds[3], bounds[5]);
60 
61  // faces
62  newPolys = vtkCellArray::New();
63  newPolys->Allocate(newPolys->EstimateSize(numPolys, 4));
64  pts[0] = 1;
65  pts[1] = 2;
66  pts[2] = 6;
67  pts[3] = 5; // +x
68  newPolys->InsertNextCell(4, pts);
69  pts[0] = 3;
70  pts[1] = 0;
71  pts[2] = 4;
72  pts[3] = 7; // -x
73  newPolys->InsertNextCell(4, pts);
74  pts[0] = 0;
75  pts[1] = 1;
76  pts[2] = 5;
77  pts[3] = 4; // +z
78  newPolys->InsertNextCell(4, pts);
79  pts[0] = 2;
80  pts[1] = 3;
81  pts[2] = 7;
82  pts[3] = 6; // -z
83  newPolys->InsertNextCell(4, pts);
84  pts[0] = 0;
85  pts[1] = 3;
86  pts[2] = 2;
87  pts[3] = 1; // -y
88  newPolys->InsertNextCell(4, pts);
89  pts[0] = 4;
90  pts[1] = 5;
91  pts[2] = 6;
92  pts[3] = 7; // +y
93  newPolys->InsertNextCell(4, pts);
94 
95  // lines
96  newLines = vtkCellArray::New();
97  newLines->Allocate(newLines->EstimateSize(12, 2));
98  pts_[0] = 0;
99  pts_[1] = 4; // the -x face
100  newLines->InsertNextCell(2, pts_);
101  pts_[0] = 4;
102  pts_[1] = 7;
103  newLines->InsertNextCell(2, pts_);
104  pts_[0] = 7;
105  pts_[1] = 3; // the +x face
106  newLines->InsertNextCell(2, pts_);
107  pts_[0] = 3;
108  pts_[1] = 0;
109  newLines->InsertNextCell(2, pts_);
110  pts_[0] = 2;
111  pts_[1] = 6; // the -y face
112  newLines->InsertNextCell(2, pts_);
113  pts_[0] = 6;
114  pts_[1] = 5;
115  newLines->InsertNextCell(2, pts_);
116  pts_[0] = 5;
117  pts_[1] = 1; // the +y face
118  newLines->InsertNextCell(2, pts_);
119  pts_[0] = 1;
120  pts_[1] = 2;
121  newLines->InsertNextCell(2, pts_);
122  pts_[0] = 0;
123  pts_[1] = 1; // the -z face
124  newLines->InsertNextCell(2, pts_);
125  pts_[0] = 4;
126  pts_[1] = 5;
127  newLines->InsertNextCell(2, pts_);
128  pts_[0] = 7;
129  pts_[1] = 6; // the +Z face
130  newLines->InsertNextCell(2, pts_);
131  pts_[0] = 3;
132  pts_[1] = 2;
133  newLines->InsertNextCell(2, pts_);
134 
135  //
136  // Update ourselves and release memory
137  //
138  output->SetPoints(newPoints);
139  newPoints->Delete();
140  output->SetLines(newLines);
141  newLines->Delete();
142  newPolys->Squeeze();
143  output->SetPolys(newPolys);
144  newPolys->Delete();
145 
146  return 1;
147 }
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkStandardNewMacro(vtkAnnotationBoxSource)