Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r624 - in branches/itanium2: StandAlone UserInterface


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r624 - in branches/itanium2: StandAlone UserInterface
  • Date: Fri, 14 Oct 2005 04:42:00 -0600 (MDT)

Author: abe
Date: Fri Oct 14 04:41:59 2005
New Revision: 624

Modified:
   branches/itanium2/StandAlone/manta_tile_size.pl
   branches/itanium2/UserInterface/PromptUI.cc
   branches/itanium2/UserInterface/PromptUI.h
Log:

Half finished** the implementation of PromptUI to allow a perl script to 
manipulate manta using 
stdin and stdout. Useful for running batches of benchmarks where you want to 
change a parameter
(like tile size) without reloading all of the data. Before now we couldn't 
realistically run
some benchmarks with the boeing777 since it would require waiting for the 
data to load before each run.

Updated manta_tile_size.pl plotting script to use PromptUI and automatically 
produce a plot with unu.

Details on the wiki.***

M    StandAlone/manta_tile_size.pl
M    UserInterface/PromptUI.cc
M    UserInterface/PromptUI.h

** A masochistic human might try to use PromptUI in its current state instead 
of the X11 interface. 
It works pretty well with a perl script that doesn't mis-type the command 
line directives.

*** As soon as it is available.



Modified: branches/itanium2/StandAlone/manta_tile_size.pl
==============================================================================
--- branches/itanium2/StandAlone/manta_tile_size.pl     (original)
+++ branches/itanium2/StandAlone/manta_tile_size.pl     Fri Oct 14 04:41:59 
2005
@@ -1,5 +1,7 @@
 #!/usr/bin/perl
 
+use IPC::Open2;
+
 # Perl script for testing different tile sizes.
 # Use 
 # cat manta_tile_size_1_to_32.txt | unu save -f nrrd | unu reshape -s 32 32 
| unu rmap -m ~/data/colormap/rainbow3x12.nrrd | unu resample -s = 512 512 -k 
box | unu quantize -b 8 | unu save -f png -o tile.png
@@ -7,75 +9,103 @@
 # 
 # Abe Stephens abe@sgi.com
 
+# Updated October 2005 to use PromptUI so that scene doesn't need to
+# be reloaded between runs.
+
 ######################################################################
 # Default args.
 $np     = 1;
 @min    = (1, 1);
 @max    = (32, 32);
