20 #ifndef _STELSPHEREGEOMETRY_HPP_ 21 #define _STELSPHEREGEOMETRY_HPP_ 23 #include "OctahedronPolygon.hpp" 24 #include "StelVertexArray.hpp" 25 #include "VecMath.hpp" 30 #include <QSharedPointer> 31 #include <QVarLengthArray> 32 #include <QDataStream> 57 SphericalRegionP(
const QWeakPointer<SphericalRegion>& other) : QSharedPointer<SphericalRegion>(other) {;}
110 static void serializeToJson(
const QVariant& jsonObject, QIODevice* output,
int indentLevel=0);
118 static int initialize();
148 virtual ~SphericalRegion() {;}
157 virtual double getArea()
const {
return getOctahedronPolygon().getArea();}
160 virtual bool isEmpty()
const {
return getOctahedronPolygon().isEmpty();}
166 virtual QVector<SphericalCap> getBoundingSphericalCaps()
const;
189 virtual QVector<QVector<Vec3d > > getSimplifiedContours()
const;
192 virtual QVariantList toQVariant()
const = 0;
195 virtual void serialize(QDataStream& out)
const = 0;
199 QByteArray toJSON()
const;
203 bool contains(
const SphericalRegion* r)
const;
205 virtual bool contains(
const Vec3d& p)
const {
return getOctahedronPolygon().contains(p);}
215 bool intersects(
const SphericalRegion* r)
const;
216 bool intersects(
const SphericalRegionP r)
const {
return intersects(r.data());}
217 bool intersects(
const Vec3d& p)
const {
return contains(p);}
259 bool containsDefault(
const SphericalRegion* r)
const;
260 bool intersectsDefault(
const SphericalRegion* r)
const;
285 Q_ASSERT(d==0 || std::fabs(n.lengthSquared()-1.)<0.0000001);}
303 virtual double getArea()
const {
return 2.*M_PI*(1.-d);}
315 virtual bool contains(
const Vec3d &v)
const {Q_ASSERT(d==0 || std::fabs(v.lengthSquared()-1.)<0.0000002);
return (v*n>=d);}
316 virtual bool contains(
const Vec3f &v)
const {Q_ASSERT(d==0 || std::fabs(v.lengthSquared()-1.f)<0.000002f);
return (v[0]*n[0]+v[1]*n[1]+v[2]*n[2]>=d);}
320 const double a = n*h.
n-d*h.
d;
321 return d<=h.
d && ( a>=1. || (a>=0. && a*a >= (1.-d*d)*(1.-h.
d*h.
d)));
331 const double a = d*h.
d - n*h.
n;
332 return d+h.
d<=0. || a<=0. || (a<=1. && a*a <= (1.-d*d)*(1.-h.
d*h.
d));
339 virtual QVariantList toQVariant()
const;
341 virtual void serialize(QDataStream& out)
const {out << n << d;}
355 const double a = n[0]*hn0+n[1]*hn1+n[2]*hn2;
356 return d<=0. || a<=0. || (a<=1. && a*a <= (1.-d*d));
361 bool clipGreatCircle(
Vec3d& v1,
Vec3d& v2)
const;
367 QVector<Vec3d> getClosedOutlineContour()
const;
370 bool intersectsConvexContour(
const Vec3d* vertice,
int nbVertice)
const;
373 bool containsTriangle(
const Vec3d* vertice)
const;
376 bool intersectsTriangle(
const Vec3d* vertice)
const;
404 return (v1[1] * v2[2] - v1[2] * v2[1])*p[0] +
405 (v1[2] * v2[0] - v1[0] * v2[2])*p[1] +
406 (v1[0] * v2[1] - v1[1] * v2[0])*p[2]>=-1e-17;
412 Vec3d n(v1[1]*v2[2]-v1[2]*v2[1], v2[0]*v1[2]-v2[2]*v1[0], v2[1]*v1[0]-v2[0]*v1[1]);
414 const double a = n*h.
n;
415 return 0<=h.
d && ( a>=1. || (a>=0. && a*a >= 1.-h.
d*h.
d));
421 Vec3d n(v1[1]*v2[2]-v1[2]*v2[1], v2[0]*v1[2]-v2[2]*v1[0], v2[1]*v1[0]-v2[0]*v1[1]);
442 virtual QVariantList toQVariant()
const;
443 virtual void serialize(QDataStream& out)
const {out << n;}
446 virtual bool contains(
const Vec3d& p)
const {
return n==p;}
449 virtual bool contains(
const SphericalCap&)
const {
return false;}
454 virtual bool intersects(
const SphericalCap& r)
const {
return r.contains(n);}
455 virtual bool intersects(
const SphericalPoint& r)
const {
return n==r.
n;}
474 virtual double getArea()
const {
return 4.*M_PI;}
480 virtual QVariantList toQVariant()
const;
484 virtual bool contains(
const Vec3d&)
const {
return true;}
487 virtual bool contains(
const SphericalCap&)
const {
return true;}
492 virtual bool intersects(
const SphericalCap&)
const {
return true;}
493 virtual bool intersects(
const SphericalPoint&)
const {
return true;}
522 virtual QVariantList toQVariant()
const;
526 virtual bool contains(
const Vec3d&)
const {
return false;}
529 virtual bool contains(
const SphericalCap&)
const {
return false;}
530 virtual bool contains(
const SphericalPoint&)
const {
return false;}
534 virtual bool intersects(
const SphericalCap&)
const {
return false;}
535 virtual bool intersects(
const SphericalPoint&)
const {
return false;}
557 SphericalPolygon(
const QVector<QVector<Vec3d> >& contours) : octahedronPolygon(contours) {;}
561 SphericalPolygon(
const QList<OctahedronPolygon>& octContours) : octahedronPolygon(octContours) {;}
570 virtual QVariantList toQVariant()
const;
571 virtual void serialize(QDataStream& out)
const;
575 virtual bool contains(
const Vec3d& p)
const {
return octahedronPolygon.contains(p);}
576 virtual bool contains(
const SphericalPolygon& r)
const {
return octahedronPolygon.contains(r.octahedronPolygon);}
579 virtual bool contains(
const SphericalPoint& r)
const {
return octahedronPolygon.contains(r.
n);}
582 virtual bool intersects(
const SphericalPolygon& r)
const {
return octahedronPolygon.intersects(r.octahedronPolygon);}
584 virtual bool intersects(
const SphericalCap& r)
const {
return r.intersects(*
this);}
585 virtual bool intersects(
const SphericalPoint& r)
const {
return octahedronPolygon.contains(r.
n);}
615 static SphericalRegionP multiUnion(
const QList<SphericalRegionP>& regions,
bool optimizeByPreGrouping=
false);
618 static SphericalRegionP multiIntersection(
const QList<SphericalRegionP>& regions);
638 SphericalConvexPolygon(
const QVector<QVector<Vec3d> >& contours) {Q_ASSERT(contours.size()==1); setContour(contours.at(0));}
650 virtual double getArea()
const;
651 virtual bool isEmpty()
const {
return contour.isEmpty();}
652 virtual Vec3d getPointInside()
const;
654 QVector<SphericalCap> getBoundingSphericalCaps()
const;
659 virtual QVariantList toQVariant()
const;
660 virtual void serialize(QDataStream& out)
const {out << contour;}
663 virtual bool contains(
const Vec3d& p)
const;
667 virtual bool contains(
const SphericalPoint& r)
const {
return contains(r.
n);}
669 virtual bool intersects(
const SphericalCap& r)
const {
if (!cachedBoundingCap.intersects(r))
return false;
return r.intersects(*
this);}
672 virtual bool intersects(
const SphericalPoint& r)
const {
return contains(r.
n);}
697 void setContour(
const QVector<Vec3d>& acontour) {contour=acontour; updateBoundingCap();}
703 bool checkValid()
const;
706 static bool checkValidContour(
const QVector<Vec3d>& contour);
719 void updateBoundingCap();
726 static bool areAllPointsOutsideOneSide(
const Vec3d* thisContour,
int nbThisContour,
const Vec3d* points,
int nbPoints);
731 return areAllPointsOutsideOneSide(contour.constData(), contour.size(), points.constData(), points.size());
734 bool containsConvexContour(
const Vec3d* vertice,
int nbVertex)
const;
826 virtual QVariantList toQVariant()
const;
827 virtual void serialize(QDataStream& out)
const {Q_UNUSED(out); Q_ASSERT(0);}
833 void setContours(
const QVector<QVector<TextureVertex> >& contours) {Q_UNUSED(contours); Q_ASSERT(0);}
837 void setContour(
const QVector<TextureVertex>& contour) {Q_UNUSED(contour); Q_ASSERT(0);}
842 QVector<Vec2f> textureCoords;
881 virtual QVariantList toQVariant()
const;
883 virtual void serialize(QDataStream& out)
const {out << contour << textureCoords;}
902 #endif // _STELSPHEREGEOMETRY_HPP_ SphericalConvexPolygon(const Vec3d &e0, const Vec3d &e1, const Vec3d &e2, const Vec3d &e3)
Special constructor for quads.
SphericalCap cachedBoundingCap
Cache the bounding cap.
Special SphericalRegion for the whole sphere.
bool areAllPointsOutsideOneSide(const QVector< Vec3d > &points) const
Computes whether the passed points are all outside of at least one SphericalCap defining the polygon ...
virtual StelVertexArray getFillVertexArray() const
Return an openGL compatible array to be displayed using vertex arrays.
virtual SphericalCap getBoundingCap() const
Return a bounding SphericalCap.
virtual Vec3d getPointInside() const
Return a point located inside the region.
virtual double getArea() const
Get the area of the intersection of the halfspace on the sphere in steradian.
double d
The cos of cone radius.
virtual StelVertexArray getFillVertexArray() const
Return an openGL compatible array to be displayed using vertex arrays.
SphericalConvexPolygon()
Default constructor.
SphericalConvexPolygon(const Vec3d &e0, const Vec3d &e1, const Vec3d &e2)
Special constructor for triangle.
virtual Vec3d getPointInside() const
Return a point located inside the SphericalCap.
SphericalRegionP getIntersection(const SphericalRegion *r) const
Return a new SphericalRegion consisting of the intersection of this and the given region...
SphericalRegionType
define types for all supported regions.
double getRadius() const
Return the radiusof the cap in radian.
QVector< Vec3d > contour
A list of vertices of the convex contour.
virtual OctahedronPolygon getOctahedronPolygon() const
Return the octahedron contour representation of the polygon.
SphericalConvexPolygon(const QVector< QVector< Vec3d > > &contours)
Constructor from a list of contours.
SphericalTexturedPolygon(const QVector< TextureVertex > &contour)
Constructor from one contour.
virtual bool isEmpty() const
Return true if the region is empty.
virtual bool isEmpty() const
Return true if the region is empty.
A shared pointer on a SphericalRegion.
static int metaTypeId
The meta type ID associated to a SphericalRegionP.
virtual void serialize(QDataStream &) const
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
A SphericalCap is defined by a direction and an aperture.
virtual OctahedronPolygon getOctahedronPolygon() const
Return the octahedron contour representation of the polygon.
static void serializeToJson(const QVariant &jsonObject, QIODevice *output, int indentLevel=0)
Method registered to JSON serializer.
static SphericalRegionP loadFromJson(QIODevice *in)
Create a SphericalRegion from the given input JSON stream.
Special SphericalRegion for — UMM, WHAT EXACTLY?
SphericalRegionP getUnion(const SphericalRegion *r) const
Return a new SphericalRegion consisting of the union of this and the given region.
virtual OctahedronPolygon getOctahedronPolygon() const
Return the octahedron contour representation of the polygon.
Manage a non-convex polygon which can extends on more than 180 deg.
virtual bool isEmpty() const
Return true if the region is empty.
virtual bool isEmpty() const
Return true if the region is empty.
virtual StelVertexArray getOutlineVertexArray() const
Get the outline of the contours defining the SphericalPolygon.
Vec3d n
The direction unit vector. Only if d==0, this vector doesn't need to be unit.
Class defining default implementations for some spherical geometry methods.
Special SphericalRegion for a point on the sphere.
virtual double getArea() const
Return the area of the region in steradians.
virtual bool intersects(const SphericalCap &h) const
Returns whether a SphericalCap intersects with this one.
SphericalCap(double x, double y, double z)
Construct a SphericalCap from its direction and assumes a 90 deg aperture.
virtual Vec3d getPointInside() const
Return a point located inside the region.
SphericalRegionP getSubtraction(const SphericalRegion *r) const
Return a new SphericalRegion consisting of the subtraction of the given region from this...
bool contains(const SphericalRegion *r) const
Returns whether a SphericalRegion is contained into this region.
A special case of SphericalPolygon for which the polygon is convex.
virtual bool isEmpty() const
Return true if the region is empty.
void setContours(const QVector< QVector< TextureVertex > > &contours)
Set the contours defining the SphericalPolygon.
virtual SphericalCap getBoundingCap() const
Return a bounding SphericalCap.
virtual void serialize(QDataStream &out) const
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
void setContour(const QVector< TextureVertex > &contour)
Set a single contour defining the SphericalPolygon.
static SphericalRegionP loadFromQVariant(const QVariantMap &map)
Create a SphericalRegion from the given QVariantMap with a format matching the JSON file parsed in lo...
virtual Vec3d getPointInside() const
Return a point located inside the region.
virtual Vec3d getPointInside() const
Return a point located inside the region.
Vec3d n
The unit vector of the point direction.
Vec3d greatCircleIntersection(const Vec3d &p1, const Vec3d &p2, const Vec3d &p3, const Vec3d &p4, bool &ok)
Compute the intersection of 2 great circles segments.
void setContour(const QVector< Vec3d > &acontour)
Set a single contour defining the SphericalPolygon.
SphericalTexturedConvexPolygon(const Vec3d &e0, const Vec3d &e1, const Vec3d &e2, const Vec3d &e3)
Special constructor for quads.
Abstract class defining a region of the sphere.
virtual void serialize(QDataStream &) const
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
virtual OctahedronPolygon getOctahedronPolygon() const
Return the octahedron contour representation of the polygon.
bool intersects(const SphericalRegion *r) const
Returns whether a SphericalRegion intersects with this region.
SphericalPolygon(const QVector< Vec3d > &contour)
Constructor from one contour.
SphericalCap(const SphericalCap &other)
Copy constructor.
An extension of SphericalPolygon with addition of texture coordinates.
QVector< QVector< Vec3d > > getClosedOutlineContours() const
Return the list of closed contours defining the polygon boundaries.
virtual SphericalCap getBoundingCap() const
Return a bounding SphericalCap.
virtual SphericalCap getBoundingCap() const
Return itself.
bool sideHalfSpaceIntersects(const Vec3d &v1, const Vec3d &v2, const SphericalCap &h)
Return whether the halfspace defined by the vectors v1 and v2 intersects the SphericalCap h...
virtual OctahedronPolygon getOctahedronPolygon() const
Return the octahedron contour representation of the polygon.
SphericalConvexPolygon(const QVector< Vec3d > &contour)
Constructor from one contour.
bool intersectsHalfSpace(double hn0, double hn1, double hn2) const
Returns whether a HalfSpace (like a SphericalCap with d=0) intersects with this SphericalCap.
SphericalTexturedPolygon(const QVector< QVector< TextureVertex > > &contours)
Constructor from a list of contours.
SphericalCap(const Vec3d &an, double ar)
Construct a SphericalCap from its direction and aperture.
bool sideHalfSpaceContains(const Vec3d &v1, const Vec3d &v2, const Vec3d &p)
Return whether the halfspace defined by the vectors v1^v2 and with aperture 90 deg contains the point...
virtual void serialize(QDataStream &out) const
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
virtual void serialize(QDataStream &out) const
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
SphericalTexturedConvexPolygon(const QVector< Vec3d > &contour, const QVector< Vec2f > &texCoord)
Constructor from one contour.
SphericalTexturedConvexPolygon()
Default constructor.
virtual double getArea() const
Return the area of the region in steradians.
const QVector< Vec3d > & getConvexContour() const
Get the single contour defining the SphericalConvexPolygon.
virtual double getArea() const
Return the area of the region in steradians.
SphericalPolygon(const QVector< QVector< Vec3d > > &contours)
Constructor from a list of contours.
void setContour(const QVector< Vec3d > &contour)
Set a single contour defining the SphericalPolygon.
virtual void serialize(QDataStream &out) const
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
A container for 3D vertex + associated texture coordinates.
bool operator==(const SphericalCap &other) const
Comparison operator.
virtual bool isEmpty() const
Return true if the region is empty.
virtual StelVertexArray getFillVertexArray() const
Return an openGL compatible array of texture coords to be used using vertex arrays.
SphericalCap()
Construct a SphericalCap with a 90 deg aperture and an undefined direction.
virtual void setContour(const QVector< Vec3d > &acontour, const QVector< Vec2f > &texCoord)
Set a single contour defining the SphericalPolygon.
virtual double getArea() const
Return the area of the region in steradians.
virtual StelVertexArray getFillVertexArray() const
Return an openGL compatible array to be displayed using vertex arrays.
void setContours(const QVector< QVector< Vec3d > > &contours)
Set the contours defining the SphericalPolygon.
virtual StelVertexArray getOutlineVertexArray() const
Get the outline of the contours defining the SphericalPolygon.
virtual void serialize(QDataStream &out) const
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
Extension of SphericalConvexPolygon for textured polygon.
virtual SphericalCap getBoundingCap() const
Return a bounding SphericalCap.
QVector< Vec2f > textureCoords
A list of uv textures coordinates corresponding to the triangle vertices.