Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
overlay.tcl
00001 # $Id$ #
00002 
00003 #
00004 # /** Some functions to draw on images' overlay. \file overlay.tcl \ingroup display */
00005 #
00006 
00007 namespace eval display {
00008 
00009     proc drawLine {img u1 v1 u2 v2
00010        {width 1}
00011        {color red}        
00012        {tag "jafar"} } {
00013   # draws a line from (u1,v1) to (u2,v2)
00014   # return the tk id of the line
00015 
00016   variable imageScale
00017 
00018   if {$imageScale($img) == 1.0} {
00019       return [.$img.$img create line $u1 $v1 $u2 $v2 \
00020       -fill $color -width $width -tags $tag]
00021   } else {
00022       set s $imageScale($img)
00023       return [.$img.$img create line [expr $s * $u1] [expr $s * $v1] [expr $s * $u2] [expr $s * $v2] \
00024       -fill $color -width $width -tags $tag]
00025   }
00026     }
00027 
00028     proc drawCross {img u v
00029         {size 3}
00030         {width 1}
00031         {color red}       
00032         {tag "jafar"} } {
00033   # draws a cross om img at (u,v)
00034   # return a list containing the two tk ids of the two lines
00035 
00036   variable imageScale
00037 
00038   # cross are not symmetric without the "+1"
00039   set u1 [expr $u-$size+1] 
00040   set u2 [expr $u+$size]
00041   set v1 [expr $v-$size+1]
00042   set v2 [expr $v+$size]
00043   if {$imageScale($img) == 1.0} {
00044       set id1 [.$img.$img create line $u $v1 $u $v2 \
00045        -fill $color -width $width -tags $tag]
00046       set id2 [.$img.$img create line $u1 $v $u2 $v \
00047        -fill $color -width $width -tags $tag]
00048   } else {
00049       set s $imageScale($img)
00050       set id1 [.$img.$img create line [expr $s * $u] [expr $s * $v1] [expr $s * $u] [expr $s * $v2] \
00051        -fill $color -width $width -tags $tag]
00052       set id2 [.$img.$img create line [expr $s * $u1] [expr $s * $v] [expr $s * $u2] [expr $s * $v] \
00053        -fill $color -width $width -tags $tag]
00054   }
00055   return "$id1 $id2"
00056     }
00057 
00058     proc drawInfiniteLine {img rho theta
00059          {width 1}
00060          {color red}
00061          {tag "jafar"} } {
00062   # draws a infiny line (ie across the image) with parameter (rho, theta)
00063   # return the tk id of the line
00064 
00065   variable imageScale
00066 
00067   # closest point to the origin
00068   set u0 [expr $rho * cos($theta)]
00069   set v0 [expr $rho * sin($theta)]
00070   # direction of the line
00071   set du [expr -sin($theta)]
00072   set dv [expr cos($theta)]
00073 
00074   # distance for infiny line
00075   set inf [expr [$img width] + [$img height]]
00076   # extremities
00077   set u1 [expr $u0+$inf*$du]
00078   set v1 [expr $v0+$inf*$dv]
00079   set u2 [expr $u0-$inf*$du]
00080   set v2 [expr $v0-$inf*$dv]
00081 
00082   if {$imageScale($img) == 1} {
00083       return [display::drawLine $img $u1 $v1 $u2 $v2 $width $color $tag]
00084   } else {
00085       set s $imageScale($img)
00086       return [display::drawLine $img [expr $s * $u1] [expr $s * $v1] [expr $s * $u2] [expr $s * $v2] $width $color $tag]
00087   }
00088     }
00089 
00090     proc drawSquare {img u v
00091          {size 3}
00092          {width 1}
00093          {color red}
00094          {tag "jafar"} } {
00095   # draws a square on img around pixel (u,v)
00096   # return the tk id of the rectangle
00097 
00098   variable imageScale
00099 
00100   set u1 [expr $u-$size]
00101   set u2 [expr $u+$size]
00102   set v1 [expr $v-$size]
00103   set v2 [expr $v+$size]
00104   if {$imageScale($img) == 1} {
00105       return [.$img.$img create rectangle $u1 $v1 $u2 $v2 \
00106       -width $width -outline $color -tags $tag]
00107   } else {
00108       set s $imageScale($img)
00109       return [.$img.$img create rectangle [expr $s * $u1] [expr $s * $v1] [expr $s * $u2] [expr $s * $v2] \
00110       -width $width -outline $color -tags $tag]
00111   }
00112     }
00113 
00114     proc drawRectangle {img u1 v1 u2 v2
00115       {width 1}
00116       {color red}
00117       {tag "jafar"} } {
00118   # draws a rectangle from (u0,v0) to (u1,v1)
00119   # return the tk id of the rectangle
00120 
00121   variable imageScale
00122 
00123   if {$imageScale($img) == 1} {
00124       return [.$img.$img create rectangle $u1 $v1 $u2 $v2 \
00125       -width $width -outline $color -tags $tag]
00126   } else {
00127       set s $imageScale($img)
00128       return [.$img.$img create rectangle [expr $s * $u1] [expr $s * $v1] [expr $s * $u2] [expr $s * $v2] \
00129       -width $width -outline $color -tags $tag]
00130   }
00131     }
00132 
00133     proc drawOrientedRectangle {img u v w h angle 
00134         {width 1}
00135         {color red}
00136         {tag "jafar"}} {
00137   # draws an oriented rectangle centered on (u,v) using a polygon
00138   # angle is the angle between the horizontal axis and the length (in rad)
00139   # return the tk id of the polygoon
00140 
00141   variable imageScale
00142 
00143   set cf1 [expr cos($angle) * 0.5]
00144   set cf2 [expr sin($angle) * 0.5]
00145   
00146   set x1 [expr $u - $cf1 * $h - $cf2 * $w]
00147   set y1 [expr $v + $cf2 * $h - $cf1 * $w]
00148   set x2 [expr $u + $cf1 * $h - $cf2 * $w]
00149   set y2 [expr $v - $cf2 * $h - $cf1 * $w]
00150   set x3 [expr 2 * $u - $x1]
00151   set y3 [expr 2 * $v - $y1]
00152   set x4 [expr 2 * $u - $x2]
00153   set y4 [expr 2 * $v - $y2]
00154 
00155   if {$imageScale($img) == 1} {
00156       return [.$img.$img create polygon $x1 $y1 $x2 $y2 $x3 $y3 $x4 $y4 \
00157       -width $width -outline $color -tags $tag -fill ""]
00158   } else {
00159       set s $imageScale($img)
00160       return [.$img.$img create polygon [expr $s * $x1] [expr $s * $y1] [expr $s * $x2] [expr $s * $y2] \
00161       [expr $s * $x3] [expr $s * $y3] [expr $s * $x4] [expr $s * $y4] \
00162       -width $width -outline $color -tags $tag -fill ""]
00163   }
00164     }
00165 
00166     proc drawEllipse {img u v uCov vCov uvCov
00167           {nSigma 3}
00168           {nbPoints 20}
00169           {width 1}
00170           {color red}
00171           {tag "jafar"} } {
00172   # draws the nSigma ellipse at mean x with covariance xCov
00173   # ellipse shape is approximated with a nbPoints polygon
00174   # return the tk id of the polygon 
00175 
00176   variable imageScale
00177 
00178   set points [display::ellipseToPolygone $u $v $uCov $vCov $uvCov $nSigma $nbPoints $imageScale($img)]
00179   
00180   return [.$img.$img create polygon $points \
00181         -width $width -outline $color -tags $tag -fill ""]
00182     }
00183 
00184   proc drawCircle {img u v
00185          {radius 3}
00186          {width 1}
00187          {color red}
00188          {tag "jafar"} } {
00189   # draws a circle on img around pixel (u,v)
00190   # return the tk id of the rectangle
00191 
00192   variable imageScale
00193 
00194   set u1 [expr $u-$radius]
00195   set u2 [expr $u+$radius]
00196   set v1 [expr $v-$radius]
00197   set v2 [expr $v+$radius]
00198   if {$imageScale($img) == 1} {
00199       return [.$img.$img create oval $u1 $v1 $u2 $v2 \
00200       -width $width -outline $color -tags $tag]
00201   } else {
00202       set s $imageScale($img)
00203       return [.$img.$img create oval [expr $s * $u1] [expr $s * $v1] [expr $s * $u2] [expr $s * $v2] \
00204       -width $width -outline $color -tags $tag]
00205   }
00206     } 
00207 
00208     proc drawText {img u v text
00209        {color red}
00210        {anchor "c"}
00211        {tag "jafar"} } {
00212   # add text on img at (u,v)
00213   # return the tk id of the text
00214 
00215   variable imageScale
00216   if {$imageScale($img) == 1} {
00217       return [.$img.$img create text $u $v -text $text \
00218       -anchor $anchor -fill $color -tags $tag]
00219   } else {
00220       set s $imageScale($img)
00221       return [.$img.$img create text [expr $s * $u] [expr $s * $v] -text $text \
00222       -anchor $anchor -fill $color -tags $tag]
00223   }
00224     }
00225 
00226     proc clearOverlay {img
00227            {tag "jafar"} } {
00228   # delete object draws on img with tag
00229   .$img.$img delete -tag $tag
00230     }
00231 
00232 }
00233 
00234 package provide display 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:18 for Jafar by doxygen 1.7.6.1
LAAS-CNRS