Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PredicatesU1D.py « style_modules « freestyle « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 54f920d05633c634d1f31e9c3df3fa0921d3ffa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

#  Filename : PredicatesU1D.py
#  Authors  : Fredo Durand, Stephane Grabli, Francois Sillion, Emmanuel Turquin 
#  Date     : 08/04/2005
#  Purpose  : Unary predicates (functors) to be used for 1D elements

from freestyle import Curvature2DAngleF0D, CurveNatureF1D, DensityF1D, GetCompleteViewMapDensityF1D, \
    GetDirectionalViewMapDensityF1D, GetOccludersF1D, GetProjectedZF1D, GetShapeF1D, GetSteerableViewMapDensityF1D, \
    IntegrationType, ShapeUP1D, TVertex, UnaryPredicate1D
from Functions1D import pyDensityAnisotropyF1D, pyViewMapGradientNormF1D

class pyNFirstUP1D(UnaryPredicate1D):
	def __init__(self, n):
		UnaryPredicate1D.__init__(self)
		self.__n = n
		self.__count = 0
	def __call__(self, inter):
		self.__count = self.__count + 1
		if self.__count <= self.__n:
			return 1
		return 0

class pyHigherLengthUP1D(UnaryPredicate1D):
	def __init__(self,l):
		UnaryPredicate1D.__init__(self)
		self._l = l
	def __call__(self, inter):
		return (inter.length_2d > self._l)

class pyNatureUP1D(UnaryPredicate1D):
	def __init__(self,nature):
		UnaryPredicate1D.__init__(self)
		self._nature = nature
		self._getNature = CurveNatureF1D()
	def __call__(self, inter):
		if(self._getNature(inter) & self._nature):
			return 1
		return 0

class pyHigherNumberOfTurnsUP1D(UnaryPredicate1D):
	def __init__(self,n,a):
		UnaryPredicate1D.__init__(self)
		self._n = n
		self._a = a
	def __call__(self, inter):
		count = 0
		func = Curvature2DAngleF0D()
		it = inter.vertices_begin()
		while not it.is_end:
			if func(it) > self._a:
				count = count+1
			if count > self._n:
				return 1
			it.increment()
		return 0

class pyDensityUP1D(UnaryPredicate1D):
	def __init__(self,wsize,threshold, integration = IntegrationType.MEAN, sampling=2.0):
		UnaryPredicate1D.__init__(self)
		self._wsize = wsize
		self._threshold = threshold
		self._integration = integration
		self._func = DensityF1D(self._wsize, self._integration, sampling)
	def __call__(self, inter):
		if self._func(inter) < self._threshold:
			return 1
		return 0

class pyLowSteerableViewMapDensityUP1D(UnaryPredicate1D):
	def __init__(self,threshold, level,integration = IntegrationType.MEAN):
		UnaryPredicate1D.__init__(self)
		self._threshold = threshold
		self._level = level
		self._integration = integration
	def __call__(self, inter):
		func = GetSteerableViewMapDensityF1D(self._level, self._integration)
		v = func(inter)
		#print(v)
		if v < self._threshold:
			return 1
		return 0

class pyLowDirectionalViewMapDensityUP1D(UnaryPredicate1D):
	def __init__(self,threshold, orientation, level,integration = IntegrationType.MEAN):
		UnaryPredicate1D.__init__(self)
		self._threshold = threshold
		self._orientation = orientation
		self._level = level
		self._integration = integration
	def __call__(self, inter):
		func = GetDirectionalViewMapDensityF1D(self._orientation, self._level, self._integration)
		v = func(inter)
		#print(v)
		if v < self._threshold:
			return 1
		return 0

class pyHighSteerableViewMapDensityUP1D(UnaryPredicate1D):
	def __init__(self,threshold, level,integration = IntegrationType.MEAN):
		UnaryPredicate1D.__init__(self)
		self._threshold = threshold
		self._level = level
		self._integration = integration
		self._func = GetSteerableViewMapDensityF1D(self._level, self._integration)	
	def __call__(self, inter):
		v = self._func(inter)
		if v > self._threshold:
			return 1
		return 0

