Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(geo): Geometry visualization update #3681

Merged
merged 28 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
04f506b
feat: Add mutable surface getter to Portal
paulgessinger Sep 19, 2024
2029567
feat(geo): TrackingVolume gets portal storage
paulgessinger Sep 16, 2024
e3522ed
Merge branch 'main' into feat/trk-vol-surface-storage
paulgessinger Oct 2, 2024
288125d
Merge branch 'main' into feat/trk-vol-surface-storage
kodiakhq[bot] Oct 2, 2024
16850a5
fix: pybind11 compatibility for paths
paulgessinger Sep 20, 2024
f8e1fd8
refactor: ViewConfig python bindings
paulgessinger Sep 17, 2024
202bec6
refactor: Move ObjVisualization to cpp file
paulgessinger Sep 17, 2024
4ee20a4
fix: IVisualization gets virtual destructor
paulgessinger Sep 20, 2024
f7c4d81
feat: (Obj)Visualization gets sub object support
paulgessinger Sep 17, 2024
261703a
refactor(util): Locate default visualization colors with ViewConfig s…
paulgessinger Oct 1, 2024
762d968
feat: python bindings for visualization writing
paulgessinger Sep 20, 2024
66a74ec
feat(geo): Add visualization method to Tracking{Volume,Geometry}
paulgessinger Sep 20, 2024
48c3011
refactor(util): Make Color hex construction actually constexpr
paulgessinger Oct 1, 2024
caccbfc
fix: Obj python bindings filsystem update
paulgessinger Sep 20, 2024
b5a90d3
fix: Obj python bindings
paulgessinger Sep 20, 2024
45c9487
refactor: Geometry python binding improvements
paulgessinger Sep 20, 2024
fe02d82
feat(geo): Visualize surface, use view config default colors
paulgessinger Oct 1, 2024
fb91bc6
remove some unused headers
paulgessinger Oct 2, 2024
e4ff9b2
fix warning related to missing initalizer
paulgessinger Oct 2, 2024
007a854
move hex function
paulgessinger Oct 2, 2024
542e5e4
obj: separate objects for sensitives and portals
paulgessinger Oct 2, 2024
2d34cbf
fix overlapping view config bindings
paulgessinger Oct 2, 2024
f2257f4
feat(geo): Visualization python bindings update
paulgessinger Oct 2, 2024
714729f
adapt to center interface
paulgessinger Oct 2, 2024
d311643
sonar fixes
paulgessinger Oct 2, 2024
3c45762
revert file handle change back to path argument
paulgessinger Oct 3, 2024
6187dbc
Merge remote-tracking branch 'origin/main' into feat/obj-objects
paulgessinger Oct 7, 2024
8535403
Merge branch 'main' into feat/obj-objects
kodiakhq[bot] Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Core/include/Acts/Geometry/TrackingGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ class TrackingGeometry {
const std::unordered_map<GeometryIdentifier, const Surface*>&
geoIdSurfaceMap() const;

/// Visualize a tracking geometry including substructure
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
/// @param helper The visualization helper that implement the output
/// @param gctx The geometry context
/// @param viewConfig Global view config
/// @param portalViewConfig View config for portals
/// @param sensitiveViewConfig View configuration for sensitive surfaces
void visualize(IVisualization3D& helper, const GeometryContext& gctx,
const ViewConfig& viewConfig = s_viewVolume,
const ViewConfig& portalViewConfig = s_viewPortal,
const ViewConfig& sensitiveViewConfig = s_viewSensitive) const;

private:
// the known world
std::shared_ptr<TrackingVolume> m_world;
Expand Down
12 changes: 12 additions & 0 deletions Core/include/Acts/Geometry/TrackingVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Acts/Utilities/BinnedArray.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/TransformRange.hpp"
#include "Acts/Visualization/ViewConfig.hpp"

#include <cstddef>
#include <memory>
Expand Down Expand Up @@ -473,6 +474,17 @@ class TrackingVolume : public Volume {
/// - positiveFaceXY
GlueVolumesDescriptor& glueVolumesDescriptor();

/// Produces a 3D visualization of this tracking volume
/// @param helper The visualization helper describing the output format
/// @param gctx The geometry context
/// @param viewConfig The view configuration
/// @param portalViewConfig View configuration for portals
/// @param sensitiveViewConfig View configuration for sensitive surfaces
void visualize(IVisualization3D& helper, const GeometryContext& gctx,
const ViewConfig& viewConfig = s_viewVolume,
const ViewConfig& portalViewConfig = s_viewPortal,
const ViewConfig& sensitiveViewConfig = s_viewSensitive) const;

private:
void connectDenseBoundarySurfaces(
MutableTrackingVolumeVector& confinedDenseVolumes);
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/Surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class Surface : public virtual GeometryObject,
const GeometryContext& gctx, const Vector3& position) const = 0;

void visualize(IVisualization3D& helper, const GeometryContext& gctx,
const ViewConfig& viewConfig = {}) const;
const ViewConfig& viewConfig = s_viewSurface) const;

