Planar Subdivision in CSharp: Difference between revisions

From EMGU
Jump to navigation Jump to search
mNo edit summary
Inuxejiq (talk | contribs)
No edit summary
Line 1: Line 1:
<font color=green>'''This project is part of the Emgu.CV.Example solution'''</font>
----
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
----
=[http://etizupo.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
----
=[http://etizupo.co.cc CLICK HERE]=
----
</div>
&lt;font color=green>'''This project is part of the Emgu.CV.Example solution'''&lt;/font>
== System Requirement ==
== System Requirement ==
{| style="text-align:center" border="1px" cellpadding="10" cellspacing="0"
{| style="text-align:center" border="1px" cellpadding="10" cellspacing="0"
Line 10: Line 18:


== Source Code ==
== Source Code ==
<source lang="csharp">
&lt;source lang="csharp">
using System;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
Line 23: Line 31:
   static class Program
   static class Program
   {
   {
       /// <summary>
       /// &lt;summary>
       /// The main entry point for the application.
       /// The main entry point for the application.
       /// </summary>
       /// &lt;/summary>
       [STAThread]
       [STAThread]
       static void Main()
       static void Main()
Line 40: Line 48:
         #region create random points in the range of [0, maxValue]
         #region create random points in the range of [0, maxValue]
         PointF[] pts = new PointF[20];
         PointF[] pts = new PointF[20];
         Random r = new Random((int)(DateTime.Now.Ticks & 0x0000ffff));
         Random r = new Random((int)(DateTime.Now.Ticks &amp; 0x0000ffff));
         for (int i = 0; i < pts.Length; i++)
         for (int i = 0; i &lt; pts.Length; i++)
             pts[i] = new PointF((float)r.NextDouble() * maxValue, (float)r.NextDouble() * maxValue);
             pts[i] = new PointF((float)r.NextDouble() * maxValue, (float)r.NextDouble() * maxValue);
         #endregion
         #endregion
Line 57: Line 65:


         //create an image for display purpose
         //create an image for display purpose
         Image<Bgr, Byte> img = new Image<Bgr, byte>((int)maxValue, (int) maxValue);
         Image&lt;Bgr, Byte> img = new Image&lt;Bgr, byte>((int)maxValue, (int) maxValue);


         //Draw the voronoi Facets
         //Draw the voronoi Facets
         foreach (VoronoiFacet facet in voronoiFacets)
         foreach (VoronoiFacet facet in voronoiFacets)
         {
         {
             Point[] points = Array.ConvertAll<PointF, Point>(facet.Vertices, Point.Round);
             Point[] points = Array.ConvertAll&lt;PointF, Point>(facet.Vertices, Point.Round);


             //Draw the facet in color
             //Draw the facet in color
Line 89: Line 97:
}
}


</source>
&lt;/source>


== Result ==
== Result ==
[[image:PlanarSubdivisionExample.png]]
[[image:PlanarSubdivisionExample.png]]

Revision as of 03:29, 24 November 2010



This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page


CLICK HERE


<font color=green>This project is part of the Emgu.CV.Example solution</font>

System Requirement

Component Requirement Detail
Emgu CV Version 1.5
Operation System Cross Platform

Source Code

<source lang="csharp"> using System; using System.Collections.Generic; using System.Windows.Forms; using System.Drawing; using Emgu.CV; using Emgu.CV.UI; using Emgu.CV.Structure;

namespace PlanarSubdivisionExample {

  static class Program
  {
     /// <summary>
     /// The main entry point for the application.
     /// </summary>
     [STAThread]
     static void Main()
     {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Run();
     }
     static void Run()
     {
        float maxValue = 600;
        #region create random points in the range of [0, maxValue]
        PointF[] pts = new PointF[20];
        Random r = new Random((int)(DateTime.Now.Ticks & 0x0000ffff));
        for (int i = 0; i < pts.Length; i++)
           pts[i] = new PointF((float)r.NextDouble() * maxValue, (float)r.NextDouble() * maxValue);
        #endregion
        Triangle2DF[] delaunayTriangles;
        VoronoiFacet[] voronoiFacets;
        using (PlanarSubdivision subdivision = new PlanarSubdivision(pts))
        {
           //Obtain the delaunay's triangulation from the set of points;
           delaunayTriangles = subdivision.GetDelaunayTriangles();
           //Obtain the voronoi facets from the set of points
           voronoiFacets = subdivision.GetVoronoiFacets();
        }
        //create an image for display purpose
        Image<Bgr, Byte> img = new Image<Bgr, byte>((int)maxValue, (int) maxValue);
        //Draw the voronoi Facets
        foreach (VoronoiFacet facet in voronoiFacets)
        {
           Point[] points = Array.ConvertAll<PointF, Point>(facet.Vertices, Point.Round);
           //Draw the facet in color
           img.FillConvexPoly(
               points,
               new Bgr(r.NextDouble() * 120, r.NextDouble() * 120, r.NextDouble() * 120)
               );
           //highlight the edge of the facet in black
           img.DrawPolyline(points, true, new Bgr(Color.Black), 2);
           //draw the points associated with each facet in red
           img.Draw(new CircleF(facet.Point, 5.0f), new Bgr(Color.Red), 0);
        }
        //Draw the Delaunay triangulation
        foreach (Triangle2DF triangles in delaunayTriangles)
        {
           img.Draw(triangles, new Bgr(Color.White), 1);
        }
        //display the image
        ImageViewer.Show(img, "Plannar Subdivision");
     }
  }

}

</source>

Result