class pyHighDirectionalViewMapDensityUP1D(UnaryPredicate1D):
	def __init__(self,threshold, orientation, level,integration = IntegrationType.MEAN, sampling=2.0):
		UnaryPredicate1D.__init__(self)
		self._threshold = threshold
		self._orientation = orientation
		self._level = level
		self._integration = integration
		self._sampling = sampling		
	def __call__(self, inter):
		func = GetDirectionalViewMapDensityF1D(self._orientation, self._level, self._integration, self._sampling)
		v = func(inter)
		if v > self._threshold:
			return 1
		return 0

class pyHighViewMapDensityUP1D(UnaryPredicate1D):
	def __init__(self,threshold, level,integration = IntegrationType.MEAN, sampling=2.0):
		UnaryPredicate1D.__init__(self)
		self._threshold = threshold
		self._level = level
		self._integration = integration
		self._sampling = sampling
		self._func = GetCompleteViewMapDensityF1D(self._level, self._integration, self._sampling) # 2.0 is the smpling
	def __call__(self, inter):
		#print("toto")
		#print(func.name)
		#print(inter.name)
		v= self._func(inter)
		if v > self._threshold:
			return 1
		return 0

class pyDensityFunctorUP1D(UnaryPredicate1D):
	def __init__(self,wsize,threshold, functor, funcmin=0.0, funcmax=1.0, integration = IntegrationType.MEAN):
		UnaryPredicate1D.__init__(self)
		self._wsize = wsize
		self._threshold = float(threshold)
		self._functor = functor
		self._funcmin = float(funcmin)
		self._funcmax = float(funcmax)
		self._integration = integration
	def __call__(self, inter):
		func = DensityF1D(self._wsize, self._integration)
		res = self._functor(inter)
		k = (res-self._funcmin)/(self._funcmax-self._funcmin)
		if func(inter) < self._threshold*k:
			return 1
		return 0

class pyZSmallerUP1D(UnaryPredicate1D):
	def __init__(self,z, integration=IntegrationType.MEAN):
		UnaryPredicate1D.__init__(self)
		self._z = z
		self._integration = integration
	def __call__(self, inter):
		func = GetProjectedZF1D(self._integration)
		if func(inter) < self._z:
			return 1
		return 0

class pyIsOccludedByUP1D(UnaryPredicate1D):
	def __init__(self,id):
		UnaryPredicate1D.__init__(self)
		self._id = id
	def __call__(self, inter):
		func = GetShapeF1D()
		shapes = func(inter)
		for s in shapes:
			if(s.id == self._id):
				return 0
		it = inter.vertices_begin()
		itlast = inter.vertices_end()
		itlast.decrement()
		v =  it.object
		vlast = itlast.object
		tvertex = v.viewvertex
		if type(tvertex) is TVertex:
			#print("TVertex: [ ", tvertex.id.first, ",",  tvertex.id.second," ]")
			eit = tvertex.edges_begin()
			while not eit.is_end:
				ve, incoming = eit.object
				if ve.id == self._id:
					return 1
				#print("-------", ve.id.first, "-", ve.id.second)
				eit.increment()
		tvertex = vlast.viewvertex
		if type(tvertex) is TVertex:
			#print("TVertex: [ ", tvertex.id.first, ",",  tvertex.id.second," ]")
			eit = tvertex.edges_begin()
			while not eit.is_end:
				ve, incoming = eit.object
				if ve.id == self._id:
					return 1
				#print("-------", ve.id.first, "-", ve.id.second)
				eit.increment()
		return 0

class pyIsInOccludersListUP1D(UnaryPredicate1D):
	def __init__(self,id):
		UnaryPredicate1D.__init__(self)
		self._id = id
	def __call__(self, inter):
		func = GetOccludersF1D()
		occluders = func(inter)
		for a in occluders:
			if a.id == self._id:
				return 1
		return 0

