<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div>Hallo VTK-Gurus,</div>
<div> </div>
<div>I’m trying to do the following: read in a list of 2D-coordinates representing a Kármán vortex street.<br/>
I use the normaly VectorField example from vtk http://www.vtk.org/Wiki/VTK/Examples/Cxx/WishList/Visualization/VectorField.<br/>
The data-file is an ASCII Data for the Vektorfield and looks like:<br/>
</div>
<div>x y<br/>
0.000000 0.010754<br/>
0.149071 0.126791<br/>
0.164137 0.197936<br/>
0.157218 0.216444<br/>
.....</div>
<div> </div>
<div>The read-data is saved in an array.</div>
<div>In the for-loop in which the study area is initialized is additionally a for-loop which reads the data at the array.</div>
<div>The above-described looks like this in c++ code :<br/>
</div>
<div><br/>
#include <vtkVersion.h><br/>
#include <vtkArrowSource.h><br/>
#include <vtkCellArray.h><br/>
#include <vtkGlyph2D.h><br/>
#include <vtkPointData.h><br/>
#include <vtkImageData.h><br/>
#include <vtkImageSliceMapper.h><br/>
#include <vtkImageSlice.h><br/>
#include <vtkInteractorStyleImage.h><br/>
#include <vtkPolyDataMapper.h><br/>
#include <vtkPolyData.h><br/>
#include <vtkPoints.h><br/>
#include <vtkRenderer.h><br/>
#include <vtkRenderWindow.h><br/>
#include <vtkRenderWindowInteractor.h><br/>
#include <vtkSmartPointer.h><br/>
#include <vtkXMLPolyDataWriter.h></div>
<div>#include <iostream><br/>
#include <string><br/>
#include <fstream><br/>
#include <cstdlib><br/>
#include <sstream></div>
<div>using namespace std;</div>
<div>int main()<br/>
{<br/>
ifstream Data("data_example.dat"); </div>
<div> int anzahlXY = 200*75; //X_DIM*Y_DIM;<br/>
double wert_X;<br/>
double wert_Y;<br/>
<br/>
int *array_x = new int[anzahlXY];<br/>
int *array_y = new int[anzahlXY];<br/>
<br/>
for(int line = 0; Data >> wert_X >> wert_Y; line++) <br/>
{<br/>
array_x[line] = wert_X;<br/>
array_y[line] = wert_Y;</div>
<div> }<br/>
Data.close();<br/>
<br/>
<br/>
// Create an image<br/>
vtkSmartPointer<vtkImageData> image =<br/>
vtkSmartPointer<vtkImageData>::New();<br/>
image->SetDimensions(200,75,1); <br/>
<br/>
#if VTK_MAJOR_VERSION <= 5<br/>
image->SetNumberOfScalarComponents(3); //ok or 3<br/>
image->SetScalarTypeToFloat();<br/>
image->AllocateScalars();<br/>
#else<br/>
image->AllocateScalars(VTK_FLOAT,3); // image->AllocateScalars(VTK_FLOAT,2);<br/>
#endif<br/>
int* dims = image->GetDimensions();<br/>
<br/>
<br/>
// Zero the image<br/>
for(int y = 0; y < dims[1]; y++)<br/>
{<br/>
for(int x = 0; x < dims[0]; x++)<br/>
{<br/>
for (int i = 0; i < anzahlXY; i++)<br/>
{<br/>
float* pixel = static_cast<float*>(image->GetScalarPointer(x,y,0));<br/>
pixel[0] = array_x[i]; <br/>
pixel[1] = array_y[i];<br/>
pixel[2] = 0.;<br/>
}<br/>
}<br/>
}<br/>
<br/>
// A better way to do this is (should be tested for compilablilty and correctness):<br/>
// image->GetPointData()->SetActiveVectors(image->GetPointData()->GetScalars()->GetName().c_str());<br/>
<br/>
image->GetPointData()->SetActiveVectors("ImageScalars");<br/>
<br/>
// Setup the arrows<br/>
vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New();<br/>
arrowSource->Update(); //?????<br/>
<br/>
vtkSmartPointer<vtkGlyph2D> glyphFilter = vtkSmartPointer<vtkGlyph2D>::New();<br/>
glyphFilter->SetSourceConnection(arrowSource->GetOutputPort());<br/>
glyphFilter->OrientOn(); //Richtung<br/>
glyphFilter->SetVectorModeToUseVector();<br/>
#if VTK_MAJOR_VERSION <= 5<br/>
glyphFilter->SetInputConnection(image->GetProducerPort());<br/>
#else<br/>
glyphFilter->SetInputData(image);<br/>
#endif<br/>
glyphFilter->Update(); <br/>
<br/>
// Create actors<br/>
vtkSmartPointer<vtkImageSliceMapper> imageMapper = vtkSmartPointer<vtkImageSliceMapper>::New();<br/>
#if VTK_MAJOR_VERSION <= 5<br/>
imageMapper->SetInputConnection(image->GetProducerPort());<br/>
#else<br/>
imageMapper->SetInputData(image);<br/>
#endif<br/>
<br/>
vtkSmartPointer<vtkImageSlice> imageSlice = vtkSmartPointer<vtkImageSlice>::New();<br/>
imageSlice->SetMapper(imageMapper);<br/>
<br/>
vtkSmartPointer<vtkPolyDataMapper> vectorMapper = vtkSmartPointer<vtkPolyDataMapper>::New();<br/>
vectorMapper->SetInputConnection(glyphFilter->GetOutputPort());<br/>
vtkSmartPointer<vtkActor> vectorActor = vtkSmartPointer<vtkActor>::New();<br/>
vectorActor->SetMapper(vectorMapper);<br/>
<br/>
// Setup renderer<br/>
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();<br/>
renderer->AddViewProp(imageSlice);<br/>
renderer->AddViewProp(vectorActor);<br/>
renderer->ResetCamera();<br/>
<br/>
// Setup render window<br/>
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();<br/>
renderWindow->AddRenderer(renderer);<br/>
<br/>
renderWindow->SetSize(500, 500);<br/>
<br/>
// Setup render window interactor<br/>
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();<br/>
vtkSmartPointer<vtkInteractorStyleImage> style = vtkSmartPointer<vtkInteractorStyleImage>::New();<br/>
//renderWindowInteractor->SetInteractorStyle(style);<br/>
<br/>
// Render and start interaction<br/>
renderWindowInteractor->SetRenderWindow(renderWindow);<br/>
renderWindowInteractor->Initialize();<br/>
<br/>
<br/>
renderWindowInteractor->Start();<br/>
<br/>
return EXIT_SUCCESS;<br/>
}</div>
<div> </div>
<div> </div>
<div>My output is only a black image! No error or warning message, nothing. <br/>
</div>
<div>What is wrong? Can anyone help?</div>
<div>Thank you very much in advance.</div>
<div>N.Y.</div>
<div> </div>
</div></div></body></html>