Exemplo n.º 1
0
void mitk::VtkPropRenderer::PickWorldPoint(const mitk::Point2D &displayPoint, mitk::Point3D &worldPoint) const
{
  if (this->GetRenderWindow()->GetNeverRendered() != 0)
    return; // somebody called picking before we ever rendered; cannot have enough information yet

  switch (m_PickingMode)
  {
    case (WorldPointPicking):
    {
      m_WorldPointPicker->Pick(displayPoint[0], displayPoint[1], 0, m_VtkRenderer);
      vtk2itk(m_WorldPointPicker->GetPickPosition(), worldPoint);
      break;
    }
    case (PointPicking):
    {
      m_PointPicker->Pick(displayPoint[0], displayPoint[1], 0, m_VtkRenderer);
      vtk2itk(m_PointPicker->GetPickPosition(), worldPoint);
      break;
    }
    case (CellPicking):
    {
      m_CellPicker->Pick(displayPoint[0], displayPoint[1], 0, m_VtkRenderer);
      vtk2itk(m_CellPicker->GetPickPosition(), worldPoint);
      break;
    }
  }
  // todo: is this picking in 2D renderwindows?
  //    Superclass::PickWorldPoint(displayPoint, worldPoint);
}
Exemplo n.º 2
0
void mitk::VtkPropRenderer::PickWorldPoint(const mitk::Point2D& displayPoint, mitk::Point3D& worldPoint) const
{
  if(m_VtkMapperPresent)
  {
    //m_WorldPointPicker->SetTolerance (0.0001);
    switch ( m_PickingMode )
    {
    case (WorldPointPicking) :
      {
        m_WorldPointPicker->Pick(displayPoint[0], displayPoint[1], 0, m_VtkRenderer);
        vtk2itk(m_WorldPointPicker->GetPickPosition(), worldPoint);
        break;
      }
    case (PointPicking) :
      {
        // create a new vtkRenderer
        // give it all necessary information (camera position, etc.)
        // get all surfaces from datastorage, get actors from them
        // add all those actors to the new renderer
        // give this new renderer to pointpicker
        /*
       vtkRenderer* pickingRenderer = vtkRenderer::New();
       pickingRenderer->SetActiveCamera( );

       DataStorage* dataStorage = m_DataStorage;
       TNodePredicateDataType<Surface> isSurface;

       DataStorage::SetOfObjects::ConstPointer allSurfaces = dataStorage->GetSubset( isSurface );
       MITK_INFO << "in picking: got " << allSurfaces->size() << " surfaces." << std::endl;

       for (DataStorage::SetOfObjects::const_iterator iter = allSurfaces->begin();
            iter != allSurfaces->end();
            ++iter)
       {
         const DataNode* currentNode = *iter;
         VtkMapper3D* baseVtkMapper3D = dynamic_cast<VtkMapper3D*>( currentNode->GetMapper( BaseRenderer::Standard3D ) );
         if ( baseVtkMapper3D )
         {
           vtkActor* actor = dynamic_cast<vtkActor*>( baseVtkMapper3D->GetViewProp() );
           if (actor)
           {
             MITK_INFO << "a" << std::flush;
             pickingRenderer->AddActor( actor );
           }
         }
       }

       MITK_INFO << ";" << std::endl;
       */
        m_PointPicker->Pick(displayPoint[0], displayPoint[1], 0, m_VtkRenderer);
        vtk2itk(m_PointPicker->GetPickPosition(), worldPoint);
        break;
      }
    }
  }
  else
  {
    Superclass::PickWorldPoint(displayPoint, worldPoint);
  }
}
Exemplo n.º 3
0
void mitk::BaseGeometry::TransferVtkToItkTransform()
{
  TransferVtkMatrixToItkTransform(m_VtkMatrix, m_IndexToWorldTransform.GetPointer());
  CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing);
  vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin);
  TransferItkToVtkTransform();
}
Exemplo n.º 4
0
void mitk::BaseGeometry::Compose( const mitk::BaseGeometry::TransformType * other, bool pre )
{
  mitk::ModifiedLock lock(this);

  m_IndexToWorldTransform->Compose(other, pre);
  CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing);
  vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin);
  Modified();
  TransferItkToVtkTransform();
}
Exemplo n.º 5
0
void mitk::BaseGeometry::SetIndexToWorldTransform(mitk::AffineTransform3D* transform)
{
  mitk::ModifiedLock lock(this);

  PreSetIndexToWorldTransform(transform);

  m_IndexToWorldTransform = transform;
  CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing);
  vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin);
  TransferItkToVtkTransform();
  Modified();

  PostSetIndexToWorldTransform(transform);

}
Exemplo n.º 6
0
void mitk::BaseGeometry::Initialize()
{
  float b[6] = {0,1,0,1,0,1};
  SetFloatBounds(b);

  if(m_IndexToWorldTransform.IsNull())
    m_IndexToWorldTransform = TransformType::New();
  else
    m_IndexToWorldTransform->SetIdentity();
  CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing);
  vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin);

  m_VtkMatrix->Identity();

  //m_TimeBounds[0]=ScalarTypeNumericTraits::NonpositiveMin(); m_TimeBounds[1]=ScalarTypeNumericTraits::max();

  m_FrameOfReferenceID = 0;

  m_ImageGeometry = false;

  this->PostInitialize();
}
Exemplo n.º 7
0
void mitk::ContourMapper2D::Paint(mitk::BaseRenderer * renderer)
  {
  if(IsVisible(renderer)==false) return;

  ////  @FIXME: Logik fuer update
  bool updateNeccesary=true;

  if (updateNeccesary) 
    {
    mitk::Contour::Pointer input =  const_cast<mitk::Contour*>(this->GetInput());

    // ok, das ist aus GenerateData kopiert
    mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
    assert(displayGeometry.IsNotNull());

    //apply color and opacity read from the PropertyList
    ApplyProperties(renderer);

    vtkLinearTransform* transform = GetDataNode()->GetVtkTransform();

    //    Contour::OutputType point;
    Contour::BoundingBoxType::PointType point;

    mitk::Point3D p, projected_p;
    float vtkp[3];
    float lineWidth = 3.0;

    if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("Width")) != NULL)
      lineWidth = dynamic_cast<mitk::FloatProperty*>(this->GetDataNode()->GetProperty("Width"))->GetValue();
    glLineWidth(lineWidth);

    if (input->GetClosed())
      {
      glBegin (GL_LINE_LOOP);
      }
    else 
      {
      glBegin (GL_LINE_STRIP);
      }

    //Contour::InputType end = input->GetContourPath()->EndOfInput();
    //if (end > 50000) end = 0;

    mitk::Contour::PointsContainerPointer points = input->GetPoints();
    mitk::Contour::PointsContainerIterator pointsIt = points->Begin();



    while ( pointsIt != points->End() )
      {
      //while ( idx != end )
      //{
      //      point = input->GetContourPath()->Evaluate(idx);
      point = pointsIt.Value();

      itk2vtk(point, vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp,p);

      displayGeometry->Project(p, projected_p);
      bool projectmode=false;
      GetDataNode()->GetVisibility(projectmode, renderer, "project");
      bool drawit=false;
      if(projectmode)
        drawit=true;
      else
      {
        Vector3D diff=p-projected_p;
        if(diff.GetSquaredNorm()<1.0)
          drawit=true;
      }
      if(drawit)
      {
        Point2D pt2d, tmp;
        displayGeometry->Map(projected_p, pt2d);
        displayGeometry->WorldToDisplay(pt2d, pt2d);
        glVertex2f(pt2d[0], pt2d[1]);
      }

      pointsIt++;
      //      idx += 1;
      }
    glEnd ();

    glLineWidth(1.0);

    }
  }
