Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Implement Viewports and Windows using AffineTransforms ?

Reply
Thread Tools

Implement Viewports and Windows using AffineTransforms ?

 
 
Richard A. DeVenezia
Guest
Posts: n/a
 
      06-07-2004
0,0 1000,0
+-------------------------+
| |
| .75,.75 |
| +-----------+ |
| | 100,100| |
| | | |
| | | |
| | | |
| |20,20 | |
| +-----------+ |
| .25,.25 |
| |
+-------------------------+
0,1000 1000,1000

I am trying to handle Viewports and Windows using multiple AffineTranforms

w=1000 // width of image in pixels
h=1000 // height of image in pixels

// viewport is specified as fraction of image
vllx = .25 // viewport lower left
vlly = .25
yurx = .75 // viewport upper right
yury = .75

// window is specified in world coordinates
wllx = 20 // window lower left
wlly = 20
wury = 100 // window upper right
wury = 100

*** transforms here ***

// Draw three circles centered at world coordinate 60,60 with radii 10,20,30
g.drawOval(60-10,60-10,20,20);
g.drawOval(60-20,60-20,40,40);
g.drawOval(60-30,60-30,60,60);



I am having a terrible time trying to figure out what the transforms should be.

The mapping from world coords (Wx,Wy) to pixels coords (Px,Py) is:

// pixel X
Px = 0 + w * ( vllx + (Wx - wllx)/(wurx - wllx) * (vurx - vllx);

// pixel Y
Py = h - h * ( vlly + (Wy - wlly)/(wury - wlly) * (vury - vlly);

I tried
g.translate (-wllx, -wlly);
g.scale (vw/ww,vh/wh);
g.translate (vllx, vlly);
g.scale (w, -h);
g.translate (0, h);
but nothing showed

I tried
g.translate (-wllx, -wlly);
g.scale (vw/ww,vh/wh);
which drew something, but is obviously not correct.


A program with only this stuff can be found at
www.devenezia.com/java/affine/Sample.java


Any help is greatly appreciated.

Richard A. DeVenezia
 
Reply With Quote
 
 
 
 
ak
Guest
Posts: n/a
 
      06-07-2004
> A program with only this stuff can be found at
> www.devenezia.com/java/affine/Sample.java
>

I tested it, I think you may have some problem with ImageIO.

I don't have ImageIO installed, so I replaced image saving with following
code:

JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(new JPanel() {
protected void paintComponent(Graphics g) {
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(buffer, 0, 0, null);
}

public Dimension getPreferredSize() {
return new Dimension(buffer.getWidth(), buffer.getHeight());
}
}));
frame.pack();
frame.show();

--
http://uio.dev.java.net
http://reader.imagero.com


 
Reply With Quote
 
 
 
 
Richard A. DeVenezia
Guest
Posts: n/a
 
      06-07-2004
ak wrote:
>> A program with only this stuff can be found at
>> www.devenezia.com/java/affine/Sample.java
>>

> I tested it, I think you may have some problem with ImageIO.
>
> I don't have ImageIO installed, so I replaced image saving with
> following code:
>
> JFrame frame = new JFrame();
> frame.getContentPane().add(new JScrollPane(new JPanel() {
> protected void paintComponent(Graphics g) {
> g.fillRect(0, 0, getWidth(), getHeight());
> g.drawImage(buffer, 0, 0, null);
> }
>
> public Dimension getPreferredSize() {
> return new Dimension(buffer.getWidth(),
> buffer.getHeight()); }
> }));
> frame.pack();
> frame.show();


ak,
Thanks for the JFrame snippet. I don't do alot of java gui, so it really
helped me out. (I was using Irfan to view the .png I was writing)

Instead of concatenating several Tx operations upon the Graphics2D (which
wasn't working out for me), I broke up the px= and py= equations into
components that the match affine matrix coefficients. Things are working as
I expect now, yeah!

Updated sample at
www.devenezia.com/java/affine

--
Richard A. DeVenezia


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to implement both side(horizontal and vertical) slider bar at once using mootools manilal prajapati Javascript 2 10-17-2007 07:48 AM
Trying to understand and implement VLAN's using D-Link products Mike_in_Nebraska Wireless Networking 0 06-10-2007 01:07 AM
Implement Singleton Using or Not Using dynamic object. Steven Woody C++ 2 12-29-2005 03:07 AM
How to implement Web Popup windows using User Interface Process Application Block Marco Vasquez ASP .Net 0 12-30-2003 02:49 PM
Implement Windows and Forms Authentication Rafael Veronezi ASP .Net 0 11-04-2003 12:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57