import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray.js';
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData.js';
import vtkPoints from '@kitware/vtk.js/Common/Core/Points.js';
import vtkPointSet from '@kitware/vtk.js/Common/DataModel/PointSet.js';
import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray.js';
import { number } from 'echarts';

function parseLegacyASCII(content) {
  let dataModel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  let parser = null;
  let velindex = 0;
  const separatorRegExp = /\r?\n/;
  const separatorRes = separatorRegExp.exec(content);
  const separator = separatorRes !== null ? separatorRes[0] : null;
  dataModel.dataset=vtkPolyData.newInstance();
  dataModel.velocitys = [];
  content.split(separator).forEach((line, index) => {
    if (!parser) {
      let velocity = {};
      dataModel.velocitys.push(velocity);
      let tem = line.split(',');
      velocity.name = tem[0];
      velocity.num = Number(tem[1]);
      velocity.speed = Number(tem[2]);
      velocity.vector = [Number(tem[3]), Number(tem[4]), Number(tem[5])];
      velindex = Number(tem[1]);
      velocity.points=[];
      parser = true;
    } else {
      let velocity = dataModel.velocitys[dataModel.velocitys.length - 1];
      let tem = line.split(',');
      velocity.points.push({
        x: Number(tem[0]),
        y: Number(tem[1]),
        z: Number(tem[2])
      });
      velindex--;
      if (velindex == 0) {
        parser = null;
      }
    }

  });
  console.log(dataModel);
  return dataModel;
}
var velocityAsciiParser = {
  parseLegacyASCII
};

export { velocityAsciiParser as default };
