diff --git a/Intern/rayx-core/src/Beamline/Beamline.cpp b/Intern/rayx-core/src/Beamline/Beamline.cpp index a3f33e81..6f6aae13 100644 --- a/Intern/rayx-core/src/Beamline/Beamline.cpp +++ b/Intern/rayx-core/src/Beamline/Beamline.cpp @@ -91,6 +91,16 @@ MaterialTables Group::calcMinimalMaterialTables() const { return loadMaterialTables(relevantMaterials); } +std::vector Group::compile() const { + std::vector elements; + traverse([&elements](const BeamlineNode& node) { + if (std::holds_alternative(node)) { + elements.push_back(std::get(node).compile()); + } + }); + return elements; +} + // Retrieve all DesignElements (deep) std::vector Group::getAllElements() const { std::vector elements; @@ -102,6 +112,16 @@ std::vector Group::getAllElements() const { return elements; } +size_t Group::numberOfElements() const { + size_t count = 0; + traverse([&count](const BeamlineNode& node) { + if (std::holds_alternative(node)) { + count++; + } + }); + return count; +} + // Retrieve all DesignSources (deep) std::vector Group::getAllSources() const { std::vector sources; @@ -113,6 +133,16 @@ std::vector Group::getAllSources() const { return sources; } +size_t Group::numberOfSources() const { + size_t count = 0; + traverse([&count](const BeamlineNode& node) { + if (std::holds_alternative(node)) { + count++; + } + }); + return count; +} + // Retrieve all Groups (deep) std::vector Group::getAllGroups() const { std::vector groups; diff --git a/Intern/rayx-core/src/Beamline/Beamline.h b/Intern/rayx-core/src/Beamline/Beamline.h index b5eb9514..40a74d5b 100644 --- a/Intern/rayx-core/src/Beamline/Beamline.h +++ b/Intern/rayx-core/src/Beamline/Beamline.h @@ -16,6 +16,7 @@ class Group; using BeamlineNode = std::variant; enum class NodeType { OpticalElement, LightSource, Group }; +// TODO: think about caching to avoid unnecessary recompilation/traversal class Group { public: NodeType getNodeType() const; @@ -30,10 +31,14 @@ class Group { std::vector getInputRays(int thread_count = 1) const; // Returns the smallest possible MaterialTables which cover all materials of the elements in the group MaterialTables calcMinimalMaterialTables() const; + // Compiles all elements and return vector of OpticalElements + std::vector compile() const; // New methods for retrieving elements, sources, and groups std::vector getAllElements() const; std::vector getAllSources() const; + size_t numberOfElements() const; + size_t numberOfSources() const; std::vector getAllGroups() const; // Getter & Setter diff --git a/Intern/rayx-core/src/Debug/Debug.cpp b/Intern/rayx-core/src/Debug/Debug.cpp index b55317f5..60f25d7c 100644 --- a/Intern/rayx-core/src/Debug/Debug.cpp +++ b/Intern/rayx-core/src/Debug/Debug.cpp @@ -65,7 +65,7 @@ Exit::Exit(const std::string& filename, int line) : filename(filename), line(lin formatDebugMsg(filename, line, std::cerr); } -Exit::~Exit() { +[[noreturn]] Exit::~Exit() { std::cerr << "\n"; formatDebugMsg(filename, line, std::cerr); std::cerr << "Terminating...\033[0m" << std::endl; // color reset diff --git a/Intern/rayx-core/src/Debug/Debug.h b/Intern/rayx-core/src/Debug/Debug.h index bdfd6189..5ac430ff 100644 --- a/Intern/rayx-core/src/Debug/Debug.h +++ b/Intern/rayx-core/src/Debug/Debug.h @@ -91,7 +91,7 @@ struct RAYX_API Exit { Exit(const std::string& filename, int line); - ~Exit(); + [[noreturn]] ~Exit(); template Exit& operator<<(T t) { @@ -115,12 +115,10 @@ struct RAYX_API Verb { }; // An empty implementation used in release when using "debug-only" prints like RAYX_D_LOG. -struct RAYX_API IgnoreLog { - template - IgnoreLog& operator<<(T) { - return *this; - } -}; +struct RAYX_API IgnoreLog{template IgnoreLog & operator<<(T){return *this; +} // namespace RAYX +} +; // the function to be called after RAYX_EXIT happens. // normally exit(1), but in the test suite it's ADD_FAILURE. diff --git a/Intern/rayx-core/src/Tracer/DeviceTracer.h b/Intern/rayx-core/src/Tracer/DeviceTracer.h index 449ee3f1..43782a6a 100644 --- a/Intern/rayx-core/src/Tracer/DeviceTracer.h +++ b/Intern/rayx-core/src/Tracer/DeviceTracer.h @@ -8,8 +8,6 @@ namespace RAYX { -class Beamline; - /// Expresses whether we force sequential tracing, or we use dynamic tracing. /// We prefer this over a boolean, as calling eg. the trace function with an argument of `true` has no obvious meaning. /// On the other hand calling it with `Sequential::Yes` makes the meaning more clear. @@ -31,7 +29,7 @@ class RAYX_API DeviceTracer { public: virtual ~DeviceTracer() = default; - virtual BundleHistory trace(const Beamline&, Sequential sequential, uint64_t max_batch_size, int THREAD_COUNT = 1, uint32_t maxEvents = 1) = 0; + virtual BundleHistory trace(const Group&, Sequential sequential, uint64_t max_batch_size, int THREAD_COUNT = 1, uint32_t maxEvents = 1) = 0; protected: PushConstants m_pushConstants; diff --git a/Intern/rayx-core/src/Tracer/SimpleTracer.h b/Intern/rayx-core/src/Tracer/SimpleTracer.h index 81d96ad5..1130d554 100644 --- a/Intern/rayx-core/src/Tracer/SimpleTracer.h +++ b/Intern/rayx-core/src/Tracer/SimpleTracer.h @@ -48,7 +48,7 @@ class SimpleTracer : public DeviceTracer { public: SimpleTracer(int deviceIndex); - BundleHistory trace(const Beamline&, Sequential sequential, uint64_t maxBatchSize, int getInputRaysThreadCount, uint32_t maxEvents) override; + BundleHistory trace(const Group&, Sequential sequential, uint64_t maxBatchSize, int getInputRaysThreadCount, uint32_t maxEvents) override; private: struct TraceResult { @@ -123,27 +123,21 @@ template SimpleTracer::SimpleTracer(int deviceIndex) : m_deviceIndex(deviceIndex) {} template -BundleHistory SimpleTracer::trace(const Beamline& b, Sequential seq, uint64_t maxBatchSize, int getInputRaysThreadCount, uint32_t maxEvents) { +BundleHistory SimpleTracer::trace(const Group& group, Sequential seq, uint64_t maxBatchSize, int getInputRaysThreadCount, uint32_t maxEvents) { RAYX_PROFILE_FUNCTION_STDOUT(); RAYX_VERB << "maxEvents: " << maxEvents; // don't trace if there are no optical elements - if (b.m_DesignElements.size() == 0) { + if (group.numberOfElements() == 0) { // an empty history suffices, nothing is happening to the rays! BundleHistory result; return result; } // prepare input data - auto extractElements = [&b] { - std::vector elements; - elements.reserve(b.m_DesignElements.size()); - for (const auto& e : b.m_DesignElements) elements.push_back(e.compile()); - return elements; - }; - const auto elements = extractElements(); - const auto rays = b.getInputRays(getInputRaysThreadCount); - const auto materialTables = b.calcMinimalMaterialTables(); + const auto elements = group.compile(); + const auto rays = group.getInputRays(getInputRaysThreadCount); + const auto materialTables = group.calcMinimalMaterialTables(); const auto randomSeed = randomDouble(); const auto cpu = getDevice(0); diff --git a/Intern/rayx-core/src/Tracer/Tracer.cpp b/Intern/rayx-core/src/Tracer/Tracer.cpp index 36aeaa6d..aed0067d 100644 --- a/Intern/rayx-core/src/Tracer/Tracer.cpp +++ b/Intern/rayx-core/src/Tracer/Tracer.cpp @@ -53,8 +53,8 @@ Tracer::Tracer(const DeviceConfig& deviceConfig) { } } -BundleHistory Tracer::trace(const Beamline& beamline, Sequential sequential, uint64_t max_batch_size, int THREAD_COUNT, uint32_t maxEvents) { - return m_deviceTracer->trace(beamline, sequential, max_batch_size, THREAD_COUNT, maxEvents); +BundleHistory Tracer::trace(const Group& group, Sequential sequential, uint64_t max_batch_size, int THREAD_COUNT, uint32_t maxEvents) { + return m_deviceTracer->trace(group, sequential, max_batch_size, THREAD_COUNT, maxEvents); } /// Get the last event for each ray of the bundle. @@ -75,8 +75,8 @@ BundleHistory convertToBundleHistory(const std::vector& rays) { return out; } -int Tracer::defaultMaxEvents(const Beamline* beamline) { - if (beamline) return beamline->m_DesignElements.size() * 2 + 8; +int Tracer::defaultMaxEvents(const Group* group) { + if (group) return group->numberOfElements() * 2 + 8; return 32; } diff --git a/Intern/rayx-core/src/Tracer/Tracer.h b/Intern/rayx-core/src/Tracer/Tracer.h index 6aadc907..15a8dca0 100644 --- a/Intern/rayx-core/src/Tracer/Tracer.h +++ b/Intern/rayx-core/src/Tracer/Tracer.h @@ -27,9 +27,9 @@ class RAYX_API Tracer { // This will call the trace implementation of a subclass // See `BundleHistory` for information about the return value. // `max_batch_size` corresponds to the maximal number of rays that will be put into `traceRaw` in one batch. - BundleHistory trace(const Beamline&, Sequential sequential, uint64_t max_batch_size, int THREAD_COUNT = 1, uint32_t maxEvents = 1); + BundleHistory trace(const Group&, Sequential sequential, uint64_t max_batch_size, int THREAD_COUNT = 1, uint32_t maxEvents = 1); - static int defaultMaxEvents(const Beamline* beamline = nullptr); + static int defaultMaxEvents(const Group* group = nullptr); private: std::shared_ptr m_deviceTracer;