#pragma once
#ifndef _LAMPSCATTERS1B_H_
#define _LAMPSCATTERS1B_H_
#include <stdlib.h>
#include <QString>
#include <netcdf.h>
#include <complex>
#include <memory>
#include <Qset>
#include <QMap>

#include <flann/flann.hpp>
#include <memory>
#include <vector>

inline void LAMPScatterS1BdelArrPtr(void* p)
{
	delete[] p;
	p = nullptr;
}


class LAMPScatterS1BRCSDataNode {
public:
	LAMPScatterS1BRCSDataNode(QString PolarName, double AzAngle, double IncAngle,std::shared_ptr<double> freqs, std::shared_ptr<double> RCSPoints,long freqnumber);
	~LAMPScatterS1BRCSDataNode();

public:
	long getFreqPointNumber();
	std::shared_ptr<double> getFreqPoints();
	std::shared_ptr<double> getRCSPoints();
	QString getPolarName();
	double getAzAngle();
	double getIncAngle();

private:
	double AzAngle;
	double IncAngle;
	long FreqPointNumber;
	std::shared_ptr<double> FreqPoints;
	std::shared_ptr<double> RCSPoints;
	QString PolarName;
};


class LAMPScatterS1BPolarKdTree {// 这里使用 kdTree作为 检索索引，不需要考虑调整的
public:
	LAMPScatterS1BPolarKdTree(std::vector<std::shared_ptr< LAMPScatterS1BRCSDataNode >> inDatalist);
	~LAMPScatterS1BPolarKdTree();

public:
	QVector<std::shared_ptr< LAMPScatterS1BRCSDataNode >> search(double sAzAngle, double sIncAngle,long sPointNumber);

private: //kdtree
	std::vector<std::vector<double>> dataset;
	std::shared_ptr < flann::Matrix<double>> KdtreeFlannDatasetPtr;
	std::shared_ptr < flann::Index<flann::L2<double>>> kdtreeIndexPtr;


private:
	std::vector<std::shared_ptr< LAMPScatterS1BRCSDataNode >> datalist; //所有节点
};


class LAMPScatterS1BDataset
{
public:
	int OpenFile(QString s1bfilepath);
 
public:
	std::complex<double> getRCSData(QString polarName, double AzAngle, double IncAngle, double FreqId);

private:
	long FreqPointNumber;
	long polNumber;
	long AzNumber;
	long IncNumber;
	QMap<QString,std::shared_ptr<LAMPScatterS1BPolarKdTree>> polarRCSTree;

private:
	QMap<QString,QString> ReadPolAttribution(int ncid, int polvarid);
};





#endif