[vtkusers] Bug in vtkRIBExporter

Rainer Sabelka sabelka at iue.tuwien.ac.at
Sun Nov 12 11:38:44 EST 2000


Hi,
vtkRIBExporter still had a problem with cell data in vtkDataSetMappers.
The attached patch should fix this now.

Regards,
Rainer


I wrote:

> some time ago I posted a fix for a bug in vtkRIBExporter. Recently I
> tried out the latest nightlies
> and noticed that the bug is still there (cell data do not work
> correctly).
> I'll attach the fix to this mail. Can someone with CVS access please
> incorporate it into the repository?
-------------- next part --------------
--- vtkRIBExporter.cxx.orig	Sat Nov 11 22:28:19 2000
+++ vtkRIBExporter.cxx	Sun Nov 12 17:16:31 2000
@@ -52,6 +52,8 @@
 #include "vtkAssemblyPath.h"
 #include "vtkAssemblyNode.h"
 #include "vtkObjectFactory.h"
+#include "vtkPolyDataMapper.h"
+#include "vtkDataSetMapper.h"
 
 
 
@@ -608,6 +610,17 @@
     return;
     }
 
+  vtkPolyDataMapper *aMapper;
+  if(anActor->GetMapper()->IsA("vtkPolyDataMapper"))
+    {
+    aMapper=(vtkPolyDataMapper *)(anActor->GetMapper());
+    }
+  else if(anActor->GetMapper()->IsA("vtkDataSetMapper"))
+    {
+    aMapper=((vtkDataSetMapper *)(anActor->GetMapper()))->GetPolyDataMapper();
+    }
+  else return;
+
   fprintf (this->FilePtr, "AttributeBegin\n");
 
   fprintf (this->FilePtr, "TransformBegin\n");
@@ -616,7 +629,7 @@
   this->WriteProperty (anActor->GetProperty (), anActor->GetTexture ());
   
   // get the mappers input and matrix
-  aDataSet = anActor->GetMapper()->GetInput();
+  aDataSet = aMapper->GetInput();
   anActor->GetMatrix (matrix);
   matrix->Transpose();
 
@@ -634,23 +647,24 @@
   // we really want polydata
   if ( aDataSet->GetDataObjectType() != VTK_POLY_DATA )
     {
-    geometryFilter = vtkGeometryFilter::New();
-    geometryFilter->SetInput(aDataSet);
-    geometryFilter->Update();
-    polyData = geometryFilter->GetOutput();
+    vtkErrorMacro(<< "Polydata required?");
     }
   else
     {
     polyData = (vtkPolyData *)aDataSet;
     }
 
+  int useCellData=0;
+  if(aMapper->GetScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA
+     || polyData->GetPointData()->GetScalars() == NULL) useCellData=1;
+
   if (polyData->GetNumberOfPolys ())
     {
-    this->WritePolygons (polyData, anActor->GetMapper()->GetColors (), anActor->GetProperty ());
+    this->WritePolygons (polyData, aMapper->GetColors (), anActor->GetProperty (), useCellData);
     }
   if (polyData->GetNumberOfStrips ())
     {
-    this->WriteStrips (polyData, anActor->GetMapper()->GetColors (), anActor->GetProperty ());
+    this->WriteStrips (polyData, aMapper->GetColors (), anActor->GetProperty (), useCellData);
     }
   fprintf (this->FilePtr, "TransformEnd\n");
   fprintf (this->FilePtr, "AttributeEnd\n");
@@ -661,7 +675,7 @@
   matrix->Delete();
 }
 
-void vtkRIBExporter::WritePolygons (vtkPolyData *polyData, vtkScalars *s, vtkProperty *aProperty)
+void vtkRIBExporter::WritePolygons (vtkPolyData *polyData, vtkScalars *s, vtkProperty *aProperty, int useCellData)
 {
   float vertexColors[512][3];
   RtFloat *TCoords;
@@ -719,7 +733,8 @@
     n = 0;
     }
 
-  for (polys->InitTraversal(); polys->GetNextCell(npts,pts); )
+  int cellNum=polyData->GetNumberOfVerts()+polyData->GetNumberOfLines();
+  for (polys->InitTraversal(); polys->GetNextCell(npts,pts); cellNum++)
     { 
     if (!n)
       {
@@ -731,7 +746,8 @@
       k = j;
       if (s) 
         {
-        colors = s->GetColor(pts[k]);
+        if(useCellData) colors=s->GetColor(cellNum);
+        else colors = s->GetColor(pts[k]);
         vertexColors[k][0] = colors[0] / 255.0;
         vertexColors[k][1] = colors[1] / 255.0;
         vertexColors[k][2] = colors[2] / 255.0;
@@ -805,7 +821,7 @@
   polygon->Delete();
 }
 
-void vtkRIBExporter::WriteStrips (vtkPolyData *polyData, vtkScalars *s, vtkProperty *aProperty)
+void vtkRIBExporter::WriteStrips (vtkPolyData *polyData, vtkScalars *s, vtkProperty *aProperty, int useCellData)
 {
   float vertexColors[512][3];
   RtFloat *TCoords;
@@ -867,7 +883,9 @@
 
 
   // each iteration returns a triangle strip
-  for (strips->InitTraversal(); strips->GetNextCell(npts,pts); )
+  int cellNum=polyData->GetNumberOfVerts()+polyData->GetNumberOfLines()
+       +polyData->GetNumberOfPolys();
+  for (strips->InitTraversal(); strips->GetNextCell(npts,pts); cellNum++)
     { 
     // each triangle strip is converted into a bunch of triangles
     p1 = pts[0];
@@ -898,7 +916,8 @@
         {
         if (s) 
           {
-          colors = s->GetColor(idx[k]);
+          if(useCellData) colors=s->GetColor(cellNum);
+          else colors = s->GetColor(pts[k]);
           vertexColors[k][0] = colors[0] / 255.0;
           vertexColors[k][1] = colors[1] / 255.0;
           vertexColors[k][2] = colors[2] / 255.0;

-------------- next part --------------
--- vtkRIBExporter.h.orig	Sat Nov 11 22:28:10 2000
+++ vtkRIBExporter.h	Sun Nov 12 00:17:50 2000
@@ -148,8 +148,8 @@
   void WriteLight (vtkLight *aLight, int count);
   void WriteAmbientLight (int count);
   void WriteProperty (vtkProperty *aProperty, vtkTexture *aTexture);
-  void WritePolygons (vtkPolyData *pd, vtkScalars *colors, vtkProperty *aProperty);
-  void WriteStrips (vtkPolyData *pd, vtkScalars *colors, vtkProperty *aProperty);
+  void WritePolygons (vtkPolyData *pd, vtkScalars *colors, vtkProperty *aProperty, int useCellData);
+  void WriteStrips (vtkPolyData *pd, vtkScalars *colors, vtkProperty *aProperty, int useCellData);
 
   void WriteData();
   void WriteActor(vtkActor *anActor);



More information about the vtkusers mailing list