<div>Hi,</div><div><br></div><div>I've made some progress on it.</div><div><div><div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif">Doing the following before the pipeline is updated actually generate correct arrays for the images of each pipeline steps.</font></span></div>
<div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"><br></font></span></div>
<div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"><div>vtkDataObject::SetActiveAttributeInfo(image->GetPipelineInformation(), </div>
<div> vtkDataObject::FIELD_ASSOCIATION_POINTS,</div><div> vtkDataSetAttributes::TENSORS,</div><div> "tensors",-1,9,-1);</div>
</font></span></div><div><font class="Apple-style-span" face="arial, sans-serif">This has the benefit of having vtkDataObject::GetActiveFieldInformation() return a non null inputAttributeInfo in vtkAssignAttribute.cxx:224</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"> </font></div><div><font class="Apple-style-span" face="arial, sans-serif">So my code is then</font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: 13px; background-color: rgb(255, 255, 255); ">VTK_CREATE(vtkImageData,image);</span></font></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">...</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">VTK_CREATE(vtkFloatArray, tensors);</span></div>
<div><font face="arial, sans-serif"><span class="Apple-style-span" style="font-size: 13px; background-color: rgb(255, 255, 255); "><div>...</div></span></font><font face="arial, sans-serif"><span class="Apple-style-span" style="font-size: 13px; background-color: rgb(255, 255, 255); ">image->GetPointData()->setTensors(tensors);</span><span class="Apple-style-span" style="font-size: 13px; background-color: rgb(255, 255, 255); "><div>
VTK_CREATE(vtkAssignAttribute, assign);</div><div>assign->Assign(vtkDataSetAttributes::TENSORS, vtkDataSetAttributes::SCALARS, vtkAssignAttribute::POINT_DATA);</div><div>assign->SetInput(image);</div></span></font></div>
<div><font face="arial, sans-serif"><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><div>vtkDataObject::SetActiveAttributeInfo(image->GetPipelineInformation(), </div><div> vtkDataObject::FIELD_ASSOCIATION_POINTS,</div>
<div> vtkDataSetAttributes::TENSORS,</div><div> "tensors",-1,9,-1);</div></span></font></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">VTK_CREATE(vtkImageCast, cast);</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><div>cast->SetInput(imageOut);</div><div>cast->Update();</div></span></div><div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"><br>
</font></span></div><div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif">It works but it's obviously a hack. The question is then, </font></span></div><div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif">1) where should SetActiveAttributeInfo be called ? </font></span></div>
<div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"> a) in vtkPointData::setTensors() </font></span></div><div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"> b) or in vtkAssignAttribute::RequestInformation() ?</font></span></div>
<div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"><br></font></span></div><div><font class="Apple-style-span" face="arial, sans-serif">The previous solution fixes the pipeline, but there is still another issue, when the vtkAssignAttribute output is connected to a filter that queries (in </font>RequestData()) <span class="Apple-style-span" style="font-family: arial, sans-serif; ">vtkImageData::GetNumberOfScalarComponents() or vtkImageData::GetScalarType() on the input. </span></div>
<div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif">In my case they are set to 1 and VTK_DOUBLE, probably because it's the default for my original image</font></span></div><div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"><br>
</font></span></div><div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif">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 :</font></span></div>
<div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif">VTK_CREATE(vtkImageData, image);</font></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; background-color: rgb(255, 255, 255); ">image->SetScalarTypeToFloat();</span><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"><div>
image->SetNumberOfScalarComponents(9);</div><div>...</div><div><br></div><div>Then everything works for me.</div><div>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.</div>
<div><br></div><div>2) Should it then be the kind of information vtkAssignAttribute::RequestInformation() should pass ?</div><div><br></div><div>For clarity, you'll find enclosed my test program. </div></font></span></div>
<div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif"><br></font></span></div><div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif">Thanks,</font></span></div>
<div><span style="background-color:rgb(255, 255, 255)"><font face="arial, sans-serif">Julien.</font></span></div>
<div><font face="arial, sans-serif"><br></font></div><div><div class="gmail_quote">On Thu, Aug 25, 2011 at 1:03 AM, Julien Finet <span dir="ltr"><<a href="mailto:julien.finet@kitware.com" target="_blank">julien.finet@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<div><br></div><div>I'm trying to process a tensors vtkImageData by a filter that only accept scalars.</div>
<div>However, I think that vtkAssignAttribute doesn't pass the number of components in the output information.</div>
<div><br></div><div>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?</div>
<div><br></div><div>Here is my pipeline:</div><div><br></div><div>// Create Data:</div><div><div> VTK_CREATE(vtkImageData,image);</div><div> image->SetDimensions(2,1,1);</div><div><br></div><div> VTK_CREATE(vtkFloatArray, tensors);</div>
<div> tensors->SetName("tensors");</div><div> tensors->SetNumberOfComponents(9);</div><div> // 2 tuples, identity matrices</div><div> tensors->InsertNextTuple9(1.,0.,0.,0.,1.,0.,0.,0.,1.);</div><div>
tensors->InsertNextTuple9(1.,0.,0.,0.,1.,0.,0.,0.,1.);</div><div><br></div><div> image->GetPointData()->SetTensors(tensors);</div></div><div><br></div><div>// Move tensors into scalars</div><div><div> VTK_CREATE(vtkAssignAttribute, assign);</div>
<div> assign->Assign(vtkDataSetAttributes::TENSORS, vtkDataSetAttributes::SCALARS, vtkAssignAttribute::POINT_DATA);</div><div> assign->SetInput(image);</div></div><div><br></div><div>// Cast scalars</div><div><div>
VTK_CREATE(vtkImageCast, cast); // here I use cast but it could be any other image filter that just process scalars</div><div> cast->SetOutputScalarTypeToDouble();</div><div> cast->SetInput(imageOut);</div><div>
cast->Update();</div></div><div><br></div><div>Unfortunately, the output of the cast filter is not a scalar image with 9 components but only 1.</div><div><br></div><div><div> vtkImageData* imageOut = vtkImageData::SafeDownCast(assign->GetOutput());</div>
<div> vtkImageData* imageCasted = vtkImageData::SafeDownCast(cast->GetOutput());</div><div> if (imageCasted->GetPointData()->GetNumberOfComponents() != 9)</div><div> {</div><div> cerr << "Input: \n";</div>
<div> image->GetPointData()->Print(cerr);</div><div> cerr << "Intermediate: \n";</div><div> imageOut->GetPointData()->Print(cerr);</div><div> cerr << "Casted: \n";</div>
<div> imageCasted->GetPointData()->Print(cerr);</div><div> }</div></div><div><br></div><div>produces the output:</div><div><br></div><div><div>Input:</div><div>vtkPointData (0398BBF8)</div><div> Debug: Off</div>
<div> Modified Time: 29</div><div> Reference Count: 1</div><div> Registered Events: (none)</div><div> Number Of Arrays: 1</div><div> Array 0 name = tensors</div><div> Number Of Components: 9</div><div> Number Of Tuples: 2</div>
<div> Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )</div><div> Interpolate Flags: ( 1 1 1 1 1 0 0 1 )</div><div> Pass Through Flags: ( 1 1 1 1 1 1 1 1 )</div><div> Scalars: (none)</div><div> Vectors: (none)</div><div> Normals: (none)</div>
<div> TCoords: (none)</div><div> Tensors:</div><div> Debug: Off</div><div> Modified Time: 26</div><div> Reference Count: 3</div><div> Registered Events: (none)</div><div> Name: tensors</div><div> Data type: float</div>
<div> Size: 27</div><div> MaxId: 17</div><div> NumberOfComponents: 9</div><div> Information: 00000000</div><div> Name: tensors</div><div> Number Of Components: 9</div><div> Number Of Tuples: 2</div><div>
Size: 27</div><div> MaxId: 17</div><div> LookupTable: (none)</div><div> Array: 0398C450</div><div> GlobalIds: (none)</div><div> PedigreeIds: (none)</div><div> EdgeFlag: (none)</div><div><br></div><div>Intermediate:</div>
<div>vtkPointData (0398F5B0)</div><div> Debug: Off</div><div> Modified Time: 338</div><div> Reference Count: 1</div><div> Registered Events: (none)</div><div> Number Of Arrays: 1</div><div> Array 0 name = tensors</div>
<div> Number Of Components: 9</div><div> Number Of Tuples: 2</div><div> Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )</div><div> Interpolate Flags: ( 1 1 1 1 1 0 0 1 )</div><div> Pass Through Flags: ( 1 1 1 1 1 1 1 1 )</div>
<div> Scalars:</div><div> Debug: Off</div><div> Modified Time: 26</div><div> Reference Count: 3</div><div> Registered Events: (none)</div><div> Name: tensors</div><div> Data type: float</div><div> Size: 27</div>
<div> MaxId: 17</div><div> NumberOfComponents: 9</div><div> Information: 00000000</div><div> Name: tensors</div><div> Number Of Components: 9</div><div> Number Of Tuples: 2</div><div> Size: 27</div><div>
MaxId: 17</div><div> LookupTable: (none)</div><div> Array: 0398C450</div><div> Vectors: (none)</div><div> Normals: (none)</div><div> TCoords: (none)</div><div> Tensors:</div><div> Debug: Off</div><div> Modified Time: 26</div>
<div> Reference Count: 3</div><div> Registered Events: (none)</div><div> Name: tensors</div><div> Data type: float</div><div> Size: 27</div><div> MaxId: 17</div><div> NumberOfComponents: 9</div><div>
Information: 00000000</div>
<div> Name: tensors</div><div> Number Of Components: 9</div><div> Number Of Tuples: 2</div><div> Size: 27</div><div> MaxId: 17</div><div> LookupTable: (none)</div><div> Array: 0398C450</div><div> GlobalIds: (none)</div>
<div> PedigreeIds: (none)</div><div> EdgeFlag: (none)</div><div><br></div><div>Casted:</div><div>vtkPointData (037C2A30)</div><div> Debug: Off</div><div> Modified Time: 394</div><div> Reference Count: 1</div><div> Registered Events: (none)</div>
<div> Number Of Arrays: 1</div><div> Array 0 name = tensors</div><div> Number Of Components: 1</div><div> Number Of Tuples: 2</div><div> Copy Tuple Flags: ( 1 1 1 1 1 1 1 1 )</div><div> Interpolate Flags: ( 1 1 1 1 1 1 1 1 )</div>
<div> Pass Through Flags: ( 1 1 1 1 1 1 1 1 )</div><div> Scalars:</div><div> Debug: Off</div><div> Modified Time: 391</div><div> Reference Count: 1</div><div> Registered Events: (none)</div><div> Name: tensors</div>
<div> Data type: double</div><div> Size: 2</div><div> MaxId: 1</div><div> NumberOfComponents: 1</div><div> Information: 00000000</div><div> Name: tensors</div><div> Number Of Components: 1</div><div>
Number Of Tuples: 2</div>
<div> Size: 2</div><div> MaxId: 1</div><div> LookupTable: (none)</div><div> Array: 037C6DC8</div><div> Vectors: (none)</div><div> Normals: (none)</div><div> TCoords: (none)</div><div> Tensors: (none)</div>
<div> GlobalIds: (none)</div><div> PedigreeIds: (none)</div><div> EdgeFlag: (none)</div></div><div><br></div><div>So is it a bug or a misuse? Any idea ?</div><div><br></div><div>Thanks,</div><div>Julien.</div><div>p.s. doing the following doesn't help neither.</div>
<div> assign->Assign("tensors", vtkDataSetAttributes::SCALARS, vtkAssignAttribute::POINT_DATA);</div><div>instead of </div><div> assign->Assign(vtkDataSetAttributes::TENSORS, vtkDataSetAttributes::SCALARS, vtkAssignAttribute::POINT_DATA);</div>
<div><br></div>
</blockquote></div><br></div></div></div>