SCIRun User Mailing List

Text archives Help


[SCIRUN-USERS] A number of bugs in SCIRun/BioTensor fixed


Chronological Thread 
  • From: Thomas Schultz <schultz@mpi-sb.mpg.de>
  • To: scirun-users@sci.utah.edu
  • Subject: [SCIRUN-USERS] A number of bugs in SCIRun/BioTensor fixed
  • Date: Thu, 6 Oct 2005 15:47:42 +0200 (CEST)

Hi!

I am using the BioTensor PowerApp for my master thesis (on DT-MRI imaging) at Saarland University / Max-Planck-Institut Informatik. I found it very useful so far; however, I came across a couple of bugs during my work and I would like to send you a patch that fixes them (hope it's okay to send it to the list, it's not very large).

Short description for SCIRun-bugs.diff:

 1. Parts of the network would occasionally block (wait for input)
    forever. I typically got this after turning off one of the planes and
    turning it on again. I found this problem is due to a race condition
    in the thread implementation: If a module sets its "need_execute" flag
    while the scheduler runs, this can happen after the dependency checks,
    but before the actual execution. In this case, a module gets executed
    without its dependencies being fulfilled. I fixed this by introducing
    a mutex within the scheduler which a module needs to hold while
    changing its "need_execute" flag.

 2. The ClipByFunction module does a test to determine if it really needs
    to re-execute. This test should depend not only on a change in the
    input field and clipping function, but also on the user-defined
    variables u0-u5.

Short description for BioTensor.diff:

 1. A typo in the configuration of m137 caused an error when reading in
    tensor fields.

 2. When clipping by planes, I think turning off planes altogether should
    have the same effect as turning off each individual plane. (I exploit
    the new behaviour when getting a glyph representation of the whole
    volume without having to turn off each plane separately.)

 3. If the isovalue changes, the clipping function (for glyphs and
    fibers) needs to be re-evaluated because it depends on it.

 4. In case the isovalue changes, the isosurface is not shown, but the
    planes are clipped to it, the isosurface still needs to be
    re-calculated to get the clipping right.

Thank you for a useful application. I hope my patch can contribute to its further improvement.

Kind regards
    Thomas Schultz--- /var/tmp/schultz/SCIRun/src/Packages/Teem/nets/PowerApps/BioTensor.app    
  2005-06-03 17:59:39.000000000 +0200
+++ ./BioTensor.app     2005-10-05 17:12:08.995362000 +0200
@@ -1615,7 +1612,7 @@
 set $m135-port-index {1}
 set $m136-port-index {0}
 
-set $m137-kind {nrrdKind3DMaskedSymTensor}
+set $m137-kind {nrrdKind3DMaskedSymMatrix}
 
 set $m138-filename {/tmp/tensors.nrrd}
 
@@ -4308,6 +4305,8 @@
                    sync_isosurface_tabs
                    sync_glyphs_tabs
                    sync_fibers_tabs
+
+                   initialize_clip_info
                    
                    configure_sample_planes
                    
@@ -5471,6 +5470,7 @@
        #   -u3  $span_z
 
        # Only include axis information for planes that are turned on
+       global show_planes
        global show_plane_x
        global show_plane_y
        global show_plane_z
@@ -5483,20 +5483,22 @@
        set $mods(ClipByFunction-Seeds)-u0 [set $mods(Isosurface)-isoval]
        set function "(v > u0) &&"
 
