[vtkusers] Basic question, vtkStructuredPoints

Oeyvind Knudsen knudsen at operamail.com
Thu Feb 12 11:57:24 EST 2004


I got it! 

I replaced your vtkUnsignedCharArray with a vtkDoubleArray and it worked. Now I have to check if this really is more efficient than just doing the write/read. I still think it is mysterious that the objects don't look the same when printed out though, so if anyone can give me an explanation for that I would be most grateful.

Regards,
Øyvind Knudsen

----- Original Message -----
From: REGAT-BARREL Aurélien <arbvtk at yahoo.fr>
Date: Wed, 11 Feb 2004 20:13:21 +0100 (CET)
To: Oeyvind Knudsen <knudsen at operamail.com>, vtkusers at vtk.org
Subject: Re: [vtkusers] Basic question, vtkStructuredPoints

> Hello,
> So you want to include a vtk data file directly in your Python source code and build a vtkStructuredGrid from scratch ? Why ?
> I work on a project in Python which used to build its own vtkStructuredPoints from scratch in Python.
> Here is the code equivalent for you :
>     spData = vtkStructuredPoints()
>     spData.SetDimensions( 81, 81, 1 )
>     spData.SetOrigin( 0, 0, 0 )
>     spData.SetSpacing( 1, 1, 1 )
>     scalars = vtkUnsignedCharArray()
>     for z in range( 0, 1 ) :
>         for y in range( 0, 81 ) :
>             for x in range( 0, 81 ) :
>                 val = getValue( x, y, z )
>                 scalars.InsertNextValue( val )
>     spData.GetPointData().SetScalars( scalars )
>  
> It should work (you must replace getValue( x, y, z ) by the right thing) but in my opinion you should not use this method, since it is very slow because each VTK object method call cost is high du to the wrapping layer between VTK (C++) and your Python code. That's why the program I am working on was very slow and why I moved this code to C++.  If your really want to do it in Python, I recommend your to create a temporary vtk file, to read it as you are currently doing and then delete it in order to keep good performances. But maybe that if you dont use a bigger object than your 81x81x1 grid it will be done enough fast for your need.
> Hope it helps.
>  
> Aurélien REGAT-BARREL
>  
> 
> Oeyvind Knudsen <knudsen at operamail.com> wrote:
> Hi!
> 
> I'm using VTK to visualize a surface from a data file using the vtkStructuredPointsReader in Python. But from now the data should be passed directly from within the program, i.e. without using files or readers at all. Currently the code for making the surface looks like this:
> 
> reader = vtkStructuredPointsReader()
> reader.SetFileName("data.vtk")
> 
> geometry = vtkImageDataGeometryFilter()
> geometry.SetInput(reader.GetOutput()) #
> warp = vtkWarpScalar()
> warp.SetInput(geometry.GetOutput())
> warp.XYPlaneOff()
> warp.SetScaleFactor(100)
> 
> merge = vtkMergeFilter()
> merge.SetGeometry(warp.GetOutput())
> merge.SetScalars(reader.GetOutput()) #
> 
> smoother = vtkSmoothPolyDataFilter()
> smoother.SetInput(merge.GetOutput())
> smoother.SetNumberOfIterations(50)
> 
> mapper = vtkPolyDataMapper()
> mapper.SetInput(smoother.GetOutput())
> mapper.SetScalarRange(self.minData,self.maxData)
> mapper.ImmediateModeRenderingOff()
> 
> surface = vtkLODActor()
> surface.SetMapper(mapper)
> 
> self.renderer.AddActor(surface)
> (+ some axis stuff)
> 
> The data is in this format:
> 
> # vtk DataFile Version 2.0
> data
> ASCII
> DATASET STRUCTURED_POINTS
> DIMENSIONS 81 81 1
> ORIGIN 0 0 0
> SPACING 1 1 1
> POINT_DATA 6561
> SCALARS Scalars0 float 1
> LOOKUP_TABLE default
> 0.0624595315954 0.0686842278186 0.0747777522745 (+ many more numbers)
> 
> So, instead of using this file as a source I now get a python list of the data in to my visualization method. But I can't seem to get the vtkStructuredPoints object constructed in a proper way as my surface will no longer appear. I start with this:
> 
> spData = vtkStructuredPoints()
> spData.SetDimensions(81, 81, 1)
> 
> But how do I get the scalar values into spData so that spData and reader.GetOutput() (from the current code) yields the same resulting object? The goal is to replace all the occurences of reader.GetOutput() from the above code with just spData.
> 
> Regards, 
> Øyvind Knudsen
> 
> 		
> ---------------------------------
> Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
Créez votre Yahoo! Mail
-- 
_____________________________________________________________
Web-based SMS services available at http://www.operamail.com.
>From your mailbox to local or overseas cell phones.

Powered by Outblaze



More information about the vtkusers mailing list