setupMexPoly2tri

PURPOSE ^

SETUPMEXPOLY2TRI Build mex file for polygon triangulation function POLY2TRI.

SYNOPSIS ^

function setupMexPoly2tri()

DESCRIPTION ^

SETUPMEXPOLY2TRI  Build mex file for polygon triangulation function POLY2TRI.

  Syntax:
    SETUPMEXPOLY2TRI()

  Description:
    SETUPMEXPOLY2TRI() builds a mex file implementing the function POLY2TRI,
    that performs polygon triangulation based on the General Polygon Clipper 
    library (GPC). GPC should be installed from the non-free section of the 
    official repositories on Debian based distributions, in which case the mex
    file is built using the following attributes:
      TARGET:
        /path/to/poly2tri.mex(a64)
      SOURCES:
        /path/to/poly2tri.c
      INCLUDES:
        none
      LIBRARIES:
        -l gpcl
    Alternatively, it is possible to build the mex file using the GPC sources 
    directly. This is useful on systems that do not distribute the GPC library,
    or to use a version of GPC different from the one installed in the system.
    The GPC sources should be downloaded from the official web site and 
    extracted to a directory called 'gpcl' in the same directory than the mex
    file source:
      TARGET:
        /path/to/poly2tri.mex(a64)
      SOURCES:
        /path/to/poly2tri.c /path/to/gpcl/gpc.c
      INCLUDES:
        /path/to/gpcl/gpc.h
      LIBRARIES:
        none
    Please note that when using this build rule, mex file and library sources
    are compiled together. Hence the resulting binary might be slightly bigger.

  Notes:
    GPC is a library developed by Alan Murta at the University of Manchester,
    freely available for non-profit use:
      <http://www.cs.man.ac.uk/~amurta/software/index.html#gpc>

    On Debian based systems, GPC library may be installed from the non-free
    section of the official repositories running the following command as root:
      apt-get install libgpcl-dev

    This function uses the function MEX to build the target. On GNU/Linux 
    systems, the build process might fail after a warning if the compiler 
    version is newer than the latest version supported by MATLAB, even though
    running the same MEX command on a system shell builds the target properly.
    The reason is that MATLAB may extent or overwrite the environment variable
    LD_LIBRARY_PATH to point to its own version of the standard libraries,
    causing an incompatibility with the version of the compiler.
    To solve the problem, either build the target from the shell or temporarily
    overwrite the environment variable LD_LIBRARY_PATH from the MATLAB session.

  References:
    Alan Murta, GPC - General Polygon Clipper library:
    <http://www.cs.man.ac.uk/~amurta/software/index.html#gpc>

  Examples:
    % Check that GPC development files are installed on your system,
    % or that GPC sources are present in the directory private/gpcl
    setupMexPoly2tri()

    % Incompatible versions of system compiler and libraries shipped with the
    % the interpreter may cause build failure.
    % Try to build the target against system libraries instead of shipped ones.
    ld_library_path = getenv('LD_LIBRARY_PATH')
    setenv('LD_LIBRARY_PATH')
    setupMexPoly2tri()
    setenv('LD_LIBRARY_PATH', ld_library_path)
    clear('ld_library_path')

  See also:
    POLY2TRI

  Authors:
    Joan Pau Beltran  <joanpau.beltran@socib.cat>

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

setupMexPoly2tri.m

SOURCE CODE ^

