Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs @ 15646

Last change on this file since 15646 was 15646, checked in by rhanghof, 6 years ago

#2817:

  • Dealing with stackable items
  • Enhanced the Evaluator
  • Added parameters some paramters to the packing items
File size: 22.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Windows;
26using System.Windows.Controls;
27using System.Windows.Input;
28using System.Windows.Media;
29using System.Windows.Media.Media3D;
30using HeuristicLab.Problems.BinPacking3D;
31using HeuristicLab.Collections;
32
33namespace HeuristicLab.Problems.BinPacking.Views {
34  public partial class Container3DView : UserControl {
35    private static readonly Color[] colors = new[] {
36      Color.FromRgb(0x40, 0x6A, 0xB7),
37      Color.FromRgb(0xB1, 0x6D, 0x01),
38      Color.FromRgb(0x4E, 0x8A, 0x06),
39      Color.FromRgb(0x75, 0x50, 0x7B),
40      Color.FromRgb(0x72, 0x9F, 0xCF),
41      Color.FromRgb(0xA4, 0x00, 0x00),
42      Color.FromRgb(0xAD, 0x7F, 0xA8),
43      Color.FromRgb(0x29, 0x50, 0xCF),
44      Color.FromRgb(0x90, 0xB0, 0x60),
45      Color.FromRgb(0xF5, 0x89, 0x30),
46      Color.FromRgb(0x55, 0x57, 0x53),
47      Color.FromRgb(0xEF, 0x59, 0x59),
48      Color.FromRgb(0xED, 0xD4, 0x30),
49      Color.FromRgb(0x63, 0xC2, 0x16),
50    };
51
52    private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA);
53    private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA);
54    private static readonly Color residualSpaceColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0x00);
55
56    private Point startPos;
57    private bool mouseDown = false;
58    private double startAngleX;
59    private double startAngleY;
60    private int selectedItemKey;
61    private int selectedExtremePointIndex;
62    private bool showExtremePoints;
63    private bool showResidualSpaces;
64
65    private BinPacking<BinPacking3D.PackingPosition, PackingShape, PackingItem> packing;
66    public BinPacking<BinPacking3D.PackingPosition, PackingShape, PackingItem> Packing {
67      get { return packing; }
68      set {
69        if (packing != value) {
70          this.packing = value;
71          ClearSelection(); // also updates visualization
72        }
73      }
74    }
75
76    private Dictionary<int, DiffuseMaterial> materials;
77
78    public ObservableDictionary<BinPacking3D.PackingPosition, IList<ResidualSpace>> ResidualSpaces { get; set; }
79    public ObservableCollection<BinPacking3D.PackingPosition> ExtremePoints { get; set; }
80
81    public Container3DView() {
82      InitializeComponent();
83      camMain.Position = new Point3D(0.5, 3, 3); // for design time we use a different camera position
84      materials = new Dictionary<int, DiffuseMaterial>();
85      ResidualSpaces = new ObservableDictionary<BinPacking3D.PackingPosition, IList<ResidualSpace>>();
86      ExtremePoints = new ObservableCollection<BinPacking3D.PackingPosition>();
87      selectedExtremePointIndex = -1;
88      Clear();
89    }
90
91
92    protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) {
93      base.OnRenderSizeChanged(sizeInfo);
94      var s = Math.Min(sizeInfo.NewSize.Height, sizeInfo.NewSize.Width);
95      var mySize = new Size(s, s);
96      viewport3D1.RenderSize = mySize;
97    }
98
99    /// <summary>
100    /// Selects another extreme point
101    /// </summary>
102    /// <param name="index"></param>
103    public void SelectExtremePoint(int index) {
104      selectedExtremePointIndex = index;
105      UpdateVisualization();
106    }
107
108    public void SelectItem(int itemKey) {
109      // selection of an item should make all other items semi-transparent
110      selectedItemKey = itemKey;
111      UpdateVisualization();
112    }
113
114    public void ClearSelection() {
115      // remove all transparency
116      selectedItemKey = -1;
117      selectedExtremePointIndex = -1;
118      UpdateVisualization();
119    }
120
121    private void UpdateVisualization() {
122      Clear();
123      if (packing == null)
124        return; // nothing to display
125
126      var modelGroup = (Model3DGroup)MyModel.Content;
127      var hiddenMaterial = new DiffuseMaterial(new SolidColorBrush(hiddenColor));
128
129      if (selectedItemKey >= 0) {
130        var selectedItem = packing.Items.Single(x => selectedItemKey == x.Key);
131        var selectedPos = packing.Positions[selectedItem.Key];
132
133        var colorIdx = selectedItem.Value.Material;
134        while (colorIdx < 0)
135          colorIdx += colors.Length;
136        colorIdx = colorIdx % colors.Length;
137        var color = colors[colorIdx];
138        var material = new DiffuseMaterial { Brush = new SolidColorBrush(color) };
139        materials[selectedItem.Value.Material] = material;
140
141        var selectedModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = material };
142        AddSolidCube((MeshGeometry3D)selectedModel.Geometry, selectedPos.X, selectedPos.Y, selectedPos.Z,
143          selectedItem.Value.WidthInView,
144          selectedItem.Value.HeightInView,
145          selectedItem.Value.DepthInView);
146        modelGroup.Children.Add(selectedModel);
147
148        foreach (var item in packing.Items.Where(x => selectedItemKey != x.Key)) {
149          var position = packing.Positions[item.Key];
150
151          var w = item.Value.WidthInView;
152          var h = item.Value.HeightInView;
153          var d = item.Value.DepthInView;
154
155          var model = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = hiddenMaterial };
156          AddWireframeCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d, 1);
157          modelGroup.Children.Add(model);
158        }
159
160
161      } else {
162        foreach (var item in packing.Items) {
163          var position = packing.Positions[item.Key];
164
165          var w = item.Value.WidthInView;
166          var h = item.Value.HeightInView;
167          var d = item.Value.DepthInView;
168
169          var model = new GeometryModel3D { Geometry = new MeshGeometry3D() };
170          DiffuseMaterial material;
171          if (!materials.TryGetValue(item.Value.Material, out material)) {
172            var colorIdx = item.Value.Material;
173            while (colorIdx < 0)
174              colorIdx += colors.Length;
175            colorIdx = colorIdx % colors.Length;
176            var color = colors[colorIdx];
177            material = new DiffuseMaterial { Brush = new SolidColorBrush(color) };
178            materials[item.Value.Material] = material;
179          }
180          var selectedModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = material };
181          AddSolidCube((MeshGeometry3D)selectedModel.Geometry, position.X, position.Y, position.Z, w, h, d);
182          modelGroup.Children.Add(selectedModel);
183        }
184      }
185
186
187      AddExtremePoints(modelGroup);
188
189      var container = packing.BinShape;
190      var containerModel = new GeometryModel3D(new MeshGeometry3D(), new DiffuseMaterial(new SolidColorBrush(containerColor)));
191      modelGroup.Children.Add(containerModel);
192      AddWireframeCube((MeshGeometry3D)containerModel.Geometry, container.Origin.X - .5, container.Origin.Y - .5, container.Origin.Z - .5, container.Width + 1, container.Height + 1, container.Depth + 1);
193
194      var ratio = Math.Max(container.Width, Math.Max(container.Height, container.Depth));
195      scale.ScaleX = 1.0 / ratio;
196      scale.ScaleY = 1.0 / ratio;
197      scale.ScaleZ = 1.0 / ratio;
198
199      scaleZoom.CenterX = rotateX.CenterX = rotateY.CenterX = container.Width / (2.0 * ratio);
200      scaleZoom.CenterY = rotateX.CenterY = rotateY.CenterY = container.Height / (2.0 * ratio);
201      scaleZoom.CenterZ = rotateX.CenterZ = rotateY.CenterZ = container.Depth / (2.0 * ratio);
202
203      camMain.Position = new Point3D(
204        scaleZoom.CenterX,
205        3,
206        3);
207      camMain.LookDirection = new Vector3D(
208        0,
209        scaleZoom.CenterY - camMain.Position.Y,
210        scaleZoom.CenterZ - camMain.Position.Z);
211    }
212
213    private void AddExtremePoints(Model3DGroup modelGroup) {
214      if (showExtremePoints) {
215        // draw extreme-points
216        var maxMag = (int)Math.Log10(Math.Max(packing.BinShape.Depth, Math.Max(packing.BinShape.Height, packing.BinShape.Width)));
217        var cubeSize = (int)Math.Max(Math.Pow(10, maxMag - 2), 1);
218        BinPacking3D.PackingPosition selectedExtremePoint = null;
219        if (selectedExtremePointIndex < 0) {
220          foreach (var ep in ExtremePoints) {
221            AddResidualSpacesForExtremePoint(modelGroup, ep);
222          }
223        } else {
224          selectedExtremePoint = ExtremePoints.ToList()[selectedExtremePointIndex];
225          AddResidualSpacesForExtremePoint(modelGroup, selectedExtremePoint);
226        }
227
228        foreach (var ep in ExtremePoints) {
229          Color color;
230          if (ep.Equals(selectedExtremePoint)) {
231            color = Colors.Yellow;
232          } else {
233            color = Colors.Red;
234          }
235          var epModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = new DiffuseMaterial() { Brush = new SolidColorBrush(color) } };
236          AddSolidCube((MeshGeometry3D)epModel.Geometry, ep.X, ep.Y, ep.Z, cubeSize, cubeSize, cubeSize);
237          modelGroup.Children.Add(epModel);
238        }
239      }
240    }
241
242    private void AddResidualSpacesForExtremePoint(Model3DGroup modelGroup, BinPacking3D.PackingPosition extremePoint) {
243      if (showResidualSpaces) {
244        foreach (var rs in ResidualSpaces[extremePoint]) {
245          var containerModel1 = new GeometryModel3D(new MeshGeometry3D(), new DiffuseMaterial(new SolidColorBrush(residualSpaceColor)));
246
247          modelGroup.Children.Add(containerModel1);
248
249          AddWireframeCube((MeshGeometry3D)containerModel1.Geometry,
250            extremePoint.X,
251            extremePoint.Y,
252            extremePoint.Z,
253            rs.Width,
254            rs.Height,
255            rs.Depth);
256        }
257      }
258       
259    }
260
261
262    private void Clear() {
263      ((Model3DGroup)MyModel.Content).Children.Clear();
264      materials.Clear();
265
266      mouseDown = false;
267      startAngleX = 0;
268      startAngleY = 0;
269    }
270
271    private void Container3DView_MouseMove(object sender, MouseEventArgs e) {
272      if (!mouseDown)
273        return;
274      var pos = e.GetPosition((IInputElement)this);
275
276      ((AxisAngleRotation3D)rotateX.Rotation).Angle = startAngleX + (pos.X - startPos.X) / 4;
277      ((AxisAngleRotation3D)rotateY.Rotation).Angle = startAngleY + (pos.Y - startPos.Y) / 4;
278    }
279
280    private void Container3DView_MouseDown(object sender, MouseButtonEventArgs e) {
281      startAngleX = ((AxisAngleRotation3D)rotateX.Rotation).Angle;
282      startAngleY = ((AxisAngleRotation3D)rotateY.Rotation).Angle;
283      this.startPos = e.GetPosition((IInputElement)this);
284      this.mouseDown = true;
285    }
286
287    private void Container3DView_MouseUp(object sender, MouseButtonEventArgs e) {
288      mouseDown = false;
289    }
290
291    private void Container3DView_OnMouseWheel(object sender, MouseWheelEventArgs e) {
292      if (e.Delta > 0) {
293        scaleZoom.ScaleX *= 1.1;
294        scaleZoom.ScaleY *= 1.1;
295        scaleZoom.ScaleZ *= 1.1;
296      } else if (e.Delta < 0) {
297        scaleZoom.ScaleX /= 1.1;
298        scaleZoom.ScaleY /= 1.1;
299        scaleZoom.ScaleZ /= 1.1;
300      }
301    }
302
303    private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) {
304      Focus(); // for mouse wheel events
305    }
306    private void ShowExtremePointsCheckBoxOnChecked(object sender, RoutedEventArgs e) {
307      showExtremePoints = true;
308      UpdateVisualization();
309    }
310    private void ShowExtremePointsCheckBoxOnUnchecked(object sender, RoutedEventArgs e) {
311      showExtremePoints = false;
312      UpdateVisualization();
313    }
314
315    private void ShowResidualSpacesCheckBoxOnChecked(object sender, RoutedEventArgs e) {
316      showResidualSpaces = true;
317      UpdateVisualization();
318    }
319    private void ShowResidualSpacesCheckBoxOnUnchecked(object sender, RoutedEventArgs e) {
320      showResidualSpaces = false;
321      UpdateVisualization();
322    }
323
324    #region helper for cubes
325    /// <summary>
326    /// Creates a solid cube by adding the respective points and triangles.
327    /// </summary>
328    /// <param name="mesh">The mesh to which points and triangles are added.</param>
329    /// <param name="x">The leftmost point</param>
330    /// <param name="y">The frontmost point</param>
331    /// <param name="z">The lowest point</param>
332    /// <param name="width">The extension to the right</param>
333    /// <param name="height">The extension to the back</param>
334    /// <param name="depth">The extension to the top</param>
335    private void AddSolidCube(MeshGeometry3D mesh, int x, int y, int z, int width, int height, int depth) {
336      // ground
337      mesh.Positions.Add(new Point3D(x, y, z));
338      mesh.Positions.Add(new Point3D(x + width, y, z));
339      mesh.Positions.Add(new Point3D(x + width, y + height, z));
340      mesh.Positions.Add(new Point3D(x, y + height, z));
341      // top
342      mesh.Positions.Add(new Point3D(x, y, z + depth));
343      mesh.Positions.Add(new Point3D(x + width, y, z + depth));
344      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth));
345      mesh.Positions.Add(new Point3D(x, y + height, z + depth));
346
347      // front
348      AddPlane(mesh, 0, 1, 5, 4);
349      // right side
350      AddPlane(mesh, 1, 2, 6, 5);
351      // back
352      AddPlane(mesh, 3, 7, 6, 2);
353      // left side
354      AddPlane(mesh, 0, 4, 7, 3);
355      // top
356      AddPlane(mesh, 4, 5, 6, 7);
357      // bottom
358      AddPlane(mesh, 0, 3, 2, 1);
359    }
360
361    /// <summary>
362    /// Creates a wireframe cube by adding the respective points and triangles.
363    /// </summary>
364    /// <param name="mesh">The mesh to which points and triangles are added.</param>
365    /// <param name="x">The leftmost point</param>
366    /// <param name="y">The frontmost point</param>
367    /// <param name="z">The lowest point</param>
368    /// <param name="width">The extension to the right</param>
369    /// <param name="height">The extension to the back</param>
370    /// <param name="depth">The extension to the top</param>
371    /// <param name="thickness">The thickness of the frame</param>
372    private void AddWireframeCube(MeshGeometry3D mesh, double x, double y, double z, double width, double height, double depth, double thickness = double.NaN) {
373      // default thickness of the wireframe is 5% of smallest dimension
374      if (double.IsNaN(thickness))
375        thickness = Math.Min(width, Math.Min(height, depth)) * 0.05;
376
377      // The cube contains of 8 corner, each corner has 4 points:
378      // 1. The corner point
379      // 2. A point on the edge to the right of the corner
380      // 3. A point on the edge atop or below the corner
381      // 4. A point on the edge to the left of the corner
382
383      // Point 0, Front Left Bottom
384      mesh.Positions.Add(new Point3D(x, y, z));
385      mesh.Positions.Add(new Point3D(x + thickness, y, z));
386      mesh.Positions.Add(new Point3D(x, y, z + thickness));
387      mesh.Positions.Add(new Point3D(x, y + thickness, z));
388
389      // Point 1, Front Right Bottom
390      mesh.Positions.Add(new Point3D(x + width, y, z));
391      mesh.Positions.Add(new Point3D(x + width, y + thickness, z));
392      mesh.Positions.Add(new Point3D(x + width, y, z + thickness));
393      mesh.Positions.Add(new Point3D(x + width - thickness, y, z));
394
395      // Point 2, Back Right Bottom
396      mesh.Positions.Add(new Point3D(x + width, y + height, z));
397      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z));
398      mesh.Positions.Add(new Point3D(x + width, y + height, z + thickness));
399      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z));
400
401      // Point 3, Back Left Bottom
402      mesh.Positions.Add(new Point3D(x, y + height, z));
403      mesh.Positions.Add(new Point3D(x, y + height - thickness, z));
404      mesh.Positions.Add(new Point3D(x, y + height, z + thickness));
405      mesh.Positions.Add(new Point3D(x + thickness, y + height, z));
406
407      // Point 4, Front Left Top
408      mesh.Positions.Add(new Point3D(x, y, z + depth));
409      mesh.Positions.Add(new Point3D(x + thickness, y, z + depth));
410      mesh.Positions.Add(new Point3D(x, y, z + depth - thickness));
411      mesh.Positions.Add(new Point3D(x, y + thickness, z + depth));
412
413      // Point 5, Front Right Top
414      mesh.Positions.Add(new Point3D(x + width, y, z + depth));
415      mesh.Positions.Add(new Point3D(x + width, y + thickness, z + depth));
416      mesh.Positions.Add(new Point3D(x + width, y, z + depth - thickness));
417      mesh.Positions.Add(new Point3D(x + width - thickness, y, z + depth));
418
419      // Point 6, Back Right Top
420      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth));
421      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + depth));
422      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth - thickness));
423      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + depth));
424
425      // Point 7, Back Left Top
426      mesh.Positions.Add(new Point3D(x, y + height, z + depth));
427      mesh.Positions.Add(new Point3D(x, y + height - thickness, z + depth));
428      mesh.Positions.Add(new Point3D(x, y + height, z + depth - thickness));
429      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth));
430
431      // Point 0, non-edge
432      mesh.Positions.Add(new Point3D(x + thickness, y, z + thickness));
433      mesh.Positions.Add(new Point3D(x, y + thickness, z + thickness));
434      mesh.Positions.Add(new Point3D(x + thickness, y + thickness, z));
435
436      // Point 1, non-edge
437      mesh.Positions.Add(new Point3D(x + width, y + thickness, z + thickness));
438      mesh.Positions.Add(new Point3D(x + width - thickness, y, z + thickness));
439      mesh.Positions.Add(new Point3D(x + width - thickness, y + thickness, z));
440
441      // Point 2, non-edge
442      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + thickness));
443      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + thickness));
444      mesh.Positions.Add(new Point3D(x + width - thickness, y + height - thickness, z));
445
446      // Point 3, non-edge
447      mesh.Positions.Add(new Point3D(x, y + height - thickness, z + thickness));
448      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + thickness));
449      mesh.Positions.Add(new Point3D(x + thickness, y + height - thickness, z));
450
451      // Point 4, non-edge
452      mesh.Positions.Add(new Point3D(x + thickness, y, z + depth - thickness));
453      mesh.Positions.Add(new Point3D(x, y + thickness, z + depth - thickness));
454      mesh.Positions.Add(new Point3D(x + thickness, y + thickness, z + depth));
455
456      // Point 5, non-edge
457      mesh.Positions.Add(new Point3D(x + width, y + thickness, z + depth - thickness));
458      mesh.Positions.Add(new Point3D(x + width - thickness, y, z + depth - thickness));
459      mesh.Positions.Add(new Point3D(x + width - thickness, y + thickness, z + depth));
460
461      // Point 6, non-edge
462      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + depth - thickness));
463      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + depth - thickness));
464      mesh.Positions.Add(new Point3D(x + width - thickness, y + height - thickness, z + depth));
465
466      // Point 7, non-edge
467      mesh.Positions.Add(new Point3D(x, y + height - thickness, z + depth - thickness));
468      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth - thickness));
469      mesh.Positions.Add(new Point3D(x + thickness, y + height - thickness, z + depth));
470
471      // Draw the 24 corner plates
472      AddPlane(mesh, 0, 1, 32, 2);
473      AddPlane(mesh, 0, 2, 33, 3);
474      AddPlane(mesh, 0, 3, 34, 1);
475
476      AddPlane(mesh, 4, 6, 36, 7);
477      AddPlane(mesh, 4, 5, 35, 6);
478      AddPlane(mesh, 4, 7, 37, 5);
479
480      AddPlane(mesh, 8, 10, 39, 11);
481      AddPlane(mesh, 8, 9, 38, 10);
482      AddPlane(mesh, 8, 11, 40, 9);
483
484      AddPlane(mesh, 12, 13, 41, 14);
485      AddPlane(mesh, 12, 14, 42, 15);
486      AddPlane(mesh, 12, 15, 43, 13);
487
488      AddPlane(mesh, 16, 18, 44, 17);
489      AddPlane(mesh, 16, 19, 45, 18);
490      AddPlane(mesh, 16, 17, 46, 19);
491
492      AddPlane(mesh, 20, 23, 48, 22);
493      AddPlane(mesh, 20, 22, 47, 21);
494      AddPlane(mesh, 20, 21, 49, 23);
495
496      AddPlane(mesh, 24, 27, 51, 26);
497      AddPlane(mesh, 24, 26, 50, 25);
498      AddPlane(mesh, 24, 25, 52, 27);
499
500      AddPlane(mesh, 28, 31, 54, 30);
501      AddPlane(mesh, 28, 30, 53, 29);
502      AddPlane(mesh, 28, 29, 55, 31);
503
504      // Draw the connecting plates
505      // on the bottom
506      AddPlane(mesh, 1, 7, 36, 32);
507      AddPlane(mesh, 1, 34, 37, 7);
508
509      AddPlane(mesh, 5, 11, 39, 35);
510      AddPlane(mesh, 5, 37, 40, 11);
511
512      AddPlane(mesh, 9, 15, 42, 38);
513      AddPlane(mesh, 9, 40, 43, 15);
514
515      AddPlane(mesh, 13, 3, 33, 41);
516      AddPlane(mesh, 13, 43, 34, 3);
517
518      // between bottom and top
519      AddPlane(mesh, 2, 32, 44, 18);
520      AddPlane(mesh, 2, 18, 45, 33);
521
522      AddPlane(mesh, 6, 22, 48, 36);
523      AddPlane(mesh, 6, 35, 47, 22);
524
525      AddPlane(mesh, 10, 26, 51, 39);
526      AddPlane(mesh, 10, 38, 50, 26);
527
528      AddPlane(mesh, 14, 30, 54, 42);
529      AddPlane(mesh, 14, 41, 53, 30);
530
531      // on the top
532      AddPlane(mesh, 17, 44, 48, 23);
533      AddPlane(mesh, 17, 23, 49, 46);
534
535      AddPlane(mesh, 21, 47, 51, 27);
536      AddPlane(mesh, 21, 27, 52, 49);
537
538      AddPlane(mesh, 25, 50, 54, 31);
539      AddPlane(mesh, 25, 31, 55, 52);
540
541      AddPlane(mesh, 29, 19, 46, 55);
542      AddPlane(mesh, 29, 53, 45, 19);
543    }
544
545    /// <summary>
546    /// Adds a plane by two triangles. The indices of the points have to be given
547    /// in counter-clockwise sequence.
548    /// </summary>
549    /// <param name="mesh">The mesh to add the triangles to</param>
550    /// <param name="a">The index of the first point</param>
551    /// <param name="b">The index of the second point</param>
552    /// <param name="c">The index of the third point</param>
553    /// <param name="d">The index of the fourth point</param>
554    private void AddPlane(MeshGeometry3D mesh, int a, int b, int c, int d) {
555      // two triangles form a plane
556      mesh.TriangleIndices.Add(a);
557      mesh.TriangleIndices.Add(b);
558      mesh.TriangleIndices.Add(d);
559      mesh.TriangleIndices.Add(c);
560      mesh.TriangleIndices.Add(d);
561      mesh.TriangleIndices.Add(b);
562    }
563    #endregion
564  }
565}
Note: See TracBrowser for help on using the repository browser.