You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using NaturalNeighbor;
using NeighborInterpolator;
namespace TestForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
internal static IEnumerable<(int, int, Vector2)> CreateGridEx(
float offsetX, float offsetY,
float width, float height,
int rows, int cols)
{
float scaleX = width / (cols - 1);
float scaleY = height / (rows - 1);
for (int i = 0; i < rows; ++i)
{
var y = offsetY + i * scaleX;
for (int j = 0; j < cols; ++j)
{
var x = offsetX + j * scaleY;
yield return (i, j, new Vector2(x, y));
}
}
}
private void button1_Click(object sender, EventArgs e)
{
//string strFile = "C:\\GeoIntelligent\\Test\\厚度图数据\\39SO(300).csv";
//string strResult = "C:\\GeoIntelligent\\Test\\厚度图数据\\39SO(300)-Result.dfd";
string strFile = "C:\\GeoIntelligent\\Test\\厚度图数据\\40SO(300).csv";
string strResult = "C:\\GeoIntelligent\\Test\\厚度图数据\\40SO(300)-Result.dfd";
int nCols = 100;
int nRows = 100;
//Vector3[] points = this.ReadData(strFile).ToArray();
//Vector3 rangeMin = new Vector3();
//Vector3 rangeMax = new Vector3();
//this.CalculateRange(points.ToArray(), ref rangeMin, ref rangeMax);
//int nCount = points.Length;
//for(int i=0;i<nCount;i++)
//{
// points[i].X -= rangeMin.X;
// points[i].Y -= rangeMin.Y;
//}
//Interpolator2d interpolator = Interpolator2d.Create(points.ToArray(), 0.5f);
////Vector2 minLoc = interpolator.MinValue.Value;
////Vector2 maxLoc = interpolator.MaxValue.Value;
//double dWidth = rangeMax.X - rangeMin.X;
//double dHeight = rangeMax.Y - rangeMin.Y;
//double scaleX = dWidth / (nCols - 1);
//double scaleY = dHeight / (nRows - 1);
//float dScale = (float)Math.Min(scaleX, scaleY);
//int nCalCols = (int) Math.Ceiling(dWidth / dScale);
//int nCalRows = (int)Math.Ceiling(dHeight / dScale);
//Vector2[] result = new Vector2[nCalRows * nCalCols];
//for (int i = 0; i < nCalCols; ++i)
//{
// var x = i * dScale;
// for (int j = 0; j < nCalRows; ++j)
// {
// var y = j * dScale;
// result[i * nCalRows + j] = new Vector2(x, y);
// }
//}
//double[] resultZ = new double[nCalRows * nCalCols];
//interpolator.LookupRange(result, resultZ);//, new ParallelOptions() { }
//try
//{
// IntPtr pEvent = IntPtr.Zero;
// //if (ProgressChanged != null)
// //{
// // pEvent = Marshal.GetFunctionPointerForDelegate(ProgressChanged);
// //}
// Thread newThread = new Thread(new ThreadStart(() =>
// {
// //SetDllDirectory(System.Windows.Forms.Application.StartupPath);
// // 生成网格
// SetGridData(rangeMin.X, rangeMin.Y, resultZ, nCalCols, nCalRows, (double)dScale, (double)dScale
// , rangeMin.Z, rangeMax.Z, null, 0);
// // 保存网格,同时生成等值线
// SaveDrawFile(strResult, 1, 5);
// DestoryXy();
// }), 2621440);
// newThread.Start();
// newThread.Join();
//}
//catch (Exception ex)
//{
// // MessageBox.Show(ex.Message);
// Trace.WriteLine(ex.Message);
//}
//using (StreamWriter sw = new StreamWriter(strResult, false, Encoding.Default))
//{
// for (int i = 0; i < nCalRows; i++)
// {
// for (int j = 0; j < nCalCols; j++)
// {
// sw.WriteLine($"{result[i * nCalCols + j].X+ rangeMin.X},{result[i * nCalCols + j].Y+rangeMin.Y},{resultZ[i * nCalCols + j]}");
// }
// }
//}
string strBorderFile = string.Empty;
GridCreator creater = new GridCreator();
creater.Create(strFile, strResult, strBorderFile, nCols, nRows, 3, 5, 5);
MessageBox.Show("OK");
}
}
}