Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • leggett/acts-core
  • adye/acts-core
  • xju/acts-core
  • corentin/acts-core
  • keli/acts-core
  • gli/acts-core
  • xai/acts-core
  • bschlag/acts-core
  • berkeleylab/acts/acts-core
  • emoyse/acts-core
  • smh/acts-core
  • pagessin/acts-core
  • chamont/acts-core
  • sroe/a-common-tracking-sw
  • calaf/a-common-tracking-sw
  • hgraslan/acts-core
16 results
Show changes
Commits on Source (10)
...@@ -50,5 +50,18 @@ struct PolyhedronRepresentation ...@@ -50,5 +50,18 @@ struct PolyhedronRepresentation
/// to allow for multiple output objects in one obj file. /// to allow for multiple output objects in one obj file.
std::string std::string
objString(size_t vtxOffset = 0) const; objString(size_t vtxOffset = 0) const;
template <typename helper_t>
void
draw(helper_t& helper) const
{
for (const auto& face : faces) {
std::vector<Vector3D> face_vtx;
for (size_t i : face) {
face_vtx.push_back(vertices[i]);
}
helper.face(face_vtx);
}
}
}; };
} }
...@@ -116,6 +116,14 @@ using Vector3D = Eigen::Matrix<double, 3, 1>; ...@@ -116,6 +116,14 @@ using Vector3D = Eigen::Matrix<double, 3, 1>;
using Vector2D = Eigen::Matrix<double, 2, 1>; using Vector2D = Eigen::Matrix<double, 2, 1>;
using RotationMatrix3D = Eigen::Matrix<double, 3, 3>; using RotationMatrix3D = Eigen::Matrix<double, 3, 3>;
using Rotation3F = Eigen::Quaternion<float>;
using Translation3F = Eigen::Translation<float, 3>;
using AngleAxis3F = Eigen::AngleAxisf;
using Transform3F = Eigen::Affine3f;
using Vector3F = Eigen::Matrix<float, 3, 1>;
using Vector2F = Eigen::Matrix<float, 2, 1>;
using RotationMatrix3F = Eigen::Matrix<float, 3, 3>;
/// axis defintion element for code readability /// axis defintion element for code readability
/// - please use these for access to the member variables if needed, e.g. /// - please use these for access to the member variables if needed, e.g.
/// double z = position[Acts::eZ]; /// double z = position[Acts::eZ];
......
...@@ -36,7 +36,9 @@ static const Vector2D s_origin2D(0., 0.); ...@@ -36,7 +36,9 @@ static const Vector2D s_origin2D(0., 0.);
static const Vector3D s_origin(0, 0, 0); //!< origin position static const Vector3D s_origin(0, 0, 0); //!< origin position
static const double helper[9] = {0., 1., 0., 1., 0., 0., 0., 0., -1.}; namespace detail {
static const double _helper[9] = {0., 1., 0., 1., 0., 0., 0., 0., -1.};
}
static const RotationMatrix3D s_idRotationZinverse(helper); static const RotationMatrix3D s_idRotationZinverse(detail::_helper);
} }
\ No newline at end of file
// This file is part of the Acts project.
//
// Copyright (C) 2019 Acts project team
//
// 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/.
#pragma once
#include <algorithm>
#include "Acts/Utilities/Definitions.hpp"
namespace Acts {
/**
* Partially abstract base class which provides an interface to visualization
* helper classes. It provides a number of methods that all the helpers need to
* conform to. It also provides a `color_type` typedef, but not all of the
* helpers actually support that.
*/
class IVisualization
{
public:
/**
* The color typedef. It's an array of three numbers [0, 255] indicating RGB
* color values.
*/
using color_type = std::array<int, 3>;
/**
* Draw a vertex at a given location and a color.
* @param vtx The vertex position
* @param color The color
*/
virtual void
vertex(const Vector3D& vtx, color_type color = {120, 120, 120})
= 0;
/**
* Draw a face that connects a list of vertices.
* @note Depending on the helper implementation, out of plane vertices might
* be handled differently.
* @param vtxs The vertices that make up the face
* @param color The color of the face
*/
virtual void
face(const std::vector<Vector3D>& vtxs, color_type color = {120, 120, 120})
= 0;
/**
* Draw a line from a vertex to another
* @param a The start vertex
* @param b The end vertex
* @param color The color of the line
*/
virtual void
line(const Vector3D& a, const Vector3D& b, color_type color = {120, 120, 120})
= 0;
/**
* Write the content of the helper to an outstream.
* @param os The output stream
*/
virtual void
write(std::ostream& os) const = 0;
/**
* Remove all contents of this helper
*/
virtual void
clear()
= 0;
/**
* Below are helper functions, which share the same interface as the ones
* above, but explicitly accept float values (instead of double), converts
* them and calls the above methods.
*/
/**
* @copydoc Acts::IVisualization::vertex(const Vector3D&, color_type)
*/
void
vertex(const Vector3F& vtx, color_type color = {120, 120, 120})
{
Vector3D vtxd = vtx.template cast<double>();
vertex(vtxd, color);
}
/**
* @copydoc Acts::IVisualization::face(std::vector<Vector3F>&, color_type)
*/
void
face(const std::vector<Vector3F>& vtxs, color_type color = {120, 120, 120})
{
std::vector<Vector3D> vtxsd;
std::transform(vtxs.begin(),
vtxs.end(),
std::back_inserter(vtxsd),
[](auto& v) { return v.template cast<double>(); });
face(vtxsd, color);
}
/**
* @copydoc Acts::IVisualization::line(const Vector3F&, const Vector3F&,
* color_type)
*/
void
line(const Vector3F& a, const Vector3F& b, color_type color = {120, 120, 120})
{
Vector3D ad = a.template cast<double>();
Vector3D bd = b.template cast<double>();
line(ad, bd, color);
}
};
/**
* Overload of the << operator to facilitate writing to streams.
* @param os The output stream
* @param hlp The helper instance
*/
inline std::ostream&
operator<<(std::ostream& os, const IVisualization& hlp)
{
hlp.write(os);
return os;
}
}
// This file is part of the Acts project.
//
// Copyright (C) 2019 Acts project team
//
// 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/.
#pragma once
#include "Acts/Utilities/Definitions.hpp"
#include "Acts/Utilities/IVisualization.hpp"
namespace Acts {
/**
* This helper produces output in the OBJ format. Note that colors are not
* supported in this implementation.
*/
template <typename T = double>
class ObjHelper : public IVisualization
{
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 value_type = T;
/**
* Type of a vertex based on the value type
*/
using vertex_type = ActsVector<value_type, 3>;
/**
* Typedef of what a face is.
*/
using face_type = std::vector<size_t>;
/**
* @copydoc Acts::IVisualization::vertex()
*/
void
vertex(const Vector3D& vtx,
IVisualization::color_type color = {0, 0, 0}) override
{
(void)color; // suppress unused warning
m_vertices.push_back(vtx.template cast<value_type>());
}
/**
* @copydoc Acts::IVisualization::line()
* @note This function ist not implemented for the OBJ format.
*/
void
line(const Vector3D& /*a*/,
const Vector3D& /*b*/,
IVisualization::color_type color = {0, 0, 0}) override
{
(void)color; // suppress unused warning
// not implemented
throw std::runtime_error("Line not implemented for OBJ");
}
/**
* @copydoc Acts::IVisualization::face()
*/
void
face(const std::vector<Vector3D>& vtxs,
IVisualization::color_type color = {0, 0, 0}) override
{
(void)color; // suppress unused warning
face_type idxs;
idxs.reserve(vtxs.size());
for (const auto& vtx : vtxs) {
vertex(vtx);
idxs.push_back(m_vertices.size() - 1);
}
m_faces.push_back(std::move(idxs));
}
/**
* @copydoc Acts::IVisualization::write()
*/
void
write(std::ostream& os) const override
{
for (const vertex_type& vtx : m_vertices) {
os << "v " << vtx.x() << " " << vtx.y() << " " << vtx.z() << "\n";
}
for (const face_type& fc : m_faces) {
os << "f";
for (size_t i = 0; i < fc.size(); i++) {
os << " " << fc[i] + 1;
}
os << "\n";
}
}
/**
* @copydoc Acts::IVisualization::clear()
*/
void
clear() override
{
m_vertices.clear();
m_faces.clear();
}
private:
std::vector<vertex_type> m_vertices;
std::vector<face_type> m_faces;
};
}
// This file is part of the Acts project.
//
// Copyright (C) 2019 Acts project team
//
// 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/.
#pragma once
#include "Acts/Utilities/Definitions.hpp"
#include "Acts/Utilities/IVisualization.hpp"
namespace Acts {
template <typename T = double>
class PlyHelper : public IVisualization
{
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 value_type = T;
/**
* Type of a vertex based on the value type
*/
using vertex_type = ActsVector<value_type, 3>;
/**
* Typedef of what a face is.
*/
using face_type = std::vector<size_t>;
/**
* @copydoc Acts::IVisualization::vertex()
*/
void
vertex(const Vector3D& vtx,
IVisualization::color_type color = {120, 120, 120}) override
{
m_vertices.emplace_back(vtx.template cast<value_type>(), color);
}
/**
* @copydoc Acts::IVisualization::line()
*/
void
face(const std::vector<Vector3D>& vtxs,
IVisualization::color_type color = {120, 120, 120}) override
{
face_type idxs;
idxs.reserve(vtxs.size());
for (const auto& vtx : vtxs) {
vertex(vtx, color);
idxs.push_back(m_vertices.size() - 1);
}
m_faces.push_back(std::move(idxs));
}
/**
* @copydoc Acts::IVisualization::face()
*/
void
line(const Vector3D& a,
const Vector3D& b,
IVisualization::color_type color = {120, 120, 120}) override
{
vertex(a, color);
size_t idx_a = m_vertices.size() - 1;
vertex(b, color);
size_t idx_b = m_vertices.size() - 1;
m_edges.emplace_back(std::make_pair(std::make_pair(idx_a, idx_b), color));
}
/**
* @copydoc Acts::IVisualization::write()
*/
void
write(std::ostream& os) const override
{
os << "ply\n";
os << "format ascii 1.0\n";
os << "element vertex " << m_vertices.size() << "\n";
os << "property float x\n";
os << "property float y\n";
os << "property float z\n";
os << "property uchar red\n";
os << "property uchar green\n";
os << "property uchar blue\n";
os << "element face " << m_faces.size() << "\n";
os << "property list uchar int vertex_index\n";
os << "element edge " << m_edges.size() << "\n";
os << "property int vertex1\n";
os << "property int vertex2\n";
os << "property uchar red\n";
os << "property uchar green\n";
os << "property uchar blue\n";
os << "end_header\n";
for (const std::pair<vertex_type, IVisualization::color_type>& vtx :
m_vertices) {
os << vtx.first.x() << " " << vtx.first.y() << " " << vtx.first.z()
<< " ";
os << vtx.second[0] << " " << vtx.second[1] << " " << vtx.second[2]
<< "\n";
}
for (const face_type& fc : m_faces) {
os << fc.size();
for (size_t i = 0; i < fc.size(); i++) {
os << " " << fc[i];
}
os << "\n";
}
for (const std::pair<std::pair<size_t, size_t>, IVisualization::color_type>&
edge : m_edges) {
std::pair<size_t, size_t> idxs = edge.first;
os << idxs.first << " " << idxs.second << " ";
os << edge.second[0] << " " << edge.second[1] << " " << edge.second[2]
<< "\n";
}
}
/**
* @copydoc Acts::IVisualization::clear()
*/
void
clear() override
{
m_vertices.clear();
m_faces.clear();
m_edges.clear();
}
private:
std::vector<std::pair<vertex_type, IVisualization::color_type>> m_vertices;
std::vector<face_type> m_faces;
std::vector<std::pair<std::pair<size_t, size_t>, IVisualization::color_type>>
m_edges;
};
}
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "Acts/EventData/TrackParameters.hpp" #include "Acts/EventData/TrackParameters.hpp"
#include "Acts/Extrapolator/Navigator.hpp" #include "Acts/Extrapolator/Navigator.hpp"
#include "Acts/Propagator/StraightLineStepper.hpp" #include "Acts/Propagator/StraightLineStepper.hpp"
#include "Acts/Propagator/StepperConcept.hpp"
#include "Acts/Propagator/detail/ConstrainedStep.hpp" #include "Acts/Propagator/detail/ConstrainedStep.hpp"
#include "Acts/Surfaces/CylinderSurface.hpp" #include "Acts/Surfaces/CylinderSurface.hpp"
#include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp" #include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp"
...@@ -47,9 +48,20 @@ namespace Test { ...@@ -47,9 +48,20 @@ namespace Test {
/// This is a simple cache struct to mimic a Stepper /// This is a simple cache struct to mimic a Stepper
struct Stepper struct Stepper
{ {
// comply with concept
using Jacobian = ActsMatrixD<5, 5>;
using Covariance = ActsSymMatrixD<5>;
using BoundState = std::tuple<BoundParameters, Jacobian, double>;
using CurvilinearState
= std::tuple<CurvilinearParameters, Jacobian, double>;
using Corrector = VoidIntersectionCorrector;
template <typename, typename>
using return_parameter_type = void;
/// This is a simple cache struct to mimic the /// This is a simple cache struct to mimic the
/// Stepper cache in the propagation /// Stepper cache in the propagation
struct StepperState struct State
{ {
/// Position /// Position
Vector3D pos = Vector3D(0., 0., 0.); Vector3D pos = Vector3D(0., 0., 0.);
...@@ -75,47 +87,112 @@ namespace Test { ...@@ -75,47 +87,112 @@ namespace Test {
/// Global particle position accessor /// Global particle position accessor
Vector3D Vector3D
position(const StepperState& state) const position(const State& state) const
{ {
return state.pos; return state.pos;
} }
/// Momentum direction accessor /// Momentum direction accessor
Vector3D Vector3D
direction(const StepperState& state) const direction(const State& state) const
{ {
return state.dir; return state.dir;
} }
/// Momentum accessor /// Momentum accessor
Vector3D double
momentum(const StepperState& state) const momentum(const State& state) const
{ {
return state.p * state.dir; return state.p;
} }
/// Charge access /// Charge access
double double
charge(const StepperState& state) const charge(const State& state) const
{ {
return state.q; return state.q;
} }
/// Return a corrector /// Return a corrector
static VoidIntersectionCorrector VoidIntersectionCorrector
corrector(StepperState& /*unused*/) corrector(State& /*unused*/) const
{ {
return VoidIntersectionCorrector(); return VoidIntersectionCorrector();
} }
bool bool
surfaceReached(const StepperState& state, const Surface* surface) const surfaceReached(const State& state, const Surface* surface) const
{ {
return surface->isOnSurface( return surface->isOnSurface(
tgContext, position(state), direction(state), true); tgContext, position(state), direction(state), true);
} }
BoundState
boundState(State& state,
const Surface& surface,
bool reinitialize = true) const
{
// suppress unused warning
(void)reinitialize;
BoundParameters parameters(tgContext,
nullptr,
state.pos,
state.p * state.dir,
state.q,
surface.getSharedPtr());
BoundState bState{
std::move(parameters), Jacobian::Identity(), state.pathAccumulated};
return bState;
}
CurvilinearState
curvilinearState(State& state, bool reinitialize = true) const
{
(void)reinitialize;
CurvilinearParameters parameters(
nullptr, state.pos, state.p * state.dir, state.q);
// Create the bound state
CurvilinearState curvState{
std::move(parameters), Jacobian::Identity(), state.pathAccumulated};
return curvState;
}
void
update(State& /*state*/, const BoundParameters& /*pars*/) const
{
}
void
update(State& /*state*/,
const Vector3D& /*uposition*/,
const Vector3D& /*udirection*/,
double /*up*/) const
{
}
void
covarianceTransport(State& /*state*/, bool /*reinitialize = false*/) const
{
}
void
covarianceTransport(State& /*unused*/,
const Surface& /*surface*/,
bool /*reinitialize = false*/) const
{
}
Vector3D
getField(State& /*state*/, const Vector3D& /*pos*/) const
{
// get the field from the cell
return Vector3D(0., 0., 0.);
}
}; };
static_assert(StepperConcept<Stepper>,
"Dummy stepper does not fulfill concept");
/// emulate the options template /// emulate the options template
struct Options struct Options
{ {
...@@ -142,7 +219,7 @@ namespace Test { ...@@ -142,7 +219,7 @@ namespace Test {
Options options; Options options;
/// The Stepper state - internal statew of the Stepper /// The Stepper state - internal statew of the Stepper
Stepper::StepperState stepping; Stepper::State stepping;
/// Navigation state - internal state of the Navigator /// Navigation state - internal state of the Navigator
Navigator::State navigation; Navigator::State navigation;
......
...@@ -71,3 +71,7 @@ add_test (NAME ResultTests COMMAND ResultTests) ...@@ -71,3 +71,7 @@ add_test (NAME ResultTests COMMAND ResultTests)
add_executable (TypeTraitsTest TypeTraitsTest.cpp) add_executable (TypeTraitsTest TypeTraitsTest.cpp)
target_link_libraries (TypeTraitsTest PRIVATE ActsCore ActsTestsCommonHelpers ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) target_link_libraries (TypeTraitsTest PRIVATE ActsCore ActsTestsCommonHelpers ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_test (NAME TypeTraitsTest COMMAND TypeTraitsTest) add_test (NAME TypeTraitsTest COMMAND TypeTraitsTest)
add_executable (VisualizationTests VisualizationTests.cpp)
target_link_libraries (VisualizationTests PRIVATE ActsCore ActsTestsCommonHelpers ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_test (NAME VisualizationTests COMMAND VisualizationTests)
// This file is part of the Acts project.
//
// Copyright (C) 2019 Acts project team
//
// 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/.
#define BOOST_TEST_MODULE VisualizationTest Test
#define BOOST_TEST_DYN_LINK
#include <boost/test/output_test_stream.hpp>
#include <boost/test/unit_test.hpp>
#include "Acts/Utilities/IVisualization.hpp"
#include "Acts/Utilities/ObjHelper.hpp"
#include "Acts/Utilities/PlyHelper.hpp"
#include <iostream>
using boost::test_tools::output_test_stream;
namespace Acts {
namespace Test {
BOOST_AUTO_TEST_SUITE(Utilities)
BOOST_AUTO_TEST_CASE(construction_test)
{
// this doesn't really test anything, other than conformance to the
// IVisualization interface
PlyHelper ply;
ObjHelper obj;
IVisualization* vis;
vis = &ply;
std::cout << *vis << std::endl;
vis = &obj;
std::cout << *vis << std::endl;
}
BOOST_AUTO_TEST_CASE(ply_output_test)
{
PlyHelper ply;
output_test_stream output;
ply.vertex({0, 0, 0});
std::string exp = R"(ply
format ascii 1.0
element vertex 1
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 0
property list uchar int vertex_index
element edge 0
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header
0 0 0 120 120 120
)";
output << ply;
BOOST_CHECK(output.is_equal(exp));
ply.clear();
ply.vertex({0, 1, 0});
exp = R"(ply
format ascii 1.0
element vertex 1
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 0
property list uchar int vertex_index
element edge 0
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header
0 1 0 120 120 120
)";
output << ply;
BOOST_CHECK(output.is_equal(exp));
ply.clear();
ply.line({0, 0, 1}, {1, 0, 0});
output << ply;
exp = R"(ply
format ascii 1.0
element vertex 2
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 0
property list uchar int vertex_index
element edge 1
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header
0 0 1 120 120 120
1 0 0 120 120 120
0 1 120 120 120
)";
BOOST_CHECK(output.is_equal(exp));
ply.clear();
ply.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
output << ply;
exp = R"(ply
format ascii 1.0
element vertex 3
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 1
property list uchar int vertex_index
element edge 0
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header
1 0 0 120 120 120
1 1 0 120 120 120
0 1 0 120 120 120
3 0 1 2
)";
BOOST_CHECK(output.is_equal(exp));
}
BOOST_AUTO_TEST_CASE(obj_output_test)
{
ObjHelper obj;
output_test_stream output;
obj.vertex({1, 0, 0});
output << obj;
std::string exp = R"(v 1 0 0
)";
BOOST_CHECK(output.is_equal(exp));
obj.clear();
BOOST_CHECK_THROW(obj.line({1, 0, 0}, {0, 1, 0}), std::runtime_error);
obj.clear();
obj.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}});
output << obj;
exp = R"(v 1 0 0
v 1 1 0
v 0 1 0
f 1 2 3
)";
BOOST_CHECK(output.is_equal(exp));
}
BOOST_AUTO_TEST_SUITE_END()
}
}