dantest patch file

Mar 9, 2016 at 10:54 AM
        TriangleNet.Geometry.InputGeometry geometry = TriangleNet.IO.FileReader.ReadPolyFile("..\\..\\..\\Data\\superior.poly");

In this line instead of getting only one poly file i need to choose multiple choice (selection of different poly file)

I tried with ofd.filename no error but it throws exception
    private bool Open(string p)
    {
        throw new NotImplementedException();
    }

can you help me out please.



code:
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;
using TriangleNet;
using DanTest.Properties;

namespace DanTest
{
public partial class Form1 : Form
{
    Settings settings;
    RectangleF boundary;
    TriangleNet.Tools.QuadTree quadTree;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
     //   oldClientSize = this.ClientSize;

        settings = new Settings();

      //  renderManager = new RenderManager();
      //    renderManager.CreateDefaultControl();
    }
    private void button1_Click(object sender, EventArgs e)
    {

        List<PointF> lstPoints;
        TriangleNet.Mesh mesh;
        Random random = new Random();

        TriangleNet.Geometry.InputGeometry geometry = TriangleNet.IO.FileReader.ReadPolyFile("..\\..\\..\\Data\\superior.poly");

        // add random z values so the interpolation works
        foreach (TriangleNet.Geometry.Point vertex in geometry.Points)
            vertex.Z = random.Next(100);

        mesh = new TriangleNet.Mesh();

        mesh.Triangulate(geometry);

        // get geometry boundary so we can do conversions between geometry space and picturebox1 space
        boundary = new RectangleF((float)geometry.Bounds.Xmin, (float)geometry.Bounds.Ymin, (float)geometry.Bounds.Width, (float)geometry.Bounds.Height);

        pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        // draw geometry on bitmap for picturebox1 to display
        using (Graphics g = Graphics.FromImage((Bitmap)pictureBox1.Image))
        {
            foreach (TriangleNet.Data.Triangle triangle in mesh.Triangles)
            {
                lstPoints = new List<PointF>();

                foreach (TriangleNet.Data.Vertex vertex in triangle.Vertices)
                    lstPoints.Add(PointFromVertex(vertex));

                g.FillPolygon(Brushes.Brown, lstPoints.ToArray());
                g.DrawPolygon(Pens.Red, lstPoints.ToArray());
            }
        }

        quadTree = new TriangleNet.Tools.QuadTree(mesh.Triangles);
    }

    // convert vertex to picturebox space
    private PointF PointFromVertex(TriangleNet.Data.Vertex vertex)
    {
        double x, y;

        x = vertex.X;
        y = vertex.Y;

        x = ((x - boundary.Left) / boundary.Width) * pictureBox1.Width;
        y = ((boundary.Bottom - y) / boundary.Height) * pictureBox1.Height;

        return new PointF((float)x, (float)y);
    }

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
        double dblZ = double.NaN;
        double x, y;
        TriangleNet.Data.Triangle triangle;

        if (quadTree == null)
            return;

        // convert picturebox1 mouse point to geometry space
        x = ((float)e.X / (float)pictureBox1.Width) * boundary.Width + boundary.Left;
        y = -1f * (((float)e.Y / (float)pictureBox1.Height) * boundary.Height - boundary.Bottom);

        // erase previous highlights
        pictureBox1.Invalidate();
        pictureBox1.Refresh();

        triangle = (TriangleNet.Data.Triangle)quadTree.Query(x, y);

        if (triangle != null)
        {
            dblZ = triangle.ComputeZ(x, y);

            // converts triangle points to picturebox1 space so we can highlight the current triangle
            PointF[] points = new PointF[3];
            for (int i = 0; i < triangle.Vertices.Length; i++)
                points[i] = PointFromVertex(triangle.Vertices[i]);

            Graphics g = pictureBox1.CreateGraphics();

            g.FillPolygon(Brushes.Cyan, points);
        }

        lblLocation.Text = "X:" + x.ToString("0.000") + " Y: " + y.ToString("0.000") + " Z: " + dblZ.ToString("0.0");
    }

    private void button2_Click(object sender, EventArgs e)
    {
        String Chosen_File ="";

        OpenFileDialog ofd = new OpenFileDialog();

        ofd.Filter = "PNG Images|*.png|JPEG Images|*.jpeg" ;
        ofd.FilterIndex = settings.OfdFilterIndex;
        ofd.InitialDirectory = settings.OfdDirectory;
        ofd.FileName = "";


        if (ofd.ShowDialog() == DialogResult.OK)
        {
            if (Open(ofd.FileName))
            {
                // Update folder settings
                settings.OfdFilterIndex = ofd.FilterIndex;
                settings.OfdDirectory = System.IO.Path.GetDirectoryName(ofd.FileName);
                Chosen_File = ofd.FileName;
                pictureBox1.Image = Image.FromFile(Chosen_File);
            }
        }





    }

    private bool Open(string p)
    {
        throw new NotImplementedException();
    }
}
}
Coordinator
Mar 10, 2016 at 5:50 PM
So, basically you are asking me how to open a file. This has nothing to do with Triangle.NET and nothing to do with "dantest patch file".
void OpenWithDialog()
{
    var ofd = new OpenFileDialog();

    ofd.Filter = "Triangle polygon file|*.poly";

    if (ofd.ShowDialog() == DialogResult.OK)
    {
        OpenPolyFile(ofd.FileName);
    }
}

void OpenPolyFile(string file)
{
    var geometry = TriangleNet.IO.FileReader.ReadPolyFile(file);
    // ...
}
Mar 11, 2016 at 4:18 AM
  private void button1_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Filter = "Triangle polygon file|*.poly";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                OpenPolyFile(ofd.FileName);

                var geometry = TriangleNet.IO.FileReader.ReadPolyFile(file);
            
                boundary = new RectangleF((float)geometry.Bounds.Xmin, (float)geometry.Bounds.Ymin, (float)geometry.Bounds.Width, (float)geometry.Bounds.Height);
                pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            }
Argument null exception was handeled is the runtime error iam getting
and then
g.FillPolygon(Brushes.Brown, lstPoints.ToArray());

in this line of "fillpolygon" code instead of filling single color i need to use multicolor .

In dantest with that z value can we plot lines connecting those z pts.

can you help me out to with the change in code of dantest please. i am not moving in this concept further .
Coordinator
Mar 11, 2016 at 12:01 PM
Edited Mar 11, 2016 at 12:02 PM
  1. Why did you choose to use Dan's patch as a basis for your work. Triangle.NET comes with a test application (Mesh Explorer) that shows how to work with the library and how to render meshes properly.
  2. You should use the latest source code (unreleased Beta 4).
  3. You seem to be missing some basic understanding of C# and graphics programming with .NET.
  4. You are trying my patience.
Apr 4, 2016 at 11:50 AM
Hi can you help me out to read the geometry of a poly file . i.e in a button click event iam trying to get the geometries of poly file which is selected . i was able to get to mesh of the poly file .
Coordinator
Apr 4, 2016 at 2:48 PM
Come on, that's exactly what I wrote in my first answer above. Just put the OpenWithDialog method in the event handler:
private void button1_Click(object sender, EventArgs e)
{
    OpenWithDialog();
}
Apr 5, 2016 at 5:51 AM
I know , i got it when you first explained to me, but now i dont need this. what i need is that only points to be visible like boundary and the vertex points of superior or any poly file. In triangle.net source code when we click open file which shows a message box that import mesh or only geometry(yes or no), where when we click no button it just plot the points of that poly file.I went through the code but i dont get it
Apr 5, 2016 at 9:59 AM
How to import only the geometry of the poly file .