You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Peppe <pe...@gmail.com> on 2007/01/08 11:41:49 UTC

map coordinates

So, i tried to understand how to convert coordinates system to another to
update bounding box position...
i would that you say me if this code that i wrote to map coordinates system
of bounding box is correct:

DOMMouseEvent elEvt = (DOMMouseEvent)evt;

SVGMatrix mat = ((SVGLocatable)shape).getScreenCTM();
SVGMatrix imat = mat.inverse();
bPt = doc.getRootElement().createSVGPoint();
bPt.setX(elEvt.getClientX());
bPt.setY(elEvt.getClientY());
bPt = bPt.matrixTransform(imat); 

then, when i release the button, i re-mapping the coordinate system of
bounding box to the shape coordinate system (the position of shape is
changed):
SVGMatrix rb = ((SVGLocatable)shape).getScreenCTM(); 
bPt = bPt.matrixTransform(rb);
-- 
View this message in context: http://www.nabble.com/map-coordinates-tf2938566.html#a8215638
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: map coordinates

Posted by th...@kodak.com.
Hi Peppe,

   Please reread my earliest response on this topic:
http://www.nabble.com/update-bounding-box-position-tf2786041.html#a7775398

   The code below doesn't "update" the bbox, the bbox is always correct,
it maps the bbox to another coordinate system (in the case below the
screen coordinate system).

   For your arrow function to work you probably want to map the corners of
the BBox to the coordinate system of the element you append the image
elements (referencing your arrow) to.

Peppe <pe...@gmail.com> wrote on 01/09/2007 06:41:56 AM:

