forked from midas-journal/midas-journal-709
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvtkRANSACPlaneData.cxx
executable file
·73 lines (63 loc) · 2.13 KB
/
vtkRANSACPlaneData.cxx
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
#include <vtkPolyData.h>
#include <vtkPlaneSource.h>
#include <vtkPoints.h>
#include <vtkSmartPointer.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkMath.h>
#include <vtkCellArray.h>
int main (int argc, char *argv[])
{
//verify command line arguments
if(argc != 2)
{
cout << "Required arguments: OutputFilename" << endl;
return EXIT_FAILURE;
}
//parse command line arguments
vtkstd::string outputFilename = argv[1];
vtkSmartPointer<vtkPlaneSource> planeSource = vtkSmartPointer<vtkPlaneSource>::New();
planeSource->SetCenter(1.0, 0.0, 0.0);
planeSource->SetNormal(1.0, 0.0, 0.0);
unsigned int res = 10;
planeSource->SetResolution(res, res);
planeSource->Update();
vtkPolyData* oldPolydata = planeSource->GetOutput();
vtkPoints* oldPoints = oldPolydata->GetPoints();
vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
//add erratic points and noise
double noise = .1;
for(unsigned int i = 0; i < oldPoints->GetNumberOfPoints(); i++)
{
double p[3];
oldPoints->GetPoint(i, p);
for(unsigned int j = 0; j < 3; j++)
{
p[j] = p[j] + vtkMath::Random(-noise, noise);
}
vtkIdType pid[1];
pid[0] = newPoints->InsertNextPoint(p[0], p[1], p[2]);
vertices->InsertNextCell ( 1,pid );
}
unsigned int numOutliers = oldPoints->GetNumberOfPoints() * .1;
for(unsigned int i = 0; i < numOutliers; i++)
{
double p[3];
for(unsigned int j = 0; j < 3; j++)
{
p[j] = vtkMath::Random(-5, 5);
}
vtkIdType pid[1];
pid[0] = newPoints->InsertNextPoint(p[0], p[1], p[2]);
vertices->InsertNextCell ( 1,pid );
}
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(newPoints);
polydata->SetVerts(vertices);
//write the output file with the estimated normals
vtkSmartPointer<vtkXMLPolyDataWriter> Writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
Writer->SetFileName(outputFilename.c_str());
Writer->SetInput(polydata);
Writer->Write();
return 0;
}