<br><br><div class="gmail_quote">2012/8/7 Alex Malyushytskyy <span dir="ltr">&lt;<a href="mailto:alexmalvtk@gmail.com" target="_blank">alexmalvtk@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

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