[vtk-developers] vtkAssignAttributes doesn't pass NumComponents?

Julien Finet julien.finet at kitware.com
Thu Aug 25 18:35:20 EDT 2011


Hi,

I've made some progress on it.
Doing the following before the pipeline is updated actually generate correct
arrays for the images of each pipeline steps.

vtkDataObject::SetActiveAttributeInfo(image->GetPipelineInformation(),

vtkDataObject::FIELD_ASSOCIATION_POINTS,

vtkDataSetAttributes::TENSORS,
                                                      "tensors",-1,9,-1);
This has the benefit of having vtkDataObject::GetActiveFieldInformation()
return a non null inputAttributeInfo in vtkAssignAttribute.cxx:224

So my code is then
VTK_CREATE(vtkImageData,image);
...
VTK_CREATE(vtkFloatArray, tensors);
...
image->GetPointData()->setTensors(tensors);
VTK_CREATE(vtkAssignAttribute, assign);
assign->Assign(vtkDataSetAttributes::TENSORS, vtkDataSetAttributes::SCALARS,
vtkAssignAttribute::POINT_DATA);
assign->SetInput(image);
vtkDataObject::SetActiveAttributeInfo(image->GetPipelineInformation(),

vtkDataObject::FIELD_ASSOCIATION_POINTS,

vtkDataSetAttributes::TENSORS,
                                                      "tensors",-1,9,-1);
VTK_CREATE(vtkImageCast, cast);
cast->SetInput(imageOut);
cast->Update();

It works but it's obviously a hack. The question is then,
1) where should SetActiveAttributeInfo be called ?
   a) in vtkPointData::setTensors()
   b) or in vtkAssignAttribute::RequestInformation() ?

The previous solution fixes the pipeline, but there is still another issue,
when the vtkAssignAttribute output is connected to a filter that queries
(in RequestData()) vtkImageData::GetNumberOfScalarComponents()  or
vtkImageData::GetScalarType() on the input.
In my case they are set to 1 and VTK_DOUBLE, probably because it's the
default for my original image

The hack I came up with is to manually set the scalar type and number of
components in the SCALARS attribute of the original image :
VTK_CREATE(vtkImageData, image);
image->SetScalarTypeToFloat();
image->SetNumberOfScalarComponents(9);
...

Then everything works for me.
However, it works in this case because I don't have any scalars in my origin
image, but I can see cases where we would.

2) Should it then be the kind of information
vtkAssignAttribute::RequestInformation() should pass ?

For clarity, you'll find enclosed my test program.

Thanks,
Julien.

On Thu, Aug 25, 2011 at 1:03 AM, Julien Finet <julien.finet at kitware.com>wrote:

