ThreeB 1.1
Public Member Functions | Static Public Member Functions | Package Functions | Static Package Functions | Package Attributes | Static Private Member Functions | Private Attributes
ThreeBRunner Class Reference

This class deals with running the actual 3B code It should be run in a separate thread It will make calls back to a viewer, and accepts termination calls as well. More...

List of all members.

Public Member Functions

void register (EControlPanel c)
void run ()

Static Public Member Functions

static void addLibraryPath (String pathToAdd) throws Exception

Package Functions

 ThreeBRunner (ByteProcessor mask_, ImageStack s, String cfg_, String filename_, int firstfr, int lastfr)
void stop_thread ()
boolean has_stopped ()
void send_message_string (String s)
void send_new_points (float[] points)
void die (String err)
boolean should_stop ()
native void call (String cfg, float[][] images, byte[] mask, int n_images, int rows, int cols, String file)

Static Package Functions

static String get_plugin_dir ()
static UnsatisfiedLinkError try_to_load_dlls (String[] s)
 [static initializer]

Package Attributes

ByteProcessor mask
float[][] pixels
EControlPanel cp
String config
String filename
long start_time
int its

Static Private Member Functions

static String decodePercent (String str)

Private Attributes

volatile boolean stop = false
volatile boolean stopped = false
boolean fatal = false

Detailed Description

This class deals with running the actual 3B code It should be run in a separate thread It will make calls back to a viewer, and accepts termination calls as well.

Definition at line 1283 of file three_B.java.


Constructor & Destructor Documentation

ThreeBRunner::ThreeBRunner ( ByteProcessor  mask_,
ImageStack  s,
String  cfg_,
String  filename_,
int  firstfr,
int  lastfr 
) [inline, package]

Definition at line 1296 of file three_B.java.

References config, filename, mask, and pixels.

    {
        config = cfg_;
        filename = filename_;
        
        //Take a copy of the mask to stop it getting trashed by other threads
        mask = (ByteProcessor)mask_.duplicate();
        
        //Convert all the input images into float as a common
        //format. They will be scaled differently from float images 
        //loaded by libcvd, but the later normalization will take care of that
        //
        //Oh, and ImageStack counts from 1, not 0
        pixels = new float[lastfr - firstfr + 1][];
        for(int i=firstfr; i <= lastfr; i++)
            pixels[i-firstfr] = (float[])s.getProcessor(i+1).convertToFloat().getPixels();
    }

Member Function Documentation

void ThreeBRunner::register ( EControlPanel  c) [inline]

Definition at line 1314 of file three_B.java.

References cp.

Referenced by EControlPanel::EControlPanel().

    {
        cp = c;
    }
void ThreeBRunner::stop_thread ( ) [inline, package]

Definition at line 1319 of file three_B.java.

References send_message_string(), and stop.

Referenced by EControlPanel::issue_stop(), and EControlPanel::windowClosing().

    {
        stop=true;
        send_message_string("stopping...");
    }
boolean ThreeBRunner::has_stopped ( ) [inline, package]

Definition at line 1325 of file three_B.java.

References stopped.

Referenced by EControlPanel::windowClosing().

    {
        return stopped;
    }
void ThreeBRunner::send_message_string ( String  s) [inline, package]

Definition at line 1332 of file three_B.java.

References cp, and EControlPanel::send_status_text_message().

Referenced by stop_thread().

void ThreeBRunner::send_new_points ( float[]  points) [inline, package]

Definition at line 1337 of file three_B.java.

References EControlPanel::append(), cp, ThreeBGlobalConstants::critical_iterations, its, EControlPanel::send_time_text_message(), EControlPanel::send_update_canvas_event(), start_time, Spot::x, and Spot::y.

    {
        //New points are sent in the form x, y, x, y
        ArrayList<Spot> tmp = new ArrayList<Spot>();
        for(int i=0; i < points.length; i+=2)
        {
            Spot s = new Spot();
            s.x = points[i];
            s.y = points[i+1];
            tmp.add(s);
        }

        cp.append(tmp, its);
        cp.send_update_canvas_event();
            
        //This happens each "iteration", i.e. each pass.
        long current = (new java.util.Date()).getTime();

        if(its > 0)
        {
            if(its < 8)
                cp.send_time_text_message("computing...");
            else
            {
                long time_per_it = (current -start_time) / its;
                int target = (int)Math.ceil(its * 1.0 / ThreeBGlobalConstants.critical_iterations) * ThreeBGlobalConstants.critical_iterations;
                int its_remaining = target-its;

                System.out.println("Its = " + its);
                System.out.println("rem = " + its_remaining);
                System.out.println("time_per_it = " + time_per_it);

                
                long time_remaining_s = (its_remaining * time_per_it)/1000;
                
                long s = time_remaining_s % 60;
                long m = (time_remaining_s / 60)%60;
                long h = time_remaining_s / 3600;

                cp.send_time_text_message( h + "h" + m + "m (for " + target + " iterations)");
            }
            
        }
        
        //Increment after, since it outputs the initial spots as well
        its++;
    }
