using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Tao.OpenGl;
using Tao.Platform.Windows;
using OpenCvSharp;
using System.Xml;
using Size = System.Drawing.Size;
using PaintDotNet.Base.CommTool;
namespace PaintDotNet.Instrument
{
public partial class SRWindow : PdnBaseForm
{
private GroupBox groupBox1;
private GroupBox groupBox2;
private Button button9;
private Button button8;
private Button button2;
private Button button1;
private Button button6;
private Button button5;
private Button button4;
// --- Fields ---
private static IntPtr hDC; // Private GDI Device Context
private static IntPtr hRC; // Permanent Rendering Context
private static SRWindow form; // Our Current Windows Form
//private static bool[] keys = new bool[256]; // Array Used For The Keyboard Routine
private static bool active = true; // Window Active Flag, Set To True By Default
private static bool done = false; // Bool Variable To Exit Main Loop
private AppWorkspace appWorkspace;
///
/// 三维数据
///
private Base.SettingModel.ThreeDataDemoModel threeDataDemo;
//for XML
int m_iWidth;
int m_iHeight;
int m_iDLevel;
double[] m_adDZ;
double[,] m_adDC;
double[,] m_adZV;
double[,] m_adOverTurnZV;
double m_dMaxZV;
double m_dMinZV;
float[, ,] m_afNewClr;
//bmp
float[, ,] m_afOrgClr;
//new platform
private System.Windows.Forms.PictureBox pictureBox1;
int m_iMusDown = 0;
//zzz
public static/* const*/ int LINE_PNTS = 100;
//Glfw.GLFWkeyfun m_funKeyCallBak;
//Glfw.GLFWmousebuttonfun m_funMsBtnCallBak;
//Glfw.GLFWmouseposfun m_funMsPosCallBak;
int m_iMusMod = 0;
int m_iLastmouseX, m_iLastmouseY;
int m_iLastMusDown = 0;
float[] m_fR_xyz = new float[3] { 0.0F, 0.0F, 0.0F };
float[] m_fT_xyz = new float[3] { 0.0F, 0.0F, 0.0F };
bool m_bOverTurn = false;
bool m_bRulerColor = true;
float[] m_afPonitA = new float[2] { 1.0F, 1.0F };
float[] m_afPonitB = new float[2] { 1.0F, 1.0F };
float[] m_afLineStep = new float[2] { 0.0F, 0.0F };
float[,] m_afLineXY = new float[/*LINE_PNTS - 2*/98, 2];
double[] m_adLineZV = new double[/*LINE_PNTS*/100];
double[] m_adLineOverTurnZV = new double[/*LINE_PNTS*/100];
//SRLinesForm m_fmLine;
float[, ,] m_afThisClr;
double[,] m_adThisZV;
private GroupBox groupBox3;
private TrackBar trackBar1;
private Panel panel2;
private Panel panel1;
private Label label3;
private Label label2;
private Label label1;
private GroupBox groupBox4;
private GroupBox groupBox5;
private Button button3;
private Button button7;
private PictureBox pictureBox2;
private Label label5;
private Label label4;
private Panel panel7;
private Panel panel9;
private Panel panel8;
private Panel panel6;
private Panel panel5;
private Panel panel4;
private Panel panel3;
private Label label10;
private Label label9;
private Label label8;
private Label label7;
private Label label6;
private RadioButton radioButton2;
private RadioButton radioButton1;
double[] m_adThisLineZV;
internal SRWindow(AppWorkspace appWorkspace)
{
this.appWorkspace = appWorkspace;
//
//初始化色板
//
this.colorsFormGrid = new ColorsForm();
this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
InitializeComponent();
InitializeLanguageText();
this.CreateParams.ClassStyle = this.CreateParams.ClassStyle | // Redraw On Size, And Own DC For Window.
User.CS_HREDRAW | User.CS_VREDRAW | User.CS_OWNDC;
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); // No Need To Erase Form Background
this.SetStyle(ControlStyles.DoubleBuffer, true); // Buffer Control
//zzz this.SetStyle(ControlStyles.Opaque, true); // No Need To Draw Form Background
this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize
this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves
this.Activated += new EventHandler(this.Form_Activated); // On Activate Event Call Form_Activated
this.Closing += new CancelEventHandler(this.Form_Closing); // On Closing Event Call Form_Closing
this.Deactivate += new EventHandler(this.Form_Deactivate); // On Deactivate Event Call Form_Deactivate
this.KeyDown += new KeyEventHandler(this.Form_KeyDown); // On KeyDown Event Call Form_KeyDown
//this.KeyUp += new KeyEventHandler(this.Form_KeyUp); // On KeyUp Event Call Form_KeyUp
this.Resize += new EventHandler(this.Form_Resize);
//this.Close();
ReadPar();
}
private void InitializeLanguageText()
{
this.groupBox1.Text = "三维图像";
this.groupBox2.Text = "操作";// PdnResources.GetString("Menu.operation.text");
this.button6.Text = "导出图片所有坐标对应的高度值";// PdnResources.GetString("Menu.Currentsoftware.text");
this.button5.Text = "操作点A";// "添加测量线";// PdnResources.GetString("Menu.Theharddiskimage.Text");
this.button4.Text = "操作点B";// "添加测量线";
this.button2.Text = "平移图像";
this.button1.Text = "旋转图像";
this.button9.Text = "图像翻转";
this.button8.Text = "高度彩虹色填充";
//this.groupBox3.Text = "三维图像";
this.Text = PdnResources.GetString("Menu.Tools.SurfacePlotShow.Text");
}
///
/// 初始化基础控件
///
public void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button6 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1 = new System.Windows.Forms.Panel();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.panel3 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.label10 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.panel7 = new System.Windows.Forms.Panel();
this.panel9 = new System.Windows.Forms.Panel();
this.panel8 = new System.Windows.Forms.Panel();
this.panel6 = new System.Windows.Forms.Panel();
this.panel5 = new System.Windows.Forms.Panel();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.button3 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
this.groupBox4.SuspendLayout();
this.groupBox5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.button9);
this.groupBox1.Controls.Add(this.button8);
this.groupBox1.Location = new System.Drawing.Point(20, 70);
this.groupBox1.Margin = new System.Windows.Forms.Padding(4);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4);
this.groupBox1.Size = new System.Drawing.Size(588, 424);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button2.Location = new System.Drawing.Point(407, 385);
this.button2.Margin = new System.Windows.Forms.Padding(4);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(84, 23);
this.button2.TabIndex = 0;
this.button2.Text = "平移图像";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button1.Location = new System.Drawing.Point(315, 385);
this.button1.Margin = new System.Windows.Forms.Padding(4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(84, 23);
this.button1.TabIndex = 0;
this.button1.Text = "旋转图像";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button9
//
this.button9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button9.Location = new System.Drawing.Point(98, 385);
this.button9.Margin = new System.Windows.Forms.Padding(4);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(84, 23);
this.button9.TabIndex = 0;
this.button9.Text = "图像翻转";
this.button9.UseVisualStyleBackColor = true;
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// button8
//
this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button8.Location = new System.Drawing.Point(190, 385);
this.button8.Margin = new System.Windows.Forms.Padding(4);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(117, 23);
this.button8.TabIndex = 0;
this.button8.Text = "高度彩虹色填充";
this.button8.UseVisualStyleBackColor = true;
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button6);
this.groupBox2.Controls.Add(this.button5);
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Location = new System.Drawing.Point(20, 13);
this.groupBox2.Margin = new System.Windows.Forms.Padding(4);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Padding = new System.Windows.Forms.Padding(4);
this.groupBox2.Size = new System.Drawing.Size(853, 49);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
//
// button6
//
this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button6.Location = new System.Drawing.Point(470, 16);
this.button6.Margin = new System.Windows.Forms.Padding(4);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(191, 23);
this.button6.TabIndex = 1;
this.button6.Text = "导出图片所有坐标对应的高度值";
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button5
//
this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button5.Location = new System.Drawing.Point(669, 16);
this.button5.Margin = new System.Windows.Forms.Padding(4);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(84, 23);
this.button5.TabIndex = 0;
this.button5.Text = "操作点A";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button4
//
this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button4.Location = new System.Drawing.Point(761, 16);
this.button4.Margin = new System.Windows.Forms.Padding(4);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(84, 23);
this.button4.TabIndex = 0;
this.button4.Text = "操作点B";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.trackBar1);
this.groupBox3.Controls.Add(this.panel2);
this.groupBox3.Controls.Add(this.panel1);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Controls.Add(this.label2);
this.groupBox3.Controls.Add(this.label1);
this.groupBox3.Location = new System.Drawing.Point(617, 71);
this.groupBox3.Margin = new System.Windows.Forms.Padding(4);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Padding = new System.Windows.Forms.Padding(4);
this.groupBox3.Size = new System.Drawing.Size(257, 68);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "设置";
//
// trackBar1
//
this.trackBar1.AutoSize = false;
this.trackBar1.Location = new System.Drawing.Point(79, 65);
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(125, 24);
this.trackBar1.TabIndex = 5;
this.trackBar1.Visible = false;
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.Red;
this.panel2.Location = new System.Drawing.Point(79, 44);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(125, 15);
this.panel2.TabIndex = 4;
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Black;
this.panel1.Location = new System.Drawing.Point(79, 18);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(125, 15);
this.panel1.TabIndex = 3;
this.panel1.Click += new System.EventHandler(this.panel1_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(8, 69);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 2;
this.label3.Text = "调整滤波:";
this.label3.Visible = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(8, 45);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(65, 12);
this.label2.TabIndex = 1;
this.label2.Text = "坐标颜色:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(65, 12);
this.label1.TabIndex = 0;
this.label1.Text = "背景颜色:";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.radioButton2);
this.groupBox4.Controls.Add(this.radioButton1);
this.groupBox4.Controls.Add(this.panel3);
this.groupBox4.Controls.Add(this.panel4);
this.groupBox4.Controls.Add(this.label10);
this.groupBox4.Controls.Add(this.label9);
this.groupBox4.Controls.Add(this.label8);
this.groupBox4.Controls.Add(this.label7);
this.groupBox4.Controls.Add(this.label6);
this.groupBox4.Controls.Add(this.label5);
this.groupBox4.Controls.Add(this.label4);
this.groupBox4.Controls.Add(this.panel7);
this.groupBox4.Controls.Add(this.panel9);
this.groupBox4.Controls.Add(this.panel8);
this.groupBox4.Controls.Add(this.panel6);
this.groupBox4.Controls.Add(this.panel5);
this.groupBox4.Location = new System.Drawing.Point(617, 149);
this.groupBox4.Margin = new System.Windows.Forms.Padding(4);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Padding = new System.Windows.Forms.Padding(4);
this.groupBox4.Size = new System.Drawing.Size(255, 138);
this.groupBox4.TabIndex = 6;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "彩虹色范围设置";
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(114, 22);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(53, 16);
this.radioButton2.TabIndex = 17;
this.radioButton2.Text = "主题2";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(12, 22);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(53, 16);
this.radioButton1.TabIndex = 0;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "主题1";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// panel3
//
this.panel3.BackColor = System.Drawing.Color.Lime;
this.panel3.Location = new System.Drawing.Point(45, 44);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(58, 15);
this.panel3.TabIndex = 4;
this.panel3.Click += new System.EventHandler(this.panel1_Click);
//
// panel4
//
this.panel4.BackColor = System.Drawing.Color.Red;
this.panel4.Location = new System.Drawing.Point(45, 66);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(58, 15);
this.panel4.TabIndex = 5;
this.panel4.Click += new System.EventHandler(this.panel1_Click);
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(114, 116);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(53, 12);
this.label10.TabIndex = 16;
this.label10.Text = "Range5:";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(114, 99);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(53, 12);
this.label9.TabIndex = 15;
this.label9.Text = "Range4:";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(114, 80);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(53, 12);
this.label8.TabIndex = 14;
this.label8.Text = "Range3:";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(114, 60);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(53, 12);
this.label7.TabIndex = 13;
this.label7.Text = "Range2:";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(114, 41);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(53, 12);
this.label6.TabIndex = 12;
this.label6.Text = "Range1:";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(11, 68);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(35, 12);
this.label5.TabIndex = 11;
this.label5.Text = "Max:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(11, 47);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(35, 12);
this.label4.TabIndex = 6;
this.label4.Text = "Min:";
//
// panel7
//
this.panel7.BackColor = System.Drawing.Color.Yellow;
this.panel7.Location = new System.Drawing.Point(167, 78);
this.panel7.Name = "panel7";
this.panel7.Size = new System.Drawing.Size(58, 15);
this.panel7.TabIndex = 6;
this.panel7.Click += new System.EventHandler(this.panel1_Click);
//
// panel9
//
this.panel9.BackColor = System.Drawing.Color.Maroon;
this.panel9.Location = new System.Drawing.Point(167, 116);
this.panel9.Name = "panel9";
this.panel9.Size = new System.Drawing.Size(58, 15);
this.panel9.TabIndex = 10;
this.panel9.Click += new System.EventHandler(this.panel1_Click);
//
// panel8
//
this.panel8.BackColor = System.Drawing.Color.Red;
this.panel8.Location = new System.Drawing.Point(167, 97);
this.panel8.Name = "panel8";
this.panel8.Size = new System.Drawing.Size(58, 15);
this.panel8.TabIndex = 6;
this.panel8.Click += new System.EventHandler(this.panel1_Click);
//
// panel6
//
this.panel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
this.panel6.Location = new System.Drawing.Point(167, 59);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(58, 15);
this.panel6.TabIndex = 6;
this.panel6.Click += new System.EventHandler(this.panel1_Click);
//
// panel5
//
this.panel5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.panel5.Location = new System.Drawing.Point(167, 40);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(58, 15);
this.panel5.TabIndex = 5;
this.panel5.Click += new System.EventHandler(this.panel1_Click);
//
// groupBox5
//
this.groupBox5.Controls.Add(this.pictureBox2);
this.groupBox5.Controls.Add(this.button3);
this.groupBox5.Controls.Add(this.button7);
this.groupBox5.Location = new System.Drawing.Point(616, 293);
this.groupBox5.Margin = new System.Windows.Forms.Padding(4);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Padding = new System.Windows.Forms.Padding(4);
this.groupBox5.Size = new System.Drawing.Size(257, 201);
this.groupBox5.TabIndex = 7;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "测量线高度图";
//
// pictureBox2
//
this.pictureBox2.Location = new System.Drawing.Point(7, 52);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(242, 142);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 2;
this.pictureBox2.TabStop = false;
//
// button3
//
this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button3.Location = new System.Drawing.Point(165, 22);
this.button3.Margin = new System.Windows.Forms.Padding(4);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(84, 23);
this.button3.TabIndex = 1;
this.button3.Text = "导出数据";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button7
//
this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button7.Location = new System.Drawing.Point(73, 22);
this.button7.Margin = new System.Windows.Forms.Padding(4);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(84, 23);
this.button7.TabIndex = 2;
this.button7.Text = "导出图片";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// SRWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(891, 507);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Margin = new System.Windows.Forms.Padding(4);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(907, 546);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(907, 546);
this.Name = "SRWindow";
this.Text = "SRWindow";
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.Controls.SetChildIndex(this.groupBox4, 0);
this.Controls.SetChildIndex(this.groupBox5, 0);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.groupBox5.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.ResumeLayout(false);
}
///
/// 操作点A按钮
///
///
///
private void button5_Click(object sender, EventArgs e)
{
m_iMusMod = 5;//操作点A
}
///
/// 操作点B按钮
///
///
///
private void button4_Click(object sender, EventArgs e)
{
m_iMusMod = 6;//操作点B
}
///
/// 图像翻转按钮
///
///
///
private void button9_Click(object sender, EventArgs e)
{
overturn();
}
///
/// 高度彩虹色填充按钮
///
///
///
private void button8_Click(object sender, EventArgs e)
{
ChangeColor();
}
///
/// 平移图片按钮
///
///
///
private void button2_Click(object sender, EventArgs e)
{
m_iMusMod = 2;//平移
}
///
/// 旋转图像按钮
///
///
///
private void button1_Click(object sender, EventArgs e)
{
m_iMusMod = 1;//旋转
}
public void ReadPar()
{
string fileName = System.Windows.Forms.Application.StartupPath/* + "\\Config\\" + "Default"*//*SettingPrefix*/ + "\\ThreeDataDemo_temp.xml";
threeDataDemo = Base.CommTool.XmlSerializeHelper.DESerializer(Base.CommTool.FileOperationHelper.ReadStringFromFile(fileName, System.IO.FileMode.Open));
//XmlDocument xd = new XmlDocument();
//string fileName = @"C:\Users\win10SSD\Desktop\工作目录\ThreeDDemo\ThreeDDemo20201029\ThreeDataDemo_00.xml";
////string fileName = @"C:\Users\win10SSD\Desktop\工作目录\ThreeDDemo\ThreeDSR20201108\ThreeDSR\ThreeDData.xml";
//xd.Load(fileName);
string str;
string[] strarr;
////XmlElement oneitem = (XmlElement)(xd.SelectSingleNode("Size"));
////str = oneitem.GetAttribute("width");
////m_iWidth = int.Parse(str);
////str = oneitem.GetAttribute("height");
////m_iHeight = int.Parse(str);
//XmlNodeList xmlNoteList = xd.GetElementsByTagName("Size");
if (threeDataDemo.size.Width < 1)
//if (xmlNoteList.Count < 1)
{
MessageBox.Show("XML文件错");
return;
}
str = threeDataDemo.size.Width.ToString();
m_iWidth = int.Parse(str);
str = threeDataDemo.size.Height.ToString();
m_iHeight = int.Parse(str);
//foreach (XmlElement item in xmlNoteList)
//{
// str = item.GetAttribute("width");
// m_iWidth = int.Parse(str);
// str = item.GetAttribute("height");
// m_iHeight = int.Parse(str);
// break;
//}
/*
XmlNode onenode = xd.SelectSingleNode("Z_level");
str = onenode.InnerXml;
string[] strarr = str.Split(',');
m_iDLevel = strarr.Length;
m_adDZ = new double[m_iDLevel];
m_adDC = new double[m_iDLevel,3];
for(int i = 0; i < m_iDLevel; i++)
{
m_adDZ[i] = double.Parse(strarr[i]);
}
*/
//xmlNoteList = xd.GetElementsByTagName("Z_level");
if (threeDataDemo.Z_level == null)
//if (xmlNoteList.Count < 1)
{
MessageBox.Show("XML文件错");
//return;
}
else
{
str = threeDataDemo.Z_level.ToString();
strarr = str.Split(',');
m_iDLevel = strarr.Length;
m_adDZ = new double[m_iDLevel];
m_adDC = new double[m_iDLevel, 3];
for (int i = 0; i < m_iDLevel; i++)
{
m_adDZ[i] = double.Parse(strarr[i]);
}
}
//foreach (XmlElement item in xmlNoteList)
//{
// str = item.InnerXml;
// strarr = str.Split(',');
// m_iDLevel = strarr.Length;
// m_adDZ = new double[m_iDLevel];
// m_adDC = new double[m_iDLevel, 3];
// for (int i = 0; i < m_iDLevel; i++)
// {
// m_adDZ[i] = double.Parse(strarr[i]);
// }
// break;
//}
//xmlNoteList = xd.GetElementsByTagName("colour");
if (threeDataDemo.Dyeing.Count < m_iDLevel)
//if (xmlNoteList.Count < m_iDLevel)
{
MessageBox.Show("XML文件错");
return;
}
int iX = 0;
for (int dyeingIndex = 0; dyeingIndex < threeDataDemo.Dyeing.Count; dyeingIndex++)
//foreach (XmlElement item in xmlNoteList)
{
str = threeDataDemo.Dyeing[dyeingIndex].ToString();
//str = item.InnerXml;
strarr = str.Split(',');
if (strarr.Length < 3)
{
MessageBox.Show("XML文件错");
return;
}
m_adDC[iX, 0] = double.Parse(strarr[0]);
m_adDC[iX, 1] = double.Parse(strarr[1]);
m_adDC[iX, 2] = double.Parse(strarr[2]);
iX++;
}
//xmlNoteList = xd.GetElementsByTagName("Column");
if (threeDataDemo.Z_value.Count < m_iWidth)
//if (xmlNoteList.Count < m_iWidth)
{
MessageBox.Show("XML文件错");
return;
}
m_adZV = new double[m_iWidth, m_iHeight];
bool bFirst = true;
iX = 0;
for (int Z_valueIndex = 0; Z_valueIndex < threeDataDemo.Z_value.Count; Z_valueIndex++)
//foreach (XmlElement item in xmlNoteList)
{
str = threeDataDemo.Z_value[Z_valueIndex].ToString();
//str = item.InnerXml;
strarr = str.Split(',');
if (strarr.Length < m_iHeight)
{
MessageBox.Show("XML文件错");
return;
}
for (int iY = 0; iY < m_iHeight; iY++)
{
m_adZV[iX, m_iHeight - 1 - iY] = double.Parse(strarr[iY]);
if ((bFirst) || (m_adZV[iX, m_iHeight - 1 - iY] > m_dMaxZV))
{
m_dMaxZV = m_adZV[iX, m_iHeight - 1 - iY];
}
if ((bFirst) || (m_adZV[iX, m_iHeight - 1 - iY] < m_dMinZV))
{
m_dMinZV = m_adZV[iX, m_iHeight - 1 - iY];
bFirst = false;
}
}
iX++;
}
//处理剖面线参数
m_afPonitB[0] = m_iWidth - 1;
m_afPonitB[1] = m_iHeight - 1;
CalculationIne();
//处理颜色和翻转参数
m_afNewClr = new float[m_iWidth, m_iHeight, 3];
m_adOverTurnZV = new double[m_iWidth, m_iHeight];
for (iX = 0; iX < m_iWidth; iX++)
{
for (int iY = 0; iY < m_iHeight; iY++)
{
float[] fColor = CalculationColorf(m_adZV[iX, iY]);
m_afNewClr[iX, iY, 0] = fColor[0];
m_afNewClr[iX, iY, 1] = fColor[1];
m_afNewClr[iX, iY, 2] = fColor[2];
m_adOverTurnZV[iX, iY] = m_dMinZV + (m_dMaxZV - m_adZV[iX, iY]);
}
}
fileName = System.Windows.Forms.Application.StartupPath/* + "\\Config\\" + "Default"*//*SettingPrefix*/ + "\\ThreeDataDemo_temp.bmp";
//fileName = @"C:\Users\win10SSD\Desktop\工作目录\ThreeDDemo\ThreeDDemo20201029\d2.bmp";
//fileName = @"C:\Users\win10SSD\Desktop\工作目录\ThreeDDemo\ThreeDSR20201108\ThreeDSR\d1.bmp";
Mat OrgImg = OpenCvSharp.Cv2.ImRead(fileName);
if ((m_iWidth != OrgImg.Cols) || (m_iHeight != OrgImg.Rows))//行数Rows是Y,列数是X
{
MessageBox.Show("图像尺寸和XML文件矛盾");
return;
}
m_afOrgClr = new float[m_iWidth, m_iHeight, 3];
int[] point = new int[2];
Vec3b OrgClr;
for (point[0] = 0; point[0] < m_iHeight; point[0]++)
{
for (point[1] = 0; point[1] < m_iWidth; point[1]++)
{
OrgClr = OrgImg.At(point[0], point[1]);
m_afOrgClr[point[1], m_iHeight - 1 - point[0], 0] = OrgClr.Item2 / 255.0F;
m_afOrgClr[point[1], m_iHeight - 1 - point[0], 1] = OrgClr.Item1 / 255.0F;
m_afOrgClr[point[1], m_iHeight - 1 - point[0], 2] = OrgClr.Item0 / 255.0F;
}
}
m_bRulerColor = false;
m_afThisClr = m_afOrgClr;
m_bOverTurn = false;
m_adThisZV = m_adZV;
m_adThisLineZV = m_adLineZV;
}
public float[] CalculationColorf(double dZ)
{
float[] fColor = new float[3];
if (dZ <= m_adDZ[m_iDLevel - 1])
{
fColor[0] = (float)m_adDC[m_iDLevel - 1, 0];
fColor[1] = (float)m_adDC[m_iDLevel - 1, 1];
fColor[2] = (float)m_adDC[m_iDLevel - 1, 2];
return fColor;
}
if (dZ >= m_adDZ[0])
{
fColor[0] = (float)m_adDC[0, 0];
fColor[1] = (float)m_adDC[0, 1];
fColor[2] = (float)m_adDC[0, 2];
return fColor;
}
int i, j;
for (j = 1; j < m_iDLevel; j++)
{
if (dZ > m_adDZ[j])
{
break;
}
}
i = j - 1;
double dIJ = Math.Abs(m_adDZ[i] - m_adDZ[j]);
double dWI = Math.Abs(dZ - m_adDZ[j]) / dIJ;
double dWJ = Math.Abs(m_adDZ[i] - dZ) / dIJ;
fColor[0] = (float)((m_adDC[i, 0] * dWI + m_adDC[j, 0] * dWJ) / 255.0);
fColor[1] = (float)((m_adDC[i, 1] * dWI + m_adDC[j, 1] * dWJ) / 255.0);
fColor[2] = (float)((m_adDC[i, 2] * dWI + m_adDC[j, 2] * dWJ) / 255.0);
return fColor;
}
private void CalculationIne()
{
LINE_PNTS = (int)Math.Sqrt((m_afPonitB[0] - m_afPonitA[0]) * (m_afPonitB[0] - m_afPonitA[0]) + (m_afPonitB[1] - m_afPonitA[1]) * (m_afPonitB[1] - m_afPonitA[1]));
if (LINE_PNTS < 3)
LINE_PNTS = 3;
m_afLineStep[0] = (m_afPonitB[0] - m_afPonitA[0]) / (LINE_PNTS - 1);
m_afLineStep[1] = (m_afPonitB[1] - m_afPonitA[1]) / (LINE_PNTS - 1);
m_afLineXY = new float[LINE_PNTS - 2, 2];
m_adLineZV = new double[LINE_PNTS];
m_adLineOverTurnZV = new double[LINE_PNTS];
if (!m_bOverTurn)
m_adThisLineZV = m_adLineZV;
else
m_adThisLineZV = m_adLineOverTurnZV;
m_adLineZV[0] = CalculationInterpolation(m_afPonitA[0], m_afPonitA[1]);
m_adLineOverTurnZV[0] = m_dMinZV + (m_dMaxZV - m_adLineZV[0]);
for (int i = 0; i < (LINE_PNTS - 2); i++)
{
m_afLineXY[i, 0] = m_afPonitA[0] + (i + 1) * m_afLineStep[0];
m_afLineXY[i, 1] = m_afPonitA[1] + (i + 1) * m_afLineStep[1];
m_adLineZV[i + 1] = CalculationInterpolation(m_afLineXY[i, 0], m_afLineXY[i, 1]);
m_adLineOverTurnZV[i + 1] = m_dMinZV + (m_dMaxZV - m_adLineZV[i + 1]);
}
m_adLineZV[LINE_PNTS - 1] = CalculationInterpolation(m_afPonitB[0], m_afPonitB[1]);
m_adLineOverTurnZV[LINE_PNTS - 1] = m_dMinZV + (m_dMaxZV - m_adLineZV[LINE_PNTS - 1]);
ShowSectionLine();
}
private double CalculationInterpolation(float fX, float fY)
{
int iXS = Math.Min(Math.Max((int)(fX), 0), m_iWidth - 1);
int iYS = Math.Min(Math.Max((int)(fY), 0), m_iHeight - 1);
int iXB = Math.Min(Math.Max((int)(fX + 1.0), 0), m_iWidth - 1);
int iYB = Math.Min(Math.Max((int)(fY + 1.0), 0), m_iHeight - 1);
double dWXB = Math.Min(Math.Max((fX - (double)iXS), 0.0), 1.0);
double dWXS = 1.0 - dWXB;
double dWYB = Math.Min(Math.Max((fY - (double)iYS), 0.0), 1.0);
double dWYS = 1.0 - dWYB;
double dTempA = m_adZV[iXS, iYS];
double dTempB = m_adZV[iXS, iYB];
double dTempC = m_adZV[iXB, iYS];
double dTempD = m_adZV[iXB, iYB];
double dTempAB = dTempA * dWYS + dTempB * dWYB;
double dTempCD = dTempC * dWYS + dTempD * dWYB;
double dRtn = dTempAB * dWXS + dTempCD * dWXB;
return dRtn;// dTempA;//
}
private static void PictureBox1_Paint(object sender, PaintEventArgs e)
{
//Application.DoEvents(); // Process Events
//// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
//if ((active && (form != null) && !DrawGLScene()) /*|| keys[(int) Keys.Escape]*/)
//{ // Active? Was There A Quit Received?
// done = true; // ESC Or DrawGLScene Signalled A Quit
//}
//else
//{ // Not Time To Quit, Update Screen
// Gdi.SwapBuffers(hDC); // Swap Buffers (Double Buffering)
//}
}
internal static void Run(AppWorkspace appWorkspace) {
done = false;
// Create Our OpenGL Window
if (!CreateGLWindow(appWorkspace, PdnResources.GetString("Menu.Tools.SurfacePlotShow.Text"), 990, 690, 16)) {
return; // Quit If Window Was Not Created
}
while (!done)
{ // Loop That Runs While done = false
Application.DoEvents(); // Process Events
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && (form != null) && !DrawGLScene()) /*|| keys[(int) Keys.Escape]*/)
{ // Active? Was There A Quit Received?
done = true; // ESC Or DrawGLScene Signalled A Quit
}
else
{ // Not Time To Quit, Update Screen
Gdi.SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
/*
if(keys[(int) Keys.F1]) { // Is F1 Being Pressed?
keys[(int) Keys.F1] = false; // If So Make Key false
KillGLWindow(); // Kill Our Current Window
// Recreate Our OpenGL Window
if(!CreateGLWindow("三维面绘制", 640, 480, 16)) {
return; // Quit If Window Was Not Created
}
done = false; // We're Not Done Yet
}
*/
}
// Shutdown
KillGLWindow(); // Kill The Window
return; // Exit The Program
}
private static bool CreateGLWindow(AppWorkspace appWorkspace, string title, int width, int height, int bits)
{
int pixelFormat; // Holds The Results After Searching For A Match
form = null; // Null The Form
GC.Collect(); // Request A Collection
// This Forces A Swap
Kernel.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
form = new SRWindow(appWorkspace); // Create The Window
form.FormBorderStyle = FormBorderStyle.Sizable; // Sizable
Cursor.Show(); // Show Mouse Pointer
form.Width = width; // Set Window Width
form.Height = height; // Set Window Height
form.Text = title; // Set Window Title
Gdi.PIXELFORMATDESCRIPTOR pfd = new Gdi.PIXELFORMATDESCRIPTOR(); // pfd Tells Windows How We Want Things To Be
pfd.nSize = (short) Marshal.SizeOf(pfd); // Size Of This Pixel Format Descriptor
pfd.nVersion = 1; // Version Number
pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW | // Format Must Support Window
Gdi.PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
Gdi.PFD_DOUBLEBUFFER; // Format Must Support Double Buffering
pfd.iPixelType = (byte) Gdi.PFD_TYPE_RGBA; // Request An RGBA Format
pfd.cColorBits = (byte) bits; // Select Our Color Depth
pfd.cRedBits = 0; // Color Bits Ignored
pfd.cRedShift = 0;
pfd.cGreenBits = 0;
pfd.cGreenShift = 0;
pfd.cBlueBits = 0;
pfd.cBlueShift = 0;
pfd.cAlphaBits = 0; // No Alpha Buffer
pfd.cAlphaShift = 0; // Shift Bit Ignored
pfd.cAccumBits = 0; // No Accumulation Buffer
pfd.cAccumRedBits = 0; // Accumulation Bits Ignored
pfd.cAccumGreenBits = 0;
pfd.cAccumBlueBits = 0;
pfd.cAccumAlphaBits = 0;
pfd.cDepthBits = 16; // 16Bit Z-Buffer (Depth Buffer)
pfd.cStencilBits = 0; // No Stencil Buffer
pfd.cAuxBuffers = 0; // No Auxiliary Buffer
pfd.iLayerType = (byte) Gdi.PFD_MAIN_PLANE; // Main Drawing Layer
pfd.bReserved = 0; // Reserved
pfd.dwLayerMask = 0; // Layer Masks Ignored
pfd.dwVisibleMask = 0;
pfd.dwDamageMask = 0;
//hDC = User.GetDC(form.Handle); // Attempt To Get A Device Context
form.pictureBox1 = new PictureBox();
((System.ComponentModel.ISupportInitialize)(form.pictureBox1)).BeginInit();
//form.pictureBox1.Location = new System.Drawing.Point(22, 40);
//form.pictureBox1.Location = new System.Drawing.Point(20, 180);
form.pictureBox1.Location = new System.Drawing.Point(15, 18);
form.pictureBox1.Name = "pictureBox1";
form.pictureBox1.Size = new System.Drawing.Size(560, 400);
//form.pictureBox1.Size = new System.Drawing.Size(1272, 651);
form.pictureBox1.TabIndex = 0;
form.pictureBox1.TabStop = false;
/*form*/form.groupBox1.Controls.Add(form.pictureBox1);
((System.ComponentModel.ISupportInitialize)(form.pictureBox1)).EndInit();
form.pictureBox1.Paint += PictureBox1_Paint;
form.pictureBox1.MouseMove += new MouseEventHandler(form.pictureBox1_MouseMove);
form.pictureBox1.MouseDown += new MouseEventHandler(form.pictureBox1_MouseDown);
form.pictureBox1.MouseUp += new MouseEventHandler(form.pictureBox1_MouseUp);
form.pictureBox1.MouseLeave += new EventHandler(form.pictureBox1_MouseLeave);
hDC = User.GetDC(form.pictureBox1.Handle);
if(hDC == IntPtr.Zero) { // Did We Get A Device Context?
KillGLWindow(); // Reset The Display
MessageBox.Show("Can't Create A GL Device Context.", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
pixelFormat = Gdi.ChoosePixelFormat(hDC, ref pfd); // Attempt To Find An Appropriate Pixel Format
if(pixelFormat == 0) { // Did Windows Find A Matching Pixel Format?
KillGLWindow(); // Reset The Display
MessageBox.Show("Can't Find A Suitable PixelFormat.", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if(!Gdi.SetPixelFormat(hDC, pixelFormat, ref pfd)) { // Are We Able To Set The Pixel Format?
KillGLWindow(); // Reset The Display
MessageBox.Show("Can't Set The PixelFormat.", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
hRC = Wgl.wglCreateContext(hDC); // Attempt To Get The Rendering Context
if(hRC == IntPtr.Zero) { // Are We Able To Get A Rendering Context?
KillGLWindow(); // Reset The Display
MessageBox.Show("Can't Create A GL Rendering Context.", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if(!Wgl.wglMakeCurrent(hDC, hRC)) { // Try To Activate The Rendering Context
KillGLWindow(); // Reset The Display
MessageBox.Show("Can't Activate The GL Rendering Context.", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
form.Show(); // Show The Window
//zzz form.TopMost = true; // Topmost Window
form.Focus(); // Focus The Window
//form.BackColor = Color.Gray;
////form.WindowState = FormWindowState.Maximized;
//ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen
if (!InitGL())
{ // Initialize Our Newly Created GL Window
KillGLWindow(); // Reset The Display
MessageBox.Show("Initialization Failed.", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true; // Success
}
private static bool DrawGLScene()
{
//new platform
iniView();
Gl.glTranslatef(0, 0, 0);
myRotate();
//错了 Gl.glTranslatef(m_fT_xyz[0],m_fT_xyz[1],0);
for (int i = 0; i < form.m_iWidth - 1; i++)
{
Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
for (int j = 0; j < form.m_iHeight; j++)
{
DrowOnePnt(i, j);
DrowOnePnt(i + 1, j);
}
Gl.glEnd();
}
if ((form.m_iMusMod >= 5) && (form.m_iMusMod <= 7) || true)
{
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor3f(1.0F, 1.0F, 0.0F);
Gl.glVertex3d(form.m_afPonitA[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glVertex3d(form.m_afPonitA[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glVertex3d(form.m_afPonitA[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glVertex3d(form.m_afPonitA[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glEnd();
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glColor3f(0.0F, 1.0F, 0.0F);
Gl.glVertex3d(form.m_afPonitA[0] - form.m_iWidth / 2.0, form.m_afPonitA[1] - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
for (int i = 0; i < (LINE_PNTS - 2); i++)
{
Gl.glVertex3d(form.m_afLineXY[i, 0] - form.m_iWidth / 2.0, form.m_afLineXY[i, 1] - form.m_iHeight / 2.0, 1.0 + /*form.m_adThisZV[(int)form.m_afLineXY[i, 0], (int)form.m_afLineXY[i, 1]]*/form.m_adThisLineZV[i + 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
}
Gl.glVertex3d(form.m_afPonitB[0] - form.m_iWidth / 2.0, form.m_afPonitB[1] - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glEnd();
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor3f(0.0F, 1.0F, 01.0F);
Gl.glVertex3d(form.m_afPonitB[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glVertex3d(form.m_afPonitB[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glVertex3d(form.m_afPonitB[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glVertex3d(form.m_afPonitB[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
Gl.glEnd();
}
Gl.glLoadIdentity();
return true;
}
private static void myRotate()
{
int[,] vec = new int[3, 3] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
for (int i = 0; i <= 2; i++)
{
Gl.glRotatef(form.m_fR_xyz[i], vec[i, 0], vec[i, 1], vec[i, 2]);
}
}
public static void DrowOnePnt(int i, int j)
{
Gl.glColor3f(form.m_afThisClr[i, j, 0], form.m_afThisClr[i, j, 1], form.m_afThisClr[i, j, 2]);
Gl.glVertex3d(i - form.m_iWidth / 2.0, j - form.m_iHeight / 2.0, form.m_adThisZV[i, j] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
}
private static bool InitGL()
{
//Gl.glShadeModel(Gl.GL_SMOOTH); // Enable Smooth Shading
//Gl.glClearColor(0, 0, 0, 0.5f); // Black Background
//Gl.glClearDepth(1); // Depth Buffer Setup
Gl.glEnable(Gl.GL_DEPTH_TEST); // Enables Depth Testing
//Gl.glDepthFunc(Gl.GL_LEQUAL); // The Type Of Depth Testing To Do
//Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST); // Really Nice Perspective Calculations
// 设置视口 viewport
Gl.glViewport(0, 0, form.pictureBox1.Width, form.pictureBox1.Height);
//启用阴影平滑
Gl.glShadeModel(Gl.GL_SMOOTH);
//启用反走样
Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);
// 设置投影模式 projection matrix
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
iniView();
return true;
}
public static void iniView(bool clearColor = true)
{
// 重置黑色背景
if (clearColor)
{
Gl.glClearColor((float)(form.panel1.BackColor.R / 255.0), (float)(form.panel1.BackColor.G / 255.0), (float)(form.panel1.BackColor.B / 255.0), (float)(form.panel1.BackColor.A / 255.0));
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
}
else
return;
form.m_fT_xyz[2] = (float)Math.Max(form.m_dMaxZV, Math.Abs(form.m_dMinZV));
form.m_fT_xyz[2] = (float)(-1.0 * Math.Max(Math.Max(form.m_iWidth * 0.8, form.m_iHeight * 0.8), form.m_fT_xyz[2]));
////form.m_fT_xyz[2] = (float)(1.2 * form.m_fT_xyz[2]);
////Glu.gluPerspective(85, form.pictureBox1.Width / (double)form.pictureBox1.Height, 1, -4.0/*-2.0*/ * form.m_fT_xyz[2]);//距离裁减
//Gl.glOrtho(0, form.pictureBox1.Width, form.pictureBox1.Height, 0, 1, -4.0/*-2.0*/ * form.m_fT_xyz[2]);
double size1 = form.m_iHeight / 1.0;
Gl.glOrtho(-size1 * form.pictureBox1.Width / (double)form.pictureBox1.Height, size1 * form.pictureBox1.Width / (double)form.pictureBox1.Height, -size1, size1, 2.4 * form.m_fT_xyz[2], -12.4 * form.m_fT_xyz[2]);
// 选择模型观察矩阵 modelview matrix
Gl.glMatrixMode(Gl.GL_MODELVIEW);
//重置模型观察矩阵
Gl.glLoadIdentity();
Glu.gluLookAt(-1.0 * form.m_fT_xyz[0], -1.0 * form.m_fT_xyz[1], -1.2/*-1.0*/ * form.m_fT_xyz[2], // 眼睛位置
-1.0 * form.m_fT_xyz[0], -1.0 * form.m_fT_xyz[1], 0, // 观察点
0, 1, 0);
}
private static void KillGLWindow() {
if(hRC != IntPtr.Zero) { // Do We Have A Rendering Context?
if(!Wgl.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero)) { // Are We Able To Release The DC and RC Contexts?
MessageBox.Show("Release Of DC And RC Failed.", "SHUTDOWN ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if(!Wgl.wglDeleteContext(hRC)) { // Are We Able To Delete The RC?
MessageBox.Show("Release Rendering Context Failed.", "SHUTDOWN ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
hRC = IntPtr.Zero; // Set RC To Null
}
if(hDC != IntPtr.Zero) { // Do We Have A Device Context?
if(form != null && !form.IsDisposed) { // Do We Have A Window?
if(form.Handle != IntPtr.Zero) { // Do We Have A Window Handle?
if(!User.ReleaseDC(form.Handle, hDC)) { // Are We Able To Release The DC?
MessageBox.Show("Release Device Context Failed.", "SHUTDOWN ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
hDC = IntPtr.Zero; // Set DC To Null
}
if(form != null) { // Do We Have A Windows Form?
form.Hide(); // Hide The Window
form.Close(); // Close The Form
form = null; // Set form To Null
}
}
private static void ReSizeGLScene(int width, int height) {
if(height == 0) { // Prevent A Divide By Zero...
height = 1; // By Making Height Equal To One
}
Gl.glViewport(0, 0, width, height); // Reset The Current Viewport
Gl.glMatrixMode(Gl.GL_PROJECTION); // Select The Projection Matrix
Gl.glLoadIdentity(); // Reset The Projection Matrix
Glu.gluPerspective(45, width / (double) height, 0.1, 100); // Calculate The Aspect Ratio Of The Window
Gl.glMatrixMode(Gl.GL_MODELVIEW); // Select The Modelview Matrix
Gl.glLoadIdentity(); // Reset The Modelview Matrix
}
private void Form_Activated(object sender, EventArgs e)
{
active = true; // Program Is Active
}
private void Form_Closing(object sender, CancelEventArgs e)
{
done = true; // Send A Quit Message
}
private void Form_Deactivate(object sender, EventArgs e)
{
active = false; // Program Is No Longer Active
}
private void Form_KeyDown(object sender, KeyEventArgs e)
{
//keys[e.KeyValue] = true; // Key Has Been Pressed, Mark It As true
switch (e.KeyValue)
{
case (int) Keys.Escape://退出
done = true;
break;
case 49://'1'
m_iMusMod = 1;//旋转图像
break;
case 50://'2'
m_iMusMod = 2;//平移图像
break;
case 53://'5'
m_iMusMod = 5;//操作点A
break;
case 54://'6'
m_iMusMod = 6;//操作点B
break;
case 55://'7'
m_iMusMod = 7;//看剖面线
ShowSectionLine();
break;
case 56://'8'
overturn();
break;
case 57://'9'
ChangeColor();
break;
default:
m_iMusMod = 0;//no meaning
break;
}
}
private void ShowSectionLine()
{
//m_fmLine = new SRLinesForm();
//m_fmLine.Show();
this.m_adValue = new double[LINE_PNTS];
this.m_dYVMax = m_dMaxZV + 1.0;
this.m_dYVMin = m_dMinZV - 1.0;
for (int i = 0; i < LINE_PNTS; i++)
{
this.m_adValue[i] = m_adLineZV[i];
}
this.draw(0);
}
//zzz
public int m_iYVCount = 10;
public double m_dYVMax = 51;
public double m_dYVMin = -51;
///
/// Z轴高度集合,从A到B按照均匀取到了100个点
///
private double[] m_adValue = new double[LINE_PNTS];
public int m_iYPixelMax = 350;
public int m_iYPixelMin = 40;
public int m_iXPixelMax = 1100;
public int m_iXPixelMin = 60;
// x1,y1为鼠标移动的坐标,画十字线用,xbuf,ybuf绘制点坐标数组
void draw(int x1/*, int y1, int[] xbuf, int[] ybuf*/)
{
//定义画布大小
int height = m_iYPixelMax, width = m_iXPixelMax;
int showLINE_PNTS = 100;
//创建位图
System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height);
//创建Graphics类对象
Graphics g = Graphics.FromImage(image);
//清空图片背景色
g.Clear(Color.White);
Font font = new System.Drawing.Font("Arial", 16, FontStyle.Regular);
Font font1 = new System.Drawing.Font("宋体", 14, FontStyle.Regular);
Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
g.FillRectangle(Brushes.SeaGreen, 0, 0, width, height);
Brush brush1 = new SolidBrush(Color.Blue);
Brush brush2 = new SolidBrush(Color.SaddleBrown);
//画图片的边框线
g.DrawRectangle(new Pen(Color.Black), m_iXPixelMin, m_iYPixelMin, (showLINE_PNTS - 1) * 10, 270);
g.DrawRectangle(new Pen(Color.Black), m_iXPixelMin, m_iYPixelMin - 5, (showLINE_PNTS - 1) * 10, 275);
System.Drawing.Pen mypen = new Pen(brush, 1);
System.Drawing.Pen mypen2 = new Pen(Color.Red, 2);
System.Drawing.Pen mypen3 = new Pen(Color.Yellow, 1);
//绘制线条
//绘制纵向线条
double x = 0.0 + m_iXPixelMin;
for (int i = 0; i < 9; i++)
{
x = x + 100;
g.DrawLine(mypen, (float)x, 40, (float)x, m_iYPixelMax - 40);
}
//Pen mypen1 = new Pen(Color.Blue, 2);
//g.DrawLine(mypen1, x - 480, 80, x - 480, 340);
//绘制横向线条
int y = m_iYPixelMin + 30;
for (int i = 0; i < 8; i++)
{
g.DrawLine(mypen, m_iXPixelMin, y, m_iXPixelMin + (showLINE_PNTS - 1) * 10, y);
y = y + 30;
}
//x轴上对应的标记
/*
String[] n = { " 10", " 20", " 30", " 40", " 50", " 60", " 70",
" 80", " 90", " 100", "110", "120", "130", "140", "150", "160", "170"};
*/
x = m_iXPixelMin - 5;
g.DrawString("A", font, Brushes.Red, (float)x, m_iYPixelMax - 35);
x += 10;
for (int i = 1; i < showLINE_PNTS - 1; i++)
{
g.DrawString(".", font, Brushes.Red, (float)x, m_iYPixelMax - 35); //设置文字内容及输出位置
x = x + 10;
}
g.DrawString("B", font, Brushes.Red, (float)x, m_iYPixelMax - 35);
//y轴上对应的标记
/*
String[] m = {"40", "35", "30", "25", "20", "15", "10",
" 5"};
*/
double dYStep = (m_dYVMax - m_dYVMin) / 9.0;
y = m_iYPixelMin - 5;
for (int i = 0; i < 10; i++)
{
double dTemp = m_dYVMax - i * dYStep;
string str = dTemp.ToString("f1");
g.DrawString(str, font1, Brushes.Red, 1, y); //设置文字内容及输出位置
y = y + 30;
}
x = m_iXPixelMin;
y = (int)(m_iYPixelMin + 270.0 * ((m_dYVMax - m_adValue[0]) / (m_dYVMax - m_dYVMin)) + 0.5);
double dXStep = 10.0 * showLINE_PNTS / LINE_PNTS;
for (int i = 1; i < LINE_PNTS; i++)//##################################showLINE_PNTS
{
int yNext = (int)(m_iYPixelMin + 270.0 * ((m_dYVMax - m_adValue[Math.Min(i, LINE_PNTS - 1)]) / (m_dYVMax - m_dYVMin)) + 0.5);
g.DrawLine(mypen3, (int)x, y, (int)(x + dXStep), yNext);
x += dXStep;
y = yNext;
}
/*
if (drawflag == 1)
{
for (int i = 0; i < readlen / 2; i++)
{
g.DrawEllipse(mypen2, xbuf[i] - 2, ybuf[i] - 2, 4, 4);
if (i < readlen / 2 - 1)
g.DrawLine(mypen3, xbuf[i], ybuf[i], xbuf[i + 1], ybuf[i + 1]);
}
}
if (flag == true)
{
g.DrawLine(mypen2, x1, 41, x1, 310);
g.DrawLine(mypen2, 41, y1, 760, y1);
}
g.Dispose();
*/
this.pictureBox2.Image = image;
}
private void overturn()
{
if (m_bOverTurn)
{
m_bOverTurn = false;
m_adThisZV = m_adZV;
m_adThisLineZV = m_adLineZV;
}
else
{
m_bOverTurn = true;
m_adThisZV = m_adOverTurnZV;
m_adThisLineZV = m_adLineOverTurnZV;
}
RefreshColorAction();
}
private void ChangeColor()
{
if (m_bRulerColor)
m_bRulerColor = false;
else
m_bRulerColor = true;
if (m_bRulerColor)
RefreshColorAction();
else
m_afThisClr = m_afOrgClr;
}
private void RefreshColorAction()
{
if (m_bRulerColor)
{
colorStyle1 = this.radioButton1.Checked;
if (colorStyle1)
{
style1Color1 = this.panel3.BackColor;//.ToArgb();
style1Color2 = this.panel4.BackColor;//.ToArgb();
}
else
{
style2ColorList.Clear();
style2ColorList.Add(this.panel5.BackColor/*.ToArgb()*/);
style2ColorList.Add(this.panel6.BackColor/*.ToArgb()*/);
style2ColorList.Add(this.panel7.BackColor/*.ToArgb()*/);
style2ColorList.Add(this.panel8.BackColor/*.ToArgb()*/);
style2ColorList.Add(this.panel9.BackColor/*.ToArgb()*/);
}
double adZVRange = m_dMaxZV - m_dMinZV;
//处理颜色和翻转参数
m_afNewClr = new float[m_iWidth, m_iHeight, 3];
//m_adOverTurnZV = new double[m_iWidth, m_iHeight];
for (int iX = 0; iX < m_iWidth; iX++)
{
for (int iY = 0; iY < m_iHeight; iY++)
{
Color fColor = /*Color.FromArgb(*/CalculationColorfRange(((m_bOverTurn ? m_adOverTurnZV[iX, iY] : m_adZV[iX, iY]) - m_dMinZV) / adZVRange)/*)*/;
m_afNewClr[iX, iY, 0] = (float)(fColor.R / 255.0);
m_afNewClr[iX, iY, 1] = (float)(fColor.G / 255.0);
m_afNewClr[iX, iY, 2] = (float)(fColor.B / 255.0);
//m_adOverTurnZV[iX, iY] = m_dMinZV + (m_dMaxZV - m_adZV[iX, iY]);
}
}
m_afThisClr = m_afNewClr;
}
}
private bool colorStyle1 = true;
private Color style1Color1;
private Color style1Color2;
private List style2ColorList = new List();
///
/// 根据设置计算彩虹色的变化
///
///
///
public Color CalculationColorfRange(double dZ)
{
if (dZ < 0)
dZ = 0;
if (dZ > 1)
dZ = 1;
if (colorStyle1)
return Color.FromArgb(255, (int)(style1Color1.R + (style1Color2.R - style1Color1.R) * dZ), (int)(style1Color1.G + (style1Color2.G - style1Color1.G) * dZ), (int)(style1Color1.B + (style1Color2.B - style1Color1.B) * dZ));// (int)(style1Color1 + (style1Color2 - style1Color1) * dZ);
int color_index = Math.Min(3, (int)(dZ / 0.2));
//for (color_index = 0; color_index < style2ColorList.Count - 1; color_index++)
//{
// if ((style2ColorList[color_index] - dZ) * (style2ColorList[color_index + 1] - dZ) <= 0)
// break;
//}
return Color.FromArgb(255, (int)(style2ColorList[color_index].R + (style2ColorList[color_index + 1].R - style2ColorList[color_index].R) * (dZ - color_index * 0.2)), (int)(style2ColorList[color_index].G + (style2ColorList[color_index + 1].G - style2ColorList[color_index].G) * (dZ - color_index * 0.2)), (int)(style2ColorList[color_index].B + (style2ColorList[color_index + 1].B - style2ColorList[color_index].B) * (dZ - color_index * 0.2)));// (int)(style2ColorList[color_index] + (style2ColorList[color_index + 1] - style2ColorList[color_index]) * (dZ - color_index * 0.2));
//float[] fColor = new float[3];
//if (dZ < m_adDZ[m_iDLevel - 1])
//{
// fColor[0] = (float)m_adDC[m_iDLevel - 1, 0];
// fColor[1] = (float)m_adDC[m_iDLevel - 1, 1];
// fColor[2] = (float)m_adDC[m_iDLevel - 1, 2];
// return fColor;
//}
//if (dZ > m_adDZ[0])
//{
// fColor[0] = (float)m_adDC[0, 0];
// fColor[1] = (float)m_adDC[0, 1];
// fColor[2] = (float)m_adDC[0, 2];
// return fColor;
//}
//int i, j;
//for (j = 1; j < m_iDLevel; j++)
//{
// if (dZ > m_adDZ[j])
// {
// break;
// }
//}
//i = j - 1;
//double dIJ = Math.Abs(m_adDZ[i] - m_adDZ[j]);
//double dWI = Math.Abs(dZ - m_adDZ[j]) / dIJ;
//double dWJ = Math.Abs(m_adDZ[i] - dZ) / dIJ;
//fColor[0] = (float)((m_adDC[i, 0] * dWI + m_adDC[j, 0] * dWJ) / 255.0);
//fColor[1] = (float)((m_adDC[i, 1] * dWI + m_adDC[j, 1] * dWJ) / 255.0);
//fColor[2] = (float)((m_adDC[i, 2] * dWI + m_adDC[j, 2] * dWJ) / 255.0);
//return fColor;
}
/*
private void Form_KeyUp(object sender, KeyEventArgs e) {
keys[e.KeyValue] = false; // Key Has Been Released, Mark It As false
}
*/
private void Form_Resize(object sender, EventArgs e)
{
//ReSizeGLScene(form.Width, form.Height); // Resize The OpenGL Window
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if ((m_iMusMod <= 0) || (m_iMusMod >= 7))
{
return;
}
//int iBtnDwn = Glfw.glfwGetMouseButton(Glfw.GLFW_MOUSE_BUTTON_LEFT);
if (0 == m_iMusDown)
{
m_iLastMusDown = 0;
return;
}
else if (0 == m_iLastMusDown)
{
m_iLastMusDown = 1;
m_iLastmouseX = e.X;
m_iLastmouseY = e.Y;
return;
}
float fXChange = e.X - m_iLastmouseX;
float fYChange = e.Y - m_iLastmouseY;
m_fR_xyz[0] = AngleNormalization(m_fR_xyz[0]);
m_fR_xyz[1] = AngleNormalization(m_fR_xyz[1]);
if (1 == m_iMusMod)
{
if ((m_fR_xyz[0] > 90.0) && (m_fR_xyz[0] < 270.0))//先绕X轴转完了
{
fXChange *= -1.0F;
}
m_fR_xyz[0] += fYChange;
m_fR_xyz[1] += fXChange;
//m_fR_xyz[2] = 0.0F;
}
else if (2 == m_iMusMod)
{
m_fT_xyz[0] += fXChange * 0.91F;
m_fT_xyz[1] += fYChange * -0.91F;
}
else if (5 == m_iMusMod)
{
if ((m_fR_xyz[0] > 90.0) && (m_fR_xyz[0] < 270.0))//先绕X轴转完了
{
fYChange *= -1.0F;
}
if ((m_fR_xyz[1] > 90.0) && (m_fR_xyz[1] < 270.0))//先绕X轴转完了
{
fXChange *= -1.0F;
}
m_afPonitA[0] += fXChange * 0.95F;
m_afPonitA[0] = (float)Math.Min(Math.Max(m_afPonitA[0], 1.0), m_iWidth - 1);
m_afPonitA[1] += fYChange * -0.95F;
m_afPonitA[1] = (float)Math.Min(Math.Max(m_afPonitA[1], 1.0), m_iHeight - 1);
CalculationIne();
}
else if (6 == m_iMusMod)
{
if ((m_fR_xyz[0] > 90.0) && (m_fR_xyz[0] < 270.0))//先绕X轴转完了
{
fYChange *= -1.0F;
}
if ((m_fR_xyz[1] > 90.0) && (m_fR_xyz[1] < 270.0))//先绕X轴转完了
{
fXChange *= -1.0F;
}
m_afPonitB[0] += fXChange * 0.95F;
m_afPonitB[0] = (float)Math.Min(Math.Max(m_afPonitB[0], 1.0), m_iWidth - 1);
m_afPonitB[1] += fYChange * -0.95F;
m_afPonitB[1] = (float)Math.Min(Math.Max(m_afPonitB[1], 1.0), m_iHeight - 1);
CalculationIne();
}
m_iLastmouseX = e.X;
m_iLastmouseY = e.Y;
}
private float AngleNormalization(float fOldAngle)
{
float fNewAngle = fOldAngle % 360.0F;
if (fNewAngle < 0)
{
fNewAngle += 360.0F;
}
return fNewAngle;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
m_iMusDown = 1;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
m_iMusDown = 0;
}
}
///
/// 导出图片所有坐标对应的高度值
///
///
///
private void button6_Click(object sender, EventArgs e)
{
SaveFileDialog exe = new SaveFileDialog();
exe.Filter = "Execl files (*.xlsx)|*.xlsx";
exe.FilterIndex = 0;
exe.RestoreDirectory = true;
exe.Title = "Export Excel File";
exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
exe.FileName = this.Text + "-" + "图片高度数据" + DateTime.Now.ToString("yyyyMMddHHmmss");
DialogResult dr = exe.ShowDialog();
if (dr != DialogResult.OK)
return;
//m_adZV = new double[m_iWidth, m_iHeight];
List list = new List();
DataTable dt = new DataTable("tag");
dt.Columns.Add(new DataColumn(@"Y\X", typeof(string)));
for (int iX = 0; iX < m_iWidth; iX++)
dt.Columns.Add(new DataColumn(iX + "", typeof(string)));//这里是X坐标
for (int itemIndex = 0; itemIndex < m_iHeight; itemIndex++)
{
DataRow dataRow = dt.NewRow();
dataRow[@"Y\X"] = itemIndex.ToString();//这里是Y坐标
for (int iX = 0; iX < m_iWidth; iX++)
{
dataRow[iX + ""] = form.m_adThisZV[iX, m_iHeight - 1 - itemIndex].ToString();
////m_adZV[iX, iY] = double.Parse(strarr[iY]);
//form.m_adThisZV[iX, iY]
}
dt.Rows.Add(dataRow);
}
OfficeFileHandleHelper.ExporeToExcel(exe.FileName, dt);
//list.Add(dt);
//this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName/*, true, true, this, PdnResources.GetString("Menu.ExportdatatoEXECLtable.Text")*/);
//MessageBox.Show(PdnResources.GetString("Menu.ResultsExportedsuccessfully.Text"));
//System.IO.Stream ms;
//ms = exe.OpenFile();
//System.IO.StreamWriter sw = new System.IO.StreamWriter(ms, System.Text.Encoding.GetEncoding(-0));
//string str = "";
//try
//{
// for (int i = 0; i < dt.Columns.Count; i++)
// {
// if (i > 0)
// {
// str += "\t";
// }
// str += dt.Columns[i].ColumnName;
// }
// sw.WriteLine(str);
// for (int j = 0; j < dt.Rows.Count; j++)
// {
// string temp = "";
// for (int k = 0; k < dt.Columns.Count; k++)
// {
// if (k > 0)
// {
// temp += "\t";
// }
// string cell = dt.Rows[j][k].ToString();
// cell = cell.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\r\n", "");
// temp += cell;
// }
// sw.WriteLine(temp);
// }
// sw.Close();
// ms.Close();
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
// return;
//}
//finally
//{
// sw.Close();
// ms.Close();
//}
//Base.CommTool.OfficeFileHandleHelper.ExportDataToExcel(exe.FileName, list);
//测试说不要提示结果
//MessageBox.Show(PdnResources.GetString("Menu.ResultsExportedsuccessfully.Text"));
//if (this.m_adValue.Length > 0)
//{
// if (dr == DialogResult.OK)
// {
// if (this.m_adValue.Length > 0)
// {
// List list = new List();
// DataTable dt = new DataTable("tag");
// dt.Columns.Add(new DataColumn("序号", typeof(string)));
// dt.Columns.Add(new DataColumn("高度", typeof(string)));
// int itemIndex = 0;
// foreach (var item in this.m_adValue)
// {
// DataRow dataRow = dt.NewRow();
// dataRow["序号"] = itemIndex.ToString();
// dataRow["高度"] = item.ToString();
// dt.Rows.Add(dataRow);
// itemIndex++;
// }
// list.Add(dt);
// ///#########################################
// Base.CommTool.OfficeFileHandleHelper.ExportDataToExcel(exe.FileName, list);
// MessageBox.Show(PdnResources.GetString("Menu.ResultsExportedsuccessfully.Text"));
// }
// else
// {
// MessageBox.Show(PdnResources.GetString("Menu.Selecttheresultstoexport.Text"));
// return;
// }
// }
//}
//else
//{
// MessageBox.Show("没有获取到测量线高度数据"/*PdnResources.GetString("Menu.Noanalysineratereport.text")*/ + "!");
//}
//m_iMusMod = 7;//看剖面线
//ShowSectionLine();
}
///
/// 测量线高度图-导出图片
///
///
///
private void button7_Click(object sender, EventArgs e)
{
OpenFileImpl((Bitmap)this.pictureBox2.Image);
}
/////
///// 步长
/////
//string stepLength = "001";
///
/// 创建新图片
///
///
private void OpenFileImpl(Bitmap bitmap)
{
if (bitmap != null)
{
DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace();
dw.Document = Document.FromImageMat(Camera.Tools.ToMat(bitmap));
// TODO ZYH 这里的图像名称,需要走系统的配置
dw.fileText = this.Text + "-" + Startup.instance.step_length/*stepLength*/;
this.appWorkspace.ActiveDocumentWorkspace = dw;
//this.appWorkspace.ActiveDocumentWorkspace.PanelBottom.documentStrip.ShowPictures = false;
this.appWorkspace.ActiveDocumentWorkspace.Refresh();
Startup.instance.step_length += 1;
}
}
///
/// 测量线高度图-导出数据
///
///
///
private void button3_Click(object sender, EventArgs e)
{
if (this.m_adValue.Length > 0)
{
SaveFileDialog exe = new SaveFileDialog();
exe.Filter = "Execl files (*.xlsx)|*.xlsx";
exe.FilterIndex = 0;
exe.RestoreDirectory = true;
exe.Title = "Export Excel File";
exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
exe.FileName = this.Text + "-" + "测量线高度数据" + DateTime.Now.ToString("yyyyMMddHHmmss");
DialogResult dr = exe.ShowDialog();
if (dr == DialogResult.OK)
{
if (this.m_adValue.Length > 0)
{
List list = new List();
DataTable dt = new DataTable("tag");
dt.Columns.Add(new DataColumn("序号", typeof(string)));
dt.Columns.Add(new DataColumn("高度", typeof(string)));
int itemIndex = 0;
foreach (var item in this.m_adValue)
{
DataRow dataRow = dt.NewRow();
dataRow["序号"] = itemIndex.ToString();
dataRow["高度"] = item.ToString();
dt.Rows.Add(dataRow);
itemIndex++;
}
list.Add(dt);
///#########################################
Base.CommTool.OfficeFileHandleHelper.ExportDataToExcel(exe.FileName, list);
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Selecttheresultstoexport.Text"));
return;
}
}
}
else
{
MessageBox.Show("没有获取到测量线高度数据"/*PdnResources.GetString("Menu.Noanalysineratereport.text")*/ + "!");
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
RefreshColorAction();
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
RefreshColorAction();
}
private Panel panelC;
///
/// 调色板
///
private ColorsForm colorsFormGrid;
///
/// 颜色点击事件
///
///
///
private void panel1_Click(object sender, EventArgs e)
{
this.panelC = (Panel)sender;
this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
this.colorsFormGrid.ShowDialog();
}
///
/// PanelC的调色板颜色改变
///
///
///
private void gridColorChanged(object sender, EventArgs e)
{
Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
//更改背景色,触发事件
this.panelC.BackColor = color;
if (this.panelC == this.panel3 || this.panelC == this.panel4)
{
if (this.radioButton1.Checked)
RefreshColorAction();
}
else if (!this.radioButton1.Checked && (this.panelC == this.panel5 || this.panelC == this.panel6 || this.panelC == this.panel7 || this.panelC == this.panel8 || this.panelC == this.panel9))
RefreshColorAction();
//// 重置黑色背景
//if (this.panelC == this.panel5)
//{
// Gl.glClearColor(color.R, color.G, color.B, color.A);
// Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
// //重置模型观察矩阵
// Gl.glLoadIdentity();
//}
//关闭色板
this.colorsFormGrid.Close();
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
m_iMusDown = 0;
}
}
}