diff --git a/Rout/rout.pd b/Rout/rout.pd index 4af5300..cc50c8c 100644 --- a/Rout/rout.pd +++ b/Rout/rout.pd @@ -12,184 +12,10 @@ PDL::Graphics::TriD::Rout - Helper routines for Three-dimensional graphics =head1 DESCRIPTION This module is for miscellaneous PP-defined utility routines for -the PDL::Graphics::TriD module. Currently, there are +the PDL::Graphics::TriD module. EOD -pp_def( - 'combcoords', - GenericTypes => ['F','D'], - DefaultFlow => 1, - Pars => 'x(); y(); z(); - float [o]coords(tri=3);', - Code => ' - $coords(tri => 0) = $x(); - $coords(tri => 1) = $y(); - $coords(tri => 2) = $z(); - ', - Doc => < ['F','D'], - Pars => 'coords(nc,np); - [o]vecs(nc,np); - int [t]links(np);', - OtherPars => ' - double boxsize; - int dmult; - double a; - double b; - double c; - double d; - ', - Code => ' - double a = $COMP(a); - double b = $COMP(b); - double c = $COMP(c); - double d = $COMP(d); - int ind; int x,y,z; - HV *hv = newHV(); - double boxsize = $COMP(boxsize); - int dmult = $COMP(dmult); - loop(np) %{ - int index = 0; - $links() = -1; - loop(nc) %{ - $vecs() = 0; - index *= dmult; - index += (int)($coords()/boxsize); - %} - /* Repulse old (shame to use x,y,z...) */ - for(x=-1; x<=1; x++) { - for(y=-1; y<=1; y++) { - for(z=-1; z<=1; z++) { - int ni = index + x + dmult * y + - dmult * dmult * z; - SV **svp = hv_fetch(hv, (char *)&ni, sizeof(int), - 0); - if(svp && *svp) { - ind = SvIV(*svp) - 1; - while(ind>=0) { - double dist = 0; - double dist2; - double tmp; - double func; - loop(nc) %{ - tmp = - ($coords() - - $coords(np => ind)); - dist += tmp * tmp; - %} - dist = sqrt(1/(sqrt(dist)+d)); - func = c * dist; - dist2 = dist * dist; - func += b * dist2; - dist2 *= dist2; - func += a * dist2; - loop(nc) %{ - tmp = - ($coords() - - $coords(np => ind)); - $vecs() -= - func * tmp; - $vecs(np => ind) += - func * tmp; - %} - ind = $links(np => ind); - } - } - } - } - } - /* Store new */ - SV **svp = hv_fetch(hv, (char *)&index, sizeof(index), 1); - if(!svp || !*svp) - $CROAK("Invalid sv from hvfetch"); - SV *sv = *svp; - int npv; - if(SvOK(sv) && (npv = SvIV(sv))) { - npv --; - $links() = $links(np => npv); - $links(np => npv) = np; - } else { - sv_setiv(sv,np+1); - $links() = -1; - } - %} - hv_undef(hv); - ', Doc => ' -=for ref - -Repulsive potential for molecule-like constructs. - -C uses a hash table of cubes to quickly calculate -a repulsive force that vanishes at infinity for many -objects. For use by the module L. -For definition of the potential, see the actual function. -' -); - -pp_def( - 'attract', - GenericTypes => ['F','D'], - Pars => 'coords(nc,np); - int from(nl); - int to(nl); - strength(nl); - [o]vecs(nc,np);', - OtherPars => ' - double m; - double ms; - ', - Code => ' - double m = $COMP(m); - double ms = $COMP(ms); - loop(nc,np) %{ $vecs() = 0; %} - loop(nl) %{ - int f = $from(); - int t = $to(); - double s = $strength(); - double dist = 0; - double tmp; - loop(nc) %{ - tmp = $coords(np => f) - - $coords(np => t); - dist += tmp * tmp; - %} - s *= ms * dist + m * sqrt(dist); - loop(nc) %{ - tmp = $coords(np => f) - - $coords(np => t); - $vecs(np => f) -= tmp * s; - $vecs(np => t) += tmp * s; - %} - %} - ', Doc => ' -=for ref - -Attractive potential for molecule-like constructs. - -C is used to calculate -an attractive force for many -objects, of which some attract each other (in a way -like molecular bonds). -For use by the module L. -For definition of the potential, see the actual function. -' -); - sub trid { my ($par,$ind) = @_; join ',', map {"\$$par($ind => $_)"} (0..2); diff --git a/TriD.pm b/TriD.pm index 74e599c..c0012bd 100644 --- a/TriD.pm +++ b/TriD.pm @@ -728,7 +728,7 @@ use PDL::Graphics::TriD::ViewPort; use PDL::Graphics::TriD::Graph; use PDL::Graphics::TriD::Quaternion; use PDL::Graphics::TriD::Objects; -use PDL::Graphics::TriD::Rout; +use PDL::ImageND; # Then, see which display method are we using: @@ -805,7 +805,7 @@ sub realcoords { $c[$_] = $c[$_]*(PDL->ones($c[($_+1)%3]->dims)); } } - my $g = PDL::Graphics::TriD::Rout::combcoords(@c); + my $g = PDL::ImageND::combcoords(@c); $g->dump if $PDL::Graphics::TriD::verbose; return $g; } diff --git a/TriD/MathGraph.pm b/TriD/MathGraph.pm index 5265d7c..c12e935 100644 --- a/TriD/MathGraph.pm +++ b/TriD/MathGraph.pm @@ -51,7 +51,7 @@ sub get_valid_options { package PDL::GraphEvolver; use PDL::Lite; -use PDL::Graphics::TriD::Rout ":Func"; +use PDL::ImageND ":Func"; sub new { my($type,$coords) = @_; @@ -62,17 +62,9 @@ sub new { },$type; } -sub set_links { - my($this,$from,$to,$strength) = @_; - $this->{From} = $from; - $this->{To} = $to; - $this->{Strength} = $strength; -} +sub set_links { my $this = shift; @$this{qw(From To Strength)} = @_; } -sub set_fixed { - my($this,$ind,$coord) = @_; - $this->{FInd} = $ind; $this->{FCoord} = $coord; -} +sub set_fixed { my $this = shift; @$this{qw(FInd FCoord)} = @_; } sub step { my($this) = @_; @@ -84,12 +76,11 @@ sub step { $this->{Velo} *= (0.92*50/(50+$this->{Velo}->magnover->dummy(0)))**$tst; $c += $tst * 0.05 * $this->{Velo}; - (my $tmp = $c->transpose->index($this->{FInd}->dummy(0))) - .= $this->{FCoord} - if (defined $this->{FInd}); + $c->transpose->index($this->{FInd}->dummy(0)) .= $this->{FCoord} + if (defined $this->{FInd}); print "C: $c\n" if $PDL::Graphics::TriD::verbose; } -sub getcoords {return $_[0]{Coords}} +sub getcoords {$_[0]{Coords}} 1;