[Liblas-commits] hg: make liblas::Bounds n-dimensional
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Aug 3 10:13:46 EDT 2010
changeset 06239bc11752 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=06239bc11752
summary: make liblas::Bounds n-dimensional
diffstat:
include/liblas/lasbounds.hpp | 15 ++++----
src/lasbounds.cpp | 75 ++++++++++++++++++++++++++++++++-----------
2 files changed, 63 insertions(+), 27 deletions(-)
diffs (204 lines):
diff -r 39362a321c31 -r 06239bc11752 include/liblas/lasbounds.hpp
--- a/include/liblas/lasbounds.hpp Tue Aug 03 00:59:05 2010 +0100
+++ b/include/liblas/lasbounds.hpp Tue Aug 03 09:13:39 2010 -0500
@@ -43,8 +43,8 @@
#define LIBLAS_LASBOUNDS_HPP_INCLUDED
#include <liblas/detail/fwd.hpp>
-// boost
-#include <boost/array.hpp>
+
+#include <vector>
namespace liblas {
@@ -52,12 +52,13 @@
{
public:
- typedef boost::array<double, 3> Array;
+ typedef std::vector<double> Vector;
Bounds();
Bounds(double minx, double miny, double maxx, double maxy, double minz, double maxz);
Bounds(double minx, double miny, double maxx, double maxy);
Bounds(const Point& min, const Point& max);
+ Bounds( std::vector<double> const& low, std::vector<double> const& high);
Bounds(Bounds const& other);
Bounds& operator=(Bounds const& rhs);
@@ -82,12 +83,12 @@
}
bool equal(Bounds const& other) const;
- bool intersects2d(Bounds const& other) const;
- bool intersects3d(Bounds const& other) const;
+ bool intersects(Bounds const& other) const;
+ uint32_t dimension() const;
private:
- Array mins;
- Array maxs;
+ Vector mins;
+ Vector maxs;
void verify();
};
diff -r 39362a321c31 -r 06239bc11752 src/lasbounds.cpp
--- a/src/lasbounds.cpp Tue Aug 03 00:59:05 2010 +0100
+++ b/src/lasbounds.cpp Tue Aug 03 09:13:39 2010 -0500
@@ -41,15 +41,18 @@
#include <liblas/lasbounds.hpp>
#include <liblas/laspoint.hpp>
+#include <liblas/detail/utility.hpp>
+
// boost
#include <boost/cstdint.hpp>
-#include <boost/array.hpp>
+
#include <boost/concept_check.hpp>
// std
#include <cmath>
#include <limits>
#include <string>
#include <sstream>
+#include <vector>
using namespace boost;
@@ -57,8 +60,8 @@
Bounds::Bounds()
{
- mins.assign(0);
- maxs.assign(0);
+ mins.resize(0);
+ maxs.resize(0);
}
Bounds::Bounds( double minx,
@@ -68,6 +71,9 @@
double minz,
double maxz)
{
+ mins.resize(3);
+ maxs.resize(3);
+
mins[0] = minx;
mins[1] = miny;
mins[2] = minz;
@@ -82,6 +88,9 @@
}
Bounds::Bounds( const Point& min, const Point& max)
{
+ mins.resize(3);
+ maxs.resize(3);
+
mins[0] = min.GetX();
mins[1] = min.GetY();
mins[2] = min.GetZ();
@@ -100,12 +109,12 @@
double maxx,
double maxy)
{
+ mins.resize(2);
+ maxs.resize(2);
mins[0] = minx;
mins[1] = miny;
- mins[2] = 0;
maxs[0] = maxx;
maxs[1] = maxy;
- maxs[2] = 0;
#ifdef DEBUG
verify();
@@ -113,6 +122,24 @@
}
+Bounds::Bounds( std::vector<double> const& low, std::vector<double> const& high)
+{
+ if (low.size() != high.size() ) {
+ std::ostringstream msg;
+ msg << "Bounds dimensions are not equal. Low bounds dimensions are " << low.size()
+ << " and the high bounds are " << high.size();
+ throw std::runtime_error(msg.str());
+ }
+ mins.resize(low.size());
+
+ mins = low;
+ maxs = high;
+
+#ifdef DEBUG
+ verify();
+#endif
+
+}
Bounds::Bounds(Bounds const& other)
: mins(other.mins)
, maxs(other.maxs)
@@ -129,9 +156,13 @@
return *this;
}
+uint32_t Bounds::dimension() const
+{
+ return mins.size();
+}
void Bounds::verify()
{
- for (uint32_t d = 0; d < 3; ++d)
+ for (uint32_t d = 0; d < dimension(); ++d)
{
if (min(d) > max(d) )
{
@@ -151,9 +182,10 @@
bool Bounds::equal(Bounds const& other) const
{
- // FIXME: direct comparison of float-point values may give wrong result --mloskot
- for (Array::size_type i = 0; i < 3; i++) {
- if (!(min(i) == other.min(i)) && !(max(i) == other.max(i)))
+ for (Vector::size_type i = 0; i < dimension(); i++) {
+
+ if (!(detail::compare_distance(min(i), other.min(i)))
+ && !(detail::compare_distance(max(i), other.max(i))))
{
return false;
}
@@ -161,20 +193,23 @@
return true;
}
-bool Bounds::intersects2d(Bounds const& other) const
+bool Bounds::intersects(Bounds const& other) const
{
+
+ if (other.dimension() != dimension())
+ {
+ std::ostringstream msg;
+ msg << "Bounds dimensions are not equal. Comparison dimension is " << other.dimension()
+ << " and this dimension is " << dimension();
+ throw std::runtime_error(msg.str());
+ }
- return (other.min(0) < max(0) && other.min(0) > min(0) && other.min(1) < max(1) && other.min(1) > max(1))
- || (other.max(0) < max(0) && other.max(0) > min(0) && other.min(1) < max(1) && other.min(1) > max(1))
- || (other.min(0) < max(0) && other.min(0) > min(0) && other.max(1) < max(1) && other.max(1) > max(1))
- || (other.max(0) < max(0) && other.max(0) > min(0) && other.max(1) < max(1) && other.max(1) > max(1));
+ for (uint32_t i = 0; i < dimension(); i++){
+ if (min(i) > other.max(i) || max(i) < other.min(i)) return false;
+ }
+
+ return true;
}
-bool Bounds::intersects3d(Bounds const& other) const
-{
- boost::ignore_unused_variable_warning(other);
- // not implemented
- throw std::runtime_error("not implemented");
-}
} // namespace liblas
More information about the Liblas-commits
mailing list