void mitk::ContourModelSetGLMapper2D::Paint(mitk::BaseRenderer *renderer)
{
  BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);

  mitk::DataNode *dataNode = this->GetDataNode();
  bool visible = true;
  dataNode->GetVisibility(visible, renderer, "visible");

  if (!visible)
    return;

  mitk::ContourModelSet *input = this->GetInput();

  mitk::ContourModelSet::ContourModelSetIterator it = input->Begin();

  mitk::ContourModelSet::ContourModelSetIterator end = input->End();

  while (it != end)
  {
    this->DrawContour(it->GetPointer(), renderer);
    ++it;
  }

  if (input->GetSize() < 1)
    return;

  ls->UpdateGenerateDataTime();
}
예제 #2
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)
  BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);
  bool needGenerateData = ls->IsGenerateDataRequired(renderer, this, GetDataNode());

  if (!needGenerateData)
  {
    if (this->GetDataNode()->GetPropertyList()->GetMTime() > ls->GetLastGenerateDataTime() ||
        this->GetDataNode()->GetPropertyList(renderer)->GetMTime() > ls->GetLastGenerateDataTime())
    {
      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_SelectedActor->SetVisibility(showPoints);

  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);
}
void mitk::EnhancedPointSetVtkMapper3D::GenerateDataForRenderer( mitk::BaseRenderer * renderer )
{

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

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

  ApplyProperties(renderer);
}
void mitk::PlaneGeometryDataMapper2D::GenerateDataForRenderer( mitk::BaseRenderer *renderer )
{
  BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);

  // The PlaneGeometryDataMapper2D mapper is special in that the rendering of
  // OTHER PlaneGeometryDatas affects how we render THIS PlaneGeometryData
  // (for the gap at the point where they intersect). A change in any of the
  // other PlaneGeometryData nodes could mean that we render ourself
  // differently, so we check for that here.
  bool generateDataRequired = false;
  for (AllInstancesContainer::iterator it = s_AllInstances.begin();
       it != s_AllInstances.end();
       ++it)
  {
    generateDataRequired = ls->IsGenerateDataRequired(renderer, this, (*it)->GetDataNode());
    if (generateDataRequired) break;
  }

  ls->UpdateGenerateDataTime();

  // Collect all other PlaneGeometryDatas that are being mapped by this mapper
  m_OtherPlaneGeometries.clear();

  for (AllInstancesContainer::iterator it = s_AllInstances.begin(); it != s_AllInstances.end(); ++it)
  {
    Self *otherInstance = *it;

    // Skip ourself
    if (otherInstance == this) continue;

    mitk::DataNode *otherNode = otherInstance->GetDataNode();
    if (!otherNode) continue;

    // Skip other PlaneGeometryData nodes that are not visible on this renderer
    if (!otherNode->IsVisible(renderer)) continue;

    PlaneGeometryData* otherData = dynamic_cast<PlaneGeometryData*>(otherNode->GetData());
    if (!otherData) continue;

    PlaneGeometry* otherGeometry = dynamic_cast<PlaneGeometry*>(otherData->GetPlaneGeometry());
    if ( otherGeometry && !dynamic_cast<AbstractTransformGeometry*>(otherData->GetPlaneGeometry()) )
    {
      m_OtherPlaneGeometries.push_back(otherNode);
    }
  }

  CreateVtkCrosshair(renderer);

  ApplyAllProperties(renderer);
}
예제 #5
0
void mitk::ContourModelGLMapper2D::Paint(mitk::BaseRenderer *renderer)
{
    BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);

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

    bool visible = true;
    dataNode->GetVisibility(visible, renderer, "visible");

    if (!visible)
        return;

    mitk::ContourModel *input = this->GetInput();

    mitk::ContourModel::Pointer renderingContour = input;

    bool subdivision = false;

    dataNode->GetBoolProperty("subdivision curve", subdivision, renderer);
    if (subdivision)
    {
        if (this->m_SubdivisionContour->GetMTime() < renderingContour->GetMTime() || m_InitSubdivisionCurve)
        {
            // mitk::ContourModel::Pointer subdivContour = mitk::ContourModel::New();

            mitk::ContourModelSubDivisionFilter::Pointer subdivFilter = mitk::ContourModelSubDivisionFilter::New();

            subdivFilter->SetInput(input);
            subdivFilter->Update();

            this->m_SubdivisionContour = subdivFilter->GetOutput();

            m_InitSubdivisionCurve = false;
        }
        renderingContour = this->m_SubdivisionContour;
    }

    this->DrawContour(renderingContour, renderer);

    ls->UpdateGenerateDataTime();
}
/*
* Generate a vtkPolyData by creating vectors as glyphs
* This method is called, each time a specific renderer is updated.
*/
void mitk::VectorImageVtkGlyphMapper3D::GenerateDataForRenderer( mitk::BaseRenderer* renderer )
{

  bool visible = true;
  GetDataNode()->GetVisibility(visible, renderer, "visible");

  if ( !visible )
  {
    if ( m_Glyph3DActor != NULL )
      m_Glyph3DActor->VisibilityOff();
    return ;
  }
  else
  {
    if ( m_Glyph3DActor != NULL )
      m_Glyph3DActor->VisibilityOn();
  }

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

  if(!needGenerateData)
  {
    return;
  }

  ls->UpdateGenerateDataTime();

  //
  // get the input image...
  //
  mitk::Image::Pointer mitkImage = this->GetInput();
  if ( mitkImage.GetPointer() == NULL )
  {
    itkWarningMacro( << "VectorImage is null !" );
    return;
  }
void mitk::UnstructuredGridVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer* renderer)
{

  mitk::DataNode::ConstPointer node = this->GetDataNode();

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

  if(needGenerateData)
  {
    ls->UpdateGenerateDataTime();

    m_Assembly->VisibilityOn();

    m_ActorWireframe->GetProperty()->SetAmbient(1.0);
    m_ActorWireframe->GetProperty()->SetDiffuse(0.0);
    m_ActorWireframe->GetProperty()->SetSpecular(0.0);

    mitk::TransferFunctionProperty::Pointer transferFuncProp;
    if (node->GetProperty(transferFuncProp, "TransferFunction"))
    {
      mitk::TransferFunction::Pointer transferFunction = transferFuncProp->GetValue();
      if (transferFunction->GetColorTransferFunction()->GetSize() < 2)
      {
        mitk::UnstructuredGrid::Pointer input  = const_cast< mitk::UnstructuredGrid* >(this->GetInput());
        if (input.IsNull()) return;

        vtkUnstructuredGrid * grid = input->GetVtkUnstructuredGrid(this->GetTimestep());
        if (grid == 0) return;

        double* scalarRange = grid->GetScalarRange();
        vtkColorTransferFunction* colorFunc = transferFunction->GetColorTransferFunction();
        colorFunc->RemoveAllPoints();
        colorFunc->AddRGBPoint(scalarRange[0], 1, 0, 0);
        colorFunc->AddRGBPoint((scalarRange[0] + scalarRange[1])/2.0, 0, 1, 0);
        colorFunc->AddRGBPoint(scalarRange[1], 0, 0, 1);
      }
    }
  }

  bool visible = true;
  GetDataNode()->GetVisibility(visible, renderer, "visible");

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

  //
  // get the TimeGeometry of the input object
  //
  mitk::UnstructuredGrid::Pointer input  = const_cast< mitk::UnstructuredGrid* >( this->GetInput() );

  //
  // set the input-object at time t for the mapper
  //
  vtkUnstructuredGrid * grid = input->GetVtkUnstructuredGrid( this->GetTimestep() );
  if(grid == 0)
  {
    m_Assembly->VisibilityOff();
    return;
  }

  m_Assembly->VisibilityOn();

  m_VtkTriangleFilter->SetInputData(grid);
  m_VtkDataSetMapper->SetInput(grid);
  m_VtkDataSetMapper2->SetInput(grid);

  bool clip = false;
  node->GetBoolProperty("enable clipping", clip);
  mitk::DataNode::Pointer bbNode = renderer->GetDataStorage()->GetNamedDerivedNode("Clipping Bounding Object", node);
  if (clip && bbNode.IsNotNull())
  {
    m_VtkDataSetMapper->SetBoundingObject(dynamic_cast<mitk::BoundingObject*>(bbNode->GetData()));
    m_VtkDataSetMapper2->SetBoundingObject(dynamic_cast<mitk::BoundingObject*>(bbNode->GetData()));
  }
  else
  {
    m_VtkDataSetMapper->SetBoundingObject(0);
    m_VtkDataSetMapper2->SetBoundingObject(0);
  }

  //
  // apply properties read from the PropertyList
  //
  ApplyProperties(0, renderer);
}
void mitk::UnstructuredGridMapper2D::GenerateDataForRenderer( mitk::BaseRenderer* renderer )
{

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

  if(needGenerateData)
  {
    ls->UpdateGenerateDataTime();

    mitk::DataNode::ConstPointer node = this->GetDataNode();
    if ( node.IsNull() )
      return;

    if (!node->GetProperty(m_ScalarMode, "scalar mode"))
    {
      m_ScalarMode = mitk::VtkScalarModeProperty::New(0);
    }

    if (!node->GetProperty(m_ScalarVisibility, "scalar visibility"))
    {
      m_ScalarVisibility = mitk::BoolProperty::New(true);
    }

    if (!node->GetProperty(m_Outline, "outline polygons"))
    {
      m_Outline = mitk::BoolProperty::New(false);
    }

    if (!node->GetProperty(m_Color, "color"))
    {
      m_Color = mitk::ColorProperty::New(1.0f, 1.0f, 1.0f);
    }

    if (!node->GetProperty(m_LineWidth, "line width"))
    {
      m_LineWidth = mitk::IntProperty::New(1);
    }

  }
  mitk::BaseData::Pointer input = const_cast<mitk::BaseData*>( GetDataNode()->GetData() );
  assert( input );

  input->Update();

  if (m_VtkPointSet) m_VtkPointSet->UnRegister(0);
  m_VtkPointSet = this->GetVtkPointSet(renderer, this->GetTimestep());
  assert(m_VtkPointSet);
  m_VtkPointSet->Register(0);

  if (m_ScalarVisibility->GetValue())
  {
    mitk::DataNode::ConstPointer node = this->GetDataNode();
    mitk::TransferFunctionProperty::Pointer transferFuncProp;
    node->GetProperty(transferFuncProp, "TransferFunction", renderer);
    if (transferFuncProp.IsNotNull())
    {
      mitk::TransferFunction::Pointer tf = transferFuncProp->GetValue();
      if (m_ScalarsToColors) m_ScalarsToColors->UnRegister(0);
      m_ScalarsToColors = static_cast<vtkScalarsToColors*>(tf->GetColorTransferFunction());
      m_ScalarsToColors->Register(0);

      if (m_ScalarsToOpacity) m_ScalarsToOpacity->UnRegister(0);
      m_ScalarsToOpacity = tf->GetScalarOpacityFunction();
      m_ScalarsToOpacity->Register(0);
    }
    else
    {
      if (m_ScalarsToColors) m_ScalarsToColors->UnRegister(0);
      m_ScalarsToColors = this->GetVtkLUT(renderer);
      assert(m_ScalarsToColors);
      m_ScalarsToColors->Register(0);

      float opacity;
      node->GetOpacity(opacity, renderer);
      if (m_ScalarsToOpacity) m_ScalarsToOpacity->UnRegister(0);
      m_ScalarsToOpacity = vtkPiecewiseFunction::New();
      double range[2];
      m_VtkPointSet->GetScalarRange(range);
      m_ScalarsToOpacity->AddSegment(range[0], opacity, range[1], opacity);
    }
  }
}
예제 #9
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();
  }
}