-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPointsSource.cpp
118 lines (101 loc) · 3.23 KB
/
PointsSource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "PointsSource.h"
#include "vtkPointSource.h"
#include "vtkCellArray.h"
#include "vtkMath.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include <iostream>
#include <float.h>
#include <math.h>
vtkStandardNewMacro(PointSource);
//----------------------------------------------------------------------------
PointSource::PointSource(vtkIdType numPts)
{
this->NumberOfPoints = (numPts > 0 ? numPts : 10);
this->SetNumberOfInputPorts(0);
this->points = vtkSmartPointer<vtkPoints>::New();
};
void PointSource::SetPoints(vtkSmartPointer<vtkPoints> *pts, int npts)
{
vtkIdType ni = 0;
double x[3];
for(vtkIdType i = 0; i < npts; i++)
{
ni = pts[i]->GetNumberOfPoints();
for(vtkIdType j = 0; j < ni; j++)
{
pts[i]->GetPoint(j, x);
this->points->InsertNextPoint(x);
}
}
this->NumberOfPoints = this->points->GetNumberOfPoints();
}
//----------------------------------------------------------------------------
int PointSource::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
// get the info object
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the ouptut
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkIdType i;
// double theta, rho, cosphi, sinphi, radius;
double x[3];
vtkPoints *newPoints;
vtkCellArray *newVerts;
newPoints = vtkPoints::New();
newPoints->Allocate(this->NumberOfPoints);
newVerts = vtkCellArray::New();
newVerts->Allocate(newVerts->EstimateSize(1,this->NumberOfPoints));
newVerts->InsertNextCell(this->NumberOfPoints);
for(i = 0; i < points->GetNumberOfPoints(); i++)
{
points->GetPoint(i, x);
newVerts->InsertCellPoint(newPoints->InsertNextPoint(x));
}
/*
if (this->Distribution == VTK_POINT_SHELL)
{ // only produce points on the surface of the sphere
for (i=0; i<this->NumberOfPoints; i++)
{
cosphi = 1 - 2*vtkMath::Random();
sinphi = sqrt(1 - cosphi*cosphi);
radius = this->Radius * sinphi;
theta = 2.0 * vtkMath::Pi() * vtkMath::Random();
x[0] = this->Center[0] + radius*cos(theta);
x[1] = this->Center[1] + radius*sin(theta);
x[2] = this->Center[2] + this->Radius*cosphi;
newVerts->InsertCellPoint(newPoints->InsertNextPoint(x));
}
}
else
{ // uniform distribution throughout the sphere volume
for (i=0; i<this->NumberOfPoints; i++)
{
cosphi = 1 - 2*vtkMath::Random();
sinphi = sqrt(1 - cosphi*cosphi);
rho = this->Radius*pow(vtkMath::Random(),0.33333333);
radius = rho * sinphi;
theta = 2.0 * vtkMath::Pi() * vtkMath::Random();
x[0] = this->Center[0] + radius*cos(theta);
x[1] = this->Center[1] + radius*sin(theta);
x[2] = this->Center[2] + rho*cosphi;
newVerts->InsertCellPoint(newPoints->InsertNextPoint(x));
}
}
*/
//
// Update ourselves and release memory
//
output->SetPoints(newPoints);
newPoints->Delete();
output->SetVerts(newVerts);
newVerts->Delete();
return 1;
}