-       if {$show_plane_x} {
-           set $mods(ClipByFunction-Seeds)-u1 $span_x
-           set index [string last "&&" $function]
-           set function [string replace $function $index end "&& (x $clip_x 
u1) &&"]
-       }
-       if {$show_plane_y} {
-           set $mods(ClipByFunction-Seeds)-u2 $span_y
-           set index [string last "&&" $function]
-           set function [string replace $function $index end "&& (y $clip_y 
u2) &&"]
-       }
-       if {$show_plane_z} {
-           set $mods(ClipByFunction-Seeds)-u3 $span_z
-           set index [string last "&&" $function]
-           set function [string replace $function $index end "&& (z $clip_z 
u3) &&"]
+       if {$show_planes} {
+           if {$show_plane_x} {
+               set $mods(ClipByFunction-Seeds)-u1 $span_x
+               set index [string last "&&" $function]
+               set function [string replace $function $index end "&& (x 
$clip_x u1) &&"]
+           }
+           if {$show_plane_y} {
+               set $mods(ClipByFunction-Seeds)-u2 $span_y
+               set index [string last "&&" $function]
+               set function [string replace $function $index end "&& (y 
$clip_y u2) &&"]
+           }
+           if {$show_plane_z} {
+               set $mods(ClipByFunction-Seeds)-u3 $span_z
+               set index [string last "&&" $function]
+               set function [string replace $function $index end "&& (z 
$clip_z u3) &&"]
+           }
        }
        set index [string last "&&" $function]
        set function [string replace $function $index end ""]
@@ -6544,7 +6546,7 @@
            set result [expr [expr $plane_x / [expr $size_x / 2.0] ] - 1.0]
            set $mods(SamplePlane-X)-pos $result
            
-           # set the glabal clipping planes values
+           # set the global clipping planes values
            set clip $mods(Viewer)-ViewWindow_0-clip
            global $clip-normal-d-1
            global $clip-normal-d-2
@@ -6565,9 +6567,9 @@
            global $mods(ChooseField-GlyphSeeds)-port-index
            global $mods(ShowField-Fibers)-edges-on
            global $mods(ChooseField-FiberSeeds)-port-index
-           # if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) || ([set 
$mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
+           if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) || ([set 
$mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
                $mods(ClipByFunction-Seeds)-c needexecute
-           # }            
+           }              
            
            $mods(SamplePlane-X)-c needexecute
            $mods(Viewer)-ViewWindow_0-c redraw
@@ -6586,7 +6588,7 @@
            set result [expr [expr $plane_y / [expr $size_y / 2.0] ] - 1.0]
            set $mods(SamplePlane-Y)-pos $result
            
-           # set the glabal clipping planes values
+           # set the global clipping planes values
            set clip $mods(Viewer)-ViewWindow_0-clip
            global $clip-normal-d-3
            global $clip-normal-d-4
@@ -6606,9 +6608,10 @@
            global $mods(ChooseField-GlyphSeeds)-port-index
            global $mods(ShowField-Fibers)-edges-on
            global $mods(ChooseField-FiberSeeds)-port-index
-           # if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) || ([set 
$mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
+
+           if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) || ([set 
$mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
                $mods(ClipByFunction-Seeds)-c needexecute
-           # }     
+           }       
            
            $mods(SamplePlane-Y)-c needexecute
            $mods(Viewer)-ViewWindow_0-c redraw
@@ -6627,7 +6630,7 @@
            set result [expr [expr $plane_z / [expr $size_z / 2.0] ] - 1.0]
            set $mods(SamplePlane-Z)-pos $result
            
-           # set the glabal clipping planes values
+           # set the global clipping planes values
            set clip $mods(Viewer)-ViewWindow_0-clip
            global $clip-normal-d-5
            global $clip-normal-d-6
@@ -6647,9 +6650,9 @@
            global $mods(ChooseField-GlyphSeeds)-port-index
            global $mods(ShowField-Fibers)-edges-on
            global $mods(ChooseField-FiberSeeds)-port-index
-           # if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) || ([set 
$mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
+           if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) || ([set 
$mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
                $mods(ClipByFunction-Seeds)-c needexecute
-           # }
+           }
            $mods(SamplePlane-Z)-c needexecute
            $mods(Viewer)-ViewWindow_0-c redraw
        } else {
@@ -6661,6 +6664,8 @@
     method toggle_plane { which } {
        global mods
        global show_plane_x show_plane_y show_plane_z
+       global $mods(ShowField-Glyphs)-tensors-on
+       global $mods(ShowField-Fibers)-edges-on
        global $mods(ShowField-X)-faces-on
        global $mods(ShowField-Y)-faces-on
        global $mods(ShowField-Z)-faces-on
@@ -6690,9 +6695,9 @@
 
            configure_ClipByFunction
 
-           # only take the time to rexecute of glyphs or fibers are
+           # only take the time to rexecute of glyphs or fibers are on and
            # being seeded in the grid
-           if {[set $mods(ChooseField-GlyphSeeds)-port-index] == 3 || [set 
$mods(ChooseField-FiberSeeds)-port-index] == 3} {
+           if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) || ([set 
$mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
                $mods(ClipByFunction-Seeds)-c needexecute
            }
 
@@ -6722,9 +6727,7 @@
            }   
            configure_ClipByFunction
 
-           # only take the time to rexecute of glyphs or fibers are
-           # being seeded in the grid
-           if {[set $mods(ChooseField-GlyphSeeds)-port-index] == 3 || [set 
$mods(ChooseField-FiberSeeds)-port-index] == 3} {
+           if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) || ([set 
$mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
                $mods(ClipByFunction-Seeds)-c needexecute
            }
 
@@ -6755,8 +6758,6 @@
            }   
            configure_ClipByFunction
 
-           # only take the time to rexecute of glyphs or fibers are
-           # being seeded in the grid
            if {[set $mods(ChooseField-GlyphSeeds)-port-index] == 3 || [set 
$mods(ChooseField-FiberSeeds)-port-index] == 3} {
                $mods(ClipByFunction-Seeds)-c needexecute
            }
@@ -6856,6 +6857,17 @@
                $mods(Viewer)-ViewWindow_0-c redraw
            }
        }
