Пример #1
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 ShowSegmentationAsSurface::ThreadedUpdateSuccessful()
  {
    m_Node = DataNode::New();

    bool wireframe(false);
    GetParameter("Wireframe", wireframe);
    if (wireframe)
    {
      VtkRepresentationProperty *np =
        dynamic_cast<VtkRepresentationProperty *>(m_Node->GetProperty("material.representation"));
      if (np)
        np->SetRepresentationToWireframe();
    }

    m_Node->SetProperty("opacity", FloatProperty::New(0.3));
    m_Node->SetProperty("line width", IntProperty::New(1));
    m_Node->SetProperty("scalar visibility", BoolProperty::New(false));

    std::string groupNodesName("surface");

    DataNode *groupNode = GetGroupNode();
    if (groupNode)
    {
      groupNode->GetName(groupNodesName);
      // if parameter smooth is set add extension to node name
      bool smooth(true);
      GetParameter("Smooth", smooth);
      if (smooth)
        groupNodesName.append("_smoothed");
    }
    m_Node->SetProperty("name", StringProperty::New(groupNodesName));

    // synchronize this object's color with the parent's color
    // surfaceNode->SetProperty( "color", parentNode->GetProperty( "color" ) );
    // surfaceNode->SetProperty( "visible", parentNode->GetProperty( "visible" ) );

    m_Node->SetData(m_Surface);

    BaseProperty *colorProp = groupNode->GetProperty("color");
    if (colorProp)
      m_Node->ReplaceProperty("color", colorProp->Clone());
    else
      m_Node->SetProperty("color", ColorProperty::New(1.0, 1.0, 0.0));

    bool showResult(true);
    GetParameter("Show result", showResult);

    bool syncVisibility(false);
    GetParameter("Sync visibility", syncVisibility);

    Image::Pointer image;
    GetPointerParameter("Input", image);

    BaseProperty *organTypeProp = image->GetProperty("organ type");
    if (organTypeProp)
      m_Surface->SetProperty("organ type", organTypeProp);

    BaseProperty *visibleProp = groupNode->GetProperty("visible");
    if (visibleProp && syncVisibility)
      m_Node->ReplaceProperty("visible", visibleProp->Clone());
    else
      m_Node->SetProperty("visible", BoolProperty::New(showResult));

    InsertBelowGroupNode(m_Node);

    Superclass::ThreadedUpdateSuccessful();
  }
void ShowSegmentationAsSmoothedSurface::ThreadedUpdateSuccessful()
{
  DataNode::Pointer node = DataNode::New();

  bool wireframe = false;
  GetParameter("Wireframe", wireframe);

  if (wireframe)
  {
    VtkRepresentationProperty *representation = dynamic_cast<VtkRepresentationProperty *>(
      node->GetProperty("material.representation"));

    if (representation != nullptr)
      representation->SetRepresentationToWireframe();
  }

  node->SetProperty("opacity", FloatProperty::New(1.0));
  node->SetProperty("line width", IntProperty::New(1));
  node->SetProperty("scalar visibility", BoolProperty::New(false));

  std::string groupNodeName = "surface";
  DataNode *groupNode = GetGroupNode();

  if (groupNode != nullptr)
    groupNode->GetName(groupNodeName);

  node->SetProperty("name", StringProperty::New(groupNodeName));
  node->SetData(m_Surface);

  BaseProperty *colorProperty = groupNode->GetProperty("color");

  if (colorProperty != nullptr)
    node->ReplaceProperty("color", colorProperty->Clone());
  else
    node->SetProperty("color", ColorProperty::New(1.0f, 0.0f, 0.0f));

  bool showResult = true;
  GetParameter("Show result", showResult);

  bool syncVisibility = false;
  GetParameter("Sync visibility", syncVisibility);

  Image::Pointer image;
  GetPointerParameter("Input", image);

  BaseProperty *organTypeProperty = image->GetProperty("organ type");

  if (organTypeProperty != nullptr)
    m_Surface->SetProperty("organ type", organTypeProperty);

  BaseProperty *visibleProperty = groupNode->GetProperty("visible");

  if (visibleProperty != nullptr && syncVisibility)
    node->ReplaceProperty("visible", visibleProperty->Clone());
  else
    node->SetProperty("visible", BoolProperty::New(showResult));

  InsertBelowGroupNode(node);

  Superclass::ThreadedUpdateSuccessful();
}
void ShowSegmentationAsSmoothedSurface::ThreadedUpdateSuccessful()
{
  DataNode::Pointer node = LookForPointerTargetBelowGroupNode("Surface representation");
  bool addToTree = node.IsNull();

  if (addToTree)
  {
    node = DataNode::New();

    bool wireframe = false;
    GetParameter("Wireframe", wireframe);

    if (wireframe)
    {
      VtkRepresentationProperty *representation = dynamic_cast<VtkRepresentationProperty *>(
        node->GetProperty("material.representation"));

      if (representation != NULL)
        representation->SetRepresentationToWireframe();
    }

    node->SetProperty("opacity", FloatProperty::New(1.0));
    node->SetProperty("line width", IntProperty::New(1));
    node->SetProperty("scalar visibility", BoolProperty::New(false));

    UIDGenerator uidGenerator("Surface_");
    node->SetProperty("FILENAME", StringProperty::New(uidGenerator.GetUID() + ".vtk"));

    std::string groupNodeName = "surface";
    DataNode *groupNode = GetGroupNode();

    if (groupNode != NULL)
      groupNode->GetName(groupNodeName);

    node->SetProperty("name", StringProperty::New(groupNodeName));
  }

  node->SetData(m_Surface);

  if (addToTree)
  {
    DataNode* groupNode = GetGroupNode();

    if (groupNode != NULL)
    {
      groupNode->SetProperty("Surface representation", SmartPointerProperty::New(node));

      BaseProperty *colorProperty = groupNode->GetProperty("color");

      if (colorProperty != NULL)
        node->ReplaceProperty("color", colorProperty);
      else
        node->SetProperty("color", ColorProperty::New(1.0f, 0.0f, 0.0f));

      bool showResult = true;
      GetParameter("Show result", showResult);

      bool syncVisibility = false;
      GetParameter("Sync visibility", syncVisibility);

      Image::Pointer image;
      GetPointerParameter("Input", image);

      BaseProperty *organTypeProperty = image->GetProperty("organ type");

      if (organTypeProperty != NULL)
        m_Surface->SetProperty("organ type", organTypeProperty);

      BaseProperty *visibleProperty = groupNode->GetProperty("visible");

      if (visibleProperty != NULL && syncVisibility)
        node->ReplaceProperty("visible", visibleProperty);
      else
        node->SetProperty("visible", BoolProperty::New(showResult));
    }

    InsertBelowGroupNode(node);
  }

  Superclass::ThreadedUpdateSuccessful();
}