哎嗨,今天来嘚瑟一下,翻车终于修好了,自己的坑自己填,医学四视图-003-解决图像反转(失败)这个坑今天可以填上了。
修车程工,以图为证!!!
文章目录
- 继续修VtkImageViewer2的车
- 问题所在
- 声明:
- SetSliceOrientation
- ☞ 源码
问题所在关键字: SliceOrientation、vtkImageViewer2、UpdateOrientation、SetSliceOrientation、vtkCamera
其实出现这个问题,可以从两个方面考虑,要么是物体位置不正切,要么就是摄像机位置不正确,其实是一个问题,那就是摄像机和物体不匹配当先的条件。BestMPRbaseVtk-005-翻车加修车,既然三个视图是根据矩阵来做的,那我应该vrkImageViewer2 里面也可以这么来搞。看下官方的代码
声明:vtkGetMacro(SliceOrientation, int); virtual void SetSliceOrientation(int orientation); virtual void SetSliceOrientationToXY() { this->SetSliceOrientation(vtkImageViewer2::SLICE_ORIENTATION_XY); } virtual void SetSliceOrientationToYZ() { this->SetSliceOrientation(vtkImageViewer2::SLICE_ORIENTATION_YZ); } virtual void SetSliceOrientationToXZ() { this->SetSliceOrientation(vtkImageViewer2::SLICE_ORIENTATION_XZ); }SetSliceOrientation
void vtkImageViewer2::SetSliceOrientation(int orientation) { if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ || orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) { vtkErrorMacro("Error - invalid slice orientation " << orientation); return; } if (this->SliceOrientation == orientation) { return; } this->SliceOrientation = orientation; // Update the viewer int* range = this->GetSliceRange(); if (range) { this->Slice = static_cast((range[0] + range[1]) * 0.5); } this->UpdateOrientation(); this->UpdateDisplayExtent(); if (this->Renderer && this->GetInput()) { double scale = this->Renderer->GetActiveCamera()->GetParallelScale(); this->Renderer->ResetCamera(); this->Renderer->GetActiveCamera()->SetParallelScale(scale); } this->Render(); }
这里我们要看到,调用了一个函数UpdateOrientation
void vtkImageViewer2::UpdateOrientation() { // Set the camera position vtkCamera* cam = this->Renderer ? this->Renderer->GetActiveCamera() : nullptr; if (cam) { switch (this->SliceOrientation) { case vtkImageViewer2::SLICE_ORIENTATION_XY: cam->SetFocalPoint(0, 0, 0); cam->SetPosition(0, 0, 1); // -1 if medical ? cam->SetViewUp(0, 1, 0); break; case vtkImageViewer2::SLICE_ORIENTATION_XZ: cam->SetFocalPoint(0, 0, 0); cam->SetPosition(0, -1, 0); // 1 if medical ? cam->SetViewUp(0, 0, 1); break; case vtkImageViewer2::SLICE_ORIENTATION_YZ: cam->SetFocalPoint(0, 0, 0); cam->SetPosition(1, 0, 0); // -1 if medical ? cam->SetViewUp(0, 0, 1); break; } } }
是不是看到了熟悉的内容了。
就是该他,这里需要说明一点的是,UpdateOrientation在源码中被声明了保护的,这个我C++基础不咋地,不到能不能重写了,我这里不存在问题,是因为我把官方代码全部换皮搬运了,说白了就是直接动刀该官方源代码了,
修改后代码
void ImagePipeLine::updateOrientation() { vtkCamera* cam = this->Renderer ? this->Renderer->GetActiveCamera() : nullptr; if(cam) { switch (this->SliceOrientation) { case ImagePipeLine::SLICE_ORIENTATION_XY: cam->SetFocalPoint(0,0,0); cam->SetPosition(0,0,1); cam->SetViewUp(0,1,0); break; case ImagePipeLine::SLICE_ORIENTATION_XZ: cam->SetFocalPoint(0,0,0); cam->SetPosition(0,1,0); cam->SetViewUp(0,0,-1); break; case ImagePipeLine::SLICE_ORIENTATION_YZ: cam->SetFocalPoint(0,0,0); cam->SetPosition(1,0,0); cam->SetViewUp(0,0,-1); break; } } }
自此,坑已填上。不过,如果不重写VtkImageViewer2,应该可以通过设置相机坐标,也可以解决问题。
☞ 源码源码链接:GitHub仓库自取
使用方法:☟☟☟
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)