StelSphereGeometry.hpp   StelSphereGeometry.hpp
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef _STELSPHEREGEOMETRY_HPP_ #ifndef _STELSPHEREGEOMETRY_HPP_
#define _STELSPHEREGEOMETRY_HPP_ #define _STELSPHEREGEOMETRY_HPP_
#include "config.h"
#include "OctahedronPolygon.hpp"
#include "StelVertexArray.hpp"
#include "VecMath.hpp"
#include <QVector>
#include <QVariant>
#include <QDebug> #include <QDebug>
#include <QSharedPointer> #include <QSharedPointer>
#include <QVarLengthArray> #include <QVarLengthArray>
#include <Q> #include <QDataStream>
#include #include <stdio.h>
class SphericalRegion; class SphericalRegion;
class SphericalPolygon; class SphericalPolygon;
class SphericalConvexPolygon; class SphericalConvexPolygon;
class SphericalCap; class SphericalCap;
class SphericalPoint; class SphericalPoint;
class AllSkySphericalRegion; class AllSkySphericalRegion;
class EmptySphericalRegion; class EmptySphericalRegion;
//! @file StelSphereGeometry.hpp //! @file StelSphereGeometry.hpp
skipping to change at line 146 skipping to change at line 150
{ {
Point = 0, Point = 0,
Cap = 1, Cap = 1,
AllSky = 2, AllSky = 2,
Polygon = 3, Polygon = 3,
ConvexPolygon = 4, ConvexPolygon = 4,
Empty = 5, Empty = 5,
Invalid = 6 Invalid = 6
}; };
virtual ~SphericalRegion() {;}
virtual ~SphericalRegion()
virtual SphericalRegionType getType() const = 0; virtual SphericalRegionType getType() const = 0;
//! Return the octahedron contour representation of the polygon. //! Return the octahedron contour representation of the polygon.
//! It can be used for safe computation of intersection/union in the general case. //! It can be used for safe computation of intersection/union in the general case.
virtual OctahedronPolygon getOctahedronPolygon() const =0; virtual OctahedronPolygon getOctahedronPolygon() const =0;
//! Return the area of the region in steradians. //! Return the area of the region in steradians.
virtual double getArea() const {return getOctahedronPolygon().getAre a();} virtual double getArea() const {return getOctahedronPolygon().getAre a();}
skipping to change at line 317 skipping to change at line 182
virtual SphericalCap getBoundingCap() const; virtual SphericalCap getBoundingCap() const;
//! Return an enlarged version of this SphericalRegion so that any p oint distant of more //! Return an enlarged version of this SphericalRegion so that any p oint distant of more
//! than the given margin now lays within the region. //! than the given margin now lays within the region.
//! The returned region can be larger than the smallest enlarging re gion, therefore returning //! The returned region can be larger than the smallest enlarging re gion, therefore returning
//! false positive on subsequent intersection tests. //! false positive on subsequent intersection tests.
//! The default implementation always return an enlarged bounding Sp hericalCap. //! The default implementation always return an enlarged bounding Sp hericalCap.
//! @param margin the minimum enlargement margin in radian. //! @param margin the minimum enlargement margin in radian.
virtual SphericalRegionP getEnlarged(double margin) const; virtual SphericalRegionP getEnlarged(double margin) const;
//! vertex //! Return an openGL compatible array to be displayed using vertex a
rrays.
virtual StelVertexArray getFillVertexArray() const {return getOctahe
dronPolygon().getFillVertexArray();}
virtual const
//! Get the outline of the contours defining the SphericalPolygon. //! Get the outline of the contours defining the SphericalPolygon.
//! @return a list of which define the contours of the //! @return a list of vertex which taken 2 by 2 define the contours
of the polygon.
virtual const virtual StelVertexArray getOutlineVertexArray() const {return getOct
ahedronPolygon().getOutlineVertexArray();}
//! Get the contours defining the SphericalPolygon when combined usi ng a positive winding rule. //! Get the contours defining the SphericalPolygon when combined usi ng a positive winding rule.
//! The default implementation return a list of tesselated triangles derived from the OctahedronPolygon. //! The default implementation return a list of tesselated triangles derived from the OctahedronPolygon.
virtual QVector<QVector<Vec3d > > getSimplifiedContours() const; virtual QVector<QVector<Vec3d > > getSimplifiedContours() const;
//! Serialize the region into a QVariant list matching the JSON form at. //! Serialize the region into a QVariant list matching the JSON form at.
virtual QVariantList toQVariant() const = 0; virtual QVariantList toQVariant() const = 0;
//! Serialize the region. This method must allow as fast as possible serialization and work with deserialize(). //! Serialize the region. This method must allow as fast as possible serialization and work with deserialize().
virtual void serialize(QDataStream& out) const = 0; virtual void serialize(QDataStream& out) const = 0;
skipping to change at line 419 skipping to change at line 260
//! A default potentially very slow implementation is provided for e ach cases. //! A default potentially very slow implementation is provided for e ach cases.
SphericalRegionP getSubtraction(const SphericalRegion* r) const; SphericalRegionP getSubtraction(const SphericalRegion* r) const;
SphericalRegionP getSubtraction(const SphericalRegionP r) const {ret urn getSubtraction(r.data());} SphericalRegionP getSubtraction(const SphericalRegionP r) const {ret urn getSubtraction(r.data());}
virtual SphericalRegionP getSubtraction(const SphericalPolygon& r) c onst; virtual SphericalRegionP getSubtraction(const SphericalPolygon& r) c onst;
virtual SphericalRegionP getSubtraction(const SphericalConvexPolygon & r) const; virtual SphericalRegionP getSubtraction(const SphericalConvexPolygon & r) const;
virtual SphericalRegionP getSubtraction(const SphericalCap& r) const ; virtual SphericalRegionP getSubtraction(const SphericalCap& r) const ;
virtual SphericalRegionP getSubtraction(const SphericalPoint& r) con st; virtual SphericalRegionP getSubtraction(const SphericalPoint& r) con st;
SphericalRegionP getSubtraction(const AllSkySphericalRegion& r) cons t; SphericalRegionP getSubtraction(const AllSkySphericalRegion& r) cons t;
virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const; virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const;
private: private:
bool containsDefault(const SphericalRegion* r) const; bool containsDefault(const SphericalRegion* r) const;
bool intersectsDefault(const SphericalRegion* r) const; bool intersectsDefault(const SphericalRegion* r) const;
SphericalRegionP getIntersectionDefault(const SphericalRegion* r) co nst; SphericalRegionP getIntersectionDefault(const SphericalRegion* r) co nst;
SphericalRegionP getUnionDefault(const SphericalRegion* r) const; SphericalRegionP getUnionDefault(const SphericalRegion* r) const;
SphericalRegionP getSubtractionDefault(const SphericalRegion* r) con st; SphericalRegionP getSubtractionDefault(const SphericalRegion* r) con st;
}; };
//! @class SphericalCap //! @class SphericalCap
//! A SphericalCap is defined by a direction and an aperture. //! A SphericalCap is defined by a direction and an aperture.
//! It forms a cone from the center of the Coordinate frame with a radius d . //! It forms a cone from the center of the Coordinate frame with a radius d .
//! It is a disc on the sphere, a region above a circle on the unit sphere. //! It is a disc on the sphere, a region above a circle on the unit sphere.
class SphericalCap : public SphericalRegion class SphericalCap : public SphericalRegion
{ {
using SphericalRegion::contains;
public: public:
//! Construct a SphericalCap with a 90 deg aperture and an undefined direction. //! Construct a SphericalCap with a 90 deg aperture and an undefined direction.
SphericalCap() : d(0) {;} SphericalCap() : d(0) {;}
//! Construct a SphericalCap from its direction and assumes a 90 deg aperture. //! Construct a SphericalCap from its direction and assumes a 90 deg aperture.
SphericalCap(double x, double y, double z) : n(x,y,z), d(0) {;} SphericalCap(double x, double y, double z) : n(x,y,z), d(0) {;}
//! Construct a SphericalCap from its direction and aperture. //! Construct a SphericalCap from its direction and aperture.
//! @param an a unit vector indicating the direction. //! @param an a unit vector indicating the direction.
//! @param ar cosinus of the aperture. //! @param ar cosinus of the aperture.
SphericalCap(const Vec3d& an, double ar) : n(an), d(ar) {//n.normali ze(); SphericalCap(const Vec3d& an, double ar) : n(an), d(ar) {//n.normali ze();
Q_ASSERT(d==0 || std::fabs(n.l engthSquared()-1.)<0.0000001);} Q_ASSERT(d==0 || std::fabs(n.l engthSquared()-1.)<0.0000001);}
// ause n should be normalized at this point, but // FIXME: GZ reports 2013-03-02: apparently the Q_ASSERT is here bec ause n should be normalized at this point, but
// for efficiency n.normalize() should not be called at this point. // for efficiency n.normalize() should not be called at this point.
// However, when zooming in a bit in Hammer-Aitoff and Mercator proj ections, this Assertion fires. // However, when zooming in a bit in Hammer-Aitoff and Mercator proj ections, this Assertion fires.
// Atmosphere must be active // Atmosphere must be active
// It may have to do with DSO texture rendering. // It may have to do with DSO texture rendering.
// found at r5863. // found at r5863.
// n.normalize() prevents this for now, but may cost performance. // n.normalize() prevents this for now, but may cost performance.
// AARGH - activating n.normalize() inhibits mouse-identification/se lection of stars! // AARGH - activating n.normalize() inhibits mouse-identification/se lection of stars!
// May be compiler dependent (seen on Win/MinGW), AW cannot confirm it on Linux. // May be compiler dependent (seen on Win/MinGW), AW cannot confirm it on Linux.
//! Copy constructor. //! Copy constructor.
skipping to change at line 545 skipping to change at line 316
//! Return true if the region is empty. //! Return true if the region is empty.
virtual bool isEmpty() const {return d>=1.;} virtual bool isEmpty() const {return d>=1.;}
//! Return a point located inside the SphericalCap. //! Return a point located inside the SphericalCap.
virtual Vec3d getPointInside() const {return n;} virtual Vec3d getPointInside() const {return n;}
//! Return itself. //! Return itself.
virtual SphericalCap getBoundingCap() const {return *this;} virtual SphericalCap getBoundingCap() const {return *this;}
// Contain and intersect // Contain and intersect
bool contains(const Vec3d &v) const virtual bool contains(const Vec3d &v) const {Q_ASSERT(d==0 || std::f
abs(v.lengthSquared()-1.)<0.0000002);return (v*n>=d);}
|| virtual bool contains(const Vec3f &v) const {Q_ASSERT(d==0 || std::f
abs(v.lengthSquared()-1.f)<0.000002f);return (v[0]*n[0]+v[1]*n[1]+v[2]*n[2]
>=d);}
virtual bool contains(const SphericalConvexPolygon& r) const; virtual bool contains(const SphericalConvexPolygon& r) const;
virtual bool contains(const SphericalCap& h) const virtual bool contains(const SphericalCap& h) const
{ {
const double a = n*h.n-d*h.d; const double a = n*h.n-d*h.d;
return d<=h.d && ( a>=1. || (a>=0. && a*a >= (1.-d*d)*(1.-h. d*h.d))); return d<=h.d && ( a>=1. || (a>=0. && a*a >= (1.-d*d)*(1.-h. d*h.d)));
} }
virtual bool contains(const AllSkySphericalRegion&) const {return d< =-1;} virtual bool contains(const AllSkySphericalRegion&) const {return d< =-1;}
virtual bool intersects(const SphericalPolygon& r) const; virtual bool intersects(const SphericalPolygon& r) const;
virtual bool intersects(const SphericalConvexPolygon& r) const; virtual bool intersects(const SphericalConvexPolygon& r) const;
//! Returns whether a SphericalCap intersects with this one. //! Returns whether a SphericalCap intersects with this one.
skipping to change at line 605 skipping to change at line 373
//! Comparison operator. //! Comparison operator.
bool operator==(const SphericalCap& other) const {return (n==other.n && d==other.d);} bool operator==(const SphericalCap& other) const {return (n==other.n && d==other.d);}
//! Return the list of closed contours defining the polygon boundari es. //! Return the list of closed contours defining the polygon boundari es.
QVector<Vec3d> getClosedOutlineContour() const; QVector<Vec3d> getClosedOutlineContour() const;
//! Return whether the cap intersect with a convex contour defined b y nbVertice. //! Return whether the cap intersect with a convex contour defined b y nbVertice.
bool intersectsConvexContour(const Vec3d* vertice, int nbVertice) co nst; bool intersectsConvexContour(const Vec3d* vertice, int nbVertice) co nst;
//! the cap the passed //! Return whether the cap contains the passed triangle.
bool containsTriangle(const const; bool containsTriangle(const Vec3d* vertice) const;
//! the cap intersect with the passed //! Return whether the cap intersect with the passed triangle.
bool intersectsTriangle(const const; bool intersectsTriangle(const Vec3d* vertice) const;
//! Deserialize the region. This method must allow as fast as possib le deserialization. //! Deserialize the region. This method must allow as fast as possib le deserialization.
static SphericalRegionP deserialize(QDataStream& in); static SphericalRegionP deserialize(QDataStream& in);
//! Return the relative overlap between the areas of the 2 caps, i.e : //! Return the relative overlap between the areas of the 2 caps, i.e :
//! min(intersectionArea/c1.area, intersectionArea/c2.area) //! min(intersectionArea/c1.area, intersectionArea/c2.area)
static double relativeAreaOverlap(const SphericalCap& c1, const Sphe ricalCap& c2); static double relativeAreaOverlap(const SphericalCap& c1, const Sphe ricalCap& c2);
//! Return the relative overlap between the diameter of the 2 caps, i.e: //! Return the relative overlap between the diameter of the 2 caps, i.e:
//! min(intersectionDistance/c1.diameter, intersectionDistance/c2.di ameter) //! min(intersectionDistance/c1.diameter, intersectionDistance/c2.di ameter)
skipping to change at line 706 skipping to change at line 474
}; };
//! @class AllSkySphericalRegion //! @class AllSkySphericalRegion
//! Special SphericalRegion for the whole sphere. //! Special SphericalRegion for the whole sphere.
class AllSkySphericalRegion : public SphericalRegion class AllSkySphericalRegion : public SphericalRegion
{ {
public: public:
virtual ~AllSkySphericalRegion() {;} virtual ~AllSkySphericalRegion() {;}
virtual SphericalRegionType getType() const {return SphericalRegion: :AllSky;} virtual SphericalRegionType getType() const {return SphericalRegion: :AllSky;}
virtual OctahedronPolygon getOctahedronPolygon() const virtual OctahedronPolygon getOctahedronPolygon() const {return Octah
edronPolygon::getAllSkyOctahedronPolygon();}
virtual double getArea() const {return 4.*M_PI;} virtual double getArea() const {return 4.*M_PI;}
virtual bool isEmpty() const {return false;} virtual bool isEmpty() const {return false;}
virtual Vec3d getPointInside() const {return Vec3d(1,0,0);} virtual Vec3d getPointInside() const {return Vec3d(1,0,0);}
virtual SphericalCap getBoundingCap() const {return SphericalCap(Vec 3d(1,0,0), -2);} virtual SphericalCap getBoundingCap() const {return SphericalCap(Vec 3d(1,0,0), -2);}
//! Serialize the region into a QVariant map matching the JSON forma t. //! Serialize the region into a QVariant map matching the JSON forma t.
//! The format is ["ALLSKY"] //! The format is ["ALLSKY"]
virtual QVariantList toQVariant() const; virtual QVariantList toQVariant() const;
virtual void serialize(QDataStream&) const {;} virtual void serialize(QDataStream&) const {;}
// Contain and intersect // Contain and intersect
skipping to change at line 735 skipping to change at line 500
virtual bool contains(const AllSkySphericalRegion&) const {return tr ue;} virtual bool contains(const AllSkySphericalRegion&) const {return tr ue;}
virtual bool intersects(const SphericalPolygon&) const {return true; } virtual bool intersects(const SphericalPolygon&) const {return true; }
virtual bool intersects(const SphericalConvexPolygon&) const {return true;} virtual bool intersects(const SphericalConvexPolygon&) const {return true;}
virtual bool intersects(const SphericalCap&) const {return true;} virtual bool intersects(const SphericalCap&) const {return true;}
virtual bool intersects(const SphericalPoint&) const {return true;} virtual bool intersects(const SphericalPoint&) const {return true;}
virtual bool intersects(const AllSkySphericalRegion&) const {return true;} virtual bool intersects(const AllSkySphericalRegion&) const {return true;}
static const SphericalRegionP staticInstance; static const SphericalRegionP staticInstance;
}; };
//! @class //! @class EmptySphericalRegion
//! Special SphericalRegion for //! Special SphericalRegion for --- UMM, WHAT EXACTLY?
class EmptySphericalRegion : public SphericalRegion class EmptySphericalRegion : public SphericalRegion
{ {
public: public:
using SphericalRegion::intersects; using SphericalRegion::intersects;
using SphericalRegion::contains; using SphericalRegion::contains;
using SphericalRegion::getIntersection; using SphericalRegion::getIntersection;
using SphericalRegion::getUnion; using SphericalRegion::getUnion;
using SphericalRegion::getSubtraction; using SphericalRegion::getSubtraction;
EmptySphericalRegion() {;} EmptySphericalRegion() {;}
virtual ~EmptySphericalRegion() {;} virtual ~EmptySphericalRegion() {;}
virtual SphericalRegionType getType() const {return SphericalRegion: :Empty;} virtual SphericalRegionType getType() const {return SphericalRegion: :Empty;}
virtual OctahedronPolygon getOctahedronPolygon() const virtual OctahedronPolygon getOctahedronPolygon() const {return Octah
edronPolygon::getEmptyOctahedronPolygon();}
virtual double getArea() const {return 0.;} virtual double getArea() const {return 0.;}
virtual bool isEmpty() const {return true;} virtual bool isEmpty() const {return true;}
virtual Vec3d getPointInside() const {return Vec3d(1,0,0);} virtual Vec3d getPointInside() const {return Vec3d(1,0,0);}
virtual SphericalCap getBoundingCap() const {return SphericalCap(Vec 3d(1,0,0), 2);} virtual SphericalCap getBoundingCap() const {return SphericalCap(Vec 3d(1,0,0), 2);}
//! Serialize the region into a QVariant map matching the JSON forma t. //! Serialize the region into a QVariant map matching the JSON forma t.
//! The format is ["EMPTY"] //! The format is ["EMPTY"]
virtual QVariantList toQVariant() const; virtual QVariantList toQVariant() const;
virtual void serialize(QDataStream&) const {;} virtual void serialize(QDataStream&) const {;}
// Contain and intersect // Contain and intersect
skipping to change at line 780 skipping to change at line 542
virtual bool contains(const AllSkySphericalRegion&) const {return fa lse;} virtual bool contains(const AllSkySphericalRegion&) const {return fa lse;}
virtual bool intersects(const SphericalPolygon&) const {return false ;} virtual bool intersects(const SphericalPolygon&) const {return false ;}
virtual bool intersects(const SphericalConvexPolygon&) const {return false;} virtual bool intersects(const SphericalConvexPolygon&) const {return false;}
virtual bool intersects(const SphericalCap&) const {return false;} virtual bool intersects(const SphericalCap&) const {return false;}
virtual bool intersects(const SphericalPoint&) const {return false;} virtual bool intersects(const SphericalPoint&) const {return false;}
virtual bool intersects(const AllSkySphericalRegion&) const {return false;} virtual bool intersects(const AllSkySphericalRegion&) const {return false;}
static const SphericalRegionP staticInstance; static const SphericalRegionP staticInstance;
}; };
//! @class //! @class SphericalPolygon
//! defining default implementations for some spherical //! Class defining default implementations for some spherical geometry meth
ods.
//! All methods are reentrant. //! All methods are reentrant.
class SphericalPolygon : public SphericalRegion class SphericalPolygon : public SphericalRegion
{ {
public: public:
using SphericalRegion::intersects; using SphericalRegion::intersects;
using SphericalRegion::contains; using SphericalRegion::contains;
using SphericalRegion::getIntersection; using SphericalRegion::getIntersection;
using SphericalRegion::getUnion; using SphericalRegion::getUnion;
using SphericalRegion::getSubtraction; using SphericalRegion::getSubtraction;
SphericalPolygon() {;} SphericalPolygon() {;}
//! Constructor from a list of contours. //! Constructor from a list of contours.
SphericalPolygon(const QVector<QVector<Vec3d> >& contours) : octahed ronPolygon(contours) {;} SphericalPolygon(const QVector<QVector<Vec3d> >& contours) : octahed ronPolygon(contours) {;}
//! Constructor from one contour. //! Constructor from one contour.
SphericalPolygon(const QVector<Vec3d>& contour) : octahedronPolygon( contour) {;} SphericalPolygon(const QVector<Vec3d>& contour) : octahedronPolygon( contour) {;}
SphericalPolygon(const OctahedronPolygon& octContour) : octahedronPo lygon(octContour) {;} SphericalPolygon(const OctahedronPolygon& octContour) : octahedronPo lygon(octContour) {;}
SphericalPolygon(const QList<OctahedronPolygon>& octContours) : octa hedronPolygon(octContours) {;} SphericalPolygon(const QList<OctahedronPolygon>& octContours) : octa hedronPolygon(octContours) {;}
virtual SphericalRegionType getType() const {return SphericalRegion: :Polygon;} virtual SphericalRegionType getType() const {return SphericalRegion: :Polygon;}
virtual OctahedronPolygon getOctahedronPolygon() const virtual OctahedronPolygon getOctahedronPolygon() const {return octah
edronPolygon;}
//! Serialize the region into a QVariant map matching the JSON forma t. //! Serialize the region into a QVariant map matching the JSON forma t.
//! The format is: //! The format is:
//! @code[[[ra,dec], [ra,dec], [ra,dec], [ra,dec]], [[ra,dec], [ra,d ec], [ra,dec]],[...]]@endcode //! @code[[[ra,dec], [ra,dec], [ra,dec], [ra,dec]], [[ra,dec], [ra,d ec], [ra,dec]],[...]]@endcode
//! it is a list of closed contours, with each points defined by ra dec in degree in the ICRS frame. //! it is a list of closed contours, with each points defined by ra dec in degree in the ICRS frame.
virtual QVariantList toQVariant() const; virtual QVariantList toQVariant() const;
virtual void serialize(QDataStream& out) const; virtual void serialize(QDataStream& out) const;
virtual SphericalCap getBoundingCap() const; virtual SphericalCap getBoundingCap() const;
skipping to change at line 843 skipping to change at line 602
virtual SphericalRegionP getUnion(const EmptySphericalRegion&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));} virtual SphericalRegionP getUnion(const EmptySphericalRegion&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
virtual SphericalRegionP getSubtraction(const SphericalPoint&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));} virtual SphericalRegionP getSubtraction(const SphericalPoint&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
virtual SphericalRegionP getSubtraction(const EmptySphericalRegion&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));} virtual SphericalRegionP getSubtraction(const EmptySphericalRegion&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Methods specific to SphericalPolygon // Methods specific to SphericalPolygon
//! Set the contours defining the SphericalPolygon. //! Set the contours defining the SphericalPolygon.
//! @param contours the list of contours defining the polygon area. The contours are combined using //! @param contours the list of contours defining the polygon area. The contours are combined using
//! the positive winding rule, meaning that the polygon is the union of the positive contours minus the negative ones. //! the positive winding rule, meaning that the polygon is the union of the positive contours minus the negative ones.
void setContours(const QVector<QVector<Vec3d> >& contours) void setContours(const QVector<QVector<Vec3d> >& contours) {octahedr
onPolygon = OctahedronPolygon(contours);}
=
//! Set a single contour defining the SphericalPolygon. //! Set a single contour defining the SphericalPolygon.
//! @param contour a contour defining the polygon area. //! @param contour a contour defining the polygon area.
void setContour(const QVector<Vec3d>& contour) void setContour(const QVector<Vec3d>& contour) {octahedronPolygon =
OctahedronPolygon(contour);}
=
//! Return the list of closed contours defining the polygon boundari es. //! Return the list of closed contours defining the polygon boundari es.
QVector<QVector<Vec3d> > getClosedOutlineContours() const {Q_ASSERT( 0); return QVector<QVector<Vec3d> >();} QVector<QVector<Vec3d> > getClosedOutlineContours() const {Q_ASSERT( 0); return QVector<QVector<Vec3d> >();}
//! Deserialize the region. This method must allow as fast as possib le deserialization. //! Deserialize the region. This method must allow as fast as possib le deserialization.
static SphericalRegionP deserialize(QDataStream& in); static SphericalRegionP deserialize(QDataStream& in);
//! Create a new SphericalRegionP which is the union of all the pass ed ones. //! Create a new SphericalRegionP which is the union of all the pass ed ones.
static SphericalRegionP multiUnion(const QList<SphericalRegionP>& re gions, bool optimizeByPreGrouping=false); static SphericalRegionP multiUnion(const QList<SphericalRegionP>& re gions, bool optimizeByPreGrouping=false);
skipping to change at line 884 skipping to change at line 637
{ {
public: public:
using SphericalRegion::intersects; using SphericalRegion::intersects;
using SphericalRegion::contains; using SphericalRegion::contains;
//! Default constructor. //! Default constructor.
SphericalConvexPolygon() {;} SphericalConvexPolygon() {;}
//! Constructor from a list of contours. //! Constructor from a list of contours.
SphericalConvexPolygon(const QVector<QVector<Vec3d> >& contours) SphericalConvexPolygon(const QVector<QVector<Vec3d> >& contours) {Q_
ASSERT(contours.size()==1); setContour(contours.at(0));}
//! Constructor from one contour. //! Constructor from one contour.
SphericalConvexPolygon(const QVector<Vec3d>& contour) SphericalConvexPolygon(const QVector<Vec3d>& contour) {setContour(co
ntour);}
//! Special constructor for triangle. //! Special constructor for triangle.
SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d & SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &
e2) e2) {contour << e0 << e1 << e2; updateBoundingCap();}
<< e0 << e1 << e2;
SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d & SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &
e2, const Vec3d &e3) e2, const Vec3d &e3) {contour << e0 << e1 << e2 << e3; updateBoundingCap()
;}
<< e0 << e1 << e2 << e3;
virtual SphericalRegionType getType() const {return SphericalRegion: :ConvexPolygon;} virtual SphericalRegionType getType() const {return SphericalRegion: :ConvexPolygon;}
virtual OctahedronPolygon getOctahedronPolygon() const {return Octah
virtual OctahedronPolygon getOctahedronPolygon() const edronPolygon(contour);}
virtual StelVertexArray getFillVertexArray() const {return StelVerte
xArray(contour, StelVertexArray::TriangleFan);}
virtual StelVertexArray getOutlineVertexArray() const {return StelVe
rtexArray(contour, StelVertexArray::LineLoop);}
virtual const
virtual const
virtual double getArea() const; virtual double getArea() const;
virtual bool isEmpty() const {return contour.isEmpty();} virtual bool isEmpty() const {return contour.isEmpty();}
virtual Vec3d getPointInside() const; virtual Vec3d getPointInside() const;
virtual SphericalCap getBoundingCap() const {return cachedBoundingCa p;} virtual SphericalCap getBoundingCap() const {return cachedBoundingCa p;}
QVector<SphericalCap> getBoundingSphericalCaps() const; QVector<SphericalCap> getBoundingSphericalCaps() const;
//! Serialize the region into a QVariant map matching the JSON forma t. //! Serialize the region into a QVariant map matching the JSON forma t.
//! The format is //! The format is
//! @code["CONVEX_POLYGON", [[ra,dec], [ra,dec], [ra,dec], [ra,dec]] ]@endcode //! @code["CONVEX_POLYGON", [[ra,dec], [ra,dec], [ra,dec], [ra,dec]] ]@endcode
//! where the coords are a closed convex contour, with each points d efined by ra dec in degree in the ICRS frame. //! where the coords are a closed convex contour, with each points d efined by ra dec in degree in the ICRS frame.
virtual QVariantList toQVariant() const; virtual QVariantList toQVariant() const;
skipping to change at line 986 skipping to change at line 696
// virtual SphericalRegionP getSubtraction(const SphericalConvexPolygon & r) const; // virtual SphericalRegionP getSubtraction(const SphericalConvexPolygon & r) const;
// virtual SphericalRegionP getSubtraction(const SphericalCap& r) const ; // virtual SphericalRegionP getSubtraction(const SphericalCap& r) const ;
// virtual SphericalRegionP getSubtraction(const SphericalPoint& r) con st; // virtual SphericalRegionP getSubtraction(const SphericalPoint& r) con st;
// virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const; // virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Methods specific to SphericalConvexPolygon // Methods specific to SphericalConvexPolygon
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
//! Set a single contour defining the SphericalPolygon. //! Set a single contour defining the SphericalPolygon.
//! @param acontour a contour defining the polygon area. //! @param acontour a contour defining the polygon area.
void setContour(const QVector<Vec3d>& acontour) void setContour(const QVector<Vec3d>& acontour) {contour=acontour; u
pdateBoundingCap();}
//! Get the single contour defining the SphericalConvexPolygon. //! Get the single contour defining the SphericalConvexPolygon.
const QVector<Vec3d>& getConvexContour() const {return contour;} const QVector<Vec3d>& getConvexContour() const {return contour;}
//! Check if the polygon is valid, i.e. it has no side >180. //! Check if the polygon is valid, i.e. it has no side >180.
bool checkValid() const; bool checkValid() const;
//! Check if the passed contour is convex and valid, i.e. it has no side >180. //! Check if the passed contour is convex and valid, i.e. it has no side >180.
static bool checkValidContour(const QVector<Vec3d>& contour); static bool checkValidContour(const QVector<Vec3d>& contour);
//! Deserialize the region. This method must allow as fast as possib le deserialization. //! Deserialize the region. This method must allow as fast as possib le deserialization.
static SphericalRegionP deserialize(QDataStream& in); static SphericalRegionP deserialize(QDataStream& in);
protected: protected:
//! A list of vertices of the convex contour. //! A list of vertices of the convex contour.
QVector<Vec3d> contour; QVector<Vec3d> contour;
//! Cache the bounding cap. //! Cache the bounding cap.
SphericalCap cachedBoundingCap; SphericalCap cachedBoundingCap;
//! Update the bounding cap from the vertex list. //! Update the bounding cap from the vertex list.
void updateBoundingCap(); void updateBoundingCap();
//! Computes whether the passed points are all outside of at least o ne SphericalCap defining the polygon boundary. //! Computes whether the passed points are all outside of at least o ne SphericalCap defining the polygon boundary.
//! @param thisContour the vertices defining the contour. //! @param thisContour the vertices defining the contour.
//! @param nbThisContour nb of vertice of the contour. //! @param nbThisContour nb of vertice of the contour.
//! @param points the points to test. //! @param points the points to test.
//! @param nbPoints the number of points to test. //! @param nbPoints the number of points to test.
static bool areAllPointsOutsideOneSide(const Vec3d* thisContour, int nbThisContour, const Vec3d* points, int nbPoints); static bool areAllPointsOutsideOneSide(const Vec3d* thisContour, int nbThisContour, const Vec3d* points, int nbPoints);
//! Computes whether the passed points are all outside of at least o ne SphericalCap defining the polygon boundary. //! Computes whether the passed points are all outside of at least o ne SphericalCap defining the polygon boundary.
bool areAllPointsOutsideOneSide(const QVector<Vec3d>& points) const bool areAllPointsOutsideOneSide(const QVector<Vec3d>& points) const
{ {
return areAllPointsOutsideOneSide(contour.constData(), conto ur.size(), points.constData(), points.size()); return areAllPointsOutsideOneSide(contour.constData(), conto ur.size(), points.constData(), points.size());
} }
bool containsConvexContour(const Vec3d* vertice, int nbVertex) const ; bool containsConvexContour(const Vec3d* vertice, int nbVertex) const ;
}; };
@class SphericalConvexPolygonSet // ! @class SphericalConvexPolygonSet
A special case of SphericalPolygon for which the polygon is composed // ! A special case of SphericalPolygon for which the polygon is composed o
disjoint convex polygons. f disjoint convex polygons.
//class SphericalConvexPolygonSet : public SphericalRegion //class SphericalConvexPolygonSet : public SphericalRegion
//{ //{
//public: //public:
// using SphericalRegion::intersects; // using SphericalRegion::intersects;
// using SphericalRegion::contains; // using SphericalRegion::contains;
// //
// //! Default constructor. // //! Default constructor.
// SphericalConvexPolygonSet() {;} // SphericalConvexPolygonSet() {;}
// //
skipping to change at line 1108 skipping to change at line 796
//protected: //protected:
// QVector<SphericalConvexPolygon> contours; // QVector<SphericalConvexPolygon> contours;
// //
// //! Cache the bounding cap. // //! Cache the bounding cap.
// SphericalCap cachedBoundingCap; // SphericalCap cachedBoundingCap;
// //
// //! Update the bounding cap from the vertex list. // //! Update the bounding cap from the vertex list.
// void updateBoundingCap(); // void updateBoundingCap();
//}; //};
//! @class SphericalTexturedPolygon
//! An extension of SphericalPolygon with addition of texture coordinates.
class SphericalTexturedPolygon : public SphericalPolygon
{
public:
//! @struct TextureVertex
//! A container for 3D vertex + associated texture coordinates
struct TextureVertex
{
Vec3d vertex;
Vec2f texCoord;
};
SphericalTexturedPolygon() {;}
//! Constructor from a list of contours.
SphericalTexturedPolygon(const QVector<QVector<TextureVertex> >& con
tours) {Q_UNUSED(contours); Q_ASSERT(0);}
//! Constructor from one contour.
SphericalTexturedPolygon(const QVector<TextureVertex>& contour) {Q_U
NUSED(contour); Q_ASSERT(0);}
//! Return an openGL compatible array of texture coords to be used u
sing vertex arrays.
virtual StelVertexArray getFillVertexArray() const {Q_ASSERT(0); ret
urn StelVertexArray();}
//! Serialize the region into a QVariant map matching the JSON forma
t.
//! The format is:
//! @code["TEXTURED_POLYGON", [[[ra,dec], [ra,dec], [ra,dec], [ra,de
c]], [[ra,dec], [ra,dec], [ra,dec]],[...]],
//! [[[u,v],[u,v],[u,v],[u,v]], [[u,v],[u,v],[u,v]], [...]]]@endcode
//! where the two lists are a list of closed contours, with each poi
nts defined by ra dec in degree in the ICRS frame
//! followed by a list of texture coordinates in the u,v texture spa
ce (between 0 and 1).
//! There must be one texture coordinate for each vertex.
virtual QVariantList toQVariant() const;
virtual void serialize(QDataStream& out) const {Q_UNUSED(out); Q_ASS
ERT(0);}
////////////////////////////////////////////////////////////////////
// Methods specific to SphericalTexturedPolygon
//! Set the contours defining the SphericalPolygon.
//! @param contours the list of contours defining the polygon area u
sing the WindingPositive winding rule.
void setContours(const QVector<QVector<TextureVertex> >& contours) {
Q_UNUSED(contours); Q_ASSERT(0);}
//! Set a single contour defining the SphericalPolygon.
//! @param contour a contour defining the polygon area.
void setContour(const QVector<TextureVertex>& contour) {Q_UNUSED(con
tour); Q_ASSERT(0);}
private:
//! A list of uv textures coordinates corresponding to the triangle
vertices.
//! There should be 1 uv position per vertex.
QVector<Vec2f> textureCoords;
};
Q_DECLARE_TYPEINFO(SphericalTexturedPolygon::TextureVertex, Q_PRIMITIVE_TYP
E);
//! @class SphericalTexturedConvexPolygon //! @class SphericalTexturedConvexPolygon
//! Extension of SphericalConvexPolygon for textured polygon. //! Extension of SphericalConvexPolygon for textured polygon.
class SphericalTexturedConvexPolygon : public SphericalConvexPolygon class SphericalTexturedConvexPolygon : public SphericalConvexPolygon
{ {
public: public:
//! Default constructor. //! Default constructor.
SphericalTexturedConvexPolygon() SphericalTexturedConvexPolygon() {;}
//! Constructor from one contour. //! Constructor from one contour.
SphericalTexturedConvexPolygon(const QVector<Vec3d>& contour, const SphericalTexturedConvexPolygon(const QVector<Vec3d>& contour, const
QVector<Vec2f>& texCoord) QVector<Vec2f>& texCoord) {setContour(contour, texCoord);}
//! Use the 4 textures corners for the 4 vertices. //! Use the 4 textures corners for the 4 vertices.
SphericalTexturedConvexPolygon(const Vec3d &e0,const Vec3d &e1,const SphericalTexturedConvexPolygon(const Vec3d &e0,const Vec3d &e1,const
Vec3d &e2, const Vec3d &e3) Vec3d &e2, const Vec3d &e3) : SphericalConvexPolygon(e0,e1,e2,e3)
: SphericalConvexPolygon(e0,e1,e2,e3)
{ {
textureCoords << Vec2f(0.f, 0.f) << Vec2f(1.f, 0.f) << Vec2f (1.f, 1.f) << Vec2f(0.f, 1.f); textureCoords << Vec2f(0.f, 0.f) << Vec2f(1.f, 0.f) << Vec2f (1.f, 1.f) << Vec2f(0.f, 1.f);
} }
virtual //! Return an openGL compatible array to be displayed using vertex a
rrays.
//! This method is not optimized for SphericalConvexPolygon instance
s.
virtual StelVertexArray getFillVertexArray() const {return StelVerte
xArray(contour, StelVertexArray::TriangleFan, textureCoords);}
//! Set a single contour defining the SphericalPolygon. //! Set a single contour defining the SphericalPolygon.
//! @param acontour a contour defining the polygon area. //! @param acontour a contour defining the polygon area.
//! @param texCoord a list of texture coordinates matching the verti ces of the contour. //! @param texCoord a list of texture coordinates matching the verti ces of the contour.
virtual void setContour(const QVector<Vec3d>& acontour, const QVecto virtual void setContour(const QVector<Vec3d>& acontour, const QVecto
r<Vec2f>& texCoord) r<Vec2f>& texCoord) {SphericalConvexPolygon::setContour(acontour); textureC
oords=texCoord;}
//! Serialize the region into a QVariant map matching the JSON forma t. //! Serialize the region into a QVariant map matching the JSON forma t.
//! The format is: //! The format is:
//! @code["TEXTURED_CONVEX_POLYGON", [[ra,dec], [ra,dec], [ra,dec], [ra,dec]], [[u,v],[u,v],[u,v],[u,v]]]@endcode //! @code["TEXTURED_CONVEX_POLYGON", [[ra,dec], [ra,dec], [ra,dec], [ra,dec]], [[u,v],[u,v],[u,v],[u,v]]]@endcode
//! where the two lists are a closed convex contours, with each poin ts defined by ra dec in degree in the ICRS frame //! where the two lists are a closed convex contours, with each poin ts defined by ra dec in degree in the ICRS frame
//! followed by a list of texture coordinates in the u,v texture spa ce (between 0 and 1). //! followed by a list of texture coordinates in the u,v texture spa ce (between 0 and 1).
//! There must be one texture coordinate for each vertex. //! There must be one texture coordinate for each vertex.
virtual QVariantList toQVariant() const; virtual QVariantList toQVariant() const;
virtual void serialize(QDataStream& out) const {out << contour << te xtureCoords;} virtual void serialize(QDataStream& out) const {out << contour << te xtureCoords;}
protected: protected:
//! A list of uv textureertices. //! A list of uv textures coordinates corresponding to the triangle vertices.
//! There should be 1 uv position per vertex. //! There should be 1 uv position per vertex.
QVector<Vec2f> textureCoords; QVector<Vec2f> textureCoords;
}; };
//! Compute the intersection of 2 great circles segments. //! Compute the intersection of 2 great circles segments.
//! @param ok is set to false if no intersection was found. //! @param ok is set to false if no intersection was found.
//! @return the intersection point on the sphere (normalized) if ok is true , or undefined of ok is false. //! @return the intersection point on the sphere (normalized) if ok is true , or undefined of ok is false.
Vec3d greatCircleIntersection(const Vec3d& p1, const Vec3d& p2, const Vec3d & p3, const Vec3d& p4, bool& ok); Vec3d greatCircleIntersection(const Vec3d& p1, const Vec3d& p2, const Vec3d & p3, const Vec3d& p4, bool& ok);
//! Compute the intersection of a great circles segment with another great circle. //! Compute the intersection of a great circles segment with another great circle.
//! @param ok is set to false if no intersection was found. //! @param ok is set to false if no intersection was found.
//! @return the intersection point on the sphere (normalized) if ok is true , or undefined of ok is false. //! @return the intersection point on the sphere (normalized) if ok is true , or undefined of ok is false.
Vec3d greatCircleIntersection(const Vec3d& p1, const Vec3d& p2, const Vec3d & nHalfSpace, bool& ok); Vec3d greatCircleIntersection(const Vec3d& p1, const Vec3d& p2, const Vec3d & nHalfSpace, bool& ok);
#endif // _STELSPHEREGEOMETRY_HPP_ #endif // _STELSPHEREGEOMETRY_HPP_
End of changes. 41 change blocks.
468 lines changed or deleted 143 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/