cherish
Static Public Member Functions | List of all members
Utilities Class Reference

Some generic methods compiled into one class. Methods that describe: More...

#include <Utilities.h>

Static Public Member Functions

static QColor getQColor (const osg::Vec4f &color)
 
static osg::Vec4f getOsgColor (const QColor &color)
 
static bool areStrokesProjectable (const std::vector< entity::Stroke *> &strokes, entity::Canvas *source, entity::Canvas *target, osg::Camera *camera)
 
static bool getViewProjectionWorld (osgGA::GUIActionAdapter &aa, osg::Matrix &VPW, osg::Matrix &invVPW)
 
static void getFarNear (double x, double y, const osg::Matrix &invVPW, osg::Vec3f &near, osg::Vec3f &far)
 
static bool getRayPlaneIntersection (const osg::Plane &plane, const osg::Vec3f &center, const osg::Vec3f &nearPoint, const osg::Vec3f &farPoint, osg::Vec3f &P, bool isLine=false)
 
static bool getModel (entity::Canvas *canvas, osg::Matrix &M, osg::Matrix &invM)
 
static bool getLocalFromGlobal (const osg::Vec3f &P, const osg::Matrix &invM, osg::Vec3f &p)
 
static bool getGlobalFromLocal (const osg::Vec3f &p, const osg::Matrix &M, osg::Vec3f &P)
 
static double getAngleTwoVectors (const osg::Vec2f &p1, const osg::Vec2f &p2, const osg::Vec2f &p3, const osg::Vec2f &p4)
 
static osg::Vec3f rotate2DPointAround (const osg::Vec3f &center, float theta, const osg::Vec3f &original)
 
static bool getSkewLinesProjection (const osg::Vec3f &center, const osg::Vec3f &farPoint, const osg::Vec3f &nearPoint, const osg::Vec3f &normal, osg::Vec3f &X1)
 
static double getSkewLinesDistance (const osg::Vec3d &r1, const osg::Vec3d &r2, const osg::Vec3d &v1, const osg::Vec3d &v2)
 
static bool getLinesIntersection (const osg::Vec3f &La1, const osg::Vec3f &La2, const osg::Vec3f &Lb1, const osg::Vec3f &Lb2, osg::Vec3f &intersection)
 
static int getCanvasesIntersection (entity::Canvas *current, entity::Canvas *previous, osg::Vec3f &p1, osg::Vec3f &p2, osg::Vec3f &p3, osg::Vec3f &p4)
 
static int getPlanesIntersection (entity::Canvas *canvas1, entity::Canvas *canvas2, osg::Vec3f &iP, osg::Vec3f &u)
 
static osg::Vec3f projectPointOnLine (const osg::Vec3f &iP, const osg::Vec3f &u, const osg::Vec3f &P)
 
static double distanceTwoPoints (const osg::Vec3f &P1, const osg::Vec3f &P2)
 
static osg::Vec3f getAnchorLineSegment (const osg::Vec3f &P0, const osg::Vec3f &P1)
 
static QCursor getCursorFromMode (cher::MOUSE_MODE mode)
 
static bool getCameraPosition (entity::SVMData *svm, osg::Vec3f &eye, osg::Vec3f &center, osg::Vec3f &up)
 

Detailed Description

Some generic methods compiled into one class. Methods that describe:

Member Function Documentation

§ areStrokesProjectable()

bool Utilities::areStrokesProjectable ( const std::vector< entity::Stroke *> &  strokes,
entity::Canvas source,
entity::Canvas target,
osg::Camera *  camera 
)
static

A tester method in order to check if a set of strokes can be projected into a selected canvas under the given view point.

Parameters
strokesis the set of selected strokes
sourceis the Canvas which contains the set of strokes to project
targetis the Canvas on which the projection should be done
camerais the camera view true if all the strokes can be projected successfully.

§ distanceTwoPoints()

double Utilities::distanceTwoPoints ( const osg::Vec3f &  P1,
const osg::Vec3f &  P2 
)
static

A method to estimate Euclidean distance between two points in 3D.

Parameters
P1is the first 3D point.
P2is the second 3D point.
Returns
Euclidean distance according to https://en.wikipedia.org/wiki/Euclidean_distance

§ getAnchorLineSegment()

osg::Vec3f Utilities::getAnchorLineSegment ( const osg::Vec3f &  P0,
const osg::Vec3f &  P1 
)
static

A method to obtain coordinate of the second point of entity::LineSegment which is anchored to canvas' local u and v coordinates.

Parameters
canvasis the canvas within which the segment is drawn.
P0is the first point of segment,
P1is the second point on segment, which is a subject to change to the result point.
Returns
local anchored point.

§ getAngleTwoVectors()

double Utilities::getAngleTwoVectors ( const osg::Vec2f &  p1,
const osg::Vec2f &  p2,
const osg::Vec2f &  p3,
const osg::Vec2f &  p4 
)
static

A method which obtains an angle between two vectors in 2d. For more info, see: http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm .

Parameters
p1is the first point of the first vector.
p2is the second point of the first vector.
p3is the first point of the second vector.
p4is the second point of the second vector.
Returns
an angle between two vectors in radians.

§ getCameraPosition()

bool Utilities::getCameraPosition ( entity::SVMData svm,
osg::Vec3f &  eye,
osg::Vec3f &  center,
osg::Vec3f &  up 
)
static

A method to obtain camera pose given 4 intersecting rays (obtained from entity::SVMData). The algorithm is as follows: first, find 4 intersections between each neighboring rays (or use all possible pair?). Second, calculate the camera eye - average of the calculated four intersections. The camera's center vector passes through one of the wire's centers, and the up vector is always constant - (0,1,0).

Returns
true if the parameters were calculated successfully, false otherwise.

§ getCanvasesIntersection()

int Utilities::getCanvasesIntersection ( entity::Canvas current,
entity::Canvas previous,
osg::Vec3f &  p1,
osg::Vec3f &  p2,
osg::Vec3f &  p3,
osg::Vec3f &  p4 
)
static

A method to obtain intersection between two canvases (planes) so that to do projection on the intersection onto the second canvas.

Parameters
currentis the first canvas
previousis the second canvas (where the intersection will be cast on)
p1

§ getCursorFromMode()

QCursor Utilities::getCursorFromMode ( cher::MOUSE_MODE  mode)
static

UI method to obtain cursor data based on the given mouse mode.

§ getFarNear()

void Utilities::getFarNear ( double  x,
double  y,
const osg::Matrix &  invVPW,
osg::Vec3f &  near,
osg::Vec3f &  far 
)
static

A method to obtain far and near points of the screen point that cast a projection ray.

Parameters
x- x-coordinate of the screen
y- y-coordinate of the screen
invVPW- inverse matrix of View-Projection-World matrix
nearis the result 3D point on the near point on the cast ray
faris the result 3D point as the far point on the cast ray.
Returns
true if the points were obtained successfully.
See also
getViewProjectionWorld().

§ getGlobalFromLocal()

bool Utilities::getGlobalFromLocal ( const osg::Vec3f &  p,
const osg::Matrix &  M,
osg::Vec3f &  P 
)
static

A method which is inverse to the method getLocalFromGlobal().

See also
getModel(), getLocalFromGlobal().

§ getLinesIntersection()

bool Utilities::getLinesIntersection ( const osg::Vec3f &  La1,
const osg::Vec3f &  La2,
const osg::Vec3f &  Lb1,
const osg::Vec3f &  Lb2,
osg::Vec3f &  intersection 
)
static

A method to obtain an intersection between the two lines. Each line is presented by two points in 3D space. The algorithm treats the lines as skew and the intersection is calculated as average between two projections on each line. The projection between the skew lines is a shortest distance between the lines.

Parameters
La1is the first 3D point on first line.
La2is the second 3D point on first line.
Lb1is the first 3D point on second line.
Lb2is the second 3D point on second line.
intersectionis the result intersection.
Returns
true if the intersection calculation was successful.

§ getLocalFromGlobal()

bool Utilities::getLocalFromGlobal ( const osg::Vec3f &  P,
const osg::Matrix &  invM,
osg::Vec3f &  p 
)
static

A method to convert a global point into local system of coordinates.

Parameters
Pis the requested point to convert
invMis an inverted model matrix
pis the result 2D point (local system of coordinates).
Returns
true is derivation passed successfully.
See also
getModel(), getLocalFromGlobal()

§ getModel()

bool Utilities::getModel ( entity::Canvas canvas,
osg::Matrix &  M,
osg::Matrix &  invM 
)
static

