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 <QDebug> #include <QDebug>
#include <QSharedPointer> #include <QSharedPointer>
#include <QVariant>
#include <QVarLengthArray> #include <QVarLengthArray>
#include #include <QVector>
#include "OctahedronPolygon.hpp" #include "OctahedronPolygon.hpp"
#include #include "renderer/StelVertexBuffer.hpp"
#include "Triplet.hpp"
#include "VecMath.hpp"
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 144 skipping to change at line 146
{ {
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() //! Parameters specifying how to draw a SphericalRegion.
//!
//! Passed to e.g. drawFill().
//!
//! Also used to remember previously used draw parameters, which ena
bles
//! vertex buffer caching.
//!
//! This is a builder-style struct. Parameters can be specified like
this:
//!
//! @code
//! // Default parameters. Projector is mandatory, so it is specifie
d in the constructor.
//! SphericalRegion::DrawParams a(someProjectorPointer);
//! // Do not subdivide the region into smaller triangles.
//! SphericalRegion::DrawParams b = SphericalRegion::DrawParams(some
ProjectorPointer)
//! .doNotSubdivide(
);
//! // Do not subdivide and clip the part of the region outside of s
pecified cap.
//! SphericalRegion::DrawParams c = SphericalRegion::DrawParams(some
ProjectorPointer)
//! .doNotSubdivide(
)
//! .clippingCap(som
eSphericalCapPointer);
//! @endcode
//!
//!
struct DrawParams
{
//! Construct DrawParams with default parameters and specifi
ed projector.
//!
//! @param projector Projector to use for drawing.
//!
//! The default parameters are: no clipping cap, subdivide t
he region to
//! follow projection distortions, max distortion 5.0.
DrawParams(class StelProjector* projector)
: projector_(projector)
, clippingCap_(NULL)
, subdivide_(true)
, maxSqDistortion_(5.0)
{}
//! Only used to determine whether to update cached vertex b
uffers.
//!
//! Compares parameters given in a previous drawXXX()
//! call with parameters given in the current call.
//!
//! Projector is ignored - outside code needs to figure out
if projector
//! affects vertex buffer generation. Clipping cap is only a
ssumed to be
//! the same if both previos and current is NULL (which is u
sually the case).
bool operator != (const DrawParams& rhs) const
{
// Projector is ignored, as even if the pointer poin
ts to the same object,
// the objects' state might have changed, making com
parison useless.
// Instead, we only cache in cases when projector is
not used used outside
// Renderer (i.e. not affecting vertex buffers that
get cached) or NULL.
// Clipping caps are only considered equal when NULL
(which is the
// most common case, anyway). There is no opportunit
y for special handling
// like projectors, since, when not NULL, clipping c
aps are always used
// in vertex buffer generation.
return (clippingCap_ == NULL && rhs.clippingCap_ ==
NULL) ||
subdivide_ != rhs.subdivide_ ||
//Fuzzy compare might be better here
maxSqDistortion_ != rhs.maxSqDistortion_;
}
//! If not NULL, used to clip the part of the region outside
the cap.
DrawParams& clippingCap(const SphericalCap* clippingCap)
{
clippingCap_ = clippingCap;
return *this;
}
//! Do not subdivide the region to follow projection distort
ions.
//!
//! Improves drawing speed.
//!
//! You can use this if you think that the region is fully c
ontained in the viewport.
DrawParams& doNotSubdivide()
{
subdivide_ = false;
return *this;
}
//! Specify maximum distortion - we try to subdivide to be w
ithil this limit.
DrawParams& maxSqDistortion(const double maxSqDistortion)
{
maxSqDistortion_ = maxSqDistortion;
return *this;
}
//! Projector to use when drawing.
class StelProjector* projector_;
//! If specified, clips the part of the region outside of ca
p.
const SphericalCap* clippingCap_;
//! Subdivide triangles?
bool subdivide_;
//! Maximum distortion.
double maxSqDistortion_;
};
//! 3D vertex with only a position.
struct PlainVertex
{
Vec3f position;
PlainVertex(const Vec3f& position) : position(position){}
PlainVertex(const Vec3d& pos) : position(pos[0], pos[1], pos
[2]) {}
VERTEX_ATTRIBUTES(Vec3f Position)
};
//! 3D vertex with position and a texture coordinate.
struct TexturedVertex
{
Vec3f position;
Vec2f texCoord;
TexturedVertex(const Vec3f& position, const Vec2f& texCoord)
: position(position) , texCoord(texCoord) {}
TexturedVertex(const Vec3d& pos, const Vec2f& texCoord)
: position(pos[0], pos[1], pos[2]) , texCoord(texCoo
rd) {}
VERTEX_ATTRIBUTES(Vec3f Position, Vec2f TexCoord)
};
//! Default constructor. Inializes with no vertex buffers.
SphericalRegion()
: fillPlainVertexBuffer(NULL)
, previousFillDrawParams(NULL)
{
// Make sure previousFillDrawParams is invalid at start, so
it gets replaced
// at first drawFill() call.
previousFillDrawParams.maxSqDistortion_ = -42.0f;
}
//! Destructor. Cleans up vertex buffers, if any.
virtual ~SphericalRegion()
{
if(NULL != fillPlainVertexBuffer)
{
delete fillPlainVertexBuffer;
}
}
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 176 skipping to change at line 317
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;
//! a //! Get a vector of vertex positions forming the region.
virtual const QVector<Vec3d>& getFillVertexPositions() const
virtual const {
return getOctahedronPolygon().fillVertices();
}
//! Get primitive type determining how vertices in vector returned b
y
//! getFillVertexPositions() form triangles.
virtual PrimitiveType getFillPrimitiveType() const
{
return PrimitiveType_Triangles;
}
//! 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 //! @return a list of vertices which define the contours of the poly
of the gon.
virtual const virtual const QVector<Vec3d>& getOutlineVertexPositions() const
{
// This is a workaround around a compiler bug with Clang (as
of Clang 3.2).
// Returning the reference directly results in an uninitiali
zed
// reference which breaks calling code.
const QVector<Vec3d>& result(getOctahedronPolygon().outlineV
ertices());
return result;
}
//! Get primitive type determining how vertices in vector returned b
y
//! getOutlinePrimitiveType() form lines.
virtual PrimitiveType getOutlinePrimitiveType() const
{
return PrimitiveType_Lines;
}
//! 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 254 skipping to change at line 419
//! 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;
//! Draw the region as triangles (i.e. filling the region).
//!
//! @param renderer Renderer to use for drawing.
//! @param params Drawing parameters (projector, clipping cap, if
any, etc.).
//!
//! @see DrawParams
virtual void drawFill(class StelRenderer* renderer, const DrawParams
& params);
//! Draw the outline of the region.
//!
//! @param renderer Renderer to use for drawing.
//! @param params Drawing parameters (projector, clipping cap, if
any, etc.).
//! Note that maxSqDistortion has no effect here.
//!
//! @see DrawParams
virtual void drawOutline(class StelRenderer* renderer, const DrawPar
ams& params);
protected:
//! Cached plain vertex buffer for drawing.
StelVertexBuffer<PlainVertex>* fillPlainVertexBuffer;
//! Should Renderer draw calls specify a projector?
//!
//! This is true unless we've projected the vertices ourselves (whic
h is the
//! case when we're subdividing the region into smaller triangles.)
bool useProjector;
//! Update the vertex buffer used by drawFill().
//!
//! Called when drawing parameters have changed, or when we cannot c
ache
//! vertices (e.g. when subdividing and this projecting outside Rend
erer).
//!
//! @param renderer Renderer to create vertex buffer.
//! @param params Parameters used for drawing
//! (which also affect vertex generation)
.
//! @param handleDiscontinuity Do we need to ensure that no triangle
s cross a
//! projection discontinuity?
virtual void updateFillVertexBuffer(class StelRenderer* renderer, co
nst DrawParams& params, bool handleDiscontinuity);
//! Drawing part of drawFill() - assumes the buffer/s is/are generat
ed.
//!
//! @param renderer Renderer used for drawing.
//! @param projector Projector to project the vertices
//! (NULL if subdivision is enabled, as in that cas
e
//! the projection is done during buffer generation
)
virtual void drawFillVertexBuffer(class StelRenderer* renderer, clas
s StelProjector* projector);
//! Do we need to update vertex buffer/s used by drawFill()?
//!
//! Might be true if e.g. the region has changed. Note that this is
only
//! one possible reason to update the buffers, drawFill() contains t
he full
//! logic to determine this (e.g. we always update when subdividing
is enabled).
virtual bool needToUpdateFillVertexBuffers() const
{
// Can't determine whether we can cache anything -
// we'd need to know if polygon returned by getOctahedronPol
ygon has changed,
// but since getOctahedronPolygon returns by value, not refe
rence,
// it returns a new octahedronPolygon every time.
//
// If it was by reference, _and_ guaranteed to always point
to the same polygon,
// we might store a flag in the polygon determining if its v
ertex array has
// changed, and use that for caching.
return true;
}
//! Called after updating vertex buffer/s used by drawFill().
virtual void fillVertexBuffersUpdated() {}
private: private:
//! Parameters used for the previous drawFill() call.
DrawParams previousFillDrawParams;
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 .
skipping to change at line 299 skipping to change at line 535
//! 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 || bool contains(const Vec3d &v) const
{
Q_ASSERT(d==0 || std::fabs(v.lengthSquared()-1.)<0.00000021)
;
return (v*n>=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 356 skipping to change at line 595
//! 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 //! Does the cap contain the passed triangle?
bool containsTriangle(const const; bool containsTriangle(const Triplet<Vec3d> triangle) const;
//! the cap intersect with the passed //! Does the cap intersect with the passed triangle?
bool intersectsTriangle(const const; bool intersectsTriangle(const Triplet<Vec3d>& triangle) 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 457 skipping to change at line 696
}; };
//! @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 OctahedronPolygon::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 499 skipping to change at line 741
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 OctahedronPolygon::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 547 skipping to change at line 792
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 octahedronPolygon;
}
//! 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 585 skipping to change at line 833
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)
= {
octahedronPolygon = 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 620 skipping to change at line 874
{ {
public: public:
// Avoid name hiding when overloading the virtual methods. // Avoid name hiding when overloading the virtual methods.
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)
: fillVertexBufferNeedsUpdate(true)
{
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)
: fillVertexBufferNeedsUpdate(true)
{
setContour(contour);
}
//! 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) << e0 << e1 << e2; e2)
: fillVertexBufferNeedsUpdate(true)
{
contour << e0 << e1 << e2; updateBoundingCap();
}
//! Special constructor for quads. //! Special constructor for quads.
SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d & SphericalConvexPolygon(const Vec3d &e0,const Vec3d &e1,const Vec3d &
e2, const Vec3d &e3) << e0 << e1 << e2 << e3; e2, const Vec3d &e3)
: fillVertexBufferNeedsUpdate(true)
{
contour << e0 << e1 << e2 << e3; updateBoundingCap();
}
virtual SphericalRegionType getType() const {return SphericalRegion: :ConvexPolygon;} virtual SphericalRegionType getType() const {return SphericalRegion: :ConvexPolygon;}
virtual OctahedronPolygon getOctahedronPolygon() const
virtual OctahedronPolygon getOctahedronPolygon() const
virtual const {
return OctahedronPolygon(contour);
virtual const }
virtual const QVector<Vec3d>& getFillVertexPositions() const
{
return contour;
}
virtual PrimitiveType getFillPrimitiveType() const
{
return PrimitiveType_TriangleFan;
}
virtual const QVector<Vec3d>& getOutlineVertexPositions() const
{
return contour;
}
virtual PrimitiveType getOutlinePrimitiveType() const
{
return PrimitiveType_LineLoop;
}
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 679 skipping to change at line 976
// 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;
fillVertexBufferNeedsUpdate = true;
updateBoundingCap();
}
//! 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;
//! Does the drawFill() vertex buffer need an update?
bool fillVertexBufferNeedsUpdate;
//! Update the bounding cap from the vertex list. //! Update the bounding cap from the vertex list.
void updateBoundingCap(); void updateBoundingCap();
virtual void updateFillVertexBuffer(class StelRenderer* renderer, co
nst DrawParams& params, bool handleDiscontinuity);
virtual void drawFillVertexBuffer(class StelRenderer* renderer, clas
s StelProjector* projector);
virtual bool needToUpdateFillVertexBuffers() const
{
return fillVertexBufferNeedsUpdate;
}
virtual void fillVertexBuffersUpdated()
{
fillVertexBufferNeedsUpdate = false;
}
//! 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
{ {
skipping to change at line 779 skipping to change at line 1098
//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 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() : fillTexturedVertexBuffer(NULL)
{
fillVertexBufferNeedsUpdate = true;
}
//! 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)
: fillTexturedVertexBuffer(NULL)
{
setContour(contour, texCoord);
fillVertexBufferNeedsUpdate = true;
}
//! Special constructor for quads. //! Special constructor for quads.
//! 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) : SphericalConvexPolygon(e0,e1,e2,e3) Vec3d &e2, const Vec3d &e3)
: SphericalConvexPolygon(e0,e1,e2,e3)
, fillTexturedVertexBuffer(NULL)
{ {
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);
fillVertexBufferNeedsUpdate = true;
} }
virtual ~SphericalTexturedConvexPolygon()
{
if(NULL != fillTexturedVertexBuffer)
{
virtual delete fillTexturedVertexBuffer;
}
}
//! 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);
textureCoords=texCoord;
fillVertexBufferNeedsUpdate = true;
}
//! 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 texture coordinates corresponding to the triangle v ertices.
//! There should be 1 uv position per vertex. //! There should be 1 uv position per vertex.
QVector<Vec2f> textureCoords; QVector<Vec2f> textureCoords;
//! Vertex buffer used in our override of drawFill() (using vertices
with texcoords).
StelVertexBuffer<TexturedVertex>* fillTexturedVertexBuffer;
virtual void updateFillVertexBuffer(class StelRenderer* renderer, co
nst DrawParams& params, bool handleDiscontinuity);
virtual void drawFillVertexBuffer(class StelRenderer* renderer, clas
s StelProjector* projector);
}; };
//! Compute the intersection of 2 great circles segments. //! Compute the intersection of 2 great circles segments.
//! @param p1 Start of the first great circle segment.
//! @param p2 End of the first great circle segment.
//! @param p3 Start of the second great circle segment.
//! @param p4 End of the second great circle segment.
//! @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 p1 Start of the great circle segment.
//! @param p2 End of the great circle segment.
//! @param nHalfSpace Normal of the plane separating half space to intersec
t with.
//! @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. 36 change blocks.
127 lines changed or deleted 459 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/