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

hatches/patterns don't work in vcs 2.0.beta #541

Closed
jypeter opened this issue Aug 7, 2014 · 82 comments
Closed

hatches/patterns don't work in vcs 2.0.beta #541

jypeter opened this issue Aug 7, 2014 · 82 comments
Assignees
Labels
Milestone

Comments

@jypeter
Copy link
Member

@jypeter jypeter commented Aug 7, 2014

The test script pasted at the end is supposed to plot a map with hatches, and a canvas with some test patterns

  • It works correctly with 1.5.1 (though I'm getting strange warning messages that I did not get in earlier versions)
    test_fillarea
    test_fillarea_list
  • In 2.0.beta, after typing x.interact() (I did not know about this one, but a Warning told me to use it), I get some Nope no array[0] messages and the display is not exactly what I expected. I have attached a screen copy below, since the generated png files are empty

hatch_pb_2 0 beta

The test script I used

#!/usr/bin/env python

# J-Y Peterschmitt - LSCE - 09/2011 - pmip2web@lsce.ipsl.fr

# Test the use of hatches and patterns in the isofill
# and fill area graphics methods

# Import some standard modules
import sys, os
from os import path

# Import what we need from CDAT
import cdms2
import vcs

# Some data we can plot from the 'sample_data' directory
# supplied with CDAT
data_dir = path.join(sys.prefix, 'sample_data')
data_file = 'tas_ccsr-95a_1979.01-1979.12.nc'
var_name = 'tas'

# Zone that we want to plot
#
# NOTE: the (latmin, latmax, lonmin, lonmax) information HAS TO be the
# same in the variable, the 'isof' isofill method and the 2 'cont_*'
# continents plotting methods! Otherwise, the data will not match the
# continents that are plotted over it...
(latmin, latmax, lonmin, lonmax) = (-90, 90, -180, 180)

# Use black on white continents (nicer with black and white plots) i.e
# we plot a 'large' white continent outline over the data, and then a
# smaller 'black' continent outline
bw_cont = False
#bw_cont = True

# Read one time step (the first one) from the data file
# and explicitely specify the lat/lon range we need. cdms2
# will retrieve the data in the order we want, regardless of the way
# it is stored in the data file
f = cdms2.open(path.join(data_dir, data_file))
v = f(var_name, time=slice(0, 1), latitude=(latmin, latmax),
      longitude=(lonmin, lonmax, 'co'), squeeze=1)
f.close()

# Initialize the graphics canvas
x = vcs.init()

# Create the isofill method
isof = x.createisofill('test_hatch')
isof.datawc(latmin, latmax, lonmin, lonmax)
isof.levels = [220, 240, 260, 280, 300, 320]
isof.fillareastyle = 'hatch'
isof.fillareacolors = [241, 241, 241, 241, 241] # All black
#isof.fillareacolors = [243, 248, 254, 255, 241] # Colors
isof.fillareaindices = [20, 9, 2, 7, 3]

# Define some graphics methods for plotting black on white continents
if bw_cont:
    cont_black = x.createcontinents('black')
    cont_black.datawc(latmin, latmax, lonmin, lonmax)
    cont_black.linecolor = 241
    cont_black.linewidth = 2
    cont_white = x.createcontinents('white')
    cont_white.datawc(latmin, latmax, lonmin, lonmax)
    cont_white.linecolor = 240
    cont_white.linewidth = 6

    cont_type = 0 # Do not plot the default continents
else:
    cont_type = 1

# Plot the test data
#
# We have to make sure the data and the continents are plotted at the
# same place ('data' area) on the canvas, by using the same template!
# It's even better if we can use for the continents a template that
# will only plot the data area (the priority of the other elements of
# the canvas is set to zero)
tpl = x.createtemplate('tpl', 'default')
x.plot(tpl, isof, v, continents=cont_type)
if bw_cont:
    tpl_data = x.createtemplate('tpl_data', 'default_dud') # plots only data area
    x.plot(tpl_data, cont_white)
    x.plot(tpl_data, cont_black)

# Create a test plot for listing all the hatches and patterns
style_list = []
index_list = []
col_cycle = [243, 248, 254, 241, 255]
nb_cols = len(col_cycle)
color_list = []
x_list = []
y_list = []
txt_x_list = []
txt_y_list = []
txt_str_list = []

shear_x = .05
for j, style in enumerate(['hatch', 'pattern']):
    slide_y = j * .4
    for i in range(20):
        slide_x = i * 0.04
        x1, y1 = (.05 + slide_x, .25 + slide_y)
        x2, y2 = (.08 + slide_x, .45 + slide_y)

        # Add (sheared) rectangles to the list of positions
        # NOTE: no need to close the fill area. Giving 4 vertices
        #       for getting a filled rectangle is enough
        x_list.append([x1, x2, x2 + shear_x, x1 + shear_x])
        y_list.append([y1, y1, y2, y2])

        style_list.append(style)
        # Hatches/Patterns indices have to be in 1-20 range
        index_list.append(i+1)
        col_idx = col_cycle[i % nb_cols]
        color_list.append(col_idx)

        # Annotations
        txt_x_list.append(x1 + 0.015)
        txt_y_list.append(y1 - 0.015)
        txt_str_list.append('%s = %i  -  Color = %i' %
                             (style, i+1, col_idx))

# Create the fill area and the text annotations
fill_test = x.createfillarea('fill_test')
fill_test.style = style_list
fill_test.index = index_list
fill_test.color = color_list
fill_test.x = x_list
fill_test.y = y_list

fill_info = x.createtext('fill_info')
fill_info.angle = 45
fill_info.height = 12
fill_info.color = 241 # Black
fill_info.string = txt_str_list
fill_info.x = txt_x_list
fill_info.y = txt_y_list

# Create a title
plot_title = x.createtext('plot_title')
plot_title.height = 40
plot_title.string = ['Testing hatches and patterns in VCS/CDAT']
plot_title.x = [.01]
plot_title.y = [.9]

# Initialize and use a second graphics canvas
y = vcs.init()
y.plot(plot_title)
y.plot(fill_test)
y.plot(fill_info)

# Save the plots
x.pdf('test_fillarea')
x.png('test_fillarea')
y.pdf('test_fillarea_list')
y.png('test_fillarea_list')

# Note: depending on the version of CDAT, text may not resize
#       correctly when creating a bigger png
#x.png('test_fillarea_big', width=3*11, height=3*8)
#y.png('test_fillarea_list_big', width=3*11, height=3*8)

# The end

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 8, 2014

we are aware of this. @aashish24 and Kitware are going to fix this. This is duplicate of bug #493 .
Keeping this version because better documented

@aashish24
Copy link
Contributor

@aashish24 aashish24 commented Aug 8, 2014

Thanks for the script @jypeter. We will fix it hopefully soon.

@williams13 williams13 added this to the 2.1 milestone Sep 3, 2014
@williams13 williams13 removed this from the 2.0.0 milestone Sep 3, 2014
@doutriaux1 doutriaux1 added this to the 2.2 milestone Nov 10, 2014
@doutriaux1 doutriaux1 removed this from the 2.1 milestone Nov 10, 2014
@durack1
Copy link
Member

@durack1 durack1 commented Nov 19, 2014

This would be really useful to have the ability to stipple over mesh or boxfilled graphics.. I'm not sure how useful VCS will be for me until stippling is available..

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Feb 10, 2015

@aashish24 @dlonie any progress on this?

@aashish24
Copy link
Contributor

@aashish24 aashish24 commented Feb 11, 2015

@doutriaux1 @jypeter I have to remember what was the bug or how much @doutriaux1 had developed the code. I doubt that we can get this one in 2.2 (other higher priorities for now) but we can try.

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Feb 11, 2015

@aashish24 I think most of the code is already in, my guess is that my test png were too big. If you could explain me how to pass a VTK-made pattern rather a png as texture I think we would be set.

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Feb 20, 2015

@dlonie @aashish24 I guess we're moving this to 2.3...

@doutriaux1 doutriaux1 added this to the 2.3 milestone Feb 20, 2015
@doutriaux1 doutriaux1 removed this from the 2.2 milestone Feb 20, 2015
@aashish24
Copy link
Contributor

@aashish24 aashish24 commented Feb 21, 2015

@dlonie is looking into this but I don't think we can make into 2.2

@allisonvacanti
Copy link
Contributor

@allisonvacanti allisonvacanti commented Feb 25, 2015

@aashish24 @doutriaux1 Should we hold this off until the vtk/vcs layer rewrite? It looks like significant effort that will just be replaced in the near future.

@jypeter
Copy link
Member Author

@jypeter jypeter commented Feb 25, 2015

It's not a feature I use often, because I tend to forget about it, so it can wait a bit more, if need be

Hey, @chaosphere2112 , that's another example you can use for the gallery once the problems are fixed! :)

@aashish24
Copy link
Contributor

@aashish24 aashish24 commented Feb 25, 2015

@dlonie I won't suggest that. Can you describe the problem you are running into? I was hoping that it should not be a lot of work but I haven't look at the code. I can see some complications.

@chaosphere2112
Copy link
Contributor

@chaosphere2112 chaosphere2112 commented Feb 25, 2015

@jypeter Added to the list 👍

@allisonvacanti
Copy link
Contributor

@allisonvacanti allisonvacanti commented Feb 26, 2015

Here's where I stopped:

    if isinstance(mapper,list):
      ## This is the sport to add patterns
      #act.GetMapper().ScalarVisibilityOff()
      #act.SetTexture(mapper[1])
      pass

If mapper is a list in the plot2d megafunction, then somehow that means a hatch/pattern is needed. This is hacky, undocumented, and raises a lot of red flags. There's way too much going on here, and any changes I make are likely to break a dozen other things.

We should really just leave this code alone until we can rewrite in to a cleaner, better documented format where it's clear how each task is carried out.

This is going to tricky to implement and will need a custom override for the GL2PS exporter to get this working completely (GL2PS can't handle textures, I'll have to manually inject them into the image). I'd rather just get it right the first time and not have to deal with the fallout that will come from modifying this function.

@aashish24
Copy link
Contributor

@aashish24 aashish24 commented Feb 26, 2015

@dlonie I wouldn't worry about the cleaness of the code as far as we can write a method that applies the texture to the data layer. Once we have that function, we can always use that when we re-structure. Let's talk more about it today. May be I am missing sometihng.

@allisonvacanti
Copy link
Contributor

@allisonvacanti allisonvacanti commented Feb 26, 2015

Talked with @aashish24, and I'll add a function that applies a texture to an actor and add a handler to the vector graphics exporter to copy the texture data over.

This will leave the following tasks to the VCS team:

  • Produce textures to create the desired patterns.
  • Set appropriate texture coordinates on the polydata points.
  • Integrate the texture setup code into the VTKPlots.py.

@allisonvacanti
Copy link
Contributor

@allisonvacanti allisonvacanti commented Feb 27, 2015

This is going to requires some C++ extensions to VTK to add a specialized GL2PSExporter subclass (Can't override the proper virtuals from Python). Do we have an existing C++ layer that I can add to, or should I add a new subproject?

@aashish24
Copy link
Contributor

@aashish24 aashish24 commented Feb 27, 2015

No existing C++ layer but in VCS there is some C code. May be within VCS, we can create a sub-project for it?

@bonfils2
Copy link

@bonfils2 bonfils2 commented Aug 26, 2015

@sankhesh I love the diversity of hatches, but I agree with @doutriaux1 and @durack1 and confirm that transparency is the most crucial feature. I will exclusively use the hatches function to display regions of significance.

@sankhesh
Copy link
Contributor

@sankhesh sankhesh commented Aug 26, 2015

Sure. I'll make the pattern background transparent.

@durack1
Copy link
Member

@durack1 durack1 commented Aug 26, 2015

@sankhesh transparent by default would be awesome.. If it's not too hard, also being able to toggle that would also be useful functionality, if it's already in there and easy to expose that would be ideal..

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 26, 2015

@durack1 i think the toggle might just add a level of complexity which can easily be replace by simply plotting the data once, once with pattern on, once w/o... The simpler the code the easier it will be to maintain!

@durack1
Copy link
Member

@durack1 durack1 commented Aug 26, 2015

@doutriaux1 my preference is to add well documented functionality, with intelligent defaults.. If there are options for granular control I'd like them exposed for power users..

@sankhesh
Copy link
Contributor

@sankhesh sankhesh commented Aug 27, 2015

@doutriaux1 @durack1 @aashish24 @bonfils2

I added a parameter called opacity to the fillarea template. This opacity behaves differently based on the fill area style as follows:

  • solid: Solid fill opacity
  • pattern: Background fill opacity
  • hatch: Foreground opacity

Exhibit 1: Patterns with different opacity values
test_fillarea

Exhibit 2: Hatches with different opacity values
test_fillarea

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 27, 2015

@sankhesh so you made the opacity a list, correct? That's a great idea, I was thinking of just one value applied to all levels, but that's even better!

@durack1
Copy link
Member

@durack1 durack1 commented Aug 27, 2015

@sankhesh this is great, is it possible to also include a "stippling" option in the hatch/pattern selections - so as above

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 27, 2015

@durack1 what is stippling? Another pattern style?

@durack1
Copy link
Member

@durack1 durack1 commented Aug 27, 2015

@doutriaux1 @sankhesh so the transparent grey dots in the figure above

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 27, 2015

so like hatch10 but horizontal? @sankhesh how hard is it to add patterns? Could we somehow pass some png or vtk object instead of a pattern number and use this?

@durack1
Copy link
Member

@durack1 durack1 commented Aug 27, 2015

@doutriaux1 @sankhesh if there are a bunch of VTK options like this, it'd be great to expose them too.. The hatch/patterns above are pretty 1980s technology in my opinion.. They look pretty klunky..

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 27, 2015

@durack1 @sankhesh remeber we need to stay backend-agnostic as much as possible, a png would probably be what works best.

@durack1
Copy link
Member

@durack1 durack1 commented Aug 27, 2015

@doutriaux1 if we have access to more functionality/patterns/options and modernization through the VTK backend, then expose it.. There's no good reason to limit functionality in the off chance that you might want to change the backend renderer some day.. That's way too conservative.. The plotting tools and options in UV-CDAT should be up-to-date and bleeding edge as of 2015-08-27..

In the case that a functionality wasn't available in the future, this would need to be caught with an error message.. Which would happen anyway.. And obviously other tweaks and bugfixes would also be needed if the backend renderer changed..

My recommendation would be modernize and expose everything we have! Make it the best it can be..

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 27, 2015

but that's exactly why vcs lived through 30years or so worth of languages and technologies 😉 you need flexibility. Every time I introduced rigidity it came back to haunt me. We can always hook up things from the backend directly if needed for "expert" users.

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 27, 2015

vcs.backend gives you access to VTK so if you want to moveon to the VTK world purely you can still do it. But that's no longer vcs.

@durack1
Copy link
Member

@durack1 durack1 commented Aug 27, 2015

@doutriaux1 neither of the comments above are a reasonable justification to limit forward development in my opinion.. I think it's a way way too conservative approach.. There aren't many folks who have clung to the ever reliable Windows 1995, just because it's been around 20 years..

I want to plot 21st century graphics using UV-CDAT, whether it's VCS or VTK or matplotlib or something else I don't really care, I just want high resolution, high production quality graphics.. And fine granular control to generate them and export them to differing formats..

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Aug 27, 2015

@durack1 that's what @sankhesh and I are working on, getting to you the features you want in a fashion that will not render our software obsolete. My point was exactly that vcs went through the ages because it is flexible enough to handle ever changing technologies and integrate them in a nice way.

@bonfils2
Copy link

@bonfils2 bonfils2 commented Aug 27, 2015

@sankhesh : small dots would be great too!
slide1

@sankhesh
Copy link
Contributor

@sankhesh sankhesh commented Aug 28, 2015

How about this? - I can add additional patterns (stipple and small dots) to the mix and get these changes merged in. Once that is done, I can look at adding the ability to pass a PNG image to the backend. I'll add that as a separate issue.

@durack1
Copy link
Member

@durack1 durack1 commented Aug 28, 2015

@sankhesh that would be a great start.. What other graphics modes/patterns/hatches are available in VTK that you could expose? Is there a gallery/webpage somewhere that lists these?

@sankhesh
Copy link
Contributor

@sankhesh sankhesh commented Aug 28, 2015

@durack1 The current code-base uses vtkImageCanvasSource2D to generate the pattern images. All the above patterns are generated using the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants