Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

core/StelSphereGeometry.hpp

Go to the documentation of this file.
00001 /*
00002  * Stellarium
00003  * Copyright (C) 2009 Fabien Chereau
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00020 #ifndef _STELSPHEREGEOMETRY_HPP_
00021 #define _STELSPHEREGEOMETRY_HPP_
00022 
00023 #include <QVector>
00024 #include <QVariant>
00025 #include <QDebug>
00026 #include <QSharedPointer>
00027 #include <QVarLengthArray>
00028 #include "VecMath.hpp"
00029 #include "OctahedronPolygon.hpp"
00030 #include "StelVertexArray.hpp"
00031 
00032 class SphericalRegion;
00033 class SphericalPolygon;
00034 class SphericalConvexPolygon;
00035 class SphericalCap;
00036 class SphericalPoint;
00037 class AllSkySphericalRegion;
00038 class EmptySphericalRegion;
00039 
00042 
00045 class SphericalRegionP : public QSharedPointer<SphericalRegion>
00046 {
00047 public:
00048     // Override the constructors of QSharedPointer
00049     SphericalRegionP() {;}
00050     SphericalRegionP(SphericalRegion* ptr) : QSharedPointer<SphericalRegion>(ptr) {;}
00051     template <class Deleter> SphericalRegionP(SphericalRegion* ptr, Deleter deleter) : QSharedPointer<SphericalRegion>(ptr, deleter) {;}
00052     SphericalRegionP(const SphericalRegionP& other) : QSharedPointer<SphericalRegion>(other) {;}
00053     SphericalRegionP(const QWeakPointer<SphericalRegion>& other) : QSharedPointer<SphericalRegion>(other) {;}
00054 
00093     static SphericalRegionP loadFromJson(QIODevice* in);
00094 
00097     static SphericalRegionP loadFromJson(const QByteArray& a);
00098 
00101     static SphericalRegionP loadFromQVariant(const QVariantMap& map);
00102     static SphericalRegionP loadFromQVariant(const QVariantList& list);
00103 
00105     static const QVariant::Type qVariantType;
00106 
00108     static int metaTypeId;
00109 
00110 private:
00111     static QVector<QVector<Vec3d> > loadContourFromQVariant(const QVariantList& contoursList);
00112 
00114     static int initialize();
00115 };
00116 
00117 // Allow to use SphericalRegionP with the Qt MetaType system.
00118 Q_DECLARE_METATYPE(SphericalRegionP);
00119 
00121 QDataStream& operator<<(QDataStream& out, const SphericalRegionP& region);
00123 QDataStream& operator>>(QDataStream& in, SphericalRegionP& region);
00124 
00129 class SphericalRegion
00130 {
00131 public:
00133     enum SphericalRegionType
00134     {
00135         Point = 0,
00136         Cap = 1,
00137         AllSky = 2,
00138         Polygon = 3,
00139         ConvexPolygon = 4,
00140         Empty = 5,
00141         Invalid = 6
00142     };
00143 
00144     virtual ~SphericalRegion() {;}
00145 
00146     virtual SphericalRegionType getType() const = 0;
00147 
00150     virtual OctahedronPolygon getOctahedronPolygon() const =0;
00151 
00153     virtual double getArea() const {return getOctahedronPolygon().getArea();}
00154 
00156     virtual bool isEmpty() const {return getOctahedronPolygon().isEmpty();}
00157 
00159     virtual Vec3d getPointInside() const {return getOctahedronPolygon().getPointInside();}
00160 
00162     virtual QVector<SphericalCap> getBoundingSphericalCaps() const;
00163 
00166     virtual SphericalCap getBoundingCap() const;
00167 
00174     virtual SphericalRegionP getEnlarged(double margin) const;
00175 
00177     virtual StelVertexArray getFillVertexArray() const {return getOctahedronPolygon().getFillVertexArray();}
00178 
00181     virtual StelVertexArray getOutlineVertexArray() const {return getOctahedronPolygon().getOutlineVertexArray();}
00182 
00184     virtual QVariantMap toQVariant() const = 0;
00185 
00187     virtual void serialize(QDataStream& out) const = 0;
00188 
00191     QByteArray toJSON() const;
00192 
00195     bool contains(const SphericalRegion* r) const;
00196     bool contains(const SphericalRegionP r) const {return contains(r.data());}
00197     virtual bool contains(const Vec3d& p) const {return getOctahedronPolygon().contains(p);}
00198     virtual bool contains(const SphericalPolygon& r) const;
00199     virtual bool contains(const SphericalConvexPolygon& r) const;
00200     virtual bool contains(const SphericalCap& r) const;
00201     virtual bool contains(const SphericalPoint& r) const;
00202     virtual bool contains(const AllSkySphericalRegion& r) const;
00203     bool contains(const EmptySphericalRegion&) const {return false;}
00204 
00207     bool intersects(const SphericalRegion* r) const;
00208     bool intersects(const SphericalRegionP r) const {return intersects(r.data());}
00209     bool intersects(const Vec3d& p) const {return contains(p);}
00210     virtual bool intersects(const SphericalPolygon& r) const;
00211     virtual bool intersects(const SphericalConvexPolygon& r) const;
00212     virtual bool intersects(const SphericalCap& r) const;
00213     virtual bool intersects(const SphericalPoint& r) const;
00214     virtual bool intersects(const AllSkySphericalRegion& r) const;
00215     bool intersects(const EmptySphericalRegion&) const {return false;}
00216 
00219     SphericalRegionP getIntersection(const SphericalRegion* r) const;
00220     SphericalRegionP getIntersection(const SphericalRegionP r) const {return getIntersection(r.data());}
00221     virtual SphericalRegionP getIntersection(const SphericalPolygon& r) const;
00222     virtual SphericalRegionP getIntersection(const SphericalConvexPolygon& r) const;
00223     virtual SphericalRegionP getIntersection(const SphericalCap& r) const;
00224     virtual SphericalRegionP getIntersection(const SphericalPoint& r) const;
00225     virtual SphericalRegionP getIntersection(const AllSkySphericalRegion& r) const;
00226     SphericalRegionP getIntersection(const EmptySphericalRegion& r) const;
00227 
00230     SphericalRegionP getUnion(const SphericalRegion* r) const;
00231     SphericalRegionP getUnion(const SphericalRegionP r) const {return getUnion(r.data());}
00232     virtual SphericalRegionP getUnion(const SphericalPolygon& r) const;
00233     virtual SphericalRegionP getUnion(const SphericalConvexPolygon& r) const;
00234     virtual SphericalRegionP getUnion(const SphericalCap& r) const;
00235     virtual SphericalRegionP getUnion(const SphericalPoint& r) const;
00236     SphericalRegionP getUnion(const AllSkySphericalRegion& r) const;
00237     virtual SphericalRegionP getUnion(const EmptySphericalRegion& r) const;
00238 
00241     SphericalRegionP getSubtraction(const SphericalRegion* r) const;
00242     SphericalRegionP getSubtraction(const SphericalRegionP r) const {return getSubtraction(r.data());}
00243     virtual SphericalRegionP getSubtraction(const SphericalPolygon& r) const;
00244     virtual SphericalRegionP getSubtraction(const SphericalConvexPolygon& r) const;
00245     virtual SphericalRegionP getSubtraction(const SphericalCap& r) const;
00246     virtual SphericalRegionP getSubtraction(const SphericalPoint& r) const;
00247     SphericalRegionP getSubtraction(const AllSkySphericalRegion& r) const;
00248     virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const;
00249 
00250 private:
00251     bool containsDefault(const SphericalRegion* r) const;
00252     bool intersectsDefault(const SphericalRegion* r) const;
00253     SphericalRegionP getIntersectionDefault(const SphericalRegion* r) const;
00254     SphericalRegionP getUnionDefault(const SphericalRegion* r) const;
00255     SphericalRegionP getSubtractionDefault(const SphericalRegion* r) const;
00256 };
00257 
00258 
00263 class SphericalCap : public SphericalRegion
00264 {
00265 public:
00267     SphericalCap() : d(0) {;}
00268 
00270     SphericalCap(double x, double y, double z) : n(x,y,z), d(0) {;}
00271 
00275     SphericalCap(const Vec3d& an, double ar) : n(an), d(ar) {Q_ASSERT(d==0 || std::fabs(n.lengthSquared()-1.)<0.0000001);}
00276 
00278     SphericalCap(const SphericalCap& other) : SphericalRegion(), n(other.n), d(other.d) {;}
00279 
00280     virtual SphericalRegionType getType() const {return SphericalRegion::Cap;}
00281     virtual OctahedronPolygon getOctahedronPolygon() const;
00282 
00284     virtual double getArea() const {return 2.*M_PI*(1.-d);}
00285 
00287     virtual bool isEmpty() const {return d>=1.;}
00288 
00290     virtual Vec3d getPointInside() const {return n;}
00291 
00293     virtual SphericalCap getBoundingCap() const {return *this;}
00294 
00295     // Contain and intersect
00296     virtual bool contains(const Vec3d &v) const {Q_ASSERT(d==0 || std::fabs(v.lengthSquared()-1.)<0.0000001);return (v*n>=d);}
00297     virtual bool contains(const Vec3f &v) const {Q_ASSERT(d==0 || std::fabs(v.lengthSquared()-1.f)<0.0000001f);return (v[0]*n[0]+v[1]*n[1]+v[2]*n[2]>=d);}
00298     virtual bool contains(const SphericalConvexPolygon& r) const;
00299     virtual bool contains(const SphericalCap& h) const
00300     {
00301         const double a = n*h.n-d*h.d;
00302         return d<=h.d && ( a>=1. || (a>=0. && a*a >= (1.-d*d)*(1.-h.d*h.d)));
00303     }
00304     virtual bool contains(const AllSkySphericalRegion&) const {return d<=-1;}
00305     virtual bool intersects(const SphericalPolygon& r) const;
00306     virtual bool intersects(const SphericalConvexPolygon& r) const;
00310     virtual bool intersects(const SphericalCap& h) const
00311     {
00312         const double a = d*h.d - n*h.n;
00313         return d+h.d<=0. || a<=0. || (a<=1. && a*a <= (1.-d*d)*(1.-h.d*h.d));
00314     }
00315     virtual bool intersects(const AllSkySphericalRegion&) const {return d<=1.;}
00316 
00320     virtual QVariantMap toQVariant() const;
00321 
00322     virtual void serialize(QDataStream& out) const {out << n << d;}
00323 
00325     // Methods specific to SphericalCap
00326 
00328     double getRadius() const {return std::acos(d);}
00329 
00334     inline bool intersectsHalfSpace(double hn0, double hn1, double hn2) const
00335     {
00336         const double a = n[0]*hn0+n[1]*hn1+n[2]*hn2;
00337         return d<=0. || a<=0. || (a<=1. && a*a <= (1.-d*d));
00338     }
00339 
00342     bool clipGreatCircle(Vec3d& v1, Vec3d& v2) const;
00343 
00345     bool operator==(const SphericalCap& other) const {return (n==other.n && d==other.d);}
00346 
00348     QVector<Vec3d> getClosedOutlineContour() const;
00349 
00351     bool intersectsConvexContour(const Vec3d* vertice, int nbVertice) const;
00352 
00354     bool containsTriangle(const Vec3d* vertice) const;
00355 
00357     bool intersectsTriangle(const Vec3d* vertice) const;
00358 
00360     static SphericalRegionP deserialize(QDataStream& in);
00361 
00364     static double relativeAreaOverlap(const SphericalCap& c1, const SphericalCap& c2);
00365 
00368     static double relativeDiameterOverlap(const SphericalCap& c1, const SphericalCap& c2);
00369 
00372     static bool intersectionPoints(const SphericalCap& h1, const SphericalCap& h2, Vec3d& p1, Vec3d& p2);
00373 
00375     Vec3d n;
00377     double d;
00378 };
00379 
00383 inline bool sideHalfSpaceContains(const Vec3d& v1, const Vec3d& v2, const Vec3d& p)
00384 {
00385     return (v1[1] * v2[2] - v1[2] * v2[1])*p[0] +
00386             (v1[2] * v2[0] - v1[0] * v2[2])*p[1] +
00387             (v1[0] * v2[1] - v1[1] * v2[0])*p[2]>=-1e-17;
00388 }
00389 
00391 inline bool sideHalfSpaceContains(const Vec3d& v1, const Vec3d& v2, const SphericalCap& h)
00392 {
00393     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]);
00394     n.normalize();
00395     const double a = n*h.n;
00396     return 0<=h.d && ( a>=1. || (a>=0. && a*a >= 1.-h.d*h.d));
00397 }
00398 
00400 inline bool sideHalfSpaceIntersects(const Vec3d& v1, const Vec3d& v2, const SphericalCap& h)
00401 {
00402     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]);
00403     n.normalize();
00404     return  h.intersectsHalfSpace(n[0], n[1], n[2]);
00405 }
00406 
00409 class SphericalPoint : public SphericalRegion
00410 {
00411 public:
00412     SphericalPoint(const Vec3d& an) : n(an) {Q_ASSERT(std::fabs(1.-n.length())<0.0000001);}
00413     virtual ~SphericalPoint() {;}
00414 
00415     virtual SphericalRegionType getType() const {return SphericalRegion::Point;}
00416     virtual OctahedronPolygon getOctahedronPolygon() const;
00417     virtual double getArea() const {return 0.;}
00418     virtual bool isEmpty() const {return false;}
00419     virtual Vec3d getPointInside() const {return n;}
00420     virtual SphericalCap getBoundingCap() const {return SphericalCap(n, 1);}
00423     virtual QVariantMap toQVariant() const;
00424     virtual void serialize(QDataStream& out) const {out << n;}
00425 
00426     // Contain and intersect
00427     virtual bool contains(const Vec3d& p) const {return n==p;}
00428     virtual bool contains(const SphericalPolygon&) const {return false;}
00429     virtual bool contains(const SphericalConvexPolygon&) const {return false;}
00430     virtual bool contains(const SphericalCap&) const {return false;}
00431     virtual bool contains(const SphericalPoint& r) const {return n==r.n;}
00432     virtual bool contains(const AllSkySphericalRegion&) const {return false;}
00433     virtual bool intersects(const SphericalPolygon&) const;
00434     virtual bool intersects(const SphericalConvexPolygon&) const;
00435     virtual bool intersects(const SphericalCap& r) const {return r.contains(n);}
00436     virtual bool intersects(const SphericalPoint& r) const {return n==r.n;}
00437     virtual bool intersects(const AllSkySphericalRegion&) const {return true;}
00438 
00440     static SphericalRegionP deserialize(QDataStream& in);
00441 
00443     Vec3d n;
00444 };
00445 
00448 class AllSkySphericalRegion : public SphericalRegion
00449 {
00450 public:
00451     virtual ~AllSkySphericalRegion() {;}
00452 
00453     virtual SphericalRegionType getType() const {return SphericalRegion::AllSky;}
00454     virtual OctahedronPolygon getOctahedronPolygon() const {return OctahedronPolygon::getAllSkyOctahedronPolygon();}
00455     virtual double getArea() const {return 4.*M_PI;}
00456     virtual bool isEmpty() const {return false;}
00457     virtual Vec3d getPointInside() const {return Vec3d(1,0,0);}
00458     virtual SphericalCap getBoundingCap() const {return SphericalCap(Vec3d(1,0,0), -2);}
00461     virtual QVariantMap toQVariant() const;
00462     virtual void serialize(QDataStream&) const {;}
00463 
00464     // Contain and intersect
00465     virtual bool contains(const Vec3d&) const {return true;}
00466     virtual bool contains(const SphericalPolygon&) const {return true;}
00467     virtual bool contains(const SphericalConvexPolygon&) const {return true;}
00468     virtual bool contains(const SphericalCap&) const {return true;}
00469     virtual bool contains(const SphericalPoint&) const {return true;}
00470     virtual bool contains(const AllSkySphericalRegion&) const {return true;}
00471     virtual bool intersects(const SphericalPolygon&) const {return true;}
00472     virtual bool intersects(const SphericalConvexPolygon&) const {return true;}
00473     virtual bool intersects(const SphericalCap&) const {return true;}
00474     virtual bool intersects(const SphericalPoint&) const {return true;}
00475     virtual bool intersects(const AllSkySphericalRegion&) const {return true;}
00476 
00477     static const SphericalRegionP staticInstance;
00478 };
00479 
00482 class EmptySphericalRegion : public SphericalRegion
00483 {
00484 public:
00485     // Avoid name hiding when overloading the virtual methods.
00486     using SphericalRegion::intersects;
00487     using SphericalRegion::contains;
00488     using SphericalRegion::getIntersection;
00489     using SphericalRegion::getUnion;
00490     using SphericalRegion::getSubtraction;
00491 
00492     EmptySphericalRegion() {;}
00493     virtual ~EmptySphericalRegion() {;}
00494 
00495     virtual SphericalRegionType getType() const {return SphericalRegion::Empty;}
00496     virtual OctahedronPolygon getOctahedronPolygon() const {return OctahedronPolygon::getEmptyOctahedronPolygon();}
00497     virtual double getArea() const {return 0.;}
00498     virtual bool isEmpty() const {return true;}
00499     virtual Vec3d getPointInside() const {return Vec3d(1,0,0);}
00500     virtual SphericalCap getBoundingCap() const {return SphericalCap(Vec3d(1,0,0), 2);}
00503     virtual QVariantMap toQVariant() const;
00504     virtual void serialize(QDataStream&) const {;}
00505 
00506     // Contain and intersect
00507     virtual bool contains(const Vec3d&) const {return false;}
00508     virtual bool contains(const SphericalPolygon&) const {return false;}
00509     virtual bool contains(const SphericalConvexPolygon&) const {return false;}
00510     virtual bool contains(const SphericalCap&) const {return false;}
00511     virtual bool contains(const SphericalPoint&) const {return false;}
00512     virtual bool contains(const AllSkySphericalRegion&) const {return false;}
00513     virtual bool intersects(const SphericalPolygon&) const {return false;}
00514     virtual bool intersects(const SphericalConvexPolygon&) const {return false;}
00515     virtual bool intersects(const SphericalCap&) const {return false;}
00516     virtual bool intersects(const SphericalPoint&) const {return false;}
00517     virtual bool intersects(const AllSkySphericalRegion&) const {return false;}
00518 
00519     static const SphericalRegionP staticInstance;
00520 };
00521 
00522 
00526 class SphericalPolygon : public SphericalRegion
00527 {
00528 public:
00529     // Avoid name hiding when overloading the virtual methods.
00530     using SphericalRegion::intersects;
00531     using SphericalRegion::contains;
00532     using SphericalRegion::getIntersection;
00533     using SphericalRegion::getUnion;
00534     using SphericalRegion::getSubtraction;
00535 
00536     SphericalPolygon() {;}
00538     SphericalPolygon(const QVector<QVector<Vec3d> >& contours) : octahedronPolygon(contours) {;}
00540     SphericalPolygon(const QVector<Vec3d>& contour) : octahedronPolygon(contour) {;}
00541     SphericalPolygon(const OctahedronPolygon& octContour) : octahedronPolygon(octContour) {;}
00542     SphericalPolygon(const QList<OctahedronPolygon>& octContours) : octahedronPolygon(octContours) {;}
00543 
00544     virtual SphericalRegionType getType() const {return SphericalRegion::Polygon;}
00545     virtual OctahedronPolygon getOctahedronPolygon() const {return octahedronPolygon;}
00546 
00551     virtual QVariantMap toQVariant() const;
00552     virtual void serialize(QDataStream& out) const;
00553 
00554     virtual SphericalCap getBoundingCap() const;
00555 
00556     virtual bool contains(const Vec3d& p) const {return octahedronPolygon.contains(p);}
00557     virtual bool contains(const SphericalPolygon& r) const {return octahedronPolygon.contains(r.octahedronPolygon);}
00558     virtual bool contains(const SphericalConvexPolygon& r) const;
00559     virtual bool contains(const SphericalCap& r) const {return octahedronPolygon.contains(r.getOctahedronPolygon());}
00560     virtual bool contains(const SphericalPoint& r) const {return octahedronPolygon.contains(r.n);}
00561     virtual bool contains(const AllSkySphericalRegion& r) const {return octahedronPolygon.contains(r.getOctahedronPolygon());}
00562 
00563     virtual bool intersects(const SphericalPolygon& r) const {return octahedronPolygon.intersects(r.octahedronPolygon);}
00564     virtual bool intersects(const SphericalConvexPolygon& r) const;
00565     virtual bool intersects(const SphericalCap& r) const {return r.intersects(*this);}
00566     virtual bool intersects(const SphericalPoint& r) const {return octahedronPolygon.contains(r.n);}
00567     virtual bool intersects(const AllSkySphericalRegion&) const {return !isEmpty();}
00568 
00569     virtual SphericalRegionP getIntersection(const SphericalPoint& r) const {return contains(r.n) ? SphericalRegionP(new SphericalPoint(r)) : EmptySphericalRegion::staticInstance;}
00570     virtual SphericalRegionP getIntersection(const AllSkySphericalRegion& ) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00571 
00572     virtual SphericalRegionP getUnion(const SphericalPoint&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00573     virtual SphericalRegionP getUnion(const EmptySphericalRegion&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00574 
00575     virtual SphericalRegionP getSubtraction(const SphericalPoint&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00576     virtual SphericalRegionP getSubtraction(const EmptySphericalRegion&) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00577 
00579     // Methods specific to SphericalPolygon
00583     void setContours(const QVector<QVector<Vec3d> >& contours) {octahedronPolygon = OctahedronPolygon(contours);}
00584 
00587     void setContour(const QVector<Vec3d>& contour) {octahedronPolygon = OctahedronPolygon(contour);}
00588 
00590     QVector<QVector<Vec3d> > getClosedOutlineContours() const {Q_ASSERT(0); return QVector<QVector<Vec3d> >();}
00591 
00593     static SphericalRegionP deserialize(QDataStream& in);
00594 
00596     static SphericalRegionP multiUnion(const QList<SphericalRegionP>& regions);
00597 
00598 private:
00599     OctahedronPolygon octahedronPolygon;
00600 };
00601 
00602 
00605 class SphericalConvexPolygon : public SphericalRegion
00606 {
00607 public:
00608     // Avoid name hiding when overloading the virtual methods.
00609     using SphericalRegion::intersects;
00610     using SphericalRegion::contains;
00611 
00613     SphericalConvexPolygon() {;}
00614 
00616     SphericalConvexPolygon(const QVector<QVector<Vec3d> >& contours) {Q_ASSERT(contours.size()==1); setContour(contours.at(0));}
00618     SphericalConvexPolygon(const QVector<Vec3d>& contour) {setContour(contour);}
00620     SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &e2) {contour << e0 << e1 << e2; updateBoundingCap();}
00622     SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &e2, const Vec3d &e3)  {contour << e0 << e1 << e2 << e3; updateBoundingCap();}
00623 
00624     virtual SphericalRegionType getType() const {return SphericalRegion::ConvexPolygon;}
00625     virtual OctahedronPolygon getOctahedronPolygon() const {return OctahedronPolygon(contour);}
00626     virtual StelVertexArray getFillVertexArray() const {return StelVertexArray(contour, StelVertexArray::TriangleFan);}
00627     virtual StelVertexArray getOutlineVertexArray() const {return StelVertexArray(contour, StelVertexArray::LineLoop);}
00628     virtual double getArea() const;
00629     virtual bool isEmpty() const {return contour.isEmpty();}
00630     virtual Vec3d getPointInside() const;
00631     virtual SphericalCap getBoundingCap() const {return cachedBoundingCap;}
00632     QVector<SphericalCap> getBoundingSphericalCaps() const;
00637     virtual QVariantMap toQVariant() const;
00638     virtual void serialize(QDataStream& out) const {out << contour;}
00639 
00640     // Contain and intersect
00641     virtual bool contains(const Vec3d& p) const;
00642     virtual bool contains(const SphericalPolygon& r) const;
00643     virtual bool contains(const SphericalConvexPolygon& r) const;
00644     virtual bool contains(const SphericalCap& r) const;
00645     virtual bool contains(const SphericalPoint& r) const {return contains(r.n);}
00646     virtual bool contains(const AllSkySphericalRegion&) const {return false;}
00647     virtual bool intersects(const SphericalCap& r) const {if (!cachedBoundingCap.intersects(r)) return false; return r.intersects(*this);}
00648     virtual bool intersects(const SphericalPolygon& r) const;
00649     virtual bool intersects(const SphericalConvexPolygon& r) const;
00650     virtual bool intersects(const SphericalPoint& r) const {return contains(r.n);}
00651     virtual bool intersects(const AllSkySphericalRegion&) const {return true;}
00652 
00654 //  virtual SphericalRegionP getIntersection(const SphericalPolygon& r) const;
00655 //  virtual SphericalRegionP getIntersection(const SphericalConvexPolygon& r) const;
00656 //  virtual SphericalRegionP getIntersection(const SphericalCap& r) const;
00657 //  virtual SphericalRegionP getIntersection(const SphericalPoint& r) const;
00658 //  virtual SphericalRegionP getIntersection(const AllSkySphericalRegion& r) const;
00659 //  virtual SphericalRegionP getUnion(const SphericalPolygon& r) const;
00660 //  virtual SphericalRegionP getUnion(const SphericalConvexPolygon& r) const;
00661 //  virtual SphericalRegionP getUnion(const SphericalCap& r) const;
00662 //  virtual SphericalRegionP getUnion(const SphericalPoint& r) const;
00663 //  virtual SphericalRegionP getUnion(const EmptySphericalRegion& r) const;
00664 //  virtual SphericalRegionP getSubtraction(const SphericalPolygon& r) const;
00665 //  virtual SphericalRegionP getSubtraction(const SphericalConvexPolygon& r) const;
00666 //  virtual SphericalRegionP getSubtraction(const SphericalCap& r) const;
00667 //  virtual SphericalRegionP getSubtraction(const SphericalPoint& r) const;
00668 //  virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const;
00669 
00671     // Methods specific to SphericalConvexPolygon
00675     void setContour(const QVector<Vec3d>& acontour) {contour=acontour; updateBoundingCap();}
00676 
00678     const QVector<Vec3d>& getConvexContour() const {return contour;}
00679 
00681     bool checkValid() const;
00682 
00684     static bool checkValidContour(const QVector<Vec3d>& contour);
00685 
00687     static SphericalRegionP deserialize(QDataStream& in);
00688 
00689 protected:
00691     QVector<Vec3d> contour;
00692 
00694     SphericalCap cachedBoundingCap;
00695 
00697     void updateBoundingCap();
00698 
00704     static bool areAllPointsOutsideOneSide(const Vec3d* thisContour, int nbThisContour, const Vec3d* points, int nbPoints);
00705 
00707     bool areAllPointsOutsideOneSide(const QVector<Vec3d>& points) const
00708     {
00709         return areAllPointsOutsideOneSide(contour.constData(), contour.size(), points.constData(), points.size());
00710     }
00711 
00712     bool containsConvexContour(const Vec3d* vertice, int nbVertex) const;
00713 };
00714 
00715 
00716 
00719 class SphericalTexturedPolygon : public SphericalPolygon
00720 {
00721 public:
00724     struct TextureVertex
00725     {
00726         Vec3d vertex;
00727         Vec2f texCoord;
00728     };
00729 
00730     SphericalTexturedPolygon() {;}
00732     SphericalTexturedPolygon(const QVector<QVector<TextureVertex> >& contours) {Q_UNUSED(contours); Q_ASSERT(0);}
00734     SphericalTexturedPolygon(const QVector<TextureVertex>& contour) {Q_UNUSED(contour); Q_ASSERT(0);}
00735 
00737     virtual StelVertexArray getFillVertexArray() const {Q_ASSERT(0); return StelVertexArray();}
00746     virtual QVariantMap toQVariant() const;
00747     virtual void serialize(QDataStream& out) const {Q_UNUSED(out); Q_ASSERT(0);}
00748 
00750     // Methods specific to SphericalTexturedPolygon
00753     void setContours(const QVector<QVector<TextureVertex> >& contours) {Q_UNUSED(contours); Q_ASSERT(0);}
00754 
00757     void setContour(const QVector<TextureVertex>& contour) {Q_UNUSED(contour); Q_ASSERT(0);}
00758 
00759 private:
00762     QVector<Vec2f> textureCoords;
00763 };
00764 
00765 
00766 Q_DECLARE_TYPEINFO(SphericalTexturedPolygon::TextureVertex, Q_PRIMITIVE_TYPE);
00767 
00770 class SphericalTexturedConvexPolygon : public SphericalConvexPolygon
00771 {
00772 public:
00774     SphericalTexturedConvexPolygon() {;}
00775 
00777     SphericalTexturedConvexPolygon(const QVector<Vec3d>& contour, const QVector<Vec2f>& texCoord) {setContour(contour, texCoord);}
00778 
00781     SphericalTexturedConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &e2, const Vec3d &e3) : SphericalConvexPolygon(e0,e1,e2,e3)
00782     {
00783         textureCoords << Vec2f(0.f, 0.f) << Vec2f(1.f, 0.f) << Vec2f(1.f, 1.f) << Vec2f(0.f, 1.f);
00784     }
00785 
00788     virtual StelVertexArray getFillVertexArray() const {return StelVertexArray(contour, StelVertexArray::TriangleFan, textureCoords);}
00789 
00793     virtual void setContour(const QVector<Vec3d>& acontour, const QVector<Vec2f>& texCoord) {SphericalConvexPolygon::setContour(acontour); textureCoords=texCoord;}
00794 
00803     virtual QVariantMap toQVariant() const;
00804 
00805     virtual void serialize(QDataStream& out) const {out << contour << textureCoords;}
00806 
00807 protected:
00810     QVector<Vec2f> textureCoords;
00811 };
00812 
00813 
00817 Vec3d greatCircleIntersection(const Vec3d& p1, const Vec3d& p2, const Vec3d& p3, const Vec3d& p4, bool& ok);
00818 
00822 Vec3d greatCircleIntersection(const Vec3d& p1, const Vec3d& p2, const Vec3d& nHalfSpace, bool& ok);
00823 
00824 #endif // _STELSPHEREGEOMETRY_HPP_
00825 

Generated on Wed Jun 2 13:11:13 2010 for Stellarium by  doxygen 1.5.5