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.
nmWTAI-Platform/Include/nmNum/nmRender/nmVTKScalarBarLayer.h

108 lines
5.0 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.

#ifndef NMVTKSCALARBARLAYER_H
#define NMVTKSCALARBARLAYER_H
#include "nmVTKRenderLayer.h"
#include <vtkSmartPointer.h>
class vtkActor2D;
class vtkLookupTable;
class vtkPoints;
class vtkPropAssembly;
class vtkScalarBarActor;
class vtkTextActor;
/**
* @brief 通用色标图层。
*
* 色标只展示外部 LookupTable,不解析单位,也不自行计算数据范围。
*/
class NM_RENDER_EXPORT nmVTKScalarBarLayer : public nmVTKRenderLayer
{
public:
/** @brief 创建空色标,并将色标及独立二维装饰加入稳定根 Assembly。 */
explicit nmVTKScalarBarLayer(const QString& sLayerId);
/** @brief 先解除 Renderer,再释放外部颜色表的共享引用。 */
virtual ~nmVTKScalarBarLayer();
/** @brief 共享外部 LookupTable 的 VTK 引用。 */
void setLookupTable(vtkLookupTable* pLookupTable);
/** @brief 返回当前共享颜色表的非所有权指针。 */
vtkLookupTable* getLookupTable() const;
/** @brief 使用 UTF-8 设置色标标题,不解释标题中的业务含义。 */
void setTitle(const QString& sTitle);
/** @brief 返回调用方设置的标题。 */
QString getTitle() const;
/** @brief 设置普通刻度格式,例如 %.6g;空格式返回 false。 */
bool setLabelFormat(const QString& sFormat);
/** @brief 返回调用方最后设置的普通刻度格式。 */
QString getLabelFormat() const;
/** @brief 设置 0~64 个普通刻度;常量色标使用 0。 */
bool setNumberOfLabels(int nLabelCount);
/** @brief 返回当前普通刻度数量。 */
int getNumberOfLabels() const;
/**
* @brief 按 QVTK 视口像素尺寸更新固定宽度的响应式二维布局。
* @note 只修改 Actor 布局,不主动 Render,也不修改 LookupTable。
*/
bool setViewportSize(int nWidth, int nHeight);
/** @brief 返回当前视口和色带高度建议使用的普通刻度数量。 */
int getResponsiveLabelCount() const;
/** @brief 配置低于显示范围的独立二维色块和说明文字。 */
void setBelowRangeSwatch(bool bVisible, const QString& sText);
/** @brief 配置高于显示范围的独立二维色块和说明文字。 */
void setAboveRangeSwatch(bool bVisible, const QString& sText);
/**
* @brief 显示或隐藏常量属性的唯一业务值。
*
* 该文字由独立 vtkTextActor 绘制,不启用共享 LUT 的 IndexedLookup,
* 因而不会改变网格使用的连续颜色映射语义。
*/
void setConstantValueLabel(bool bVisible, const QString& sText);
/** @brief 设置归一化视口坐标中的左下角位置。 */
bool setPosition(double dX, double dY);
/** @brief 设置归一化视口坐标中的宽度和高度。 */
bool setSize(double dWidth, double dHeight);
/** @brief 返回图层持有的 vtkScalarBarActor 非所有权指针。 */
vtkScalarBarActor* getActor() const;
private:
Q_DISABLE_COPY(nmVTKScalarBarLayer)
/** @brief 根据当前色标位置和尺寸同步全部独立二维装饰的位置。 */
void updateOverlayLayout();
/** @brief 从活动 LookupTable 同步上下越界色块的实际颜色。 */
void updateRangeSwatchColors();
vtkSmartPointer<vtkLookupTable> m_pLookupTable; ///< 共享外部颜色表引用。
vtkSmartPointer<vtkPropAssembly> m_pRootAssembly; ///< Scene 挂载的稳定根 Prop。
vtkSmartPointer<vtkScalarBarActor> m_pActor; ///< 图层独占的二维色标 Actor。
vtkSmartPointer<vtkTextActor> m_pTitleActor; ///< 独立左对齐 ASCII 标题。
vtkSmartPointer<vtkTextActor> m_pConstantValueActor; ///< 常量属性唯一值文字。
vtkSmartPointer<vtkPoints> m_pBelowRangeSwatchPoints; ///< 下越界色块四角坐标。
vtkSmartPointer<vtkActor2D> m_pBelowRangeSwatchActor; ///< 下越界独立色块。
vtkSmartPointer<vtkTextActor> m_pBelowRangeTextActor; ///< 下越界说明文字。
vtkSmartPointer<vtkPoints> m_pAboveRangeSwatchPoints; ///< 上越界色块四角坐标。
vtkSmartPointer<vtkActor2D> m_pAboveRangeSwatchActor; ///< 上越界独立色块。
vtkSmartPointer<vtkTextActor> m_pAboveRangeTextActor; ///< 上越界说明文字。
QString m_sTitle; ///< 保留无损 Qt 标题,避免从 VTK 窄字符串反向解析。
QString m_sLabelFormat; ///< 普通刻度的 printf 风格格式字符串。
QString m_sConstantValueText; ///< 保留常量值文字,避免从 VTK 反向解析。
QString m_sBelowRangeText; ///< 下越界说明文字状态。
QString m_sAboveRangeText; ///< 上越界说明文字状态。
double m_dPositionX; ///< 色标左下角的归一化视口 X 坐标。
double m_dPositionY; ///< 色标左下角的归一化视口 Y 坐标。
double m_dWidth; ///< 色标在归一化视口中的宽度。
double m_dHeight; ///< 色标在归一化视口中的高度。
int m_nViewportWidth; ///< 最近一次有效 QVTK 视口像素宽度。
int m_nViewportHeight; ///< 最近一次有效 QVTK 视口像素高度。
};
#endif // NMVTKSCALARBARLAYER_H