script runs fine - perl5.16.2, debian x64

On 22 January 2013 07:53, David Mertens <[email protected]> wrote:

> Frank, err... Chris, err... This is going to be a mixed email.
>
> 1) Frank, it sounds like everything works. Is this correct? In that case,
> if I can get away without digging out my code, I'd prefer not to. I believe
> that the GL program that I wrote only really displayed a 2d raster image,
> so I'm not sure how useful it would be to you. Couple that with the fact
> that said code may not even be on any of my current drives (I accidentally
> but literally toasted a hard drive shortly after writing my GL program),
> and I think I'd prefer not to root around for it up unless you think you
> really need it. :-)
>
> 2) To any POGL devs reading along, Frank's script segfaults on my machine.
> I'm pretty sure Perl library's aren't supposed to segfault on user data
> unless the user is using Inline. :-) Shall we start a separate thread and
> chase down this bug?
>
> David
>
>
> On Mon, Jan 21, 2013 at 6:36 AM, Frank Boers <[email protected]>wrote:
>
>> Hi Chris,
>> thank`s for your help.
>> I followed the link and downloaded the examples, very use full.
>> I followed vividsnow's suggestion to update and plot the data with OpenGL
>> and PDL and here is a working example.
>> Please have look into the script comments are welcome.
>>
>> best regards, happy for now
>>
>> Frank
>>
>> #!/usr/bin/perl -w
>>
>> use strict;
>> use OpenGL qw(:all);
>>
>> use PDL;
>> use PDL::Constants qw(PI);
>>     $PDL::BIGPDL = 1;
>>
>> my $pending = 0;
>>
>> #--- init demo data
>> my $tsl      = 10000; # time slices;
>> my $channels =     5; # channels to plot
>>
>> my $time_points  = pdl( sequence( $tsl ) /1000 )->float();
>> my $f0   = 2; # Hz
>> my $data = pdl( zeroes($channels,$time_points-**>dim(-1) ) )->float();
>>
>>       print"---> START init demo data\n";
>>       print"     Channels: $channels\n";
>>       print"     TSLs    : $tsl\n";
>>
>> my $t00 = time;
>>
>> my $f    = pdl( sequence($channels) ) +1 * $f0;
>>   # $data.= (sin( $time_points * $f->transpose *2* PI) )->transpose;
>>      $data.= (sin( $time_points * $f->transpose * PI) + cos( $time_points
>> *  $f->transpose * rand(100) * PI ) )->transpose;
>>
>>    $t00 = time() - $t00;
>>    print"---> DONE init demo data: $t00\n";
>>
>>
>> #-----------------------------**----------------------------#
>> #---- update_plot_pdl_to_vbo     -------------------------#
>> #---  copy pdl data to opengl vertex buffer
>> #---  generates a sub plot for each channel
>> #-----------------------------**----------------------------#
>> sub update_plot_pdl_to_vbo{
>>
>> my ($x,$y) = @_;
>>
>>    return if ( $pending );
>>    $pending = 1;
>> my $t00 = time;
>>
>> #--- init data for vertex buffer obj
>> my $data_4_vbo             = pdl( zeroes(2,$data->dim(-1) ) )->float();
>> my $data_4_vbo_timepoints  = $data_4_vbo->slice("(0),:");
>> my $data_4_vbo_signal      = $data_4_vbo->slice("(1),:");
>>      $data_4_vbo_timepoints .= $time_points;
>> my $data_vbo               = $data_4_vbo->flat;
>>
>> my $float_size = 4;
>>
>>
>>    glClear(GL_COLOR_BUFFER_BIT);
>>    glMatrixMode(GL_MODELVIEW);
>>    glLoadIdentity();
>>    glColor3f(0.0,0.0,1.0);
>>
>> #--- create OGL verts buffer
>>    glDisableClientState(GL_**VERTEX_ARRAY);
>>
>> my $VertexObjID = glGenBuffersARB_p(1);
>>    glBindBufferARB(GL_ARRAY_**BUFFER_ARB,$VertexObjID);
>>
>> my $ogl_array = OpenGL::Array->new_scalar(GL_**FLOAT,
>> $data_vbo->get_dataref,$data_**vbo->dim(0)*$float_size);
>>    glBufferDataARB_p(GL_ARRAY_**BUFFER_ARB,$ogl_array,GL_**
>> DYNAMIC_DRAW_ARB);
>>    $ogl_array->bind($VertexObjID)**;
>>    glVertexPointer_p(2,$ogl_**array);
>>    glEnableClientState(GL_VERTEX_**ARRAY);
>>
>> #---start sub plots
>>
>> my $w = glutGet( GLUT_WINDOW_WIDTH );
>> my $h = glutGet( GLUT_WINDOW_HEIGHT );
>>
>> my $w0 = 10;
>> my $w1 = $w-10;
>>
>> my $h0 = 0;
>> my $dh = int( $h / $data->dim(0) );
>> my $h1 = $dh;
>>
>> my $xmin = $time_points->min;
>> my $xmax = $time_points->max;
>> my $ymin = $data->min * 1.2;
>> my $ymax = $data->max * 1.2;
>>
>>
>> #--- copy data to VBO
>>    for ( my $i=0; $i < $data->dim(0); $i++ )
>>     {
>>
>> #--- sub plot window
>>       setViewport($w0,$w1,$h0,$h1);
>>       setWindow($xmin,$xmax,$ymin,$**ymax );
>>
>> #--- draw zero line
>>       glLineWidth(1);
>>       glColor3f(1,1,1);
>>
>>       glBegin(GL_LINES);
>>         glVertex2f($xmin,0.0);
>>         glVertex2f($xmax,0.0);
>>       glEnd();
>>
>> #--- start drawing signal
>>       glLineWidth(2);
>>       glColor3f(rand(1), rand(1),1.0);# mix color for each signal
>>
>> #--- copy pdl data to VBO thank's vividsnow !!!
>>       $data_4_vbo_signal .= $data->slice("($i),:");
>>       $ogl_array = OpenGL::Array->new_scalar(GL_**
>> FLOAT,$data_vbo->get_dataref,$**data_vbo->dim(0)*$float_size);
>>
>>       glBufferSubDataARB_p(GL_ARRAY_**BUFFER_ARB,0,$ogl_array);
>>
>>       glDrawArrays(GL_LINE_STRIP,0,$**data_4_vbo_timepoints->dim(-1)**-1
>> );
>>
>>       $h0 += $dh;
>>       $h1 += $dh + 1;
>>
>>      } # for
>>
>>   glBindBufferARB(GL_ARRAY_**BUFFER_ARB, 0);
>>
>>   glDisableClientState(GL_**VERTEX_ARRAY);
>>
>>   glFlush();
>>   glutSwapBuffers();
>>
>>   $pending = undef;
>>
>>   $t00 = time() - $t00;
>>
>>   print" done <update_plot_pdl_to_vbo> Time to update: $t00\n";
>>
>> } # end of update_plot_pdl_to_vbo
>>
>>
>>
>> #-----------------------------**----------------------------#
>> #---- setWindow                  -------------------------#
>> #-----------------------------**----------------------------#
>> sub setWindow{
>> my ($l,$r,$b,$t) = @_;
>>  glMatrixMode(GL_PROJECTION);
>>  glLoadIdentity();
>>  gluOrtho2D($l,$r,$b,$t);
>> } # end of setWindow
>>
>> #-----------------------------**----------------------------#
>> #---- setViewport                -------------------------#
>> #-----------------------------**----------------------------#
>> sub setViewport{
>> my ($l,$r,$b,$t) = @_;
>>  glViewport($l,$b,$r-$l,$t-$b);
>> }# end of setViewport
>>
>> #-----------------------------**----------------------------#
>> #---- myReshape                  -------------------------#
>> #-----------------------------**----------------------------#
>> sub myReshape{
>>
>> my($w,$h) = @_;
>>
>> return if (  $pending );
>>
>> glViewport(0,0,$w,$h);
>> glMatrixMode(GL_PROJECTION);
>> glLoadIdentity();
>> gluOrtho2D(0.0,$w,0.0,$h);
>>
>> } # end of reshape
>>
>>
>> #=== MAIN ==============================**=================
>>
>> glClearColor(1.0,1.0,1.0,0.0);
>> glColor3f(0.0,0.0,1.0);
>> glLineWidth(2);
>>
>> glutInit();
>>
>> glutInitDisplayMode(GLUT_**DOUBLE | GLUT_RGB | GLUT_ALPHA);
>>
>> glutInitWindowSize(300,400);
>> glutInitWindowPosition(10,10);
>>
>> my $IDwindow = glutCreateWindow("PDL OGL TEST");
>> glutDisplayFunc( sub{ update_plot_pdl_to_vbo(@_) } );
>>
>>
>> glutReshapeFunc( sub{ myReshape(@_) } );
>>
>> glutMainLoop();
>>
>>
>>
>>
>>
>> On 20.01.2013 00:14, Chris Marshall wrote:
>>
>>> Hi Frank-
>>>
>>> Without code I have to guess but my suspicion
>>> is that the difficulty lies in the OpenGL API and
>>> not the perl/PDL.  Here is a link that I found that
>>> seems useful:
>>>
>>>    
>>> http://www.songho.ca/opengl/**gl_vbo.html<http://www.songho.ca/opengl/gl_vbo.html>
>>>
>>> Sorry I don't have specific code but most of my
>>> OpenGL has been the 1.x fixed function pipeline
>>> stuff and haven't done much with 2.x and higher.
>>>
>>> --Chris
>>>
>>> On Sat, Jan 19, 2013 at 4:36 PM, Frank Boers<[email protected]>
>>>  wrote:
>>>
>>>> Dear PDL`s,
>>>> thank for your help.
>>>> Vividsnow`s code is working perfect. So first step is done.
>>>>
>>>> Now I`m trying to generate a subplot with a few more  sine wave signals
>>>> to
>>>> display.
>>>> Unfortunately I could not find out how to update the data in the opengl
>>>> vertex buffer to display different signals for each plot window.
>>>>
>>>> I did something like
>>>>    $ogl_data->assign_data(0,$**vert);
>>>>   or
>>>>    $ogl_data->assign_data(0,$**vert->get_dataref);
>>>>
>>>> but the plots showed only the first signal
>>>>
>>>> So how can I update the opengl vertex buffer with new data?
>>>>
>>>>
>>>>
>>>> On 19.01.2013 17:04, David Mertens wrote:
>>>>
>>>> Frank -
>>>>
>>>> Did these posts answer your questions? I did something like this, I
>>>> think, a
>>>> number of years ago and I can look through my old code to find it if you
>>>> would like more help.
>>>>
>>>> David
>>>>
>>>>
>>>> @David: Yes, please  other code and examples will help. It may end up in
>>>> some PP code like Craig suggested.
>>>>
>>>> My question is related to visualize time series data from MEG and EEG
>>>> recordings with PDL in a very fast way.
>>>> (~ 300 channels , ~20 minutes, 1kHz samplingrate, float )
>>>>
>>>> best regards
>>>> Frank
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Jan 17, 2013 at 8:46 AM, Craig DeForest<deforest@boulder.**
>>>> swri.edu <[email protected]>>
>>>> wrote:
>>>>
>>>>> vividsnow's answer is concise and great, but I'll expand a little bit.
>>>>> You
>>>>> can access the PDL data
>>>>> via "get_dataref", which returns a scalar ref whose scalar contains the
>>>>> data itself.  The data are in
>>>>> whatever order they happen to be in, which may (or may not) be the
>>>>> usual
>>>>> first-dimensions-fastest order.
>>>>> (freshly copy()'ed PDLs are guaranteed to be in that order).  If you
>>>>> want
>>>>> more control than that I suggest
>>>>> dropping down to PP or C with PDL::Inline or with XS -- then you can
>>>>> access the PDL data directly from compiled C.
>>>>>
>>>>>
>>>>>
>>>>> On Jan 17, 2013, at 3:58 AM, Frank Boers<[email protected]>
>>>>>  wrote:
>>>>>
>>>>>  Dear PDLs,
>>>>>>
>>>>>> how can I copy piddels direct to an opengl vertex buffer without
>>>>>> converting the piddel to a perl array?
>>>>>> Please have a look to the example, line 97- 98
>>>>>>
>>>>>> best regards
>>>>>> Frank
>>>>>>
>>>>>> #!/usr/bin/perl -w
>>>>>>
>>>>>> use strict;
>>>>>> use OpenGL qw(:all);
>>>>>>
>>>>>> use PDL;
>>>>>>
>>>>>> my $pending = 0;
>>>>>> my $t       = pdl(sequence(1000) );
>>>>>> my $data    = pdl( 10 * sin( $t * 10 * 6.28) )->float;
>>>>>>
>>>>>> #-----------------------------**----------------------------#
>>>>>> #---- setWindow                  -------------------------#
>>>>>> #-----------------------------**----------------------------#
>>>>>> sub setWindow{
>>>>>> my ($l,$r,$b,$t) = @_;
>>>>>>   glMatrixMode(GL_PROJECTION);
>>>>>>   glLoadIdentity();
>>>>>>   gluOrtho2D($l,$r,$b,$t);
>>>>>> } # end of setWindow
>>>>>>
>>>>>> #-----------------------------**----------------------------#
>>>>>> #---- setViewport                -------------------------#
>>>>>> #-----------------------------**----------------------------#
>>>>>> sub setViewport{
>>>>>> my ($l,$r,$b,$t) = @_;
>>>>>>   glViewport($l,$b,$r-$l,$t-$b);
>>>>>> }# end of setViewport
>>>>>>
>>>>>> #-----------------------------**----------------------------#
>>>>>> #---- myReshape                  -------------------------#
>>>>>> #-----------------------------**----------------------------#
>>>>>> sub myReshape{
>>>>>>
>>>>>> my($w,$h) = @_;
>>>>>>
>>>>>> return if (  $pending );
>>>>>>
>>>>>> glViewport(0,0,$w,$h);
>>>>>> glMatrixMode(GL_PROJECTION);
>>>>>> glLoadIdentity();
>>>>>> gluOrtho2D(0.0,$w,0.0,$h);
>>>>>>
>>>>>> } # end of reshape
>>>>>>
>>>>>> #-----------------------------**----------------------------#
>>>>>> #---- update_plot        -------------------------#
>>>>>> #-----------------------------**----------------------------#
>>>>>> sub update_plot{
>>>>>> my ($x,$y) = @_;
>>>>>>
>>>>>>    return if ( $pending );
>>>>>>    $pending = 1;
>>>>>>
>>>>>> #---
>>>>>> my $v = pdl( zeroes(2,$data->dim(0) ) )->float();
>>>>>> my $v0 = $v->slice("(0),:");
>>>>>> my $v1 = $v->slice("(1),:");
>>>>>>    $v0.= $t;
>>>>>> my $size= $v->nelem * 4;
>>>>>>
>>>>>>    glClear(GL_COLOR_BUFFER_BIT);
>>>>>>    glMatrixMode(GL_MODELVIEW);
>>>>>>    glLoadIdentity();
>>>>>>    glColor3f(0.0,0.0,1.0);
>>>>>>
>>>>>>
>>>>>> #--- create OGL verts buffer
>>>>>>    glDisableClientState(GL_**VERTEX_ARRAY);
>>>>>>
>>>>>> my $VertexObjID = glGenBuffersARB_p(1);
>>>>>>    glBindBufferARB(GL_ARRAY_**BUFFER_ARB, $VertexObjID);
>>>>>>
>>>>>>
>>>>>> my $verts = OpenGL::Array->new_list(GL_**FLOAT,$v->list() );
>>>>>>    $verts->bind($VertexObjID);
>>>>>>    glBufferDataARB_p(GL_ARRAY_**BUFFER_ARB, $verts,
>>>>>> GL_DYNAMIC_DRAW_ARB);
>>>>>>
>>>>>>    glVertexPointer_p(2,$verts);
>>>>>>
>>>>>>    glEnableClientState(GL_VERTEX_**ARRAY);
>>>>>>
>>>>>> #--- plot
>>>>>> my $w = glutGet( GLUT_WINDOW_WIDTH );
>>>>>> my $h = glutGet( GLUT_WINDOW_HEIGHT );
>>>>>>
>>>>>> my $w0 = 0;
>>>>>> my $w1 = $w-1;
>>>>>>
>>>>>> my $h0 = 0;
>>>>>>
>>>>>>    setViewport($w0,$w1,$h0,$h);
>>>>>>    setWindow($t->min,$t->max,$**data->min,$data->max );
>>>>>>
>>>>>>    $v1.= $data;
>>>>>>
>>>>>> ### !!!! this is slow  for large data
>>>>>>    $verts->assign( 0,$v->list() );
>>>>>>
>>>>>>    glBufferSubDataARB_p(GL_ARRAY_**BUFFER_ARB,0,$verts);
>>>>>>
>>>>>>    glDrawArrays(GL_LINE_STRIP,0,$**t->dim(-1)-1 );
>>>>>>
>>>>>>    glDisableClientState(GL_**VERTEX_ARRAY);
>>>>>>
>>>>>>    glFlush();
>>>>>>    glutSwapBuffers();
>>>>>>
>>>>>>   $pending = undef;
>>>>>>
>>>>>> } # end of update_plot
>>>>>>
>>>>>>
>>>>>> #=== MAIN
>>>>>> glClearColor(1.0,1.0,1.0,0.0);
>>>>>> glColor3f(0.0,0.0,1.0);
>>>>>> glLineWidth(2);
>>>>>>
>>>>>> glutInit();
>>>>>>
>>>>>> glutInitDisplayMode(GLUT_**DOUBLE | GLUT_RGB | GLUT_ALPHA);
>>>>>>
>>>>>> glutInitWindowSize(300,400);
>>>>>> glutInitWindowPosition(10,10);
>>>>>>
>>>>>> my $IDwindow = glutCreateWindow("PDL OGL TEST");
>>>>>> glutDisplayFunc( sub{ update_plot(@_) } );
>>>>>> glutReshapeFunc( sub{ myReshape(@_) } );
>>>>>>
>>>>>> glutMainLoop();
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Frank Boers
>>>>>> Institute of Neuroscience and Medicine - 4
>>>>>> Medical Imaging Physics
>>>>>> Forschungszentrum Juelich GmbH
>>>>>> 52425 Juelich
>>>>>> phone: +49 - (0)2461-61-6005
>>>>>> fax  : +49 - (0)2461-61-2820
>>>>>> email: [email protected]
>>>>>> http://www.fz-juelich.de/inm/**inm-4/DE/Forschung/MEG-Physik/**
>>>>>> _node.html<http://www.fz-juelich.de/inm/inm-4/DE/Forschung/MEG-Physik/_node.html>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ------------------------------**------------------------------**
>>>>>> ------------------------------**------
>>>>>>
>>>>>> ------------------------------**------------------------------**
>>>>>> ------------------------------**------
>>>>>> Forschungszentrum Juelich GmbH
>>>>>> 52425 Juelich
>>>>>> Sitz der Gesellschaft: Juelich
>>>>>> Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
>>>>>> Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
>>>>>> Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
>>>>>> Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
>>>>>> Prof. Dr. Sebastian M. Schmidt
>>>>>>
>>>>>> ------------------------------**------------------------------**
>>>>>> ------------------------------**------
>>>>>>
>>>>>> ------------------------------**------------------------------**
>>>>>> ------------------------------**------
>>>>>>
>>>>>> ______________________________**_________________
>>>>>> Perldl mailing list
>>>>>> [email protected]
>>>>>> http://mailman.jach.hawaii.**edu/mailman/listinfo/perldl<http://mailman.jach.hawaii.edu/mailman/listinfo/perldl>
>>>>>>
>>>>>>
>>>>> ______________________________**_________________
>>>>> Perldl mailing list
>>>>> [email protected]
>>>>> http://mailman.jach.hawaii.**edu/mailman/listinfo/perldl<http://mailman.jach.hawaii.edu/mailman/listinfo/perldl>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>   "Debugging is twice as hard as writing the code in the first place.
>>>>    Therefore, if you write the code as cleverly as possible, you are,
>>>>    by definition, not smart enough to debug it." -- Brian Kernighan
>>>>
>>>>
>>>> --
>>>> Frank Boers
>>>> Institute of Neuroscience and Medicine - 4
>>>> Medical Imaging Physics
>>>> Forschungszentrum Juelich GmbH
>>>> 52425 Juelich
>>>> phone: +49 - (0)2461-61-6005
>>>> fax  : +49 - (0)2461-61-2820
>>>> email: [email protected]
>>>> http://www.fz-juelich.de/inm/**inm-4/DE/Forschung/MEG-Physik/**
>>>> _node.html<http://www.fz-juelich.de/inm/inm-4/DE/Forschung/MEG-Physik/_node.html>
>>>>
>>>>
>>>> ______________________________**_________________
>>>> Perldl mailing list
>>>> [email protected]
>>>> http://mailman.jach.hawaii.**edu/mailman/listinfo/perldl<http://mailman.jach.hawaii.edu/mailman/listinfo/perldl>
>>>>
>>>>
>> --
>> Frank Boers
>> Institute of Neuroscience and Medicine - 4
>> Medical Imaging Physics
>> Forschungszentrum Juelich GmbH
>> 52425 Juelich
>> phone: +49 - (0)2461-61-6005
>> fax  : +49 - (0)2461-61-2820
>> email: [email protected]
>> http://www.fz-juelich.de/inm/**inm-4/DE/Forschung/MEG-Physik/**_node.html<http://www.fz-juelich.de/inm/inm-4/DE/Forschung/MEG-Physik/_node.html>
>>
>>
>>
>
>
> --
>  "Debugging is twice as hard as writing the code in the first place.
>   Therefore, if you write the code as cleverly as possible, you are,
>   by definition, not smart enough to debug it." -- Brian Kernighan
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to