[vtkusers] Problem with SimpleImageToImageFilter Implementation
David Doria
daviddoria+vtk at gmail.com
Thu Feb 11 12:15:41 EST 2010
On Thu, Feb 11, 2010 at 11:33 AM, Christian Werner <
christian.werner at rwth-aachen.de> wrote:
> 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
> __
>
>
It looks like this (from vtkTexturePainter.cxx) is returning NULL:
vtkDataArray* scalars = vtkAbstractMapper::GetScalars(input,
this->ScalarMode,
this->ScalarArrayName? VTK_GET_ARRAY_BY_NAME : VTK_GET_ARRAY_BY_ID,
this->ScalarArrayIndex,
this->ScalarArrayName,
cellFlag);
It looks like you can call
painter->SetScalarArrayName("yourArray");
to set the array that you want it to use.
Hope that helps,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100211/464500f9/attachment.htm>
More information about the vtkusers
mailing list