C++ code fragment converted to Python?

Dean N. Williams williams13 at llnl.gov
Wed Nov 3 05:00:34 EST 1999


Dear Vtk Users,

    I have a code fragment that I am having troubles converting
    to Python. I am wondering if anyone has done this. I am on
    a Linux 5.2 RH PC running Python 1.5.2 and Vtk 2.4.

    The problem is the last statement. That is, casing the vtkFloatArray

    in Python. I'm not sure how to do this without getting errors.

C++ code:

// create a place for the data
  vtkScalars *scalars = vtkScalars::New();
    scalars->SetDataTypeToFloat();
    scalars->SetNumberOfScalars(num);
    ((vtkFloatArray*)(scalars->GetData()))->SetArray(data,num,0);

Python Conversion:

scalars = vtkScalars()
scalars.SetDataTypeToFloat()
scalars.SetNumberOfScalars(num)
vtkFloatArray(scalars.GetData()).SetArray(data,num,0)  # This statement

# doesn't work!
Python Conversion 2:

Python Conversion (The sloow way, but works):
scalars = vtkScalars()
scalars.SetDataTypeToFloat()
scalars.SetNumberOfScalars(num)
for i in range(num):
      scalars.SetScalar(i,data[i])    #Very slow but works!

How can I get the first Python Conversion to work? SetArray is not
a defined attribute. Maybe there is a completely different way of doing
this in Python.

Thanks for your help!

-Dean




--
Dean N. Williams
Computer Scientist/Computation Group Leader             o
Lawrence Livermore National Laboratory                --
Livermore, California 94550                          `\< *
Phone: (925) 423-0145    FAX: (925) 422-7675        /  \
http://www-pcmdi.llnl.gov                         williams13 at llnl.gov





-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list