Skip to content

Commit

Permalink
Create path_cleanup code for use by the Mac OS-X backend. Refactor C+…
Browse files Browse the repository at this point in the history
…+ 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
  • Loading branch information
mdboom committed Feb 2, 2009
1 parent 853eacc commit 969d9cf
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 279 deletions.
266 changes: 135 additions & 131 deletions lib/matplotlib/delaunay/VoronoiDiagramGenerator.cpp

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,8 @@ def build_ft2font(ext_modules, packages):
deps.extend(glob.glob('CXX/*.cxx'))
deps.extend(glob.glob('CXX/*.c'))

module = Extension('matplotlib.ft2font', deps)
module = Extension('matplotlib.ft2font', deps,
define_macros=[('PY_ARRAYAUNIQUE_SYMBOL', 'MPL_ARRAY_API')])
add_ft2font_flags(module)
ext_modules.append(module)
BUILT_FT2FONT = True
Expand All @@ -1100,12 +1101,13 @@ def build_ttconv(ext_modules, packages):
def build_gtkagg(ext_modules, packages):
global BUILT_GTKAGG
if BUILT_GTKAGG: return # only build it if you you haven't already
deps = ['src/_gtkagg.cpp', 'src/mplutils.cpp']#, 'src/_transforms.cpp']
deps = ['src/agg_py_transforms.cpp', 'src/_gtkagg.cpp', 'src/mplutils.cpp']
deps.extend(glob.glob('CXX/*.cxx'))
deps.extend(glob.glob('CXX/*.c'))

module = Extension('matplotlib.backends._gtkagg',
deps,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)

# add agg flags before pygtk because agg only supports freetype1
Expand Down Expand Up @@ -1164,6 +1166,7 @@ def build_macosx(ext_modules, packages):
module = Extension('matplotlib.backends._macosx',
['src/_macosx.m'],
extra_link_args = ['-framework','Cocoa'],
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)
add_numpy_flags(module)
ext_modules.append(module)
Expand All @@ -1182,6 +1185,7 @@ def build_png(ext_modules, packages):
'matplotlib._png',
deps,
include_dirs=numpy_inc_dirs,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)

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


agg = (
'agg_trans_affine.cpp',
'agg_bezier_arc.cpp',
Expand All @@ -1204,22 +1207,20 @@ def build_agg(ext_modules, packages):
'agg_image_filters.cpp',
)


deps = ['%s/src/%s'%(AGG_VERSION, name) for name in agg]
deps.extend(('src/_image.cpp', 'src/ft2font.cpp', 'src/mplutils.cpp'))
deps.extend(['src/mplutils.cpp', 'src/agg_py_transforms.cpp'])
deps.extend(glob.glob('CXX/*.cxx'))
deps.extend(glob.glob('CXX/*.c'))

temp_copy('src/_backend_agg.cpp', 'src/backend_agg.cpp')
deps.append('src/backend_agg.cpp')
module = Extension(
'matplotlib.backends._backend_agg',
deps,
include_dirs=numpy_inc_dirs,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)

add_numpy_flags(module)

add_agg_flags(module)
add_ft2font_flags(module)
ext_modules.append(module)
Expand All @@ -1242,11 +1243,14 @@ def build_path(ext_modules, packages):
deps.extend(glob.glob('CXX/*.c'))

temp_copy('src/_path.cpp', 'src/path.cpp')
deps.extend(['src/path.cpp'])
deps.extend(['src/agg_py_transforms.cpp',
'src/path_cleanup.cpp',
'src/path.cpp'])
module = Extension(
'matplotlib._path',
deps,
include_dirs=numpy_inc_dirs,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)

add_numpy_flags(module)
Expand Down Expand Up @@ -1275,6 +1279,7 @@ def build_image(ext_modules, packages):
'matplotlib._image',
deps,
include_dirs=numpy_inc_dirs,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)

