在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → 等值线生成源码(绘制)

等值线生成源码(绘制)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:1.40M
  • 下载次数:28
  • 浏览次数:312
  • 发布时间:2019-05-22
  • 实例类别:C#语言基础
  • 发 布 人:yyzxx
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 源码 等值线

实例介绍

【实例简介】

【实例截图】

from clipboard

【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MouStudio {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        C_Trianglate trianglate = null;
        C_Trianglate2 trianglate2 = null;

        double dMax_X = -999999999;
        double dMax_Y = -999999999;
        double dMin_X = 9999999999;
        double dMin_Y = 9999999999;
        double dMax_Z = -9999999999;
        double dMin_Z = 9999999999;

        
        private void pictureBox1_Move(object sender, EventArgs e) {

        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e) {
            Graphics g = e.Graphics;
            if (trianglate != null)
            {                
                if (conTrace != null && conTrace.list_ContourLine.Count > 0)
                {
                    //------- 等值线填充 -------   
                    if (isFill)
                        conTrace.CTrace_Fill(g);

                    //------- 边标记 -------
                    if(isMarkEdge)
                    conTrace.CTrace_MarkEdge(g);

                    //------- 三角形标记 -------
                    if(isMarkTriangle)
                    conTrace.CTrace_MarkTriangle(g);

                    //------- 等值线绘制 -------
                    if (isDrawConLine)
                    {
                        #region "Draw ConLine"
                        PointF p1 = new PointF(0, 0);
                        PointF p2 = new PointF(0, 0);
                        Contour.Cmou_Point conP1 = new MouStudio.Contour.Cmou_Point();
                        Contour.Cmou_Point conP2 = new MouStudio.Contour.Cmou_Point();
                        foreach (Contour.Cmou_ContourLine conLine in conTrace.list_ContourLine)
                        {
                            //Contour.Cmou_ContourLine conLine = conTrace.list_ContourLine[0];
                            if (conLine.conType == MouStudio.Contour.ContourLineType.Opened)
                            {
                                for (int iP = 0; iP < conLine.list_Point.Count; iP  )
                                {
                                    if (iP == 0)
                                    {
                                        conP1 = conLine.list_Point[iP];
                                        p1.X = (float)conP1.X;
                                        p1.Y = (float)conP1.Y;
                                    }
                                    else
                                    {
                                        conP2 = conLine.list_Point[iP];
                                        p2.X = (float)conP2.X;
                                        p2.Y = (float)conP2.Y;
                                        g.DrawLine(Pens.Black, p1, p2);
                                        p1 = p2;
                                    }
                                }
                            }
                            else
                            {
                                for (int iP = 0; iP < conLine.list_Point.Count; iP  )
                                {
                                    if (iP == 0)
                                    {
                                        conP1 = conLine.list_Point[iP];
                                        p1.X = (float)conP1.X;
                                        p1.Y = (float)conP1.Y;
                                    }
                                    else
                                    {
                                        conP2 = conLine.list_Point[iP];
                                        p2.X = (float)conP2.X;
                                        p2.Y = (float)conP2.Y;
                                        g.DrawLine(Pens.Black, p1, p2);
                                        p1 = p2;
                                    }
                                }

                                conP1 = conLine.list_Point[0];
                                p1.X = (float)conP1.X;
                                p1.Y = (float)conP1.Y;
                                g.DrawLine(Pens.Black, p2, p1);
                            }
                        }
                        #endregion
                    }   
          
                    //------- 标注等值线 -------
                    conTrace.CTrace_MarkContourLine(g);
                }

                //------- 绘制三角形 -------
                if(isDrawTriangle)
                trianglate.drawtriangle(g);

            }
            
        }

        C_ContourTrace conTrace = null;
        private void btn_ConTrace_Click(object sender, EventArgs e)
        {
            conTrace = new C_ContourTrace(trianglate);
            conTrace.d_Max = dMax_Z;
            conTrace.d_Min = dMin_Z;
            conTrace.CTrace_ContourLineTrace();
            pictureBox1.Invalidate();
        }

        bool isDrawConLine = true;
        private void btn_DrawContourLine_Click(object sender, EventArgs e)
        {

            if (isDrawConLine)
            {
                isDrawConLine = false;
            }
            else
            {
                isDrawConLine = true;
            }
            pictureBox1.Invalidate();
        }

        bool isFill = false;
        private void btn_Test_Click(object sender, EventArgs e)
        {
            if (isFill)
            {
                isFill = false;
            } 
            else
            {
                isFill = true;
            }
            pictureBox1.Invalidate();
        }

        bool isMarkEdge = false;
        private void btn_MarkEdge_Click(object sender, EventArgs e)
        {
            if (isMarkEdge)
            {
                isMarkEdge = false;
            }
            else
            {
                isMarkEdge = true;
            }
            pictureBox1.Invalidate();
        }

        bool isMarkTriangle = false;
        private void btn_MarkTriangle_Click(object sender, EventArgs e)
        {
            if (isMarkTriangle)
            {
                isMarkTriangle = false;
            }
            else
            {
                isMarkTriangle = true;
            }
            pictureBox1.Invalidate();
        }

        bool isDrawTriangle = false;
        private void btn_DrawTriangle_Click(object sender, EventArgs e)
        {
            if (isDrawTriangle)
            {
                isDrawTriangle = false;
            }
            else
            {
                isDrawTriangle = true;
            }
            pictureBox1.Invalidate();
        }

        string str_FilePath = null;
        private void btn_OpenFile_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog open = new OpenFileDialog())
            {
                if (open.ShowDialog() == DialogResult.OK)
                {
                    str_FilePath = open.FileName;
                    ReadReguXFile();

                    btn_ConTrace_Click(sender, e);
                }
            }
        }

        private void ReadReguXFile()
        {
            System.IO.StreamReader sr_ScatterData = new System.IO.StreamReader(str_FilePath);
            sr_ScatterData.ReadLine();
            string temp_str = sr_ScatterData.ReadLine();
            temp_str.TrimStart();
            temp_str.TrimEnd();
            string[] tempData_str = temp_str.Split(' ').ToArray();
            int iNum_Point = int.Parse(tempData_str[1]);
            //iNum_Point  ;
            double[] dData_X = new double[iNum_Point];
            double[] dData_Y = new double[iNum_Point];
            double[] dData_Z = new double[iNum_Point];
            PointF[] ps = new PointF[iNum_Point];
            int iCount = 3;

            int i = 0;
            while (!sr_ScatterData.EndOfStream)
            {
                if (iCount == 3)
                {
                    temp_str = sr_ScatterData.ReadLine();
                    temp_str.TrimStart();
                    temp_str.TrimEnd();
                    tempData_str = temp_str.Split(' ').ToArray();
                    dData_X[i] = double.Parse(tempData_str[1]);
                    dData_Y[i] = double.Parse(tempData_str[2]);
                    dData_Z[i] = double.Parse(tempData_str[3]);
                    if (dMax_X < dData_X[i]) dMax_X = dData_X[i];
                    if (dMin_X > dData_X[i]) dMin_X = dData_X[i];
                    if (dMax_Y < dData_Y[i]) dMax_Y = dData_Y[i];
                    if (dMin_Y > dData_Y[i]) dMin_Y = dData_Y[i];
                    if (dMax_Z < dData_Z[i]) dMax_Z = dData_Z[i];
                    if (dMin_Z > dData_Z[i]) dMin_Z = dData_Z[i];
                    i  ;
                    iCount = 0;
                }
                else
                {
                    sr_ScatterData.ReadLine();
                    iCount  ;
                }
            }
            sr_ScatterData.Close();

            double dSx = (dMax_X - dMin_X) / (pictureBox1.Width - 3);
            double dSy = (dMax_Y - dMin_Y) / (pictureBox1.Height - 3);
            for (i = 0; i < iNum_Point; i  )
            {
                dData_X[i] = Convert.ToSingle((dData_X[i] - dMin_X) / dSx);
                dData_Y[i] = Convert.ToSingle((dData_Y[i] - dMin_Y) / dSy);
                //ps[i].X = (float)dData_X[i];
                //ps[i].Y = (float)dData_Y[i];
            }

            if (iNum_Point > 3)
            {
                trianglate = new C_Trianglate(dData_X, dData_Y, dData_Z);
                int iNum_Tri = trianglate.Triangulate();
                //trianglate2 = new C_Trianglate2(ps);
                //trianglate2.GeneTIN(pictureBox1.CreateGraphics());
                pictureBox1.Invalidate();
            }
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            if (str_FilePath != null)
            {
                ReadReguXFile();
                btn_ConTrace_Click(sender, e);
            }
        }
    }
}

标签: 源码 等值线

实例下载地址

等值线生成源码(绘制)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警