void mitk::ContourSetVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer *renderer)
{
  bool visible = true;
  GetDataNode()->GetVisibility(visible, renderer, "visible");

  if (!visible)
  {
    m_Actor->VisibilityOff();
    return;
  }

  m_Actor->VisibilityOn();

  if (renderer->GetCurrentWorldPlaneGeometryUpdateTime() > 0UL && renderer->GetCurrentWorldPlaneGeometryUpdateTime() < this->GetInput()->GetMTime())
  {
    m_ContourSet = vtkPolyData::New();

    vtkPoints *points = vtkPoints::New();
    vtkCellArray *lines = vtkCellArray::New();

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

    vtkIdType firstPointIndex = 0, lastPointIndex = 0;

    vtkIdType ptIndex = 0;
    while (contourIt != contourVec.end())
    {
      auto *nextContour = (mitk::Contour *)(*contourIt).second;
      Contour::InputType idx = nextContour->GetContourPath()->StartOfInput();

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

      mitk::Contour::PointsContainerPointer contourPoints = nextContour->GetPoints();
      mitk::Contour::PointsContainerIterator pointsIt = contourPoints->Begin();
      unsigned int counter = 0;

      firstPointIndex = ptIndex;
      while (pointsIt != contourPoints->End())
      {
        if (counter % 2 == 0)
        {
          Contour::BoundingBoxType::PointType point;
          point = pointsIt.Value();
          points->InsertPoint(ptIndex, point[0], point[1], point[2]);
          if (ptIndex > firstPointIndex)
          {
            vtkIdType cell[2] = {ptIndex - 1, ptIndex};
            lines->InsertNextCell((vtkIdType)2, cell);
          }
          lastPointIndex = ptIndex;
          ptIndex++;
        }
        pointsIt++;
        idx += 1;
      }

      if (nextContour->GetClosed())
      {
        vtkIdType cell[2] = {lastPointIndex, firstPointIndex};
        lines->InsertNextCell((vtkIdType)2, cell);
      }
      contourIt++;
    }

    m_ContourSet->SetPoints(points);
    m_ContourSet->SetLines(lines);

    m_TubeFilter->SetInputData(m_ContourSet);
    m_TubeFilter->SetRadius(1);
    m_TubeFilter->Update();
    m_VtkPolyDataMapper->SetInputConnection(m_TubeFilter->GetOutputPort());

    double rgba[4] = {0.0f, 1.0f, 0.0f, 0.6f};

    m_Actor->GetProperty()->SetColor(rgba);
    m_Actor->SetMapper(m_VtkPolyDataMapper);
  }

  SetVtkMapperImmediateModeRendering(m_VtkPolyDataMapper);
}
Ejemplo n.º 2
0
  void Geometry2DDataVtkMapper3D::GenerateDataForRenderer(BaseRenderer* renderer)
  {
    SetVtkMapperImmediateModeRendering(m_EdgeMapper);
    SetVtkMapperImmediateModeRendering(m_BackgroundMapper);

    // Remove all actors from the assembly, and re-initialize it with the
    // edge actor
    m_ImageAssembly->GetParts()->RemoveAllItems();

    if ( !this->IsVisible(renderer) )
    {
      // visibility has explicitly to be set in the single actors
      // due to problems when using cell picking:
      // even if the assembly is invisible, the renderer contains
      // references to the assemblies parts. During picking the
      // visibility of each part is checked, and not only for the
      // whole assembly.
      m_ImageAssembly->VisibilityOff();
      m_EdgeActor->VisibilityOff();
      return;
    }

    // visibility has explicitly to be set in the single actors
    // due to problems when using cell picking:
    // even if the assembly is invisible, the renderer contains
    // references to the assemblies parts. During picking the
    // visibility of each part is checked, and not only for the
    // whole assembly.
    m_ImageAssembly->VisibilityOn();
    m_EdgeActor->VisibilityOn();

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

    if (input.IsNotNull() && (input->GetGeometry2D() != NULL))
    {
      SmartPointerProperty::Pointer surfacecreatorprop;
      surfacecreatorprop = dynamic_cast< SmartPointerProperty * >(GetDataNode()->GetProperty("surfacegeometry", renderer));

      if ( (surfacecreatorprop.IsNull())
        || (surfacecreatorprop->GetSmartPointer().IsNull())
        || ((m_SurfaceCreator = dynamic_cast<Geometry2DDataToSurfaceFilter*>
             (surfacecreatorprop->GetSmartPointer().GetPointer())).IsNull() ) )
        {
        m_SurfaceCreator->PlaceByGeometryOn();
        surfacecreatorprop = SmartPointerProperty::New( m_SurfaceCreator );
        GetDataNode()->SetProperty("surfacegeometry", surfacecreatorprop);
      }

      m_SurfaceCreator->SetInput(input);

      int res;
      if (GetDataNode()->GetIntProperty("xresolution", res, renderer))
      {
        m_SurfaceCreator->SetXResolution(res);
      }
      if (GetDataNode()->GetIntProperty("yresolution", res, renderer))
      {
        m_SurfaceCreator->SetYResolution(res);
      }

      double tubeRadius = 1.0; // Radius of tubular edge surrounding plane

      // Clip the Geometry2D with the reference geometry bounds (if available)
      if ( input->GetGeometry2D()->HasReferenceGeometry() )
      {
        Geometry3D *referenceGeometry =
            input->GetGeometry2D()->GetReferenceGeometry();

        BoundingBox::PointType boundingBoxMin, boundingBoxMax;
        boundingBoxMin = referenceGeometry->GetBoundingBox()->GetMinimum();
        boundingBoxMax = referenceGeometry->GetBoundingBox()->GetMaximum();

        if ( referenceGeometry->GetImageGeometry() )
        {
          for ( unsigned int i = 0; i < 3; ++i )
          {
            boundingBoxMin[i] -= 0.5;
            boundingBoxMax[i] -= 0.5;
          }
        }

        m_SurfaceCreatorPointsContainer->CreateElementAt( 0 ) = boundingBoxMin;
        m_SurfaceCreatorPointsContainer->CreateElementAt( 1 ) = boundingBoxMax;

        m_SurfaceCreatorBoundingBox->ComputeBoundingBox();

        m_SurfaceCreator->SetBoundingBox( m_SurfaceCreatorBoundingBox );

        tubeRadius = referenceGeometry->GetDiagonalLength() / 450.0;
      }

      // If no reference geometry is available, clip with the current global
      // bounds
      else if (m_DataStorage.IsNotNull())
      {
        m_SurfaceCreator->SetBoundingBox(m_DataStorage->ComputeVisibleBoundingBox(NULL, "includeInBoundingBox"));
        tubeRadius = sqrt( m_SurfaceCreator->GetBoundingBox()->GetDiagonalLength2() ) / 450.0;
      }

      // Calculate the surface of the Geometry2D
      m_SurfaceCreator->Update();
      Surface *surface = m_SurfaceCreator->GetOutput();

      // Check if there's something to display, otherwise return
      if ( (surface->GetVtkPolyData() == 0 )
        || (surface->GetVtkPolyData()->GetNumberOfCells() == 0) )
        {
        m_ImageAssembly->VisibilityOff();
        return;
      }

      // add a graphical representation of the surface normals if requested
      DataNode* node = this->GetDataNode();
      bool displayNormals = false;
      bool colorTwoSides = false;
      bool invertNormals = false;
      node->GetBoolProperty("draw normals 3D", displayNormals, renderer);
      node->GetBoolProperty("color two sides", colorTwoSides, renderer);
      node->GetBoolProperty("invert normals", invertNormals, renderer);

      //if we want to draw the display normals or render two sides we have to get the colors
      if( displayNormals || colorTwoSides )
      {
        //get colors
        float frontColor[3] = { 0.0, 0.0, 1.0 };
        node->GetColor( frontColor, renderer, "front color" );
        float backColor[3] = { 1.0, 0.0, 0.0 };
        node->GetColor( backColor, renderer, "back color" );

        if ( displayNormals )
        {
          m_NormalsTransformer->SetInput( surface->GetVtkPolyData() );
          m_NormalsTransformer->SetTransform(node->GetVtkTransform(this->GetTimestep()) );

          m_FrontHedgeHog->SetInput( m_NormalsTransformer->GetOutput() );
          m_FrontHedgeHog->SetVectorModeToUseNormal();
          m_FrontHedgeHog->SetScaleFactor( invertNormals ? 1.0 : -1.0 );

          m_FrontNormalsActor->GetProperty()->SetColor( frontColor[0], frontColor[1], frontColor[2] );

          m_BackHedgeHog->SetInput( m_NormalsTransformer->GetOutput() );
          m_BackHedgeHog->SetVectorModeToUseNormal();
          m_BackHedgeHog->SetScaleFactor( invertNormals ? -1.0 : 1.0 );

          m_BackNormalsActor->GetProperty()->SetColor( backColor[0], backColor[1], backColor[2] );

          //if there is no actor added yet, add one
          if ( !m_NormalsActorAdded )
          {
            m_Prop3DAssembly->AddPart( m_FrontNormalsActor );
            m_Prop3DAssembly->AddPart( m_BackNormalsActor );
            m_NormalsActorAdded = true;
          }
        }
        //if we don't want to display normals AND there is an actor added remove the actor
        else if ( m_NormalsActorAdded )
        {
          m_Prop3DAssembly->RemovePart( m_FrontNormalsActor );
          m_Prop3DAssembly->RemovePart( m_BackNormalsActor );
          m_NormalsActorAdded = false;
        }

        if ( colorTwoSides )
        {
          if ( !invertNormals )
          {
            m_BackgroundActor->GetProperty()->SetColor( backColor[0], backColor[1], backColor[2] );
            m_BackgroundActor->GetBackfaceProperty()->SetColor( frontColor[0], frontColor[1], frontColor[2] );
          }
          else
          {
            m_BackgroundActor->GetProperty()->SetColor( frontColor[0], frontColor[1], frontColor[2] );
            m_BackgroundActor->GetBackfaceProperty()->SetColor( backColor[0], backColor[1], backColor[2] );
          }
        }
      }

      // Add black background for all images (which may be transparent)
      m_BackgroundMapper->SetInput( surface->GetVtkPolyData() );
      m_ImageAssembly->AddPart( m_BackgroundActor );

      LayerSortedActorList layerSortedActors;

      // Traverse the data tree to find nodes resliced by ImageMapperGL2D
      mitk::NodePredicateOr::Pointer p = mitk::NodePredicateOr::New();
      //use a predicate to get all data nodes which are "images" or inherit from mitk::Image
      mitk::TNodePredicateDataType< mitk::Image >::Pointer predicateAllImages = mitk::TNodePredicateDataType< mitk::Image >::New();
      mitk::DataStorage::SetOfObjects::ConstPointer all = m_DataStorage->GetSubset(predicateAllImages);
      //process all found images
      for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin(); it != all->End(); ++it)
      {

        DataNode *node = it->Value();
        if (node != NULL)
          this->ProcessNode(node, renderer, surface, layerSortedActors);
      }

      // Add all image actors to the assembly, sorted according to
      // layer property
      LayerSortedActorList::iterator actorIt;
      for ( actorIt = layerSortedActors.begin(); actorIt != layerSortedActors.end(); ++actorIt )
      {
        m_ImageAssembly->AddPart( actorIt->second );
      }

      // Configurate the tube-shaped frame: size according to the surface
      // bounds, color as specified in the plane's properties
      vtkPolyData *surfacePolyData = surface->GetVtkPolyData();
      m_Cleaner->SetInput(surfacePolyData);
      m_EdgeTransformer->SetTransform(this->GetDataNode()->GetVtkTransform(this->GetTimestep()) );

      // Adjust the radius according to extent
      m_EdgeTuber->SetRadius( tubeRadius );

      // Get the plane's color and set the tube properties accordingly
      ColorProperty::Pointer colorProperty;
      colorProperty = dynamic_cast<ColorProperty*>(this->GetDataNode()->GetProperty( "color" ));
      if ( colorProperty.IsNotNull() )
      {
        const Color& color = colorProperty->GetColor();
        m_EdgeActor->GetProperty()->SetColor(color.GetRed(), color.GetGreen(), color.GetBlue());
      }
      else
      {
        m_EdgeActor->GetProperty()->SetColor( 1.0, 1.0, 1.0 );
      }

      m_ImageAssembly->SetUserTransform(this->GetDataNode()->GetVtkTransform(this->GetTimestep()) );
    }

    VtkRepresentationProperty* representationProperty;
    this->GetDataNode()->GetProperty(representationProperty, "material.representation", renderer);
    if ( representationProperty != NULL )
      m_BackgroundActor->GetProperty()->SetRepresentation( representationProperty->GetVtkRepresentation() );
  }
