/Controls/HelixToolkit.Wpf/Visual3Ds/MeshVisuals/TruncatedConeVisual3D.cs

https://bitbucket.org/kubrakms/thermalconductivity · C# · 236 lines · 138 code · 32 blank · 66 comment · 0 complexity · d8ed2503c8e0a0d4234aa4bd2e62ba23 MD5 · raw file

  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="TruncatedConeVisual3D.cs" company="Helix 3D Toolkit">
  3. // http://helixtoolkit.codeplex.com, license: Ms-PL
  4. // </copyright>
  5. // --------------------------------------------------------------------------------------------------------------------
  6. namespace HelixToolkit.Wpf
  7. {
  8. using System.Windows;
  9. using System.Windows.Media.Media3D;
  10. /// <summary>
  11. /// A visual element that shows a truncated cone defined by origin, height, normal, base- and top radius.
  12. /// </summary>
  13. public class TruncatedConeVisual3D : MeshElement3D
  14. {
  15. #region Constants and Fields
  16. /// <summary>
  17. /// The base cap property.
  18. /// </summary>
  19. public static readonly DependencyProperty BaseCapProperty = DependencyProperty.Register(
  20. "BaseCap", typeof(bool), typeof(TruncatedConeVisual3D), new UIPropertyMetadata(true, GeometryChanged));
  21. /// <summary>
  22. /// The base radius property.
  23. /// </summary>
  24. public static readonly DependencyProperty BaseRadiusProperty = DependencyProperty.Register(
  25. "BaseRadius", typeof(double), typeof(TruncatedConeVisual3D), new PropertyMetadata(1.0, GeometryChanged));
  26. /// <summary>
  27. /// The height property.
  28. /// </summary>
  29. public static readonly DependencyProperty HeightProperty = DependencyProperty.Register(
  30. "Height", typeof(double), typeof(TruncatedConeVisual3D), new PropertyMetadata(2.0, GeometryChanged));
  31. /// <summary>
  32. /// The normal property.
  33. /// </summary>
  34. public static readonly DependencyProperty NormalProperty = DependencyProperty.Register(
  35. "Normal",
  36. typeof(Vector3D),
  37. typeof(TruncatedConeVisual3D),
  38. new PropertyMetadata(new Vector3D(0, 0, 1), GeometryChanged));
  39. /// <summary>
  40. /// The origin property.
  41. /// </summary>
  42. public static readonly DependencyProperty OriginProperty = DependencyProperty.Register(
  43. "Origin",
  44. typeof(Point3D),
  45. typeof(TruncatedConeVisual3D),
  46. new PropertyMetadata(new Point3D(0, 0, 0), GeometryChanged));
  47. /// <summary>
  48. /// The theta div property.
  49. /// </summary>
  50. public static readonly DependencyProperty ThetaDivProperty = DependencyProperty.Register(
  51. "ThetaDiv", typeof(int), typeof(TruncatedConeVisual3D), new PropertyMetadata(35, GeometryChanged));
  52. /// <summary>
  53. /// The top cap property.
  54. /// </summary>
  55. public static readonly DependencyProperty TopCapProperty = DependencyProperty.Register(
  56. "TopCap", typeof(bool), typeof(TruncatedConeVisual3D), new UIPropertyMetadata(true, GeometryChanged));
  57. /// <summary>
  58. /// The top radius property.
  59. /// </summary>
  60. public static readonly DependencyProperty TopRadiusProperty = DependencyProperty.Register(
  61. "TopRadius", typeof(double), typeof(TruncatedConeVisual3D), new PropertyMetadata(0.0, GeometryChanged));
  62. #endregion
  63. #region Public Properties
  64. /// <summary>
  65. /// Gets or sets a value indicating whether to include a base cap.
  66. /// </summary>
  67. public bool BaseCap
  68. {
  69. get
  70. {
  71. return (bool)this.GetValue(BaseCapProperty);
  72. }
  73. set
  74. {
  75. this.SetValue(BaseCapProperty, value);
  76. }
  77. }
  78. /// <summary>
  79. /// Gets or sets the base radius.
  80. /// </summary>
  81. /// <value>The base radius.</value>
  82. public double BaseRadius
  83. {
  84. get
  85. {
  86. return (double)this.GetValue(BaseRadiusProperty);
  87. }
  88. set
  89. {
  90. this.SetValue(BaseRadiusProperty, value);
  91. }
  92. }
  93. /// <summary>
  94. /// Gets or sets the height.
  95. /// </summary>
  96. /// <value>The height.</value>
  97. public double Height
  98. {
  99. get
  100. {
  101. return (double)this.GetValue(HeightProperty);
  102. }
  103. set
  104. {
  105. this.SetValue(HeightProperty, value);
  106. }
  107. }
  108. /// <summary>
  109. /// Gets or sets the normal.
  110. /// </summary>
  111. /// <value>The normal.</value>
  112. public Vector3D Normal
  113. {
  114. get
  115. {
  116. return (Vector3D)this.GetValue(NormalProperty);
  117. }
  118. set
  119. {
  120. this.SetValue(NormalProperty, value);
  121. }
  122. }
  123. /// <summary>
  124. /// Gets or sets the origin.
  125. /// </summary>
  126. /// <value>The origin.</value>
  127. public Point3D Origin
  128. {
  129. get
  130. {
  131. return (Point3D)this.GetValue(OriginProperty);
  132. }
  133. set
  134. {
  135. this.SetValue(OriginProperty, value);
  136. }
  137. }
  138. /// <summary>
  139. /// Gets or sets the theta div.
  140. /// </summary>
  141. /// <value>The theta div.</value>
  142. public int ThetaDiv
  143. {
  144. get
  145. {
  146. return (int)this.GetValue(ThetaDivProperty);
  147. }
  148. set
  149. {
  150. this.SetValue(ThetaDivProperty, value);
  151. }
  152. }
  153. /// <summary>
  154. /// Gets or sets a value indicating whether to include a top cap.
  155. /// </summary>
  156. public bool TopCap
  157. {
  158. get
  159. {
  160. return (bool)this.GetValue(TopCapProperty);
  161. }
  162. set
  163. {
  164. this.SetValue(TopCapProperty, value);
  165. }
  166. }
  167. /// <summary>
  168. /// Gets or sets the top radius.
  169. /// </summary>
  170. /// <value>The top radius.</value>
  171. public double TopRadius
  172. {
  173. get
  174. {
  175. return (double)this.GetValue(TopRadiusProperty);
  176. }
  177. set
  178. {
  179. this.SetValue(TopRadiusProperty, value);
  180. }
  181. }
  182. #endregion
  183. #region Methods
  184. /// <summary>
  185. /// Do the tesselation and return the <see cref="MeshGeometry3D"/>.
  186. /// </summary>
  187. /// <returns>A triangular mesh geometry.</returns>
  188. protected override MeshGeometry3D Tessellate()
  189. {
  190. var builder = new MeshBuilder(false,false);
  191. builder.AddCone(
  192. this.Origin,
  193. this.Normal,
  194. this.BaseRadius,
  195. this.TopRadius,
  196. this.Height,
  197. this.BaseCap,
  198. this.TopCap,
  199. this.ThetaDiv);
  200. return builder.ToMesh();
  201. }
  202. #endregion
  203. }
  204. }