[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 6289 - (download) (as text) (annotate)
Mon May 31 18:41:40 2010 UTC (9 years, 6 months ago) by gage
File size: 6125 byte(s)
 brings the pg copy in line with the copy in NPL/macros/Union

    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 => "live.jar", # "${htmlURL}live.jar",
   69     codebase => findAppletCodebase("live.jar"),
   70     # codebase => "http://hosted2.webwork.rochester.edu/webwork2_files/applets/",  # used for testing
   71     background => "#FFFFFF",
   72     scale => 1.,
   73     tex_size => 500,
   74     tex_cener => 0,
   75     @_
   76   );
   77   my $out = ""; my $p; my %pval;
   78   my $ratio = $options{tex_size} * (.001);
   79 
   80   if ($main::displayMode eq "TeX") {
   81     #
   82     #  In TeX mode, include the image, if there is one, or
   83     #   else give the user a message about using it on line
   84     #
   85     if ($options{image}) {
   86       $out = "\\includegraphics[width=$ratio\\linewidth]{$options{image}}";
   87       $out = "\\centerline{$out}" if $options{tex_center};
   88       $out .= "\n";
   89     } else {
   90       $out = "\\vbox{
   91          \\hbox{[ This image is created by}
   92          \\hbox{\\quad an interactive applet;}
   93          \\hbox{you must view it on line ]}
   94       }";
   95     }
   96   } else {
   97     my ($w,$h) = @{$options{size}};
   98     $out .= $bHTML if ($main::displayMode eq "Latex2HTML");
   99     #
  100     #  Put the applet in a table
  101     #
  102     $out .= qq{\n<TABLE BORDER="1" CELLSPACING="2" CELLPADDING="0">\n<TR>};
  103     $out .= qq{<TD WIDTH="$w" HEIGHT="$h" ALIGN="CENTER">};
  104     #
  105     #  start the applet
  106     #
  107     $out .= qq{
  108       <APPLET CODEBASE="$options{codebase}" ARCHIVE="$options{jar}" CODE="Live.class" WIDTH="$w" HEIGHT="$h">
  109       <PARAM NAME="BGCOLOR" VALUE="$options{background}">
  110       <PARAM NAME="MAGNIFICATION" VALUE="$options{scale}">
  111     };
  112     #
  113     #  include the file or data
  114     #
  115     $out .= qq{<PARAM NAME="INPUT_ARCHIVE" VALUE="$options{archive}">\n}
  116       if ($options{archive});
  117     $out .= qq{<PARAM NAME="INPUT_FILE" VALUE="$options{file}">\n}
  118       if ($options{file});
  119     $out .= qq{<PARAM NAME="INPUT" VALUE="$options{input}">\n}
  120       if ($options{input});
  121     #
  122     #  include any independent variables
  123     #
  124     if ($options{vars}) {
  125       my @vars = (); %pval = @{$options{vars}};
  126       foreach $p (lex_sort(keys(%pval))) {push(@vars,"${p}->$pval{$p}");}
  127       $out .=
  128   '<PARAM NAME="INDEPENDENT_VARIABLES" VALUE="{'.join(',',@vars).'}">';
  129       $out .= "\n";
  130     }
  131     #
  132     #  include dependent variables
  133     #
  134     if ($options{depend}) {
  135       my @depend = (); $pval = @{$options{depend}};
  136       foreach $p (lex_sort(keys(%pval))) {push(@depend,"${p}->$pval{$p}");}
  137       $out .=
  138   '<PARAM NAME="DEPENDENT_VARIABLES" VALUE="{'.join(',',@depend).'}">';
  139       $out .= "\n";
  140     }
  141     #
  142     #  include any extra Live3D parameters
  143     #
  144     if ($options{Live3D}) {
  145       my %pval = @{$options{Live3D}};
  146       foreach $p (lex_sort(keys(%pval))) {
  147   $out .= qq{<PARAM NAME="$p" VALUE="$pval{$p}">\n};
  148       }
  149     }
  150     #
  151     #  End the applet and table
  152     #
  153     $out .= qq{<IMG SRC="$options{image}" BORDER="0">} if ($options{image});
  154     $out .= "<SMALL>[Enable Java to make this image interactive]</SMALL><BR>";
  155     $out .= "</APPLET>";
  156     $out .= "</TD></TD>\n</TABLE>\n";
  157     $out .= $eHTML if ($main::displayMode eq "Latex2HTML");
  158   }
  159 
  160   return $out;
  161 }
  162 
  163 #
  164 #  Syntactic sugar to make it easier to pass files and data to
  165 #  LiveGraphics3D.
  166 #
  167 sub Live3Dfile {
  168   my $file = shift;
  169   LiveGraphics3D(file => $file, @_);
  170 }
  171 
  172 #
  173 #  Syntactic sugar to make it easier to pass raw Graohics3D data
  174 #  to LiveGraphics3D.
  175 #
  176 sub Live3Ddata {
  177   my $data = shift;
  178   LiveGraphics3D(input => $data, @_);
  179 }
  180 
  181 
  182 #
  183 #  A message you can use for a caption under a graph
  184 #
  185 $LIVEMESSAGE = MODES(
  186   TeX => '',
  187   Latex2HTML =>
  188      $BCENTER.$BSMALL."Drag the surface to rotate it".$ESMALL.$ECENTER,
  189   HTML => $BCENTER.$BSMALL."Drag the surface to rotate it".$ESMALL.$ECENTER
  190 );
  191 
  192 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9