Skip to content

Commit d51a6ea

Browse files
Base classes for python interface
1 parent b3ef3da commit d51a6ea

File tree

13 files changed

+687
-110
lines changed

13 files changed

+687
-110
lines changed

python/helios/helios_python.cpp

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ PYBIND11_MAKE_OPAQUE(std::vector<Trajectory>);
6767
#include <filems/facade/FMSFacade.h>
6868
#include <python/GLMTypeCaster.h>
6969
#include <python/ScannerWrap.h>
70-
#include<python/PyHeliosSimulation.h>
70+
#include <python/PyHeliosSimulation.h>
7171
#include <python/SimulationWrap.h>
72-
#include<python/NoiseSourceWrap.h>
73-
#include<python/AbstractDetectorWrap.h>
74-
#include<python/utils.h>
72+
#include <python/NoiseSourceWrap.h>
73+
#include <python/AbstractDetectorWrap.h>
74+
#include <python/utils.h>
75+
#include <python/PrimitiveWrap.h>
76+
#include <python/AbstractBeamDeflectorWrap.h>
7577

7678

7779

@@ -83,8 +85,7 @@ namespace pyhelios{
8385
py::bind_vector<std::vector<std::string>>(m, "StringVector");
8486
py::bind_vector<std::vector<Measurement>>(m, "MeasurementVector");
8587
py::bind_vector<std::vector<Trajectory>>(m, "TrajectoryVector");
86-
py::bind_vector<std::vector<double>>(m, "DoubleVector"); // CHECK THIS!!!! : you'll need to make sure that you correctly handle the vector's indexing and modification methods.
87-
88+
py::bind_vector<std::vector<double>>(m, "DoubleVector");
8889
py::implicitly_convertible<py::iterable, VectorString>();
8990

9091
logging::makeQuiet();
@@ -105,16 +106,19 @@ namespace pyhelios{
105106
m.def("logging_time", &logging::makeTime, "Set the logging verbosity level to time");
106107

107108
m.def("default_rand_generator_seed", &setDefaultRandomnessGeneratorSeed, "Set the seed for the default randomness generator");
108-
109-
py::class_<AABB> aabb(m, "AABB");
109+
110+
py::class_<AABB, std::shared_ptr<AABB>> aabb(m, "AABB");
110111
aabb
111-
.def_static("create", []() { return std::make_unique<AABB>(); }, py::return_value_policy::take_ownership)
112+
.def_static("create", []() { return std::make_shared<AABB>(); }, py::return_value_policy::take_ownership)
113+
112114
.def_property_readonly("min_vertex", [](AABB &aabb) { return &(aabb.vertices[0]); }, py::return_value_policy::reference)
113115
.def_property_readonly("max_vertex", [](AABB &aabb) { return &(aabb.vertices[1]); }, py::return_value_policy::reference)
114116
.def("__str__", &AABB::toString);
115117

116-
py::class_<AbstractBeamDeflector, std::shared_ptr<AbstractBeamDeflector>> abstract_beam_deflector(m, "AbstractBeamDeflector");
118+
py::class_<AbstractBeamDeflector, AbstractBeamDeflectorWrap, std::shared_ptr<AbstractBeamDeflector>> abstract_beam_deflector(m, "AbstractBeamDeflector");
117119
abstract_beam_deflector
120+
.def(py::init<double, double, double>(),
121+
py::arg("scanAngleMax_rad"), py::arg("scanFreqMax_Hz"), py::arg("scanFreqMin_Hz"))
118122
.def_readwrite("scan_freq_max",&AbstractBeamDeflector::cfg_device_scanFreqMax_Hz)
119123
.def_readwrite("scan_freq_min",&AbstractBeamDeflector::cfg_device_scanFreqMin_Hz)
120124
.def_readwrite("scan_angle_max",&AbstractBeamDeflector::cfg_device_scanAngleMax_rad)
@@ -129,8 +133,9 @@ namespace pyhelios{
129133
&AbstractBeamDeflector::getEmitterRelativeAttitudeByReference)
130134
.def_property_readonly("optics_type", &AbstractBeamDeflector::getOpticsType);
131135

132-
py::class_<Primitive> primitive(m, "Primitive");
136+
py::class_<Primitive, PrimitiveWrap, std::shared_ptr<Primitive>> primitive(m, "Primitive");
133137
primitive
138+
.def(py::init<>())
134139
.def_property_readonly("scene_part", [](Primitive &prim) {
135140
return prim.part.get(); })
136141
.def_property_readonly("material", [](Primitive &prim) {
@@ -169,18 +174,18 @@ namespace pyhelios{
169174
});
170175

171176

172-
py::class_<DetailedVoxel> detailed_voxel(m, "DetailedVoxel", py::base<Primitive>());
177+
py::class_<DetailedVoxel, std::shared_ptr<DetailedVoxel>, Primitive> detailed_voxel(m, "DetailedVoxel");
173178
detailed_voxel
174179
.def(py::init<>())
175-
.def(py::init<double, double, double, double, std::vector<int>, std::vector<double>>(),
176-
py::arg("x"), py::arg("y"), py::arg("z"), py::arg("halfVoxelSize"), py::arg("intValues"), py::arg("doubleValues"))
180+
.def(py::init<glm::dvec3, double, std::vector<int>, std::vector<double>>(),
181+
py::arg("center"), py::arg("VoxelSize"), py::arg("intValues"), py::arg("doubleValues"))
177182

178183
.def_property("nb_echos", &DetailedVoxel::getNbEchos, &DetailedVoxel::setNbEchos)
179184
.def_property("nb_sampling", &DetailedVoxel::getNbSampling, &DetailedVoxel::setNbSampling)
180185
.def_property_readonly("number_of_double_values", &DetailedVoxel::getNumberOfDoubleValues)
181-
.def_property("maxPad", &DetailedVoxel::getMaxPad, &DetailedVoxel::setMaxPad)
182-
.def("doubleValue", &DetailedVoxel::getDoubleValue, "Get the value at index")
183-
.def("doubleValue", &DetailedVoxel::setDoubleValue, "Set the value at index", py::arg("index"), py::arg("value"));
186+
.def_property("max_pad", &DetailedVoxel::getMaxPad, &DetailedVoxel::setMaxPad)
187+
.def("get_double_value", &DetailedVoxel::getDoubleValue, "Get the value at index")
188+
.def("set_double_value", &DetailedVoxel::setDoubleValue, "Set the value at index", py::arg("index"), py::arg("value"));
184189

185190

186191
py::class_<AbstractDetector, AbstractDetectorWrap, std::shared_ptr<AbstractDetector>> abstract_detector(m, "AbstractDetector");
@@ -189,14 +194,12 @@ namespace pyhelios{
189194
std::shared_ptr<Scanner>,
190195
double,
191196
double,
192-
double,
193-
std::shared_ptr<UnivarExprTreeNode<double>>
197+
double
194198
>(),
195199
py::arg("scanner"),
196200
py::arg("accuracy_m"),
197201
py::arg("rangeMin_m"),
198-
py::arg("rangeMax_m") = std::numeric_limits<double>::max(),
199-
py::arg("errorDistanceExpr") = nullptr)
202+
py::arg("rangeMax_m") = std::numeric_limits<double>::max())
200203

201204
.def_readwrite("accuracy", &AbstractDetector::cfg_device_accuracy_m)
202205
.def_readwrite("range_min", &AbstractDetector::cfg_device_rangeMin_m)
@@ -207,7 +210,7 @@ namespace pyhelios{
207210
[](AbstractDetector &self, double lasScale) {
208211
self.getFMS()->write.setMeasurementWriterLasScale(lasScale);});
209212

210-
py::class_<Triangle> triangle(m, "Triangle", py::base<Primitive>());
213+
py::class_<Triangle, std::shared_ptr<Triangle>, Primitive> triangle(m, "Triangle");
211214
triangle
212215
.def(py::init<Vertex, Vertex, Vertex>(), py::arg("v0"), py::arg("v1"), py::arg("v2"))
213216
.def("__str__", &Triangle::toString)
@@ -229,9 +232,7 @@ namespace pyhelios{
229232
.def(py::init<>())
230233
.def(py::init<double, glm::dvec3, double, double, double>())
231234
.def_readwrite("gps_time", &Trajectory::gpsTime)
232-
.def_property("position",
233-
[](const Trajectory &t) { return t.position; },
234-
[](Trajectory &t, const glm::dvec3 &pos) { t.position = pos; })
235+
.def_readwrite("position", &Trajectory::position)
235236
.def_readwrite("roll", &Trajectory::roll)
236237
.def_readwrite("pitch", &Trajectory::pitch)
237238
.def_readwrite("yaw", &Trajectory::yaw);
@@ -462,6 +463,8 @@ namespace pyhelios{
462463
py::class_<Survey, std::unique_ptr<Survey, py::nodelete>> survey(m, "Survey", py::module_local());
463464
survey
464465
.def(py::init<>())
466+
467+
.def_readwrite("scanner", &Survey::scanner)
465468
.def("calculate_length", &Survey::calculateLength)
466469
.def_property_readonly("length", &Survey::getLength)
467470
.def_property("name",
@@ -489,7 +492,7 @@ namespace pyhelios{
489492
.def_property("strip", &Leg::getStrip, &Leg::setStrip)
490493
.def("belongs_to_strip", &Leg::isContainedInAStrip);
491494

492-
py::class_<ScenePart> scene_part(m, "ScenePart");
495+
py::class_<ScenePart, std::shared_ptr<ScenePart>> scene_part(m, "ScenePart");
493496
scene_part
494497
.def(py::init<>())
495498
.def(py::init<const ScenePart&, bool>(),
@@ -534,7 +537,7 @@ namespace pyhelios{
534537
}
535538
})
536539

537-
540+
.def_property("primitives", &ScenePart::getPrimitives, &ScenePart::setPrimitives)
538541
.def("primitive", [](ScenePart& self, size_t index) -> Primitive* {
539542
if (index < self.mPrimitives.size()) {
540543
return self.mPrimitives[index];
@@ -610,12 +613,10 @@ namespace pyhelios{
610613
.def_readwrite("speed_m_s", &PlatformSettings::movePerSec_m)
611614

612615
.def_property_readonly("base_template", &PlatformSettings::getTemplate, py::return_value_policy::reference)
613-
.def_property_readonly("position", &PlatformSettings::getPosition)
616+
.def_property("position", &PlatformSettings::getPosition, [](PlatformSettings& self, const glm::dvec3& pos) { self.setPosition(pos); }) //&PlatformSettings::setPosition)
614617

615618
.def("cherryPick", &PlatformSettings::cherryPick, py::arg("cherries"), py::arg("fields"), py::arg("templateFields") = nullptr)
616619

617-
.def("set_position", py::overload_cast<glm::dvec3>(&PlatformSettings::setPosition))
618-
.def("set_position", py::overload_cast<double, double, double>(&PlatformSettings::setPosition))
619620
.def("has_template", &PlatformSettings::hasTemplate)
620621
.def("to_string", &PlatformSettings::toString);
621622

@@ -624,12 +625,13 @@ namespace pyhelios{
624625
.def(py::init<>())
625626
.def(py::init<Scene&>(), py::arg("scene"))
626627

628+
.def_readwrite("scene_parts", &Scene::parts)
627629

628630
.def_property("bbox", &Scene::getBBox, &Scene::setBBox)
629631
.def_property("bbox_crs", &Scene::getBBoxCRS, &Scene::setBBoxCRS)
630632
.def_property_readonly("num_primitives", [](const ScenePart& self) -> size_t {
631633
return self.mPrimitives.size();})
632-
.def_property_readonly("AABB", &Scene::getAABB, py::return_value_policy::reference)
634+
.def_property_readonly("aabb", &Scene::getAABB, py::return_value_policy::reference)
633635

634636
.def_property_readonly("shift", &Scene::getShift)
635637
.def_property("dyn_scene_step",
@@ -720,8 +722,8 @@ namespace pyhelios{
720722
.def_property_readonly("last_ground_check", [](const Platform &self) {
721723
return self.lastGroundCheck;})
722724

723-
.def_property_readonly("position", &Platform::getPosition)//, &Platform::setPosition)
724-
.def_property_readonly("attitude", &Platform::getAttitude)//, &Platform::setAttitude)
725+
.def_property_readonly("position", &Platform::getPosition)
726+
.def_property_readonly("attitude", &Platform::getAttitude)
725727
.def_property_readonly("absolute_mount_position", &Platform::getAbsoluteMountPosition)
726728
.def_property_readonly("absolute_mount_attitude", &Platform::getAbsoluteMountAttitude)
727729

@@ -791,7 +793,14 @@ namespace pyhelios{
791793

792794
py::class_<Scanner, ScannerWrap, std::shared_ptr<Scanner>> scanner(m, "Scanner");
793795
scanner
794-
.def(py::init<>())
796+
.def(py::init<std::string const&, std::list<int> const&, bool, bool, bool, bool, bool>(),
797+
py::arg("id"),
798+
py::arg("pulseFreqs"),
799+
py::arg("writeWaveform") = false,
800+
py::arg("writePulse") = false,
801+
py::arg("calcEchowidth") = false,
802+
py::arg("fullWaveNoise") = false,
803+
py::arg("platformNoiseDisabled") = false)
795804
.def(py::init<Scanner&>(), py::arg("scanner"))
796805

797806
.def("initialize_sequential_generators", &Scanner::initializeSequentialGenerators)
@@ -950,21 +959,17 @@ namespace pyhelios{
950959
py::overload_cast<>(&Scanner::getDeviceId, py::const_),
951960
py::overload_cast<std::string>(&Scanner::setDeviceId))
952961

953-
.def_property("scanner_head",
954-
py::overload_cast<>(&Scanner::getScannerHead),
955-
py::overload_cast<std::shared_ptr<ScannerHead>>(&Scanner::setScannerHead))
962+
.def_property_readonly("scanner_head",
963+
py::overload_cast<>(&Scanner::getScannerHead))
956964

957-
.def_property("beam_deflector",
958-
py::overload_cast<>(&Scanner::getBeamDeflector),
959-
py::overload_cast<std::shared_ptr<AbstractBeamDeflector>>(&Scanner::setBeamDeflector))
965+
.def_property_readonly("beam_deflector",
966+
py::overload_cast<>(&Scanner::getBeamDeflector))
960967

961-
.def_property("detector",
962-
py::overload_cast<>(&Scanner::getDetector),
963-
py::overload_cast<std::shared_ptr<AbstractDetector>>(&Scanner::setDetector))
968+
.def_property_readonly("detector",
969+
py::overload_cast<>(&Scanner::getDetector))
964970

965-
.def_property("supported_pulse_freqs_hz",
966-
py::overload_cast<>(&Scanner::getSupportedPulseFreqs_Hz),
967-
py::overload_cast<std::list<int>&>(&Scanner::setSupportedPulseFreqs_Hz))
971+
.def_property_readonly("supported_pulse_freqs_hz",
972+
py::overload_cast<>(&Scanner::getSupportedPulseFreqs_Hz))
968973

969974
.def_property("num_time_bins",
970975
py::overload_cast<>(&Scanner::getNumTimeBins, py::const_),

python/helios/scene.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

python/pyhelios/leg.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from pyhelios.utils import Validatable, ValidatedCppManagedProperty
2+
from pyhelios.platforms import PlatformSettings
3+
from pyhelios.scanner import ScannerSettings
4+
from typing import Optional, List, Tuple, Annotated, Type, Any
5+
6+
import _helios
7+
8+
9+
10+
class ScanningStrip(Validatable):
11+
def __init__(self, strip_id: Optional[str] = "", legs: Optional[List['Leg']] = None) -> None:
12+
13+
self._cpp_object = _helios.ScanningStrip(strip_id)
14+
self.strip_id = strip_id
15+
16+
17+
strip_id: Optional[str] = ValidatedCppManagedProperty("strip_id")
18+
19+
class Leg(Validatable):
20+
def __init__(self, platform_settings: Optional[PlatformSettings] = None, scanner_settings: Optional[ScannerSettings] = None,
21+
scanning_strip: Optional[ScanningStrip] = None, length: Optional[float] = 0.0, serial_id: Optional[int] = 0, belongs_to_strip: Optional[bool] = False) -> None:
22+
23+
self._cpp_object = _helios.Leg()
24+
self.platform_settings = platform_settings
25+
self.scanner_settings = scanner_settings
26+
self.strip = scanning_strip
27+
28+
29+
self.length = length
30+
self.serial_id = serial_id
31+
32+
33+
platform_settings: Optional[PlatformSettings] = ValidatedCppManagedProperty("platform_settings")
34+
scanner_settings: Optional[ScannerSettings] = ValidatedCppManagedProperty("scanner_settings")
35+
scanning_strip: Optional[ScanningStrip] = ValidatedCppManagedProperty("scanning_strip")
36+
length: Optional[float] = ValidatedCppManagedProperty("length")
37+
serial_id: Optional[int] = ValidatedCppManagedProperty("serial_id")
38+

0 commit comments

Comments
 (0)