<!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. <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>
int i, j, k;<br>
vtkXMLWriterC* writer = vtkXMLWriterC_New();<br>
const char filename[] = "cube.vti";<br>
<br>
double origin[3] = {-.5, -.5, -.5};<br>
<br>
double spacing[3] = { 10.0/(NPOINTS-1.0),<br>
10.0/(NPOINTS-1.0),<br>
10.0/(NPOINTS-1.0)};<br>
int extent[6] = {0, NPOINTS-1, 0, NPOINTS-1, 0, NPOINTS-1};<br>
<br>
for(i=0; i<NPOINTS; i++)<br>
{<br>
double x = origin[0]+i*spacing[0];<br>
for(j=0; j<NPOINTS; j++)<br>
{<br>
double y = origin[0]+j*spacing[1];<br>
for(k=0; k<NPOINTS; k++)<br>
{<br>
double z = origin[0]+k*spacing[2];<br>
vectordata[i][j][k][0] = (-10.0 * x + 10.0 * y);<br>
vectordata[i][j][k][1] = (28.0 * x - y - x*z);<br>
vectordata[i][j][k][2] = (-8.0/(3.0*z) + x*y);<br>
}<br>
}<br>
}<br>
<br>
/* #define VTK_IMAGE_DATA 6*/<br>
vtkXMLWriterC_SetDataObjectType(writer, VTK_IMAGE_DATA);<br>
<br>
vtkXMLWriterC_SetExtent(writer, extent);<br>
<br>
vtkXMLWriterC_SetFileName(writer, filename);<br>
<br>
vtkXMLWriterC_SetOrigin(writer, origin);<br>
<br>
vtkXMLWriterC_SetSpacing(writer, spacing);<br>
<br>
vtkXMLWriterC_Start(writer);<br>
<br>
/* #define VTK_FLOAT 10 */<br>
vtkXMLWriterC_SetPointData(writer, "velocity", 10, vectordata,<br>
NPOINTS * NPOINTS * NPOINTS, 3,
"VECTORS");<br>
vtkXMLWriterC_Write(writer);<br>
vtkXMLWriterC_Stop(writer);<br>
vtkXMLWriterC_Delete(writer);<br>
<br>
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>
MESSAGE(FATAL_ERROR "VTK is required. 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>