[vtkusers] Unstructured grid visualization problem......please help

Lachlan Hurst lachlan at vpac.org
Fri Mar 19 01:34:24 EST 2004


Hi,
Just doesn't seem like the most efficient method, read in FEA/CAE mesh
file - write out VTK file - read in VTK file.  I do a small amount of work
in this field myself.  Have a look at the python code below - it basically
takes a model type data structure (not shown, but very basic) and translates
it into a vtkUnstructuredGrid (self.vtkGRID) object ready for visualisation.
It only does solid elements but the shell's are very easy to include. VTK
definately has a lot of potential in this field.  Hope it helps.

Cheers,
Lachlan

----------------------------------------------------------------------------
----------------------------------------------------------------------------
-------------

    def MakeVTKGRID(self):
        self.vtkGRID = vtk.vtkUnstructuredGrid()
        aPoints = vtk.vtkPoints()
        aTetra = vtk.vtkTetra()
        aMapper = vtk.vtkDataSetMapper()

        for tetra in self.CTETRA:
            aPoints.InsertPoint(tetra.node1,
self.GRID[tetra.node1].nodeXCoord, self.GRID[tetra.node1].nodeYCoord,
self.GRID[tetra.node1].nodeZCoord)
            aPoints.InsertPoint(tetra.node2,
self.GRID[tetra.node2].nodeXCoord, self.GRID[tetra.node2].nodeYCoord,
self.GRID[tetra.node2].nodeZCoord)
            aPoints.InsertPoint(tetra.node3,
self.GRID[tetra.node3].nodeXCoord, self.GRID[tetra.node3].nodeYCoord,
self.GRID[tetra.node3].nodeZCoord)
            aPoints.InsertPoint(tetra.node4,
self.GRID[tetra.node4].nodeXCoord, self.GRID[tetra.node4].nodeYCoord,
self.GRID[tetra.node4].nodeZCoord)
            aTetra.GetPointIds().SetId(0, tetra.node1)
            aTetra.GetPointIds().SetId(1, tetra.node2)
            aTetra.GetPointIds().SetId(2, tetra.node3)
            aTetra.GetPointIds().SetId(3, tetra.node4)
            self.vtkGRID.InsertNextCell(aTetra.GetCellType(),
aTetra.GetPointIds())

        pentaPoints = vtk.vtkPoints()
        aPenta = vtk.vtkWedge()

        for penta in self.CPENTA:
            aPoints.InsertPoint(penta.node1,
self.GRID[penta.node1].nodeXCoord, self.GRID[penta.node1].nodeYCoord,
self.GRID[penta.node1].nodeZCoord)
            aPoints.InsertPoint(penta.node2,
self.GRID[penta.node2].nodeXCoord, self.GRID[penta.node2].nodeYCoord,
self.GRID[penta.node2].nodeZCoord)
            aPoints.InsertPoint(penta.node3,
self.GRID[penta.node3].nodeXCoord, self.GRID[penta.node3].nodeYCoord,
self.GRID[penta.node3].nodeZCoord)
            aPoints.InsertPoint(penta.node4,
self.GRID[penta.node4].nodeXCoord, self.GRID[penta.node4].nodeYCoord,
self.GRID[penta.node4].nodeZCoord)
            aPoints.InsertPoint(penta.node5,
self.GRID[penta.node5].nodeXCoord, self.GRID[penta.node5].nodeYCoord,
self.GRID[penta.node5].nodeZCoord)
            aPoints.InsertPoint(penta.node6,
self.GRID[penta.node6].nodeXCoord, self.GRID[penta.node6].nodeYCoord,
self.GRID[penta.node6].nodeZCoord)
            aPenta.GetPointIds().SetId(0, penta.node1)
            aPenta.GetPointIds().SetId(1, penta.node2)
            aPenta.GetPointIds().SetId(2, penta.node3)
            aPenta.GetPointIds().SetId(3, penta.node4)
            aPenta.GetPointIds().SetId(4, penta.node5)
            aPenta.GetPointIds().SetId(5, penta.node6)
            self.vtkGRID.InsertNextCell(aPenta.GetCellType(),
aPenta.GetPointIds())

        pyraPoints = vtk.vtkPoints()
        aPyra = vtk.vtkWedge()

        for pyra in self.CPYRA:
            aPoints.InsertPoint(pyra.node1,
self.GRID[pyra.node1].nodeXCoord, self.GRID[pyra.node1].nodeYCoord,
self.GRID[pyra.node1].nodeZCoord)
            aPoints.InsertPoint(pyra.node2,
self.GRID[pyra.node2].nodeXCoord, self.GRID[pyra.node2].nodeYCoord,
self.GRID[pyra.node2].nodeZCoord)
            aPoints.InsertPoint(pyra.node3,
self.GRID[pyra.node3].nodeXCoord, self.GRID[pyra.node3].nodeYCoord,
self.GRID[pyra.node3].nodeZCoord)
            aPoints.InsertPoint(pyra.node4,
self.GRID[pyra.node4].nodeXCoord, self.GRID[pyra.node4].nodeYCoord,
self.GRID[pyra.node4].nodeZCoord)
            aPoints.InsertPoint(pyra.node5,
self.GRID[pyra.node5].nodeXCoord, self.GRID[pyra.node5].nodeYCoord,
self.GRID[pyra.node5].nodeZCoord)
            aPoints.InsertPoint(pyra.node6,
self.GRID[pyra.node6].nodeXCoord, self.GRID[pyra.node6].nodeYCoord,
self.GRID[pyra.node6].nodeZCoord)
            aPyra.GetPointIds().SetId(0, pyra.node1)
            aPyra.GetPointIds().SetId(1, pyra.node2)
            aPyra.GetPointIds().SetId(2, pyra.node3)
            aPyra.GetPointIds().SetId(3, pyra.node4)
            aPyra.GetPointIds().SetId(4, pyra.node5)
            aPyra.GetPointIds().SetId(5, pyra.node6)
            self.vtkGRID.InsertNextCell(aPyra.GetCellType(),
aPyra.GetPointIds())

        hexaPoints = vtk.vtkPoints()
        aHexa = vtk.vtkHexahedron()

        for hexa in self.CHEXA:
            aPoints.InsertPoint(hexa.node1,
self.GRID[hexa.node1].nodeXCoord, self.GRID[hexa.node1].nodeYCoord,
self.GRID[hexa.node1].nodeZCoord)
            aPoints.InsertPoint(hexa.node2,
self.GRID[hexa.node2].nodeXCoord, self.GRID[hexa.node2].nodeYCoord,
self.GRID[hexa.node2].nodeZCoord)
            aPoints.InsertPoint(hexa.node3,
self.GRID[hexa.node3].nodeXCoord, self.GRID[hexa.node3].nodeYCoord,
self.GRID[hexa.node3].nodeZCoord)
            aPoints.InsertPoint(hexa.node4,
self.GRID[hexa.node4].nodeXCoord, self.GRID[hexa.node4].nodeYCoord,
self.GRID[hexa.node4].nodeZCoord)
            aPoints.InsertPoint(hexa.node5,
self.GRID[hexa.node5].nodeXCoord, self.GRID[hexa.node5].nodeYCoord,
self.GRID[hexa.node5].nodeZCoord)
            aPoints.InsertPoint(hexa.node6,
self.GRID[hexa.node6].nodeXCoord, self.GRID[hexa.node6].nodeYCoord,
self.GRID[hexa.node6].nodeZCoord)
            aPoints.InsertPoint(hexa.node7,
self.GRID[hexa.node7].nodeXCoord, self.GRID[hexa.node7].nodeYCoord,
self.GRID[hexa.node7].nodeZCoord)
            aPoints.InsertPoint(hexa.node8,
self.GRID[hexa.node8].nodeXCoord, self.GRID[hexa.node8].nodeYCoord,
self.GRID[hexa.node8].nodeZCoord)
            aHexa.GetPointIds().SetId(0, hexa.node1)
            aHexa.GetPointIds().SetId(1, hexa.node2)
            aHexa.GetPointIds().SetId(2, hexa.node3)
            aHexa.GetPointIds().SetId(3, hexa.node4)
            aHexa.GetPointIds().SetId(4, hexa.node5)
            aHexa.GetPointIds().SetId(5, hexa.node6)
            aHexa.GetPointIds().SetId(6, hexa.node7)
            aHexa.GetPointIds().SetId(7, hexa.node8)
            self.vtkGRID.InsertNextCell(aHexa.GetCellType(),
aHexa.GetPointIds())

        self.vtkGRID.SetPoints(aPoints)










