1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
# -*- tcl -*-
# Informal test for plotcontour
#
if {![package vsatisfies [package provide Tcl] 8.5]} {
puts " Aborting the tests found in \"[file tail [info script]]\"."
puts " Requiring Tcl 8.5, have [package present Tcl]"
return
}
# Future: put all tests under constraint tk and set constraint properly
if {[catch { package require Tk 8.5 } msg]} {
puts " Aborting the tests found in \"[file tail [info script]]\"."
puts " Requiring Tk 8.5, $msg"
return
}
::tcltest::testConstraint tk 1
# -------------------------------------------------------------------------
#
# Note:
# The tests assume tcltest 2.1, in order to compare
# floating-point results
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2.1
#package require tcltest 2.2
namespace import ::tcltest::*
} else {
# Ensure that 2.1 or higher present.
if {![package vsatisfies [package present tcltest] 2.1]} {
puts "Aborting tests for Plotchart"
puts "Requiring tcltest 2.1, have [package present tcltest]"
return
}
}
catch { console show }
source [file join [file dirname [info script]] plotchart.tcl]
#puts "Plotchart [package present Plotchart]"
#tcltest::configure -match Plotcontours-1.1
tcltest::test Plotcontours-1.0 {Informal test for plotcontour} {
########################################################################
proc cowboyhat {x y} {
set x1 [expr {$x/9.0}]
set y1 [expr {$y/9.0}]
expr { 3.0 * (1.0-($x1*$x1+$y1*$y1))*(1.0-($x1*$x1+$y1*$y1)) }
}
#
# Main code
#
set choice 1
if {$choice == 0} {
set x { {0.0 1.0 2.0 3.0}
{0.0 1.0 2.0 3.0}
{0.0 1.0 2.0 3.0}
{0.0 1.0 2.0 3.0} }
set y { {0.0 0.0 0.0 0.0}
{1.0 1.0 1.0 1.0}
{2.0 2.0 2.0 2.0}
{3.0 3.0 3.0 3.0} }
set f { {0.0 0.0 2.0 3.0}
{0.0 0.0 2.0 3.0}
{2.0 2.0 3.0 4.0}
{3.0 3.0 4.0 5.0} }
set contours [list 1.0 2.0 3.0 4.0 5.0 ]
# set contours [list 1.0 1.3 1.6 2.0 2.3 2.6 3.0 3.3 3.6 4.0 4.3 4.6 5.0 5.3 ]
set xlimits {0 3.5 0.5}
set ylimits {0 3.5 0.5}
}
if {$choice == 1} {
set x { {0.0 100.0 200.0}
{0.0 100.0 200.0}
{0.0 100.0 200.0}
{0.0 100.0 200.0}}
set y { {0.0 0.0 0.0}
{30.0 30.0 30.0}
{60.0 60.0 60.0}
{90.0 90.0 90.0}}
set f { {0.0 1.0 10.0}
{ 0.0 30.0 30.0}
{10.0 60.0 60.0}
{30.0 90.0 90.0}}
set contours [list \
0.0 \
5.2631578947 \
10.5263157895 \
15.7894736842 \
21.0526315789 \
26.3157894737 \
31.5789473684 \
36.8421052632 \
42.1052631579 \
47.3684210526 \
52.6315789474 \
57.8947368421 \
63.1578947368 \
68.4210526316 \
73.6842105263 \
78.9473684211 \
84.2105263158 \
89.4736842105 \
94.7368421053 \
100.0 \
105.263157895 \
]
set xlimits {0 200 50}
set ylimits {0 100 20}
}
########################################################################
wm title . "Contour Demo : shade (jet colormap)"
set c [canvas .c -background white \
-width 500 -height 500]
lappend windows $c
pack $c -fill both -side top
set chart [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap jet
#$chart contourlines $x $y $f $contours
$chart contourfill $x $y $f $contours
#$chart contourbox $x $y $f $contours
$chart grid $x $y
set t [toplevel .contourlines]
lappend windows $t
wm title $t "Contour Demo : contourlines (default colormap)"
set c [canvas $t.c -background white \
-width 500 -height 500]
pack $c -fill both -side top
set chart1 [::Plotchart::createXYPlot $c $xlimits $ylimits]
$chart1 grid $x $y
$chart1 contourlines $x $y $f $contours
set t [toplevel .hot]
lappend windows $t
wm title $t "Contour Demo : contourlines (hot colormap)"
set c [canvas $t.c -background white \
-width 500 -height 500]
pack $c -fill both -side top
set chart2 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap hot
$chart2 contourfill $x $y $f $contours
$chart2 grid $x $y
set t [toplevel .gray]
lappend windows $t
wm title $t "Contour Demo : gray contourfill , jet contourlines"
set c [canvas $t.c -background white \
-width 500 -height 500]
pack $c -fill both -side top
set chart3 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap gray
$chart3 contourfill $x $y $f $contours
::Plotchart::colorMap jet
$chart3 contourlines $x $y $f $contours
$chart3 grid $x $y
set t [toplevel .cool]
lappend windows $t
wm title $t "Contour Demo : contourlines (cool colormap)"
set c [canvas $t.c -background white \
-width 500 -height 500]
pack $c -fill both -side top
set chart4 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap cool
$chart4 contourfill $x $y $f $contours
$chart4 grid $x $y
set t [toplevel .defcont]
lappend windows $t
wm title $t "Contour Demo : default contours (jet colormap)"
set c [canvas $t.c -background white \
-width 500 -height 500]
pack $c -fill both -side top
set chart5 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap jet
$chart5 contourfill $x $y $f
$chart5 grid $x $y
set t [toplevel .3dcontour]
lappend windows $t
wm title $t "Contour Demo : contours on a 3DPlot"
set c [canvas $t.c -background white \
-width 500 -height 500]
pack $c -fill both -side top
set xlimits {-10. 10. 10. }
set ylimits {-10. 10. 10. }
set zlimits { -5. 10. 5. }
set zmin 0.0
set zmax 3.0
set nc 51
set dz [expr {($zmax - $zmin) / ($nc - 1)}]
set contours {}
for {set cnt 1} {$cnt < $nc} {incr cnt} {
set zval [expr {$zmin + ($dz * ($cnt - 1))}]
lappend contours $zval
}
set chart6 [::Plotchart::create3DPlot $c $xlimits $ylimits $zlimits]
::Plotchart::colorMap jet
$chart6 title "3D Plot"
$chart6 plotfuncont cowboyhat $contours
after 10000 {
foreach t $windows {
destroy $t
}
set vv 1
}
vwait vv
set v 1
} 1
tcltest::test Plotcontours-1.1 {Test of rosenbrock contours with given function values} {
proc rosenbrock {x} {
set x1 [lindex $x 0]
set x2 [lindex $x 1]
set y [expr {100.0 * pow($x2 - $x1*$x1,2) + pow(1.0 - $x1,2)}]
return $y
}
set xvec {-2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0}
set yvec {-1.0 -0.5 0.0 0.5 1.0 1.5 2.0}
set fmat {}
foreach y $yvec {
set frow {}
foreach x $xvec {
lappend frow [rosenbrock [list $x $y]]
}
lappend fmat $frow
}
set contours { \
0.0 5.0 10 20 30 40 \
50 100 200 500 1000 2000 3000 \
}
set xlimits {-2.0 2.0 2.0}
set ylimits {-1.0 2.0 1.0}
wm title . "Rosenbrock contours"
::Plotchart::colorMap jet
set c [canvas .c -background white -width 200 -height 200]
pack $c -fill both -side top
set chart1 [::Plotchart::createXYPlot $c $xlimits $ylimits]
$chart1 contourlinesfunctionvalues $xvec $yvec $fmat $contours
$chart1 title "Rosenbrock"
after 1000 {
destroy $c
set vv 1
}
vwait vv
set res 1
} 1
# -------------------------------------------------------------------------
::tcltest::cleanupTests
|