コード例 #1
0
mitk::AffineTransform3D::Pointer mitk::NeedleProjectionFilter::NavigationDataToTransform(const mitk::NavigationData * nd)
{
  mitk::AffineTransform3D::Pointer affineTransform = mitk::AffineTransform3D::New();
  affineTransform->SetIdentity();

  //calculate the transform from the quaternions
  static itk::QuaternionRigidTransform<double>::Pointer quatTransform = itk::QuaternionRigidTransform<double>::New();

  mitk::NavigationData::OrientationType orientation = nd->GetOrientation();
  // convert mitk::ScalarType quaternion to double quaternion because of itk bug
  vnl_quaternion<double> doubleQuaternion(orientation.x(), orientation.y(), orientation.z(), orientation.r());
  quatTransform->SetIdentity();
  quatTransform->SetRotation(doubleQuaternion);
  quatTransform->Modified();

  /* because of an itk bug, the transform can not be calculated with float data type.
  To use it in the mitk geometry classes, it has to be transfered to mitk::ScalarType which is float */
  static AffineTransform3D::MatrixType m;
  mitk::TransferMatrix(quatTransform->GetMatrix(), m);
  affineTransform->SetMatrix(m);

  /*set the offset by convert from itkPoint to itkVector and setting offset of transform*/
  mitk::Vector3D pos;
  pos.SetVnlVector(nd->GetPosition().GetVnlVector());
  affineTransform->SetOffset(pos);

  affineTransform->Modified();
  return affineTransform;
}
コード例 #2
0
void mitk::NavigationDataObjectVisualizationFilter::GenerateData()
{
  /*get each input, lookup the associated BaseData and transfer the data*/
  DataObjectPointerArray inputs = this->GetInputs(); //get all inputs
  for (unsigned int index=0; index < inputs.size(); index++)
  {
    //get the needed variables
    const mitk::NavigationData* nd = this->GetInput(index);
    assert(nd);

    mitk::NavigationData* output = this->GetOutput(index);
    assert(output);

    //check if the data is valid
    if (!nd->IsDataValid())
    {
      output->SetDataValid(false);
      continue;
    }
    output->Graft(nd); // copy all information from input to output
    const mitk::BaseData* data = this->GetRepresentationObject(index);
    if (data == NULL)
    {
      MITK_WARN << "No BaseData associated with input " << index;
      continue;
    }

    //get the transform from data
    mitk::AffineTransform3D::Pointer affineTransform = data->GetGeometry()->GetIndexToWorldTransform();
    if (affineTransform.IsNull())
    {
      MITK_WARN << "AffineTransform IndexToWorldTransform not initialized!";
      continue;
    }

    //check for offset
    mitk::AffineTransform3D::Pointer offset = this->GetOffset(index);

    //store the current scaling to set it after transformation
    mitk::Vector3D spacing = data->GetGeometry()->GetSpacing();
    //clear spacing of data to be able to set it again afterwards
    ScalarType scale[] = {1.0, 1.0, 1.0};
    data->GetGeometry()->SetSpacing(scale);

    /*now bring quaternion to affineTransform by using vnl_Quaternion*/
    affineTransform->SetIdentity();

    if (this->GetTransformOrientation(index) == true)
    {
      mitk::NavigationData::OrientationType orientation = nd->GetOrientation();

      /* because of an itk bug, the transform can not be calculated with float data type.
      To use it in the mitk geometry classes, it has to be transfered to mitk::ScalarType which is float */
      static AffineTransform3D::MatrixType m;

      //convert quaternion to rotation matrix depending on the rotation mode
      if(m_RotationMode == RotationStandard)
        {
        //calculate the transform from the quaternions
        static itk::QuaternionRigidTransform<double>::Pointer quatTransform = itk::QuaternionRigidTransform<double>::New();
        // convert mitk::ScalarType quaternion to double quaternion because of itk bug
        vnl_quaternion<double> doubleQuaternion(orientation.x(), orientation.y(), orientation.z(), orientation.r());
        quatTransform->SetIdentity();
        quatTransform->SetRotation(doubleQuaternion);
        quatTransform->Modified();
        mitk::TransferMatrix(quatTransform->GetMatrix(), m);
        }

      else if(m_RotationMode == RotationTransposed)
        {
        vnl_matrix_fixed<mitk::ScalarType,3,3> rot = orientation.rotation_matrix_transpose();
        for(int i=0; i<3; i++) for (int j=0; j<3; j++) m[i][j] = rot[i][j];
        }
      affineTransform->SetMatrix(m);

    }
    if (this->GetTransformPosition(index) == true)
    {
      ///*set the offset by convert from itkPoint to itkVector and setting offset of transform*/
      mitk::Vector3D pos;
      pos.SetVnlVector(nd->GetPosition().GetVnlVector());
      affineTransform->SetOffset(pos);
    }
    affineTransform->Modified();


    //set the transform to data
    if(offset.IsNotNull()) //first use offset if there is one.
      {
      mitk::AffineTransform3D::Pointer overallTransform = mitk::AffineTransform3D::New();
      overallTransform->SetIdentity();
      overallTransform->Compose(offset);
      overallTransform->Compose(affineTransform);
      data->GetGeometry()->SetIndexToWorldTransform(overallTransform);
      }
    else
      {
      data->GetGeometry()->SetIndexToWorldTransform(affineTransform);
      }

    //set the original spacing to keep scaling of the geometrical object
    data->GetGeometry()->SetSpacing(spacing);
    data->GetGeometry()->Modified();
    data->Modified();
    output->SetDataValid(true); // operation was successful, therefore data of output is valid.
  }
  //m_Measurement->AddMeasurement(10);
}