> Hi all,
>
> I'm trying to process a tensors vtkImageData by a filter that only accept
> scalars.
> However, I think that vtkAssignAttribute doesn't pass the number of
> components in the output information.
>
> Indeed, looking at vtkAssignAttribute::RequestInformation(), I don't see
> how it could pass the "number of components". Maybe it's done later in
> RequestData, but wouldn't it be too late when vtkAssignAttribute output is
> connected as an input of another filter?
>
> Here is my pipeline:
>
> // Create Data:
>   VTK_CREATE(vtkImageData,image);
>   image->SetDimensions(2,1,1);
>
>   VTK_CREATE(vtkFloatArray, tensors);
>   tensors->SetName("tensors");
>   tensors->SetNumberOfComponents(9);
>   // 2 tuples, identity matrices
>   tensors->InsertNextTuple9(1.,0.,0.,0.,1.,0.,0.,0.,1.);
>   tensors->InsertNextTuple9(1.,0.,0.,0.,1.,0.,0.,0.,1.);
>
>   image->GetPointData()->SetTensors(tensors);
>
> // Move tensors into scalars
>   VTK_CREATE(vtkAssignAttribute, assign);
>   assign->Assign(vtkDataSetAttributes::TENSORS,
> vtkDataSetAttributes::SCALARS, vtkAssignAttribute::POINT_DATA);
>   assign->SetInput(image);
>
> // Cast scalars
>   VTK_CREATE(vtkImageCast, cast); // here I use cast but it could be any
> other image filter that just process scalars
>   cast->SetOutputScalarTypeToDouble();
>   cast->SetInput(imageOut);
>   cast->Update();
>
> Unfortunately, the output of the cast filter is not a scalar image with 9
> components but only 1.
>
>   vtkImageData* imageOut = vtkImageData::SafeDownCast(assign->GetOutput());
>   vtkImageData* imageCasted =
> vtkImageData::SafeDownCast(cast->GetOutput());
>   if (imageCasted->GetPointData()->GetNumberOfComponents() != 9)
>     {
>     cerr << "Input: \n";
>     image->GetPointData()->Print(cerr);
>     cerr << "Intermediate: \n";
>     imageOut->GetPointData()->Print(cerr);
>     cerr << "Casted: \n";
>     imageCasted->GetPointData()->Print(cerr);
>     }
>
> produces the output:
>
> Input:
> vtkPointData (0398BBF8)
>   Debug: Off
>   Modified Time: 29
>   Reference Count: 1
>   Registered Events: (none)
>   Number Of Arrays: 1
>   Array 0 name = tensors
>   Number Of Components: 9
>   Number Of Tuples: 2
>   Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
>   Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
>   Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
>   Scalars: (none)
>   Vectors: (none)
>   Normals: (none)
>   TCoords: (none)
>   Tensors:
>     Debug: Off
>     Modified Time: 26
>     Reference Count: 3
>     Registered Events: (none)
>     Name: tensors
>     Data type: float
>     Size: 27
>     MaxId: 17
>     NumberOfComponents: 9
>     Information: 00000000
>     Name: tensors
>     Number Of Components: 9
>     Number Of Tuples: 2
>     Size: 27
>     MaxId: 17
>     LookupTable: (none)
>     Array: 0398C450
>   GlobalIds: (none)
>   PedigreeIds: (none)
>   EdgeFlag: (none)
>
> Intermediate:
> vtkPointData (0398F5B0)
>   Debug: Off
>   Modified Time: 338
>   Reference Count: 1
>   Registered Events: (none)
>   Number Of Arrays: 1
>   Array 0 name = tensors
>   Number Of Components: 9
>   Number Of Tuples: 2
>   Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
>   Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
>   Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
>   Scalars:
>     Debug: Off
>     Modified Time: 26
>     Reference Count: 3
>     Registered Events: (none)
>     Name: tensors
>     Data type: float
>     Size: 27
>     MaxId: 17
>     NumberOfComponents: 9
>     Information: 00000000
>     Name: tensors
>     Number Of Components: 9
>     Number Of Tuples: 2
>     Size: 27
>     MaxId: 17
>     LookupTable: (none)
>     Array: 0398C450
>   Vectors: (none)
>   Normals: (none)
>   TCoords: (none)
>   Tensors:
>     Debug: Off
>     Modified Time: 26
>     Reference Count: 3
>     Registered Events: (none)
>     Name: tensors
>     Data type: float
>     Size: 27
>     MaxId: 17
>     NumberOfComponents: 9
>     Information: 00000000
>     Name: tensors
>     Number Of Components: 9
>     Number Of Tuples: 2
>     Size: 27
>     MaxId: 17
>     LookupTable: (none)
>     Array: 0398C450
>   GlobalIds: (none)
>   PedigreeIds: (none)
>   EdgeFlag: (none)
>
> Casted:
> vtkPointData (037C2A30)
>   Debug: Off
>   Modified Time: 394
>   Reference Count: 1
>   Registered Events: (none)
>   Number Of Arrays: 1
>   Array 0 name = tensors
>   Number Of Components: 1
>   Number Of Tuples: 2
>   Copy Tuple Flags: ( 1 1 1 1 1 1 1 1 )
>   Interpolate Flags: ( 1 1 1 1 1 1 1 1 )
>   Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
>   Scalars:
>     Debug: Off
>     Modified Time: 391
>     Reference Count: 1
>     Registered Events: (none)
>     Name: tensors
>     Data type: double
>     Size: 2
>     MaxId: 1
>     NumberOfComponents: 1
>     Information: 00000000
>     Name: tensors
>     Number Of Components: 1
>     Number Of Tuples: 2
>     Size: 2
>     MaxId: 1
>     LookupTable: (none)
>     Array: 037C6DC8
>   Vectors: (none)
>   Normals: (none)
>   TCoords: (none)
>   Tensors: (none)
>   GlobalIds: (none)
>   PedigreeIds: (none)
>   EdgeFlag: (none)
>
> So is it a bug or a misuse? Any idea ?
>
> Thanks,
> Julien.
> p.s. doing the following doesn't help neither.
>      assign->Assign("tensors", vtkDataSetAttributes::SCALARS,
> vtkAssignAttribute::POINT_DATA);
> instead of
>      assign->Assign(vtkDataSetAttributes::TENSORS,
> vtkDataSetAttributes::SCALARS, vtkAssignAttribute::POINT_DATA);
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20110825/bd09bdff/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestAssignAttribute.cxx
Type: application/octet-stream
Size: 3092 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20110825/bd09bdff/attachment-0001.obj>


More information about the vtk-developers mailing list