1
# ##### BEGIN GPL LICENSE BLOCK #####
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.
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.
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.
17
# ##### END GPL LICENSE BLOCK #####
19
# Filename : Functions0D.py
20
# Authors : Fredo Durand, Stephane Grabli, Francois Sillion, Emmanuel Turquin
22
# Purpose : Functions (functors) to be used for 0D elements
24
from freestyle import Curvature2DAngleF0D, CurvePoint, ReadCompleteViewMapPixelF0D, \
25
ReadSteerableViewMapPixelF0D, UnaryFunction0DDouble, UnaryFunction0DMaterial, \
27
from freestyle import ContextFunctions as CF
32
class CurveMaterialF0D(UnaryFunction0DMaterial):
33
# A replacement of the built-in MaterialF0D for stroke creation.
34
# MaterialF0D does not work with Curves and Strokes.
35
def __call__(self, inter):
37
assert(isinstance(cp, CurvePoint))
38
fe = cp.first_svertex.get_fedge(cp.second_svertex)
39
assert(fe is not None)
40
return fe.material if fe.is_smooth else fe.material_left
42
class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble):
43
def __call__(self, inter):
44
func = Curvature2DAngleF0D()
48
class pyCurvilinearLengthF0D(UnaryFunction0DDouble):
49
def __call__(self, inter):
51
assert(isinstance(cp, CurvePoint))
54
## estimate anisotropy of density
55
class pyDensityAnisotropyF0D(UnaryFunction0DDouble):
56
def __init__(self,level):
57
UnaryFunction0DDouble.__init__(self)
58
self.IsoDensity = ReadCompleteViewMapPixelF0D(level)
59
self.d0Density = ReadSteerableViewMapPixelF0D(0, level)
60
self.d1Density = ReadSteerableViewMapPixelF0D(1, level)
61
self.d2Density = ReadSteerableViewMapPixelF0D(2, level)
62
self.d3Density = ReadSteerableViewMapPixelF0D(3, level)
63
def __call__(self, inter):
64
c_iso = self.IsoDensity(inter)
65
c_0 = self.d0Density(inter)
66
c_1 = self.d1Density(inter)
67
c_2 = self.d2Density(inter)
68
c_3 = self.d3Density(inter)
69
cMax = max(max(c_0,c_1), max(c_2,c_3))
70
cMin = min(min(c_0,c_1), min(c_2,c_3))
77
## Returns the gradient vector for a pixel
79
## the level at which one wants to compute the gradient
80
class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f):
81
def __init__(self, l):
82
UnaryFunction0DVec2f.__init__(self)
84
self._step = math.pow(2,self._l)
85
def __call__(self, iter):
86
p = iter.object.point_2d
87
gx = CF.read_complete_view_map_pixel(self._l, int(p.x+self._step), int(p.y)) - \
88
CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y))
89
gy = CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y+self._step)) - \
90
CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y))
91
return mathutils.Vector([gx, gy])
93
class pyViewMapGradientNormF0D(UnaryFunction0DDouble):
94
def __init__(self, l):
95
UnaryFunction0DDouble.__init__(self)
97
self._step = math.pow(2,self._l)
98
def __call__(self, iter):
99
p = iter.object.point_2d
100
gx = CF.read_complete_view_map_pixel(self._l, int(p.x+self._step), int(p.y)) - \
101
CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y))
102
gy = CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y+self._step)) - \
103
CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y))
104
grad = mathutils.Vector([gx, gy])