vtk mpr部分調用堆棧分析

給定由兩點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());

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章