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();
195 virtual void serialize(QDataStream& out)
const = 0;
199 QByteArray
toJSON()
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));
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));
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]);
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);}
474 virtual double getArea()
const {
return 4.*M_PI;}
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;}
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) {;}
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);}
650 virtual double getArea()
const;
663 virtual bool contains(
const Vec3d& p)
const;
667 virtual bool contains(
const SphericalPoint& r)
const {
return contains(r.
n);}
672 virtual bool intersects(
const SphericalPoint& r)
const {
return contains(r.
n);}
734 bool containsConvexContour(
const Vec3d* vertice,
int nbVertex)
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;
902 #endif // _STELSPHEREGEOMETRY_HPP_
SphericalConvexPolygon(const Vec3d &e0, const Vec3d &e1, const Vec3d &e2, const Vec3d &e3)
Special constructor for quads.
bool containsTriangle(const Vec3d *vertice) const
Return whether the cap contains the passed triangle.
static SphericalRegionP deserialize(QDataStream &in)
Deserialize the region. This method must allow as fast as possible deserialization.
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 SphericalRegionP getEnlarged(double margin) const
Return an enlarged version of this SphericalRegion so that any point distant of more than the given m...
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.
bool clipGreatCircle(Vec3d &v1, Vec3d &v2) const
Clip the passed great circle connecting points v1 and v2.
static bool areAllPointsOutsideOneSide(const Vec3d *thisContour, int nbThisContour, const Vec3d *points, int nbPoints)
Computes whether the passed points are all outside of at least one SphericalCap defining the polygon ...
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.
virtual double getArea() const
Return the area of the region in steradians.
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.
bool checkValid() const
Check if the polygon is valid, i.e. it has no side >180.
virtual bool isEmpty() const
Return true if the region is empty.
A shared pointer on a SphericalRegion.
virtual QVariantList toQVariant() const
Serialize the region into a QVariant map matching the JSON format.
virtual QVariantList toQVariant() const
Serialize the region into a QVariant map matching the JSON format.
static int metaTypeId
The meta type ID associated to a SphericalRegionP.
static SphericalRegionP multiIntersection(const QList< SphericalRegionP > ®ions)
Create a new SphericalRegionP which is the intersection of all the passed ones.
virtual void serialize(QDataStream &out) const =0
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
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.
virtual Vec3d getPointInside() const
Return a point located inside the region.
static bool intersectionPoints(const SphericalCap &h1, const SphericalCap &h2, Vec3d &p1, Vec3d &p2)
Compute the intersection of 2 halfspaces on the sphere (usually on 2 points) and return it in p1 and ...
virtual QVariantList toQVariant() const
Serialize the region into a QVariant map matching the JSON format.
QByteArray toJSON() const
Output a JSON string representing the polygon.
virtual void serialize(QDataStream &out) const
Serialize the region. This method must allow as fast as possible serialization and work with deserial...
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.
static SphericalRegionP multiUnion(const QList< SphericalRegionP > ®ions, bool optimizeByPreGrouping=false)
Create a new SphericalRegionP which is the union of all the passed ones.
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.
StelVertexArray getFillVertexArray() const
Returns the list of triangles resulting from tesselating the contours.
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.
virtual QVariantList toQVariant() const
Serialize the region into a QVariant map matching the JSON format.
static SphericalRegionP deserialize(QDataStream &in)
Deserialize the region. This method must allow as fast as possible deserialization.
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...
virtual SphericalCap getBoundingCap() const
Return a bounding SphericalCap.
bool contains(const SphericalRegion *r) const
Returns whether a SphericalRegion is contained into this region.
static double relativeDiameterOverlap(const SphericalCap &c1, const SphericalCap &c2)
Return the relative overlap between the diameter of the 2 caps, i.e: min(intersectionDistance/c1.diameter, intersectionDistance/c2.diameter)
A special case of SphericalPolygon for which the polygon is convex.
QDataStream & operator<<(QDataStream &out, const SphericalRegionP ®ion)
Serialize the passed SphericalRegionP into a binary blob.
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 QVector< SphericalCap > getBoundingSphericalCaps() const
Return the list of SphericalCap bounding the ConvexPolygon.
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 bool checkValidContour(const QVector< Vec3d > &contour)
Check if the passed contour is convex and valid, i.e. it has no side >180.
static SphericalRegionP loadFromQVariant(const QVariantMap &map)
Create a SphericalRegion from the given QVariantMap with a format matching the JSON file parsed in lo...
static SphericalRegionP deserialize(QDataStream &in)
Deserialize the region. This method must allow as fast as possible deserialization.
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.
virtual QVariantList toQVariant() const
Serialize the region into a QVariant map matching the JSON format.
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.
QVector< SphericalCap > getBoundingSphericalCaps() const
Return the list of SphericalCap bounding the ConvexPolygon.
virtual OctahedronPolygon getOctahedronPolygon() const =0
Return the octahedron contour representation of the polygon.
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.
QVector< Vec3d > getClosedOutlineContour() const
Return the list of closed contours defining the polygon boundaries.
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...
static SphericalRegionP deserialize(QDataStream &in)
Deserialize the region. This method must allow as fast as possible deserialization.
virtual OctahedronPolygon getOctahedronPolygon() const
Return the octahedron contour representation of the polygon.
QDataStream & operator>>(QDataStream &in, SphericalRegionP ®ion)
Load the SphericalRegionP from a binary blob.
bool intersectsConvexContour(const Vec3d *vertice, int nbVertice) const
Return whether the cap intersect with a convex contour defined by nbVertice.
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 QVariantList toQVariant() const
Serialize the region into a QVariant map matching the JSON format.
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.
bool intersectsTriangle(const Vec3d *vertice) const
Return whether the cap intersect with the passed triangle.
virtual double getArea() const
Return the area of the region in steradians.
SphericalPolygon(const QVector< QVector< Vec3d > > &contours)
Constructor from a list of contours.
virtual QVariantList toQVariant() const
Serialize the region into a QVariant map matching the JSON format.
void setContour(const QVector< Vec3d > &contour)
Set a single contour defining the SphericalPolygon.
virtual QVector< QVector< Vec3d > > getSimplifiedContours() const
Get the contours defining the SphericalPolygon when combined using a positive winding rule...
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.
virtual OctahedronPolygon getOctahedronPolygon() const
Return the octahedron contour representation of the polygon.
SphericalCap()
Construct a SphericalCap with a 90 deg aperture and an undefined direction.
static double relativeAreaOverlap(const SphericalCap &c1, const SphericalCap &c2)
Return the relative overlap between the areas of the 2 caps, i.e: min(intersectionArea/c1.area, intersectionArea/c2.area)
virtual void setContour(const QVector< Vec3d > &acontour, const QVector< Vec2f > &texCoord)
Set a single contour defining the SphericalPolygon.
virtual QVariantList toQVariant() const
Serialize the region into a QVariant map matching the JSON format.
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 QVariantList toQVariant() const =0
Serialize the region into a QVariant list matching the JSON format.
void updateBoundingCap()
Update the bounding cap from the vertex list.
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.
virtual SphericalCap getBoundingCap() const
Return a bounding SphericalCap.