<p>If reader executes after you assigned the vectors, the array will be discarded. Try making a shallow copy of reader's output, add your array, and visualize that instead.</p>
<div class="gmail_quote">On Jan 22, 2012 5:06 AM, "Martijn Steenwijk" <<a href="mailto:martijnsteenwijk@gmail.com">martijnsteenwijk@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal">Dear all,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I would like to assign vectors to a vtkImageData which already contains scalars which will be used for coloring. I’m using the code as below:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">vtkImageData *im = reader->GetOutput();<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none">
<span style="font-size:9.5pt;font-family:Consolas">vtkSmartPointer<vtkFloatArray> vec = <u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> vtkSmartPointer<vtkFloatArray>::New();<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">vec->SetName(<span style="color:#a31515">"v1"</span>);<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none">
<span style="font-size:9.5pt;font-family:Consolas">vec->SetNumberOfComponents(3);<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">for</span><span style="font-size:9.5pt;font-family:Consolas">(<span style="color:blue">int</span> i = 0; i< im->GetDimensions()[0]; i++)<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> {<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> std::cout << i << std::endl;<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> <span style="color:blue">for</span>(<span style="color:blue">int</span> j = 0; j< im->GetDimensions()[1]; j++)<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> {<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> <span style="color:blue">for</span>(<span style="color:blue">int</span> k = 0; k< im->GetDimensions()[2]; k++) <span style="color:green">// assign dummy vectors (1,1,1)</span><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> {<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> <span style="color:blue">float</span> tuple[3];<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> tuple[0] = (<span style="color:blue">float</span>)1.0;<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none">
<span style="font-size:9.5pt;font-family:Consolas"> tuple[1] = (<span style="color:blue">float</span>)1.0;<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> tuple[2] = (<span style="color:blue">float</span>)1.0;<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> vec->InsertNextTuple(tuple);<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none">
<span style="font-size:9.5pt;font-family:Consolas"> }<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> }<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">im->GetPointData()->SetVectors(vec);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">im->GetPointData()->SetActiveVectors(<span style="color:#a31515">"v1"</span>);<u></u><u></u></span></p><p class="MsoNormal" style="text-autospace:none">
<span style="font-size:9.5pt;font-family:Consolas"><u></u> <u></u></span></p><p class="MsoNormal">When I try to visualise the vector field by using vtkHedgeHog now, VTK complains that ‘vtkHedgeHog (0000000003C0D9B0): No vectors in input data’. Does somebody has a clue why?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Best,<u></u><u></u></p><p class="MsoNormal">Martijn<u></u><u></u></p><p class="MsoNormal"><span lang="NL"><u></u> <u></u></span></p></div></div><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>
<br></blockquote></div>