#pragma once

#ifndef BASECONSTVARIABLE_H
#define BASECONSTVARIABLE_H
//#define EIGEN_USE_MKL_ALL
//#define EIGEN_NO_DEBUG 



#ifdef BASECONSTVARIABLE_API
#define BASECONSTVARIABLEAPI __declspec(dllexport)
#else
#define BASECONSTVARIABLEAPI __declspec(dllimport)
#endif






#define EIGEN_USE_BLAS
#define EIGEN_USE_LAPACK
#define EIGEN_VECTORIZE_SSE2

//#define DEBUGSHOWDIALOG

#define __CUDANVCC___ // 定义CUDA函数

#define __PRFDEBUG__
//#define __PRFDEBUG_PRFINF__
//#define __ECHOTIMEDEBUG__

#define __TBPIMAGEDEBUG__

//#include <mkl.h>
#include <complex>
#include <math.h>
#include <complex>
#include <time.h>

/** 打印时间 ***************************************************************/
inline char* get_cur_time() {
	static char s[20];
	time_t t;
	struct tm* ltime;
	time(&t);
	ltime = localtime(&t);
	strftime(s, 20, "%Y-%m-%d %H:%M:%S", ltime);
	return s;
}

#define PRINT(fmt, ...) printf("%s " fmt, get_cur_time(), ##__VA_ARGS__)




#define MATPLOTDRAWIMAGE


#define r2d 180/3.141592653589793238462643383279
#define d2r 3.141592653589793238462643383279/180
#define LIGHTSPEED 299792458
#define PRECISIONTOLERANCE 1e-6
#define Radians2Degrees(Radians) Radians*PI_180
#define Degrees2Radians(Degrees) Degrees*T180_PI
#define EARTHWE 0.000072292115
#define PI 3.141592653589793238462643383279
 


#define earthRoute 0.000072292115
#define Memory1GB 1073741824
#define Memory1MB 1048576
#define Memory1KB 1024

const std::complex<double> imagI(0, 1);

 
const double epsilon = 0.000000000000001;
const double pi = 3.14159265358979323846;
 

const double a = 6378137.0;		//椭球长半轴
const double ae = 6378137.0;		//椭球长半轴
const double ee = 0.0818191910428;// 第一偏心率
const double f_inverse = 298.257223563;			//扁率倒数
const double b = a - a / f_inverse;
const double eSquare = (a * a - b * b) / (a * a);
const double e = sqrt(eSquare);
const double earth_Re = 6378136.49;
const double earth_Rp = (1 - 1 / f_inverse) * earth_Re;
const double earth_We = 0.000072292115;

/*********************************************** openMap参数 ********************************************************************/
static long Paral_num_thread = 14;


/*********************************************** 基础枚举 ********************************************************************/

enum POLARTYPEENUM { // 极化类型
	POLARHH,
	POLARHV,
	POLARVH,
	POLARVV,
	POLARUNKOWN
};


/*********************************************** 基础结构体区域 ********************************************************************/

/// <summary>
/// 地理坐标点
/// </summary>
struct Landpoint //  点   SAR影像的像素坐标；
{
	double lon; // 经度x lon pixel_col
	double lat; // 纬度y lat pixel_row
	double ati; // 高程z ati pixel_time
};

struct Point2 {
	double x = 0;
	double y = 0;
};


struct Point3 {
	double x = 0;
	double y = 0;
	double z = 0;
	void setX(double ix) { x = ix; }
	void setY(double iy) { y = iy; }
	void setZ(double iz) { z = iz; }
};

struct DemBox {
	double min_lon;
	double max_lon;
	double min_lat;
	double max_lat;
};

struct Vector3 { double x, y, z; };


/*********************************************** FEKO仿真参数 ********************************************************************/
struct SatellitePos {
	double time;
	double Px  ;
	double Py  ;
	double Pz  ;
	double Vx  ;
	double Vy  ;
	double Vz  ;
};


struct SatelliteAntPos {
	double time; // 0
	double Px;
	double Py;
	double Pz;
	double Vx;
	double Vy;
	double Vz; //7
	double AntDirectX;
	double AntDirectY;
	double AntDirectZ;
	double AVx;
	double AVy;
	double AVz;//13
	double ZeroAntDiectX;
	double ZeroAntDiectY;
	double ZeroAntDiectZ;
	double lon;
	double lat;
	double ati; // 19
};


