- Timestamp:
- 07/10/17 17:41:38 (7 years ago)
- Location:
- branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views
-
Property
svn:mergeinfo
set to
/trunk/sources/HeuristicLab.Problems.BinPacking.Views merged eligible
-
Property
svn:mergeinfo
set to
-
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml
r14835 r15182 30 30 MouseWheel="Container3DView_OnMouseWheel" 31 31 MouseEnter="Container3DView_OnMouseEnter" 32 KeyDown="Container3DView_OnKeyDown"33 32 Focusable="true" 34 33 > 35 34 <Grid> 36 < Viewport3D Name="viewport3D1">37 <Viewport3D .Camera>38 < PerspectiveCamera x:Name="camMain" Position="0.5 8 8" LookDirection="0 -1 -1"> <!-- camera position for design time-->39 </PerspectiveCamera>40 </Viewport3D.Camera>41 <ModelVisual3D>42 <ModelVisual3D .Content>43 < DirectionalLight x:Name="dirLightMain" Direction="0,-1,-1"/>44 </ModelVisual3D.Content>45 </ModelVisual3D>46 <ModelVisual3D>47 </ModelVisual3D>48 <ModelVisual3D x:Name="MyModel">49 <ModelVisual3D .Content>50 <Model 3DGroup>51 </Model3DGroup>52 </ModelVisual3D.Content>53 <ModelVisual3D.Transform>54 < Transform3DGroup>55 < ScaleTransform3D x:Name="scale" ScaleX="1" ScaleY="1" ScaleZ="1"/>56 <TranslateTransform3D OffsetX="-0.5" OffsetY="-0.5" OffsetZ="-0.5"/>57 <RotateTransform3D>58 <RotateTransform3D.Rotation>59 <AxisAngleRotation3D x:Name="rotateX"Axis="0 1 0"/>60 </RotateTransform3D.Rotation>61 </RotateTransform3D>62 <RotateTransform3D>63 <RotateTransform3D.Rotation>64 <AxisAngleRotation3D x:Name="rotateY"Axis="1 0 0"/>65 </RotateTransform3D.Rotation>66 </RotateTransform3D>67 <TranslateTransform3D OffsetX="0.5" OffsetY="0.5" OffsetZ="0.5"/>68 < ScaleTransform3D x:Name="scaleZoom" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="1" ScaleY="1" ScaleZ="1"/>69 </ Transform3DGroup>70 </ModelVisual3D .Transform>71 </ ModelVisual3D>72 </ Viewport3D>35 <Border BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"> 36 <Viewport3D Name="viewport3D1" > 37 <Viewport3D.Camera> 38 <PerspectiveCamera x:Name="camMain" Position="0.5 8 8" LookDirection="0 -1 -1"> <!-- camera position for design time--> 39 </PerspectiveCamera> 40 </Viewport3D.Camera> 41 <ModelVisual3D> 42 <ModelVisual3D.Content> 43 <DirectionalLight x:Name="dirLightMain" Direction="0,-1,-1"/> 44 </ModelVisual3D.Content> 45 </ModelVisual3D> 46 <ModelVisual3D> 47 </ModelVisual3D> 48 <ModelVisual3D x:Name="MyModel"> 49 <ModelVisual3D.Content> 50 <Model3DGroup> 51 </Model3DGroup> 52 </ModelVisual3D.Content> 53 <ModelVisual3D.Transform> 54 <Transform3DGroup> 55 <ScaleTransform3D x:Name="scale" ScaleX="1" ScaleY="1" ScaleZ="1"/> 56 <RotateTransform3D x:Name="rotateX"> 57 <RotateTransform3D.Rotation> 58 <AxisAngleRotation3D Axis="0 1 0"/> 59 </RotateTransform3D.Rotation> 60 </RotateTransform3D> 61 <RotateTransform3D x:Name="rotateY"> 62 <RotateTransform3D.Rotation> 63 <AxisAngleRotation3D Axis="1 0 0"/> 64 </RotateTransform3D.Rotation> 65 </RotateTransform3D> 66 <ScaleTransform3D x:Name="scaleZoom" ScaleX="1" ScaleY="1" ScaleZ="1"/> 67 </Transform3DGroup> 68 </ModelVisual3D.Transform> 69 </ModelVisual3D> 70 </Viewport3D> 71 </Border> 73 72 </Grid> 74 73 </UserControl> -
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs
r14835 r15182 46 46 Color.FromRgb(0x63, 0xC2, 0x16), 47 47 }; 48 48 49 49 private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA); 50 50 private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA); … … 52 52 private Point startPos; 53 53 private bool mouseDown = false; 54 private bool ctrlDown = false;55 54 private double startAngleX; 56 55 private double startAngleY; … … 103 102 var hiddenMaterial = new DiffuseMaterial(new SolidColorBrush(hiddenColor)); 104 103 105 foreach (var item in packing.Items) { 106 var position = packing.Positions[item.Key]; 107 108 var w = position.Rotated ? item.Value.Depth : item.Value.Width; 109 var h = item.Value.Height; 110 var d = position.Rotated ? item.Value.Width : item.Value.Depth; 111 112 var model = new GeometryModel3D { Geometry = new MeshGeometry3D() }; 113 DiffuseMaterial material; 114 if (selectedItemKey >= 0 && selectedItemKey != item.Key) 115 material = hiddenMaterial; 116 else { 104 if (selectedItemKey >= 0) { 105 var selectedItem = packing.Items.Single(x => selectedItemKey == x.Key); 106 var selectedPos = packing.Positions[selectedItem.Key]; 107 108 var colorIdx = selectedItem.Value.Material; 109 while (colorIdx < 0) colorIdx += colors.Length; 110 colorIdx = colorIdx % colors.Length; 111 var color = colors[colorIdx]; 112 var material = new DiffuseMaterial { Brush = new SolidColorBrush(color) }; 113 materials[selectedItem.Value.Material] = material; 114 115 var selectedModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = material }; 116 AddSolidCube((MeshGeometry3D)selectedModel.Geometry, selectedPos.X, selectedPos.Y, selectedPos.Z, 117 selectedPos.Rotated ? selectedItem.Value.Depth : selectedItem.Value.Width, 118 selectedItem.Value.Height, 119 selectedPos.Rotated ? selectedItem.Value.Width : selectedItem.Value.Depth); 120 modelGroup.Children.Add(selectedModel); 121 122 foreach (var item in packing.Items.Where(x => selectedItemKey != x.Key)) { 123 var position = packing.Positions[item.Key]; 124 125 var w = position.Rotated ? item.Value.Depth : item.Value.Width; 126 var h = item.Value.Height; 127 var d = position.Rotated ? item.Value.Width : item.Value.Depth; 128 129 var model = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = hiddenMaterial }; 130 AddWireframeCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d, 1); 131 modelGroup.Children.Add(model); 132 } 133 } else { 134 foreach (var item in packing.Items) { 135 var position = packing.Positions[item.Key]; 136 137 var w = position.Rotated ? item.Value.Depth : item.Value.Width; 138 var h = item.Value.Height; 139 var d = position.Rotated ? item.Value.Width : item.Value.Depth; 140 141 var model = new GeometryModel3D { Geometry = new MeshGeometry3D() }; 142 DiffuseMaterial material; 117 143 if (!materials.TryGetValue(item.Value.Material, out material)) { 118 144 var colorIdx = item.Value.Material; … … 123 149 materials[item.Value.Material] = material; 124 150 } 151 var selectedModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = material }; 152 AddSolidCube((MeshGeometry3D)selectedModel.Geometry, position.X, position.Y, position.Z, w, h, d); 153 modelGroup.Children.Add(selectedModel); 125 154 } 126 model.Material = material;127 modelGroup.Children.Add(model);128 129 AddSolidCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d);130 155 } 131 156 … … 140 165 scale.ScaleZ = 1.0 / ratio; 141 166 142 scale.CenterX = .5; 143 scale.CenterY = .5; 144 scale.CenterZ = 0; 167 scaleZoom.CenterX = rotateX.CenterX = rotateY.CenterX = container.Width / (2.0 * ratio); 168 scaleZoom.CenterY = rotateX.CenterY = rotateY.CenterY = container.Height / (2.0 * ratio); 169 scaleZoom.CenterZ = rotateX.CenterZ = rotateY.CenterZ = container.Depth / (2.0 * ratio); 170 171 camMain.Position = new Point3D( 172 scaleZoom.CenterX, 173 3, 174 3); 175 camMain.LookDirection = new Vector3D( 176 0, 177 scaleZoom.CenterY - camMain.Position.Y, 178 scaleZoom.CenterZ - camMain.Position.Z); 145 179 } 146 180 … … 149 183 ((Model3DGroup)MyModel.Content).Children.Clear(); 150 184 materials.Clear(); 151 185 152 186 mouseDown = false; 153 187 startAngleX = 0; … … 158 192 if (!mouseDown) return; 159 193 var pos = e.GetPosition((IInputElement)this); 160 161 rotateX.Angle = startAngleX + (pos.X - startPos.X) / 4;162 rotateY.Angle = startAngleY + (pos.Y - startPos.Y) / 4;194 195 ((AxisAngleRotation3D)rotateX.Rotation).Angle = startAngleX + (pos.X - startPos.X) / 4; 196 ((AxisAngleRotation3D)rotateY.Rotation).Angle = startAngleY + (pos.Y - startPos.Y) / 4; 163 197 } 164 198 165 199 private void Container3DView_MouseDown(object sender, MouseButtonEventArgs e) { 166 startAngleX = rotateX.Angle;167 startAngleY = rotateY.Angle;200 startAngleX = ((AxisAngleRotation3D)rotateX.Rotation).Angle; 201 startAngleY = ((AxisAngleRotation3D)rotateY.Rotation).Angle; 168 202 this.startPos = e.GetPosition((IInputElement)this); 169 203 this.mouseDown = true; … … 189 223 Focus(); // for mouse wheel events 190 224 } 191 192 private void Container3DView_OnKeyDown(object sender, KeyEventArgs e) {193 ctrlDown = e.Key.HasFlag(Key.LeftCtrl) || e.Key.HasFlag(Key.RightCtrl);194 }195 196 225 197 226 #region helper for cubes … … 302 331 mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth)); 303 332 304 AddPlane(mesh, 0, 4, 6, 2); 305 AddPlane(mesh, 0, 3, 5, 4); 306 307 AddPlane(mesh, 4, 8, 10, 6); 308 AddPlane(mesh, 4, 7, 9, 8); 309 310 AddPlane(mesh, 8, 12, 14, 10); 311 AddPlane(mesh, 8, 11, 13, 12); 312 313 AddPlane(mesh, 0, 2, 14, 12); 314 AddPlane(mesh, 0, 12, 15, 1); 315 316 AddPlane(mesh, 0, 1, 17, 16); 317 AddPlane(mesh, 0, 16, 19, 3); 318 319 AddPlane(mesh, 4, 20, 23, 7); 320 AddPlane(mesh, 4, 5, 21, 20); 321 322 AddPlane(mesh, 8, 24, 27, 11); 323 AddPlane(mesh, 8, 9, 25, 24); 324 325 AddPlane(mesh, 12, 28, 31, 15); 326 AddPlane(mesh, 12, 13, 29, 28); 327 328 AddPlane(mesh, 16, 18, 22, 20); 329 AddPlane(mesh, 16, 20, 21, 19); 330 331 AddPlane(mesh, 20, 22, 26, 24); 332 AddPlane(mesh, 20, 24, 25, 23); 333 334 AddPlane(mesh, 24, 28, 29, 27); 335 AddPlane(mesh, 24, 26, 30, 28); 336 337 AddPlane(mesh, 28, 30, 18, 16); 338 AddPlane(mesh, 28, 16, 17, 31); 333 // Point 0, non-edge 334 mesh.Positions.Add(new Point3D(x + thickness, y, z + thickness)); 335 mesh.Positions.Add(new Point3D(x, y + thickness, z + thickness)); 336 mesh.Positions.Add(new Point3D(x + thickness, y + thickness, z)); 337 338 // Point 1, non-edge 339 mesh.Positions.Add(new Point3D(x + width, y + thickness, z + thickness)); 340 mesh.Positions.Add(new Point3D(x + width - thickness, y, z + thickness)); 341 mesh.Positions.Add(new Point3D(x + width - thickness, y + thickness, z)); 342 343 // Point 2, non-edge 344 mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + thickness)); 345 mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + thickness)); 346 mesh.Positions.Add(new Point3D(x + width - thickness, y + height - thickness, z)); 347 348 // Point 3, non-edge 349 mesh.Positions.Add(new Point3D(x, y + height - thickness, z + thickness)); 350 mesh.Positions.Add(new Point3D(x + thickness, y + height, z + thickness)); 351 mesh.Positions.Add(new Point3D(x + thickness, y + height - thickness, z)); 352 353 // Point 4, non-edge 354 mesh.Positions.Add(new Point3D(x + thickness, y, z + depth - thickness)); 355 mesh.Positions.Add(new Point3D(x, y + thickness, z + depth - thickness)); 356 mesh.Positions.Add(new Point3D(x + thickness, y + thickness, z + depth)); 357 358 // Point 5, non-edge 359 mesh.Positions.Add(new Point3D(x + width, y + thickness, z + depth - thickness)); 360 mesh.Positions.Add(new Point3D(x + width - thickness, y, z + depth - thickness)); 361 mesh.Positions.Add(new Point3D(x + width - thickness, y + thickness, z + depth)); 362 363 // Point 6, non-edge 364 mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + depth - thickness)); 365 mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + depth - thickness)); 366 mesh.Positions.Add(new Point3D(x + width - thickness, y + height - thickness, z + depth)); 367 368 // Point 7, non-edge 369 mesh.Positions.Add(new Point3D(x, y + height - thickness, z + depth - thickness)); 370 mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth - thickness)); 371 mesh.Positions.Add(new Point3D(x + thickness, y + height - thickness, z + depth)); 372 373 // Draw the 24 corner plates 374 AddPlane(mesh, 0, 1, 32, 2); 375 AddPlane(mesh, 0, 2, 33, 3); 376 AddPlane(mesh, 0, 3, 34, 1); 377 378 AddPlane(mesh, 4, 6, 36, 7); 379 AddPlane(mesh, 4, 5, 35, 6); 380 AddPlane(mesh, 4, 7, 37, 5); 381 382 AddPlane(mesh, 8, 10, 39, 11); 383 AddPlane(mesh, 8, 9, 38, 10); 384 AddPlane(mesh, 8, 11, 40, 9); 385 386 AddPlane(mesh, 12, 13, 41, 14); 387 AddPlane(mesh, 12, 14, 42, 15); 388 AddPlane(mesh, 12, 15, 43, 13); 389 390 AddPlane(mesh, 16, 18, 44, 17); 391 AddPlane(mesh, 16, 19, 45, 18); 392 AddPlane(mesh, 16, 17, 46, 19); 393 394 AddPlane(mesh, 20, 23, 48, 22); 395 AddPlane(mesh, 20, 22, 47, 21); 396 AddPlane(mesh, 20, 21, 49, 23); 397 398 AddPlane(mesh, 24, 27, 51, 26); 399 AddPlane(mesh, 24, 26, 50, 25); 400 AddPlane(mesh, 24, 25, 52, 27); 401 402 AddPlane(mesh, 28, 31, 54, 30); 403 AddPlane(mesh, 28, 30, 53, 29); 404 AddPlane(mesh, 28, 29, 55, 31); 405 406 // Draw the connecting plates 407 // on the bottom 408 AddPlane(mesh, 1, 7, 36, 32); 409 AddPlane(mesh, 1, 34, 37, 7); 410 411 AddPlane(mesh, 5, 11, 39, 35); 412 AddPlane(mesh, 5, 37, 40, 11); 413 414 AddPlane(mesh, 9, 15, 42, 38); 415 AddPlane(mesh, 9, 40, 43, 15); 416 417 AddPlane(mesh, 13, 3, 33, 41); 418 AddPlane(mesh, 13, 43, 34, 3); 419 420 // between bottom and top 421 AddPlane(mesh, 2, 32, 44, 18); 422 AddPlane(mesh, 2, 18, 45, 33); 423 424 AddPlane(mesh, 6, 22, 48, 36); 425 AddPlane(mesh, 6, 35, 47, 22); 426 427 AddPlane(mesh, 10, 26, 51, 39); 428 AddPlane(mesh, 10, 38, 50, 26); 429 430 AddPlane(mesh, 14, 30, 54, 42); 431 AddPlane(mesh, 14, 41, 53, 30); 432 433 // on the top 434 AddPlane(mesh, 17, 44, 48, 23); 435 AddPlane(mesh, 17, 23, 49, 46); 436 437 AddPlane(mesh, 21, 47, 51, 27); 438 AddPlane(mesh, 21, 27, 52, 49); 439 440 AddPlane(mesh, 25, 50, 54, 31); 441 AddPlane(mesh, 25, 31, 55, 52); 442 443 AddPlane(mesh, 29, 19, 46, 55); 444 AddPlane(mesh, 29, 53, 45, 19); 339 445 } 340 446
Note: See TracChangeset
for help on using the changeset viewer.