文章目录 3D空间坐标转换例程心得 3D空间坐标转换 在冠状图、矢状面、横截面等创建的角度组件的三个端点坐标,不能直接用在3D视图中。这是因为2D切片的坐标是基于像素的,而3D空间的坐标可能是基于实际物理尺寸的。 解决方案是使用
在冠状图、矢状面、横截面等创建的角度组件的三个端点坐标,不能直接用在3D视图中。这是因为2D切片的坐标是基于像素的,而3D空间的坐标可能是基于实际物理尺寸的。
解决方案是使用2D点的坐标、切片的物理位置和方向以及可能的其他参数(例如切片厚度或间距),来计算空间坐标。将计算好的空间坐标p1、p2、p3传入下面的函数中,就可以在3D视图中画出角度组件。
get3DViewAngle(double* p1, double* p2, double* mid, int* indexVal) { double modifiedPoints[3][3]; int currentAngleIndex = *indexVal; auto iter = threeDActors.find(currentAngleIndex); if (iter != threeDActors.end()) { for (auto act : iter->second) { threeDRenderer->RemoveActor(act); } threeDActors.erase(iter); } double* pts[] = {p1, p2, mid}; for(int i = 0; i < 3; i++) { modifiedPoints[i][0] = pts[i][0] * xRange[1] / imageDims[0]; modifiedPoints[i][1] = pts[i][1] * yRange[1] / imageDims[1]; modifiedPoints[i][2] = pts[i][2] * zRange[1] / imageDims[2]; } vtkSmartPointer<vtkSphereSource> src1 = vtkSmartPointer<vtkSphereSource>::New(); src1->SetCenter(modifiedPoints[0]); src1->SetRadius(2); vtkSmartPointer<vtkPolyDataMapper> map1 = vtkSmartPointer<vtkPolyDataMapper>::New(); map1->SetInputConnection(src1->GetOutputPort()); vtkSmartPointer<vtkActor> act1 = vtkSmartPointer<vtkActor>::New(); act1->SetMapper(map1); vtkSmartPointer<vtkSphereSource> src2 = vtkSmartPointer<vtkSphereSource>::New(); src2->SetCenter(modifiedPoints[1]); src2->SetRadius(2); vtkSmartPointer<vtkPolyDataMapper> map2 = vtkSmartPointer<vtkPolyDataMapper>::New(); map2->SetInputConnection(src2->GetOutputPort()); vtkSmartPointer<vtkActor> act2 = vtkSmartPointer<vtkActor>::New(); act2->SetMapper(map2); vtkSmartPointer<vtkSphereSource> src3 = vtkSmartPointer<vtkSphereSource>::New(); src3->SetCenter(modifiedPoints[2]); src3->SetRadius(2); vtkSmartPointer<vtkPolyDataMapper> map3 = vtkSmartPointer<vtkPolyDataMapper>::New(); map3->SetInputConnection(src3->GetOutputPort()); vtkSmartPointer<vtkActor> act3 = vtkSmartPointer<vtkActor>::New(); act3->SetMapper(map3); vtkSmartPointer<vtkLineSource> lnSrc1 = vtkSmartPointer<vtkLineSource>::New(); lnSrc1->SetPoint1(modifiedPoints[0]); lnSrc1->SetPoint2(modifiedPoints[2]); vtkSmartPointer<vtkPolyDataMapper> lnMap1 = vtkSmartPointer<vtkPolyDataMapper>::New(); lnMap1->SetInputConnection(lnSrc1->GetOutputPort()); vtkSmartPointer<vtkActor> lnAct1 = vtkSmartPointer<vtkActor>::New(); lnAct1->SetMapper(lnMap1); vtkSmartPointer<vtkLineSource> lnSrc2 = vtkSmartPointer<vtkLineSource>::New(); lnSrc2->SetPoint1(modifiedPoints[1]); lnSrc2->SetPoint2(modifiedPoints[2]); vtkSmartPointer<vtkPolyDataMapper> lnMap2 = vtkSmartPointer<vtkPolyDataMapper>::New(); lnMap2->SetInputConnection(lnSrc2->GetOutputPort()); vtkSmartPointer<vtkActor> lnAct2 = vtkSmartPointer<vtkActor>::New(); lnAct2->SetMapper(lnMap2); threeDRenderer->AddActor(act1); threeDRenderer->AddActor(act2); threeDRenderer->AddActor(act3); threeDRenderer->AddActor(lnAct1); threeDRenderer->AddActor(lnAct2); std::vector<vtkSmartPointer<vtkActor>> acts = {act1, act2, act3, lnAct1, lnAct2}; threeDActors[currentAngleIndex] = acts; for (auto act : acts) { threeDRenderer->AddActor(act); } renderWidget[3]->interactor()->Render();}}
lineCallback->Execute(lineWidget, vtkCommand::EndInteractionEvent, nullptr); //手动触发回调
如果想要保证实时删除2D和3D视图中的角度组件,可以使用map,只需要记住创建的索引就能直接删除组件。这样可以与页面上的组件数量和组件索引独立开来.
std::map<int,vtkSmartPointer<vtkAngleWidget>> ngleWidgets;
来源地址:https://blog.csdn.net/Algabeno/article/details/132565284
--结束END--
本文标题: VTK——angleWidget的3D转换
本文链接: https://lsjlt.com/news/383189.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0