<commit_before>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "mitkPlaneGeometryDataVtkMapper3D.h"

#include "mitkImageVtkMapper2D.h"
#include "mitkSmartPointerProperty.h"
#include "mitkSurface.h"
#include "mitkVtkRepresentationProperty.h"
#include "mitkWeakPointerProperty.h"
#include "mitkNodePredicateDataType.h"
#include "mitkNodePredicateOr.h"
#include "vtkNeverTranslucentTexture.h"
#include "vtkMitkLevelWindowFilter.h"

#include <vtkAssembly.h>
#include <vtkDataSetMapper.h>
#include <vtkFeatureEdges.h>
#include <vtkHedgeHog.h>
#include <vtkImageData.h>
#include <vtkLinearTransform.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProp3DCollection.h>
#include <vtkProperty.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkTubeFilter.h>

namespace mitk
{

  PlaneGeometryDataVtkMapper3D::PlaneGeometryDataVtkMapper3D()
    : m_NormalsActorAdded(false),
    m_DataStorage(NULL)
  {
    m_EdgeTuber = vtkTubeFilter::New();
    m_EdgeMapper = vtkPolyDataMapper::New();

    m_SurfaceCreator = PlaneGeometryDataToSurfaceFilter::New();
    m_SurfaceCreatorBoundingBox = BoundingBox::New();
    m_SurfaceCreatorPointsContainer = BoundingBox::PointsContainer::New();
    m_Edges = vtkFeatureEdges::New();

    m_Edges->BoundaryEdgesOn();
    m_Edges->FeatureEdgesOff();
    m_Edges->NonManifoldEdgesOff();
    m_Edges->ManifoldEdgesOff();

    m_EdgeTransformer = vtkTransformPolyDataFilter::New();
    m_NormalsTransformer = vtkTransformPolyDataFilter::New();
    m_EdgeActor = vtkActor::New();
    m_BackgroundMapper = vtkPolyDataMapper::New();
    m_BackgroundActor = vtkActor::New();
    m_Prop3DAssembly = vtkAssembly::New();
    m_ImageAssembly = vtkAssembly::New();

    m_SurfaceCreatorBoundingBox->SetPoints( m_SurfaceCreatorPointsContainer );

    m_Cleaner = vtkCleanPolyData::New();

    m_Cleaner->PieceInvariantOn();
    m_Cleaner->ConvertLinesToPointsOn();
    m_Cleaner->ConvertPolysToLinesOn();
    m_Cleaner->ConvertStripsToPolysOn();
    m_Cleaner->PointMergingOn();

    // Make sure that the FeatureEdge algorithm is initialized with a "valid"
    // (though empty) input
    vtkPolyData *emptyPolyData = vtkPolyData::New();
    m_Cleaner->SetInputData( emptyPolyData );
    emptyPolyData->Delete();

    m_Edges->SetInputConnection(m_Cleaner->GetOutputPort());
    m_EdgeTransformer->SetInputConnection( m_Edges->GetOutputPort() );

    m_EdgeTuber->SetInputConnection( m_EdgeTransformer->GetOutputPort() );
    m_EdgeTuber->SetVaryRadiusToVaryRadiusOff();
    m_EdgeTuber->SetNumberOfSides( 12 );
    m_EdgeTuber->CappingOn();

    m_EdgeMapper->SetInputConnection( m_EdgeTuber->GetOutputPort() );
    m_EdgeMapper->ScalarVisibilityOff();

    m_BackgroundMapper->SetInputData(emptyPolyData);
    m_BackgroundMapper->Update();

    m_EdgeActor->SetMapper( m_EdgeMapper );

    m_BackgroundActor->GetProperty()->SetAmbient( 0.5 );
    m_BackgroundActor->GetProperty()->SetColor( 0.0, 0.0, 0.0 );
    m_BackgroundActor->GetProperty()->SetOpacity( 0.0 );
    m_BackgroundActor->SetMapper( m_BackgroundMapper );

    vtkProperty * backfaceProperty = m_BackgroundActor->MakeProperty();
    backfaceProperty->SetColor( 0.0, 0.0, 0.0 );
    m_BackgroundActor->SetBackfaceProperty( backfaceProperty );
    backfaceProperty->Delete();

    m_FrontHedgeHog = vtkHedgeHog::New();
    m_BackHedgeHog  = vtkHedgeHog::New();

    m_FrontNormalsMapper = vtkPolyDataMapper::New();
    m_FrontNormalsMapper->SetInputConnection( m_FrontHedgeHog->GetOutputPort());
    m_BackNormalsMapper = vtkPolyDataMapper::New();

    m_Prop3DAssembly->AddPart( m_EdgeActor );
    m_Prop3DAssembly->AddPart( m_ImageAssembly );
    m_FrontNormalsActor = vtkActor::New();
    m_FrontNormalsActor->SetMapper(m_FrontNormalsMapper);
    m_BackNormalsActor = vtkActor::New();
    m_BackNormalsActor->SetMapper(m_BackNormalsMapper);

    m_ImageMapperDeletedCommand = MemberCommandType::New();
    m_ImageMapperDeletedCommand->SetCallbackFunction(
        this, &PlaneGeometryDataVtkMapper3D::ImageMapperDeletedCallback );
  }