class pyIsOccludedByItselfUP1D(UnaryPredicate1D):
	def __init__(self):
		UnaryPredicate1D.__init__(self)
		self.__func1 = GetOccludersF1D()
		self.__func2 = GetShapeF1D()
	def __call__(self, inter):
		lst1 = self.__func1(inter)
		lst2 = self.__func2(inter)
		for vs1 in lst1:
			for vs2 in lst2:
				if vs1.id == vs2.id:
					return 1
		return 0

class pyIsOccludedByIdListUP1D(UnaryPredicate1D):
	def __init__(self, idlist):
		UnaryPredicate1D.__init__(self)
		self._idlist = idlist
		self.__func1 = GetOccludersF1D()
	def __call__(self, inter):
		lst1 = self.__func1(inter)
		for vs1 in lst1:
			for _id in self._idlist:
				if vs1.id == _id:
					return 1
		return 0

class pyShapeIdListUP1D(UnaryPredicate1D):
	def __init__(self,idlist):
		UnaryPredicate1D.__init__(self)
		self._idlist = idlist
		self._funcs = []
		for _id in idlist :
			self._funcs.append(ShapeUP1D(_id.first, _id.second))
	def __call__(self, inter):
		for func in self._funcs :
			if func(inter) == 1:
				return 1
		return 0

## deprecated
class pyShapeIdUP1D(UnaryPredicate1D):
	def __init__(self, _id):
		UnaryPredicate1D.__init__(self)
		self._id = _id
	def __call__(self, inter):
		func = GetShapeF1D()
		shapes = func(inter)
		for a in shapes:
			if a.id == self._id:
				return 1
		return 0

class pyHighDensityAnisotropyUP1D(UnaryPredicate1D):
	def __init__(self,threshold, level, sampling=2.0):
		UnaryPredicate1D.__init__(self)
		self._l = threshold
		self.func = pyDensityAnisotropyF1D(level, IntegrationType.MEAN, sampling)
	def __call__(self, inter):
		return (self.func(inter) > self._l)

class pyHighViewMapGradientNormUP1D(UnaryPredicate1D):
	def __init__(self,threshold, l, sampling=2.0):
		UnaryPredicate1D.__init__(self)
		self._threshold = threshold
		self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN)
	def __call__(self, inter):
		gn = self._GetGradient(inter)
		#print(gn)
		return (gn > self._threshold)

class pyDensityVariableSigmaUP1D(UnaryPredicate1D):
	def __init__(self,functor, sigmaMin,sigmaMax, lmin, lmax, tmin, tmax, integration = IntegrationType.MEAN, sampling=2.0):
		UnaryPredicate1D.__init__(self)
		self._functor = functor
		self._sigmaMin = float(sigmaMin)
		self._sigmaMax = float(sigmaMax)
		self._lmin = float(lmin)
		self._lmax = float(lmax)
		self._tmin = tmin
		self._tmax = tmax
		self._integration = integration
		self._sampling = sampling
	def __call__(self, inter):
		sigma = (self._sigmaMax-self._sigmaMin)/(self._lmax-self._lmin)*(self._functor(inter)-self._lmin) + self._sigmaMin
		t = (self._tmax-self._tmin)/(self._lmax-self._lmin)*(self._functor(inter)-self._lmin) + self._tmin
		if sigma < self._sigmaMin:
			sigma = self._sigmaMin
		self._func = DensityF1D(sigma, self._integration, self._sampling)
		d = self._func(inter)
		if d < t:
			return 1
		return 0

class pyClosedCurveUP1D(UnaryPredicate1D):
	def __call__(self, inter):
		it = inter.vertices_begin()
		itlast = inter.vertices_end()
		itlast.decrement()	
		vlast = itlast.object
		v = it.object
		#print(v.id.first, v.id.second)
		#print(vlast.id.first, vlast.id.second)
		if v.id == vlast.id:
			return 1
		return 0