aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/contourpy/src/converter.h
blob: 5bf9ab5119d1db1dabb5dc0a6b62ee4f2781c531 (plain) (blame)
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
#ifndef CONTOURPY_CONVERTER_H
#define CONTOURPY_CONVERTER_H

#include "common.h"

namespace contourpy {

// Conversion of C++ point/code/offset array to return to Python as a NumPy array.
// There are two versions of each function, the first creates, populates and returns a NumPy array
// whereas the second populates one that has already been created. The former are used in serial
// code and the latter in threaded code where the creation and manipulation of NumPy arrays needs to
// be threadlocked whereas the population of those arrays does not.
class Converter
{
public:
    // Create and populate codes array,
    static CodeArray convert_codes(
        count_t point_count, count_t cut_count, const offset_t* cut_start, offset_t subtract);

    // Populate codes array that has already been created.
    static void convert_codes(
        count_t point_count, count_t cut_count, const offset_t* cut_start, offset_t subtract,
        CodeArray::value_type* codes);

    // Create and populate codes array,
    static CodeArray convert_codes_check_closed(
        count_t point_count, count_t cut_count, const offset_t* cut_start, const double* points);

    // Populate codes array that has already been created.
    static void convert_codes_check_closed(
        count_t point_count, count_t cut_count, const offset_t* cut_start, const double* points,
        CodeArray::value_type* codes);

    // Create and populate codes array (single line loop/strip).
    static CodeArray convert_codes_check_closed_single(
        count_t point_count, const double* points);

    // Populate codes array that has already been created (single line loop/strip).
    static void convert_codes_check_closed_single(
        count_t point_count, const double* points, CodeArray::value_type* codes);

    // Create and populate offsets array,
    static OffsetArray convert_offsets(
        count_t offset_count, const offset_t* start, offset_t subtract);

    // Populate offsets array that has already been created.
    static void convert_offsets(
        count_t offset_count, const offset_t* start, offset_t subtract,
        OffsetArray::value_type* offsets);

    // Create and populate points array,
    static PointArray convert_points(count_t point_count, const double* start);

    // Populate points array that has already been created.
    static void convert_points(count_t point_count, const double* start, double* points);

private:
    static void check_max_offset(count_t max_offset);
};

} // namespace contourpy

#endif // CONTOURPY_CONVERTER_H