void ThreeBRunner::die ( String  err) [inline, package]

Definition at line 1385 of file three_B.java.

References cp, EControlPanel::die(), and fatal.

    {
        cp.die(err);
        fatal=true;
    }
boolean ThreeBRunner::should_stop ( ) [inline, package]

Definition at line 1391 of file three_B.java.

References stop.

    {
        return stop;
    }
native void ThreeBRunner::call ( String  cfg,
float  images[][],
byte[]  mask,
int  n_images,
int  rows,
int  cols,
String  file 
) [package]

Referenced by run().

void ThreeBRunner::run ( ) [inline]

Definition at line 1398 of file three_B.java.

References call(), config, cp, fatal, filename, its, mask, pixels, EControlPanel::send_status_text_message(), start_time, and stopped.

    {
        System.out.println("About to call...");
        start_time = (new java.util.Date()).getTime();
        its=0;

        call(config, pixels, (byte[])mask.getPixels(), pixels.length, mask.getHeight(), mask.getWidth(), filename);

        System.out.println("Finished.");
        
        if(!fatal)
        {
            cp.send_status_text_message("Finished\n");
            ij.IJ.showStatus("3B run terminated");
        }

        stopped=true;
    }
static String ThreeBRunner::decodePercent ( String  str) [inline, static, private]

Definition at line 1420 of file three_B.java.

    {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < str.length(); i++) 
        {
            char c = str.charAt(i);
            if(c == '+')
                sb.append(' ');
            else if(c == '%')
            {
                sb.append((char) Integer.parseInt(str.substring(i + 1, i + 3), 16));
                i += 2;
            }
            else
                sb.append(c);
        }
        return sb.toString();
    }
static void ThreeBRunner::addLibraryPath ( String  pathToAdd) throws Exception [inline, static]

Adds the specified path to the java library path.

Parameters:
pathToAddthe path to add
Exceptions:
Exception

Definition at line 1445 of file three_B.java.

                                                                        {
        final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
        usrPathsField.setAccessible(true);
     
        //get array of paths
        final String[] paths = (String[])usrPathsField.get(null);
     
        //check if the path to add is already present
        for(String path : paths) {
            if(path.equals(pathToAdd)) {
                return;
            }
        }
     
        //add the new path
        final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
        newPaths[newPaths.length-1] = pathToAdd;
        usrPathsField.set(null, newPaths);
    }
static String ThreeBRunner::get_plugin_dir ( ) [inline, static, package]

Definition at line 1489 of file three_B.java.

Referenced by try_to_load_dlls().

    {
        try{
            String img_url = (new SPair()).getClass().getResource("img").getFile();
            URI jar_url = null;
            
            jar_url= new URI(img_url.substring(0, img_url.length()-5));

            File jar = new File(jar_url);

            System.out.println("File: " + jar.getCanonicalPath());


            String dir = jar.getParentFile().getCanonicalPath() + File.separator;
            System.out.println("Dir: " + dir);

            return dir;
            
        }
        catch(Exception e){
            return "";
        }
    }
static UnsatisfiedLinkError ThreeBRunner::try_to_load_dlls ( String[]  s) [inline, static, package]

Definition at line 1514 of file three_B.java.

References get_plugin_dir().

    {
        String dir = get_plugin_dir();
        
        try{
            for(int i=0; i < s.length; i++)
            {
                System.out.println("Loading " + dir+s[i]);
                System.load(dir + s[i]);
            }
            
            return null;
        }
        catch(UnsatisfiedLinkError e)
        {
            System.out.println("Link error: " + e.getMessage());
            return e;
        }

    }
ThreeBRunner::[static initializer] ( ) [inline, static, package]

Member Data Documentation

ByteProcessor ThreeBRunner::mask [package]

Definition at line 1285 of file three_B.java.

Referenced by run(), and ThreeBRunner().

float [][] ThreeBRunner::pixels [package]

Definition at line 1286 of file three_B.java.

Referenced by run(), and ThreeBRunner().

volatile boolean ThreeBRunner::stop = false [private]

Definition at line 1287 of file three_B.java.

Referenced by should_stop(), and stop_thread().

volatile boolean ThreeBRunner::stopped = false [private]

Definition at line 1288 of file three_B.java.

Referenced by has_stopped(), and run().

boolean ThreeBRunner::fatal = false [private]

Definition at line 1289 of file three_B.java.

Referenced by die(), and run().

Definition at line 1290 of file three_B.java.

Referenced by die(), register(), run(), send_message_string(), and send_new_points().

String ThreeBRunner::config [package]

Definition at line 1291 of file three_B.java.

Referenced by run(), and ThreeBRunner().

String ThreeBRunner::filename [package]

Definition at line 1292 of file three_B.java.

Referenced by run(), and ThreeBRunner().

long ThreeBRunner::start_time [package]

Definition at line 1293 of file three_B.java.

Referenced by run(), and send_new_points().

int ThreeBRunner::its [package]

Definition at line 1294 of file three_B.java.

Referenced by run(), and send_new_points().


The documentation for this class was generated from the following file: