#ifndef GENERATEFILETHREAD_H
#define GENERATEFILETHREAD_H

#include <QThread>
#include <QMap>

#include <array>

#include "global.h"

class vtkUnstructuredGrid;
class vtkPoints;
class vtkDoubleArray;
class vtkUnsignedCharArray;
class vtkCellArray;

class GenerateFileThread : public QThread
{
    Q_OBJECT
public:
    GenerateFileThread(QObject* parent = nullptr);
    ~GenerateFileThread();

    void setConfigParam(ConfigParam p);

    int getCellNum();

Q_SIGNALS:
    void progressTip(int val, int sum, const QString& tip);

protected:
    void run();

private:
    void initParam();

    void generatePoint(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);

	void generateVertexCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generateVertexCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

	void generatePolyVertexCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generatePolyVertexCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

	void generateLineCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generateLineCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

	void generatePolyLineCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generatePolyLineCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

    void generateTriangleCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
    void generateTriangleCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

    void generateQuadCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
    void generateQuadCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

    void generateTetraCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
    void generateTetraCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

	void generateHexahedronCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generateHexahedronCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

	void generateWedgeCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generateWedgeCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

	void generatePyramidCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generatePyramidCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

	void generatePentagonalPrismCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generatePentagonalPrismCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

	void generateHexagonalPrismCoor(vtkPoints* points, vtkDoubleArray* pointArray, double xspan, double yspan, double zspan);
	void generateHexagonalPrismCell(vtkDoubleArray* cellValueArray, vtkCellArray* cellArray, vtkUnsignedCharArray* cellTypes);

private:
    ConfigParam mConfigParam;

    int mCellTotalNum;

    int mTempX;
    int mTempY;
    int mTempZ;

    QMap<int, std::array<int, 3>> mNumOfPerCell; // int 单元类型序号，std::array<int, 3> 分别表示单元数的开始，单元数的结束，每中单元对应点的数量
};

#endif // GENERATEFILETHREAD_H
