17
17
from cStringIO import StringIO
18
18
from datetime import datetime
19
19
from math import ceil , cos , floor , pi , sin
20
- import struct
21
20
try :
22
21
set
23
22
except NameError :
@@ -1068,11 +1067,10 @@ def writeGouraudTriangles(self):
1068
1067
gouraudDict [name ] = ob
1069
1068
shape = points .shape
1070
1069
flat_points = points .reshape ((shape [0 ] * shape [1 ], 2 ))
1070
+ flat_colors = colors .reshape ((shape [0 ] * shape [1 ], 4 ))
1071
1071
points_min = npy .min (flat_points , axis = 0 ) - (1 << 8 )
1072
1072
points_max = npy .max (flat_points , axis = 0 ) + (1 << 8 )
1073
1073
factor = float (0xffffffff ) / (points_max - points_min )
1074
- adjpoints = npy .array ((points - points_min ) * factor , dtype = npy .uint32 )
1075
- adjcolors = npy .array (colors * 255.0 , dtype = npy .uint8 )
1076
1074
1077
1075
self .beginStream (
1078
1076
ob .id , None ,
@@ -1087,10 +1085,16 @@ def writeGouraudTriangles(self):
1087
1085
0 , 1 , 0 , 1 , 0 , 1 ]
1088
1086
})
1089
1087
1090
- for tpoints , tcolors in zip (adjpoints , adjcolors ):
1091
- for p , c in zip (tpoints , tcolors ):
1092
- values = [int (x ) for x in [0 ] + list (p ) + list (c [:3 ])]
1093
- self .write (struct .pack ('>BLLBBB' , * values ))
1088
+ streamarr = npy .empty (
1089
+ (shape [0 ] * shape [1 ],),
1090
+ dtype = [('flags' , 'u1' ),
1091
+ ('points' , '>u4' , (2 ,)),
1092
+ ('colors' , 'u1' , (3 ,))])
1093
+ streamarr ['flags' ] = 0
1094
+ streamarr ['points' ] = (flat_points - points_min ) * factor
1095
+ streamarr ['colors' ] = flat_colors [:, :3 ] * 255.0
1096
+
1097
+ self .write (streamarr .tostring ())
1094
1098
self .endStream ()
1095
1099
self .writeObject (self .gouraudObject , gouraudDict )
1096
1100
@@ -1375,11 +1379,20 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
1375
1379
colors .reshape ((1 , 3 , 4 )), trans )
1376
1380
1377
1381
def draw_gouraud_triangles (self , gc , points , colors , trans ):
1382
+ assert len (points ) == len (colors )
1383
+ assert points .ndim == 3
1384
+ assert points .shape [1 ] == 3
1385
+ assert points .shape [2 ] == 2
1386
+ assert colors .ndim == 3
1387
+ assert colors .shape [1 ] == 3
1388
+ assert colors .shape [2 ] == 4
1389
+
1378
1390
shape = points .shape
1379
1391
points = points .reshape ((shape [0 ] * shape [1 ], 2 ))
1380
1392
tpoints = trans .transform (points )
1381
1393
tpoints = tpoints .reshape (shape )
1382
1394
name = self .file .addGouraudTriangles (tpoints , colors )
1395
+ self .check_gc (gc )
1383
1396
self .file .output (name , Op .shading )
1384
1397
1385
1398
def _setup_textpos (self , x , y , descent , angle , oldx = 0 , oldy = 0 , olddescent = 0 , oldangle = 0 ):
0 commit comments