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

  Program:   Visualization Toolkit
  Module:    vtkChartXYZ.h

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm 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 notice for more information.

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

#include "vtkChartXYZ.h"

#include "vtkAnnotationLink.h"
#include "vtkAxis.h"
#include "vtkCommand.h"
#include "vtkContext2D.h"
#include "vtkContext3D.h"
#include "vtkContextKeyEvent.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextScene.h"
#include "vtkLookupTable.h"
#include "vtkMath.h"
#include "vtkPen.h"
#include "vtkPlane.h"
#include "vtkPlaneCollection.h"
#include "vtkPlot3D.h"
#include "vtkTable.h"
#include "vtkTextProperty.h"
#include "vtkTransform.h"
#include "vtkVector.h"
#include "vtkVectorOperators.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkIdTypeArray.h"

#include "vtkObjectFactory.h"

#include <sstream>

vtkStandardNewMacro(vtkChartXYZ)

//-----------------------------------------------------------------------------
vtkChartXYZ::vtkChartXYZ() : Geometry(0, 0, 10, 10), IsX(false), Angle(0)
{
  this->Pen->SetWidth(5);
  this->Pen->SetColor(0, 0, 0, 255);
  this->AxisPen->SetWidth(1);
  this->AxisPen->SetColor(0, 0, 0, 255);
  this->Rotation->Identity();
  this->Rotation->PostMultiply();
  this->Translation->Identity();
  this->Translation->PostMultiply();
  this->Scale->Identity();
  this->Scale->PostMultiply();
  this->Interactive = true;
  this->SceneWidth = 0;
  this->SceneHeight = 0;
  this->InitializeAxesBoundaryPoints();
  this->AutoRotate = false;
  this->DrawAxesDecoration = true;
  this->FitToScene = true;
  this->Axes.resize(3);
  for(unsigned int i = 0; i < 3; ++i)
    {
    vtkNew<vtkAxis> axis;
    this->Axes[i] = axis.GetPointer();
    }
}

