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.
78 lines
2.8 KiB
C++
78 lines
2.8 KiB
C++
#ifndef NMVTKPLANARPOLYGONINTERACTORSTYLE_H
|
|
#define NMVTKPLANARPOLYGONINTERACTORSTYLE_H
|
|
|
|
#include "nmRender_global.h"
|
|
|
|
#include <QPointF>
|
|
#include <QVector>
|
|
|
|
#include <vtkCommand.h>
|
|
#include <vtkInteractorStyle.h>
|
|
|
|
/**
|
|
* @brief 在世界坐标 Z=0 平面逐点绘制多边形的临时 VTK 交互样式。
|
|
*
|
|
* 本类不持有任何业务窗口或渲染图层。调用方通过 VTK Observer 监听点集变化、
|
|
* 完成、取消和无效完成事件,并在回调中复制当前点集。样式不修改相机。
|
|
*/
|
|
class NM_RENDER_EXPORT nmVTKPlanarPolygonInteractorStyle
|
|
: public vtkInteractorStyle
|
|
{
|
|
public:
|
|
static nmVTKPlanarPolygonInteractorStyle* New();
|
|
vtkTypeMacro(nmVTKPlanarPolygonInteractorStyle, vtkInteractorStyle);
|
|
|
|
enum InteractionEvent
|
|
{
|
|
PolygonChangedEvent = vtkCommand::UserEvent + 310,
|
|
PolygonCompletedEvent,
|
|
PolygonCancelledEvent,
|
|
PolygonInvalidEvent
|
|
};
|
|
|
|
/** @brief 左键添加点;双击的第二次按下尝试完成当前多边形。 */
|
|
virtual void OnLeftButtonDown();
|
|
/** @brief 右键取消当前绘制。 */
|
|
virtual void OnRightButtonDown();
|
|
/** @brief Enter 完成、Backspace 撤销、Esc 取消。 */
|
|
virtual void OnKeyPress();
|
|
/** @brief 绘制期间屏蔽基类的退出、复位和拾取字符快捷键。 */
|
|
virtual void OnChar();
|
|
|
|
/** @brief 清空节点并恢复未完成状态,不发出事件且不主动 Render。 */
|
|
void reset();
|
|
/** @brief 复制当前按绘制顺序保存的世界坐标点。 */
|
|
QVector<QPointF> getPoints() const;
|
|
/** @brief 返回当前点数。 */
|
|
int getPointCount() const;
|
|
/** @brief 返回是否已经成功发出完成事件。 */
|
|
bool isCompleted() const;
|
|
|
|
protected:
|
|
nmVTKPlanarPolygonInteractorStyle();
|
|
virtual ~nmVTKPlanarPolygonInteractorStyle();
|
|
|
|
private:
|
|
nmVTKPlanarPolygonInteractorStyle(
|
|
const nmVTKPlanarPolygonInteractorStyle&);
|
|
void operator=(const nmVTKPlanarPolygonInteractorStyle&);
|
|
|
|
/** @brief 把当前显示坐标射线与 Z=0 平面求交。 */
|
|
bool projectEventPositionToPlane(QPointF& oPoint);
|
|
/** @brief 添加非重复有限点并同步发出变化事件。 */
|
|
bool appendCurrentPoint();
|
|
/** @brief 校验点数和面积,成功后依次发出变化及完成事件。 */
|
|
bool completePolygon();
|
|
/** @brief 撤销最后一个点并发出变化事件。 */
|
|
void removeLastPoint();
|
|
/** @brief 发出取消事件;点集保留到调用方回调结束。 */
|
|
void cancelPolygon();
|
|
/** @brief 请求 Interactor 重绘当前视图。 */
|
|
void renderInteractor();
|
|
|
|
QVector<QPointF> m_vecPoints; ///< 当前候选多边形世界坐标。
|
|
bool m_bCompleted; ///< 成功完成后阻止重复输入。
|
|
};
|
|
|
|
#endif // NMVTKPLANARPOLYGONINTERACTORSTYLE_H
|