[vtkusers] Re: How to re-render on input data updates
Andy Treisch
Andy.Treisch at gmx.de
Tue Sep 12 13:30:25 EDT 2006
Thanks for your tip but that doesn't seem to fit my needs. Some more detail
on my program:
The window creation routine ending up in the usual iren->Start(); is created
in a new thread
by the windows API call CreateThread. It creates the window and I can
interact with it while
my main program can continue to do some more things. When data changes, I
call the following:
vtkDoubleArray* z_data = vtkDoubleArray::New();
imagedata->SetDimensions(d.xDim, d.yDim, 1);
for (int i = 0; i < (d.yDim * d.xDim); ++i) {
z_data->InsertNextValue(d.z_matrix[i]);
}
imagedata->GetPointData()->SetScalars(z_data);
imagedata->Update(); //inserted at your advice
mapper->Update();
z_data->Delete();
Now I call the upper code but nothing happens in the output window. Even
when I interact
with it, there's no reaction (ok, there's a point flickering somewhere in
the window). Before
I inserted the Update() line, the above code was an extra function which I
set in a
vtkCallbackCommand and added via the AddObserver method of
vtkRenderWindowInteractor.
when I did this and used vtkCommand::LeftButtonPressEvent as Event, the
window updates
whenever I click with the mouse in it and shows my output as I expected. But
if I change the Event
to a vtkCommand::UserEvent and execute iren->InvokeEvent instead of the
above code, the
observer won't be called.
Some more source code:
//This is the function which creates my window
DWORD WINAPI plotWindow(LPVOID lParam) {
//all variables used here are defined global
imagedata = vtkImageData::New();
imagedata->SetDimensions(1,1,1);
imgfilt = vtkImageDataGeometryFilter::New();
imgfilt->SetInput(imagedata);
warp = vtkWarpScalar::New();
warp->SetInputConnection(imgfilt->GetOutputPort());
mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(warp->GetOutputPort());
actor = vtkActor::New();
actor->SetMapper(mapper);
ren = vtkRenderer::New();
ren->AddActor(actor);
renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
callback = vtkCallbackCommand::New();
callback->SetCallback(updateFieldData);
iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
eventid = iren->AddObserver(vtkCommand::UserEvent, callback, 1.0);
iren->Initialize();
iren->Start();
return 0;
}
//the above function is executed in my program via the following line of
code:
void main() {
//... some code here
hThread = CreateThread(NULL, 0, plotWindow, &dwThirdParam, 0, &dwThreadId);
//some more code...
}
//the updateFieldData function, which is used as Observer function is the
following one:
static void updateFieldData(vtkObject*, unsigned long, void*, void*) {
//z_data is a local variable to create a vtkDoubleArray from my data struct
//the other vars are declared global
vtkDoubleArray* z_data = vtkDoubleArray::New();
imagedata->SetDimensions(d.xDim, d.yDim, 1);
for (int i = 0; i < (d.yDim * d.xDim); ++i) {
z_data->InsertNextValue(d.z_matrix[i]);
}
imagedata->GetPointData()->SetScalars(z_data);
imagedata->Update();
mapper->Update();
z_data->Delete();
}
//theres an event which occurs, when new input data is arrived, it executes
a function
//where I inserted the code to update the render window
(eventfcn) {
//... other stuff processing the data
d = data; //used to access the data via updateFieldData data is a class
member, I assign its content to the global var d
iren->InvokeEvent(eventid);
//I also tried iren->InvokeEvent(vtkCommand::UserEvent) but the
updateFieldData function will neither be called
//instead of the above line I tried to call updateFieldData directly but
that gives results as described above in the text
//... other stuff processing the data
}
"Marc Cotran" <marc at cotran.ca> schrieb im Newsbeitrag
news:4506C621.2030306 at cotran.ca...
> You might need to force your vtkImageData to update via a call to
> vtkImageData::Update() once you add the new scalars. If the rest of the
> pipeline doesn't update automatically, try updating a downstream pipeline
> object (your mapper) as well.
>
> hth
>
> Marc
> _______________________________________________
> This is the private VTK discussion list. Please keep messages on-topic.
> Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list