agg_gamma_functions.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //----------------------------------------------------------------------------
  2. // Anti-Grain Geometry - Version 2.4
  3. // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
  4. //
  5. // C# port by: Lars Brubaker
  6. // larsbrubaker@gmail.com
  7. // Copyright (C) 2007
  8. //
  9. // Permission to copy, use, modify, sell and distribute this software
  10. // is granted provided this copyright notice appears in all copies.
  11. // This software is provided "as is" without express or implied
  12. // warranty, and with no claim as to its suitability for any purpose.
  13. //
  14. //----------------------------------------------------------------------------
  15. // Contact: mcseem@antigrain.com
  16. // mcseemagg@yahoo.com
  17. // http://www.antigrain.com
  18. //----------------------------------------------------------------------------
  19. using System;
  20. namespace MatterHackers.Agg
  21. {
  22. public interface IGammaFunction
  23. {
  24. double GetGamma(double x);
  25. }
  26. public struct gamma_none : IGammaFunction
  27. {
  28. public double GetGamma(double x)
  29. {
  30. return x;
  31. }
  32. }
  33. //==============================================================gamma_power
  34. public class gamma_power : IGammaFunction
  35. {
  36. public gamma_power()
  37. {
  38. m_gamma = 1.0;
  39. }
  40. public gamma_power(double g)
  41. {
  42. m_gamma = g;
  43. }
  44. public void gamma(double g)
  45. {
  46. m_gamma = g;
  47. }
  48. public double gamma()
  49. {
  50. return m_gamma;
  51. }
  52. public double GetGamma(double x)
  53. {
  54. return Math.Pow(x, m_gamma);
  55. }
  56. private double m_gamma;
  57. }
  58. //==========================================================gamma_threshold
  59. public class gamma_threshold : IGammaFunction
  60. {
  61. public gamma_threshold()
  62. {
  63. m_threshold = 0.5;
  64. }
  65. public gamma_threshold(double t)
  66. {
  67. m_threshold = t;
  68. }
  69. public void threshold(double t)
  70. {
  71. m_threshold = t;
  72. }
  73. public double threshold()
  74. {
  75. return m_threshold;
  76. }
  77. public double GetGamma(double x)
  78. {
  79. return (x < m_threshold) ? 0.0 : 1.0;
  80. }
  81. private double m_threshold;
  82. }
  83. //============================================================gamma_linear
  84. public class gamma_linear : IGammaFunction
  85. {
  86. public gamma_linear()
  87. {
  88. m_start = (0.0);
  89. m_end = (1.0);
  90. }
  91. public gamma_linear(double s, double e)
  92. {
  93. m_start = (s);
  94. m_end = (e);
  95. }
  96. public void set(double s, double e)
  97. {
  98. m_start = s; m_end = e;
  99. }
  100. public void start(double s)
  101. {
  102. m_start = s;
  103. }
  104. public void end(double e)
  105. {
  106. m_end = e;
  107. }
  108. public double start()
  109. {
  110. return m_start;
  111. }
  112. public double end()
  113. {
  114. return m_end;
  115. }
  116. public double GetGamma(double x)
  117. {
  118. if (x < m_start) return 0.0;
  119. if (x > m_end) return 1.0;
  120. double EndMinusStart = m_end - m_start;
  121. if (EndMinusStart != 0)
  122. return (x - m_start) / EndMinusStart;
  123. else
  124. return 0.0;
  125. }
  126. private double m_start;
  127. private double m_end;
  128. }
  129. //==========================================================gamma_multiply
  130. public class gamma_multiply : IGammaFunction
  131. {
  132. public gamma_multiply()
  133. {
  134. m_mul = (1.0);
  135. }
  136. public gamma_multiply(double v)
  137. {
  138. m_mul = (v);
  139. }
  140. public void value(double v)
  141. {
  142. m_mul = v;
  143. }
  144. public double value()
  145. {
  146. return m_mul;
  147. }
  148. public double GetGamma(double x)
  149. {
  150. double y = x * m_mul;
  151. if (y > 1.0) y = 1.0;
  152. return y;
  153. }
  154. private double m_mul;
  155. }
  156. }