[vtkusers] newbie VTK file format for vector data
fred
fredmfp at gmail.com
Thu Feb 1 13:50:57 EST 2007
Jean Favre wrote:
> deusexcomputer at gmail.com wrote:
>> I have trying to write out a vtk file with a custom cpp function
>> however I am unsure of how to format a file for vector data.
> I suggest the following source code example, which you can test and
> then adapt to your own needs.
>
> #include "vtkXMLWriterC.h"
> #include "vtkType.h"
>
> #define NPOINTS 20
>
> float vectordata[NPOINTS][NPOINTS][NPOINTS][3];
>
> int main()
> {
> int i, j, k;
> vtkXMLWriterC* writer = vtkXMLWriterC_New();
> const char filename[] = "cube.vti";
>
> double origin[3] = {-.5, -.5, -.5};
>
> double spacing[3] = { 10.0/(NPOINTS-1.0),
> 10.0/(NPOINTS-1.0),
> 10.0/(NPOINTS-1.0)};
> int extent[6] = {0, NPOINTS-1, 0, NPOINTS-1, 0, NPOINTS-1};
>
> for(i=0; i<NPOINTS; i++)
> {
> double x = origin[0]+i*spacing[0];
> for(j=0; j<NPOINTS; j++)
> {
> double y = origin[0]+j*spacing[1];
> for(k=0; k<NPOINTS; k++)
> {
> double z = origin[0]+k*spacing[2];
> vectordata[i][j][k][0] = (-10.0 * x + 10.0 * y);
> vectordata[i][j][k][1] = (28.0 * x - y - x*z);
> vectordata[i][j][k][2] = (-8.0/(3.0*z) + x*y);
> }
> }
> }
>
> /* #define VTK_IMAGE_DATA 6*/
> vtkXMLWriterC_SetDataObjectType(writer, VTK_IMAGE_DATA);
>
> vtkXMLWriterC_SetExtent(writer, extent);
>
> vtkXMLWriterC_SetFileName(writer, filename);
>
> vtkXMLWriterC_SetOrigin(writer, origin);
>
> vtkXMLWriterC_SetSpacing(writer, spacing);
>
> vtkXMLWriterC_Start(writer);
>
> /* #define VTK_FLOAT 10 */
> vtkXMLWriterC_SetPointData(writer, "velocity", 10, vectordata,
> NPOINTS * NPOINTS * NPOINTS, 3, "VECTORS");
> vtkXMLWriterC_Write(writer);
> vtkXMLWriterC_Stop(writer);
> vtkXMLWriterC_Delete(writer);
>
> return 0;
> }
>
> Compilation is trivial if you have cmake installed. The CMakeLists.txt
> file would look like this:
>
> PROJECT(CUBEIO)
> FIND_PACKAGE(VTK)
> IF(NOT VTK_FOUND)
> MESSAGE(FATAL_ERROR "VTK is required. Set VTK_DIR.")
> ENDIF(NOT VTK_FOUND)
> INCLUDE(${VTK_USE_FILE})
> ADD_EXECUTABLE(WriteCube WriteCube.c)
> LINK_DIRECTORIES(${PROJECT_SOURCE_DIR})
> TARGET_LINK_LIBRARIES(WriteCube vtkIO)
>
>
Hi,
I tested it.
But
cmake .
fails:
CMake Error: Error in cmake code at
/usr/share/cmake-2.4/Modules/UseVTKConfig40.cmake:21:
LOAD_CACHE Cannot load cache file from
/usr/bin/../lib/vtk-5.0/CMakeCache.txt
Current CMake stack:
/home/fred/tmp/vtktest/tmp/CMakeLists.txt;/usr/share/cmake-2.4/Modules/CMakeCInformation.cmake;/usr/share/cmake-2.4/Modules/CMakeCXXInformation.cmake;/usr/share/cmake-2.4/Modules/FindVTK.cmake;/usr/share/cmake-2.4/Modules/UseVTKConfig40.cmake
-- Configuring done
Why does it looks for CMakeCache.txt in /usr/bin/../lib/vtk-5.0/ ??
What's wrong ?
Cheers,
--
/F
More information about the vtkusers
mailing list