/**
 * Default constructor. Protected to prevent "normal" creation
 */
mitk::LabeledImageLookupTable::LabeledImageLookupTable()
  : m_LevelWindow(128,256)
{
  if ( m_LookupTable == NULL )
  {
    itkWarningMacro("LookupTable is NULL, it should have been initialized by the default constructor of mitk::LookupTable");
    m_LookupTable = vtkLookupTable::New();
  }
  m_LookupTable->SetNumberOfTableValues(256);
  
  // set the background to black and fully transparent
  m_LookupTable->SetTableValue( 0, 0.0, 0.0, 0.0, 0.0 ); 
  
  // initialize the remaining 255 colors with random values and 
  // an alpha value of 1.0
  vtkFloatingPointType r, g, b;
  
  //
  // Initialize the random number generator with an arbitrary seed.
  // This way, the generated colors are random, but always the same...
  std::srand( 2 );
  for ( vtkIdType index = 1 ; index < 256 ; ++index )
  {
    GenerateRandomColor(r, g, b);
    m_LookupTable->SetTableValue(index, r, g, b);
  }
  
  // initialize the default level/window settings,
  // which can be accessed via GetLevelWindow();
  m_LevelWindow.SetRangeMinMax(0,255);
  m_LevelWindow.SetWindowBounds(0,255);
  m_LevelWindow.SetFixed(true);
  
}
예제 #2
0
void mitk::PointLocator::SetPoints(vtkPointSet *pointSet)
{
  if (pointSet == nullptr)
  {
    itkWarningMacro("Points are NULL!");
    return;
  }
  vtkPoints *points = pointSet->GetPoints();

  if (m_VtkPoints)
  {
    if ((m_VtkPoints == points) && (m_VtkPoints->GetMTime() == points->GetMTime()))
    {
      return; // no need to recalculate search tree
    }
  }
  m_VtkPoints = points;

  size_t size = points->GetNumberOfPoints();
  if (m_ANNDataPoints != nullptr)
    delete[] m_ANNDataPoints;
  m_ANNDataPoints = annAllocPts(size, m_ANNDimension);
  m_IndexToPointIdContainer.clear();
  m_IndexToPointIdContainer.resize(size);
  for (vtkIdType i = 0; (unsigned)i < size; ++i)
  {
    double *currentPoint = points->GetPoint(i);
    (m_ANNDataPoints[i])[0] = currentPoint[0];
    (m_ANNDataPoints[i])[1] = currentPoint[1];
    (m_ANNDataPoints[i])[2] = currentPoint[2];
    m_IndexToPointIdContainer[i] = i;
  }
  InitANN();
}
void mitk::PointSetToCurvedGeometryFilter::GenerateOutputInformation()
{
  mitk::PointSet::ConstPointer input  = this->GetInput();
  mitk::Geometry2DData::Pointer output  = dynamic_cast<mitk::Geometry2DData*> ( this->GetOutput() );

  if ( input.IsNull() )
    itkGenericExceptionMacro ( "Input point set is NULL!" );

  if ( input->GetTimeGeometry()->CountTimeSteps() != 1 )
    itkWarningMacro ( "More than one time step is not yet supported!" );

  if ( output.IsNull() )
    itkGenericExceptionMacro ( "Output is NULL!" );

  if ( m_ImageToBeMapped.IsNull() )
    itkGenericExceptionMacro ( "Image to be mapped is NULL!" );

  bool update = false;
  if ( output->GetGeometry() == NULL || output->GetGeometry2D() == NULL || output->GetTimeGeometry() == NULL )
    update = true;
  if ( ( ! update ) && ( output->GetTimeGeometry()->CountTimeSteps() != input->GetTimeGeometry()->CountTimeSteps() ) )
    update = true;
  if ( update )
  {
    mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New();
    output->SetGeometry(curvedGeometry);
  }
}
/**
 * Sets the color for a given label
 * @param label The pixel value used as a label in the image
 * @param r The red component of the rgba color value. Values sould be given in the range [0,1]
 * @param g The green component of the rgba color value. Values sould be given in the range [0,1] 
 * @param b The blue component of the rgba color value. Values sould be given in the range [0,1]
 * @param a The alpha component of the rgba color value. Values sould be given in the range [0,1]. Default is 1.
 */
void mitk::LabeledImageLookupTable::SetColorForLabel ( const mitk::LabeledImageLookupTable::LabelType& label, const vtkFloatingPointType& r, const vtkFloatingPointType& g, const vtkFloatingPointType& b, const vtkFloatingPointType a )
{
  if ( m_LookupTable == NULL )
  {
    itkWarningMacro("LookupTable is NULL, but it should have been initialized by the constructor");
    return;
  }  
  m_LookupTable->SetTableValue(label, r, g, b, a);
}
/**
 * Determines the color which will be used for coloring a given label.
 * @param label the label for which the color should be returned
 * @returns an rgba array containing the color information for the given label
 *          Color components are expressed as [0,1] double values.
 */
