# Library functions for the scripting library (scrib)
#
# File: scrib/lib/quality.tcl
#
# $Revision$ on $Date$
# 
# Copyright (c) 1993-2003 ICEM CFD Engineering
#
#--------------------------------------------------------------------
#
# scrib_lib_quality_check2: checks the grid quality after meshing
#   --may have to be interactive
#
# --> if the name of the first proc already exists in interp, return
#
if {"" != [info commands scrib_lib_quality_check2]} { return }
#
# --> procs in this file depend on the following scrib/lib/ files--source them
#     I guess we could do this by proc, too, not sure waht's best
#
if {"" != [info commands scrib_lib_setup_source_files]} {
    set required_files "tetra utils"
    scrib_lib_setup_source_files $required_files
}

## needs doc.

proc scrib_lib_quality_check { } {    
    global proc_scrib_data

    set diagnostic_range {
	{"Max_Warpage" "QUAD_4" "Max warpgls"  4}
	{"Max_Quad_Aspect_Ratio" "QUAD_4" "Max ratio" 4} 
	{"Max_Tria_Aspect_Ratio" "TRI_3" "Max ratio" 4} 
	{"Min_Distortion" "QUAD_4" "Distortion" 3} 
	{"Min_Quad_Angle" "QUAD_4" "Min angle"  3} 
	{"Min_Tria_Angle" "TRI_3" "Min angle"  3} 
	{"Max_Quad_Angle" "QUAD_4" "Max angle"  4} 
	{"Max_Tria_Angle" "TRI_3" "Max angle"  4} 
	{"Custom_Quality" "QUAD_4 TRI_3" "Custom quality"  3} 
    }
    #{"Min_Skew" "QUAD_4" "Skew"  } 
    set fams [ic_uns_list_families]
    set text_line ""
    set result_line ""
    
    foreach item $diagnostic_range {
	#
	# parse it up
	#
	set diag [lindex $item 0]
	set type [lindex $item 1]
	set title [lindex $item 2]
	set locate [lindex $item 3]
	#set range_1 [lindex $item 3]
	#set range_2 [lindex $item 4]
	#scrib_lib_utils_report_message " diag is $diag, type is $type, title is $title, range_1 is $range_1, range_2 is $range_2\n"
	
	#
	#
	#
	set tmpmap [ic_uns_subset_create]
	ic_uns_subset_add_families_and_types $tmpmap $fams $type
	set worst_quality [lindex [ic_uns_metric $tmpmap $title] $locate]
	ic_uns_subset_delete $tmpmap	
	
	#set tmpmap2 [ic_uns_create_diagnostic_subset 0]
	#ic_uns_set_with_diagnostic $tmpmap2 $tmpmap [list $range_1 $range_2]

	#set list($diag) [ic_uns_subset_list_elements $tmpmap2]	
	#set num($diag) [llength $list($diag)]
	#ic_uns_subset_delete $tmpmap2
	
	#if {$range_1 == 0} {
	 #   scrib_lib_utils_report_message "number of cells with $diag below $range_2 are $num($diag)\n"
	#} else {
	 #   scrib_lib_utils_report_message "number of cells with $diag above $range_1 are $num($diag)\n"
	#}
	scrib_lib_utils_report_message "Worst element with $diag is $worst_quality\n"
	lappend text_line $diag 
	lappend result_line $worst_quality
    }
    scrib_lib_utils_report_message $text_line
    scrib_lib_utils_report_message $result_line
    #
    #
    #
    set tris [ic_count_elements TRI_3]
    set quads [ic_count_elements QUAD_4]
    scrib_lib_utils_report_message "number of tris: $tris; number of quads: $quads\n"
    
    set num_elements [expr $tris + $quads]
    mess "Number of total elements is $num_elements\n"
    
    set tri [expr $tris * 1.0000]
    set quad [expr $quads * 1.0000]    
    if {$quad != 0 } {
	set percent [expr ($tri / ($tri + $quad) ) * 100 ]
    } else { set percent 100.0 }    
    
    set text_line [concat $text_line %tris \#tris \#quads ]
    set result_line [concat $result_line $percent $tris $quads]
    
    set quality [pwd]/quality.txt
    if ![file exists quality.txt] {
	set q [open $quality "w"]
	set text_line [concat PartName $text_line]
	puts $q $text_line	
    } else {
	set q [open $quality "a"]	
    }
    set result_line [concat $proc_scrib_data(name) $result_line]
    puts $q $result_line
    close $q
    
    
    scrib_lib_utils_report_message $text_line
    scrib_lib_utils_report_message $result_line
    #
    # return the number of elements
    #
    return $num_elements
}

## needs doc. this proc has problems.

proc scrib_lib_quality_check2 { diagnostic_range } {
    
    set fams [ic_uns_list_families "" 0]
    foreach item $diagnostic_range {
	
	set diag [lindex $item 0]
	set type [lindex $item 1]
	set title [lindex $item 2]
	set range_1 [lindex $item 3]
	set range_2 [lindex $item 4]
	
	scrib_lib_utils_report_message " diag is $diag, type is $type, title is $title, range_1 is $range_1, range_2 is $range_2\n"
	#
	set tmpmap [ic_uns_create_diagnostic_subset 0]
	ic_uns_subset_add_families_and_types $tmpmap $fams $type
	ic_uns_metric $tmpmap $title
	
	set tmpmap2 [ic_uns_create_diagnostic_subset 0]
	ic_uns_set_with_diagnostic $tmpmap2 $tmpmap [list $range_1 $range_2]
	ic_uns_subset_delete $tmpmap
	
	set list($diag) [ic_uns_subset_list_elements $tmpmap2]	
	ic_uns_subset_delete $tmpmap2
	set num($diag) [llength $list($diag)]
	
	if {$range_1 == 0} {
	    scrib_lib_utils_report_message "number of cells with $diag below $range_2 are $num($diag)\n"
	} else {
	    scrib_lib_utils_report_message "number of cells with $diag above $range_1 are $num($diag)\n"
	}
    }
    #
    set tris [ic_count_elements TRI_3]
    set quads [ic_count_elements QUAD_4]
    scrib_lib_utils_report_message "number of tris: $tris; number of quads: $quads\n"
    set num_elements [expr $tris + $quads]
    if {$quads != 0 } {
	set tris [expr $tris * 1.0000]
	set quads [expr $quads * 1.0000]
	set percent [expr ($tris / $quads) * 100 ]
    } else {
	set percent 100.0
    }
    scrib_lib_utils_report_message "Percent of tris/quads is $percent\n"
    #
    # return the number of elements
    #    
    return $num_elements
}

proc scrib_lib_quality_surface_mesh_custom_standard_old {} {
    
    
    set tmpmap [ic_uns_create_diagnostic_subset 0]    
    ic_uns_subset_add_families_and_types $tmpmap [ic_uns_list_families] {TRI_3 QUAD_4}
    
    ic_uns_set_metric_weights { \
	    {Angle      QUAD_4 acc_min 30  des_min 45  ideal 90 des_max 135 acc_max 150} \
	    {Angle       TRI_3 acc_min 10  des_min 30  ideal 60 des_max 120 acc_max 140} \
	    {Distortion QUAD_4 acc_min 0.4 des_min 0.7 ideal  1 des_max  1  acc_max  1 } \
	    {Distortion  TRI_3 acc_min -1  des_min -1  ideal -1 des_max -1  acc_max -1 } \
	    {{Aspect ratio} QUAD_4 acc_min 0.1 des_min 0.3 ideal 1 des_max 1 acc_max 1} \
	    {{Aspect ratio}  TRI_3 acc_min 0.1 des_min 0.3 ideal 1 des_max 1 acc_max 1} \
	    {{Max warp} QUAD_4 acc_min  0 des_min  0 ideal  0 des_max 10 acc_max 30} \
	    {{Max warp}  TRI_3 acc_min -1 des_min -1 ideal -1 des_max -1 acc_max -1} \
	    {Skew QUAD_4 acc_min 0 des_min 0 ideal 0 des_max 45 acc_max 60} \
	    {Skew  TRI_3 acc_min 0 des_min 0 ideal 0 des_max 45 acc_max 60}} 1
    ic_uns_metric $tmpmap {Custom quality}
    
    set tmpmap2 [ic_uns_subset_create]
    ic_uns_set_with_diagnostic $tmpmap2 $tmpmap {{-1000 0.6}}
    
    # what's happening to these subsets?? fixme xxx --jka
}

proc scrib_lib_quality_surface_mesh_custom_standard {} {
    
    
    set tmpmap [ic_uns_create_diagnostic_subset 0]    
    ic_uns_subset_add_families_and_types $tmpmap [ic_uns_list_families] {TRI_3 QUAD_4}
    
    ic_uns_set_metric_weights 	[scrib_lib_quality_standard_weights {Custom quality}] 1
    ic_uns_metric $tmpmap {Custom quality}
    
    set tmpmap2 [ic_uns_subset_create]
    ic_uns_set_with_diagnostic $tmpmap2 $tmpmap {{-1000 0.6}}
    
    # what's happening to these subsets?? fixme xxx --jka
}

## if a mesh is loaded show the custom quality results.

proc scrib_lib_quality_show {} {
    global custom_metric  
     
    if { ![ic_uns_is_loaded] } { return }
    
    if [ic_uns_subset_exists visible] {	    
	
	ic_uns_update_family_type visible [ic_uns_list_families] [ic_uns_list_types] update 1
	
	set quality_metric {Custom quality}
	mess "\nHighlighting elements by \"$quality_metric\" in visible mesh...\n"

	set weights [scrib_lib_quality_standard_weights $quality_metric]
#mess "weights are $weights\n"
	set custom_metric_keys [list 	angle distortion aspect warpage skew minside ]
	foreach k $custom_metric_keys {
	    set custom_metric($k,active) 1 ; #this turns on this check
	    foreach t {quad tri} {
		foreach v {acc_min des_min id des_max acc_max} {
		    foreach w $weights {
			set OK 0
			switch $k {
			    angle {if {[lsearch $w Angle] != -1} {set OK 1}}
			    distortion {if {[lsearch $w Distortion] != -1} {set OK 1}}
			    aspect {if {[lsearch $w "Aspect Ratio"] != -1} {set OK 1}}
			    warpage {if {[lsearch $w "Max warp"] != -1} {set OK 1}}
			    skew {if {[lsearch $w "Skew"] != -1} {set OK 1}}
			    minside {if {[lsearch $w "Min side"] != -1} {set OK 1}}
			}
			if $OK { 
			    switch $t {
				tri {
					if {[lsearch $w TRI_3] != -1} {
					    set place [lsearch $w $v]
					    set custom_metric($k,$t,$v) [lindex $w [expr $place + 1]]
					}
				     }
				quad {
					if {[lsearch $w QUAD_4] != -1} {
					    set place [lsearch $w $v]
					    set custom_metric($k,$t,$v) [lindex $w [expr $place + 1]]
					}
				     }
			    }
			}
		    }
		}
	    }
	}
#Need to tell DEZ that min edge values should not be overridden
#	qualityMetricsDEZ set have_set_defaults 1

	ic_uns_set_metric_weights $weights 1
	set stat [ic_uns_metric visible $quality_metric]
	set nok  [lindex $stat 0]
	if {[string is integer $nok] && ($nok > 0)} {
	    global aie_meshDisplay disp_options
	    set args [list -shade flat_wire -shrink 100 -only_edges 0 -single_surfaces 0 \
		-multiple_surfaces 0 -draw_normals 0 -draw_normals_colored 0 -draw_midside_nodes 1 \
		-draw_icons 0 -draw_couplings 0 -draw_icons_normals_vol 0 -draw_enums 0 \
		-draw_thickness 0 -draw_orientation 0 -draw_vol_bounds 0 -draw_surf_bounds 0 \
		-shrink_npos 0 -draw_periodicity 0 -draw_no_inner 0 -draw_changes 0 -color_by_quality 1 \
		-locked_elements 0 -width 0 -draw_bcfield ""]
	    foreach {u v} $args {
		ic_uns_subset_configure visible $u $v
		set aie_meshDisplay([string range $u 1 end]) $v
#mess "set aie_meshDisplay([string range $u 1 end]) $v \n"
	    }
#	    ic_uns_subset_configure "" -color_by_quality 1
	    ic_uns_print_diagnostic_quality_key $quality_metric
	}
	#display_update
    }
    
    # don't show the single edges anymore --jka
    if 0 { scrib_lib_quality_show_single }
}



## delete all problems of <em>type</em> from a the current mesh.
## <em>type</em> can be one of: xxxxxxxxxx
## <em>verbose</em> is just a verbose description of type for text.

proc scrib_lib_quality_diagnostic_type_delete {type {subset all} {verbose ""}} {
    
    if {"" == $verbose} { set verbose "$type elements" }
    
    if ![ic_uns_is_loaded] {
	mess "must have mesh loaded to delete $verbose!\n" red
	return
    }
    if {"" == $subset} {
	set subset all
    } elseif ![ic_uns_subset_exists $subset] {
	mess "cannot find subset $subset to delete $type elements...checking all\n" red
	set subset all
    }
    
    set map [ic_uns_subset_create]
    catch {ic_uns_diagnostic subset $subset diag_type $type disp_subset $map \
	    diag_verb $verbose} ret
    
    catch {lindex $ret 0} nprobs
    
    set conts [ic_uns_subset_count_elements $map]
    if {0 < $conts} {
	mess "deleting $conts $verbose from the mesh!\n"
	ic_uns_delete_contents $map
    }
    ic_uns_subset_delete $map
}

## delete all disconnected bars from a the current mesh xxx details

proc scrib_lib_quality_disconnected_bars_delete {} {
    scrib_lib_quality_diagnostic_type_delete disconnbars all "disconnected bars"
}

## delete all hanging bars from a the current mesh xxx details

proc scrib_lib_quality_hanging_bars_delete {} {
    set tmpmap [ic_uns_subset_create [ic_uns_subset_unused_name hanging_bars_check]]
    ic_uns_subset_add_families_and_types $tmpmap [ic_uns_list_families] {BAR_2 BAR_3 LINE_2}
    scrib_lib_quality_diagnostic_type_delete hanging $tmpmap "hanging bars"
    ic_uns_subset_delete $tmpmap
}

## delete all hanging bars from a the current mesh xxx details

proc scrib_lib_quality_duplicate_elements_delete {} {
    scrib_lib_quality_diagnostic_type_delete duplicate all "duplicate elements"
}
  
## delete all single-multiple edges from a the current mesh xxx details

proc scrib_lib_quality_single_multiple_delete {} {
    scrib_lib_quality_diagnostic_type_delete single_multiple all "single-multiple edges"
    return
    
    # This is what I had found in quad.tcl:scrib_lib_quad_clean
    #ic_uns_subset_create single_multiple
    #ic_uns_diagnostic subset all diag_type single_multiple \
	    #    fix_fam FIX_single_multiple \
	    #    disp_subset single_multiple \
	    #    diag_verb {Single-Multiple edges} fams {}
    # if [llength [ic_uns_subset_list_elements single_multiple]] {
	#ic_uns_subset_create single_2
	#ic_uns_diagnostic subset single_multiple diag_type single_2 fix_fam FIX_single_2 \
		#	disp_subset single_2 diag_verb {2-Single edges} fams {}
	#ic_uns_delete_contents single_2
	#ic_uns_subset_delete single_2
    # }
} 

## needs doc.

proc scrib_lib_quality_standard_weights_custom {} {
    global proc_scrib_data

#-----  Quad Angle
    if ![info exists proc_scrib_data(Q_A_Q4_amin)] {
	set proc_scrib_data(Q_A_Q4_amin) 30
    }
    set Q_A_Q4_amin $proc_scrib_data(Q_A_Q4_amin)

    if ![info exists proc_scrib_data(Q_A_Q4_min)] {
	set proc_scrib_data(Q_A_Q4_min) 45
    }
    set Q_A_Q4_min $proc_scrib_data(Q_A_Q4_min)
    
    if ![info exists proc_scrib_data(Q_A_Q4_ideal)] {
	set proc_scrib_data(Q_A_Q4_ideal) 90
    }
    set Q_A_Q4_ideal $proc_scrib_data(Q_A_Q4_ideal)

    if ![info exists proc_scrib_data(Q_A_Q4_max)] {
	set proc_scrib_data(Q_A_Q4_max) 135
    }
    set Q_A_Q4_max $proc_scrib_data(Q_A_Q4_max)

    if ![info exists proc_scrib_data(Q_A_Q4_amax)] {
	set proc_scrib_data(Q_A_Q4_amax) 150
    }
    set Q_A_Q4_amax $proc_scrib_data(Q_A_Q4_amax)

#----------- Tri Angle
    if ![info exists proc_scrib_data(Q_A_T3_amin)] {
	set proc_scrib_data(Q_A_T3_amin) 10
    }
    set Q_A_T3_amin $proc_scrib_data(Q_A_T3_amin)

    if ![info exists proc_scrib_data(Q_A_T3_min)] {
	set proc_scrib_data(Q_A_T3_min) 20
    }
    set Q_A_T3_min $proc_scrib_data(Q_A_T3_min)

    if ![info exists proc_scrib_data(Q_A_T3_ideal)] {
	set proc_scrib_data(Q_A_T3_ideal) 60
    }
    set Q_A_T3_ideal $proc_scrib_data(Q_A_T3_ideal)

    if ![info exists proc_scrib_data(Q_A_T3_max)] {
	set proc_scrib_data(Q_A_T3_max) 120
    }
    set Q_A_T3_max $proc_scrib_data(Q_A_T3_max)

   if ![info exists proc_scrib_data(Q_A_T3_amax)] {
	set proc_scrib_data(Q_A_T3_amax) 130
    }
    set Q_A_T3_amax $proc_scrib_data(Q_A_T3_amax)

#------------ Determinant
    if ![info exists proc_scrib_data(Q_D_Q4_amin)] {
	set proc_scrib_data(Q_D_Q4_amin) .5
    }
    set Q_D_Q4_amin $proc_scrib_data(Q_D_Q4_amin)

    if ![info exists proc_scrib_data(Q_D_Q4_min)] {
	set proc_scrib_data(Q_D_Q4_min) .7
    }
    set Q_D_Q4_min $proc_scrib_data(Q_D_Q4_min)

    if ![info exists proc_scrib_data(Q_D_Q4_ideal)] {
	set proc_scrib_data(Q_D_Q4_ideal) 1
    }
    set Q_D_Q4_ideal $proc_scrib_data(Q_D_Q4_ideal)

    if ![info exists proc_scrib_data(Q_D_Q4_max)] {
	set proc_scrib_data(Q_D_Q4_max) 1
    }
    set Q_D_Q4_max $proc_scrib_data(Q_D_Q4_max)

#------------- Quad Aspect Ratio
    if ![info exists proc_scrib_data(Q_AR_Q4_amin)] {
	set proc_scrib_data(Q_AR_Q4_amin) .2
    }
    set Q_AR_Q4_amin $proc_scrib_data(Q_AR_Q4_amin)

    if ![info exists proc_scrib_data(Q_AR_Q4_min)] {
	set proc_scrib_data(Q_AR_Q4_min) .3
    }
    set Q_AR_Q4_min $proc_scrib_data(Q_AR_Q4_min)

    if ![info exists proc_scrib_data(Q_AR_Q4_ideal)] {
	set proc_scrib_data(Q_AR_Q4_ideal) 1
    }
    set Q_AR_Q4_ideal $proc_scrib_data(Q_AR_Q4_ideal)

    if ![info exists proc_scrib_data(Q_AR_Q4_max)] {
	set proc_scrib_data(Q_AR_Q4_max) 1
    }
    set Q_AR_Q4_max $proc_scrib_data(Q_AR_T3_min)

#------------- Tri Aspect Ratio
    if ![info exists proc_scrib_data(Q_AR_T3_amin)] {
	set proc_scrib_data(Q_AR_T3_amin) .1
    }
    set Q_AR_T3_amin $proc_scrib_data(Q_AR_T3_amin)

    if ![info exists proc_scrib_data(Q_AR_T3_min)] {
	set proc_scrib_data(Q_AR_T3_min) .2
    }
    set Q_AR_T3_min $proc_scrib_data(Q_AR_T3_min)

    if ![info exists proc_scrib_data(Q_AR_T3_ideal)] {
	set proc_scrib_data(Q_AR_T3_ideal) 1
    }
    set Q_AR_T3_ideal $proc_scrib_data(Q_AR_T3_ideal)

    if ![info exists proc_scrib_data(Q_AR_T3_max)] {
	set proc_scrib_data(Q_AR_T3_max) 1
    }
    set Q_AR_T3_max $proc_scrib_data(Q_AR_T3_max)

#----------------- Warpage
    if ![info exists proc_scrib_data(Q_W_Q4_max)] {
	set proc_scrib_data(Q_W_Q4_max) 8
    }
    set Q_W_Q4_max $proc_scrib_data(Q_W_Q4_max)

    if ![info exists proc_scrib_data(Q_W_Q4_amax)] {
	set proc_scrib_data(Q_W_Q4_amax) 15
    }
    set Q_W_Q4_amax $proc_scrib_data(Q_W_Q4_amax)

#------------------ Quad Skew
     if ![info exists proc_scrib_data(Q_S_Q4_max)] {
	set proc_scrib_data(Q_S_Q4_max) 45
    }
    set Q_S_Q4_max $proc_scrib_data(Q_S_Q4_max)

    if ![info exists proc_scrib_data(Q_S_Q4_amax)] {
	set proc_scrib_data(Q_S_Q4_amax) 60
    }
    set Q_S_Q4_amax $proc_scrib_data(Q_S_Q4_amax)

#------------------ Tri Skew
    if ![info exists proc_scrib_data(Q_S_T3_max)] {
	set proc_scrib_data(Q_S_T3_max) 45
    }
    set Q_S_T3_max $proc_scrib_data(Q_S_T3_max)

    if ![info exists proc_scrib_data(Q_S_T3_amax)] {
	set proc_scrib_data(Q_S_T3_amax) 60
    }
    set Q_S_T3_amax $proc_scrib_data(Q_S_T3_amax)

#-----  Quad Min Edge
    if ![info exists proc_scrib_data(Q_ME_Q4_amin)] {
	set proc_scrib_data(Q_ME_Q4_amin) 3
    }
    set Q_ME_Q4_amin $proc_scrib_data(Q_ME_Q4_amin)

    if ![info exists proc_scrib_data(Q_ME_Q4_min)] {
	set proc_scrib_data(Q_ME_Q4_min) 5
    }
    set Q_ME_Q4_min $proc_scrib_data(Q_ME_Q4_min)

    if ![info exists proc_scrib_data(Q_ME_Q4_max)] {
	set proc_scrib_data(Q_ME_Q4_max) 25
    } 
    set Q_ME_Q4_max $proc_scrib_data(Q_ME_Q4_max)
   
    if {[info exists proc_scrib_data(Q_ME_Q4_min)] && [info exists proc_scrib_data(Q_ME_Q4_max)] } {
	set proc_scrib_data(Q_ME_Q4_ideal) [expr [expr $proc_scrib_data(Q_ME_Q4_min) + $proc_scrib_data(Q_ME_Q4_max) ] / 2 ]
    } else {
	set  proc_scrib_data(Q_ME_Q4_ideal)l 15
    }
    set Q_ME_Q4_ideal $proc_scrib_data(Q_ME_Q4_ideal)

    if ![info exists proc_scrib_data(Q_ME_Q4_amax)] {
	set proc_scrib_data(Q_ME_Q4_amax) 30
    }
    set Q_ME_Q4_amax $proc_scrib_data(Q_ME_Q4_amax)

#----------- Min Tri Edge
#Should probably seperate min edge for tri and quad at some  point, but now just using Quad values.

    
    mess " * \n ** \n ***\n **** \n ***** \n " green
    mess " smoothing by custom quality \n " green
    #mess "Angle QUAD_4 min $proc_scrib_data(Q_A_Q4_min) ideal $proc_scrib_data(Q_A_Q4_ideal) max $proc_scrib_data(Q_A_Q4_max) \n" blue
    #mess "Angle TRI_3 min $proc_scrib_data(Q_A_T3_min) ideal $proc_scrib_data(Q_A_T3_ideal) max $proc_scrib_data(Q_A_T3_max) \n" blue
    #mess "Distortion QUAD_4 min $proc_scrib_data(Q_D_Q4_min) ideal $proc_scrib_data(Q_D_Q4_ideal) max $proc_scrib_data(Q_D_Q4_max) \n" blue
    #mess "Distortion TRI_3 min -1 ideal -1 max -1 \n" blue
    #mess "Aspect ratio QUAD_4 min $proc_scrib_data(Q_AR_Q4_min) ideal $proc_scrib_data(Q_AR_Q4_ideal) max $proc_scrib_data(Q_AR_Q4_max) \n" blue
    #mess "Aspect ratio TRI_3 min $proc_scrib_data(Q_AR_T3_min) ideal $proc_scrib_data(Q_AR_T3_ideal) max $proc_scrib_data(Q_AR_T3_max) \n" blue
    #mess "Max warp QUAD_4 min 0 ideal 0 max $proc_scrib_data(Q_W_Q4_max) \n" blue
    #mess "Max warp TRI_3 min -1 ideal -1 max -1 \n" blue
    #mess "Skew QUAD_4 min 0 ideal 0 max $proc_scrib_data(Q_S_Q4_max) \n" blue
    #mess "Skew TRI_3 min 0 ideal 0 max $proc_scrib_data(Q_S_T3_max) \n" blue
    
    return [list \
	[list Angle QUAD_4 acc_min  $Q_A_Q4_amin des_min  $Q_A_Q4_min ideal  $Q_A_Q4_ideal des_max  $Q_A_Q4_max acc_max $Q_A_Q4_amax] \
	[list Angle TRI_3 acc_min $Q_A_T3_amin des_min  $Q_A_T3_min ideal  $Q_A_T3_ideal des_max  $Q_A_T3_max acc_max $Q_A_T3_amax] \
	[list Distortion QUAD_4 acc_min $Q_D_Q4_amin des_min  $Q_D_Q4_min ideal 1 des_max 1 acc_max 1] \
	[list Distortion  TRI_3 acc_min -1 des_min -1  ideal -1 des_max -1 acc_max -1] \
	[list {Aspect ratio} QUAD_4 acc_min $Q_AR_Q4_amin des_min $Q_AR_Q4_min ideal 1 des_max 1 acc_max 1] \
	[list {Aspect ratio}  TRI_3 acc_min $Q_AR_T3_amin des_min $Q_AR_T3_min ideal 1 des_max 1 acc_max 1] \
	[list {Max warp} QUAD_4 acc_min 0 des_min 0 ideal 0 des_max  $Q_W_Q4_max acc_max  $Q_W_Q4_amax] \
	[list {Max warp} TRI_3 acc_min -1 des_min -1 ideal -1 des_max -1 acc_max -1] \
	[list Skew QUAD_4 acc_min 0 des_min 0 ideal  0 des_max $Q_S_Q4_max acc_max $Q_S_Q4_amax] \
	[list Skew TRI_3 acc_min 0 des_min 0 ideal 0 des_max $Q_S_T3_max acc_max $Q_S_T3_amax] \
	[list {Min side} QUAD_4 acc_min  $Q_ME_Q4_amin des_min  $Q_ME_Q4_min ideal  $Q_ME_Q4_ideal des_max  $Q_ME_Q4_max acc_max $Q_ME_Q4_amax] \
	[list {Min side} TRI_3 acc_min  $Q_ME_Q4_amin des_min  $Q_ME_Q4_min ideal  $Q_ME_Q4_ideal des_max  $Q_ME_Q4_max acc_max $Q_ME_Q4_amax] \
    ]
}

## needs doc.

proc scrib_lib_quality_standard_weights {metric} {
    switch -- $metric {
	"Custom quality" {
	    return [scrib_lib_quality_standard_weights_custom]
	}
	default {
	    mess "cannot get standard quality metric weights for $metric...\n" red
	}
    }
    return ""
}














