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

92 lines
4.0 KiB
C

#ifndef NMVTKSCALARBARLAYER_H
#define NMVTKSCALARBARLAYER_H
#include "nmVTKRenderLayer.h"
#include <vtkSmartPointer.h>
class vtkLookupTable;
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 在色带上下端同时显示或隐藏单值属性的真实业务值。
*
* 两个文字由独立 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();
vtkSmartPointer<vtkLookupTable> m_pLookupTable; ///< 共享外部颜色表引用。
vtkSmartPointer<vtkPropAssembly> m_pRootAssembly; ///< Scene 挂载的稳定根 Prop。
vtkSmartPointer<vtkScalarBarActor> m_pActor; ///< 图层独占的二维色标 Actor。
vtkSmartPointer<vtkTextActor> m_pTitleActor; ///< 独立左对齐 ASCII 标题。
vtkSmartPointer<vtkTextActor> m_pConstantMinimumValueActor; ///< 单值属性下端值文字。
vtkSmartPointer<vtkTextActor> m_pConstantMaximumValueActor; ///< 单值属性上端值文字。
QString m_sTitle; ///< 保留无损 Qt 标题,避免从 VTK 窄字符串反向解析。
QString m_sLabelFormat; ///< 普通刻度的 printf 风格格式字符串。
QString m_sConstantValueText; ///< 保留单值属性文字,避免从 VTK 反向解析。
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