////////////////////////////////////////////////////////////////////////////// //文件 Mesh.h //主要功能: // //程序编写: 2005-12-07 ///////////////////////////////////////////////////////////////////////////// #pragma once #include "ImageInsert.h" #include "colorruler.h" #include "rect8ex.h" #include ".\name.h" #include ".\curveex.h" #include #include "MeshPackage.h" #include using namespace std; #define MESH_TEXT 0x00000001 //3DMesh格式,使用CDimension2D类 #define MESH_DFG 0x00000002 //DFG格式 #define MESH_FXY 0x00000004 //F(x,y)格式 #define MESH_FUN_2D 0x00000008 //使用CFunction2D类 #define MESH_DIFFERENTIAL_X 0x00000010 //X方向一阶偏导 #define MESH_DIFFERENTIAL_Y 0x00000020 //Y方向一阶偏导 #define MESH_DIFFERENTIAL_XY 0x00000040 //XY方向一阶偏导 #define MESH_DIFFERENTIAL_X2 0x00000100 //X方向二阶偏导 #define MESH_DIFFERENTIAL_Y2 0x00000200 //Y方向二阶偏导 #define MESH_DIFFERENTIAL_XY2 0x00000400 //XY方向二阶偏导 #define MESH_DRAW_RULER 0x00001000 //显示颜色标尺 #define MESH_UPDATE_RULER 0x00002000 //更新颜色标尺 //#define IMAGE_TRANSPARENT_ALPHA 0x00004000 //位图透明显示,可设置不同颜色的不同透明度,为了保持与CImageInsert中的相同 //#define IMAGE_TRANSPARENT_COLOR 0x00008000 //位图透明显示,可指定一个颜色完全透明 #define MESH_SERIALIZE_RULER 0x00010000 //保存标尺 class AFX_EXT_CLASS CMesh : public CMeshBase , public CRect8 { public: CMesh(void); virtual ~CMesh(void); int64_t GetId() const; void SetId(int64_t id); void Serialize(CArchive& ar, const short& ver) override; virtual int Read(CFile& fr, const short& ver); virtual void Write(CFile &fw, const short& ver); virtual void GetRange(CRect8& range); virtual void GetRange(CPoint3D& minPoint, CPoint3D& maxPoint); virtual BOOL IsInRange(CRect8& range); virtual void Empty(void); virtual void Rotate(double xs, double ys, double angle); virtual void ScaleProperty(double sx, double sy); virtual void Calibrate(int type, void* pValue); virtual void ScaleCoordinate(double sx, double sy, int mode); //mode=0:加,1:减,2:乘,3:除 virtual void WriteDML(CFile& fw, const short& ver, int nBaseTabNum); virtual int ReadDML(CFile &fr, const short &ver); virtual void WritePCG(CFile& fw, const short& ver, int nBaseTabNum); virtual int ReadPCG(CFile &fr, const short &ver); virtual void WritePCG2(CFile& fw, const short& ver, int nBaseTabNum); virtual int ReadPCG2(CFile &fr, const short &ver); void WriteElementDML(BYTE*& buffElement, int& buffLen); BOOL ReadElementDML(BYTE* bufData, const short& ver, int bufLen); int ReadElementDML(CFile &fr, const short &ver); void GetRange(CPoint3D& minPoint, CPoint3D& maxPoint, BOOL bValue4);//bValue4表示是否Z值按照第四列值计算,否则按照第三列计算 void SetMesh(CGrid* pDfg, int nMeshType, BOOL bGetZRange=FALSE, double dInvaliData=1e30, BOOL bInitColor=TRUE); int Read(CFile& fr, const short& ver, BOOL bNewFormat); int ReadGrid_SurferAscii(LPCTSTR lpszFileName); //读取Surfer的文本网格文件 void WriteGrid_SurferAscii(LPCTSTR lpszFileName); //写 int ReadGrid_SurferBinary6(LPCTSTR lpszFileName); //读取Surfer6的二进制网格文件 void WriteGrid_SurferBinary6(LPCTSTR lpszFileName); //写 int ReadGrid_SurferBinary7(LPCTSTR lpszFileName, void* pParentXy); //读取Surfer7的二进制网格文件 int ReadGrid_GeoFrameAscii(LPCTSTR lpszFileName); void WriteGrid_GeoFrameAscii(LPCTSTR lpszFileName); int ReadGrid_EPT(LPCTSTR lpszFileName); //读取EPT网格文件 int ReadGrid_Zmap(LPCTSTR lpszFileName); //读取Petrel、ZMAP grid文件 int ReadGrid_EarthVision(LPCTSTR lpszFileName); //读取EarthVision网格文件 int ReadGrid_DEMAscii(LPCTSTR lpszFileName); //Digital Elevation Models int ReadGrid_ArcInfoASCII(LPCTSTR lpszFileName); //读取ArcInfo ASCII Grid Format网格文件 int ReadGridData(CFile& fr, CDimension2D* pDfg, BOOL bReversal=FALSE); //读取ASCII文件中纯网格数据部分 //对DFG类型曲面做平滑 int Smooth(double smooth_coe = 1.0, long smooth_times = 1); //第一行:GDFGRID void WriteGdfGrid(LPCTSTR lpszFileName); void WriteGdfGrid(CFile& fw, int times); int ReadGdfGrid(CFile& fr); int ReadGdfGrid(CString strGridFile); int CreateImage(CImageInsert* pImage, int times=1); void ContourCreate(POSITION(AddContourCurve)(CCurve* pCurve, CString strLayer), double step, long nameStep, CString nameLineLayer, CString otherLineLayer, double czmin, double czmax); void ContourCreate(std::vector* curves, std::vector* layers, double step, long nameStep, CString nameLineLayer, CString otherLineLayer, double czmin, double czmax); void GetM( double &zmin, double &zmax, BOOL bRerange=FALSE, double minValidValue=-1e100, double maxValidValue=1e100 ); void SetM(double zmin, double zmax); void GetDelt(double& dx, double& dy); void GetOrg(double& x0, double& y0); virtual void CreateColor(void); virtual void GetBitmap(void); virtual void UpdateColorRuler(void); virtual void ExchangeXY(void); //交换XY坐标 virtual void ExchangeXY(void* pProjection); //转换到指定投影坐标,CProjection* pProjection CColorRuler *m_pRuler; CColorBase color; void InitColor(); int ReadColor(CFile &fr, const short &ver); void WriteColor(CFile &fw, const short &ver); int CreateColorFromRuler(void); //根据颜色标尺的个数设置颜色表 void Offset(double dx, double dy); void SetValue(CPtrList& curveList, double z0, BOOL bRangeOut); void SetZ(long i, long j, double z0); int DeleteValue(double valueStart, double endValue, double invalidValue); BOOL IsInRangeZ(double z0); long SetValueZ(double a, int nModeSel); void ScaleZ(double dScale); double Volume(CCurveEx& curve, double dClosedZ); //计算构造图的体积,根据圈闭闭合线与内部之间的差值计算体积 // 面积衡量 double TradeArea(CCurve& curve, double baseZ = 0); double GetClosedZ(CCurveEx& curve, double hightPointZ); //获得闭合Z值,hightPointZ一般为GetHightPoint获得的高点Z值 int GetHightPoint(CCurveEx* pCurve, CPoint3D& hightPoint); //获得曲线范围内的高点, 返回0表示获得不成功 void operator=(CMesh& mesh); void CloneOtherParamter(CMesh& mesh); //复制除网格外的参数 int GetNumber(long& numx, long& numy, long* pNumz=NULL); int AutoReadFile(CString strMeshPathName); //将根据扩展名自动识别 int AutoReadFile(CFile& fr, CString strExt); int ReadMeshFile(CString strMeshPathName); int GeologicalSection(CCurveEx& split, CCurveEx& section); //根据split曲线切地质剖面 void WriteMesh(LPCTSTR lpszMeshName, DWORD dwFileType); //保存文件 void WriteOnlyDataToXYZ(CFile& fw, int times, const short& ver); /** * 是否启用了光照 */ bool IsLightingEnabled() const; /** * 启用光照 */ void EnableLighting(); /** * 禁用光照 */ void DisableLighting(); /** * 获取光线水平照射角度 */ int GetLightAzimuth() const; /** * 设置光线水平照射角度 * \param azimuth 水平照射角度,范围 [0, 360] */ void SetLightAzimuth(float azimuth); /** * 获取光线垂直照射角度 */ float GetLightElevation() const; /** * 设置光线垂直照射角度 * \param elevation 水平照射角度,范围 [0, 360] */ void SetLightElevation(float elevation); /** * 获取环境光强度 */ float GetLightIntensity() const; /** * 设置环境光强度 */ void SetLightIntensity(float intensity); /** * 获取 z 轴缩放因子 */ float GetZScaleFactor() const; /** * 设置 z 轴缩放因子 */ void SetZScaleFactor(double factor); public: BOOL CutOut(CCurveEx* pCurve); //剪裁背景 BOOL CutIn(CCurveEx* pCurve); //剪裁背景 int CutSectionDfg(CCurveEx& split, CDimension2D& outDfg); //根据split曲线切剖面(结果为一二维曲面) int CutSlice(CDimension2D& outDfg, double zValue); //根据指定的Z值切等时(深)切片 CString GetName(void); void SetName(LPCTSTR lpszName); void EnableUpdateRuler(BOOL bDraw); void EnableDrawRuler(BOOL bDraw); BOOL IsSerializeRuler(void); BOOL IsDrawRuler(void); BOOL IsUpdateRuler(void); CRect8 GetRulerRange(void); CMeshPackage* GetPackage(); void InitMeshBaseType(); DWORD GetMeshType(void); void SetMeshType(DWORD nType); void SetMeshFunction(DWORD nFunType); DWORD GetMeshFunction(void); CDimension3D* FunToDfg(CFunction2D* pfun); BOOL EncryptGrid(CDimension3D* pInDfg, CDimension3D* pOutDfg, int times); static BOOL GetSaveAsFileName(CString &strePathName, LPCTSTR lpExt); CImageInsert* GetImage() { return this->m_pImage.get(); } public: long m_nTimes; //加密次数 long m_FunctionSelect; //没有使用,可以用于以后扩展保存用 CString m_name; int m_nFxyIndexZ; //对于三维数据体时,显示在平面上的Z方向索引,缺省为0 DWORD m_nFlags; //是否透明显示.... COLORREF m_colTransparent; //透明色, 透明度(透明0-255不透明) CString m_FileName; bool IsPropertyChanged; // 属性是否被修改 CxImage m_imgCapture; // 突变下矢量图 用于pdf gdbx public: CDimension3D* GetDfg(void); void SetTransparentColor(COLORREF col); //设置透明色 COLORREF GetTransparentColor(void); BOOL IsTransparent(void); //是否透明显示 void SetTransparentMode(DWORD nMode); //设置透明模式 DWORD GetTransparentMode(void); //获得透明模式 // 创建补丁 void MakePackages(vector* pFaults); void RecreatPackages(vector* pFaults, BOOL force); bool SetAlpha(BYTE level); void RemoveAlpha(void); void CreateDfgPackage(CCurveEx* pCurve, vector& packages , std::vector& ranges, vector& colors , vector& Zs); inline void CreatePackageCross2(CCrossList &list, CCurveEx * pCurveGrid , dfPoint &pt1, dfPoint &pt2, dfPoint &pt3, dfPoint &pt4 , std::vector & colors,vector& dZs , std::vector & packages, std::vector& ranges); inline void CreatePackageCross4(CCrossList &list, CCurveEx * pCurveGrid , dfPoint &pt1, dfPoint &pt2, dfPoint &pt3, dfPoint &pt4 , std::vector & colors, vector& Zs , std::vector & packages, vector& ranges); void SetEnablePackage(BOOL enable) { EnablePackage = enable; } BOOL GetEnablePackage() { return EnablePackage; } double CalculateAngle(dfPoint& pt1, dfPoint& pt2); double CalculateAngle(CCurveEx& curve); protected: std::unique_ptr m_pImage; CGrid* m_pMeshFun; //仅是为了显示曲面处理结果,CDimension3D* or CFunction2D* CMeshPackage* m_pMeshPackage; // 网格补丁 BOOL EnablePackage = TRUE; protected: CFunction2D* GetFun(void); void ClearMeshFun(void); virtual void ClearMesh(void); // void SerializeDfg(CArchive& ar); // void SerializeFxy(CArchive& ar); void WriteDfg(CFile &fw, const short& ver); void WriteFxy(CFile &fw, const short& ver); void WriteFun(CFile &fw, const short& ver); BOOL BeforeWrite(LPCTSTR lpszExtStr); int Read3DMesh(CString strPathName); int Read3DMesh(CFile& fr); void Write3DMesh(CFile& fw, int times, const short& ver); //读取内存串中的曲面文件 int ReadBuffer(BYTE* pDataBuffer, DWORD nDataLen, CString& strType); //将曲面文件写入到一个内存串中 int GetFileBuffer(BYTE** ppBuffer, DWORD& nBufSize, CString& strType); int ReadDfg(CString strDfgPathName); int ReadFxy(CString strFxyPathName); void DfgToBitmap(CImageBase& image,CColorBase& color, int times, int selPlane); void DfgToBitmap(CImageBase& image,CColorBase& color,int times, long bnumx, long bnumy, long enumx, long enumy); void FunToBitmap(CImageBase& image,CColorBase& color,int times, long bnumx, long bnumy, long enumx, long enumy); void MeshFunction(CDimension3D* pSourceDim, CDimension3D* pDestDim, long nFunSel); void MeshFunction(CFunction2D* pSourceDim, CFunction2D* pDestDim, long nFunSel); double GetZ(CDimension3D* pDim, long i, long j, long nFunSel); double GetZ(CFunction2D* pDim, long i, long j, long nFunSel); inline int GetZ(vector pts, CCurveEx& area,double& zValue); inline COLORREF GetZColor(double& z); CString GetDfgFileName(CString strSourcePathName, CString ext); void SetValueDfg(CPtrList& curveList, double z0, BOOL bRangeOut); /** @brief 将曲线链表中所有曲线内部或外部(由bRangeOut控制)网格结点的值设置为z0 */ void SetValueFun(CPtrList& curveList, double z0, BOOL bRangeOut); BOOL CutOutDfg(CCurveEx* pCurve); //剪裁背景 /** @brief 剪裁曲线外部背景,先裁剪矩形网格,再将曲线外结点赋空*/ BOOL CutOutFun(CCurveEx* pCurve); /** @brief 剪裁曲线内部背景 wcw*/ BOOL CutInFun(CCurveEx* pCurve); int GeologicalSectionDfg(CCurveEx& split, CCurveEx& section); //根据split曲线切地质剖面 int GeologicalSectionFun(CCurveEx& split, CCurveEx& section); //根据split曲线切地质剖面 public: // 判断是否包含突变颜色,决定是否启用矢量绘制 BOOL NeedVectorDraw(); // 矢量化绘图入口 void DrawVectorContours(CDC* pDC, void* pXyDc); /******************************************************沉积相*************************************************/ // 设置网格为沉积相类型 void SetFaciesType(bool state); // 获取网格类型 bool GetFaciesType(); // 沉积相处理 绘制平滑填充层 void DrawSmoothFill(CDC* pDC, void* pXyDc); /*******************************************************************************************************/ private: // 颜色线性插值 COLORREF InterpolateColor(COLORREF c1, COLORREF c2, double ratio); // 辅助计算:线性插值 inline double GetInterpT(double v1, double v2, double threshold); // contourf填充 void DrawIsoRegion(CDC* pDC, void* pXyDc, CDimension3D* pDfg, int nIndexZ, double threshold, COLORREF color, double nextThreshold, int step); /******************************************************沉积相*************************************************/ //沉积相类型 bool m_faciesType = false; /*******************************************************************************************************/ private: /** @brief 将曲线集外部网格点设置为z0*/ void SetValueFunOutside(CFunction2D* pf,CPtrList& curveList, double z0); /** @brief 判断点是否在所有曲线的外部*/ BOOL IsPtOutside(double x0, double y0, CPtrList& curveList); /** @brief 将曲线集内部的网格点值设置为z0*/ void SetValueFunInside(CFunction2D* pf,CPtrList& curveList, double z0); /** @brief 将曲线内部包围的网格点值设置为z0*/ void SetValueCurveInside(CFunction2D* pf,CCurveEx* pCurve, double z0); double zero = 1e-30; bool isEdited = true; // 启用光照效果 bool m_isLightingEnabled = false; // 光线水平照射角度 float m_lightAzimuth = 127.0f; // 光线垂直照射角度 float m_lightElevation = 50.0f; // 环境光强度 float m_lightIntensity = 0.1f; // 计算光照时的 z 轴缩放因子 float m_zScaleFactor = 1.0f; int64_t m_id = -1; public: virtual int ReadPCG(void *pxp, const short &ver); virtual int ReadPCG2(void *pxp, const short &ver); };