[Liblas-commits] libpc: turned on liblas writer for point types
liblas-commits at liblas.org
liblas-commits at liblas.org
Mon Feb 28 18:34:25 EST 2011
details: http://hg.liblas.orglibpc/rev/4e5167bc4720
changeset: 119:4e5167bc4720
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 15:32:03 2011 -0800
description:
turned on liblas writer for point types
Subject: libpc: moved note on custom fields NYI
details: http://hg.liblas.orglibpc/rev/c77eb9547b3b
changeset: 120:c77eb9547b3b
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 15:34:03 2011 -0800
description:
moved note on custom fields NYI
Subject: libpc: updated liblas ref file
details: http://hg.liblas.orglibpc/rev/d9188caa4f11
changeset: 121:d9188caa4f11
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 15:34:21 2011 -0800
description:
updated liblas ref file
diffstat:
src/FauxReader.cpp | 4 +-
src/drivers/liblas/writer.cpp | 154 ++++++++++++++++++++++++++++++++++------
src/drivers/liblas/writer.hpp | 10 ++-
test/data/simple.las | 0
test/unit/LiblasWriterTest.cpp | 24 ++++-
5 files changed, 159 insertions(+), 33 deletions(-)
diffs (truncated from 328 to 300 lines):
diff -r a4f68c513443 -r d9188caa4f11 src/FauxReader.cpp
--- a/src/FauxReader.cpp Mon Feb 28 15:31:29 2011 -0800
+++ b/src/FauxReader.cpp Mon Feb 28 15:34:21 2011 -0800
@@ -78,7 +78,6 @@
throw; // BUG
}
schema.addDimensions(dimensions);
- throw not_yet_implemented("need to add ability to read from arbitrary fields");
header->setNumPoints(numPoints);
header->setBounds(bounds);
@@ -91,6 +90,9 @@
boost::uint32_t FauxReader::readPoints(PointData& data)
{
+ if (data.getSchemaLayout().getSchema().getDimensions().size() != 4)
+ throw not_yet_implemented("need to add ability to read from arbitrary fields");
+
// make up some data and put it into the buffer
const boost::uint32_t numPoints = data.getNumPoints();
diff -r a4f68c513443 -r d9188caa4f11 src/drivers/liblas/writer.cpp
--- a/src/drivers/liblas/writer.cpp Mon Feb 28 15:31:29 2011 -0800
+++ b/src/drivers/liblas/writer.cpp Mon Feb 28 15:34:21 2011 -0800
@@ -39,6 +39,8 @@
#include "header.hpp"
#include <liblas/Writer.hpp>
+#include <libpc/exceptions.hpp>
+
namespace libpc
{
@@ -47,19 +49,17 @@
LiblasWriter::LiblasWriter(Stage& prevStage, std::ostream& ostream)
: Writer(prevStage)
, m_ostream(ostream)
- , m_writer(NULL)
+ , m_externalWriter(NULL)
{
- liblas::Header extHeader;
- extHeader.SetCompressed(false);
+ m_externalHeader = new liblas::Header;
+ m_externalHeader->SetCompressed(false);
- extHeader.SetCreationDOY(55);
- extHeader.SetCreationYear(2011);
-
- m_writer = new liblas::Writer(m_ostream, extHeader);
+ setFormatVersion(1,2);
+ setPointFormat(0);
// make our own header
- LiblasHeader* myHeader = new LiblasHeader;
- setHeader(myHeader);
+ LiblasHeader* internalHeader = new LiblasHeader;
+ setHeader(internalHeader);
//myHeader->setNumPoints( extHeader.GetPointRecordsCount() );
@@ -67,29 +67,49 @@
//const Bounds<double> bounds(extBounds.minx(), extBounds.miny(), extBounds.minz(), extBounds.maxx(), extBounds.maxy(), extBounds.maxz());
//myHeader->setBounds(bounds);
- //Schema& schema = myHeader->getSchema();
- //schema.addDimension(Dimension(Dimension::Field_X, Dimension::Double));
- //schema.addDimension(Dimension(Dimension::Field_Y, Dimension::Double));
- //schema.addDimension(Dimension(Dimension::Field_Z, Dimension::Double));
-
return;
}
LiblasWriter::~LiblasWriter()
{
- delete m_writer;
+ delete m_externalHeader;
+ return;
+}
+
+
+void LiblasWriter::setFormatVersion(boost::uint8_t majorVersion, boost::uint8_t minorVersion)
+{
+ m_externalHeader->SetVersionMajor(majorVersion);
+ m_externalHeader->SetVersionMinor(minorVersion);
+}
+
+
+void LiblasWriter::setPointFormat(boost::int8_t pointFormat)
+{
+ m_externalHeader->SetDataFormatId((liblas::PointFormatName)pointFormat);
+}
+
+
+void LiblasWriter::setDate(boost::uint16_t dayOfYear, boost::uint16_t year)
+{
+ m_externalHeader->SetCreationDOY(dayOfYear);
+ m_externalHeader->SetCreationYear(year);
}
void LiblasWriter::writeBegin()
{
+ m_externalHeader->SetPointRecordsCount(99);
+ m_externalWriter = new liblas::Writer(m_ostream, *m_externalHeader);
return;
}
void LiblasWriter::writeEnd()
{
+ delete m_externalWriter;
+ m_externalWriter = NULL;
return;
}
@@ -99,25 +119,111 @@
boost::uint32_t numPoints = pointData.getNumPoints();
boost::uint32_t i = 0;
+ bool hasTimeData = false;
+ bool hasColorData = false;
+ bool hasWaveData = false;
+
+ const liblas::PointFormatName pointFormat = m_externalHeader->GetDataFormatId();
+ switch (pointFormat)
+ {
+ case liblas::ePointFormat0:
+ break;
+ case liblas::ePointFormat1:
+ hasTimeData = true;
+ break;
+ case liblas::ePointFormat2:
+ hasColorData = true;
+ break;
+ case liblas::ePointFormat3:
+ hasTimeData = true;
+ hasColorData = true;
+ break;
+ case liblas::ePointFormat4:
+ hasTimeData = true;
+ hasWaveData = true;
+ break;
+ case liblas::ePointFormat5:
+ hasColorData = true;
+ hasTimeData = true;
+ hasWaveData = true;
+ break;
+ }
+
+ if (hasWaveData)
+ {
+ throw not_yet_implemented("Waveform data (types 4 and 5) not supported");
+ }
+
const std::size_t indexX = pointData.getDimensionIndex(Dimension::Field_X);
const std::size_t indexY = pointData.getDimensionIndex(Dimension::Field_Y);
const std::size_t indexZ = pointData.getDimensionIndex(Dimension::Field_Z);
- const std::size_t indexT = pointData.getDimensionIndex(Dimension::Field_GpsTime);
+
+ const std::size_t indexIntensity = pointData.getDimensionIndex(Dimension::Field_Intensity);
+ const std::size_t indexReturnNumber = pointData.getDimensionIndex(Dimension::Field_ReturnNumber);
+ const std::size_t indexNumberOfReturns = pointData.getDimensionIndex(Dimension::Field_NumberOfReturns);
+ const std::size_t indexScanDirectionFlag = pointData.getDimensionIndex(Dimension::Field_ScanDirectionFlag);
+ const std::size_t indexEdgeOfFlightLine = pointData.getDimensionIndex(Dimension::Field_EdgeOfFlightLine);
+ const std::size_t indexClassification = pointData.getDimensionIndex(Dimension::Field_Classification);
+ const std::size_t indexScanAngleRank = pointData.getDimensionIndex(Dimension::Field_ScanAngleRank);
+ const std::size_t indexUserData = pointData.getDimensionIndex(Dimension::Field_UserData);
+ const std::size_t indexPointSourceId = pointData.getDimensionIndex(Dimension::Field_PointSourceId);
+
+ const std::size_t indexGpsTime = (hasTimeData ? pointData.getDimensionIndex(Dimension::Field_GpsTime) : 0);
+
+ const std::size_t indexRed = (hasColorData ? pointData.getDimensionIndex(Dimension::Field_Red) : 0);
+ const std::size_t indexGreen = (hasColorData ? pointData.getDimensionIndex(Dimension::Field_Green) : 0);
+ const std::size_t indexBlue = (hasColorData ? pointData.getDimensionIndex(Dimension::Field_Blue) : 0);
+
+ //const std::size_t indexWavePacketDescriptorIndex = (hasWaveData ? pointData.getDimensionIndex(Dimension::Field_WavePacketDescriptorIndex) : 0);
+ //const std::size_t indexWaveformDataOffset = (hasWaveData ? pointData.getDimensionIndex(Dimension::Field_WaveformDataOffset) : 0);
+ //const std::size_t indexReturnPointWaveformLocation = (hasWaveData ? pointData.getDimensionIndex(Dimension::Field_ReturnPointWaveformLocation) : 0);
+ //const std::size_t indexWaveformXt = (hasWaveData ? pointData.getDimensionIndex(Dimension::Field_WaveformXt) : 0);
+ //const std::size_t indexWaveformYt = (hasWaveData ? pointData.getDimensionIndex(Dimension::Field_WaveformYt) : 0);
+ //const std::size_t indexWaveformZt = (hasWaveData ? pointData.getDimensionIndex(Dimension::Field_WaveformZt) : 0);
liblas::Point pt;
for (i=0; i<numPoints; i++)
{
- const double x = pointData.getField<float>(i, indexX);
- const double y = pointData.getField<float>(i, indexY);
- const double z = pointData.getField<float>(i, indexZ);
- const boost::uint64_t t = pointData.getField<boost::uint64_t>(i, indexT);
+ const boost::int32_t x = pointData.getField<boost::int32_t>(i, indexX);
+ const boost::int32_t y = pointData.getField<boost::int32_t>(i, indexY);
+ const boost::int32_t z = pointData.getField<boost::int32_t>(i, indexZ);
+ pt.SetRawX(x);
+ pt.SetRawY(y);
+ pt.SetRawZ(z);
- pt.SetCoordinates(x,y,z);
- pt.SetTime((double)t);
+ const boost::uint16_t intensity = pointData.getField<boost::uint16_t>(i, indexIntensity);
+ const boost::int8_t returnNumber = pointData.getField<boost::int8_t>(i, indexReturnNumber);
+ const boost::int8_t numberOfReturns = pointData.getField<boost::int8_t>(i, indexNumberOfReturns);
+ const boost::int8_t scanDirFlag = pointData.getField<boost::int8_t>(i, indexScanDirectionFlag);
+ const boost::int8_t edgeOfFlightLine = pointData.getField<boost::int8_t>(i, indexEdgeOfFlightLine);
+ const boost::uint8_t classification = pointData.getField<boost::uint8_t>(i, indexClassification);
+ const boost::uint8_t scanAngleRank = pointData.getField<boost::uint8_t>(i, indexScanAngleRank);
+ const boost::uint8_t userData = pointData.getField<boost::uint8_t>(i, indexUserData);
+ const boost::uint16_t pointSourceId = pointData.getField<boost::uint16_t>(i, indexPointSourceId);
- bool ok = m_writer->WritePoint(pt);
- assert(ok);
+ if (hasTimeData)
+ {
+ const double gpsTime = pointData.getField<double>(i, indexGpsTime);
+ pt.SetTime(gpsTime);
+ }
+
+ if (hasColorData)
+ {
+ const boost::uint16_t red = pointData.getField<boost::uint16_t>(i, indexRed);
+ const boost::uint16_t green = pointData.getField<boost::uint16_t>(i, indexGreen);
+ const boost::uint16_t blue = pointData.getField<boost::uint16_t>(i, indexBlue);
+ liblas::Color color(red, green, blue);
+ pt.SetColor(color);
+ }
+
+ if (hasWaveData)
+ {
+ assert(false);
+ }
+
+ bool ok = m_externalWriter->WritePoint(pt);
+ assert(ok); // BUG
}
return numPoints;
diff -r a4f68c513443 -r d9188caa4f11 src/drivers/liblas/writer.hpp
--- a/src/drivers/liblas/writer.hpp Mon Feb 28 15:31:29 2011 -0800
+++ b/src/drivers/liblas/writer.hpp Mon Feb 28 15:34:21 2011 -0800
@@ -40,18 +40,23 @@
namespace liblas
{
class Writer;
+ class Header;
}
namespace libpc
{
+// we default to LAS 1.2, point format 0
class LIBPC_DLL LiblasWriter : public Writer
{
public:
LiblasWriter(Stage& prevStage, std::ostream&);
-
~LiblasWriter();
+
+ void setFormatVersion(boost::uint8_t majorVersion, boost::uint8_t minorVersion);
+ void setPointFormat(boost::int8_t pointFormat);
+ void setDate(boost::uint16_t dayOfYear, boost::uint16_t year);
protected:
// this is called once before the loop with the writeBuffer calls
@@ -65,7 +70,8 @@
private:
std::ostream& m_ostream;
- liblas::Writer* m_writer;
+ liblas::Writer* m_externalWriter;
+ liblas::Header* m_externalHeader;
LiblasWriter& operator=(const LiblasWriter&); // not implemented
LiblasWriter(const LiblasWriter&); // not implemented
diff -r a4f68c513443 -r d9188caa4f11 test/data/simple.las
Binary file test/data/simple.las has changed
diff -r a4f68c513443 -r d9188caa4f11 test/unit/LiblasWriterTest.cpp
--- a/test/unit/LiblasWriterTest.cpp Mon Feb 28 15:31:29 2011 -0800
+++ b/test/unit/LiblasWriterTest.cpp Mon Feb 28 15:34:21 2011 -0800
@@ -37,6 +37,7 @@
#include "libpc/FauxReader.hpp"
#include "libpc/../../src/drivers/liblas/writer.hpp"
+#include "libpc/../../src/drivers/liblas/reader.hpp"
#include "support.hpp"
@@ -49,22 +50,33 @@
// remove file from earlier run, if needed
Utils::deleteFile("temp.las");
- Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
- FauxReader reader(bounds, 1000, FauxReader::Constant);
-
+ std::istream* ifs = Utils::openFile("../../test/data/1.2-with-color.las");
+ LiblasReader reader(*ifs);
+
std::ostream* ofs = Utils::createFile("temp.las");
More information about the Liblas-commits
mailing list