OctahedronPolygon.hpp   OctahedronPolygon.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 _OCTAHEDRON_REGION_HPP_ #ifndef _OCTAHEDRON_REGION_HPP_
#define _OCTAHEDRON_REGION_HPP_ #define _OCTAHEDRON_REGION_HPP_
#include "config.h"
#include "StelVertexArray.hpp"
#include "VecMath.hpp"
#include <QVector> #include <QVector>
#include <QDebug> #include <QDebug>
#include <QVarLengthArray> #include <QVarLengthArray>
//! @struct EdgeVertex //! @struct EdgeVertex
//! Describe a vertex composing polygon contours, and whether it belong to an edge or not. //! Describe a vertex composing polygon contours, and whether it belong to an edge or not.
struct EdgeVertex struct EdgeVertex
{ {
EdgeVertex() : edgeFlag(false) {;} EdgeVertex() : edgeFlag(false) {;}
EdgeVertex(bool b) : edgeFlag(b) {;} EdgeVertex(bool b) : edgeFlag(b) {;}
EdgeVertex(const Vec3d& v, bool b) : vertex(v), edgeFlag(b) {;} EdgeVertex(const Vec3d& v, bool b) : vertex(v), edgeFlag(b) {;}
//! The normalized vertex direction. //! The normalized vertex direction.
Vec3d vertex; Vec3d vertex;
skipping to change at line 57 skipping to change at line 61
{ {
public: public:
// Create a SubContour from a list of vertices // Create a SubContour from a list of vertices
SubContour(const QVector<Vec3d>& vertices, bool closed=true); SubContour(const QVector<Vec3d>& vertices, bool closed=true);
SubContour() {;} SubContour() {;}
SubContour(int size, const EdgeVertex& v) : QVector<EdgeVertex>(size , v) {;} SubContour(int size, const EdgeVertex& v) : QVector<EdgeVertex>(size , v) {;}
SubContour reversed() const; SubContour reversed() const;
QString toJSON() const; QString toJSON() const;
}; };
//! @class Octahedron //! @class OctahedronPolygon
//! Manage a non-convex polygon which can extends on more than 180 deg. //! Manage a non-convex polygon which can extends on more than 180 deg.
//! The contours defining the polygon are splits of an Octahedron to enable 2D geometry //! The contours defining the polygon are splitted and projected on the 8 s ides of an Octahedron to enable 2D geometry
//! algorithms to be used. //! algorithms to be used.
class OctahedronPolygon class OctahedronPolygon
{ {
public: public:
OctahedronPolygon() OctahedronPolygon() : fillCachedVertexArray(StelVertexArray::Triangl
: es), outlineCachedVertexArray(StelVertexArray::Lines), capN(1,0,0), capD(-2
.)
{sides.resize(8);}
//! Create the Octahedron by splitting the passed SubContour on the 8 sides of the octahedron. //! Create the OctahedronPolygon by splitting the passed SubContour on the 8 sides of the octahedron.
OctahedronPolygon(const SubContour& subContour); OctahedronPolygon(const SubContour& subContour);
OctahedronPolygon(const QVector<QVector<Vec3d> >& contours); OctahedronPolygon(const QVector<QVector<Vec3d> >& contours);
OctahedronPolygon(const QVector<Vec3d>& contour); OctahedronPolygon(const QVector<Vec3d>& contour);
OctahedronPolygon(const QList<OctahedronPolygon>& octContours); OctahedronPolygon(const QList<OctahedronPolygon>& octContours);
double getArea() const; double getArea() const;
Vec3d getPointInside() const; Vec3d getPointInside() const;
//! Returns the list of triangles resulting from tesselating the con
tours.
StelVertexArray getFillVertexArray() const {return fillCachedVertexA
rray;}
StelVertexArray getOutlineVertexArray() const {return outlineCachedV
ertexArray;}
void getBoundingCap(Vec3d& v, double& d) const {v=capN; d=capD;} void getBoundingCap(Vec3d& v, double& d) const {v=capN; d=capD;}
//! Set this Octahedron. //! Set this OctahedronPolygon as the intersection of itself with th e given OctahedronPolygon.
void inPlaceIntersection(const OctahedronPolygon& mpoly); void inPlaceIntersection(const OctahedronPolygon& mpoly);
//! Set this Octahedron. //! Set this OctahedronPolygon as the union of itself with the given OctahedronPolygon.
void inPlaceUnion(const OctahedronPolygon& mpoly); void inPlaceUnion(const OctahedronPolygon& mpoly);
//! Set this Octahedron. //! Set this OctahedronPolygon as the subtraction of itself with the given OctahedronPolygon.
void inPlaceSubtraction(const OctahedronPolygon& mpoly); void inPlaceSubtraction(const OctahedronPolygon& mpoly);
bool intersects(const OctahedronPolygon& mpoly) const; bool intersects(const OctahedronPolygon& mpoly) const;
bool contains(const OctahedronPolygon& mpoly) const; bool contains(const OctahedronPolygon& mpoly) const;
bool contains(const Vec3d& p) const; bool contains(const Vec3d& p) const;
bool isEmpty() const; bool isEmpty() const;
static const OctahedronPolygon& getAllSkyOctahedronPolygon(); static const OctahedronPolygon& getAllSkyOctahedronPolygon();
static const OctahedronPolygon& getEmptyOctahedronPolygon() static const OctahedronPolygon& getEmptyOctahedronPolygon() {static
OctahedronPolygon poly; return poly;}
OctahedronPolygon poly; return
static double sphericalTriangleArea(const Vec3d& v0, const Vec3d& v1 , const Vec3d& v2) static double sphericalTriangleArea(const Vec3d& v0, const Vec3d& v1 , const Vec3d& v2)
{ {
const Vec3d& p1 = v0 ^ v1; const Vec3d& p1 = v0 ^ v1;
const Vec3d& p2 = v1 ^ v2; const Vec3d& p2 = v1 ^ v2;
const Vec3d& p3 = v2 ^ v0; const Vec3d& p3 = v2 ^ v0;
return 2.*M_PI - p1.angle(p2) - p2.angle(p3) - p3.angle(p1); return 2.*M_PI - p1.angle(p2) - p2.angle(p3) - p3.angle(p1);
} }
QString toJson() const; QString toJson() const;
private: private:
// For unit tests // For unit tests
friend class TestStelSphericalGeometry; friend class TestStelSphericalGeometry;
friend QDataStream& operator<<(QDataStream&, const OctahedronPolygon &); friend QDataStream& operator<<(QDataStream&, const OctahedronPolygon &);
friend QDataStream& operator>>(QDataStream&, OctahedronPolygon&); friend QDataStream& operator>>(QDataStream&, OctahedronPolygon&);
friend OctahedronPolygon createAllSkyOctahedronPolygon(); friend OctahedronPolygon createAllSkyOctahedronPolygon();
//! Creates a full Octahedron. //! Creates a full Octahedron.
static OctahedronPolygon createAllSkyOctahedronPolygon(); static OctahedronPolygon createAllSkyOctahedronPolygon();
skipping to change at line 149 skipping to change at line 138
void appendSubContour(const SubContour& contour); void appendSubContour(const SubContour& contour);
enum TessWindingRule enum TessWindingRule
{ {
WindingPositive=0, //!< Positive winding rule (used for union) WindingPositive=0, //!< Positive winding rule (used for union)
WindingAbsGeqTwo=1 //!< Abs greater or equal 2 winding rule (used for intersection) WindingAbsGeqTwo=1 //!< Abs greater or equal 2 winding rule (used for intersection)
}; };
bool sideContains2D(const Vec3d& p, int sideNb) const; bool sideContains2D(const Vec3d& p, int sideNb) const;
//! Tesselate the contours per side, producing ubcontours according to the given rule. //! Tesselate the contours per side, producing (in @var sides) a lis t of triangles subcontours according to the given rule.
void tesselate(TessWindingRule rule); void tesselate(TessWindingRule rule);
QVector<SubContour> tesselateOneSideLineLoop(struct GLUEStesselator* tess, int sidenb) const; QVector<SubContour> tesselateOneSideLineLoop(struct GLUEStesselator* tess, int sidenb) const;
QVector<Vec3d> tesselateOneSideTriangles(struct GLUEStesselator* tes s, int sidenb) const; QVector<Vec3d> tesselateOneSideTriangles(struct GLUEStesselator* tes s, int sidenb) const;
QVarLengthArray<QVector<SubContour>,8 > sides; QVarLengthArray<QVector<SubContour>,8 > sides;
//! Update the content of both cached vertex arrays. //! Update the content of both cached vertex arrays.
void updateVertexArray(); void updateVertexArray();
StelVertexArray fillCachedVertexArray;
StelVertexArray outlineCachedVertexArray;
fillCachedVertexArray;
outlineCachedVertexArray;
void computeBoundingCap(); void computeBoundingCap();
Vec3d capN; Vec3d capN;
double capD; double capD;
static const Vec3d sideDirections[]; static const Vec3d sideDirections[];
static int getSideNumber(const Vec3d& v) {return v[0]>=0. ? (v[1]>= 0. ? (v[2]>=0.?0:1) : (v[2]>=0.?4:5)) : (v[1]>=0. ? (v[2]>=0.?2:3) : (v [2]>=0.?6:7));} static int getSideNumber(const Vec3d& v) {return v[0]>=0. ? (v[1]>= 0. ? (v[2]>=0.?0:1) : (v[2]>=0.?4:5)) : (v[1]>=0. ? (v[2]>=0.?2:3) : (v [2]>=0.?6:7));}
static bool isTriangleConvexPositive2D(const Vec3d& a, const Vec3d& b, const Vec3d& c); static bool isTriangleConvexPositive2D(const Vec3d& a, const Vec3d& b, const Vec3d& c);
static bool triangleContains2D(const Vec3d& a, const Vec3d& b, const Vec3d& c, const Vec3d& p); static bool triangleContains2D(const Vec3d& a, const Vec3d& b, const Vec3d& c, const Vec3d& p);
static void projectOnOctahedron(QVarLengthArray<QVector<SubContour>, 8 >& inSides); static void projectOnOctahedron(QVarLengthArray<QVector<SubContour>, 8 >& inSides);
End of changes. 14 change blocks.
38 lines changed or deleted 27 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/