vtkFloatingPointType* mitk::LabeledImageLookupTable::GetColorForLabel ( const mitk::LabeledImageLookupTable::LabelType& label )
{
  if ( m_LookupTable == NULL )
  {
    itkWarningMacro("LookupTable is NULL, but it should have been initialized by the constructor");
    return NULL;
  }
  return m_LookupTable->GetTableValue( label );
}
예제 #6
0
void mitk::BaseRenderer::SetWorldGeometry(mitk::Geometry3D* geometry)
{
    itkDebugMacro("setting WorldGeometry to " << geometry);

    if (m_WorldGeometry != geometry)
    {
        if (geometry->GetBoundingBox()->GetDiagonalLength2() == 0)
            return;

        m_WorldGeometry = geometry;
        m_TimeSlicedWorldGeometry = dynamic_cast<TimeSlicedGeometry*>(geometry);
        SlicedGeometry3D* slicedWorldGeometry;
        if (m_TimeSlicedWorldGeometry.IsNotNull())
        {
            itkDebugMacro("setting TimeSlicedWorldGeometry to " << m_TimeSlicedWorldGeometry);
            if (m_TimeStep >= m_TimeSlicedWorldGeometry->GetTimeSteps())
                m_TimeStep = m_TimeSlicedWorldGeometry->GetTimeSteps() - 1;
            slicedWorldGeometry = dynamic_cast<SlicedGeometry3D*>(m_TimeSlicedWorldGeometry->GetGeometry3D(m_TimeStep));
        }
        else
        {
            slicedWorldGeometry = dynamic_cast<SlicedGeometry3D*>(geometry);
        }
        Geometry2D::Pointer geometry2d;
        if (slicedWorldGeometry != NULL)
        {
            if (m_Slice >= slicedWorldGeometry->GetSlices() && (m_Slice != 0))
                m_Slice = slicedWorldGeometry->GetSlices() - 1;
            geometry2d = slicedWorldGeometry->GetGeometry2D(m_Slice);
            if (geometry2d.IsNull())
            {
                PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
                plane->InitializeStandardPlane(slicedWorldGeometry);
                geometry2d = plane;
            }
            SetCurrentWorldGeometry(slicedWorldGeometry);
        }
        else
        {
            geometry2d = dynamic_cast<Geometry2D*>(geometry);
            if (geometry2d.IsNull())
            {
                PlaneGeometry::Pointer plane = PlaneGeometry::New();
                plane->InitializeStandardPlane(geometry);
                geometry2d = plane;
            }
            SetCurrentWorldGeometry(geometry);
        }
        SetCurrentWorldGeometry2D(geometry2d); // calls Modified()
    }
    if (m_CurrentWorldGeometry2D.IsNull())
        itkWarningMacro("m_CurrentWorldGeometry2D is NULL");
}
 void SliceNavigationController::SetInputWorldGeometry3D(const BaseGeometry *geometry)
 {
 if ( geometry != nullptr )
   {
     if (const_cast<BoundingBox *>(geometry->GetBoundingBox())->GetDiagonalLength2() < eps)
     {
       itkWarningMacro("setting an empty bounding-box");
     geometry = nullptr;
     }
   }
   if (m_InputWorldGeometry3D != geometry)
   {
     m_InputWorldGeometry3D = geometry;
   m_InputWorldTimeGeometry = mitk::TimeGeometry::ConstPointer();
     this->Modified();
   }
 }
예제 #8
0
  void FiberBundleXReader
    ::GenerateData()
  {
    if ( ( ! m_OutputCache ) )
    {
      Superclass::SetNumberOfRequiredOutputs(0);
      this->GenerateOutputInformation();
    }

    if (!m_OutputCache)
    {
      itkWarningMacro("Output cache is empty!");
    }


    Superclass::SetNumberOfRequiredOutputs(1);
    Superclass::SetNthOutput(0, m_OutputCache.GetPointer());
  }
