-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvtkLASReader.cxx
152 lines (129 loc) · 5.11 KB
/
vtkLASReader.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "vtkLASReader.h"
vtkStandardNewMacro(vtkLASReader)
//----------------------------------------------------------------------------
unsigned char vtkLASReader::ClassificationColorMap[][3] = {
//{Red, Green, Blue}
{ 0, 0, 0}, //0 Created, Never Classified Black
{255, 0, 0}, //1 Unclassified Red
{145, 100, 45}, //2 Ground Brown
{ 0, 255, 0}, //3 Low Vegetation Light Green
{ 0, 160, 0}, //4 Medium Vegetation Medium Green
{ 0, 90, 255}, //5 High Vegetation Dark Green
{255, 255, 0}, //6 Building Yellow
{255, 140, 0}, //7 Low Point Orange
{255, 0, 255}, //8 Model Key-Point Purple
{ 0, 255, 255}, //9 Water Blue
};
//----------------------------------------------------------------------------
vtkLASReader::vtkLASReader()
{
this->FileName = NULL;
this->pointRecordsCount = 0;
this->VisualisationType = None;
this->Header = NULL;
this->SetNumberOfInputPorts(0);
this->SetNumberOfOutputPorts(1);
}
//----------------------------------------------------------------------------
vtkLASReader::~vtkLASReader()
{
if ( ! FileName )
delete[] FileName;
if ( ! Header )
delete Header;
}
//----------------------------------------------------------------------------
int vtkLASReader::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(request),
vtkInformationVector* outputVector)
{
// Get the info object
vtkInformation* outInfo = outputVector->GetInformationObject(0);
// Get the ouptut
vtkPolyData* output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
// Open LAS File for reading
std::ifstream ifs;
ifs.open(FileName, std::ios_base::binary | std::ios_base::in);
if ( ! ifs.is_open() )
{
vtkErrorMacro (<< "Unable to open File for reading in binary mode");
return VTK_ERROR;
}
// Read header data
liblas::ReaderFactory readerFactory;
liblas::Reader reader = readerFactory.CreateWithStream(ifs);
Header = new liblas::Header(reader.GetHeader());
pointRecordsCount = Header->GetPointRecordsCount();
vtkPolyData* pointsPolyData = vtkPolyData::New();
ReadPointRecordData(reader, pointsPolyData);
// Convert points to verts in output polydata
vtkVertexGlyphFilter* vertexFilter = vtkVertexGlyphFilter::New();
vertexFilter->SetInputData(pointsPolyData);
vertexFilter->Update();
output->ShallowCopy(vertexFilter->GetOutput());
return VTK_OK;
}
//----------------------------------------------------------------------------
void vtkLASReader::SetClassificationColor(ClassificationType type,
unsigned char red,
unsigned char green,
unsigned char blue)
{
if(type <= 0 || type > Water)
{
vtkErrorMacro (<< "Invalid type of Class Specified!");
return;
}
this->ClassificationColorMap[type][0] = red;
this->ClassificationColorMap[type][1] = green;
this->ClassificationColorMap[type][2] = blue;
}
//----------------------------------------------------------------------------
void vtkLASReader::SetClassificationColor(ClassificationType type, unsigned char color[])
{
this->SetClassificationColor(type, color[0], color[1], color[2]);
}
//----------------------------------------------------------------------------
void vtkLASReader::ReadPointRecordData(liblas::Reader &reader, vtkPolyData* pointsPolyData)
{
vtkPoints* points = vtkPoints::New();
vtkUnsignedCharArray* colors = vtkUnsignedCharArray::New();
colors->SetNumberOfComponents(3);
for ( int i= 0; i < pointRecordsCount && reader.ReadNextPoint(); i++)
{
liblas::Point const& p = reader.GetPoint();
points->InsertNextPoint(p.GetX() * Header->GetScaleX() * 2 + Header->GetOffsetX(),
p.GetY() * Header->GetScaleY() * 2 + Header->GetOffsetY(),
p.GetZ() * Header->GetScaleZ() * 2 + Header->GetOffsetZ());
unsigned char* color;
switch(VisualisationType)
{
case None:
break;
case Color:
color = new unsigned char[3];
color[0] = p.GetColor().GetRed() / 256;
color[1] = p.GetColor().GetGreen() / 256;
color[2] = p.GetColor().GetBlue() / 256;
colors->InsertNextTupleValue(color);
break;
case Classification:
colors->InsertNextTupleValue( vtkLASReader::ClassificationColorMap[ p.GetClassification().GetClass() ] );
break;
default:
break;
}
}
pointsPolyData->SetPoints(points);
if (VisualisationType)
{
pointsPolyData->GetPointData()->SetScalars(colors);
}
}
//----------------------------------------------------------------------------
void vtkLASReader::PrintSelf(ostream &os, vtkIndent indent)
{
Superclass::PrintSelf(os, indent);
os << "vtkLASReader" << std::endl;
os << "Filename: " << this->FileName << std::endl;
}