r"""Utility module for easy manipultions of lookup tables. This module is intended for use with by simple.py. DEPRECATED: will be removed in future releases of ParaView. """ #============================================================================== # # Program: ParaView # Module: lookuptable.py # # Copyright (c) Kitware, Inc. # All rights reserved. # See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details. # # This software is distributed WITHOUT ANY WARRANTY; without even # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the above copyright notice for more information. # #============================================================================== from __future__ import absolute_import import os from math import sqrt from . import servermanager from ._colorMaps import getColorMaps # ----------------------------------------------------------------------------- class _vtkPVLUTData: """ Internal container for ParaView lookup table data. Don't use this directly. Use vtkPVLUTReader. """ def __init__(self): self.Name="" self.Space="" self.Values=[] self.Coords=[] def SetName(self,aName): self.Name=aName def GetName(self): return self.Name def SetColorSpace(self,aSpace): self.Space=aSpace def GetColorSpace(self): return self.Space def SetRGBValues(self,aValues): self.Values=aValues def GetRGBValues(self): return self.Values def SetMapCoordinates(self,aCoords): self.Coords=aCoords # normalize the coordinates # in preparation to map onto # an arbitrary scalar range nCoords = len(self.Coords) minCoord = float(min(self.Coords)) maxCoord = float(max(self.Coords)) deltaCoord = maxCoord - minCoord if (minCoord>=maxCoord): print ('ERROR: in coordinate values') return i=0 while i ... ... ... ... ... """ def __init__(self,ns=None): self.LUTS={} self.DefaultLUT=None self.Globals=ns defaultColorMaps = getColorMaps() if defaultColorMaps: self._Read(defaultColorMaps) else: print('WARNING: default LUTs not found.') return def Clear(self): """ Clear internal data structures. """ self.LUTS={} self.DefaultLUT=None return def Read(self, aFileName): """ Read in the LUT's defined in the named file. Each call to read extends the internal list of LUTs. """ parser=servermanager.vtkPVXMLParser() parser.SetFileName(aFileName) if (not parser.Parse()): print ('ERROR: parsing lut file %s'%(aFileName)) return root=parser.GetRootElement() if root.GetName()!='ColorMaps': print ('ERROR: parsing LUT file %s'%(aFileName)) print ('ERROR: root element must be ') return return self._Read(root) def _Read(self, root): nElems=root.GetNumberOfNestedElements() i=0 nFound=0 while (i0: self.DefaultLUT=names[0] return nFound def GetLUT(self,aArray,aLutName,aRangeOveride=[]): """ Given an array and lookup table name assign the LUT to the given array and return the LUT. If aRangeOveride is specified then LUT will be mapped through that range rather than the array's actual range. """ try: self.LUTS[aLutName] except KeyError: if self.DefaultLUT is not None: print ('ERROR: No LUT named %s using %s'%(aLutName,self.DefaultLUT)) aLutName = self.DefaultLUT else: print ('ERROR: No LUT named %s and no default available.'%(aLutName)) return None range = self.__GetRange(aArray,aRangeOveride) return self.__GetLookupTableForArray(aArray, RGBPoints=self.__MapRGB(aLutName,range), ColorSpace=self.__GetColorSpace(aLutName), VectorMode='Magnitude', ScalarRangeInitialized=1.0) def GetLUTNames(self): """ Return a list of the currently available LUT's names. """ return sorted(iter(self.LUTS),cmp=lambda x,y: cmp(x.lower(), y.lower())) def Print(self): """ Print the available list of LUT's. """ names="" i=0 for k in sorted(iter(self.LUTS),cmp=lambda x,y: cmp(x.lower(), y.lower())): lut=self.LUTS[k] names+=lut.GetName() names+=", " if ((i%6)==5): names+="\n" i+=1 print (names) return # end of public interface def __GetColorSpace(self,aName): """ Return the color space from the lookup table object. """ return self.LUTS[aName].GetColorSpace() def __GetRGB(self,aName): """ Return the rgb values for the named lut """ return self.LUTS[aName] def __MapRGB(self,aName,aRange): """ Map the rgb values onto a scalar range results are an array of [x r g b] values """ colors=self.LUTS[aName].GetRGBValues() mapCoords=self.LUTS[aName].GetMapCoordinates() nColors=len(colors) coord0=float(aRange[0]) coordDelta=float(aRange[1])-float(aRange[0]) mappedColors=[] i=0 while(i