@@ -285,16 +285,16 @@ def __call__(self, uv):
285285converted_cmaps = {}
286286temp = []
287287
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 ):
290290 if cmap in converted_cmaps :
291291 return converted_cmaps [cmap ]
292292 cmap = cm .get_cmap (cmap )
293293
294294 if isinstance (cmap , vtk .vtkLookupTable ):
295295 return cmap
296296
297- if isinstance (cmap , (colors .ListedColormap , colors .LinearSegmentedColormap )):
297+ if cache and isinstance (cmap , (colors .ListedColormap , colors .LinearSegmentedColormap )):
298298 name = cmap .name
299299 if name in converted_cmaps :
300300 return converted_cmaps [name ]
@@ -316,44 +316,44 @@ def vtk_cmap(cmap):
316316 table .SetTable (numpy_to_vtk (cmap ))
317317
318318 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
321321 return table
322322
323323 else :
324- raise ValueError ()
324+ raise ValueError ("`cmap` should have shape (n, 3) or (n, 4). Received {}." . format ( cmap . shape ) )
325325
326326
327327
328328
329329
330330
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))
357357# im.show()
358358
359359# cmap = plt.get_cmap("Blues")
0 commit comments