[vtkusers] Many vector fields associated to the point data - and want to create glyphs rendering one (arbitrary) of them.

Mirosław Habarta Miroslaw.Habarta at polsl.pl
Sun Jul 3 06:02:44 EDT 2011


Hi,
I have the problem mentioned in the subject:
My source - is the collection of points (particles) and there are 
several vector fields associated to them. I want to render the points 
(as small spheres- vtkGlyph3d is used here) and the vector fields 
associated to them. Say, that there are 2 vector fields, one will be 
rendered as green arrows, the second - as red arrows. I know how to 
connect the first field. But I don't know how to do the same with the 
second.
I wrote a the new class for my data source, here is the way I add vector 
fields to them:

int cVtkMoleculeModelSource::RequestData(
   vtkInformation *vtkNotUsed(request),
   vtkInformationVector **vtkNotUsed(inputVector),
   vtkInformationVector *outputVector)
{

     vtkDebugMacro("Molecule Source Executing");

      vtkInformation *outInfo = outputVector->GetInformationObject(0);

   vtkPolyData *output = 
vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));

     size_t numPts = mMolecularModel->NumOfMolecules() ;

     vtkPoints* newPoints = vtkPoints::New();
   newPoints->SetDataTypeToDouble(); //used later during transformation
   newPoints->Allocate(numPts);

     mForces = vtkDoubleArray::New();
   mForces->SetNumberOfComponents(3); //used later during transformation
     mForces->SetName("Resultant_F") ;

     mLoads= vtkDoubleArray::New();
   mLoads->SetNumberOfComponents(3); //used later during transformation
     mLoads->SetName("External_F") ;


      vtkCellArray* newVerts = vtkCellArray::New();

     for( size_t i = 0; i < numPts; ++i)
     {
         const  GLW::Molecule & mol = mMolecularModel->getMolecule(i) ;
         const  GLW::Point & x = mol.getCoord() ;
         const  GLW::Point  f = mMolecularModel->getResultantForce(i) ;
         const  GLW::Point  L = mol.getForce();

         vtkIdType id = newPoints->InsertNextPoint(x[0],x[1], x[2] ) ;
         newVerts->InsertNextCell(1,&id ) ;
         //mNodeMap[node.GetNumber()] = id ;

         mForces->InsertNextTuple3(f[0],f[1],f[2]) ;
         mLoads->InsertNextTuple3(L[0],L[1],L[2]) ;
     }

     output->SetPoints(newPoints);
     // TODO: what are verts? Are they necessary ?
     output->SetVerts(newVerts) ;

     output->GetPointData()->SetVectors(mForces) ;
     output->GetPointData()->AddArray(mLoads) ; ;


   newPoints->Delete();
     newVerts->Delete() ;

     return 1 ;

}

Note the lines:
output->GetPointData()->SetVectors(mForces) ;
output->GetPointData()->AddArray(mLoads) ;
What I understand from the documentations is, that we have 2 vector 
fields added to the data set, but one of them is treated in a special 
way - mForces. And this is the field, which will be rendered by arrows, 
when this source will be set as input to the vtkGlyph3d object, and 
calling the  vtkGlyph3D::SetVectorModeToUseVector() function. But I want 
to have another vtkGlyph3d object (simultaneously), but connected to 
mLoads field ? How to achieve this ?
One of my first thoughts is to write a filter wich takes the second 
vector field associated whith input and calls 
output->GetPointData()->SetVectors(input->GetPointData()->GetArray(1)

Does it looks reasonable ? Or perhaps there is already a simpler way ?

Regards,
M.H.

	
	
	

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110703/f5112be1/attachment.htm>


More information about the vtkusers mailing list