Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1271 colormap on object #1523

Merged
merged 10 commits into from Sep 15, 2015
2 changes: 1 addition & 1 deletion Packages/vcs/Lib/Canvas.py
Expand Up @@ -865,7 +865,7 @@ def __init__(self, gui=0, mode=1, pause_time=0,
self._canvas_id = vcs.next_canvas_id
self.ParameterChanged = SIGNAL('ParameterChanged')
vcs.next_canvas_id += 1
self.colormap = "default"
self.colormap = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not leave it to "default"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are three spots where cmap can be set, so I need to know if user did set it or not.

self.backgroundcolor = 255, 255, 255
# default size for bg
self.bgX = 814
Expand Down
14 changes: 9 additions & 5 deletions Packages/vcs/Lib/VTKPlots.py
Expand Up @@ -462,7 +462,7 @@ def plot(self, data1, data2, template, gtype, gname, bg, *args, **kargs):

pipeline = vcsvtk.createPipeline(gm, self)
if pipeline is not None:
returned.update(pipeline.plot(data1, data2, tpl, gm,
returned.update(pipeline.plot(data1, data2, tpl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice..

vtk_backend_grid, vtk_backend_geo))
elif gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"]:
cdms_file = kargs.get('cdmsfile', None)
Expand All @@ -486,11 +486,13 @@ def plot(self, data1, data2, template, gtype, gname, bg, *args, **kargs):
returned["vtk_backend_text_actors"] = vcs2vtk.genTextActor(
ren,
to=to,
tt=tt)
tt=tt,
cmap=self.canvas.colormap)
self.setLayer(ren, tt.priority)
elif gtype == "line":
if gm.priority != 0:
actors = vcs2vtk.prepLine(self.renWin, gm)
actors = vcs2vtk.prepLine(self.renWin, gm,
cmap=self.canvas.colormap)
returned["vtk_backend_line_actors"] = actors
for act, geo in actors:
ren = self.fitToViewport(
Expand All @@ -502,7 +504,8 @@ def plot(self, data1, data2, template, gtype, gname, bg, *args, **kargs):
create_renderer=True)
elif gtype == "marker":
if gm.priority != 0:
actors = vcs2vtk.prepMarker(self.renWin, gm)
actors = vcs2vtk.prepMarker(self.renWin, gm,
cmap=self.canvas.colormap)
returned["vtk_backend_marker_actors"] = actors
for g, gs, pd, act, geo in actors:
ren = self.fitToViewport(
Expand All @@ -517,7 +520,8 @@ def plot(self, data1, data2, template, gtype, gname, bg, *args, **kargs):

elif gtype == "fillarea":
if gm.priority != 0:
actors = vcs2vtk.prepFillarea(self.renWin, gm)
actors = vcs2vtk.prepFillarea(self.renWin, gm,
cmap=self.canvas.colormap)
returned["vtk_backend_fillarea_actors"] = actors
for act, geo in actors:
ren = self.fitToViewport(
Expand Down
2 changes: 2 additions & 0 deletions Packages/vcs/Lib/__init__.py
Expand Up @@ -36,6 +36,8 @@
import os
from manageElements import * # noqa

_colorMap = "default"

_default_time_units = 'days since 2000'


Expand Down
3 changes: 2 additions & 1 deletion Packages/vcs/Lib/isoline.py
Expand Up @@ -988,7 +988,8 @@ def script(self, script_filename, mode='a'):
(unique_name, self.yaxisconvert))
# Unique attribute for isoline
fp.write("%s.label = '%s'\n" % (unique_name, self.label))
fp.write("%s.labelskipdistance = '%s'\n" % (unique_name, self.labelskipdistance))
fp.write("%s.labelskipdistance = '%s'\n" %
(unique_name, self.labelskipdistance))
fp.write("%s.line = %s\n" % (unique_name, self.line))
fp.write("%s.linecolors = %s\n" % (unique_name, self.linecolors))
fp.write("%s.linewidths = %s\n" % (unique_name, self.linewidths))
Expand Down
37 changes: 17 additions & 20 deletions Packages/vcs/Lib/vcs2vtk.py
Expand Up @@ -898,11 +898,10 @@ def prepTextProperty(p, winSize, to="default", tt="default", cmap=None,
if isinstance(tt, str):
tt = vcs.elements["texttable"][tt]

if cmap is None:
if tt.colormap is not None:
cmap = tt.colormap
else:
cmap = 'default'
if tt.colormap is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just do this:

if tt.colormap is not None:
cmap = ***
else:
cmap = +++

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because user can send a cmap to the function

cmap = tt.colormap
elif cmap is None:
cmap = vcs._colorMap
if isinstance(cmap, str):
cmap = vcs.elements["colormap"][cmap]
colorIndex = overrideColorIndex if overrideColorIndex else tt.color
Expand Down Expand Up @@ -1046,11 +1045,10 @@ def prepFillarea(renWin, farea, cmap=None):
actors = []

# Find color map:
if cmap is None:
if farea.colormap is not None:
cmap = farea.colormap
else:
cmap = 'default'
if farea.colormap is not None:
cmap = farea.colormap
elif cmap is None:
cmap = vcs._colorMap
if isinstance(cmap, str):
cmap = vcs.elements["colormap"][cmap]

Expand Down Expand Up @@ -1324,11 +1322,10 @@ def prepGlyph(g, marker, index=0):

def setMarkerColor(p, marker, c, cmap=None):
# Color
if cmap is None:
if marker.colormap is not None:
cmap = marker.colormap
else:
cmap = 'default'
if marker.colormap is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. if elif should be used if there is else as well. Unless cmap has some default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, user can send a cmap to function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if cmap is not None then should you do this instead:

Check if cmap is None

if cmap is None and maker.colormap is not None:
cmap = ***
elif cmake is None and vcs._colorMap is not None:
cmap = ***
else:
cmap = 'default' # Do we need need default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i reviewed the code, it's good as is, if primitive has colorset then it wins. Then falls back on canvas cmap (which is passed I believed) and if nothing fallasback on vcs. Good to be merged when you're happy

cmap = marker.colormap
elif cmap is None:
cmap = vcs._colorMap
if isinstance(cmap, str):
cmap = vcs.elements["colormap"][cmap]
color = cmap.index[c]
Expand Down Expand Up @@ -1460,11 +1457,11 @@ def prepLine(renWin, line, cmap=None):
p = a.GetProperty()
p.SetLineWidth(w)

if cmap is None:
if line.colormap is not None:
cmap = line.colormap
else:
cmap = 'default'
if line.colormap is not None:
cmap = line.colormap
elif cmap is None:
cmap = vcs._colorMap

if isinstance(cmap, str):
cmap = vcs.elements["colormap"][cmap]
color = cmap.index[c]
Expand Down
12 changes: 7 additions & 5 deletions Packages/vcs/Lib/vcsvtk/boxfillpipeline.py
Expand Up @@ -18,8 +18,8 @@ class BoxfillPipeline(Pipeline2D):
set of ivars (at minimum, identify what the mappers are rendering).
"""

def __init__(self, context_):
super(BoxfillPipeline, self).__init__(context_)
def __init__(self, gm, context_):
super(BoxfillPipeline, self).__init__(gm, context_)

self._contourLabels = None
self._mappers = None
Expand Down Expand Up @@ -220,7 +220,7 @@ def _plotInternal(self):
self._context().renderColorBar(self._template, self._contourLevels,
self._contourColors,
self._contourLabels,
self._colorMap))
self.getColorMap()))

if self._context().canvas._continents is None:
self._useContinents = False
Expand Down Expand Up @@ -264,8 +264,9 @@ def _plotInternalBoxfill(self):

lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(numLevels)
_colorMap = self.getColorMap()
for i in range(numLevels):
r, g, b = self._colorMap.index[self._contourColors[i]]
r, g, b = _colorMap.index[self._contourColors[i]]
lut.SetTableValue(i, r / 100., g / 100., b / 100.)

mapper.SetLookupTable(lut)
Expand Down Expand Up @@ -333,6 +334,7 @@ def _plotInternalCustomBoxfill(self):
luts = []
geos = []
wholeDataMin, wholeDataMax = vcs.minmax(self._originalData1)
_colorMap = self.getColorMap()
for i, l in enumerate(tmpLevels):
# Ok here we are trying to group together levels can be, a join
# will happen if: next set of levels contnues where one left off
Expand All @@ -350,7 +352,7 @@ def _plotInternalCustomBoxfill(self):
geos.append(geoFilter2)
mapper.SetInputConnection(geoFilter2.GetOutputPort())
lut.SetNumberOfTableValues(1)
r, g, b = self._colorMap.index[color]
r, g, b = _colorMap.index[color]
lut.SetTableValue(0, r / 100., g / 100., b / 100.)
mapper.SetLookupTable(lut)
mapper.SetScalarRange(l[j], l[j + 1])
Expand Down
19 changes: 11 additions & 8 deletions Packages/vcs/Lib/vcsvtk/isofillpipeline.py
Expand Up @@ -12,8 +12,8 @@ class IsofillPipeline(Pipeline2D):

"""Implementation of the Pipeline interface for VCS isofill plots."""

def __init__(self, context_):
super(IsofillPipeline, self).__init__(context_)
def __init__(self, gm, context_):
super(IsofillPipeline, self).__init__(gm, context_)

self._patternActors = None

Expand Down Expand Up @@ -158,10 +158,11 @@ def _plotInternal(self):
luts = []
cots = []
mappers = []
_colorMap = self.getColorMap()
self._patternActors = []
for i, l in enumerate(tmpLevels):
# Ok here we are trying to group together levels can be, a join
# will happen if: next set of levels contnues where one left off
# will happen if: next set of levels continues where one left off
# AND pattern is identical
mapper = vtk.vtkPolyDataMapper()
lut = vtk.vtkLookupTable()
Expand All @@ -178,7 +179,8 @@ def _plotInternal(self):
mapper.SetInputConnection(cot.GetOutputPort())
lut.SetNumberOfTableValues(len(tmpColors[i]))
for j, color in enumerate(tmpColors[i]):
r, g, b = self._colorMap.index[color]
r, g, b = _colorMap.index[color]
lut.SetTableValue(j, r / 100., g / 100., b / 100.)
if style in ['solid', 'pattern']:
lut.SetTableValue(j, r / 100., g / 100., b / 100.,
tmpOpacities[i] / 100.)
Expand All @@ -191,7 +193,7 @@ def _plotInternal(self):
mappers.append(mapper)

# Since pattern creation requires a single color, assuming the first
c = [val*255/100.0 for val in self._colorMap.index[tmpColors[i][0]]]
c = [val*255/100.0 for val in _colorMap.index[tmpColors[i][0]]]
act = fillareautils.make_patterned_polydata(cot.GetOutput(),
fillareastyle=style,
fillareaindex=tmpIndices[i],
Expand All @@ -216,7 +218,7 @@ def _plotInternal(self):
lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(numLevels)
for i in range(numLevels):
r, g, b = self._colorMap.index[self._contourColors[i]]
r, g, b = _colorMap.index[self._contourColors[i]]
lut.SetTableValue(i, r / 100., g / 100., b / 100.)

mapper.SetLookupTable(lut)
Expand Down Expand Up @@ -292,7 +294,8 @@ def _plotInternal(self):
if isinstance(self._contourLevels[0], list):
if numpy.less(abs(self._contourLevels[0][0]), 1.e20):
# Ok we need to add the ext levels
self._contourLevels.insert(0, [-1.e20, self._contourLevels[0][0]])
self._contourLevels.insert(
0, [-1.e20, self._contourLevels[0][0]])
else:
if numpy.less(abs(self._contourLevels[0]), 1.e20):
# need to add an ext
Expand All @@ -311,7 +314,7 @@ def _plotInternal(self):
self._resultDict.update(
self._context().renderColorBar(self._template, self._contourLevels,
self._contourColors, legend,
self._colorMap,
self.getColorMap(),
style=style,
index=self._gm.fillareaindices,
opacity=opacities))
Expand Down
12 changes: 6 additions & 6 deletions Packages/vcs/Lib/vcsvtk/isolinepipeline.py
Expand Up @@ -10,8 +10,8 @@ class IsolinePipeline(Pipeline2D):

"""Implementation of the Pipeline interface for VCS isoline plots."""

def __init__(self, context_):
super(IsolinePipeline, self).__init__(context_)
def __init__(self, gm, context_):
super(IsolinePipeline, self).__init__(gm, context_)

def _updateVTKDataSet(self):
"""Overrides baseclass implementation."""
Expand Down Expand Up @@ -85,8 +85,7 @@ def _plotInternal(self):

lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(len(self._contourColors))
cmap = self._context().canvas.getcolormapname()
cmap = vcs.elements["colormap"][cmap]
cmap = self.getColorMap()
for i, col in enumerate(self._contourColors):
r, g, b = cmap.index[col]
lut.SetTableValue(i, r / 100., g / 100., b / 100.)
Expand Down Expand Up @@ -138,14 +137,15 @@ def _plotInternal(self):
tprop = vtk.vtkTextProperty()
vcs2vtk.prepTextProperty(tprop,
self._context().renWin.GetSize(),
to, tt)
to, tt, cmap=cmap)
tprops.AddItem(tprop)
if colorOverride is not None:
del(vcs.elements["texttable"][tt])
else: # No text properties specified. Use the default:
tprop = vtk.vtkTextProperty()
vcs2vtk.prepTextProperty(tprop,
self._context().renWin.GetSize())
self._context().renWin.GetSize(),
cmap=cmap)
tprops.AddItem(tprop)
self._resultDict["vtk_backend_contours_labels_text_properties"] = \
tprops
Expand Down
9 changes: 5 additions & 4 deletions Packages/vcs/Lib/vcsvtk/meshfillpipeline.py
Expand Up @@ -11,8 +11,8 @@ class MeshfillPipeline(Pipeline2D):

"""Implementation of the Pipeline interface for VCS meshfill plots."""

def __init__(self, context_):
super(MeshfillPipeline, self).__init__(context_)
def __init__(self, gm, context_):
super(MeshfillPipeline, self).__init__(gm, context_)

def _updateScalarData(self):
"""Overrides baseclass implementation."""
Expand Down Expand Up @@ -118,6 +118,7 @@ def _plotInternal(self):
mappers = []
luts = []
geos = []
_colorMap = self.getColorMap()
for i, l in enumerate(tmpLevels):
# Ok here we are trying to group together levels can be, a join
# will happen if: next set of levels contnues where one left off
Expand All @@ -136,7 +137,7 @@ def _plotInternal(self):
geos.append(geoFilter2)
mapper.SetInputConnection(geoFilter2.GetOutputPort())
lut.SetNumberOfTableValues(1)
r, g, b = self._colorMap.index[color]
r, g, b = _colorMap.index[color]
lut.SetTableValue(0, r / 100., g / 100., b / 100.)
mapper.SetLookupTable(lut)
mapper.SetScalarRange(l[j], l[j + 1])
Expand Down Expand Up @@ -288,7 +289,7 @@ def _plotInternal(self):
self._resultDict.update(
self._context().renderColorBar(self._template, self._contourLevels,
self._contourColors, legend,
self._colorMap))
self.getColorMap()))

if self._context().canvas._continents is None:
self._useContinents = False
Expand Down
16 changes: 15 additions & 1 deletion Packages/vcs/Lib/vcsvtk/pipeline.py
@@ -1,4 +1,5 @@
import weakref
import vcs


class Pipeline(object):
Expand All @@ -9,15 +10,28 @@ class Pipeline(object):
VTK plot command. Refer to the method documentation for details.
"""

def __init__(self, context_):
def __init__(self, graphics_method, context_):
"""Initialize the pipeline object.

_gm is a vcs graphics method
_context is a weakref of the VTKVCSBackend object that created this
Pipeline.
"""
self._context = weakref.ref(context_)
self._gm = graphics_method

# For now, we'll just throw everything at plot. This might need to be
# broken up into set_data, set_template, etc methods...
def plot(self, data1, data2, template, graphics_method, grid, transform):
raise NotImplementedError("Missing override.")

def getColorMap(self):
_colorMap = self._gm.colormap
if _colorMap is None:
_colorMap = \
_colorMap = self._context().canvas.getcolormapname()
if _colorMap is None:
_colorMap = vcs._colorMap
if isinstance(_colorMap, str):
_colorMap = vcs.elements["colormap"][_colorMap]
return _colorMap