cherish
Utilities.h
1 #ifndef UTILITIES_H
2 #define UTILITIES_H
3 
4 #include <vector>
5 
6 #include <QColor>
7 #include <QCursor>
8 
9 #include <osgGA/GUIEventAdapter>
10 #include <osgViewer/View>
11 #include <osg/Camera>
12 #include <osg/Plane>
13 #include <osg/Matrixd>
14 
15 #include "Canvas.h"
16 #include "Stroke.h"
17 #include "SVMData.h"
18 #include "DraggableWire.h"
19 
28 class Utilities
29 {
30 public:
33  static QColor getQColor(const osg::Vec4f& color);
34 
37  static osg::Vec4f getOsgColor(const QColor& color);
38 
45  static bool areStrokesProjectable(const std::vector<entity::Stroke *> &strokes, entity::Canvas *source, entity::Canvas *target, osg::Camera* camera);
46 
52  static bool getViewProjectionWorld(osgGA::GUIActionAdapter& aa,
53  osg::Matrix& VPW, osg::Matrix& invVPW);
54 
63  static void getFarNear(double x, double y, const osg::Matrix& invVPW,
64  osg::Vec3f& near, osg::Vec3f& far);
65 
76  static bool getRayPlaneIntersection(const osg::Plane& plane, const osg::Vec3f& center,
77  const osg::Vec3f& nearPoint, const osg::Vec3f& farPoint, osg::Vec3f& P, bool isLine = false);
78 
84  static bool getModel(entity::Canvas* canvas, osg::Matrix& M, osg::Matrix& invM);
85 
92  static bool getLocalFromGlobal(const osg::Vec3f& P,const osg::Matrix& invM, osg::Vec3f& p);
93 
96  static bool getGlobalFromLocal(const osg::Vec3f& p, const osg::Matrix& M, osg::Vec3f& P);
97 
105  static double getAngleTwoVectors(const osg::Vec2f& p1, const osg::Vec2f& p2, const osg::Vec2f& p3, const osg::Vec2f& p4);
106 
113  static osg::Vec3f rotate2DPointAround(const osg::Vec3f& center, float theta, const osg::Vec3f& original);
114 
115  /* algorithm for distance between skew lines:
116  *
117  * For two points P1 and P2 on skew lines;
118  * and d - the direction vector from P1 to P2;
119  * u1 and u2 - unit direction vectors for the lines
120  */
130  static bool getSkewLinesProjection(const osg::Vec3f& center,
131  const osg::Vec3f& farPoint, const osg::Vec3f& nearPoint,
132  const osg::Vec3f& normal, osg::Vec3f& X1);
133 
134 
137  static double getSkewLinesDistance(const osg::Vec3d &r1, const osg::Vec3d &r2,
138  const osg::Vec3d &v1, const osg::Vec3d &v2);
139 
151  static bool getLinesIntersection(const osg::Vec3f& La1, const osg::Vec3f& La2, const osg::Vec3f& Lb1, const osg::Vec3f& Lb2,
152  osg::Vec3f& intersection);
153 
154 
161  static int getCanvasesIntersection(entity::Canvas* current, entity::Canvas* previous,
162  osg::Vec3f& p1, osg::Vec3f& p2, osg::Vec3f& p3, osg::Vec3f& p4);
163 
165  static int getPlanesIntersection(entity::Canvas* canvas1, entity::Canvas* canvas2, osg::Vec3f& iP, osg::Vec3f& u);
166 
172  static osg::Vec3f projectPointOnLine(const osg::Vec3f& iP, const osg::Vec3f& u, const osg::Vec3f& P);
173 
178  static double distanceTwoPoints(const osg::Vec3f& P1, const osg::Vec3f& P2);
179 
186  static osg::Vec3f getAnchorLineSegment(const osg::Vec3f& P0, const osg::Vec3f& P1);
187 
189  static QCursor getCursorFromMode(cher::MOUSE_MODE mode);
190 
196  static bool getCameraPosition(entity::SVMData* svm, osg::Vec3f& eye, osg::Vec3f& center, osg::Vec3f& up);
197 
206 // static bool getProjectionMatrix(entity::SVMData* svm, osg::Matrixd &projection);
207 };
208 
209 #endif // UTILITIES_H
Some generic methods compiled into one class. Methods that describe:
Definition: Utilities.h:28
static bool getViewProjectionWorld(osgGA::GUIActionAdapter &aa, osg::Matrix &VPW, osg::Matrix &invVPW)
Definition: Utilities.cpp:98
static osg::Vec4f getOsgColor(const QColor &color)
Definition: Utilities.cpp:18
Definition: SVMData.h:22
static osg::Vec3f rotate2DPointAround(const osg::Vec3f &center, float theta, const osg::Vec3f &original)
Definition: Utilities.cpp:221
Definition: Canvas.h:31
static bool getCameraPosition(entity::SVMData *svm, osg::Vec3f &eye, osg::Vec3f &center, osg::Vec3f &up)
Definition: Utilities.cpp:589
static QColor getQColor(const osg::Vec4f &color)
Definition: Utilities.cpp:13
static int getPlanesIntersection(entity::Canvas *canvas1, entity::Canvas *canvas2, osg::Vec3f &iP, osg::Vec3f &u)
Definition: Utilities.cpp:390
static double distanceTwoPoints(const osg::Vec3f &P1, const osg::Vec3f &P2)
Definition: Utilities.cpp:459
static double getSkewLinesDistance(const osg::Vec3d &r1, const osg::Vec3d &r2, const osg::Vec3d &v1, const osg::Vec3d &v2)
Definition: Utilities.cpp:271
static void getFarNear(double x, double y, const osg::Matrix &invVPW, osg::Vec3f &near, osg::Vec3f &far)
Definition: Utilities.cpp:129
static double getAngleTwoVectors(const osg::Vec2f &p1, const osg::Vec2f &p2, const osg::Vec2f &p3, const osg::Vec2f &p4)
Definition: Utilities.cpp:209
static bool getLinesIntersection(const osg::Vec3f &La1, const osg::Vec3f &La2, const osg::Vec3f &Lb1, const osg::Vec3f &Lb2, osg::Vec3f &intersection)
Definition: Utilities.cpp:282
MOUSE_MODE
Definition: Settings.h:97
static bool getLocalFromGlobal(const osg::Vec3f &P, const osg::Matrix &invM, osg::Vec3f &p)
Definition: Utilities.cpp:188
static bool areStrokesProjectable(const std::vector< entity::Stroke *> &strokes, entity::Canvas *source, entity::Canvas *target, osg::Camera *camera)
Definition: Utilities.cpp:26
static bool getModel(entity::Canvas *canvas, osg::Matrix &M, osg::Matrix &invM)
Definition: Utilities.cpp:171
static osg::Vec3f getAnchorLineSegment(const osg::Vec3f &P0, const osg::Vec3f &P1)
Definition: Utilities.cpp:467
static int getCanvasesIntersection(entity::Canvas *current, entity::Canvas *previous, osg::Vec3f &p1, osg::Vec3f &p2, osg::Vec3f &p3, osg::Vec3f &p4)
Definition: Utilities.cpp:350
static QCursor getCursorFromMode(cher::MOUSE_MODE mode)
Definition: Utilities.cpp:484
static osg::Vec3f projectPointOnLine(const osg::Vec3f &iP, const osg::Vec3f &u, const osg::Vec3f &P)
Definition: Utilities.cpp:454
static bool getSkewLinesProjection(const osg::Vec3f &center, const osg::Vec3f &farPoint, const osg::Vec3f &nearPoint, const osg::Vec3f &normal, osg::Vec3f &X1)
Definition: Utilities.cpp:233
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)
Definition: Utilities.cpp:135
static bool getGlobalFromLocal(const osg::Vec3f &p, const osg::Matrix &M, osg::Vec3f &P)
Definition: Utilities.cpp:199