Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/freestyle/modules/freestyle/functions.py
| Context not available. | |||||
| from mathutils import Vector | from mathutils import Vector | ||||
| # -- Functions for 0D elements (vertices) -- # | # -- Functions for 0D elements (vertices) -- # | ||||
| class CurveMaterialF0D(UnaryFunction0DMaterial): | class CurveMaterialF0D(UnaryFunction0DMaterial): | ||||
| """ | """ | ||||
| A replacement of the built-in MaterialF0D for stroke creation. | A replacement of the built-in MaterialF0D for stroke creation. | ||||
| MaterialF0D does not work with Curves and Strokes. Line color | MaterialF0D does not work with Curves and Strokes. Line color | ||||
| priority is used to pick one of the two materials at material | priority is used to pick one of the two materials at material | ||||
| boundaries. | boundaries. | ||||
| Note: expects instances of CurvePoint to be iterated over | |||||
| """ | """ | ||||
kjym3: Is there any reason to comment this assertion? | |||||
Not Done Inline Actionswell, is this assertion needed? I've added a comment to describe the input it expects, and if an incorrect object is given, line 106 will raise a correct error (AttributeError, I think) The thing here is that every object is checked, and this function is called many times in loops. (isinstance also needs to find out that StrokeVertex is a subclass of Curvepoint for every call), so removing this assertion has a, albeit small, advantage speedwise. flokkievids: well, is this assertion needed?
I've added a comment to describe the input it expects, and if… | |||||
Not Done Inline ActionsOk, the rationale sounds fine to me. kjym3: Ok, the rationale sounds fine to me. | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| cp = inter.object | #assert(isinstance(cp, CurvePoint)) | ||||
| assert(isinstance(cp, CurvePoint)) | #fe = inter.object.fedge | ||||
| fe = cp.first_svertex.get_fedge(cp.second_svertex) | fe = inter.object.first_svertex.get_fedge(inter.object.second_svertex) | ||||
| assert(fe is not None), "CurveMaterialF0D: fe is None" | assert(fe is not None), "CurveMaterialF0D: fe is None" | ||||
| if fe.is_smooth: | if fe.is_smooth: | ||||
| return fe.material | return fe.material | ||||
| elif fe.material_right.priority > fe.material_left.priority: | |||||
| return fe.material_right | |||||
| else: | else: | ||||
| return fe.material_left | right, left = fe.material_right, fe.material_left | ||||
| return right if (right.priority > left.priority) else left | |||||
| class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble): | class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble): | ||||
| Context not available. | |||||
| class pyDensityAnisotropyF0D(UnaryFunction0DDouble): | class pyDensityAnisotropyF0D(UnaryFunction0DDouble): | ||||
| """Estimates the anisotropy of density""" | """Estimates the anisotropy of density""" | ||||
| def __init__(self,level): | def __init__(self, level): | ||||
| UnaryFunction0DDouble.__init__(self) | UnaryFunction0DDouble.__init__(self) | ||||
| self.IsoDensity = ReadCompleteViewMapPixelF0D(level) | self.IsoDensity = ReadCompleteViewMapPixelF0D(level) | ||||
| self.d0Density = ReadSteerableViewMapPixelF0D(0, level) | self.d0Density = ReadSteerableViewMapPixelF0D(0, level) | ||||
| Context not available. | |||||
| c_1 = self.d1Density(inter) | c_1 = self.d1Density(inter) | ||||
| c_2 = self.d2Density(inter) | c_2 = self.d2Density(inter) | ||||
| c_3 = self.d3Density(inter) | c_3 = self.d3Density(inter) | ||||
| cMax = max(max(c_0,c_1), max(c_2,c_3)) | cMax = max(max(c_0, c_1), max(c_2, c_3)) | ||||
| cMin = min(min(c_0,c_1), min(c_2,c_3)) | cMin = min(min(c_0, c_1), min(c_2, c_3)) | ||||
| return 0 if (c_iso == 0) else (cMax-cMin) / c_iso | return 0 if (c_iso == 0) else (cMax - cMin) / c_iso | ||||
| class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f): | class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f): | ||||
| Context not available. | |||||
| def __call__(self, iter): | def __call__(self, iter): | ||||
| p = iter.object.point_2d | p = iter.object.point_2d | ||||
| gx = CF.read_complete_view_map_pixel(self._l, int(p.x+self._step), int(p.y)) - \ | gx = CF.read_complete_view_map_pixel(self._l, int(p.x + self._step), int(p.y)) - \ | ||||
| CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) | CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) | ||||
| gy = CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y+self._step)) - \ | gy = CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y + self._step)) - \ | ||||
| CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) | CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) | ||||
| return Vector((gx, gy)) | return Vector((gx, gy)) | ||||
| Context not available. | |||||
| CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) | CF.read_complete_view_map_pixel(self._l, int(p.x), int(p.y)) | ||||
| return Vector((gx, gy)).length | return Vector((gx, gy)).length | ||||
| # -- Functions for 1D elements (curves) -- # | # -- Functions for 1D elements (curves) -- # | ||||
| Context not available. | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = GetProjectedZF1D() | func = GetProjectedZF1D() | ||||
| z = func(inter) | z = func(inter) | ||||
| return (1.0 - z*z) | return (1.0 - pow(z, 2)) | ||||
| class pyDensityAnisotropyF1D(UnaryFunction1DDouble): | class pyDensityAnisotropyF1D(UnaryFunction1DDouble): | ||||
| def __init__(self,level, integrationType=IntegrationType.MEAN, sampling=2.0): | def __init__(self, level, integrationType=IntegrationType.MEAN, sampling=2.0): | ||||
| UnaryFunction1DDouble.__init__(self, integrationType) | UnaryFunction1DDouble.__init__(self, integrationType) | ||||
| self._func = pyDensityAnisotropyF0D(level) | self._func = pyDensityAnisotropyF0D(level) | ||||
| self._integration = integrationType | self._integration = integrationType | ||||
| Context not available. | |||||
| class pyViewMapGradientNormF1D(UnaryFunction1DDouble): | class pyViewMapGradientNormF1D(UnaryFunction1DDouble): | ||||
| def __init__(self,l, integrationType, sampling=2.0): | def __init__(self, l, integrationType, sampling=2.0): | ||||
| UnaryFunction1DDouble.__init__(self, integrationType) | UnaryFunction1DDouble.__init__(self, integrationType) | ||||
| self._func = pyViewMapGradientNormF0D(l) | self._func = pyViewMapGradientNormF0D(l) | ||||
| self._integration = integrationType | self._integration = integrationType | ||||
| Context not available. | |||||
Is there any reason to comment this assertion?