struct PatternImageDesc {
	long  phinum;
	long  thetanum;
	double  startTheta;
	double  startPhi;
	double  dtheta;
	double  dphi;
};


struct CUDA_AntSate_PtrList {
	long PRF_len = 0;
	double* h_antpx = nullptr, * d_antpx = nullptr;
	double* h_antpy = nullptr, * d_antpy = nullptr;
	double* h_antpz = nullptr, * d_antpz = nullptr;
	double* h_antvx = nullptr, * d_antvx = nullptr;
	double* h_antvy = nullptr, * d_antvy = nullptr;
	double* h_antvz = nullptr, * d_antvz = nullptr;
	double* h_antdirectx = nullptr, * d_antdirectx = nullptr;
	double* h_antdirecty = nullptr, * d_antdirecty = nullptr;
	double* h_antdirectz = nullptr, * d_antdirectz = nullptr;
	double* h_antXaxisX = nullptr, * d_antXaxisX = nullptr;
	double* h_antXaxisY = nullptr, * d_antXaxisY = nullptr;
	double* h_antXaxisZ = nullptr, * d_antXaxisZ = nullptr;
	double* h_antYaxisX = nullptr, * d_antYaxisX = nullptr;
	double* h_antYaxisY = nullptr, * d_antYaxisY = nullptr;
	double* h_antYaxisZ = nullptr, * d_antYaxisZ = nullptr;
	double* h_antZaxisX = nullptr, * d_antZaxisX = nullptr;
	double* h_antZaxisY = nullptr, * d_antZaxisY = nullptr;
	double* h_antZaxisZ = nullptr, * d_antZaxisZ = nullptr;
};

/*********************************************** 卫星轨道坐标 ********************************************************************/


/// <summary>
/// 轨道节点,坐标系统为WGS84
/// </summary>
struct SatelliteOribtNode {
	double time;

	double Px;// 位置
	double Py;
	double Pz;

	double Vx;// 速度
	double Vy;
	double Vz;

	double AVx; // 加速度
	double AVy;
	double AVz;

	double AntXaxisX; // X天线指向，对应翻滚角等参数
	double AntXaxisY; //  
	double AntXaxisZ; //  

	double AntYaxisX; // Y天线指向，对应翻滚角等参数
	double AntYaxisY; //  
	double AntYaxisZ; //  

	double AntZaxisX; // Z天线指向，对应翻滚角等参数
	double AntZaxisY; //  
	double AntZaxisZ; //  


	double AntDirecX; // 天线指向，对应翻滚角等参数
	double AntDirecY;
	double AntDirecZ;

	double zeroDopplerDirectX; // 0 多普勒方向
	double zeroDopplerDirectY;
	double zeroDopplerDirectZ;

	double beamAngle; // 波位角
	double AzAngle;// 摆动角


};


struct SatelliteAntDirect {
	double Xst;		 // 地面-->卫星矢量
	double Yst;
	double Zst;
	double Vxs;		// 卫星速度
	double Vys;
	double Vzs;

	double Xant;	// 天线坐标系下的 矢量坐标
	double Yant;
	double Zant;

	double Norm;

	double ThetaAnt; // 天线坐标系下的 theta 坐标系
	double PhiAnt;
};



struct RadiationPatternGainPoint {
	double theta;
	double phi;
	double GainValue;
};




/*********************************************** 指针回收区域 ********************************************************************/

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

inline void delPointer(void* p)
{
	delete p;
	p = nullptr;
}
  
inline void PrintTime() {
	time_t current_time;
	time(&current_time);
	printf("Current timestamp in seconds: %ld\n", (long)current_time);
}

/** 计算分块 ******************************************************************/

inline long getBlockRows(long sizeMB, long cols,long sizeMeta,long maxRows) {
	long rownum= (round(Memory1MB * 1.0 / sizeMeta / cols * sizeMB) + cols - 1);
	rownum = rownum < 0 ? 1 : rownum;
	rownum =rownum < maxRows ? rownum : maxRows;
	return rownum;
}


inline long nextpow2(long n) {
	long en = ceil(log2(n));
	return pow(2,en);
}



#endif