Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
9 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.. _readers.pts: | ||
|
||
readers.pts | ||
============ | ||
|
||
The **PTS reader** reads data from PTS files. | ||
|
||
|
||
Example Pipeline | ||
---------------- | ||
|
||
.. code-block:: json | ||
{ | ||
"pipeline":[ | ||
{ | ||
"type":"readers.pts", | ||
"filename":"test.pts" | ||
}, | ||
{ | ||
"type":"writers.text", | ||
"filename":"outputfile.txt" | ||
} | ||
] | ||
} | ||
Options | ||
------- | ||
|
||
filename | ||
text file to read [Required] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Text driver CMake configuration | ||
# | ||
|
||
set(srcs | ||
PtsReader.cpp | ||
) | ||
|
||
set(incs | ||
PtsReader.hpp | ||
) | ||
|
||
PDAL_ADD_DRIVER(reader pts "${srcs}" "${incs}" objects) | ||
set(PDAL_TARGET_OBJECTS ${PDAL_TARGET_OBJECTS} ${objects} PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2016, Hobu Inc., info@hobu.co | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of Hobu, Inc. nor the | ||
* names of its contributors may be used to endorse or promote | ||
* products derived from this software without specific prior | ||
* written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
* OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#include <pdal/PDALUtils.hpp> | ||
#include <pdal/util/Algorithm.hpp> | ||
|
||
#include "PtsReader.hpp" | ||
|
||
#include <pdal/pdal_macros.hpp> | ||
|
||
namespace pdal | ||
{ | ||
|
||
static PluginInfo const s_info = PluginInfo( | ||
"readers.pts", | ||
"Pts Reader", | ||
"http://pdal.io/stages/readers.pts.html" ); | ||
|
||
CREATE_STATIC_PLUGIN(1, 0, PtsReader, Reader, s_info) | ||
|
||
std::string PtsReader::getName() const { return s_info.name; } | ||
|
||
void PtsReader::initialize(PointTableRef table) | ||
{ | ||
m_istream = Utils::openFile(m_filename); | ||
if (!m_istream) | ||
{ | ||
std::ostringstream oss; | ||
oss << getName() << ": Unable to open pts file '" << | ||
m_filename << "'."; | ||
throw pdal_error(oss.str()); | ||
} | ||
|
||
std::string buf; | ||
std::getline(*m_istream, buf); | ||
|
||
// Very first line is point count | ||
Utils::fromString(buf, m_PointCount); | ||
Utils::closeFile(m_istream); | ||
} | ||
|
||
|
||
void PtsReader::addDimensions(PointLayoutPtr layout) | ||
{ | ||
// Dimensions are fixed in PTS | ||
|
||
m_dims.push_back(Dimension::Id::X); | ||
m_dims.push_back(Dimension::Id::Y); | ||
m_dims.push_back(Dimension::Id::Z); | ||
m_dims.push_back(Dimension::Id::Reflectance); | ||
m_dims.push_back(Dimension::Id::Red); | ||
m_dims.push_back(Dimension::Id::Green); | ||
m_dims.push_back(Dimension::Id::Blue); | ||
|
||
for (auto d: m_dims) | ||
{ | ||
layout->registerDim(d); | ||
} | ||
|
||
} | ||
|
||
|
||
void PtsReader::ready(PointTableRef table) | ||
{ | ||
m_istream = Utils::openFile(m_filename); | ||
if (!m_istream) | ||
{ | ||
std::ostringstream oss; | ||
oss << getName() << ": Unable to open text file '" << | ||
m_filename << "'."; | ||
throw pdal_error(oss.str()); | ||
} | ||
|
||
// Skip header line. | ||
std::string buf; | ||
std::getline(*m_istream, buf); | ||
} | ||
|
||
|
||
point_count_t PtsReader::read(PointViewPtr view, point_count_t numPts) | ||
{ | ||
PointId idx = view->size(); | ||
|
||
point_count_t cnt = 0; | ||
size_t line = 1; | ||
|
||
while (m_istream->good() && cnt < numPts) | ||
{ | ||
std::string buf; | ||
StringList fields; | ||
|
||
std::getline(*m_istream, buf); | ||
line++; | ||
if (buf.empty()) | ||
continue; | ||
|
||
fields = Utils::split2(buf, m_separator); | ||
if (fields.size() != m_dims.size()) | ||
{ | ||
log()->get(LogLevel::Error) << "Line " << line << | ||
" in '" << m_filename << "' contains " << fields.size() << | ||
" fields when " << m_dims.size() << " were expected. " | ||
"Ignoring." << std::endl; | ||
continue; | ||
} | ||
|
||
double d; | ||
for (size_t i = 0; i < fields.size(); ++i) | ||
{ | ||
if (!Utils::fromString(fields[i], d)) | ||
{ | ||
log()->get(LogLevel::Error) << "Can't convert " | ||
"field '" << fields[i] << "' to numeric value on line " << | ||
line << " in '" << m_filename << "'. Setting to 0." << | ||
std::endl; | ||
d = 0; | ||
} | ||
view->setField(m_dims[i], idx, d); | ||
} | ||
cnt++; | ||
idx++; | ||
} | ||
return cnt; | ||
} | ||
|
||
|
||
void PtsReader::done(PointTableRef table) | ||
{ | ||
Utils::closeFile(m_istream); | ||
} | ||
|
||
|
||
} // namespace pdal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2016, Hobu Inc. (info@hobu.co) | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of Hobu, Inc. nor the | ||
* names of its contributors may be used to endorse or promote | ||
* products derived from this software without specific prior | ||
* written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
* OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <istream> | ||
|
||
#include <pdal/Reader.hpp> | ||
#include <pdal/plugin.hpp> | ||
|
||
extern "C" int32_t PtsReader_ExitFunc(); | ||
extern "C" PF_ExitFunc PtsReader_InitPlugin(); | ||
|
||
namespace pdal | ||
{ | ||
|
||
class PDAL_DLL PtsReader : public Reader | ||
{ | ||
public: | ||
static void * create(); | ||
static int32_t destroy(void *); | ||
std::string getName() const; | ||
|
||
PtsReader() : m_separator(' '), m_PointCount(0), m_istream(NULL) | ||
{} | ||
|
||
private: | ||
/** | ||
Initialize the reader by opening the file and reading the header line | ||
for the point count. | ||
Closes the file on completion. | ||
\param table Point table being initialized. | ||
*/ | ||
virtual void initialize(PointTableRef table); | ||
|
||
/** | ||
Add dimensions fixed dimensions for PTS format | ||
http://w3.leica-geosystems.com/kb/?guid=5532D590-114C-43CD-A55F-FE79E5937CB2 | ||
\param layout Layout to which the dimenions are added. | ||
*/ | ||
virtual void addDimensions(PointLayoutPtr layout); | ||
|
||
/** | ||
Reopen the file in preparation for reading. | ||
\param table Point table to make ready. | ||
*/ | ||
virtual void ready(PointTableRef table); | ||
|
||
/** | ||
Read up to numPts points into the \ref view. | ||
\param view PointView in which to insert point data. | ||
\param numPts Maximum number of points to read. | ||
\return Number of points read. | ||
*/ | ||
virtual point_count_t read(PointViewPtr view, point_count_t numPts); | ||
|
||
/** | ||
Close input file. | ||
\param table PointTable we're done with. | ||
*/ | ||
virtual void done(PointTableRef table); | ||
|
||
private: | ||
char m_separator; | ||
point_count_t m_PointCount; | ||
std::istream *m_istream; | ||
StringList m_dimNames; | ||
Dimension::IdList m_dims; | ||
}; | ||
|
||
} // namespace pdal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
19 | ||
3.980972 -2.006119 -0.010086 -1035 97 59 38 | ||
-25.050461 -2.689682 -0.124985 -1164 32 19 11 | ||
-21.257339 -16.137466 -2.000961 -1397 15 10 10 | ||
-17.998978 -24.000290 -0.014267 -935 38 25 19 | ||
-19.475418 -24.485733 -0.103165 -1212 17 13 12 | ||
-19.483017 -24.488449 -0.121323 -1218 16 12 11 | ||
-19.377609 -24.499924 -1.078964 -1311 13 9 8 | ||
-19.504745 -24.508835 -1.603256 -1249 19 14 13 | ||
-19.503983 -24.513992 -1.596115 -1292 15 12 12 | ||
-19.501144 -24.502396 -1.659653 -1261 20 15 12 | ||
-19.500870 -24.506485 -1.639847 -1275 19 14 11 | ||
-19.500046 -24.518112 -1.600815 -1275 19 15 11 | ||
-19.500992 -24.505173 -1.619644 -1230 20 15 12 | ||
-19.505936 -24.500900 -1.617966 -1248 21 16 13 | ||
-19.502487 -24.524185 -1.573502 -1348 17 13 13 | ||
-19.503708 -24.515854 -1.588211 -1331 17 14 13 | ||
-19.503311 -24.518600 -1.580551 -1326 17 12 12 | ||
-19.502060 -24.526901 -1.565781 -1323 14 12 11 | ||
-19.501053 -24.533554 -1.533951 -1307 17 13 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.