+        configure_ClipByFunction
+       global $mods(ChooseField-GlyphSeeds)-port-index
+       global $mods(ChooseField-FiberSeeds)-port-index
+       global $mods(ShowField-Glyphs)-tensors-on
+       global $mods(ShowField-Fibers)-edges-on
+       # only take the time to rexecute if glyphs or fibers are
+       # being seeded in the grid
+       if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) ||
+           ([set $mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
+           $mods(ClipByFunction-Seeds)-c needexecute
+       }
     }
     
 
@@ -7392,8 +7404,10 @@
     method execute_isoval_change {} {
        global mods
        global $mods(ShowField-Isosurface)-faces-on
+       global clip_to_isosurface
 
-       if {$vis_activated && [set $mods(ShowField-Isosurface)-faces-on]==1} {
+       if {$vis_activated && ([set $mods(ShowField-Isosurface)-faces-on]==1 
||
+                               $clip_to_isosurface==1)} {
            $mods(Isosurface)-c needexecute
            $mods(IsoClip-X)-c needexecute
            $mods(IsoClip-Y)-c needexecute
@@ -7406,6 +7420,18 @@
            set exec_iso(IsoClip-Z) 1
 
        }
+       # Isovalue also has an effect on the clipping function
+       configure_ClipByFunction
+       global $mods(ChooseField-GlyphSeeds)-port-index
+       global $mods(ChooseField-FiberSeeds)-port-index
+       global $mods(ShowField-Glyphs)-tensors-on
+       global $mods(ShowField-Fibers)-edges-on
+       # only take the time to rexecute if glyphs or fibers are
+       # being seeded in the grid
+       if {([set $mods(ShowField-Glyphs)-tensors-on] && [set 
$mods(ChooseField-GlyphSeeds)-port-index] == 3) ||
+           ([set $mods(ChooseField-FiberSeeds)-port-index] == 3 && [set 
$mods(ShowField-Fibers)-edges-on])} {
+           $mods(ClipByFunction-Seeds)-c needexecute
+       }
     }
 
 
diff -ur SCIRun.orig/src/Dataflow/Modules/Fields/ClipByFunction.cc 
SCIRun/src/Dataflow/Modules/Fields/ClipByFunction.cc
--- SCIRun.orig/src/Dataflow/Modules/Fields/ClipByFunction.cc   2005-03-01 
23:55:31.000000000 +0100
+++ SCIRun/src/Dataflow/Modules/Fields/ClipByFunction.cc        2005-10-06 
15:10:46.000000000 +0200
@@ -76,6 +76,7 @@
 
   string mode_;
   string function_;
+  double u0_, u1_, u2_, u3_, u4_, u5_;
 
   FieldHandle  fHandle_;
   MatrixHandle mHandle_;
@@ -136,13 +137,23 @@
 
   string mode = gMode_.get();
   string function = gFunction_.get();
+  double u0 = gui_uservar0_.get();
+  double u1 = gui_uservar1_.get();
+  double u2 = gui_uservar2_.get();
+  double u3 = gui_uservar3_.get();
+  double u4 = gui_uservar4_.get();
+  double u5 = gui_uservar5_.get();
 
   if( mode_     != mode ||
-      function_ != function ) {
+      function_ != function ||
+      u0 != u0_ || u1 != u1_ || u2 != u2_ ||
+      u3 != u3_ || u4 != u4_ || u5 != u5_) {
     update = true;
     
     mode_      = mode;
     function_ = function;
+    u0_ = u0; u1_ = u1; u2_ = u2;
+    u3_ = u3; u4_ = u4; u5_ = u5;
   }
 
   if( !fHandle_.get_rep() ||
@@ -185,12 +196,12 @@
       gMode = -1;
 
     // User Variables.
-    algo->u0 = gui_uservar0_.get();
-    algo->u1 = gui_uservar1_.get();
-    algo->u2 = gui_uservar2_.get();
-    algo->u3 = gui_uservar3_.get();
-    algo->u4 = gui_uservar4_.get();
-    algo->u5 = gui_uservar5_.get();
+    algo->u0 = u0;
+    algo->u1 = u1;
+    algo->u2 = u2;
+    algo->u3 = u3;
+    algo->u4 = u4;
+    algo->u5 = u5;
 
     if (!(fHandle->basis_order() == 0 && gMode == 0 ||
           fHandle->basis_order() == 1 && gMode != 0))
diff -ur SCIRun.orig/src/Dataflow/Network/Module.cc 
SCIRun/src/Dataflow/Network/Module.cc
--- SCIRun.orig/src/Dataflow/Network/Module.cc  2005-02-26 00:03:50.000000000 
+0100
+++ SCIRun/src/Dataflow/Network/Module.cc       2005-10-06 15:10:46.000000000 
+0200
@@ -546,7 +546,9 @@
 
 void Module::want_to_execute()
 {
+    sched->need_execute_mtx.lock();
     need_execute=true;
+    sched->need_execute_mtx.unlock();
     sched->do_scheduling();
 }
 
diff -ur SCIRun.orig/src/Dataflow/Network/NetworkEditor.cc 
SCIRun/src/Dataflow/Network/NetworkEditor.cc
--- SCIRun.orig/src/Dataflow/Network/NetworkEditor.cc   2005-04-05 
21:37:03.000000000 +0200
+++ SCIRun/src/Dataflow/Network/NetworkEditor.cc        2005-10-06 
15:10:46.000000000 +0200
@@ -55,6 +55,7 @@
 #include <Dataflow/Network/Network.h>
 #include <Dataflow/Network/PackageDB.h>
 #include <Dataflow/Network/Port.h>
+#include <Dataflow/Network/Scheduler.h>
 #include <Dataflow/Network/ComponentNode.h>
 #include <Dataflow/Network/GenFiles.h>
 #include <Dataflow/XMLUtil/XMLUtil.h>
@@ -201,16 +202,22 @@
   } else if(args[1] == "scheduleok"){
     net->schedule();
   } else if(args[1] == "scheduleall"){
+    Scheduler *sched = net->get_scheduler();
+    sched->need_execute_mtx.lock();
     for(int i=0;i<net->nmodules();i++){
       Module* m=net->module(i);
       m->need_execute=1;
     }
+    sched->need_execute_mtx.unlock();
     net->schedule();
   } else if(args[1] == "reset_scheduler"){
+    Scheduler *sched = net->get_scheduler();
+    sched->need_execute_mtx.lock();
     for(int i=0;i<net->nmodules();i++){
       Module* m=net->module(i);
       m->need_execute=0;
     }
+    sched->need_execute_mtx.unlock();
   } else if(args[1] == "packageName"){
     if(args.count() != 3){
       args.error("packageName needs a module id");
diff -ur SCIRun.orig/src/Dataflow/Network/Scheduler.cc 
SCIRun/src/Dataflow/Network/Scheduler.cc
--- SCIRun.orig/src/Dataflow/Network/Scheduler.cc       2004-05-20 
18:30:12.000000000 +0200
+++ SCIRun/src/Dataflow/Network/Scheduler.cc    2005-10-06 15:10:46.000000000 
+0200
@@ -53,7 +53,8 @@
 
 Scheduler::Scheduler(Network* net)
   : net(net), first_schedule(true), schedule(true),
-    mailbox("NetworkEditor request FIFO", 100)
+    mailbox("NetworkEditor request FIFO", 100),
+    need_execute_mtx("Module need_execute lock")
 {
   net->attach(this);
 }
@@ -133,14 +134,18 @@
   int nmodules=net->nmodules();
   queue<Module *> needexecute;         
 
+  need_execute_mtx.lock();
   // build queue of module ptrs to execute
   int i;                           
   for(i=0;i<nmodules;i++){
     Module* module=net->module(i);
     if(module->need_execute)
-      needexecute.push(module);
+      {
+       needexecute.push(module);
+      }
   }
   if(needexecute.empty()){
+    need_execute_mtx.unlock();
     return;
   }
 
@@ -213,11 +218,11 @@
   for(i=0;i<nmodules;i++){
     Module* module=net->module(i);
     if(module->need_execute){
-
       module->mailbox.send(scinew Scheduler_Module_Message);
       module->need_execute=0;
     }
   }
+  need_execute_mtx.unlock();
 }
 
 void Scheduler::do_scheduling()
diff -ur SCIRun.orig/src/Dataflow/Network/Scheduler.h 
SCIRun/src/Dataflow/Network/Scheduler.h
--- SCIRun.orig/src/Dataflow/Network/Scheduler.h        2004-05-20 
18:30:12.000000000 +0200
+++ SCIRun/src/Dataflow/Network/Scheduler.h     2005-10-06 15:10:46.000000000 
+0200
@@ -47,6 +47,7 @@
 #include <Dataflow/Comm/MessageBase.h>
 #include <Core/GuiInterface/GuiCallback.h>
 #include <Core/Thread/Mailbox.h>
+#include <Core/Thread/Mutex.h>
 #include <Core/Thread/Runnable.h>
 #include <string>
 
@@ -78,6 +79,10 @@
  
     void do_scheduling();
     void request_multisend(OPort*);
+    // Any module that wants to change its need_execute status must
+    // acquire this lock first!
+    Mutex need_execute_mtx;
+
   private:
     virtual void run();
     void main_loop();



Archive powered by MHonArc 2.6.16.

Top of page