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

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date: 2009-07-08 11:04:08 +0200 (Mi, 08 Jul 2009) $
Version:   $Revision: 18029 $

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

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


#include "mitkPlanarFigure.h"
#include "mitkGeometry2D.h"
#include "mitkProperties.h"

#include "algorithm"


mitk::PlanarFigure::PlanarFigure()
: m_FigurePlaced( false ),
m_PreviewControlPointVisible( false ),
m_SelectedControlPoint( -1 ),
m_Geometry2D( NULL ),
m_PolyLineUpToDate(false),
m_HelperLinesUpToDate(false),
m_FeaturesUpToDate(false),
m_FeaturesMTime( 0 )
{
  m_HelperPolyLinesToBePainted = BoolContainerType::New();

  m_DisplaySize.first = 0.0;
  m_DisplaySize.second = 0;

  this->SetProperty( "closed", mitk::BoolProperty::New( false ) );

  // Currently only single-time-step geometries are supported
  this->InitializeTimeSlicedGeometry( 1 );
}


mitk::PlanarFigure::~PlanarFigure()
{
}


void mitk::PlanarFigure::SetGeometry2D( mitk::Geometry2D *geometry )
{
  this->SetGeometry( geometry );
  m_Geometry2D = geometry;
}


const mitk::Geometry2D *mitk::PlanarFigure::GetGeometry2D() const
{
  return m_Geometry2D;
}


bool mitk::PlanarFigure::IsClosed() const
{
  mitk::BoolProperty* closed = dynamic_cast< mitk::BoolProperty* >( this->GetProperty( "closed" ).GetPointer() );
  if ( closed != NULL )
  {
    return closed->GetValue();
  }
  return false;
}


void mitk::PlanarFigure::PlaceFigure( const mitk::Point2D& point )
{
  for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
  {
    m_ControlPoints.push_back( this->ApplyControlPointConstraints( i, point ) );
  }

  m_FigurePlaced = true;
  m_SelectedControlPoint = 1;
}


bool mitk::PlanarFigure::AddControlPoint( const mitk::Point2D& point, int position )
{
  // if we already have the maximum number of control points, do nothing
  if ( m_NumberOfControlPoints < this->GetMaximumNumberOfControlPoints() )
  {
    // if position has not been defined or position would be the last control point, just append the new one
    if ( position == -1 || position > m_NumberOfControlPoints-1 )
    {
      m_ControlPoints.push_back( this->ApplyControlPointConstraints( m_NumberOfControlPoints, point ) );
      m_SelectedControlPoint = m_NumberOfControlPoints;
    }
    else
    {
      // insert the point at the given position
      ControlPointListType::iterator iter = m_ControlPoints.begin() + position;
      m_ControlPoints.insert( iter, this->ApplyControlPointConstraints( m_NumberOfControlPoints, point ) );
      m_SelectedControlPoint = m_NumberOfControlPoints;
    }

    // polylines & helperpolylines need to be repainted
    m_PolyLineUpToDate = false;
    m_HelperLinesUpToDate = false;<commit_msg>resetting m_ControlPoints to ensure correctness of PlanarCross<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date: 2009-07-08 11:04:08 +0200 (Mi, 08 Jul 2009) $
Version:   $Revision: 18029 $

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

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


#include "mitkPlanarFigure.h"
#include "mitkGeometry2D.h"
#include "mitkProperties.h"

#include "algorithm"


mitk::PlanarFigure::PlanarFigure()
: m_FigurePlaced( false ),
m_PreviewControlPointVisible( false ),
m_SelectedControlPoint( -1 ),
m_Geometry2D( NULL ),
m_PolyLineUpToDate(false),
m_HelperLinesUpToDate(false),
m_FeaturesUpToDate(false),
m_FeaturesMTime( 0 )
{
  m_HelperPolyLinesToBePainted = BoolContainerType::New();

  m_DisplaySize.first = 0.0;
  m_DisplaySize.second = 0;

  this->SetProperty( "closed", mitk::BoolProperty::New( false ) );

  // Currently only single-time-step geometries are supported
  this->InitializeTimeSlicedGeometry( 1 );
}


mitk::PlanarFigure::~PlanarFigure()
{
}


void mitk::PlanarFigure::SetGeometry2D( mitk::Geometry2D *geometry )
{
  this->SetGeometry( geometry );
  m_Geometry2D = geometry;
}


const mitk::Geometry2D *mitk::PlanarFigure::GetGeometry2D() const
{
  return m_Geometry2D;
}


bool mitk::PlanarFigure::IsClosed() const
{
  mitk::BoolProperty* closed = dynamic_cast< mitk::BoolProperty* >( this->GetProperty( "closed" ).GetPointer() );
  if ( closed != NULL )
  {
    return closed->GetValue();
  }
  return false;
}


void mitk::PlanarFigure::PlaceFigure( const mitk::Point2D& point )
{
  for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
  {
    m_ControlPoints.push_back( this->ApplyControlPointConstraints( i, point ) );
  }

  m_FigurePlaced = true;
  m_SelectedControlPoint = 1;
}


bool mitk::PlanarFigure::AddControlPoint( const mitk::Point2D& point, int position )
{
  // if we already have the maximum number of control points, do nothing
  if ( m_NumberOfControlPoints < this->GetMaximumNumberOfControlPoints() )
  {
    // if position has not been defined or position would be the last control point, just append the new one
    if ( position == -1 || position > m_NumberOfControlPoints-1 )
    {
      if ( m_ControlPoints.size() > this->GetMaximumNumberOfControlPoints()-1 )
      {
        m_ControlPoints.resize( this->GetMaximumNumberOfControlPoints()-1 );
      }

      m_ControlPoints.push_back( this->ApplyControlPointConstraints( m_NumberOfControlPoints, point ) );
      m_SelectedControlPoint = m_NumberOfControlPoints;
    }
    else
    {
      // insert the point at the given position
      ControlPointListType::iterator iter = m_ControlPoints.begin() + position;
      m_ControlPoints.insert( iter, this->ApplyControlPointConstraints( m_NumberOfControlPoints, point ) );
      m_SelectedControlPoint = m_NumberOfControlPoints;
    }

    // polylines & helperpolylines need to be repainted
    m_PolyLineUpToDate = false;
    m_HelperLinesUpToDate = false;
{'fraction_non_alphanumeric': 0.1448099744629713, 'fraction_numerical': 0.01502178158329578, 'mean_word_length': 4.8868258178603, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 30, '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': '6812650', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1958, 'n_words': 496}