Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ vtk xml writer (vtkImageData) - multiple variables in the same vti file
    primarykey
    data
    text
    <p>I am trying to write data from a uniform grid to a vtk XML file, so that I can render it using Paraview. I would like my output file to contain two variables: one 3-component vector and one scalar value at every point. I have managed to write a .vti file, containing the vectors only, like so:</p> <pre><code>#include &lt;vtkVersion.h&gt; #include &lt;vtkSmartPointer.h&gt; #include &lt;vtkXMLImageDataWriter.h&gt; #include &lt;vtkImageData.h&gt; int main() { int nx = 10, ny = 10, nz = 10; vtkSmartPointer&lt;vtkImageData&gt; imageData = vtkSmartPointer&lt;vtkImageData&gt;::New(); imageData-&gt;SetDimensions(nx, ny, nz); #if VTK_MAJOR_VERSION &lt;= 5 imageData-&gt;SetNumberOfScalarComponents(3); imageData-&gt;SetScalarTypeToDouble(); #else imageData-&gt;AllocateScalars(VTK_DOUBLE, 3); #endif for (int k = 0; k &lt; nz; ++k) { for (int j = 0; j &lt; ny; ++j) { for (int i = 0; i &lt; nx; ++i) { double * voxel = static_cast&lt;double*&gt;(imageData-&gt;GetScalarPointer(i,j,k)); int coord = i + j * nx + k * nx * ny; double t = 0.0; double p = 1.0; voxel[0] = sin(t) * cos(p); voxel[1] = sin(t) * sin(p); voxel[2] = cos(t); } } } vtkSmartPointer&lt;vtkXMLImageDataWriter&gt; writer = vtkSmartPointer&lt;vtkXMLImageDataWriter&gt;::New(); writer-&gt;SetFileName("test.vti"); #if VTK_MAJOR_VERSION &lt;= 5 writer-&gt;SetInputConnection(imageData-&gt;GetProducerPort()); #else writer-&gt;SetInputData(imageData); #endif writer-&gt;Write(); return EXIT_SUCCESS; } </code></pre> <p>How can I add an additional scalar value to every point on the grid?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload