[vtkusers] vtkAppendPolyData delete the scalars

Gonzalo Amadio gonzaloamadio at gmail.com
Wed Aug 8 06:31:08 EDT 2012


2012/8/7 Alex Malyushytskyy <alexmalvtk at gmail.com>

> > What additional information do you need?
>
> To see that arrays are compatible you need to show details how both of
> them are created, not 1
> But you can check this yourself.
> As far as I understand having both lines below do not make any sense,
> leave one
>

Here you have the code.. it seems long, but it can be read quickly =)
http://pastie.org/private/ukqsezzfnkuxdsp1cb2jaw


>
>     scalars->SetNumberOfValues(myPolyData->GetNumberOfCells());
> //    scalars->SetNumberOfTuples(myPolyData->GetNumberOfCells());
>
> Correct way of casting instead of
> >> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());
> would be
>      vtkIntArray*  _array = vtkIntArray::SafeDownCast( .... );
>

> even though arrays might be created and combined, I am not sure active
> scalar would be set.
> so I suggested you to check that array exist first:
>
> finalPolyData->GetCellData()->GetArray( name )
>

finalPolyData, is the append of other polydatas, so I don't know the name
of the scalar array. Even though, I think they don't have names.


>
> And if it exist set the active scalar to newly created polydata
>            finalPolyData->SetActiveScalars(  name );
>
> o guessing does not work usually, so you need to find out what is wrong
>
> the following line may crash the program only if finalPolyData or
> GetCellData() is null which should not be the case
> vtkDataArray * pA =finalPolyData->GetCellData()->GetScalars();
>
> your code
>   vtkIntArray* scalarArray =
> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());
> will crash it or produce garbage in the case when currently set scalar
> is not type of vtkIntArray
>
> also even though this is not a reason your code does not work,
> remember the rule: every ::New() has to be paired with Delete() , in your
> code
>
> vtkIntArray* scalars = vtkIntArray::New(); // never will be deleted
>
> so I suggest you to add scalars->Delete() after
>           myPolyData->GetCellData()->SetScalars(scalars);
>

Thenk you!.. I really appreciate your help =)


>
>
>
> >>
> >>
> >> // replace the following line with line above
> >>   vtkIntArray* scalarArray =
> >> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());
> >>
> >
> > This make the program crash, so there is nothng there.
> >
>
>
> On Tue, Aug 7, 2012 at 8:34 AM, Gonzalo Amadio <gonzaloamadio at gmail.com>
> wrote:
> >
> >
> > 2012/8/7 Alex Malyushytskyy <alexmalvtk at gmail.com>
> >>
> >> If both polydata have exactly the same scalars (type, dimensions )
> >> output should have a scalar field.
> >> If it does not , it is a bug.
> >
> >
> > myPolyData->GetNumberOfPoints() = 2421
> > myPolyData->GetNumberOfCells()   = 3010 (so the scalar array for this
> > polydata is the same length)
> >
> > otherPolyData->GetNumberOfPoints() = 574
> > otherPolyData->GetNumberOfCells()   = 524
> >
> >
> >>
> >>
> >> But I doubt it. You do not show all significant code, so
> >> I am not sure these 2 scalars are compatible.
> >
> >
> > What additional information do you need?
> >
> >>
> >>
> >> Did you want 1 scalar value per cell?
> >> If so, could you try to replace
> >>
> >>     vtkIntArray* scalars = vtkIntArray::New();
> >>     scalars->SetNumberOfComponents(1);
> >>     scalars->SetNumberOfValues(myPolyData->GetNumberOfCells());
> >>     scalars->SetNumberOfTuples(myPolyData->GetNumberOfCells());
> >>
> >>  with
> >>
> >>    vtkIntArray* scalars = vtkIntArray::New();
> >>    scalars->SetNumberOfValues( myPolyData->GetNumberOfCells());
> >
> >
> > Yes, I want 1 scalar per cell, I tried this but didn't work.
> >
> >>
> >>
> >> if this does not help, or it is not what you want check what value (
> >> if not null, what type of array ) the following line would return
> >>
> >> vtkDataArray * pA =finalPolyData->GetCellData()->GetScalars();
> >>
> >> // replace the following line with line above
> >>   vtkIntArray* scalarArray =
> >> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());
> >>
> >
> > This make the program crash, so there is nothng there.
> >
> >>
> >> Alex
> >>
> >> On Mon, Aug 6, 2012 at 2:18 AM, Gonzalo Amadio <gonzaloamadio at gmail.com
> >
> >> wrote:
> >> > Yes, what I wanted to mean with "is Strange" is that letting the input
> >> > without appending works fine, so it means that it has its scalars.
> >> > In other words, I printed the scalars of "otherPolyData" and
> >> > "myPolyData"
> >> > before appending, and I obtain desired results. So it means that they
> >> > have
> >> > scalars.
> >> >
> >> > So I don't know what is happening here. Maybe I have to add something
> >> > more
> >> > to satisfy conditions for using the filter, but I don't know.
> >> > Some help?
> >> >
> >> > Thank you!
> >> >
> >> >
> >> >
> >> > 2012/8/3 Alex Malyushytskyy <alexmalvtk at gmail.com>
> >> >>
> >> >> >> appendGreenSubdAndRedBlue->AddInput(otherPolyData);   // what is
> >> >> >> extrange is that if I comment this line, it works fine
> >> >> >> appendGreenSubdAndRedBlue->AddInput(myPolyData);
> >> >>
> >> >> there is nothing strange, if you comment this line there is no
> >> >> modification were made,
> >> >> so output is the same as input.
> >> >>
> >> >> why it removes scalar?
> >> >> otherPolyData probably does not the same scalar. From documentation:
> >> >>
> >> >> "All geometry is extracted and appended, but point and cell
> attributes
> >> >> (i.e., scalars, vectors, normals) are extracted and appended only if
> >> >> all datasets have the point and/or cell attributes available. (For
> >> >> example, if one dataset has point scalars but another does not, point
> >> >> scalars will not be appended.)"
> >> >>
> >> >> Regards,
> >> >>   Alex
> >> >>
> >> >>
> >> >> On Thu, Aug 2, 2012 at 4:25 AM, Gonzalo Amadio
> >> >> <gonzaloamadio at gmail.com>
> >> >> wrote:
> >> >> > 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
> >> >> >
> >> >> > _______________________________________________
> >> >> > 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
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > --------
> >> > Gonzalo Amadio
> >> >
> >> _______________________________________________
> >> 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
> >
> >
> >
> >
> > --
> > --------
> > Gonzalo Amadio
> >
> _______________________________________________
> 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
>



-- 
--------
Gonzalo Amadio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120808/bf45b6e7/attachment.htm>


More information about the vtkusers mailing list