Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BPy_ContextFunctions.cpp « python « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a4b83b840f338f680e98d0f9d195dcb50ffb3450 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup freestyle
 */

#include "BPy_ContextFunctions.h"
#include "BPy_Convert.h"

#include "../stroke/ContextFunctions.h"

#include "BLI_sys_types.h"

using namespace Freestyle;

#ifdef __cplusplus
extern "C" {
#endif

///////////////////////////////////////////////////////////////////////////////////////////

//------------------------ MODULE FUNCTIONS ----------------------------------

static char ContextFunctions_get_time_stamp___doc__[] =
    ".. function:: get_time_stamp()\n"
    "\n"
    "   Returns the system time stamp.\n"
    "\n"
    "   :return: The system time stamp.\n"
    "   :rtype: int\n";

static PyObject *ContextFunctions_get_time_stamp(PyObject * /*self*/)
{
  return PyLong_FromLong(ContextFunctions::GetTimeStampCF());
}

static char ContextFunctions_get_canvas_width___doc__[] =
    ".. method:: get_canvas_width()\n"
    "\n"
    "   Returns the canvas width.\n"
    "\n"
    "   :return: The canvas width.\n"
    "   :rtype: int\n";

static PyObject *ContextFunctions_get_canvas_width(PyObject * /*self*/)
{
  return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF());
}

static char ContextFunctions_get_canvas_height___doc__[] =
    ".. method:: get_canvas_height()\n"
    "\n"
    "   Returns the canvas height.\n"
    "\n"
    "   :return: The canvas height.\n"
    "   :rtype: int\n";

static PyObject *ContextFunctions_get_canvas_height(PyObject * /*self*/)
{
  return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF());
}

static char ContextFunctions_get_border___doc__[] =
    ".. method:: get_border()\n"
    "\n"
    "   Returns the border.\n"
    "\n"
    "   :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n"
    "   :rtype: tuple\n";

static PyObject *ContextFunctions_get_border(PyObject * /*self*/)
{
  BBox<Vec2i> border(ContextFunctions::GetBorderCF());
  PyObject *v = PyTuple_New(4);
  PyTuple_SET_ITEMS(v,
                    PyLong_FromLong(border.getMin().x()),
                    PyLong_FromLong(border.getMin().y()),
                    PyLong_FromLong(border.getMax().x()),
                    PyLong_FromLong(border.getMax().y()));
  return v;
}

static char ContextFunctions_load_map___doc__[] =
    ".. function:: load_map(file_name, map_name, num_levels=4, sigma=1.0)\n"
    "\n"
    "   Loads an image map for further reading.\n"
    "\n"
    "   :arg file_name: The name of the image file.\n"
    "   :type file_name: str\n"
    "   :arg map_name: The name that will be used to access this image.\n"
    "   :type map_name: str\n"
    "   :arg num_levels: The number of levels in the map pyramid\n"
    "      (default = 4).  If num_levels == 0, the complete pyramid is\n"
    "      built.\n"
    "   :type num_levels: int\n"
    "   :arg sigma: The sigma value of the gaussian function.\n"
    "   :type sigma: float\n";

static PyObject *ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds)
{
  static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", nullptr};
  char *fileName, *mapName;
  uint nbLevels = 4;
  float sigma = 1.0;

  if (!PyArg_ParseTupleAndKeywords(
          args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma)) {
    return nullptr;
  }
  ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
  Py_RETURN_NONE;
}

static char ContextFunctions_read_map_pixel___doc__[] =
    ".. function:: read_map_pixel(map_name, level, x, y)\n"
    "\n"
    "   Reads a pixel in a user-defined map.\n"
    "\n"
    "   :arg map_name: The name of the map.\n"
    "   :type map_name: str\n"
    "   :arg level: The level of the pyramid in which we wish to read the\n"
    "      pixel.\n"
    "   :type level: int\n"
    "   :arg x: The x coordinate of the pixel we wish to read.  The origin\n"
    "      is in the lower-left corner.\n"
    "   :type x: int\n"
    "   :arg y: The y coordinate of the pixel we wish to read.  The origin\n"
    "      is in the lower-left corner.\n"
    "   :type y: int\n"
    "   :return: The floating-point value stored for that pixel.\n"
    "   :rtype: float\n";

static PyObject *ContextFunctions_read_map_pixel(PyObject * /*self*/,
                                                 PyObject *args,
                                                 PyObject *kwds)
{
  static const char *kwlist[] = {"map_name", "level", "x", "y", nullptr};
  char *mapName;
  int level;
  uint x, y;

  if (!PyArg_ParseTupleAndKeywords(
          args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y)) {
    return nullptr;
  }
  return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y));
}

static char ContextFunctions_read_complete_view_map_pixel___doc__[] =
    ".. function:: read_complete_view_map_pixel(level, x, y)\n"
    "\n"
    "   Reads a pixel in the complete view map.\n"
    "\n"
    "   :arg level: The level of the pyramid in which we wish to read the\n"
    "      pixel.\n"
    "   :type level: int\n"
    "   :arg x: The x coordinate of the pixel we wish to read.  The origin\n"
    "      is in the lower-left corner.\n"
    "   :type x: int\n"
    "   :arg y: The y coordinate of the pixel we wish to read.  The origin\n"
    "      is in the lower-left corner.\n"
    "   :type y: int\n"
    "   :return: The floating-point value stored for that pixel.\n"
    "   :rtype: float\n";

