Skip to content

Commit

Permalink
Merge pull request #1670 from UV-CDAT/pattern_size_scaling
Browse files Browse the repository at this point in the history
Pattern size scaling
  • Loading branch information
doutriaux1 committed Nov 16, 2015
2 parents b83881a + d78cd45 commit 63ae58d
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 150 deletions.
5 changes: 3 additions & 2 deletions Packages/vcs/Lib/vcs2vtk.py
Expand Up @@ -1190,9 +1190,10 @@ def prepFillarea(renWin, farea, cmap=None):
st,
idx,
color,
opacity)
opacity,
renWin.GetSize())
if act is not None:
if opacity > 0:
if (st == "pattern" and opacity > 0) or st == "hatch":
m = vtk.vtkPolyDataMapper()
m.SetInputData(pd)
a = vtk.vtkActor()
Expand Down
6 changes: 5 additions & 1 deletion Packages/vcs/Lib/vcsvtk/boxfillpipeline.py
Expand Up @@ -382,6 +382,9 @@ def _plotInternalCustomBoxfill(self):
wholeDataMin, wholeDataMax = vcs.minmax(self._originalData1)
_colorMap = self.getColorMap()
self._patternActors = []
x1, x2, y1, y2 = vcs.utils.getworldcoordinates(self._gm,
self._data1.getAxis(-1),
self._data1.getAxis(-2))
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 continues where one left off
Expand Down Expand Up @@ -422,7 +425,8 @@ def _plotInternalCustomBoxfill(self):
fillareastyle=style,
fillareaindex=tmpIndices[i],
fillareacolors=c,
fillareaopacity=tmpOpacities[i] * 255 / 100.0)
fillareaopacity=tmpOpacities[i] * 255 / 100.0,
size=(x2 - x1, y2 - y1))
if act is not None:
self._patternActors.append(act)

Expand Down
36 changes: 20 additions & 16 deletions Packages/vcs/Lib/vcsvtk/fillareautils.py
@@ -1,13 +1,16 @@
import vtk
from patterns import pattern_list

# number of pixels per individual pattern block
NUM_PIXELS = 16

def num_pixels_for_size(size):
# Select the largest dimension available
dim = max(size)
return int(round(dim / 20))


def make_patterned_polydata(inputContours, fillareastyle=None,
fillareaindex=None, fillareacolors=None,
fillareaopacity=None):
fillareaopacity=None, size=None):
if inputContours is None or fillareastyle == 'solid':
return None
if inputContours.GetNumberOfCells() == 0:
Expand All @@ -16,10 +19,12 @@ def make_patterned_polydata(inputContours, fillareastyle=None,
fillareaindex = 1
if fillareaopacity is None:
fillareaopacity = 255
num_pixels = num_pixels_for_size(size)

# Create the plane that will be textured with the pattern
# The bounds of the plane match the bounds of the input polydata
bounds = inputContours.GetBounds()

patternPlane = vtk.vtkPlaneSource()
patternPlane.SetOrigin(bounds[0], bounds[2], 0.0)
patternPlane.SetPoint1(bounds[0], bounds[3], 0.0)
Expand All @@ -30,22 +35,20 @@ def make_patterned_polydata(inputContours, fillareastyle=None,

# Create the pattern image of the size of the input polydata
# and type defined by fillareaindex
# Scaled the size to 2 times to make the pattern image of a finer resolution
xBounds = bounds[1] - bounds[0]
yBounds = bounds[3] - bounds[2]

if xBounds <= 1 and yBounds <= 1 and size is not None:
xBounds *= size[0]
yBounds *= size[1]
xres, yres = int(xBounds), int(yBounds)

xres = int(4.0*xBounds)
yres = int(4.0*yBounds)

# Handle the case when the bounds are less than 1 in physical dimensions
if xBounds < 1 or yBounds < 1:
boundsAspect = xBounds / yBounds
global NUM_PIXELS
if boundsAspect > 1.0:
yres = 2 * NUM_PIXELS
xres = int(boundsAspect * yres)
else:
xres = 2 * NUM_PIXELS
yres = int(xres / boundsAspect)
patternImage = create_pattern(xres, yres, fillareastyle,

patternImage = create_pattern(xres, yres, num_pixels, fillareastyle,
fillareaindex, fillareacolors,
fillareaopacity)
if patternImage is None:
Expand Down Expand Up @@ -82,6 +85,7 @@ def make_patterned_polydata(inputContours, fillareastyle=None,
patternTexture = vtk.vtkTexture()
patternTexture.SetInputData(patternImage)
patternTexture.InterpolateOn()
patternTexture.RepeatOn()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(textureMap.GetOutputPort())
actor = vtk.vtkActor()
Expand All @@ -90,7 +94,7 @@ def make_patterned_polydata(inputContours, fillareastyle=None,
return actor


def create_pattern(width, height, fillareastyle=None,
def create_pattern(width, height, num_pixels, fillareastyle=None,
fillareaindex=None, fillareacolors=None, fillareaopacity=None):
if fillareastyle == 'solid':
return None
Expand All @@ -105,5 +109,5 @@ def create_pattern(width, height, fillareastyle=None,
fillareaopacity = 255

# Create a pattern source image of the given size
pattern = pattern_list[fillareaindex](width, height, fillareacolors, fillareastyle, fillareaopacity)
pattern = pattern_list[fillareaindex](width, height, num_pixels, fillareacolors, fillareastyle, fillareaopacity)
return pattern.render()
18 changes: 11 additions & 7 deletions Packages/vcs/Lib/vcsvtk/isofillpipeline.py
Expand Up @@ -162,6 +162,9 @@ def _plotInternal(self):
mappers = []
_colorMap = self.getColorMap()
self._patternActors = []
x1, x2, y1, y2 = vcs.utils.getworldcoordinates(self._gm,
self._data1.getAxis(-1),
self._data1.getAxis(-2))
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 continues where one left off
Expand Down Expand Up @@ -194,12 +197,17 @@ def _plotInternal(self):
mappers.append(mapper)

# Since pattern creation requires a single color, assuming the first
c = [val*255/100.0 for val in _colorMap.index[tmpColors[i][0]]]
act = fillareautils.make_patterned_polydata(cot.GetOutput(),
c = [val * 255 / 100.0 for val in _colorMap.index[tmpColors[i][0]]]

# The isofill actor is scaled by the camera, so we need to use this size
# instead of window size for scaling the pattern.
viewsize = (x2 - x1, y2 - y1)
act = fillareautils.make_patterned_polydata(cots[i].GetOutput(),
fillareastyle=style,
fillareaindex=tmpIndices[i],
fillareacolors=c,
fillareaopacity=tmpOpacities[i] * 255 / 100.0)
fillareaopacity=tmpOpacities[i] * 255 / 100.0,
size=viewsize)
if act is not None:
self._patternActors.append(act)

Expand Down Expand Up @@ -237,10 +245,6 @@ def _plotInternal(self):
if self._maskedDataMapper is not None:
mappers.insert(0, self._maskedDataMapper)

x1, x2, y1, y2 = vcs.utils.getworldcoordinates(self._gm,
self._data1.getAxis(-1),
self._data1.getAxis(-2))

# And now we need actors to actually render this thing
actors = []
for mapper in mappers:
Expand Down

0 comments on commit 63ae58d

Please sign in to comment.