~ubuntu-branches/ubuntu/trusty/pdl/trusty-proposed

« back to all changes in this revision

Viewing changes to Graphics/TriD/TriD.pm

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-12-05 12:37:41 UTC
  • mfrom: (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091205123741-ilqkc9s4zlk71z13
Tags: 1:2.4.5+dfsg-2ubuntu1
* Merge from debian testing (LP: #492898), remaining changes:
  - debian/perldl.conf: Enabled NAN support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
=head1 SYNOPSIS
6
6
 
7
 
use PDL::Graphics::TriD;
8
 
 
9
 
# After each graph, let the user rotate is and
10
 
# wait for him to press 'q', then make new graph
11
 
line3d($coords);       # $coords = (3,n,...)
12
 
line3d($coords,$colors);  # $colors = (3,n,...)
13
 
line3d([$x,$y,$z]);
14
 
imagrgb([$r,$g,$b]);
15
 
lattice3d([$x,$y,$z]); # 2-d piddles
16
 
points3d([$x,$y,$z]);
17
 
 
18
 
hold3d(); # the following graphs are on top of each other and the previous
19
 
line3d([$x,$y,$z]);
20
 
line3d([$x,$y,$z+1]);
21
 
$pic = grabpic3d(); # Returns the picture in a (3,$x,$y) float piddle (0..1).
22
 
 
23
 
release3d(); # the next graph will again wipe out things.
 
7
 use PDL::Graphics::TriD;
 
8
 
 
9
 # After each graph, let the user rotate is and
 
10
 # wait for him to press 'q', then make new graph
 
11
 line3d($coords);       # $coords = (3,n,...)
 
12
 line3d($coords,$colors);  # $colors = (3,n,...)
 
13
 line3d([$x,$y,$z]);
 
14
 imagrgb([$r,$g,$b]);
 
15
 lattice3d([$x,$y,$z]); # 2-d piddles
 
16
 points3d([$x,$y,$z]);
 
17
 
 
18
 hold3d(); # the following graphs are on top of each other and the previous
 
19
 line3d([$x,$y,$z]);
 
20
 line3d([$x,$y,$z+1]);
 
21
 $pic = grabpic3d(); # Returns the picture in a (3,$x,$y) float piddle (0..1).
 
22
 
 
23
 release3d(); # the next graph will again wipe out things.
24
24
 
25
25
 
26
26
=head1 WARNING
37
37
With OpenGL, it is easy to manipulate the resulting 3D objects
38
38
with the mouse in real time - this helps data visualization a lot.
39
39
 
 
40
=for comment
40
41
With VRML, you can generate objects for everyone to see with e.g.
41
42
Silicon Graphics' Cosmo Player. You can find out more about VRML
42
43
at C<http://vrml.sgi.com/> or C<http://www.vrml.org/>
61
62
OpenGL but off-line (pixmap) rendering and writing to
62
63
a graphics file.
63
64
 
64
 
=item VRML
 
65
=item VRML (I< Not available this release >)
65
66
 
66
67
VRML objects rendering. This writes a VRML file describing the
67
68
scene. This VRML file can then be read with  a browser.
93
94
 
94
95
The alternative syntaxes for specifying a set of coordinates (or colors) are
95
96
 
96
 
$piddle                             # MUST have 3 as first dim.
 
97
   $piddle                             # MUST have 3 as first dim.
97
98
  [$piddle]
98
99
  [$piddle1,$piddle2]
99
100
  [$piddle1,$piddle2,$piddle3]
113
114
 
114
115
=item SURF2D
115
116
 
116
 
A 2-D lattice. [$piddle] is interpreted as the Z coordinate over
 
117
A 2-D lattice. C< [$piddle] > is interpreted as the Z coordinate over
117
118
a lattice over the first dimension. Equivalent to
118
 
[$piddle->xvals, $piddle->yvals, $piddle].
 
119
C< [$piddle->xvals, $piddle->yvals, $piddle] >.
119
120
 
120
121
=item POLAR2D
121
122
 
122
 
A 2-D polar coordinate system. [$piddle] is interpreted as the
 
123
A 2-D polar coordinate system. C< [$piddle] > is interpreted as the
123
124
z coordinate over theta and r (theta = the first dimension of the piddle).
124
125
 
125
126
=item COLOR
126
127
 
127
 
A set of colors. [$piddle] is interpreted as grayscale color
128
 
(equivalent to [$piddle,$piddle,$piddle]).
 
128
A set of colors. C< [$piddle] > is interpreted as grayscale color
 
129
(equivalent to C< [$piddle,$piddle,$piddle] >).
129
130
 
130
131
=item LINE
131
132
 
132
 
A line made of 1 or 2 coordinates. [$piddle] is interpreted as
133
 
[$piddle->xvals,$piddle,0]. [$piddle1,$piddle2] is interpreted as
134
 
[$piddle1,$piddle2,$piddle1->xvals].
 
133
A line made of 1 or 2 coordinates. C< [$piddle] > is interpreted as
 
134
C< [$piddle->xvals,$piddle,0] >. C< [$piddle1,$piddle2] > is interpreted as
 
135
C< [$piddle1,$piddle2,$piddle1->xvals] >.
135
136
 
136
137
=back
137
138
 
142
143
 
143
144
you don't need to start thinking about where to plot the points:
144
145
 
145
 
        points3d([SURF2D,$zcoords]);
 
146
  points3d([SURF2D,$zcoords]);
146
147
 
147
148
will do exactly the same.
148
149
 
364
365
 nokeeptwiddling3d();
365
366
 $o = imag3d($c);
366
367
 while(1) {
367
 
        $c .= nextfunc($c);
368
 
        $o->data_changed();
369
 
        twiddle3d();            # animate one step, then return.
 
368
        $c .= nextfunc($c);
 
369
        $o->data_changed();
 
370
        twiddle3d();            # animate one step, then return.
370
371
 }
371
372
 
372
373
=head2 twiddle3d
468
469
This is a special class: in order to obtain a new viewport, you
469
470
need to have an earlier viewport on hand. The usage is:
470
471
 
471
 
        $new_vp = $old_vp->new_viewport($x0,$y0,$x1,$y1);
 
472
  $new_vp = $old_vp->new_viewport($x0,$y0,$x1,$y1);
472
473
 
473
474
where $x0 etc are the coordinates of the upper left and lower right
474
475
corners of the new viewport inside the previous (relative
525
526
        $dev ||= $::PDL::Graphics::TriD::device; # First, take it from this variable.
526
527
        $dev ||= $::ENV{PDL_3D_DEVICE};
527
528
 
528
 
        if(!defined $dev) {
529
 
#               warn "Default PDL 3D device is GL (OpenGL):
530
 
#Set PDL_3D_DEVICE=GL in your environment in order not to see this warning.
531
 
#You must have OpenGL or Mesa installed and the PDL::Graphics::OpenGL extension
532
 
#compiled. Otherwise you will get strange warnings.";
533
 
                $dev = $^O =~ /win32/i ? "VRML" : "GL";
534
 
        }
 
529
        if(!defined $dev) {
 
530
#            warn "Default PDL 3D device is GL (OpenGL):
 
531
# Set PDL_3D_DEVICE=GL in your environment in order not to see this warning.
 
532
# You must have OpenGL or Mesa installed and the PDL::Graphics::OpenGL extension
 
533
# compiled. Otherwise you will get strange warnings.";
 
534
 
 
535
           $dev = "GL";  # default GL works on all platforms now
 
536
        }
535
537
        my $dv;
536
538
# The following is just a sanity check.
537
539
        for($dev) {
865
867
 
866
868
sub new {
867
869
  my($type,@args) = @_;
868
 
  my $this = bless [\%{"$type\::FIELDS"}], $type;
 
870
  my $this = fields::new($type);
869
871
 
870
872
  $this->{Args} = [@args];
871
 
  return $this;
 
873
 
 
874
  $this;
872
875
}
873
876
 
874
877
package PDL::Graphics::TriD::Scale;