I have a VTK app that is extremely slow due to some setup/cleanup work,
and I'ld like to multiprocess those steps, as they should be very
trivial. Can someone show me how this is done with VTK?<br>
<br>
My setup code is like the following:<br>
(first setup a vtkDataSetReader & load the data)<br>
if ((data = (double*)malloc(sizeof(double)*bins*bins*bins)) == NULL) {<br>
perror("Unable to allocate memory!\n\t");<br>
return -1;<br>
}<br>
vtkDoubleArray *velarray = static_cast<vtkDoubleArray *><br>
(reader->GetOutput()->GetPointData()->GetArray("Velocity"));<br>
printf("Using array: %s\n", velarray->GetName());<br>
for(id=0; id < reader->GetOutput()->GetNumberOfPoints(); id++) {<br>
velarray->GetTupleValue(id, velocity);<br>
data[id] = velocity[0];<br>
}<br>
reader->Delete();<br>
vtkDoubleArray *ucPointer = vtkDoubleArray::New();<br>
ucPointer->SetNumberOfComponents(1);<br>
ucPointer->SetArray(data, bins*bins*bins, 1);<br>
ucPointer->SetName("Velocity");<br>
<br>
vtkImageData *image = vtkImageData::New();<br>
image->Initialize();<br>
image->SetDimensions(bins,bins,bins);<br>
image->SetExtent(1, bins, 1, bins, 1, bins);<br>
image->SetScalarTypeToDouble();<br>
image->SetNumberOfScalarComponents(1);<br>
image->GetPointData()->SetScalars(ucPointer);<br>
<br>
ucPointer->Delete();<br>
Essentially, I just create a vtkImageData of the 1 field from the dataset that I want.<br>
<br>
Then I do all my computations, and at the end:<br>
<br>
vtkDoubleArray *fftMag = static_cast<vtkDoubleArray *><br>
(fft->GetOutput()->GetPointData()->GetArray("Velocity"));<br>
for(id=0; id < fft->GetOutput()->GetNumberOfPoints(); id++) {<br>
fft->GetOutput()->GetPoint(id, xyz);<br>
xpos = xyz[0];<br>
if ((xyz[1] <= halfbins) && (xyz[0] <= halfbins)) {<br>
fftMag->GetTupleValue(id, val);<br>
sums[xpos] += ((val[0]*val[0]) + (val[1]*val[1]));<br>
}<br>
}<br>
<br>
Here I take the output of all the FFT & computational stuff, and
create a simple 1-D array which is written to a text file on disk later.<br>
<br>
Both of these should be prime candidates for multithreading. Any suggestions?<br>
<br clear="all"><br>-- <br>Randall Hand<br>Visualization Scientist, <br>ERDC-MSRC Vicksburg, MS<br>Homepage: <a href="http://www.yeraze.com">http://www.yeraze.com</a>