[Paraview] How to color by Cell Data

Michael Jackson mike.jackson at bluequartz.net
Wed Feb 24 17:08:40 EST 2010


I have a custom filter that sets an RGB value for each cell in a  
surface mesh, where each cell is a triangle. When the filter runs in  
paraview I "see" the new arrays show up when I click on the  
"Information" tab but the "Color By" drop down only has the "Solid  
Color" available.

Here is the relevant parts of the code:

vtkCellData* cd = input->GetCellData();
   vtkDataArray* normals = cd->GetNormals();
   if (NULL == normals || (normals && normals->GetNumberOfTuples() <=  
0 ) )
   {
     std::cout << "NORMALS were not present" << std::endl;
     normals = NULL;
   }

   if (NULL == normals)
   {
     vtkPolyDataNormals* polyNormals = vtkPolyDataNormals::New();
     polyNormals->SetInput(input);
     polyNormals->SplittingOff();
     polyNormals->ConsistencyOn ();
     polyNormals->AutoOrientNormalsOn();
     polyNormals->ComputePointNormalsOff();
     polyNormals->ComputeCellNormalsOn();
     polyNormals->FlipNormalsOff();
     polyNormals->NonManifoldTraversalOff();
     polyNormals->Update();
     output->ShallowCopy(polyNormals->GetOutput());
   }

   cd = output->GetCellData();
   normals = cd->GetNormals();

   vtkUnsignedCharArray* rgb = vtkUnsignedCharArray::New();
   rgb->SetName(INTERFACE_COLORING);
   rgb->SetNumberOfComponents(3);

   vtkDataArray* eulerArray = input->GetFieldData()- 
 >GetArray(OIMColoring::EulerAngles().c_str());
   if (NULL == eulerArray)
   {
     vtkErrorMacro( << "Euler Angles Field Data Missing from Data set.  
This filter requires the euler angles to work");
     return 0;
   }

   double* eulers = eulerArray->GetTuple3(0);
   double* refDirection; //[3] = {45.0, 45.0, 0.0};
   unsigned char bytes[3] =  { 65, 0, 255 };
   for (vtkIdType i = 0; i < normals->GetNumberOfTuples(); ++i)
   {
     refDirection = normals->GetTuple3(i);
     OIMColoring::GenerateIPFColor<double>(eulers, refDirection, bytes);
   //  std::cout << (int)(bytes[0]) << " " << (int)(bytes[1]) << " "  
<< (int)(bytes[2]) << std::endl;
     rgb->InsertNextTupleValue(bytes);
   }

   output->GetCellData()->SetScalars(rgb);
   output->GetCellData()->SetActiveScalars(INTERFACE_COLORING);

Helpful insights are very welcome.
___________________________________________________________
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       mike.jackson at bluequartz.net
BlueQuartz Software               Dayton, Ohio




More information about the ParaView mailing list