<br><br><div class="gmail_quote">2012/8/7 Alex Malyushytskyy <span dir="ltr"><<a href="mailto:alexmalvtk@gmail.com" target="_blank">alexmalvtk@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">> What additional information do you need?<br>
<br>
</div>To see that arrays are compatible you need to show details how both of<br>
them are created, not 1<br>
But you can check this yourself.<br>
As far as I understand having both lines below do not make any sense, leave one<br></blockquote><div><br></div><div>Here you have the code.. it seems long, but it can be read quickly =)</div><div><a href="http://pastie.org/private/ukqsezzfnkuxdsp1cb2jaw">http://pastie.org/private/ukqsezzfnkuxdsp1cb2jaw</a></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
scalars->SetNumberOfValues(myPolyData->GetNumberOfCells());<br>
// scalars->SetNumberOfTuples(myPolyData->GetNumberOfCells());<br>
<br>
Correct way of casting instead of<br>
<div class="im">>> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());<br>
</div>would be<br>
vtkIntArray* _array = vtkIntArray::SafeDownCast( .... );<br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
even though arrays might be created and combined, I am not sure active<br>
scalar would be set.<br>
so I suggested you to check that array exist first:<br>
<br>
finalPolyData->GetCellData()->GetArray( name )<br></blockquote><div><br></div><div>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.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
And if it exist set the active scalar to newly created polydata<br>
finalPolyData->SetActiveScalars( name );<br>
<br>
o guessing does not work usually, so you need to find out what is wrong<br>
<br>
the following line may crash the program only if finalPolyData or<br>
GetCellData() is null which should not be the case<br>
<div class="im">vtkDataArray * pA =finalPolyData->GetCellData()->GetScalars();<br>
<br>
</div>your code<br>
<div class="im"> vtkIntArray* scalarArray =<br>
static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());<br>
</div>will crash it or produce garbage in the case when currently set scalar<br>
is not type of vtkIntArray<br>
<br>
also even though this is not a reason your code does not work,<br>
remember the rule: every ::New() has to be paired with Delete() , in your code<br>
<br>
vtkIntArray* scalars = vtkIntArray::New(); // never will be deleted<br>
<br>
so I suggest you to add scalars->Delete() after<br>
myPolyData->GetCellData()->SetScalars(scalars);<br></blockquote><div><br></div><div>Thenk you!.. I really appreciate your help =)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im HOEnZb"><br>
<br>
<br>
>><br>
>><br>
>> // replace the following line with line above<br>
>> vtkIntArray* scalarArray =<br>
>> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());<br>
>><br>
><br>
> This make the program crash, so there is nothng there.<br>
><br>
<br>
<br>
</div><div class="HOEnZb"><div class="h5">On Tue, Aug 7, 2012 at 8:34 AM, Gonzalo Amadio <<a href="mailto:gonzaloamadio@gmail.com">gonzaloamadio@gmail.com</a>> wrote:<br>
><br>
><br>
> 2012/8/7 Alex Malyushytskyy <<a href="mailto:alexmalvtk@gmail.com">alexmalvtk@gmail.com</a>><br>
>><br>
>> If both polydata have exactly the same scalars (type, dimensions )<br>
>> output should have a scalar field.<br>
>> If it does not , it is a bug.<br>
><br>
><br>
> myPolyData->GetNumberOfPoints() = 2421<br>
> myPolyData->GetNumberOfCells() = 3010 (so the scalar array for this<br>
> polydata is the same length)<br>
><br>
> otherPolyData->GetNumberOfPoints() = 574<br>
> otherPolyData->GetNumberOfCells() = 524<br>
><br>
><br>
>><br>
>><br>
>> But I doubt it. You do not show all significant code, so<br>
>> I am not sure these 2 scalars are compatible.<br>
><br>
><br>
> What additional information do you need?<br>
><br>
>><br>
>><br>
>> Did you want 1 scalar value per cell?<br>
>> If so, could you try to replace<br>
>><br>
>> vtkIntArray* scalars = vtkIntArray::New();<br>
>> scalars->SetNumberOfComponents(1);<br>
>> scalars->SetNumberOfValues(myPolyData->GetNumberOfCells());<br>
>> scalars->SetNumberOfTuples(myPolyData->GetNumberOfCells());<br>
>><br>
>> with<br>
>><br>
>> vtkIntArray* scalars = vtkIntArray::New();<br>
>> scalars->SetNumberOfValues( myPolyData->GetNumberOfCells());<br>
><br>
><br>
> Yes, I want 1 scalar per cell, I tried this but didn't work.<br>
><br>
>><br>
>><br>
>> if this does not help, or it is not what you want check what value (<br>
>> if not null, what type of array ) the following line would return<br>
>><br>
>> vtkDataArray * pA =finalPolyData->GetCellData()->GetScalars();<br>
>><br>
>> // replace the following line with line above<br>
>> vtkIntArray* scalarArray =<br>
>> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());<br>
>><br>
><br>
> This make the program crash, so there is nothng there.<br>
><br>
>><br>
>> Alex<br>
>><br>
>> On Mon, Aug 6, 2012 at 2:18 AM, Gonzalo Amadio <<a href="mailto:gonzaloamadio@gmail.com">gonzaloamadio@gmail.com</a>><br>
>> wrote:<br>
>> > Yes, what I wanted to mean with "is Strange" is that letting the input<br>
>> > without appending works fine, so it means that it has its scalars.<br>
>> > In other words, I printed the scalars of "otherPolyData" and<br>
>> > "myPolyData"<br>
>> > before appending, and I obtain desired results. So it means that they<br>
>> > have<br>
>> > scalars.<br>
>> ><br>
>> > So I don't know what is happening here. Maybe I have to add something<br>
>> > more<br>
>> > to satisfy conditions for using the filter, but I don't know.<br>
>> > Some help?<br>
>> ><br>
>> > Thank you!<br>
>> ><br>
>> ><br>
>> ><br>
>> > 2012/8/3 Alex Malyushytskyy <<a href="mailto:alexmalvtk@gmail.com">alexmalvtk@gmail.com</a>><br>
>> >><br>
>> >> >> appendGreenSubdAndRedBlue->AddInput(otherPolyData); // what is<br>
>> >> >> extrange is that if I comment this line, it works fine<br>
>> >> >> appendGreenSubdAndRedBlue->AddInput(myPolyData);<br>
>> >><br>
>> >> there is nothing strange, if you comment this line there is no<br>
>> >> modification were made,<br>
>> >> so output is the same as input.<br>
>> >><br>
>> >> why it removes scalar?<br>
>> >> otherPolyData probably does not the same scalar. From documentation:<br>
>> >><br>
>> >> "All geometry is extracted and appended, but point and cell attributes<br>
>> >> (i.e., scalars, vectors, normals) are extracted and appended only if<br>
>> >> all datasets have the point and/or cell attributes available. (For<br>
>> >> example, if one dataset has point scalars but another does not, point<br>
>> >> scalars will not be appended.)"<br>
>> >><br>
>> >> Regards,<br>
>> >> Alex<br>
>> >><br>
>> >><br>
>> >> On Thu, Aug 2, 2012 at 4:25 AM, Gonzalo Amadio<br>
>> >> <<a href="mailto:gonzaloamadio@gmail.com">gonzaloamadio@gmail.com</a>><br>
>> >> wrote:<br>
>> >> > Hello everyone. Is there some reason whereby vtkAppendPolyData delete<br>
>> >> > the<br>
>> >> > scalars when I append 2 polydatas?<br>
>> >> ><br>
>> >> > Here is my code.<br>
>> >> ><br>
>> >> >> myPolyData->ShallowCopy(otherPolyData);<br>
>> >> >> SubdividePolyData(myPolyData); /// Here I modified the<br>
>> >> >> polydata,<br>
>> >> >> so I need to assign it again the scalar array.<br>
>> >> >><br>
>> >> >><br>
>> >> >><br>
>> >> >> // The problem I think is here in this lines, where I assign<br>
>> >> >> the<br>
>> >> >> scalar array<br>
>> >> >> vtkIntArray* scalars = vtkIntArray::New();<br>
>> >> >> scalars->SetNumberOfComponents(1);<br>
>> >> >> scalars->SetNumberOfValues(myPolyData->GetNumberOfCells());<br>
>> >> >> scalars->SetNumberOfTuples(myPolyData->GetNumberOfCells());<br>
>> >> >><br>
>> >> >><br>
>> >> >><br>
>> >> >> for (int i = 0; i < myPolyData->GetNumberOfCells(); i++)<br>
>> >> >> scalars->SetValue(i, 1);<br>
>> >> >><br>
>> >> >><br>
>> >> >><br>
>> >> >> myPolyData->GetCellData()->SetScalars(scalars);<br>
>> >> >><br>
>> >> >><br>
>> >> >><br>
>> >> >> vtkSmartPointer<vtkAppendPolyData> appendGreenSubdAndRedBlue<br>
>> >> >> =<br>
>> >> >> vtkSmartPointer<vtkAppendPolyData>::New();<br>
>> >> >> appendGreenSubdAndRedBlue->AddInput(otherPolyData); // what is<br>
>> >> >> extrange<br>
>> >> >> is that if I comment this line, it works fine<br>
>> >> >> appendGreenSubdAndRedBlue->AddInput(myPolyData);<br>
>> >> >> appendGreenSubdAndRedBlue->Update();<br>
>> >> >><br>
>> >> >><br>
>> >> >><br>
>> >> >> vtkPolyData * finalPolyData =<br>
>> >> >> appendGreenSubdAndRedBlue->GetOutput();<br>
>> >> >><br>
>> >> >><br>
>> >> >><br>
>> >> >> vtkIntArray* scalarArray =<br>
>> >> >><br>
>> >> >> static_cast<vtkIntArray*>(finalPolyData->GetCellData()->GetScalars());<br>
>> >> >> std::cout << scalarArray->GetNumberOfTuples() << std::endl;<br>
>> >> >> //This line gives me an error<br>
>> >> ><br>
>> >> ><br>
>> >> ><br>
>> >> > The error that I obtain is the following :<br>
>> >> ><br>
>> >> > File : vtkAbstractArray.h - line 104<br>
>> >> ><br>
>> >> > vtkIdType GetNumberOfTuples()<br>
>> >> > {return (this->MaxId + 1)/this->NumberOfComponents;}<br>
>> >> ><br>
>> >> > error:<br>
>> >> ><br>
>> >> > name type value<br>
>> >> > this vtkAbstractArray * const 0x0<br>
>> >> ><br>
>> >> ><br>
>> >> > I can assign "manually" again the scalars to the finalPolyData, but<br>
>> >> > it<br>
>> >> > is<br>
>> >> > suppose that the scalars remains when I append them.<br>
>> >> ><br>
>> >> > Thank you!<br>
>> >> ><br>
>> >> > --<br>
>> >> > --------<br>
>> >> > Gonzalo<br>
>> >> ><br>
>> >> > _______________________________________________<br>
>> >> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >> ><br>
>> >> > Visit other Kitware open-source projects at<br>
>> >> > <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >> ><br>
>> >> > Please keep messages on-topic and check the VTK FAQ at:<br>
>> >> > <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>> >> ><br>
>> >> > Follow this link to subscribe/unsubscribe:<br>
>> >> > <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>> >> ><br>
>> >> _______________________________________________<br>
>> >> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >><br>
>> >> Visit other Kitware open-source projects at<br>
>> >> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >><br>
>> >> Please keep messages on-topic and check the VTK FAQ at:<br>
>> >> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>> >><br>
>> >> Follow this link to subscribe/unsubscribe:<br>
>> >> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > --<br>
>> > --------<br>
>> > Gonzalo Amadio<br>
>> ><br>
>> _______________________________________________<br>
>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>><br>
>> Visit other Kitware open-source projects at<br>
>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>><br>
>> Please keep messages on-topic and check the VTK FAQ at:<br>
>> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>><br>
>> Follow this link to subscribe/unsubscribe:<br>
>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
><br>
><br>
><br>
> --<br>
> --------<br>
> Gonzalo Amadio<br>
><br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>--------<br>Gonzalo Amadio<br><br>