static PyObject *ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/,
                                                               PyObject *args,
                                                               PyObject *kwds)
{
  static const char *kwlist[] = {"level", "x", "y", nullptr};
  int level;
  uint x, y;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y)) {
    return nullptr;
  }
  return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y));
}

static char ContextFunctions_read_directional_view_map_pixel___doc__[] =
    ".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n"
    "\n"
    "   Reads a pixel in one of the oriented view map images.\n"
    "\n"
    "   :arg orientation: The number telling which orientation we want to\n"
    "      check.\n"
    "   :type orientation: int\n"
    "   :arg level: The level of the pyramid in which we wish to read the\n"
    "      pixel.\n"
    "   :type level: int\n"
    "   :arg x: The x coordinate of the pixel we wish to read.  The origin\n"
    "      is in the lower-left corner.\n"
    "   :type x: int\n"
    "   :arg y: The y coordinate of the pixel we wish to read.  The origin\n"
    "      is in the lower-left corner.\n"
    "   :type y: int\n"
    "   :return: The floating-point value stored for that pixel.\n"
    "   :rtype: float\n";

static PyObject *ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/,
                                                                  PyObject *args,
                                                                  PyObject *kwds)
{
  static const char *kwlist[] = {"orientation", "level", "x", "y", nullptr};
  int orientation, level;
  uint x, y;

  if (!PyArg_ParseTupleAndKeywords(
          args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y)) {
    return nullptr;
  }
  return PyFloat_FromDouble(
      ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y));
}

static char ContextFunctions_get_selected_fedge___doc__[] =
    ".. function:: get_selected_fedge()\n"
    "\n"
    "   Returns the selected FEdge.\n"
    "\n"
    "   :return: The selected FEdge.\n"
    "   :rtype: :class:`FEdge`\n";

static PyObject *ContextFunctions_get_selected_fedge(PyObject * /*self*/)
{
  FEdge *fe = ContextFunctions::GetSelectedFEdgeCF();
  if (fe) {
    return Any_BPy_FEdge_from_FEdge(*fe);
  }
  Py_RETURN_NONE;
}

/*-----------------------ContextFunctions module docstring-------------------------------*/

static char module_docstring[] = "The Blender Freestyle.ContextFunctions submodule\n\n";

/*-----------------------ContextFunctions module functions definitions-------------------*/

static PyMethodDef module_functions[] = {
    {"get_time_stamp",
     (PyCFunction)ContextFunctions_get_time_stamp,
     METH_NOARGS,
     ContextFunctions_get_time_stamp___doc__},
    {"get_canvas_width",
     (PyCFunction)ContextFunctions_get_canvas_width,
     METH_NOARGS,
     ContextFunctions_get_canvas_width___doc__},
    {"get_canvas_height",
     (PyCFunction)ContextFunctions_get_canvas_height,
     METH_NOARGS,
     ContextFunctions_get_canvas_height___doc__},
    {"get_border",
     (PyCFunction)ContextFunctions_get_border,
     METH_NOARGS,
     ContextFunctions_get_border___doc__},
    {"load_map",
     (PyCFunction)ContextFunctions_load_map,
     METH_VARARGS | METH_KEYWORDS,
     ContextFunctions_load_map___doc__},
    {"read_map_pixel",
     (PyCFunction)ContextFunctions_read_map_pixel,
     METH_VARARGS | METH_KEYWORDS,
     ContextFunctions_read_map_pixel___doc__},
    {"read_complete_view_map_pixel",
     (PyCFunction)ContextFunctions_read_complete_view_map_pixel,
     METH_VARARGS | METH_KEYWORDS,
     ContextFunctions_read_complete_view_map_pixel___doc__},
    {"read_directional_view_map_pixel",
     (PyCFunction)ContextFunctions_read_directional_view_map_pixel,
     METH_VARARGS | METH_KEYWORDS,
     ContextFunctions_read_directional_view_map_pixel___doc__},
    {"get_selected_fedge",
     (PyCFunction)ContextFunctions_get_selected_fedge,
     METH_NOARGS,
     ContextFunctions_get_selected_fedge___doc__},
    {nullptr, nullptr, 0, nullptr},
};

/*-----------------------ContextFunctions module definition--------------------------------*/

static PyModuleDef module_definition = {
    PyModuleDef_HEAD_INIT,
    /*m_name*/ "Freestyle.ContextFunctions",
    /*m_doc*/ module_docstring,
    /*m_size*/ -1,
    /*m_methods*/ module_functions,
    /*m_slots*/ NULL,
    /*m_traverse*/ NULL,
    /*m_clear*/ NULL,
    /*m_free*/ NULL,
};

//------------------- MODULE INITIALIZATION --------------------------------

int ContextFunctions_Init(PyObject *module)
{
  PyObject *m;

  if (module == nullptr) {
    return -1;
  }

  m = PyModule_Create(&module_definition);
  if (m == nullptr) {
    return -1;
  }
  Py_INCREF(m);
  PyModule_AddObject(module, "ContextFunctions", m);

  return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////

#ifdef __cplusplus
}
#endif