<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi, Paw,<div><br></div><div>I believe the problem is that you are mixing calls for scalars and vectors…</div><div><br></div><div>For scalars you want to use SetNumberOfValues()/SetValue():</div><div><br></div><div>&nbsp; &nbsp; vtkIntArray* temperature = vtkIntArray::New();<br>&nbsp; &nbsp; temperature-&gt;SetName("Temperature");<br>&nbsp; &nbsp; temperature-&gt;SetNumberOfComponents(1);<br>&nbsp; &nbsp; temperature-&gt;SetNumberOfValues(nx*ny*nz);<br>&nbsp; &nbsp; for(int i=0;i&lt;mesh.nn;i++){<br>&nbsp; &nbsp; &nbsp; &nbsp;temperature-&gt;SetValue(i,10); // set everything to 10<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;rgrid-&gt;GetPointData()-&gt;AddArray(temperature);</div><div><br></div><div><br></div><div>For vectors you want to use SetNumberOfTuples()/SetTuple3() (assuming SetNumberOfComponents(3)):</div><div><br></div><div><div>&nbsp; &nbsp; vtkFloatArray* velocity = vtkFloatArray::New();</div><div>&nbsp; &nbsp; velocity-&gt;SetName("Velocity");<br>&nbsp; &nbsp;&nbsp;velocity-&gt;SetNumberOfComponents(3);<br>&nbsp; &nbsp;&nbsp;velocity-&gt;SetNumberOfTuples(nx*ny*nz);<br>&nbsp; &nbsp; for(int i=0;i&lt;mesh.nn;i++){<br>&nbsp; &nbsp; &nbsp; &nbsp;velocity-&gt;SetTuple3(i,10, 10, 10); // set everything to 10<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;rgrid-&gt;GetPointData()-&gt;AddArray(velocity);</div></div><div><br></div><div><br></div><div>I also tend to use GetPointData()-&gt;AddArray() rather than SetScalars()/SetVectors(), which has caused me trouble if I have more than one scalar/vector.</div><div>I don't know if that is necessarily the best practice, but it has worked well for me.</div><div><br></div><div>Hope that helps,</div><div>joe.</div><div><br><div><div>On Apr 2, 2013, at 1:10 PM, Paw Møller wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi,</span><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Using the C++ VTK library for writing an .vtr file, I'm able to create the mesh, but not assign any skalars/vectors to the grid points. This is more or less given in the example file RGrid.cxx.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">But how do I assign values at the mesh-points?</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">Write the mesh:</div><div style="font-family:arial,sans-serif;font-size:13px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>#include &lt;stdio.h&gt;</div>
<div>#include &lt;vtkRectilinearGrid.h&gt;</div><div>#include &lt;vtkXMLRectilinearGridWriter.h&gt;</div><div>#include &lt;vtkDoubleArray.h&gt;</div><div>#include &lt;vtkIntArray.h&gt;</div><div>#include &lt;vtkSmartPointer.h&gt;</div>
<div><br></div><div>int main(){</div><div>&nbsp; int nx = 3, ny = 3, nz = 3;</div><div><br></div><div>&nbsp; // coordinates</div><div>&nbsp; vtkDoubleArray *xCoords = vtkDoubleArray::New();</div><div>&nbsp; for (int i=0; i&lt;nx; i++) xCoords-&gt;InsertNextValue(i);</div>
<div>&nbsp; vtkDoubleArray *yCoords = vtkDoubleArray::New();</div><div>&nbsp; for (int i=0; i&lt;ny; i++) yCoords-&gt;InsertNextValue(i);</div><div>&nbsp; vtkDoubleArray *zCoords = vtkDoubleArray::New();</div><div>&nbsp; for (int i=0; i&lt;nz; i++) zCoords-&gt;InsertNextValue(i);</div>
<div><br></div><div>&nbsp; // The coordinates are assigned to the rectilinear grid.</div><div>&nbsp; vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();</div><div>&nbsp; rgrid-&gt;SetDimensions(nx,ny,nz);</div><div>&nbsp; rgrid-&gt;SetXCoordinates(xCoords);</div>
<div>&nbsp; rgrid-&gt;SetYCoordinates(yCoords);</div><div>&nbsp; rgrid-&gt;SetZCoordinates(zCoords);</div><div><br></div><div>&nbsp; /* Write to file */</div><div>&nbsp; vtkSmartPointer&lt;vtkXMLRectilinearGridWriter&gt;</div><div>&nbsp; &nbsp; writer = vtkSmartPointer&lt;vtkXMLRectilinearGridWriter&gt;::New();</div>
<div>&nbsp; writer-&gt;SetFileName("test.vtr");</div><div><br></div><div>#if VTK_MAJOR_VERSION &lt;= 5</div><div>&nbsp; writer-&gt;SetInput(rgrid);</div><div>#else</div><div>&nbsp; writer-&gt;SetInputData(rgrid);</div><div>#endif</div>
<div>&nbsp; writer-&gt;Write();</div><div><br></div><div>&nbsp; /* clean up */</div><div>&nbsp; xCoords-&gt;Delete();</div><div>&nbsp; yCoords-&gt;Delete();</div><div>&nbsp; zCoords-&gt;Delete();</div><div>&nbsp; rgrid-&gt;Delete();</div><div><br></div>
<div>&nbsp; printf("DONE printing\n");</div><div>}</div><div><br></div></blockquote>For setting values at the mesh-points, I assumed something like:</div><div style="font-family:arial,sans-serif;font-size:13px"><div>
&nbsp; &nbsp; vtkIntArray* temperature = vtkIntArray::New();</div><div>&nbsp; &nbsp; temperature-&gt;SetName("Temperature");</div><div>&nbsp; &nbsp; temperature-&gt;SetNumberOfComponents(1);</div><div>&nbsp; &nbsp; temperature-&gt;SetNumberOfTuples(nx*ny*nz);</div>
<div>&nbsp; &nbsp; for(int i=0;i&lt;mesh.nn;i++){</div><div>&nbsp; &nbsp; &nbsp; &nbsp;temperature-&gt;SetValue(i,10); // set everything to 10</div><div>&nbsp; &nbsp; }</div></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
&nbsp; &nbsp;rgrid-&gt;GetPointData()-&gt;SetScalars(temperature);</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">But that doesn't work. As expected, when looking at&nbsp;<a href="http://www.vtk.org/doc/nightly/html/classvtkRectilinearGrid.html" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkRectilinearGrid.html</a></div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">So how do I set values/vectors for all the points in the mesh.</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">Regards,</div><div style="font-family:arial,sans-serif;font-size:13px">Paw</div></div>
_______________________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView">http://paraview.org/Wiki/ParaView</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.paraview.org/mailman/listinfo/paraview">http://www.paraview.org/mailman/listinfo/paraview</a><br></blockquote></div><br></div></body></html>