  PlaneGeometryDataVtkMapper3D::~PlaneGeometryDataVtkMapper3D()
  {
    m_ImageAssembly->Delete();
    m_Prop3DAssembly->Delete();
    m_EdgeTuber->Delete();
    m_EdgeMapper->Delete();
    m_EdgeTransformer->Delete();
    m_Cleaner->Delete();
    m_Edges->Delete();
    m_NormalsTransformer->Delete();
    m_EdgeActor->Delete();
    m_BackgroundMapper->Delete();
    m_BackgroundActor->Delete();
    m_FrontNormalsMapper->Delete();
    m_FrontNormalsActor->Delete();
    m_FrontHedgeHog->Delete();
    m_BackNormalsMapper->Delete();
    m_BackNormalsActor->Delete();
    m_BackHedgeHog->Delete();

    // Delete entries in m_ImageActors list one by one
    m_ImageActors.clear();

    m_DataStorage = NULL;
  }<commit_msg>release graphics resources<commit_after>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "mitkPlaneGeometryDataVtkMapper3D.h"

#include "mitkImageVtkMapper2D.h"
#include "mitkSmartPointerProperty.h"
#include "mitkSurface.h"
#include "mitkVtkRepresentationProperty.h"
#include "mitkWeakPointerProperty.h"
#include "mitkNodePredicateDataType.h"
#include "mitkNodePredicateOr.h"
#include "vtkNeverTranslucentTexture.h"
#include "vtkMitkLevelWindowFilter.h"

#include <vtkAssembly.h>
#include <vtkDataSetMapper.h>
#include <vtkFeatureEdges.h>
#include <vtkHedgeHog.h>
#include <vtkImageData.h>
#include <vtkLinearTransform.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProp3DCollection.h>
#include <vtkProperty.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkTubeFilter.h>

namespace mitk
{

