@@ -285,16 +285,16 @@ def __call__(self, uv):
285
285
converted_cmaps = {}
286
286
temp = []
287
287
288
- def vtk_cmap (cmap ):
289
- if isinstance (cmap , str ):
288
+ def as_vtk_cmap (cmap , cache = True ):
289
+ if cache and isinstance (cmap , str ):
290
290
if cmap in converted_cmaps :
291
291
return converted_cmaps [cmap ]
292
292
cmap = cm .get_cmap (cmap )
293
293
294
294
if isinstance (cmap , vtk .vtkLookupTable ):
295
295
return cmap
296
296
297
- if isinstance (cmap , (colors .ListedColormap , colors .LinearSegmentedColormap )):
297
+ if cache and isinstance (cmap , (colors .ListedColormap , colors .LinearSegmentedColormap )):
298
298
name = cmap .name
299
299
if name in converted_cmaps :
300
300
return converted_cmaps [name ]
@@ -316,44 +316,44 @@ def vtk_cmap(cmap):
316
316
table .SetTable (numpy_to_vtk (cmap ))
317
317
318
318
temp .append (cmap )
319
- # if name is not None:
320
- # converted_cmaps[name] = table
319
+ if name is not None :
320
+ converted_cmaps [name ] = table
321
321
return table
322
322
323
323
else :
324
- raise ValueError ()
324
+ raise ValueError ("`cmap` should have shape (n, 3) or (n, 4). Received {}." . format ( cmap . shape ) )
325
325
326
326
327
327
328
328
329
329
330
330
331
- if __name__ == "__main__" :
332
- import vtkplotlib as vpl
333
- for args in [((.3 , .4 , .6 ), .2 ),
334
- ([5 , 8 , 10 ], None ),
335
- ("red" , ),
336
- ("orange red" , .5 ),
337
- ("Orange_Red" , ),
338
- ("or33ange_rEd" , ),
339
- ]:
340
- print ("process_color" , args , "->" , process_color (* args ), "\n " )
341
-
342
- path = Path ('C:/Users/Brénainn/Downloads/3dm/duck/Bird_v1_L2.123ca5dbb1bc-8ef6-44e4-b558-3e6e2bbc7dd7/12248_Bird_v1_diff.jpg' )
343
-
344
- self = TextureMap (path )
345
- self .interpolate = True
346
-
347
- n = 1000
348
- t = np .linspace (0 , 1 , n )
349
- uv = vpl .nuts_and_bolts .zip_axes (* np .meshgrid (t , t ))
350
-
351
- # plt.figure(figsize=(n // 72,) * 2)
352
- # plt.imshow(self(uv))
353
- # plt.show()
354
-
355
- from PIL import Image
356
- im = Image .fromarray ((self (uv ) * 255 ).astype (np .uint8 ))
331
+ # if __name__ == "__main__":
332
+ # import vtkplotlib as vpl
333
+ # for args in [((.3, .4, .6), .2),
334
+ # ([5, 8, 10], None),
335
+ # ("red", ),
336
+ # ("orange red", .5),
337
+ # ("Orange_Red", ),
338
+ # ("or33ange_rEd", ),
339
+ # ]:
340
+ # print("process_color", args, "->", process_color(*args), "\n")
341
+ #
342
+ # path = Path('C:/Users/Brénainn/Downloads/3dm/duck/Bird_v1_L2.123ca5dbb1bc-8ef6-44e4-b558-3e6e2bbc7dd7/12248_Bird_v1_diff.jpg')
343
+ #
344
+ # self = TextureMap(path)
345
+ # self.interpolate = True
346
+ #
347
+ # n = 1000
348
+ # t = np.linspace(0, 1, n)
349
+ # uv = vpl.nuts_and_bolts.zip_axes(*np.meshgrid(t, t))
350
+ #
351
+ ## plt.figure(figsize=(n // 72,) * 2)
352
+ ## plt.imshow(self(uv))
353
+ ## plt.show()
354
+ #
355
+ # from PIL import Image
356
+ # im = Image.fromarray((self(uv) * 255).astype(np.uint8))
357
357
# im.show()
358
358
359
359
# cmap = plt.get_cmap("Blues")
0 commit comments