@@ -858,51 +858,64 @@ def prepFillarea(renWin,ren,farea,cmap=None):
858858 n = prepPrimitive (farea )
859859 if n == 0 :
860860 return
861+
862+ # Find color map:
863+ if cmap is None :
864+ if farea .colormap is not None :
865+ cmap = farea .colormap
866+ else :
867+ cmap = 'default'
868+ if isinstance (cmap ,str ):
869+ cmap = vcs .elements ["colormap" ][cmap ]
870+
871+ # Create data structures:
872+ pts = vtk .vtkPoints ()
873+ polygons = vtk .vtkCellArray ()
874+ colors = vtk .vtkUnsignedCharArray ()
875+ colors .SetNumberOfComponents (3 )
876+ colors .SetNumberOfTuples (n )
877+ polygonPolyData = vtk .vtkPolyData ()
878+ polygonPolyData .SetPoints (pts )
879+ polygonPolyData .SetPolys (polygons )
880+ polygonPolyData .GetCellData ().SetScalars (colors )
881+
882+ # Reuse this temporary container to avoid reallocating repeatedly:
883+ polygon = vtk .vtkPolygon ()
884+
885+ # Iterate through polygons:
861886 for i in range (n ):
862887 x = farea .x [i ]
863888 y = farea .y [i ]
864889 c = farea .color [i ]
865890 st = farea .style [i ]
866891 idx = farea .index [i ]
867892 N = max (len (x ),len (y ))
893+
868894 for a in [x ,y ]:
869- while len (a )< n :
870- a .append (a [- 1 ])
871- #Create points
872- pts = vtk .vtkPoints ()
873- for j in range (N ):
874- pts .InsertNextPoint (x [j ],y [j ],0. )
875- #Create polygon out of these points
876- polygon = vtk .vtkPolygon ()
895+ assert (len (a ) == N )
896+
897+ # Add current polygon
877898 pid = polygon .GetPointIds ()
878899 pid .SetNumberOfIds (N )
879900 for j in range (N ):
880- pid .SetId (j ,j )
881- polygons = vtk .vtkCellArray ()
882- polygons .InsertNextCell (polygon )
901+ pid .SetId (j , pts .InsertNextPoint (x [j ],y [j ],0. ))
902+ cellId = polygons .InsertNextCell (polygon )
883903
884- polygonPolyData = vtk .vtkPolyData ()
885- geo ,pts = project (pts ,farea .projection ,farea .worldcoordinate )
886- polygonPolyData .SetPoints (pts )
887- polygonPolyData .SetPolys (polygons )
904+ # Add the color to the color array:
905+ color = cmap .index [c ]
906+ colors .SetTupleValue (cellId , [int ((C / 100. ) * 255 ) for C in color ])
888907
889- a = vtk .vtkActor ()
890- m = vtk .vtkPolyDataMapper ()
891- m .SetInputData (polygonPolyData )
892- a .SetMapper (m )
893- p = a .GetProperty ()
908+ # Transform points:
909+ geo ,pts = project (pts ,farea .projection ,farea .worldcoordinate )
894910
895- if cmap is None :
896- if farea .colormap is not None :
897- cmap = farea .colormap
898- else :
899- cmap = 'default'
900- if isinstance (cmap ,str ):
901- cmap = vcs .elements ["colormap" ][cmap ]
902- color = cmap .index [c ]
903- p .SetColor ([C / 100. for C in color ])
904- ren .AddActor (a )
905- fitToViewport (a ,ren ,farea .viewport ,wc = farea .worldcoordinate ,geo = geo )
911+ # Setup rendering
912+ m = vtk .vtkPolyDataMapper ()
913+ m .SetInputData (polygonPolyData )
914+ a = vtk .vtkActor ()
915+ a .SetMapper (m )
916+
917+ fitToViewport (a ,ren ,farea .viewport ,wc = farea .worldcoordinate ,geo = geo )
918+ ren .AddActor (a )
906919 return
907920
908921def genPoly (coords ,pts ,filled = True ):
0 commit comments