<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 "mitkContourModelSetGLMapper2D.h"

#include "mitkColorProperty.h"
#include "mitkContourModelSet.h"
#include "mitkPlaneGeometry.h"
#include "mitkProperties.h"
#include <vtkLinearTransform.h>

#include "mitkGL.h"

mitk::ContourModelSetGLMapper2D::ContourModelSetGLMapper2D()
{
}

mitk::ContourModelSetGLMapper2D::~ContourModelSetGLMapper2D()
{
}

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

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

  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();
}

mitk::ContourModelSet *mitk::ContourModelSetGLMapper2D::GetInput(void)
{
  return const_cast<mitk::ContourModelSet *>(static_cast<const mitk::ContourModelSet *>(GetDataNode()->GetData()));
}

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)
    {<commit_msg>Displaying of contourModels is now possible in real time (had extreme lags)<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 "mitkContourModelSetGLMapper2D.h"

#include "mitkColorProperty.h"
#include "mitkContourModelSet.h"
#include "mitkPlaneGeometry.h"
#include "mitkProperties.h"
#include <vtkLinearTransform.h>

#include "mitkGL.h"

mitk::ContourModelSetGLMapper2D::ContourModelSetGLMapper2D()
{
}

mitk::ContourModelSetGLMapper2D::~ContourModelSetGLMapper2D()
{
}

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

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

    if (!visible)
        return;

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

    auto centerOfViewPointZ = renderer->GetCurrentWorldPlaneGeometry()->GetCenter()[2];
    mitk::ContourModelSet::ContourModelSetIterator it = input->Begin();

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

    while (it != end)
    {
        //we have the assumption that each contour model vertex has the same z coordinate
        auto currentZValue = (*it)->GetVertexAt(0)->Coordinates[2];
        double acceptedDeviationInMM = 5.0;
        //only draw contour if it is visible
        if (currentZValue - acceptedDeviationInMM < centerOfViewPointZ && currentZValue + acceptedDeviationInMM > centerOfViewPointZ){
            this->DrawContour(it->GetPointer(), renderer);
        }
        ++it;
    }

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

    ls->UpdateGenerateDataTime();
}

mitk::ContourModelSet *mitk::ContourModelSetGLMapper2D::GetInput(void)
{
  return const_cast<mitk::ContourModelSet *>(static_cast<const mitk::ContourModelSet *>(GetDataNode()->GetData()));
}

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)
    {
{'fraction_non_alphanumeric': 0.15813953488372093, 'fraction_numerical': 0.00483005366726297, 'mean_word_length': 4.8852631578947365, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3522003', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1623, 'n_words': 344}