Browse Source

Python wrapper additions

iss7
Trevor Irons 5 years ago
parent
commit
729aeb3585

+ 16
- 0
Modules/LemmaCore/python/CMakeLists.txt View File

@@ -0,0 +1,16 @@
1
+# include directories
2
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/python)
3
+
4
+# create the lib
5
+add_library(pyLemmaCore SHARED ${CMAKE_CURRENT_SOURCE_DIR}/pyLemmaCore.cpp)
6
+
7
+# link
8
+target_link_libraries(pyLemmaCore ${Boost_LIBRARIES} lemmacore)
9
+
10
+# Copy the __init__.py file
11
+configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py COPYONLY)
12
+
13
+# Suppress prefix "lib" because Python does not allow this prefix
14
+set_target_properties(pyLemmaCore PROPERTIES PREFIX "")
15
+
16
+#install(TARGETS pyLemmaCore __init__.py DESTINATION "${PYTHON_INSTALL_PATH}")

+ 2
- 0
Modules/LemmaCore/python/__init__.py View File

@@ -0,0 +1,2 @@
1
+from .pyLemmaCore import * # Add class or functions
2
+# ...

+ 65
- 0
Modules/LemmaCore/python/pyLemmaCore.cpp View File

@@ -0,0 +1,65 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      22/04/19 14:06:32
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@utah.edu
16
+ * @copyright Copyright (c) 2019, University of Utah
17
+ * @copyright Copyright (c) 2019, Lemma Software, LLC
18
+ */
19
+
20
+#include "LemmaCore"
21
+#include <string>
22
+
23
+#include <boost/python.hpp>
24
+#include <boost/python/numpy.hpp>
25
+// Include the headers of MyLib
26
+
27
+//using namespace boost::python;
28
+
29
+namespace bp = boost::python;
30
+namespace np = boost::python::numpy;
31
+
32
+BOOST_PYTHON_MODULE(pyLemmaCore)
33
+{
34
+    Py_Initialize();
35
+    np::initialize();
36
+
37
+ 	bp::class_<Lemma::RectilinearGrid, boost::noncopyable> ("RectilinearGrid", boost::python::no_init)
38
+
39
+        // print
40
+        .def(boost::python::self_ns::str(bp::self))
41
+
42
+        // Lifecycle
43
+        .def("__init__", boost::python::make_constructor(&Lemma::RectilinearGrid::NewSP))
44
+        //.def("Serialize", &Lemma::RectilinearGrid::Serialize)
45
+        //.def("DeSerialize", &Lemma::RectilinearGrid::DeSerialize)
46
+
47
+        // Accessors
48
+        .def("GetName", &Lemma::RectilinearGrid::GetName)
49
+        .def("GetNx", &Lemma::RectilinearGrid::GetNx)
50
+        .def("GetNy", &Lemma::RectilinearGrid::GetNy)
51
+        .def("GetNz", &Lemma::RectilinearGrid::GetNz)
52
+        .def("GetOx", &Lemma::RectilinearGrid::GetOx)
53
+        .def("GetOy", &Lemma::RectilinearGrid::GetOy)
54
+        .def("GetOz", &Lemma::RectilinearGrid::GetOz)
55
+        //.def("GetDx", &Lemma::RectilinearGrid::GetDx)
56
+        //.def("GetDy", &Lemma::RectilinearGrid::GetDy)
57
+        //.def("GetDz", &Lemma::RectilinearGrid::GetDz)
58
+
59
+        .def("SetDimensions", &Lemma::RectilinearGrid::SetDimensions)
60
+        .def("SetOffset", &Lemma::RectilinearGrid::SetOffset)
61
+        .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing)
62
+
63
+    ;
64
+
65
+}

Loading…
Cancel
Save