using GeoSigmaDrawLib; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace QuikGridCS { public class Interface { /// /// 快速网格化算法生成网格. /// /// 输入的散点文件. /// 输出结果文件. /// The x count. /// The y count. /// The contour space. /// The contour lable. /// A bool. public static bool QuikGridCreate(string inputFile,string outputFile, int xCount, int yCount, double contourSpace, int contourLable, double smoothFactor) { if (Interface.QuikGridFromFile(inputFile, xCount, xCount) == true) { Interface.QuikGridGenerateGrid(); double xMin = 0; double xMax = 0; double yMin = 0; double yMax = 0; int countX = 0; int countY = 0; double zMin = 0; double zMax = 0; int nReturn = Interface.QuikGridGetView(ref xMin, ref xMax, ref yMin, ref yMax, ref countX, ref countY, ref zMin, ref zMax); if (nReturn == 0) { return false; } double dStepX = (xMax - xMin) / (countX - 1); double dStepY = (yMax - yMin) / (countY - 1); //string strFileOut = this.txtOutput.Text; //if (!string.IsNullOrEmpty(strFileOut)) //{ // Interface.QuikGridSaveFileGrd(strFileOut); //} string strFileKev = outputFile; if (!string.IsNullOrEmpty(strFileKev)) { IntPtr ptrValues = Interface.QuikGridGridValue(); DrawerData drawer = new DrawerData(); long pos = drawer.CreateMesh("背景", ptrValues, xMin, yMin, countX, countY, dStepX, dStepY, zMin, zMax); if (smoothFactor > 0.001) { drawer.MeshSmooth(pos, smoothFactor); } if (contourSpace > 0 && contourLable > 0) { drawer.CreateContour(pos, contourSpace, contourLable); } drawer.SaveAs(strFileKev); drawer.Dispose(); // 释放数据指针 GeoSigmaLib.PointerArrayDelete(ptrValues); } return true; } return false; } #if DEBUG const string SIGMALIB = "QUIKGRIDLIB.dll"; #else const string SIGMALIB = "QuikGridLib.dll"; #endif [DllImport(SIGMALIB, EntryPoint = "QuikGridLoadFileXyz", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int QuikGridLoadFileXyz(string fileName); [DllImport(SIGMALIB, EntryPoint = "QuikGridFromFile", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern bool QuikGridFromFile(string fileName, int xCount, int yCount); [DllImport(SIGMALIB, EntryPoint = "QuikGridGetView", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int QuikGridGetView(ref double xMin, ref double xMax, ref double yMin, ref double yMax , ref int countX, ref int countY, ref double zMin, ref double zMax); [DllImport(SIGMALIB, EntryPoint = "QuikGridGenerateGrid", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern bool QuikGridGenerateGrid(); [DllImport(SIGMALIB, EntryPoint = "QuikGridSaveFileGrd", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int QuikGridSaveFileGrd(string fileName); [DllImport(SIGMALIB, EntryPoint = "QuikGridGridValue", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr QuikGridGridValue(); [DllImport(SIGMALIB, EntryPoint = "QuikGridRecreate", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern bool QuikGridRecreate(int xCount, int yCount); } }