<HTML>
<HEAD>
<TITLE>Re: [vtkusers] Efficiency problem in mesh display script ; TCL - VTK</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>I believe that you want to use vtkUnstructuredGrid to represent the object.<BR>
<BR>
Vince<BR>
<BR>
<BR>
<BR>
On 1/25/10 2:46 PM, &quot;Rafal Robak&quot; &lt;<a href="rafalrobak@gmail.com">rafalrobak@gmail.com</a>&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hi,<BR>
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. <BR>
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.<BR>
VTK has possibility to create something like poly vtkHexahedron object ?<BR>
in vertex is polyvertex and therefore i'm wondering about poly hex object ?<BR>
Do you have any idea ?<BR>
Best regards,<BR>
<BR>
####### CODE #######<BR>
package require vtk<BR>
package require vtkinteraction<BR>
package require vtktesting<BR>
package require Tcl<BR>
package require Tk<BR>
<BR>
global qty<BR>
<BR>
# Main code<BR>
vtkRenderer model_renderer<BR>
[model_renderer GetCullers] RemoveAllItems<BR>
<BR>
vtkRenderWindow model_window<BR>
model_window AddRenderer model_renderer<BR>
<BR>
model_renderer SetBackground .5 .5 .5<BR>
<BR>
model_renderer ResetCamera<BR>
[model_renderer GetActiveCamera] Dolly 2.5<BR>
model_renderer ResetCameraClippingRange<BR>
<BR>
vtkRenderWindowInteractor iaction<BR>
iaction SetRenderWindow model_window<BR>
<BR>
wm title . &quot;CDB reader&quot;<BR>
label .l1 -text &quot;OpenGL module ver 0.1 - CDB Reader&quot;<BR>
frame .f1<BR>
entry .e1 -textvariable node_qty<BR>
entry .e2 -textvariable elem_qty<BR>
button .b1 -text &quot;Open node&quot; -command &quot;open_model_node node_qty&quot;<BR>
button .b2 -text &quot;Open elem&quot; -command &quot;open_model_elem elem_qty&quot;<BR>
button .b3 -text &quot;Render&quot; -command &quot;render elem_qty&quot;<BR>
button .b4 -text &quot;Close&quot; -command &quot;destroy .&quot;<BR>
set render_widget [vtkTkRenderWidget .f1.r -width 800 -height 600 -rw model_window]<BR>
iaction Initialize<BR>
::vtk::bind_tk_render_widget $render_widget<BR>
<BR>
grid .l1 -row 1 -column 1 -columnspan 7<BR>
grid .f1 -row 2 -column 1 -columnspan 7<BR>
grid .e1 -row 3 -column 2<BR>
grid .e2 -row 3 -column 3<BR>
grid .b1 -row 3 -column 4<BR>
grid .b2 -row 3 -column 5<BR>
grid .b3 -row 3 -column 6<BR>
grid .b4 -row 3 -column 7<BR>
grid .f1.r -row 1 -column 1<BR>
<BR>
.b3 configure -state disabled<BR>
<BR>
#$render_widget Render<BR>
<BR>
proc generate {qty} {<BR>
upvar 1 $qty qty_loc<BR>
set fw [open node_file.txt w]<BR>
for {set i 1} {$i &lt;= $qty_loc} {incr i} {<BR>
puts $fw &quot;$i [expr rand()] [expr rand()] [expr rand()]&quot;<BR>
}<BR>
close $fw<BR>
}<BR>
<BR>
<BR>
proc open_model_node {node_qty} {<BR>
global ndata<BR>
upvar 1 $node_qty node_qty_loc<BR>
<BR>
set file_select [tk_getOpenFile -initialdir [pwd]]<BR>
set fr_node [open $file_select r]<BR>
<BR>
for {set i 1} {$i &lt;= $node_qty_loc} {incr i} {<BR>
set line [gets $fr_node]<BR>
lappend ndata([lindex $line 0]) [lindex $line 1]<BR>
lappend ndata([lindex $line 0]) [lindex $line 2]<BR>
lappend ndata([lindex $line 0]) [lindex $line 3]<BR>
}<BR>
close $fr_node<BR>
}<BR>
<BR>
proc open_model_elem {elem_qty} {<BR>
global edata<BR>
upvar 1 $elem_qty elem_qty_loc<BR>
<BR>
set file_select [tk_getOpenFile -initialdir [pwd]]<BR>
set fr_elem [open $file_select r]<BR>
<BR>
for {set i 1} {$i &lt;= $elem_qty_loc} {incr i} {<BR>
set line [gets $fr_elem]<BR>
lappend edata($i) [lindex $line 13]<BR>
lappend edata($i) [lindex $line 0]<BR>
lappend edata($i) [lindex $line 1]<BR>
lappend edata($i) [lindex $line 2]<BR>
lappend edata($i) [lindex $line 3]<BR>
lappend edata($i) [lindex $line 4]<BR>
lappend edata($i) [lindex $line 5]<BR>
lappend edata($i) [lindex $line 6]<BR>
lappend edata($i) [lindex $line 7]<BR>
} <BR>
<BR>
<BR>
.b3 configure -state normal<BR>
}<BR>
<BR>
proc clear {} {<BR>
model_renderer Clear<BR>
model_window Clear<BR>
}<BR>
<BR>
proc element {eid n1 n2 n3 n4 n5 n6 n7 n8} {<BR>
global ndata<BR>
<BR>
vtkPoints hexahedronPoints_$eid<BR>
&nbsp;&nbsp;hexahedronPoints_$eid SetNumberOfPoints 8<BR>
&nbsp;&nbsp;hexahedronPoints_$eid InsertPoint 0 [lindex $ndata($n1) 0] [lindex $ndata($n1) 1] [lindex $ndata($n1) 2]<BR>
&nbsp;&nbsp;hexahedronPoints_$eid InsertPoint 1 [lindex $ndata($n2) 0] [lindex $ndata($n2) 1] [lindex $ndata($n2) 2]<BR>
&nbsp;&nbsp;hexahedronPoints_$eid InsertPoint 2 [lindex $ndata($n3) 0] [lindex $ndata($n3) 1] [lindex $ndata($n3) 2]<BR>
&nbsp;&nbsp;hexahedronPoints_$eid InsertPoint 3 [lindex $ndata($n4) 0] [lindex $ndata($n4) 1] [lindex $ndata($n4) 2]<BR>
&nbsp;&nbsp;hexahedronPoints_$eid InsertPoint 4 [lindex $ndata($n5) 0] [lindex $ndata($n5) 1] [lindex $ndata($n5) 2]<BR>
&nbsp;&nbsp;hexahedronPoints_$eid InsertPoint 5 [lindex $ndata($n6) 0] [lindex $ndata($n6) 1] [lindex $ndata($n6) 2]<BR>
&nbsp;&nbsp;hexahedronPoints_$eid InsertPoint 6 [lindex $ndata($n7) 0] [lindex $ndata($n7) 1] [lindex $ndata($n7) 2]<BR>
&nbsp;&nbsp;hexahedronPoints_$eid InsertPoint 7 [lindex $ndata($n8) 0] [lindex $ndata($n8) 1] [lindex $ndata($n8) 2]<BR>
vtkHexahedron aHexahedron_$eid<BR>
&nbsp;&nbsp;[aHexahedron_$eid GetPointIds] SetId 0 0<BR>
&nbsp;&nbsp;[aHexahedron_$eid GetPointIds] SetId 1 1<BR>
&nbsp;&nbsp;[aHexahedron_$eid GetPointIds] SetId 2 2<BR>
&nbsp;&nbsp;[aHexahedron_$eid GetPointIds] SetId 3 3<BR>
&nbsp;&nbsp;[aHexahedron_$eid GetPointIds] SetId 4 4<BR>
&nbsp;&nbsp;[aHexahedron_$eid GetPointIds] SetId 5 5<BR>
&nbsp;&nbsp;[aHexahedron_$eid GetPointIds] SetId 6 6<BR>
&nbsp;&nbsp;[aHexahedron_$eid GetPointIds] SetId 7 7<BR>
vtkUnstructuredGrid aHexahedronGrid_$eid<BR>
&nbsp;&nbsp;aHexahedronGrid_$eid Allocate 1 1<BR>
&nbsp;&nbsp;aHexahedronGrid_$eid InsertNextCell [aHexahedron_$eid GetCellType] [aHexahedron_$eid GetPointIds]<BR>
&nbsp;&nbsp;aHexahedronGrid_$eid SetPoints hexahedronPoints_$eid<BR>
vtkDataSetMapper aHexahedronMapper_$eid<BR>
&nbsp;&nbsp;aHexahedronMapper_$eid SetInput aHexahedronGrid_$eid<BR>
vtkActor aHexahedronActor_$eid<BR>
&nbsp;&nbsp;aHexahedronActor_$eid SetMapper aHexahedronMapper_$eid<BR>
&nbsp;&nbsp;[aHexahedronActor_$eid GetProperty] SetColor 0.5 1 1<BR>
<BR>
model_renderer AddActor aHexahedronActor_$eid<BR>
}<BR>
<BR>
proc render {elem_qty} {<BR>
global ndata<BR>
global edata<BR>
upvar 1 $elem_qty elem_qty_loc<BR>
<BR>
for {set i 1} {$i &lt;= $elem_qty_loc} {incr i} {<BR>
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]<BR>
}<BR>
<BR>
model_renderer ResetCamera<BR>
}<BR>
<BR>
####### CODE #######<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
----------------------<BR>
Associate Professor<BR>
Department of Radiology<BR>
0453-D JCP<BR>
200 Hawkins Drive<BR>
Iowa City, IA 52242<BR>
E-mail: <a href="vincent-magnotta@uiowa.edu">vincent-magnotta@uiowa.edu</a><BR>
Phone: 319-356-8255 Fax: 319-353-6275<BR>
Website: <a href="http://www.radiology.uiowa.edu">http://www.radiology.uiowa.edu</a><BR>
<BR>
<BR>
</SPAN></FONT>
</BODY>
</HTML>