0001 function setupMexPoly2tri()
0002 %SETUPMEXPOLY2TRI  Build mex file for polygon triangulation function POLY2TRI.
0003 %
0004 %  Syntax:
0005 %    SETUPMEXPOLY2TRI()
0006 %
0007 %  Description:
0008 %    SETUPMEXPOLY2TRI() builds a mex file implementing the function POLY2TRI,
0009 %    that performs polygon triangulation based on the General Polygon Clipper
0010 %    library (GPC). GPC should be installed from the non-free section of the
0011 %    official repositories on Debian based distributions, in which case the mex
0012 %    file is built using the following attributes:
0013 %      TARGET:
0014 %        /path/to/poly2tri.mex(a64)
0015 %      SOURCES:
0016 %        /path/to/poly2tri.c
0017 %      INCLUDES:
0018 %        none
0019 %      LIBRARIES:
0020 %        -l gpcl
0021 %    Alternatively, it is possible to build the mex file using the GPC sources
0022 %    directly. This is useful on systems that do not distribute the GPC library,
0023 %    or to use a version of GPC different from the one installed in the system.
0024 %    The GPC sources should be downloaded from the official web site and
0025 %    extracted to a directory called 'gpcl' in the same directory than the mex
0026 %    file source:
0027 %      TARGET:
0028 %        /path/to/poly2tri.mex(a64)
0029 %      SOURCES:
0030 %        /path/to/poly2tri.c /path/to/gpcl/gpc.c
0031 %      INCLUDES:
0032 %        /path/to/gpcl/gpc.h
0033 %      LIBRARIES:
0034 %        none
0035 %    Please note that when using this build rule, mex file and library sources
0036 %    are compiled together. Hence the resulting binary might be slightly bigger.
0037 %
0038 %  Notes:
0039 %    GPC is a library developed by Alan Murta at the University of Manchester,
0040 %    freely available for non-profit use:
0041 %      <http://www.cs.man.ac.uk/~amurta/software/index.html#gpc>
0042 %
0043 %    On Debian based systems, GPC library may be installed from the non-free
0044 %    section of the official repositories running the following command as root:
0045 %      apt-get install libgpcl-dev
0046 %
0047 %    This function uses the function MEX to build the target. On GNU/Linux
0048 %    systems, the build process might fail after a warning if the compiler
0049 %    version is newer than the latest version supported by MATLAB, even though
0050 %    running the same MEX command on a system shell builds the target properly.
0051 %    The reason is that MATLAB may extent or overwrite the environment variable
0052 %    LD_LIBRARY_PATH to point to its own version of the standard libraries,
0053 %    causing an incompatibility with the version of the compiler.
0054 %    To solve the problem, either build the target from the shell or temporarily
0055 %    overwrite the environment variable LD_LIBRARY_PATH from the MATLAB session.
0056 %
0057 %  References:
0058 %    Alan Murta, GPC - General Polygon Clipper library:
0059 %    <http://www.cs.man.ac.uk/~amurta/software/index.html#gpc>
0060 %
0061 %  Examples:
0062 %    % Check that GPC development files are installed on your system,
0063 %    % or that GPC sources are present in the directory private/gpcl
0064 %    setupMexPoly2tri()
0065 %
0066 %    % Incompatible versions of system compiler and libraries shipped with the
0067 %    % the interpreter may cause build failure.
0068 %    % Try to build the target against system libraries instead of shipped ones.
0069 %    ld_library_path = getenv('LD_LIBRARY_PATH')
0070 %    setenv('LD_LIBRARY_PATH')
0071 %    setupMexPoly2tri()
0072 %    setenv('LD_LIBRARY_PATH', ld_library_path)
0073 %    clear('ld_library_path')
0074 %
0075 %  See also:
0076 %    POLY2TRI
0077 %
0078 %  Authors:
0079 %    Joan Pau Beltran  <joanpau.beltran@socib.cat>
0080 
0081 %  Copyright (C) 2013-2016
0082 %  ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears
0083 %  <http://www.socib.es>
0084 %
0085 %  This program is free software: you can redistribute it and/or modify
0086 %  it under the terms of the GNU General Public License as published by
0087 %  the Free Software Foundation, either version 3 of the License, or
0088 %  (at your option) any later version.
0089 %
0090 %  This program is distributed in the hope that it will be useful,
0091 %  but WITHOUT ANY WARRANTY; without even the implied warranty of
0092 %  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0093 %  GNU General Public License for more details.
0094 %
0095 %  You should have received a copy of the GNU General Public License
0096 %  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0097 
0098   error(nargchk(0, 0, nargin, 'struct'));
0099 
0100   funcname = 'poly2tri';
0101   funcpath =  which(funcname);
0102   
0103   if isempty(funcpath)
0104     error('glider_toolbox:setup:NotFound', ...
0105           'Could not find location of %s.', funcname);
0106   end
0107   
0108   prefix = fileparts(funcpath);
0109   target = fullfile(prefix, [funcname '.' mexext()]);
0110   sources = fullfile(prefix, [funcname '.c']);
0111   gpcldir = fullfile(prefix, 'gpcl');
0112   gpclsrc = fullfile(gpcldir, 'gpc.c');
0113   gpcl = 'gpcl';
0114 
0115   if exist(gpcldir, 'dir')
0116     % mex -outdir mex_tools mex_tools/poly2tri.c mex_tools/gpcl/gpc.c
0117     mex('-output', target, sources, gpclsrc);
0118   else
0119     % mex -outdir mex_tools -lgpcl mex_tools/poly2tri.c
0120     mex('-output', target, ['-l' gpcl], sources);
0121   end
0122 
0123 end

Generated on Fri 06-Oct-2017 10:47:42 by m2html © 2005