Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2817:

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