You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlow/FITK_Component/FITKRenderWindowVTK/FITKGraph3DWindowVTK.h

561 lines
18 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
*
* @file FITKGraph3DWindow.h
* @brief 三维渲染窗口接口声明
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*
*/
#ifndef _FITKGraph3D_H_VTK_
#define _FITKGraph3D_H_VTK_
#include "FITKRenderWindowVTKAPI.h"
#include "FITKGraph3DWindowInterface.h"
#include "FITK_Kernel/FITKCore/FITKAbstractGraphWidget.h"
#include <QWidget>
#include <QMutex>
#include <QVariant>
class vtkRenderWindow;
class vtkCamera;
class vtkRenderWindowInteractor;
class vtkOrientationMarkerWidget;
class vtkActor;
class vtkRenderer;
class QGridLayout;
class QToolBar;
class FITKLegendScaleActor;
namespace Ui
{
class FITKGraph3DWindowVTK;
}
namespace Comp
{
class FITKGraphRender;
class FITKGraphObjectVTK;
class FITKGraphInteractionStyle;
class FITKBoundaryActor;
class Graph3DWindowInitializer;
/**
* @brief 三维渲染窗口toolbar位置枚举
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-05
*/
enum class FITKGraphWinToolBarPos
{
FITKLeftTop = 1, ///1左侧顶部
FITKLeftCenter, ///2左侧中部
FITKLeftBottom, ///3左侧底部
FITKBottomCenter, ///4底部中间
FITKRightBottom, ///5右侧底部
FITKRightCenter, ///6右侧中部
FITKRightTop, ///7右侧顶部
FITKTopCenter, ///8顶部中间
};
/**
* @brief 三维渲染窗口接口声明
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
class FITKRenderWindowVTKAPI FITKGraph3DWindowVTK
: public Core::FITKAbstractGraph3DWidget
{
Q_OBJECT;
public:
/**
* @brief Construct a new FITKGraph3DWindow object
* @param[i] info 渲染窗口信息
* @param[i] gInterface 渲染窗口对应接口类
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
FITKGraph3DWindowVTK(Graph3DWindowInitializer * initializer);
/**
* @brief Destroy the FITKGraph3DWindow object
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
virtual ~FITKGraph3DWindowVTK();
/**
* @brief 强制刷新
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
void reRender();
/**
* @brief 设置坐标系状态
* @param[i] state ture显示false隐藏
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
void setAxesEnable(bool state);
/**
* @brief 设置相机视角
* @param[i] focalPoint 相机焦点三坐标
* @param[i] viewUp 相机向上方向三坐标
* @param[i] position 相机位置三坐标
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
void setView(double* focalPoint, double* viewUp, double* position) override;
/**
* @brief 获取当前相机视角
* @param[o] pos 相机位置三坐标
* @param[o] focual 相机焦点三坐标
* @param[o] viewup 相机向上方向三坐标
* @return true 获取成功
* @return false 获取失败
* @author BaGuijun (baguijun@163.com)
* @date 2024-04-08
*/
bool getView(double* pos, double* focual, double* viewup) override;
/**
* @brief 添加渲染对象
* @param[i] index 渲染图层索引值
* @param[i] object 渲染对象
* @param[i] fitview 是否自适应(仅在窗口为空时生效)
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
void addObject(int index, FITKGraphObjectVTK* object, bool fitview = true);
/**
* @brief 清空所有显示对象(不删除对象)
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-28
*/
void clear() override;
/**
* @brief 设置渲染图层背景颜色
* @param[i] topValue 顶部颜色
* @param[i] bottomValue 底部颜色
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
void setBackground(double topValue[3],double bottomValue[3]);
/**
* @brief 自适应对象大小
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
void fitView() override;
/**
* @brief 强制刷新窗口
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-17
*/
virtual void flush() override;
/**
* @brief 设置背景颜色
* @param[i] rgb1 顶部颜色
* @param[i] rgb2 底部颜色
* @author libaojun (libaojunqd@foxmail.com)
* @date 2024-05-08
*/
virtual void setBackgroundColor(float* rgb1, float* rgb2 =nullptr) override;
/**
* @brief 获取背景颜色
* @param[o] rgb1 顶部颜色
* @param[o] rgb2 底部颜色
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
virtual void getBackgroundColor(float* rgb1, float* rgb2 = nullptr) override;
/**
* @brief 根据索引获取渲染图层
* @param[i] index 渲染图层索引值
* @return FITKGraphRender*
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-19
*/
FITKGraphRender* getRenderer(int index);
/**
* @brief 获取渲染图层数目
* @return int
* @author libaojun (libaojunqd@foxmail.com)
* @date 2024-04-17
*/
int getRenderCount();
/**
* @brief 获取vtk渲染窗口
* @return int
* @author libaojun (libaojunqd@foxmail.com)
* @date 2024-04-17
*/
vtkRenderWindow* getVTKRenderWindow();
/**
* @brief 获取三维窗口相机。
* @return 相机
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-17
*/
vtkCamera* getVTKCamera();
/**
* @brief 获取三维渲染器。
* @return 渲染器索引(-1代表最后一个[默认值]
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-17
*/
vtkRenderer* getVTKRenderer(int index = -1);
/**
* @brief 设置是否平行投影
* @param[i] enable 是否激活
* @author BaGuijun (baguijun@163.com)
* @date 2024-04-08
*/
virtual void setParallelProjection(bool on = true) override;
/**
* @brief 从渲染窗口移除渲染对象
* @param[i] FITKAbstractGraphObject 移除的渲染对象
* @author libaojun (libaojunqd@foxmail.com)
* @date 2024-04-11
*/
void removeGraphObj(Core::FITKAbstractGraphObject* gobj) override;
/**
* @brief 获取渲染对象数量
* @return int
* @author libaojun (libaojunqd@foxmail.com)
* @date 2024-04-26
*/
int getGraphObjCount();
/**
* @brief 获取渲染对象中心
* @param[o] center[3] 渲染对象中心
* @return bool
* @author libaojun (libaojunqd@foxmail.com)
* @date 2024-04-26
*/
bool getGraphObjCenter(double* center);
/**
* @brief 设置用户自定义信息。[模板]
* @param info窗口信息可以传入结构体或指针
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-11
*/
template<class T>
void setUserInformation(T info)
{
m_userInfo = QVariant::fromValue(info);
}
/**
* @brief 获取用户自定义信息。[模板]
* @return 窗口信息(支持结构体或指针)
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-11
*/
template<class T>
T getUserInformationAs()
{
return m_userInfo.value<T>();
}
/**
* @brief 设置用户自定义信息。
* @param info窗口信息可以传入结构体或指针
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-11
*/
void setUserInformation(QVariant info);
/**
* @brief 获取用户自定义信息。
* @return 窗口信息(支持结构体或指针)
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-11
*/
QVariant getUserInformation();
/**
* @brief 保存当前渲染窗口为图片
* @param[i] image 图片路径
* @param[i] w 图片宽度
* @param[i] h 图片高度
* @author BaGuijun (baguijun@163.com)
* @date 2024-05-28
*/
virtual void saveImage(const QString& image, int w = -1, int h = -1)override;
/**
* @brief 显示/隐藏比例尺图例。
* @param visibility可见性
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-29
*/
void showScaleLegend(bool visibility);
/**
* @brief 渲染窗口工具栏中添加action
* @param[i] actions action列表
* @param[i] beforeActions 插入action的位置
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-04
*/
void addActionsToolBar(QList<QAction*> actions, QAction* beforeAction = nullptr);
/**
* @brief 设置工具栏位置
* @param[i] pos 工具栏位置
* 1左顶 2左中 3左底 4底部 5右底 6右中 7右上 8顶部
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-04
*/
void setToolBarPos(FITKGraphWinToolBarPos pos);
/**
* @brief 设置渲染窗口的图标(可多次调用切换图标与图标位置)
* 图标的位置只在左侧顶部、左侧底部、右侧底部、右侧顶部有效
* @param[i] iconPath 图片路径
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-05
*/
void initRenderIcon(const QPixmap& image, FITKGraphWinToolBarPos pos = FITKGraphWinToolBarPos::FITKRightTop);
/**
* @brief 获取渲染窗口中默认的actions
* @return QList<QAction*> actio列表
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
QList<QAction*> getActions();
/**
* @brief 设置渲染窗口中的action是否显示
* @param[i] isShow 是否显示
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
void setIsShowActions(bool isShow);
public slots:
;
/**
* @brief 前视角按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewFrontEvent();
/**
* @brief 后视角按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewBackEvent();
/**
* @brief 顶部视角按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewTopEvent();
/**
* @brief 底部视角按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewBottomEvent();
/**
* @brief 左视角按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewLeftEvent();
/**
* @brief 右视角按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewRightEvent();
/**
* @brief 正视角按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewIsoEvent();
/**
* @brief 自适应按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewPanEvent();
/**
* @brief 保存图片按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionSaveImageEvent();
/**
* @brief 平行投影按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewParallelEvent();
/**
* @brief 正交投影按钮事件
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-13
*/
virtual void slotActionViewPerspectiveEvent();
protected:
/**
* @brief 渲染窗口初始化
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
virtual void init();
/**
* @brief 渲染窗口action初始化
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-14
*/
virtual void initActions();
/**
* @brief 设置交互器
* @param[i] style 交互器对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
void setInteractionStyle(FITKGraphInteractionStyle* style);
/**
* @brief 初始化显示属性。
* @param event
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-28
*/
virtual void showEvent(QShowEvent* event) override;
/**
* @brief 刷新边界演员包围盒。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-07-11
*/
void updateBoundray();
protected:
/**
* @brief 渲染窗口信息对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
Graph3DWindowInitializer* _initializer{};
/**
* @brief 三维渲染界面对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-11
*/
Ui::FITKGraph3DWindowVTK* m_ui = nullptr;
/**
* @brief VTK界面
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-11
*/
QWidget* m_vtkWidget = nullptr;
/**
* @brief 三维比例尺。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-28
*/
FITKLegendScaleActor* m_legendScaleActor{ nullptr };
/**
* @brief 三维渲染交互器对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-11
*/
vtkRenderWindowInteractor* m_interactor = nullptr;
/**
* @brief 三维渲染窗口对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-11
*/
//#if VTK_MAJOR_VERSION >= 8
vtkRenderWindow* m_renderWindow = nullptr;
//#else
// vtkGenericOpenGLRenderWindow* m_renderWindow = nullptr;
//#endif
/**
* @brief 三维渲染相机对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-11
*/
vtkCamera* m_camera = nullptr;
/**
* @brief 三维渲染坐标系对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-11
*/
vtkOrientationMarkerWidget* m_axesWidget = nullptr;
/**
* @brief 三维渲染图层链表
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-11
*/
QHash<int, FITKGraphRender*> m_renders = {};
/**
* @brief 交互器对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
FITKGraphInteractionStyle* m_interactionStyle = nullptr;
/**
* @brief 渲染窗口边界对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
FITKBoundaryActor* m_actorBound = nullptr;
/**
* @brief 用户自定义数据。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-11
*/
QVariant m_userInfo;
/**
* @brief 窗口是否初始化。适应低版本VTK在showEvent内对某些演员与视角进行初始化与刷新
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-05-29
*/
bool m_initFlag = false;
/**
* @brief 渲染窗口布局对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
QGridLayout* _renderToolBarLayout = nullptr;
/**
* @brief 渲染窗口工具栏对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
QToolBar* _renderToolBar = nullptr;
/**
* @brief 渲染窗口图标工具栏对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
QToolBar* _renderIconToolBar = nullptr;
/**
* @brief 渲染窗口布局类型
* @author BaGuijun (baguijun@163.com)
* @date 2024-03-18
*/
FITKGraphWinToolBarPos _renderBarStyle = FITKGraphWinToolBarPos::FITKLeftTop;
private:
/**
* @brief 互斥锁对象
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-06
*/
static QMutex _mutex;
};
}
#endif