1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkPolyPointSource.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkPolyPointSource.h"
16 
17 #include "vtkCellArray.h"
18 #include "vtkIdList.h"
19 #include "vtkInformation.h"
20 #include "vtkInformationVector.h"
21 #include "vtkObjectFactory.h"
22 #include "vtkSmartPointer.h"
23 
24 //------------------------------------------------------------------------------
25 vtkStandardNewMacro(vtkPolyPointSource);
26 
27 vtkCxxSetObjectMacro(vtkPolyPointSource, Points, vtkPoints);
28 
29 //------------------------------------------------------------------------------
vtkPolyPointSource()30 vtkPolyPointSource::vtkPolyPointSource()
31 {
32   this->Points = nullptr;
33 
34   this->SetNumberOfInputPorts(0);
35 }
36 
37 //------------------------------------------------------------------------------
~vtkPolyPointSource()38 vtkPolyPointSource::~vtkPolyPointSource()
39 {
40   if (this->Points)
41   {
42     this->Points->Delete();
43   }
44 }
45 
46 //------------------------------------------------------------------------------
GetMTime()47 vtkMTimeType vtkPolyPointSource::GetMTime()
48 {
49   vtkMTimeType mTime = this->Superclass::GetMTime();
50   vtkMTimeType time;
51 
52   if (this->Points != nullptr)
53   {
54     time = this->Points->GetMTime();
55     mTime = (time > mTime ? time : mTime);
56   }
57 
58   return mTime;
59 }
60 
61 //------------------------------------------------------------------------------
SetNumberOfPoints(vtkIdType numPoints)62 void vtkPolyPointSource::SetNumberOfPoints(vtkIdType numPoints)
63 {
64   if (!this->Points)
65   {
66     vtkPoints* pts = vtkPoints::New(VTK_DOUBLE);
67     this->SetPoints(pts);
68     this->Points = pts;
69     pts->Delete();
70   }
71 
72   if (numPoints != this->GetNumberOfPoints())
73   {
74     this->Points->SetNumberOfPoints(numPoints);
75     this->Modified();
76   }
77 }
78 
79 //------------------------------------------------------------------------------
GetNumberOfPoints()80 vtkIdType vtkPolyPointSource::GetNumberOfPoints()
81 {
82   if (this->Points)
83   {
84     return this->Points->GetNumberOfPoints();
85   }
86 
87   return 0;
88 }
89 
90 //------------------------------------------------------------------------------
Resize(vtkIdType numPoints)91 void vtkPolyPointSource::Resize(vtkIdType numPoints)
92 {
93   if (!this->Points)
94   {
95     this->SetNumberOfPoints(numPoints);
96   }
97 
98   if (numPoints != this->GetNumberOfPoints())
99   {
100     this->Points->Resize(numPoints);
101     this->Modified();
102   }
103 }
104 
105 //------------------------------------------------------------------------------
SetPoint(vtkIdType id,double x,double y,double z)106 void vtkPolyPointSource::SetPoint(vtkIdType id, double x, double y, double z)
107 {
108   if (!this->Points)
109   {
110     return;
111   }
112 
113   if (id >= this->Points->GetNumberOfPoints())
114   {
115     vtkErrorMacro(<< "point id " << id << " is larger than the number of points");
116     return;
117   }
118 
119   this->Points->SetPoint(id, x, y, z);
120   this->Modified();
121 }
122 
123 //------------------------------------------------------------------------------
RequestData(vtkInformation * vtkNotUsed (request),vtkInformationVector ** vtkNotUsed (inputVector),vtkInformationVector * outputVector)124 int vtkPolyPointSource::RequestData(vtkInformation* vtkNotUsed(request),
125   vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
126 {
127   // get the info object
128   vtkInformation* outInfo = outputVector->GetInformationObject(0);
129 
130   // get the output
131   vtkPolyData* output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
132 
133   vtkIdType numPoints = this->GetNumberOfPoints();
134   vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
135   pointIds->SetNumberOfIds(numPoints);
136   for (vtkIdType i = 0; i < numPoints; ++i)
137   {
138     pointIds->SetId(i, i);
139   }
140 
141   vtkSmartPointer<vtkCellArray> PolyPoint = vtkSmartPointer<vtkCellArray>::New();
142   PolyPoint->InsertNextCell(pointIds);
143 
144   output->SetPoints(this->Points);
145   output->SetVerts(PolyPoint);
146 
147   return 1;
148 }
149 
150 //------------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)151 void vtkPolyPointSource::PrintSelf(ostream& os, vtkIndent indent)
152 {
153   this->Superclass::PrintSelf(os, indent);
154 
155   os << indent << "Points: " << this->Points << "\n";
156 }
157