1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
43 // 2004-03-16, Gabriel Schreiber <schreiber@ient.rwth-aachen.de>
44 // Mark Asbach <asbach@ient.rwth-aachen.de>
45 // Institute of Communications Engineering, RWTH Aachen University
46 // 2008-04-09 Xavier Delacour <xavier.delacour@gmail.com>
48 // todo remove these..
49 #pragma SWIG nowarn=312,362,303,365,366,367,368,370,371,372,451,454,503
55 #include "octhelpers.h"
56 #include "octcvseq.hpp"
59 // include octave-specific files
60 %include "./octtypemaps.i"
61 %include "exception.i"
63 // the wrapping code to enable the use of Octave-based mouse callbacks
65 // This encapsulates the octave callback and user_data for mouse callback
66 struct OctCvMouseCBData {
67 octave_value oct_func;
68 octave_value user_data;
70 // This encapsulates the octave callback and user_data for mouse callback
71 // C helper function which is responsible for calling
72 // the Octave real trackbar callback function
73 static void icvOctOnMouse (int event, int x, int y,
74 int flags, OctCvMouseCBData * param) {
75 octave_value oct_func(param->oct_func);
76 if (!oct_func.is_function() && !oct_func.is_function_handle())
79 octave_value_list args;
80 args.append(octave_value(event));
81 args.append(octave_value(x));
82 args.append(octave_value(y));
83 args.append(octave_value(flags));
84 args.append(param->user_data);
85 oct_func.subsref ("(", std::list<octave_value_list>(1, args), 0);
89 // adapt cvSetMouseCallback to use octave callback
90 %rename (cvSetMouseCallbackOld) cvSetMouseCallback;
91 %rename (cvSetMouseCallback) cvSetMouseCallbackOct;
93 void cvSetMouseCallbackOct( const char* window_name, octave_value on_mouse, octave_value param = octave_value() ){
94 OctCvMouseCBData * oct_callback = new OctCvMouseCBData;
95 oct_callback->oct_func = on_mouse;
96 oct_callback->user_data = param;
97 cvSetMouseCallback( window_name, (CvMouseCallback) icvOctOnMouse, (void *) oct_callback );
101 // The following code enables trackbar callbacks from octave. Unfortunately, there is no
102 // way to distinguish which trackbar the event originated from, so must hard code a
103 // fixed number of unique c callback functions using the macros below
105 // C helper function which is responsible for calling
106 // the Octave real trackbar callback function
107 static void icvOctOnTrackbar( octave_value oct_cb_func, int pos) {
108 if (!oct_cb_func.is_function() && !oct_cb_func.is_function_handle())
111 octave_value_list args;
112 args.append(octave_value(pos));
113 oct_cb_func.subsref ("(", std::list<octave_value_list>(1, args), 0);
116 #define ICV_OCT_MAX_CB 10
118 struct OctCvTrackbar {
119 CvTrackbarCallback cv_func;
120 octave_value oct_func;
121 octave_value oct_pos;
124 static int my_trackbar_cb_size=0;
125 extern OctCvTrackbar my_trackbar_cb_funcs[ICV_OCT_MAX_CB];
128 // Callback table entry
129 %define %ICV_OCT_CB_TAB_ENTRY(idx)
130 {(CvTrackbarCallback) icvOctTrackbarCB##idx, octave_value(), octave_value() }
133 // Table of callbacks
134 %define %ICV_OCT_CB_TAB
136 OctCvTrackbar my_trackbar_cb_funcs[ICV_OCT_MAX_CB] = {
137 %ICV_OCT_CB_TAB_ENTRY(0),
138 %ICV_OCT_CB_TAB_ENTRY(1),
139 %ICV_OCT_CB_TAB_ENTRY(2),
140 %ICV_OCT_CB_TAB_ENTRY(3),
141 %ICV_OCT_CB_TAB_ENTRY(4),
142 %ICV_OCT_CB_TAB_ENTRY(5),
143 %ICV_OCT_CB_TAB_ENTRY(6),
144 %ICV_OCT_CB_TAB_ENTRY(7),
145 %ICV_OCT_CB_TAB_ENTRY(8),
146 %ICV_OCT_CB_TAB_ENTRY(9)
151 // Callback definition
152 %define %ICV_OCT_CB_IMPL(idx)
154 static void icvOctTrackbarCB##idx(int pos){
155 icvOctOnTrackbar(my_trackbar_cb_funcs[idx].oct_func, pos);
173 // typemap to memorize the Octave callback when doing cvCreateTrackbar ()
174 %typemap(in) CvTrackbarCallback {
175 if(my_trackbar_cb_size == ICV_OCT_MAX_CB){
176 SWIG_exception(SWIG_IndexError, "Exceeded maximum number of trackbars");
179 my_trackbar_cb_size++;
181 // memorize the Octave address of the callback function
182 my_trackbar_cb_funcs[my_trackbar_cb_size-1].oct_func = (octave_value) $input;
184 // prepare to call the C function who will register the callback
185 $1 = my_trackbar_cb_funcs[ my_trackbar_cb_size-1 ].cv_func;
189 %include "../general/highgui.i"
190 %include "adapters.i"