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     };
00142 
00143     virtual ~SphericalRegion() {;}
00144 
00145     virtual SphericalRegionType getType() const = 0;
00146 
00149     virtual OctahedronPolygon getOctahedronPolygon() const =0;
00150 
00152     virtual double getArea() const {return getOctahedronPolygon().getArea();}
00153 
00155     virtual bool isEmpty() const {return getOctahedronPolygon().isEmpty();}
00156 
00158     virtual Vec3d getPointInside() const {return getOctahedronPolygon().getPointInside();}
00159 
00161     virtual QVector<SphericalCap> getBoundingSphericalCaps() const;
00162 
00165     virtual SphericalCap getBoundingCap() const;
00166 
00173     virtual SphericalRegionP getEnlarged(double margin) const;
00174 
00176     virtual StelVertexArray getFillVertexArray() const {return getOctahedronPolygon().getFillVertexArray();}
00177 
00180     virtual StelVertexArray getOutlineVertexArray() const {return getOctahedronPolygon().getOutlineVertexArray();}
00181 
00183     virtual QVariantMap toQVariant() const = 0;
00184 
00186     virtual void serialize(QDataStream& out) const = 0;
00187 
00190     QByteArray toJSON() const;
00191 
00194     bool contains(const SphericalRegion* r) const;
00195     bool contains(const SphericalRegionP r) const {return contains(r.data());}
00196     virtual bool contains(const Vec3d& p) const {return getOctahedronPolygon().contains(p);}
00197     virtual bool contains(const SphericalPolygon& r) const;
00198     virtual bool contains(const SphericalConvexPolygon& r) const;
00199     virtual bool contains(const SphericalCap& r) const;
00200     virtual bool contains(const SphericalPoint& r) const;
00201     virtual bool contains(const AllSkySphericalRegion& r) const;
00202     bool contains(const EmptySphericalRegion& r) const {return false;}
00203 
00206     bool intersects(const SphericalRegion* r) const;
00207     bool intersects(const SphericalRegionP r) const {return intersects(r.data());}
00208     bool intersects(const Vec3d& p) const {return contains(p);}
00209     virtual bool intersects(const SphericalPolygon& r) const;
00210     virtual bool intersects(const SphericalConvexPolygon& r) const;
00211     virtual bool intersects(const SphericalCap& r) const;
00212     virtual bool intersects(const SphericalPoint& r) const;
00213     virtual bool intersects(const AllSkySphericalRegion& r) const;
00214     bool intersects(const EmptySphericalRegion& r) const {return false;}
00215 
00218     SphericalRegionP getIntersection(const SphericalRegion* r) const;
00219     SphericalRegionP getIntersection(const SphericalRegionP r) const {return getIntersection(r.data());}
00220     virtual SphericalRegionP getIntersection(const SphericalPolygon& r) const;
00221     virtual SphericalRegionP getIntersection(const SphericalConvexPolygon& r) const;
00222     virtual SphericalRegionP getIntersection(const SphericalCap& r) const;
00223     virtual SphericalRegionP getIntersection(const SphericalPoint& r) const;
00224     virtual SphericalRegionP getIntersection(const AllSkySphericalRegion& r) const;
00225     SphericalRegionP getIntersection(const EmptySphericalRegion& r) const;
00226 
00229     SphericalRegionP getUnion(const SphericalRegion* r) const;
00230     SphericalRegionP getUnion(const SphericalRegionP r) const {return getUnion(r.data());}
00231     virtual SphericalRegionP getUnion(const SphericalPolygon& r) const;
00232     virtual SphericalRegionP getUnion(const SphericalConvexPolygon& r) const;
00233     virtual SphericalRegionP getUnion(const SphericalCap& r) const;
00234     virtual SphericalRegionP getUnion(const SphericalPoint& r) const;
00235     SphericalRegionP getUnion(const AllSkySphericalRegion& r) const;
00236     virtual SphericalRegionP getUnion(const EmptySphericalRegion& r) const;
00237 
00240     SphericalRegionP getSubtraction(const SphericalRegion* r) const;
00241     SphericalRegionP getSubtraction(const SphericalRegionP r) const {return getSubtraction(r.data());}
00242     virtual SphericalRegionP getSubtraction(const SphericalPolygon& r) const;
00243     virtual SphericalRegionP getSubtraction(const SphericalConvexPolygon& r) const;
00244     virtual SphericalRegionP getSubtraction(const SphericalCap& r) const;
00245     virtual SphericalRegionP getSubtraction(const SphericalPoint& r) const;
00246     SphericalRegionP getSubtraction(const AllSkySphericalRegion& r) const;
00247     virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const;
00248 
00249 private:
00250     bool containsDefault(const SphericalRegion* r) const;
00251     bool intersectsDefault(const SphericalRegion* r) const;
00252     SphericalRegionP getIntersectionDefault(const SphericalRegion* r) const;
00253     SphericalRegionP getUnionDefault(const SphericalRegion* r) const;
00254     SphericalRegionP getSubtractionDefault(const SphericalRegion* r) const;
00255 };
00256 
00257 
00262 class SphericalCap : public SphericalRegion
00263 {
00264 public:
00266     SphericalCap() : d(0) {;}
00267 
00269     SphericalCap(double x, double y, double z) : n(x,y,z), d(0) {;}
00270 
00274     SphericalCap(const Vec3d& an, double ar) : n(an), d(ar) {Q_ASSERT(d==0 || std::fabs(n.lengthSquared()-1.)<0.0000001);}
00275 
00277     SphericalCap(const SphericalCap& other) : SphericalRegion(), n(other.n), d(other.d) {;}
00278 
00279     virtual SphericalRegionType getType() const {return SphericalRegion::Cap;}
00280     virtual OctahedronPolygon getOctahedronPolygon() const;
00281 
00283     virtual double getArea() const {return 2.*M_PI*(1.-d);}
00284 
00286     virtual bool isEmpty() const {return d>=1.;}
00287 
00289     virtual Vec3d getPointInside() const {return n;}
00290 
00292     virtual SphericalCap getBoundingCap() const {return *this;}
00293 
00294     // Contain and intersect
00295     virtual bool contains(const Vec3d &v) const {Q_ASSERT(d==0 || std::fabs(v.lengthSquared()-1.)<0.0000001);return (v*n>=d);}
00296     virtual bool contains(const SphericalConvexPolygon& r) const;
00297     virtual bool contains(const SphericalCap& h) const
00298     {
00299         const double a = n*h.n-d*h.d;
00300         return d<=h.d && ( a>=1. || (a>=0. && a*a >= (1.-d*d)*(1.-h.d*h.d)));
00301     }
00302     virtual bool contains(const AllSkySphericalRegion& r) const {return d<=-1;}
00303     virtual bool intersects(const SphericalPolygon& r) const;
00304     virtual bool intersects(const SphericalConvexPolygon& r) const;
00308     virtual bool intersects(const SphericalCap& h) const
00309     {
00310         const double a = d*h.d - n*h.n;
00311         return d+h.d<=0. || a<=0. || (a<=1. && a*a <= (1.-d*d)*(1.-h.d*h.d));
00312     }
00313     virtual bool intersects(const AllSkySphericalRegion& poly) const {return d<=1.;}
00314 
00318     virtual QVariantMap toQVariant() const;
00319 
00320     virtual void serialize(QDataStream& out) const {out << n << d;}
00321 
00323     // Methods specific to SphericalCap
00324 
00326     double getRadius() const {return std::acos(d);}
00327 
00332     inline bool intersectsHalfSpace(double hn0, double hn1, double hn2) const
00333     {
00334         const double a = n[0]*hn0+n[1]*hn1+n[2]*hn2;
00335         return d<=0. || a<=0. || (a<=1. && a*a <= (1.-d*d));
00336     }
00337 
00340     bool clipGreatCircle(Vec3d& v1, Vec3d& v2) const;
00341 
00343     bool operator==(const SphericalCap& other) const {return (n==other.n && d==other.d);}
00344 
00346     QVector<Vec3d> getClosedOutlineContour() const;
00347 
00349     bool intersectsConvexContour(const Vec3d* vertice, int nbVertice) const;
00350 
00352     bool containsTriangle(const Vec3d* vertice) const;
00353 
00355     bool intersectsTriangle(const Vec3d* vertice) const;
00356 
00358     static SphericalRegionP deserialize(QDataStream& in);
00359 
00362     static double relativeAreaOverlap(const SphericalCap& c1, const SphericalCap& c2);
00363 
00366     static double relativeDiameterOverlap(const SphericalCap& c1, const SphericalCap& c2);
00367 
00370     static bool intersectionPoints(const SphericalCap& h1, const SphericalCap& h2, Vec3d& p1, Vec3d& p2);
00371 
00373     Vec3d n;
00375     double d;
00376 };
00377 
00381 inline bool sideHalfSpaceContains(const Vec3d& v1, const Vec3d& v2, const Vec3d& p)
00382 {
00383     return (v1[1] * v2[2] - v1[2] * v2[1])*p[0] +
00384             (v1[2] * v2[0] - v1[0] * v2[2])*p[1] +
00385             (v1[0] * v2[1] - v1[1] * v2[0])*p[2]>=-1e-17;
00386 }
00387 
00389 inline bool sideHalfSpaceContains(const Vec3d& v1, const Vec3d& v2, const SphericalCap& h)
00390 {
00391     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]);
00392     n.normalize();
00393     const double a = n*h.n;
00394     return 0<=h.d && ( a>=1. || (a>=0. && a*a >= 1.-h.d*h.d));
00395 }
00396 
00398 inline bool sideHalfSpaceIntersects(const Vec3d& v1, const Vec3d& v2, const SphericalCap& h)
00399 {
00400     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]);
00401     n.normalize();
00402     return  h.intersectsHalfSpace(n[0], n[1], n[2]);
00403 }
00404 
00407 class SphericalPoint : public SphericalRegion
00408 {
00409 public:
00410     SphericalPoint(const Vec3d& an) : n(an) {Q_ASSERT(std::fabs(1.-n.length())<0.0000001);}
00411     virtual ~SphericalPoint() {;}
00412 
00413     virtual SphericalRegionType getType() const {return SphericalRegion::Point;}
00414     virtual OctahedronPolygon getOctahedronPolygon() const;
00415     virtual double getArea() const {return 0.;}
00416     virtual bool isEmpty() const {return false;}
00417     virtual Vec3d getPointInside() const {return n;}
00418     virtual SphericalCap getBoundingCap() const {return SphericalCap(n, 1);}
00421     virtual QVariantMap toQVariant() const;
00422     virtual void serialize(QDataStream& out) const {out << n;}
00423 
00424     // Contain and intersect
00425     virtual bool contains(const Vec3d& p) const {return n==p;}
00426     virtual bool contains(const SphericalPolygon& r) const {return false;}
00427     virtual bool contains(const SphericalConvexPolygon& r) const {return false;}
00428     virtual bool contains(const SphericalCap& c) const {return false;}
00429     virtual bool contains(const SphericalPoint& r) const {return n==r.n;}
00430     virtual bool contains(const AllSkySphericalRegion& r) const {return false;}
00431     virtual bool intersects(const SphericalPolygon& r) const;
00432     virtual bool intersects(const SphericalConvexPolygon& r) const;
00433     virtual bool intersects(const SphericalCap& r) const {return r.contains(n);}
00434     virtual bool intersects(const SphericalPoint& r) const {return n==r.n;}
00435     virtual bool intersects(const AllSkySphericalRegion& r) const {return true;}
00436 
00438     static SphericalRegionP deserialize(QDataStream& in);
00439 
00441     Vec3d n;
00442 };
00443 
00446 class AllSkySphericalRegion : public SphericalRegion
00447 {
00448 public:
00449     virtual ~AllSkySphericalRegion() {;}
00450 
00451     virtual SphericalRegionType getType() const {return SphericalRegion::AllSky;}
00452     virtual OctahedronPolygon getOctahedronPolygon() const {return OctahedronPolygon::getAllSkyOctahedronPolygon();}
00453     virtual double getArea() const {return 4.*M_PI;}
00454     virtual bool isEmpty() const {return false;}
00455     virtual Vec3d getPointInside() const {return Vec3d(1,0,0);}
00456     virtual SphericalCap getBoundingCap() const {return SphericalCap(Vec3d(1,0,0), -2);}
00459     virtual QVariantMap toQVariant() const;
00460     virtual void serialize(QDataStream& out) const {;}
00461 
00462     // Contain and intersect
00463     virtual bool contains(const Vec3d& p) const {return true;}
00464     virtual bool contains(const SphericalPolygon& r) const {return true;}
00465     virtual bool contains(const SphericalConvexPolygon& r) const {return true;}
00466     virtual bool contains(const SphericalCap& r) const {return true;}
00467     virtual bool contains(const SphericalPoint& r) const {return true;}
00468     virtual bool contains(const AllSkySphericalRegion& r) const {return true;}
00469     virtual bool intersects(const SphericalPolygon& r) const {return true;}
00470     virtual bool intersects(const SphericalConvexPolygon& r) const {return true;}
00471     virtual bool intersects(const SphericalCap& r) const {return true;}
00472     virtual bool intersects(const SphericalPoint& r) const {return true;}
00473     virtual bool intersects(const AllSkySphericalRegion& r) const {return true;}
00474 
00475     static const SphericalRegionP staticInstance;
00476 };
00477 
00480 class EmptySphericalRegion : public SphericalRegion
00481 {
00482 public:
00483     // Avoid name hiding when overloading the virtual methods.
00484     using SphericalRegion::intersects;
00485     using SphericalRegion::contains;
00486     using SphericalRegion::getIntersection;
00487     using SphericalRegion::getUnion;
00488     using SphericalRegion::getSubtraction;
00489 
00490     EmptySphericalRegion() {;}
00491     virtual ~EmptySphericalRegion() {;}
00492 
00493     virtual SphericalRegionType getType() const {return SphericalRegion::Empty;}
00494     virtual OctahedronPolygon getOctahedronPolygon() const {return OctahedronPolygon::getEmptyOctahedronPolygon();}
00495     virtual double getArea() const {return 0.;}
00496     virtual bool isEmpty() const {return true;}
00497     virtual Vec3d getPointInside() const {return Vec3d(1,0,0);}
00498     virtual SphericalCap getBoundingCap() const {return SphericalCap(Vec3d(1,0,0), 2);}
00501     virtual QVariantMap toQVariant() const;
00502     virtual void serialize(QDataStream& out) const {;}
00503 
00504     // Contain and intersect
00505     virtual bool contains(const Vec3d& p) const {return false;}
00506     virtual bool contains(const SphericalPolygon& r) const {return false;}
00507     virtual bool contains(const SphericalConvexPolygon& r) const {return false;}
00508     virtual bool contains(const SphericalCap& r) const {return false;}
00509     virtual bool contains(const SphericalPoint& r) const {return false;}
00510     virtual bool contains(const AllSkySphericalRegion& r) const {return false;}
00511     virtual bool intersects(const SphericalPolygon& r) const {return false;}
00512     virtual bool intersects(const SphericalConvexPolygon& r) const {return false;}
00513     virtual bool intersects(const SphericalCap& r) const {return false;}
00514     virtual bool intersects(const SphericalPoint& r) const {return false;}
00515     virtual bool intersects(const AllSkySphericalRegion& r) const {return false;}
00516 
00517     static const SphericalRegionP staticInstance;
00518 };
00519 
00520 
00524 class SphericalPolygon : public SphericalRegion
00525 {
00526 public:
00527     // Avoid name hiding when overloading the virtual methods.
00528     using SphericalRegion::intersects;
00529     using SphericalRegion::contains;
00530     using SphericalRegion::getIntersection;
00531     using SphericalRegion::getUnion;
00532     using SphericalRegion::getSubtraction;
00533 
00534     SphericalPolygon() {;}
00536     SphericalPolygon(const QVector<QVector<Vec3d> >& contours) : octahedronPolygon(contours) {;}
00538     SphericalPolygon(const QVector<Vec3d>& contour) : octahedronPolygon(contour) {;}
00539     SphericalPolygon(const OctahedronPolygon& octContour) : octahedronPolygon(octContour) {;}
00540     SphericalPolygon(const QList<OctahedronPolygon>& octContours) : octahedronPolygon(octContours) {;}
00541 
00542     virtual SphericalRegionType getType() const {return SphericalRegion::Polygon;}
00543     virtual OctahedronPolygon getOctahedronPolygon() const {return octahedronPolygon;}
00544 
00549     virtual QVariantMap toQVariant() const;
00550     virtual void serialize(QDataStream& out) const;
00551 
00552     virtual SphericalCap getBoundingCap() const;
00553 
00554     virtual bool contains(const Vec3d& p) const {return octahedronPolygon.contains(p);}
00555     virtual bool contains(const SphericalPolygon& r) const {return octahedronPolygon.contains(r.octahedronPolygon);}
00556     virtual bool contains(const SphericalConvexPolygon& r) const;
00557     virtual bool contains(const SphericalCap& r) const {return octahedronPolygon.contains(r.getOctahedronPolygon());}
00558     virtual bool contains(const SphericalPoint& r) const {return octahedronPolygon.contains(r.n);}
00559     virtual bool contains(const AllSkySphericalRegion& r) const {return octahedronPolygon.contains(r.getOctahedronPolygon());}
00560 
00561     virtual bool intersects(const SphericalPolygon& r) const {return octahedronPolygon.intersects(r.octahedronPolygon);}
00562     virtual bool intersects(const SphericalConvexPolygon& r) const;
00563     virtual bool intersects(const SphericalCap& r) const {return r.intersects(*this);}
00564     virtual bool intersects(const SphericalPoint& r) const {return octahedronPolygon.contains(r.n);}
00565     virtual bool intersects(const AllSkySphericalRegion& r) const {return !isEmpty();}
00566 
00567     virtual SphericalRegionP getIntersection(const SphericalPoint& r) const {return contains(r.n) ? SphericalRegionP(new SphericalPoint(r)) : EmptySphericalRegion::staticInstance;}
00568     virtual SphericalRegionP getIntersection(const AllSkySphericalRegion& r) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00569 
00570     virtual SphericalRegionP getUnion(const SphericalPoint& r) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00571     virtual SphericalRegionP getUnion(const EmptySphericalRegion& r) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00572 
00573     virtual SphericalRegionP getSubtraction(const SphericalPoint& r) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00574     virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const {return SphericalRegionP(new SphericalPolygon(octahedronPolygon));}
00575 
00577     // Methods specific to SphericalPolygon
00581     void setContours(const QVector<QVector<Vec3d> >& contours) {octahedronPolygon = OctahedronPolygon(contours);}
00582 
00585     void setContour(const QVector<Vec3d>& contour) {octahedronPolygon = OctahedronPolygon(contour);}
00586 
00588     QVector<QVector<Vec3d> > getClosedOutlineContours() const {Q_ASSERT(0); return QVector<QVector<Vec3d> >();}
00589 
00591     static SphericalRegionP deserialize(QDataStream& in);
00592 
00594     static SphericalRegionP multiUnion(const QList<SphericalRegionP>& regions);
00595 
00596 private:
00597     OctahedronPolygon octahedronPolygon;
00598 };
00599 
00600 
00603 class SphericalConvexPolygon : public SphericalRegion
00604 {
00605 public:
00606     // Avoid name hiding when overloading the virtual methods.
00607     using SphericalRegion::intersects;
00608     using SphericalRegion::contains;
00609 
00611     SphericalConvexPolygon() {;}
00612 
00614     SphericalConvexPolygon(const QVector<QVector<Vec3d> >& contours) {Q_ASSERT(contours.size()==1); setContour(contours.at(0));}
00616     SphericalConvexPolygon(const QVector<Vec3d>& contour) {setContour(contour);}
00618     SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &e2) {contour << e0 << e1 << e2; updateBoundingCap();}
00620     SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &e2, const Vec3d &e3)  {contour << e0 << e1 << e2 << e3; updateBoundingCap();}
00621 
00622     virtual SphericalRegionType getType() const {return SphericalRegion::ConvexPolygon;}
00623     virtual OctahedronPolygon getOctahedronPolygon() const {return OctahedronPolygon(contour);}
00624     virtual StelVertexArray getFillVertexArray() const {return StelVertexArray(contour, StelVertexArray::TriangleFan);}
00625     virtual StelVertexArray getOutlineVertexArray() const {return StelVertexArray(contour, StelVertexArray::LineLoop);}
00626     virtual double getArea() const;
00627     virtual bool isEmpty() const {return contour.isEmpty();}
00628     virtual Vec3d getPointInside() const;
00629     virtual SphericalCap getBoundingCap() const {return cachedBoundingCap;}
00630     QVector<SphericalCap> getBoundingSphericalCaps() const;
00635     virtual QVariantMap toQVariant() const;
00636     virtual void serialize(QDataStream& out) const {out << contour;}
00637 
00638     // Contain and intersect
00639     virtual bool contains(const Vec3d& p) const;
00640     virtual bool contains(const SphericalPolygon& r) const;
00641     virtual bool contains(const SphericalConvexPolygon& r) const;
00642     virtual bool contains(const SphericalCap& r) const;
00643     virtual bool contains(const SphericalPoint& r) const {return contains(r.n);}
00644     virtual bool contains(const AllSkySphericalRegion& r) const {return false;}
00645     virtual bool intersects(const SphericalCap& r) const {if (!cachedBoundingCap.intersects(r)) return false; return r.intersects(*this);}
00646     virtual bool intersects(const SphericalPolygon& r) const;
00647     virtual bool intersects(const SphericalConvexPolygon& r) const;
00648     virtual bool intersects(const SphericalPoint& r) const {return contains(r.n);}
00649     virtual bool intersects(const AllSkySphericalRegion& r) const {return true;}
00650 
00652 //  virtual SphericalRegionP getIntersection(const SphericalPolygon& r) const;
00653 //  virtual SphericalRegionP getIntersection(const SphericalConvexPolygon& r) const;
00654 //  virtual SphericalRegionP getIntersection(const SphericalCap& r) const;
00655 //  virtual SphericalRegionP getIntersection(const SphericalPoint& r) const;
00656 //  virtual SphericalRegionP getIntersection(const AllSkySphericalRegion& r) const;
00657 //  virtual SphericalRegionP getUnion(const SphericalPolygon& r) const;
00658 //  virtual SphericalRegionP getUnion(const SphericalConvexPolygon& r) const;
00659 //  virtual SphericalRegionP getUnion(const SphericalCap& r) const;
00660 //  virtual SphericalRegionP getUnion(const SphericalPoint& r) const;
00661 //  virtual SphericalRegionP getUnion(const EmptySphericalRegion& r) const;
00662 //  virtual SphericalRegionP getSubtraction(const SphericalPolygon& r) const;
00663 //  virtual SphericalRegionP getSubtraction(const SphericalConvexPolygon& r) const;
00664 //  virtual SphericalRegionP getSubtraction(const SphericalCap& r) const;
00665 //  virtual SphericalRegionP getSubtraction(const SphericalPoint& r) const;
00666 //  virtual SphericalRegionP getSubtraction(const EmptySphericalRegion& r) const;
00667 
00669     // Methods specific to SphericalConvexPolygon
00673     void setContour(const QVector<Vec3d>& acontour) {contour=acontour; updateBoundingCap();}
00674 
00676     const QVector<Vec3d>& getConvexContour() const {return contour;}
00677 
00679     bool checkValid() const;
00680 
00682     static bool checkValidContour(const QVector<Vec3d>& contour);
00683 
00685     static SphericalRegionP deserialize(QDataStream& in);
00686 
00687 protected:
00689     QVector<Vec3d> contour;
00690 
00692     SphericalCap cachedBoundingCap;
00693 
00695     void updateBoundingCap();
00696 
00702     static bool areAllPointsOutsideOneSide(const Vec3d* thisContour, int nbThisContour, const Vec3d* points, int nbPoints);
00703 
00705     bool areAllPointsOutsideOneSide(const QVector<Vec3d>& points) const
00706     {
00707         return areAllPointsOutsideOneSide(contour.constData(), contour.size(), points.constData(), points.size());
00708     }
00709 
00710     bool containsConvexContour(const Vec3d* vertice, int nbVertex) const;
00711 };
00712 
00713 
00714 
00717 class SphericalTexturedPolygon : public SphericalPolygon
00718 {
00719 public:
00722     struct TextureVertex
00723     {
00724         Vec3d vertex;
00725         Vec2f texCoord;
00726     };
00727 
00728     SphericalTexturedPolygon() {;}
00730     SphericalTexturedPolygon(const QVector<QVector<TextureVertex> >& contours) {Q_ASSERT(0);}
00732     SphericalTexturedPolygon(const QVector<TextureVertex>& contour) {Q_ASSERT(0);}
00733 
00735     virtual StelVertexArray getFillVertexArray() const {Q_ASSERT(0); return StelVertexArray();}
00744     virtual QVariantMap toQVariant() const;
00745     virtual void serialize(QDataStream& out) const {Q_ASSERT(0);}
00746 
00748     // Methods specific to SphericalTexturedPolygon
00753     void setContours(const QVector<QVector<TextureVertex> >& contours) {Q_ASSERT(0);}
00754 
00757     void setContour(const QVector<TextureVertex>& contour) {Q_ASSERT(0);}
00758 
00759 private:
00762     QVector<Vec2f> textureCoords;
00763 };
00764 
00765 
00768 class SphericalTexturedConvexPolygon : public SphericalConvexPolygon
00769 {
00770 public:
00772     SphericalTexturedConvexPolygon() {;}
00773 
00775     SphericalTexturedConvexPolygon(const QVector<Vec3d>& contour, const QVector<Vec2f>& texCoord) {setContour(contour, texCoord);}
00776 
00779     SphericalTexturedConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &e2, const Vec3d &e3) : SphericalConvexPolygon(e0,e1,e2,e3)
00780     {
00781         textureCoords << Vec2f(0.f, 0.f) << Vec2f(1.f, 0.f) << Vec2f(1.f, 1.f) << Vec2f(0.f, 1.f);
00782     }
00783 
00786     virtual StelVertexArray getFillVertexArray() const {return StelVertexArray(contour, StelVertexArray::TriangleFan, textureCoords);}
00787 
00791     virtual void setContour(const QVector<Vec3d>& acontour, const QVector<Vec2f>& texCoord) {SphericalConvexPolygon::setContour(acontour); textureCoords=texCoord;}
00792 
00801     virtual QVariantMap toQVariant() const;
00802 
00803     virtual void serialize(QDataStream& out) const {out << contour << textureCoords;}
00804 
00805 protected:
00808     QVector<Vec2f> textureCoords;
00809 };
00810 
00811 
00815 Vec3d greatCircleIntersection(const Vec3d& p1, const Vec3d& p2, const Vec3d& p3, const Vec3d& p4, bool& ok);
00816 
00820 Vec3d greatCircleIntersection(const Vec3d& p1, const Vec3d& p2, const Vec3d& nHalfSpace, bool& ok);
00821 
00822 #endif // _STELSPHEREGEOMETRY_HPP_
00823 

Generated on Mon Mar 22 09:55:38 2010 for Stellarium by  doxygen 1.5.5