  PlaneGeometryDataVtkMapper3D::PlaneGeometryDataVtkMapper3D()
    : m_NormalsActorAdded(false),
    m_DataStorage(NULL)
  {
    m_EdgeTuber = vtkTubeFilter::New();
    m_EdgeMapper = vtkPolyDataMapper::New();

    m_SurfaceCreator = PlaneGeometryDataToSurfaceFilter::New();
    m_SurfaceCreatorBoundingBox = BoundingBox::New();
    m_SurfaceCreatorPointsContainer = BoundingBox::PointsContainer::New();
    m_Edges = vtkFeatureEdges::New();

    m_Edges->BoundaryEdgesOn();
    m_Edges->FeatureEdgesOff();
    m_Edges->NonManifoldEdgesOff();
    m_Edges->ManifoldEdgesOff();

    m_EdgeTransformer = vtkTransformPolyDataFilter::New();
    m_NormalsTransformer = vtkTransformPolyDataFilter::New();
    m_EdgeActor = vtkActor::New();
    m_BackgroundMapper = vtkPolyDataMapper::New();
    m_BackgroundActor = vtkActor::New();
    m_Prop3DAssembly = vtkAssembly::New();
    m_ImageAssembly = vtkAssembly::New();

    m_SurfaceCreatorBoundingBox->SetPoints( m_SurfaceCreatorPointsContainer );

    m_Cleaner = vtkCleanPolyData::New();

    m_Cleaner->PieceInvariantOn();
    m_Cleaner->ConvertLinesToPointsOn();
    m_Cleaner->ConvertPolysToLinesOn();
    m_Cleaner->ConvertStripsToPolysOn();
    m_Cleaner->PointMergingOn();

    // Make sure that the FeatureEdge algorithm is initialized with a "valid"
    // (though empty) input
    vtkPolyData *emptyPolyData = vtkPolyData::New();
    m_Cleaner->SetInputData( emptyPolyData );
    emptyPolyData->Delete();

    m_Edges->SetInputConnection(m_Cleaner->GetOutputPort());
    m_EdgeTransformer->SetInputConnection( m_Edges->GetOutputPort() );

    m_EdgeTuber->SetInputConnection( m_EdgeTransformer->GetOutputPort() );
    m_EdgeTuber->SetVaryRadiusToVaryRadiusOff();
    m_EdgeTuber->SetNumberOfSides( 12 );
    m_EdgeTuber->CappingOn();

    m_EdgeMapper->SetInputConnection( m_EdgeTuber->GetOutputPort() );
    m_EdgeMapper->ScalarVisibilityOff();

    m_BackgroundMapper->SetInputData(emptyPolyData);
    m_BackgroundMapper->Update();

    m_EdgeActor->SetMapper( m_EdgeMapper );

    m_BackgroundActor->GetProperty()->SetAmbient( 0.5 );
    m_BackgroundActor->GetProperty()->SetColor( 0.0, 0.0, 0.0 );
    m_BackgroundActor->GetProperty()->SetOpacity( 0.0 );
    m_BackgroundActor->SetMapper( m_BackgroundMapper );

    vtkProperty * backfaceProperty = m_BackgroundActor->MakeProperty();
    backfaceProperty->SetColor( 0.0, 0.0, 0.0 );
    m_BackgroundActor->SetBackfaceProperty( backfaceProperty );
    backfaceProperty->Delete();

    m_FrontHedgeHog = vtkHedgeHog::New();
    m_BackHedgeHog  = vtkHedgeHog::New();

    m_FrontNormalsMapper = vtkPolyDataMapper::New();
    m_FrontNormalsMapper->SetInputConnection( m_FrontHedgeHog->GetOutputPort());
    m_BackNormalsMapper = vtkPolyDataMapper::New();

    m_Prop3DAssembly->AddPart( m_EdgeActor );
    m_Prop3DAssembly->AddPart( m_ImageAssembly );
    m_FrontNormalsActor = vtkActor::New();
    m_FrontNormalsActor->SetMapper(m_FrontNormalsMapper);
    m_BackNormalsActor = vtkActor::New();
    m_BackNormalsActor->SetMapper(m_BackNormalsMapper);

    m_ImageMapperDeletedCommand = MemberCommandType::New();
    m_ImageMapperDeletedCommand->SetCallbackFunction(
        this, &PlaneGeometryDataVtkMapper3D::ImageMapperDeletedCallback );
  }

  PlaneGeometryDataVtkMapper3D::~PlaneGeometryDataVtkMapper3D()
  {
    m_ImageAssembly->Delete();
    m_Prop3DAssembly->Delete();
    m_EdgeTuber->Delete();
    m_EdgeMapper->Delete();
    m_EdgeTransformer->Delete();
    m_Cleaner->Delete();
    m_Edges->Delete();
    m_NormalsTransformer->Delete();
    m_EdgeActor->Delete();
    m_BackgroundMapper->Delete();
    m_BackgroundActor->Delete();
    m_FrontNormalsMapper->Delete();
    m_FrontNormalsActor->Delete();
    m_FrontHedgeHog->Delete();
    m_BackNormalsMapper->Delete();
    m_BackNormalsActor->Delete();
    m_BackHedgeHog->Delete();

    for(ActorList::iterator it = m_ImageActors.begin();
        it!=m_ImageActors.end(); ++it)
      it->second.m_Actor->ReleaseGraphicsResources(0);

    // Delete entries in m_ImageActors list one by one
    m_ImageActors.clear();

    m_DataStorage = NULL;
  }
{'fraction_non_alphanumeric': 0.14093391075127096, 'fraction_numerical': 0.0057427979664846545, 'mean_word_length': 5.5817843866171, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 153, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5040953', 'n_tokens_mistral': 3475, 'n_tokens_neox': 3386, 'n_words': 500}