"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Graphics/TriD/TriD.pm" between
PDL-2.076.tar.gz and PDL-2.077.tar.gz

About: PDL (Perl Data Language) aims to turn perl into an efficient numerical language for scientific computing (similar to IDL and MatLab).

TriD.pm  (PDL-2.076):TriD.pm  (PDL-2.077)
skipping to change at line 17 skipping to change at line 17
use PDL::Graphics::TriD; use PDL::Graphics::TriD;
# Generate a somewhat interesting sequence of points: # Generate a somewhat interesting sequence of points:
$t = sequence(100)/10; $t = sequence(100)/10;
$x = sin($t); $y = cos($t), $z = $t; $x = sin($t); $y = cos($t), $z = $t;
$coords = cat($x, $y, $z)->transpose; $coords = cat($x, $y, $z)->transpose;
my $red = cos(2*$t); my $green = sin($t); my $blue = $t; my $red = cos(2*$t); my $green = sin($t); my $blue = $t;
$colors = cat($red, $green, $blue)->transpose; $colors = cat($red, $green, $blue)->transpose;
# After each graph, let the user rotate and # After each graph, let the user rotate and
# wait for him to press 'q', then make new graph # wait for them to press 'q', then make new graph
line3d($coords); # $coords = (3,n,...) line3d($coords); # $coords = (3,n,...)
line3d($coords,$colors); # $colors = (3,n,...) line3d($coords,$colors); # $colors = (3,n,...)
line3d([$x,$y,$z]); line3d([$x,$y,$z]);
# Generate a somewhat interesting sequence of surfaces # Generate a somewhat interesting sequence of surfaces
$surf1 = (rvals(100, 100) / 50)**2 + sin(xvals(100, 100) / 10); $surf1 = (rvals(100, 100) / 50)**2 + sin(xvals(100, 100) / 10);
$surf2 = sqrt(rvals(zeroes(50,50))/2); $surf2 = sqrt(rvals(zeroes(50,50))/2);
$x = sin($surface); $y = cos($surface), $z = $surface; $x = sin($surface); $y = cos($surface), $z = $surface;
$coords = cat($x, $y, $z)->transpose; $coords = cat($x, $y, $z)->transpose;
$red = cos(2*$surface); $green = sin($surface); $blue = $surface; $red = cos(2*$surface); $green = sin($surface); $blue = $surface;
skipping to change at line 124 skipping to change at line 124
[$ndarray1,$ndarray2] [$ndarray1,$ndarray2]
[$ndarray1,$ndarray2,$ndarray3] [$ndarray1,$ndarray2,$ndarray3]
[CONTEXT,$ndarray] [CONTEXT,$ndarray]
[CONTEXT,$ndarray1,$ndarray2] [CONTEXT,$ndarray1,$ndarray2]
[CONTEXT,$ndarray1,$ndarray2,$ndarray3] [CONTEXT,$ndarray1,$ndarray2,$ndarray3]
where C<CONTEXT> is a string describing in which context you wish these where C<CONTEXT> is a string describing in which context you wish these
ndarrays to be interpreted. Each routine specifies a default context ndarrays to be interpreted. Each routine specifies a default context
which is explained in the routines documentation. which is explained in the routines documentation.
Context is usually used only to understand what the user wants Context is usually used only to understand what the user wants
when he/she specifies less than 3 ndarrays. when they specify less than 3 ndarrays.
The following contexts are currently supported: The following contexts are currently supported:
=over 8 =over 8
=item SURF2D =item SURF2D
A 2-D lattice. C< [$ndarray] > is interpreted as the Z coordinate over A 2-D lattice. C< [$ndarray] > is interpreted as the Z coordinate over
a lattice over the first dimension. Equivalent to a lattice over the first dimension. Equivalent to
C<< [$ndarray->xvals, $ndarray->yvals, $ndarray] >>. C<< [$ndarray->xvals, $ndarray->yvals, $ndarray] >>.
skipping to change at line 520 skipping to change at line 520
twiddle3d(); # animate one step, then return. twiddle3d(); # animate one step, then return.
} }
=head2 twiddle3d =head2 twiddle3d
=for ref =for ref
Wait for the user to rotate the image in 3D space. Wait for the user to rotate the image in 3D space.
Let the user rotate the image in 3D space, either for one step Let the user rotate the image in 3D space, either for one step
or until (s)he presses 'q', depending on the 'keeptwiddling3d' or until they press 'q', depending on the 'keeptwiddling3d'
setting. If 'keeptwiddling3d' is not set the routine returns setting. If 'keeptwiddling3d' is not set the routine returns
immediately and indicates that a 'q' event was received by immediately and indicates that a 'q' event was received by
returning 1. If the only events received were mouse events, returning 1. If the only events received were mouse events,
returns 0. returns 0.
=head2 close3d
=for ref
Close the currently-open 3D window.
=head1 CONCEPTS =head1 CONCEPTS
The key concepts (object types) of TriD are explained in the following: The key concepts (object types) of TriD are explained in the following:
=head2 Object =head2 Object
In this 3D abstraction, everything that you can "draw" In this 3D abstraction, everything that you can "draw"
without using indices is an Object. That is, if you have a surface, without using indices is an Object. That is, if you have a surface,
each vertex is not an object and neither is each segment of a long each vertex is not an object and neither is each segment of a long
curve. The whole curve (or a set of curves) is the lowest level Object. curve. The whole curve (or a set of curves) is the lowest level Object.
skipping to change at line 635 skipping to change at line 641
#KGB: NEEDS DOCS ON COMMON OPTIONS!!!!! #KGB: NEEDS DOCS ON COMMON OPTIONS!!!!!
# List of global variables # List of global variables
# #
# $PDL::Graphics::TriD::offline # $PDL::Graphics::TriD::offline
# $PDL::Graphics::TriD::Settings # $PDL::Graphics::TriD::Settings
$PDL::Graphics::TriD::verbose //= 0; $PDL::Graphics::TriD::verbose //= 0;
# $PDL::Graphics::TriD::keeptwiddling # $PDL::Graphics::TriD::keeptwiddling
# $PDL::Graphics::TriD::hold_on # $PDL::Graphics::TriD::hold_on
# $PDL::Graphics::TriD::curgraph # $PDL::Graphics::TriD::curgraph
# $PDL::Graphics::TriD::cur
# $PDL::Graphics::TriD::create_window_sub # $PDL::Graphics::TriD::create_window_sub
# $PDL::Graphics::TriD::current_window # $PDL::Graphics::TriD::current_window
# #
# ' # '
package PDL::Graphics::TriD; package PDL::Graphics::TriD;
use strict; use strict;
use warnings; use warnings;
use PDL::Exporter; use PDL::Exporter;
use PDL::Core ''; # barf use PDL::Core ''; # barf
our @ISA = qw/PDL::Exporter/; our @ISA = qw/PDL::Exporter/;
our @EXPORT_OK = qw/imag3d_ns imag3d line3d mesh3d lattice3d points3d our @EXPORT_OK = qw/imag3d_ns imag3d line3d mesh3d lattice3d points3d
spheres3d describe3d imagrgb imagrgb3d hold3d release3d spheres3d describe3d imagrgb imagrgb3d hold3d release3d
keeptwiddling3d nokeeptwiddling3d keeptwiddling3d nokeeptwiddling3d close3d
twiddle3d grabpic3d tridsettings/; twiddle3d grabpic3d tridsettings/;
our %EXPORT_TAGS = (Func=>\@EXPORT_OK); our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
our $verbose; our $verbose;
use PDL::Graphics::TriD::Object; use PDL::Graphics::TriD::Object;
use PDL::Graphics::TriD::Window; use PDL::Graphics::TriD::Window;
use PDL::Graphics::TriD::ViewPort; use PDL::Graphics::TriD::ViewPort;
use PDL::Graphics::TriD::Graph; use PDL::Graphics::TriD::Graph;
use PDL::Graphics::TriD::Quaternion; use PDL::Graphics::TriD::Quaternion;
use PDL::Graphics::TriD::Objects; use PDL::Graphics::TriD::Objects;
skipping to change at line 689 skipping to change at line 694
my $dv; my $dv;
# The following is just a sanity check. # The following is just a sanity check.
for($dev) { for($dev) {
# (/^OOGL$/ and $dv="PDL::Graphics::TriD::OOGL") or # (/^OOGL$/ and $dv="PDL::Graphics::TriD::OOGL") or
(/^GL$/ and $dv="PDL::Graphics::TriD::GL") or (/^GL$/ and $dv="PDL::Graphics::TriD::GL") or
(/^GLpic$/ and $dv="PDL::Graphics::TriD::GL" and $PDL::Graphics: :TriD::offline=1) or (/^GLpic$/ and $dv="PDL::Graphics::TriD::GL" and $PDL::Graphics: :TriD::offline=1) or
(/^VRML$/ and $dv="PDL::Graphics::TriD::VRML" and $PDL::Graphics ::TriD::offline=1) or (/^VRML$/ and $dv="PDL::Graphics::TriD::VRML" and $PDL::Graphics ::TriD::offline=1) or
(barf "Invalid PDL 3D device '$_' specified!"); (barf "Invalid PDL 3D device '$_' specified!");
} }
my $mod = $dv; my $mod = $dv;
$mod =~ s|::|//|g; $mod =~ s|::|/|g;
print "dev = $dev mod=$mod\n" if($verbose); print "dev = $dev mod=$mod\n" if($verbose);
require "$mod.pm"; require "$mod.pm";
$dv->import; $dv->import;
my $verbose; my $verbose;
} }
# currently only used by VRML backend # currently only used by VRML backend
$PDL::Graphics::TriD::Settings = $PDL::Graphics::TriD::Settings; $PDL::Graphics::TriD::Settings = $PDL::Graphics::TriD::Settings;
sub tridsettings {return $PDL::Graphics::TriD::Settings} sub tridsettings {return $PDL::Graphics::TriD::Settings}
skipping to change at line 779 skipping to change at line 784
*nokeeptwiddling3d=*nokeeptwiddling3d=\&PDL::nokeeptwiddling3d; *nokeeptwiddling3d=*nokeeptwiddling3d=\&PDL::nokeeptwiddling3d;
sub PDL::nokeeptwiddling3d { sub PDL::nokeeptwiddling3d {
$PDL::Graphics::TriD::keeptwiddling = 0 ; $PDL::Graphics::TriD::keeptwiddling = 0 ;
} }
keeptwiddling3d(); keeptwiddling3d();
*twiddle3d = *twiddle3d = \&PDL::twiddle3d; *twiddle3d = *twiddle3d = \&PDL::twiddle3d;
sub PDL::twiddle3d { sub PDL::twiddle3d {
twiddle_current(); twiddle_current();
} }
*close3d = *close3d = \&PDL::close3d;
sub PDL::close3d {
return if !ref $PDL::Graphics::TriD::current_window;
return if !$PDL::Graphics::TriD::current_window->can('close');
$PDL::Graphics::TriD::current_window->close;
}
sub graph_object { sub graph_object {
my($obj) = @_; my($obj) = @_;
if(!defined $obj or !ref $obj) { if(!defined $obj or !ref $obj) {
barf("Invalid object to TriD::graph_object"); barf("Invalid object to TriD::graph_object");
} }
print "graph_object: calling get_new_graph\n" if($PDL::debug_trid); print "graph_object: calling get_new_graph\n" if($PDL::Graphics::TriD::ve rbose);
my $g = get_new_graph(); my $g = get_new_graph();
print "graph_object: back from get_new_graph\n" if($PDL::debug_trid); print "graph_object: back from get_new_graph\n" if($PDL::Graphics::TriD::
verbose);
my $name = $g->add_dataseries($obj); my $name = $g->add_dataseries($obj);
$g->bind_default($name); $g->bind_default($name);
$g->scalethings(); $g->scalethings();
print "ADDED TO GRAPH: '$name'\n" if $PDL::Graphics::TriD::verbose; print "ADDED TO GRAPH: '$name'\n" if $PDL::Graphics::TriD::verbose;
twiddle_current(); twiddle_current();
return $obj; return $obj;
} }
# Plotting routines that use the whole viewport # Plotting routines that use the whole viewport
*describe3d=*describe3d=\&PDL::describe3d; *describe3d=*describe3d=\&PDL::describe3d;
sub PDL::describe3d { sub PDL::describe3d {
require PDL::Graphics::TriD::TextObjects; require PDL::Graphics::TriD::TextObjects;
my ($text) = @_; my ($text) = @_;
skipping to change at line 827 skipping to change at line 837
$win->twiddle(); $win->twiddle();
} }
# Plotting routines that use the 3D graph # Plotting routines that use the 3D graph
# Call: line3d([$x,$y,$z],[$color]); # Call: line3d([$x,$y,$z],[$color]);
*line3d=*line3d=\&PDL::line3d; *line3d=*line3d=\&PDL::line3d;
sub PDL::line3d { sub PDL::line3d {
&checkargs; &checkargs;
my $obj = new PDL::Graphics::TriD::LineStrip(@_); my $obj = new PDL::Graphics::TriD::LineStrip(@_);
print "line3d: object is $obj\n" if($PDL::debug_trid); print "line3d: object is $obj\n" if($PDL::Graphics::TriD::verbose);
&graph_object($obj); &graph_object($obj);
} }
*contour3d=*contour3d=\&PDL::contour3d; *contour3d=*contour3d=\&PDL::contour3d;
sub PDL::contour3d { sub PDL::contour3d {
# &checkargs; # &checkargs;
require PDL::Graphics::TriD::Contours; require PDL::Graphics::TriD::Contours;
&graph_object(new PDL::Graphics::TriD::Contours(@_)); &graph_object(new PDL::Graphics::TriD::Contours(@_));
} }
skipping to change at line 887 skipping to change at line 897
} }
*spheres3d=*spheres3d=\&PDL::spheres3d; *spheres3d=*spheres3d=\&PDL::spheres3d;
sub PDL::spheres3d { &checkargs; sub PDL::spheres3d { &checkargs;
&graph_object(new PDL::Graphics::TriD::Spheres(@_)); &graph_object(new PDL::Graphics::TriD::Spheres(@_));
} }
*grabpic3d=*grabpic3d=\&PDL::grabpic3d; *grabpic3d=*grabpic3d=\&PDL::grabpic3d;
sub PDL::grabpic3d { sub PDL::grabpic3d {
my $win = PDL::Graphics::TriD::get_current_window(); my $win = PDL::Graphics::TriD::get_current_window();
barf "backend doesn't support grabing the rendered scene" barf "backend doesn't support grabbing the rendered scene"
unless $win->can('read_picture'); unless $win->can('read_picture');
my $pic = $win->read_picture(); my $pic = $win->read_picture();
return ($pic->float) / 255; return ($pic->float) / 255;
} }
$PDL::Graphics::TriD::hold_on = 0; $PDL::Graphics::TriD::hold_on = 0;
sub PDL::hold3d {$PDL::Graphics::TriD::hold_on =(!defined $_[0] ? 1 : $_[0]);} sub PDL::hold3d {$PDL::Graphics::TriD::hold_on =(!defined $_[0] ? 1 : $_[0]);}
sub PDL::release3d {$PDL::Graphics::TriD::hold_on = 0;} sub PDL::release3d {$PDL::Graphics::TriD::hold_on = 0;}
*hold3d=*hold3d=\&PDL::hold3d; *hold3d=*hold3d=\&PDL::hold3d;
*release3d=*release3d=\&PDL::release3d; *release3d=*release3d=\&PDL::release3d;
sub get_new_graph { sub get_new_graph {
print "get_new_graph: calling PDL::Graphics::TriD::get_current_window...\n" if($PDL::debug_trid); print "get_new_graph: calling PDL::Graphics::TriD::get_current_window...\n" if($PDL::Graphics::TriD::verbose);
my $win = PDL::Graphics::TriD::get_current_window(); my $win = PDL::Graphics::TriD::get_current_window();
print "get_new_graph: calling get_current_graph...\n" if($PDL::debug_trid); print "get_new_graph: calling get_current_graph...\n" if($PDL::Graphics::Tri D::verbose);
my $g = get_current_graph($win); my $g = get_current_graph($win);
print "get_new_graph: back get_current_graph returned $g...\n" if($PDL::debu g_trid); print "get_new_graph: back get_current_graph returned $g...\n" if($PDL::Grap hics::TriD::verbose);
if(!$PDL::Graphics::TriD::hold_on) { if(!$PDL::Graphics::TriD::hold_on) {
$g->clear_data(); $g->clear_data();
$win->clear_viewport(); $win->clear_viewport();
} }
$g->default_axes(); $g->default_axes();
$win->add_object($g); $win->add_object($g);
return $g; return $g;
} }
skipping to change at line 931 skipping to change at line 941
my $g = $win->current_viewport()->graph(); my $g = $win->current_viewport()->graph();
if(!defined $g) { if(!defined $g) {
$g = new PDL::Graphics::TriD::Graph(); $g = new PDL::Graphics::TriD::Graph();
$g->default_axes(); $g->default_axes();
$win->current_viewport()->graph($g); $win->current_viewport()->graph($g);
} }
return $g; return $g;
} }
# $PDL::Graphics::TriD::cur = {};
# $PDL::Graphics::TriD::create_window_sub = undef; # $PDL::Graphics::TriD::create_window_sub = undef;
sub get_current_window { sub get_current_window {
my $opts = shift @_; my $opts = shift @_;
my $win = $PDL::Graphics::TriD::cur; my $win = $PDL::Graphics::TriD::current_window;
if(!defined $win) { if(!defined $win) {
if(!$PDL::Graphics::TriD::create_window_sub) { if(!$PDL::Graphics::TriD::create_window_sub) {
barf("PDL::Graphics::TriD must be used with a display mechanism: for example PDL::Graphics::TriD::GL!\n"); barf("PDL::Graphics::TriD must be used with a display mechanism: for example PDL::Graphics::TriD::GL!\n");
} }
print "get_current_window - creating window...\n" if($PDL::debug_trid); print "get_current_window - creating window...\n" if($PDL::Graphics::Tri
$win = new PDL::Graphics::TriD::Window($opts); D::verbose);
$PDL::Graphics::TriD::current_window = $win = new PDL::Graphics::TriD::W
indow($opts);
print "get_current_window - calling set_material...\n" if($PDL::debug_tr id); print "get_current_window - calling set_material...\n" if($PDL::Graphics ::TriD::verbose);
$win->set_material(new PDL::Graphics::TriD::Material); $win->set_material(new PDL::Graphics::TriD::Material);
$PDL::Graphics::TriD::current_window = $win;
$PDL::Graphics::TriD::cur = $win
} }
return $PDL::Graphics::TriD::current_window; return $PDL::Graphics::TriD::current_window;
} }
# Get the current graphbox # Get the current graphbox
sub get_current_graphbox { sub get_current_graphbox {
die "get_current_graphbox: ERROR graphbox is not implemented! \n"; die "get_current_graphbox: ERROR graphbox is not implemented! \n";
my $graph = $PDL::Graphics::TriD::curgraph; my $graph = $PDL::Graphics::TriD::curgraph;
if(!defined $graph) { if(!defined $graph) {
$graph = new PDL::Graphics::TriD::Graph(); $graph = new PDL::Graphics::TriD::Graph();
 End of changes. 21 change blocks. 
22 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)