Skip to content

Commit

Permalink
feat: add obj drawing possibility as python function (#2400)
Browse files Browse the repository at this point in the history
Title says it all, since Obj is a natural visualisation of the Core library that doesn't need any extension, it's also handy from the python side.

This practically allows you to do
```python
acts.drawSurfacesObj(surfaces, context, colouring, filename)
```
  • Loading branch information
asalzburger committed Aug 28, 2023
1 parent c1e0cb5 commit 22bdf2a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions Examples/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pybind11_add_module(ActsPythonBindings
src/Input.cpp
src/Propagation.cpp
src/Generators.cpp
src/Obj.cpp
src/TruthTracking.cpp
src/TrackFitting.cpp
src/TrackFinding.cpp
Expand Down
2 changes: 2 additions & 0 deletions Examples/Python/src/ModuleEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ void addHepMC3(Context& ctx);
void addExaTrkXTrackFinding(Context& ctx);
void addEDM4hep(Context& ctx);
void addSvg(Context& ctx);
void addObj(Context& ctx);
void addOnnx(Context& ctx);
void addOnnxMlpack(Context& ctx);
void addOnnxNeuralCalibrator(Context& ctx);
Expand Down Expand Up @@ -399,6 +400,7 @@ PYBIND11_MODULE(ActsPythonBindings, m) {
addHepMC3(ctx);
addExaTrkXTrackFinding(ctx);
addEDM4hep(ctx);
addObj(ctx);
addSvg(ctx);
addOnnx(ctx);
addOnnxMlpack(ctx);
Expand Down
55 changes: 55 additions & 0 deletions Examples/Python/src/Obj.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <Acts/Definitions/Algebra.hpp>
#include <Acts/Geometry/GeometryContext.hpp>
#include <Acts/Plugins/Python/Utilities.hpp>
#include <Acts/Surfaces/Surface.hpp>
#include <Acts/Visualization/GeometryView3D.hpp>
#include <Acts/Visualization/ObjVisualization3D.hpp>
#include <Acts/Visualization/ViewConfig.hpp>

#include <memory>

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;
using namespace pybind11::literals;

using namespace Acts;

namespace Acts::Python {
void addObj(Context& ctx) {
auto [m, mex] = ctx.get("main", "examples");

{
/// Write a collection of surfaces to an '.obj' file
///
/// @param surfaces is the collection of surfaces
/// @param viewContext is the geometry context
/// @param viewRgb is the color of the surfaces
/// @param fileName is the path to the output file
///
mex.def("writeSurfacesObj",
[](const std::vector<std::shared_ptr<Surface>>& surfaces,
const GeometryContext& viewContext,
const std::array<int, 3>& viewRgb, const std::string& fileName) {
Acts::ViewConfig sConfig = Acts::ViewConfig{viewRgb};
Acts::GeometryView3D view3D;
Acts::ObjVisualization3D obj;

for (const auto& surface : surfaces) {
view3D.drawSurface(obj, *surface, viewContext,
Acts::Transform3::Identity(), sConfig);
}
obj.write(fileName);
});
}
}
} // namespace Acts::Python

0 comments on commit 22bdf2a

Please sign in to comment.