void mitk::VolumeDataVtkMapper3D::GenerateDataForRenderer( mitk::BaseRenderer *renderer )
{
  SetVtkMapperImmediateModeRendering(m_BoundingBoxMapper);

  mitk::Image *input = const_cast< mitk::Image * >( this->GetInput() );
  if ( !input || !input->IsInitialized() )
    return;

  vtkRenderWindow* renderWindow = renderer->GetRenderWindow();

  bool volumeRenderingEnabled = true;

  if (this->IsVisible(renderer)==false ||
      this->GetDataNode() == NULL ||
      dynamic_cast<mitk::BoolProperty*>(GetDataNode()->GetProperty("volumerendering",renderer))==NULL ||
      dynamic_cast<mitk::BoolProperty*>(GetDataNode()->GetProperty("volumerendering",renderer))->GetValue() == false
    )
  {
    volumeRenderingEnabled = false;

    // Check if a bounding box should be displayed around the dataset
    // (even if volume rendering is disabled)
    bool hasBoundingBox = false;
    this->GetDataNode()->GetBoolProperty( "bounding box", hasBoundingBox );

    if ( !hasBoundingBox )
    {
      m_BoundingBoxActor->VisibilityOff();
    }
    else
    {
      m_BoundingBoxActor->VisibilityOn();

      const BoundingBox::BoundsArrayType &bounds =
        input->GetTimeSlicedGeometry()->GetBounds();

      m_BoundingBox->SetBounds(
        bounds[0], bounds[1],
        bounds[2], bounds[3],
        bounds[4], bounds[5] );

      ColorProperty *colorProperty;
      if ( this->GetDataNode()->GetProperty(
        colorProperty, "color" ) )
      {
        const mitk::Color &color = colorProperty->GetColor();
        m_BoundingBoxActor->GetProperty()->SetColor(
          color[0], color[1], color[2] );
      }
      else
      {
        m_BoundingBoxActor->GetProperty()->SetColor(
          1.0, 1.0, 1.0 );
      }
    }
  }

  // Don't do anything if VR is disabled
  if ( !volumeRenderingEnabled )
  {
    m_VolumeLOD->VisibilityOff();
    return;
  }
  else
  {
        mitk::VtkVolumeRenderingProperty* vrp=dynamic_cast<mitk::VtkVolumeRenderingProperty*>(GetDataNode()->GetProperty("volumerendering configuration",renderer));
        if(vrp)
        {
          int renderingValue = vrp->GetValueAsId();

          switch(renderingValue)
          {
              case  VTK_VOLUME_RAY_CAST_MIP_FUNCTION:
              {
                  vtkVolumeRayCastMIPFunction* mipFunction = vtkVolumeRayCastMIPFunction::New();
                  m_HiResMapper->SetVolumeRayCastFunction(mipFunction);
                  mipFunction->Delete();
                  MITK_INFO <<"in switch" <<std::endl;
                  break;
              }

              case VTK_RAY_CAST_COMPOSITE_FUNCTION:
              {
                  vtkVolumeRayCastCompositeFunction* compositeFunction = vtkVolumeRayCastCompositeFunction::New();
                  compositeFunction->SetCompositeMethodToClassifyFirst();
                  m_HiResMapper->SetVolumeRayCastFunction(compositeFunction);
                  compositeFunction->Delete();
                  break;
              }
              default:
                  MITK_ERROR <<"Warning: invalid volume rendering option.  " << std::endl;

          }
        }
    m_VolumeLOD->VisibilityOn();
  }

  this->SetPreferences();
/*
  switch ( mitk::RenderingManager::GetInstance()->GetNextLOD( renderer ) )
  {
  case 0:
    m_VolumeLOD->SetSelectedLODID(m_MedResID);  m_LowResID );
    break;

  default:
  case 1:
    m_VolumeLOD->SetSelectedLODID( m_HiResID );
    break;
  }
*/
  m_VolumeLOD->SetSelectedLODID( m_HiResID );

  assert(input->GetTimeSlicedGeometry());

  const Geometry3D* worldgeometry = renderer->GetCurrentWorldGeometry();
  if(worldgeometry==NULL)
  {
    GetDataNode()->SetProperty("volumerendering",mitk::BoolProperty::New(false));
    return;
  }

  vtkImageData *inputData = input->GetVtkImageData( this->GetTimestep() );
  if(inputData==NULL)
    return;


  m_ImageCast->SetInput( inputData );

  //If mask exists, process mask before resampling.
  if (this->m_Mask)
  {
    this->m_ImageMaskFilter->SetImageInput(this->m_UnitSpacingImageFilter->GetOutput());
    this->m_Resampler->SetInput(this->m_ImageMaskFilter->GetOutput());
    this->m_HiResMapper->SetInput(this->m_ImageMaskFilter->GetOutput());
  }
  else
  {
    this->m_Resampler->SetInput(this->m_UnitSpacingImageFilter->GetOutput());
    this->m_HiResMapper->SetInput(this->m_UnitSpacingImageFilter->GetOutput());
  }

  this->UpdateTransferFunctions( renderer );

  vtkRenderWindowInteractor *interactor = renderWindow->GetInteractor();

  float frameRate;
  if( this->GetDataNode()->GetFloatProperty( "framerate", frameRate ) && frameRate > 0 && frameRate <= 60)
  {
    interactor->SetDesiredUpdateRate(  frameRate );
    interactor->SetStillUpdateRate( frameRate );
  }
  else if( frameRate > 60 )
  {
    this->GetDataNode()->SetProperty( "framerate",mitk::FloatProperty::New(60));
    interactor->SetDesiredUpdateRate(  60 );
    interactor->SetStillUpdateRate( 60 );
  }
  else
  {
    this->GetDataNode()->SetProperty( "framerate",mitk::FloatProperty::New(0.00001));
    interactor->SetDesiredUpdateRate(  0.00001 );
    interactor->SetStillUpdateRate( 0.00001 );
  }

  if ( m_RenderWindowInitialized.find( renderWindow ) == m_RenderWindowInitialized.end() )
  {
    m_RenderWindowInitialized.insert( renderWindow );

//    mitk::RenderingManager::GetInstance()->SetNextLOD( 0, renderer );

    mitk::RenderingManager::GetInstance()->SetShading( true, 0 );
    mitk::RenderingManager::GetInstance()->SetShading( true, 1 );
    //mitk::RenderingManager::GetInstance()->SetShading( true, 2 );

    mitk::RenderingManager::GetInstance()->SetShadingValues(
      m_VolumePropertyHigh->GetAmbient(),
      m_VolumePropertyHigh->GetDiffuse(),
      m_VolumePropertyHigh->GetSpecular(),
      m_VolumePropertyHigh->GetSpecularPower());

    mitk::RenderingManager::GetInstance()->SetClippingPlaneStatus(false);
  }

  this->SetClippingPlane( interactor );
}
void mitk::EnhancedPointSetVtkMapper3D::ApplyProperties( mitk::BaseRenderer * renderer )
{

  this->UpdateVtkObjects();

  /* iterate over all points in pointset and apply properties to corresponding vtk objects */
  // get and update the PointSet
  const mitk::PointSet* pointset = this->GetInput();
  int timestep = this->GetTimestep();
  mitk::PointSet::DataType* itkPointSet = pointset->GetPointSet( timestep );
  mitk::PointSet::PointsContainer* points = itkPointSet->GetPoints();
  mitk::PointSet::PointDataContainer* pointData = itkPointSet->GetPointData();
  assert(points->Size() == pointData->Size());
  mitk::PointSet::PointsIterator pIt;
  mitk::PointSet::PointDataIterator pdIt;
  mitk::DataNode* n = this->GetDataNode();
  assert(n != NULL);

  for (pIt = points->Begin(), pdIt = pointData->Begin(); pIt != itkPointSet->GetPoints()->End(); ++pIt, ++pdIt)  // for each point in the pointset
  {
    PointIdentifier pointID = pIt->Index();
    assert (pointID == pdIt->Index());

    mitk::PointSet::PointType point = pIt->Value();
    mitk::PointSet::PointDataType data = pdIt->Value();

    ActorMap::iterator aIt = m_PointActors.find(pointID); // Does an actor exist for the point?
    assert(aIt != m_PointActors.end()); // UpdateVtkObjects() must ensure that actor exists

    vtkActor* a = aIt->second.first;
    assert(a != NULL);

    SetVtkMapperImmediateModeRendering(a->GetMapper());

    /* update properties */
    // visibility
    bool pointVisibility = true;
    bool visValueFound = false;
    mitk::BaseProperty* visProp = n->GetProperty("visibility", renderer);
    mitk::BoolLookupTableProperty* visLTProp = dynamic_cast<mitk::BoolLookupTableProperty*>(visProp);
    if (visLTProp != NULL)
    {
      mitk::BoolLookupTable visLookupTable = visLTProp->GetValue();
      //if (visLookupTable != NULL)
      //{
        try
        {
          pointVisibility = visLookupTable.GetTableValue(pointID);
          visValueFound = true;
        }
        catch (...)
        {
        }
      //}
    }
    if (visValueFound == false)
    {
      pointVisibility = n->IsVisible(renderer, "show points");  // use BoolProperty instead
    }
    a->SetVisibility(pointVisibility);

    // opacity
    float opacity = 1.0;
    bool opValueFound = false;
    mitk::BaseProperty* opProp = n->GetProperty("opacity", renderer);
    mitk::FloatLookupTableProperty* opLTProp = dynamic_cast<mitk::FloatLookupTableProperty*>(opProp);
    if (opLTProp != NULL)
    {
      mitk::FloatLookupTable opLookupTable = opLTProp->GetValue();
      //if (opLookupTable != NULL)
      //{
        try
        {
          opacity = opLookupTable.GetTableValue(pointID);
          opValueFound = true;
        }
        catch (...)
        {
        }
      //}
    }
    if (opValueFound == false)
    {
      n->GetOpacity(opacity, renderer);
    }
    a->GetProperty()->SetOpacity(opacity);
////////////////////// continue here ///////////////////

    // pointsize & point position
    float pointSize = 1.0;
    n->GetFloatProperty( "pointsize", pointSize, renderer);
    switch (data.pointSpec)
    {                                               //TODO: look up representation in a representationlookuptable
    case PTSTART:        //cube
      m_CubeSources[pointID]->SetXLength(pointSize);
      m_CubeSources[pointID]->SetYLength(pointSize);
      m_CubeSources[pointID]->SetZLength(pointSize);
      //m_CubeSources[pointID]->SetCenter(pos[0], pos[1], pos[2]);
      break;
    case PTCORNER:          //cone
      m_ConeSources[pointID]->SetRadius(pointSize/2);
      m_ConeSources[pointID]->SetHeight(pointSize);
      m_ConeSources[pointID]->SetResolution(2); // two crossed triangles. Maybe introduce an extra property for
      //m_ConeSources[pointID]->SetCenter(pos[0], pos[1], pos[2]);
      break;
    case PTEDGE:          // cylinder
      m_CylinderSources[pointID]->SetRadius(pointSize/2);
      m_CylinderSources[pointID]->SetHeight(pointSize);
      m_CylinderSources[pointID]->CappingOn();
      m_CylinderSources[pointID]->SetResolution(6);
      //m_CylinderSources[pointID]->SetCenter(pos[0], pos[1], pos[2]);
      break;
    case PTUNDEFINED:     // sphere
    case PTEND:
    default:
      m_SphereSources[pointID]->SetRadius(pointSize/2);
      m_SphereSources[pointID]->SetThetaResolution(10);
      m_SphereSources[pointID]->SetPhiResolution(10);
      //m_SphereSources[pointID]->SetCenter(pos[0], pos[1], pos[2]);
      break;
    }

    // set position
    mitk::Point3D pos = pIt->Value();
    aIt->second.first->SetPosition(pos[0], pos[1], pos[2]);

    // selectedcolor & color
    float color[3];
    if (data.selected)
    {
      if(!n->GetColor(color, renderer, "selectedcolor"))
        n->GetColor(color, renderer);
    }
    else
    {
      mitk::BaseProperty* a = n->GetProperty("colorLookupTable", renderer);
      mitk::LookupTableProperty* b = dynamic_cast<mitk::LookupTableProperty*>(a);
      if (b != NULL)
      {
         mitk::LookupTable::Pointer c = b->GetLookupTable();
         vtkLookupTable *d = c->GetVtkLookupTable();
         double *e=d->GetTableValue(pointID);
         color[0]=e[0];
         color[1]=e[1];
         color[2]=e[2];
      }
      else
      {
        if(!n->GetColor(color, renderer, "unselectedcolor"))
          n->GetColor(color, renderer);
      }
    }


        // TODO: What about "color" property? 2D Mapper only uses unselected and selected color properties
    a->GetProperty()->SetColor(color[0], color[1], color[2]);

    // TODO: label property
  }
  //TODO test different pointSpec
  // TODO "line width" "show contour" "contourcolor" "contoursize" "close contour" "show label", "label"
  // TODO "show points" vs "visibility"  - is visibility evaluated at all? in a superclass maybe?
  // TODO create lookup tables for all properties that should be evaluated per point. also create editor widgets for these lookup tables!
  // TODO check if property changes and pointset changes are reflected in the render window immediately.
  // TODO check behavior with large PointSets
  // TODO check for memory leaks on adding/deleting points
}
Ejemplo n.º 5
0
void mitk::ContourVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer* renderer)
{
  if ( IsVisible(renderer)==false )
  {
    m_Actor->VisibilityOff();
    return;
  }
  m_Actor->VisibilityOn();

  m_Contour = vtkPolyData::New();

  mitk::Contour::Pointer input  = const_cast<mitk::Contour*>(this->GetInput());
  bool makeContour = true;

  if ( makeContour )
  {
    vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
    vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();

    int numPts=input->GetNumberOfPoints();
    if ( numPts > 200000 )
      numPts = 200000;
    mitk::Contour::PathPointer path = input->GetContourPath();
    mitk::Contour::PathType::InputType cstart = path->StartOfInput();
    mitk::Contour::PathType::InputType cend   = path->EndOfInput();
    mitk::Contour::PathType::InputType cstep  = (cend-cstart+1)/numPts;
    mitk::Contour::PathType::InputType ccur;

    vtkIdType ptIndex = 0;
    vtkIdType lastPointIndex = 0;

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

    vtkFloatingPointType vtkpoint[3];

    int i;
    float pointSize = 2;
    this->GetDataNode()->GetFloatProperty("spheres size", pointSize);

    bool showPoints = true;
    this->GetDataNode()->GetBoolProperty("show points", showPoints);
    if ( showPoints )
    {
      m_VtkPointList = vtkAppendPolyData::New();
    }
    for ( i=0, ccur=cstart; i<numPts; ++i, ccur+=cstep )
    {
      itk2vtk(path->Evaluate(ccur), vtkpoint);
      points->InsertPoint(ptIndex, vtkpoint);
      if ( ptIndex > 0 )
      {
        int cell[2] = {ptIndex-1,ptIndex};
        lines->InsertNextCell((vtkIdType)2,(vtkIdType*) cell);
      }
      lastPointIndex = ptIndex;
      ++ptIndex;

      if ( showPoints )
      {
        vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();

        sphere->SetRadius(pointSize);
        sphere->SetCenter(vtkpoint);

        m_VtkPointList->AddInput(sphere->GetOutput());
        sphere->Update();
      }
    }

    if ( input->GetClosed() )
    {
      int cell[2] = {lastPointIndex,0};
      lines->InsertNextCell((vtkIdType)2,(vtkIdType*) cell);
    }

    m_Contour->SetPoints(points);
    m_Contour->SetLines(lines);
    m_Contour->Update();

    m_TubeFilter->SetInput(m_Contour);
    m_TubeFilter->SetRadius(pointSize / 2.0f);
    m_TubeFilter->SetNumberOfSides(8);
    m_TubeFilter->Update();

    if ( showPoints )
    {
      m_VtkPointList->AddInput(m_TubeFilter->GetOutput());
      m_VtkPolyDataMapper->SetInput(m_VtkPointList->GetOutput());
    }
    else
    {
      m_VtkPolyDataMapper->SetInput(m_TubeFilter->GetOutput());
    }
    vtkFloatingPointType rgba[4]={0.0f,1.0f,0.0f,0.6f};
    m_Actor->GetProperty()->SetColor(rgba);
    m_Actor->SetMapper(m_VtkPolyDataMapper);
  }
  
  SetVtkMapperImmediateModeRendering(m_VtkPolyDataMapper);
}
Ejemplo n.º 6
0
void mitk::PointSetVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer *renderer)
{
  bool visible = true;
  GetDataNode()->GetVisibility(visible, renderer, "visible");
  if (!visible)
  {
    m_UnselectedActor->VisibilityOff();
    m_SelectedActor->VisibilityOff();
    m_ContourActor->VisibilityOff();
    return;
  }

  // create new vtk render objects (e.g. sphere for a point)

  SetVtkMapperImmediateModeRendering(m_VtkSelectedPolyDataMapper);
  SetVtkMapperImmediateModeRendering(m_VtkUnselectedPolyDataMapper);

  BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);
  bool needGenerateData = ls->IsGenerateDataRequired(renderer, this, GetDataNode());

  if (!needGenerateData)
  {
    mitk::FloatProperty *pointSizeProp =
      dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("pointsize"));
    mitk::FloatProperty *contourSizeProp =
      dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("contoursize"));

    bool useVertexRendering = false;
    this->GetDataNode()->GetBoolProperty("Vertex Rendering", useVertexRendering);

    // only create new vtk render objects if property values were changed
    if (pointSizeProp && m_PointSize != pointSizeProp->GetValue())
      needGenerateData = true;
    if (contourSizeProp && m_ContourRadius != contourSizeProp->GetValue())
      needGenerateData = true;

    // when vertex rendering is enabled the pointset is always
    // drawn with opengl, thus we leave needGenerateData always false
    if (useVertexRendering && m_VertexRendering != useVertexRendering)
    {
      needGenerateData = false;
      m_VertexRendering = true;
    }
    else if (!useVertexRendering && m_VertexRendering)
    {
      m_VertexRendering = false;
      needGenerateData = true;
    }
  }

  if (needGenerateData)
  {
    this->CreateVTKRenderObjects();
    ls->UpdateGenerateDataTime();
  }

  this->ApplyAllProperties(renderer, m_ContourActor);

  bool showPoints = true;
  this->GetDataNode()->GetBoolProperty("show points", showPoints);

  m_UnselectedActor->SetVisibility(showPoints && !m_VertexRendering);
  m_SelectedActor->SetVisibility(showPoints && !m_VertexRendering);

  if (false && dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("opacity")) != nullptr)
  {
    mitk::FloatProperty::Pointer pointOpacity =
      dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("opacity"));
    float opacity = pointOpacity->GetValue();
    m_ContourActor->GetProperty()->SetOpacity(opacity);
    m_UnselectedActor->GetProperty()->SetOpacity(opacity);
    m_SelectedActor->GetProperty()->SetOpacity(opacity);
  }

  bool showContour = false;
  this->GetDataNode()->GetBoolProperty("show contour", showContour);
  m_ContourActor->SetVisibility(showContour);

  // use vertex rendering
  if (m_VertexRendering)
  {
    VertexRendering();
    ls->UpdateGenerateDataTime();
  }
}
Ejemplo n.º 7
0
void mitk::PointSetVtkMapper3D::GenerateDataForRenderer( mitk::BaseRenderer *renderer )
{
  // create new vtk render objects (e.g. sphere for a point)
  this->CreateVTKRenderObjects();

  SetVtkMapperImmediateModeRendering(m_VtkSelectedPolyDataMapper);
  SetVtkMapperImmediateModeRendering(m_VtkUnselectedPolyDataMapper);

  mitk::FloatProperty::Pointer pointSizeProp = dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("pointsize"));
  mitk::FloatProperty::Pointer contourSizeProp = dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("contoursize"));
  // only create new vtk render objects if property values were changed
  if ( pointSizeProp.IsNotNull() &&  contourSizeProp.IsNotNull() )
  {
    if (m_PointSize!=pointSizeProp->GetValue() || m_ContourRadius!= contourSizeProp->GetValue())
    {
      this->CreateVTKRenderObjects();
    }
  }

  this->ApplyAllProperties(renderer, m_ContourActor);

  bool visible = true;
  GetDataNode()->GetVisibility(visible, renderer, "visible");
  if(!visible)
  {
    m_UnselectedActor->VisibilityOff();
    m_SelectedActor->VisibilityOff();
    m_ContourActor->VisibilityOff();
    return;
  }

  bool showPoints = true;
  this->GetDataNode()->GetBoolProperty("show points", showPoints);

  if(showPoints)
  {
    m_UnselectedActor->VisibilityOn();
    m_SelectedActor->VisibilityOn();
  }
  else
  {
    m_UnselectedActor->VisibilityOff();
    m_SelectedActor->VisibilityOff();
  }

  if(dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("opacity")) != NULL)
  {
    mitk::FloatProperty::Pointer pointOpacity =dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("opacity"));
    float opacity = pointOpacity->GetValue();
    m_ContourActor->GetProperty()->SetOpacity(opacity);
    m_UnselectedActor->GetProperty()->SetOpacity(opacity);
    m_SelectedActor->GetProperty()->SetOpacity(opacity);
  }

  bool makeContour = false;
  this->GetDataNode()->GetBoolProperty("show contour", makeContour);
  if (makeContour)
  {
    m_ContourActor->VisibilityOn();
  }
  else
  {
    m_ContourActor->VisibilityOff();
  }
}