[vtkusers] Problem with SimpleImageToImageFilter Implementation

Christian Werner christian.werner at rwth-aachen.de
Thu Feb 11 11:33:36 EST 2010


Hello!

I used the vtkSimpleImageToImageFilter to make a nifty little 
segmentation to get started. Below is how I overwrote the SimpleExecute 
function. It looks good and actually does the job, at least in a 
Reader>MyFilter>Writer setup. But if its passed to a vtkTexturePainter I 
get a warning that comes from the function

int vtkTexturePainter::SetupScalars(vtkImageData* input) ...

Warning: In /opt/ParaView3/Servers/Filters/vtkTexturePainter.cxx, line 173
vtkTexturePainter (0x1a34fd0): Failed to locate selected scalars. Will 
use image scalars by default.


What is displayed then (this is all with Paraview by the way) is an 
image which is indeed segmented as meant, but it has strange colors. The 
background color of the image mysteriously gets the background color of 
the 2d viewer (but should be 0/black), and the foreground color (which 
should be white) is some ugly pink, or green, now that I tried again. 
Also Paraview does not seem to have information about the data array, at 
least its not listed where as there IS information on the original 
image: DataType: unsigned char, Data Ranges[0,255]...


Here is my code:


void vtkDislev::SimpleExecute(vtkImageData* input, vtkImageData* output)
{
    if (input==NULL) {
    vtkErrorMacro(<<"Bad Input to vtkDislev");
    return;
    }
   
    int dim[3];
    input->GetDimensions(dim);
    int numvox  = dim[0]*dim[1]*dim[2];
    int numcomp = input->GetNumberOfScalarComponents();
   
    vtkDataArray* inarray  = input->GetPointData()->GetScalars();
    vtkDataArray* outarray = output->GetPointData()->GetScalars();
   
    unsigned char in=255;
    unsigned char out=0;
    for (int component=0; component < numcomp; component++) {
    for (int i=0; i < numvox; i++) {
        unsigned char v=inarray->GetComponent(i,component);
        if (v >= this->LowerThreshold && v<=this->UpperThreshold) {
        outarray->SetComponent(i,component,in);
        } else {
        outarray->SetComponent(i,component,out);       
        }
    }
    }
}


Anyone any idea?

Best regards,
Christian



More information about the vtkusers mailing list