VTK切割图

vtkPlane:表示一个无限的平面,要由一个法向量和一个通过该平面的点来定义

  • SetOrigin:设置原点(平面经过的点)
  • SetNormal:垂直于平面的方向向量(法向量)

vtkCutter:使用指定的vtkPlane对数据进行切割

  • SetCutFunction:切割工具,可以是vtkPlane
  • SetInputData:切割的数据
  • Update:执行切割
cpp 复制代码
 // 获取数据集的边界框
double bounds[6];
m_dataSet->GetBounds(bounds);

// 根据方向和位置计算切割平面
// model.sliceDirection: 0=XY平面(Z值变化), 1=XZ平面(Y值变化), 2=YZ平面(X值变化)
// model.slicePosition: 0.0~1.0 相对范围
double origin[3] = {
    0.5 * (bounds[0] + bounds[1]),
    0.5 * (bounds[2] + bounds[3]),
    0.5 * (bounds[4] + bounds[5])
};
double normal[3] = {0.0, 0.0, 1.0};

const double t = qBound(0.0, model.slicePosition, 1.0);
switch (model.sliceDirection) {
    case 0: // XY: Z = zMin + t * (zMax - zMin)
        origin[2] = bounds[4] + t * (bounds[5] - bounds[4]);
        normal[0] = 0.0; normal[1] = 0.0; normal[2] = 1.0;
        break;
    case 1: // XZ: Y = yMin + t * (yMax - yMin)
        origin[1] = bounds[2] + t * (bounds[3] - bounds[2]);
        normal[0] = 0.0; normal[1] = 1.0; normal[2] = 0.0;
        break;
    case 2: // YZ: X = xMin + t * (xMax - xMin)
        origin[0] = bounds[0] + t * (bounds[1] - bounds[0]);
        normal[0] = 1.0; normal[1] = 0.0; normal[2] = 0.0;
        break;
    default:
        return false;
}

// 构建切割管线:DataSet -> Plane + Cutter -> Mapper -> Actor
m_slicePlane = vtkSmartPointer<vtkPlane>::New();
m_slicePlane->SetOrigin(origin);
m_slicePlane->SetNormal(normal);

m_sliceCutter = vtkSmartPointer<vtkCutter>::New();
m_sliceCutter->SetCutFunction(m_slicePlane);
m_sliceCutter->SetInputData(m_dataSet);
m_sliceCutter->Update();

if (m_sliceCutter->GetOutput()->GetNumberOfCells() == 0)
    return false;

m_sliceMapper = vtkSmartPointer<vtkDataSetMapper>::New();
m_sliceMapper->SetInputConnection(m_sliceCutter->GetOutputPort());
m_sliceMapper->ScalarVisibilityOff();

if (!m_sliceActor) {
    m_sliceActor = vtkSmartPointer<vtkActor>::New();
}

m_renderer->RemoveActor(m_sliceActor);
m_renderer->AddActor(m_sliceActor);
m_sliceActor->SetMapper(m_sliceMapper);
m_sliceActor->GetProperty()->SetRepresentationToSurface();
m_sliceActor->GetProperty()->SetColor(1.0, 0.2, 0.2);
m_sliceActor->GetProperty()->SetLineWidth(2.0);
m_sliceActor->GetProperty()->LightingOff();

// 切割显示时隐藏本体,避免截面被不透明外表面完全遮挡。
if (m_actor)
    m_actor->SetVisibility(0);

// 切割显示时隐藏云图色标,避免右侧图例误导。
if (m_scalarBar)
    m_scalarBar->SetVisibility(0);
相关推荐
·薯条大王11 小时前
经济实惠玩云服务器|一台云服务器多人共用,子账号配置教程
java·linux·运维·服务器·汇编·c++·python
hansang_IR16 小时前
【题解】LC:倍增 / 区间并查集(Range Parallel Unionfind)
c++·算法·并查集
东东最爱敲键盘16 小时前
day7.c++继承
c++
沫璃染墨16 小时前
《从零入门Linux系统篇(十五):系统工具篇·六——GDB调试器详解:从程序执行控制到高级调试技巧》
linux·运维·服务器·c语言·c++
吃着火锅x唱着歌17 小时前
Effective C++ 学习笔记 条款40 明智而审慎地使用多重继承
c++·笔记·学习
醉城夜风~17 小时前
(超详细)C++ STL list容器详解:从使用方法到双向链表底层原理全面解析
c++·windows
≮傷£≯√18 小时前
Opencv VideoCapture
qt·opencv
烟花落o18 小时前
C++ 从 C 到进阶 ②:引用、inline 、nullptr
c++·引用·inline·nullptr·c++入门
liulilittle18 小时前
MOE路由:路由(logits: top-k/8)
c++·人工智能·算法·机器学习·llm
旖旎夜光18 小时前
LeetCode 11:盛最多水的容器(双指针问题) —— 题解
数据结构·c++·算法·leetcode·双指针