[Liblas-commits] hg: complete a working but ugly implementation of
--point-translate
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Nov 3 15:50:01 EDT 2010
changeset 6f96b326bc0e in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=6f96b326bc0e
summary: complete a working but ugly implementation of --point-translate
diffstat:
include/liblas/lastransform.hpp | 16 +++-
src/lastransform.cpp | 112 ++++++++++++++++++++++++++++++++-------
2 files changed, 102 insertions(+), 26 deletions(-)
diffs (189 lines):
diff -r b75eee10bb92 -r 6f96b326bc0e include/liblas/lastransform.hpp
--- a/include/liblas/lastransform.hpp Wed Nov 03 11:33:45 2010 -0500
+++ b/include/liblas/lastransform.hpp Wed Nov 03 14:49:52 2010 -0500
@@ -125,18 +125,24 @@
~TranslationTransform();
bool transform(Point& point);
+
+ enum OPER_TYPE
+ {
+ eOPER_MULTIPLY = 0,
+ eOPER_DIVIDE = 1,
+ eOPER_SUBTRACT = 2,
+ eOPER_ADD = 3,
+ eOPER_NONE = -99
+ };
// Yes, Mateusz, I'm embarassed by this :)
struct operation{
- bool multiply;
- bool divide;
- bool subtract;
- bool add;
+ OPER_TYPE oper;
std::string dimension;
double value;
std::string expression;
- operation(std::string name) : multiply(false), divide(false), subtract(false), add(false), dimension(name), value(0.0)
+ operation(std::string name) : oper(eOPER_NONE), dimension(name), value(0.0)
{
}
};
diff -r b75eee10bb92 -r 6f96b326bc0e src/lastransform.cpp
--- a/src/lastransform.cpp Wed Nov 03 11:33:45 2010 -0500
+++ b/src/lastransform.cpp Wed Nov 03 14:49:52 2010 -0500
@@ -170,29 +170,12 @@
boost::char_separator<char> sep_space(" ");
tokenizer dimensions(expression, sep_space);
-
-
-
- boost::char_separator<char> sep_star("*");
- boost::char_separator<char> sep_dash("-");
- boost::char_separator<char> sep_plus("+");
- boost::char_separator<char> sep_div("/");
-
-
- boost::uint32_t dimension_size = 0;
for (tokenizer::iterator t = dimensions.begin(); t != dimensions.end(); ++t) {
- std::cout << "token: " << *t;
std::string const& s = *t;
operation op = GetOperation(s);
operations.push_back(op);
-
- dimension_size++;
}
- std::cout << std::endl;
- std::cout << dimension_size << std::endl;
-
-
}
@@ -262,24 +245,24 @@
std::string::size_type data_pos = std::string::npos;
if (found_star != std::string::npos)
{
- output.multiply = true;
+ output.oper = eOPER_MULTIPLY;
data_pos = expression.find_last_of(star) + 1;
}
if (found_divide != std::string::npos)
{
- output.divide = true;
+ output.oper = eOPER_DIVIDE;
data_pos = expression.find_last_of(divide) + 1;
}
if (found_plus != std::string::npos)
{
- output.add = true;
+ output.oper = eOPER_ADD;
data_pos = expression.find_last_of(plus) + 1;
}
if (found_minus != std::string::npos)
{
- output.subtract = true;
+ output.oper = eOPER_SUBTRACT;
data_pos = expression.find_last_of(minus) + 1;
}
@@ -302,6 +285,93 @@
}
bool TranslationTransform::transform(Point& point)
{
+ for(std::vector<TranslationTransform::operation>::const_iterator op = operations.begin();
+ op != operations.end();
+ op++)
+ {
+
+ switch (op->oper)
+ {
+ case eOPER_MULTIPLY:
+ if (!op->dimension.compare("X"))
+ {
+ point.SetX(point.GetX() * op->value);
+ }
+ if (!op->dimension.compare("Y"))
+ {
+ point.SetY(point.GetY() * op->value);
+ }
+ if (!op->dimension.compare("Z"))
+ {
+ point.SetZ(point.GetZ() * op->value);
+ }
+ break;
+ case eOPER_DIVIDE:
+ if (!op->dimension.compare("X"))
+ {
+ point.SetX(point.GetX() / op->value);
+ }
+ if (!op->dimension.compare("Y"))
+ {
+ point.SetY(point.GetY() / op->value);
+ }
+ if (!op->dimension.compare("Z"))
+ {
+ point.SetZ(point.GetZ() / op->value);
+ }
+ break;
+ case eOPER_ADD:
+ if (!op->dimension.compare("X"))
+ {
+ point.SetX(point.GetX() + op->value);
+ }
+ if (!op->dimension.compare("Y"))
+ {
+ point.SetY(point.GetY() + op->value);
+ }
+ if (!op->dimension.compare("Z"))
+ {
+ point.SetZ(point.GetZ() + op->value);
+ }
+
+ break;
+ case eOPER_SUBTRACT:
+ if (!op->dimension.compare("X"))
+ {
+ point.SetX(point.GetX() - op->value);
+ }
+ if (!op->dimension.compare("Y"))
+ {
+ point.SetY(point.GetY() - op->value);
+ }
+ if (!op->dimension.compare("Z"))
+ {
+ point.SetZ(point.GetZ() - op->value);
+ }
+ break;
+
+ default:
+ std::ostringstream oss;
+ oss << "Unhandled expression operation id " << static_cast<boost::int32_t>(op->oper);
+ throw std::runtime_error(oss.str());
+ }
+
+ 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 of this file is insufficient to represent the data given the expression ");
+ }
+
+ 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 of this file is insufficient to represent the data given the expression");
+ }
+
+ 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 of this file is insufficient to represent the data given the expression");
+ }
+
+ }
return true;
}
More information about the Liblas-commits
mailing list