Beispiel #1
0
void mitk::BaseGeometry::_SetSpacing(const mitk::Vector3D& aSpacing, bool enforceSetSpacing){
  if(mitk::Equal(m_Spacing, aSpacing) == false || enforceSetSpacing)
  {
    assert(aSpacing[0]>0 && aSpacing[1]>0 && aSpacing[2]>0);

    m_Spacing = aSpacing;

    AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix;

    vnlmatrix = m_IndexToWorldTransform->GetMatrix().GetVnlMatrix();

    mitk::VnlVector col;
    col = vnlmatrix.get_column(0); col.normalize(); col*=aSpacing[0]; vnlmatrix.set_column(0, col);
    col = vnlmatrix.get_column(1); col.normalize(); col*=aSpacing[1]; vnlmatrix.set_column(1, col);
    col = vnlmatrix.get_column(2); col.normalize(); col*=aSpacing[2]; vnlmatrix.set_column(2, col);

    Matrix3D matrix;
    matrix = vnlmatrix;

    AffineTransform3D::Pointer transform = AffineTransform3D::New();
    transform->SetMatrix(matrix);
    transform->SetOffset(m_IndexToWorldTransform->GetOffset());

    SetIndexToWorldTransform(transform.GetPointer());
  }
}
Beispiel #2
0
void
PlaneGeometry::SetMatrixByVectors( const VnlVector &rightVector,
  const VnlVector &downVector, ScalarType thickness )
{
  VnlVector normal = vnl_cross_3d(rightVector, downVector);
  normal.normalize();
  normal *= thickness;

  AffineTransform3D::Pointer transform = AffineTransform3D::New();
  Matrix3D matrix;
  matrix.GetVnlMatrix().set_column(0, rightVector);
  matrix.GetVnlMatrix().set_column(1, downVector);
  matrix.GetVnlMatrix().set_column(2, normal);
  transform->SetMatrix(matrix);
  transform->SetOffset(m_IndexToWorldTransform->GetOffset());
  SetIndexToWorldTransform(transform);
}
Beispiel #3
0
  void
  PlaneGeometry::SetMatrixByVectors( const VnlVector &rightVector,
                                     const VnlVector &downVector, ScalarType thickness /* = 1.0 */ )
  {
    VnlVector normal = vnl_cross_3d(rightVector, downVector);
    normal.normalize();
    normal *= thickness;
    // Crossproduct vnl_cross_3d is always righthanded, but that is okay here
    // because in this method we create a new IndexToWorldTransform and
    // a negative thickness could still make it lefthanded.

    AffineTransform3D::Pointer transform = AffineTransform3D::New();
    Matrix3D matrix;
    matrix.GetVnlMatrix().set_column(0, rightVector);
    matrix.GetVnlMatrix().set_column(1, downVector);
    matrix.GetVnlMatrix().set_column(2, normal);
    transform->SetMatrix(matrix);
    transform->SetOffset(this->GetIndexToWorldTransform()->GetOffset());
    SetIndexToWorldTransform(transform);
  }
Beispiel #4
0
void mitk::TimeSlicedGeometry::InitializeEvenlyTimed(mitk::Geometry3D* geometry3D, unsigned int timeSteps)
{
  assert(geometry3D!=NULL);

  geometry3D->Register();

  InitializeEmpty(timeSteps);

  AffineTransform3D::Pointer transform = AffineTransform3D::New();
  transform->SetMatrix(geometry3D->GetIndexToWorldTransform()->GetMatrix());
  transform->SetOffset(geometry3D->GetIndexToWorldTransform()->GetOffset());
  SetIndexToWorldTransform(transform);

  SetBounds(geometry3D->GetBounds());
  SetGeometry3D(geometry3D, 0);
  SetEvenlyTimed();

  UpdateInformation();

  SetFrameOfReferenceID(geometry3D->GetFrameOfReferenceID());
  SetImageGeometry(geometry3D->GetImageGeometry());

  geometry3D->UnRegister();
}
Beispiel #5
0
void mitk::TimeSlicedGeometry::UpdateInformation()
{
  if(m_TimeSteps==0) return;

  unsigned long maxModifiedTime = 0, curModifiedTime;

  mitk::ScalarType stmin, stmax;
  stmin= ScalarTypeNumericTraits::NonpositiveMin();
  stmax= ScalarTypeNumericTraits::max();

  TimeBounds timeBounds;
  timeBounds[0]=stmax; timeBounds[1]=stmin;

  mitk::BoundingBox::Pointer boundingBox=mitk::BoundingBox::New();

  mitk::BoundingBox::PointsContainer::Pointer pointscontainer=mitk::BoundingBox::PointsContainer::New();

  unsigned int t;

  mitk::Geometry3D* geometry3d;
  mitk::BoundingBox::ConstPointer nextBoundingBox;
  mitk::BoundingBox::PointIdentifier pointid=0;

  // Need to check for zero bounding boxes
  mitk::ScalarType zeropoint[]={0,0,0,0,0,0};
  BoundingBox::BoundsArrayType itkBoundsZero(zeropoint);

  for(t=0; t < m_TimeSteps; ++t)
  {
    geometry3d = GetGeometry3D(t);
    assert(geometry3d!=NULL);

    curModifiedTime = geometry3d->GetMTime();
    if(maxModifiedTime < curModifiedTime)
      maxModifiedTime = curModifiedTime;

    const TimeBounds & curTimeBounds = geometry3d->GetTimeBounds();
    if((curTimeBounds[0] > stmin) && (curTimeBounds[0] < timeBounds[0]))
      timeBounds[0] = curTimeBounds[0];
    if((curTimeBounds[1] < stmax) && (curTimeBounds[1] > timeBounds[1]))
      timeBounds[1] = curTimeBounds[1];

    nextBoundingBox = geometry3d->GetBoundingBox();
    assert(nextBoundingBox.IsNotNull());

    // Only respect non-zero BBes
    if (nextBoundingBox->GetBounds() == itkBoundsZero)
    {
      continue;
    }

    const mitk::BoundingBox::PointsContainer * nextPoints = nextBoundingBox->GetPoints();
    if(nextPoints!=NULL)
    {
      mitk::BoundingBox::PointsContainer::ConstIterator pointsIt = nextPoints->Begin();

      while (pointsIt != nextPoints->End() )
      {
        pointscontainer->InsertElement( pointid++, pointsIt->Value());
        ++pointsIt;
      }
    }
  }

  if(!(timeBounds[0] < stmax))
  {
    timeBounds[0] = stmin;
    timeBounds[1] = stmax;
  }

  m_TimeBounds = timeBounds;
  assert(timeBounds[0]<=timeBounds[1]);

  boundingBox->SetPoints(pointscontainer);

  boundingBox->ComputeBoundingBox();

  m_BoundingBox = boundingBox;

  SetIndexToWorldTransform(GetGeometry3D(0)->GetIndexToWorldTransform());

  if(this->GetMTime() < maxModifiedTime)
    Modified();
}