TriD1.pm (PDL-2.077) | : | TriD1.pm (PDL-2.078) | ||
---|---|---|---|---|

# Copyright (C) 1998 Tuomas J. Lukka. | # Copyright (C) 1998 Tuomas J. Lukka. | |||

# All rights reserved, except redistribution | # All rights reserved, except redistribution | |||

# with PDL under the PDL License permitted. | # with PDL under the PDL License permitted. | |||

package PDL::Demos::TriD1; | package PDL::Demos::TriD1; | |||

use PDL::Graphics::TriD; | use PDL::Graphics::TriD; | |||

use PDL::Graphics::TriD::Image; | ||||

sub info {('3d', '3d demo (requires TriD with OpenGL or Mesa)')} | sub info {('3d', '3d demo (requires TriD with OpenGL or Mesa)')} | |||

sub init {' | sub init {' | |||

use PDL::Graphics::TriD; | use PDL::Graphics::TriD; | |||

use PDL::Graphics::TriD::Image; | ||||

'} | '} | |||

my @demo = ( | my @demo = ( | |||

[comment => q| | [comment => q| | |||

Welcome to a short tour of the capabilities of | Welcome to a short tour of the capabilities of | |||

PDL::Graphics::TriD. | PDL::Graphics::TriD. | |||

Press 'q' in the graphics window for the next screen. | Press 'q' in the graphics window for the next screen. | |||

Rotate the image by pressing mouse button one and | Rotate the image by pressing mouse button one and | |||

dragging in the graphics window. | dragging in the graphics window. | |||

Zoom in/out by pressing MB3 and drag up/down. | Zoom in/out by pressing MB3 and drag up/down. | |||

Note that a standalone TriD script must start with | Note that a standalone TriD script must start with | |||

use PDL; | use PDL; | |||

use PDL::Graphics::TriD; | use PDL::Graphics::TriD; | |||

use PDL::Graphics::TriD::Image; | ||||

to work properly. | to work properly. | |||

|], | |], | |||

[actnw => q| | [actnw => q| | |||

# See if we had a 3D window open already | # See if we had a 3D window open already | |||

$|.__PACKAGE__.q|::we_opened = !defined $PDL::Graphics::TriD::current_win dow; | $|.__PACKAGE__.q|::we_opened = !defined $PDL::Graphics::TriD::current_win dow; | |||

# Number of subdivisions for lines / surfaces. | # Number of subdivisions for lines / surfaces. | |||

$size = 25; | $size = 25; | |||

skipping to change at line 93 | skipping to change at line 90 | |||

imag3d_ns [$x,$y,$z], [$r,$g,$b]; # Draw a colored surface | imag3d_ns [$x,$y,$z], [$r,$g,$b]; # Draw a colored surface | |||

# [press 'q' in the graphics window when done] | # [press 'q' in the graphics window when done] | |||

|], | |], | |||

[actnw => q| | [actnw => q| | |||

imag3d [$x,$y,$z]; # Draw a shaded surface | imag3d [$x,$y,$z]; # Draw a shaded surface | |||

# [press 'q' in the graphics window when done] | # [press 'q' in the graphics window when done] | |||

|], | |], | |||

[actnw => q| | [actnw => q| | |||

# Draw a textured surface | # Draw a shaded, coloured, unsmoothed (default is on) surface | |||

imag3d [$x,$y,$z], [$x,$y,$z], { | imag3d [$x,$y,$z], [$x,$y,$z], { Smooth => 0 }; | |||

Material => PDL::Graphics::TriD::Material->new( | # [press 'q' in the graphics window when done] | |||

Shine => 0.212766, | |], | |||

Specular =>[0.753217,0.934416,1], | ||||

Ambient =>[0,0,0], | [actnw => q| | |||

Diffuse =>[0.09855,0.153113,0.191489], | # Draw a shaded, coloured, smoothed (the default) surface | |||

Emissive =>[0, 0, 0] | imag3d [$x,$y,$z], [$x,$y,$z]; | |||

), | ||||

}; | ||||

# [press 'q' in the graphics window when done] | # [press 'q' in the graphics window when done] | |||

|], | |], | |||

[actnw => q| | [actnw => q| | |||

hold3d(); # Leave the previous object in.. | hold3d(); # Leave the previous object in.. | |||

imag3d_ns [$x,$y,$z+1], [$r,$g,$b]; | imag3d_ns [$x,$y,$z+1], [$r,$g,$b]; | |||

# ...and draw a colored surface on top of it... | # ...and draw a colored surface on top of it... | |||

# [press 'q' in the graphics window when done] | # [press 'q' in the graphics window when done] | |||

|], | |], | |||

skipping to change at line 157 | skipping to change at line 152 | |||

[actnw => q| | [actnw => q| | |||

# 3. You can plot in certain other systems as defaults | # 3. You can plot in certain other systems as defaults | |||

imag3d_ns [POLAR2D, $z], [$r, $g, $b]; # Draw the familiar | imag3d_ns [POLAR2D, $z], [$r, $g, $b]; # Draw the familiar | |||

# bumpy surface in polar | # bumpy surface in polar | |||

# coordinates | # coordinates | |||

# [press 'q' in the graphics window when done] | # [press 'q' in the graphics window when done] | |||

|], | |], | |||

[actnw => q| | [actnw => q| | |||

# One last thing: you can plot a color image like this | # Show graph-evolver | |||

imagrgb([$r,$g,$b]); | use PDL::Graphics::TriD::MathGraph; | |||

use PDL::Graphics::TriD::Labels; | ||||

my @coords = ([0,-1,0], [-1,-1,-2], [3,5,2], | ||||

[2,1,-3], [1,3,1], [1,1,2]); | ||||

my $from = PDL->pdl(indx, [0,1,2,3,4,4,4,5,5,5]); | ||||

my $to = PDL->pdl(indx, [1,2,3,1,0,2,3,0,1,2]); | ||||

my @names = map ' '.join(",",@$_), @coords; | ||||

my $e = PDL::GraphEvolver->new(pdl(@coords)); | ||||

$e->set_links($from,$to,PDL->ones(1)); | ||||

my $c = $e->getcoords; | ||||

my $graph = PDL::Graphics::TriD::get_new_graph(); # also clears | ||||

hold3d(); | ||||

nokeeptwiddling3d(); | ||||

PDL::Graphics::TriD::graph_object( | ||||

my $lab = PDL::Graphics::TriD::Labels->new($c,{Strings => \@names})); | ||||

PDL::Graphics::TriD::graph_object( | ||||

my $lin = PDL::Graphics::TriD::MathGraph->new( | ||||

$c, {From => $from, To => $to})); | ||||

PDL::Graphics::TriD::graph_object( | ||||

my $sph = PDL::Graphics::TriD::Spheres->new($c)); | ||||

my $ind = 0; | ||||

while(1) { | ||||

$e->step(); | ||||

if(++$ind%2 == 0) { | ||||

$_->data_changed for $lab, $lin, $sph; | ||||

$graph->scalethings() if (($ind % 200) == 0 or 1); | ||||

last if twiddle3d(); | ||||

} | ||||

} | ||||

keeptwiddling3d(); | ||||

release3d(); | ||||

# [press 'q' in the graphics window when done] | ||||

|], | ||||

[actnw => q| | ||||

# Show the world! | ||||

use PDL::Transform::Cartography; | ||||

$shape = earth_shape(); | ||||

$floats = t_raster2float()->apply($shape->mv(2,0)); | ||||

$radius = $floats->slice('(2)'); # r g b all same | ||||

$radius *= float((6377.09863 - 6370.69873) / 6371); | ||||

$radius += float(6370.69873 / 6371); | ||||

$e_i = earth_image('day'); | ||||

$earth = t_raster2float()->apply($e_i->mv(2,0)); | ||||

$earth = $earth->append($radius->dummy(0)); | ||||

$shrink = 2.5; # how much to shrink by | ||||

$new_x = int($e_i->dim(0) / $shrink); | ||||

$earth2 = $earth->mv(0,2)->match([$new_x,int($new_x/2),6])->mv(2,0); # sh | ||||

rink | ||||

($lonlatrad, $rgb) = map $earth2->slice($_), pdl(0,1,5), '2:4'; | ||||

$sph = t_spherical()->inverse()->apply($lonlatrad); | ||||

imag3d($sph, $rgb, {Lines=>0}); | ||||

# [press 'q' in the graphics window when done] | ||||

|], | ||||

[actnw => q| | ||||

# Show off the world! | ||||

# The Earth's radius doesn't proportionally vary much, | ||||

# but let's exaggerate it to prove we have height information! | ||||

$lonlatrad->slice('2') -= 1; | ||||

$lonlatrad->slice('2') *= 100; | ||||

$lonlatrad->slice('2') += 1; | ||||

$sph = t_spherical()->inverse()->apply($lonlatrad); | ||||

imag3d($sph, $rgb, {Lines=>0}); | ||||

# [press 'q' in the graphics window when done] | ||||

|], | ||||

[actnw => q| | ||||

# Now zoom in over Europe | ||||

($lats, $lons) = map $_ / 180, pdl(22, 72), pdl(-10, 40); | ||||

$lats = indx(($lats + 0.5) * $earth->dim(2)); | ||||

$lons = indx((($lons + 1) / 2) * $earth->dim(1)); | ||||

$earth3 = $earth->slice(':', map [$_->list], $lons, $lats)->sever; # zoom | ||||

($lonlatrad, $rgb) = map $earth3->slice($_), pdl(0,1,5), '2:4'; | ||||

$lonlatrad->slice('2') -= 1; | ||||

$lonlatrad->slice('2') *= 50; # exaggerate terrain but less | ||||

$lonlatrad->slice('2') += 1; | ||||

$sph = t_spherical()->inverse()->apply($lonlatrad); | ||||

imag3d($sph, $rgb, {Lines=>0}); | ||||

# [press 'q' in the graphics window when done] | # [press 'q' in the graphics window when done] | |||

|], | |], | |||

[actnw => q| | [actnw => q| | |||

# '3d2' contains some of the more special constructions available | # '3d2' contains some of the more special constructions available | |||

# in the PDL::Graphics::TriD modules. | # in the PDL::Graphics::TriD modules. | |||

# close 3D window if we opened it | # close 3D window if we opened it | |||

close3d() if $|.__PACKAGE__.q|::we_opened; | close3d() if $|.__PACKAGE__.q|::we_opened; | |||

|], | |], | |||

End of changes. 5 change blocks. | ||||

15 lines changed or deleted | | 88 lines changed or added |