Hi eveyone,
I have a 3D-volume ,its size is as following:
witdth:180mm,X
height:100mm,Y
depth:300 mm,Z
it likes a fallen cuboid.
At begining camera faces to xy-plane which means 180*100 mm.
Now I want to extract a slice from any direction.
So I utilize vtkimagereslice
filter and vtkMatrix4x4
as rotation matrix, The rotation is around the Y-axis, i.e., along a 100 mm edge. FinallyI use imageviewer2
to display the result .
Code compile successfully and the reslice looks right. But it has annoying additional black edges at left side(the origin point on middle of top left edge). In other words, the FOV is bigger than it should be. It seems like that vtkimagereslice automatic create this area and fill it all zero.
Here is the screenshot ,the parts that are framed in red are the black areas that shouldnāt be there.
Here is my code in minisize:
void cut(double angle) {
vtkImageData* reslice;
vtkNew<vtkImageReslice> imageReslice;
vtkNew<vtkMatrix4x4> resliceAxes;
vtkNew<vtkImageViewer2> image_view_reslice;
double axialElements[16] = {
cos(angle), 0, sin(angle), 0,
0 , 1, 0, 0,
-sin(angle),0, cos(angle), 0,
0, 0, 0, 1 };
this->resliceAxes->DeepCopy(axialElements);
//std::cout << "origin :" << center[0] << "," << center[1] << "," << center[2] << endl;
resliceAxes->SetElement(0, 3, source_center[0] - Xmmus / 2 + 16);
resliceAxes->SetElement(1, 3, source_center[1] + Ymmus / 2 - 1);
resliceAxes->SetElement(2, 3, source_center[2]);
imageReslice->SetOutputDimensionality(2);
imageReslice->SetResliceAxes(this->resliceAxes);
imageReslice->SetInterpolationModeToCubic();
//this->imageReslice->AutoCropOutputOn();
imageReslice->Update();
int extent[6];
imageReslice->GetOutput()->GetExtent(extent);
double origin[3];
this->imageReslice->GetOutput()->GetOrigin(origin);
double spacing[3];
imageReslice->GetOutput()->GetSpacing(spacing);
float xc = origin[0] + 0.5*(extent[0] + extent[1])*spacing[0];
float yc = origin[1] + 0.5*(extent[2] + extent[3])*spacing[1];
float zc = origin[2] + 0.5*(extent[4] + extent[5])*spacing[2];
float xd = (extent[1] - extent[0] + 1)*spacing[0];
float yd = (extent[3] - extent[2] + 1)*spacing[1];
float zd = (extent[5] - extent[4] + 1)*spacing[2];
image_view_reslice->SetInputConnection(imageReslice->GetOutputPort());
image_view_reslice->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
image_view_reslice->GetRenderer()->GetActiveCamera()->SetParallelScale(0.5f*static_cast<float>(yd));
float d = image_view_reslice->GetRenderer()->GetActiveCamera()->GetDistance();
image_view_reslice->GetRenderer()->GetActiveCamera()->SetFocalPoint(xc, yc, 0);
image_view_reslice->GetRenderer()->GetActiveCamera()->SetPosition(xc, yc, +d);
image_view_reslice->UpdateDisplayExtent();
image_view_reslice->Render();
ui->usImagereslice->update();
ui->usImagereslice->show();