ginput equivalent in octave

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

ginput equivalent in octave

Andy Adler-4
hi,

I'm looking for a way to achieve the functionality of Matlab's "ginput"
in octave. ([x,y]=ginput allows you to click on the graph and get the
locations of the points)

I've started coding the following hack. But I'd like to check if there
is an easier way.

My hack relies on the script

d201:~/octave>cat getmouse
#!/bin/sh

GPID=$(xwininfo -name Gnuplot | awk '/Window id:/ {print $4}')
if [ -z GPID ] ; then
  echo "Gnuplot window not found"
  exit
fi

xev -id $GPID | awk \
       '/ButtonPress event/ {x=1} ; \
        (x==2)   { printf("L=%sB=",$7) }; \
        (x++==3) { print $4 ; \
                   if ($4 ~ 2) system("killall xev") } ' \
       

This attaches xev to the Gnuplot window and sends all the X events to
awk which extracts the location from the Button Press events.

Pressing the second button kills the process, returning me to octave.

I invoke this with, and then click in the gnuplot window a little.

octave:54> system('/u/andy/octave/getmouse')
L=(658,107),B=1,
L=(675,107),B=1,
L=(700,105),B=1,
L=(801,118),B=1,
L=(851,119),B=1,
L=(851,119),B=2,

However, this has two problems.

1) It's slow. You have to wait a little (or move the mouse) after each
click
   before the pipe "flushes" into awk

2) It's difficult to convert from window coordinates. You have to click
on the
   axis and then calculate from there.


So, my question is:

1) Does this functionality exist in octave, or has someone already
written it?

2) If not, does anyone have any suggestions. I'm prepared to work this
code
   into something fairly user friendly and then contribute it to the
octave
   community.

thanks,
_____________________________________________________________________
Andy Adler,    | Pulmonary Physiology Unit         | Lab 303-398-1626
[hidden email] | National Jewish Center,Denver,USA | Fax 303-398-1607

   For the Snark _was_ a Boojum, you see.    -Lewis Carroll


Reply | Threaded
Open this post in threaded view
|

ginput equivalent in octave

John W. Eaton-6
On 11-Sep-1997, Andy Adler <[hidden email]> wrote:

| I'm looking for a way to achieve the functionality of Matlab's "ginput"
| in octave. ([x,y]=ginput allows you to click on the graph and get the
| locations of the points)
|
| I've started coding the following hack. But I'd like to check if there
| is an easier way.

[...]

| So, my question is:
|
| 1) Does this functionality exist in octave, or has someone already
| written it?

Not that I know of.

| 2) If not, does anyone have any suggestions. I'm prepared to work this
| code
|    into something fairly user friendly and then contribute it to the
| octave
|    community.

To do this right, I think that either gnuplot must be modified or
Octave must use something better for graphics.  I have some plans for
the latter, but I have no idea when it might actually happen.

Thanks,

jwe


Reply | Threaded
Open this post in threaded view
|

Re: ginput equivalent in octave

Terrence Brannon-13

> To do this right, I think that either gnuplot must be modified or
> Octave must use something better for graphics.  I have some plans for
> the latter, but I have no idea when it might actually happen.
>

I really like PGPLOT:

http://astro.caltech.edu/~tjp/pgplot/


--

  Terrence Brannon * [hidden email] * http://quake.usc.edu/~brannon


Reply | Threaded
Open this post in threaded view
|

Re: ginput equivalent in octave

John W. Eaton-6
On 12-Sep-1997, Terrence Brannon <[hidden email]> wrote:

|
| > To do this right, I think that either gnuplot must be modified or
| > Octave must use something better for graphics.  I have some plans for
| > the latter, but I have no idea when it might actually happen.
| >
|
| I really like PGPLOT:
|
| http://astro.caltech.edu/~tjp/pgplot/