add_numpy_flags(module)
Expand All @@ -1294,7 +1299,9 @@ def build_delaunay(ext_modules, packages):
"delaunay_utils.cpp", "natneighbors.cpp"]
sourcefiles = [os.path.join('lib/matplotlib/delaunay',s) for s in sourcefiles]
delaunay = Extension('matplotlib._delaunay',sourcefiles,
include_dirs=numpy_inc_dirs)
include_dirs=numpy_inc_dirs,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)
add_numpy_flags(delaunay)
add_base_flags(delaunay)
ext_modules.append(delaunay)
Expand All @@ -1310,6 +1317,7 @@ def build_contour(ext_modules, packages):
'matplotlib._cntr',
[ 'src/cntr.c'],
include_dirs=numpy_inc_dirs,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)
add_numpy_flags(module)
add_base_flags(module)
Expand All @@ -1325,6 +1333,7 @@ def build_nxutils(ext_modules, packages):
'matplotlib.nxutils',
[ 'src/nxutils.c'],
include_dirs=numpy_inc_dirs,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)
add_numpy_flags(module)
add_base_flags(module)
Expand All @@ -1343,6 +1352,7 @@ def build_gdk(ext_modules, packages):
['src/backend_gdk.c'],
libraries = [],
include_dirs=numpy_inc_dirs,
define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]
)

add_numpy_flags(module)
Expand Down
25 changes: 12 additions & 13 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "swig_runtime.h"
#include "MPL_isnan.h"

#define PY_ARRAY_TYPES_PREFIX NumPy
#include "numpy/arrayobject.h"
#include "agg_py_transforms.h"

Expand Down Expand Up @@ -253,7 +252,7 @@ GCAgg::_set_clip_path( const Py::Object& gc) {
Py::Tuple path_and_transform = method.apply(Py::Tuple());
if (path_and_transform[0].ptr() != Py_None) {
clippath = path_and_transform[0];
clippath_trans = py_to_agg_transformation_matrix(path_and_transform[1]);
clippath_trans = py_to_agg_transformation_matrix(path_and_transform[1].ptr());
}
}

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

Py::Object gc_obj = args[0];
Py::Object marker_path_obj = args[1];
agg::trans_affine marker_trans = py_to_agg_transformation_matrix(args[2]);
agg::trans_affine marker_trans = py_to_agg_transformation_matrix(args[2].ptr());
Py::Object path_obj = args[3];
agg::trans_affine trans = py_to_agg_transformation_matrix(args[4]);
agg::trans_affine trans = py_to_agg_transformation_matrix(args[4].ptr());
Py::Object face_obj;
if (args.size() == 6)
face_obj = args[5];
Expand Down Expand Up @@ -748,7 +747,7 @@ RendererAgg::draw_image(const Py::Tuple& args) {
rendererBase.reset_clipping(true);
if (args.size() == 6) {
clippath = args[4];
clippath_trans = py_to_agg_transformation_matrix(args[5], false);
clippath_trans = py_to_agg_transformation_matrix(args[5].ptr(), false);
has_clippath = render_clippath(clippath, clippath_trans);
}

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

Py::Object gc_obj = args[0];
Py::Object path_obj = args[1];
agg::trans_affine trans = py_to_agg_transformation_matrix(args[2]);
agg::trans_affine trans = py_to_agg_transformation_matrix(args[2].ptr());
Py::Object face_obj;
if (args.size() == 4)
face_obj = args[3];
Expand Down Expand Up @@ -1071,7 +1070,7 @@ RendererAgg::_draw_path_collection_generic
transforms.reserve(Ntransforms);
for (i = 0; i < Ntransforms; ++i) {
agg::trans_affine trans = py_to_agg_transformation_matrix
(transforms_obj[i], false);
(transforms_obj[i].ptr(), false);
trans *= master_transform;

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

//segments, trans, clipbox, colors, linewidths, antialiaseds
agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0]);
agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0].ptr());
Py::Object cliprect = args[1];
Py::Object clippath = args[2];
agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3], false);
agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3].ptr(), false);
Py::SeqBase<Py::Object> paths = args[4];
Py::SeqBase<Py::Object> transforms_obj = args[5];
Py::Object offsets_obj = args[6];
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7]);
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7].ptr());
Py::Object facecolors_obj = args[8];
Py::Object edgecolors_obj = args[9];
Py::SeqBase<Py::Float> linewidths = args[10];
Expand Down Expand Up @@ -1328,15 +1327,15 @@ RendererAgg::draw_quad_mesh(const Py::Tuple& args) {


//segments, trans, clipbox, colors, linewidths, antialiaseds
agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0]);
agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0].ptr());
Py::Object cliprect = args[1];
Py::Object clippath = args[2];
agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3], false);
agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3].ptr(), false);
size_t mesh_width = Py::Int(args[4]);
size_t mesh_height = Py::Int(args[5]);
PyObject* coordinates = args[6].ptr();
Py::Object offsets_obj = args[7];
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[8]);
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[8].ptr());
Py::Object facecolors_obj = args[9];
bool antialiased = (bool)Py::Int(args[10]);
bool showedges = (bool)Py::Int(args[11]);
Expand Down
1 change: 0 additions & 1 deletion src/_backend_gdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

