[system] / trunk / pg / macros / LiveGraphics3D.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/LiveGraphics3D.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6248 - (download) (as text) (annotate)
Fri May 14 01:17:21 2010 UTC (9 years, 6 months ago) by gage
File size: 5953 byte(s)
major update which adds objective methods to the basic code of PG.
HEAD should be considered more beta than usual for a few days until minor glitches
are shaken out.
new modules needed:

PGcore PGalias PGresource PGloadfiles PGanswergroup PGresponsegroup  Tie::IxHash

    1 sub _LiveGraphics3D_init {}; # don't reload this file
    2 
    3 ###########################################################################
    4 #
    5 #   Macros for handling interactive 3D graphics via the LiveGraphics3D
    6 #   Java applet.  The applet needs to be in the course html directory.
    7 #   (If it is in the system html area, you will need to change the
    8 #   default below or supply the jar option explicitly).
    9 #
   10 #   The LiveGraphics3D applet displays a mathematica Graphics3D object
   11 #   that is stored in a .m file (or a compressed one).  Use Mathematica
   12 #   to create one.  (In the future, I plan to write a perl class that
   13 #   will create these for you on the fly. -- DPVC)
   14 #
   15 #   The main routines are
   16 #
   17 #      Live3Dfile          load a data file
   18 #      Live3Ddata          load raw Graphics3D data
   19 #      LiveGraphics3D      access to all parameters
   20 #
   21 
   22 #
   23 #  LiveGraphics3D(options)
   24 #
   25 #  Options are from:
   26 #
   27 #     file => name           name of .m file to load
   28 #
   29 #     archive => name        name of a .zip file to load
   30 #
   31 #     input => 3Ddata        string containing Graphics3D data to
   32 #                            be displayed by the applet
   33 #
   34 #     size => [w,h]          width and height of applet
   35 #
   36 #     vars => [vars]         hash of variables to pass as independent
   37 #                            variables to the applet, togther with
   38 #                            their initial values
   39 #                              e.g., vars => [a=>1,b=>1]
   40 #
   41 #     depend => [list]       list of dependent variables to pass to
   42 #                            the applet with their replacement strings
   43 #                            (see LiveGraphics3D documentation)
   44 #
   45 #     jar => URL             where to find the live.jar file
   46 #
   47 #     background=>"#RRGGBB"  the background color to use (default is white)
   48 #
   49 #     scale => n             scaling factor for applet (default is 1.)
   50 #
   51 #     image => file          a file containing an image to use in TeX mode
   52 #                            or when Java is disabled
   53 #
   54 #     tex_size => ratio      a scaling factor for the TeX image (as a portion
   55 #                            of the line width).
   56 #                                1000 is 100%, 500 is 50%, etc.
   57 #
   58 #     tex_center => 0 or 1   center the image in TeX mode or not
   59 #
   60 #     Live3D => [params]     hash of additional parameters to pass to
   61 #                            the Live3D applet.
   62 #                              e.g. Live3D => [VISIBLE_FACES => "FRONT"]
   63 #
   64 
   65 sub LiveGraphics3D {
   66   my %options = (
   67     size => [250,250],
   68     jar => findAppletCodebase("live.jar")."/live.jar",
   69     background => "#FFFFFF",
   70     scale => 1.,
   71     tex_size => 500,
   72     tex_cener => 0,
   73     @_
   74   );
   75   my $out = ""; my $p; my %pval;
   76   my $ratio = $options{tex_size} * (.001);
   77 
   78   if ($main::displayMode eq "TeX") {
   79     #
   80     #  In TeX mode, include the image, if there is one, or
   81     #   else give the user a message about using it on line
   82     #
   83     if ($options{image}) {
   84       $out = "\\includegraphics[width=$ratio\\linewidth]{$options{image}}";
   85       $out = "\\centerline{$out}" if $options{tex_center};
   86       $out .= "\n";
   87     } else {
   88       $out = "\\vbox{
   89          \\hbox{[ This image is created by}
   90          \\hbox{\\quad an interactive applet;}
   91          \\hbox{you must view it on line ]}
   92       }";
   93     }
   94   } else {
   95     my ($w,$h) = @{$options{size}};
   96     $out .= $bHTML if ($main::displayMode eq "Latex2HTML");
   97     #
   98     #  Put the applet in a table
   99     #
  100     $out .= qq{\n<TABLE BORDER="1" CELLSPACING="2" CELLPADDING="0">\n<TR>};
  101     $out .= qq{<TD WIDTH="$w" HEIGHT="$h" ALIGN="CENTER">};
  102     #
  103     #  start the applet
  104     #
  105     $out .= qq{
  106       <APPLET ARCHIVE="$options{jar}" CODE="Live.class" WIDTH="$w" HEIGHT="$h">
  107       <PARAM NAME="BGCOLOR" VALUE="$options{background}">
  108       <PARAM NAME="MAGNIFICATION" VALUE="$options{scale}">
  109     };
  110     #
  111     #  include the file or data
  112     #
  113     $out .= qq{<PARAM NAME="INPUT_ARCHIVE" VALUE="$options{archive}">\n}
  114       if ($options{archive});
  115     $out .= qq{<PARAM NAME="INPUT_FILE" VALUE="$options{file}">\n}
  116       if ($options{file});
  117     $out .= qq{<PARAM NAME="INPUT" VALUE="$options{input}">\n}
  118       if ($options{input});
  119     #
  120     #  include any independent variables
  121     #
  122     if ($options{vars}) {
  123       my @vars = (); %pval = @{$options{vars}};
  124       foreach $p (lex_sort(keys(%pval))) {push(@vars,"${p}->$pval{$p}");}
  125       $out .=
  126   '<PARAM NAME="INDEPENDENT_VARIABLES" VALUE="{'.join(',',@vars).'}">';
  127       $out .= "\n";
  128     }
  129     #
  130     #  include dependent variables
  131     #
  132     if ($options{depend}) {
  133       my @depend = (); $pval = @{$options{depend}};
  134       foreach $p (lex_sort(keys(%pval))) {push(@depend,"${p}->$pval{$p}");}
  135       $out .=
  136   '<PARAM NAME="DEPENDENT_VARIABLES" VALUE="{'.join(',',@depend).'}">';
  137       $out .= "\n";
  138     }
  139     #
  140     #  include any extra Live3D parameters
  141     #
  142     if ($options{Live3D}) {
  143       my %pval = @{$options{Live3D}};
  144       foreach $p (lex_sort(keys(%pval))) {
  145   $out .= qq{<PARAM NAME="$p" VALUE="$pval{$p}">\n};
  146       }
  147     }
  148     #
  149     #  End the applet and table
  150     #
  151     $out .= qq{<IMG SRC="$options{image}" BORDER="0">} if ($options{image});
  152     $out .= "<SMALL>[Enable Java to make this image interactive]</SMALL><BR>";
  153     $out .= "</APPLET>";
  154     $out .= "</TD></TD>\n</TABLE>\n";
  155     $out .= $eHTML if ($main::displayMode eq "Latex2HTML");
  156   }
  157 
  158   return $out;
  159 }
  160 
  161 #
  162 #  Syntactic sugar to make it easier to pass files and data to
  163 #  LiveGraphics3D.
  164 #
  165 sub Live3Dfile {
  166   my $file = shift;
  167   LiveGraphics3D(file => $file, @_);
  168 }
  169 
  170 #
  171 #  Syntactic sugar to make it easier to pass raw Graohics3D data
  172 #  to LiveGraphics3D.
  173 #
  174 sub Live3Ddata {
  175   my $data = shift;
  176   LiveGraphics3D(input => $data, @_);
  177 }
  178 
  179 
  180 #
  181 #  A message you can use for a caption under a graph
  182 #
  183 $LIVEMESSAGE = MODES(
  184   TeX => '',
  185   Latex2HTML =>
  186      $BCENTER.$BSMALL."Drag the surface to rotate it".$ESMALL.$ECENTER,
  187   HTML => $BCENTER.$BSMALL."Drag the surface to rotate it".$ESMALL.$ECENTER
  188 );
  189 
  190 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9