Skip to content

Commit 969d9cf

Browse files
committed
Create path_cleanup code for use by the Mac OS-X backend. Refactor C++ code to follow Numpy's guidelines for linking multiple C files into a single extension. Remove dependency of Agg backend on _image.cpp and _ft2font.cpp (simplifies linking problems and reduces generated code size).
svn path=/trunk/matplotlib/; revision=6865
1 parent 853eacc commit 969d9cf

16 files changed

Lines changed: 440 additions & 279 deletions

lib/matplotlib/delaunay/VoronoiDiagramGenerator.cpp

Lines changed: 135 additions & 131 deletions
Large diffs are not rendered by default.

setupext.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,8 @@ def build_ft2font(ext_modules, packages):
10791079
deps.extend(glob.glob('CXX/*.cxx'))
10801080
deps.extend(glob.glob('CXX/*.c'))
10811081

1082-
module = Extension('matplotlib.ft2font', deps)
1082+
module = Extension('matplotlib.ft2font', deps,
1083+
define_macros=[('PY_ARRAYAUNIQUE_SYMBOL', 'MPL_ARRAY_API')])
10831084
add_ft2font_flags(module)
10841085
ext_modules.append(module)
10851086
BUILT_FT2FONT = True
@@ -1100,12 +1101,13 @@ def build_ttconv(ext_modules, packages):
11001101
def build_gtkagg(ext_modules, packages):
11011102
global BUILT_GTKAGG
11021103
if BUILT_GTKAGG: return # only build it if you you haven't already
1103-
deps = ['src/_gtkagg.cpp', 'src/mplutils.cpp']#, 'src/_transforms.cpp']
1104+
deps = ['src/agg_py_transforms.cpp', 'src/_gtkagg.cpp', 'src/mplutils.cpp']
11041105
deps.extend(glob.glob('CXX/*.cxx'))
11051106
deps.extend(glob.glob('CXX/*.c'))
11061107

11071108
module = Extension('matplotlib.backends._gtkagg',
11081109
deps,
1110+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
11091111
)
11101112

11111113
# add agg flags before pygtk because agg only supports freetype1
@@ -1164,6 +1166,7 @@ def build_macosx(ext_modules, packages):
11641166
module = Extension('matplotlib.backends._macosx',
11651167
['src/_macosx.m'],
11661168
extra_link_args = ['-framework','Cocoa'],
1169+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
11671170
)
11681171
add_numpy_flags(module)
11691172
ext_modules.append(module)
@@ -1182,6 +1185,7 @@ def build_png(ext_modules, packages):
11821185
'matplotlib._png',
11831186
deps,
11841187
include_dirs=numpy_inc_dirs,
1188+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
11851189
)
11861190

11871191
add_png_flags(module)
@@ -1194,7 +1198,6 @@ def build_agg(ext_modules, packages):
11941198
global BUILT_AGG
11951199
if BUILT_AGG: return # only build it if you you haven't already
11961200

1197-
11981201
agg = (
11991202
'agg_trans_affine.cpp',
12001203
'agg_bezier_arc.cpp',
@@ -1204,22 +1207,20 @@ def build_agg(ext_modules, packages):
12041207
'agg_image_filters.cpp',
12051208
)
12061209

1207-
12081210
deps = ['%s/src/%s'%(AGG_VERSION, name) for name in agg]
1209-
deps.extend(('src/_image.cpp', 'src/ft2font.cpp', 'src/mplutils.cpp'))
1211+
deps.extend(['src/mplutils.cpp', 'src/agg_py_transforms.cpp'])
12101212
deps.extend(glob.glob('CXX/*.cxx'))
12111213
deps.extend(glob.glob('CXX/*.c'))
1212-
12131214
temp_copy('src/_backend_agg.cpp', 'src/backend_agg.cpp')
12141215
deps.append('src/backend_agg.cpp')
12151216
module = Extension(
12161217
'matplotlib.backends._backend_agg',
12171218
deps,
12181219
include_dirs=numpy_inc_dirs,
1220+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
12191221
)
12201222

12211223
add_numpy_flags(module)
1222-
12231224
add_agg_flags(module)
12241225
add_ft2font_flags(module)
12251226
ext_modules.append(module)
@@ -1242,11 +1243,14 @@ def build_path(ext_modules, packages):
12421243
deps.extend(glob.glob('CXX/*.c'))
12431244

12441245
temp_copy('src/_path.cpp', 'src/path.cpp')
1245-
deps.extend(['src/path.cpp'])
1246+
deps.extend(['src/agg_py_transforms.cpp',
1247+
'src/path_cleanup.cpp',
1248+
'src/path.cpp'])
12461249
module = Extension(
12471250
'matplotlib._path',
12481251
deps,
12491252
include_dirs=numpy_inc_dirs,
1253+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
12501254
)
12511255

