~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to release/scripts/freestyle/style_modules/Functions0D.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
#  Filename : Functions0D.py
 
20
#  Authors  : Fredo Durand, Stephane Grabli, Francois Sillion, Emmanuel Turquin 
 
21
#  Date     : 30/06/2005
 
22
#  Purpose  : Functions (functors) to be used for 0D elements
 
23
 
 
24
from freestyle import Curvature2DAngleF0D, CurvePoint, ReadCompleteViewMapPixelF0D, \
 
25
    ReadSteerableViewMapPixelF0D, UnaryFunction0DDouble, UnaryFunction0DMaterial, \
 
26
    UnaryFunction0DVec2f
 
27
from freestyle import ContextFunctions as CF
 
28
 
 
29
import math
 
30
import mathutils
 
31
 
 
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):
 
36
                cp = inter.object
 
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
 
41
 
 
42
class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble):
 
43
        def __call__(self, inter):
 
44
                func = Curvature2DAngleF0D()
 
45
                c = func(inter)
 
46
                return (3.1415 - c)
 
47
 
 
48
class pyCurvilinearLengthF0D(UnaryFunction0DDouble):
 
49
        def __call__(self, inter):
 
50
                cp = inter.object               
 
51
                assert(isinstance(cp, CurvePoint))
 
52
                return cp.t2d
 
53
 
 
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))
 
71
                if c_iso == 0:
 
72
                        v = 0
 
73
                else:
 
74
                        v = (cMax-cMin)/c_iso
 
75
                return v
 
76
 
 
77
## Returns the gradient vector for a pixel 
 
78
##      l
 
79
##        the level at which one wants to compute the gradient
 
80
class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f):
 
81
        def __init__(self, l):
 
82
                UnaryFunction0DVec2f.__init__(self)
 
83
                self._l = l
 
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])
 
92
 
 
93
class pyViewMapGradientNormF0D(UnaryFunction0DDouble):
 
94
        def __init__(self, l):
 
95
                UnaryFunction0DDouble.__init__(self)
 
96
                self._l = l
 
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])
 
105
                return grad.length