generated by zdoc.tcl on Thu Feb 14 16:15:16 MET 2002

tclSM2.tcl



SM2
Comments  
Arguments  
Used by  
Uses  
   variable t2state "connect to..."
   variable t2first none

}


SM2::addSM2View
Comments  
Arguments name
mname
toff
color
Used by  
Uses SM2::isSM2InView
proc SM2::addSM2View { name mname {toff 0} {color "#E8E0D2"}} {
    set scn [ lindex [ split [ $mname -views] ] 0 ]
    $name add cascade -label "2-Simplex Mesh" -menu $name.mesh
    menu $name.mesh -tearoff $toff -bg $color -postcommand  "set SM2::scn \[ \[ lindex \[ split \[ ${mname} -views\] \] 0 \] -scene \]; $name.mesh delete 0 last; foreach {i} \[which sm\] { set SM2::view(\$i) \[ SM2::isSM2InView \${SM2::scn} \$i \];  }; foreach {i} \[which sm\] {$name.mesh add checkbutton -selectcolor black -variable SM2::view(\$i) -label \$i -command \" if  \$SM2::view(\$i) \{evaluate {\[SM2::getSM2InView  \${SM2::scn} \$i\] -destroy } \} else  \{evaluate {new smview \$i -scene \${SM2::scn} } \}  \"}"
}


SM2::balloonForce
Comments  
Arguments object
color
Used by  
Uses  
proc SM2::balloonForce { object color } {
    variable ebal

    if ![winfo exists .balloon] {
    toplevel .balloon -bg $color
    wm title .balloon "balloon force"

    checkbutton .balloon.b -text enable -selectcolor black -bg $color -variable SM2::ebal -onvalue true -offvalue false
    scale .balloon.s -label "balloon coefficient" -orient horizontal -bg $color -from -0.3 -to 0.3 -resolution 0.001
    bind .balloon.s <Enter> {focus .balloon.s}
    scan [$object -balloon] "%s %f" ebal f
    .balloon.s set $f

    frame .balloon.f -bg $color
    button .balloon.f.a -text apply -bg $color -command "if !\[string compare \$SM2::ebal true\] { evaluate \"$object -balloon true \[.balloon.s get\]\" } else { evaluate \"$object -balloon false\" }"
    button .balloon.f.ad -text "apply & dismiss" -bg $color -command "if !\[string compare \$SM2::ebal true\] { evaluate \"$object -balloon true \[.balloon.s get\]\" } else { evaluate \"$object -balloon false\" }; destroy .balloon"
    button .balloon.f.d -text dismiss -bg $color -command {destroy .balloon}
    pack .balloon.f.a .balloon.f.ad .balloon.f.d -side left -fill x -padx 10 -pady 5

    pack .balloon.b .balloon.s .balloon.f -fill both -expand true
    }
}


SM2::createProfile
Comments  
Arguments object
color
Used by  
Uses  
proc SM2::createProfile { object color } {
    if ![winfo exists .cprofile${object}] {
    set name .cprofile${object}
    toplevel $name -bg $color
    wm title $name "create/delete intensity profile"

    variable l
    variable inr none
    variable mn

    frame $name.f -bg $color
    label $name.f.nm -bg $color -text "profile name" -anchor e
    entry $name.f.e -bg white -width 20
    label $name.f.img -bg $color -text "source image" -anchor e
    set mn [tk_optionMenu $name.f.inr SM2::inr none]
    $name.f.inr configure -bg $color
    $mn configure -bg $color
    $mn entryconfigure 0 -selectcolor black -variable SM2::inr
    foreach inr [which inr] {
        $mn add radiobutton -selectcolor black -variable SM2::inr -label $inr
    }
    grid $name.f.nm -row 1 -column 1 -sticky ew
    grid $name.f.e -row 1 -column 2 -sticky ew
    grid $name.f.img -row 2 -column 1 -sticky ew
    grid $name.f.inr -row 2 -column 2 -sticky ew
    scale $name.s -bg $color -from 0.1 -to 20.0 -orient horizontal -resolution 0.1 -label "profile half length"
    $name.s set 3.0

    listbox $name.l -height 10 -bg white
    foreach l [$object -profile list] {
        $name.l insert end $l
    }
    $name.l insert end ""
    bind $name.l <ButtonRelease-1> "$name.f.e delete 0 end; $name.f.e insert 0 \[$name.l get \[$name.l curselection\]\]"
    
    frame $name.fb -bg $color
    button $name.fb.create -bg $color -text Create -command "if {  \[string compare \$SM2::inr none\] && \[string compare \[$name.f.e get\] \"\"\]} { evaluate \"$object -profile create \[$name.f.e get\] \$SM2::inr \[$name.s get\]\"; $name.l insert \[ expr \[$name.l size\] - 1\] \[$name.f.e get\]; $name.f.e delete 0 end}"
    button $name.fb.delete -bg $color -text Delete -command "if \[string compare \[$name.f.e get\] {} \] { set index \[SM2::listfind $name.l \[$name.f.e get\]\]; if {\$index >= 0} {evaluate \"$object -profile delete \[$name.f.e get\]\"; $name.f.e delete 0 end; $name.l delete \$index} }"
    button $name.fb.dismiss -bg $color -text Dismiss -command "destroy $name"
    pack $name.fb.create $name.fb.delete $name.fb.dismiss -side left -expand true

    pack $name.f $name.s $name.l $name.fb -expand true -fill both -padx 5 -pady 5
    
    }
}


