1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
public class GeometryGroupAndPoint3D
{
public GeometryGroup geometryGroup { get; set; }
public Point3D[] point3D { get; set; }
public Int32Collection indicies { get; set; }
public GeometryGroupAndPoint3D(GeometryGroup geometryGroup, Point3D[] point3D, Int32Collection indicies)
{
this.geometryGroup = geometryGroup;
this.point3D = point3D;
this.indicies = indicies;
}
}
public static Geometry Create2DGeometryFromModel3D(Model3D model3D, Matrix3D transform2D)
{
Int32Collection indicies = mesh.TriangleIndices;
// Combined all triangle into one geometry (union)
GeometryGroup g1 = new GeometryGroup();
//Lancement du calcul parallèle
//i : paramètre qui s'incrémente, loop: paramètre de boucle, subtotal : variable locale du type GeometryGroupAndPoint3D
Parallel.For<GeometryGroupAndPoint3D>(0, (int)indicies.Count / 3,
() => new GeometryGroupAndPoint3D(g1, points, indicies)//Initialisation de la variable locale, effectuée au tout début
, (i, loop, subtotal) =>
{
var g2 = new StreamGeometry();
//Tracé des points
using (StreamGeometryContext ctx = g2.Open())
{
ctx.BeginFigure(new Point(subtotal.point3D[subtotal.indicies[i * 3]].X, subtotal.point3D[subtotal.indicies[i * 3]].Y), true, true);
ctx.LineTo(new Point(subtotal.point3D[subtotal.indicies[i * 3 + 1]].X, subtotal.point3D[subtotal.indicies[i * 3 + 1]].Y), true, false);
ctx.LineTo(new Point(subtotal.point3D[subtotal.indicies[i * 3 + 2]].X, subtotal.point3D[subtotal.indicies[i * 3 + 2]].Y), true, false);
}
g2.Freeze();
//Ajout du tracé à la collection
subtotal.geometryGroup.Children.Add((Geometry)g2);
return subtotal;
},
(x) => g1.Children.Add((Geometry) x.geometryGroup) //Action effectuée au sortir de la boucle
);
g1.Freeze();
return (Geometry)g1;
} |
Partager