-@bench  = (5, 5);
-$file   = 0;
-$scene  = 0;
-$camera = 0;
+$file   = "-";
+$manta  = "";
+$path   = "";
+$title  = "Manta tile size plot";
+$nrrd_plot = 0;
+
+# Path parameters.
+$path   = "";
+$path_start = 0;
+$path_last  = 0;
+$path_sync  = 1;
 
 ######################################################################
 # Parse args.
 for ($i=0;$i<@ARGV;++$i) {
-    if ($ARGV[$i] eq "-np") {
-       $np = $ARGV[++$i];
-    }
-    elsif ($ARGV[$i] eq "-min") {
-       $res = $ARGV[++$i];
-       if ($res =~ /(\d+)x(\d+)/) {
-           $min[0] = $1;
-           $min[1] = $2;
-       }
-       else {
-           print "Bad resolution should be NxN\n";
-       }
+    if ($ARGV[$i] eq "-min") {
+        $res = $ARGV[++$i];
+        if ($res =~ /(\d+)x(\d+)/) {
+            $min[0] = $1;
+            $min[1] = $2;
+        }
+        else {
+            print "Bad resolution should be NxN\n";
+        }
     }
     elsif ($ARGV[$i] eq "-max") {
-       $res = $ARGV[++$i];
-       if ($res =~ /(\d+)x(\d+)/) {
-           $max[0] = $1;
-           $max[1] = $2;
-       }
-       else {
-           print "Bad resolution should be NxN\n";
-       }
+        $res = $ARGV[++$i];
+        if ($res =~ /(\d+)x(\d+)/) {
+            $max[0] = $1;
+            $max[1] = $2;
+        }
+        else {
+            print "Bad resolution should be NxN\n";
+        }
     }
     elsif ($ARGV[$i] eq "-o") {
-       $file = $ARGV[++$i];
-
+        $file = $ARGV[++$i];        
     }
-    elsif ($ARGV[$i] eq "-bench") {
-       $bench[0] = $ARGV[++$i];
-       $bench[1] = $ARGV[++$i];
+    elsif ($ARGV[$i] eq "-manta") {
+        $manta = $ARGV[++$i];
+    }
+    elsif ($ARGV[$i] eq "-path") {
+        $path = $ARGV[++$i];
     }    
-    elsif ($ARGV[$i] eq "-camera") {
-       $camera   = $ARGV[++$i];
+    elsif ($ARGV[$i] eq "-interval") {
+        $path_start   = $ARGV[++$i];
+        $path_last    = $ARGV[++$i];
+    }
+    elsif ($ARGV[$i] eq "-sync") {
+        $sync = $ARGV[++$i];
     }
-    elsif ($ARGV[$i] eq "-scene") {
-       $scene   = $ARGV[++$i];
+    elsif ($ARGV[$i] eq "-title") {
+        $title = $ARGV[++$i];
+    }
+    elsif ($ARGV[$i] eq "-plot") {
+        $nrrd_plot = 1;
     }
 }
 
 # Determine output file.
-if (!$file) {
+if (($manta eq "") || ($path eq "")) {
+
+    if ($manta eq "") {
+        print "-manta option missing\n";
+    }
+
+    if ($path eq "") {
+        print "-path option missing\n";
+    }
 
     # Print usage.
-    print "Usage: manta_tile_size.pl -o <filename or ->\n";
-    print "\t-np <num procs>   (default 1)\n";
+    print "Usage: manta_tile_size.pl -o <filename or -> -manta 
<manta_command> -path <camera_path>\n";
+    print "\t-manta <string>   (Command to run usually bin/manta -np ...)\n";
+    print "\t-path <file.txt>\n";
+    print "\t-interval M N     (default entire path)\n";
+    print "\t-sync N           (default 1)\n";
     print "\t-min NxN          (default 1x1)\n";
     print "\t-max NxN          (default 32x32)\n";
-    print "\t-o <out_file>     (required)\n";
-    print "\t-bench N M        (default is 5 5)\n";
+    print "\t-o <out_file>     (default stdout)\n";
+    print "\t-title <string>   (html plot title)\n";
+    print "\t-plot             (use unu to create a plot and html page)\n";
+
     exit(0);
 
 }
 elsif ($file ne "-") {
     if (!open( $out, "+>".$file )) {
-       print "Could not open output file.\n";
-       exit(0);
+        print "Could not open output file.\n";
+        exit(0);
     }
 }
 else {
@@ -83,54 +113,200 @@
 }
 
 
-######################################################################
-######################################################################
-# Main benchmark.
+# Invoke manta.
+$command = "$manta -ui prompt";
+
+if (!open2(MANTA_OUT,MANTA_IN, $command)) {
+    print "Could not open manta: $command\n";
+    exit(1);
+}
+
+# Create the camera path directive.
+$camera_path = "-ui camerapath( -file $path -sync $path_sync ";
+
+if ($path_last > 0) {
+    $camera_path = $camera_path . "-interval $path_start $path_last ";
+}
+$camera_path = $camera_path . ")\n";
 
+# Determine the total number of iterations.
 $iter = 0;
-$total = ($max[0]-$min[0]+1)*($max[1]-$min[1]+1);
+$size_x = ($max[0]-$min[0]+1);
+$size_y = ($max[1]-$min[1]+1);
+$total = $size_x * $size_y;
+
+$overall_max = 0.0;
+$overall_min = 999.0;
+
+$max_i = 0;
+$max_j = 0;
+$min_i = 0;
+$min_j = 0;
 
 for ($y=$min[1];$y<=$max[1];++$y) {
 
     for ($x=$min[0];$x<=$max[0];++$x) {
        
-       # Create the command.
-       $command = "bin/manta " .
-           " -np " . $np .
-           " -ui null -imagedisplay null " .
-           " -bench " . $bench[0] . " " . $bench[1] . " " .
-           " -imagetraverser \"tiled( -tilesize " . $x . "x" . $y . " )\" ";
-
-       if ($camera) {
-           $command = $command . " -camera \"$camera\"";
-       }
-
-       if ($scene) {
-           $command = $command . " -scene \"$scene\"";
-       }
-
-       print "" . ($iter+1) . " of " . $total . 
-             " (" . (($iter+1)/$total*100) . "%)\n";
-       print $command . "\n";
-
-       # Run the command.
-       if (!open( CMD, $command . "|" )) {
-           print "Error command failed.\n";
-           return 0;
-       }
+        # Create the image traverser directive.
+        $imagetraverser = " -imagetraverser \"tiled( -tilesize $x"."x"."$y 
)\"\n";
 
-       # Read the result 
-       $result = <CMD>;
+        # Set the image traverser.
+        print MANTA_IN $imagetraverser;
 
-       # Output result.
-       print $out $result;
+        # Run the camera path.
+        print MANTA_IN $camera_path;
 
-       ++$iter;
+        $total_samples = 0;
+        $total_fps     = 0;
+
+        # Collect path output or automator complete method.
+        current_run: while (<MANTA_OUT>) {
+
+            chomp;
+            $line = $_;
+
+            # See if the output line contains the complete message.
+            if ($line =~ /COMPLETE/) {
+                last current_run;
+            }
+
+            # Check to see how many columns are in the output.
+            if ($line =~ /^[0-9]+/) {
+                
+                @column = split(/[ \t]+/,$line);
+
+                # Look for five columns.
+                if ((@column == 5) && ($column[4] =~ /^[0-9]+[\.]?[0-9]?/)) {
+                    $total_fps = $total_fps + $column[4];
+                    $total_samples++;
+                }
+                
+                # Otherwise output a warning.
+                else {
+                    print "WARNING Unexpected output: $line\n";
+                }
+            }
+        }
+
+        # Output the average fps.
+        if ($total_samples > 0) {
+
+            $average_fps = ($total_fps/$total_samples);
+            print $out $average_fps . "\n";
+
+            # Update overall min and max.
+            if ($average_fps > $overall_max) {
+                $overall_max = $average_fps;
+
+                $max_i = $x;
+                $max_j = $y;
+            }
+            elsif ($average_fps < $overall_min) {
+                $overall_min = $average_fps;
+
+                $min_i = $x;
+                $min_j = $y;
+            }
+
+        }
+        else {
+            print "WARNING No samples collected.\n";
+        }
+        
+        # Output progress
+        print "PROGRESS: " . ($iter+1) . " of " . $total . 
+             " (" . (($iter+1)/$total*100) . "%)\n";
+        ++$iter;
     }
 } 
 
+print MANTA_IN "-quit\n";
+close MANTA_IN;
+close MANTA_OUT;
 
 # Produce a plot.
-print "cat $file | unu save -f nrrd | unu reshape -s 32 32 | unu rmap -m 
~/data/colormap/rainbow3x12.nrrd | unu resample -s = 512 512 -k box | unu 
quantize -b 8 | unu save -f png -o tile.png\n"
+if ($file ne "-") {
+
+    # Write out a temporary colormap file.
+    $colormap = "$file-colormap.temp.txt";
+    if (!open( TEMP, ">$colormap")) {
+        print "Could not open $colomap.\n";
+        exit( 1 );
+    }
+
+    # Output the rainbow colormap.
+    print TEMP "0 0 255\n";
+    print TEMP "0 102 255\n";
+    print TEMP "0 204 255\n";
+    print TEMP "0 255 204\n";
+    print TEMP "0 255 102\n";
+    print TEMP "0 255 0\n";
+    print TEMP "102 255 0\n";
+    print TEMP "204 255 0\n";
+    print TEMP "255 234 0\n";
+    print TEMP "255 204 0\n";
+    print TEMP "255 102 0\n";
+    print TEMP "255 0 0\n";
+
+    close( TEMP );
+
+
+    # Open html file.
+    if (!open( HTML, ">$file.html")) {
+        print "Could not open $file.html\n";
+        exit(1);
+    }
+
+    print HTML "<head title=\"$title\"></head>\n";
+    print HTML "<h1>$title</h1>\n";
+    print HTML "Generated using:<br><font face=\"courier\" 
size=-1>manta_path_plot.pl " . join(" ",@ARGV) . "</font><p>\n";    
+
+
+    # Form the unu command.
+    $file_png = "$file.png";
+    $command = "cat $file | " . 
+               "unu save -f nrrd | " .
+               "unu reshape -s $size_x $size_y | ". 
+               "unu rmap -m $colormap | " .
+               "unu resample -s = 512 512 -k box | ". 
+               "unu quantize -b 8 | unu save -f png -o $file_png\n";
+
+    print HTML "<font face=\"courier\" size=-1>plot command: 
$command</font><p>\n";
+
+    # Execute the command.
+    system( $command );
+
+    # Save the colormap.
+    $colormap_png = "$file-colormap.png";
+    $command = "cat $colormap | " . 
+               "unu save -f nrrd | " .
+               "unu reshape -s 3 1 12 |" .
+               "unu quantize -b 8 | unu save -f png -o $colormap_png\n";
+
+    print $command;
+    system( $command );
+
+    $overall_max = sprintf( "%3.2f", $overall_max );
+    $overall_min = sprintf( "%3.2f", $overall_min );
+
+
+    print HTML "<table>\n";
+    print HTML "<tr><td>$overall_min fps</td><td rowspan=3><img 
src=\"$file_png\"></td></tr>\n";
+    print HTML "<tr><td><img src=\"$colormap_png\" height=512></td></tr>\n";
+    print HTML "<tr><td>$overall_max fps</td></tr>\n";
+    print HTML "</table>\n";
+
+    print HTML "<font face=\"courier\" size=-1>\n";
+    print HTML "Max average fps: $max_i x $max_j<br>\n";
+    print HTML "Min average fps: $min_i x $min_j<br>\n";
+    print HTML "</font>\n";
+    
+    close(HTML);
+}
+
+
+
+
+
 
 

Modified: branches/itanium2/UserInterface/PromptUI.cc
==============================================================================
--- branches/itanium2/UserInterface/PromptUI.cc (original)
+++ branches/itanium2/UserInterface/PromptUI.cc Fri Oct 14 04:41:59 2005
@@ -1,8 +1,38 @@
 
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005
+  Scientific Computing and Imaging Institue, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
 #include <UserInterface/PromptUI.h>
+#include <UserInterface/AutomatorUI.h>
 #include <Interface/RTRTInterface.h>
-#include <Core/Util/Args.h>
+#include <Interface/Camera.h>
 #include <Interface/ShadowAlgorithm.h>
+#include <Core/Util/Args.h>
 #include <Core/Exceptions/Exception.h>
 #include <Core/Thread/Runnable.h>
 #include <Core/Thread/Thread.h>
@@ -18,21 +48,22 @@
 using SCIRun::Exception;
 using SCIRun::Thread;
 
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// SETUP  SETUP  SETUP  SETUP  SETUP  SETUP  SETUP  SETUP  SETUP  SETUP  
SETUP
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
 UserInterface* PromptUI::create(const vector<string>& args,
-                               RTRTInterface *rtrt_int) {
-  UserInterface *newUI = new PromptUI(args, rtrt_int);
-  // Probably need to create a thread and start it going.
+                               RTRTInterface *manta_interface_) {
 
-  return newUI;
+  return new PromptUI( args, manta_interface_ );
 }
 
-PromptUI::PromptUI(const vector<string>& args, RTRTInterface *rtrt_int):
-  rtrt_int(rtrt_int)
+PromptUI::PromptUI(const vector<string>& args, RTRTInterface 
*manta_interface_) :
+  manta_interface( manta_interface_ ),
+  current_channel( 0 )
 {
-  cout << "PromptUI::PromptUI created with args = (";
-  for(unsigned int i = 0; i < args.size(); i++)
-    cout << args[1] << ", ";
-  cout << ")\n";
 }
 
 PromptUI::~PromptUI() {
@@ -42,89 +73,252 @@
   (new Thread(this, "Manta User Interface"))->detach();
 }
 
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN  RUN 
 R
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
 void PromptUI::run() {
-  cout << "Prompt User Interface starting up...\n";
 
-  cout << "What is thy bidding my master?\n";
-  cout << "It's a desaster.  It's Skywalker we're after.\n";
-  cout << "But if he could be turned to the dark side?\n";
-  cout << "Yes, he'd be a powerful ally.  Another dark Jedi!\n";
-  cout << "He will join us or die...!\n";
-
-  for (;;) {
-    cout << "manta> ";
-
-    // Get the prompt
-    const int buf_size = 1000;
-    char command_buf[buf_size];
-    // Never use gets as it is unsafe to use (security).
-    fgets(command_buf, buf_size, stdin);
+  char buffer[256];
+  
+  while (1) {
+
+    // Read in a line from stdin.
+    cin.getline( buffer, 255 );
 
-    // Parse the command
-    vector<string> args;
     try {
-      parseArgs(string(command_buf), args);
-    } catch (Exception& e) {
-      cerr << e.message() << '\n';
-      continue;
-    }
-    if (args.size() < 1)
-      // No arguments
-      continue;
-    string command = args[0];
-
-    if (command == "show") {
-      show(args);
-    } else if (command == "quit") {
-      // kill the rtrt engine and stop
-      cout << "Are you sure you wish to kill everything (y/n)? ";
-      int response = fgetc(stdin);
-      if (response == 'y' || response == 'Y') {
-       cout << "Goodbye!\n";
-       Thread::exitAll(0);
-      } else {
-       cout << "\nNot quitting.\n";
-      }
-    } else if (command == "quitUI") {
-      cout << "PromptUI going away!\n";
-      return;
-    } else if (command == "help") {
-      cout << "The following commands are recognized:\n\n";
-      cout << "\tquit - stops the manta engine and exits the program\n";
-      cout << "\tquitUI - stops this user interface thread.\n";
-      cout << "\tshow S - show attributes specified by S (blank to see 
usage).\n";
-    } else {
-      cout << "Unknown command: "<<command<<".  Type help\n";
+      // Process the command.
+      processCommand( buffer );
+    }
+    catch (SCIRun::Exception &e) {
+      cerr << e.message() << std::endl;
+    }
+    catch (SCIRun::Exception *e) {
+      cerr << e->message() << std::endl;
     }
   }
 }
 
-void PromptUI::show(const vector<string>& args) {
-  if (args.size() < 2) {
-    // Print usage for show
-    cout << "Options for show\n";
-    cout << "\tshadows\n";
-    cout << "\tnumworkers\n";
+void PromptUI::processCommand( const string &input_line ) {
+
+  // Each line of input should contain:
+  // -option value"( -args ... )"
+  // Everything between the value( and ) will be passed to the 
manta_interface
+  // as a string. Note the quotes are unnecessary
+
+  // cerr << "Input line: " << input_line << endl;
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Find the option string.
+  string::const_iterator iter = input_line.begin();
+
+  // Skip leading whitespace.
+  while ((iter != input_line.end()) &&
+         (((*iter) == ' ') ||
+          ((*iter) == '\t')))
+    ++iter;
+
+  // Make sure the first character is a '-'
+  if (*iter != '-') {
     return;
   }
-  string command = args[1];
-  vector<string> results;
-  if (rtrt_int->queryState(command, results)) {
-    // the command was sucessful
-    if (command == "shadows") {
-      if (results.size() != 2) {
-       cerr << "queryState returned the wrong number of args for shadows.  
Wanted 2 and got "<<results.size()<<".\n";
-       return;
+
+  string::const_iterator begin = iter;  
+  
+  // Advance to white space.
+  while ((iter != input_line.end()) &&
+         !(((*iter) == ' ') ||
+           ((*iter) == '\t')))
+    ++iter;
+
+  // Found the option string.
+  string option_string( begin, iter );
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Find the value string.
+
+  // Skip white space
+  while ((iter != input_line.end()) &&
+         (((*iter) == ' ') ||
+          ((*iter) == '\t')))
+    ++iter;
+
+  begin = iter;
+
+  // Find either a space or the end of the line.
+  while ((iter != input_line.end()) &&
+         !(((*iter) == ' ') ||
+           ((*iter) == '(')))
+    ++iter;
+
+  // Check to see if args are specified.
+  if (*iter == '(') {
+
+    while ((iter != input_line.end()) &&
+         !((*iter) == ')'))
+    ++iter;
+
+    // Advance one past the closing ')'
+    if (iter != input_line.end())
+      ++iter;
+  }
+
+  string value_string( begin, iter );
+
+  // cerr << "Parsed directive: option: " << option_string << " value: " << 
value_string << std::endl;
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Match the option string to a known option.
+
+  try {
+  
+    if (option_string == "-help") {
+      printHelp();
+    }
+    else if (option_string == "-bench") {
+    }
+    else if (option_string == "-camera") {
+      manta_interface->addTransaction( "select camera",
+                                       Callback::create( this, 
PromptUI::mantaCamera, value_string ));
+    }
+    else if (option_string == "-idlemode") {
+    }
+    else if (option_string == "-imagetraverser") {
+      manta_interface->addTransaction( "select imagetraverser",
+                                       Callback::create( this, 
PromptUI::mantaImageTraverser, value_string ));
+    }
+    else if (option_string == "-loadbalancer") {
+    }
+    else if (option_string == "-np") {
+    }  
+    else if (option_string == "-pixelsampler") {
+    }  
+    else if (option_string == "-renderer") {
+    }
+    else if (option_string == "-scene") {
+    }  
+    else if (option_string == "-shadows") {
+    }  
+    else if (option_string == "-ui") {
+      UserInterface *ui = manta_interface->createUserInterface( value_string 
);
+
+      // Make sure a ui was created.
+      if (ui == 0) {
+        return;
       }
-      cout << "Current shadow algorithm is ("<<results[0]<<") with specs 
("<<results[1]<<")\n";
-    } else if (command == "numworkers") {
-      if (results.size() != 1) {
-       cerr << "queryState returned the wrong number of args for numworkers. 
 Wanted 1 and got "<<results.size()<<".\n";
-       return;
+    
+      // Check to see if the ui is a Automator.
+      AutomatorUI *automator = dynamic_cast<AutomatorUI *>( ui );
+      if (automator != 0) {
+
+        // Set the termination callback so we know when the automator 
finishes.
+        automator->set_terminate_callback( Callback::create( this, 
automatorComplete ));
       }
-      cout << "Number of workers are "<<results[0]<<".\n";
+
+      // Start the ui.
+      ui->startup();
     }
-  } else {
-    cout << "Unknown option \""<<command<<"\" for show\n";
+    else if (option_string == "-quit") {
+
+      Thread::exitAll( 0 );
+    }
+
+  } catch (SCIRun::Exception *e) {
+    cerr << "Caught exception: " << e->message() << std::endl << std::endl;
+  } catch (SCIRun::Exception& e) {
+    cerr << "Caught exception: " << e.message() << '\n';
+    if(e.stackTrace())
+      cerr << "Stack trace: " << e.stackTrace() << '\n';
+  } catch (std::exception e){
+    cerr << "Caught std exception: " << e.what() << '\n';
+               
+  } catch(...){
+    cerr << "Caught unknown exception\n";
+  }
+  
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// TRANSACTION CALLBACKS  TRANSACTION CALLBACKS  TRANSACTION CALLBACKS  
TRANSAC
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+void PromptUI::mantaCamera( const string text ) {
+
+  // Create the camera.
+       Camera *new_camera = manta_interface->createCamera( text );
+       if (new_camera == 0) {
+               std::cerr << "Could not select camera " << text << std::endl;
+               return;
+       }
+
+  // Get the old camera.
+  Camera *old_camera = manta_interface->getCamera( current_channel );
+       
+       // Replace the camera.
+       manta_interface->setCamera( current_channel, new_camera );
+       
+       delete old_camera;  
+}
+
+void PromptUI::mantaImageTraverser( const string text ) {
+
+  manta_interface->selectImageTraverser( text );
+}
+
+void PromptUI::automatorComplete() {
+
+  std::cout << "PROMPT_UI_AUTOMATOR_COMPLETE" << std::endl;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// HELP  HELP  HELP  HELP  HELP  HELP  HELP  HELP  HELP  HELP  HELP  HELP  
HELP
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+void PromptUI::printHelp() {
+
+  cerr << "Usage: manta [options]\n";
+  cerr << "Valid options are:\n";
+  cerr << " -help           - Print this message and exit\n";
+  cerr << " -bench [N [M]]  - Time N frames after an M frame warmup period 
and print out the framerate,\n";
+  cerr << "                   default N=100, M=10\n";
+  cerr << " -np N           - Use N processors\n";
+  cerr << " -res NxM        - Use N by M pixels for rendering (needs the 
x).\n";
+  cerr << " -imagedisplay S - Use image display mode named S, valid modes 
are:\n";
+  printList(cerr, manta_interface->listImageDisplays(), 4);
+  cerr << " -imagetype S    - Use image display mode named S, valid modes 
are:\n";
+  printList(cerr, manta_interface->listImageTypes(), 4);
+  cerr << " -ui S           - Use the user interface S, valid options 
are:\n";
+  printList(cerr, manta_interface->listUserInterfaces(), 4);
+  cerr << " -shadows S      - Use S mode for rendering shadows, valid modes 
are:\n";
+  printList(cerr, manta_interface->listShadowAlgorithms(), 4);
+  cerr << " -imagetraverser S - Use S method for image traversing, valid 
modes are:\n";
+  printList(cerr, manta_interface->listImageTraversers(), 4);
+  cerr << " -pixelsampler S - Use S method for pixel sampling, valid modes 
are:\n";
+  printList(cerr, manta_interface->listPixelSamplers(), 4);
+  cerr << " -camera S       - User camera model S, valid cameras are:\n";
+  printList(cerr, manta_interface->listCameras(), 4);
+  cerr << " -renderer S     - Use renderer S, valid renderers are:\n";
+  printList(cerr, manta_interface->listRenderers(), 2);
+  cerr << " -scene S        - Render Scene S\n";
+}
+
+// This method prints a list of options.
+void PromptUI::printList( ostream& out, const RTRTInterface::listType& list, 
int spaces ) {
+  
+  for(int i=0;i<spaces;i++)
+    out << ' ';
+  
+  for(RTRTInterface::listType::const_iterator iter = list.begin();
+      iter != list.end(); ++iter){
+    if(iter != list.begin())
+      out << ", ";
+    out << *iter;
   }
+  out << "\n";
 }

Modified: branches/itanium2/UserInterface/PromptUI.h
==============================================================================
--- branches/itanium2/UserInterface/PromptUI.h  (original)
+++ branches/itanium2/UserInterface/PromptUI.h  Fri Oct 14 04:41:59 2005
@@ -1,8 +1,35 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
 
+  The MIT License
+
+  Copyright (c) 2005
+  Scientific Computing and Imaging Institue, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
 
 #ifndef RTRT_PromptUI_h
 #define RTRT_PromptUI_h
 
+#include <Interface/RTRTInterface.h>
 #include <Interface/UserInterface.h>
 #include <Core/Thread/Runnable.h>
 
@@ -15,24 +42,52 @@
   using namespace std;
 
   class RTRTInterface;
-  
+
+  
/////////////////////////////////////////////////////////////////////////////
+  
///////////////////////////////////////////////////////////////////////////// 
 
+  // PromptUI is a userinterface which listens on STDIN for command line
+  // directives and then changes manta's state. The directives match 
bin/manta
+  // command line args.
+  //
+  // PromptUI is designed to be driven by a perl script for batch benchmarks.
+  //
+  // In general, manta outputs performance information on STDOUT and outputs
+  // all other warnings and messages on STDERR. PromptUI will listen on STDIN
+  // but by default won't output anything on STDOUT unless an error occurs.
+  //
+  
/////////////////////////////////////////////////////////////////////////////
+  
///////////////////////////////////////////////////////////////////////////// 
 
   class PromptUI: public UserInterface, public SCIRun::Runnable {
+  protected:
+    RTRTInterface *manta_interface;
+
+    // Channel that the ui is operating on.
+    int current_channel;
+
+    // Helper methods.
+    void printHelp();
+    void printList( ostream& out, const RTRTInterface::listType& list, int 
spaces=0 );
+
+    void processCommand( const string &input_line );
+
+    // Transaction callbacks
+    void mantaCamera( const string text );
+    void mantaImageTraverser( const string text );
+
+    void automatorComplete();
+    
   public:
     PromptUI(const vector<string>& args, RTRTInterface *rtrt_int);
     virtual ~PromptUI();
 
+    // UserInterface method.
     virtual void startup();
 
+    // Runnable method.
     virtual void run();
 
     static UserInterface* create(const vector<string>& args,
-                                RTRTInterface *rtrt_int);
-
-  protected:
-    // This is a pointer to the interface we will use to interact with manta.
-    RTRTInterface *rtrt_int;
-
-    void show(const vector<string>& args);
+                                 RTRTInterface *manta_interface_ );
     
   private:
     PromptUI(const PromptUI&);




  • [MANTA] r624 - in branches/itanium2: StandAlone UserInterface, abe, 10/14/2005

Archive powered by MHonArc 2.6.16.

Top of page