SM2::display
Comments  
Arguments object
color
Used by  
Uses  
proc SM2::display { object color } {
    if ![winfo exists .display${object}] {
    set name .display${object}
    toplevel $name -bg $color
    wm title $name "display components for $object"

    variable forces { internal external global averaged gc total }
    variable colors { \#FF0000 \#FF00FF \#FF0080 \#0000FF \#00FF00 \#FFFFFF }
    variable nd${object}
    variable nc${object}
    variable nw${object}
    variable ns${object}
    variable nr${object}
    
    variable i
    variable j
    variable str

    variable fd${object} true
    set j 0
    foreach i $forces {
        variable fd${object}${i} false
        variable fc${object}${i} [lindex ${colors} $j]
        incr j
    }
    variable fw${object}
    variable fs${object}
    
    scan [$object -normal] "%s %s %s %s %s %s %s %s %s %s" ign SM2::nd${object} ign SM2::nc${object} ign SM2::nw${object} ign SM2::ns${object} ign SM2::nr${object}
    set str [$object -force]
    for {set i 0} { $i < [llength $str]} {incr i} {
        switch [lindex $str $i] {
        false {
            set fd${object} false
            foreach j $forces { set fd${object}${j} false }
        }
        width {
            incr i
            set fw${object} [lindex $str $i]
        }
        scale {
            incr i
            set fs${object} [lindex $str $i]
        }
        default {
            foreach j $forces {
            if ![string compare $j [lindex $str $i]] {
                set fd${object}${j} ${j}
                incr i
                set fc${object}${j} [lindex $str $i]
            }
            }
        }
        }
    }

    # normals
    checkbutton $name.n -text "display normals" -bg $color -selectcolor black -anchor w -onvalue true -offvalue false -variable SM2::nd${object}
    frame $name.nf -bg $color
    checkbutton $name.nf.rev -text reverse -bg $color -selectcolor black -onvalue true -offvalue false -anchor w -variable SM2::nr${object}
    button $name.nf.c -bg $color -text "Color..." -command "set SM2::nc${object} \[tk_chooseColor -initialcolor \$SM2::nc${object}\]"
    scale $name.nf.w -bg $color -orient horizontal -from 1 -to 5 -label width
    $name.nf.w set [set SM2::nw$object]
    scale $name.nf.s -bg $color -orient horizontal -from 1 -to 20 -label scale
    $name.nf.s set [set SM2::ns$object]
    grid $name.nf.rev -row 1 -column 1 -sticky ew -padx 5
    grid $name.nf.c -row 1 -column 2 -sticky ew -padx 5
    grid $name.nf.w -row 2 -column 1 -sticky ew -padx 5
    grid $name.nf.s -row 2 -column 2 -sticky ew -padx 5

    # forces
    checkbutton $name.f -text "display forces" -bg $color -selectcolor black -anchor w -onvalue true -offvalue false -variable SM2::fd${object}
    frame $name.ff -bg $color
    set j 0
    foreach i $forces {
        checkbutton $name.ff.$i -anchor w -text $i -bg $color -selectcolor black -onvalue $i -offvalue false -variable SM2::fd${object}${i}
        button $name.ff.c${i} -bg $color -text "Color..." -command "set SM2::fc${object}${i} \[tk_chooseColor -initialcolor \$SM2::fc${object}${i}\]"
        grid $name.ff.$i -row $j -column 1 -sticky ew -padx 5
        grid $name.ff.c$i -row $j -column 2 -sticky ew -padx 5
        incr j
    }      
    scale $name.ff.w -bg $color -orient horizontal -from 1 -to 5 -label width
    $name.ff.w set [set SM2::fw$object]
    scale $name.ff.s -bg $color -orient horizontal -from 1 -to 20 -label scale
    $name.ff.s set [set SM2::fs$object]
    grid $name.ff.w -row 7 -column 1 -sticky ew -padx 5
    grid $name.ff.s -row 7 -column 2 -sticky ew -padx 5

    frame $name.b -bg $color
    button $name.b.apply -text Apply -bg $color -command "$object -normal display \$SM2::nd$object color \$SM2::nc$object width \[$name.nf.w get\] scale \[$name.nf.s get\] reverse \$SM2::nr$object; if !\[string compare \$SM2::fd${object} false\] { evaluate \"$object -force false\" } else { set SM2::str \"$object -force width \[$name.ff.w get\] scale \[$name.ff.s get\]\"; foreach i {${SM2::forces}} { if !\[string compare \[set SM2::fd${object}\${i}\] false\] { set SM2::str \"\${SM2::str} -\${i}\"} else { set SM2::str \"\${SM2::str} +\${i} \[set SM2::fc${object}\${i}\]\" } }; evaluate \$SM2::str }"
    button $name.b.applydismiss -text "Apply & dismiss" -bg $color -command "$object -normal display \$SM2::nd$object color \$SM2::nc$object width \[$name.nf.w get\] scale \[$name.nf.s get\] reverse \$SM2::nr$object; if !\[string compare \$SM2::fd${object} false\] { evaluate \"$object -force false\" } else { set SM2::str \"$object -force width \[$name.ff.w get\] scale \[$name.ff.s get\]\"; foreach i {${SM2::forces}} { if !\[string compare \[set SM2::fd${object}\${i}\] false\] { set SM2::str \"\${SM2::str} -\${i}\"} else { set SM2::str \"\${SM2::str} +\${i} \[set SM2::fc${object}\${i}\]\" } }; evaluate \$SM2::str }; destroy $name"
    button $name.b.dismiss -text Dismiss -bg $color -command "destroy $name"
    pack $name.b.apply $name.b.applydismiss $name.b.dismiss -side left -expand true -padx 5

    pack $name.n $name.nf $name.f $name.ff $name.b -expand true -fill both -pady 5
    }
}


SM2::displayInternalForceSM2
Comments  
Arguments contour
item
force
Used by  
Uses  
proc SM2::displayInternalForceSM2 { contour item force } {
    variable setRestLength
    set root .dialogInternalForceSM2
    set list [winfo children $root.f]
    set bg #A0D0A0
    set bg2  #80C080
    foreach w $list {destroy $w}

    switch $force {
    "spring" {
        set  setRestLength 0
        checkbutton $root.f.restLength -variable SM2::setRestLength -text "Set Spring Rest Length" -relief flat -bg $bg
        pack $root.f.restLength -side left
        pack $root.f -expand true -fill both
    }
    "C2" {
        set  setMetricParameters 0
        checkbutton $root.f.setMetric -variable SM2::setMetricParameters -text "Set Metric Parameters" -relief flat -bg $bg
        set resetMetricParameters 0
        checkbutton $root.f.resetMetric -variable SM2::resetMetricParameters -text "Reset Metric Parameters" -relief flat -bg $bg
        pack $root.f.setMetric $root.f.resetMetric  -side left
        pack $root.f -expand true -fill both
    }
    }
}


SM2::displayProfile
Comments  
Arguments model
vertex
cam
color
Used by  
Uses  
proc SM2::displayProfile { model vertex cam color } {
    foreach obj [[$model -scene] -objects] {
    if [string match {rimg3D*} $obj ] {
        evaluate "$obj -displayLine [$model $vertex -position] [$model $vertex -normal] [$model $vertex -range] $color {$model $vertex in $obj}"
    }
    }
}


SM2::editPositionConstraintSM2
Comments  
Arguments name
mesh
color
list
Used by SM2::positionConstraintSM2
Uses SM2::faceQualityConstraint
SM2::faceAreaConstraint
SM2::topologyConstraint
proc SM2::editPositionConstraintSM2 { name mesh color list} {
    switch $name {
    "Topology Constraint" { set result [ $mesh -topologyConstraint ]; SM2::topologyConstraint $mesh [lindex $result 0]  [lindex $result 1] $color $list }
    "Face Area Constraint" { set result [ $mesh -faceAreaConstraint ]; SM2::faceAreaConstraint $mesh [lindex $result 0]  [lindex $result 1] $color $list }
    "Face Quality Constraint" { set result [ $mesh -faceQualityConstraint ]; SM2::faceQualityConstraint $mesh [lindex $result 0]  [lindex $result 1] [lindex $result 2] $color $list}
    }
}


SM2::faceAreaConstraint
Comments  
Arguments mesh
frequency
magnitude
color
list
Used by SM2::editPositionConstraintSM2
Uses SM2::positionConstraintList
proc SM2::faceAreaConstraint { mesh frequency magnitude color list} {
    set root .distanceConstraint2D
    if {![winfo exists $root]} {
    toplevel $root -bg $color
    wm title $root "Face Area Constraint"
    
    frame $root.f -bg $color

    frame $root.f.freq -bd 2 -bg $color
    entry $root.f.freq.entry -relief sunken -width 10 -bg $color
    $root.f.freq.entry delete 0 10
    $root.f.freq.entry insert 0 $frequency
    label $root.f.freq.label -text "Frequency" -bg $color
    pack $root.f.freq.entry -side right -padx 20
    pack $root.f.freq.label -side left -padx 20

    frame $root.f.mag -bd 2 -bg $color
    scale $root.f.mag.scale -orient horizontal -from 0 -to 1 -length 200 -resolution 0.05 -bg $color
    $root.f.mag.scale set $magnitude
    label $root.f.mag.label -text "Constraint Magnitude" -bg $color
    pack $root.f.mag.scale -side right -padx 20
    pack $root.f.mag.label -side left -padx 20


    pack  $root.f.freq  $root.f.mag -side top -fill x
    pack $root.f -expand true -fill both
    
    frame $root.buttons -bg $color
    button $root.buttons.apply -text Apply -command "evaluate \"$mesh -faceAreaConstraint \[$root.f.freq.entry get\] \[$root.f.mag.scale get\]\"; SM2::positionConstraintList $list $mesh" -bg $color
    button $root.buttons.applyDismiss -text "Apply & Dismiss" -command "evaluate \"$mesh -faceAreaConstraint \[$root.f.freq.entry get\] \[$root.f.mag.scale get\]\"; SM2::positionConstraintList $list $mesh; destroy $root" -bg $color
    button $root.buttons.destroy -text "Destroy" -command "destroy $root" -bg $color
    pack $root.buttons.apply $root.buttons.applyDismiss  $root.buttons.destroy -side left -expand true -fill both -padx 20 -pady 10
    pack $root.buttons -expand true -fill both
    }
}


SM2::faceQualityConstraint
Comments  
Arguments mesh
frequency
areaMagnitude
lengthMagnitude
color
list
Used by SM2::editPositionConstraintSM2
Uses SM2::positionConstraintList
proc SM2::faceQualityConstraint { mesh frequency areaMagnitude lengthMagnitude color list} {
    set root .distanceConstraint2D
    if {![winfo exists $root]} {
    toplevel $root -bg $color
    wm title $root "Face Quality Constraint"
    
    frame $root.f -bg $color

    frame $root.f.freq -bd 2 -bg $color
    entry $root.f.freq.entry -relief sunken -width 10 -bg $color
    $root.f.freq.entry delete 0 10
    $root.f.freq.entry insert 0 $frequency
    label $root.f.freq.label -text "Frequency" -bg $color
    pack $root.f.freq.entry -side right -padx 20
    pack $root.f.freq.label -side left -padx 20

    frame $root.f.are -bd 2 -bg $color
    scale $root.f.are.scale -orient horizontal -from 1.1 -to 10 -length 180 -resolution 0.05 -bg $color
    $root.f.are.scale set $areaMagnitude
    label $root.f.are.label -text "Area variation ratio" -bg $color
    pack $root.f.are.scale -side right -padx 20
    pack $root.f.are.label -side left -padx 20

    frame $root.f.len -bd 2 -bg $color
    scale $root.f.len.scale -orient horizontal -from 1.1 -to 10 -length 180 -resolution 0.05 -bg $color
    $root.f.len.scale set $lengthMagnitude
    label $root.f.len.label -text "Diameter variation ratio" -bg $color
    pack $root.f.len.scale -side right -padx 20
    pack $root.f.len.label -side left -padx 20


    pack  $root.f.freq  $root.f.are $root.f.len -side top -fill x
    pack $root.f -expand true -fill both
    
    frame $root.buttons -bg $color
    button $root.buttons.apply -text Apply -command "evaluate \"$mesh -faceQualityConstraint \[$root.f.freq.entry get\] \[$root.f.are.scale get\] \[$root.f.len.scale get\]\"; SM2::positionConstraintList $list $mesh" -bg $color
    button $root.buttons.applyDismiss -text "Apply & Dismiss" -command "evaluate \"$mesh -faceQualityConstraint \[$root.f.freq.entry get\] \[$root.f.are.scale get\] \[$root.f.len.scale get\]\"; SM2::positionConstraintList $list $mesh; destroy $root" -bg $color
    button $root.buttons.destroy -text "Destroy" -command "destroy $root" -bg $color
    pack $root.buttons.apply $root.buttons.applyDismiss  $root.buttons.destroy -side left -expand true -fill both -padx 20 -pady 10
    pack $root.buttons -expand true -fill both
    }
}


SM2::getSM2InView
Comments  
Arguments scn
sm
Used by  
Uses  
proc SM2::getSM2InView { scn sm } {
    set val 0
    foreach {i} [$scn -objects] {
    if {[string match smview* $i]} {
        if { ![string compare [$i -mesh] $sm]} {
        set val $i
        }
    }
    }
    return $val
}


SM2::infobox
Comments  
Arguments sm
subobject
color
Used by  
Uses  
proc SM2::infobox { sm subobject {color \#90C090}} {
    set name .${sm}info
    if ![winfo exists $name] {
    toplevel $name -bg $color
    
    # selected vertex
    frame ${name}.fv -bg \#A0D0A0
    label ${name}.fv.vert -bg \#A0D0A0 -anchor w
    label ${name}.fv.posi -text "position:" -bg $color -anchor e
    label ${name}.fv.norm -text "normal:" -bg $color -anchor e
    label ${name}.fv.meanc -text "mean curvature:" -bg $color -anchor e
    label ${name}.fv.sangle -text "simplex angle:" -bg $color -anchor e
    label ${name}.fv.radius -text "radius:" -bg $color -anchor e
    label ${name}.fv.neig -text "neighbors:" -bg $color -anchor e
    label ${name}.fv.face -text "faces:" -bg $color -anchor e
    label ${name}.fv.edge -text "edge:" -bg $color -anchor e
    label ${name}.fv.metr -text "metric:" -bg $color -anchor e
    label ${name}.fv.posir -bg $color -anchor w
    label ${name}.fv.normr -bg $color -anchor w
    label ${name}.fv.meancr -bg $color -anchor w
    label ${name}.fv.sangler -bg $color -anchor w
    label ${name}.fv.radiusr -bg $color -anchor w
    label ${name}.fv.neigr -bg $color -anchor w
    label ${name}.fv.facer -bg $color -anchor w
    label ${name}.fv.edger -bg $color -anchor w
    label ${name}.fv.metrr -bg $color -anchor w
    grid ${name}.fv.vert -column 1 -row 1 -sticky ew
    grid ${name}.fv.posi -column 1 -row 2 -sticky ew
    grid ${name}.fv.norm -column 1 -row 3 -sticky ew
    grid ${name}.fv.meanc -column 1 -row 4 -sticky ew
    grid ${name}.fv.sangle -column 1 -row 5 -sticky ew
    grid ${name}.fv.radius -column 1 -row 6 -sticky ew
    grid ${name}.fv.metr -column 1 -row 7 -sticky ew
    grid ${name}.fv.neig -column 1 -row 8 -sticky ew
    grid ${name}.fv.face -column 1 -row 9 -sticky ew
    grid ${name}.fv.edge -column 1 -row 10 -sticky ew
    grid ${name}.fv.posir -column 2 -row 2 -sticky ew
    grid ${name}.fv.normr -column 2 -row 3 -sticky ew
    grid ${name}.fv.meancr -column 2 -row 4 -sticky ew
    grid ${name}.fv.sangler -column 2 -row 5 -sticky ew
    grid ${name}.fv.radiusr -column 2 -row 6 -sticky ew
    grid ${name}.fv.metrr -column 2 -row 7 -sticky ew
    grid ${name}.fv.neigr -column 2 -row 8 -sticky ew
    grid ${name}.fv.facer -column 2 -row 9 -sticky ew
    grid ${name}.fv.edger -column 2 -row 10 -sticky ew
    
    # selected edge      
    frame ${name}.fe -bg \#A0D0A0
    label ${name}.fe.edge -bg  \#A0D0A0 -anchor w
    label ${name}.fe.cent -text "center:" -bg $color -anchor e
    label ${name}.fe.vert -text "vertices:" -bg $color -anchor e
    label ${name}.fe.face -text "faces:" -bg $color -anchor e
    label ${name}.fe.edger -bg $color -anchor w
    label ${name}.fe.centr -bg $color -anchor w
    label ${name}.fe.vertr -bg $color -anchor w
    label ${name}.fe.facer -bg $color -anchor w
    grid ${name}.fe.edge -column 1 -row 1 -sticky ew
    grid ${name}.fe.cent -column 1 -row 2 -sticky ew
    grid ${name}.fe.vert -column 1 -row 3 -sticky ew
    grid ${name}.fe.face -column 1 -row 4 -sticky ew
    grid ${name}.fe.centr -column 2 -row 2 -sticky ew
    grid ${name}.fe.vertr -column 2 -row 3 -sticky ew
    grid ${name}.fe.facer -column 2 -row 4 -sticky ew
    
    # selected face
    frame ${name}.ff -bg \#A0D0A0
    label ${name}.ff.face -bg \#A0D0A0  -anchor w
    label ${name}.ff.cent -text "center:" -bg $color -anchor e
    label ${name}.ff.norm -text "normal:" -bg $color -anchor e
    label ${name}.ff.area -text "area:" -bg $color -anchor e
    label ${name}.ff.edge -text "edge:" -bg $color -anchor e
    label ${name}.ff.orie -text "orientation:" -bg $color -anchor e
    label ${name}.ff.zone -text "zone:" -bg $color -anchor e
    label ${name}.ff.vert -text "vertices:" -bg $color -anchor e
    label ${name}.ff.edgs -text "edges:" -bg $color -anchor e
    label ${name}.ff.facer -bg $color -anchor w
    label ${name}.ff.centr -bg $color -anchor w
    label ${name}.ff.normr -bg $color -anchor w
    label ${name}.ff.arear -bg $color -anchor w
    label ${name}.ff.edger -bg $color -anchor w
    label ${name}.ff.orier -bg $color -anchor w
    label ${name}.ff.zoner -bg $color -anchor w
    label ${name}.ff.vertr -bg $color -anchor w
    label ${name}.ff.edgsr -bg $color -anchor w
    grid ${name}.ff.face -column 1 -row 1 -sticky ew
    grid ${name}.ff.cent -column 1 -row 2 -sticky ew
    grid ${name}.ff.norm -column 1 -row 3 -sticky ew
    grid ${name}.ff.area -column 1 -row 4 -sticky ew
    grid ${name}.ff.edge -column 1 -row 5 -sticky ew
    grid ${name}.ff.orie -column 1 -row 6 -sticky ew
    grid ${name}.ff.zone -column 1 -row 7 -sticky ew
    grid ${name}.ff.vert -column 1 -row 8 -sticky ew
    grid ${name}.ff.edgs -column 1 -row 9 -sticky ew
    grid ${name}.ff.centr -column 2 -row 2 -sticky ew
    grid ${name}.ff.normr -column 2 -row 3 -sticky ew
    grid ${name}.ff.arear -column 2 -row 4 -sticky ew
    grid ${name}.ff.edger -column 2 -row 5 -sticky ew
    grid ${name}.ff.orier -column 2 -row 6 -sticky ew
    grid ${name}.ff.zoner -column 2 -row 7 -sticky ew
    grid ${name}.ff.vertr -column 2 -row 8 -sticky ew
    grid ${name}.ff.edgsr -column 2 -row 9 -sticky ew
    
    # selected mesh      
    frame ${name}.fm -bg \#A0D0A0
    label ${name}.fm.mesh -bg  \#A0D0A0 -anchor w
    label ${name}.fm.cent -text "center:" -bg $color -anchor e
    label ${name}.fm.vert -text "number of vertices:" -bg $color -anchor e
    label ${name}.fm.edge -text "number of edges:" -bg $color -anchor e
    label ${name}.fm.face -text "number of faces:" -bg $color -anchor e
    label ${name}.fm.zone -text "number of zones:" -bg $color -anchor e
    label ${name}.fm.centr -bg $color -anchor w
    label ${name}.fm.vertr -bg $color -anchor w
    label ${name}.fm.edger -bg $color -anchor w
    label ${name}.fm.facer -bg $color -anchor w
    label ${name}.fm.zoner -bg $color -anchor w
    grid ${name}.fm.mesh -column 1 -row 1 -sticky ew
    grid ${name}.fm.cent -column 1 -row 2 -sticky ew
    grid ${name}.fm.vert -column 1 -row 3 -sticky ew
    grid ${name}.fm.edge -column 1 -row 4 -sticky ew
    grid ${name}.fm.face -column 1 -row 5 -sticky ew
    grid ${name}.fm.zone -column 1 -row 6 -sticky ew
    grid ${name}.fm.centr -column 2 -row 2 -sticky ew
    grid ${name}.fm.vertr -column 2 -row 3 -sticky ew
    grid ${name}.fm.edger -column 2 -row 4 -sticky ew
    grid ${name}.fm.facer -column 2 -row 5 -sticky ew
    grid ${name}.fm.zoner -column 2 -row 6 -sticky ew
    
    # buttons
    frame ${name}.fb -bg $color
    button ${name}.fb.refresh -text "Refresh" -command "SM2::infobox $sm $subobject" -bg $color
    button ${name}.fb.dismiss -text "Dismiss" -command "evaluate \"$sm -infobox false\"" -bg $color
    pack ${name}.fb.refresh ${name}.fb.dismiss -side left -expand true -pady 5
    grid ${name}.fb -row 2 -column 1
    }

    switch -regexp $subobject {
    "v[0-9]+" {    
        grid forget ${name}.fe ${name}.ff ${name}.fm
        grid ${name}.fv -row 1 -column 1
        ${name}.fv.vert configure -text $subobject
        ${name}.fv.posir configure -text [$sm $subobject -info position]
        ${name}.fv.normr configure -text [$sm $subobject -info normal]
        ${name}.fv.meancr configure -text [$sm $subobject -info meanCurvature]
        ${name}.fv.sangler configure -text [$sm $subobject -info simplexAngle]
        ${name}.fv.radiusr configure -text [$sm $subobject -info radius]
        ${name}.fv.neigr configure -text [$sm $subobject -info neighbors]
        ${name}.fv.facer configure -text [$sm $subobject -info faces]
        ${name}.fv.edger configure -text [$sm $subobject -info edges]
        ${name}.fv.metrr configure -text [$sm $subobject -info metric]
    }
    "e[0-9]+" {
        grid forget ${name}.fv ${name}.ff ${name}.fm
        grid ${name}.fe -row 1 -column 1
        ${name}.fe.edge configure -text $subobject
        ${name}.fe.centr configure -text [$sm $subobject -info center]
        ${name}.fe.vertr configure -text [$sm $subobject -info vertices]
        ${name}.fe.facer configure -text [$sm $subobject -info faces]
    }
    "f[0-9]+" {
        grid forget ${name}.fv ${name}.fe ${name}.fm
        grid ${name}.ff -row 1 -column 1
        ${name}.ff.face configure -text $subobject
        ${name}.ff.centr configure -text [$sm $subobject -info center]
        ${name}.ff.normr configure -text [$sm $subobject -info normal]
        ${name}.ff.arear configure -text [$sm $subobject -info area]
        ${name}.ff.edger configure -text [$sm $subobject -info edge]
        ${name}.ff.orier configure -text [$sm $subobject -info orientation]
        ${name}.ff.zoner configure -text [$sm $subobject -info zone]
        ${name}.ff.vertr configure -text [$sm $subobject -info vertices]
        ${name}.ff.edgsr configure -text [$sm $subobject -info edges]
    }
    "mesh" {
        grid forget ${name}.fv ${name}.fe ${name}.ff
        grid ${name}.fm -row 1 -column 1
        ${name}.fm.mesh configure -text $sm
        ${name}.fm.centr configure -text [$sm -info center]
        ${name}.fm.vertr configure -text [$sm -info vertices]
        ${name}.fm.edger configure -text [$sm -info edges]
        ${name}.fm.facer configure -text [$sm -info faces]
        ${name}.fm.zoner configure -text [$sm -info zones]
    }
    }
}


SM2::installContourSM2Menu
Comments  
Arguments parent
camera
object
color
Used by  
Uses contour::installActiveContour3DMenu
proc SM2::installContourSM2Menu { parent camera object color } {
    contour::installActiveContour3DMenu $parent $camera $object $color
}


SM2::installSM2
Comments  
Arguments parent
camera
object
color
Used by  
Uses graphics3D::renderoptions
imagedata::createRangeInformation
graphics3D::materialoptions
imagedata::editRangeInformation
modules::selectColorStr
imagedata::editIntensityProfileDialog
proc SM2::installSM2 { parent camera object color } {
    variable select$camera
    
    set popup [menu $parent.popup -tearoff 0 -bg "white" -postcommand "set SM2::select$camera \[$object -selectionMode $camera\]" ]
    $popup add command -label "Left Button" -foreground black -state disabled -command {}
    $popup add radio -label "Select Object" -command "evaluate \"$object -selectionMode model $camera\"" -selectcolor black -variable SM2::select$camera -value model
    $popup add radio -label "Select Zone" -command "evaluate \"$object -selectionMode zone $camera\"" -selectcolor black -variable SM2::select$camera -value zone
    $popup add radio -label "Edit Zone" -command "evaluate \"$object -selectionMode editZone $camera\"" -selectcolor black -variable SM2::select$camera -value editZone
    $popup add radio -label "Select Vertex/Edge/Face" -command "evaluate \"$object -selectionMode subobject $camera\"" -selectcolor black -variable SM2::select$camera -value subobject
    $popup add radio -label "Select Face" -command "evaluate \"$object -selectionMode face $camera\"" -selectcolor black -variable SM2::select$camera -value face
    $popup add radio -label "Grab Simplex Mesh" -command "evaluate \"$object -selectionMode grab $camera\"" -selectcolor black -variable SM2::select$camera -value grab
    $popup add separator
    bind [$camera -widget]  <Button-3> "tk_popup $popup %X %Y"

    menubutton $parent.context.object -text "File" -menu $parent.context.object.mn -bg $color
    set menu [menu $parent.context.object.mn -bg $color ]
    $menu add command -label "save..." -command "set SM2::name \[tk_getSaveFile -filetypes {{\"Simplex Mesh\" {.sm} } {All *}} -parent . -title {Save mesh as}\]; if \[string compare \$SM2::name {}\] { evaluate \"$object -save \$SM2::name\"}"
    $menu add command -label "Save As..." -command "SM2::saveOption $object {{\"Simplex Mesh\" {*.sm } } {All * }  } {Select a 2-simplex mesh name}"
    $menu add separator
    $menu add command -label destroy -command "evaluate \"$object -destroy\""

    menubutton $parent.context.graphics -text "Graphics" -menu $parent.context.graphics.mn -bg $color
    set menu [menu $parent.context.graphics.mn -bg $color -postcommand "set graphics3D::v$object \[$object -render\]; scan \[$object -normal\] \"%s %s %s %s %s %s %s %s %s %s\" ign SM2::nd${object} ign ign ign ign ign ign ign SM2::nr${object}; if \[string compare \[lindex \[$object -force\] 0\] false \] { set SM2::fd${object} \"external scale 10\"} else {set SM2::fd${object} false}"]
    graphics3D::renderoptions $menu $object
    $menu add separator
    $menu add checkbutton -label "display normals" -variable SM2::nd${object} -onvalue true -offvalue false -selectcolor black -command "evaluate \"$object -normal display \${SM2::nd$object}\" scale 10"
    $menu add checkbutton -label "reverse normals" -variable SM2::nr${object} -onvalue true -offvalue false -selectcolor black -command "evaluate \"$object -normal display reverse \${SM2::nr$object}\""
    $menu add checkbutton -label "display forces" -variable SM2::fd${object}l -onvalue "external scale 10" -offvalue false -selectcolor black -command "evaluate \"$object -force \${SM2::fd$object}\""
    $menu add command -label "display..." -command "SM2::display $object $color"
    $menu add separator
    $menu add command -label "color..." -command "evaluate \"$object -color \[ modules::selectColorStr  \[ $object -color\] \]\""
    $menu add command -label "material..." -command "graphics3D::material $object $color"
    graphics3D::materialoptions $menu $object

    menubutton $parent.context.forces -text "Internal Constraints" -menu $parent.context.forces.mn -bg $color
    set menu [menu $parent.context.forces.mn -bg $color -postcommand "set SM2::refshape \[$object -referenceShape\]"]
    $menu add command -label "Internal Parameters..." -command "SM2::internalParametersDialog $object $color"
    $menu add command -label "Internal Force Type..." -command "SM2::internalForceSM2 $object"
    $menu add cascade -label "Deformation Mode" -menu $parent.context.forces.mode
    set mn [menu $parent.context.forces.mode -bg $color -tearoff 0 -postcommand "set SM2::mode \[$object -deformationMode\]"]
    $mn add radiobutton -label "none" -variable SM2::mode -selectcolor black -value no -command "evaluate \"$object -deformationMode no\""
    $mn add radiobutton -label "local" -variable SM2::mode -selectcolor black -command "evaluate \"$object -deformationMode local\""
    $mn add radiobutton -label "globally constrained" -variable SM2::mode -selectcolor black -command "evaluate \"$object -deformationMode globallyConstrained\"" -value globallyConstrained
    $mn add radiobutton -label "global" -variable SM2::mode -selectcolor black -command "evaluate \"$object -deformationMode global\""

    $menu add cascade -label "Global Transformation" -menu $parent.context.forces.transfo
    set mn [menu $parent.context.forces.transfo -bg $color -tearoff 0 -postcommand "set SM2::transfo \[$object -globalTransformation\]"]
    $mn add radiobutton -label "rigid" -variable SM2::transfo -selectcolor black -command "evaluate \"$object -globalTransformation rigid\""
    $mn add radiobutton -label "similarity" -variable SM2::transfo -selectcolor black -command "evaluate \"$object -globalTransformation similarity\""
    $mn add radiobutton -label "affine" -variable SM2::transfo -selectcolor black -command "evaluate \"$object -globalTransformation affine\""
    $mn add radiobutton -label "spline" -variable SM2::transfo -selectcolor black -command "evaluate \"$object -globalTransformation spline\""
    $mn add radiobutton -label "axial" -variable SM2::transfo -selectcolor black -command "evaluate \"$object -globalTransformation axial\""

    $menu add separator

    $menu add separator
    $menu add checkbutton -label "use reference shape" -selectcolor black -variable SM2::refshape -onvalue true -offvalue false -command "if !\[string compare \$SM2::refshape true\] { evaluate \"$object -referenceShape true store\"; evaluate \"$object -deformationMode globallyConstrained\" } else { evaluate \"$object -referenceShape false\" }"
    $menu add command -label "store reference shape" -command "evaluate \"$object -referenceShape store\""
    $menu add separator
    $menu add command -label "select profile..." -command "SM2::selectProfile $object $color"
    $menu add command -label "create profile..." -command "SM2::createProfile $object $color"

    $menu add separator
    #       $menu add cascade -label "internal" -menu  $parent.context.forces.int
    #       set mn [menu $parent.context.forces.int -bg $color -tearoff 0 -postcommand "set SM2::internal \[$object -internal\]"]
    #       foreach { force } [$object -internal all] {
    #       $mn add radiobutton -label $force -variable SM2::internal -selectcolor black -command "evaluate \"$object -internal $force\""
    #       }

    $menu add command -label "Position Constraint" -command "SM2::positionConstraintSM2 $object $color"

    #       $menu add command -label "balloon..." -command "SM2::balloonForce $object $color"

    menubutton $parent.context.ext -text "External Constraints" -menu $parent.context.ext.mn -bg $color
    set mn [menu $parent.context.ext.mn -bg $color -tearoff 0 ]
    $mn add command -label "Edit Range Information" -command " if [string compare [isModuleLoaded tclImageData] no] { imagedata::editRangeInformation \[$object -rangeInformation\]}"
    
    $mn add cascade -label "Set New Range Information" -menu $mn.new
    set mn2 [menu $mn.new -bg $color -tearoff 0 ]
    if [string compare [isModuleLoaded tclImageData] no] { imagedata::createRangeInformation $mn.new $object $color }
    $mn add command -label "Store Intensity Profiles..." -command "SM2::storeIntensityProfileDialog $object"
    $mn add command -label "Edit Intensity Profiles..." -command "set rinfs \[ $object -rangeInformationSet \]; if \[ string compare \$rinfs \"Intensity Profile\" \] { if \[string compare \[isModuleLoaded tclImageData \] no \] { imagedata::editIntensityProfileDialog \[ new ipinfos \$rinfs \]  } } "
    
    menubutton $parent.context.topology -text "Mesh" -menu $parent.context.topology.mn -bg $color
    set menu [menu $parent.context.topology.mn -bg $color]
    $menu add command -label "Create New Zone..." -command "SM2::newZone $object $camera $color"
    $menu add cascade -label "Select Zone..." -menu $menu.zones
    menu $menu.zones -tearoff 0 -bg $color -postcommand "
        set SM2::selectedZone \[ $object -select\]
        $menu.zones delete 0 last
        foreach {z} \[ $object -zones \] {
           $menu.zones add radio -label \[ $object \$z -name \] -selectcolor black -variable SM2::selectedZone -value \$z -command \"evaluate {$object -selectionMode zone $camera};evaluate {$object -select \$z} \" }"
    $menu add separator
    $menu add cascade -label "Append Mesh..." -menu $menu.append
    menu $menu.append -tearoff 0 -bg $color -postcommand "
        $menu.append delete 0 last
        foreach {m} \[ which sm \] {
           if {\[ string compare \$m $object \]} {$menu.append add command -label \" \$m \" -command \"evaluate {$object -append \$m} \"  } }"
    $menu add command -label "Refine Mesh" -command "evaluate \"$object -refine\""
    $menu add command -label "Decimate Mesh" -command "evaluate \"$object -decimate\""
    $menu add command -label "Swap Mesh Edges" -command "evaluate \"$object -swap\""

    pack $parent.context.object $parent.context.graphics $parent.context.forces $parent.context.ext  $parent.context.topology -side left
}


SM2::internalForceSM2
Comments  
Arguments mesh
Used by  
Uses  
proc SM2::internalForceSM2 { mesh } {
    global forceType
    variable zm

    if {![winfo exists .dialogInternalForceSM2]} {
    set bg #A0D0A0
    set bg2  #80C080
    set root .dialogInternalForceSM2
    toplevel $root -bg $bg
    wm title $root "2-Simplex Mesh Internal Force"

    if { [string match z* [$mesh -select]]} {
        set mn [tk_optionMenu $root.item deformableItem [$mesh -select]  Mesh]
    } else {
        set mn [tk_optionMenu $root.item deformableItem Mesh]
    }
    $root.item  configure -bg $bg2

    for {set i 0} {$i <= [$mn index last]} {incr i} {
        $mn entryconfigure $i -selectcolor black -command "SM2::displayInternalForceSM2 $mesh \[$mn entrycget $i -label\] \$forceType" -background $bg2
    }
    pack $root.item -padx 10 -pady 10 -expand true -fill x

    set mn2 [tk_optionMenu $root.type forceType "C0" "C1" "C2" "G2" "shape" "spring" "none" ]
    $root.type  configure -bg $bg2

    for {set i 0} {$i <= [$mn2 index last]} {incr i} {
        $mn2 entryconfigure $i -selectcolor black -command "SM2::displayInternalForceSM2 $mesh \$deformableItem \[$mn2 entrycget $i -label\]" -background $bg2
    }
    pack $root.type -padx 10 -pady 10 -expand true -fill x

    
    frame $root.f -bg $bg
    pack $root.f -expand true -fill both

    frame $root.buttons -bg $bg
    button $root.buttons.apply -text Apply -command "SM2::setInternalForceSM2 $mesh \$deformableItem \$forceType" -bg $bg2
    button $root.buttons.applyDismiss -text "Apply & Dismiss" -command "SM2::setInternalForceSM2 $mesh \$deformableItem \$forceType;destroy $root" -bg $bg2
    button $root.buttons.destroy -text "Destroy" -command "destroy $root" -bg $bg2
    pack $root.buttons.apply $root.buttons.applyDismiss  $root.buttons.destroy -side left -expand true -fill both -padx 20 -pady 10
    pack $root.buttons -expand true -fill both

    set forceType [$mesh -internal]
    SM2::displayInternalForceSM2 $mesh "Mesh" $forceType
    }
}


SM2::internalParametersDialog
Comments  
Arguments object
color
Used by  
Uses  
proc SM2::internalParametersDialog { object color } {
    variable zm

    set name .dialogInternal$object
    if ![winfo exists $name] {
    toplevel $name -bg $color
    wm title $name "$object internal parameters"
    set SM2::zm $object

    scale $name.alpha -orient horizontal -label Alpha -from 0 -to 1 -length 200 -resolution 0.01 -bg $color
    bind $name.alpha <ButtonRelease-1> "evaluate \"\$SM2::zm -alpha \[$name.alpha get\]\""
    $name.alpha set [$object -alpha]

    scale $name.beta -orient horizontal -label Beta -from 0 -to 1 -length 200 -resolution 0.01 -bg $color
    bind $name.beta <ButtonRelease-1> "evaluate \"\$SM2::zm -beta \[$name.beta get\]\""
    $name.beta set [$object -beta]

    scale $name.locality -orient horizontal -label Locality -from 0 -to 1 -length 200 -resolution 0.01 -bg $color
    bind $name.locality <ButtonRelease-1> "evaluate \"\$SM2::zm -locality \[$name.locality get\]\""
    $name.locality set [$object -locality]

    scale $name.weight -orient horizontal -label Weight -from 0 -to 1 -resolution 0.01 -length 200 -bg $color
    bind $name.weight <ButtonRelease-1> "evaluate \"\$SM2::zm -weight \[$name.weight get\]\""
    $name.weight set [$object -weight]

    scale $name.rigidity -orient horizontal -label Rigidity -from 0 -to [$object -rigidity max] -length 200 -bg $color
    bind $name.rigidity <ButtonRelease-1> "evaluate \"\$SM2::zm -rigidity \[$name.rigidity get\]\""
    $name.rigidity set [$object -rigidity]

    button $name.dismiss -text "Dismiss" -command "destroy $name" -bg $color

    set mn [tk_optionMenu $name.zm SM2::zm sm1]
    $name.zm configure -bg $color
    $mn configure -postcommand "
             set sel \[$object -select\]
        if { \[string match v* \$sel\] } {
              set add 1
         for {set i 0} {\$i <= \[$mn index last\]} {incr i} {
                if !\[string compare \[$mn entrycget \$i -label\] \$sel\] {
                  set add 0
                }
         }
         if \$add { $mn add radiobutton -variable SM2::zm -label \$sel -value \"$object \$sel\" -selectcolor black -background $color -command \"$name.alpha set \\\[eval \\\$SM2::zm -alpha\\\]; $name.beta set \\\[eval \\\$SM2::zm -beta\\\]; $name.locality set \\\[eval \\\$SM2::zm -locality\\\]; $name.weight set \\\[eval \\\$SM2::zm -weight\\\]; $name.rigidity set \\\[eval \\\$SM2::zm -rigidity\\\]\" }
       }"
    foreach z "[$object -zones]"  {
        $mn add radiobutton -variable SM2::zm -label "$z ([$object $z -name])" -value "$object $z"
    }
    for {set i 0} {$i <= [$mn index last]} {incr i} {
        $mn entryconfigure $i -selectcolor black -background $color -command "$name.alpha set \[eval \$SM2::zm -alpha\]; $name.beta set \[eval \$SM2::zm -beta\]; $name.locality set \[eval \$SM2::zm -locality\]; $name.weight set \[eval \$SM2::zm -weight\]; $name.rigidity set \[eval \$SM2::zm -rigidity\]"
    }

    pack $name.zm -padx 10 -pady 10
    pack $name.alpha $name.beta $name.locality $name.weight $name.rigidity -padx 10 -pady 5
    pack $name.dismiss -padx 10 -pady 20
    }
}


SM2::isSM2InView
Comments  
Arguments scn
sm
Used by SM2::addSM2View
Uses  
proc SM2::isSM2InView { scn sm } {
    set val 0
    foreach {i} [$scn -objects] {
    if {[string match smview* $i]} {
        if { ![string compare [$i -mesh] $sm]} {
        set val 1
        }
    }
    }
    return $val
}


SM2::listfind
Comments  
Arguments box
str
Used by  
Uses  
proc SM2::listfind { box str } {
    for { set index 0 } { $index <= [$box size] } { incr index } {
    if ![string compare [$box get $index] $str] {
        return $index
    }
    }
    return -1
}


SM2::newZone
Comments  
Arguments object
camera
bg
Used by  
Uses  
proc SM2::newZone {object camera bg} {
    set root .smNewZone    
    if {![winfo exists $root]} {
    set bg "#A0D0A0"
    set bg2  "#80C080"
    toplevel $root -bg $bg
    wm title $root "New 2-simplex mesh Zone"
    
    frame $root.f -bg $bg
    
    frame $root.f.name -bd 2 -bg $bg
    entry $root.f.name.entry -relief sunken -width 20 -bg $bg
    $root.f.name.entry delete 0 20
    $root.f.name.entry insert 0 {New part}
    label $root.f.name.label -text "Zone Name" -bg $bg
    pack $root.f.name.entry -side right -padx 20
    pack $root.f.name.label -side left -padx 20

    pack $root.f.name  -side top -fill x
    pack $root.f -expand true -fill both

    frame $root.buttons -bg $bg
    button $root.buttons.applyDismiss -text "Apply & Dismiss" -command "evaluate \"$object -selectionMode editZone $camera\";evaluate \"$object -newZone \{\[$root.f.name.entry get\]\}\"; destroy $root" -bg $bg
    button $root.buttons.destroy -text "Destroy" -command "destroy $root" -bg $bg
    pack $root.buttons.applyDismiss  $root.buttons.destroy -side left -expand true -fill both -padx 20 -pady 10
    pack $root.buttons -expand true -fill both
    }
}


SM2::positionConstraintList
Comments  
Arguments list
mesh
Used by SM2::faceAreaConstraint
SM2::topologyConstraint
SM2::faceQualityConstraint
SM2::positionConstraintSM2
Uses  
proc SM2::positionConstraintList { list mesh } {
    set nbConstraints [$mesh -positionConstraint]
    $list delete 0 end
    for { set i 0 } { $i < $nbConstraints } { incr i } {
    $list insert $i [$mesh -positionConstraint $i ]
    }
}


SM2::positionConstraintSM2
Comments  
Arguments mesh
color
Used by  
Uses SM2::positionConstraintList
SM2::editPositionConstraintSM2
proc SM2::positionConstraintSM2 { mesh color } {
    set root .positionConstraint2D
    if {![winfo exists $root]} {
    toplevel $root -bg $color
    wm title $root "2-simplex Mesh Position Constraint"
    label $root.msg -justify center -text "List of Position Constraints" -bg $color
    pack $root.msg  -side top
    
    frame $root.f -borderwidth .5c -bg $color
    pack $root.f -side top -expand yes -fill y
    
    scrollbar $root.f.scroll -command "$root.f.list yview" -bg $color
    listbox $root.f.list -yscroll "$root.f.scroll set" -setgrid 1 -height 12 -bg $color
    pack $root.f.scroll -side right -fill y
    pack $root.f.list -side left -expand 1 -fill both

    SM2::positionConstraintList $root.f.list $mesh

    frame $root.process -bg $color
    pack $root.process -side top -pady 2m
    menubutton $root.process.create -text "Create Constraint" -bg $color -underline 0 -direction above -menu $root.process.create.m -relief raised
    menu $root.process.create.m -tearoff 0 -bg $color
    $root.process.create.m add command -label "Topology Constraint" -command "SM2::topologyConstraint $mesh 8 \[expr \[ $mesh -radius \] / 10.0 \] $color $root.f.list"
    $root.process.create.m add command -label "Face Area Constraint" -command "SM2::faceAreaConstraint $mesh 8 1.0 $color $root.f.list"
    $root.process.create.m add command -label "Face Quality Constraint" -command "SM2::faceQualityConstraint $mesh 8 2.0 2.0 $color $root.f.list"
    button $root.process.edit -text "Edit Constraint" -bg $color -command " SM2::editPositionConstraintSM2 \[ $root.f.list get \[ lindex \[ $root.f.list curselection \] 0 \] \] $mesh $color $root.f.list"
    button $root.process.delete -text "Delete Constraint" -bg $color -command "evaluate \"$mesh -positionConstraint \[ lindex \[ $root.f.list curselection \] 0 \] delete\"; SM2::positionConstraintList $root.f.list $mesh"
    pack $root.process.create $root.process.edit $root.process.delete -side top -expand 1

    frame $root.button -bg $color
    pack $root.button -side bottom -pady 2m
    button $root.button.dismiss -text Dismiss -command "destroy $root" -bg $color
    pack  $root.button.dismiss -side left -expand 1
    }
}


SM2::saveOption
Comments  
Arguments object
fileType
windowTitle
Used by  
Uses  
proc SM2::saveOption { object fileType windowTitle} {
    set root .trianSave
    if {![winfo exists $root]} {
    set bg "#A0D0A0"
    set bg2  "#80C080"
    toplevel $root -bg $bg
    wm title $root "Save Simplex Mesh"
    frame $root.f -bg $bg

    foreach f [$object -saveOption] {
        set name $root.f.[string tolower $f]
        set $f.save [$object -saveOption $f]
        checkbutton $name  -text $f -variable $f.save -relief flat -bg $bg -onvalue {true} -offvalue {false}
        if {[$object -saveOption $f]}  {
        $name select
        } else {
        $name deselect
        }
        pack $name -side top -expand true -fill both
    }
    pack $root.f -side top
    frame $root.buttons -bg $bg
    button $root.buttons.save -text "Save" -command "destroy $root;  foreach f \[$object -saveOption\] {evaluate \"$object -saveOption \$f \[subst $\\{\$f.save\\} \]\"}; evaluate \"$object -save \[ tk_getSaveFile -filetypes \{$fileType\} -title \{$windowTitle\}\]\"" -bg $bg
    button $root.buttons.destroy -text "Dismiss" -command "evaluate\"destroy $root\"" -bg $bg
    pack $root.buttons.save  $root.buttons.destroy -side left -expand true -fill both -padx 20 -pady 10
    pack $root.buttons -expand true -fill both
    }
}


SM2::selectEdge
Comments  
Arguments widget
object
subobject
color
Used by  
Uses  
proc SM2::selectEdge { widget object subobject color } {
    if ![winfo exists $widget] {
    menubutton $widget -text $subobject -bg $color -menu $widget.mn
    pack $widget -side right
    set menu [menu $widget.mn -bg $color -postcommand ""]
    $menu add command -label [set SM2::t2state] -command "if \[string compare \$SM2::t2first none\] {$object -T2 \$SM2::t2first $subobject; set SM2::t2state \"connect to...\"; set SM2::t2first none} else {set SM2::t2first $subobject; set SM2::t2state \"connect to \$SM2::t2first\"}"
    $menu add command -label {Remove Edge} -command "evaluate \"$object -T1 $subobject\""
    $menu add command -label {Swap Edge} -command "evaluate \"$object -T7 $subobject\""
    $menu add command -label "info..." -command "$object -infobox true"
    }
}


SM2::selectFace
Comments  
Arguments widget
object
subobject
color
Used by  
Uses  
proc SM2::selectFace { widget object subobject color } {
    if ![winfo exists $widget] {
    menubutton $widget -text $subobject -bg $color -menu $widget.mn
    pack $widget -side right
    set menu [menu $widget.mn -bg $color]
    $menu add command -label "info..." -command "$object -infobox true"
    $menu add command -label [set SM2::t4state] -command "if \[string compare \$SM2::t4first none\] {$object $subobject -mergeFace \$SM2::t4first ; set SM2::t4state \"Merge with...\"; set SM2::t4first none} else {set SM2::t4first $subobject; set SM2::t4state \"Merge with \$SM2::t4first\"}"
    }
}


SM2::selectProfile
Comments  
Arguments object
color
Used by  
Uses  
proc SM2::selectProfile { object color } {
    if ![winfo exists .sprofile${object}] {
    set name .sprofile${object}
    toplevel $name -bg $color
    wm title $name "select intensity profile"

    variable criterion differences

    listbox $name.l -height 10 -bg white
    foreach l [$object -profile list] {
        $name.l insert end $l
    }
    $name.l selection set 0
    $name.l activate 0

    scale $name.th -label threshold -orient horizontal -from 0 -to 255 -bg $color
    $name.th set 50
    bind $name.th <Enter> "focus $name.th"

    scale $name.rng -label "force range" -orient horizontal -from 0.0 -to 30.0 -resolution 0.1 -bg $color
    $name.rng set 10.0
    bind $name.rng <Enter> "focus $name.rng"

    radiobutton $name.r1 -text "absolute differences" -selectcolor black -variable SM2::criterion -value differences -bg $color -anchor w -command "$name.th configure -from 0 -to 255 -resolution 1; $name.th set 50"
    radiobutton $name.r2 -text "linear coefficient" -selectcolor black -variable SM2::criterion -value linear -bg $color -anchor w -command "$name.th configure -from 0.0 -to 1.0 -resolution 0.01; $name.th set 0.5"
    radiobutton $name.r3 -text "correlation coefficient" -selectcolor black -variable SM2::criterion -value correlation -bg $color -anchor w -command "$name.th configure -from 0.0 -to 1.0 -resolution 0.01; $name.th set 0.5"
    radiobutton $name.r4 -text "pattern intensity" -selectcolor black -variable SM2::criterion -value pattern -bg $color -anchor w -command "$name.th configure -from 0 -to 100 -resolution 1; $name.th set 30"

    frame $name.b -bg $color

    button $name.b.select -text Select -bg $color -command "evaluate \"$object -profile select \[$name.l get active\] criterion \$SM2::criterion threshold \[$name.th get\] range \[$name.rng get\]\""
    button $name.b.dismiss -text Dismiss -bg $color -command "destroy $name"
    pack $name.b.select $name.b.dismiss -expand true -side left -padx 5 -pady 5

    pack $name.l $name.th $name.rng $name.r1 $name.r2 $name.r3 $name.r4 $name.b -fill both -expand true
    }
}


SM2::selectVertex
Comments  
Arguments widget
object
subobject
color
Used by  
Uses imagedata::createRangeInformation
imagedata::editRangeInformation
proc SM2::selectVertex { widget object subobject color } {
    if ![winfo exists $widget] {
    menubutton $widget -text $subobject -bg $color -menu $widget.mn
    pack $widget -side right
    set menu [menu $widget.mn -bg $color -postcommand "set SM2::fixed \[$object $subobject -fix\]"]
    $menu add checkbutton -label "fixed" -variable SM2::fixed -onvalue true -offvalue false -selectcolor black -command "evaluate \"$object $subobject -fix \$SM2::fixed\""
    $menu add command -label "info..." -command "$object -infobox true"
    $menu add command -label "Intensity profile" -command "if \[string compare [isModuleLoaded tclImageData] no\] {if \[ string compare \[which rimg3D\] \"\" \] {set SM2::a \[new il \[ \[ lindex \[which rimg3D \] 0 \] -images intensity \] [ $object $subobject -position] [$object $subobject -normal] 10 \];\$SM2::a -draw   } } "
    $menu add command -label "Gradient profile" -command "if \[string compare [isModuleLoaded tclImageData] no\] {if \[ string compare \[which rimg3D\] \"\" \] {if \[ string compare \[ \[ lindex \[which rimg3D \] 0 \] -images gradient \] \"\" \] {  set SM2::a \[new il \[ \[ lindex \[which rimg3D \] 0 \] -images gradient \] [ $object $subobject -position] [$object $subobject -normal] 10 \];\$SM2::a -draw   } } }"
    $menu add command -label "closest..." -command "tk_messageBox -message \[ concat \" closest point in \" \[ $object $subobject -closest \] \]"
    $menu add command -label "Edit Range Information" -command " if [string compare [isModuleLoaded tclImageData] no] { imagedata::editRangeInformation \[$object $subobject -rangeInformation\]}"
    $menu add cascade -label "Set New Range Information" -menu $menu.new
    set mn2 [menu $menu.new -bg $color -tearoff 0 ]
    if [string compare [isModuleLoaded tclImageData] no] { imagedata::createRangeInformation $menu.new "$object $subobject" $color }
    }
}


SM2::selectZone
Comments  
Arguments widget
object
subobject
color
Used by  
Uses graphics3D::materialoptions
imagedata::editRangeInformation
modules::selectColorStr
graphics3D::textureoptions
graphics3D::renderoptions
imagedata::createRangeInformation
proc SM2::selectZone { widget object subobject color } {
    if ![winfo exists $widget] {
    menubutton $widget -text $subobject -bg $color -menu $widget.mn
    pack $widget -side right
    set menu [menu $widget.mn -bg $color -postcommand "set graphics3D::v$object$subobject \[$object $subobject -render\]"]
    $menu add command -label "Expand Zone" -command "evaluate \"$object $subobject -expand\""
    $menu add command -label "Shrink Zone" -command "evaluate \"$object $subobject -shrink\""
    $menu add command -label "Keep Main Component" -command "evaluate \"$object $subobject -keepMainComponent\""
    $menu add command -label "Cut Zone" -command "evaluate \"$object $subobject -cut\""
    $menu add command -label "Refine Zone" -command "evaluate \"$object $subobject -refine\""
    $menu add command -label "Decimate Zone" -command "evaluate \"$object $subobject -decimate\""
    $menu add command -label "Swap Zone Edges" -command "evaluate \"$object $subobject -swap\""
    $menu add separator
    $menu add cascade -label "Display Options" -menu $menu.dis
    set mn0 [menu $menu.dis -bg $color -tearoff 0 ]
    graphics3D::renderoptions $mn0 $object $subobject
    graphics3D::textureoptions $mn0 "$object $subobject" $color
    $menu add command -label "color..." -command "evaluate \"$object $subobject -color \[ modules::selectColorStr  \[ $object $subobject -color\] \]\""
    $menu add command -label "material..." -command "graphics3D::material \"$object $subobject\" $color"
    $menu add cascade -label "Predefined Materials" -menu $menu.pre
    set mn1 [menu $menu.pre -bg $color -tearoff 0 ]
    graphics3D::materialoptions $mn1 "$object $subobject"
    $menu add separator
    $menu add command -label "Edit Range Information" -command " if [string compare [isModuleLoaded tclImageData] no] { imagedata::editRangeInformation \[$object $subobject -rangeInformation\]}"
    $menu add cascade -label "Set New Range Information" -menu $menu.new
    set mn2 [menu $menu.new -bg $color -tearoff 0 ]
    if [string compare [isModuleLoaded tclImageData] no] { imagedata::createRangeInformation $menu.new "$object $subobject" $color }
    }
}


SM2::setInternalForceSM2
Comments  
Arguments mesh
item
force
Used by  
Uses  
proc SM2::setInternalForceSM2 { mesh item force } {
    variable itemName
    if {[ string match z* $item ]} {
    set itemName "$mesh $item"
    } else {
    set itemName $mesh
    }

    switch $force {
    "spring" { if { $SM2::setRestLength == 1 } {
        evaluate "$mesh -setRestLength" }
    }
    "C2" {
        if { $SM2::setMetricParameters == 1 } {
        evaluate "$mesh -metricParameters store" }
        if { $SM2::resetMetricParameters == 1 } {
        evaluate "$mesh -metricParameters reset" }
    }
    }
    evaluate "$itemName -internal \"$force\" "
}


SM2::storeIntensityProfile
Comments  
Arguments object
range
Used by  
Uses  
proc SM2::storeIntensityProfile { object range } {
    if [string compare [isModuleLoaded tclImageData] no ] {
    if [ string compare [which rimg3D] "" ] {
        set i 0
        set inr [ [lindex [which rimg3D] 0] -images intensity ]
        for {set i 0} {$i < [$object -info vertices] } { incr i} {
        set vertex v$i
        set p  [ $object $vertex -position]
        set d [ $object $vertex -normal ]
        set line [new il $inr  [ lindex $p 0] [lindex $p 1] [lindex $p 2]   [ lindex $d 0] [lindex $d 1] [lindex $d 2]  $range ]
        set profile [ new ipinfo $line 50 0 10.0 differences ]
        $line -destroy
        $object $vertex -rangeInformation [$profile -cast]
        }
    }
    }
}


SM2::storeIntensityProfileDialog
Comments  
Arguments object
Used by  
Uses  
proc SM2::storeIntensityProfileDialog { object } {
    set root .storeIntensityProfile
    variable rangeIP
    if {![winfo exists $root]} {
    set bg #A0D0A0
    toplevel $root -bg $bg
    wm title $root "2-Simplex Mesh Intensity Profile Storage"
    frame $root.f -bg $bg
    pack $root.f -expand true -fill both

    frame $root.f.sc -bg $bg
    set SM2::rangeIP 10
    scale $root.f.sc.range -label "Range of Intensity Profile" -orient horizontal -variable SM2::rangeIP -from 1 -to 30 -resolution 1 -bg $bg -length 200
    pack  $root.f.sc.range  -side left
    pack $root.f.sc -expand true -fill both
    
    frame $root.f.buttons -bg $bg
    button $root.f.buttons.store -text "Store Intensity Profiles" -command "destroy $root;SM2::storeIntensityProfile $object $SM2::rangeIP" -bg $bg
    button $root.f.buttons.dismiss -text Dismiss -command "destroy $root" -bg $bg
    pack $root.f.buttons.store  $root.f.buttons.dismiss -side left
    pack $root.f.buttons -expand true -fill both
    }
}


SM2::topologyConstraint
Comments  
Arguments mesh
frequency
gridSize
color
list
Used by SM2::editPositionConstraintSM2
Uses SM2::positionConstraintList
proc SM2::topologyConstraint { mesh frequency gridSize color list} {
    set root .topologyConstraint2D
    if {![winfo exists $root]} {
    toplevel $root -bg $color
    wm title $root "Topology Constraint"
    
    frame $root.f -bg $color

    frame $root.f.freq -bd 2 -bg $color
    entry $root.f.freq.entry -relief sunken -width 10 -bg $color
    $root.f.freq.entry delete 0 10
    $root.f.freq.entry insert 0 $frequency
    label $root.f.freq.label -text "Frequency" -bg $color
    pack $root.f.freq.entry -side right -padx 20
    pack $root.f.freq.label -side left -padx 20

    frame $root.f.mag -bd 2 -bg $color
    scale $root.f.mag.scale -orient horizontal -from 0 -to 1 -length 200 -resolution 0.05 -bg $color
    $root.f.mag.scale set $gridSize
    label $root.f.mag.label -text "Grid Size" -bg $color
    pack $root.f.mag.scale -side right -padx 20
    pack $root.f.mag.label -side left -padx 20


    pack  $root.f.freq  $root.f.mag -side top -fill x
    pack $root.f -expand true -fill both
    
    frame $root.buttons -bg $color
    button $root.buttons.apply -text Apply -command "evaluate \"$mesh -topologyConstraint \[$root.f.freq.entry get\] \[$root.f.mag.scale get\]\"; SM2::positionConstraintList $list $mesh" -bg $color
    button $root.buttons.applyDismiss -text "Apply & Dismiss" -command "evaluate \"$mesh -topologyConstraint \[$root.f.freq.entry get\] \[$root.f.mag.scale get\]\"; SM2::positionConstraintList $list $mesh; destroy $root" -bg $color
    button $root.buttons.destroy -text "Destroy" -command "destroy $root" -bg $color
    pack $root.buttons.apply $root.buttons.applyDismiss  $root.buttons.destroy -side left -expand true -fill both -padx 20 -pady 10
    pack $root.buttons -expand true -fill both
    }
}


SM2::uninstallContourSM2Menu
Comments  
Arguments viewer
camera
object
Used by  
Uses contour::uninstallContourMenu
proc SM2::uninstallContourSM2Menu { viewer camera object } {
    contour::uninstallContourMenu $viewer $camera $object
}


SM2::uninstallSM2
Comments  
Arguments parent
camera
object
Used by  
Uses  
proc SM2::uninstallSM2 { parent camera object } {
    destroy $parent.context.object $parent.context.graphics $parent.context.forces $parent.context.topology $parent.context.ext
    destroy $parent.popup
    bind [$camera -widget]  <Button-3> ""
}