[vtkusers] vtkAppendPolyData delete the scalars

Gonzalo Amadio gonzaloamadio at gmail.com
Thu Aug 2 07:25:26 EDT 2012


Hello everyone. Is there some reason whereby vtkAppendPolyData delete the
scalars when I append 2 polydatas?

Here is my code.

 myPolyData->ShallowCopy(otherPolyData);
>         SubdividePolyData(myPolyData);   /// Here I modified the polydata,
> so I need to assign it again the scalar array.
>


        // The problem I think is here in this lines, where I assign the
> scalar array
> vtkIntArray* scalars = vtkIntArray::New();
>  scalars->SetNumberOfComponents(1);
> scalars->SetNumberOfValues(myPolyData->GetNumberOfCells());
>  scalars->SetNumberOfTuples(myPolyData->GetNumberOfCells());
>


for (int i = 0; i < myPolyData->GetNumberOfCells(); i++)
>  scalars->SetValue(i, 1);
>


myPolyData->GetCellData()->SetScalars(scalars);
>


        vtkSmartPointer<vtkAppendPolyData> appendGreenSubdAndRedBlue =
> vtkSmartPointer<vtkAppendPolyData>::New();
> appendGreenSubdAndRedBlue->AddInput(otherPolyData);   // what is extrange
> is that if I comment this line, it works fine
>  appendGreenSubdAndRedBlue->AddInput(myPolyData);
> appendGreenSubdAndRedBlue->Update();
>


 vtkPolyData * finalPolyData = appendGreenSubdAndRedBlue->GetOutput();
>


        vtkIntArray* scalarArray =
> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());
>         std::cout  << scalarArray->GetNumberOfTuples() << std::endl; //This
> line gives me an error



The error that I obtain is the following :

*File *:     vtkAbstractArray.h -  line 104

  vtkIdType GetNumberOfTuples()
    {return (this->MaxId + 1)/this->NumberOfComponents;}

*error:*

name               type                          value
this        vtkAbstractArray * const           0x0


I can assign "manually" again the scalars to the finalPolyData, but it is
suppose that the scalars remains when I append them.

Thank you!

-- 
--------
Gonzalo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120802/3098cdfc/attachment.htm>


More information about the vtkusers mailing list