OLD | NEW |
(Empty) | |
| 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 from Freestyle import Curvature2DAngleF0D, CurvePoint, ReadCompleteViewMapPixelF
0D, \ |
| 20 ReadSteerableViewMapPixelF0D, UnaryFunction0DDouble, UnaryFunction0DMaterial
, \ |
| 21 UnaryFunction0DVec2f |
| 22 from Freestyle import ContextFunctions as CF |
| 23 |
| 24 import math |
| 25 import mathutils |
| 26 |
| 27 class CurveMaterialF0D(UnaryFunction0DMaterial): |
| 28 # A replacement of the built-in MaterialF0D for stroke creation. |
| 29 # MaterialF0D does not work with Curves and Strokes. |
| 30 def __call__(self, inter): |
| 31 cp = inter.object |
| 32 assert(isinstance(cp, CurvePoint)) |
| 33 fe = cp.first_svertex.get_fedge(cp.second_svertex) |
| 34 assert(fe is not None) |
| 35 return fe.material if fe.is_smooth else fe.material_left |
| 36 |
| 37 class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble): |
| 38 def __call__(self, inter): |
| 39 func = Curvature2DAngleF0D() |
| 40 c = func(inter) |
| 41 return (3.1415 - c) |
| 42 |
| 43 class pyCurvilinearLengthF0D(UnaryFunction0DDouble): |
| 44 def __call__(self, inter): |
| 45 cp = inter.object··············· |
| 46 assert(isinstance(cp, CurvePoint)) |
| 47 return cp.t2d |
| 48 |
| 49 ## estimate anisotropy of density |
| 50 class pyDensityAnisotropyF0D(UnaryFunction0DDouble): |
| 51 def __init__(self,level): |
| 52 UnaryFunction0DDouble.__init__(self) |
| 53 self.IsoDensity = ReadCompleteViewMapPixelF0D(level) |
| 54 self.d0Density = ReadSteerableViewMapPixelF0D(0, level) |
| 55 self.d1Density = ReadSteerableViewMapPixelF0D(1, level) |
| 56 self.d2Density = ReadSteerableViewMapPixelF0D(2, level) |
| 57 self.d3Density = ReadSteerableViewMapPixelF0D(3, level) |
| 58 def __call__(self, inter): |
| 59 c_iso = self.IsoDensity(inter)· |
| 60 c_0 = self.d0Density(inter)· |
| 61 c_1 = self.d1Density(inter)· |
| 62 c_2 = self.d2Density(inter)· |
| 63 c_3 = self.d3Density(inter)· |
| 64 cMax = max(max(c_0,c_1), max(c_2,c_3)) |
| 65 cMin = min(min(c_0,c_1), min(c_2,c_3)) |
| 66 if c_iso == 0: |
| 67 v = 0 |
| 68 else: |
| 69 v = (cMax-cMin)/c_iso |
| 70 return v |
| 71 |
| 72 ## Returns the gradient vector for a pixel· |
| 73 ## l |
| 74 ## the level at which one wants to compute the gradient |
| 75 class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f): |
| 76 def __init__(self, l): |
| 77 UnaryFunction0DVec2f.__init__(self) |
| 78 self._l = l |
| 79 self._step = math.pow(2,self._l) |
| 80 def __call__(self, iter): |
| 81 p = iter.object.point_2d |
| 82 gx = CF.read_complete_view_map_pixel(self._l, int(p.x+self._step
), int(p.y)) - \ |
| 83 CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) |
| 84 gy = CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y+
self._step)) - \ |
| 85 CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) |
| 86 return mathutils.Vector([gx, gy]) |
| 87 |
| 88 class pyViewMapGradientNormF0D(UnaryFunction0DDouble): |
| 89 def __init__(self, l): |
| 90 UnaryFunction0DDouble.__init__(self) |
| 91 self._l = l |
| 92 self._step = math.pow(2,self._l) |
| 93 def __call__(self, iter): |
| 94 p = iter.object.point_2d |
| 95 gx = CF.read_complete_view_map_pixel(self._l, int(p.x+self._step
), int(p.y)) - \ |
| 96 CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) |
| 97 gy = CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y+
self._step)) - \ |
| 98 CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) |
| 99 grad = mathutils.Vector([gx, gy]) |
| 100 return grad.length |
OLD | NEW |