StelProjector.hpp   StelProjector.hpp 
skipping to change at line 40 skipping to change at line 40
//! All methods from this class are threadsafe. The usual usage is to creat e local instances of StelProjectorP using the //! All methods from this class are threadsafe. The usual usage is to creat e local instances of StelProjectorP using the
//! getProjection() method from StelCore where needed. //! getProjection() method from StelCore where needed.
//! For performing drawing using a particular projection, refer to the Stel Painter class. //! For performing drawing using a particular projection, refer to the Stel Painter class.
//! @sa StelProjectorP //! @sa StelProjectorP
class StelProjector class StelProjector
{ {
public: public:
friend class StelPainter; friend class StelPainter;
friend class StelCore; friend class StelCore;
class ModelViewTranform;
//! @typedef ModelViewTranformP
//! Shared pointer on a ModelViewTranform instance (implement refere
nce counting)
typedef QSharedPointer<ModelViewTranform> ModelViewTranformP;
//! @class PreModelViewFunc
//! Allows to define non linear operations in addition to the standa
rd linear (Matrix 4d) ModelView transformation.
class ModelViewTranform
{
public:
ModelViewTranform() {;}
virtual ~ModelViewTranform() {;}
virtual void forward(Vec3d&) const =0;
virtual void backward(Vec3d&) const =0;
virtual void forward(Vec3f&) const =0;
virtual void backward(Vec3f&) const =0;
virtual void combine(const Mat4d&)=0;
virtual ModelViewTranformP clone() const=0;
virtual Mat4d getApproximateLinearTransfo() const=0;
};
class Mat4dTransform: public ModelViewTranform
{
public:
Mat4dTransform(const Mat4d& m) : transfoMat(m),
transfoMatf(m[0], m[1], m[2], m[3],
m[4], m[5], m[6], m
[7],
m[8], m[9], m[10],
m[11],
m[12], m[13], m[14]
, m[15]) {;}
void forward(Vec3d& v) const {v.transfo4d(transfoMat);}
void backward(Vec3d& v) const
{
// We need no matrix inversion because we always wor
k with orthogonal matrices (where the transposed is the inverse).
//v.transfo4d(inverseTransfoMat);
const double x = v[0] - transfoMat.r[12];
const double y = v[1] - transfoMat.r[13];
const double z = v[2] - transfoMat.r[14];
v[0] = transfoMat.r[0]*x + transfoMat.r[1]*y + trans
foMat.r[2]*z;
v[1] = transfoMat.r[4]*x + transfoMat.r[5]*y + trans
foMat.r[6]*z;
v[2] = transfoMat.r[8]*x + transfoMat.r[9]*y + trans
foMat.r[10]*z;
}
void forward(Vec3f& v) const {v.transfo4d(transfoMatf);}
void backward(Vec3f& v) const
{
// We need no matrix inversion because we always wor
k with orthogonal matrices (where the transposed is the inverse).
//v.transfo4d(inverseTransfoMat);
const float x = v[0] - transfoMatf.r[12];
const float y = v[1] - transfoMatf.r[13];
const float z = v[2] - transfoMatf.r[14];
v[0] = transfoMatf.r[0]*x + transfoMatf.r[1]*y + tra
nsfoMatf.r[2]*z;
v[1] = transfoMatf.r[4]*x + transfoMatf.r[5]*y + tra
nsfoMatf.r[6]*z;
v[2] = transfoMatf.r[8]*x + transfoMatf.r[9]*y + tra
nsfoMatf.r[10]*z;
}
void combine(const Mat4d& m)
{
Mat4f mf(m[0], m[1], m[2], m[3],
m[4], m[5], m[6], m
[7],
m[8], m[9], m[10],
m[11],
m[12], m[13], m[14]
, m[15]);
transfoMat=transfoMat*m;
transfoMatf=transfoMatf*mf;
}
Mat4d getApproximateLinearTransfo() const {return transfoMat
;}
ModelViewTranformP clone() const {return ModelViewTranformP(
new Mat4dTransform(transfoMat));}
private:
//! transfo matrix and invert
Mat4d transfoMat;
Mat4f transfoMatf;
};
//! @enum StelProjectorMaskType //! @enum StelProjectorMaskType
//! Define viewport mask types //! Define viewport mask types
enum StelProjectorMaskType enum StelProjectorMaskType
{ {
MaskNone, //!< Regular - no mask. MaskNone, //!< Regular - no mask.
MaskDisk //!< For disk viewport mode (circular mask t o seem like bins/telescope) MaskDisk //!< For disk viewport mode (circular mask t o seem like bins/telescope)
}; };
//! @struct StelProjectorParams //! @struct StelProjectorParams
//! Contains all the param needed to initialize a StelProjector //! Contains all the param needed to initialize a StelProjector
skipping to change at line 65 skipping to change at line 139
bool gravityLabels; //! the flag to use gravity labels or not bool gravityLabels; //! the flag to use gravity labels or not
float defautAngleForGravityText;//! a rotation angle to appl y to gravity text (only if gravityLabels is set to false) float defautAngleForGravityText;//! a rotation angle to appl y to gravity text (only if gravityLabels is set to false)
StelProjectorMaskType maskType; //! The current projector ma sk StelProjectorMaskType maskType; //! The current projector ma sk
float zNear, zFar; //! Near and far clipping pl anes float zNear, zFar; //! Near and far clipping pl anes
Vec2f viewportCenter; //! Viewport center in scree n pixel Vec2f viewportCenter; //! Viewport center in scree n pixel
float viewportFovDiameter; //! diameter of the FOV disk in pixel float viewportFovDiameter; //! diameter of the FOV disk in pixel
bool flipHorz, flipVert; //! Whether to flip in horiz ontal or vertical directions bool flipHorz, flipVert; //! Whether to flip in horiz ontal or vertical directions
}; };
//! Destructor //! Destructor
virtual ~StelProjector() {;} virtual ~StelProjector() {}
//////////////////////////////////////////////////////////////////// /////// //////////////////////////////////////////////////////////////////// ///////
// Methods which must be reimplemented by all instance of StelProjec tor // Methods which must be reimplemented by all instance of StelProjec tor
//! Get a human-readable name for this projection type //! Get a human-readable name for this projection type
virtual QString getNameI18() const = 0; virtual QString getNameI18() const = 0;
//! Get a human-readable short description for this projection type //! Get a human-readable short description for this projection type
virtual QString getDescriptionI18() const {return "No description";} virtual QString getDescriptionI18() const {return "No description";}
//! Get a HTML version of the short description for this projection type //! Get a HTML version of the short description for this projection type
QString getHtmlSummary() const; QString getHtmlSummary() const;
//! Get the maximum FOV apperture in degree //! Get the maximum FOV apperture in degree
skipping to change at line 94 skipping to change at line 168
//! Apply the transformation in the backward projection in place. //! Apply the transformation in the backward projection in place.
virtual bool backward(Vec3d& v) const = 0; virtual bool backward(Vec3d& v) const = 0;
//! Return the small zoom increment to use at the given FOV for nice movements //! Return the small zoom increment to use at the given FOV for nice movements
virtual float deltaZoom(float fov) const = 0; virtual float deltaZoom(float fov) const = 0;
//! Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity. //! Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity.
//! For many projections without discontinuity, this should return a lways false, but for other like //! For many projections without discontinuity, this should return a lways false, but for other like
//! cylindrical projection it will return true if the line cuts the wrap-around line (i.e. at lon=180 if the observer look at lon=0). //! cylindrical projection it will return true if the line cuts the wrap-around line (i.e. at lon=180 if the observer look at lon=0).
bool intersectViewportDiscontinuity(const Vec3d& p1, const Vec3d& p2 ) const bool intersectViewportDiscontinuity(const Vec3d& p1, const Vec3d& p2 ) const
{ {
return hasDiscontinuity() && intersectViewportDiscontinuityI if (hasDiscontinuity()==false)
nternal(modelViewMatrix*p1, modelViewMatrix*p2); return false;
Vec3d v1(p1);
modelViewTransform->forward(v1);
Vec3d v2(p2);
modelViewTransform->forward(v2);
return intersectViewportDiscontinuityInternal(v1, v2);
} }
bool intersectViewportDiscontinuity(const SphericalCap& cap) const bool intersectViewportDiscontinuity(const SphericalCap& cap) const
{ {
return hasDiscontinuity() && intersectViewportDiscontinuityI if (hasDiscontinuity()==false)
nternal(modelViewMatrix*cap.n, cap.d); return false;
Vec3d v1(cap.n);
modelViewTransform->forward(v1);
return intersectViewportDiscontinuityInternal(v1, cap.d);
} }
//! Convert a Field Of View radius value in radians in ViewScalingFa ctor (used internally) //! Convert a Field Of View radius value in radians in ViewScalingFa ctor (used internally)
virtual float fovToViewScalingFactor(float fov) const = 0; virtual float fovToViewScalingFactor(float fov) const = 0;
//! Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians //! Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians
virtual float viewScalingFactorToFov(float vsf) const = 0; virtual float viewScalingFactorToFov(float vsf) const = 0;
//! Get the current state of the flag which decides whether to //! Get the current state of the flag which decides whether to
//! arrage labels so that they are aligned with the bottom of a 2d //! arrage labels so that they are aligned with the bottom of a 2d
//! screen, or a 3d dome. //! screen, or a 3d dome.
skipping to change at line 211 skipping to change at line 295
win = v; win = v;
return projectInPlace(win); return projectInPlace(win);
} }
virtual void project(int n, const Vec3d* in, Vec3f* out) virtual void project(int n, const Vec3d* in, Vec3f* out)
{ {
Vec3d v; Vec3d v;
for (int i = 0; i < n; ++i, ++out) for (int i = 0; i < n; ++i, ++out)
{ {
v = in[i]; v = in[i];
v.transfo4d(modelViewMatrix); modelViewTransform->forward(v);
out->set(v[0], v[1], v[2]); out->set(v[0], v[1], v[2]);
forward(*out); forward(*out);
out->set(viewportCenter[0] + flipHorz * pixelPerRad * (*out)[0], out->set(viewportCenter[0] + flipHorz * pixelPerRad * (*out)[0],
viewportCenter[1] + flipVert * pixelPerRad * (*out)[1], viewportCenter[1] + flipVert * pixelPerRad * (*out)[1],
((*out)[2] - zNear) * oneOverZNearMinusZFar) ; ((*out)[2] - zNear) * oneOverZNearMinusZFar) ;
} }
} }
virtual void project(int n, const Vec3f* in, Vec3f* out) virtual void project(int n, const Vec3f* in, Vec3f* out)
{ {
for (int i = 0; i < n; ++i, ++out) for (int i = 0; i < n; ++i, ++out)
{ {
*out=in[i]; *out=in[i];
out->transfo4d(modelViewMatrixf); modelViewTransform->forward(*out);
forward(*out); forward(*out);
out->set(viewportCenter[0] + flipHorz * pixelPerRad * (*out)[0], out->set(viewportCenter[0] + flipHorz * pixelPerRad * (*out)[0],
viewportCenter[1] + flipVert * pixelPerRad * (*out)[1], viewportCenter[1] + flipVert * pixelPerRad * (*out)[1],
((*out)[2] - zNear) * oneOverZNearMinusZFar) ; ((*out)[2] - zNear) * oneOverZNearMinusZFar) ;
} }
} }
//! Project the vector v from the current frame into the viewport. //! Project the vector v from the current frame into the viewport.
//! @param vd the vector in the current frame. //! @param vd the vector in the current frame.
//! @return true if the projected coordinate is valid. //! @return true if the projected coordinate is valid.
inline bool projectInPlace(Vec3d& vd) const inline bool projectInPlace(Vec3d& vd) const
{ {
vd.transfo4d(modelViewMatrix); modelViewTransform->forward(vd);
Vec3f v(vd[0], vd[1], vd[2]); Vec3f v(vd[0], vd[1], vd[2]);
const bool rval = forward(v); const bool rval = forward(v);
// very important: even when the projected point comes from an // very important: even when the projected point comes from an
// invisible region of the sky (rval=false), we must finish // invisible region of the sky (rval=false), we must finish
// reprojecting, so that OpenGl can successfully eliminate // reprojecting, so that OpenGl can successfully eliminate
// polygons by culling. // polygons by culling.
vd[0] = viewportCenter[0] + flipHorz * pixelPerRad * v[0]; vd[0] = viewportCenter[0] + flipHorz * pixelPerRad * v[0];
vd[1] = viewportCenter[1] + flipVert * pixelPerRad * v[1]; vd[1] = viewportCenter[1] + flipVert * pixelPerRad * v[1];
vd[2] = (v[2] - zNear) * oneOverZNearMinusZFar; vd[2] = (v[2] - zNear) * oneOverZNearMinusZFar;
return rval; return rval;
} }
//! Project the vector v from the current frame into the viewport. //! Project the vector v from the current frame into the viewport.
//! @param v the vector in the current frame. //! @param v the vector in the current frame.
//! @return true if the projected coordinate is valid. //! @return true if the projected coordinate is valid.
inline bool projectInPlace(Vec3f& v) const inline bool projectInPlace(Vec3f& v) const
{ {
v.transfo4d(modelViewMatrixf); modelViewTransform->forward(v);
const bool rval = forward(v); const bool rval = forward(v);
// very important: even when the projected point comes from an // very important: even when the projected point comes from an
// invisible region of the sky (rval=false), we must finish // invisible region of the sky (rval=false), we must finish
// reprojecting, so that OpenGl can successfully eliminate // reprojecting, so that OpenGl can successfully eliminate
// polygons by culling. // polygons by culling.
v[0] = viewportCenter[0] + flipHorz * pixelPerRad * v[0]; v[0] = viewportCenter[0] + flipHorz * pixelPerRad * v[0];
v[1] = viewportCenter[1] + flipVert * pixelPerRad * v[1]; v[1] = viewportCenter[1] + flipVert * pixelPerRad * v[1];
v[2] = (v[2] - zNear) * oneOverZNearMinusZFar; v[2] = (v[2] - zNear) * oneOverZNearMinusZFar;
return rval; return rval;
} }
skipping to change at line 297 skipping to change at line 381
//! Project the vectors v1 and v2 from the current frame into the vi ewport. //! Project the vectors v1 and v2 from the current frame into the vi ewport.
//! @param v1 the first vector in the current frame. //! @param v1 the first vector in the current frame.
//! @param v2 the second vector in the current frame. //! @param v2 the second vector in the current frame.
//! @param win1 the first projected vector in the viewport 2D frame. //! @param win1 the first projected vector in the viewport 2D frame.
//! @param win2 the second projected vector in the viewport 2D frame . //! @param win2 the second projected vector in the viewport 2D frame .
//! @return true if at least one of the projected vector is within t he viewport. //! @return true if at least one of the projected vector is within t he viewport.
bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const
{return project(v1, win1) && project(v2, win2) && (checkInVi ewport(win1) || checkInViewport(win2));} {return project(v1, win1) && project(v2, win2) && (checkInVi ewport(win1) || checkInViewport(win2));}
//! Get the current model view matrix. //! Get the current model view matrix.
const Mat4d& getModelViewMatrix() const {return modelViewMatrix;} ModelViewTranformP getModelViewTransform() const {return modelViewTr ansform;}
//! Get the current projection matrix. //! Get the current projection matrix.
Mat4f getProjectionMatrix() const {return Mat4f(2.f/viewportXywh[2], 0, 0, 0, 0, 2.f/viewportXywh[3], 0, 0, 0, 0, -1., 0., -(2.f*viewportXywh[0 ] + viewportXywh[2])/viewportXywh[2], -(2.f*viewportXywh[1] + viewportXywh[ 3])/viewportXywh[3], 0, 1);} Mat4f getProjectionMatrix() const {return Mat4f(2.f/viewportXywh[2], 0, 0, 0, 0, 2.f/viewportXywh[3], 0, 0, 0, 0, -1., 0., -(2.f*viewportXywh[0 ] + viewportXywh[2])/viewportXywh[2], -(2.f*viewportXywh[1] + viewportXywh[ 3])/viewportXywh[3], 0, 1);}
//////////////////////////////////////////////////////////////////// /////// //////////////////////////////////////////////////////////////////// ///////
//! Get a string description of a StelProjectorMaskType. //! Get a string description of a StelProjectorMaskType.
static const QString maskTypeToString(StelProjectorMaskType type); static const QString maskTypeToString(StelProjectorMaskType type);
//! Get a StelProjectorMaskType from a string description. //! Get a StelProjectorMaskType from a string description.
static StelProjectorMaskType stringToMaskType(const QString &s); static StelProjectorMaskType stringToMaskType(const QString &s);
//! Get the current type of the mask if any. //! Get the current type of the mask if any.
StelProjectorMaskType getMaskType(void) const {return maskType;} StelProjectorMaskType getMaskType(void) const {return maskType;}
protected: protected:
//! Private constructor. Only StelCore can create instances of StelP rojector. //! Private constructor. Only StelCore can create instances of StelP rojector.
StelProjector(const Mat4d& modelViewMat) : modelViewMatrix(modelView StelProjector(ModelViewTranformP amodelViewTransform) : modelViewTra
Mat), nsform(amodelViewTransform) {;}
modelViewMatrixf(modelViewMat[0], modelViewMat[1], modelView
Mat[2], modelViewMat[3],
modelViewMat[4], modelViewM
at[5], modelViewMat[6], modelViewMat[7],
modelViewMat[8], modelViewM
at[9], modelViewMat[10], modelViewMat[11],
modelViewMat[12], modelView
Mat[13], modelViewMat[14], modelViewMat[15]) {;}
//! Return whether the projection presents discontinuities. Used for optimization. //! Return whether the projection presents discontinuities. Used for optimization.
virtual bool hasDiscontinuity() const =0; virtual bool hasDiscontinuity() const =0;
//! Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity. //! Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity.
//! For many projections without discontinuity, this should return a lways false, but for other like //! For many projections without discontinuity, this should return a lways false, but for other like
//! cylindrical projection it will return true if the line cuts the wrap-around line (i.e. at lon=180 if the observer look at lon=0). //! cylindrical projection it will return true if the line cuts the wrap-around line (i.e. at lon=180 if the observer look at lon=0).
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0; virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0;
//! Determine whether a cap intersects with a projection discontinui ty. //! Determine whether a cap intersects with a projection discontinui ty.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& cap N, double capD) const = 0; virtual bool intersectViewportDiscontinuityInternal(const Vec3d& cap N, double capD) const = 0;
//! Initialize the bounding cap. //! Initialize the bounding cap.
virtual void computeBoundingCap(); virtual void computeBoundingCap();
Mat4d modelViewMatrix; // openGL MODELVIEW Matr ModelViewTranformP modelViewTransform; // Operator to apply (if not
ix NULL) before the modelview projection step
Mat4f modelViewMatrixf; // openGL MODELVIEW Matrix
float flipHorz,flipVert; // Whether to flip in horizontal or vertical directions float flipHorz,flipVert; // Whether to flip in horizontal or vertical directions
float pixelPerRad; // pixel per rad at the center o f the viewport disk float pixelPerRad; // pixel per rad at the center o f the viewport disk
StelProjectorMaskType maskType; // The current projector mask StelProjectorMaskType maskType; // The current projector mask
float zNear, oneOverZNearMinusZFar; // Near and far clipping planes float zNear, oneOverZNearMinusZFar; // Near and far clipping planes
Vec4i viewportXywh; // Viewport parameters Vec4i viewportXywh; // Viewport parameters
Vec2f viewportCenter; // Viewport center in screen pix el Vec2f viewportCenter; // Viewport center in screen pix el
float viewportFovDiameter; // diameter of the FOV disk in p ixel float viewportFovDiameter; // diameter of the FOV disk in p ixel
bool gravityLabels; // should label text align with the horizon? bool gravityLabels; // should label text align with the horizon?
float defautAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false) float defautAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false)
SphericalCap boundingCap; // Bounding cap of the whole vie wport SphericalCap boundingCap; // Bounding cap of the whole vie wport
 End of changes. 11 change blocks. 
23 lines changed or deleted 116 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/