<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<a class="moz-txt-link-abbreviated" href="mailto:deusexcomputer@gmail.com">deusexcomputer@gmail.com</a> wrote:
<blockquote
 cite="mid5bc5869e0701220834y15882990g44de6c3b98475a4@mail.gmail.com"
 type="cite">I have trying to write out a vtk file with a custom cpp
function
  <br>
however I am unsure of how to format a file for vector data.&nbsp; <br>
</blockquote>
I suggest the following source code example, which you can test and
then adapt to your own needs.<br>
<br>
#include "vtkXMLWriterC.h"<br>
#include "vtkType.h"<br>
<br>
#define NPOINTS 20<br>
<br>
float vectordata[NPOINTS][NPOINTS][NPOINTS][3];<br>
<br>
int main()<br>
{<br>
&nbsp; int i, j, k;<br>
&nbsp; vtkXMLWriterC* writer = vtkXMLWriterC_New();<br>
&nbsp; const char filename[] = "cube.vti";<br>
<br>
&nbsp; double origin[3] = {-.5, -.5, -.5};<br>
<br>
&nbsp; double spacing[3] = { 10.0/(NPOINTS-1.0),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10.0/(NPOINTS-1.0),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10.0/(NPOINTS-1.0)};<br>
&nbsp; int extent[6] = {0, NPOINTS-1, 0, NPOINTS-1, 0, NPOINTS-1};<br>
<br>
&nbsp; for(i=0; i&lt;NPOINTS; i++)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; double x = origin[0]+i*spacing[0];<br>
&nbsp;&nbsp;&nbsp; for(j=0; j&lt;NPOINTS; j++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double y = origin[0]+j*spacing[1];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(k=0; k&lt;NPOINTS; k++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double z = origin[0]+k*spacing[2];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vectordata[i][j][k][0] = (-10.0 * x + 10.0 * y);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vectordata[i][j][k][1] = (28.0 * x - y - x*z);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vectordata[i][j][k][2] = (-8.0/(3.0*z) + x*y);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp; /* #define VTK_IMAGE_DATA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6*/<br>
&nbsp; vtkXMLWriterC_SetDataObjectType(writer, VTK_IMAGE_DATA);<br>
<br>
&nbsp; vtkXMLWriterC_SetExtent(writer, extent);<br>
<br>
&nbsp; vtkXMLWriterC_SetFileName(writer, filename);<br>
<br>
&nbsp; vtkXMLWriterC_SetOrigin(writer, origin);<br>
<br>
&nbsp; vtkXMLWriterC_SetSpacing(writer, spacing);<br>
<br>
&nbsp; vtkXMLWriterC_Start(writer);<br>
<br>
&nbsp; /* #define VTK_FLOAT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10 */<br>
&nbsp; vtkXMLWriterC_SetPointData(writer, "velocity", 10, vectordata,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NPOINTS * NPOINTS * NPOINTS, 3,
"VECTORS");<br>
&nbsp; vtkXMLWriterC_Write(writer);<br>
&nbsp; vtkXMLWriterC_Stop(writer);<br>
&nbsp; vtkXMLWriterC_Delete(writer);<br>
<br>
&nbsp; return 0;<br>
}<br>
<br>
Compilation is trivial if you have cmake installed. The CMakeLists.txt
file would look like this:<br>
<br>
PROJECT(CUBEIO)<br>
FIND_PACKAGE(VTK)<br>
IF(NOT VTK_FOUND)<br>
&nbsp; MESSAGE(FATAL_ERROR "VTK is required.&nbsp; Set VTK_DIR.")<br>
ENDIF(NOT VTK_FOUND)<br>
INCLUDE(${VTK_USE_FILE})<br>
ADD_EXECUTABLE(WriteCube WriteCube.c)<br>
LINK_DIRECTORIES(${PROJECT_SOURCE_DIR})<br>
TARGET_LINK_LIBRARIES(WriteCube vtkIO)<br>
<br>
Enjoy<br>
<div class="moz-signature">-- <br>
<img src="cid:part1.05060306.03050900@cscs.ch" border="0"></div>
</body>
</html>