一 VTK MPR 三维重建 多层面重建 四视图( 二 )


接下来定义了切面的变换矩阵,该矩阵的前三列分别表示X、Y和Z方向矢量,第四列为切面坐标系原点 。通过修改切面坐标系原点,可以得到不同位置的切面图像 。
然后将读取的图像作为的输入,通过函数()设置变换矩阵
int main(){vtkSmartPointer pImageResliceX = vtkSmartPointer::New();vtkSmartPointer pImageResliceY = vtkSmartPointer::New();vtkSmartPointer pImageResliceZ = vtkSmartPointer::New();vtkSmartPointer pXMLImageDataReader = vtkSmartPointer::New();vtkSmartPointer pImageCast = vtkSmartPointer::New();vtkSmartPointer pImageActorX = vtkSmartPointer::New();vtkSmartPointer pImageActorY = vtkSmartPointer::New();vtkSmartPointer pImageActorZ = vtkSmartPointer::New();vtkSmartPointer pRendererX = vtkSmartPointer::New();vtkSmartPointer pRendererY = vtkSmartPointer::New();vtkSmartPointer pRendererZ = vtkSmartPointer::New();vtkSmartPointer pRenderer = vtkSmartPointer::New();vtkSmartPointer pRenderWindow = vtkSmartPointer::New();//vtkSmartPointer reader =// vtkSmartPointer::New();//reader->SetFileName("D:/datasource/brain.mhd");//reader->Update();vtkSmartPointer reader = vtkSmartPointer::New();reader->SetDirectoryName("D:/datasource/fei/ScalarVolume_13");reader->Update();int extent[6];double spacing[3];double origin[3];reader->GetOutput()->GetExtent(extent);reader->GetOutput()->GetSpacing(spacing);reader->GetOutput()->GetOrigin(origin);// 计算中心位置 。double center[3];center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);//轴状面double Axial[16] = {1, 0, 0, 0,0, 1, 0, 0,0, 0, 1, 0,0, 0, 0, 1 };//冠状面double Coronal[16] = {1, 0, 0, 0,0, 0, -1, 0,0, 1, 0, 0,0, 0, 0, 1 };//矢状面double Sagittal[16] = {0, 0, 1, 0,1, 0, 0, 0,0, 1, 0, 0,0, 0, 0, 1 };pImageCast->SetInputConnection(reader->GetOutputPort());pImageCast->SetOutputScalarTypeToChar();pImageCast->ClampOverflowOn();pImageCast->Update();//pImageCast->SetUpdateExtentToWholeExtent();//xinitImageActor(Axial, center, pImageCast, pImageResliceX, pImageActorX);//yinitImageActor(Coronal, center, pImageCast, pImageResliceY, pImageActorY);//zinitImageActor(Sagittal, center, pImageCast, pImageResliceZ, pImageActorZ);float fOpac = 0.5;pRendererX->AddActor(pImageActorX);pRendererY->AddActor(pImageActorY);pRendererZ->AddActor(pImageActorZ);//pRenderer->SetBackground(1, 1, 1);pRendererX->SetBackground(0, 0, 0);pRendererY->SetBackground(0, 0, 0);pRendererZ->SetBackground(0, 0, 0);/*#renderer 0: BOTTOM LEFT#renderer 1: BOTTOM RIGHT#renderer 2: TOP LEFT#renderer 3: TOP RIGHT*/double ltView[4] = { 0, 0, 0.5, 0.5 }; double rtView[4] = { 0.5, 0, 1, 0.5 }; double lbView[4] = { 0, 0.5, 0.5, 1 }; double rbView[4] = { 0.5, 0.5, 1, 1 }; //pRenderer->SetViewport(0, 0, 0.6, 1);//pRendererX->SetViewport(0.6, 0.66, 1, 1);//pRendererY->SetViewport(0.6, 0.33, 1, 0.66);//pRendererZ->SetViewport(0.6, 0, 1, 0.33);pRenderer->SetViewport(rtView);pRendererX->SetViewport(lbView);pRendererY->SetViewport(rbView);pRendererZ->SetViewport(ltView);pRenderWindow->AddRenderer(pRendererX);pRenderWindow->AddRenderer(pRendererY);pRenderWindow->AddRenderer(pRendererZ);pRenderWindow->AddRenderer(pRenderer);vtkSmartPointer pRenderWindowInteractor =vtkSmartPointer::New();pRenderWindow->SetSize(600, 600);// add observer;vtkSmartPointer imagestyle =vtkSmartPointer::New();pRenderWindowInteractor->SetInteractorStyle(imagestyle);pRenderWindowInteractor->SetRenderWindow(pRenderWindow);pRenderWindowInteractor->Initialize();vtkSmartPointer