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