Exemplo n.º 8
0
mitk::DataNode *
    mitk::VtkPropRenderer::PickObject( const Point2D &displayPosition, Point3D &worldPosition ) const
{
  if ( m_VtkMapperPresent )
  {
    m_CellPicker->InitializePickList();

    // Iterate over all DataStorage objects to determine all vtkProps intended
    // for picking
    DataStorage::SetOfObjects::ConstPointer allObjects = m_DataStorage->GetAll();
    for ( DataStorage::SetOfObjects::ConstIterator it = allObjects->Begin();
    it != allObjects->End();
    ++it )
    {
      DataNode *node = it->Value();
      if ( node == NULL )
        continue;

      bool pickable = false;
      node->GetBoolProperty( "pickable", pickable );
      if ( !pickable )
        continue;

      VtkMapper *mapper = dynamic_cast < VtkMapper * >  ( node->GetMapper( m_MapperID ) );
      if ( mapper == NULL )
        continue;

      vtkProp *prop = mapper->GetVtkProp( (mitk::BaseRenderer *)this );
      if ( prop == NULL )
        continue;

      m_CellPicker->AddPickList( prop );
    }

    // Do the picking and retrieve the picked vtkProp (if any)
    m_CellPicker->PickFromListOn();
    m_CellPicker->Pick( displayPosition[0], displayPosition[1], 0.0, m_VtkRenderer );
    m_CellPicker->PickFromListOff();

    vtk2itk( m_CellPicker->GetPickPosition(), worldPosition );
    vtkProp *prop = m_CellPicker->GetViewProp();

    if ( prop == NULL )
    {
      return NULL;
    }

    // Iterate over all DataStorage objects to determine if the retrieved
    // vtkProp is owned by any associated mapper.
    for ( DataStorage::SetOfObjects::ConstIterator it = allObjects->Begin();
    it != allObjects->End();
    ++it)
    {
      DataNode::Pointer node = it->Value();
      if ( node.IsNull() )
        continue;

      mitk::Mapper * mapper = node->GetMapper( m_MapperID );
      if ( mapper == NULL)
        continue;

      mitk::VtkMapper * vtkmapper = dynamic_cast< VtkMapper * >(mapper);

      if(vtkmapper){
        //if vtk-based, then ...
       if ( vtkmapper->HasVtkProp( prop, const_cast< mitk::VtkPropRenderer * >( this ) ) )
       {
          return node;
       }
      }
    }

    return NULL;
  }
  else
  {
    return Superclass::PickObject( displayPosition, worldPosition );
  }
};
Exemplo n.º 9
0
void mitk::SurfaceGLMapper2D::PaintCells(mitk::BaseRenderer* renderer, vtkPolyData* contour,
                                       const PlaneGeometry* worldGeometry,
                                       const DisplayGeometry* displayGeometry,
                                       vtkLinearTransform * vtktransform,
                                       vtkLookupTable *lut,
                                       vtkPolyData* original3DObject)
{
  // deprecated settings
  bool usePointData = false;

  bool useCellData = false;
  this->GetDataNode()->GetBoolProperty("deprecated useCellDataForColouring", useCellData, renderer);

  bool scalarVisibility = false;
  this->GetDataNode()->GetBoolProperty("scalar visibility", scalarVisibility, renderer);

  if(scalarVisibility)
  {
    VtkScalarModeProperty* scalarMode;
    if(this->GetDataNode()->GetProperty(scalarMode, "scalar mode", renderer))
    {
      if( (scalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_POINT_DATA) ||
        (scalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_DEFAULT) )
      {
        usePointData = true;
      }
      if(scalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA)
      {
        useCellData = true;
      }
    }
    else
    {
      usePointData = true;
    }
  }

  vtkPoints    *vpoints = contour->GetPoints();
  vtkDataArray *vpointscalars = contour->GetPointData()->GetScalars();

  vtkCellArray *vlines  = contour->GetLines();
  vtkDataArray* vcellscalars = contour->GetCellData()->GetScalars();

  Point3D p; Point2D p2d, last;
  int i, j;
  int numberOfLines = vlines->GetNumberOfCells();

  glLineWidth( m_LineWidth );
  glBegin (GL_LINES);

  glColor4fv(m_LineColor);

  double distanceSinceLastNormal(0.0);

  vlines->InitTraversal();
  for(i=0;i<numberOfLines;++i)
  {
    vtkIdType *cell(NULL);
    vtkIdType cellSize(0);
    double vp[3];

    vlines->GetNextCell(cellSize, cell);

    vpoints->GetPoint(cell[0], vp);
    //take transformation via vtktransform into account
    vtktransform->TransformPoint(vp, vp);
    vtk2itk(vp, p);

    //convert 3D point (in mm) to 2D point on slice (also in mm)
    worldGeometry->Map(p, p2d);

    //convert point (until now mm and in world coordinates) to display coordinates (units )
    displayGeometry->WorldToDisplay(p2d, p2d);
    last=p2d;

    for(j=1; j<cellSize; ++j)
    {
      vpoints->GetPoint(cell[j], vp);
      Point3D originalPoint;
      vtk2itk(vp, originalPoint);
      //take transformation via vtktransform into account
      vtktransform->TransformPoint(vp, vp);
      vtk2itk(vp, p);

      //convert 3D point (in mm) to 2D point on slice (also in mm)
      worldGeometry->Map(p, p2d);

      //convert point (until now mm and in world coordinates) to display coordinates (units )
      displayGeometry->WorldToDisplay(p2d, p2d);

      double color[3];
      if (useCellData && vcellscalars != NULL )
      {
        // color each cell according to cell data
        lut->GetColor( vcellscalars->GetComponent(i,0),color);
        glColor3f(color[0],color[1],color[2]);
        glVertex2f(last[0], last[1]);
        glVertex2f(p2d[0], p2d[1]);
      }
      else if (usePointData && vpointscalars != NULL )
      {
        lut->GetColor( vpointscalars->GetComponent(cell[j-1],0),color);
        glColor3f(color[0],color[1],color[2]);
        glVertex2f(last[0], last[1]);
        lut->GetColor( vpointscalars->GetComponent(cell[j],0),color);
        glColor3f(color[0],color[1],color[2]);
        glVertex2f(p2d[0], p2d[1]);
      }
      else
      {
        glVertex2f(last[0], last[1]);
        glVertex2f(p2d[0], p2d[1]);

        // draw normals ?
        if (m_DrawNormals && original3DObject)
        {
          distanceSinceLastNormal += sqrt((p2d[0]-last[0])*(p2d[0]-last[0]) + (p2d[1]-last[1])*(p2d[1]-last[1]));
          if (distanceSinceLastNormal >= 5.0)
          {
            distanceSinceLastNormal = 0.0;

            vtkPointData* pointData = original3DObject->GetPointData();
            if (!pointData) break;

            vtkDataArray* normalsArray = pointData->GetNormals();
            if (!normalsArray) break;

            // find 3D point closest to the currently drawn point
            double distance(0.0);
            vtkIdType closestPointId = m_PointLocator->FindClosestPoint(originalPoint[0], originalPoint[1], originalPoint[2], distance);
            if (closestPointId >= 0)
            {
              // find normal of 3D object at this 3D point
              double* normal = normalsArray->GetTuple3(closestPointId);
              double transformedNormal[3];
              vtktransform->TransformNormal(normal, transformedNormal);

              Vector3D normalITK;
              vtk2itk(transformedNormal, normalITK);
              normalITK.Normalize();

              // calculate a point (point from the cut 3D object) + (normal vector of closest point)
              Point3D tip3D = p + normalITK;

              // map this point into our 2D coordinate system
              Point2D tip2D;
              worldGeometry->Map(tip3D, tip2D);

              displayGeometry->WorldToDisplay(tip2D, tip2D);

              // calculate 2D vector from point to point+normal, normalize it to standard length
              Vector2D tipVectorGLFront = tip2D - p2d;
              tipVectorGLFront.Normalize();
              tipVectorGLFront *= m_FrontNormalLengthInPixels;

              Vector2D tipVectorGLBack = p2d - tip2D;
              tipVectorGLBack.Normalize();
              tipVectorGLBack *= m_BackNormalLengthInPixels;

              Point2D tipPoint2D = p2d + tipVectorGLFront;
              Point2D backTipPoint2D = p2d + tipVectorGLBack;

              // draw normalized mapped normal vector
              glColor4f(m_BackSideColor[0], m_BackSideColor[1], m_BackSideColor[2], m_BackSideColor[3]); // red backside
              glVertex2f(p2d[0], p2d[1]);
              glVertex2f(tipPoint2D[0], tipPoint2D[1]);
              glColor4f(m_FrontSideColor[0], m_FrontSideColor[1], m_FrontSideColor[2], m_FrontSideColor[3]); // green backside
              glVertex2f(p2d[0], p2d[1]);
              glVertex2f(backTipPoint2D[0], backTipPoint2D[1]);
              glColor4fv(m_LineColor); // back to line color
            }
          }
        }
      }
      last=p2d;
    }
  }

  glEnd();
  glLineWidth(1.0);
}
void mitk::ContourSetMapper2D::Paint(mitk::BaseRenderer *renderer)
{
  bool visible = true;
  GetDataNode()->GetVisibility(visible, renderer, "visible");

  if (!visible)
    return;

  ////  @FIXME: Logik fuer update
  bool updateNeccesary = true;

  if (updateNeccesary)
  {
    // apply color and opacity read from the PropertyList
    ApplyColorAndOpacityProperties(renderer);

    mitk::ContourSet::Pointer input = const_cast<mitk::ContourSet *>(this->GetInput());
    mitk::ContourSet::ContourVectorType contourVec = input->GetContours();
    mitk::ContourSet::ContourIterator contourIt = contourVec.begin();

    while (contourIt != contourVec.end())
    {
      mitk::Contour::Pointer nextContour = (mitk::Contour::Pointer)(*contourIt).second;
      vtkLinearTransform *transform = GetDataNode()->GetVtkTransform();

      //    Contour::OutputType point;
      Contour::BoundingBoxType::PointType point;

      mitk::Point3D p, projected_p;
      float vtkp[3];

      glLineWidth(nextContour->GetWidth());

      if (nextContour->GetClosed())
      {
        glBegin(GL_LINE_LOOP);
      }
      else
      {
        glBegin(GL_LINE_STRIP);
      }

      // float rgba[4]={1.0f,1.0f,1.0f,1.0f};
      // if ( nextContour->GetSelected() )
      //{
      //  rgba[0] = 1.0;
      //  rgba[1] = 0.0;
      //  rgba[2] = 0.0;
      //}
      // glColor4fv(rgba);

      mitk::Contour::PointsContainerPointer points = nextContour->GetPoints();
      mitk::Contour::PointsContainerIterator pointsIt = points->Begin();

      while (pointsIt != points->End())
      {
        point = pointsIt.Value();

        itk2vtk(point, vtkp);
        transform->TransformPoint(vtkp, vtkp);
        vtk2itk(vtkp, p);

        renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
        Vector3D diff = p - projected_p;
        if (diff.GetSquaredNorm() < 1.0)
        {
          Point2D pt2d, tmp;
          renderer->WorldToDisplay(p, pt2d);
          glVertex2f(pt2d[0], pt2d[1]);
        }

        pointsIt++;
        //      idx += 1;
      }

      glEnd();

      glLineWidth(1.0);

      contourIt++;
    }
  }
}
void mitk::ContourModelSetGLMapper2D::InternalDrawContour(mitk::ContourModel *renderingContour,
                                                          mitk::BaseRenderer *renderer)
{
  if (!renderingContour)
    return;

  mitk::DataNode *dataNode = this->GetDataNode();

  renderingContour->UpdateOutputInformation();

  unsigned int timestep = renderer->GetTimeStep();

  if (!renderingContour->IsEmptyTimeStep(timestep))
  {
    // apply color and opacity read from the PropertyList
    ApplyColorAndOpacityProperties(renderer);

    mitk::ColorProperty::Pointer colorprop =
      dynamic_cast<mitk::ColorProperty *>(dataNode->GetProperty("contour.color", renderer));
    float opacity = 0.5;
    dataNode->GetFloatProperty("opacity", opacity, renderer);

    if (colorprop)
    {
      // set the color of the contour
      double red = colorprop->GetColor().GetRed();
      double green = colorprop->GetColor().GetGreen();
      double blue = colorprop->GetColor().GetBlue();
      glColor4f(red, green, blue, opacity);
    }

    mitk::ColorProperty::Pointer selectedcolor =
      dynamic_cast<mitk::ColorProperty *>(dataNode->GetProperty("contour.points.color", renderer));
    if (!selectedcolor)
    {
      selectedcolor = mitk::ColorProperty::New(1.0, 0.0, 0.1);
    }

    vtkLinearTransform *transform = dataNode->GetVtkTransform();

    //    ContourModel::OutputType point;
    mitk::Point3D point;

    mitk::Point3D p;
    float vtkp[3];
    float lineWidth = 3.0;

    bool drawit = false;

    bool isHovering = false;
    dataNode->GetBoolProperty("contour.hovering", isHovering);

    if (isHovering)
      dataNode->GetFloatProperty("contour.hovering.width", lineWidth);
    else
      dataNode->GetFloatProperty("contour.width", lineWidth);

    bool showSegments = false;
    dataNode->GetBoolProperty("contour.segments.show", showSegments);

    bool showControlPoints = false;
    dataNode->GetBoolProperty("contour.controlpoints.show", showControlPoints);

    bool showPoints = false;
    dataNode->GetBoolProperty("contour.points.show", showPoints);

    bool showPointsNumbers = false;
    dataNode->GetBoolProperty("contour.points.text", showPointsNumbers);

    bool showControlPointsNumbers = false;
    dataNode->GetBoolProperty("contour.controlpoints.text", showControlPointsNumbers);

    bool projectmode = false;
    dataNode->GetVisibility(projectmode, renderer, "contour.project-onto-plane");

    mitk::ContourModel::VertexIterator pointsIt = renderingContour->IteratorBegin(timestep);

    Point2D pt2d; // projected_p in display coordinates
    Point2D lastPt2d;

    int index = 0;

    mitk::ScalarType maxDiff = 0.25;

    while (pointsIt != renderingContour->IteratorEnd(timestep))
    {
      lastPt2d = pt2d;

      point = (*pointsIt)->Coordinates;

      itk2vtk(point, vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp, p);

      renderer->WorldToDisplay(p, pt2d);

      ScalarType scalardiff = fabs(renderer->GetCurrentWorldPlaneGeometry()->SignedDistance(p));

      // project to plane
      if (projectmode)
      {
        drawit = true;
      }
      else if (scalardiff < maxDiff) // point is close enough to be drawn
      {
        drawit = true;
      }
      else
      {
        drawit = false;
      }

      // draw line
      if (drawit)
      {
        if (showSegments)
        {
          // lastPt2d is not valid in first step
          if (!(pointsIt == renderingContour->IteratorBegin(timestep)))
          {
            glLineWidth(lineWidth);
            glBegin(GL_LINES);
            glVertex2f(pt2d[0], pt2d[1]);
            glVertex2f(lastPt2d[0], lastPt2d[1]);
            glEnd();
            glLineWidth(1);
          }
        }

        if (showControlPoints)
        {
          // draw ontrol points
          if ((*pointsIt)->IsControlPoint)
          {
            float pointsize = 4;
            Point2D tmp;

            Vector2D horz, vert;
            horz[1] = 0;
            vert[0] = 0;
            horz[0] = pointsize;
            vert[1] = pointsize;
            glColor3f(selectedcolor->GetColor().GetRed(),
                      selectedcolor->GetColor().GetBlue(),
                      selectedcolor->GetColor().GetGreen());
            glLineWidth(1);
            // a rectangle around the point with the selected color
            glBegin(GL_LINE_LOOP);
            tmp = pt2d - horz;
            glVertex2dv(&tmp[0]);
            tmp = pt2d + vert;
            glVertex2dv(&tmp[0]);
            tmp = pt2d + horz;
            glVertex2dv(&tmp[0]);
            tmp = pt2d - vert;
            glVertex2dv(&tmp[0]);
            glEnd();
            glLineWidth(1);
            // the actual point in the specified color to see the usual color of the point
            glColor3f(
              colorprop->GetColor().GetRed(), colorprop->GetColor().GetGreen(), colorprop->GetColor().GetBlue());
            glPointSize(1);
            glBegin(GL_POINTS);
            tmp = pt2d;
            glVertex2dv(&tmp[0]);
            glEnd();
          }
        }

        if (showPoints)
        {
          float pointsize = 3;
          Point2D tmp;

          Vector2D horz, vert;
          horz[1] = 0;
          vert[0] = 0;
          horz[0] = pointsize;
          vert[1] = pointsize;
          glColor3f(0.0, 0.0, 0.0);
          glLineWidth(1);
          // a rectangle around the point with the selected color
          glBegin(GL_LINE_LOOP);
          tmp = pt2d - horz;
          glVertex2dv(&tmp[0]);
          tmp = pt2d + vert;
          glVertex2dv(&tmp[0]);
          tmp = pt2d + horz;
          glVertex2dv(&tmp[0]);
          tmp = pt2d - vert;
          glVertex2dv(&tmp[0]);
          glEnd();
          glLineWidth(1);
          // the actual point in the specified color to see the usual color of the point
          glColor3f(colorprop->GetColor().GetRed(), colorprop->GetColor().GetGreen(), colorprop->GetColor().GetBlue());
          glPointSize(1);
          glBegin(GL_POINTS);
          tmp = pt2d;
          glVertex2dv(&tmp[0]);
          glEnd();
        }

        if (showPointsNumbers)
        {
          std::string l;
          std::stringstream ss;
          ss << index;
          l.append(ss.str());

          float rgb[3];
          rgb[0] = 0.0;
          rgb[1] = 0.0;
          rgb[2] = 0.0;

          WriteTextWithAnnotation(m_PointNumbersAnnotation, l.c_str(), rgb, pt2d, renderer);
        }

        if (showControlPointsNumbers && (*pointsIt)->IsControlPoint)
        {
          std::string l;
          std::stringstream ss;
          ss << index;
          l.append(ss.str());

          float rgb[3];
          rgb[0] = 1.0;
          rgb[1] = 1.0;
          rgb[2] = 0.0;

          WriteTextWithAnnotation(m_ControlPointNumbersAnnotation, l.c_str(), rgb, pt2d, renderer);
        }

        index++;
      }

      pointsIt++;
    } // end while iterate over controlpoints

    // close contour if necessary
    if (renderingContour->IsClosed(timestep) && drawit && showSegments)
    {
      lastPt2d = pt2d;
      point = renderingContour->GetVertexAt(0, timestep)->Coordinates;
      itk2vtk(point, vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp, p);
      renderer->WorldToDisplay(p, pt2d);

      glLineWidth(lineWidth);
      glBegin(GL_LINES);
      glVertex2f(lastPt2d[0], lastPt2d[1]);
      glVertex2f(pt2d[0], pt2d[1]);
      glEnd();
      glLineWidth(1);
    }

    // draw selected vertex if exists
    if (renderingContour->GetSelectedVertex())
    {
      // transform selected vertex
      point = renderingContour->GetSelectedVertex()->Coordinates;

      itk2vtk(point, vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp, p);

      renderer->WorldToDisplay(p, pt2d);

      ScalarType scalardiff = fabs(renderer->GetCurrentWorldPlaneGeometry()->SignedDistance(p));
      //----------------------------------

      // draw point if close to plane
      if (scalardiff < maxDiff)
      {
        float pointsize = 5;
        Point2D tmp;
        glColor3f(0.0, 1.0, 0.0);
        glLineWidth(1);
        // a diamond around the point
        glBegin(GL_LINE_LOOP);
        // begin from upper left corner and paint clockwise
        tmp[0] = pt2d[0] - pointsize;
        tmp[1] = pt2d[1] + pointsize;
        glVertex2dv(&tmp[0]);
        tmp[0] = pt2d[0] + pointsize;
        tmp[1] = pt2d[1] + pointsize;
        glVertex2dv(&tmp[0]);
        tmp[0] = pt2d[0] + pointsize;
        tmp[1] = pt2d[1] - pointsize;
        glVertex2dv(&tmp[0]);
        tmp[0] = pt2d[0] - pointsize;
        tmp[1] = pt2d[1] - pointsize;
        glVertex2dv(&tmp[0]);
        glEnd();
      }
      //------------------------------------
    }
  }
}
Exemplo n.º 12
0
void mitk::MeshMapper2D::Paint(mitk::BaseRenderer *renderer)
{
  bool visible = true;

  GetDataNode()->GetVisibility(visible, renderer, "visible");

  if (!visible)
    return;

  //  @FIXME: Logik fuer update
  bool updateNeccesary = true;

  if (updateNeccesary)
  {
    // aus GenerateData
    mitk::Mesh::Pointer input = const_cast<mitk::Mesh *>(this->GetInput());

    // Get the TimeGeometry of the input object
    const TimeGeometry *inputTimeGeometry = input->GetTimeGeometry();
    if ((inputTimeGeometry == NULL) || (inputTimeGeometry->CountTimeSteps() == 0))
    {
      return;
    }

    //
    // get the world time
    //
    ScalarType time = renderer->GetTime();

    //
    // convert the world time in time steps of the input object
    //
    int timeStep = 0;
    if (time > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin())
      timeStep = inputTimeGeometry->TimePointToTimeStep(time);
    if (inputTimeGeometry->IsValidTimeStep(timeStep) == false)
    {
      return;
    }

    mitk::Mesh::MeshType::Pointer itkMesh = input->GetMesh(timeStep);

    if (itkMesh.GetPointer() == NULL)
    {
      return;
    }

    const PlaneGeometry *worldplanegeometry = (renderer->GetCurrentWorldPlaneGeometry());

    // apply color and opacity read from the PropertyList
    ApplyColorAndOpacityProperties(renderer);

    vtkLinearTransform *transform = GetDataNode()->GetVtkTransform();

    // List of the Points
    Mesh::DataType::PointsContainerConstIterator it, end;
    it = itkMesh->GetPoints()->Begin();
    end = itkMesh->GetPoints()->End();

    // iterator on the additional data of each point
    Mesh::PointDataIterator dataIt; //, dataEnd;
    dataIt = itkMesh->GetPointData()->Begin();

    // for switching back to old color after using selected color
    float unselectedColor[4];
    glGetFloatv(GL_CURRENT_COLOR, unselectedColor);

    while (it != end)
    {
      mitk::Point3D p, projected_p;
      float vtkp[3];

      itk2vtk(it->Value(), vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp, p);

      renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
      Vector3D diff = p - projected_p;
      if (diff.GetSquaredNorm() < 4.0)
      {
        Point2D pt2d, tmp;
        renderer->WorldToDisplay(p, pt2d);

        Vector2D horz, vert;
        horz[0] = 5;
        horz[1] = 0;
        vert[0] = 0;
        vert[1] = 5;

        // check if the point is to be marked as selected
        if (dataIt->Value().selected)
        {
          horz[0] = 8;
          vert[1] = 8;
          glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red

          switch (dataIt->Value().pointSpec)
          {
            case PTSTART:
            {
              // a quad
              glBegin(GL_LINE_LOOP);
              tmp = pt2d - horz + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz - vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d - horz - vert;
              glVertex2dv(&tmp[0]);
              glEnd();
            }
            break;
            case PTUNDEFINED:
            {
              // a diamond around the point
              glBegin(GL_LINE_LOOP);
              tmp = pt2d - horz;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz;
              glVertex2dv(&tmp[0]);
              tmp = pt2d - vert;
              glVertex2dv(&tmp[0]);
              glEnd();
            }
            break;
            default:
              break;
          } // switch

          // the actual point
          glBegin(GL_POINTS);
          tmp = pt2d;
          glVertex2dv(&tmp[0]);
          glEnd();
        }
        else // if not selected
        {
          glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
          switch (dataIt->Value().pointSpec)
          {
            case PTSTART:
            {
              // a quad
              glBegin(GL_LINE_LOOP);
              tmp = pt2d - horz + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz - vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d - horz - vert;
              glVertex2dv(&tmp[0]);
              glEnd();
            }
            case PTUNDEFINED:
            {
              // drawing crosses
              glBegin(GL_LINES);
              tmp = pt2d - horz;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz;
              glVertex2dv(&tmp[0]);
              tmp = pt2d - vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + vert;
              glVertex2dv(&tmp[0]);
              glEnd();
            }
            default:
            {
              break;
            }
          } // switch
        }   // else
      }
      ++it;
      ++dataIt;
    }

    // now connect the lines inbetween
    mitk::Mesh::PointType thisPoint;
    thisPoint.Fill(0);
    Point2D *firstOfCell = NULL;
    Point2D *lastPoint = NULL;
    unsigned int lastPointId = 0;
    bool lineSelected = false;

    Point3D firstOfCell3D;
    Point3D lastPoint3D;
    bool first;
    mitk::Line<mitk::ScalarType> line;
    std::vector<mitk::Point3D> intersectionPoints;
    double t;

    // iterate through all cells and then iterate through all indexes of points in that cell
    Mesh::CellIterator cellIt, cellEnd;
    Mesh::CellDataIterator cellDataIt; //, cellDataEnd;
    Mesh::PointIdIterator cellIdIt, cellIdEnd;

    cellIt = itkMesh->GetCells()->Begin();
    cellEnd = itkMesh->GetCells()->End();
    cellDataIt = itkMesh->GetCellData()->Begin();

    while (cellIt != cellEnd)
    {
      unsigned int numOfPointsInCell = cellIt->Value()->GetNumberOfPoints();
      if (numOfPointsInCell > 1)
      {
        // iterate through all id's in the cell
        cellIdIt = cellIt->Value()->PointIdsBegin();
        cellIdEnd = cellIt->Value()->PointIdsEnd();

        firstOfCell3D = input->GetPoint(*cellIdIt, timeStep);

        intersectionPoints.clear();
        intersectionPoints.reserve(numOfPointsInCell);

        first = true;

        while (cellIdIt != cellIdEnd)
        {
          lastPoint3D = thisPoint;

          thisPoint = input->GetPoint(*cellIdIt, timeStep);

          // search in data (vector<> selectedLines) if the index of the point is set. if so, then the line is selected.
          lineSelected = false;
          Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines;

          // a line between 1(lastPoint) and 2(pt2d) has the Id 1, so look for the Id of lastPoint
          // since we only start, if we have more than one point in the cell, lastPointId is initiated with 0
          Mesh::SelectedLinesIter position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId);
          if (position != selectedLines.end())
          {
            lineSelected = true;
          }

          mitk::Point3D p, projected_p;
          float vtkp[3];
          itk2vtk(thisPoint, vtkp);
          transform->TransformPoint(vtkp, vtkp);
          vtk2itk(vtkp, p);
          renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
          Vector3D diff = p - projected_p;
          if (diff.GetSquaredNorm() < 4.0)
          {
            Point2D pt2d, tmp;
            renderer->WorldToDisplay(p, pt2d);

            if (lastPoint == NULL)
            {
              // set the first point in the cell. This point in needed to close the polygon
              firstOfCell = new Point2D;
              *firstOfCell = pt2d;
              lastPoint = new Point2D;
              *lastPoint = pt2d;
              lastPointId = *cellIdIt;
            }
            else
            {
              if (lineSelected)
              {
                glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red
                // a line from lastPoint to thisPoint
                glBegin(GL_LINES);
                glVertex2dv(&(*lastPoint)[0]);
                glVertex2dv(&pt2d[0]);
                glEnd();
              }
              else // if not selected
              {
                glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
                // drawing crosses
                glBegin(GL_LINES);
                glVertex2dv(&(*lastPoint)[0]);
                glVertex2dv(&pt2d[0]);
                glEnd();
              }
              // to draw the line to the next in iteration step
              *lastPoint = pt2d;
              // and to search for the selection state of the line
              lastPointId = *cellIdIt;
            } // if..else
          }   // if <4.0

          // fill off-plane polygon part 1
          if ((!first) && (worldplanegeometry != NULL))
          {
            line.SetPoints(lastPoint3D, thisPoint);
            if (worldplanegeometry->IntersectionPointParam(line, t) && ((t >= 0) && (t <= 1)))
            {
              intersectionPoints.push_back(line.GetPoint(t));
            }
          }
          ++cellIdIt;
          first = false;
        } // while cellIdIter

        // closed polygon?
        if (cellDataIt->Value().closed)
        {
          // close the polygon if needed
          if (firstOfCell != NULL)
          {
            lineSelected = false;
            Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines;
            Mesh::SelectedLinesIter position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId);
            if (position != selectedLines.end()) // found the index
            {
              glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red
              // a line from lastPoint to firstPoint
              glBegin(GL_LINES);
              glVertex2dv(&(*lastPoint)[0]);
              glVertex2dv(&(*firstOfCell)[0]);
              glEnd();
            }
            else
            {
              glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
              glBegin(GL_LINES);
              glVertex2dv(&(*lastPoint)[0]);
              glVertex2dv(&(*firstOfCell)[0]);
              glEnd();
            }
          }
        } // if closed

        // Axis-aligned bounding box(AABB) around the cell if selected and set in Property
        bool showBoundingBox;
        if (dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox")) == NULL)
          showBoundingBox = false;
        else
          showBoundingBox =
            dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox"))->GetValue();

        if (showBoundingBox)
        {
          if (cellDataIt->Value().selected)
          {
            mitk::Mesh::DataType::BoundingBoxPointer aABB = input->GetBoundingBoxFromCell(cellIt->Index());
            if (aABB.IsNotNull())
            {
              mitk::Mesh::PointType min, max;
              min = aABB->GetMinimum();
              max = aABB->GetMaximum();

              // project to the displayed geometry
              Point2D min2D, max2D;
              Point3D p, projected_p;
              float vtkp[3];
              itk2vtk(min, vtkp);
              transform->TransformPoint(vtkp, vtkp);
              vtk2itk(vtkp, p);
              renderer->WorldToDisplay(p, min2D);

              itk2vtk(max, vtkp);
              transform->TransformPoint(vtkp, vtkp);
              vtk2itk(vtkp, p);
              renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
              Vector3D diff = p - projected_p;
              if (diff.GetSquaredNorm() < 4.0)
              {
                renderer->WorldToDisplay(p, max2D);

                // draw the BoundingBox
                glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red
                // a line from lastPoint to firstPoint
                glBegin(GL_LINE_LOOP);
                glVertex2f(min2D[0], min2D[1]);
                glVertex2f(min2D[0], max2D[1]);
                glVertex2f(max2D[0], max2D[1]);
                glVertex2f(max2D[0], min2D[1]);
                glEnd();
              } // draw bounding-box
            }   // bounding-box exists
          }     // cell selected
        }       // show bounding-box

        // fill off-plane polygon part 2
        if (worldplanegeometry != NULL)
        {
          // consider line from last to first
          line.SetPoints(thisPoint, firstOfCell3D);
          if (worldplanegeometry->IntersectionPointParam(line, t) && ((t >= 0) && (t <= 1)))
          {
            intersectionPoints.push_back(line.GetPoint(t));
          }
          std::sort(intersectionPoints.begin(), intersectionPoints.end(), point3DSmaller);
          std::vector<mitk::Point3D>::iterator it, end;
          end = intersectionPoints.end();
          if ((intersectionPoints.size() % 2) != 0)
          {
            --end; // ensure even number of intersection-points
          }
          Point2D pt2d;
          for (it = intersectionPoints.begin(); it != end; ++it)
          {
            glBegin(GL_LINES);
            renderer->WorldToDisplay(*it, pt2d);
            glVertex2dv(pt2d.GetDataPointer());
            ++it;
            renderer->WorldToDisplay(*it, pt2d);
            glVertex2dv(pt2d.GetDataPointer());
            glEnd();
          }
          if (it != intersectionPoints.end())
          {
            glBegin(GL_LINES);
            renderer->WorldToDisplay(*it, pt2d);
            glVertex2dv(pt2d.GetDataPointer());
            glVertex2dv(pt2d.GetDataPointer());
            glEnd();
          }
        } // fill off-plane polygon part 2
      }   // if numOfPointsInCell>1
      delete firstOfCell;
      delete lastPoint;
      lastPoint = NULL;
      firstOfCell = NULL;
      lastPointId = 0;
      ++cellIt;
      ++cellDataIt;
    }
  }
}
void mitk::PointSetVtkMapper2D::CreateVTKRenderObjects(mitk::BaseRenderer* renderer)
{
  LocalStorage *ls = m_LSH.GetLocalStorage(renderer);

  unsigned i = 0;

  // The vtk text actors need to be removed manually from the propassembly
  // since the same vtk text actors are not overwriten within this function,
  // but new actors are added to the propassembly each time this function is executed.
  // Thus, the actors from the last call must be removed in the beginning.
  for(i=0; i< ls->m_VtkTextLabelActors.size(); i++)
  {
    if(ls->m_PropAssembly->GetParts()->IsItemPresent(ls->m_VtkTextLabelActors.at(i)))
      ls->m_PropAssembly->RemovePart(ls->m_VtkTextLabelActors.at(i));
  }

  for(i=0; i< ls->m_VtkTextDistanceActors.size(); i++)
  {
    if(ls->m_PropAssembly->GetParts()->IsItemPresent(ls->m_VtkTextDistanceActors.at(i)))
      ls->m_PropAssembly->RemovePart(ls->m_VtkTextDistanceActors.at(i));
  }

  for(i=0; i< ls->m_VtkTextAngleActors.size(); i++)
  {
    if(ls->m_PropAssembly->GetParts()->IsItemPresent(ls->m_VtkTextAngleActors.at(i)))
      ls->m_PropAssembly->RemovePart(ls->m_VtkTextAngleActors.at(i));
  }

  // initialize polydata here, otherwise we have update problems when
  // executing this function again
  ls->m_VtkUnselectedPointListPolyData = vtkSmartPointer<vtkPolyData>::New();
  ls->m_VtkSelectedPointListPolyData = vtkSmartPointer <vtkPolyData>::New();
  ls->m_VtkContourPolyData = vtkSmartPointer<vtkPolyData>::New();

  // get input point set and update the PointSet
  mitk::PointSet::Pointer input  = const_cast<mitk::PointSet*>(this->GetInput());

  // only update the input data, if the property tells us to
  bool update = true;
  this->GetDataNode()->GetBoolProperty("updateDataOnRender", update);
  if (update == true)
    input->Update();

  int timestep = this->GetTimestep();
  mitk::PointSet::DataType::Pointer itkPointSet = input->GetPointSet( timestep );

  if ( itkPointSet.GetPointer() == NULL)
  {
    ls->m_PropAssembly->VisibilityOff();
    return;
  }

  //iterator for point set
  mitk::PointSet::PointsContainer::Iterator pointsIter = itkPointSet->GetPoints()->Begin();

  // PointDataContainer has additional information to each point, e.g. whether
  // it is selected or not
  mitk::PointSet::PointDataContainer::Iterator pointDataIter;
  pointDataIter = itkPointSet->GetPointData()->Begin();

  //check if the list for the PointDataContainer is the same size as the PointsContainer.
  //If not, then the points were inserted manually and can not be visualized according to the PointData (selected/unselected)
  bool pointDataBroken = (itkPointSet->GetPointData()->Size() != itkPointSet->GetPoints()->Size());

  if( itkPointSet->GetPointData()->size() == 0 || pointDataBroken)
  {
    ls->m_PropAssembly->VisibilityOff();
    return;
  }

  ls->m_PropAssembly->VisibilityOn();

  // empty point sets, cellarrays, scalars
  ls->m_UnselectedPoints->Reset();
  ls->m_SelectedPoints->Reset();

  ls->m_ContourPoints->Reset();
  ls->m_ContourLines->Reset();

  ls->m_UnselectedScales->Reset();
  ls->m_SelectedScales->Reset();

  ls->m_DistancesBetweenPoints->Reset();

  ls->m_VtkTextLabelActors.clear();
  ls->m_VtkTextDistanceActors.clear();
  ls->m_VtkTextAngleActors.clear();

  ls->m_UnselectedScales->SetNumberOfComponents(3);
  ls->m_SelectedScales->SetNumberOfComponents(3);

  int NumberContourPoints = 0;
  bool pointsOnSameSideOfPlane = false;

  const int text2dDistance = 10;

  // initialize points with a random start value

  // current point in point set
  itk::Point<ScalarType> point = pointsIter->Value();

  mitk::Point3D p = point;              // currently visited point
  mitk::Point3D lastP = point;          // last visited point (predecessor in point set of "point")
  mitk::Vector3D vec;                   // p - lastP
  mitk::Vector3D lastVec;               // lastP - point before lastP
  vec.Fill(0.0);
  lastVec.Fill(0.0);

  mitk::Point3D projected_p = point;     // p projected on viewplane

  mitk::Point2D pt2d;
  pt2d[0] = point[0];                    // projected_p in display coordinates
  pt2d[1] = point[1];
  mitk::Point2D lastPt2d = pt2d;         // last projected_p in display coordinates (predecessor in point set of "pt2d")
  mitk::Point2D preLastPt2d = pt2d ;     // projected_p in display coordinates before lastPt2

  mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
  const mitk::PlaneGeometry* geo2D = renderer->GetCurrentWorldPlaneGeometry();

  vtkLinearTransform* dataNodeTransform = input->GetGeometry()->GetVtkTransform();

  int count = 0;

  for (pointsIter=itkPointSet->GetPoints()->Begin();
    pointsIter!=itkPointSet->GetPoints()->End();
    pointsIter++)
  {
    lastP = p; // valid for number of points count > 0
    preLastPt2d = lastPt2d; // valid only for count > 1
    lastPt2d = pt2d;  // valid for number of points count > 0

    lastVec = vec;    // valid only for counter > 1

    // get current point in point set
    point = pointsIter->Value();

    // transform point
    {
      float vtkp[3];
      itk2vtk(point, vtkp);
      dataNodeTransform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp,point);
    }

    p[0] = point[0];
    p[1] = point[1];
    p[2] = point[2];

    displayGeometry->Project(p, projected_p);
    displayGeometry->Map(projected_p, pt2d);
    displayGeometry->WorldToDisplay(pt2d, pt2d);

    vec = p-lastP;    // valid only for counter > 0

    // compute distance to current plane
    float diff = geo2D->Distance(point);
    diff = diff * diff;

    //draw markers on slices a certain distance away from the points
    //location according to the tolerance threshold (m_DistanceToPlane)
    if(diff < m_DistanceToPlane)
    {
      // is point selected or not?
      if (pointDataIter->Value().selected)
      {
        ls->m_SelectedPoints->InsertNextPoint(point[0],point[1],point[2]);
        // point is scaled according to its distance to the plane
        ls->m_SelectedScales->InsertNextTuple3(m_Point2DSize - (2*diff),0,0);
      }
      else
      {
        ls->m_UnselectedPoints->InsertNextPoint(point[0],point[1],point[2]);
        // point is scaled according to its distance to the plane
        ls->m_UnselectedScales->InsertNextTuple3(m_Point2DSize - (2*diff),0,0);
      }

      //---- LABEL -----//
      //paint label for each point if available
      if (dynamic_cast<mitk::StringProperty *>(this->GetDataNode()->GetProperty("label")) != NULL)
      {
        const char * pointLabel = dynamic_cast<mitk::StringProperty *>(
          this->GetDataNode()->GetProperty("label"))->GetValue();
        std::string l = pointLabel;
        if (input->GetSize()>1)
        {
          std::stringstream ss;
          ss << pointsIter->Index();
          l.append(ss.str());
        }

        ls->m_VtkTextActor = vtkSmartPointer<vtkTextActor>::New();

        ls->m_VtkTextActor->SetPosition(pt2d[0] + text2dDistance, pt2d[1] + text2dDistance);
        ls->m_VtkTextActor->SetInput(l.c_str());
        ls->m_VtkTextActor->GetTextProperty()->SetOpacity( 100 );

        float unselectedColor[4] = {1.0, 1.0, 0.0, 1.0};

        //check if there is a color property
        GetDataNode()->GetColor(unselectedColor);

        ls->m_VtkTextActor->GetTextProperty()->SetColor(unselectedColor[0], unselectedColor[1], unselectedColor[2]);

        ls->m_VtkTextLabelActors.push_back(ls->m_VtkTextActor);
      }
    }

    // draw contour, distance text and angle text in render window

    // lines between points, which intersect the current plane, are drawn
    if( m_ShowContour && count > 0 )
    {
      ScalarType distance =    displayGeometry->GetWorldGeometry()->SignedDistance(point);
      ScalarType lastDistance =    displayGeometry->GetWorldGeometry()->SignedDistance(lastP);

      pointsOnSameSideOfPlane = (distance * lastDistance) > 0.5;

      // Points must be on different side of plane in order to draw a contour.
      // If "show distant lines" is enabled this condition is disregarded.
      if ( !pointsOnSameSideOfPlane || m_ShowDistantLines)
      {
        vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();

        ls->m_ContourPoints->InsertNextPoint(lastP[0],lastP[1],lastP[2]);
        line->GetPointIds()->SetId(0, NumberContourPoints);
        NumberContourPoints++;

        ls->m_ContourPoints->InsertNextPoint(point[0], point[1], point[2]);
        line->GetPointIds()->SetId(1, NumberContourPoints);
        NumberContourPoints++;

        ls->m_ContourLines->InsertNextCell(line);

        if(m_ShowDistances) // calculate and print distance between adjacent points
        {
          float distancePoints = point.EuclideanDistanceTo(lastP);

          std::stringstream buffer;
          buffer<<std::fixed <<std::setprecision(m_DistancesDecimalDigits)<<distancePoints<<" mm";

          // compute desired display position of text
          Vector2D vec2d = pt2d-lastPt2d;
          makePerpendicularVector2D(vec2d, vec2d); // text is rendered within text2dDistance perpendicular to current line
          Vector2D pos2d = (lastPt2d.GetVectorFromOrigin() + pt2d.GetVectorFromOrigin() ) * 0.5 + vec2d * text2dDistance;

          ls->m_VtkTextActor = vtkSmartPointer<vtkTextActor>::New();

          ls->m_VtkTextActor->SetPosition(pos2d[0],pos2d[1]);
          ls->m_VtkTextActor->SetInput(buffer.str().c_str());
          ls->m_VtkTextActor->GetTextProperty()->SetColor(0.0, 1.0, 0.0);

          ls->m_VtkTextDistanceActors.push_back(ls->m_VtkTextActor);
        }

        if(m_ShowAngles && count > 1) // calculate and print angle between connected lines
        {
          std::stringstream buffer;
          buffer << angle(vec.GetVnlVector(), -lastVec.GetVnlVector())*180/vnl_math::pi << "°";

          //compute desired display position of text
          Vector2D vec2d = pt2d-lastPt2d;             // first arm enclosing the angle
          vec2d.Normalize();
          Vector2D lastVec2d = lastPt2d-preLastPt2d;  // second arm enclosing the angle
          lastVec2d.Normalize();
          vec2d=vec2d-lastVec2d;                      // vector connecting both arms
          vec2d.Normalize();

          // middle between two vectors that enclose the angle
          Vector2D pos2d = lastPt2d.GetVectorFromOrigin() + vec2d * text2dDistance * text2dDistance;

          ls->m_VtkTextActor = vtkSmartPointer<vtkTextActor>::New();

          ls->m_VtkTextActor->SetPosition(pos2d[0],pos2d[1]);
          ls->m_VtkTextActor->SetInput(buffer.str().c_str());
          ls->m_VtkTextActor->GetTextProperty()->SetColor(0.0, 1.0, 0.0);

          ls->m_VtkTextAngleActors.push_back(ls->m_VtkTextActor);
        }
      }
    }

    if(pointDataIter != itkPointSet->GetPointData()->End())
    {
      pointDataIter++;
      count++;
    }
  }

  // add each single text actor to the assembly
  for(i=0; i< ls->m_VtkTextLabelActors.size(); i++)
  {
    ls->m_PropAssembly->AddPart(ls->m_VtkTextLabelActors.at(i));
  }

  for(i=0; i< ls->m_VtkTextDistanceActors.size(); i++)
  {
    ls->m_PropAssembly->AddPart(ls->m_VtkTextDistanceActors.at(i));
  }

  for(i=0; i< ls->m_VtkTextAngleActors.size(); i++)
  {
    ls->m_PropAssembly->AddPart(ls->m_VtkTextAngleActors.at(i));
  }

  //---- CONTOUR -----//

  //create lines between the points which intersect the plane
  if (m_ShowContour)
  {
    // draw line between first and last point which is rendered
    if(m_CloseContour && NumberContourPoints > 1){
      vtkSmartPointer<vtkLine> closingLine = vtkSmartPointer<vtkLine>::New();
      closingLine->GetPointIds()->SetId(0, 0); // index of first point
      closingLine->GetPointIds()->SetId(1, NumberContourPoints-1); // index of last point
      ls->m_ContourLines->InsertNextCell(closingLine);
    }

    ls->m_VtkContourPolyData->SetPoints(ls->m_ContourPoints);
    ls->m_VtkContourPolyData->SetLines(ls->m_ContourLines);

    ls->m_VtkContourPolyDataMapper->SetInputData(ls->m_VtkContourPolyData);
    ls->m_ContourActor->SetMapper(ls->m_VtkContourPolyDataMapper);
    ls->m_ContourActor->GetProperty()->SetLineWidth(m_LineWidth);

    ls->m_PropAssembly->AddPart(ls->m_ContourActor);
  }

  // the point set must be transformed in order to obtain the appropriate glyph orientation
  // according to the current view
  vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
  vtkSmartPointer<vtkMatrix4x4> a,b = vtkSmartPointer<vtkMatrix4x4>::New();

  a = geo2D->GetVtkTransform()->GetMatrix();
  b->DeepCopy( a );

  // delete transformation from matrix, only take orientation
  b->SetElement(3,3,1);
  b->SetElement(2,3,0);
  b->SetElement(1,3,0);
  b->SetElement(0,3,0);
  b->SetElement(3,2,0);
  b->SetElement(3,1,0);
  b->SetElement(3,0,0);

  transform->SetMatrix(  b );

  //---- UNSELECTED POINTS  -----//

  // apply properties to glyph
  ls->m_UnselectedGlyphSource2D->SetGlyphType(m_IDShapeProperty);

  if(m_FillShape)
    ls->m_UnselectedGlyphSource2D->FilledOn();
  else
    ls->m_UnselectedGlyphSource2D->FilledOff();

  // apply transform
  vtkSmartPointer<vtkTransformFilter> transformFilterU = vtkSmartPointer<vtkTransformFilter>::New();
  transformFilterU->SetInputConnection(ls->m_UnselectedGlyphSource2D->GetOutputPort());
  transformFilterU->SetTransform(transform);

  ls->m_VtkUnselectedPointListPolyData->SetPoints(ls->m_UnselectedPoints);
  ls->m_VtkUnselectedPointListPolyData->GetPointData()->SetVectors(ls->m_UnselectedScales);

  // apply transform of current plane to glyphs
  ls->m_UnselectedGlyph3D->SetSourceConnection(transformFilterU->GetOutputPort());
  ls->m_UnselectedGlyph3D->SetInputData(ls->m_VtkUnselectedPointListPolyData);
  ls->m_UnselectedGlyph3D->SetScaleModeToScaleByVector();
  ls->m_UnselectedGlyph3D->SetVectorModeToUseVector();

  ls->m_VtkUnselectedPolyDataMapper->SetInputConnection(ls->m_UnselectedGlyph3D->GetOutputPort());
  ls->m_UnselectedActor->SetMapper(ls->m_VtkUnselectedPolyDataMapper);
  ls->m_UnselectedActor->GetProperty()->SetLineWidth(m_PointLineWidth);

  ls->m_PropAssembly->AddPart(ls->m_UnselectedActor);

  //---- SELECTED POINTS  -----//

  ls->m_SelectedGlyphSource2D->SetGlyphTypeToDiamond();
  ls->m_SelectedGlyphSource2D->CrossOn();
  ls->m_SelectedGlyphSource2D->FilledOff();

  // apply transform
  vtkSmartPointer<vtkTransformFilter> transformFilterS = vtkSmartPointer<vtkTransformFilter>::New();
  transformFilterS->SetInputConnection(ls->m_SelectedGlyphSource2D->GetOutputPort());
  transformFilterS->SetTransform(transform);

  ls->m_VtkSelectedPointListPolyData->SetPoints(ls->m_SelectedPoints);
  ls->m_VtkSelectedPointListPolyData->GetPointData()->SetVectors(ls->m_SelectedScales);

  // apply transform of current plane to glyphs
  ls->m_SelectedGlyph3D->SetSourceConnection(transformFilterS->GetOutputPort());
  ls->m_SelectedGlyph3D->SetInputData(ls->m_VtkSelectedPointListPolyData);
  ls->m_SelectedGlyph3D->SetScaleModeToScaleByVector();
  ls->m_SelectedGlyph3D->SetVectorModeToUseVector();

  ls->m_VtkSelectedPolyDataMapper->SetInputConnection(ls->m_SelectedGlyph3D->GetOutputPort());
  ls->m_SelectedActor->SetMapper(ls->m_VtkSelectedPolyDataMapper);
  ls->m_SelectedActor->GetProperty()->SetLineWidth(m_PointLineWidth);

  ls->m_PropAssembly->AddPart(ls->m_SelectedActor);
}
Exemplo n.º 14
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);

}
bool mitk::ExtrudedContourInteractor::ExecuteAction(mitk::Action* action, mitk::StateEvent const* stateEvent)
{
  mitk::Point3D eventPoint;
  mitk::Vector3D eventPlaneNormal;

  const mitk::PositionEvent* posEvent = dynamic_cast<const mitk::PositionEvent*>(stateEvent->GetEvent());

  if(posEvent==NULL)
  {
    const mitk::DisplayPositionEvent* displayPosEvent = dynamic_cast<const mitk::DisplayPositionEvent*>(stateEvent->GetEvent());
    mitk::VtkPropRenderer* sender = (mitk::VtkPropRenderer*) stateEvent->GetEvent()->GetSender();

    if((displayPosEvent == NULL) || (sender == NULL))
      return false;

    eventPoint[0] = displayPosEvent->GetDisplayPosition()[0];
    eventPoint[1] = displayPosEvent->GetDisplayPosition()[1];
    eventPoint[2] = 0;

    typedef itk::Point<double,3> DoublePoint3D;
    DoublePoint3D p;
    p.CastFrom(eventPoint);
    sender->GetVtkRenderer()->SetDisplayPoint(p.GetDataPointer());

    sender->GetVtkRenderer()->DisplayToWorld();

    double *vtkwp = sender->GetVtkRenderer()->GetWorldPoint();

    vtk2itk(vtkwp, eventPoint);

    double *vtkvpn = sender->GetVtkRenderer()->GetActiveCamera()->GetViewPlaneNormal();
    vtk2itk(vtkvpn, eventPlaneNormal); eventPlaneNormal = -eventPlaneNormal;
  }
  else
  {
    eventPoint = posEvent->GetWorldPosition();
    mitk::BaseRenderer* sender = (mitk::BaseRenderer*) stateEvent->GetEvent()->GetSender();
    eventPlaneNormal = sender->GetCurrentWorldPlaneGeometry()->GetAxisVector(2);
  }


  bool ok = false;
  switch (action->GetActionId())
  {
  case mitk::AcNEWPOINT:
    {
      Press(eventPoint);
      ok = true;
      m_Started = true;
      break;
    }
  case mitk::AcINITMOVEMENT:
    {
      if (m_Started)
      {
        Move(eventPoint);
        ok = true;
        break;
      }
    }
  case mitk::AcMOVEPOINT:
    {
      if (m_Started)
      {
        Move(eventPoint);
        ok = true;
        break;
      }
    }
  case mitk::AcFINISHMOVEMENT:
    {
      if (m_Started)
      {
        mitk::ExtrudedContour* extrudedcontour = dynamic_cast<mitk::ExtrudedContour*>(m_DataNode->GetData());
        extrudedcontour->SetContour(m_Contour);
        extrudedcontour->SetVector(eventPlaneNormal);
        Release(eventPoint);
        ok = true;
        m_Started = false;
        InvokeEvent(itk::EndEvent());
      }
      break;
    }
  default:
    ok = false;
    break;
  }
  return ok;
}
void mitk::UnstructuredGridMapper2D::Paint( mitk::BaseRenderer* renderer )
{
  if ( IsVisible( renderer ) == false )
    return ;

  vtkLinearTransform * vtktransform = GetDataNode()->GetVtkTransform();
  vtkLinearTransform * inversetransform = vtktransform->GetLinearInverse();

  Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D();
  PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast<const PlaneGeometry*>( worldGeometry.GetPointer() );

  Point3D point;
  Vector3D normal;

  if(worldPlaneGeometry.IsNotNull())
  {
    // set up vtkPlane according to worldGeometry
    point=worldPlaneGeometry->GetOrigin();
    normal=worldPlaneGeometry->GetNormal(); normal.Normalize();
    m_Plane->SetTransform((vtkAbstractTransform*)NULL);
  }
  else
  {
    //@FIXME: does not work correctly. Does m_Plane->SetTransform really transforms a "plane plane" into a "curved plane"?
    return;
    AbstractTransformGeometry::ConstPointer worldAbstractGeometry = dynamic_cast<const AbstractTransformGeometry*>(renderer->GetCurrentWorldGeometry2D());
    if(worldAbstractGeometry.IsNotNull())
    {
      // set up vtkPlane according to worldGeometry
      point=const_cast<mitk::BoundingBox*>(worldAbstractGeometry->GetParametricBoundingBox())->GetMinimum();
      FillVector3D(normal, 0, 0, 1);
      m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse());
    }
    else
      return;
  }

  vtkFloatingPointType vp[ 3 ], vnormal[ 3 ];

  vnl2vtk(point.Get_vnl_vector(), vp);
  vnl2vtk(normal.Get_vnl_vector(), vnormal);

  //normally, we would need to transform the surface and cut the transformed surface with the cutter.
  //This might be quite slow. Thus, the idea is, to perform an inverse transform of the plane instead.
  //@todo It probably does not work for scaling operations yet:scaling operations have to be
  //dealed with after the cut is performed by scaling the contour.
  inversetransform->TransformPoint( vp, vp );
  inversetransform->TransformNormalAtPoint( vp, vnormal, vnormal );

  m_Plane->SetOrigin( vp );
  m_Plane->SetNormal( vnormal );

  // set data into cutter
  m_Slicer->SetInput( m_VtkPointSet );
  //    m_Cutter->GenerateCutScalarsOff();
  //    m_Cutter->SetSortByToSortByCell();

  // calculate the cut
  m_Slicer->Update();

  // fetch geometry
  mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
  assert( displayGeometry );
  //  float toGL=displayGeometry->GetSizeInDisplayUnits()[1];

  //apply color and opacity read from the PropertyList
  ApplyProperties( renderer );

  // traverse the cut contour
  vtkPolyData * contour = m_Slicer->GetOutput();

  vtkPoints *vpoints = contour->GetPoints();
  vtkCellArray *vlines = contour->GetLines();
  vtkCellArray *vpolys = contour->GetPolys();
  vtkPointData *vpointdata = contour->GetPointData();
  vtkDataArray* vscalars = vpointdata->GetScalars();

  vtkCellData *vcelldata = contour->GetCellData();
  vtkDataArray* vcellscalars = vcelldata->GetScalars();

  const int numberOfLines = contour->GetNumberOfLines();
  const int numberOfPolys = contour->GetNumberOfPolys();

  const bool useCellData = m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_DEFAULT ||
              m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA;
  const bool usePointData = m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_POINT_DATA;

  Point3D p;
  Point2D p2d;

  vlines->InitTraversal();
  vpolys->InitTraversal();
  
  mitk::Color outlineColor = m_Color->GetColor();

  glLineWidth((float)m_LineWidth->GetValue());

  for (int i = 0;i < numberOfLines;++i )
  {
    vtkIdType *cell(0);
    vtkIdType cellSize(0);

    vlines->GetNextCell( cellSize, cell );

    float rgba[4] = {outlineColor[0], outlineColor[1], outlineColor[2], 1.0f};
    if (m_ScalarVisibility->GetValue() && vcellscalars)
    {
      if ( useCellData )
      {  // color each cell according to cell data
        double scalar = vcellscalars->GetComponent( i, 0 );
        double rgb[3] = { 1.0f, 1.0f, 1.0f };
        m_ScalarsToColors->GetColor(scalar, rgb);
        rgba[0] = (float)rgb[0];
        rgba[1] = (float)rgb[1];
        rgba[2] = (float)rgb[2];
        rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
      }
      else if ( usePointData )
      {
        double scalar = vscalars->GetComponent( i, 0 );
        double rgb[3] = { 1.0f, 1.0f, 1.0f };
        m_ScalarsToColors->GetColor(scalar, rgb);
        rgba[0] = (float)rgb[0];
        rgba[1] = (float)rgb[1];
        rgba[2] = (float)rgb[2];
        rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
      }
    }
    
    glColor4fv( rgba );
    
    glBegin ( GL_LINE_LOOP );
    for ( int j = 0;j < cellSize;++j )
    {
      vpoints->GetPoint( cell[ j ], vp );
      //take transformation via vtktransform into account
      vtktransform->TransformPoint( vp, vp );

      vtk2itk( vp, p );

      //convert 3D point (in mm) to 2D point on slice (also in mm)
      worldGeometry->Map( p, p2d );

      //convert point (until now mm and in worldcoordinates) to display coordinates (units )
      displayGeometry->WorldToDisplay( p2d, p2d );

      //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left )
      //p2d[1]=toGL-p2d[1];

      //add the current vertex to the line
      glVertex2f( p2d[0], p2d[1] );
    }
    glEnd ();

  }
  
  bool polyOutline = m_Outline->GetValue();
  bool scalarVisibility = m_ScalarVisibility->GetValue();

  // only draw polygons if there are cell scalars
  // or the outline property is set to true
  if ((scalarVisibility && vcellscalars) || polyOutline)
  {
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // cache the transformed points
    // a fixed size array is way faster than 'new'
    // slices through 3d cells usually do not generated
    // polygons with more than 6 vertices
    Point2D cachedPoints[10];

    for (int i = 0;i < numberOfPolys;++i )
    {
      vtkIdType *cell(0);
      vtkIdType cellSize(0);

      vpolys->GetNextCell( cellSize, cell );

      float rgba[4] = {1.0f, 1.0f, 1.0f, 0};
      if (scalarVisibility && vcellscalars)
      {
        if ( useCellData )
        {  // color each cell according to cell data
          double scalar = vcellscalars->GetComponent( i, 0 );
          double rgb[3] = { 1.0f, 1.0f, 1.0f };
          m_ScalarsToColors->GetColor(scalar, rgb);
          rgba[0] = (float)rgb[0];
          rgba[1] = (float)rgb[1];
          rgba[2] = (float)rgb[2];
          rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
        }
        else if ( usePointData )
        {
          double scalar = vscalars->GetComponent( i, 0 );
          double rgb[3] = { 1.0f, 1.0f, 1.0f };
          m_ScalarsToColors->GetColor(scalar, rgb);
          rgba[0] = (float)rgb[0];
          rgba[1] = (float)rgb[1];
          rgba[2] = (float)rgb[2];
          rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
        }
      }
      glColor4fv( rgba );

      glBegin( GL_POLYGON );
      for (int j = 0; j < cellSize; ++j)
      {
        vpoints->GetPoint( cell[ j ], vp );
        //take transformation via vtktransform into account
        vtktransform->TransformPoint( vp, vp );

        vtk2itk( vp, p );

        //convert 3D point (in mm) to 2D point on slice (also in mm)
        worldGeometry->Map( p, p2d );

        //convert point (until now mm and in worldcoordinates) to display coordinates (units )
        displayGeometry->WorldToDisplay( p2d, p2d );

        //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left )
        //p2d[1]=toGL-p2d[1];

        cachedPoints[j][0] = p2d[0];
        cachedPoints[j][1] = p2d[1];

        //add the current vertex to the line
        glVertex2f( p2d[0], p2d[1] );
      }
      glEnd();

      if (polyOutline)
      {
        glColor4f(outlineColor[0], outlineColor[1], outlineColor[2], 1.0f);

        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glBegin( GL_POLYGON );
        //glPolygonOffset(1.0, 1.0);
        for (int j = 0; j < cellSize; ++j)
        {
          //add the current vertex to the line
          glVertex2f( cachedPoints[j][0], cachedPoints[j][1] );
        }
        glEnd();
      }
    }
    glDisable(GL_BLEND);
  }
}
Exemplo n.º 17
0
void mitk::PolyDataGLMapper2D::Paint( mitk::BaseRenderer * renderer )
{
    if ( IsVisible( renderer ) == false )
        return ;

    // ok, das ist aus GenerateData kopiert
    mitk::BaseData::Pointer input = const_cast<mitk::BaseData*>( GetData() );

    assert( input );

    input->Update();

    vtkPolyData * vtkpolydata = this->GetVtkPolyData();
    assert( vtkpolydata );


    vtkLinearTransform * vtktransform = GetDataNode() ->GetVtkTransform();

    if (vtktransform)
    {
      vtkLinearTransform * inversetransform = vtktransform->GetLinearInverse();

      Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D();
      PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast<const PlaneGeometry*>( worldGeometry.GetPointer() );

      if ( vtkpolydata != NULL )
      {
          Point3D point;
          Vector3D normal;

          if(worldPlaneGeometry.IsNotNull())
          {
            // set up vtkPlane according to worldGeometry
            point=worldPlaneGeometry->GetOrigin();
            normal=worldPlaneGeometry->GetNormal(); normal.Normalize();
            m_Plane->SetTransform((vtkAbstractTransform*)NULL);
          }
          else
          {
            //@FIXME: does not work correctly. Does m_Plane->SetTransform really transforms a "plane plane" into a "curved plane"?
            return;
            AbstractTransformGeometry::ConstPointer worldAbstractGeometry = dynamic_cast<const AbstractTransformGeometry*>(renderer->GetCurrentWorldGeometry2D());
            if(worldAbstractGeometry.IsNotNull())
            {
              // set up vtkPlane according to worldGeometry
              point=const_cast<mitk::BoundingBox*>(worldAbstractGeometry->GetParametricBoundingBox())->GetMinimum();
              FillVector3D(normal, 0, 0, 1);
              m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse());
            }
            else
              return;
          }

          vtkFloatingPointType vp[ 3 ], vnormal[ 3 ];

          vnl2vtk(point.Get_vnl_vector(), vp);
          vnl2vtk(normal.Get_vnl_vector(), vnormal);

          //normally, we would need to transform the surface and cut the transformed surface with the cutter.
          //This might be quite slow. Thus, the idea is, to perform an inverse transform of the plane instead.
          //@todo It probably does not work for scaling operations yet:scaling operations have to be
          //dealed with after the cut is performed by scaling the contour.
          inversetransform->TransformPoint( vp, vp );
          inversetransform->TransformNormalAtPoint( vp, vnormal, vnormal );

          m_Plane->SetOrigin( vp );
          m_Plane->SetNormal( vnormal );

          // set data into cutter
          m_Cutter->SetInput( vtkpolydata );
          //    m_Cutter->GenerateCutScalarsOff();
          //    m_Cutter->SetSortByToSortByCell();

          // calculate the cut
          m_Cutter->Update();

          // fetch geometry
          mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
          assert( displayGeometry );
          //  float toGL=displayGeometry->GetSizeInDisplayUnits()[1];

          //apply color and opacity read from the PropertyList
          ApplyProperties( renderer );

          // traverse the cut contour
          vtkPolyData * contour = m_Cutter->GetOutput();

          vtkPoints *vpoints = contour->GetPoints();
          vtkCellArray *vpolys = contour->GetLines();
          vtkPointData *vpointdata = contour->GetPointData();
          vtkDataArray* vscalars = vpointdata->GetScalars();

          vtkCellData *vcelldata = contour->GetCellData();
          vtkDataArray* vcellscalars = vcelldata->GetScalars();

          int i, numberOfCells = vpolys->GetNumberOfCells();

          Point3D p;
          Point2D p2d, last, first;

          vpolys->InitTraversal();
          vtkScalarsToColors* lut = GetVtkLUT();
          assert ( lut != NULL );

          for ( i = 0;i < numberOfCells;++i )
          {
              vtkIdType *cell(NULL);
              vtkIdType cellSize(0);

              vpolys->GetNextCell( cellSize, cell );

              if ( m_ColorByCellData )
              {  // color each cell according to cell data
                vtkFloatingPointType* color = lut->GetColor( vcellscalars->GetComponent( i, 0 ) );
                glColor3f( color[ 0 ], color[ 1 ], color[ 2 ] );
              }
              if ( m_ColorByPointData )
              {
                vtkFloatingPointType* color = lut->GetColor( vscalars->GetComponent( cell[0], 0 ) );
                glColor3f( color[ 0 ], color[ 1 ], color[ 2 ] );
              }

              glBegin ( GL_LINE_LOOP );
              for ( int j = 0;j < cellSize;++j )
              {
                  vpoints->GetPoint( cell[ j ], vp );
                  //take transformation via vtktransform into account
                  vtktransform->TransformPoint( vp, vp );

                  vtk2itk( vp, p );

                  //convert 3D point (in mm) to 2D point on slice (also in mm)
                  worldGeometry->Map( p, p2d );

                  //convert point (until now mm and in worldcoordinates) to display coordinates (units )
                  displayGeometry->WorldToDisplay( p2d, p2d );

                  //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left )
                  //p2d[1]=toGL-p2d[1];

                  //add the current vertex to the line
                  glVertex2f( p2d[0], p2d[1] );
              }
              glEnd ();
          }
      }
    }
}
//##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;
  }
}
Exemplo n.º 19
0
void BoundingObjectCutter::GenerateOutputInformation()
{
    mitk::Image::Pointer output = this->GetOutput();
    if ((output->IsInitialized()) && (output->GetPipelineMTime() <= m_TimeOfHeaderInitialization.GetMTime()))
        return;

    mitk::Image::Pointer input = const_cast< mitk::Image * > ( this->GetInput() );

    if(input.IsNull())
    {
        MITK_WARN << "Input is not a mitk::Image";
        return;
    }
    itkDebugMacro(<<"GenerateOutputInformation()");
    unsigned int dimension = input->GetDimension();

    if (dimension < 3)
    {
        MITK_WARN << "ImageCropper cannot handle 1D or 2D Objects. Operation aborted.";
        return;
    }

    if((m_BoundingObject.IsNull()) || (m_BoundingObject->GetTimeGeometry()->CountTimeSteps() == 0))
        return;

    mitk::BaseGeometry* boGeometry =  m_BoundingObject->GetGeometry();
    mitk::BaseGeometry* inputImageGeometry = input->GetSlicedGeometry();
    // calculate bounding box of bounding-object relative to the geometry
    // of the input image. The result is in pixel coordinates of the input
    // image (because the m_IndexToWorldTransform includes the spacing).
    mitk::BoundingBox::Pointer boBoxRelativeToImage = boGeometry->CalculateBoundingBoxRelativeToTransform( inputImageGeometry->GetIndexToWorldTransform() );

    // PART I: initialize input requested region. We do this already here (and not
    // later when GenerateInputRequestedRegion() is called), because we
    // also need the information to setup the output.

    // pre-initialize input-requested-region to largest-possible-region
    // and correct time-region; spatial part will be cropped by
    // bounding-box of bounding-object below
    m_InputRequestedRegion = input->GetLargestPossibleRegion();

    // build region out of bounding-box of bounding-object
    mitk::SlicedData::IndexType  index=m_InputRequestedRegion.GetIndex(); //init times and channels
    mitk::BoundingBox::PointType min = boBoxRelativeToImage->GetMinimum();
    index[0] = (mitk::SlicedData::IndexType::IndexValueType)(std::ceil(min[0]));
    index[1] = (mitk::SlicedData::IndexType::IndexValueType)(std::ceil(min[1]));
    index[2] = (mitk::SlicedData::IndexType::IndexValueType)(std::ceil(min[2]));

    mitk::SlicedData::SizeType   size = m_InputRequestedRegion.GetSize(); //init times and channels
    mitk::BoundingBox::PointType max = boBoxRelativeToImage->GetMaximum();
    size[0] = (mitk::SlicedData::SizeType::SizeValueType)(std::ceil(max[0])-index[0]);
    size[1] = (mitk::SlicedData::SizeType::SizeValueType)(std::ceil(max[1])-index[1]);
    size[2] = (mitk::SlicedData::SizeType::SizeValueType)(std::ceil(max[2])-index[2]);

    mitk::SlicedData::RegionType boRegion(index, size);

    if(m_UseWholeInputRegion == false)
    {
        // crop input-requested-region with region of bounding-object
        if(m_InputRequestedRegion.Crop(boRegion)==false)
        {
            // crop not possible => do nothing: set time size to 0.
            size.Fill(0);
            m_InputRequestedRegion.SetSize(size);
            boRegion.SetSize(size);
            m_BoundingObject->SetRequestedRegion(&boRegion);
            return;
        }
    }

    // set input-requested-region, because we access it later in
    // GenerateInputRequestedRegion (there we just set the time)
    input->SetRequestedRegion(&m_InputRequestedRegion);

    // PART II: initialize output image

    unsigned int *dimensions = new unsigned int [dimension];
    itk2vtk(m_InputRequestedRegion.GetSize(), dimensions);
    if(dimension>3)
        memcpy(dimensions+3, input->GetDimensions()+3, (dimension-3)*sizeof(unsigned int));
    output->Initialize(mitk::PixelType(GetOutputPixelType()), dimension, dimensions);
    delete [] dimensions;

    // now we have everything to initialize the transform of the output
    mitk::SlicedGeometry3D* slicedGeometry = output->GetSlicedGeometry();

    // set the transform: use the transform of the input;
    // the origin will be replaced afterwards
    AffineTransform3D::Pointer indexToWorldTransform = AffineTransform3D::New();
    indexToWorldTransform->SetParameters(input->GetSlicedGeometry()->GetIndexToWorldTransform()->GetParameters());
    slicedGeometry->SetIndexToWorldTransform(indexToWorldTransform);

    // Position the output Image to match the corresponding region of the input image
    const mitk::SlicedData::IndexType& start = m_InputRequestedRegion.GetIndex();
    mitk::Point3D origin;
    vtk2itk(start, origin);
    inputImageGeometry->IndexToWorld(origin, origin);
    slicedGeometry->SetOrigin(origin);

    m_TimeOfHeaderInitialization.Modified();
}
Exemplo n.º 20
0
void mitk::AutoCropImageFilter::GenerateOutputInformation()
{
  mitk::Image::Pointer input = const_cast<mitk::Image*> (this->GetInput());
  mitk::Image::Pointer output = this->GetOutput();

  if(input->GetDimension() <= 2)
  {
    MITK_ERROR << "Only 3D any 4D images are supported." << std::endl;
    return;
  }

  ComputeNewImageBounds();

  if ((output->IsInitialized()) && (output->GetPipelineMTime() <= m_TimeOfHeaderInitialization.GetMTime()))
    return;

  itkDebugMacro(<<"GenerateOutputInformation()");

  // PART I: initialize input requested region. We do this already here (and not
  // later when GenerateInputRequestedRegion() is called), because we
  // also need the information to setup the output.

  // pre-initialize input-requested-region to largest-possible-region
  // and correct time-region; spatial part will be cropped by
  // bounding-box of bounding-object below
  m_InputRequestedRegion = input->GetLargestPossibleRegion();

  // build region out of index and size calculated in ComputeNewImageBounds()

  mitk::SlicedData::IndexType index;
  index[0] = m_RegionIndex[0];
  index[1] = m_RegionIndex[1];
  index[2] = m_RegionIndex[2];
  index[3] = m_InputRequestedRegion.GetIndex()[3];
  index[4] = m_InputRequestedRegion.GetIndex()[4];

  mitk::SlicedData::SizeType  size;
  size[0] = m_RegionSize[0];
  size[1] = m_RegionSize[1];
  size[2] = m_RegionSize[2];
  size[3] = m_InputRequestedRegion.GetSize()[3];
  size[4] = m_InputRequestedRegion.GetSize()[4];

  mitk::SlicedData::RegionType cropRegion(index, size);

  // crop input-requested-region with cropping region computed from the image data
  if(m_InputRequestedRegion.Crop(cropRegion)==false)
  {
    // crop not possible => do nothing: set time size to 0.
    size.Fill(0);
    m_InputRequestedRegion.SetSize(size);
    return;
  }

  // set input-requested-region, because we access it later in
  // GenerateInputRequestedRegion (there we just set the time)
  input->SetRequestedRegion(&m_InputRequestedRegion);


  // PART II: initialize output image
  unsigned int dimension = input->GetDimension();
  unsigned int *dimensions = new unsigned int [dimension];
  itk2vtk(m_InputRequestedRegion.GetSize(), dimensions);
  if(dimension>3)
    memcpy(dimensions+3, input->GetDimensions()+3, (dimension-3)*sizeof(unsigned int));

  // create basic slicedGeometry that will be initialized below
  output->Initialize(mitk::PixelType( GetOutputPixelType() ), dimension, dimensions);
  delete [] dimensions;

  //clone the IndexToWorldTransform from the input, otherwise we will overwrite it, when adjusting the origin of the output image!!
  itk::ScalableAffineTransform< mitk::ScalarType,3 >::Pointer cloneTransform = itk::ScalableAffineTransform< mitk::ScalarType,3 >::New();
  cloneTransform->Compose(input->GetGeometry()->GetIndexToWorldTransform());
  output->GetGeometry()->SetIndexToWorldTransform( cloneTransform.GetPointer() );

  // Position the output Image to match the corresponding region of the input image
  mitk::SlicedGeometry3D* slicedGeometry = output->GetSlicedGeometry();
  mitk::SlicedGeometry3D::Pointer inputGeometry = input->GetSlicedGeometry();
  const mitk::SlicedData::IndexType& start = m_InputRequestedRegion.GetIndex();
  mitk::Point3D origin; vtk2itk(start, origin);
  input->GetSlicedGeometry()->IndexToWorld(origin, origin);
  slicedGeometry->SetOrigin(origin);

  // get the PlaneGeometry for the first slice of the original image
  mitk::PlaneGeometry::Pointer plane = dynamic_cast<mitk::PlaneGeometry*>( inputGeometry->GetGeometry2D( 0 )->Clone().GetPointer() );
  assert( plane );

  // re-initialize the plane according to the new requirements:
  // dimensions of the cropped image
  // right- and down-vector as well as spacing do not change, so use the ones from
  // input image
  ScalarType dimX = output->GetDimensions()[0];
  ScalarType dimY = output->GetDimensions()[1];
  mitk::Vector3D right = plane->GetAxisVector(0);
  mitk::Vector3D down = plane->GetAxisVector(1);
  mitk::Vector3D spacing = plane->GetSpacing();
  plane->InitializeStandardPlane( dimX, dimY, right, down, &spacing );
  // set the new origin on the PlaneGeometry as well
  plane->SetOrigin(origin);

  // re-initialize the slicedGeometry with the correct planeGeometry
  // in order to get a fully initialized SlicedGeometry3D
  slicedGeometry->InitializeEvenlySpaced( plane, inputGeometry->GetSpacing()[2], output->GetSlicedGeometry()->GetSlices() );


  mitk::TimeGeometry* timeSlicedGeometry = output->GetTimeGeometry();
  mitk::ProportionalTimeGeometry* propTimeGeometry = dynamic_cast<ProportionalTimeGeometry*>(timeSlicedGeometry);
  propTimeGeometry->Initialize(slicedGeometry, output->GetDimension(3));

  m_TimeOfHeaderInitialization.Modified();

  output->SetPropertyList(input->GetPropertyList()->Clone());
}
Exemplo n.º 21
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;
  }
}