//-----------------------------------------------------------------------------
vtkChartXYZ::~vtkChartXYZ()
{
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAngle(double angle)
{
  this->Angle = angle;
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAroundX(bool IsX_)
{
  this->IsX = IsX_;
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAutoRotate(bool b)
{
  this->AutoRotate = b;
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetDecorateAxes(bool b)
{
  this->DrawAxesDecoration = b;
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAnnotationLink(vtkAnnotationLink *link)
{
  if (this->Link != link)
    {
    this->Link = link;
    this->Modified();
    }
}

//-----------------------------------------------------------------------------
vtkAxis * vtkChartXYZ::GetAxis(int axis)
{
  assert(axis >= 0 && axis < 3);
  return this->Axes[axis].GetPointer();
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAxisColor(const vtkColor4ub& color)
{
  this->AxisPen->SetColor(color);
  this->Modified();
}

//-----------------------------------------------------------------------------
vtkColor4ub vtkChartXYZ::GetAxisColor()
{
  return this->AxisPen->GetColorObject();
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetGeometry(const vtkRectf &bounds)
{
  this->Geometry = bounds;

  this->Axes[0]->SetPoint1(vtkVector2f(this->Geometry.GetX(),
                           this->Geometry.GetY()));
  this->Axes[0]->SetPoint2(vtkVector2f(this->Geometry.GetX() + this->Geometry.GetWidth(),
                           this->Geometry.GetY()));

  this->Axes[1]->SetPoint1(vtkVector2f(this->Geometry.GetX(),
                           this->Geometry.GetY()));
  this->Axes[1]->SetPoint2(vtkVector2f(this->Geometry.GetX(),
                           this->Geometry.GetY() + this->Geometry.GetHeight()));

  // Z is faked, largely to get valid ranges and rounded numbers...
  this->Axes[2]->SetPoint1(vtkVector2f(this->Geometry.GetX(),
                           0));
  if (this->IsX)
    {
    this->Axes[2]->SetPoint2(vtkVector2f(this->Geometry.GetX(),
                             this->Geometry.GetHeight()));
    }
  else
    {
    this->Axes[2]->SetPoint2(vtkVector2f(this->Geometry.GetX(),
                             this->Geometry.GetWidth()));
    }
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::RecalculateBounds()
{
  if (this->Plots.empty())
    {
    return;
    }

  vtkVector3f firstPoint = this->Plots[0]->GetPoints()[0];
  double bounds[] = { firstPoint.GetX(), firstPoint.GetX(),
                      firstPoint.GetY(), firstPoint.GetY(),
                      firstPoint.GetZ(), firstPoint.GetZ()};

  // Need to calculate the bounds in three dimensions and set up the axes.
  for (unsigned int i = 0; i < this->Plots.size(); ++i)
    {
    std::vector<vtkVector3f> points = this->Plots[i]->GetPoints();
    for (unsigned int j = 0; j < points.size(); ++j)
      {
      const vtkVector3f &v = points[j];
      for (int k = 0; k < 3; ++k)
        {
        if (v[k] < bounds[2 * k])
          {
          bounds[2 * k] = v[k];
          }
        else if (v[k] > bounds[2 * k + 1])
          {
          bounds[2 * k + 1] = v[k];
          }
        }
      }
    }
  for (int i = 0; i < 3; ++i)
    {
    this->Axes[i]->SetUnscaledRange(&bounds[2*i]);
    }

  // Recalculate transform since axes' ranges were modified
  this->RecalculateTransform();
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::PrintSelf(ostream &os, vtkIndent indent)
{
  Superclass::PrintSelf(os, indent);
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::Update()
{
  if (this->Link)
    {
    vtkSelection *selection =
        vtkSelection::SafeDownCast(this->Link->GetOutputDataObject(2));<commit_msg>vtkChartXYZ: use dummy bounds rather for bounds calculation<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkChartXYZ.h

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm 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 notice for more information.

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

#include "vtkChartXYZ.h"

#include "vtkAnnotationLink.h"
#include "vtkAxis.h"
#include "vtkCommand.h"
#include "vtkContext2D.h"
#include "vtkContext3D.h"
#include "vtkContextKeyEvent.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextScene.h"
#include "vtkLookupTable.h"
#include "vtkMath.h"
#include "vtkPen.h"
#include "vtkPlane.h"
#include "vtkPlaneCollection.h"
#include "vtkPlot3D.h"
#include "vtkTable.h"
#include "vtkTextProperty.h"
#include "vtkTransform.h"
#include "vtkVector.h"
#include "vtkVectorOperators.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkIdTypeArray.h"

#include "vtkObjectFactory.h"

#include <sstream>

vtkStandardNewMacro(vtkChartXYZ)

//-----------------------------------------------------------------------------
vtkChartXYZ::vtkChartXYZ() : Geometry(0, 0, 10, 10), IsX(false), Angle(0)
{
  this->Pen->SetWidth(5);
  this->Pen->SetColor(0, 0, 0, 255);
  this->AxisPen->SetWidth(1);
  this->AxisPen->SetColor(0, 0, 0, 255);
  this->Rotation->Identity();
  this->Rotation->PostMultiply();
  this->Translation->Identity();
  this->Translation->PostMultiply();
  this->Scale->Identity();
  this->Scale->PostMultiply();
  this->Interactive = true;
  this->SceneWidth = 0;
  this->SceneHeight = 0;
  this->InitializeAxesBoundaryPoints();
  this->AutoRotate = false;
  this->DrawAxesDecoration = true;
  this->FitToScene = true;
  this->Axes.resize(3);
  for(unsigned int i = 0; i < 3; ++i)
    {
    vtkNew<vtkAxis> axis;
    this->Axes[i] = axis.GetPointer();
    }
}

//-----------------------------------------------------------------------------
vtkChartXYZ::~vtkChartXYZ()
{
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAngle(double angle)
{
  this->Angle = angle;
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAroundX(bool IsX_)
{
  this->IsX = IsX_;
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAutoRotate(bool b)
{
  this->AutoRotate = b;
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetDecorateAxes(bool b)
{
  this->DrawAxesDecoration = b;
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAnnotationLink(vtkAnnotationLink *link)
{
  if (this->Link != link)
    {
    this->Link = link;
    this->Modified();
    }
}

//-----------------------------------------------------------------------------
vtkAxis * vtkChartXYZ::GetAxis(int axis)
{
  assert(axis >= 0 && axis < 3);
  return this->Axes[axis].GetPointer();
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAxisColor(const vtkColor4ub& color)
{
  this->AxisPen->SetColor(color);
  this->Modified();
}

//-----------------------------------------------------------------------------
vtkColor4ub vtkChartXYZ::GetAxisColor()
{
  return this->AxisPen->GetColorObject();
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::SetGeometry(const vtkRectf &bounds)
{
  this->Geometry = bounds;

  this->Axes[0]->SetPoint1(vtkVector2f(this->Geometry.GetX(),
                           this->Geometry.GetY()));
  this->Axes[0]->SetPoint2(vtkVector2f(this->Geometry.GetX() + this->Geometry.GetWidth(),
                           this->Geometry.GetY()));

  this->Axes[1]->SetPoint1(vtkVector2f(this->Geometry.GetX(),
                           this->Geometry.GetY()));
  this->Axes[1]->SetPoint2(vtkVector2f(this->Geometry.GetX(),
                           this->Geometry.GetY() + this->Geometry.GetHeight()));

  // Z is faked, largely to get valid ranges and rounded numbers...
  this->Axes[2]->SetPoint1(vtkVector2f(this->Geometry.GetX(),
                           0));
  if (this->IsX)
    {
    this->Axes[2]->SetPoint2(vtkVector2f(this->Geometry.GetX(),
                             this->Geometry.GetHeight()));
    }
  else
    {
    this->Axes[2]->SetPoint2(vtkVector2f(this->Geometry.GetX(),
                             this->Geometry.GetWidth()));
    }
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::RecalculateBounds()
{
  if (this->Plots.empty())
    {
    return;
    }

  double bounds[] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MIN,
                      VTK_DOUBLE_MAX, VTK_DOUBLE_MIN,
                      VTK_DOUBLE_MAX, VTK_DOUBLE_MIN};

  // Need to calculate the bounds in three dimensions and set up the axes.
  for (unsigned int i = 0; i < this->Plots.size(); ++i)
    {
    std::vector<vtkVector3f> points = this->Plots[i]->GetPoints();
    for (unsigned int j = 0; j < points.size(); ++j)
      {
      const vtkVector3f &v = points[j];
      for (int k = 0; k < 3; ++k)
        {
        if (v[k] < bounds[2 * k])
          {
          bounds[2 * k] = v[k];
          }
        if (v[k] > bounds[2 * k + 1])
          {
          bounds[2 * k + 1] = v[k];
          }
        }
      }
    }
  for (int i = 0; i < 3; ++i)
    {
    this->Axes[i]->SetUnscaledRange(&bounds[2*i]);
    }

  // Recalculate transform since axes' ranges were modified
  this->RecalculateTransform();
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::PrintSelf(ostream &os, vtkIndent indent)
{
  Superclass::PrintSelf(os, indent);
}

//-----------------------------------------------------------------------------
void vtkChartXYZ::Update()
{
  if (this->Link)
    {
    vtkSelection *selection =
        vtkSelection::SafeDownCast(this->Link->GetOutputDataObject(2));
{'fraction_non_alphanumeric': 0.3248775090880354, 'fraction_numerical': 0.011458827248300933, 'mean_word_length': 1.7092699636052238, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 187, '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': '4596110', 'n_tokens_mistral': 3855, 'n_tokens_neox': 3716, 'n_words': 678}