----- Original Message ----- 
From: "Mathieu Malaterre" <mathieu.malaterre at kitware.com>
To: "nikhil butala" <nvbutala at yahoo.com>
Cc: <vtkusers at vtk.org>
Sent: Friday, March 19, 2004 7:35 AM
Subject: Re: [vtkusers] Unstructured grid visualization problem......please
help


> Nikhil,
>
> What type of file are you reading. I strongly suggest you use an
> already existing file reader to achieve this.
>
> I look at your file, and your tetras do not respect the right hand
> rule. Please see doc for more info:
>
> http://www.vtk.org/doc/nightly/html/classvtkTetra.html
>
> HTH,
> Mathieu
>
> nikhil butala wrote:
> >
> >
> > Note: forwarded message attached.
> >
> > Do you Yahoo!?
> > *Yahoo! Mail* <http://us.rd.yahoo.com/mailtag_us/*http://mail.yahoo.com>
> > - More reliable, more storage, less spam
> >
> > ------------------------------------------------------------------------
> >
> > Subject:
> > unstructured grid visualization problem
> > From:
> > nikhil butala <nvbutala at yahoo.com>
> > Date:
> > Wed, 17 Mar 2004 15:11:17 -0800 (PST)
> > To:
> > vtkusers at vtk.org
> >
> >
> > Dear vtk-users,
> >
> >                    I am a newbie with vtk and am trying to read 3D
> > tetrahedral mesh from FEA softwares into VTK.
> > I converted the FEA mesh into vtk format. I am first trying to read
> > simple mesh of a cube. The input vtk file is as follows:
> >
> > # vtk DataFile Version 2.0
> >
> > Trial
> >
> > ASCII
> >
> > DATASET UNSTRUCTURED_GRID
> >
> > POINTS 10 float
> >
> > -1 1 2
> >
> > -1 1 0
> >
> > -1 -1 2
> >
> > -1 -1 0
> >
> > 1 -1 2
> >
> > 1 -1 0
> >
> > 1 1 2
> >
> > 1 1 0
> >
> > 0.400316 0.171597 0.759397
> >
> > -0.099509 -0.159484 1.126592
> >
> > CELLS 16 80
> >
> > 4 7 1 10 2
> >
> > 4 9 8 2 6
> >
> > 4 10 1 5 3
> >
> > 4 10 7 5 1
> >
> > 4 7 2 10 9
> >
> > 4 10 9 5 7
> >
> > 4 6 9 10 2
> >
> > 4 8 6 9 5
> >
> > 4 8 5 9 7
> >
> > 4 8 7 9 2
> >
> > 4 6 5 3 10
> >
> > 4 6 2 10 4
> >
> > 4 10 4 2 1
> >
> > 4 4 1 10 3
> >
> > 4 6 10 3 4
> >
> > 4 6 5 10 9
> >
> > CELL_TYPES 16
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> > 10
> >
> >
> > I am reading the vtk file using the following code:
> >
> > package require vtk
> > vtkUnstructuredGridReader reader
> >     reader SetFileName "$DataSource/outputfile2.vtk"
> >
> > vtkDataSetMapper mapper
> >     mapper SetInput [reader GetOutput]
> >
> > vtkActor actor
> >    actor SetMapper mapper
> >     [actor GetProperty] SetColor .2 .2 .2
> >     [actor GetProperty] SetRepresentationToWireframe
> > vtkExtractUnstructuredGrid extractGrid
> >     extractGrid SetInput [reader GetOutput]
> >
> >
> > # graphics stuff
> > vtkRenderer ren1
> > vtkRenderWindow renWin
> >     renWin AddRenderer ren1
> > vtkRenderWindowInteractor iren
> >     iren SetRenderWindow renWin
> > # Add the actors to the renderer, set the background and size
> > #
> > ren1 AddActor actor
> > ren1 SetBackground 1 1 1
> > [ren1 GetActiveCamera] Azimuth 60
> > [ren1 GetActiveCamera] Roll -90
> > [ren1 GetActiveCamera] Dolly 2
> > ren1 ResetCameraClippingRange
> > renWin SetSize 500 375
> > iren Initialize
> > # prevent the tk window from showing up then start the event loop
> > wm withdraw .
> >
> > The output visualization of the mesh is not as expected. I are not able
> > to see the outer bounds of the cube. Can anyone help me and tell why
> > this problem is arising???
> >
> > thanking you,
> > regards,
> > Nikhil Butala
> >
> >
> >
> > Do you Yahoo!?
> > *Yahoo! Mail* <http://us.rd.yahoo.com/mailtag_us/*http://mail.yahoo.com>
> > - More reliable, more storage, less spam
> >
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list