A method to obtain model matrix (global to local conversion matrix) from a given canvas.

Parameters
canvasis the 2D plane canvas from which to derive the model matrix
Mis the result model matrix
invMis the result inverse of model matrix
Returns
true if model matrices were obtaibed successfully.

§ getOsgColor()

osg::Vec4f Utilities::getOsgColor ( const QColor &  color)
static

A method to convert a Qt color representation into an OSG.

See also
getQColor().

§ getPlanesIntersection()

int Utilities::getPlanesIntersection ( entity::Canvas canvas1,
entity::Canvas canvas2,
osg::Vec3f &  iP,
osg::Vec3f &  u 
)
static

A method to obtaib intersection between two planes. For more details on the algorithm, see: http://geomalgorithms.com/a05-_intersect-1.html

§ getQColor()

QColor Utilities::getQColor ( const osg::Vec4f &  color)
static

A method to convert an OSG color representation into a Qt

See also
getQColor().

§ getRayPlaneIntersection()

bool Utilities::getRayPlaneIntersection ( const osg::Plane &  plane,
const osg::Vec3f &  center,
const osg::Vec3f &  nearPoint,
const osg::Vec3f &  farPoint,
osg::Vec3f &  P,
bool  isLine = false 
)
static

A method to obtain intersection point between a given plane and a line (ray).

Parameters
planeis the given plane
centeris an arbitrary point on the plane that represents the plane's center (global coordinates).
nearPointis the 3D near point of the ray that was cast from a screen point
farPointis the 3D far point of the ray that was cast from a screen point
Pis the result point that represents intersection of the plane and a ray that is given by far and near points
isLineis boolean indicating whether we deal with ray (false) or line (true). Ray may not intersect the plane if both points lie above or below the plane.
Returns
true if the point was obtained without any errors
See also
getFarNear()

§ getSkewLinesDistance()

double Utilities::getSkewLinesDistance ( const osg::Vec3d &  r1,
const osg::Vec3d &  r2,
const osg::Vec3d &  v1,
const osg::Vec3d &  v2 
)
static

A method to obtain a distance between skew rays. For more info, see: https://en.wikipedia.org/wiki/Skew_lines

See also
getSkewLinesProjection()

§ getSkewLinesProjection()

bool Utilities::getSkewLinesProjection ( const osg::Vec3f &  center,
const osg::Vec3f &  farPoint,
const osg::Vec3f &  nearPoint,
const osg::Vec3f &  normal,
osg::Vec3f &  X1 
)
static

A method to obtain a distance between skew lines. For more info, see: http://www2.washjeff.edu/users/mwoltermann/Dorrie/69.pdf or here: http://paulbourke.net/geometry/pointlineplane/

Parameters
centeris the first point P1 (see notations in the link above)
farPointis to describe the line on which P1 lies
nearPointis the second point P2
normalis to describe the line on which P2 lies
X1is the projection point on first line onto second line
Returns
true if point was obtained successfully.
See also
getSkewLinesDistance()

§ getViewProjectionWorld()

bool Utilities::getViewProjectionWorld ( osgGA::GUIActionAdapter &  aa,
osg::Matrix &  VPW,
osg::Matrix &  invVPW 
)
static

A method to obtain two matrices - VPW and its invertse given the action adapter.

Parameters
aais OSG-based variable from which camera, view and other matrices can be derived.
VPWis the output View-Projection-World matrix
invVPWis the ourput inverse of View-Projection-World matrix.
Returns
true if both matrices were obtained without an error.

§ projectPointOnLine()

osg::Vec3f Utilities::projectPointOnLine ( const osg::Vec3f &  iP,
const osg::Vec3f &  u,
const osg::Vec3f &  P 
)
static

A method to project 3d point onto 3D line.

Parameters
iPis the global point on the line.
uis the vector defining the line direction.
Pis the point to project.
Returns
global coordinate of the projected point.

§ rotate2DPointAround()

osg::Vec3f Utilities::rotate2DPointAround ( const osg::Vec3f &  center,
float  theta,
const osg::Vec3f &  original 
)
static

A method to rotate a 2D point around another point on a specified angle. The input and output points have "local point" format: [u,v,0].

Parameters
centeris the point around which the rotation will be done.
thetais the angle of rotation in radians.
originalis the point to rotate.
Returns
the result rotated point.

The documentation for this class was generated from the following files: