<commit_before>import * as macro from '../../../macro';
import vtk from '../../../vtk';

import vtkPoints from '../../../Common/Core/Points';

// ----------------------------------------------------------------------------
// Global methods
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Static API
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// vtkWarpScalar methods
// ----------------------------------------------------------------------------

function vtkWarpScalar(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkWarpScalar');

  publicAPI.requestData = (inData, outData) => { // implement requestData
    if (!outData[0] || inData[0].getMTime() > outData[0].getMTime() || publicAPI.getMTime() > outData[0].getMTime()) {
      const input = inData[0];

      // if (!input)
        // {
        // Try converting image data.
        // vtkImageData *inImage = vtkImageData::GetData(inputVector[0]);
        // if (inImage)
          // {
          // vtkNew<vtkImageDataToPointSet> image2points;
          // image2points->SetInputData(inImage);
          // image2points->Update();
          // input = image2points->GetOutput();
          // }
        // }

      // if (!input)
        // {
        // Try converting rectilinear grid.
        // vtkRectilinearGrid *inRect = vtkRectilinearGrid::GetData(inputVector[0]);
        // if (inRect)
          // {
          // vtkNew<vtkRectilinearGridToPointSet> rect2points;
          // rect2points->SetInputData(inRect);
          // rect2points->Update();
          // input = rect2points->GetOutput();
          // }
        // }

      if (!input) {
        vtkErrorMacro('Invalid or missing input');
        return 1;
      }

      // First, copy the input to the output as a starting point
      // output->CopyStructure( input );

      const inPts = input.getPoints().getData();
      const pd = input.getPointData();
      const inNormals = pd.getNormals();
      const inScalars = publicAPI.getInputArrayToProcess(0);

      if (!inPts || !inScalars) {
        vtkDebugMacro('No data to warp', !!inPts, !!inScalars);
        outData[0] = inData[0];
        return 1;
      }

      const numPts = inPts.getNumberOfValues();

      let pointNormal = null;

      const normal = [0, 0, 1];
      if (inNormals && !model.useNormal) {
        pointNormal = (id, array) => [
          array.getData()[(id * 3)],
          array.getData()[(id * 3) + 1],
          array.getData()[(id * 3) + 2],
        ];
        // vtkDebugMacro('Using data normals');
      } else if (publicAPI.getXyPlane()) {
        pointNormal = (id, array) => normal;
        // vtkDebugMacro('Using x-y plane normal');
      } else {
        pointNormal = (id, array) => model.normal;
        // vtkDebugMacro('Using Normal instance variable');
      }

      const newPtsData = new Float32Array(numPts * 3);
      const inPoints = inPts.getData();
      let ptOffset = 0;
      let n = [0, 0, 1];
      let s = 1;

      // Loop over all points, adjusting locations
      const scalarDataArray = inScalars.getData();
      for (let ptId = 0; ptId < numPts; ++ptId) {
        ptOffset = ptId * 3;
        n = pointNormal(ptId, inNormals);

        if (model.xyPlane) {
          s = inPoints[ptOffset + 2];
        } else {
          s = scalarDataArray[ptId];
        }

        newPtsData[ptOffset] = inPoints[ptOffset] + (model.scaleFactor * s * n[0]);
        newPtsData[ptOffset + 1] = inPoints[ptOffset + 1] + (model.scaleFactor * s * n[1]);
        newPtsData[ptOffset + 2] = inPoints[ptOffset + 2] + (model.scaleFactor * s * n[2]);
      }
<commit_msg>fix(WarpScalar): Use first component of array...<commit_after>import * as macro from '../../../macro';
import vtk from '../../../vtk';

import vtkPoints from '../../../Common/Core/Points';

// ----------------------------------------------------------------------------
// Global methods
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Static API
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// vtkWarpScalar methods
// ----------------------------------------------------------------------------

function vtkWarpScalar(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkWarpScalar');

  publicAPI.requestData = (inData, outData) => { // implement requestData
    if (!outData[0] || inData[0].getMTime() > outData[0].getMTime() || publicAPI.getMTime() > outData[0].getMTime()) {
      const input = inData[0];

      // if (!input)
        // {
        // Try converting image data.
        // vtkImageData *inImage = vtkImageData::GetData(inputVector[0]);
        // if (inImage)
          // {
          // vtkNew<vtkImageDataToPointSet> image2points;
          // image2points->SetInputData(inImage);
          // image2points->Update();
          // input = image2points->GetOutput();
          // }
        // }

      // if (!input)
        // {
        // Try converting rectilinear grid.
        // vtkRectilinearGrid *inRect = vtkRectilinearGrid::GetData(inputVector[0]);
        // if (inRect)
          // {
          // vtkNew<vtkRectilinearGridToPointSet> rect2points;
          // rect2points->SetInputData(inRect);
          // rect2points->Update();
          // input = rect2points->GetOutput();
          // }
        // }

      if (!input) {
        vtkErrorMacro('Invalid or missing input');
        return 1;
      }

      // First, copy the input to the output as a starting point
      // output->CopyStructure( input );

      const inPts = input.getPoints().getData();
      const pd = input.getPointData();
      const inNormals = pd.getNormals();
      const inScalars = publicAPI.getInputArrayToProcess(0);

      if (!inPts || !inScalars) {
        vtkDebugMacro('No data to warp', !!inPts, !!inScalars);
        outData[0] = inData[0];
        return 1;
      }

      const numPts = inPts.getNumberOfValues();

      let pointNormal = null;

      const normal = [0, 0, 1];
      if (inNormals && !model.useNormal) {
        pointNormal = (id, array) => [
          array.getData()[(id * 3)],
          array.getData()[(id * 3) + 1],
          array.getData()[(id * 3) + 2],
        ];
        // vtkDebugMacro('Using data normals');
      } else if (publicAPI.getXyPlane()) {
        pointNormal = (id, array) => normal;
        // vtkDebugMacro('Using x-y plane normal');
      } else {
        pointNormal = (id, array) => model.normal;
        // vtkDebugMacro('Using Normal instance variable');
      }

      const newPtsData = new Float32Array(numPts * 3);
      const inPoints = inPts.getData();
      let ptOffset = 0;
      let n = [0, 0, 1];
      let s = 1;

      // Loop over all points, adjusting locations
      const scalarDataArray = inScalars.getData();
      const nc = inScalars.getNumberOfComponents();
      for (let ptId = 0; ptId < numPts; ++ptId) {
        ptOffset = ptId * 3;
        n = pointNormal(ptId, inNormals);

        if (model.xyPlane) {
          s = inPoints[ptOffset + 2];
        } else {
          // Use component 0 of array if there are multiple components
          s = scalarDataArray[ptId * nc];
        }

        newPtsData[ptOffset] = inPoints[ptOffset] + (model.scaleFactor * s * n[0]);
        newPtsData[ptOffset + 1] = inPoints[ptOffset + 1] + (model.scaleFactor * s * n[1]);
        newPtsData[ptOffset + 2] = inPoints[ptOffset + 2] + (model.scaleFactor * s * n[2]);
      }

{'fraction_non_alphanumeric': 0.25053940855438506, 'fraction_numerical': 0.011803528366543978, 'mean_word_length': 1.440384019820378, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3422696', 'n_tokens_mistral': 2294, 'n_tokens_neox': 2206, 'n_words': 491}