Added edges property to mesh,

Added a simple mesh smoother

git-svn-id: https://triangle.svn.codeplex.com/svn@70496 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
This commit is contained in:
SND\wo80_cp
2012-10-26 14:44:56 +00:00
parent 04c45ed41a
commit 4dccadc246
13 changed files with 439 additions and 12 deletions
+1
View File
@@ -134,6 +134,7 @@ namespace MeshExplorer
darkListBox1.Items.Add(new RandomPointsCircle());
darkListBox1.Items.Add(new StarInBox());
darkListBox1.Items.Add(new RingPolygon());
darkListBox1.Items.Add(new BoxWithHole());
darkListBox1.SelectedIndex = 0;
}
+1
View File
@@ -51,6 +51,7 @@
this.listLog.UseCompatibleStateImageBehavior = false;
this.listLog.View = System.Windows.Forms.View.Details;
this.listLog.DoubleClick += new System.EventHandler(this.listLog_DoubleClick);
this.listLog.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listLog_KeyDown);
//
// colMessage
//
+12
View File
@@ -74,6 +74,18 @@ namespace MeshExplorer
}
}
private void listLog_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (ModifierKeys == Keys.Control)
{
listLog.Items.Clear();
SimpleLog.Instance.Clear();
}
}
}
private void listLog_DoubleClick(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
+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>
+2 -4
View File
@@ -289,7 +289,7 @@ namespace MeshExplorer
// Update Statistic view
statisticView.HandleMeshChange(mesh);
// TODO: Should the Voronoi diagram automaticaly update?
// TODO: Should the Voronoi diagram automatically update?
menuViewVoronoi.Checked = false;
// Enable menu items
@@ -534,7 +534,7 @@ namespace MeshExplorer
statisticView.UpdateStatistic(mesh);
HandleMeshChange();
HandleMeshUpdate();
}
catch (Exception ex)
{
@@ -650,8 +650,6 @@ namespace MeshExplorer
voronoi = new Voronoi(mesh);
}
voronoi.Generate();
renderData.SetVoronoi(voronoi);
renderManager.SetData(renderData);
@@ -0,0 +1,163 @@
// -----------------------------------------------------------------------
// <copyright file="StarInBox.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TriangleNet.Geometry;
/// <summary>
/// Generates a star contained in a box.
/// </summary>
public class BoxWithHole : IGenerator
{
public string Name
{
get { return "Box with Hole"; }
}
public string Description
{
get { return ""; }
}
public int ParameterCount
{
get { return 3; }
}
public string ParameterDescription(int paramIndex)
{
if (paramIndex == 1)
{
return "Points on box sides:";
}
if (paramIndex == 2)
{
return "Points on hole:";
}
if (paramIndex == 3)
{
return "Radius:";
}
return "";
}
public string ParameterDescription(int paramIndex, double paramValue)
{
if (paramIndex == 1)
{
int numPoints = (int)((50.0 - 5.0) / 100.0 * paramValue + 5.0);
if (numPoints < 5)
{
numPoints = 5;
}
return numPoints.ToString();
}
if (paramIndex == 2)
{
int numPoints = (int)((100.0 - 10.0) / 100.0 * paramValue + 10.0);
numPoints = (numPoints / 5) * 5;
if (numPoints < 10)
{
numPoints = 10;
}
return numPoints.ToString();
}
if (paramIndex == 3)
{
int radius = (int)((20.0 - 5.0) / 100.0 * paramValue + 5.0);
return radius.ToString();
}
return "";
}
public InputGeometry Generate(double param1, double param2, double param3)
{
int numPoints = (int)((100.0 - 10.0) / 100.0 * param2 + 10.0);
InputGeometry input = new InputGeometry(numPoints + 4);
double x, y, step = 2 * Math.PI / numPoints;
double r = (int)((20.0 - 5.0) / 100.0 * param3 + 5.0);
// Generate circle
for (int i = 0; i < numPoints; i++)
{
x = r * Math.Cos(i * step);
y = r * Math.Sin(i * step);
input.AddPoint(x, y, 2);
input.AddSegment(i, (i + 1) % numPoints, 2);
}
numPoints = input.Count;
int numPointsB = (int)((50.0 - 5.0) / 100.0 * param1 + 5.0);
// Box sides are 100 units long
step = 100.0 / numPointsB;
// Left box boundary points
for (int i = 0; i < numPointsB; i++)
{
input.AddPoint(-50, -50 + i * step, 1);
}
// Top box boundary points
for (int i = 0; i < numPointsB; i++)
{
input.AddPoint(-50 + i * step, 50, 1);
}
// Right box boundary points
for (int i = 0; i < numPointsB; i++)
{
input.AddPoint(50, 50 - i * step, 1);
}
// Bottom box boundary points
for (int i = 0; i < numPointsB; i++)
{
input.AddPoint(50 - i * step, -50, 1);
}
// Add box segments
for (int i = numPoints; i < input.Count - 1; i++)
{
input.AddSegment(i, i + 1, 1);
}
// Add last segments which closes the box
input.AddSegment(input.Count - 1, numPoints, 1);
// Add hole
input.AddHole(0, 0);
return input;
}
public override string ToString()
{
return this.Name;
}
}
}
@@ -96,6 +96,7 @@
<Compile Include="FormMain.Designer.cs">
<DependentUpon>FormMain.cs</DependentUpon>
</Compile>
<Compile Include="Generators\BoxWithHole.cs" />
<Compile Include="Generators\IGenerator.cs" />
<Compile Include="Generators\RandomPoints.cs" />
<Compile Include="Generators\RandomPointsCircle.cs" />
@@ -138,6 +139,9 @@
<EmbeddedResource Include="FormGenerator.resx">
<DependentUpon>FormGenerator.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormLog.resx">
<DependentUpon>FormLog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormMain.resx">
<DependentUpon>FormMain.cs</DependentUpon>
</EmbeddedResource>
+17 -2
View File
@@ -129,6 +129,21 @@ namespace TriangleNet
get { return this.subsegs.Values; }
}
/// <summary>
/// Gets the mesh edges.
/// </summary>
public IEnumerable<Edge> Edges
{
get
{
EdgeEnumerator e = new EdgeEnumerator(this);
while (e.MoveNext())
{
yield return e.Current;
}
}
}
/// <summary>
/// Gets the number of input vertices.
/// </summary>
@@ -457,8 +472,8 @@ namespace TriangleNet
{
numbering = NodeNumbering.None;
//ISmoother smoother = new CvdSmoother(this);
//smoother.Smooth();
ISmoother smoother = new SimpleSmoother(this);
smoother.Smooth();
}
/// <summary>
@@ -0,0 +1,98 @@
// -----------------------------------------------------------------------
// <copyright file="SimpleSmoother.cs" company="">
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace TriangleNet.Smoothing
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TriangleNet.Geometry;
using TriangleNet.Tools;
/// <summary>
/// Simple mesh smoother implementation.
/// </summary>
public class SimpleSmoother : ISmoother
{
Mesh mesh;
public SimpleSmoother(Mesh mesh)
{
this.mesh = mesh;
}
public void Smooth()
{
// Take a few smoothing rounds.
for (int i = 0; i < 5; i++)
{
Step();
// Actually, we only want to rebuild, if mesh is no longer
// Delaunay. Flipping edges could be the right choice instead
// of re-triangulating...
var geometry = Rebuild();
mesh.SetOption(Options.Quality, false);
mesh.Triangulate(geometry);
}
}
/// <summary>
/// Smooth all free nodes.
/// </summary>
private void Step()
{
BoundedVoronoi voronoi = new BoundedVoronoi(this.mesh, false);
var cells = voronoi.Regions;
double x, y;
int n;
foreach (var cell in cells)
{
n = 0;
x = y = 0.0;
foreach (var p in cell.Vertices)
{
n++;
x += p.x;
y += p.y;
}
cell.Generator.x = x / n;
cell.Generator.y = y / n;
}
}
/// <summary>
/// Rebuild the input geometry.
/// </summary>
private InputGeometry Rebuild()
{
InputGeometry geometry = new InputGeometry(mesh.vertices.Count);
foreach (var vertex in mesh.vertices.Values)
{
geometry.AddPoint(vertex.x, vertex.y, vertex.mark);
}
foreach (var segment in mesh.subsegs.Values)
{
geometry.AddSegment(segment.P0, segment.P1, segment.Boundary);
}
foreach (var hole in mesh.holes)
{
geometry.AddHole(hole.x, hole.y);
}
return geometry;
}
}
}
+16 -2
View File
@@ -31,13 +31,27 @@ namespace TriangleNet.Tools
Dictionary<int, Segment> subsegMap;
bool includeBoundary = true;
/// <summary>
/// Initializes a new instance of the <see cref="BoundedVoronoi" /> class.
/// </summary>
/// <param name="mesh">Mesh instance.</param>
public BoundedVoronoi(Mesh mesh)
: this(mesh, true)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BoundedVoronoi" /> class.
/// </summary>
/// <param name="mesh">Mesh instance.</param>
public BoundedVoronoi(Mesh mesh, bool includeBoundary)
{
this.mesh = mesh;
this.includeBoundary = includeBoundary;
Generate();
}
/// <summary>
@@ -59,7 +73,7 @@ namespace TriangleNet.Tools
/// <summary>
/// Computes the bounded voronoi diagram.
/// </summary>
public void Generate()
private void Generate()
{
mesh.Renumber();
mesh.MakeVertexMap();
@@ -79,7 +93,7 @@ namespace TriangleNet.Tools
{
ConstructBvdCell(v);
}
else
else if (includeBoundary)
{
ConstructBoundaryBvdCell(v);
}
+1 -3
View File
@@ -20,10 +20,8 @@ namespace TriangleNet.Tools
Point[] Points { get; }
/// <summary>
/// Gets the directions for infinite Voronoi edges.
/// Gets the list of Voronoi regions.
/// </summary>
List<VoronoiRegion> Regions { get; }
void Generate();
}
}
+3 -1
View File
@@ -34,6 +34,8 @@ namespace TriangleNet.Tools
public Voronoi(Mesh mesh)
{
this.mesh = mesh;
Generate();
}
/// <summary>
@@ -63,7 +65,7 @@ namespace TriangleNet.Tools
/// triangles, and the Voronoi edges are listed by traversing the Delaunay
/// edges.
///</remarks>
public void Generate()
private void Generate()
{
mesh.Renumber();
mesh.MakeVertexMap();
+1
View File
@@ -81,6 +81,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sampler.cs" />
<Compile Include="Smoothing\ISmoother.cs" />
<Compile Include="Smoothing\SimpleSmoother.cs" />
<Compile Include="Tools\BoundedVoronoi.cs" />
<Compile Include="Tools\CuthillMcKee.cs" />
<Compile Include="Tools\IVoronoi.cs" />