Skip to content
Snippets Groups Projects
Commit 5340dfd9 authored by Dan Lipsa's avatar Dan Lipsa
Browse files

Read the Point Data Record format from the header.

This determines the point scalar (classification or RGB)
parent 96bea510
No related branches found
No related tags found
No related merge requests found
......@@ -34,12 +34,13 @@ int TestLASReader(int argc, char **argv)
{
//const char* fileName = "Data/tp_manual_20160907131754_flt.las";
const char* fileName = "Data/test_buildings.las";
//const char* fileName = "Data/test_1.las";
//const char* fileName = "Data/test_3.las";
const char* path = vtkTestUtilities::ExpandDataFileName(argc, argv, fileName);
vtkNew<vtkLASReader> reader;
//Select source file
reader->SetFileName(path);
reader->SetVisualizationType(vtkLASReader::Classification);
//Read the output
reader->Update();
......
......@@ -29,6 +29,7 @@
#include <fstream>
#include <iostream>
#include <valarray>
vtkStandardNewMacro(vtkLASReader)
......@@ -51,7 +52,6 @@ vtkLASReader::vtkLASReader() :
{
this->FileName = NULL;
this->PointRecordsCount = 0;
this->VisualizationType = None;
this->Header = NULL;
this->SetNumberOfInputPorts(0);
......@@ -136,20 +136,30 @@ void vtkLASReader::ReadPointRecordData(liblas::Reader &reader, vtkPolyData* poin
vtkNew<vtkPoints> points;
vtkNew<vtkUnsignedCharArray> colors;
colors->SetNumberOfComponents(3);
std::valarray<double> scale = {
this->Header->GetScaleX(), this->Header->GetScaleY(), this->Header->GetScaleZ()
};
std::valarray<double> offset = {
this->Header->GetOffsetX(), this->Header->GetOffsetY(), this->Header->GetOffsetZ()
};
liblas::PointFormatName pointFormat = this->Header->GetDataFormatId();
std::cout << "PointFormat: " << pointFormat << std::endl;
for ( int i= 0; i < this->PointRecordsCount && reader.ReadNextPoint(); i++)
{
liblas::Point const& p = reader.GetPoint();
points->InsertNextPoint(p.GetX() * this->Header->GetScaleX() * 2 + this->Header->GetOffsetX(),
p.GetY() * this->Header->GetScaleY() * 2 + this->Header->GetOffsetY(),
p.GetZ() * this->Header->GetScaleZ() * 2 + this->Header->GetOffsetZ());
std::valarray<double> lasPoint = {
p.GetX(), p.GetY(), p.GetZ()
};
std::valarray<double> point = lasPoint * scale + offset;
points->InsertNextPoint(&lasPoint[0]);
unsigned char* color;
switch(this->VisualizationType)
switch(pointFormat)
{
case None:
break;
case Color:
case liblas::ePointFormat2:
case liblas::ePointFormat3:
case liblas::ePointFormat5:
{
unsigned char color[3];
color[0] = p.GetColor().GetRed() / 256;
......@@ -158,9 +168,13 @@ void vtkLASReader::ReadPointRecordData(liblas::Reader &reader, vtkPolyData* poin
colors->InsertNextTypedTuple(color);
}
break;
case Classification:
case liblas::ePointFormat0:
case liblas::ePointFormat1:
colors->InsertNextTypedTuple( this->ClassificationColorMap[p.GetClassification().GetClass()] );
break;
case liblas::ePointFormatUnknown:
default:
break;
}
......@@ -168,7 +182,7 @@ void vtkLASReader::ReadPointRecordData(liblas::Reader &reader, vtkPolyData* poin
pointsPolyData->SetPoints(points);
if (this->VisualizationType)
if (pointFormat != liblas::ePointFormatUnknown)
{
pointsPolyData->GetPointData()->SetScalars(colors);
}
......
......@@ -46,15 +46,6 @@ public:
vtkTypeMacro(vtkLASReader,vtkPolyDataAlgorithm);
virtual void PrintSelf(ostream &os, vtkIndent indent) override;
/**
* All the Visualization Types have been listed here
*/
enum VisualizationTypeConstants {
None = 0,
Color,
Classification
};
/**
* All the Classification Types according to LAS spec are listed here
*/
......@@ -77,11 +68,6 @@ public:
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
/**
* Accessor for Visualization Type
*/
vtkSetMacro(VisualizationType, VisualizationTypeConstants);
vtkGetMacro(VisualizationType, VisualizationTypeConstants);
/**
* Accessor for the LAS Header file
......@@ -116,7 +102,6 @@ protected:
unsigned char ClassificationColorMap[10][3];
int PointRecordsCount;
VisualizationTypeConstants VisualizationType;
liblas::Header* Header;
char* FileName;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment