Scaling and Centering Displays

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Scaling and Centering Displays

Post by Jon »

Just a quick note…I decided to deprecate the "center" method of the display wrapper class (it's still there and works the same--for now!) in favor of the following methods:

  • setCenter(latitude, longitude) / getCenter()
  • setScaleFactor(scale) / getScaleFactor()

NOTE:

Code: Select all

setScaleFactor(1.2) 
setScaleFactor(1.2)

will rescale the display to be 1.2 times the size of the display after the first call. Or, those calls are essentially the same as "setScaleFactor(2.4)."

(for some of the reasoning behind the name change, try "import this" from the Jython shell!)
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Scaling and Centering Displays

Post by joleenf »

Hi Jon,

The setScaleFactor is working as stated. Still not sure how docs are being written. There will need to be a note that negative values flip the display. Good news,

md=firstDisplay() #get the main display view manager
md.setScaleFactor(-2) #inverts display North to South
md.setScaleFactor(-1) #inverts display North to South returning to the original orientation.

md.getCenter() # worked
md.setCenter(45,-85) # not working

The error for setCenter was
Error: Traceback (most recent call last): File " ", line 1, in File " ", line 298, in setCenter NameError: global name 'scale' is not defined
Last edited by joleenf on Fri Sep 09, 2011 7:54 pm, edited 1 time in total.
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: Scaling and Centering Displays

Post by Jon »

I'll write a more useful reply soon…but I just wanted to apologize for not being more active in the forum as of late! I've been trying to get the documentation generation stuff in working order ASAP. It's so close (though it's been like that for several days :().
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Scaling and Centering Displays

Post by joleenf »

Jon,

It may be good to add a function which allows the user to return to the original scaling of the frame. I am running a script currently and the scaling is retained between function calls, so each run the scaling builds. It seems that I could

1.) reset the scale factor by performing the inverse operation (possibly introducing some error). This is what I chose to do.

2.) create a new dc handle

3.) open a new McV session for each run of the function

What is your opinion? Is it possible to hold the original scale and then call a reset scale? Is creating a handle for each display the best route or is that too cluttered? I don't want to call a separate runMcV each time I need to load a new band of data, but maybe there is an advantage?

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Scaling and Centering Displays

Post by joleenf »

Hi,

The display centering and scale has been explained to me before, but I can't remember how it works. How do I find out the exact center and scale of an active display, so that I can replicate it my script?

I tried this:
1.) Open McIDAS-V, translate and zoom the display without changing the projection.
2.) Open the shell and type:

Code: Select all

print activeDisplay().getScreenCenter()

3.) Get the display scale from View-->Properties-->Aspect Ratio (Scale X). See image below, the top Properties listing is for the original window. In this case, ScaleX was 1.2969
4.) Create a new window using panel=buildWindow()
5.) Type panel[0].setCenter(<lat from getScreenCenter>,<lon from screen center>, scale=<scale from ScaleX>).

Please see image below for the sequence. The created panel does not reproduce the view in the original window, nor does the scale reflect the value entered (Result is 0.6484, not 1.2969).

Screen Shot 2015-04-15 at 9.35.44 AM.png


This has consistently confused me.

It is also confusing that repeating the panel[0].getScreenCenter does not reproduce the entered values for setCenter. I theorized that it was the order that mattered. Since I had zoomed before I translated, I chose to do another test where setScaleFactor is used first, then setCenter without a scale. This still did not reproduced the entered value for the center lat/lon. This also did not reproduced the entered scale for the scaleFactor.

Thanks,
Joleen
User avatar
mhiley
Posts: 90
Joined: Mon Jan 23, 2012 10:22 pm

Re: Scaling and Centering Displays

Post by mhiley »

Joleen,

Have you tried the setViewpoint method I put in for HP?:

viewtopic.php?f=31&t=1166&hilit=setviewpoint

Sounds like it would be useful for what you are trying to accomplish. Basically you just arrange your display as desired, save off a viewpoint using Projections->Viewpoints->Save Current Viewpoint, and then recall it from your scripts using setViewpoint('name').

Mike
User avatar
mhiley
Posts: 90
Joined: Mon Jan 23, 2012 10:22 pm

Re: Scaling and Centering Displays

Post by mhiley »

Also, with the disclaimer that I'm not at all an expert an VisAD's projection matrix... when you do setScaleFactor, what ultimately gets called is DisplayMaster.zoom ... which in turn *multiplies* the scale factor you specified by the current projection matrix ... so I wouldn't expect the resulting scale to be the same as what you specified in setScaleFactor...

I'm not sure though why getScreenCenter doesn't return what you specified in setCenter ... how far off is it?
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Scaling and Centering Displays

Post by joleenf »

Hi Mike,

It is not off by too much somewhere around 0.2 to 0.3 degrees. I chose to use the the setCenter rather than setViewpoint because was not working in the script at that time. However, it was working consistently. After a restart, setViewpoint is working consistently. The other reason I thought I would use the center and scaleFactor method was that I was sharing the script. I did not want to pass the dependency of a specific viewpoint name.

Joleen
User avatar
mhiley
Posts: 90
Joined: Mon Jan 23, 2012 10:22 pm

Re: Scaling and Centering Displays

Post by mhiley »

joleenf wrote:I did not want to pass the dependency of a specific viewpoint name.


Yep, that's definitely the downside of viewpoints. It looks like a "viewpoint" is basically just the combination of a projection name and a 4x4 projection matrix... It wouldn't look pretty to have a 4x4 matrix hard coded into your script, but it might not be a bad way of dealing with this issue! Maybe we could write a 'dumpViewpoint' method that would give you something to copy/paste into a script and essentially persist the viewpoint for passing around to others.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Scaling and Centering Displays

Post by joleenf »

It sounds like a dumpViewpoint option would be exactly what I am looking for in consistency.

Joleen
Post Reply