You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-33Lines changed: 48 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,15 @@ The macro `_p` captures variable name and expands into ("variable_name", variabl
78
78
79
79
**Note**: Every container that is passed to python for plotting will be converted into an numpy array. This means fancy array slicing and array manipulations is possible. Just treat data as if it is originated in python with numpy.
80
80
81
+
Currently supports
82
+
* 1D std vector
83
+
* 1D std array
84
+
* 2D std vector
85
+
* 2D std array
86
+
* Eigen containers
87
+
88
+
For information on how to include support for custom containers read section [custom container support](https://github.com/muralivnv/Cppyplot#custom-container-support).
89
+
81
90
## How-it-works
82
91
Plot object `cppyplot` passes all the commands and containers to a python server (which is spawned automatically when the `cppyplot` object is created) using ZeroMQ. The spawned python server uses [asteval](https://anaconda.org/conda-forge/asteval) library to parse the passed commands. This means any command that can be used in python can be written on C++ side.
83
92
@@ -96,63 +105,69 @@ As the library uses zmq, link the source file which uses cppyplot.hpp with the l
96
105
## Custom Container Support
97
106
By defining 3 helper functions, any c++ container can be adapted to pass onto python side.
98
107
99
-
#### Define `size_str`
100
-
Define function to transform container size (total number of elems) into string object. See example down below where `size_str` function was defined for containers of type `std::array` and `std::vector`.
108
+
Define the following functions at the end of the **cppyplot_container_support.h** located in the include folder.
109
+
110
+
#### Define `container_size`
111
+
Define function to return container size (total number of elems). See example down below where `container_size` function was defined for containers of type `std::array` and `std::vector`.
Follow the link, [Eigen_Support](https://github.com/muralivnv/Cppyplot/blob/master/include/cppyplot.hpp#L171) to look at Eigen container support.
119
-
**Note**: This function need to be defined before the class defintion `cppyplot` in file `cppyplot.hpp`.
120
-
121
-
#### Define `shape_str`
122
-
Define function to transform container shape (number of row, number of cols) into string object. See example down below where `shape_str` function was defined for containers of type `std::vector` and `std::vector<std::vector>`. This shape information will be used to reshape the array on python side using numpy.
125
+
#### Define `container_shape`
126
+
Define function to return container shape (number of row, number of cols). See example down below where `container_shape` function was defined for containers of type `std::vector` and `std::vector<std::vector>`. This shape information will be used to reshape the array on python side using numpy.
The underlying zmq publisher requires pointer to the raw buffer inside the container to pass the data to python server. For that purpose define function `void_ptr` to extract data pointer and cast it into `(void*)`. See example down below which shows how to extract raw pointers for containers of type `std::vector` and `std::array`.
140
+
#### Define `fill_zmq_buffer`
141
+
The underlying zmq buffer requires either copying data to its buffer or pointing the zmq buffer to the container buffer.
142
+
143
+
Use the technique down below to point zmq buffer to the container buffer if the data inside the container is stored in one single continuous buffer. See example down below, where `fill_zmq_buffer` is defined for 1D-vector. As the internal vector buffer is stored in one continuous buffer, we can just point zmq buffer to vector buffer with custom dealloc function.
If the buffer insider custom container is not stored in one single continuous buffer(for example `vector<vector<float>>`) then use mempcy to copy data.
155
+
156
+
```cpp
157
+
// 2D vector
158
+
// this uses mempcpy, there will be a runtime overhead
159
+
template<typename T, std::size_t N, std::size_t M>
0 commit comments