#include <vtkSphereSource.h>
#include <vtkImageMathematics.h>
#include <vtkCutter.h>
#include <vtkPlane.h>
#include <vtkStripper.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkLinearExtrusionFilter.h>
#include <vtkMetaImageWriter.h>
#include <vtkMetaImageReader.h>
#include <vtkImplicitModeller.h>
#include <vtkOutlineFilter.h>
#include <vtkImageGaussianSmooth.h>
#include <vtkAppendPolyData.h>
#include <vtkImageImport.h>
#include <vtkImageMapper.h>
#include <vtkLineSource.h>
#include <vtkFloatArray.h>
#include <vtkChartXY.h>
#include <vtkAxis.h>
#include <vtkConeSource.h>
#include <vtkContourFilter.h>
#include <vtkBrush.h>
#include <vtkPen.h>
#include <vtkPlot.h>
#include <vtkTextProperty.h>
#include <vtkTable.h>
#include <vtkFloatArray.h>
#include <vtkChartXY.h>
#include <vtkContextView.h>
#include <vtkChartLegend.h>
#include "DvhDraw.h"
#include "DvhCalculate.h"
#include "DvhChartSave.h"
#include "stdafx.h"
#include "DataLayer.h"
#include "algorithm.h"
#include "ReadDoseData.h"
#include "DatabaseDefine.h"
#include "MedicineDatabase.h"
#include "PlanDataDefine.h"
#include "CustomInteractorStyle.h"
#include "PluginDefine.h"
#include "LogUtil.h"
#include "RTDataModelDefine.h"
#include "PluginDefine.h"
vtkSmartPointer<vtkRenderer> DvhDraw:: DvhDrawDVH(vtkSmartPointer<vtkTable> tableIntdraw) {
// 输出 tableIntdraw 的列和行数以验证
int numColumnsTableIntdraw = tableIntdraw->GetNumberOfColumns();
int numRowsTableIntdraw = tableIntdraw->GetNumberOfRows();
_logUtil.LogInfo(("tableIntdraw 的列数:" + std::to_string(numColumnsTableIntdraw)).c_str());
_logUtil.LogInfo(("tableIntdraw 的行数:" + std::to_string(numRowsTableIntdraw)).c_str());
if (numColumnsTableIntdraw == 0 || numRowsTableIntdraw == 0) {
_logUtil.LogError("Error: tableIntdraw is null.");
}
// 创建积分 DVH 图表
vtkSmartPointer<vtkChartXY> integratedDVHChart = vtkSmartPointer<vtkChartXY>::New();
integratedDVHChart->GetAxis(vtkAxis::LEFT)->SetTitle("Volume (%)");
integratedDVHChart->GetAxis(vtkAxis::BOTTOM)->SetTitle("Dose (cGy (IsoE))");
vtkAxis* yAxis = integratedDVHChart->GetAxis(vtkAxis::LEFT);
yAxis->SetRange(0, 100);
vtkAxis* xAxis = integratedDVHChart->GetAxis(vtkAxis::BOTTOM);
//xAxis->SetRange(0, XofDVH * 1.50);
//integratedDVHChart->Modified();
// 为每个 ROI 添加积分 DVH 曲线和图注
unsigned char a;
a = 255.0;
size_t totalRois = numColumnsTableIntdraw - 1;
if (totalRois > 0) {
// 为每个 ROI 添加积分 DVH 曲线和图注
for (size_t i = 0; i < totalRois; ++i) {
vtkPlot* integratedDVHPlot = integratedDVHChart->AddPlot(vtkChart::LINE);
integratedDVHPlot->SetInputData(tableIntdraw, 0, i + 1);
//integratedDVHPlot->SetColor(realroiColors[i][0], realroiColors[i][1], realroiColors[i][2], a); // 根据 ROI 索引设置颜色
//integratedDVHPlot->SetLabel(realroiNames[i].c_str()); // 设置图注
_logUtil.LogInfo("创建integratedDVHPlot成功");
//_logUtil.LogError(("realroiNames:" + roiName + "创建tableInt成功.").c_str());
}
}
else {
_logUtil.LogError("Error: realroiNames is null.");
}
// 设置图注的属性
vtkChartLegend* legend = integratedDVHChart->GetLegend();
legend->SetVisible(true);
legend->GetBrush()->SetColor(255, 255, 255, 0); // 背景颜色设置为白色,透明度为0
legend->GetPen()->SetColor(255, 255, 255); // 边框颜色设置为白色
legend->SetHorizontalAlignment(vtkChartLegend::RIGHT);// 设置图例的水平对齐方式为右对齐
legend->SetVerticalAlignment(vtkChartLegend::TOP);// 设置图例的垂直对齐方式为顶部对齐
// 根据ROI数量动态设置字体大小
int fontSize = 12; // 默认字体大小
fontSize = -0.4 * totalRois + 16;
legend->GetLabelProperties()->SetFontSize(fontSize); // 设置图注字体大小为12像素
//设置轴的范围
integratedDVHChart->GetLegend()->SetVisible(true);
vtkSmartPointer<vtkContextView> integratedDVHView = vtkSmartPointer<vtkContextView>::New();
// 添加图表到渲染窗口
vtkSmartPointer<vtkRenderer> dvhRenderer;
// 检查 doseMatrix 是否为空并根据结果处理 integratedDVHView
if (!totalRois == 0) {
integratedDVHView->GetScene()->AddItem(integratedDVHChart);
//integratedDVHView->GetRenderWindow()->SetSize(800, 600);
dvhRenderer = integratedDVHView->GetRenderer();
_logUtil.LogInfo("创建返回真实DVHdvhRenderer成功");
}
else {
// 设置一个默认的渲染器或者处理空的情况
dvhRenderer = vtkSmartPointer<vtkRenderer>::New();
_logUtil.LogInfo("创建返回空的DVHdvhRenderer成功");
}
//
//vtkSmartPointer<vtkRenderer> dvh ;
dvh = dvhRenderer;
return dvh;
}
读取DVH计算好的表格绘制DVH图(VTK)
最新推荐文章于 2025-07-26 17:43:58 发布