[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 6499 - (download) (as text) (annotate)
Thu Nov 11 13:03:14 2010 UTC (9 years, 2 months ago) by gage
File size: 6219 byte(s)
transferred some much used macro files to pg/macros for those not including the
NPL/macros/Union  directory in their macros search path

added PGanalyzeGraph to support graphical input

added POD documenta^tion to LiveGraphics3D.pl


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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9