2013-11-11 14:42:11 +00:00
|
|
|
#ifndef SPACESEGMENT_H
|
|
|
|
#define SPACESEGMENT_H
|
|
|
|
|
|
|
|
#include "basics_global.h"
|
|
|
|
|
|
|
|
#include "Vector3.h"
|
|
|
|
|
2014-03-01 00:34:34 +00:00
|
|
|
namespace paysages {
|
|
|
|
namespace basics {
|
2013-11-11 14:42:11 +00:00
|
|
|
|
2015-10-15 18:01:08 +00:00
|
|
|
/**
|
|
|
|
* A delimited segment in 3D space (mainly useful for rays).
|
2013-11-11 14:42:11 +00:00
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class BASICSSHARED_EXPORT SpaceSegment {
|
|
|
|
public:
|
|
|
|
SpaceSegment(const Vector3 &start, const Vector3 &end);
|
|
|
|
SpaceSegment() : SpaceSegment(Vector3(), Vector3()) {
|
|
|
|
}
|
2013-11-11 14:42:11 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline const Vector3 &getStart() const {
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
inline const Vector3 &getEnd() const {
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
inline Vector3 getDirection() const {
|
|
|
|
return end.sub(start);
|
|
|
|
}
|
|
|
|
inline double getLength() const {
|
|
|
|
return end.sub(start).getNorm();
|
|
|
|
}
|
2013-11-11 14:42:11 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline double getXDiff() const {
|
|
|
|
return end.x - start.x;
|
|
|
|
}
|
|
|
|
inline double getYDiff() const {
|
|
|
|
return end.y - start.y;
|
|
|
|
}
|
|
|
|
inline double getZDiff() const {
|
|
|
|
return end.z - start.z;
|
|
|
|
}
|
2015-09-29 20:31:25 +00:00
|
|
|
|
2015-10-15 18:01:08 +00:00
|
|
|
/**
|
|
|
|
* Keep only the intersection with a slice orthogonal to the Y axis.
|
|
|
|
*
|
|
|
|
* Return true if a segment remains.
|
2013-11-11 14:42:11 +00:00
|
|
|
*/
|
|
|
|
bool intersectYInterval(double ymin, double ymax);
|
|
|
|
|
2015-11-02 19:14:35 +00:00
|
|
|
/**
|
|
|
|
* Return true if the segment intersects a bounding box, represented by another segment (crossing diagonal).
|
|
|
|
*/
|
|
|
|
bool intersectBoundingBox(const SpaceSegment &bbox) const;
|
|
|
|
|
2015-10-15 18:01:08 +00:00
|
|
|
/**
|
|
|
|
* Return a version of this segment, projected on a X plane.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
SpaceSegment projectedOnXPlane(double x = 0.0) const;
|
2015-10-15 18:01:08 +00:00
|
|
|
/**
|
|
|
|
* Return a version of this segment, projected on a Y plane.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
SpaceSegment projectedOnYPlane(double y = 0.0) const;
|
2015-10-15 18:01:08 +00:00
|
|
|
/**
|
|
|
|
* Return a version of this segment, projected on a Z plane.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
SpaceSegment projectedOnZPlane(double z = 0.0) const;
|
2015-10-15 18:01:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a scaled version of this segment.
|
|
|
|
*
|
|
|
|
* Pay attention, scaling is done from the coordinates origin (0,0,0), not the segment center.
|
|
|
|
*/
|
|
|
|
SpaceSegment scaled(double factor) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate inside a virtual grid.
|
|
|
|
*
|
|
|
|
* The space is considered as cut into 1.0-sized cubic cells,
|
|
|
|
* and the delegate will be called with coordinates of the cells
|
|
|
|
* traversed by this segment.
|
|
|
|
*
|
|
|
|
* Return false if the iteration was aborted by the delegate, true otherwise.
|
|
|
|
*/
|
|
|
|
bool iterateOnGrid(SpaceGridIterator &delegate);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2013-11-11 14:42:11 +00:00
|
|
|
Vector3 start;
|
|
|
|
Vector3 end;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SPACESEGMENT_H
|