<commit_before>/*=========================================================================
  
Program:   Visualization Toolkit
Module:    vtkPairwiseExtractHistogram2D.cxx

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.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2009 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
  -------------------------------------------------------------------------*/

#include "vtkPairwiseExtractHistogram2D.h"
//------------------------------------------------------------------------------
#include "vtkArrayData.h"
#include "vtkArrayIteratorIncludes.h"
#include "vtkStatisticsAlgorithmPrivate.h"
#include "vtkCollection.h"
#include "vtkExtractHistogram2D.h"
#include "vtkIdTypeArray.h"
#include "vtkImageData.h"
#include "vtkImageMedian3D.h"
#include "vtkInformation.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkStdString.h"
#include "vtkTable.h"
#include "vtkTimerLog.h"
#include "vtkUnsignedIntArray.h"
//------------------------------------------------------------------------------
#include <vtkstd/set>
#include <vtkstd/vector>
#include <vtkstd/string>
#include <vtkstd/map>
//------------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkPairwiseExtractHistogram2D, "1.3");
vtkStandardNewMacro(vtkPairwiseExtractHistogram2D);
//------------------------------------------------------------------------------
class vtkPairwiseExtractHistogram2D::Internals
{
public:
  vtkstd::vector< vtkstd::pair< vtkStdString,vtkStdString > > ColumnPairs;
  vtkstd::map< vtkstd::string,bool > ColumnUsesCustomExtents;
  vtkstd::map< vtkstd::string,vtkstd::vector<double> > ColumnExtents;
};
//------------------------------------------------------------------------------
vtkPairwiseExtractHistogram2D::vtkPairwiseExtractHistogram2D()
{
  this->Implementation = new Internals;
  
  this->SetNumberOfOutputPorts(4);
  
  this->NumberOfBins[0] = 0;
  this->NumberOfBins[1] = 0;
  
  this->CustomColumnRangeIndex = -1;
  
  this->ScalarType = VTK_UNSIGNED_INT;
  this->HistogramFilters = vtkSmartPointer<vtkCollection>::New();
  this->BuildTime.Modified();
}
//------------------------------------------------------------------------------
vtkPairwiseExtractHistogram2D::~vtkPairwiseExtractHistogram2D()
{
  delete this->Implementation;
}
//------------------------------------------------------------------------------
void vtkPairwiseExtractHistogram2D::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
  os << "NumberOfBins: " << this->NumberOfBins[0] << ", " << this->NumberOfBins[1] << endl;
  os << "CustomColumnRangeIndex: " << this->CustomColumnRangeIndex << endl;
  os << "ScalarType: " << this->ScalarType << endl;
}
//------------------------------------------------------------------------------
void vtkPairwiseExtractHistogram2D::Learn(vtkTable *inData, 
                                          vtkTable* vtkNotUsed(inParameters), 
                                          vtkDataObject *outMetaDO)
{
  vtkTable* outMeta = vtkTable::SafeDownCast( outMetaDO ); 
  if ( ! outMeta ) 
    { 
    return; 
    } 
  
  if (this->NumberOfBins[0] == 0 || this->NumberOfBins[1] == 0)
    {
    vtkErrorMacro(<<"Error: histogram dimensions not set (use SetNumberOfBins).");
    return;
    }
  
  
  // if the number of columns in the input has changed, we'll need to do 
  // some reinitializing
  int numHistograms = inData->GetNumberOfColumns()-1;
  if (numHistograms != this->HistogramFilters->GetNumberOfItems())
    {
    // clear out the list of histogram filters
    for (int i=0; i<this->HistogramFilters->GetNumberOfItems(); i++)
      {
      this->HistogramFilters->GetItemAsObject(i)->Delete();
      }
    
    // clear out the internals
    this->HistogramFilters->RemoveAllItems();
    this->Implementation->ColumnPairs.clear();
    this->Implementation->ColumnUsesCustomExtents.clear();
    this->Implementation->ColumnExtents.clear();
    
    // fill it up with new histogram filters
    for (int i=0; i<numHistograms; i++)
      {
      vtkDataArray* col1 = vtkDataArray::SafeDownCast(inData->GetColumn(i));
      vtkDataArray* col2 = vtkDataArray::SafeDownCast(inData->GetColumn(i+1));
      
      if (!col1 || !col2)
        {
        vtkErrorMacro("All inputs must be numeric arrays.");
        return;
        }
      
      // create a new histogram filter
      vtkExtractHistogram2D* f = this->NewHistogramFilter();
      f->SetInput(inData);
      f->SetNumberOfBins(this->NumberOfBins);
      vtkstd::pair<vtkStdString,vtkStdString> colpair(inData->GetColumn(i)->GetName(),inData->GetColumn(i+1)->GetName());
      f->AddColumnPair(colpair.first.c_str(),colpair.second.c_str());
      f->SetSwapColumns(strcmp(colpair.first.c_str(),colpair.second.c_str())>=0);
      this->HistogramFilters->AddItem(f);
      
      // update the internals accordingly
      this->Implementation->ColumnPairs.push_back(colpair);
      this->Implementation->ColumnUsesCustomExtents[colpair.first.c_str()] = false;
      <commit_msg>BUG: Fig grievous errors in handling internal filters.<commit_after>/*=========================================================================
  
Program:   Visualization Toolkit
Module:    vtkPairwiseExtractHistogram2D.cxx

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.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2009 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
  -------------------------------------------------------------------------*/

#include "vtkPairwiseExtractHistogram2D.h"
//------------------------------------------------------------------------------
#include "vtkArrayData.h"
#include "vtkArrayIteratorIncludes.h"
#include "vtkStatisticsAlgorithmPrivate.h"
#include "vtkCollection.h"
#include "vtkExtractHistogram2D.h"
#include "vtkIdTypeArray.h"
#include "vtkImageData.h"
#include "vtkImageMedian3D.h"
#include "vtkInformation.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkStdString.h"
#include "vtkTable.h"
#include "vtkTimerLog.h"
#include "vtkUnsignedIntArray.h"

#define VTK_CREATE(type, name) \
  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
//------------------------------------------------------------------------------
#include <vtkstd/set>
#include <vtkstd/vector>
#include <vtkstd/string>
#include <vtkstd/map>
//------------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkPairwiseExtractHistogram2D, "1.4");
vtkStandardNewMacro(vtkPairwiseExtractHistogram2D);
//------------------------------------------------------------------------------
class vtkPairwiseExtractHistogram2D::Internals
{
public:
  vtkstd::vector< vtkstd::pair< vtkStdString,vtkStdString > > ColumnPairs;
  vtkstd::map< vtkstd::string,bool > ColumnUsesCustomExtents;
  vtkstd::map< vtkstd::string,vtkstd::vector<double> > ColumnExtents;
};
//------------------------------------------------------------------------------
vtkPairwiseExtractHistogram2D::vtkPairwiseExtractHistogram2D()
{
  this->Implementation = new Internals;
  
  this->SetNumberOfOutputPorts(4);
  
  this->NumberOfBins[0] = 0;
  this->NumberOfBins[1] = 0;
  
  this->CustomColumnRangeIndex = -1;
  
  this->ScalarType = VTK_UNSIGNED_INT;
  this->HistogramFilters = vtkSmartPointer<vtkCollection>::New();
  this->BuildTime.Modified();
}
//------------------------------------------------------------------------------
vtkPairwiseExtractHistogram2D::~vtkPairwiseExtractHistogram2D()
{
  delete this->Implementation;
}
//------------------------------------------------------------------------------
void vtkPairwiseExtractHistogram2D::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
  os << "NumberOfBins: " << this->NumberOfBins[0] << ", " << this->NumberOfBins[1] << endl;
  os << "CustomColumnRangeIndex: " << this->CustomColumnRangeIndex << endl;
  os << "ScalarType: " << this->ScalarType << endl;
}
//------------------------------------------------------------------------------
void vtkPairwiseExtractHistogram2D::Learn(vtkTable *inData, 
                                          vtkTable* vtkNotUsed(inParameters), 
                                          vtkDataObject *outMetaDO)
{
  vtkTable* outMeta = vtkTable::SafeDownCast( outMetaDO ); 
  if ( ! outMeta ) 
    { 
    return; 
    } 
  
  if (this->NumberOfBins[0] == 0 || this->NumberOfBins[1] == 0)
    {
    vtkErrorMacro(<<"Error: histogram dimensions not set (use SetNumberOfBins).");
    return;
    }
  
  
  // if the number of columns in the input has changed, we'll need to do 
  // some reinitializing
  int numHistograms = inData->GetNumberOfColumns()-1;
  if (numHistograms != this->HistogramFilters->GetNumberOfItems())
    {
    // clear out the list of histogram filters
    for (int i=0; i<this->HistogramFilters->GetNumberOfItems(); i++)
      {
      this->HistogramFilters->GetItemAsObject(i)->Delete();
      }
    
    // clear out the internals
    this->HistogramFilters->RemoveAllItems();
    this->Implementation->ColumnPairs.clear();
    this->Implementation->ColumnUsesCustomExtents.clear();
    this->Implementation->ColumnExtents.clear();

    // Make a shallow copy of the input to be safely passed to internal
    // histogram filters.
    VTK_CREATE(vtkTable, inDataCopy);
    inDataCopy->ShallowCopy(inData);
    
    // fill it up with new histogram filters
    for (int i=0; i<numHistograms; i++)
      {
      vtkDataArray* col1 = vtkDataArray::SafeDownCast(inData->GetColumn(i));
      vtkDataArray* col2 = vtkDataArray::SafeDownCast(inData->GetColumn(i+1));
      
      if (!col1 || !col2)
        {
        vtkErrorMacro("All inputs must be numeric arrays.");
        return;
        }
      
      // create a new histogram filter
      vtkSmartPointer<vtkExtractHistogram2D> f;
      f.TakeReference(this->NewHistogramFilter());
      f->SetInput(inDataCopy);
      f->SetNumberOfBins(this->NumberOfBins);
      vtkstd::pair<vtkStdString,vtkStdString> colpair(inData->GetColumn(i)->GetName(),inData->GetColumn(i+1)->GetName());
      f->AddColumnPair(colpair.first.c_str(),colpair.second.c_str());
      f->SetSwapColumns(strcmp(colpair.first.c_str(),colpair.second.c_str())>=0);
      this->HistogramFilters->AddItem(f);
      
      // update the internals accordingly
      this->Implementation->ColumnPairs.push_back(colpair);
      this->Implementation->ColumnUsesCustomExtents[colpair.first.c_str()] = false;
      
{'fraction_non_alphanumeric': 0.2674730021598272, 'fraction_numerical': 0.008812095032397408, 'mean_word_length': 2.332181922855498, 'pattern_counts': {'":': 0, '<': 86, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3507316', 'n_tokens_mistral': 3337, 'n_tokens_neox': 3288, 'n_words': 603}