[Index for tmp_for_tar/vrml.doc] [Return to Master Index]

vrml_browse

(tmp_for_tar/vrml.doc/vrml_browse.m)


Function Synopsis

p = vrml_browse (s)

Help text

  p = vrml_browse ([s])       - View vrml code s with FreeWRL
      vrml_browse ("-kill")   - Kill the browser

 s : string : VRML code, as returned by the vrml_XYZ functions. 
              If  s  is not specified, a sombrero is showed

 p : int    : pid of the current browser. If freewrl has not been started
              or has died, a new one is started. p is zero or negative in
              case of failure to start freewrl.

 Some keystrokes for FreeWRL (more in the freewrl manpage) :

 'e'   : Examine : mouse 1 rotates the scene
                   mouse 3 moves closer/farther          
 'w'   : Walk    : mouse 1 moves for/backward, turns
                   mouse 3 translates parallely to screen
 's'   : Save a snapshot in files 'octave.snapshot.NNNN.ppm'
 'q'   : Quit

 WARNING : FreeWRL >0.25 (http://www.crc.ca/FreeWRL/) must be installed

 BUG     : The vrml browser is not killed when octave exits. Sometimes the
           vrml browser does not get raised or gets raised improperly
           (shows the contents of the topmost window above it). Use
           "-kill".



Cross-Reference Information

This function calls

Listing of function file tmp_for_tar/vrml.doc/vrml_browse.m

##  p = vrml_browse ([s])       - View vrml code s with FreeWRL
##      vrml_browse ("-kill")   - Kill the browser
##
## s : string : VRML code, as returned by the vrml_XYZ functions. 
##              If  s  is not specified, a sombrero is showed
##
## p : int    : pid of the current browser. If freewrl has not been started
##              or has died, a new one is started. p is zero or negative in
##              case of failure to start freewrl.
##
## Some keystrokes for FreeWRL (more in the freewrl manpage) :
##
## 'e'   : Examine : mouse 1 rotates the scene
##                   mouse 3 moves closer/farther          
## 'w'   : Walk    : mouse 1 moves for/backward, turns
##                   mouse 3 translates parallely to screen
## 's'   : Save a snapshot in files 'octave.snapshot.NNNN.ppm'
## 'q'   : Quit
## 
## WARNING : FreeWRL >0.25 (http://www.crc.ca/FreeWRL/) must be installed
##
## BUG     : The vrml browser is not killed when octave exits. Sometimes the
##           vrml browser does not get raised or gets raised improperly
##           (shows the contents of the topmost window above it). Use
##           "-kill".
##
## Author  : Etienne Grossmann   <etienne@isr.ist.utl.pt>
function p = vrml_browse (s)

verbose = 0 ;
best_option = " ";		# "-best" or fast rendering

				# Allow scripting and specify where
				# browser's output goes 
out_option = "-ps -psout /tmp/octave_browser_out.txt " ;
global vrml_b_pid = 0;
global vrml_b_name = [];

p = vrml_b_pid ;

if nargin<1, s = ""; end

if strcmp (s, "-kill"),
  s = "";
  if vrml_b_pid, 
    printf ("vrml_browse : Sending kill signal to browser\n");
    system (sprintf ("kill -KILL %d &> /dev/null",vrml_b_pid));
  else
    printf ("vrml_browse : No live browser to kill\n");
  end
  vrml_b_pid = 0;
  return
end

## freewrl_can_serve = 1 ;		# Assume freewrl's a server

## if freewrl_can_serve,
  
vrml_b_name = "freewrl" ;
## b_opt = "-best -server" ;
b_opt = [out_option," ",best_option," -server -snapb octave.snap "] ;

				# Not a server : Use my silly wrapper
#  else
#    if isempty (vrml_b_name),
#      vrml_b_name = file_in_path (LOADPATH,"silly_browser.pl")
#    end
#    if isempty (vrml_b_name),
#      printf ("vrml_browse : can't find browser ... sorry\n");
#      return
#    end
#    b_opt  = [best_option," -sig"] ;
#  end
## vrml_b_name = "/home/etienne/prog/octave/mylib/tools/vrml/silly_browser.pl" ;


b_temp = "/tmp/octave_vrml_output.wrl" ;
b_log  = " &> /tmp/octave_vrml_browser.log";

new_browser = 0 ;
				# ####################################
if vrml_b_pid > 0,		# There's already a browser ##########

				# Check that browser is really alive

  [dum,status]=system (sprintf ("kill -CONT %d &> /dev/null",vrml_b_pid));
  
  if ! status,
    sayif (verbose, "vrml_browse : browser pid=%d is still alive\n",vrml_b_pid);

  else 
    sayif (verbose, ["vrml_browse : ",\
	     "browser pid=%d has died. I'll spawn another\n"], vrml_b_pid);
    vrml_b_pid = -1 ;
  end
end				# End of check if old browser's alive 
				# ####################################

				# ####################################
				# Check that temp file exists ########
[dum,status] = system (["test -e ",b_temp]);
if !length (s),

  sayif (verbose, "vrml_browse : Trying to create temp file\n");

				# Do a sombrero
  n = 30 ;
  x = y = linspace (-8, 8, n)';
  [xx, yy] = meshgrid (x, y);
  r = sqrt (xx .^ 2 + yy .^ 2) + eps;
  z = 3*sin (r) ./ (2*r);
  x /= 4 ; y /= 4 ;

  ##  pix = ones (n) ;
  ##    tmp = [1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 0 ;\
  ##  	 0 1 1 0 1 0 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1 ;\
  ##  	 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 1 0 0 0 ;\
  ##  	 0 1 1 0 1 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 1 1 ;\
  ##  	 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 1 0 0 0 ];

  ##    rtmp = rows(tmp)+2;
  ##    for i=1:rtmp:n-rtmp,
  ##      pix(i+[1:rows(tmp)],1:columns(tmp)) = tmp ;
  ##    end
  ##    pix = flipud (pix);
  ##    col = [1;1;1]*pix(:)' ;
  ## keyboard
  rmat = [0.90000  -0.38730   0.20000;
	  0.38730   0.50000  -0.77460;
	  0.20000   0.77460   0.60000];
  ## s = vrml_points ([x(:),y(:),z(:)],"balls");
  ## s =  vrml_transfo (vrml_thick_surf (x,y,z, "col",col), [0.25,0,0],rmat);
  s =  vrml_transfo (vrml_thick_surf (x,y,z), [0.25,0,0],rmat );
end	


save_vrml (b_temp, s); # "nobg", s) ;
				# End of preparing temp file #########
				# ####################################

				# ####################################
				# Eventually start browser ###########
if vrml_b_pid <= 0,
  new_browser = 1 ;
  sayif (verbose, "vrml_browse : spawning browser ...\n");
  ## keyboard
				# Starting a background browser : 
				# 
				# popen2 seems broken.
				# popen  had some problem, can't recall what
				# system "async" does not give me pid of
				#        browser, but pid of shell
				# system "sync" only returns when child
				#        process has exited
				# 
				# So my solution is : "system" a process that
				# forks. Its child is a browser. The parent
				# prints the child's pid (given by fork())
				# and exits. Octave reads the output of the
				# system call, which is the browser's pid.
				# Phew!  
  [out, status] = system ([vrml_b_name," ",b_opt," ",b_temp], 1);
  if status,
    
    ## keyboard
    ## if ([vrml_b_pid] = system([vrml_b_name," ",b_opt," ",b_temp," ",b_log],0,"async")) <= 0
    ##  [foo,bar,vrml_b_pid] = popen2(vrml_b_name,[b_opt," ",b_temp]) ;
    ##  if vrml_b_pid <= 0,
    printf("vrml_browse : Can't spawn browser ...\n");
    p = vrml_b_pid ;
    return ;
  else
    ##    pclose (foo);
    ##    pclose (bar);
    vrml_b_pid = str2num (out);
    sayif (verbose, "vrml_browse : OK\n");
  end
end				# End of starting new browser ########
				# ####################################

if ! new_browser,
				# ####################################
				# Send USR1 signal to browser ########
  [dum,status]=system (sprintf ("kill -USR1 %d &> /dev/null",vrml_b_pid));

  if status,  
    printf ("vrml_browse : browser pid=%d can't be signaled\n",vrml_b_pid);
  else 
    sayif (verbose, ["vrml_browse : USR1 sent to browser pid=%d\n"], vrml_b_pid);
  end
end				# End of signaling  browser ##########
				# ####################################

p = vrml_b_pid ;

Produced by oct2html on Sat Dec 2 19:08:39 2000
Cross-Directory links are: ON