void
SliceNavigationController::SetInputWorldGeometry( const Geometry3D *geometry )
{
  if ( geometry != NULL )
  {
    if ( const_cast< BoundingBox * >( geometry->GetBoundingBox())
         ->GetDiagonalLength2() < eps )
    {
      itkWarningMacro( "setting an empty bounding-box" );
      geometry = NULL;
    }
  }
  if ( m_InputWorldGeometry != geometry )
  {
    m_InputWorldGeometry = geometry;
    this->Modified();
  }
}
void mitk::PointSetToCurvedGeometryFilter::GenerateOutputInformation()
{
  mitk::PointSet::ConstPointer input  = this->GetInput();
  mitk::Geometry2DData::Pointer output  = dynamic_cast<mitk::Geometry2DData*> ( this->GetOutput() );

  if ( input.IsNull() )
    itkGenericExceptionMacro ( "Input point set is NULL!" );

  if ( input->GetTimeSlicedGeometry()->GetTimeSteps() != 1 )
    itkWarningMacro ( "More than one time step is not yet supported!" );

  if ( output.IsNull() )
    itkGenericExceptionMacro ( "Output is NULL!" );

  if ( m_ImageToBeMapped.IsNull() )
    itkGenericExceptionMacro ( "Image to be mapped is NULL!" );

  bool update = false;
  if ( output->GetGeometry() == NULL || output->GetGeometry2D() == NULL || output->GetTimeSlicedGeometry() == NULL )
    update = true;
  if ( ( ! update ) && ( output->GetTimeSlicedGeometry()->GetTimeSteps() != input->GetTimeSlicedGeometry()->GetTimeSteps() ) )
    update = true;
  if ( update )
  {
    mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New();
    output->SetGeometry(curvedGeometry);

    /*
    mitk::TimeSlicedGeometry::Pointer timeGeometry = mitk::TimeSlicedGeometry::New();
    mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New();

    timeGeometry->InitializeEvenlyTimed ( curvedGeometry, input->GetPointSetSeriesSize() );

    for ( unsigned int t = 1; t < input->GetPointSetSeriesSize(); ++t )
    {
      mitk::ThinPlateSplineCurvedGeometry::Pointer tmpCurvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New();
      timeGeometry->SetGeometry3D ( tmpCurvedGeometry.GetPointer(), t );
    }
    output->SetGeometry ( timeGeometry );
    output->SetGeometry2D ( curvedGeometry ); // @FIXME SetGeometry2D of mitk::Geometry2DData reinitializes the TimeSlicedGeometry to 1 time step
    */
  }
}
예제 #11
0
void mitk::PointLocator::SetPoints(mitk::PointSet *points)
{
  if (points == nullptr)
  {
    itkWarningMacro("Points are NULL!");
    return;
  }

  if (m_MitkPoints)
  {
    if ((m_MitkPoints == points) && (m_MitkPoints->GetMTime() == points->GetMTime()))
    {
      return; // no need to recalculate search tree
    }
  }
  m_MitkPoints = points;

  size_t size = points->GetSize();
  if (m_ANNDataPoints != nullptr)
    delete[] m_ANNDataPoints;
  m_ANNDataPoints = annAllocPts(size, m_ANNDimension);
  m_IndexToPointIdContainer.clear();
  m_IndexToPointIdContainer.resize(size);
  size_t counter = 0;
  mitk::PointSet::PointsContainer *pointsContainer = points->GetPointSet()->GetPoints();
  mitk::PointSet::PointsContainer::Iterator it;
  mitk::PointSet::PointType currentPoint;
  mitk::PointSet::PointsContainer::ElementIdentifier currentId;
  for (it = pointsContainer->Begin(); it != pointsContainer->End(); ++it, ++counter)
  {
    currentPoint = it->Value();
    currentId = it->Index();
    (m_ANNDataPoints[counter])[0] = currentPoint[0];
    (m_ANNDataPoints[counter])[1] = currentPoint[1];
    (m_ANNDataPoints[counter])[2] = currentPoint[2];
    m_IndexToPointIdContainer[counter] = currentId;
  }
  InitANN();
}
예제 #12
0
void mitk::SplineMapper2D::Paint ( mitk::BaseRenderer * renderer )
{
  Superclass::Paint ( renderer );
  if ( IsVisible ( renderer ) == false )
    return;

  //
  // get the poly data of the splines in 3D
  //
  mitk::SplineVtkMapper3D::Pointer mapper3D = dynamic_cast<mitk::SplineVtkMapper3D*> ( this->GetDataNode()->GetMapper ( 2 ) );
  if ( mapper3D.IsNull() )
  {
    itkWarningMacro ( "Mapper used for 3D mapping is not a mitk::SplineVtkMapper3D!" );
    return;
  }
  //
  // update the 3D spline, if the accoring mapper has not been updated yet
  //
  if ( mapper3D->GetLastUpdateTime() < GetDataNode()->GetData()->GetMTime() )
    mapper3D->UpdateSpline();
  vtkPolyData* spline3D = NULL;
  if ( mapper3D->SplinesAreAvailable() )
    spline3D = mapper3D->GetSplinesPolyData();
  else
    return;
  if ( spline3D == NULL )
  {
    itkWarningMacro ( "3D spline is not available!" );
    return;
  }
  //
  // get the transform associated with the data tree node
  //
  vtkLinearTransform* transform = this->GetDataNode()->GetVtkTransform();
  if ( transform == NULL )
  {
    itkWarningMacro("transfrom is NULL");
  }

  //
  // get the plane geometry of the current renderer
  //
  mitk::Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D();
  if ( worldGeometry.IsNull() )
  {
    itkWarningMacro("worldGeometry is NULL!");
    return;
  }
  PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast<const mitk::PlaneGeometry*> ( worldGeometry.GetPointer() );
  if ( worldPlaneGeometry.IsNull() )
  {
    itkWarningMacro("worldPlaneGeometry is NULL!");
    return;
  }

  //
  // determine color of the spline
  //
  float color[3];
  this->GetDataNode()->GetColor ( color, renderer );

  //
  // iterate over the points
  //
  vtkPoints    *vpoints = spline3D->GetPoints();
  vtkCellArray *vlines  = spline3D->GetLines();
  if (vpoints == NULL)
  {
    itkWarningMacro("points are NULL!");
    return;
  }
  if (vlines == NULL)
  {
    itkWarningMacro("lines are NULL!");
    return;
  }

  mitk::Point3D currentPoint3D;
  mitk::Point2D currentPoint2D;
  vtkFloatingPointType currentPoint3DVtk[3];

  vlines->InitTraversal();
  int numberOfLines = vlines->GetNumberOfCells();
  vtkFloatingPointType currentPointDistance;
  for ( int i = 0;i < numberOfLines; ++i )
  {
    bool previousPointOnPlane = false;
    bool currentPointOnPlane = false;
    vtkIdType* cell ( NULL );
    vtkIdType cellSize ( 0 );
    vlines->GetNextCell ( cellSize, cell );
    for ( int j = 0 ; j < cellSize; ++j )
    {
      vpoints->GetPoint ( cell[j], currentPoint3DVtk );

      // take transformation via vtktransform into account
      transform->TransformPoint ( currentPoint3DVtk, currentPoint3DVtk );
      vtk2itk ( currentPoint3DVtk, currentPoint3D );

      // check if the point has a distance to the plane
      // which is smaller than m_MaxProjectionDistance
      currentPointDistance = worldPlaneGeometry->DistanceFromPlane ( currentPoint3D );

      if ( currentPointDistance < m_MaxProjectionDistance )
      {
        currentPointOnPlane = true;
        //convert 3D point (in mm) to 2D point on slice (also in mm)
        worldGeometry->Map ( currentPoint3D, currentPoint2D );
        //convert point (until now mm and in worldcoordinates) to display coordinates (units )
        renderer->GetDisplayGeometry()->WorldToDisplay ( currentPoint2D, currentPoint2D );
      }
      else
        currentPointOnPlane = false;

      //
      // check if we have to begin or end a GL_LINE
      //
      if ( ( previousPointOnPlane == false ) && ( currentPointOnPlane == true ) )
      {
        glLineWidth ( m_LineWidth );
        glColor3f ( color[0], color[1], color[2] );
        glBegin ( GL_LINE_STRIP );
      }
      else if ( ( previousPointOnPlane == true ) && ( currentPointOnPlane == false ) )
      {
        glEnd ();
        glLineWidth ( 1.0 );
      }
      // the current ponit is on the plane, add it as point to the
      // line segment
      if ( currentPointOnPlane == true )
      {
        glVertex2f ( currentPoint2D[0], currentPoint2D[1] );
      }
      previousPointOnPlane = currentPointOnPlane;
    }
    // the last point of the spline segment is on the plane, thus we have to
    // close the GL_LINE
    if ( previousPointOnPlane == true )
    {
      glEnd ();
      glLineWidth ( 1.0 );
    }
    previousPointOnPlane = false;
  }
}
예제 #13
0
bool mitk::FileSeriesReader::GenerateFileList()
{
    typedef std::vector<std::string> StringContainer;
    typedef std::map<unsigned int, std::string> SortedStringContainer;

    if ( m_FileName == "" )
    {
      throw itk::ImageFileReaderException( __FILE__, __LINE__, "FileName must be non-empty" );
    }
    //MITK_INFO << "FileName: "<< m_FileName <<", FilePrefix: "<< m_FilePrefix << ", FilePattern: "<< m_FilePattern << std::endl;

    // determine begin and end idexes of the last digit sequence in the
    // filename from the sample file name
    // Therefore, walk backwards from the end of the filename until
    // a number is found. The string in front of the number is the prefix,
    // the string after the number is the extension.
    std::string basename, path;
    path = itksys::SystemTools::GetFilenamePath( m_FileName );
    basename = itksys::SystemTools::GetFilenameName( m_FileName );

    unsigned int digitBegin = 0;
    unsigned int digitEnd = 0;
    bool digitFound = false;
    for ( unsigned int i = basename.length() - 1; ; --i )
    {
      char character = basename[ i ];
      if ( character >= '0' && character <= '9' )
      {
        if (!digitFound)
        {
          digitEnd = i;
          digitBegin = i;
          digitFound = true;
        }
        else
          digitBegin = i;
      }
      else
      {
        //end of digit series found, jump out of loop!
        if (digitFound)
          break;
      }
      if ( i == 0 )
        break;
    }

    //
    // if there is no digit in the filename, then we have a problem
    // no matching filenames can be identified!
    //
    if ( !digitFound )
    {
      itkWarningMacro("Filename contains no digit!");
      return false;
    }

    //
    // determine prefix and extension start and length
    //
    unsigned int prefixBegin = 0;
    unsigned int prefixLength = digitBegin;
    unsigned int extensionBegin = digitEnd + 1;
    unsigned int extensionLength = (digitEnd == basename.length() -1 ? 0 : basename.length() - 1 - digitEnd);
    unsigned int numberLength = digitEnd - digitBegin + 1;

    //
    // extract prefix and extension
    //
    std::string prefix = "";
    if (prefixLength != 0)
      prefix = basename.substr( prefixBegin, prefixLength );
    std::string extension = "";
    if (extensionLength != 0)
      extension = basename.substr( extensionBegin, extensionLength );

    //
    // print debug information
    //
    /*
    MITK_INFO << "digitBegin      : " << digitBegin << std::endl;
    MITK_INFO << "digitEnd        : " << digitEnd << std::endl;
    MITK_INFO << "number of digits: " << numberLength << std::endl;
    MITK_INFO << "prefixBegin     : " << prefixBegin << std::endl;
    MITK_INFO << "prefixLength    : " << prefixLength << std::endl;
    MITK_INFO << "prefix          : " << prefix << std::endl;
    MITK_INFO << "extensionBegin  : " << extensionBegin << std::endl;
    MITK_INFO << "extensionLength : " << extensionLength << std::endl;
    MITK_INFO << "extension       : " << extension << std::endl;
    */
    if( (prefixLength + extensionLength + numberLength) != basename.length() )
    {
      throw itk::ImageFileReaderException( __FILE__, __LINE__, "prefixLength + extensionLength + numberLength != basenameLength" );
    }


    //
    // Load Directory
    //
    std::string directory = itksys::SystemTools::GetFilenamePath( m_FileName );
    itksys::Directory itkDir;
    if ( !itkDir.Load ( directory.c_str() ) )
    {
      itkWarningMacro ( << "Directory " << directory << " cannot be read!" );
      return false;
    }
//##Documentation
//## overwritten cause this class can handle it better!
float mitk::ConnectPointsInteractor::CanHandleEvent(StateEvent const* stateEvent) const
{
  float returnValue = 0;
  
  mitk::PositionEvent const  *posEvent = dynamic_cast <const mitk::PositionEvent *> (stateEvent->GetEvent());
  //checking if a keyevent can be handled:
  if (posEvent == NULL)
  {
    //check, if the current state has a transition waiting for that key event.
    if (this->GetCurrentState()->GetTransition(stateEvent->GetId())!=NULL)
    {
      return 0.5;
    }
    else
    {
      return 0;
    }
  }

  //Mouse event handling:
  //on MouseMove do nothing! reimplement if needed differently
  if (stateEvent->GetEvent()->GetType() == mitk::Type_MouseMove)
  {
    return 0;
  }

  //check on the right data-type
  mitk::PointSet* pointSet = dynamic_cast<mitk::PointSet*>(m_DataNode->GetData());
  if (pointSet == NULL)
    return 0;


  //since we now have 3D picking in GlobalInteraction and all events send are DisplayEvents with 3D information,
  //we concentrate on 3D coordinates
  mitk::Point3D worldPoint = posEvent->GetWorldPosition();
  float p[3];
  itk2vtk(worldPoint, p);
  //transforming the Worldposition to local coordinatesystem
  m_DataNode->GetData()->GetGeometry()->GetVtkTransform()->GetInverse()->TransformPoint(p, p);
  vtk2itk(p, worldPoint);

  float distance = 5;
  int index = pointSet->SearchPoint(worldPoint, distance);
  if (index>-1)
    //how far away is the line from the point?
  {
    //get the point and calculate the jurisdiction out of it.
    mitk::PointSet::PointType point;
    pointSet->GetPointSet()->GetPoint(index, &point); 
    returnValue = point.EuclideanDistanceTo(worldPoint);

    //between 1 and 0.     1 if directly hit
    returnValue = 1 - ( returnValue / distance );
    if (returnValue<0 || returnValue>1)
    {
      itkWarningMacro("Difficulties in calculating Jurisdiction. Check PointInteractor");
      return 0;
    }
    
    //and now between 0,5 and 1
    returnValue = 0.5 + (returnValue / 2);

    return returnValue;
  }
  else //not found
  {
    return 0;
  }
}
예제 #15
0
void mitk::PointSet::ExecuteOperation( Operation* operation )
{
    int timeStep = -1;

    mitkCheckOperationTypeMacro(PointOperation, operation, pointOp);

    if ( pointOp )
    {
        timeStep = this->GetTimeGeometry()->TimePointToTimeStep( pointOp->GetTimeInMS() );
    }

    if ( timeStep < 0 )
    {
        MITK_ERROR << "Time step (" << timeStep << ") outside of PointSet time bounds" << std::endl;
        return;
    }

    switch (operation->GetOperationType())
    {
    case OpNOTHING:
        break;

    case OpINSERT://inserts the point at the given position and selects it.
    {
        int position = pointOp->GetIndex();

        PointType pt;
        pt.CastFrom(pointOp->GetPoint());

        //transfer from world to index coordinates
        mitk::Geometry3D* geometry = this->GetGeometry( timeStep );
        if (geometry == NULL)
        {
            MITK_INFO<<"GetGeometry returned NULL!\n";
            return;
        }
        geometry->WorldToIndex(pt, pt);

        m_PointSetSeries[timeStep]->GetPoints()->InsertElement(position, pt);

        PointDataType pointData =
        {
            static_cast<unsigned int>(pointOp->GetIndex()),
            pointOp->GetSelected(),
            pointOp->GetPointType()
        };

        m_PointSetSeries[timeStep]->GetPointData()
        ->InsertElement(position, pointData);

        this->Modified();

        //boundingbox has to be computed
        m_CalculateBoundingBox = true;

        this->InvokeEvent( PointSetAddEvent() );
        this->OnPointSetChange();
    }
    break;

    case OpMOVE://moves the point given by index
    {
        PointType pt;
        pt.CastFrom(pointOp->GetPoint());

        //transfer from world to index coordinates
        this->GetGeometry( timeStep )->WorldToIndex(pt, pt);

        // Copy new point into container
        m_PointSetSeries[timeStep]->SetPoint(pointOp->GetIndex(), pt);

        // Insert a default point data object to keep the containers in sync
        // (if no point data object exists yet)
        PointDataType pointData;
        if ( !m_PointSetSeries[timeStep]->GetPointData( pointOp->GetIndex(), &pointData ) )
        {
            m_PointSetSeries[timeStep]->SetPointData( pointOp->GetIndex(), pointData );
        }

        this->OnPointSetChange();

        this->Modified();

        //boundingbox has to be computed anyway
        m_CalculateBoundingBox = true;

        this->InvokeEvent( PointSetMoveEvent() );
    }
    break;

    case OpREMOVE://removes the point at given by position
    {
        m_PointSetSeries[timeStep]->GetPoints()->DeleteIndex((unsigned)pointOp->GetIndex());
        m_PointSetSeries[timeStep]->GetPointData()->DeleteIndex((unsigned)pointOp->GetIndex());

        this->OnPointSetChange();

        this->Modified();
        //boundingbox has to be computed anyway
        m_CalculateBoundingBox = true;

        this->InvokeEvent( PointSetRemoveEvent() );
    }
    break;

    case OpSELECTPOINT://select the given point
    {
        PointDataType pointData = {0, false, PTUNDEFINED};
        m_PointSetSeries[timeStep]->GetPointData(pointOp->GetIndex(), &pointData);
        pointData.selected = true;
        m_PointSetSeries[timeStep]->SetPointData(pointOp->GetIndex(), pointData);
        this->Modified();
    }
    break;

    case OpDESELECTPOINT://unselect the given point
    {
        PointDataType pointData = {0, false, PTUNDEFINED};
        m_PointSetSeries[timeStep]->GetPointData(pointOp->GetIndex(), &pointData);
        pointData.selected = false;
        m_PointSetSeries[timeStep]->SetPointData(pointOp->GetIndex(), pointData);
        this->Modified();
    }
    break;

    case OpSETPOINTTYPE:
    {
        PointDataType pointData = {0, false, PTUNDEFINED};
        m_PointSetSeries[timeStep]->GetPointData(pointOp->GetIndex(), &pointData);
        pointData.pointSpec = pointOp->GetPointType();
        m_PointSetSeries[timeStep]->SetPointData(pointOp->GetIndex(), pointData);
        this->Modified();
    }
    break;

    case OpMOVEPOINTUP: // swap content of point with ID pointOp->GetIndex() with the point preceding it in the container // move point position within the pointset
    {
        PointIdentifier currentID = pointOp->GetIndex();
        /* search for point with this id and point that precedes this one in the data container */
        PointsContainer::STLContainerType points = m_PointSetSeries[timeStep]->GetPoints()->CastToSTLContainer();
        PointsContainer::STLContainerType::iterator it = points.find(currentID);
        if (it == points.end()) // ID not found
            break;
        if (it == points.begin()) // we are at the first element, there is no previous element
            break;

        /* get and cache current point & pointdata and previous point & pointdata */
        --it;
        PointIdentifier prevID = it->first;
        if (this->SwapPointContents(prevID, currentID, timeStep) == true)
            this->Modified();
    }
    break;
    case OpMOVEPOINTDOWN: // move point position within the pointset
    {
        PointIdentifier currentID = pointOp->GetIndex();
        /* search for point with this id and point that succeeds this one in the data container */
        PointsContainer::STLContainerType points = m_PointSetSeries[timeStep]->GetPoints()->CastToSTLContainer();
        PointsContainer::STLContainerType::iterator it = points.find(currentID);
        if (it == points.end()) // ID not found
            break;
        ++it;
        if (it == points.end()) // ID is already the last element, there is no succeeding element
            break;

        /* get and cache current point & pointdata and previous point & pointdata */
        PointIdentifier nextID = it->first;
        if (this->SwapPointContents(nextID, currentID, timeStep) == true)
            this->Modified();
    }
    break;

    default:
        itkWarningMacro("mitkPointSet could not understrand the operation. Please check!");
        break;
    }

    //to tell the mappers, that the data is modified and has to be updated
    //only call modified if anything is done, so call in cases
    //this->Modified();

    mitk::OperationEndEvent endevent(operation);
    ((const itk::Object*)this)->InvokeEvent(endevent);

    //*todo has to be done here, cause of update-pipeline not working yet
    // As discussed lately, don't mess with the rendering from inside data structures
    //mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}
예제 #16
0
 void TestItkWarningMessage()
   {
   itkWarningMacro("Test ITK Warning message");
   }
예제 #17
0
void mitk::ExtrudedContour::BuildGeometry()
{
  if(m_Contour.IsNull())
    return;

//  Initialize(1);

  Vector3D nullvector; nullvector.Fill(0.0);
  float xProj[3];
  unsigned int i;
  unsigned int numPts = 20; //m_Contour->GetNumberOfPoints();
  mitk::Contour::PathPointer path = m_Contour->GetContourPath();
  mitk::Contour::PathType::InputType cstart = path->StartOfInput();
  mitk::Contour::PathType::InputType cend   = path->EndOfInput();
  mitk::Contour::PathType::InputType cstep  = (cend-cstart)/numPts;
  mitk::Contour::PathType::InputType ccur;

  // Part I: guarantee/calculate legal vectors

  m_Vector.Normalize();
  itk2vtk(m_Vector, m_Normal);
  // check m_Vector
  if(mitk::Equal(m_Vector, nullvector) || m_AutomaticVectorGeneration)
  {
    if ( m_AutomaticVectorGeneration == false)
      itkWarningMacro("Extrusion vector is 0 ("<< m_Vector << "); trying to use normal of polygon");

    vtkPoints *loopPoints = vtkPoints::New();
    //mitk::Contour::PointsContainerIterator pointsIt = m_Contour->GetPoints()->Begin();
    double vtkpoint[3];

    unsigned int i=0;
    for(i=0, ccur=cstart; i<numPts; ++i, ccur+=cstep)
    {
      itk2vtk(path->Evaluate(ccur), vtkpoint);
      loopPoints->InsertNextPoint(vtkpoint);
    }

    // Make sure points define a loop with a m_Normal
    vtkPolygon::ComputeNormal(loopPoints, m_Normal);
    loopPoints->Delete();

    vtk2itk(m_Normal, m_Vector);
    if(mitk::Equal(m_Vector, nullvector))
    {
      itkExceptionMacro("Cannot calculate normal of polygon");
    }
  }
  // check m_RightVector
  if((mitk::Equal(m_RightVector, nullvector)) || (mitk::Equal(m_RightVector*m_Vector, 0.0)==false))
  {
    if(mitk::Equal(m_RightVector, nullvector))
    {
      itkDebugMacro("Right vector is 0. Calculating.");
    }
    else
    {
      itkWarningMacro("Right vector ("<<m_RightVector<<") not perpendicular to extrusion vector "<<m_Vector<<": "<<m_RightVector*m_Vector);
    }
    // calculate a legal m_RightVector
    if( mitk::Equal( m_Vector[1], 0.0f ) == false )
    {
      FillVector3D( m_RightVector, 1.0f, -m_Vector[0]/m_Vector[1], 0.0f );
      m_RightVector.Normalize();
    }
    else
    {
      FillVector3D( m_RightVector, 0.0f, 1.0f, 0.0f );
    }
  }

  // calculate down-vector
  VnlVector rightDV = m_RightVector.GetVnlVector(); rightDV.normalize(); vnl2vtk(rightDV, m_Right);
  VnlVector downDV  = vnl_cross_3d( m_Vector.GetVnlVector(), rightDV ); downDV.normalize();  vnl2vtk(downDV,  m_Down);

  // Part II: calculate plane as base for extrusion, project the contour
  // on this plane and store as polygon for IsInside test and BoundingBox calculation

  // initialize m_ProjectionPlane, yet with origin at 0
  m_ProjectionPlane->InitializeStandardPlane(rightDV, downDV);

  // create vtkPolygon from contour and simultaneously determine 2D bounds of
  // contour projected on m_ProjectionPlane
  //mitk::Contour::PointsContainerIterator pointsIt = m_Contour->GetPoints()->Begin();
  m_Polygon->Points->Reset();
  m_Polygon->Points->SetNumberOfPoints(numPts);
  m_Polygon->PointIds->Reset();
  m_Polygon->PointIds->SetNumberOfIds(numPts);
  mitk::Point2D pt2d;
  mitk::Point3D pt3d;
  mitk::Point2D min, max;
  min.Fill(ScalarTypeNumericTraits::max());
  max.Fill(ScalarTypeNumericTraits::min());
  xProj[2]=0.0;
  for(i=0, ccur=cstart; i<numPts; ++i, ccur+=cstep)
  {
    pt3d.CastFrom(path->Evaluate(ccur));
    m_ProjectionPlane->Map(pt3d, pt2d);
    xProj[0]=pt2d[0];
    if(pt2d[0]<min[0]) min[0]=pt2d[0];
    if(pt2d[0]>max[0]) max[0]=pt2d[0];
    xProj[1]=pt2d[1];
    if(pt2d[1]<min[1]) min[1]=pt2d[1];
    if(pt2d[1]>max[1]) max[1]=pt2d[1];
    m_Polygon->Points->SetPoint(i, xProj);
    m_Polygon->PointIds->SetId(i, i);
  }
  // shift parametric origin to (0,0)
  for(i=0; i<numPts; ++i)
  {
    double * pt = this->m_Polygon->Points->GetPoint(i);

    pt[0]-=min[0]; pt[1]-=min[1];
    itkDebugMacro( << i << ": (" << pt[0] << "," << pt[1] << "," << pt[2] << ")" );
  }
  this->m_Polygon->GetBounds(m_ProjectedContourBounds);
  //m_ProjectedContourBounds[4]=-1.0; m_ProjectedContourBounds[5]=1.0;

  // calculate origin (except translation along the normal) and bounds
  // of m_ProjectionPlane:
  //  origin is composed of the minimum x-/y-coordinates of the polygon,
  //  bounds from the extent of the polygon, both after projecting on the plane
  mitk::Point3D origin;
  m_ProjectionPlane->Map(min, origin);
  ScalarType bounds[6]={0, max[0]-min[0], 0, max[1]-min[1], 0, 1};
  m_ProjectionPlane->SetBounds(bounds);
  m_ProjectionPlane->SetOrigin(origin);

  // Part III: initialize geometry
  if(m_ClippingGeometry.IsNotNull())
  {
    ScalarType min_dist=ScalarTypeNumericTraits::max(), max_dist=ScalarTypeNumericTraits::min(), dist;
    unsigned char i;
    for(i=0; i<8; ++i)
    {
      dist = m_ProjectionPlane->SignedDistance( m_ClippingGeometry->GetCornerPoint(i) );
      if(dist<min_dist) min_dist=dist;
      if(dist>max_dist) max_dist=dist;
    }
    //incorporate translation along the normal into origin
    origin = origin+m_Vector*min_dist;
    m_ProjectionPlane->SetOrigin(origin);
    bounds[5]=max_dist-min_dist;
  }
  else
    bounds[5]=20;

  itk2vtk(origin, m_Origin);

  mitk::Geometry3D::Pointer g3d = GetGeometry( 0 );
  assert( g3d.IsNotNull() );
  g3d->SetBounds(bounds);
  g3d->SetIndexToWorldTransform(m_ProjectionPlane->GetIndexToWorldTransform());
  g3d->TransferItkToVtkTransform();

  ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New();
  timeGeometry->Initialize(g3d,1);
  SetTimeGeometry(timeGeometry);

}