Well, I'm building a vtkDoubleArray, and the vtkArrayCalculator claims
it's returning a vtkDoubleArray.. So that shouldn't be the case in this
situation.<br><br><div><span class="gmail_quote">On 9/14/05, <b class="gmail_sendername">Berk Geveci</b> <<a href="mailto:berk.geveci@gmail.com">berk.geveci@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This is a guess but if the array calculator outputs a data type than<br>the input's scalars, no imaging filter can be used down the pipeline.<br>This is a known bug. Essentially no (non-imaging) filter that changes<br>the data type of the scalars is allowed in a pipeline with imaging
<br>filters. There is work (slow) going on to fix this issue. I would not<br>hold my breath for it's completion.<br><br>On 9/14/05, Randall Hand <<a href="mailto:randall.hand@gmail.com">randall.hand@gmail.com</a>> wrote:
<br>> Ok, I posted this once before, but here it is again with some more<br>> information.<br>><br>> I've written a piece of code to create a synthetic dataset. It's a 128^3<br>> dataset, each point with a 3-component double value consisting of (sin(x),
<br>> junk, morejunk). I extract just the first component, and do an FFT. You'll<br>> find the code at the end of this message, along with my "PrintStatistics"<br>> function attached.<br>><br>> You'll see from the #if/#endif blocks that there's two possible ways to do
<br>> it. The first is with a vtkArrayCalculator, where I set a very trivial<br>> function to simply copy out the one value. The other way is with a<br>> vtkImageExtractComponents. When doing it with the vtkArrayCalculator, the
<br>> filter seems to work just fine but then the FFT yields values like :<br>><br>> p Array [0]: vtkDoubleArray "result", 2,097,152 points, 8 bytes per<br>> point<br>> p
Magnitude
Range: 0.0000 1482912.5793<br>> p
Component 0 Range: -1048575.9848<br>> 1048575.8760<br>> p
Component 1 Range: -1048572.9243<br>> 1048579.0968<br>> With a simple sin wave, the result should be almost purely imaginary, so<br>> the Component 0 range should be almost 0 to 0.<br>><br>> When I switch to using the vtkImageExtractComponents, the results look
<br>> better:<br>><br>><br>> p Array [0]: vtkDoubleArray "image", 2,097,152 points, 8 bytes per<br>> point<br>> p
Magnitude
Range: 0.0000 1048576.0091<br>> p
Component 0 Range: -0.0557 0.0011<br>> p
Component 1 Range: -1048576.0089<br>> 1048576.0091<br>><br>><br>> Unfortunately, when working with the vtkImageExtractComponents filter, I<br>> lose the other two fields if I had planned on using them for coloring or
<br>> something. Also, my results aren't quite what I expected. Much better, but<br>> on more complex datasets I seem to get results that are a little off from<br>> the expected result. I don't know if the cause of all this is related, but
<br>> I'm chasing down what I can.<br>><br>> So, any ideas?<br>><br>> ----- Code starts here -------<br>><br>> #include <stdio.h><br>> #include <string.h><br>> #include <stdlib.h
><br>> #include <unistd.h><br>> #include "stat.h"<br>> #include <sys/types.h><br>> #include <sys/stat.h><br>> #include <sys/mman.h><br>> #include <fcntl.h>
<br>> #include <vtkObject.h><br>> #include "vtkImageData.h"<br>> #include "vtkPointData.h"<br>> #include <vtkDataArray.h><br>> #include <vtkUnsignedCharArray.h><br>
> #include <vtkDoubleArray.h><br>> #include <vtkImageData.h><br>> #include <vtkImageFFT.h><br>> #include <vtkArrayCalculator.h><br>> #include <vtkImageExtractComponents.h>
<br>><br>> int main (int argc, char *argv[])<br>> {<br>> double *data;<br>> int xdim, ydim, zdim;<br>> double kx;<br>> int x,y,z;<br>> long index;<br>> xdim = 128;
<br>> ydim = 128;<br>> zdim = 128;<br>><br>> if ((data =<br>> (double*)malloc(sizeof(double)*xdim*ydim*zdim*3)) == NULL)<br>> {<br>> perror("Unable to allocate memory!\n\t");
<br>> return -1;<br>> }<br>><br>> printf("Constructing sin(kx * x) dataset...\n");<br>> kx = 2.0 * 3.1415926 / (double)xdim;<br>> for(x=0; x<xdim; x++) {<br>> for(y=0; y<ydim; y++) {
<br>> for(z=0; z<zdim; z++) {<br>> index
= z + (y*zdim) + (x * ydim * zdim);<br>> data[(index*3)+0]
= sin(kx * (double)x);<br>> data[(index*3)+1]
= cos(kx * (double)x);<br>> data[(index*3)+2]
= tan(kx * (double)x);<br>> }<br>> }<br>> }<br>><br>> vtkDoubleArray *ucPointer = vtkDoubleArray::New();<br>> ucPointer->SetNumberOfComponents(3);<br>> ucPointer->SetArray(data, xdim*ydim*zdim*3, 1);
<br>> ucPointer->SetName("image");<br>><br>> vtkImageData *image = vtkImageData::New();<br>> image->Initialize();<br>> image->SetDimensions(xdim, ydim, zdim);<br>> image->SetExtent(1, xdim, 1, ydim, 1, zdim);
<br>> image->SetScalarTypeToDouble();<br>> image->SetNumberOfScalarComponents(3);<br>> image->GetPointData()->SetScalars(ucPointer);<br>> PrintStatistics(image);<br>> printf("Extracting Velocity X-Component...\n");
<br>><br>> #if 0<br>> vtkArrayCalculator *extract = vtkArrayCalculator::New();<br>> extract->SetInput(image);<br>> extract->SetResultArrayName("result");<br>> extract->AddScalarVariable("x", "image", 0);
<br>> extract->SetFunction("(x*1.0)+0.0");<br>> extract->ReplaceInvalidValuesOff();<br>> extract->Update();<br>><br>> extract->GetOutput()->GetPointData()->RemoveArray("image");
<br>><br>> extract->GetOutput()->GetPointData()->SetActiveScalars("result");<br>> #else<br>> vtkImageExtractComponents *extract =<br>> vtkImageExtractComponents::New();<br>> extract->SetInput(image);
<br>> extract->SetComponents(0);<br>> extract->Update();<br>> #endif<br>> PrintStatistics(extract->GetOutput());<br>><br>> printf("Computing FFT...\n");<br>> vtkImageFFT *fft = vtkImageFFT::New();
<br>> fft->SetInput(extract->GetOutput());<br>> fft->Update();<br>> PrintStatistics(fft->GetOutput());<br>><br>> }<br>><br>><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><br>> _______________________________________________<br>> vtk-developers mailing list<br>> <a href="mailto:vtk-developers@vtk.org">
vtk-developers@vtk.org</a><br>> <a href="http://www.vtk.org/mailman/listinfo/vtk-developers">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>><br>><br>><br>><br></blockquote></div><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>