[Liblas-commits] hg-main-tree: getDimensionIndex() now takes both
the field name ...
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Mar 25 18:12:36 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/64024d55e94f
changeset: 473:64024d55e94f
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Mar 25 15:12:09 2011 -0700
description:
getDimensionIndex() now takes both the field name and the datatype, to reduce errors; it is defined to throw if the field is not found or if it is found but with the wrong datatype
diffstat:
include/libpc/Schema.hpp | 58 +++++++++------------------------
src/Schema.cpp | 66 ++++++++++++++++++++++++++++++++++++++
src/drivers/faux/Reader.cpp | 8 ++--
src/drivers/faux/Writer.cpp | 6 +-
src/drivers/las/Header.cpp | 8 ++--
src/drivers/las/Reader.cpp | 38 ++++++++++----------
src/drivers/las/Writer.cpp | 32 +++++++++---------
src/drivers/liblas/Iterator.cpp | 32 +++++++++---------
src/drivers/liblas/Reader.cpp | 8 ++--
src/drivers/liblas/Writer.cpp | 38 ++++++++++----------
src/drivers/oci/Writer.cpp | 12 +++---
src/filters/Chipper.cpp | 4 +-
src/filters/ColorFilter.cpp | 8 ++--
src/filters/CropFilter.cpp | 6 +-
test/unit/CacheFilterTest.cpp | 2 +-
test/unit/DecimationFilterTest.cpp | 2 +-
test/unit/FauxReaderTest.cpp | 40 +++++++++++-----------
test/unit/LiblasReaderTest.cpp | 6 +-
test/unit/MosaicFilterTest.cpp | 8 ++--
test/unit/SchemaLayoutTest.cpp | 15 +++++---
test/unit/SchemaTest.cpp | 1 -
21 files changed, 220 insertions(+), 178 deletions(-)
diffs (truncated from 705 to 300 lines):
diff -r 65fe5562bd8e -r 64024d55e94f include/libpc/Schema.hpp
--- a/include/libpc/Schema.hpp Fri Mar 25 14:58:05 2011 -0500
+++ b/include/libpc/Schema.hpp Fri Mar 25 15:12:09 2011 -0700
@@ -73,56 +73,30 @@
void addDimension(Dimension const& dim);
void addDimensions(const std::vector<Dimension>& dims);
- const Dimension& getDimension(std::size_t index) const
- {
- return m_dimensions[index];
- }
+ const Dimension& getDimension(std::size_t index) const;
+ const Dimensions& getDimensions() const;
- Dimension& getDimension(std::size_t index)
- {
- return m_dimensions[index];
- }
+ // returns the index of the field
+ //
+ // This function assumes the field is present and valid. If not, it will throw.
+ // (This behaviour is okay because looking up the diemsnion index is not expected
+ // to be on the critical path anywhere.)
+ int getDimensionIndex(Dimension::Field field, Dimension::DataType datatype) const;
+ int getDimensionIndex(const Dimension& dim) const;
- const Dimensions& getDimensions() const
- {
- return m_dimensions;
- }
+ bool hasDimension(Dimension::Field field, Dimension::DataType datatype) const;
+ bool hasDimension(const Dimension& dim) const;
- bool hasDimension(Dimension::Field field) const
- {
- int index = m_indexTable[field];
- return index != -1;
- }
+ boost::property_tree::ptree getPTree() const;
- bool hasDimension(Dimension::Field field, Dimension::DataType datatype) const
- {
- int index = m_indexTable[field];
- if (index == -1) return false;
- const Dimension& dim = m_dimensions[index];
- if (dim.getDataType() != datatype) return false;
- return true;
- }
-
- bool hasDimension(const Dimension& dim) const
- {
- return hasDimension(dim.getField(), dim.getDataType());
- }
-
- // assumes the index does, in fact, exist
- int getDimensionIndex(Dimension::Field field) const
- {
- int index = m_indexTable[field];
- assert(index != -1);
- return index;
- }
-
- boost::property_tree::ptree getPTree() const;
+ void dump() const;
private:
std::vector<Dimension> m_dimensions;
- // BUG: use boost::array?
- int m_indexTable[Dimension::Field_LAST]; // mapping from field name to index position, or -1 if field not present
+ // this is a mapping from field name to index position in the
+ // m_dimensions array (or -1 if field not present)
+ int m_indexTable[Dimension::Field_LAST];
};
diff -r 65fe5562bd8e -r 64024d55e94f src/Schema.cpp
--- a/src/Schema.cpp Fri Mar 25 14:58:05 2011 -0500
+++ b/src/Schema.cpp Fri Mar 25 15:12:09 2011 -0700
@@ -41,6 +41,10 @@
#include <libpc/Schema.hpp>
+#include <iostream>
+
+#include <libpc/exceptions.hpp>
+
namespace libpc
{
@@ -143,6 +147,68 @@
}
+const Dimension& Schema::getDimension(std::size_t index) const
+{
+ return m_dimensions[index];
+}
+
+
+const Schema::Dimensions& Schema::getDimensions() const
+{
+ return m_dimensions;
+}
+
+
+int Schema::getDimensionIndex(Dimension::Field field, Dimension::DataType datatype) const
+{
+ const int index = m_indexTable[field];
+
+ assert(index != -1);
+ if (index == -1)
+ {
+ throw libpc_error("Requested dimension field not present");
+ }
+
+ const Dimension& dim = m_dimensions[index];
+
+ assert(dim.getDataType() == datatype);
+ if (dim.getDataType() != datatype)
+ {
+ throw libpc_error("Requested dimension field present, but with different datatype");
+ }
+
+ return index;
+}
+
+
+int Schema::getDimensionIndex(const Dimension& dim) const
+{
+ return getDimensionIndex(dim.getField(), dim.getDataType());
+}
+
+
+bool Schema::hasDimension(Dimension::Field field, Dimension::DataType datatype) const
+{
+ const int index = m_indexTable[field];
+ if (index == -1) return false;
+ const Dimension& dim = m_dimensions[index];
+ if (dim.getDataType() != datatype) return false;
+ return true;
+}
+
+
+bool Schema::hasDimension(const Dimension& dim) const
+{
+ return hasDimension(dim.getField(), dim.getDataType());
+}
+
+
+void Schema::dump() const
+{
+ std::cout << *this;
+}
+
+
std::ostream& operator<<(std::ostream& os, Schema const& schema)
{
using boost::property_tree::ptree;
diff -r 65fe5562bd8e -r 64024d55e94f src/drivers/faux/Reader.cpp
--- a/src/drivers/faux/Reader.cpp Fri Mar 25 14:58:05 2011 -0500
+++ b/src/drivers/faux/Reader.cpp Fri Mar 25 15:12:09 2011 -0700
@@ -145,10 +145,10 @@
const double delY = (maxY - minY) / numDeltas;
const double delZ = (maxZ - minZ) / numDeltas;
- const int offsetT = schema.getDimensionIndex(Dimension::Field_Time);
- const int offsetX = schema.getDimensionIndex(Dimension::Field_X);
- const int offsetY = schema.getDimensionIndex(Dimension::Field_Y);
- const int offsetZ = schema.getDimensionIndex(Dimension::Field_Z);
+ const int offsetT = schema.getDimensionIndex(Dimension::Field_Time, Dimension::Uint64);
+ const int offsetX = schema.getDimensionIndex(Dimension::Field_X, Dimension::Double);
+ const int offsetY = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Double);
+ const int offsetZ = schema.getDimensionIndex(Dimension::Field_Z, Dimension::Double);
boost::uint64_t time = index;
diff -r 65fe5562bd8e -r 64024d55e94f src/drivers/faux/Writer.cpp
--- a/src/drivers/faux/Writer.cpp Fri Mar 25 14:58:05 2011 -0500
+++ b/src/drivers/faux/Writer.cpp Fri Mar 25 15:12:09 2011 -0700
@@ -90,9 +90,9 @@
const boost::uint32_t numPoints = PointBuffer.getNumPoints();
const Schema& schema = PointBuffer.getSchemaLayout().getSchema();
- const int fieldIndexX = schema.getDimensionIndex(Dimension::Field_X);
- const int fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y);
- const int fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z);
+ const int fieldIndexX = schema.getDimensionIndex(Dimension::Field_X, Dimension::Double);
+ const int fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Double);
+ const int fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z, Dimension::Double);
for (boost::uint32_t pointIndex=0; pointIndex<numPoints; pointIndex++)
{
diff -r 65fe5562bd8e -r 64024d55e94f src/drivers/las/Header.cpp
--- a/src/drivers/las/Header.cpp Fri Mar 25 14:58:05 2011 -0500
+++ b/src/drivers/las/Header.cpp Fri Mar 25 15:12:09 2011 -0700
@@ -717,21 +717,21 @@
{
std::ostringstream text;
- Dimension x(Dimension::Field_X, Dimension::Uint32);
+ Dimension x(Dimension::Field_X, Dimension::Int32);
text << "x coordinate as a long integer. You must use the scale and "
<< "offset information of the header to determine the double value.";
x.setDescription(text.str());
schema.addDimension(x);
text.str("");
- Dimension y(Dimension::Field_Y, Dimension::Uint32);
+ Dimension y(Dimension::Field_Y, Dimension::Int32);
text << "y coordinate as a long integer. You must use the scale and "
<< "offset information of the header to determine the double value.";
y.setDescription(text.str());
schema.addDimension(y);
text.str("");
- Dimension z(Dimension::Field_Z, Dimension::Uint32);
+ Dimension z(Dimension::Field_Z, Dimension::Int32);
text << "z coordinate as a long integer. You must use the scale and "
<< "offset information of the header to determine the double value.";
z.setDescription(text.str());
@@ -865,7 +865,7 @@
{
std::ostringstream text;
- Dimension t(Dimension::Field_Time, Dimension::Uint64);
+ Dimension t(Dimension::Field_Time, Dimension::Double);
text << "The GPS Time is the double floating point time tag value at "
"which the point was acquired. It is GPS Week Time if the "
"Global Encoding low bit is clear and Adjusted Standard GPS "
diff -r 65fe5562bd8e -r 64024d55e94f src/drivers/las/Reader.cpp
--- a/src/drivers/las/Reader.cpp Fri Mar 25 14:58:05 2011 -0500
+++ b/src/drivers/las/Reader.cpp Fri Mar 25 15:12:09 2011 -0700
@@ -138,25 +138,25 @@
throw not_yet_implemented("Unknown point format encountered");
}
- const int fieldIndexX = schema.getDimensionIndex(Dimension::Field_X);
- const int fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y);
- const int fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z);
+ const int fieldIndexX = schema.getDimensionIndex(Dimension::Field_X, Dimension::Int32);
+ const int fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Int32);
+ const int fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z, Dimension::Int32);
- const int fieldIndexIntensity = schema.getDimensionIndex(Dimension::Field_Intensity);
- const int fieldIndexReturnNum = schema.getDimensionIndex(Dimension::Field_ReturnNumber);
- const int fieldIndexNumReturns = schema.getDimensionIndex(Dimension::Field_NumberOfReturns);
- const int fieldIndexScanDir = schema.getDimensionIndex(Dimension::Field_ScanDirectionFlag);
- const int fieldIndexFlight = schema.getDimensionIndex(Dimension::Field_EdgeOfFlightLine);
- const int fieldIndexClassification = schema.getDimensionIndex(Dimension::Field_Classification);
- const int fieldIndexScanAngle = schema.getDimensionIndex(Dimension::Field_ScanAngleRank);
- const int fieldIndexUserData = schema.getDimensionIndex(Dimension::Field_UserData);
- const int fieldIndexPointSource = schema.getDimensionIndex(Dimension::Field_PointSourceId);
+ const int fieldIndexIntensity = schema.getDimensionIndex(Dimension::Field_Intensity, Dimension::Int16);
+ const int fieldIndexReturnNum = schema.getDimensionIndex(Dimension::Field_ReturnNumber, Dimension::Uint8);
+ const int fieldIndexNumReturns = schema.getDimensionIndex(Dimension::Field_NumberOfReturns, Dimension::Uint8);
+ const int fieldIndexScanDir = schema.getDimensionIndex(Dimension::Field_ScanDirectionFlag, Dimension::Uint8);
+ const int fieldIndexFlight = schema.getDimensionIndex(Dimension::Field_EdgeOfFlightLine, Dimension::Uint8);
+ const int fieldIndexClassification = schema.getDimensionIndex(Dimension::Field_Classification, Dimension::Uint8);
+ const int fieldIndexScanAngle = schema.getDimensionIndex(Dimension::Field_ScanAngleRank, Dimension::Int8);
+ const int fieldIndexUserData = schema.getDimensionIndex(Dimension::Field_UserData, Dimension::Uint8);
+ const int fieldIndexPointSource = schema.getDimensionIndex(Dimension::Field_PointSourceId, Dimension::Uint16);
- const int fieldIndexTime = (hasTimeData ? schema.getDimensionIndex(Dimension::Field_Time) : 0);
+ const int fieldIndexTime = (hasTimeData ? schema.getDimensionIndex(Dimension::Field_Time, Dimension::Double) : 0);
- const int fieldIndexRed = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Red) : 0);
- const int fieldIndexGreen = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Green) : 0);
- const int fieldIndexBlue = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Blue) : 0);
+ const int fieldIndexRed = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Red, Dimension::Uint16) : 0);
+ const int fieldIndexGreen = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Green, Dimension::Uint16) : 0);
+ const int fieldIndexBlue = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Blue, Dimension::Uint16) : 0);
for (boost::uint32_t pointIndex=0; pointIndex<numPoints; pointIndex++)
{
@@ -168,9 +168,9 @@
boost::uint8_t* p = buf;
- const boost::uint32_t x = Utils::read_field<boost::uint32_t>(p);
- const boost::uint32_t y = Utils::read_field<boost::uint32_t>(p);
- const boost::uint32_t z = Utils::read_field<boost::uint32_t>(p);
+ const boost::int32_t x = Utils::read_field<boost::int32_t>(p);
+ const boost::int32_t y = Utils::read_field<boost::int32_t>(p);
+ const boost::int32_t z = Utils::read_field<boost::int32_t>(p);
const boost::uint16_t intensity = Utils::read_field<boost::uint16_t>(p);
const boost::uint8_t flags = Utils::read_field<boost::uint8_t>(p);
const boost::uint8_t classification = Utils::read_field<boost::uint8_t>(p);
diff -r 65fe5562bd8e -r 64024d55e94f src/drivers/las/Writer.cpp
--- a/src/drivers/las/Writer.cpp Fri Mar 25 14:58:05 2011 -0500
+++ b/src/drivers/las/Writer.cpp Fri Mar 25 15:12:09 2011 -0700
@@ -118,25 +118,25 @@
throw not_yet_implemented("Unknown point format encountered");
}
- const int fieldIndexX = schema.getDimensionIndex(Dimension::Field_X);
- const int fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y);
- const int fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z);
+ const int fieldIndexX = schema.getDimensionIndex(Dimension::Field_X, Dimension::Int32);
+ const int fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Int32);
More information about the Liblas-commits
mailing list