[Paraview] MapDataArrayToVertexAttribute question / extending PointSprites plugin

Florian Hoffmann florian.hoffmann at inutech.de
Thu Nov 20 11:32:56 EST 2014


Hi Utkarsh, dear all,

thanks for your answer. This was just an example (maybe a rather stupid 
one). Please let me rephrase my question:
I am trying to extend the pointSprites plugin with my own shaders. For 
this I would like to pass up to 3 size parameters and the 4 components 
of quarternions for orientation to the shader code. Currently I do it 
like this:

void vtkPointSpriteProperty::Render(vtkActor *act, vtkRenderer *ren)
{
    vtkPainterPolyDataMapper*  mapper  =  vtkPainterPolyDataMapper::SafeDownCast(act->GetMapper());

       if  (mapper)

       {

mapper->RemoveVertexAttributeMapping("SizeParam1");

         mapper->MapDataArrayToVertexAttribute("SizeParam1",  this->SizeParam1ArrayName,

             vtkDataObject::FIELD_ASSOCIATION_POINTS,  -1);

         mapper->RemoveVertexAttributeMapping("SizeParam2");

         mapper->MapDataArrayToVertexAttribute("SizeParam2",  this->SizeParam2ArrayName,

             vtkDataObject::FIELD_ASSOCIATION_POINTS,  -1);

         mapper->RemoveVertexAttributeMapping("SizeParam3");

         mapper->MapDataArrayToVertexAttribute("SizeParam3",  this->SizeParam3ArrayName,

             vtkDataObject::FIELD_ASSOCIATION_POINTS,  -1);

         mapper->RemoveVertexAttributeMapping("rotQionW");

         mapper->MapDataArrayToVertexAttribute("rotQionW",  this->RotQionWArrayName,

             vtkDataObject::FIELD_ASSOCIATION_POINTS,  -1);

         mapper->RemoveVertexAttributeMapping("rotQionX");

         mapper->MapDataArrayToVertexAttribute("rotQionX",  this->RotQionXArrayName,

             vtkDataObject::FIELD_ASSOCIATION_POINTS,  -1);

         mapper->RemoveVertexAttributeMapping("rotQionY");

         mapper->MapDataArrayToVertexAttribute("rotQionY",  this->RotQionYArrayName,

             vtkDataObject::FIELD_ASSOCIATION_POINTS,  -1);

         mapper->RemoveVertexAttributeMapping("rotQionZ");

         mapper->MapDataArrayToVertexAttribute("rotQionZ",  this->RotQionZArrayName,

             vtkDataObject::FIELD_ASSOCIATION_POINTS,  -1);


     
     if  (this->Internal->PushedAttrib  ==  0)
     {
       glPushAttrib(GL_ALL_ATTRIB_BITS);
       this->Internal->PushedAttrib  =  1;
     }
      


       glEnable(vtkgl::VERTEX_PROGRAM_POINT_SIZE_ARB);

         float  sizeParam1Span[2];
         sizeParam1Span[0]  =  this->SizeParam1Range[0];
         sizeParam1Span[1]  =  (this->SizeParam1Range[1]  -  this->SizeParam1Range[0]);
         this->AddShaderVariable("SizeParam1Span",  2,  sizeParam1Span);


         float  sizeParam2Span[2];
         sizeParam2Span[0]  =  this->SizeParam2Range[0];
         sizeParam2Span[1]  =  (this->SizeParam2Range[1]  -  this->SizeParam2Range[0]);
         this->AddShaderVariable("SizeParam2Span",  2,  sizeParam2Span);


         float  sizeParam3Span[2];
         sizeParam3Span[0]  =  this->SizeParam3Range[0]  *  factor;
         sizeParam3Span[1]  =  (this->SizeParam3Range[1]  -  this->SizeParam3Range[0]);
         this->AddShaderVariable("SizeParam3Span",  2,  sizeParam3Span);




         float  rotQionWSpan[2];
         rotQionWSpan[0]  =  this->RotQionWRange[0];
         rotQionWSpan[1]  =  (this->RotQionWRange[1]  -  this->RotQionWRange[0]);
         this->AddShaderVariable("rotQionWSpan",  2,  rotQionWSpan);


         float  rotQionXSpan[2];
         rotQionXSpan[0]  =  this->RotQionXRange[0];
         rotQionXSpan[1]  =  (this->RotQionXRange[1]  -  this->RotQionXRange[0]);
         this->AddShaderVariable("rotQionXSpan",  2,  rotQionXSpan);


         float  rotQionYSpan[2];
         rotQionYSpan[0]  =  this->RotQionYRange[0];
         rotQionYSpan[1]  =  (this->RotQionYRange[1]  -  this->RotQionYRange[0]);
         this->AddShaderVariable("rotQionYSpan",  2,  rotQionYSpan);


         float  rotQionZSpan[2];
         rotQionZSpan[0]  =  this->RotQionZRange[0];
         rotQionZSpan[1]  =  (this->RotQionZRange[1]  -  this->RotQionZRange[0]);
         this->AddShaderVariable("rotQionZSpan",  2,  rotQionZSpan);


   this->Superclass::Render(act,  ren);
}


in my vertex shader code I have something like this

in float SizeParam1;
in float SizeParam2;
in float SizeParam3;

uniform  vec2  SizeParam1Span;
uniform  vec2  SizeParam2Span;
uniform  vec2  SizeParam3Span;

     vec3  radius  =  vec3(0.0,  0.0,  0.0);


     radius.x  =  SizeParam1Span.x+SizeParam1*SizeParam1Span.y;
     radius.y  =  SizeParam2Span.x+SizeParam2*SizeParam2Span.y;
     radius.z  =  SizeParam3Span.x+SizeParam3*SizeParam3Span.y;

  ...


  
in  float  rotQionW;
in  float  rotQionX;
in  float  rotQionY;
in  float  rotQionZ;

uniform  vec2  rotQionWSpan;
uniform  vec2  rotQionXSpan;
uniform  vec2  rotQionYSpan;
uniform  vec2  rotQionZSpan;


   vec4  rotQions=vec4(1.0,0.0,0.0,0.0);


   rotQions.w  =  rotQionWSpan.x  +  rotQionW  *  rotQionWSpan.y;
   rotQions.x  =  rotQionXSpan.x  +  rotQionX  *  rotQionXSpan.y;
   rotQions.y  =  rotQionYSpan.x  +  rotQionY  *  rotQionYSpan.y;
   rotQions.z  =  rotQionZSpan.x  +  rotQionZ  *  rotQionZSpan.y;

   ...


I discovered that my the data of the field variable (this->...ArrayName) passed into

MapDataArrayToVertexAttribute(...)

is somehow between 0 and 1. This is why I also have to pass the span to convert it back ( as it is done in the original pointSprite plugin code).


Even though I can render some geometry (for example ellipsoids) around several points/vertices (=this means my shader code works), I have the feeling that the Mapping to the individual vertices is not working as expected !

For example in the case of having three vertices of which each one has different values for SizeParam1, SizeParam2 and SizeParam3 - for example:

v1 : pos(0,0,0) SizeParam1 = 1.0, SizeParam2 = 1.0, SizeParam3 = 1.0
v2 : pos(0,1,0) SizeParam1 = 1.0, SizeParam2 = 2.0, SizeParam3 = 0.5
v3 : pos(0,0,1) SizeParam1 = 1.0, SizeParam2 = 1.0, SizeParam3 = 1.0


where the values for SizeParam1, SizeParam2 and SizeParam3 are taken from the selected fields (=multiblock, where individual blocks represent individual time steps) associated with the points/vertices.


Nevertheless the individual vertices do not seem to receive their correct values !
My current problem is that all of them are rendered the same size, thus I assume that the shader variables are not passed as expected.


The essential difference to the original pointSprites code is that I have several calls to


         mapper->RemoveVertexAttributeMapping(...);

         mapper->MapDataArrayToVertexAttribute(...);

whereas in the original pointSprites implementation there was only 1 call for the RadiusArray.
I checked with the debugger and found that the mappings are added to the array
vtkGenericVertexAttributeMapping* mappings in

void  vtkPainterPolyDataMapper::MapDataArrayToVertexAttribute(
   const  char*  vertexAttributeName,
   const  char*  dataArrayName,
   int  field,
   int  componentno)
{
   vtkGenericVertexAttributeMapping*  mappings  =  0;
   if(  this->PainterInformation->Has(
       vtkPrimitivePainter::DATA_ARRAY_TO_VERTEX_ATTRIBUTE())  )
     {
     mappings  =  vtkGenericVertexAttributeMapping::SafeDownCast(
       this->PainterInformation->Get(
         vtkPolyDataPainter::DATA_ARRAY_TO_VERTEX_ATTRIBUTE()));
     }


   if  (mappings==NULL)
     {
     mappings  =  vtkGenericVertexAttributeMapping::New();
     this->PainterInformation->Set(
       vtkPolyDataPainter::DATA_ARRAY_TO_VERTEX_ATTRIBUTE(),  mappings);
     mappings->Delete();
     }


   mappings->AddMapping(
     vertexAttributeName,  dataArrayName,  field,  componentno);
}



Nevertheless I do not know how to further investigate my problem or where to start looking for the actual mapping and data passing process.
Maybe anybody could point me to the catch here or to the interesting bits of code I should check or maybe explain me about the contraints when passing varying field data to shaders.

Is/Might the fact that I have a multi-block dataset somehow affecting the mapping process ?

Thanks

Best regards,

Florian




Am 15.11.2014 um 04:29 schrieb Utkarsh Ayachit:
> Florian,
>
> MapDataArrayToVertexAttribute expects the data array to be present in
> the input data going into the mapper itself. I see you're creating a
> new `darr`, but I don't see it being added to a dataset and then that
> being passed on to the mapper. Are you doing that?
>
> Having said that, you should look into adding a filter to add this
> data array to your dataset, vtkProperty/vtkPointSpriteProperty isn't a
> the best place to change input dataset being fed to the mapper.
>
> Utkarsh
>
> On Thu, Nov 13, 2014 at 7:19 AM, Florian Hoffmann
> <florian.hoffmann at inutech.de> wrote:
>> Dear all,
>>
>> I am trying to reuse some code from the point sprites plugin.
>> I would like to pass some size information onto some shader code for nine
>> different points like this:
>>
>> void vtkPointSpriteProperty::Render(vtkActor *act, vtkRenderer *ren)
>>
>> {
>>
>>
>>
>>     vtkPainterPolyDataMapper* mapper =
>>
>>            vtkPainterPolyDataMapper::SafeDownCast(act->GetMapper());
>>
>>
>>     vtkSmartPointer<vtkDoubleArray> darr =
>> vtkSmartPointer<vtkDoubleArray>::New();
>>
>>          darr->SetNumberOfTuples(9);
>>
>>          darr->SetName("testArray");
>>
>>          double size_tuple[1] = {0.2};
>>
>>          darr->SetNumberOfComponents(1);
>>
>>
>>          darr->SetTupleValue(0, size_tuple);
>>
>>          darr->SetTupleValue(1, size_tuple);
>>
>>          darr->SetTupleValue(2, size_tuple);
>>
>>          darr->SetTupleValue(3, size_tuple);
>>
>>          darr->SetTupleValue(4, size_tuple);
>>
>>          darr->SetTupleValue(5, size_tuple);
>>
>>          darr->SetTupleValue(6, size_tuple);
>>
>>          darr->SetTupleValue(7, size_tuple);
>>
>>          darr->SetTupleValue(8, size_tuple);
>>
>>
>>
>>     mapper->RemoveVertexAttributeMapping("SizeParam1");
>>     mapper->MapDataArrayToVertexAttribute("SizeParam1", darr->GetName(),
>>
>>              vtkDataObject::FIELD_ASSOCIATION_POINTS, 0);
>>
>>
>>
>>    glPushAttrib(GL_ALL_ATTRIB_BITS);
>>
>>    glEnable(vtkgl::VERTEX_PROGRAM_POINT_SIZE_ARB);
>>
>>    this->Superclass::Render(act, ren);
>> }
>>
>> shader code :
>>
>> attribute float SizeParam1;
>>
>> attribute float SizeParam2;
>>
>> attribute float SizeParam3;
>>
>>
>> vec3 GetSizeParams()
>>
>> {
>>
>>    vec3 sizeparams=vec3(0.0,0.5,0.8);
>>
>>      sizeparams.x = SizeParam1;
>>
>> //  sizeparams.y = SizeParam2;
>> //  sizeparams.z = SizeParam3;
>>
>>
>>    return sizeparams;
>>
>> }
>>
>>
>>
>> Question: How is the 0.2 stored in the tuple modified while passed to the
>> shader code ?
>>
>> Because the value arriving in the
>> shader code seems to be different from the value 0.2 which is stored in the
>> tuples.
>> I noticed, because if I hardwire 0.2 in the shader code like this
>>
>>
>> vec3 GetSizeParams()
>>
>> {
>>
>>   vec3 sizeparams=vec3(0.2,0.5,0.8);
>>
>>    return sizeparams;
>> }
>>
>> I see a different rendering.
>>
>> Could anyone please cast a light into this issue and tell me what I am doing
>> wrong or rather which settings influencing the mapping I should draw my
>> attention to ?
>>
>> Thanks.
>>
>> Best regards,
>>
>> Florian
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the ParaView Wiki at:
>> http://paraview.org/Wiki/ParaView
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/paraview
>>

-- 
Mit freundlichen Grüßen
--
Dr.-Ing. Florian Hoffmann
inuTech GmbH		Phone	 : +49-(0)911-323843-22
Fuerther Strasse 212	Fax	 : +49-(0)911-323843-43
90429 Nuernberg		E-Mai l	 : florian.hoffmann at inutech.de
Germany		        Internet : http://www.inutech.de

inuTech GmbH
Sitz / Registered Office: Nuernberg
Handelsregister / Companies' Register: AG Nürnberg HRB Nr. 19026
Geschäftsführer / Managing Director: Frank Vogel

*****************************************************************
DIFFPACK - THE NEW GENERATION OF SIMULATION-SOFTWARE!

Go to http://www.diffpack.com to read the details
*****************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20141120/84729b96/attachment-0001.html>


More information about the ParaView mailing list