/Source/HelixToolkit.Wpf/Visual3Ds/ScreenSpaceVisuals/LinesVisual3D.cs

http://helixtoolkit.codeplex.com · C# · 92 lines · 50 code · 10 blank · 32 comment · 5 complexity · f59b76902f772f2357f89a960cf717e5 MD5 · raw file

  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="LinesVisual3D.cs" company="Helix 3D Toolkit">
  3. // http://helixtoolkit.codeplex.com, license: MIT
  4. // </copyright>
  5. // --------------------------------------------------------------------------------------------------------------------
  6. namespace HelixToolkit.Wpf
  7. {
  8. using System.Windows;
  9. /// <summary>
  10. /// A visual element that contains a set of line segments. The thickness of the lines is defined in screen space.
  11. /// </summary>
  12. public class LinesVisual3D : ScreenSpaceVisual3D
  13. {
  14. /// <summary>
  15. /// Identifies the <see cref="Thickness"/> dependency property.
  16. /// </summary>
  17. public static readonly DependencyProperty ThicknessProperty = DependencyProperty.Register(
  18. "Thickness", typeof(double), typeof(LinesVisual3D), new UIPropertyMetadata(1.0, GeometryChanged));
  19. /// <summary>
  20. /// The builder.
  21. /// </summary>
  22. private readonly LineGeometryBuilder builder;
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref = "LinesVisual3D" /> class.
  25. /// </summary>
  26. public LinesVisual3D()
  27. {
  28. this.builder = new LineGeometryBuilder(this);
  29. }
  30. /// <summary>
  31. /// Gets or sets the thickness of the lines.
  32. /// </summary>
  33. /// <value>
  34. /// The thickness.
  35. /// </value>
  36. public double Thickness
  37. {
  38. get
  39. {
  40. return (double)this.GetValue(ThicknessProperty);
  41. }
  42. set
  43. {
  44. this.SetValue(ThicknessProperty, value);
  45. }
  46. }
  47. /// <summary>
  48. /// Updates the geometry.
  49. /// </summary>
  50. protected override void UpdateGeometry()
  51. {
  52. if (this.Points == null)
  53. {
  54. this.Mesh.Positions = null;
  55. return;
  56. }
  57. int n = this.Points.Count;
  58. if (n > 0)
  59. {
  60. if (this.Mesh.TriangleIndices.Count != n * 3)
  61. {
  62. this.Mesh.TriangleIndices = this.builder.CreateIndices(n);
  63. }
  64. this.Mesh.Positions = this.builder.CreatePositions(this.Points, this.Thickness, this.DepthOffset);
  65. }
  66. else
  67. {
  68. this.Mesh.Positions = null;
  69. }
  70. }
  71. /// <summary>
  72. /// Updates the transforms.
  73. /// </summary>
  74. /// <returns>
  75. /// True if the transform is updated.
  76. /// </returns>
  77. protected override bool UpdateTransforms()
  78. {
  79. return this.builder.UpdateTransforms();
  80. }
  81. }
  82. }