<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> vtkIntArray* temperature = vtkIntArray::New();<br> temperature->SetName("Temperature");<br> temperature->SetNumberOfComponents(1);<br> temperature->SetNumberOfValues(nx*ny*nz);<br> for(int i=0;i<mesh.nn;i++){<br> temperature->SetValue(i,10); // set everything to 10<br> }<br> rgrid->GetPointData()->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> vtkFloatArray* velocity = vtkFloatArray::New();</div><div> velocity->SetName("Velocity");<br> velocity->SetNumberOfComponents(3);<br> velocity->SetNumberOfTuples(nx*ny*nz);<br> for(int i=0;i<mesh.nn;i++){<br> velocity->SetTuple3(i,10, 10, 10); // set everything to 10<br> }<br> rgrid->GetPointData()->AddArray(velocity);</div></div><div><br></div><div><br></div><div>I also tend to use GetPointData()->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 <stdio.h></div>
<div>#include <vtkRectilinearGrid.h></div><div>#include <vtkXMLRectilinearGridWriter.h></div><div>#include <vtkDoubleArray.h></div><div>#include <vtkIntArray.h></div><div>#include <vtkSmartPointer.h></div>
<div><br></div><div>int main(){</div><div> int nx = 3, ny = 3, nz = 3;</div><div><br></div><div> // coordinates</div><div> vtkDoubleArray *xCoords = vtkDoubleArray::New();</div><div> for (int i=0; i<nx; i++) xCoords->InsertNextValue(i);</div>
<div> vtkDoubleArray *yCoords = vtkDoubleArray::New();</div><div> for (int i=0; i<ny; i++) yCoords->InsertNextValue(i);</div><div> vtkDoubleArray *zCoords = vtkDoubleArray::New();</div><div> for (int i=0; i<nz; i++) zCoords->InsertNextValue(i);</div>
<div><br></div><div> // The coordinates are assigned to the rectilinear grid.</div><div> vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();</div><div> rgrid->SetDimensions(nx,ny,nz);</div><div> rgrid->SetXCoordinates(xCoords);</div>
<div> rgrid->SetYCoordinates(yCoords);</div><div> rgrid->SetZCoordinates(zCoords);</div><div><br></div><div> /* Write to file */</div><div> vtkSmartPointer<vtkXMLRectilinearGridWriter></div><div> writer = vtkSmartPointer<vtkXMLRectilinearGridWriter>::New();</div>
<div> writer->SetFileName("test.vtr");</div><div><br></div><div>#if VTK_MAJOR_VERSION <= 5</div><div> writer->SetInput(rgrid);</div><div>#else</div><div> writer->SetInputData(rgrid);</div><div>#endif</div>
<div> writer->Write();</div><div><br></div><div> /* clean up */</div><div> xCoords->Delete();</div><div> yCoords->Delete();</div><div> zCoords->Delete();</div><div> rgrid->Delete();</div><div><br></div>
<div> 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>
vtkIntArray* temperature = vtkIntArray::New();</div><div> temperature->SetName("Temperature");</div><div> temperature->SetNumberOfComponents(1);</div><div> temperature->SetNumberOfTuples(nx*ny*nz);</div>
<div> for(int i=0;i<mesh.nn;i++){</div><div> temperature->SetValue(i,10); // set everything to 10</div><div> }</div></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
rgrid->GetPointData()->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 <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>