18 #ifndef __otbPointSetFileReader_txx
19 #define __otbPointSetFileReader_txx
24 #include <liblas/capi/liblas.h>
32 template <
class TOutputPo
intSet>
36 m_NumberOfPoints = -1;
43 template <
class TOutputPo
intSet>
49 template <
class TOutputPo
intSet>
54 typename TOutputPointSet::Pointer output = this->GetOutput();
56 otbDebugMacro(<<
"Reading file for GenerateOutputInformation()" << m_FileName);
65 this->TestFileExistanceAndReadability();
67 LASReaderH reader = LASReader_Create(m_FileName.c_str());
68 LASHeaderH header = LASReader_GetHeader(reader);
70 otbDebugMacro(<<
"Signature: " << LASHeader_GetFileSignature(header));
71 otbDebugMacro(<<
"Points count: " << LASHeader_GetPointRecordsCount(header));
73 m_NumberOfPoints = LASHeader_GetPointRecordsCount(header);
75 m_MinX = LASHeader_GetMinX(header);
76 m_MaxX = LASHeader_GetMaxX(header);
77 m_MinY = LASHeader_GetMinY(header);
78 m_MaxY = LASHeader_GetMaxY(header);
80 LASReader_Destroy(reader);
83 template <
class TOutputPo
intSet>
89 if (!itksys::SystemTools::FileExists(m_FileName.c_str()))
92 std::ostringstream msg;
93 msg <<
"The file doesn't exist. "
94 << std::endl <<
"Filename = " << m_FileName
102 std::ifstream readTester;
103 readTester.open(m_FileName.c_str());
104 if (readTester.fail())
107 std::ostringstream msg;
108 msg <<
"The file couldn't be opened for reading. "
109 << std::endl <<
"Filename: " << m_FileName
119 template <
class TOutputPo
intSet>
123 typename TOutputPointSet::Pointer output = this->GetOutput();
125 LASReaderH reader = LASReader_Create(m_FileName.c_str());
126 LASHeaderH header = LASReader_GetHeader(reader);
128 otbDebugMacro(<<
"Signature: " << LASHeader_GetFileSignature(header));
129 otbDebugMacro(<<
"Points count: " << LASHeader_GetPointRecordsCount(header));
131 m_NumberOfPoints = LASHeader_GetPointRecordsCount(header);
134 if (PointType::PointDimension == 2)
136 LASPointH pt = LASPoint_Create();
137 while ((pt = LASReader_GetNextPoint(reader)))
141 point[0] = LASPoint_GetX(pt);
142 point[1] = LASPoint_GetY(pt);
144 unsigned long i = output->GetNumberOfPoints();
145 output->SetPoint(i, point);
148 V =
static_cast<PixelType>(LASPoint_GetZ(pt));
149 output->SetPointData(i, V);
153 else if (PointType::PointDimension == 3)
155 LASPointH p = LASPoint_Create();
156 while ((p = LASReader_GetNextPoint(reader)))
161 point[0] = LASPoint_GetX(p);
162 point[1] = LASPoint_GetY(p);
163 point[2] = LASPoint_GetZ(p);
165 unsigned long i = output->GetNumberOfPoints();
166 output->SetPoint(i, point);
169 V =
static_cast<PixelType>(LASPoint_GetZ(p));
170 output->SetPointData(i, V);
176 itkExceptionMacro(<<
"Can't handle pointset dimension other than 2 and 3");
179 LASReader_Destroy(reader);
182 template <
class TOutputPo
intSet>
186 Superclass::PrintSelf(os, indent);
187 os << indent <<
"Number of points: " << this->m_NumberOfPoints << std::endl;
188 os << indent << std::setprecision(15);
189 os << indent <<
"Min X: " << this->m_MinX << std::endl;
190 os << indent <<
"Max X: " << this->m_MaxX << std::endl;
191 os << indent <<
"Min Y: " << this->m_MinY << std::endl;
192 os << indent <<
"Max Y: " << this->m_MaxY << std::endl;
193 os << indent <<
"m_FileName: " << this->m_FileName <<
"\n";