[Paraview] Export to vtk file needed to get colours!

B.W.H. van Beest bwvb at xs4all.nl
Tue Oct 14 16:23:28 EDT 2014


Hello All,

I wonder if I stumbled upon a bug, or if I made a thinking error myself.

The issue is: I can get colouring of my Source object only after I write
it first to a vtk file and then read it back again!

This is what I do:

-) I create a single (rectangular) 3D cell from a (handcrafted) Source type,
     subclassed from vtkUnstructuredGridAlgorithm.
    This cell has scalar properties assigned to both its vertices as
well as the cell itself.

-)  After "Apply", the box becomes visible (surface representation)
     However, there are no colours. The "Coloring" section in the
     Properties panel does not show the scalar properties. Only
     "Solid Color" and "cellNormals" appear as combo-options.

-)   After writing the model to a vtk file, and loading the latter, the
     loaded box does appear in its coloured form, with the scalar
properties
     selectable in the "Coloring" combo box.    

Why do the colours not show up immediately after I created ("Apply") the
source object. I naively tried a Modified() on the underlying unstructed
grid object,
but that didn't help.

For completeness, I paste the relevant code as well as the vtk file (ascii).

Kind Regards,
Bertwim



====================
int sphBoxSourceC::RequestData( vtkInformation *vtkNotUsed(request),
                                vtkInformationVector
**vtkNotUsed(inputVector),
                                vtkInformationVector *outputVector)
{
   // Get the info object
   vtkInformation *outInfo = outputVector->GetInformationObject(0);
   vtkUnstructuredGrid *umesh = vtkUnstructuredGrid::SafeDownCast(
outInfo->Get( vtkDataObject::DATA_OBJECT() ) );
  
   // Pre-allocate some memory
   umesh->Allocate( 1024 );

   // Scalars for the property values
   vtkFloatArray* vtxdata = vtkFloatArray::New(); // property defined on
a vertex.
   vtkFloatArray* vxldata = vtkFloatArray::New(); // property defined in
a voxel.

   // Specify points.
   float r0[] = { 0.0, 0.0, 0.0 };
   float r1[] = { 1.0, 0.0, 0.0 };
   float r2[] = { 0.0, 1.0, 0.0 };
   float r3[] = { 1.0, 1.0, 0.0 };
   float r4[] = { 0.0, 0.0, 1.0 };
   float r5[] = { 1.0, 0.0, 1.0 };
   float r6[] = { 0.0, 1.0, 1.0 };
   float r7[] = { 1.0, 1.0, 1.0 };
  
   // Collect the points in a vtk data structures.
   {
      vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
      points->SetDataType( VTK_FLOAT );

      points->InsertNextPoint( r0 );  vtxdata->InsertNextValue( cos(0.1) );
      points->InsertNextPoint( r1 );  vtxdata->InsertNextValue( cos(0.4) );
      points->InsertNextPoint( r2 );  vtxdata->InsertNextValue( cos(0.7) );
      points->InsertNextPoint( r3 );  vtxdata->InsertNextValue( cos(1.0) );
      points->InsertNextPoint( r4 );  vtxdata->InsertNextValue( cos(1.3) );
      points->InsertNextPoint( r5 );  vtxdata->InsertNextValue( cos(1.6) );
      points->InsertNextPoint( r6 );  vtxdata->InsertNextValue( cos(1.9) );
      points->InsertNextPoint( r7 );  vtxdata->InsertNextValue( cos(2.2) );

      // Transfer points to umesh.
      umesh->SetPoints( points );
      umesh->GetPointData()->SetScalars( vtxdata );
   }

   // Cell Topology
   vtkIdType vtx[8] = { 0, 1, 3, 2, 4, 5, 7, 6 };
   umesh->InsertNextCell( VTK_HEXAHEDRON, 8, vtx );
vxldata->InsertNextValue( 3.14 );
   umesh->GetCellData()->SetScalars( vxldata );
  
   // Write data to a file
   {
      std::string fileName( "myfile.vtk" );
      V3D::Utils::WriteUMesh( umesh, "Rectangular block as umesh",
fileName, VTK_ASCII );
      cerr << "Created: " << fileName << std::endl;
   }

   vtxdata->Delete();
   vxldata->Delete();
  
   return 1;
}

=======================
The file "myfile.vtk", written above read:
=======================
# vtk DataFile Version
3.0                                                                                                                      

Rectangular block as
umesh                                                                                                                      

ASCII                                                                                                                                           

DATASET
UNSTRUCTURED_GRID                                                                                                                       

POINTS 8
float                                                                                                                                  

0 0 0 1 0 0 0 1
0                                                                                                                               

1 1 0 0 0 1 1 0
1                                                                                                                               

0 1 1 1 1
1                                                                                                                                     

CELLS 1
9                                                                                                                                       

8 0 1 3 2 4 5 7
6                                                                                                                               

                                                                                                                                                

CELL_TYPES
1                                                                                                                                    

12                                                                                                                                              

                                                                                                                                                

CELL_DATA
1                                                                                                                                     

SCALARS scalars
float                                                                                                                           

LOOKUP_TABLE
default                                                                                                                            

3.14                                                                                                                                            

POINT_DATA
8                                                                                                                                    

SCALARS scalars
float                                                                                                                           

LOOKUP_TABLE
default                                                                                                                            

0.995004 0.921061 0.764842 0.540302 0.267499 -0.0291995 -0.32329
-0.588501                                                                      

=======================







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20141014/31ec7f7b/attachment.html>


More information about the ParaView mailing list