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

  Program:   Visualization Toolkit
  Module:    vtkIconGlyphFilter.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.

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


#include "vtkIconGlyphFilter.h"

#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkIdList.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPointLocator.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"

vtkCxxRevisionMacro(vtkIconGlyphFilter, "1.6");
vtkStandardNewMacro(vtkIconGlyphFilter);

//-----------------------------------------------------------------------------
vtkIconGlyphFilter::vtkIconGlyphFilter()
{
  this->IconSize[0] = 1;
  this->IconSize[1] = 1;
  this->IconSheetSize[0] = 1;
  this->IconSheetSize[1] = 1;
  this->UseIconSize = true;

  this->SetInputArrayToProcess(0, 0, 0, 
    vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::SCALARS);
}

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

//-----------------------------------------------------------------------------
void vtkIconGlyphFilter::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "IconSize: " << this->IconSize[0] << " " << this->IconSize[1] << endl;
  os << indent << "IconSheetSize: " << this->IconSheetSize[0] << " " << this->IconSheetSize[1] << endl;
}

//----------------------------------------------------------------------------
void vtkIconGlyphFilter::SetUseIconSize(bool b)
{
  this->UseIconSize = b;
}

//----------------------------------------------------------------------------
bool vtkIconGlyphFilter::GetUseIconSize()
{
  return this->UseIconSize;
}

//-----------------------------------------------------------------------------
int vtkIconGlyphFilter::RequestData(vtkInformation *vtkNotUsed(request),
                                  vtkInformationVector **inputVector,
                                  vtkInformationVector *outputVector)
{
  // Get the information object.
  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
  vtkInformation *outInfo = outputVector->GetInformationObject(0);

  // Get the data objects.
  vtkPointSet *input = vtkPointSet::SafeDownCast(
                                     inInfo->Get(vtkDataObject::DATA_OBJECT()));
  vtkPolyData *output = vtkPolyData::SafeDownCast(
                                    outInfo->Get(vtkDataObject::DATA_OBJECT()));

  int numPoints = input->GetNumberOfPoints();

  if (numPoints <= 0)
    {
    // nothing to do...
    return 1;
    }

  vtkIntArray* scalars = vtkIntArray::SafeDownCast(
    this->GetInputArrayToProcess(0, inputVector));
  if (!scalars)
    {
    vtkErrorMacro("Input Scalars must be specified to index into the icon sheet.");
    return 0;
    }

  double point[3], textureCoord[2];
  double sheetXDim = this->IconSheetSize[0]/this->IconSize[0];
  double sheetYDim = this->IconSheetSize[1]/this->IconSize[1];
  int iconIndex = 0;
  int j, k;

  vtkPoints * outPoints = vtkPoints::New();
  outPoints->Allocate(4 * numPoints);

  vtkCellArray * outCells = vtkCellArray::New();
  outCells->Allocate(outCells->EstimateSize(numPoints, 4));

  vtkFloatArray *outTCoords = vtkFloatArray::New();
  outTCoords->SetNumberOfComponents(2);
  outTCoords->Allocate(8*numPoints);

  double size = 1.0;
  if(this->UseIconSize)
    {
    size = 32.0;
    }

  for(int i = 0; i < numPoints; i++)
    {
    iconIndex = scalars->GetValue(i);
    input->GetPoint(i, point);
    outPoints->InsertNextPoint(point[0] - 0.5 * size, point[1] - 0.5* size, point[2]);

    this->IconConvertIndex(iconIndex, j, k);
    textureCoord[0] = j/sheetXDim;
    textureCoord[1] = k/sheetYDim;
    outTCoords->InsertTuple(i * 4, textureCoord);

    outPoints->InsertNextPoint(point[0] + 0.5 * size, point[1] - 0.5 * size, point[2]);

    this->IconConvertIndex(iconIndex, j, k);
    textureCoord[0] = (j + 1.0)/sheetXDim;
    textureCoord[1] = k/sheetYDim;
    outTCoords->InsertTuple(i * 4 + 1, textureCoord);

    outPoints->InsertNextPoint(point[0] + 0.5 * size, point[1] + 0.5 * size, point[2]);

    this->IconConvertIndex(iconIndex, j, k);
    textureCoord[0] = (j + 1.0)/sheetXDim;
    textureCoord[1] = (k + 1.0)/sheetYDim;
    outTCoords->InsertTuple(i * 4 + 2, textureCoord);

    outPoints->InsertNextPoint(point[0] - 0.5 * size, point[1] + 0.5 * size, point[2]);

    this->IconConvertIndex(iconIndex, j, k);
    textureCoord[0] = j/sheetXDim;
    textureCoord[1] = (k + 1.0)/sheetYDim;
    outTCoords->InsertTuple(i * 4 + 3, textureCoord);

    outCells->InsertNextCell(4);
    outCells->InsertCellPoint(i * 4);
    outCells->InsertCellPoint(i * 4 + 1);
    outCells->InsertCellPoint(i * 4 + 2);
    outCells->InsertCellPoint(i * 4 + 3);
    }

  output->SetPoints(outPoints);
  outPoints->Delete();

  outTCoords->SetName("TextureCoordinates");
  output->GetPointData()->SetTCoords(outTCoords);
  outTCoords->Delete();<commit_msg>ENH: Modified vtkIconGlyphFilter so that you can tell it to use the icons size to render the icon of 1x1.<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkIconGlyphFilter.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.

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


#include "vtkIconGlyphFilter.h"

#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkIdList.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPointLocator.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"

vtkCxxRevisionMacro(vtkIconGlyphFilter, "1.7");
vtkStandardNewMacro(vtkIconGlyphFilter);

//-----------------------------------------------------------------------------
vtkIconGlyphFilter::vtkIconGlyphFilter()
{
  this->IconSize[0] = 1;
  this->IconSize[1] = 1;
  this->IconSheetSize[0] = 1;
  this->IconSheetSize[1] = 1;
  this->UseIconSize = true;

  this->SetInputArrayToProcess(0, 0, 0, 
    vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::SCALARS);
}

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

//-----------------------------------------------------------------------------
void vtkIconGlyphFilter::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "IconSize: " << this->IconSize[0] << " " << this->IconSize[1] << endl;
  os << indent << "IconSheetSize: " << this->IconSheetSize[0] << " " << this->IconSheetSize[1] << endl;
}

//----------------------------------------------------------------------------
void vtkIconGlyphFilter::SetUseIconSize(bool b)
{
  this->UseIconSize = b;
}

//----------------------------------------------------------------------------
bool vtkIconGlyphFilter::GetUseIconSize()
{
  return this->UseIconSize;
}

//-----------------------------------------------------------------------------
int vtkIconGlyphFilter::RequestData(vtkInformation *vtkNotUsed(request),
                                  vtkInformationVector **inputVector,
                                  vtkInformationVector *outputVector)
{
  // Get the information object.
  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
  vtkInformation *outInfo = outputVector->GetInformationObject(0);

  // Get the data objects.
  vtkPointSet *input = vtkPointSet::SafeDownCast(
                                     inInfo->Get(vtkDataObject::DATA_OBJECT()));
  vtkPolyData *output = vtkPolyData::SafeDownCast(
                                    outInfo->Get(vtkDataObject::DATA_OBJECT()));

  int numPoints = input->GetNumberOfPoints();

  if (numPoints <= 0)
    {
    // nothing to do...
    return 1;
    }

  vtkIntArray* scalars = vtkIntArray::SafeDownCast(
    this->GetInputArrayToProcess(0, inputVector));
  if (!scalars)
    {
    vtkErrorMacro("Input Scalars must be specified to index into the icon sheet.");
    return 0;
    }

  double point[3], textureCoord[2];
  double sheetXDim = this->IconSheetSize[0]/this->IconSize[0];
  double sheetYDim = this->IconSheetSize[1]/this->IconSize[1];
  int iconIndex = 0;
  int j, k;

  vtkPoints * outPoints = vtkPoints::New();
  outPoints->Allocate(4 * numPoints);

  vtkCellArray * outCells = vtkCellArray::New();
  outCells->Allocate(outCells->EstimateSize(numPoints, 4));

  vtkFloatArray *outTCoords = vtkFloatArray::New();
  outTCoords->SetNumberOfComponents(2);
  outTCoords->Allocate(8*numPoints);

  double size[2] = {1.0, 1.0};
  if(this->UseIconSize)
    {
    size[0] = this->IconSize[0];
    size[1] = this->IconSize[1];
    }

  for(int i = 0; i < numPoints; i++)
    {
    iconIndex = scalars->GetValue(i);
    input->GetPoint(i, point);
    outPoints->InsertNextPoint(point[0] - 0.5 * size[0], point[1] - 0.5* size[1], point[2]);

    this->IconConvertIndex(iconIndex, j, k);
    textureCoord[0] = j/sheetXDim;
    textureCoord[1] = k/sheetYDim;
    outTCoords->InsertTuple(i * 4, textureCoord);

    outPoints->InsertNextPoint(point[0] + 0.5 * size[0], point[1] - 0.5 * size[1], point[2]);

    this->IconConvertIndex(iconIndex, j, k);
    textureCoord[0] = (j + 1.0)/sheetXDim;
    textureCoord[1] = k/sheetYDim;
    outTCoords->InsertTuple(i * 4 + 1, textureCoord);

    outPoints->InsertNextPoint(point[0] + 0.5 * size[0], point[1] + 0.5 * size[1], point[2]);

    this->IconConvertIndex(iconIndex, j, k);
    textureCoord[0] = (j + 1.0)/sheetXDim;
    textureCoord[1] = (k + 1.0)/sheetYDim;
    outTCoords->InsertTuple(i * 4 + 2, textureCoord);

    outPoints->InsertNextPoint(point[0] - 0.5 * size[0], point[1] + 0.5 * size[1], point[2]);

    this->IconConvertIndex(iconIndex, j, k);
    textureCoord[0] = j/sheetXDim;
    textureCoord[1] = (k + 1.0)/sheetYDim;
    outTCoords->InsertTuple(i * 4 + 3, textureCoord);

    outCells->InsertNextCell(4);
    outCells->InsertCellPoint(i * 4);
    outCells->InsertCellPoint(i * 4 + 1);
    outCells->InsertCellPoint(i * 4 + 2);
    outCells->InsertCellPoint(i * 4 + 3);
    }

  output->SetPoints(outPoints);
  outPoints->Delete();

  outTCoords->SetName("TextureCoordinates");
  output->GetPointData()->SetTCoords(outTCoords);
  outTCoords->Delete();
{'fraction_non_alphanumeric': 0.24107701941139636, 'fraction_numerical': 0.019143036049736113, 'mean_word_length': 2.722943722943723, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 119, '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': '3604229', 'n_tokens_mistral': 3680, 'n_tokens_neox': 3508, 'n_words': 659}