protected:
/// Output Method for std::ostream, to be overloaded by child classes
Expand Down
6 changes: 0 additions & 6 deletions Core/include/Acts/Visualization/GeometryView3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ class DetectorVolume;
class Portal;
} // namespace Experimental

static const ViewConfig s_viewSensitive;
static const ViewConfig s_viewPassive;
static const ViewConfig s_viewVolume;
static const ViewConfig s_viewGrid;
static const ViewConfig s_viewLine;

struct GeometryView3D {
/// Helper method to draw Polyhedron objects
///
Expand Down
6 changes: 6 additions & 0 deletions Core/include/Acts/Visualization/IVisualization3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class IVisualization3D {
/// Remove all contents of this helper
///
virtual void clear() = 0;

virtual ~IVisualization3D() = default;

/// Start a new object context
/// @param name The name of the object
virtual void object(const std::string& name) = 0;
paulgessinger marked this conversation as resolved.
Show resolved Hide resolved
};

/// Overload of the << operator to facilitate writing to streams.
Expand Down
44 changes: 23 additions & 21 deletions Core/include/Acts/Visualization/ObjVisualization3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
#include "Acts/Visualization/IVisualization3D.hpp"
#include "Acts/Visualization/ViewConfig.hpp"

#include <array>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <map>
#include <sstream>
#include <string>
#include <vector>

Expand All @@ -26,14 +22,10 @@ namespace Acts {
/// This helper produces output in the OBJ format. Note that colors are not
/// supported in this implementation.
///
template <typename T = double>
class ObjVisualization3D : public IVisualization3D {
public:
static_assert(std::is_same_v<T, double> || std::is_same_v<T, float>,
"Use either double or float");

/// Stored value type, should be double or float
using ValueType = T;
using ValueType = double;

/// Type of a vertex based on the value type
using VertexType = Eigen::Matrix<ValueType, 3, 1>;
Expand Down Expand Up @@ -77,22 +69,32 @@ class ObjVisualization3D : public IVisualization3D {
/// @copydoc Acts::IVisualization3D::clear()
void clear() final;

/// Start a new object context with a name
/// @param name The name of the object
void object(const std::string& name) final;

private:
struct Object {
std::string name;
std::vector<VertexType> vertices{};
std::vector<FaceType> faces{};
std::vector<LineType> lines{};

/// The object data to be written
/// Map of colors to be written at given index position
std::map<std::size_t, Color> lineColors{};
std::map<std::size_t, Color> vertexColors{};
std::map<std::size_t, Color> faceColors{};
};

Object& object();
const Object& object() const;

/// The output parameters
unsigned int m_outputPrecision = 4;
double m_outputScalor = 1.;
/// The object data to be written
std::vector<VertexType> m_vertices;
std::vector<FaceType> m_faces;
std::vector<LineType> m_lines;
/// Map of colors to be written at given index position
std::map<std::size_t, Color> m_lineColors;
std::map<std::size_t, Color> m_vertexColors;
std::map<std::size_t, Color> m_faceColors;
};

#ifndef DOXYGEN
#include "detail/ObjVisualization3D.ipp"
#endif
std::vector<Object> m_objects;
};

} // namespace Acts
4 changes: 4 additions & 0 deletions Core/include/Acts/Visualization/PlyVisualization3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class PlyVisualization3D : public IVisualization3D {
/// @copydoc Acts::IVisualization3D::clear()
void clear() final;

void object(const std::string& /*name*/) final {
paulgessinger marked this conversation as resolved.
Show resolved Hide resolved
// Unimplemented
}

private:
std::vector<std::pair<VertexType, Color>> m_vertices;
std::vector<FaceType> m_faces;
Expand Down
47 changes: 36 additions & 11 deletions Core/include/Acts/Visualization/ViewConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <array>
#include <filesystem>
#include <string>
#include <string_view>

namespace Acts {

Expand Down Expand Up @@ -49,17 +49,31 @@ struct Color {
constexpr Color(double r, double g, double b)
: Color{std::array<double, 3>{r, g, b}} {}

/// Constructor from hex string. The expected format is `#RRGGBB`
/// @param hex The hex string
constexpr explicit Color(std::string_view hex) {
auto hexToInt = [](std::string_view hexStr) {
int value = 0;
std::stringstream ss;
ss << std::hex << hexStr;
ss >> value;
return value;
private:
constexpr int hexToInt(std::string_view hex) {
constexpr auto hexCharToInt = [](char c) -> int {
if (c >= '0' && c <= '9') {
return c - '0';
} else if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
} else if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
} else {
throw std::invalid_argument("Invalid hex character");
}
};

int value = 0;
for (char c : hex) {
value = (value << 4) + hexCharToInt(c);
}
return value;
};

public:
/// Constructor from hex string. The expected format is `#RRGGBB`
/// @param hex The hex string
constexpr Color(std::string_view hex) {
paulgessinger marked this conversation as resolved.
Show resolved Hide resolved
if (hex[0] == '#' && hex.size() == 7) {
rgb[0] = hexToInt(hex.substr(1, 2)); // Extract R component
rgb[1] = hexToInt(hex.substr(3, 2)); // Extract G component
Expand All @@ -85,7 +99,6 @@ struct Color {
/// @param rhs The second color
/// @return True if the colors are equal
friend bool operator==(const Color& lhs, const Color& rhs) = default;

/// Output stream operator
/// @param os The output stream
/// @param color The color to be printed
Expand All @@ -99,6 +112,10 @@ struct Color {
std::array<int, 3> rgb{};
};

constexpr Color s_defaultSurfaceColor{"#0000aa"};
constexpr Color s_defaultPortalColor{"#308c48"};
constexpr Color s_defaultVolumColor{"#ffaa00"};

/// @brief Struct to concentrate all visualization configurations
/// in order to harmonize visualization interfaces
struct ViewConfig {
Expand All @@ -120,4 +137,12 @@ struct ViewConfig {
std::filesystem::path outputName = std::filesystem::path("");
};

static const ViewConfig s_viewSurface = {.color = {170, 170, 170}};
static const ViewConfig s_viewPortal = {.color = {"#308c48"}};
static const ViewConfig s_viewSensitive = {.color = {0, 180, 240}};
static const ViewConfig s_viewPassive = {.color = {240, 280, 0}};
static const ViewConfig s_viewVolume = {.color = {220, 220, 0}};
static const ViewConfig s_viewGrid = {.color = {220, 0, 0}};
static const ViewConfig s_viewLine = {.color = {0, 0, 220}};

} // namespace Acts
Loading
Loading