Skip to content

Commit

Permalink
add triangles constructor to DijkstraGraphDistance, option to use hig…
Browse files Browse the repository at this point in the history
…her-res plane mesh in poly triangulator
  • Loading branch information
rms80 committed Apr 26, 2018
1 parent 36ae0fb commit ecfcc2e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
20 changes: 20 additions & 0 deletions core/DijkstraGraphDistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ public static DijkstraGraphDistance MeshVertices(DMesh3 mesh, bool bSparse = fal



/// <summary>
/// shortcut to construct graph for mesh triangles
/// </summary>
public static DijkstraGraphDistance MeshTriangles(DMesh3 mesh, bool bSparse = false)
{
Func<int, int, float> tri_dist_f = (a, b) => {
return (float)mesh.GetTriCentroid(a).Distance(mesh.GetTriCentroid(b));
};

return (bSparse) ?
new DijkstraGraphDistance(mesh.MaxTriangleID, true,
(id) => { return mesh.IsTriangle(id); }, tri_dist_f,
mesh.TriTrianglesItr, null)
: new DijkstraGraphDistance(mesh.MaxTriangleID, false,
(id) => { return true; }, tri_dist_f,
mesh.TriTrianglesItr, null);
}



/// <summary>
/// reset internal data structures/etc
/// </summary>
Expand Down
21 changes: 12 additions & 9 deletions mesh_generators/TriangulatedPolygonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TriangulatedPolygonGenerator : MeshGenerator

public TrivialRectGenerator.UVModes UVMode = TrivialRectGenerator.UVModes.FullUVSquare;

public int Subdivisions = 1;

override public MeshGenerator Generate()
{
Expand Down Expand Up @@ -53,15 +54,17 @@ public DMesh3 ComputeResult(out MeshInsertPolygon insertion)
double padding = 0.1 * bounds.DiagonalLength;
bounds.Expand(padding);

TrivialRectGenerator rectgen = new TrivialRectGenerator();
rectgen.Width = (float)bounds.Width;
rectgen.Height = (float)bounds.Height;
rectgen.IndicesMap = new Index2i(1, 2);
rectgen.UVMode = UVMode;
rectgen.Clockwise = true; // MeshPolygonInserter assumes mesh faces are CW? (except code says CCW...)
rectgen.Generate();
DMesh3 base_mesh = new DMesh3();
rectgen.MakeMesh(base_mesh);
TrivialRectGenerator rectgen = (Subdivisions == 1) ?
new TrivialRectGenerator() : new GriddedRectGenerator() { EdgeVertices = Subdivisions };

rectgen.Width = (float)bounds.Width;
rectgen.Height = (float)bounds.Height;
rectgen.IndicesMap = new Index2i(1, 2);
rectgen.UVMode = UVMode;
rectgen.Clockwise = true; // MeshPolygonInserter assumes mesh faces are CW? (except code says CCW...)
rectgen.Generate();
DMesh3 base_mesh = new DMesh3();
rectgen.MakeMesh(base_mesh);

GeneralPolygon2d shiftPolygon = new GeneralPolygon2d(Polygon);
Vector2d shift = bounds.Center;
Expand Down

0 comments on commit ecfcc2e

Please sign in to comment.