Skip to content

Commit 0c3de86

Browse files
committed
revision class 'Aabb', now Qt-free
1 parent 5c72efa commit 0c3de86

File tree

7 files changed

+113
-126
lines changed

7 files changed

+113
-126
lines changed

src/aabb.cpp

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,27 @@
1919
#include "aabb.h"
2020

2121
#include <Eigen/Dense> // Eigen
22-
#include <QDataStream> // Qt
2322

24-
aabb::aabb( const double x_min,
25-
const double x_max,
26-
const double y_min,
27-
const double y_max)
28-
: x_min_(x_min)
23+
Aabb::Aabb( const double x_min, const double x_max,
24+
const double y_min, const double y_max)
25+
: m_x_min(x_min), m_x_max(x_max), m_y_min(y_min), m_y_max(y_max)
2926
{
30-
x_max_ = x_max;
31-
y_min_ = y_min;
32-
y_max_ = y_max;
33-
34-
assert( x_min_ <= x_max_ ); // option: swap
35-
assert( y_min_ <= y_max_ );
27+
assert( m_x_min <= m_x_max ); // option: swap
28+
assert( m_y_min <= m_y_max );
3629
}
3730

3831

39-
bool aabb::intersects( const aabb & other) const
32+
bool Aabb::overlaps( const Aabb & other) const
4033
{
41-
return ( ( std::fmin( x_max_, other.x_max_) > std::fmax( x_min_, other.x_min_) )
42-
&& ( std::fmin( y_max_, other.y_max_) > std::fmax( y_min_, other.y_min_) )
34+
return ( ( std::fmin( m_x_max, other.m_x_max) > std::fmax( m_x_min, other.m_x_min) )
35+
&& ( std::fmin( m_y_max, other.m_y_max) > std::fmax( m_y_min, other.m_y_min) )
4336
);
4437
}
4538

46-
aabb aabb::united( const aabb & other) const
47-
{
48-
return { std::fmin( x_min_, other.x_min_),
49-
std::fmax( x_max_, other.x_max_),
50-
std::fmin( y_min_, other.y_min_),
51-
std::fmax( y_max_, other.y_max_)};
52-
}
53-
54-
55-
void aabb::serialize( QDataStream &out ) const
39+
Aabb Aabb::united( const Aabb & other) const
5640
{
57-
// qDebug() << Q_FUNC_INFO;
58-
out << x_min_ << x_max_ << y_min_ << y_max_;
41+
return { std::fmin( m_x_min, other.m_x_min),
42+
std::fmax( m_x_max, other.m_x_max),
43+
std::fmin( m_y_min, other.m_y_min),
44+
std::fmax( m_y_max, other.m_y_max) };
5945
}
60-
61-
bool aabb::deserialize( QDataStream &in )
62-
{
63-
// qDebug() << Q_FUNC_INFO;
64-
in >> x_min_ >> x_max_ >> y_min_ >> y_max_;
65-
return in.status()==0;
66-
}
67-

src/aabb.h

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,26 @@
1919
#ifndef AABB_H
2020
#define AABB_H
2121

22-
#include <QDataStream>
23-
24-
class aabb {
22+
//! Axis-aligned bounding box
23+
class Aabb {
2524

2625
public:
27-
// aabb() = default;
28-
// ~aabb() = default;
29-
aabb( double x_min=0, double x_max=0,
30-
double y_min=0, double y_max=0 );
31-
32-
void serialize( QDataStream & out ) const;
33-
bool deserialize( QDataStream & in );
34-
35-
// aabb & operator= (const aabb & rhs) = default;
26+
Aabb( double x_min=0, double x_max=0,
27+
double y_min=0, double y_max=0 ); //!< Value constructor
3628

37-
double x_min() const { return x_min_; }
38-
double x_max() const { return x_max_; }
39-
double y_min() const { return y_min_; }
40-
double y_max() const { return y_max_; }
29+
double x_min() const { return m_x_min; } //!< Get minimum x-value
30+
double x_max() const { return m_x_max; } //!< Get maximum x-value
31+
double y_min() const { return m_y_min; } //!< Get minimum y-value
32+
double y_max() const { return m_y_max; } //!< Get maximum y-value
4133

42-
bool intersects( const aabb & other) const;
43-
/* nodiscard */ aabb united( const aabb & other) const;
34+
bool overlaps( const Aabb & other) const; //!< Check if the other box overlaps
35+
/* nodiscard */ Aabb united( const Aabb & other) const; //!< Get united box of this and the other box
4436

4537
private:
46-
double x_min_;
47-
double x_max_;
48-
double y_min_;
49-
double y_max_;
38+
double m_x_min;
39+
double m_x_max;
40+
double m_y_min;
41+
double m_y_max;
5042
};
5143

5244
#endif // AABB_H

src/state.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void impl::find_adjacencies_of_latest_segment( const Quantiles::Snapping & snap
577577
for ( int i=0; i<N-1; i++)
578578
{
579579
// pre-check (culling) via axis-aligned bounding boxes
580-
if ( !segm_.at(i)->bounding_box().intersects(
580+
if ( !segm_.at(i)->bounding_box().overlaps(
581581
segm_.last()->bounding_box()) ) {
582582
continue;
583583
}

src/upoint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ uPoint::uPoint( const Vector3d &x,
3737

3838

3939
//! Get axis-aligned bounding box
40-
aabb uPoint::bbox() const
40+
Aabb uPoint::bbox() const
4141
{
4242
double u = m_val(0);
4343
double v = m_val(1);
@@ -56,7 +56,7 @@ aabb uPoint::bbox() const
5656
double y_min = y -sqrt(Cov_xx(1,1));
5757
double y_max = y +sqrt(Cov_xx(1,1));
5858

59-
return aabb{ x_min, x_max, y_min, y_max} ;
59+
return Aabb{ x_min, x_max, y_min, y_max} ;
6060
}
6161

6262
//! Get Euclidean distance to uncertain straight line 'ul'

src/upoint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "uncertain.h"
2323

24-
class aabb; // axis-aligned bounding box
24+
class Aabb; // axis-aligned bounding box
2525

2626
namespace Uncertain {
2727

@@ -38,7 +38,7 @@ class uPoint : public BasicEntity2D
3838
// uPoint( const uPoint &ux ) = default;
3939
~uPoint() override = default;
4040

41-
aabb bbox() const;
41+
Aabb bbox() const;
4242
/* nodiscard */ uPoint euclidean() const;
4343
/* nodiscard */ uPoint sphericalNormalized() const;
4444
/* nodiscard */ uPoint transformed( const Matrix3d & TT) const;

src/usegment.cpp

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Matrix3d uStraightLineSegment::CC()
4646
uPoint uStraightLineSegment::ux() const
4747
{
4848
Matrix<double, 3,6> JJ;
49-
Matrix<double, 6,6> Cov = Cov_tt_.topLeftCorner(6,6);
49+
Matrix<double, 6,6> Cov = m_Cov_tt.topLeftCorner(6,6);
5050
Matrix3d Sl = skew( hl() );
5151

5252
JJ.leftCols(3) = -skew( hm() );
@@ -73,7 +73,7 @@ uPoint uStraightLineSegment::uy() const
7373
//! Construction of an uncertain straight line segment via two uncorrelated endpoints
7474
uStraightLineSegment::uStraightLineSegment( const uPoint & ux,
7575
const uPoint & uy)
76-
: bounding_box_( ux.bbox().united( uy.bbox()) )
76+
: m_bounding_box( ux.bbox().united( uy.bbox()) )
7777
{
7878
// (1) 9-parameter vector t = [l; m; n];
7979
const Matrix3d Sx = skew( ux.v() );
@@ -88,9 +88,9 @@ uStraightLineSegment::uStraightLineSegment( const uPoint & ux,
8888
double xh = ux.v()(2);
8989
double yh = uy.v()(2);
9090
// Vector9d t;
91-
t_.segment( 0, 3) = l;
92-
t_.segment( 3, 3) = +sign(yh)*UUx*uy.v();
93-
t_.segment( 6, 3) = -sign(xh)*UUy*ux.v();
91+
m_t.segment( 0, 3) = l;
92+
m_t.segment( 3, 3) = +sign(yh)*UUx*uy.v();
93+
m_t.segment( 6, 3) = -sign(xh)*UUy*ux.v();
9494

9595
// (2) 9x9 covariance matrix
9696
//Matrix3d JJlx = -Sy;
@@ -120,7 +120,7 @@ uStraightLineSegment::uStraightLineSegment( const uPoint & ux,
120120
Cov_pp.block(0,0,3,3) = ux.Cov();
121121
Cov_pp.block(3,3,3,3) = uy.Cov();
122122

123-
Cov_tt_ = JJ*Cov_pp*JJ.transpose();
123+
m_Cov_tt = JJ*Cov_pp*JJ.transpose();
124124
// return { t, JJ*Cov_pp*JJ.transpose()};
125125
}
126126

@@ -186,41 +186,41 @@ bool uStraightLineSegment::touchedBy( const uPoint & ux,
186186
//! Get the endpoints connecting uncertain straight line l = S(x)*y
187187
uStraightLine uStraightLineSegment::ul() const
188188
{
189-
Matrix3d Cov_ll = Cov_tt_.topLeftCorner(3,3);
190-
return { t_.head(3), Cov_ll };
189+
Matrix3d Cov_ll = m_Cov_tt.topLeftCorner(3,3);
190+
return { m_t.head(3), Cov_ll };
191191
}
192192

193193

194194
//! Get the delimiting uncertain straight line m in homogeneous coordinates.
195195
uStraightLine uStraightLineSegment::um() const
196196
{
197-
Matrix3d Cov_mm = Cov_tt_.block(3,3,3,3);
198-
return { t_.segment(3,3), Cov_mm};
197+
Matrix3d Cov_mm = m_Cov_tt.block(3,3,3,3);
198+
return { m_t.segment(3,3), Cov_mm};
199199
}
200200

201201

202202
//! Get the delimiting uncertain straight line n in homogeneous coordinates.
203203
uStraightLine uStraightLineSegment::un() const
204204
{
205-
Matrix3d Cov_nn = Cov_tt_.bottomRightCorner(3,3);
206-
return { t_.tail(3), Cov_nn};
205+
Matrix3d Cov_nn = m_Cov_tt.bottomRightCorner(3,3);
206+
return { m_t.tail(3), Cov_nn};
207207
}
208208

209209

210210
//! Get the endpoint x in homogeneous coordinates
211211
Vector3d uStraightLineSegment::hx() const
212212
{
213-
Vector3d l = t_.head(3);
214-
Vector3d m = t_.segment(3,3);
213+
Vector3d l = m_t.head(3);
214+
Vector3d m = m_t.segment(3,3);
215215
return skew( l )*m;
216216
}
217217

218218

219219
//! Get the endpoint y in homogeneous coordinates
220220
Vector3d uStraightLineSegment::hy() const
221221
{
222-
Vector3d l = t_.head(3);
223-
Vector3d n = t_.tail(3);
222+
Vector3d l = m_t.head(3);
223+
Vector3d n = m_t.tail(3);
224224
return skew( l )*n;
225225
}
226226

@@ -294,8 +294,8 @@ bool uStraightLineSegment::isCopunctualWith( const uStraightLineSegment & us,
294294
//! Transform uncertain straight line segment via 9x9 transformation matrix for t = [l',m',n']'.
295295
void uStraightLineSegment::transform( const Matrix9d & TT)
296296
{
297-
t_ = TT*t_;
298-
Cov_tt_ = TT*Cov_tt_*TT.adjoint();
297+
m_t = TT*m_t;
298+
m_Cov_tt = TT*m_Cov_tt*TT.adjoint();
299299
}
300300

301301
/* Matlab: [~,idx] = sort(x);
@@ -318,6 +318,26 @@ VectorXi uStraightLineSegment::indices_of_sorting( const VectorXd &v)
318318
}*/
319319

320320

321+
QDataStream & operator<< (QDataStream & out, const Aabb & bbox)
322+
{
323+
out << bbox.x_min() << bbox.x_max()
324+
<< bbox.y_min() << bbox.y_max();
325+
return out;
326+
}
327+
328+
QDataStream & operator>> (QDataStream & in, Aabb & bbox)
329+
{
330+
double x_min;
331+
double x_max;
332+
double y_min;
333+
double y_max;
334+
in >> x_min >> x_max >> y_min >> y_max;
335+
bbox = Aabb( x_min, x_max, y_min, y_max);
336+
337+
return in;
338+
}
339+
340+
321341
QDataStream & operator>> ( QDataStream & in, Eigen::Matrix<double,9,1> & v);
322342

323343
//! Overloaded >>operator for 9-vectors
@@ -374,38 +394,29 @@ QDataStream & operator<< ( QDataStream & out, const Eigen::Matrix<double,9,9> &M
374394
return out;
375395
}
376396

377-
QDataStream & operator<< ( QDataStream & out, const aabb & box);
378-
379-
//! Overloaded <<operator for axis-aligned bounding box
380-
QDataStream & operator<< ( QDataStream & out, const aabb & bbox)
381-
{
382-
qDebug() << Q_FUNC_INFO;
383-
out << bbox.x_min() << bbox.x_max() << bbox.y_min() << bbox.y_max();
384-
return out;
385-
}
386-
387397

388398
//! Serialization of the uncertain straight line segment t=[l',m',n']' and its bounding box
389399
void uStraightLineSegment::serialize( QDataStream & out ) const
390400
{
391401
qDebug() << Q_FUNC_INFO;
392-
out << t_;
393-
out << Cov_tt_;
394-
bounding_box_.serialize( out);
402+
out << m_t;
403+
out << m_Cov_tt;
404+
out << m_bounding_box;
395405
}
396406

397407
//! Deserialization of uncertain straight line segment and its bounding box
398408
bool uStraightLineSegment::deserialize( QDataStream & in )
399409
{
400410
qDebug() << Q_FUNC_INFO;
401-
in >> t_;
402-
in >> Cov_tt_;
403-
if ( in.status()!=0 ) {
404-
return false;
405-
}
406-
if ( !bounding_box_.deserialize( in) ) {
411+
in >> m_t;
412+
in >> m_Cov_tt;
413+
// if ( in.status()!=0 ) {
414+
// return false;
415+
// }
416+
in >> m_bounding_box;
417+
/* if ( !bounding_box_.deserialize( in) ) {
407418
return false;
408-
}
419+
} */
409420
return in.status()==0;
410421
}
411422

0 commit comments

Comments
 (0)