This is just a piece of eye candy, which is just a combination (and slight enhancement ) of examples which come with the PDL module. It is basically a little package which allows you to specify text and 3d position on a TriD graph.

The current OpenGL usage is still kind of tricky, but it's usable. The position of the text is specified as $x,$y,$z, where each can vary between 0 and 1, and represent the relative point in space where the left anchor of the text is attached. I'm sure there are many other things you can do with GL, but the docs are hard to find.

Anyways, you can just copy this package into your scripts, to give you text capability with changable text and position, or store it in a module.

To cycle thru the script, hit 'q' repeatedly.

#!/usr/bin/perl use warnings; use strict; use PDL::LiteF; use PDL::Graphics::TriD; use PDL::Graphics::TriD::GL; use PDL::Graphics::OpenGL; # hit 'q' repeatedly to cycle thru the script package TOBJ; BEGIN{@TOBJ::ISA = qw/PDL::Graphics::TriD::Object/;} use PDL::Graphics::OpenGLQ; use PDL::Graphics::OpenGL; my $self; sub new { my ($pkg, $lb, $text, $pos) = @_; # print "@_\n"; $self = bless { "lb" => $lb, "text" => $text, "x" => $pos->[0], "y" => $pos->[1], "z" => $pos->[2], }, $pkg; return $self; } sub togl { # print "togl @_\n"; glDisable(&GL_LIGHTING); glColor3f(1,0,1); glRasterPos3f($self->{'x'},$self->{'y'},$self->{'z'}); PDL::Graphics::OpenGL::glpPrintString($self->{'lb'}, $self->{'text +'}); glEnable(&GL_LIGHTING); } sub ctext{ print "ctext @_\n"; $self->{'text'} = $_[1]; if( $_[2] ){ my $pos = $_[2]; $self->{'x'} = $pos->[0], $self->{'y'} = $pos->[1], $self->{'z'} = $pos->[2], } } 1; ####################################################### package main; # little piddle to add some color my $pdlc = zeroes(3); #each elem has 3 elements my $col = $pdlc->slice('1:1,:,:'); #green #$col = $pdlc->slice('0:0,:,:'); #red $col += 1; #get GL window to pass to text object my $win = PDL::Graphics::TriD::get_current_window(); my $vp = $win->current_viewport; my $lb = $win->glpRasterFont("10x20",0,255); # glShadeModel (&GL_FLAT); glShadeModel (&GL_SMOOTH); my $tobj = new TOBJ($lb,'points3d SURF2D', [0,0,0]); $win->add_object($tobj); hold3d(); #objects built up to this point will be held my $nx = 20; my $t = (xvals zeroes $nx+1,$nx+1)/$nx; my $u = (yvals zeroes $nx+1,$nx+1)/$nx; my $x = sin($u*15 + $t * 3)/2+0.5 + 5*($t-0.5)**2; points3d(['SURF2D',$x],$pdlc); $vp->setview([3,3,3]); $tobj->ctext('line3d SURF2D',[0,0,0]); line3d(['SURF2D',$x],$pdlc); $vp->setview([3,-3,3]); $tobj->ctext('mesh3d',[0,0,.75]); mesh3d([$x]); $vp->setview([3,-3,-3]); $tobj->ctext('imag3d Lines=>0',[1,1,1]); imag3d([$x],{Lines => 0}); $vp->setview([-3,-3,-3]); $tobj->ctext('imag3d Lines => 0, Smooth => 1',[.75,.75,.75]); imag3d([$x],{Lines => 0, Smooth => 1}); $vp->setview([0,0,3]); $tobj->ctext('imag3d',[0,0,.5]); imag3d_ns([$x]);

In reply to Adding text to PDL's TriD 3d graphs by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.