Ignore:
Timestamp:
Feb 8, 2013 2:20:22 PM (11 years ago)
Author:
gah
Message:

make placeholder for isosurface viewer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Rappture 1.2/gui/scripts/mesh.tcl

    r3271 r3288  
    6565    private common _xp2obj       ;      # used for fetch/release ref counting
    6666    private common _obj2ref      ;      # used for fetch/release ref counting
    67 
     67    private variable _isValid 0
    6868    private variable _vtkoutput ""
    6969    private variable _vtkreader ""
     
    7777    private variable _yValues   "";     # For the blt contour only
    7878   
     79    private method GetDimension {}
     80    private method GetDouble { path }
     81    private method GetInt { path }
     82    private method ReadBltCloudMesh { path }
     83    private method ReadBltGridMesh { path }
     84    private method ReadBltMesh { path }
     85    private method ReadBltTriangleMesh { path }
     86    private method ReadCells { xmlobj path }
    7987    private method ReadCloud { xmlobj path }
    8088    private method ReadGrid { xmlobj path }
    8189    private method ReadTriangles { xmlobj path }
    8290    private method ReadVtk { xmlobj path }
    83     private method GetBltCloudMesh { path }
    84     private method GetBltGridMesh { path }
    85     private method GetBltTriangleMesh { path }
    86     private method GetBltMesh { path }
    87     private method GetDouble { path }
    88     private method GetInt { path }
    89     private method GetDimension {}
    9091    private method _buildNodesElements {xmlobj path}
    9192}
     
    171172    # <element> +  <node> definitions
    172173    # <cloud>           x,y coordinates or x,y,z coordinates
    173     # <unirect>         uniform rectangular grid (2D) or cubes (3D)
    174     # <rectangle>       non-uniform rectangular mesh
     174    # <grid>            rectangular mesh
     175    # <triangles>       triangular mesh
     176    # <cells>           homogeneous cell type mesh.
     177
     178    # Check that only one mesh type was defined.
     179    set subcount 0
     180    foreach cname [$_mesh children] {
     181        foreach type { vtk cloud grid triangles cells } {
     182            if { [$_mesh element $type] != "" } {
     183                incr subcount
     184                break
     185            }
     186        }
     187    }
     188    set elemcount 0
     189    foreach cname [$_mesh children] {
     190        foreach type { node element } {
     191            if { [$_mesh element $type] != "" } {
     192                incr elemcount
     193                break
     194            }
     195        }
     196    }
     197    if { $elemcount > 0 } {
     198        incr $subcount
     199    }
     200    if { $subcount > 1 } {
     201        puts stderr "too many mesh types specified: picking first found."
     202    }
    175203    if { [$_mesh element vtk] != ""} {
    176204        ReadVtk $xmlobj $path
     
    181209    } elseif {[$_mesh element triangles] != "" } {
    182210        ReadTriangles $xmlobj $path
     211    } elseif {[$_mesh element cells] != "" } {
     212        ReadCells $xmlobj $path
    183213    } elseif {[$_mesh element node] != "" && [$_mesh element element] != ""} {
    184214        ReadNodesElements $xmlobj $path
    185     } else {
    186         error "can't find mesh data in $path"
    187215    }
    188216}
     
    296324        "blt" {
    297325            if { $_bltmesh == "" } {
    298                 GetBltMesh
     326                ReadBltMesh
    299327                return $_bltmesh
    300328            }
     
    558586        set _vtkdata $out
    559587        foreach axis {x y z} {
    560         set vector [set ${axis}v]
     588            set vector [set ${axis}v]
    561589            set _limits(${axis}min) [${vector} min]
    562590            set _limits(${axis}max) [${vector} max]
     
    587615    set _vtkpoints [$_vtkoutput GetPointData]
    588616    file delete $tmpfile
     617    set _isValid 1
    589618}
    590619
     
    614643    }
    615644    if { $numNonUniform == 0 && $numUniform > 0 } {
    616         # Specially handle the case where all axes are uniform.
    617         # This means we can use a vtkImageData to represent the data
    618         # instead of a vtkRectlinearGrid.
    619         # Vtk points are always 3D     
     645        # Specially handle the case where all axes are uniform.  This means we
     646        # can use a vtkImageData to represent the data instead of a
     647        # vtkRectlinearGrid.  Vtk points are always 3D
    620648        if { $_dim == 2 } {
    621649            append out "DATASET STRUCTURED_POINTS\n"
     
    650678            error "bad dimension of mesh \"$_dim\""
    651679        }
     680        set _isValid 1
    652681        return 1
    653682    }
     
    729758    }
    730759    blt::vector destroy $xv $yv $zv
     760    set _isValid 1
    731761    return 1
     762}
     763
     764itcl::body Rappture::Mesh::ReadCells { xmlobj path } {
     765    set _type "cells"
     766    set celltype [$xmlobj get $path.cells.celltype]
     767    array set type2vertices {
     768        triangle 3
     769        quad     4
     770        tetraheadron 4
     771        voxel 8
     772        hexaheadron 8
     773        wedge 6
     774        pyramid 5
     775    }
     776    array set type2dim {
     777        triangle 2
     778        quad     2
     779        tetraheadron 3
     780        voxel 3
     781        hexaheadron 3
     782        wedge 3
     783        pyramid 3
     784    }
     785    array set type2vtkid {
     786        triangle 5
     787        quad     9
     788        tetraheadron 10
     789        voxel 11
     790        hexaheadron 12
     791        wedge 13
     792        pyramid 14
     793    }
     794    if { ![info exists type2vertices($celltype)] } {
     795        puts stderr "unknown celltype \"$celltype\""
     796        return 0
     797    }
     798    set numVertices $type2vertices($celltype)
     799    set _dim $type2dim($celltype)
     800    set vtkid $type2vtkid($celltype)
     801   
     802    set points [$xmlobj get $path.cells.points]
     803    set xvalues [$xmlobj get $path.cells.xvalues]
     804    set yvalues [$xmlobj get $path.cells.yvalues]
     805    if { $_dim == 2 } {
     806        if { $xvalues != "" && $yvalues != "" } {
     807            set xv [blt::vector create \#auto]
     808            set yv [blt::vector create \#auto]
     809            $xv set $xvalues
     810            $yx set $yvalues
     811        } elseif { $points != "" } {
     812            set all [blt::vector create \#auto]
     813            $all set $points
     814            set xv [blt::vector create \#auto]
     815            set yv [blt::vector create \#auto]
     816            $all split $xv $yv
     817        } else {
     818            puts stderr "missing either xvalues, yvalues, or points for $celltype cell mesh"
     819            return 0
     820        }
     821        set _numPoints [$xv length]
     822        set numIndices 0
     823        set data {}
     824        set indices [$xmlobj get $path.cells.indices]
     825        foreach { a b c } $indices {
     826            append data "    $numVertices $a $b $c\n"
     827            incr numIndices
     828        }
     829        set celltypes {}
     830        for { set i 0 } { $i < $numIndices } { incr i } {
     831            append celltypes "$vtkid\n"
     832        }
     833        append out "DATASET UNSTRUCTURED_GRID\n"
     834        append out "POINTS $_numPoints float\n"
     835        foreach x [$xv range 0 end] y [$yv range 0 end] {
     836            append out "    $x $y 0\n"
     837        }
     838        append out "CELLS $numIndices [expr $numIndices * 4]\n"
     839        append out $data
     840        append out "CELL_TYPES $numIndices\n"
     841        append out $celltypes
     842        append out "POINT_DATA $_numPoints\n"
     843        set _limits(xmin) [$xv min]
     844        set _limits(xmax) [$xv max]
     845        set _limits(ymin) [$yv min]
     846        set _limits(ymax) [$yv max]
     847    } else {
     848        set zvalues [$xmlobj get $path.cells.zvalues]
     849        if { $xvalues != "" && $yvalues != ""  && $zvalues != "" } {
     850            set xv [blt::vector create \#auto]
     851            set yv [blt::vector create \#auto]
     852            set zv [blt::vector create \#auto]
     853            $xv set $xvalues
     854            $yx set $yvalues
     855            $zx set $yvalues
     856        } elseif { $points != "" } {
     857            set all [blt::vector create \#auto]
     858            $all set $points
     859            set xv [blt::vector create \#auto]
     860            set yv [blt::vector create \#auto]
     861            set zv [blt::vector create \#auto]
     862            $all split $xv $yv $zv
     863        } else {
     864            puts stderr "missing either xvalues, yvalues, zvalues, or points for $celltype cell mesh"
     865            return 0
     866        }
     867        set _numPoints [$xv length]
     868        set data {}
     869        set indices [$xmlobj get $path.cells.indices]
     870        set numIndices 0
     871        foreach { a b c } $indices {
     872            append data "    $numVertices $a $b $c\n"
     873            incr numIndices
     874        }
     875        set celltypes {}
     876        for { set i 0 } { $i < $numIndices } { incr i } {
     877            append celltypes "$vtkid\n"
     878        }
     879        append out "DATASET UNSTRUCTURED_GRID\n"
     880        append out "POINTS $_numPoints float\n"
     881        foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
     882            append out "    $x $y $z\n"
     883        }
     884        append out "CELLS $numIndices [expr $numIndices * 4]\n"
     885        append out $data
     886        append out "CELL_TYPES $numIndices\n"
     887        append out $celltypes
     888        append out "POINT_DATA $_numPoints\n"
     889        set _limits(xmin) [$xv min]
     890        set _limits(xmax) [$xv max]
     891        set _limits(ymin) [$yv min]
     892        set _limits(ymax) [$yv max]
     893        set _limits(zmin) [$zv min]
     894        set _limits(zmax) [$zv max]
     895    }
     896    set _vtkdata $out
     897    set _isValid 1
    732898}
    733899
     
    784950    set _limits(ymax) [$yv max]
    785951    set _vtkdata $out
    786 }
    787 
    788 itcl::body Rappture::Mesh::GetBltGridMesh { path } {
     952    set _isValid 1
     953}
     954
     955itcl::body Rappture::Mesh::ReadBltGridMesh { path } {
    789956    if { $_dim != 2 } {
    790957        error "must be 2D mesh for BLT"
     
    8411008}
    8421009
    843 itcl::body Rappture::Mesh::GetBltTriangleMesh { path } {
     1010itcl::body Rappture::Mesh::ReadBltTriangleMesh { path } {
    8441011    set _xv [blt::vector create \#auto]
    8451012    set _yv [blt::vector create \#auto]
     
    8561023}
    8571024
    858 itcl::body Rappture::Mesh::GetBltCloudMesh { path } {
     1025itcl::body Rappture::Mesh::ReadBltCloudMesh { path } {
    8591026    # Read the points into a vector and split them into individual coordinate
    8601027    # arrays.
     
    8831050}
    8841051
    885 itcl::body Rappture::Mesh::GetBltMesh { path } {
     1052itcl::body Rappture::Mesh::ReadBltMesh { path } {
    8861053    if { $_dim != 2 } {
    8871054        error "dimension of mesh $_dim is not 2"
     
    8891056    switch -- $_type {
    8901057        "cloud" {
    891             set _bltmesh [GetBltCloudMesh $path ]
     1058            set _bltmesh [ReadBltCloudMesh $path ]
    8921059        }
    8931060        "unirect" {
    894             set _bltmesh [GetBltRegularMesh $path]
     1061            set _bltmesh [ReadBltRegularMesh $path]
    8951062        }
    8961063        "rectangle" {
    897             set _bltmesh [GetBltIrregularMesh $path]
     1064            set _bltmesh [ReadBltIrregularMesh $path]
    8981065        }
    8991066        "triangle" {
    900             set _bltmesh [GetBltTriangleMesh $path]
     1067            set _bltmesh [ReadBltTriangleMesh $path]
    9011068        }
    9021069        default {
     
    9891156    }
    9901157    set _vtkdata $out
    991 }
     1158    set _isValid 1
     1159}
Note: See TracChangeset for help on using the changeset viewer.