I can't use PGPLOT with Octave because the PGPLOT copyright notice
includes the following terms that are incompatible with the GPL.

  * The PGPLOT library, both binary and source, and the PGPLOT manual   *
  * `PGPLOT Graphics Subroutine Library' are copyrighted, but available *
  * without fee for education, academic research and non-commercial     *
  * purposes. Ownership of the software remains with the California     *
  * Institute of Technology.  Users may distribute the binary and       *
  * source code to third parties provided that the copyright notice and *
  * this statement appears on all copies and that no charge is made for *
  * such copies.  Any entity wishing to integrate all or part of the    *
  * source code into a product for commercial use or resale should      *
  * contact the author at the above address.                            *

jwe


Reply | Threaded
Open this post in threaded view
|

Re: ginput equivalent in octave

Andy Adler-4
In reply to this post by Andy Adler-4
On 11-Sep-1997, Andy Adler <[hidden email]> wrote:
> I'm looking for a way to achieve the functionality of Matlab's "ginput"
> in octave. ([x,y]=ginput allows you to click on the graph and get the
> locations of the points)

To follow up my own post:

I finally got around to learning a little X programming and
wrote a *.oct file that you can dynamically load.

It takes over control of the mouse, and allows you to click
with button 1 and terminates with buttons 2 or 3.

I've put the source at
  ftp://d201.njc.org/pub/octave/utils/ginput.cc
and a linux i386 compiled binary at
  ftp://d201.njc.org/pub/octave/utils/ginput-linux-i386.oct

here's the help:
   octave:1> help ginput
   ginput is a builtin function
   
   [...] = ginput (...)
   
   GINPUT: gets points mouse clicks on the screen
   
   [x,y]= ginput(axis)
    x -> x coordinates of the points
    y -> y coordinates of the points
   
    axis -> if specified then the first 2 (or 4) clicks
         must be on the appropriate axes. x and y (or just x
         if only 2 points specified ) will then be normalised.

   for example: x=ginput([1 10])
      the first two clicks should correspond to x=1 and x=10
      subsequent clicks will then be normalized to graph units.  
   
   for example: [x,y]=ginput;
      gives x and y in screen pixel units (upper left = 0,0 )

   select points with button #1. Buttons 2 and 3 quit.


Since it links with X, you can't use mkoctfile to compile it.
The compile details are in the source.

One additional advantage of this code over Matlab's ginput
is that it can get points from anywhere on the screen. So you
can scan in graphs and get the data from clicking on the points.

_____________________________________________________________________
Andy Adler,    | Pulmonary Physiology Unit         | Lab 303-398-1626
[hidden email] | National Jewish Center,Denver,USA | Fax 303-398-1607

Of making many books there is no end, and much study wearies the body.
                                                   - Ecclesiastes


Reply | Threaded
Open this post in threaded view
|

Re: ginput equivalent in octave

John W. Eaton-6
On 25-Sep-1997, Andy Adler <[hidden email]> wrote:

| On 11-Sep-1997, Andy Adler <[hidden email]> wrote:
| > I'm looking for a way to achieve the functionality of Matlab's "ginput"
| > in octave. ([x,y]=ginput allows you to click on the graph and get the
| > locations of the points)
|
| To follow up my own post:
|
| I finally got around to learning a little X programming and
| wrote a *.oct file that you can dynamically load.

...

| Since it links with X, you can't use mkoctfile to compile it.
| The compile details are in the source.

Here is a patch for mkoctfile that should make things like

  mkoctfile ginput.cc -L/usr/X11R6/lib -lX11

work correctly.

Thanks,

jwe

Thu Sep 25 11:47:45 1997  John W. Eaton  <[hidden email]>

        * mkoctfile.in: Really add link options to link command.
        Also handle -LDIR options.


Index: mkoctfile.in
===================================================================
RCS file: /home/jwe/src/master/octave/mkoctfile.in,v
retrieving revision 1.10
diff -c -r1.10 mkoctfile.in
*** mkoctfile.in 1997/06/20 19:27:36 1.10
--- mkoctfile.in 1997/09/25 16:47:35
***************
*** 83,88 ****
--- 83,89 ----
 
    -h, -? --help           Print this message.
    -lLIB                   Add library LIB to link command.
+   -LDIR                   Add -LDIR to link command.
    -o FILE, --output FILE  Output file name.  Default extension is .oct.
    -s, --strip             Strip output file.
    -v, --verbose           Echo commands as they are executed.
***************
*** 100,106 ****
  EOF
        exit 0
      ;;
!     -l*)
        ldflags="$ldflags $1";;
      "")
        break
--- 101,107 ----
  EOF
        exit 0
      ;;
!     -[lL]*)
        ldflags="$ldflags $1";;
      "")
        break
***************
*** 181,188 ****
 
  # Link all the object files.
 
! $dbg $SH_LD $SH_LDFLAGS -o $octfile $objfiles
! eval $SH_LD $SH_LDFLAGS -o $octfile $objfiles
 
  # Maybe strip it.
 
--- 182,189 ----
 
  # Link all the object files.
 
! $dbg $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags
! eval $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags
 
  # Maybe strip it.