# # demo for bighead data set, fixed classification, grayscale # set demo_menu_name "256^3 CT Head, Grayscale" set demo_label_name "CT Head (256 x 256 x 225)" #set demo_first 1 # load the volume and set parameters for rendering # ARG1: if true, load $directory/bighead.den, classify it, # and store in $directory/bighead.cv; # no value is returned # if false, try to load $directory/bighead.cv; if that fails # then load $directory/bighead.den and classify it; # in either case, return a context containing the # classified volume # ARG2: directory containing the volume data file bighead.cv (default: ".") # ARG3: frame for adding widgets specific to this demo # ARG4: font # RETURN: context or {} depending on ARG1 proc demo_load {reclassify {directory "."} {demoframe {}} \ {font "*-helvetica-medium-r-normal--14-100-*"}} { # get the classified volume if {$reclassify || ![file exists $directory/bighead.cv]} { # load .den file set data [vpr_array #auto] vpr_load_den $data $directory/bighead.den # create a rendering context and attach the volume data to it set context [vpr_byte_context #auto] $context config -data $data -source data # set the classification function $context config -min_voxel_opacity 0.05 $context config -scalar_opacity_ramp { 0 0.0 95 0.0 135 1.0 255 1.0 } $context config -grad_opacity_ramp { 0 0.0 70 1.0 221 1.0 } # classify the volume $context classify # clean up $context config -data {} $data delete if {$reclassify} { # store the classified volume and return $context store $directory/bighead.cv cvolume $context delete return } } else { # load classified volume from a file set context [vpr_byte_context #auto] $context load $directory/bighead.cv cvolume } $context config -status_messages 0 -clamp 1 # set lighting parameters $context set_light 0 direction -0.3 0.5 1.0 $context config -light0 on $context config -light_both_sides on # set material parameters set ambient 0.118 set diffuse 0.392 set specular 0.510 $context set_material 0 ambient both_sides $ambient $context set_material 0 diffuse both_sides $diffuse $context set_material 0 specular both_sides $specular $context set_material 0 shinyness both_sides 10 $context config -description "$ambient $diffuse $specular" # set depth cueing options $context config -depth_cue_front_factor 1.0 -depth_cue_density 1.3 $context config -depth_cue on # set shadow options, but leave shadows disabled $context config -shadow_light light0 $context config -shadow_bias 8 $context config -shadow off # set the initial view parameters $context scale 1 -1 1 $context rotate x 90 $context rotate y 15 $context rotate x 15 $context config -view_model GL $context config -projection parallel $context config -frustum_left -0.5 -frustum_right 0.5 $context config -frustum_bottom -0.5 -frustum_top 0.5 $context config -frustum_near -0.5 -frustum_far 0.5 $context config -current_matrix project $context identity_matrix $context window $context config -current_matrix model # set other rendering parameters $context config -max_ray_opacity 0.95 $context config -render_from cvolume # allocate an image set image [vpr_array #auto] $image resize -dimens {256 256} -type unsigned_1 $context config -pixel_type luminance -color_channels 1 -image $image if {$demoframe != {}} { # create brightness slider frame $demoframe.brightness -borderwidth 2 -relief sunken pack $demoframe.brightness -side top -fill x -in $demoframe.widgets vpr_slider $demoframe.brightness.s -minval 0.5 -maxval 1.5 \ -command "bighead_brightness $context $demoframe" \ -display_value 0 $demoframe.brightness.s set_value 1.0 pack $demoframe.brightness.s -side top -expand true -fill x frame $demoframe.brightness.f pack $demoframe.brightness.f -side top -expand true -fill x label $demoframe.brightness.l1 -text "darker" -font $font label $demoframe.brightness.l2 -text "lighter" -font $font pack $demoframe.brightness.l1 -side left -in $demoframe.brightness.f pack $demoframe.brightness.l2 -side right -in $demoframe.brightness.f proc bighead_brightness {context demo_widget brightness} { set params [$context info public description -value] set ambient [lindex $params 0] set diffuse [lindex $params 1] set specular [lindex $params 2] $context set_material 0 ambient both_sides \ [expr $ambient*$brightness] $context set_material 0 diffuse both_sides \ [expr $diffuse*$brightness] $context set_material 0 specular both_sides \ [expr $specular*$brightness] $demo_widget render } } return $context } # clean up memory and widgets associated with the demo # ARG1: rendering context # ARG2: frame containing widgets specific to this demo # RETURN: none proc demo_cleanup {context {demoframe {}}} { set image [$context info public image -value] $image delete $context delete if {$demoframe != {}} { $demoframe.brightness.s delete destroy $demoframe.brightness } }