コード例 #1
0
ファイル: mitkPlaneGeometry.cpp プロジェクト: AGrafmint/MITK
void
PlaneGeometry::InitializeStandardPlane( mitk::ScalarType width,
  ScalarType height, const AffineTransform3D* transform,
  PlaneGeometry::PlaneOrientation planeorientation, ScalarType zPosition,
  bool frontside, bool rotated )
{
  Superclass::Initialize();

  //construct standard view
  Point3D origin;
  VnlVector rightDV(3), bottomDV(3);
  origin.Fill(0);
  int normalDirection;
  switch(planeorientation)
  {
    case Axial:
      if(frontside)
      {
        if(rotated==false)
        {
          FillVector3D(origin,   0,  0, zPosition);
          FillVector3D(rightDV,  1,  0,         0);
          FillVector3D(bottomDV, 0,  1,         0);
        }
        else
        {
          FillVector3D(origin,   width,  height, zPosition);
          FillVector3D(rightDV,     -1,       0,         0);
          FillVector3D(bottomDV,     0,      -1,         0);
        }
      }
      else
      {
        if(rotated==false)
        {
          FillVector3D(origin,   width,  0, zPosition);
          FillVector3D(rightDV,     -1,  0,         0);
          FillVector3D(bottomDV,     0,  1,         0);
        }
        else
        {
          FillVector3D(origin,   0,  height, zPosition);
          FillVector3D(rightDV,  1,       0,         0);
          FillVector3D(bottomDV, 0,      -1,         0);
        }
      }
      normalDirection = 2;
      break;
    case Frontal:
      if(frontside)
      {
        if(rotated==false)
        {
          FillVector3D(origin,   0, zPosition, 0);
          FillVector3D(rightDV,  1, 0,         0);
          FillVector3D(bottomDV, 0, 0,         1);
        }
        else
        {
          FillVector3D(origin,   width, zPosition, height);
          FillVector3D(rightDV,     -1,         0,      0);
          FillVector3D(bottomDV,     0,         0,     -1);
        }
      }
      else
      {
        if(rotated==false)
        {
          FillVector3D(origin,    width, zPosition,  0);
          FillVector3D(rightDV,      -1,         0,  0);
          FillVector3D(bottomDV,      0,         0,  1);
        }
        else
        {
          FillVector3D(origin,   0, zPosition,  height);
          FillVector3D(rightDV,  1,         0,       0);
          FillVector3D(bottomDV, 0,         0,      -1);
        }
      }
      normalDirection = 1;
      break;
    case Sagittal:
      if(frontside)
      {
        if(rotated==false)
        {
          FillVector3D(origin,   zPosition, 0, 0);
          FillVector3D(rightDV,  0,         1, 0);
          FillVector3D(bottomDV, 0,         0, 1);
        }
        else
        {
          FillVector3D(origin,   zPosition, width, height);
          FillVector3D(rightDV,          0,    -1,      0);
          FillVector3D(bottomDV,         0,     0,     -1);
        }
      }
      else
      {
        if(rotated==false)
        {
          FillVector3D(origin,   zPosition,  width, 0);
          FillVector3D(rightDV,          0,     -1, 0);
          FillVector3D(bottomDV,         0,      0, 1);
        }
        else
        {
          FillVector3D(origin,   zPosition,  0, height);
          FillVector3D(rightDV,          0,  1,      0);
          FillVector3D(bottomDV,         0,  0,     -1);
        }
      }
      normalDirection = 0;
      break;
    default:
      itkExceptionMacro("unknown PlaneOrientation");
  }
  if ( transform != NULL )
  {
    origin = transform->TransformPoint( origin );
    rightDV = transform->TransformVector( rightDV );
    bottomDV = transform->TransformVector( bottomDV );
  }

  ScalarType bounds[6]= { 0, width, 0, height, 0, 1 };
  this->SetBounds( bounds );

  if ( transform == NULL )
  {
    this->SetMatrixByVectors( rightDV, bottomDV );
  }
  else
  {
    this->SetMatrixByVectors(
      rightDV, bottomDV,
      transform->GetMatrix().GetVnlMatrix()
        .get_column(normalDirection).magnitude()
    );
  }

  this->SetOrigin(origin);
}
コード例 #2
0
ファイル: mitkPlaneGeometry.cpp プロジェクト: 0r/MITK
  void
  PlaneGeometry::InitializeStandardPlane( mitk::ScalarType width, mitk::ScalarType height,
                                          const AffineTransform3D* transform /* = nullptr */,
                                          PlaneGeometry::PlaneOrientation planeorientation /* = Axial */,
                                          mitk::ScalarType zPosition /* = 0 */,
                                          bool frontside /* = true */,
                                          bool rotated /* = false */ )
  {
    Superclass::Initialize();

    /// construct standard view.

    // We define at the moment "frontside" as: axial from above,
    // coronal from front (nose), saggital from right.
    // TODO: Double check with medicals doctors or radiologists [ ].

    // We define the orientation in patient's view, e.g. LAI is in a axial cut
    // (parallel to the triangle ear-ear-nose):
    // first axis: To the left ear of the patient
    // seecond axis: To the nose of the patient
    // third axis: To the legs of the patient.

    // Options are: L/R left/right; A/P anterior/posterior; I/S inferior/superior
    // (AKA caudal/cranial).
    // We note on all cases in the following switch block r.h. for right handed
    // or l.h. for left handed to describe the different cases.
    // However, which system is chosen is defined at the end of the switch block.

    // CAVE / be careful: the vectors right and bottom are relative to the plane
    // and do NOT describe e.g. the right side of the patient.

    Point3D origin;
    /** Bottom means downwards, DV means Direction Vector. Both relative to the image! */
    VnlVector rightDV(3), bottomDV(3);
    /** Origin of this plane is by default a zero vector and implicitly in the top-left corner: */
    origin.Fill(0);
    /** This is different to all definitions in MITK, except the QT mouse clicks.
    *   But it is like this here and we don't want to change a running system.
    *   Just be aware, that IN THIS FUNCTION we define the origin at the top left (e.g. your screen). */

    /** NormalDirection defines which axis (i.e. column index in the transform matrix)
    * is perpendicular to the plane: */
    int normalDirection;

    switch(planeorientation) // Switch through our limited choice of standard planes:
    {
      case None:
        /** Orientation 'None' shall be done like the axial plane orientation,
         *  for whatever reasons. */
      case Axial:
        if(frontside) // Radiologist's view from below. A cut along the triangle ear-ear-nose.
        {
          if(rotated==false)
            /** Origin in the top-left corner, x=[1; 0; 0], y=[0; 1; 0], z=[0; 0; 1],
            *   origin=[0,0,zpos]: LAI (r.h.)
            *
            *  0---rightDV---->                            |
            *  |                                           |
            *  |  Picture of a finite, rectangular plane   |
            *  |  ( insert LOLCAT-scan here ^_^ )          |
            *  |                                           |
            *  v  _________________________________________|
            *
            */
          {
            FillVector3D(origin,   0,  0, zPosition);
            FillVector3D(rightDV,  1,  0,         0);
            FillVector3D(bottomDV, 0,  1,         0);
          }
          else  // Origin rotated to the bottom-right corner, x=[-1; 0; 0], y=[0; -1; 0], z=[0; 0; 1],
               // origin=[w,h,zpos]: RPI (r.h.)
          {   // Caveat emptor:  Still  using  top-left  as  origin  of  index  coordinate  system!
            FillVector3D(origin,   width,  height, zPosition);
            FillVector3D(rightDV,     -1,       0,         0);
            FillVector3D(bottomDV,     0,      -1,         0);
          }
        }
        else // 'Backside, not frontside.' Neuro-Surgeons's view from above patient.
        {
          if(rotated==false) // x=[-1; 0; 0], y=[0; 1; 0], z=[0; 0; 1], origin=[w,0,zpos]:  RAS (r.h.)
          {
            FillVector3D(origin,   width,  0, zPosition);
            FillVector3D(rightDV,     -1,  0,         0);
            FillVector3D(bottomDV,     0,  1,         0);
          }
          else // Origin in the bottom-left corner, x=[1; 0; 0], y=[0; -1; 0], z=[0; 0; 1],
              // origin=[0,h,zpos]:  LPS (r.h.)
          {
            FillVector3D(origin,   0,  height, zPosition);
            FillVector3D(rightDV,  1,       0,         0);
            FillVector3D(bottomDV, 0,      -1,         0);
          }
        }
        normalDirection = 2; // That is S=Superior=z=third_axis=middlefinger in righthanded LPS-system.
      break;

      // Frontal is known as Coronal in mitk. Plane cuts through patient's ear-ear-heel-heel:
      case Frontal:
        if(frontside)
        {
          if(rotated==false) // x=[1; 0; 0], y=[0; 0; 1], z=[0; 1; 0], origin=[0,zpos,0]: LAI (r.h.)
          {
            FillVector3D(origin,   0, zPosition, 0);
            FillVector3D(rightDV,  1, 0,         0);
            FillVector3D(bottomDV, 0, 0,         1);
          }
          else // x=[-1;0;0], y=[0;0;-1], z=[0;1;0], origin=[w,zpos,h]:  RAS  (r.h.)
          {
            FillVector3D(origin,   width, zPosition, height);
            FillVector3D(rightDV,     -1,         0,      0);
            FillVector3D(bottomDV,     0,         0,     -1);
          }
        }
        else
        {
          if(rotated==false) //  x=[-1;0;0], y=[0;0;1], z=[0;1;0], origin=[w,zpos,0]: RPI (r.h.)
          {
            FillVector3D(origin,    width, zPosition,  0);
            FillVector3D(rightDV,      -1,         0,  0);
            FillVector3D(bottomDV,      0,         0,  1);
          }
          else //  x=[1;0;0], y=[0;1;0], z=[0;0;-1], origin=[0,zpos,h]: LPS (r.h.)
          {
            FillVector3D(origin,   0, zPosition,  height);
            FillVector3D(rightDV,  1,         0,       0);
            FillVector3D(bottomDV, 0,         0,      -1);
          }
        }
        normalDirection = 1; // Normal vector = posterior direction.
      break;

      case Sagittal: // Sagittal=Medial plane, the symmetry-plane mirroring your face.
        if(frontside)
        {
          if(rotated==false) //  x=[0;1;0], y=[0;0;1], z=[1;0;0], origin=[zpos,0,0]:  LAI (r.h.)
          {
            FillVector3D(origin,   zPosition, 0, 0);
            FillVector3D(rightDV,  0,         1, 0);
            FillVector3D(bottomDV, 0,         0, 1);
          }
          else //  x=[0;-1;0], y=[0;0;-1], z=[1;0;0], origin=[zpos,w,h]:  LPS (r.h.)
          {
            FillVector3D(origin,   zPosition, width, height);
            FillVector3D(rightDV,          0,    -1,      0);
            FillVector3D(bottomDV,         0,     0,     -1);
          }
        }
        else
        {
          if(rotated==false) //  x=[0;-1;0], y=[0;0;1], z=[1;0;0], origin=[zpos,w,0]:  RPI (r.h.)
          {
            FillVector3D(origin,   zPosition,  width, 0);
            FillVector3D(rightDV,          0,     -1, 0);
            FillVector3D(bottomDV,         0,      0, 1);
          }
          else //  x=[0;1;0], y=[0;0;-1], z=[1;0;0], origin=[zpos,0,h]:  RAS (r.h.)
          {
            FillVector3D(origin,   zPosition,  0, height);
            FillVector3D(rightDV,          0,  1,      0);
            FillVector3D(bottomDV,         0,  0,     -1);
          }
        }
        normalDirection = 0; // Normal vector = Lateral direction: Left in a LPS-system.
      break;

      default:
        itkExceptionMacro("unknown PlaneOrientation");
    }

    /// Checking if lefthanded or righthanded:
    mitk::ScalarType lhOrRhSign=(+1);
    if ( transform != nullptr )
    {
      lhOrRhSign = ( (0 < vnl_determinant( transform->GetMatrix().GetVnlMatrix() )) ? (+1) : (-1) );

      MITK_DEBUG << "mitk::PlaneGeometry::InitializeStandardPlane(): lhOrRhSign, normalDirection, NameOfClass, ObjectName = "
                 << lhOrRhSign << ", " << normalDirection << ", " << transform->GetNameOfClass()
                 << ", " << transform->GetObjectName() << ".";

      origin = transform->TransformPoint( origin );
      rightDV = transform->TransformVector( rightDV );
      bottomDV = transform->TransformVector( bottomDV );

      /// Signing normal vector according to l.h./r.h. coordinate system:
      this->SetMatrixByVectors( rightDV,
                                bottomDV,
                                transform->GetMatrix().GetVnlMatrix().get_column(normalDirection).two_norm() * lhOrRhSign );
    }
    else if ( transform == nullptr )
    {
      this->SetMatrixByVectors( rightDV, bottomDV );
    }

    ScalarType bounds[6]= { 0, width, 0, height, 0, 1 };

    this->SetBounds( bounds );

    this->SetOrigin( origin );
  }