给定由两点p1、p2定义的直线;以及由法向n和点p0定义的平面,计算交点。沿直线的参数坐标以t返回,交点坐标以x返回。如果平面和直线之间不相交(0<=t<=1),则返回零。如果平面和直线平行,则返回零,并将t设置为VTK_LARGE_DOUBLE。
int vtkPlane::IntersectWithLine(double p1[3], double p2[3], double n[3],
double p0[3], double& t, double x[3])
{
double num, den, p21[3];
double fabsden, fabstolerance;
// Compute line vector
//
p21[0] = p2[0] - p1[0];
p21[1] = p2[1] - p1[1];
p21[2] = p2[2] - p1[2];
// Compute denominator. If ~0, line and plane are parallel.
//
num = vtkMath::Dot(n,p0) - ( n[0]*p1[0] + n[1]*p1[1] + n[2]*p1[2] ) ;
den = n[0]*p21[0] + n[1]*p21[1] + n[2]*p21[2];
//
// If denominator with respect to numerator is "zero", then the line and
// plane are considered parallel.
//
// trying to avoid an expensive call to fabs()
if (den < 0.0)
{
fabsden = -den;
}
else
{
fabsden = den;
}
if (num < 0.0)
{
fabstolerance = -num*VTK_PLANE_TOL;
}
else
{
fabstolerance = num*VTK_PLANE_TOL;
}
if ( fabsden <= fabstolerance )
{
t = VTK_DOUBLE_MAX;
return 0;
}
// valid intersection
t = num / den;
x[0] = p1[0] + t*p21[0];
x[1] = p1[1] + t*p21[1];
x[2] = p1[2] + t*p21[2];
if ( t >= 0.0 && t <= 1.0 )
{
return 1;
}
else
{
return 0;
}
}
this->ColorMap = vtkImageMapToColors::New();
this->ImageActor->GetMapper()->SetInputConnection(
this->ColorMap->GetOutputPort());
this->ColorMap->SetInputConnection(reslice->GetOutputPort());
void vtkResliceCursorRepresentation
::SetResliceParameters( double outputSpacingX, double outputSpacingY,
int extentX, int extentY )
{
vtkImageReslice *reslice = vtkImageReslice::SafeDownCast(this->Reslice);
if (reslice)
{
// Set the default color the minimum scalar value
double range[2];
vtkImageData::SafeDownCast(reslice->GetInput())->
GetScalarRange( range );
reslice->SetBackgroundLevel(range[0]);
this->ColorMap->SetInputConnection(reslice->GetOutputPort());
reslice->TransformInputSamplingOff();
reslice->AutoCropOutputOn();
reslice->SetResliceAxes(this->ResliceAxes);
reslice->SetOutputSpacing(outputSpacingX, outputSpacingY, 1);
reslice->SetOutputOrigin(0.5*outputSpacingX, 0.5*outputSpacingY, 0);
reslice->SetOutputExtent(0, extentX-1, 0, extentY-1, 0, 0);
}
}
//----------------------------------------------------------------------
void vtkResliceCursorRepresentation::BuildRepresentation()
{
this->Reslice->SetInputData(this->GetResliceCursor()->GetImage());
this->TexturePlaneActor->SetVisibility(
this->GetResliceCursor()->GetImage() ?
(this->ShowReslicedImage && !this->UseImageActor): 0);
this->ImageActor->SetVisibility(
this->GetResliceCursor()->GetImage() ?
(this->ShowReslicedImage && this->UseImageActor) : 0);
// Update the reslice plane if the plane is being manipulated
if (this->GetManipulationMode() != WindowLevelling )
{
this->UpdateReslicePlane();
}
this->ImageActor->SetDisplayExtent(this->ColorMap->GetOutput()->GetExtent());
// Update any text annotations
this->ManageTextDisplay();
}
void vtkResliceImageViewer::SetInputData(vtkImageData *in)
{
if(!in)
{
return;
}
this->WindowLevel->SetInputData(in);
this->GetResliceCursor()->SetImage(in);
this->GetResliceCursor()->SetCenter(in->GetCenter());
this->UpdateDisplayExtent();
double range[2];
in->GetScalarRange(range);
if (vtkResliceCursorRepresentation *rep =
vtkResliceCursorRepresentation::SafeDownCast(
this->ResliceCursorWidget->GetRepresentation()))
{
if (vtkImageReslice *reslice =
vtkImageReslice::SafeDownCast(rep->GetReslice()))
{
// default background color is the min value of the image scalar range
reslice->SetBackgroundColor(range[0],range[0],range[0],range[0]);
this->SetColorWindow(range[1]-range[0]);
this->SetColorLevel((range[0]+range[1])/2.0);
}
}
}
总结:Image数据流向路径
1.vtkResliceImageViewer::SetInputData中 vtkResliceCursor获取到数据
this->GetResliceCursor()->SetImage(in);
2.vtkResliceCursorRepresentation::BuildRepresentation中从vtkResliceCursor进入vtkImageReslice
this->Reslice->SetInputData(this->GetResliceCursor()->GetImage());
3.void vtkResliceCursorRepresentation::SetResliceParameters中从vtkImageReslice进入vtkImageMapToColors
this->ColorMap->SetInputConnection(reslice->GetOutputPort());
4.vtkResliceCursorRepresentation::vtkResliceCursorRepresentation中从vtkImageMapToColors进入vtkImageActor
this->ImageActor->GetMapper()->SetInputConnection(this->ColorMap->GetOutputPort());