Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13333 was 13032, checked in by gkronber, 9 years ago

#1966:

  • removed unused using
  • added/updated license headers
File size: 18.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    //Define positions of the textures
56    Vector2 textureTopLeft;
57    Vector2 textureTopRight;
58    Vector2 textureBottomLeft;
59    Vector2 textureBottomRight;
60    #endregion Private Members
61
62
63    public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition) : this (shapeSize, shapePosition, Color.Black) { }
64    public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition, Color color) {
65      var halfShapeSize = shapeSize / 2;
66      //Define the shape in a way so that the position is in the center of the shape.
67      //Define the 8 defining points of the cube
68      topLeftFront = shapePosition + new Vector3(-1.0f, 1.0f, 1.0f) * halfShapeSize;
69      bottomLeftFront = shapePosition + new Vector3(-1.0f, -1.0f, 1.0f) * halfShapeSize;
70      topRightFront = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * halfShapeSize;
71      bottomRightFront = shapePosition + new Vector3(1.0f, -1.0f, 1.0f) * halfShapeSize;
72      topLeftBack = shapePosition + new Vector3(-1.0f, 1.0f, -1.0f) * halfShapeSize;
73      topRightBack = shapePosition + new Vector3(1.0f, 1.0f, -1.0f) * halfShapeSize;
74      bottomLeftBack = shapePosition + new Vector3(-1.0f, -1.0f, -1.0f) * halfShapeSize;
75      bottomRightBack = shapePosition + new Vector3(1.0f, -1.0f, -1.0f) * halfShapeSize;
76
77      //Define normal vectors of the 6 surfaces
78      frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * halfShapeSize;
79      backNormal = new Vector3(0.0f, 0.0f, -1.0f) * halfShapeSize;
80      topNormal = new Vector3(0.0f, 1.0f, 0.0f) * halfShapeSize;
81      bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * halfShapeSize;
82      leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * halfShapeSize;
83      rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * halfShapeSize;
84
85      //Define colors of the 6 surfaces
86      frontColor = color;
87      backColor = color;
88      topColor = color;
89      bottomColor = color;
90      leftColor = color;
91      rightColor = color;
92
93      //Define positions of the textures
94      textureTopLeft = new Vector2(0.5f * halfShapeSize.X, 0.0f * halfShapeSize.Y);
95      textureTopRight = new Vector2(0.0f * halfShapeSize.X, 0.0f * halfShapeSize.Y);
96      textureBottomLeft = new Vector2(0.5f * halfShapeSize.X, 0.5f * halfShapeSize.Y);
97      textureBottomRight = new Vector2(0.0f * halfShapeSize.X, 0.5f * halfShapeSize.Y);
98    }
99
100    public VertexPositionColorNormal[] CreateVertexDefinitionsForTriangles () {
101      //Definition of the actual triangles
102      VertexPositionColorNormal[] shapeVertices = new VertexPositionColorNormal[36];
103
104      // Front face.
105      shapeVertices[0] = new VertexPositionColorNormal(frontColor, topLeftFront, frontNormal);
106      shapeVertices[1] = new VertexPositionColorNormal(frontColor, bottomLeftFront, frontNormal);
107      shapeVertices[2] = new VertexPositionColorNormal(frontColor, topRightFront, frontNormal);
108
109      shapeVertices[3] = new VertexPositionColorNormal(frontColor, bottomLeftFront, frontNormal);
110      shapeVertices[4] = new VertexPositionColorNormal(frontColor, bottomRightFront, frontNormal);
111      shapeVertices[5] = new VertexPositionColorNormal(frontColor, topRightFront, frontNormal);
112
113
114      // Back face.
115      shapeVertices[6] = new VertexPositionColorNormal(backColor, topLeftBack, backNormal);
116      shapeVertices[7] = new VertexPositionColorNormal(backColor, topRightBack, backNormal);
117      shapeVertices[8] = new VertexPositionColorNormal(backColor, bottomLeftBack, backNormal);
118
119      shapeVertices[9] = new VertexPositionColorNormal(backColor, bottomLeftBack, backNormal);
120      shapeVertices[10] = new VertexPositionColorNormal(backColor, topRightBack, backNormal);
121      shapeVertices[11] = new VertexPositionColorNormal(backColor, bottomRightBack, backNormal);
122
123
124      // Top face.
125      shapeVertices[12] = new VertexPositionColorNormal(topColor, topLeftFront, topNormal);
126      shapeVertices[13] = new VertexPositionColorNormal(topColor, topRightBack, topNormal);
127      shapeVertices[14] = new VertexPositionColorNormal(topColor, topLeftBack, topNormal);
128
129      shapeVertices[15] = new VertexPositionColorNormal(topColor, topLeftFront, topNormal);
130      shapeVertices[16] = new VertexPositionColorNormal(topColor, topRightFront, topNormal);
131      shapeVertices[17] = new VertexPositionColorNormal(topColor, topRightBack, topNormal);
132
133
134      // Bottom face.
135      shapeVertices[18] = new VertexPositionColorNormal(bottomColor, bottomLeftFront, bottomNormal);
136      shapeVertices[19] = new VertexPositionColorNormal(bottomColor, bottomLeftBack, bottomNormal);
137      shapeVertices[20] = new VertexPositionColorNormal(bottomColor, bottomRightBack, bottomNormal);
138
139      shapeVertices[21] = new VertexPositionColorNormal(bottomColor, bottomLeftFront, bottomNormal);
140      shapeVertices[22] = new VertexPositionColorNormal(bottomColor, bottomRightBack, bottomNormal);
141      shapeVertices[23] = new VertexPositionColorNormal(bottomColor, bottomRightFront, bottomNormal);
142
143
144      // Left face.
145      shapeVertices[24] = new VertexPositionColorNormal(leftColor, topLeftFront, leftNormal);
146      shapeVertices[25] = new VertexPositionColorNormal(leftColor, bottomLeftBack, leftNormal);
147      shapeVertices[26] = new VertexPositionColorNormal(leftColor, bottomLeftFront, leftNormal);
148
149      shapeVertices[27] = new VertexPositionColorNormal(leftColor, topLeftBack, leftNormal);
150      shapeVertices[28] = new VertexPositionColorNormal(leftColor, bottomLeftBack, leftNormal);
151      shapeVertices[29] = new VertexPositionColorNormal(leftColor, topLeftFront, leftNormal);
152
153
154      // Right face.
155      shapeVertices[30] = new VertexPositionColorNormal(rightColor, topRightFront, rightNormal);
156      shapeVertices[31] = new VertexPositionColorNormal(rightColor, bottomRightFront, rightNormal);
157      shapeVertices[32] = new VertexPositionColorNormal(rightColor, bottomRightBack, rightNormal);
158
159      shapeVertices[33] = new VertexPositionColorNormal(rightColor, topRightBack, rightNormal);
160      shapeVertices[34] = new VertexPositionColorNormal(rightColor, topRightFront, rightNormal);
161      shapeVertices[35] = new VertexPositionColorNormal(rightColor, bottomRightBack, rightNormal);
162
163      return shapeVertices;
164    }
165
166    public VertexPositionColorNormal[] CreateVertexDefinitionsForEdgeLines() {
167      return CreateVertexDefinitionsForEdgeLines(frontColor);
168    }
169
170    public VertexPositionColorNormal[] CreateVertexDefinitionsForEdgeLines(Color color) {
171      //Definition of the actual lines
172      VertexPositionColorNormal[] shapeVertices = new VertexPositionColorNormal[48];
173
174      //shapeVertices[0] = new VertexPositionColorNormal(color, topRightFront, frontNormal);
175      //shapeVertices[1] = new VertexPositionColorNormal(color, topLeftFront, frontNormal);
176      //shapeVertices[2] = new VertexPositionColorNormal(color, topLeftFront, frontNormal);
177      //shapeVertices[3] = new VertexPositionColorNormal(color, bottomLeftFront, frontNormal);
178      //shapeVertices[4] = new VertexPositionColorNormal(color, bottomLeftFront, frontNormal);
179      //shapeVertices[5] = new VertexPositionColorNormal(color, bottomRightFront, frontNormal);
180      //shapeVertices[6] = new VertexPositionColorNormal(color, bottomRightFront, frontNormal);
181      //shapeVertices[7] = new VertexPositionColorNormal(color, topRightFront, frontNormal);
182
183      //shapeVertices[8] = new VertexPositionColorNormal(color, topRightBack, backNormal);
184      //shapeVertices[9] = new VertexPositionColorNormal(color, topLeftBack, backNormal);
185      //shapeVertices[10] = new VertexPositionColorNormal(color, topLeftBack, backNormal);
186      //shapeVertices[11] = new VertexPositionColorNormal(color, bottomLeftBack, backNormal);
187      //shapeVertices[12] = new VertexPositionColorNormal(color, bottomLeftBack, backNormal);
188      //shapeVertices[13] = new VertexPositionColorNormal(color, bottomRightBack, backNormal);
189      //shapeVertices[14] = new VertexPositionColorNormal(color, bottomRightBack, backNormal);
190      //shapeVertices[15] = new VertexPositionColorNormal(color, topRightBack, backNormal);
191
192      //shapeVertices[16] = new VertexPositionColorNormal(color, topLeftFront, topNormal);
193      //shapeVertices[17] = new VertexPositionColorNormal(color, topLeftBack, topNormal);
194      //shapeVertices[18] = new VertexPositionColorNormal(color, topRightFront, topNormal);
195      //shapeVertices[19] = new VertexPositionColorNormal(color, topRightBack, topNormal);
196      //shapeVertices[20] = new VertexPositionColorNormal(color, topLeftFront, topNormal);
197      //shapeVertices[21] = new VertexPositionColorNormal(color, topRightFront, topNormal);
198      //shapeVertices[22] = new VertexPositionColorNormal(color, topRightBack, topNormal);
199      //shapeVertices[23] = new VertexPositionColorNormal(color, topLeftBack, topNormal);
200
201      //shapeVertices[24] = new VertexPositionColorNormal(color, bottomLeftFront, bottomNormal);
202      //shapeVertices[25] = new VertexPositionColorNormal(color, bottomRightFront, bottomNormal);
203      //shapeVertices[26] = new VertexPositionColorNormal(color, bottomLeftBack, bottomNormal);
204      //shapeVertices[27] = new VertexPositionColorNormal(color, bottomRightBack, bottomNormal);
205      //shapeVertices[28] = new VertexPositionColorNormal(color, bottomRightFront, bottomNormal);
206      //shapeVertices[29] = new VertexPositionColorNormal(color, bottomRightBack, bottomNormal);
207      //shapeVertices[30] = new VertexPositionColorNormal(color, bottomLeftFront, bottomNormal);
208      //shapeVertices[31] = new VertexPositionColorNormal(color, bottomLeftBack, bottomNormal);
209
210      //shapeVertices[32] = new VertexPositionColorNormal(color, topLeftFront, leftNormal);
211      //shapeVertices[33] = new VertexPositionColorNormal(color, topLeftBack, leftNormal);
212      //shapeVertices[34] = new VertexPositionColorNormal(color, topLeftBack, leftNormal);
213      //shapeVertices[35] = new VertexPositionColorNormal(color, bottomLeftBack, leftNormal);
214      //shapeVertices[36] = new VertexPositionColorNormal(color, bottomLeftBack, leftNormal);
215      //shapeVertices[37] = new VertexPositionColorNormal(color, bottomLeftFront, leftNormal);
216      //shapeVertices[38] = new VertexPositionColorNormal(color, bottomLeftFront, leftNormal);
217      //shapeVertices[39] = new VertexPositionColorNormal(color, topLeftFront, leftNormal);
218
219      //shapeVertices[40] = new VertexPositionColorNormal(color, topRightFront, rightNormal);
220      //shapeVertices[41] = new VertexPositionColorNormal(color, topRightBack, rightNormal);
221      //shapeVertices[42] = new VertexPositionColorNormal(color, topRightBack, rightNormal);
222      //shapeVertices[43] = new VertexPositionColorNormal(color, bottomRightBack, rightNormal);
223      //shapeVertices[44] = new VertexPositionColorNormal(color, bottomRightBack, rightNormal);
224      //shapeVertices[45] = new VertexPositionColorNormal(color, bottomRightFront, rightNormal);
225      //shapeVertices[46] = new VertexPositionColorNormal(color, bottomRightFront, rightNormal);
226      //shapeVertices[47] = new VertexPositionColorNormal(color, topRightFront, rightNormal);
227
228      Vector3 topRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3;
229      Vector3 topRightBackNormal = (topNormal + rightNormal + backNormal) / 3;
230      Vector3 topLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3;
231      Vector3 topLeftBackNormal = (topNormal + leftNormal + backNormal) / 3;
232      Vector3 bottomRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3;
233      Vector3 bottomRightBackNormal = (topNormal + rightNormal + backNormal) / 3;
234      Vector3 bottomLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3;
235      Vector3 bottomLeftBackNormal = (topNormal + leftNormal + backNormal) / 3;
236
237      shapeVertices[0] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
238      shapeVertices[1] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
239      shapeVertices[2] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
240      shapeVertices[3] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
241      shapeVertices[4] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
242      shapeVertices[5] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
243      shapeVertices[6] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
244      shapeVertices[7] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
245
246      shapeVertices[8] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
247      shapeVertices[9] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
248      shapeVertices[10] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
249      shapeVertices[11] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
250      shapeVertices[12] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
251      shapeVertices[13] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
252      shapeVertices[14] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
253      shapeVertices[15] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
254
255      shapeVertices[16] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
256      shapeVertices[17] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
257      shapeVertices[18] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
258      shapeVertices[19] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
259      shapeVertices[20] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
260      shapeVertices[21] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
261      shapeVertices[22] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
262      shapeVertices[23] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
263
264      shapeVertices[24] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
265      shapeVertices[25] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
266      shapeVertices[26] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
267      shapeVertices[27] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
268      shapeVertices[28] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
269      shapeVertices[29] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
270      shapeVertices[30] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
271      shapeVertices[31] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
272
273      shapeVertices[32] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
274      shapeVertices[33] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
275      shapeVertices[34] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal);
276      shapeVertices[35] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
277      shapeVertices[36] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal);
278      shapeVertices[37] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
279      shapeVertices[38] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal);
280      shapeVertices[39] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal);
281
282      shapeVertices[40] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
283      shapeVertices[41] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
284      shapeVertices[42] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal);
285      shapeVertices[43] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
286      shapeVertices[44] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal);
287      shapeVertices[45] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
288      shapeVertices[46] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal);
289      shapeVertices[47] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
290
291      return shapeVertices;
292    }
293
294
295  }
296}
Note: See TracBrowser for help on using the repository browser.