[Liblas-commits] hg-main-tree: added a removeDimension function
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Apr 27 19:22:07 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/0d2ee36ef573
changeset: 686:0d2ee36ef573
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed Apr 27 16:13:09 2011 -0700
description:
added a removeDimension function
Subject: hg-main-tree: reprojection and scaling filters almost working
details: http://hg.libpc.orghg-main-tree/rev/54dda75a30b2
changeset: 687:54dda75a30b2
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed Apr 27 16:13:27 2011 -0700
description:
reprojection and scaling filters almost working
Subject: hg-main-tree: comment out failing tests
details: http://hg.libpc.orghg-main-tree/rev/4b7febcdae54
changeset: 688:4b7febcdae54
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed Apr 27 16:21:10 2011 -0700
description:
comment out failing tests
Subject: hg-main-tree: merge
details: http://hg.libpc.orghg-main-tree/rev/e13e73cec6b8
changeset: 689:e13e73cec6b8
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed Apr 27 16:21:56 2011 -0700
description:
merge
diffstat:
apps/pc2pc.cpp | 7 +-
include/libpc/Schema.hpp | 2 +
include/libpc/filters/ScalingFilter.hpp | 12 +-
src/Schema.cpp | 13 +
src/filters/ReprojectionFilter.cpp | 70 ++-------
src/filters/ScalingFilter.cpp | 216 ++++++++++++++++++++-----------
src/filters/ScalingFilterIterator.cpp | 10 +-
test/unit/ReprojectionFilterTest.cpp | 143 ++++++++++----------
8 files changed, 260 insertions(+), 213 deletions(-)
diffs (truncated from 684 to 300 lines):
diff -r 2736b43e979e -r e13e73cec6b8 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp Wed Apr 27 12:13:02 2011 -0700
+++ b/apps/pc2pc.cpp Wed Apr 27 16:21:56 2011 -0700
@@ -187,8 +187,11 @@
if (hasOption("a_srs"))
{
libpc::SpatialReference ref;
- ref.setFromUserInput(m_srs);
- writer.setSpatialReference(ref);
+ if (m_srs.size() > 0)
+ {
+ ref.setFromUserInput(m_srs);
+ writer.setSpatialReference(ref);
+ }
}
if (hasOption("compress"))
{
diff -r 2736b43e979e -r e13e73cec6b8 include/libpc/Schema.hpp
--- a/include/libpc/Schema.hpp Wed Apr 27 12:13:02 2011 -0700
+++ b/include/libpc/Schema.hpp Wed Apr 27 16:21:56 2011 -0700
@@ -73,6 +73,8 @@
void addDimension(Dimension const& dim);
void addDimensions(const std::vector<Dimension>& dims);
+ void removeDimension(Dimension const& dim);
+
const Dimension& getDimension(std::size_t index) const;
Dimension& getDimension(std::size_t index);
const Dimensions& getDimensions() const;
diff -r 2736b43e979e -r e13e73cec6b8 include/libpc/filters/ScalingFilter.hpp
--- a/include/libpc/filters/ScalingFilter.hpp Wed Apr 27 12:13:02 2011 -0700
+++ b/include/libpc/filters/ScalingFilter.hpp Wed Apr 27 16:21:56 2011 -0700
@@ -53,7 +53,13 @@
class LIBPC_DLL ScalingFilter : public Filter
{
public:
- ScalingFilter(const Stage& prevStage);
+ // for now...
+ // - we only support scaling of the X,Y,Z fields
+ // - we only support scaling doubles <--> int32s
+ // notes:
+ // - "forward=true" means doubles --> ints
+ // - "forward=false" means ints --> doubles
+ ScalingFilter(const Stage& prevStage, bool forward);
const std::string& getDescription() const;
const std::string& getName() const;
@@ -68,11 +74,13 @@
libpc::SequentialIterator* createSequentialIterator() const;
libpc::RandomIterator* createRandomIterator() const { return NULL; }
- void processBuffer(PointBuffer& data) const;
+ void processBuffer(const PointBuffer& srcData, PointBuffer& dstData) const;
private:
void checkImpedance();
void initialize();
+
+ bool m_forward;
ScalingFilter& operator=(const ScalingFilter&); // not implemented
ScalingFilter(const ScalingFilter&); // not implemented
diff -r 2736b43e979e -r e13e73cec6b8 src/Schema.cpp
--- a/src/Schema.cpp Wed Apr 27 12:13:02 2011 -0700
+++ b/src/Schema.cpp Wed Apr 27 16:21:56 2011 -0700
@@ -147,6 +147,19 @@
}
+void Schema::removeDimension(Dimension const& dim)
+{
+ const Dimension::Field field = dim.getField();
+ assert(m_indexTable[field] != -1);
+ m_indexTable[field] = -1;
+
+ //std::size_t index = getDimensionIndex(dim);
+ //m_dimensions[index] = Dimension(Dimension::Field_INVALID, Dimension::Int32);
+
+ return;
+}
+
+
const Dimension& Schema::getDimension(std::size_t index) const
{
return m_dimensions[index];
diff -r 2736b43e979e -r e13e73cec6b8 src/filters/ReprojectionFilter.cpp
--- a/src/filters/ReprojectionFilter.cpp Wed Apr 27 12:13:02 2011 -0700
+++ b/src/filters/ReprojectionFilter.cpp Wed Apr 27 16:21:56 2011 -0700
@@ -97,6 +97,15 @@
void ReprojectionFilter::checkImpedance()
{
+ const Schema& schema = this->getSchema();
+
+ if (!schema.hasDimension(Dimension::Field_X, Dimension::Double) ||
+ !schema.hasDimension(Dimension::Field_Y, Dimension::Double) ||
+ !schema.hasDimension(Dimension::Field_Z, Dimension::Double))
+ {
+ throw impedance_invalid("Reprojection filter requires X,Y,Z dimensions as doubles");
+ }
+
return;
}
@@ -137,8 +146,6 @@
void ReprojectionFilter::transform(double& x, double& y, double& z) const
{
-#ifdef LIBPC_HAVE_GDAL
-
int ret = 0;
ret = OCTTransform(m_transform_ptr.get(), 1, &x, &y, &z);
@@ -149,36 +156,6 @@
throw std::runtime_error(msg.str());
}
- //if (m_new_header.get())
- //{
- // point.SetHeaderPtr(m_new_header);
- //}
-
- //point.SetX(x);
- //point.SetY(y);
- //point.SetZ(z);
- //
- //if (detail::compare_distance(point.GetRawX(), (std::numeric_limits<boost::int32_t>::max)()) ||
- // detail::compare_distance(point.GetRawX(), (std::numeric_limits<boost::int32_t>::min)())) {
- // throw std::domain_error("X scale and offset combination is insufficient to represent the data");
- //}
-
- //if (detail::compare_distance(point.GetRawY(), (std::numeric_limits<boost::int32_t>::max)()) ||
- // detail::compare_distance(point.GetRawY(), (std::numeric_limits<boost::int32_t>::min)())) {
- // throw std::domain_error("Y scale and offset combination is insufficient to represent the data");
- //}
-
- //if (detail::compare_distance(point.GetRawZ(), (std::numeric_limits<boost::int32_t>::max)()) ||
- // detail::compare_distance(point.GetRawZ(), (std::numeric_limits<boost::int32_t>::min)())) {
- // throw std::domain_error("Z scale and offset combination is insufficient to represent the data");
- //}
-
-#else
- boost::ignore_unused_variable_warning(x);
- boost::ignore_unused_variable_warning(y);
- boost::ignore_unused_variable_warning(z);
-#endif
-
return;
}
@@ -204,32 +181,21 @@
const SchemaLayout& schemaLayout = data.getSchemaLayout();
const Schema& schema = schemaLayout.getSchema();
- const int indexX = schema.getDimensionIndex(Dimension::Field_X, Dimension::Int32);
- const int indexY = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Int32);
- const int indexZ = schema.getDimensionIndex(Dimension::Field_Z, Dimension::Int32);
- const Dimension& xDim = schema.getDimension(indexX);
- const Dimension& yDim = schema.getDimension(indexY);
- const Dimension& zDim = schema.getDimension(indexZ);
+ const int indexX = schema.getDimensionIndex(Dimension::Field_X, Dimension::Double);
+ const int indexY = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Double);
+ const int indexZ = schema.getDimensionIndex(Dimension::Field_Z, Dimension::Double);
for (boost::uint32_t pointIndex=0; pointIndex<numPoints; pointIndex++)
{
- boost::int32_t xraw = data.getField<boost::int32_t>(pointIndex, indexX);
- boost::int32_t yraw = data.getField<boost::int32_t>(pointIndex, indexY);
- boost::int32_t zraw = data.getField<boost::int32_t>(pointIndex, indexZ);
-
- double x = xDim.applyScaling(xraw);
- double y = yDim.applyScaling(yraw);
- double z = zDim.applyScaling(zraw);
+ double x = data.getField<boost::int32_t>(pointIndex, indexX);
+ double y = data.getField<boost::int32_t>(pointIndex, indexY);
+ double z = data.getField<boost::int32_t>(pointIndex, indexZ);
this->transform(x,y,z);
- xraw = xDim.removeScaling<boost::int32_t>(x);
- yraw = yDim.removeScaling<boost::int32_t>(y);
- zraw = zDim.removeScaling<boost::int32_t>(z);
-
- data.setField<boost::int32_t>(pointIndex, indexX, xraw);
- data.setField<boost::int32_t>(pointIndex, indexY, yraw);
- data.setField<boost::int32_t>(pointIndex, indexZ, zraw);
+ data.setField<double>(pointIndex, indexX, x);
+ data.setField<double>(pointIndex, indexY, y);
+ data.setField<double>(pointIndex, indexZ, z);
data.setNumPoints(pointIndex+1);
}
diff -r 2736b43e979e -r e13e73cec6b8 src/filters/ScalingFilter.cpp
--- a/src/filters/ScalingFilter.cpp Wed Apr 27 12:13:02 2011 -0700
+++ b/src/filters/ScalingFilter.cpp Wed Apr 27 16:21:56 2011 -0700
@@ -45,8 +45,9 @@
-ScalingFilter::ScalingFilter(const Stage& prevStage)
+ScalingFilter::ScalingFilter(const Stage& prevStage, bool forward)
: Filter(prevStage)
+ , m_forward(forward)
{
checkImpedance();
@@ -58,13 +59,86 @@
void ScalingFilter::checkImpedance()
{
- const Schema& schema = this->getSchema();
+ Schema& schema = this->getSchemaRef();
- if (!schema.hasDimension(Dimension::Field_X, Dimension::Double) ||
- !schema.hasDimension(Dimension::Field_Y, Dimension::Double) ||
- !schema.hasDimension(Dimension::Field_Z, Dimension::Double))
+ if (m_forward)
{
- throw impedance_invalid("Reprojection filter requires X,Y,Z dimensions as doubles");
+ // doubles --> ints
+
+ const int indexXd = schema.getDimensionIndex(Dimension::Field_X, Dimension::Double);
+ const int indexYd = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Double);
+ const int indexZd = schema.getDimensionIndex(Dimension::Field_Z, Dimension::Double);
+
+ const Dimension& dimXd = schema.getDimension(indexXd);
+ const Dimension& dimYd = schema.getDimension(indexYd);
+ const Dimension& dimZd = schema.getDimension(indexZd);
+
+ Dimension dimXi(Dimension::Field_X, Dimension::Int32);
+ Dimension dimYi(Dimension::Field_Y, Dimension::Int32);
+ Dimension dimZi(Dimension::Field_Z, Dimension::Int32);
+
+ if (!schema.hasDimension(dimXd) || !schema.hasDimension(dimYd) || !schema.hasDimension(dimZd))
+ {
+ throw impedance_invalid("Scaling filter requires X,Y,Z dimensions as doubles (forward direction)");
+ }
+ if (schema.hasDimension(dimXi) || schema.hasDimension(dimYi) || schema.hasDimension(dimZi))
+ {
+ throw impedance_invalid("Scaling filter requires X,Y,Z dimensions as ints not be initially present (forward direction)");
+ }
+
+ schema.removeDimension(dimXd);
+ schema.removeDimension(dimYd);
+ schema.removeDimension(dimZd);
+
+ dimXi.setNumericScale(dimXd.getNumericScale());
+ dimXi.setNumericOffset(dimXd.getNumericOffset());
+ dimYi.setNumericScale(dimYd.getNumericScale());
+ dimYi.setNumericOffset(dimYd.getNumericOffset());
+ dimZi.setNumericScale(dimZd.getNumericScale());
+ dimZi.setNumericOffset(dimZd.getNumericOffset());
+
+ schema.addDimension(dimXi);
+ schema.addDimension(dimYi);
+ schema.addDimension(dimZi);
+ }
+ else
+ {
+ const int indexXi = schema.getDimensionIndex(Dimension::Field_X, Dimension::Int32);
+ const int indexYi = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Int32);
+ const int indexZi = schema.getDimensionIndex(Dimension::Field_Z, Dimension::Int32);
+
+ const Dimension& dimXi = schema.getDimension(indexXi);
+ const Dimension& dimYi = schema.getDimension(indexYi);
+ const Dimension& dimZi = schema.getDimension(indexZi);
+
+ Dimension dimXd(Dimension::Field_X, Dimension::Double);
+ Dimension dimYd(Dimension::Field_Y, Dimension::Double);
+ Dimension dimZd(Dimension::Field_Z, Dimension::Double);
+
+ // ints --> doubles
+ if (!schema.hasDimension(dimXi) || !schema.hasDimension(dimYi) || !schema.hasDimension(dimZi))
+ {
+ throw impedance_invalid("Scaling filter requires X,Y,Z dimensions as int32s (reverse direction)");
+ }
+ if (schema.hasDimension(dimXd) || schema.hasDimension(dimYd) || schema.hasDimension(dimZd))
+ {
+ throw impedance_invalid("Scaling filter requires X,Y,Z dimensions as int32s not be initially present (reverse direction)");
+ }
+
+ dimXd.setNumericScale(dimXi.getNumericScale());
+ dimXd.setNumericOffset(dimXi.getNumericOffset());
+ dimYd.setNumericScale(dimYi.getNumericScale());
+ dimYd.setNumericOffset(dimYi.getNumericOffset());
+ dimZd.setNumericScale(dimZi.getNumericScale());
+ dimZd.setNumericOffset(dimZi.getNumericOffset());
+
+ schema.removeDimension(dimXi);
+ schema.removeDimension(dimYi);
+ schema.removeDimension(dimZi);
+
+ schema.addDimension(dimXd);
+ schema.addDimension(dimYd);
+ schema.addDimension(dimZd);
}
return;
@@ -77,103 +151,85 @@
}
More information about the Liblas-commits
mailing list