[vtkusers] How to use GetTupleValue(i, array) in python?

lynx.abraxas at freenet.de lynx.abraxas at freenet.de
Fri Dec 18 15:07:03 EST 2009


Hello!


I  got  a  bit  furth  with  some  example  plugging. The problem is I have to
translate the code into python because I use it in conjunction with blender.

My code looks like this (bigger part below):

    pointNormal= [dim] #this is dimension dependent!!!

    for i in range(0, PointNormalArray.GetNumberOfTuples()):
        PointNormalArray.GetTupleValue(i, pointNormal) #make sure  pointNormal is big enough!

And I get the python error "AttributeError: GetTupleValue".
So I wonder how do I have to this in python?
And how would I be able to find that out by myself???

Thanks for any help or hints
Lynx

_______________________________

...from marching cubes output on:

    smoother= vtk.vtkWindowedSincPolyDataFilter()
    smoother.SetInput(contour.GetOutput());
    smoother.SetNumberOfIterations(5);
    #smoother.BoundarySmoothingOff();
    #smoother.FeatureEdgeSmoothingOff();
    #smoother.SetFeatureAngle(120.0);
    #smoother.SetPassBand(.001);
    smoother.NonManifoldSmoothingOn();
    smoother.NormalizeCoordinatesOn();
    smoother.Update();


    ##calc cell normal
    ##output as input but with normals added?
    
    triangleCellNormals= vtk.vtkPolyDataNormals()
    triangleCellNormals.SetInput(smoother.GetOutput())
    triangleCellNormals.ComputeCellNormalsOn()
    triangleCellNormals.ComputePointNormalsOff()
    triangleCellNormals.ConsistencyOn()
    triangleCellNormals.AutoOrientNormalsOn()
    triangleCellNormals.Update() #creates vtkPolyData


    ##calc cell area
    ##output vtkDataSet not as input!
    
    triangleCellAN= vtk.vtkMeshQuality()
    triangleCellAN.SetInput(triangleCellNormals.GetOutput())
    triangleCellAN.SetTriangleQualityMeasureToArea()
    triangleCellAN.SaveCellQualityOn() ##default
    triangleCellAN.Update() #creates vtkDataSet



#     for i in range(0, triangleCellAN.GetNumberOfCells()):
        
#         cell= triangleCellAN.GetCell(i) #triangleCellNormals.GetCell(i)
#         cell.GetNormals()
#         triangleCellAN.GetOutput().GetCellData().GetArray("Quality")

    ##triangleCellNormals.GetOutput() #= vtkPolyDataAlgorithm.GetOutput() = vtkPolyData
    ##triangleCellNormals.GetOutput().GetCellData() #= vtkPolyData->vtkPointSet->vtkDataSet.GetCellData() = vtkCellData
    ##triangleCellNormals.GetOutput().GetCellData().GetNormals() #= vtkCellData->vtkDataSetAttributes.GetNormals() = vtkDataArray

    #PointNormalArray = vtkFloatArray::SafeDownCast(triangleCellNormals.GetOutput().GetCellData().GetNormals()) #GetPointData().GetNormals() would yield the point normals
    PointNormalArray = triangleCellNormals.GetOutput().GetCellData().GetNormals() #GetPointData().GetNormals() would yield the point normals


    ##triangleCellAN.GetOutput() #= vtkDataSetAlgorithm.GetOutput() = vtkDataSet
    ##triangleCellAN.GetOutput().GetCellData() #= vtkDataSet.GetCellData() = vtkCellData
    ##triangleCellAN.GetOutput().GetCellData().GetArray("") #= vtkCellData->vtkDataSetAttributes->vtkFieldData.GetArray = vtkDataArray
    
    #qualityArray = vtkDoubleArray::SafeDownCast(triangleCellAN.GetOutput().GetCellData().GetArray("Quality"))
    qualityArray = triangleCellAN.GetOutput().GetCellData().GetArray("Quality")

    if (PointNormalArray.GetNumberOfTuples() != qualityArray.GetNumberOfTuples()):
        print "Error! Sizes of normal array and area array dont equal!"
        exit(1)


    pointNormal= [dim] #this is dimension dependent!!!

    for i in range(0, PointNormalArray.GetNumberOfTuples()):
        PointNormalArray.GetTupleValue(i, pointNormal) #make sure pointNormal is big enough!
        area= qualityArray.GetValue(i)
        print i, area, pointNormal


...now go go to blender

On 17/12/09 16:37:03, lynx.abraxas at freenet.de wrote:
> Hello!
> 
> 
> Are the normals from vtkPolyDataNormals normalized?
> 
> I need a listing of surface area weighted normals of each cell of a
> vtkPolyData mesh (from a smoothed marching cubes mesh).
> Iterating now over all cells of this vtkPolyData I wonder how I can get the
> associated cell normal and the cell area. I tried as follows but I'm
> stuck. vtkCell has no getNormal() nor a getAtrribute("Quality") in which
> the area is supposed to be after vtkMeshQuality().
> Would it be better to extract all Normals and areas into arrays?
> How would I have to calculate the weighted normals then?
> 
>     ##calc cell normal
>     ##output as input but with normals added?
> 
>     triangleCellNormals= vtk.vtkPolyDataNormals()
>     triangleCellNormals.SetInput(smoother.GetOutput())
>     triangleCellNormals.ComputeCellNormalsOn()
>     triangleCellNormals.ComputePointNormalsOff()
>     triangleCellNormals.ConsistencyOn()
>     triangleCellNormals.AutoOrientNormalsOn()
>     triangleCellNormals.Update()
> 
> 
>     ##calc cell area
>     ##output as input but with areas added?
> 
>     triangleCellAN= vtk.vtkMeshQuality()
>     triangleCellAN.SetInput(triangleCellNormals)
>     triangleCellAN.SetTriangleQualityMeasureToArea()
>     triangleCellAN.SaveCellQualityOn() ##default
>     triangleCellAN.Update()
> 
> 
> 
>     for i in range(0, triangleCellAN.GetNumberOfCells()):
> 
>         cell= triangleCellAN.GetCell(i);
>         cell.GetNormals()
>         "Quality"
> 
> 
> Thanks for any help or hints about this.
> Lynx
> 
> 
> On 17/12/09 09:09:03, David Doria wrote:
> > On Thu, Dec 17, 2009 at 2:32 AM, Bryn Lloyd <blloyd at vision.ee.ethz.ch> wrote:
> > > Another way to compute the area is via vtkMeshQuality.
> > >
> > > First pass the mesh through this filter, compute the area for all triangles
> > > (SetTriangleQualityMeasureToArea()), and the obtain the values from the
> > > vtkCellData in the output.
> > >
> > > Cheers
> > > Bryn
> > 
> > Bryn,
> > 
> > I tried that:
> > http://www.vtk.org/Wiki/VTK/Examples/Mesh_Quality
> > 
> > But the values in the "Quality" array are all 0. Any thoughts?
> > 
> > Thanks,
> > 
> > David
> > _______________________________________________
> > Powered by www.kitware.com
> > 
> > Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> > 
> > Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> > 
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list