12521256
add_numpy_flags(module)
@@ -1275,6 +1279,7 @@ def build_image(ext_modules, packages):
12751279
'matplotlib._image',
12761280
deps,
12771281
include_dirs=numpy_inc_dirs,
1282+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
12781283
)
12791284

12801285
add_numpy_flags(module)
@@ -1294,7 +1299,9 @@ def build_delaunay(ext_modules, packages):
12941299
"delaunay_utils.cpp", "natneighbors.cpp"]
12951300
sourcefiles = [os.path.join('lib/matplotlib/delaunay',s) for s in sourcefiles]
12961301
delaunay = Extension('matplotlib._delaunay',sourcefiles,
1297-
include_dirs=numpy_inc_dirs)
1302+
include_dirs=numpy_inc_dirs,
1303+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
1304+
)
12981305
add_numpy_flags(delaunay)
12991306
add_base_flags(delaunay)
13001307
ext_modules.append(delaunay)
@@ -1310,6 +1317,7 @@ def build_contour(ext_modules, packages):
13101317
'matplotlib._cntr',
13111318
[ 'src/cntr.c'],
13121319
include_dirs=numpy_inc_dirs,
1320+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
13131321
)
13141322
add_numpy_flags(module)
13151323
add_base_flags(module)
@@ -1325,6 +1333,7 @@ def build_nxutils(ext_modules, packages):
13251333
'matplotlib.nxutils',
13261334
[ 'src/nxutils.c'],
13271335
include_dirs=numpy_inc_dirs,
1336+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
13281337
)
13291338
add_numpy_flags(module)
13301339
add_base_flags(module)
@@ -1343,6 +1352,7 @@ def build_gdk(ext_modules, packages):
13431352
['src/backend_gdk.c'],
13441353
libraries = [],
13451354
include_dirs=numpy_inc_dirs,
1355+
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
13461356
)
13471357

13481358
add_numpy_flags(module)

src/_backend_agg.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "swig_runtime.h"
3838
#include "MPL_isnan.h"
3939

40-
#define PY_ARRAY_TYPES_PREFIX NumPy
4140
#include "numpy/arrayobject.h"
4241
#include "agg_py_transforms.h"
4342

@@ -253,7 +252,7 @@ GCAgg::_set_clip_path( const Py::Object& gc) {
253252
Py::Tuple path_and_transform = method.apply(Py::Tuple());
254253
if (path_and_transform[0].ptr() != Py_None) {
255254
clippath = path_and_transform[0];
256-
clippath_trans = py_to_agg_transformation_matrix(path_and_transform[1]);
255+
clippath_trans = py_to_agg_transformation_matrix(path_and_transform[1].ptr());
257256
}
258257
}
259258

@@ -471,9 +470,9 @@ RendererAgg::draw_markers(const Py::Tuple& args) {
471470

472471
Py::Object gc_obj = args[0];
473472
Py::Object marker_path_obj = args[1];
474-
agg::trans_affine marker_trans = py_to_agg_transformation_matrix(args[2]);
473+
agg::trans_affine marker_trans = py_to_agg_transformation_matrix(args[2].ptr());
475474
Py::Object path_obj = args[3];
476-
agg::trans_affine trans = py_to_agg_transformation_matrix(args[4]);
475+
agg::trans_affine trans = py_to_agg_transformation_matrix(args[4].ptr());
477476
Py::Object face_obj;
478477
if (args.size() == 6)
479478
face_obj = args[5];
@@ -748,7 +747,7 @@ RendererAgg::draw_image(const Py::Tuple& args) {
748747
rendererBase.reset_clipping(true);
749748
if (args.size() == 6) {
750749
clippath = args[4];
751-
clippath_trans = py_to_agg_transformation_matrix(args[5], false);
750+
clippath_trans = py_to_agg_transformation_matrix(args[5].ptr(), false);
752751
has_clippath = render_clippath(clippath, clippath_trans);
753752
}
754753

@@ -963,7 +962,7 @@ RendererAgg::draw_path(const Py::Tuple& args) {
963962

964963
Py::Object gc_obj = args[0];
965964
Py::Object path_obj = args[1];
966-
agg::trans_affine trans = py_to_agg_transformation_matrix(args[2]);
965+
agg::trans_affine trans = py_to_agg_transformation_matrix(args[2].ptr());
967966
Py::Object face_obj;
968967
if (args.size() == 4)
969968
face_obj = args[3];
@@ -1071,7 +1070,7 @@ RendererAgg::_draw_path_collection_generic
10711070
transforms.reserve(Ntransforms);
10721071
for (i = 0; i < Ntransforms; ++i) {
10731072
agg::trans_affine trans = py_to_agg_transformation_matrix
1074-
(transforms_obj[i], false);
1073+
(transforms_obj[i].ptr(), false);
10751074
trans *= master_transform;
10761075

10771076
transforms.push_back(trans);
@@ -1212,14 +1211,14 @@ RendererAgg::draw_path_collection(const Py::Tuple& args) {
12121211
args.verify_length(14);
12131212

12141213
//segments, trans, clipbox, colors, linewidths, antialiaseds
1215-
agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0]);
1214+
agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0].ptr());
12161215
Py::Object cliprect = args[1];
12171216
Py::Object clippath = args[2];
1218-
agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3], false);
1217+
agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3].ptr(), false);
12191218
Py::SeqBase<Py::Object> paths = args[4];
12201219
Py::SeqBase<Py::Object> transforms_obj = args[5];
12211220
Py::Object offsets_obj = args[6];
1222-
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7]);
1221+
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7].ptr());
12231222
Py::Object facecolors_obj = args[8];
12241223
Py::Object edgecolors_obj = args[9];
12251224
Py::SeqBase<Py::Float> linewidths = args[10];
@@ -1328,15 +1327,15 @@ RendererAgg::draw_quad_mesh(const Py::Tuple& args) {
13281327

13291328

13301329
//segments, trans, clipbox, colors, linewidths, antialiaseds
1331-
agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0]);
1330+
agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0].ptr());
13321331
Py::Object cliprect = args[1];
13331332
Py::Object clippath = args[2];
1334-
agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3], false);
1333+
agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3].ptr(), false);
13351334
size_t mesh_width = Py::Int(args[4]);
13361335
size_t mesh_height = Py::Int(args[5]);
13371336
PyObject* coordinates = args[6].ptr();
13381337
Py::Object offsets_obj = args[7];
1339-
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[8]);
1338+
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[8].ptr());
13401339
Py::Object facecolors_obj = args[9];
13411340
bool antialiased = (bool)Py::Int(args[10]);
13421341
bool showedges = (bool)Py::Int(args[11]);

