source: branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/CuboidShapePreperations.cs @ 13465

Last change on this file since 13465 was 13465, checked in by gkronber, 5 years ago

#1966: general code cleanup ...

File size: 13.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Joseph Helm and 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 SharpDX;
23
24namespace PackingPlanVisualizations {
25  public class CuboidShapePreparations {
26
27    #region Private Members
28    //Define the shape in a way so that the position is in the center of the shape.
29    //Define the 8 defining points of the cube
30    Vector3 topLeftFront;
31    Vector3 bottomLeftFront;
32    Vector3 topRightFront;
33    Vector3 bottomRightFront;
34    Vector3 topLeftBack;
35    Vector3 topRightBack;
36    Vector3 bottomLeftBack;
37    Vector3 bottomRightBack;
38
39    //Define normal vectors of the 6 surfaces
40    Vector3 frontNormal;
41    Vector3 backNormal;
42    Vector3 topNormal;
43    Vector3 bottomNormal;
44    Vector3 leftNormal;
45    Vector3 rightNormal;
46
47    //Define colors of the 6 surfaces
48    Color frontColor = Color.Black;
49    Color backColor = Color.Black;
50    Color topColor = Color.Black;
51    Color bottomColor = Color.Black;
52    Color leftColor = Color.Black;
53    Color rightColor = Color.Black;
54
55    #endregion Private Members
56
57
58    public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition) : this (shapeSize, shapePosition, Color.Black) { }
59    public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition, Color color) {
60      var halfShapeSize = shapeSize / 2;
61      //Define the shape in a way so that the position is in the center of the shape.
62      //Define the 8 defining points of the cube
63      topLeftFront = shapePosition + new Vector3(-1.0f, 1.0f, 1.0f) * halfShapeSize;
64      bottomLeftFront = shapePosition + new Vector3(-1.0f, -1.0f, 1.0f) * halfShapeSize;
65      topRightFront = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * halfShapeSize;
66      bottomRightFront = shapePosition + new Vector3(1.0f, -1.0f, 1.0f) * halfShapeSize;
67      topLeftBack = shapePosition + new Vector3(-1.0f, 1.0f, -1.0f) * halfShapeSize;
68      topRightBack = shapePosition + new Vector3(1.0f, 1.0f, -1.0f) * halfShapeSize;
69      bottomLeftBack = shapePosition + new Vector3(-1.0f, -1.0f, -1.0f) * halfShapeSize;
70      bottomRightBack = shapePosition + new Vector3(1.0f, -1.0f, -1.0f) * halfShapeSize;
71
72      //Define normal vectors of the 6 surfaces
73      frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * halfShapeSize;
74      backNormal = new Vector3(0.0f, 0.0f, -1.0f) * halfShapeSize;
75      topNormal = new Vector3(0.0f, 1.0f, 0.0f) * halfShapeSize;
76      bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * halfShapeSize;
77      leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * halfShapeSize;
78      rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * halfShapeSize;
79
80      //Define colors of the 6 surfaces
81      frontColor = color;
82      backColor = color;
83      topColor = color;
84      bottomColor = color;
85      leftColor = color;
86      rightColor = color;
87
88    }
89
90    public VertexPositionColorNormal[] CreateVertexDefinitionsForTriangles () {
91      //Definition of the actual triangles
92      VertexPositionColorNormal[] shapeVertices = new VertexPositionColorNormal[36];
93
94      // Front face.
95      shapeVertices[0] = new VertexPositionColorNormal(frontColor, topLeftFront, frontNormal);
96      shapeVertices[1] = new VertexPositionColorNormal(frontColor, bottomLeftFront, frontNormal);
97      shapeVertices[2] = new VertexPositionColorNormal(frontColor, topRightFront, frontNormal);
98
99      shapeVertices[3] = new VertexPositionColorNormal(frontColor, bottomLeftFront, frontNormal);
100      shapeVertices[4] = new VertexPositionColorNormal(frontColor, bottomRightFront, frontNormal);
101      shapeVertices[5] = new VertexPositionColorNormal(frontColor, topRightFront, frontNormal);
102
103
104      // Back face.
105      shapeVertices[6] = new VertexPositionColorNormal(backColor, topLeftBack, backNormal);
106      shapeVertices[7] = new VertexPositionColorNormal(backColor, topRightBack, backNormal);
107      shapeVertices[8] = new VertexPositionColorNormal(backColor, bottomLeftBack, backNormal);
108
109      shapeVertices[9] = new VertexPositionColorNormal(backColor, bottomLeftBack, backNormal);
110      shapeVertices[10] = new VertexPositionColorNormal(backColor, topRightBack, backNormal);
111      shapeVertices[11] = new VertexPositionColorNormal(backColor, bottomRightBack, backNormal);
112
113
114      // Top face.
115      shapeVertices[12] = new VertexPositionColorNormal(topColor, topLeftFront, topNormal);
116      shapeVertices[13] = new VertexPositionColorNormal(topColor, topRightBack, topNormal);
117      shapeVertices[14] = new VertexPositionColorNormal(topColor, topLeftBack, topNormal);
118
119      shapeVertices[15] = new VertexPositionColorNormal(topColor, topLeftFront, topNormal);
120      shapeVertices[16] = new VertexPositionColorNormal(topColor, topRightFront, topNormal);
121      shapeVertices[17] = new VertexPositionColorNormal(topColor, topRightBack, topNormal);
122
123
124      // Bottom face.
125      shapeVertices[18] = new VertexPositionColorNormal(bottomColor, bottomLeftFront, bottomNormal);
126      shapeVertices[19] = new VertexPositionColorNormal(bottomColor, bottomLeftBack, bottomNormal);
127      shapeVertices[20] = new VertexPositionColorNormal(bottomColor, bottomRightBack, bottomNormal);
128
129      shapeVertices[21] = new VertexPositionColorNormal(bottomColor, bottomLeftFront, bottomNormal);
130      shapeVertices[22] = new VertexPositionColorNormal(bottomColor, bottomRightBack, bottomNormal);
131      shapeVertices[23] = new VertexPositionColorNormal(bottomColor, bottomRightFront, bottomNormal);
132
133
134      // Left face.
135      shapeVertices[24] = new VertexPositionColorNormal(leftColor, topLeftFront, leftNormal);
136      shapeVertices[25] = new VertexPositionColorNormal(leftColor, bottomLeftBack, leftNormal);
137      shapeVertices[26] = new VertexPositionColorNormal(leftColor, bottomLeftFront, leftNormal);
138
139      shapeVertices[27] = new VertexPositionColorNormal(leftColor, topLeftBack, leftNormal);
140      shapeVertices[28] = new VertexPositionColorNormal(leftColor, bottomLeftBack, leftNormal);
141      shapeVertices[29] = new VertexPositionColorNormal(leftColor, topLeftFront, leftNormal);
142
143
144      // Right face.
145      shapeVertices[30] = new VertexPositionColorNormal(rightColor, topRightFront, rightNormal);
146      shapeVertices[31] = new VertexPositionColorNormal(rightColor, bottomRightFront, rightNormal);
147      shapeVertices[32] = new VertexPositionColorNormal(rightColor, bottomRightBack, rightNormal);
148
149      shapeVertices[33] = new VertexPositionColorNormal(rightColor, topRightBack, rightNormal);
150      shapeVertices[34] = new VertexPositionColorNormal(rightColor, topRightFront, rightNormal);
151      shapeVertices[35] = new VertexPositionColorNormal(rightColor, bottomRightBack, rightNormal);
152
153      return shapeVertices;
154    }
155
156    public VertexPositionColorNormal[] CreateVertexDefinitionsForEdgeLines() {
157      return CreateVertexDefinitionsForEdgeLines(frontColor);
158    }
159
160    public VertexPositionColorNormal[] CreateVertexDefinitionsForEdgeLines(Color color) {
161      //Definition of the actual lines
162      VertexPositionColorNormal[] shapeVertices = new VertexPositionColorNormal[48];
163
164      Vector3 topRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3;
165      Vector3 topRightBackNormal = (topNormal + rightNormal + backNormal) / 3;
166      Vector3 topLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3;
167      Vector3 topLeftBackNormal = (topNormal + leftNormal + backNormal) / 3;
168      Vector3 bottomRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3;
169      Vector3 bottomRightBackNormal = (topNormal + rightNormal + backNormal) / 3;
170      Vector3 bottomLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3;
171      Vector3 bottomLeftBackNormal = (topNormal + leftNormal + backNormal) / 3;
172
173      shapeVertices[0] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
174      shapeVertices[1] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
175      shapeVertices[2] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
176      shapeVertices[3] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
177      shapeVertices[4] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
178      shapeVertices[5] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
179      shapeVertices[6] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
180      shapeVertices[7] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
181
182      shapeVertices[8] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
183      shapeVertices[9] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
184      shapeVertices[10] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
185      shapeVertices[11] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
186      shapeVertices[12] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
187      shapeVertices[13] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
188      shapeVertices[14] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
189      shapeVertices[15] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
190
191      shapeVertices[16] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
192      shapeVertices[17] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
193      shapeVertices[18] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
194      shapeVertices[19] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
195      shapeVertices[20] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
196      shapeVertices[21] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
197      shapeVertices[22] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
198      shapeVertices[23] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
199
200      shapeVertices[24] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
201      shapeVertices[25] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
202      shapeVertices[26] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
203      shapeVertices[27] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
204      shapeVertices[28] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
205      shapeVertices[29] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
206      shapeVertices[30] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
207      shapeVertices[31] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
208
209      shapeVertices[32] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
210      shapeVertices[33] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
211      shapeVertices[34] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
212      shapeVertices[35] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
213      shapeVertices[36] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
214      shapeVertices[37] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
215      shapeVertices[38] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
216      shapeVertices[39] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
217
218      shapeVertices[40] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
219      shapeVertices[41] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
220      shapeVertices[42] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
221      shapeVertices[43] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
222      shapeVertices[44] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
223      shapeVertices[45] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
224      shapeVertices[46] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
225      shapeVertices[47] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
226
227      return shapeVertices;
228    }
229
230
231  }
232}
Note: See TracBrowser for help on using the repository browser.