|
|
/* 文件名:lib.h*/
|
|
|
#ifndef XJ_OSG_VIEW_H
|
|
|
#define XJ_OSG_VIEW_H
|
|
|
|
|
|
#include "XJObject.h"
|
|
|
#include "XJPoint2D.h"
|
|
|
#include "ViewExport.h"
|
|
|
#include "ViewCommon.h"
|
|
|
#include "OSGDef.h"
|
|
|
#include <string>
|
|
|
#include <vector>
|
|
|
#include <map>
|
|
|
|
|
|
class CRenderingThread;
|
|
|
class CXJPlane;
|
|
|
class CXJ2DLine;
|
|
|
class CXJ2DGeomCircle;
|
|
|
struct pickPoint2D;
|
|
|
struct pickPoint3D;
|
|
|
typedef unsigned int UINT;
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
//选择模式
|
|
|
enum eOsgPickMode
|
|
|
{
|
|
|
OSG_PICK_OBJECT = 0, //选择对象
|
|
|
OSG_PICK_POINT = 1 //选择点
|
|
|
};
|
|
|
|
|
|
class XJOSGVIEWEXPORT CXJOSGView
|
|
|
{
|
|
|
public:
|
|
|
CXJOSGView(void* hWnd, int index);
|
|
|
virtual ~CXJOSGView();
|
|
|
|
|
|
//初始化场景视图
|
|
|
void InitOSG(const std::string& bkgFile);
|
|
|
|
|
|
//开启渲染线程
|
|
|
void StartRenderingThread();
|
|
|
|
|
|
//前序更新
|
|
|
void PreFrameUpdate();
|
|
|
|
|
|
//后续更新
|
|
|
void PostFrameUpdate();
|
|
|
|
|
|
//申请场景的重绘
|
|
|
void RequestRedraw();
|
|
|
|
|
|
//设置渲染的最大帧数
|
|
|
void SetRunMaxFrameRate(double frameRate) {m_runMaxFrameRate = frameRate;}
|
|
|
double GetRunMaxFrameRate() {return m_runMaxFrameRate;}
|
|
|
|
|
|
//释放场景视图内存
|
|
|
int TerminateOSG();
|
|
|
|
|
|
//渲染视图
|
|
|
static void Render(void* ptr);
|
|
|
|
|
|
//根据传入的对象指针,来创建并更新视图对象,默认为更新对象的所有属性
|
|
|
int UpdateObjectView(CXJObject* obj, EOSGUpdateType updateType = UPDATE_ALL);
|
|
|
|
|
|
//添加UI模块中的操作事件, 都是派生自CXJMouseOperator类
|
|
|
void ActivateEventOperator(void* pEventOp);
|
|
|
void DeactiveEventOperator();
|
|
|
|
|
|
//显示文字轮廓
|
|
|
int UpdatePolyLineOnScreen(std::vector<std::vector<Point3D>>& polyline, Point3D curPoint);
|
|
|
|
|
|
//擦出文字轮廓
|
|
|
void ClearPolyLineOnScreen();
|
|
|
|
|
|
//设置投影视图(左、右视图等三视图)
|
|
|
void SetProjView(XJViewType viewType);
|
|
|
|
|
|
//设置投影视图(不缩放视图)
|
|
|
void SetProjViewNoZoom(XJViewType viewType);
|
|
|
|
|
|
//自适应视图
|
|
|
void ZoomView();
|
|
|
|
|
|
//移动视图
|
|
|
void SetViewPos(double px, double py, double scale);
|
|
|
|
|
|
//获取视图位置
|
|
|
void GetViewPos(Point2D& pt, double& scale);
|
|
|
|
|
|
//设置相机投影方式(正交投影,或者透视投影)
|
|
|
void StartOrthoProjection();
|
|
|
void StartPerspectProjection();
|
|
|
|
|
|
//获得选中对象的omkey容器
|
|
|
const std::vector<int>& GetSelOmKeyList();
|
|
|
|
|
|
/*******拾取视图对象接口*******/
|
|
|
|
|
|
//选中的对象的个数
|
|
|
int NbSelected();
|
|
|
|
|
|
//返回选中的对象的omkey
|
|
|
int SelectedObjOmKey(int index);
|
|
|
|
|
|
//返回拾取得到的网格交点,如果拾取成功,返回值为true
|
|
|
int PickedPoint(Point3D& interPt);
|
|
|
int PickedPoint(Point3D& interPt, Point3D& interNormal);
|
|
|
|
|
|
int PickedDir(Point3D& dir);
|
|
|
|
|
|
int PickedPoint2D(pickPoint2D& pp);
|
|
|
|
|
|
int PickedPoint3D(pickPoint3D& pp);
|
|
|
|
|
|
/****拾取视图对象操作*****/
|
|
|
//选择视图中的对象,默认形参为高亮
|
|
|
//返回值为对象的OMKey
|
|
|
int PickObject(int x, int y, bool hightlight = true, bool reverseY = false);
|
|
|
int PickedObject();
|
|
|
|
|
|
|
|
|
//点orgPoint被拖动到屏幕(corX,corY)坐标时的空间坐标
|
|
|
void DragPoint(const Point3D& orgPoint, int corX, int corY, Point3D& pt);
|
|
|
|
|
|
//拾取2维平面上的点
|
|
|
int Pick2DPoint(int x, int y, Point3D& pnt);
|
|
|
|
|
|
//设置视图对象拾取模式
|
|
|
void SetPickMode(int pickModel);
|
|
|
|
|
|
//根据拾取获得的osgKey来获得对于的对象的omkey
|
|
|
int GetOmKeyByOsgKey(int osgKey);
|
|
|
|
|
|
/**************在OSG视图上显示模型*****************************************/
|
|
|
|
|
|
//在屏幕上绘制多段线,不受相机操作器的旋转变化
|
|
|
int DrawPolylineOnWindow(std::vector<Point3D>& polyline);
|
|
|
int DrawPolylineOnMFCWindow(std::vector<Point3D>& polyline, int state=0);
|
|
|
//清除屏幕上绘制的多段线
|
|
|
int ClearPolylineOnWindow();
|
|
|
|
|
|
//在场景中绘制多段线,受相机操作器的旋转变化
|
|
|
int DrawPolylineOnSceneGraph(std::vector<Point3D>& polyline);
|
|
|
int ClearPolylineOnSceneGraph();
|
|
|
|
|
|
|
|
|
//在屏幕上绘制圆,指定圆心位置和半径,不受相机操作器的旋转变化
|
|
|
int DrawCircleOnWindow(int x, int y, float circleRad = 1.0);
|
|
|
|
|
|
//清除屏幕上绘制的圆
|
|
|
int ClearCircleOnWindow();
|
|
|
/***************在OSG视图上显示模型****************************************/
|
|
|
|
|
|
/****视图操作器功能接口****/
|
|
|
|
|
|
//判断osg是否拥有操作器事件
|
|
|
bool HasOperatorHandler();
|
|
|
|
|
|
//去处所有的操作事件
|
|
|
void OnNoSelectEvent();
|
|
|
|
|
|
//取消动态拾取对象的高亮加粗显示
|
|
|
void UnlightDynamicDetectedObject();
|
|
|
|
|
|
|
|
|
//使用相机平移操作器
|
|
|
void OnCameraPan();
|
|
|
|
|
|
//使用相机旋转操作器
|
|
|
void OnCameraOrbit();
|
|
|
|
|
|
//使用轨迹球操作器
|
|
|
void OnCameraTrackball();
|
|
|
|
|
|
//使用持续旋转轨迹球操作器
|
|
|
void OnCameraContinuousOrbit();
|
|
|
|
|
|
//使用固定轴来进行旋转
|
|
|
void OnCameraVerticalAxisOrbit();
|
|
|
|
|
|
//清空显示的标记
|
|
|
void ClearMarkUp();
|
|
|
|
|
|
|
|
|
//高亮对象
|
|
|
void HilightObject(int omkey);
|
|
|
void UnHilightObject(int omkey);
|
|
|
|
|
|
//选中指定key的显示对象,将其高亮
|
|
|
int SelectObject(int omkey);
|
|
|
|
|
|
//不高亮显示选择列表中的对象
|
|
|
void DeSelectSelList();
|
|
|
|
|
|
//将选中列表中的所有对象设为隐藏
|
|
|
void InvisibleSelList(bool visible);
|
|
|
|
|
|
//将选中列表中的所有对象设为透明
|
|
|
void TransparentSelList(bool transparent);
|
|
|
|
|
|
//将选中列表中的所有对象设为线框显示
|
|
|
void WireframeSelList(bool wireframe);
|
|
|
|
|
|
void SetPolygonOffsets(CXJObject* pobj, float aFactor, float aUnits);
|
|
|
|
|
|
//设置操作器是否可用
|
|
|
void SetViewManipulatorEnable(bool enable);
|
|
|
|
|
|
/*******模型拖动操作器*******/
|
|
|
//对象三维拖动器
|
|
|
void TranslateAxisDragger(CXJObject *obj);
|
|
|
//对象一维方向拖动器
|
|
|
void TranslateDirDragger(std::vector<CXJObject*> objList, Point3D dir);
|
|
|
//对象一维方向拖动并旋转
|
|
|
void TranslateDirAndRotateDragger(std::vector<CXJObject*> objList, Point3D dir);
|
|
|
|
|
|
//对象固定方向旋转拖动器
|
|
|
void RotateDirDragger( CXJObject *obj,Point3D dir );
|
|
|
|
|
|
void SetTranslationDraggerStep(double step);
|
|
|
//对象的轨迹球拖动器
|
|
|
void TrackBallDragger(CXJObject *obj);
|
|
|
void SetRotationDraggerStep(double step);
|
|
|
|
|
|
//对象的屏幕方向的拖动
|
|
|
void Translate2DDragger(CXJObject *obj);
|
|
|
|
|
|
//对象的屏幕方向的旋转
|
|
|
void TrackBall2DDragger(CXJObject* obj);
|
|
|
|
|
|
//对象按照给定坐标系方向来拖动
|
|
|
void TranslateLocalCordDragger(CXJObject* obj, const Point3D& localCorX, const Point3D& localCorY, const Point3D& localCorZ);
|
|
|
|
|
|
//对象按照给定坐标系方向来旋转
|
|
|
void TrackBallLocalCordDragger(CXJObject* obj, const Point3D& localCorX, const Point3D& localCorY, const Point3D& localCorZ);
|
|
|
|
|
|
void TransformObjectOnce(CXJObject* obj, Point3D originPt, Point3D oriVec, Point3D destVec);
|
|
|
|
|
|
//清除拖动操作器
|
|
|
void ClearDraggerObject();
|
|
|
|
|
|
//判断视图中是否已经存在拖动器
|
|
|
bool IsExistDragger();
|
|
|
|
|
|
|
|
|
|
|
|
//根据给定的参数来移动显示对象
|
|
|
void TranslateObject(CXJObject *obj, float x, float y, float z );
|
|
|
|
|
|
//根据给定的参数来旋转显示对象
|
|
|
void RotateObject(CXJObject* obj, Point3D basePt,Point3D dir,float angle);
|
|
|
|
|
|
//重设对象的显示位置
|
|
|
void ResetObjectViewPos(CXJObject* obj);
|
|
|
|
|
|
//获得显示对象拖动量
|
|
|
void GetObjectTranslation(CXJObject *obj, float &x, float &y, float &z);
|
|
|
|
|
|
void GetObjectRotation(CXJObject *obj, float &x, float &y, float &z,float &ang);
|
|
|
|
|
|
|
|
|
//获取屏幕上任一点在近平面上位置,及屏幕长度对应近平面上长度
|
|
|
void TranslatePointW2NP(Point3D& p, double& r);
|
|
|
void TranslatePointW2NFP(Point3D& p, Point3D& N, Point3D& F);
|
|
|
|
|
|
//将法矢转化为旋转轴和角度值
|
|
|
void ConvertDirToAngleAxis(const Point3D& dir, Point3D& rotAxis, double& angle);
|
|
|
|
|
|
bool MakeRotationByAxes(const Point3D& xdir, const Point3D& ydir, const Point3D& zdir,
|
|
|
Point3D& rotateAxis, double& angle, const char* priorityOrder = "ZXY");
|
|
|
|
|
|
//删除临时创建的多个偏移平面
|
|
|
void DeleteTempOffsetPlane();
|
|
|
|
|
|
void DeleteTempPattern2D();
|
|
|
|
|
|
/***********创建临时显示对象*************/
|
|
|
//显示选择的高亮点
|
|
|
void ShowSelPt(Point3D &pt);
|
|
|
|
|
|
//清除选中的高亮点
|
|
|
void ClearSelPt();
|
|
|
|
|
|
//创建样条线的临时显示点对象
|
|
|
int CreateTempObject(CXJObject* obj);
|
|
|
|
|
|
//清空样条线上的高亮插值点
|
|
|
int DeleteTempObject();
|
|
|
|
|
|
void DeleteTempObject(const CXJObject* pobj);
|
|
|
|
|
|
//显示点集
|
|
|
void ShowPointSet(const vector<Point3D>& pts);
|
|
|
//清空点集
|
|
|
void ClearPointSet();
|
|
|
|
|
|
//显示直线集
|
|
|
void ShowLineSet(const vector<Point3D>& pts);
|
|
|
//清除直线集
|
|
|
void ClearLineSet();
|
|
|
|
|
|
//将空间点转化为屏幕上的坐标点
|
|
|
void ProjectObjectToWindow(const Point3D& pt, int& x, int& y );
|
|
|
|
|
|
|
|
|
/*****************相机操作****************************/
|
|
|
//获得相机的位置,目标点位置和相机朝向
|
|
|
void GetCameraLookAt(Point3D& eye, Point3D& target, Point3D& up) const;
|
|
|
|
|
|
//获得相机朝向和向上方向
|
|
|
void GetCameraLookAt(Point3D& CameraNormal,Point3D& CameraUp) const;
|
|
|
|
|
|
Point3D GetCameraNormal() const;
|
|
|
Point3D GetCameraUp() const ;
|
|
|
|
|
|
//设置相机的位置,目标点位置和相机朝向
|
|
|
void SetCameraLookAt(Point3D a_normal,Point3D a_up);
|
|
|
|
|
|
void SetCameraLookAt(const Point3D& eye, const Point3D& target, const Point3D& up);
|
|
|
|
|
|
//设置背景图片的存储路径
|
|
|
void SetBackGroudBmpPath(const std::string& path);
|
|
|
void SetBackGroudColor(int r, int g, int b, float a);
|
|
|
|
|
|
//使用osg来获得平面与网格的交点
|
|
|
int GetPlaneMeshIntersection(CXJObject* pobj, double plnDir[3],double plnPoint[3], std::vector<std::vector<Point3D>>& pnts,int& PolygonNum );
|
|
|
|
|
|
//删除所有的osg对象
|
|
|
void DeleteAllOSGObjects();
|
|
|
|
|
|
//设置分割后的模型显示在前端
|
|
|
void setModelShowInFront(CXJObject* pobj);
|
|
|
|
|
|
//设置视图三个角上的Text, displayPos为显示文字位置,alignment表示文字对齐方式
|
|
|
void setHUDText(wchar_t* str, HUDTextWinPos displayPos = WINDOW_LEFT_TOP_POS, AlignmentType alighment = BASE_LINE_ALIGNMENT);
|
|
|
|
|
|
//设置text的属性值,包括大小,颜色,字体等
|
|
|
void setHUDTextProperties(float textSize, COLORREF textColor, std::string& font);
|
|
|
|
|
|
//获得直线与显示对象的交点
|
|
|
int GetIntersectPt(CXJObject* pobj, const Point3D& start, Point3D& lineDir, Point3D& intersectPt);
|
|
|
|
|
|
//用于自定义图片来设置视图背景
|
|
|
bool setPictureOnBackGround(const std::string& picPath);
|
|
|
|
|
|
//设置默认背景图片
|
|
|
void setDefaultBackGround();
|
|
|
|
|
|
//进行osg中的事件操作
|
|
|
void runEventHandle();
|
|
|
|
|
|
void* GetOSGInternal();
|
|
|
|
|
|
void DrawImage(std::string path);
|
|
|
|
|
|
void TakeObjectPicture(const std::vector<CXJObject*>& objList, std::string path,
|
|
|
Point3D eye,
|
|
|
Point3D dir,
|
|
|
Point3D up,
|
|
|
double rad,
|
|
|
int w=500, int h=500);
|
|
|
|
|
|
void EnablePickZValue(CXJObject* pobj, bool bEnable = true);
|
|
|
|
|
|
void EnableOpDrawPolygon(bool bEnable = true);
|
|
|
void GetOpDrawPolygon(std::vector<Point2D>& polygen);
|
|
|
|
|
|
void EnableAntiAliasing(bool bEnable);
|
|
|
|
|
|
//显示联动鼠标
|
|
|
void ShowMouse(int px, int py);
|
|
|
void GetMousePos(int& px, int& py);
|
|
|
private:
|
|
|
void * m_osgInternal;
|
|
|
void * m_hWnd;
|
|
|
int m_osgIndex;
|
|
|
double m_runMaxFrameRate;
|
|
|
CRenderingThread* m_ThreadHandle;
|
|
|
};
|
|
|
|
|
|
#endif |