> 
> To show better my problem i post a piece of code that i wrote:
> 
> private class OnMouseClick implements EventListener {
>            public void handleEvent(final Event evt) {
> 
> svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
> Runnable() {
>                   public void run() {
>                      Element svgRoot = svgCanvas.getSVGDocument().
> getRootElement();
>                      DOMMouseEvent eleEvt = (DOMMouseEvent)evt;
>                      shape = (Element)eleEvt.getTarget();
> 
>                      //map bbox
>                          SVGMatrix mat = 
((SVGLocatable)shape).getScreenCTM();
>                         shapeBound = ((SVGLocatable)shape).getBBox();
>                         SVGMatrix imat = mat.inverse();
>                         bPt1 = doc.getRootElement().createSVGPoint();
>                         bPt1.setX(shapeBound.getX());
>                         bPt1.setY(shapeBound.getY());
>                         bPt1 = bPt1.matrixTransform(mat); 
>                         bPt2 = doc.getRootElement().createSVGPoint();
> bPt2.setX(shapeBound.getX()+shapeBound.getWidth());
>                         bPt2.setY(shapeBound.getY());
>                         bPt2 = bPt2.matrixTransform(mat); 
>                         bPt3 = doc.getRootElement().createSVGPoint();
>                         bPt3.setX(shapeBound.getX());
> bPt3.setY(shapeBound.getY()+shapeBound.getHeight());
>                         bPt3 = bPt3.matrixTransform(mat); 
>                         bPt4 = doc.getRootElement().createSVGPoint();
> bPt4.setX(shapeBound.getX()+shapeBound.getWidth());
> bPt4.setY(shapeBound.getY()+shapeBound.getHeight());
>                         bPt4 = bPt4.matrixTransform(mat); 
> 
> System.out.println(""+bPt1.getX()+","+bPt1.getY());
> 
>                                        arrow();
> }
> }
> 
> private class OnDownAction implements EventListener {
>            public void handleEvent(Event evt) {
>                             DOMMouseEvent elEvt = (DOMMouseEvent)evt; 
>                   actionNode = elEvt.getTarget();
>      .....
>     .....
> }
> }
> 
> private class OnMoveAction implements EventListener {
>            public void handleEvent(Event evt) {
>      .....
>     .....
> }
> }
> 
> private class OnUpAction implements EventListener {
>            public void handleEvent(Event evt) {
>                        //update bbox
>                    shape = (Element)actionNode;
>                   SVGMatrix mat = ((SVGLocatable)shape).getScreenCTM();
>                   shapeBound = ((SVGLocatable)shape).getBBox();
>                   //SVGMatrix imat = mat.inverse();
>                   bPt1 = doc.getRootElement().createSVGPoint();
>                   bPt1.setX(shapeBound.getX());
>                   bPt1.setY(shapeBound.getY());
>                   bPt1 = bPt1.matrixTransform(mat); 
>                   bPt2 = doc.getRootElement().createSVGPoint();
>                   bPt2.setX(shapeBound.getX()+shapeBound.getWidth());
>                   bPt2.setY(shapeBound.getY());
>                   bPt2 = bPt2.matrixTransform(mat); 
>                   bPt3 = doc.getRootElement().createSVGPoint();
>                   bPt3.setX(shapeBound.getX());
>                   bPt3.setY(shapeBound.getY()+shapeBound.getHeight());
>                   bPt3 = bPt3.matrixTransform(mat); 
>                   bPt4 = doc.getRootElement().createSVGPoint();
>                   bPt4.setX(shapeBound.getX()+shapeBound.getWidth());
>                   bPt4.setY(shapeBound.getY()+shapeBound.getHeight());
>                   bPt4 = bPt4.matrixTransform(mat); 
>                   System.out.println(""+bPt1.getX()+","+bPt1.getY());
> 
>                         arrow();
>      .....
>      .....
> }
> }
> 
> arrow is a method that add images of arrows around bbox....
> -- 
> View this message in context: http://www.nabble.com/map-coordinates-
> tf2938566.html#a8236113
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 

Re: map coordinates

Posted by Peppe <pe...@gmail.com>.
To show better my problem i post a piece of code that i wrote:
 
private class OnMouseClick implements EventListener {
	        public void handleEvent(final Event evt) {
	        	
svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
						public void run() {
							Element svgRoot = svgCanvas.getSVGDocument().getRootElement();
							DOMMouseEvent eleEvt = (DOMMouseEvent)evt;
							shape = (Element)eleEvt.getTarget();
							
							//map bbox
 			            	SVGMatrix mat = ((SVGLocatable)shape).getScreenCTM();
			            	shapeBound = ((SVGLocatable)shape).getBBox();
			            	SVGMatrix imat = mat.inverse();
			            	bPt1 = doc.getRootElement().createSVGPoint();
			            	bPt1.setX(shapeBound.getX());
			            	bPt1.setY(shapeBound.getY());
			            	bPt1 = bPt1.matrixTransform(mat); 
			            	bPt2 = doc.getRootElement().createSVGPoint();
			            	bPt2.setX(shapeBound.getX()+shapeBound.getWidth());
			            	bPt2.setY(shapeBound.getY());
			            	bPt2 = bPt2.matrixTransform(mat); 
			            	bPt3 = doc.getRootElement().createSVGPoint();
			            	bPt3.setX(shapeBound.getX());
			            	bPt3.setY(shapeBound.getY()+shapeBound.getHeight());
			            	bPt3 = bPt3.matrixTransform(mat); 
			            	bPt4 = doc.getRootElement().createSVGPoint();
			            	bPt4.setX(shapeBound.getX()+shapeBound.getWidth());
			            	bPt4.setY(shapeBound.getY()+shapeBound.getHeight());
			            	bPt4 = bPt4.matrixTransform(mat); 
			            	
			            	System.out.println(""+bPt1.getX()+","+bPt1.getY());

                                       arrow();
}
}

private class OnDownAction implements EventListener {
	        public void handleEvent(Event evt) {
                            DOMMouseEvent elEvt = (DOMMouseEvent)evt;  
		            actionNode = elEvt.getTarget();
     .....
    .....
}
}

private class OnMoveAction implements EventListener {
	        public void handleEvent(Event evt) {
     .....
    .....
}
}

private class OnUpAction implements EventListener {
	        public void handleEvent(Event evt) {
                       //update bbox
	                shape = (Element)actionNode;
	            	SVGMatrix mat = ((SVGLocatable)shape).getScreenCTM();
	            	shapeBound = ((SVGLocatable)shape).getBBox();
	            	//SVGMatrix imat = mat.inverse();
	            	bPt1 = doc.getRootElement().createSVGPoint();
	            	bPt1.setX(shapeBound.getX());
	            	bPt1.setY(shapeBound.getY());
	            	bPt1 = bPt1.matrixTransform(mat); 
	            	bPt2 = doc.getRootElement().createSVGPoint();
	            	bPt2.setX(shapeBound.getX()+shapeBound.getWidth());
	            	bPt2.setY(shapeBound.getY());
	            	bPt2 = bPt2.matrixTransform(mat); 
	            	bPt3 = doc.getRootElement().createSVGPoint();
	            	bPt3.setX(shapeBound.getX());
	            	bPt3.setY(shapeBound.getY()+shapeBound.getHeight());
	            	bPt3 = bPt3.matrixTransform(mat); 
	            	bPt4 = doc.getRootElement().createSVGPoint();
	            	bPt4.setX(shapeBound.getX()+shapeBound.getWidth());
	            	bPt4.setY(shapeBound.getY()+shapeBound.getHeight());
	            	bPt4 = bPt4.matrixTransform(mat); 
	            	System.out.println(""+bPt1.getX()+","+bPt1.getY());
                        
                        arrow();
     .....
     .....
}
}

arrow is a method that add images of arrows around bbox....
-- 
View this message in context: http://www.nabble.com/map-coordinates-tf2938566.html#a8236113
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: map coordinates

Posted by Peppe <pe...@gmail.com>.


thomas.deweese wrote:
> 
> Hi Peppe,
> 
>    I noticed on mistake,
> 
> Peppe <pe...@gmail.com> wrote on 01/08/2007 09:07:11 AM:
> 
>> >>                      SVGMatrix mat = 
>> > ((SVGLocatable)shape).getScreenCTM();
>> >>                      SVGMatrix imat = mat.inverse();
> 
>     In your case you shouldn't use the mat.inverse, just use
> 'mat'.
> 
> 
> I correct the mistake....
> 



>> I add the code above also OnUpAction method (that is i release mouse 
> button)
>> but the bounding box not update it position...it stay in old position
> 
>    What bounding box?  are you saying that bPt1-4 are the same at the
> end of the down and up calls?
> 
> 
i add print statement to bPt1-4 before and after move...but if i click on
shape that i moved the arrow that are around bbox are in old position

-- 
View this message in context: http://www.nabble.com/map-coordinates-tf2938566.html#a8218686
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: map coordinates

Posted by th...@kodak.com.
Hi Peppe,

   I noticed on mistake,

Peppe <pe...@gmail.com> wrote on 01/08/2007 09:07:11 AM:

> >>                      SVGMatrix mat = 
> > ((SVGLocatable)shape).getScreenCTM();
> >>                      SVGMatrix imat = mat.inverse();

    In your case you shouldn't use the mat.inverse, just use
'mat'.

> I add the code above also OnUpAction method (that is i release mouse 
button)
> but the bounding box not update it position...it stay in old position

   What bounding box?  are you saying that bPt1-4 are the same at the
end of the down and up calls?

Re: map coordinates

Posted by Peppe <pe...@gmail.com>.


thomas.deweese wrote:
> 
> 
>                       SVGRect shapeBound = 
> ((SVGLocatable)shape).getBBox();
> 
>>                      SVGMatrix mat = 
> ((SVGLocatable)shape).getScreenCTM();
>>                      SVGMatrix imat = mat.inverse();
>>                      bPt1 = doc.getRootElement().createSVGPoint();
>>                      bPt1.setX(shapeBound.getX());
>>                      bPt1.setY(shapeBound.getY());
>>                      bPt1 = bPt1.matrixTransform(imat); 
>>                      bPt2 = doc.getRootElement().createSVGPoint();
>>                      bPt2.setX(shapeBound.getX()+shapeBound.getWidth());
>>                      bPt2.setY(shapeBound.getY());
>>                      bPt2 = bPt2.matrixTransform(imat); 
>>                      bPt3 = doc.getRootElement().createSVGPoint();
>>                      bPt3.setX(shapeBound.getX());
>> bPt3.setY(shapeBound.getY()+shapeBound.getHeight());
>>                      bPt3 = bPt3.matrixTransform(imat); 
>>                      bPt4 = doc.getRootElement().createSVGPoint();
>>                      bPt4.setX(shapeBound.getX()+shapeBound.getWidth());
>> bPt4.setY(shapeBound.getY()+shapeBound.getHeight());
>>                      bPt4 = bPt4.matrixTransform(imat); 
>> 
>> but i don't understand how to update these points to the new 
> positions... 
> 
> 

I add the code above also OnUpAction method (that is i release mouse button)
but the bounding box not update it position...it stay in old position
-- 
View this message in context: http://www.nabble.com/map-coordinates-tf2938566.html#a8218451
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: map coordinates

Posted by th...@kodak.com.
Hi Peppe,

Peppe <pe...@gmail.com> wrote on 01/08/2007 08:41:06 AM:

> i would to update bbox position when i move the element (it's called 
"shape"
> in my code; instead "actionNode" is actionNode = elEvt.getTarget()) that 
i
> selected...
> 
> you say that i have to map 4 points... in this way?:

   Yes, these are the 4 points...

> 
>                                 shape = (Element)actionNode;

   I think you should add:

                      SVGRect shapeBound = 
((SVGLocatable)shape).getBBox();

>                      SVGMatrix mat = 
((SVGLocatable)shape).getScreenCTM();
>                      SVGMatrix imat = mat.inverse();
>                      bPt1 = doc.getRootElement().createSVGPoint();
>                      bPt1.setX(shapeBound.getX());
>                      bPt1.setY(shapeBound.getY());
>                      bPt1 = bPt1.matrixTransform(imat); 
>                      bPt2 = doc.getRootElement().createSVGPoint();
>                      bPt2.setX(shapeBound.getX()+shapeBound.getWidth());
>                      bPt2.setY(shapeBound.getY());
>                      bPt2 = bPt2.matrixTransform(imat); 
>                      bPt3 = doc.getRootElement().createSVGPoint();
>                      bPt3.setX(shapeBound.getX());
> bPt3.setY(shapeBound.getY()+shapeBound.getHeight());
>                      bPt3 = bPt3.matrixTransform(imat); 
>                      bPt4 = doc.getRootElement().createSVGPoint();
>                      bPt4.setX(shapeBound.getX()+shapeBound.getWidth());
> bPt4.setY(shapeBound.getY()+shapeBound.getHeight());
>                      bPt4 = bPt4.matrixTransform(imat); 
> 
> but i don't understand how to update these points to the new 
positions... 

  Add print statements for bPt1-4 to the above, then run this code before 
the move and after, the result should be the screen pixel coords of
the shape before and after the move.

Re: map coordinates

Posted by Peppe <pe...@gmail.com>.
i would to update bbox position when i move the element (it's called "shape"
in my code; instead "actionNode" is actionNode = elEvt.getTarget()) that i
selected...

you say that i have to map 4 points... in this way?:

                                shape = (Element)actionNode;
		            	SVGMatrix mat = ((SVGLocatable)shape).getScreenCTM();
		            	SVGMatrix imat = mat.inverse();
		            	bPt1 = doc.getRootElement().createSVGPoint();
		            	bPt1.setX(shapeBound.getX());
		            	bPt1.setY(shapeBound.getY());
		            	bPt1 = bPt1.matrixTransform(imat); 
		            	bPt2 = doc.getRootElement().createSVGPoint();
		            	bPt2.setX(shapeBound.getX()+shapeBound.getWidth());
		            	bPt2.setY(shapeBound.getY());
		            	bPt2 = bPt2.matrixTransform(imat); 
		            	bPt3 = doc.getRootElement().createSVGPoint();
		            	bPt3.setX(shapeBound.getX());
		            	bPt3.setY(shapeBound.getY()+shapeBound.getHeight());
		            	bPt3 = bPt3.matrixTransform(imat); 
		            	bPt4 = doc.getRootElement().createSVGPoint();
		            	bPt4.setX(shapeBound.getX()+shapeBound.getWidth());
		            	bPt4.setY(shapeBound.getY()+shapeBound.getHeight());
		            	bPt4 = bPt4.matrixTransform(imat);        

but i don't understand how to update these points to the new positions...	
-- 
View this message in context: http://www.nabble.com/map-coordinates-tf2938566.html#a8217975
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: map coordinates

Posted by th...@kodak.com.
Hi Peppe,

Peppe <pe...@gmail.com> wrote on 01/08/2007 05:41:49 AM:

> So, i tried to understand how to convert coordinates system to another 
to
> update bounding box position...
> i would that you say me if this code that i wrote to map coordinates 
system
> of bounding box is correct:
> 
> DOMMouseEvent elEvt = (DOMMouseEvent)evt;
> 
> SVGMatrix mat = ((SVGLocatable)shape).getScreenCTM();
> SVGMatrix imat = mat.inverse();
> bPt = doc.getRootElement().createSVGPoint();
> bPt.setX(elEvt.getClientX());
> bPt.setY(elEvt.getClientY());

  Why are you using getClientX/Y instead of the
corners of your BBox?

> bPt = bPt.matrixTransform(imat); 

   The basic code to map points looks good though.

> then, when i release the button, i re-mapping the coordinate system of
> bounding box to the shape coordinate system (the position of shape is
> changed):
> SVGMatrix rb = ((SVGLocatable)shape).getScreenCTM(); 
> bPt = bPt.matrixTransform(rb);

   Once again I would map the _current_ corners of the BBox (4 new
points) instead of the same point you already mapped to screen coords 
above.

   But without a more complete example it's hard to know what
you are trying to do.  Also I would suggest that playing with
this in JavaScript instead of java might help you since, re-running
the javascript version is just 'reload' and takes less than a second.

   Once you have the jscript version running you can 'port' it
back to java.