src/_backend_gdk.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
#include "Python.h"
6-
#define PY_ARRAY_TYPES_PREFIX NumPy
76
#include "numpy/arrayobject.h"
87

98
#include <pygtk/pygtk.h>

src/_gtkagg.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
#include <fstream>
1111

1212
#include "agg_basics.h"
13-
#include "_backend_agg.h"
14-
#define PY_ARRAY_TYPES_PREFIX NumPy
1513
#include "numpy/arrayobject.h"
14+
#include "_backend_agg.h"
1615
#include "agg_py_transforms.h"
1716

1817
// the extension module

src/_image.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <cmath>
1212
#include <cstdio>
1313

14-
#define PY_ARRAY_TYPES_PREFIX NumPy
1514
#include "numpy/arrayobject.h"
1615

1716
#include "agg_color_rgba.h"
@@ -98,17 +97,6 @@ char Image::flipud_out__doc__[] =
9897
"\n"
9998
"Flip the output image upside down"
10099
;
101-
Py::Object
102-
Image::flipud_out(const Py::Tuple& args) {
103-
_VERBOSE("Image::flipud_out");
104-
105-
args.verify_length(0);
106-
int stride = rbufOut->stride();
107-
//std::cout << "flip before: " << rbufOut->stride() << std::endl;
108-
rbufOut->attach(bufferOut, colsOut, rowsOut, -stride);
109-
//std::cout << "flip after: " << rbufOut->stride() << std::endl;
110-
return Py::Object();
111-
}
112100

113101
char Image::flipud_in__doc__[] =
114102
"flipud()\n"
@@ -1756,8 +1744,6 @@ init_image(void) {
17561744

17571745
d["ASPECT_FREE"] = Py::Int(Image::ASPECT_FREE);
17581746
d["ASPECT_PRESERVE"] = Py::Int(Image::ASPECT_PRESERVE);
1759-
1760-
17611747
}
17621748

17631749

src/_image.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ class Image : public Py::PythonExtension<Image> {
3939
Py::Object set_interpolation(const Py::Tuple& args);
4040
Py::Object set_aspect(const Py::Tuple& args);
4141
Py::Object set_bg(const Py::Tuple& args);
42-
Py::Object flipud_out(const Py::Tuple& args);
42+
inline Py::Object flipud_out(const Py::Tuple& args) {
43+
args.verify_length(0);
44+
int stride = rbufOut->stride();
45+
//std::cout << "flip before: " << rbufOut->stride() << std::endl;
46+
rbufOut->attach(bufferOut, colsOut, rowsOut, -stride);
47+
//std::cout << "flip after: " << rbufOut->stride() << std::endl;
48+
return Py::Object();
49+
}
50+
4351
Py::Object flipud_in(const Py::Tuple& args);
4452
Py::Object set_resample(const Py::Tuple& args);
4553
Py::Object get_resample(const Py::Tuple& args);

0 commit comments

Comments
 (0)