[vtkusers] Efficiency problem in mesh display script ; TCL - VTK

Rafal Robak rafalrobak at gmail.com
Mon Feb 1 15:22:19 EST 2010


Yes Vincent you are right. Thank You.
It make a script much faster then previous version.

I'm also thinking to myself that it is not necessary to create hexa elements
for entire model (inside hexa elements). Maybe better solution is selecting
exterior points from vtkPoints and then create only quad elements. It should
also improve efficiency in program. What do you think about ?
It is some method to extract exterior nodes from the class vtkPoints (or
another data class should be used instead) ?

2010/1/25 Vincent Magnotta <vincent-magnotta at uiowa.edu>

>  I believe that you want to use vtkUnstructuredGrid to represent the
> object.
>
> Vince
>
>
>
>
> On 1/25/10 2:46 PM, "Rafal Robak" <rafalrobak at gmail.com> wrote:
>
> Hi,
> I'm looking for 3d engine to display a mesh from FEM softwares like ANSYS
> cdb file / Nastran bdf file. First of all i would like to display FEM model
> in 3D interactive GL window. I choose TCL and VTK and i create following
> code. In entry widget i define a quantity of nodes and elements in node and
> element file and then based on function invoked from 'Render' button model
> is displayed.
> Problem is in efficiency. Because each element is created as separate
> object (i would like to display models above 1000000 elements) VTK has big
> problem.
> VTK has possibility to create something like poly vtkHexahedron object ?
> in vertex is polyvertex and therefore i'm wondering about poly hex object ?
> Do you have any idea ?
> Best regards,
>
> ####### CODE #######
> package require vtk
> package require vtkinteraction
> package require vtktesting
> package require Tcl
> package require Tk
>
> global qty
>
> # Main code
> vtkRenderer model_renderer
> [model_renderer GetCullers] RemoveAllItems
>
> vtkRenderWindow model_window
> model_window AddRenderer model_renderer
>
> model_renderer SetBackground .5 .5 .5
>
> model_renderer ResetCamera
> [model_renderer GetActiveCamera] Dolly 2.5
> model_renderer ResetCameraClippingRange
>
> vtkRenderWindowInteractor iaction
> iaction SetRenderWindow model_window
>
> wm title . "CDB reader"
> label .l1 -text "OpenGL module ver 0.1 - CDB Reader"
> frame .f1
> entry .e1 -textvariable node_qty
> entry .e2 -textvariable elem_qty
> button .b1 -text "Open node" -command "open_model_node node_qty"
> button .b2 -text "Open elem" -command "open_model_elem elem_qty"
> button .b3 -text "Render" -command "render elem_qty"
> button .b4 -text "Close" -command "destroy ."
> set render_widget [vtkTkRenderWidget .f1.r -width 800 -height 600 -rw
> model_window]
> iaction Initialize
> ::vtk::bind_tk_render_widget $render_widget
>
> grid .l1 -row 1 -column 1 -columnspan 7
> grid .f1 -row 2 -column 1 -columnspan 7
> grid .e1 -row 3 -column 2
> grid .e2 -row 3 -column 3
> grid .b1 -row 3 -column 4
> grid .b2 -row 3 -column 5
> grid .b3 -row 3 -column 6
> grid .b4 -row 3 -column 7
> grid .f1.r -row 1 -column 1
>
> .b3 configure -state disabled
>
> #$render_widget Render
>
> proc generate {qty} {
> upvar 1 $qty qty_loc
> set fw [open node_file.txt w]
> for {set i 1} {$i <= $qty_loc} {incr i} {
> puts $fw "$i [expr rand()] [expr rand()] [expr rand()]"
> }
> close $fw
> }
>
>
> proc open_model_node {node_qty} {
> global ndata
> upvar 1 $node_qty node_qty_loc
>
> set file_select [tk_getOpenFile -initialdir [pwd]]
> set fr_node [open $file_select r]
>
> for {set i 1} {$i <= $node_qty_loc} {incr i} {
> set line [gets $fr_node]
> lappend ndata([lindex $line 0]) [lindex $line 1]
> lappend ndata([lindex $line 0]) [lindex $line 2]
> lappend ndata([lindex $line 0]) [lindex $line 3]
> }
> close $fr_node
> }
>
> proc open_model_elem {elem_qty} {
> global edata
> upvar 1 $elem_qty elem_qty_loc
>
> set file_select [tk_getOpenFile -initialdir [pwd]]
> set fr_elem [open $file_select r]
>
> for {set i 1} {$i <= $elem_qty_loc} {incr i} {
> set line [gets $fr_elem]
> lappend edata($i) [lindex $line 13]
> lappend edata($i) [lindex $line 0]
> lappend edata($i) [lindex $line 1]
> lappend edata($i) [lindex $line 2]
> lappend edata($i) [lindex $line 3]
> lappend edata($i) [lindex $line 4]
> lappend edata($i) [lindex $line 5]
> lappend edata($i) [lindex $line 6]
> lappend edata($i) [lindex $line 7]
> }
>
>
> .b3 configure -state normal
> }
>
> proc clear {} {
> model_renderer Clear
> model_window Clear
> }
>
> proc element {eid n1 n2 n3 n4 n5 n6 n7 n8} {
> global ndata
>
> vtkPoints hexahedronPoints_$eid
>   hexahedronPoints_$eid SetNumberOfPoints 8
>   hexahedronPoints_$eid InsertPoint 0 [lindex $ndata($n1) 0] [lindex
> $ndata($n1) 1] [lindex $ndata($n1) 2]
>   hexahedronPoints_$eid InsertPoint 1 [lindex $ndata($n2) 0] [lindex
> $ndata($n2) 1] [lindex $ndata($n2) 2]
>   hexahedronPoints_$eid InsertPoint 2 [lindex $ndata($n3) 0] [lindex
> $ndata($n3) 1] [lindex $ndata($n3) 2]
>   hexahedronPoints_$eid InsertPoint 3 [lindex $ndata($n4) 0] [lindex
> $ndata($n4) 1] [lindex $ndata($n4) 2]
>   hexahedronPoints_$eid InsertPoint 4 [lindex $ndata($n5) 0] [lindex
> $ndata($n5) 1] [lindex $ndata($n5) 2]
>   hexahedronPoints_$eid InsertPoint 5 [lindex $ndata($n6) 0] [lindex
> $ndata($n6) 1] [lindex $ndata($n6) 2]
>   hexahedronPoints_$eid InsertPoint 6 [lindex $ndata($n7) 0] [lindex
> $ndata($n7) 1] [lindex $ndata($n7) 2]
>   hexahedronPoints_$eid InsertPoint 7 [lindex $ndata($n8) 0] [lindex
> $ndata($n8) 1] [lindex $ndata($n8) 2]
> vtkHexahedron aHexahedron_$eid
>   [aHexahedron_$eid GetPointIds] SetId 0 0
>   [aHexahedron_$eid GetPointIds] SetId 1 1
>   [aHexahedron_$eid GetPointIds] SetId 2 2
>   [aHexahedron_$eid GetPointIds] SetId 3 3
>   [aHexahedron_$eid GetPointIds] SetId 4 4
>   [aHexahedron_$eid GetPointIds] SetId 5 5
>   [aHexahedron_$eid GetPointIds] SetId 6 6
>   [aHexahedron_$eid GetPointIds] SetId 7 7
> vtkUnstructuredGrid aHexahedronGrid_$eid
>   aHexahedronGrid_$eid Allocate 1 1
>   aHexahedronGrid_$eid InsertNextCell [aHexahedron_$eid GetCellType]
> [aHexahedron_$eid GetPointIds]
>   aHexahedronGrid_$eid SetPoints hexahedronPoints_$eid
> vtkDataSetMapper aHexahedronMapper_$eid
>   aHexahedronMapper_$eid SetInput aHexahedronGrid_$eid
> vtkActor aHexahedronActor_$eid
>   aHexahedronActor_$eid SetMapper aHexahedronMapper_$eid
>   [aHexahedronActor_$eid GetProperty] SetColor 0.5 1 1
>
> model_renderer AddActor aHexahedronActor_$eid
> }
>
> proc render {elem_qty} {
> global ndata
> global edata
> upvar 1 $elem_qty elem_qty_loc
>
> for {set i 1} {$i <= $elem_qty_loc} {incr i} {
> element [lindex $edata($i) 0] [lindex $edata($i) 1] [lindex $edata($i) 2]
> [lindex $edata($i) 3] [lindex $edata($i) 4] [lindex $edata($i) 5] [lindex
> $edata($i) 6] [lindex $edata($i) 7] [lindex $edata($i) 8]
> }
>
> model_renderer ResetCamera
> }
>
> ####### CODE #######
>
>
> ----------------------
> Associate Professor
> Department of Radiology
> 0453-D JCP
> 200 Hawkins Drive
> Iowa City, IA 52242
> E-mail: vincent-magnotta at uiowa.edu
> Phone: 319-356-8255 Fax: 319-353-6275
> Website: http://www.radiology.uiowa.edu
>
>
>


-- 
Rafał Robak
www.robak.info
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100201/979d9b75/attachment.htm>


More information about the vtkusers mailing list