#include "Python.h"
#define PY_ARRAY_TYPES_PREFIX NumPy
#include "numpy/arrayobject.h"

#include <pygtk/pygtk.h>
Expand Down
3 changes: 1 addition & 2 deletions src/_gtkagg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
#include <fstream>

#include "agg_basics.h"
#include "_backend_agg.h"
#define PY_ARRAY_TYPES_PREFIX NumPy
#include "numpy/arrayobject.h"
#include "_backend_agg.h"
#include "agg_py_transforms.h"

// the extension module
Expand Down
14 changes: 0 additions & 14 deletions src/_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <cmath>
#include <cstdio>

#define PY_ARRAY_TYPES_PREFIX NumPy
#include "numpy/arrayobject.h"

#include "agg_color_rgba.h"
Expand Down Expand Up @@ -98,17 +97,6 @@ char Image::flipud_out__doc__[] =
"\n"
"Flip the output image upside down"
;
Py::Object
Image::flipud_out(const Py::Tuple& args) {
_VERBOSE("Image::flipud_out");

args.verify_length(0);
int stride = rbufOut->stride();
//std::cout << "flip before: " << rbufOut->stride() << std::endl;
rbufOut->attach(bufferOut, colsOut, rowsOut, -stride);
//std::cout << "flip after: " << rbufOut->stride() << std::endl;
return Py::Object();
}

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

d["ASPECT_FREE"] = Py::Int(Image::ASPECT_FREE);
d["ASPECT_PRESERVE"] = Py::Int(Image::ASPECT_PRESERVE);


}


Expand Down
10 changes: 9 additions & 1 deletion src/_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ class Image : public Py::PythonExtension<Image> {
Py::Object set_interpolation(const Py::Tuple& args);
Py::Object set_aspect(const Py::Tuple& args);
Py::Object set_bg(const Py::Tuple& args);
Py::Object flipud_out(const Py::Tuple& args);
inline Py::Object flipud_out(const Py::Tuple& args) {
args.verify_length(0);
int stride = rbufOut->stride();
//std::cout << "flip before: " << rbufOut->stride() << std::endl;
rbufOut->attach(bufferOut, colsOut, rowsOut, -stride);
//std::cout << "flip after: " << rbufOut->stride() << std::endl;
return Py::Object();
}

Py::Object flipud_in(const Py::Tuple& args);
Py::Object set_resample(const Py::Tuple& args);
Py::Object get_resample(const Py::Tuple& args);
Expand Down
Loading

0 comments on commit 969d9cf

Please sign in to comment.