#0012:新增etalon 文件格式的解析与可视化,和控制

This commit is contained in:
zhengxuan.zhang
2024-09-10 17:35:19 +08:00
parent 74272c8406
commit e27c65d01a
187 changed files with 329682 additions and 22 deletions
+105
View File
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Scatter
{
static class Algerbra
{
public class Matrix<T>
{
int rows;
int columns;
private T[,] matrix;
public Matrix(int n, int m)
{
matrix = new T[n, m];
rows = n;
columns = m;
}
public void SetValByIdx(int m, int n, T x)
{
matrix[n, m] = x;
}
public T GetValByIndex(int n, int m)
{
return matrix[n, m];
}
public void SetMatrix(T[] arr)
{
for (int r = 0; r < rows; r++)
for (int c = 0; c < columns; c++)
matrix[r, c] = arr[r * columns + c];
}
public static Matrix<T> operator |(Matrix<T> m1, Matrix<T> m2)
{
Matrix<T> m = new Matrix<T>(m1.rows, m1.columns + m2.columns);
for (int r = 0; r < m1.rows; r++)
{
for (int c = 0; c < m1.columns; c++)
m.matrix[r, c] = m1.matrix[r, c];
for (int c = 0; c < m2.columns; c++)
m.matrix[r, c + m1.columns] = m2.matrix[r, c];
}
return m;
}
public static Matrix<T> operator *(Matrix<T> m1, Matrix<T> m2)
{
Matrix<T> m = new Matrix<T>(m1.rows, m2.columns);
for (int r = 0; r < m.rows; r++)
for (int c = 0; c < m.columns; c++)
{
T tmp = (dynamic)0;
for (int i = 0; i < m2.rows; i++)
tmp += (dynamic)m1.matrix[r, i] * (dynamic)m2.matrix[i, c];
m.matrix[r, c] = tmp;
}
return m;
}
public static Matrix<T> operator ~(Matrix<T> m)
{
Matrix<T> tmp = new Matrix<T>(m.columns, m.rows);
for (int r = 0; r < m.rows; r++)
for (int c = 0; c < m.columns; c++)
tmp.matrix[c, r] = m.matrix[r, c];
return tmp;
}
public static Matrix<T> operator -(Matrix<T> m)
{
Matrix<T> tmp = new Matrix<T>(m.columns, m.rows);
for (int r = 0; r < m.rows; r++)
for (int c = 0; c < m.columns; c++)
tmp.matrix[r, c] = -(dynamic)m.matrix[r, c];
return tmp;
}
public override string ToString()
{
String output = "";
for (int r = 0; r < rows; r++)
{
output += "[\t";
for (int c = 0; c < columns; c++)
{
output += matrix[r, c].ToString();
if (c < columns - 1) output += ",\t";
}
output += "]\n";
}
return output;
}
}
}
}
+68
View File
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Scatter
{
public static class MouseWheelHandler
{
public static void Add(Control ctrl, Action<MouseEventArgs> onMouseWheel)
{
if (ctrl == null || onMouseWheel == null)
throw new ArgumentNullException();
var filter = new MouseWheelMessageFilter(ctrl, onMouseWheel);
Application.AddMessageFilter(filter);
ctrl.Disposed += (s, e) => Application.RemoveMessageFilter(filter);
}
class MouseWheelMessageFilter
: IMessageFilter
{
private readonly Control _ctrl;
private readonly Action<MouseEventArgs> _onMouseWheel;
public MouseWheelMessageFilter(Control ctrl, Action<MouseEventArgs> onMouseWheel)
{
_ctrl = ctrl;
_onMouseWheel = onMouseWheel;
}
public bool PreFilterMessage(ref Message m)
{
var parent = _ctrl.Parent;
if (parent != null && m.Msg == 0x20a) // WM_MOUSEWHEEL, find the control at screen position m.LParam
{
var pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
var clientPos = _ctrl.PointToClient(pos);
if (_ctrl.ClientRectangle.Contains(clientPos)
&& ReferenceEquals(_ctrl, parent.GetChildAtPoint(parent.PointToClient(pos))))
{
var wParam = m.WParam.ToInt32();
Func<int, MouseButtons, MouseButtons> getButton =
(flag, button) => ((wParam & flag) == flag) ? button : MouseButtons.None;
var buttons = getButton(wParam & 0x0001, MouseButtons.Left)
| getButton(wParam & 0x0010, MouseButtons.Middle)
| getButton(wParam & 0x0002, MouseButtons.Right)
| getButton(wParam & 0x0020, MouseButtons.XButton1)
| getButton(wParam & 0x0040, MouseButtons.XButton2)
; // Not matching for these /*MK_SHIFT=0x0004;MK_CONTROL=0x0008*/
var delta = wParam >> 16;
var e = new MouseEventArgs(buttons, 0, clientPos.X, clientPos.Y, delta);
_onMouseWheel(e);
return true;
}
}
return false;
}
}
}
}
+67
View File
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Diagnostics;
namespace Scatter
{
static class Projection
{
static public PointF Project(double[] x, double s_x, double s_y, double f, double[] d_w, double azimuth, double elevation)
{
Algerbra.Matrix<double> Mext = GetMext(azimuth, elevation, d_w);
Algerbra.Matrix<double> Mint = GetMint(s_x, s_y, f);
Algerbra.Matrix<double> X_h = new Algerbra.Matrix<double>(4, 1);
X_h.SetMatrix(new double[] { x[0], x[1], x[2], 1.0});
//Debug.Print((Mint * Mext).ToString());
Algerbra.Matrix<double> P = Mint * Mext * X_h;
return new PointF((float)(P.GetValByIndex(0, 0) / P.GetValByIndex(2, 0)), (float)(P.GetValByIndex(1, 0) / P.GetValByIndex(2, 0)));
}
static public PointF[] ProjectVector(List<double[]> x, double s_x, double s_y, double f, double[] d_w, double azimuth, double elevation)
{
Algerbra.Matrix<double> Mext = GetMext(azimuth, elevation, d_w);
Algerbra.Matrix<double> Mint = GetMint(s_x, s_y, f);
Algerbra.Matrix<double> X_h = new Algerbra.Matrix<double>(4, 1);
PointF[] Pvec = new PointF[x.Count];
for (int i = 0; i < x.Count; i++)
{
X_h.SetMatrix(new double[] { x[i][0], x[i][1], x[i][2], 1.0 });
Algerbra.Matrix<double> P = Mint * Mext * X_h;
Pvec[i] = new PointF((float)(P.GetValByIndex(0, 0) / P.GetValByIndex(2, 0)), (float)(P.GetValByIndex(1, 0) / P.GetValByIndex(2, 0)));
}
return Pvec;
}
static Algerbra.Matrix<double> GetMint(double s_x, double s_y, double f)
{
Algerbra.Matrix<double> Mint = new Algerbra.Matrix<double>(3, 3);
double o_x = s_x / 2;
double o_y = s_y / 2;
double a = 1;
Mint.SetMatrix(new double[] { f, 0, o_x, 0, f * a, o_y, 0, 0, 1 });
return Mint;
}
static Algerbra.Matrix<double> GetMext(double azimuth, double elevation, double[] d_w)
{
Algerbra.Matrix<double> R = RotationMatrix(azimuth, elevation);
Algerbra.Matrix<double> dw = new Algerbra.Matrix<double>(3, 1);
dw.SetMatrix(d_w);
Algerbra.Matrix<double> Mext = R | (-R * dw);
return Mext;
}
static Algerbra.Matrix<double> RotationMatrix(double azimuth, double elevation)
{
Algerbra.Matrix<double> R = new Algerbra.Matrix<double>(3, 3);
R.SetMatrix(new double[] { Math.Cos(azimuth), 0, -Math.Sin(azimuth),
Math.Sin(azimuth)*Math.Sin(elevation), Math.Cos(elevation), Math.Cos(azimuth)*Math.Sin(elevation),
Math.Cos(elevation)*Math.Sin(azimuth), -Math.Sin(elevation), Math.Cos(azimuth)*Math.Cos(elevation) });
return R;
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Scatter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Scatter")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("118f69bb-9ed3-4610-8aca-b4c41401ef5e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+69
View File
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D02C6625-17E3-41BC-BFD6-D217C83DD3CE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Scatter</RootNamespace>
<AssemblyName>Scatter</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Algebra.cs" />
<Compile Include="MouseWheelHandler.cs" />
<Compile Include="Projection.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScatterPlot.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="ScatterPlot.Designer.cs">
<DependentUpon>ScatterPlot.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ScatterPlot.resx">
<DependentUpon>ScatterPlot.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+48
View File
@@ -0,0 +1,48 @@
namespace Scatter
{
partial class ScatterPlot
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// ScatterPlot
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "ScatterPlot";
this.SizeChanged += new System.EventHandler(this.ScatterPlot_SizeChanged);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ScatterPlot_MouseDown);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ScatterPlot_MouseMove);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ScatterPlot_MouseUp);
this.ResumeLayout(false);
}
#endregion
}
}
+179
View File
@@ -0,0 +1,179 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace Scatter
{
public partial class ScatterPlot : UserControl
{
List<List<double[]>> Points = new List<List<double[]>>();
List<PointF[]> ProjPoints = new List<PointF[]>();
private double f = 1000;
private double d = 5;
private double[] d_w = new double[3];
private double last_azimuth, azimuth = 0, last_elevation, elevation = 0;
private bool leftMousePressed = false;
private PointF ptMouseClick;
public double Distance
{
get { return d; }
set { d = (value >= 0.1) ? d = value : d; UpdateProjection(); }
}
public double F
{
get { return f; }
set { f = value; UpdateProjection(); }
}
public double[] CameraPos
{
get { return d_w;}
set { d_w = value; UpdateProjection(); }
}
public double Azimuth
{
get { return azimuth; }
set { azimuth = value; UpdateProjection(); }
}
public double Elevation
{
get { return elevation; }
set { elevation = value; UpdateProjection(); }
}
public ScatterPlot()
{
InitializeComponent();
MouseWheelHandler.Add(this, MyOnMouseWheel);
}
protected override CreateParams CreateParams
{
get
{
var cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
Color[] colorIdx = new Color[] { Color.Blue, Color.Red, Color.Green, Color.Orange, Color.Fuchsia, Color.Black };
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = this.CreateGraphics();
g.FillRectangle(Brushes.White, new Rectangle(0, 0, this.Width, this.Height));
if (ProjPoints != null)
{
for (int i = 0; i < ProjPoints.Count; i++)
{
foreach (PointF p in ProjPoints[i])
{
g.FillEllipse(new SolidBrush(colorIdx[i % colorIdx.Length]), new RectangleF(p.X, p.Y, 4, 4));
}
}
}
}
public void AddPoint(double x, double y, double z, int series)
{
if (Points.Count - 1 < series)
{
Points.Add(new List<double[]>());
}
Points[series].Add(new double[] { x, y, z });
foreach (List<double[]> ser in Points)
{
if (ProjPoints.Count - 1 < series)
ProjPoints.Add(Projection.ProjectVector(ser, this.Width, this.Height, f, d_w, azimuth, elevation));
else
ProjPoints[series] = Projection.ProjectVector(ser, this.Width, this.Height, f, d_w, azimuth, elevation);
}
this.Invalidate();
}
public void AddPoints(List<double[]> points)
{
List<double[]> _tmp = new List<double[]>(points);
Points.Add(_tmp);
ProjPoints.Add(Projection.ProjectVector(Points[Points.Count-1], this.Width, this.Height, f, d_w, azimuth, elevation));
UpdateProjection();
}
public void Clear()
{
ProjPoints.Clear();
Points.Clear();
Azimuth = 0;
Elevation = 0;
}
private void ScatterPlot_MouseMove(object sender, MouseEventArgs e)
{
if (leftMousePressed)
{
azimuth = last_azimuth - (ptMouseClick.X - e.X) / 100;
elevation = last_elevation + (ptMouseClick.Y - e.Y) / 100;
UpdateProjection();
}
}
private void ScatterPlot_SizeChanged(object sender, EventArgs e)
{
if (ProjPoints != null)
UpdateProjection();
}
private void ScatterPlot_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
leftMousePressed = true;
ptMouseClick = new PointF(e.X, e.Y);
last_azimuth = azimuth;
last_elevation = elevation;
}
}
private void ScatterPlot_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
leftMousePressed = false;
}
private void MyOnMouseWheel(MouseEventArgs e)
{
Distance += -e.Delta / 500D;
}
private void UpdateProjection()
{
if (ProjPoints == null)
return;
double x = d * Math.Cos(elevation) * Math.Cos(azimuth);
double y = d * Math.Cos(elevation) * Math.Sin(azimuth);
double z = d * Math.Sin(elevation);
d_w = new double[3] { -y, z, -x };
for (int i = 0; i < ProjPoints.Count; i++)
ProjPoints[i] = Projection.ProjectVector(Points[i], this.Width, this.Height, f, d_w, azimuth, elevation);
this.Invalidate();
}
}
}
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
@@ -0,0 +1 @@
010729bf4e2861a30ba2b2199c1d8d99dbfeee6c06a6af2b14fb4f09a1506f16
Binary file not shown.
Binary file not shown.