long_anisotropically_dense.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # Filename : long_anisotropically_dense.py
  19. # Author : Stephane Grabli
  20. # Date : 04/08/2005
  21. # Purpose : Selects the lines that are long and have a high anisotropic
  22. # a priori density and uses causal density
  23. # to draw without cluttering. Ideally, half of the
  24. # selected lines are culled using the causal density.
  25. #
  26. # ********************* WARNING *************************************
  27. # ******** The Directional a priori density maps must ******
  28. # ******** have been computed prior to using this style module ******
  29. from freestyle.chainingiterators import ChainSilhouetteIterator
  30. from freestyle.functions import DensityF1D
  31. from freestyle.predicates import (
  32. NotUP1D,
  33. QuantitativeInvisibilityUP1D,
  34. UnaryPredicate1D,
  35. pyHighDensityAnisotropyUP1D,
  36. pyHigherLengthUP1D,
  37. pyLengthBP1D,
  38. )
  39. from freestyle.shaders import (
  40. ConstantColorShader,
  41. ConstantThicknessShader,
  42. SamplingShader,
  43. )
  44. from freestyle.types import IntegrationType, Operators
  45. ## custom density predicate
  46. class pyDensityUP1D(UnaryPredicate1D):
  47. def __init__(self, wsize, threshold, integration=IntegrationType.MEAN, sampling=2.0):
  48. UnaryPredicate1D.__init__(self)
  49. self._wsize = wsize
  50. self._threshold = threshold
  51. self._integration = integration
  52. self._func = DensityF1D(self._wsize, self._integration, sampling)
  53. self._func2 = DensityF1D(self._wsize, IntegrationType.MAX, sampling)
  54. def __call__(self, inter):
  55. c = self._func(inter)
  56. m = self._func2(inter)
  57. if c < self._threshold:
  58. return 1
  59. if m > 4*c:
  60. if c < 1.5*self._threshold:
  61. return 1
  62. return 0
  63. Operators.select(QuantitativeInvisibilityUP1D(0))
  64. Operators.bidirectional_chain(ChainSilhouetteIterator(),NotUP1D(QuantitativeInvisibilityUP1D(0)))
  65. Operators.select(pyHigherLengthUP1D(40))
  66. ## selects lines having a high anisotropic a priori density
  67. Operators.select(pyHighDensityAnisotropyUP1D(0.3,4))
  68. Operators.sort(pyLengthBP1D())
  69. shaders_list = [
  70. SamplingShader(2.0),
  71. ConstantThicknessShader(2),
  72. ConstantColorShader(0.2,0.2,0.25,1),
  73. ]
  74. ## uniform culling
  75. Operators.create(pyDensityUP1D(3.0,2.0e-2, IntegrationType.MEAN, 0.1), shaders_list)