|
|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
#include <QByteArray>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QThread>
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
|
|
|
|
|
|
#include <vtkActor2D.h>
|
|
|
|
|
#include <vtkCellArray.h>
|
|
|
|
|
@ -20,6 +21,30 @@
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
const int SCALAR_BAR_LEFT_MARGIN_PIXELS = 20;
|
|
|
|
|
const int SCALAR_BAR_TOTAL_WIDTH_PIXELS = 108;
|
|
|
|
|
// VTK 内部留白会压缩色带,目标宽度设为 34px 后可见宽度约为 30px。
|
|
|
|
|
const int SCALAR_BAR_COLOR_WIDTH_PIXELS = 34;
|
|
|
|
|
const int SCALAR_BAR_VISIBLE_COLOR_WIDTH_PIXELS = 30;
|
|
|
|
|
const int SCALAR_BAR_TITLE_FONT_SIZE = 18;
|
|
|
|
|
const int SCALAR_BAR_TITLE_SAFE_HEIGHT_PIXELS = 24;
|
|
|
|
|
const int SCALAR_BAR_LABEL_FONT_SIZE = 15;
|
|
|
|
|
const int SCALAR_BAR_SMALL_VIEWPORT_HEIGHT = 450;
|
|
|
|
|
const int SCALAR_BAR_MEDIUM_VIEWPORT_HEIGHT = 650;
|
|
|
|
|
const int SCALAR_BAR_LABEL_SPACING_PIXELS = 80;
|
|
|
|
|
const int SCALAR_BAR_MIN_LABEL_COUNT = 6;
|
|
|
|
|
const int SCALAR_BAR_MAX_LABEL_COUNT = 9;
|
|
|
|
|
const int SCALAR_BAR_TITLE_OFFSET_Y_PIXELS = 28;
|
|
|
|
|
const int SCALAR_BAR_SWATCH_WIDTH_PIXELS = 16;
|
|
|
|
|
const int SCALAR_BAR_SWATCH_HEIGHT_PIXELS = 12;
|
|
|
|
|
const int SCALAR_BAR_SWATCH_GAP_PIXELS = 4;
|
|
|
|
|
const int SCALAR_BAR_TEXT_GAP_PIXELS = 6;
|
|
|
|
|
const int SCALAR_BAR_LABEL_GAP_PIXELS = 8;
|
|
|
|
|
const double SCALAR_BAR_NORMAL_BOTTOM_RATIO = 0.22;
|
|
|
|
|
const double SCALAR_BAR_NORMAL_HEIGHT_RATIO = 0.67;
|
|
|
|
|
const double SCALAR_BAR_SMALL_BOTTOM_RATIO = 0.22;
|
|
|
|
|
const double SCALAR_BAR_SMALL_HEIGHT_RATIO = 0.62;
|
|
|
|
|
|
|
|
|
|
// ScalarBarActor 和 LookupTable 均只能在 Qt GUI 线程中修改。
|
|
|
|
|
bool isScalarBarGuiThread()
|
|
|
|
|
{
|
|
|
|
|
@ -62,18 +87,49 @@ vtkSmartPointer<vtkActor2D> createRangeSwatchActor(vtkPoints* pPoints)
|
|
|
|
|
return pActor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 统一独立文本样式,使常量值和越界说明与普通色标刻度保持一致。
|
|
|
|
|
void configureOverlayTextActor(vtkTextActor* pActor)
|
|
|
|
|
// 独立文本共用字号和颜色;常量值可选择与普通刻度一致的强调样式。
|
|
|
|
|
void configureOverlayTextActor(vtkTextActor* pActor,
|
|
|
|
|
bool bUseTickStyle)
|
|
|
|
|
{
|
|
|
|
|
pActor->SetInput("");
|
|
|
|
|
pActor->SetTextScaleModeToNone();
|
|
|
|
|
pActor->GetTextProperty()->SetFontFamilyToArial();
|
|
|
|
|
pActor->GetTextProperty()->SetFontSize(SCALAR_BAR_LABEL_FONT_SIZE);
|
|
|
|
|
pActor->GetTextProperty()->SetColor(1.0, 1.0, 1.0);
|
|
|
|
|
if(bUseTickStyle) {
|
|
|
|
|
pActor->GetTextProperty()->BoldOn();
|
|
|
|
|
pActor->GetTextProperty()->ItalicOn();
|
|
|
|
|
pActor->GetTextProperty()->ShadowOn();
|
|
|
|
|
pActor->GetTextProperty()->SetShadowOffset(1, -1);
|
|
|
|
|
} else {
|
|
|
|
|
pActor->GetTextProperty()->BoldOff();
|
|
|
|
|
pActor->GetTextProperty()->ItalicOff();
|
|
|
|
|
pActor->GetTextProperty()->ShadowOff();
|
|
|
|
|
}
|
|
|
|
|
pActor->GetTextProperty()->SetJustificationToLeft();
|
|
|
|
|
pActor->GetTextProperty()->SetVerticalJustificationToCentered();
|
|
|
|
|
pActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
|
|
|
|
|
pActor->GetProperty()->SetDisplayLocationToForeground();
|
|
|
|
|
pActor->PickableOff();
|
|
|
|
|
pActor->SetVisibility(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 独立标题不受 vtkScalarBarActor 内部居中布局影响,始终保持左对齐。
|
|
|
|
|
void configureTitleActor(vtkTextActor* pActor)
|
|
|
|
|
{
|
|
|
|
|
pActor->SetInput("");
|
|
|
|
|
pActor->SetTextScaleModeToNone();
|
|
|
|
|
pActor->GetTextProperty()->SetFontSize(11);
|
|
|
|
|
pActor->GetTextProperty()->SetFontFamilyToArial();
|
|
|
|
|
pActor->GetTextProperty()->SetFontSize(SCALAR_BAR_TITLE_FONT_SIZE);
|
|
|
|
|
pActor->GetTextProperty()->SetColor(1.0, 1.0, 1.0);
|
|
|
|
|
pActor->GetTextProperty()->BoldOff();
|
|
|
|
|
pActor->GetTextProperty()->ItalicOff();
|
|
|
|
|
pActor->GetTextProperty()->ShadowOff();
|
|
|
|
|
pActor->GetTextProperty()->ShadowOn();
|
|
|
|
|
pActor->GetTextProperty()->SetShadowOffset(1, -1);
|
|
|
|
|
pActor->GetTextProperty()->SetJustificationToLeft();
|
|
|
|
|
pActor->GetTextProperty()->SetVerticalJustificationToCentered();
|
|
|
|
|
pActor->GetTextProperty()->SetVerticalJustificationToBottom();
|
|
|
|
|
pActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
|
|
|
|
|
pActor->GetProperty()->SetDisplayLocationToForeground();
|
|
|
|
|
pActor->PickableOff();
|
|
|
|
|
pActor->SetVisibility(0);
|
|
|
|
|
}
|
|
|
|
|
@ -97,6 +153,7 @@ nmVTKScalarBarLayer::nmVTKScalarBarLayer(const QString& sLayerId)
|
|
|
|
|
m_pLookupTable(nullptr),
|
|
|
|
|
m_pRootAssembly(vtkSmartPointer<vtkPropAssembly>::New()),
|
|
|
|
|
m_pActor(vtkSmartPointer<vtkScalarBarActor>::New()),
|
|
|
|
|
m_pTitleActor(vtkSmartPointer<vtkTextActor>::New()),
|
|
|
|
|
m_pConstantValueActor(vtkSmartPointer<vtkTextActor>::New()),
|
|
|
|
|
m_pBelowRangeSwatchPoints(vtkSmartPointer<vtkPoints>::New()),
|
|
|
|
|
m_pBelowRangeSwatchActor(nullptr),
|
|
|
|
|
@ -108,21 +165,33 @@ nmVTKScalarBarLayer::nmVTKScalarBarLayer(const QString& sLayerId)
|
|
|
|
|
m_dPositionX(0.0),
|
|
|
|
|
m_dPositionY(0.0),
|
|
|
|
|
m_dWidth(0.1),
|
|
|
|
|
m_dHeight(0.8)
|
|
|
|
|
m_dHeight(0.8),
|
|
|
|
|
m_nViewportWidth(0),
|
|
|
|
|
m_nViewportHeight(0)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(isScalarBarGuiThread());
|
|
|
|
|
// vtkScalarBarActor 是二维 Prop,仍通过图层基类统一完成挂载和显隐。
|
|
|
|
|
m_pActor->SetNumberOfLabels(5);
|
|
|
|
|
m_pActor->SetLabelFormat("%.6g");
|
|
|
|
|
m_pActor->SetTitle("");
|
|
|
|
|
m_pActor->SetOrientationToVertical();
|
|
|
|
|
m_pActor->SetTextPositionToSucceedScalarBar();
|
|
|
|
|
m_pActor->SetTextPad(3);
|
|
|
|
|
m_pActor->UnconstrainedFontSizeOn();
|
|
|
|
|
m_pActor->GetLabelTextProperty()->SetFontSize(11);
|
|
|
|
|
m_pActor->GetLabelTextProperty()->BoldOff();
|
|
|
|
|
m_pActor->GetLabelTextProperty()->ItalicOff();
|
|
|
|
|
m_pActor->GetLabelTextProperty()->ShadowOff();
|
|
|
|
|
m_pActor->GetTitleTextProperty()->SetFontSize(12);
|
|
|
|
|
m_pActor->GetTitleTextProperty()->BoldOff();
|
|
|
|
|
m_pActor->GetTitleTextProperty()->ItalicOff();
|
|
|
|
|
m_pActor->GetTitleTextProperty()->ShadowOff();
|
|
|
|
|
m_pActor->GetLabelTextProperty()->SetFontFamilyToArial();
|
|
|
|
|
m_pActor->GetLabelTextProperty()->SetFontSize(
|
|
|
|
|
SCALAR_BAR_LABEL_FONT_SIZE);
|
|
|
|
|
m_pActor->GetLabelTextProperty()->SetColor(1.0, 1.0, 1.0);
|
|
|
|
|
m_pActor->GetLabelTextProperty()->BoldOn();
|
|
|
|
|
m_pActor->GetLabelTextProperty()->ItalicOn();
|
|
|
|
|
m_pActor->GetLabelTextProperty()->ShadowOn();
|
|
|
|
|
m_pActor->GetLabelTextProperty()->SetShadowOffset(1, -1);
|
|
|
|
|
m_pActor->SetMaximumWidthInPixels(SCALAR_BAR_TOTAL_WIDTH_PIXELS);
|
|
|
|
|
m_pActor->SetBarRatio(
|
|
|
|
|
static_cast<double>(SCALAR_BAR_COLOR_WIDTH_PIXELS) /
|
|
|
|
|
static_cast<double>(SCALAR_BAR_TOTAL_WIDTH_PIXELS));
|
|
|
|
|
m_pActor->GetProperty()->SetDisplayLocationToForeground();
|
|
|
|
|
m_pActor->PickableOff();
|
|
|
|
|
m_pActor->DrawAnnotationsOff();
|
|
|
|
|
m_pActor->DrawBelowRangeSwatchOff();
|
|
|
|
|
m_pActor->DrawAboveRangeSwatchOff();
|
|
|
|
|
@ -134,13 +203,15 @@ nmVTKScalarBarLayer::nmVTKScalarBarLayer(const QString& sLayerId)
|
|
|
|
|
createRangeSwatchActor(m_pBelowRangeSwatchPoints);
|
|
|
|
|
m_pAboveRangeSwatchActor =
|
|
|
|
|
createRangeSwatchActor(m_pAboveRangeSwatchPoints);
|
|
|
|
|
configureOverlayTextActor(m_pConstantValueActor);
|
|
|
|
|
configureOverlayTextActor(m_pBelowRangeTextActor);
|
|
|
|
|
configureOverlayTextActor(m_pAboveRangeTextActor);
|
|
|
|
|
configureTitleActor(m_pTitleActor);
|
|
|
|
|
configureOverlayTextActor(m_pConstantValueActor, true);
|
|
|
|
|
configureOverlayTextActor(m_pBelowRangeTextActor, false);
|
|
|
|
|
configureOverlayTextActor(m_pAboveRangeTextActor, false);
|
|
|
|
|
updateOverlayLayout();
|
|
|
|
|
|
|
|
|
|
// 根 Assembly 只在构造时注册,运行期仅更新子 Actor 状态。
|
|
|
|
|
m_pRootAssembly->AddPart(m_pActor);
|
|
|
|
|
m_pRootAssembly->AddPart(m_pTitleActor);
|
|
|
|
|
m_pRootAssembly->AddPart(m_pConstantValueActor);
|
|
|
|
|
m_pRootAssembly->AddPart(m_pBelowRangeSwatchActor);
|
|
|
|
|
m_pRootAssembly->AddPart(m_pBelowRangeTextActor);
|
|
|
|
|
@ -162,6 +233,7 @@ nmVTKScalarBarLayer::~nmVTKScalarBarLayer()
|
|
|
|
|
m_pBelowRangeSwatchActor = nullptr;
|
|
|
|
|
m_pBelowRangeSwatchPoints = nullptr;
|
|
|
|
|
m_pConstantValueActor = nullptr;
|
|
|
|
|
m_pTitleActor = nullptr;
|
|
|
|
|
m_pActor = nullptr;
|
|
|
|
|
m_pRootAssembly = nullptr;
|
|
|
|
|
}
|
|
|
|
|
@ -190,9 +262,11 @@ void nmVTKScalarBarLayer::setTitle(const QString& sTitle)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_sTitle = sTitle;
|
|
|
|
|
// VTK 7.1 接口接收窄字符串,统一以 UTF-8 临时缓冲传入并由 Actor 复制。
|
|
|
|
|
// 内置标题永久留空,避免其按整个 ScalarBarActor 宽度自动居中。
|
|
|
|
|
m_pActor->SetTitle("");
|
|
|
|
|
const QByteArray aTitle = sTitle.toUtf8();
|
|
|
|
|
m_pActor->SetTitle(aTitle.constData());
|
|
|
|
|
m_pTitleActor->SetInput(aTitle.constData());
|
|
|
|
|
m_pTitleActor->SetVisibility(sTitle.isEmpty() ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString nmVTKScalarBarLayer::getTitle() const
|
|
|
|
|
@ -232,6 +306,73 @@ int nmVTKScalarBarLayer::getNumberOfLabels() const
|
|
|
|
|
return m_pActor != nullptr ? m_pActor->GetNumberOfLabels() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmVTKScalarBarLayer::setViewportSize(int nWidth, int nHeight)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(isScalarBarGuiThread());
|
|
|
|
|
if(!isScalarBarGuiThread() || nWidth <= 0 || nHeight <= 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_nViewportWidth = nWidth;
|
|
|
|
|
m_nViewportHeight = nHeight;
|
|
|
|
|
const bool bSmallViewport =
|
|
|
|
|
nHeight < SCALAR_BAR_SMALL_VIEWPORT_HEIGHT;
|
|
|
|
|
const double dBottomRatio = bSmallViewport
|
|
|
|
|
? SCALAR_BAR_SMALL_BOTTOM_RATIO
|
|
|
|
|
: SCALAR_BAR_NORMAL_BOTTOM_RATIO;
|
|
|
|
|
const double dHeightRatio = bSmallViewport
|
|
|
|
|
? SCALAR_BAR_SMALL_HEIGHT_RATIO
|
|
|
|
|
: SCALAR_BAR_NORMAL_HEIGHT_RATIO;
|
|
|
|
|
|
|
|
|
|
// 小于目标宽度的极端视口会安全收窄;正常窗口保持固定像素宽度。
|
|
|
|
|
const int nLeftMargin = qMin(
|
|
|
|
|
SCALAR_BAR_LEFT_MARGIN_PIXELS, qMax(0, nWidth - 1));
|
|
|
|
|
const int nLayoutWidth = qMin(
|
|
|
|
|
SCALAR_BAR_TOTAL_WIDTH_PIXELS,
|
|
|
|
|
qMax(1, nWidth - nLeftMargin));
|
|
|
|
|
const int nLayoutHeight = qMax(1, qRound(nHeight * dHeightRatio));
|
|
|
|
|
m_dPositionX = static_cast<double>(nLeftMargin) / nWidth;
|
|
|
|
|
m_dPositionY = dBottomRatio;
|
|
|
|
|
m_dWidth = static_cast<double>(nLayoutWidth) / nWidth;
|
|
|
|
|
m_dHeight = static_cast<double>(nLayoutHeight) / nHeight;
|
|
|
|
|
|
|
|
|
|
m_pActor->SetPosition(m_dPositionX, m_dPositionY);
|
|
|
|
|
m_pActor->SetWidth(m_dWidth);
|
|
|
|
|
m_pActor->SetHeight(m_dHeight);
|
|
|
|
|
m_pActor->SetMaximumWidthInPixels(nLayoutWidth);
|
|
|
|
|
m_pActor->SetMaximumHeightInPixels(nLayoutHeight);
|
|
|
|
|
double dBarRatio =
|
|
|
|
|
static_cast<double>(SCALAR_BAR_COLOR_WIDTH_PIXELS) /
|
|
|
|
|
static_cast<double>(nLayoutWidth);
|
|
|
|
|
if(dBarRatio >= 1.0) {
|
|
|
|
|
dBarRatio = 0.95;
|
|
|
|
|
}
|
|
|
|
|
m_pActor->SetBarRatio(dBarRatio);
|
|
|
|
|
updateOverlayLayout();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nmVTKScalarBarLayer::getResponsiveLabelCount() const
|
|
|
|
|
{
|
|
|
|
|
if(m_nViewportHeight <= 0) {
|
|
|
|
|
return 5;
|
|
|
|
|
}
|
|
|
|
|
if(m_nViewportHeight < SCALAR_BAR_SMALL_VIEWPORT_HEIGHT) {
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
if(m_nViewportHeight <= SCALAR_BAR_MEDIUM_VIEWPORT_HEIGHT) {
|
|
|
|
|
return 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int nBarHeight = qMax(
|
|
|
|
|
1, qRound(m_dHeight * m_nViewportHeight));
|
|
|
|
|
return qBound(
|
|
|
|
|
SCALAR_BAR_MIN_LABEL_COUNT,
|
|
|
|
|
qRound(static_cast<double>(nBarHeight) /
|
|
|
|
|
SCALAR_BAR_LABEL_SPACING_PIXELS),
|
|
|
|
|
SCALAR_BAR_MAX_LABEL_COUNT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmVTKScalarBarLayer::setBelowRangeSwatch(
|
|
|
|
|
bool bVisible,
|
|
|
|
|
const QString& sText)
|
|
|
|
|
@ -313,22 +454,50 @@ bool nmVTKScalarBarLayer::setSize(double dWidth, double dHeight)
|
|
|
|
|
|
|
|
|
|
void nmVTKScalarBarLayer::updateOverlayLayout()
|
|
|
|
|
{
|
|
|
|
|
// 常量值放在色带右侧的垂直中心,视觉位置与普通刻度标签一致。
|
|
|
|
|
const double dLabelX = m_dPositionX + m_dWidth + 0.01;
|
|
|
|
|
const bool bHasViewport =
|
|
|
|
|
m_nViewportWidth > 0 && m_nViewportHeight > 0;
|
|
|
|
|
const double dPixelX = bHasViewport
|
|
|
|
|
? 1.0 / m_nViewportWidth : 0.01;
|
|
|
|
|
const double dPixelY = bHasViewport
|
|
|
|
|
? 1.0 / m_nViewportHeight : 0.01;
|
|
|
|
|
double dColorWidth = bHasViewport
|
|
|
|
|
? SCALAR_BAR_VISIBLE_COLOR_WIDTH_PIXELS * dPixelX
|
|
|
|
|
: m_dWidth * 0.33;
|
|
|
|
|
if(dColorWidth > m_dWidth) {
|
|
|
|
|
dColorWidth = m_dWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 常量值与普通刻度共用色带右侧的固定像素起点。
|
|
|
|
|
const double dLabelX = m_dPositionX + dColorWidth +
|
|
|
|
|
SCALAR_BAR_LABEL_GAP_PIXELS * dPixelX;
|
|
|
|
|
const double dLabelY = m_dPositionY + m_dHeight * 0.5;
|
|
|
|
|
m_pConstantValueActor->GetPositionCoordinate()->SetValue(
|
|
|
|
|
dLabelX, dLabelY, 0.0);
|
|
|
|
|
|
|
|
|
|
// 越界色块位于色带上下两端外侧,避免覆盖连续色带和普通刻度。
|
|
|
|
|
double dSwatchWidth = m_dWidth * 0.25;
|
|
|
|
|
if(dSwatchWidth < 0.012) {
|
|
|
|
|
dSwatchWidth = 0.012;
|
|
|
|
|
} else if(dSwatchWidth > 0.025) {
|
|
|
|
|
dSwatchWidth = 0.025;
|
|
|
|
|
}
|
|
|
|
|
const double dSwatchHeight = 0.018;
|
|
|
|
|
const double dSwatchGap = 0.012;
|
|
|
|
|
const double dTextGap = 0.008;
|
|
|
|
|
// 标题通常位于色带左上方;极小视口下向下钳制,避免越过视口顶边。
|
|
|
|
|
const double dDesiredTitleY =
|
|
|
|
|
m_dPositionY + m_dHeight +
|
|
|
|
|
SCALAR_BAR_TITLE_OFFSET_Y_PIXELS * dPixelY;
|
|
|
|
|
const double dMaximumTitleY = bHasViewport
|
|
|
|
|
? qMax(0.0, 1.0 -
|
|
|
|
|
SCALAR_BAR_TITLE_SAFE_HEIGHT_PIXELS * dPixelY)
|
|
|
|
|
: dDesiredTitleY;
|
|
|
|
|
const double dTitleY = qMin(dDesiredTitleY, dMaximumTitleY);
|
|
|
|
|
m_pTitleActor->GetPositionCoordinate()->SetValue(
|
|
|
|
|
m_dPositionX,
|
|
|
|
|
dTitleY,
|
|
|
|
|
0.0);
|
|
|
|
|
|
|
|
|
|
// 越界色块和文字也按实际像素布局,窗口缩放时不会横向漂移。
|
|
|
|
|
const double dSwatchWidth = bHasViewport
|
|
|
|
|
? SCALAR_BAR_SWATCH_WIDTH_PIXELS * dPixelX
|
|
|
|
|
: qMin(m_dWidth * 0.25, 0.025);
|
|
|
|
|
const double dSwatchHeight = bHasViewport
|
|
|
|
|
? SCALAR_BAR_SWATCH_HEIGHT_PIXELS * dPixelY : 0.018;
|
|
|
|
|
const double dSwatchGap = bHasViewport
|
|
|
|
|
? SCALAR_BAR_SWATCH_GAP_PIXELS * dPixelY : 0.012;
|
|
|
|
|
const double dTextGap = bHasViewport
|
|
|
|
|
? SCALAR_BAR_TEXT_GAP_PIXELS * dPixelX : 0.008;
|
|
|
|
|
const double dBelowY =
|
|
|
|
|
m_dPositionY - dSwatchGap - dSwatchHeight;
|
|
|
|
|
const double dAboveY =
|
|
|
|
|
|