Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(
ViennaRay
LANGUAGES CXX
VERSION 4.2.0)
VERSION 4.3.0)

# --------------------------------------------------------------------------------------------------------
# Library switches
Expand Down Expand Up @@ -51,13 +51,13 @@ endif()

add_library(${PROJECT_NAME} INTERFACE)

target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20)
target_compile_definitions(${PROJECT_NAME}
INTERFACE VIENNARAY_EMBREE_VERSION=${VIENNARAY_EMBREE_VERSION})

set_target_properties(
${PROJECT_NAME}
PROPERTIES CXX_STANDARD 17
PROPERTIES CXX_STANDARD 20
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
WINDOWS_EXPORT_ALL_SYMBOLS ON)
Expand Down Expand Up @@ -98,7 +98,7 @@ include("cmake/cpm.cmake")

CPMAddPackage(
NAME ViennaCore
VERSION 2.1.2
VERSION 2.2.1
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore"
OPTIONS "VIENNACORE_USE_GPU ${VIENNARAY_USE_GPU}")

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ We recommend using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to consum
* Installation with CPM

```cmake
CPMAddPackage("gh:viennatools/viennaray@4.2.0") # Use the latest release version
CPMAddPackage("gh:viennatools/viennaray@4.3.0") # Use the latest release version
```

* With a local installation
Expand Down
2 changes: 1 addition & 1 deletion examples/disk2D/disk2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main() {
std::cout << "Tracing time: " << timer.currentDuration / 1e9 << " s\n";

// Extract the normalized hit counts for each geometry point
auto &flux = rayTracer.getLocalData().getVectorData("flux");
auto flux = *rayTracer.getLocalData().getScalarData("flux");
rayTracer.normalizeFlux(flux, NormalizationType::SOURCE);
rayTracer.smoothFlux(flux, 1);

Expand Down
2 changes: 1 addition & 1 deletion examples/disk3D/disk3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main() {
std::cout << "Tracing time: " << timer.currentDuration / 1e9 << " s\n";

// Extract the normalized hit counts for each geometry point
auto &flux = rayTracer.getLocalData().getVectorData("flux");
auto &flux = *rayTracer.getLocalData().getScalarData("flux");
rayTracer.normalizeFlux(flux, NormalizationType::SOURCE);
rayTracer.smoothFlux(flux);

Expand Down
7 changes: 3 additions & 4 deletions examples/triangle2D/triangle2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ int main() {

std::cout << "Tracing time: " << timer.currentDuration / 1e9 << " s\n";

auto &localData = tracer.getLocalData();
tracer.normalizeFlux(localData.getVectorData(0), NormalizationType::SOURCE);
auto flux = *tracer.getLocalData().getScalarData("flux");
tracer.normalizeFlux(flux, NormalizationType::SOURCE);

auto triMesh = convertLinesToTriangles(lineMesh);
rayInternal::writeVTP<NumericType, 3>("lineGeometryOutput.vtp", triMesh.nodes,
triMesh.triangles,
localData.getVectorData(0));
triMesh.triangles, flux);
}
6 changes: 3 additions & 3 deletions examples/triangle3D/triangle3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ int main() {

std::cout << "Tracing time: " << timer.currentDuration / 1e9 << " s\n";

auto &localData = tracer.getLocalData();
tracer.normalizeFlux(localData.getVectorData(0), NormalizationType::SOURCE);
auto flux = *tracer.getLocalData().getScalarData("flux");
tracer.normalizeFlux(flux, NormalizationType::SOURCE);

rayInternal::writeVTP<NumericType, D>("triangleGeometryOutput.vtp", points,
triangles, localData.getVectorData(0));
triangles, flux);
}
3 changes: 2 additions & 1 deletion gpu/tests/boundaries/TestPipelineTriangle.cu
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ extern "C" __global__ void __raygen__() {
// the values we store the PRD pointer in:
uint32_t u0, u1;
packPointer((void *)&prd, u0, u1);
const float initialRayWeight = prd.rayWeight;

while (continueRay(launchParams, prd)) {
while (continueRay(launchParams, prd, initialRayWeight)) {
printf("Tracing ray %u from pos (%f, %f, %f) in dir (%f, %f, %f)\n",
linearLaunchIndex, prd.pos[0], prd.pos[1], prd.pos[2], prd.dir[0],
prd.dir[1], prd.dir[2]);
Expand Down
34 changes: 18 additions & 16 deletions include/viennaray/rayParticle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include <rayTracingData.hpp>
#include <rayUtil.hpp>

#include <utility>
#include <vcPointData.hpp>
#include <vcRNG.hpp>

#include <memory>
#include <utility>

#define VIENNARAY_PARTICLE_STOP \
std::pair<NumericType, Vec3D<NumericType>> { \
Expand Down Expand Up @@ -44,7 +45,7 @@ template <typename NumericType> class AbstractParticle {
surfaceReflection(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primId, const int materialId,
const TracingData<NumericType> *globalData,
const PointData<NumericType> *globalData,
RNG &rngState) = 0;

/// Surface collision. This function gets called whenever an intersection of
Expand All @@ -55,14 +56,15 @@ template <typename NumericType> class AbstractParticle {
/// primId: ID fo the hit disc;
/// materialId: ID of material at hit disc;
/// localData: user-defined data;
/// globalData: constant user-defined data;
/// globalData: constant user-defined data; (can be nullptr if no global data
/// is provided)
/// Rng: thread-safe random number generator (standard library conform);
virtual void surfaceCollision(NumericType rayWeight,
const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primID, const int materialId,
TracingData<NumericType> &localData,
const TracingData<NumericType> *globalData,
PointData<NumericType> &localData,
const PointData<NumericType> *globalData,
RNG &rngState) = 0;

/// Set the power of the cosine source distribution for this particle.
Expand Down Expand Up @@ -96,7 +98,7 @@ class Particle : public AbstractParticle<NumericType> {
surfaceReflection(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primId, const int materialId,
const TracingData<NumericType> *globalData,
const PointData<NumericType> *globalData,
RNG &rngState) override {
// return the sticking probability and direction after reflection for this
// hit
Expand All @@ -105,8 +107,8 @@ class Particle : public AbstractParticle<NumericType> {
void surfaceCollision(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primID, const int materialId,
TracingData<NumericType> &localData,
const TracingData<NumericType> *globalData,
PointData<NumericType> &localData,
const PointData<NumericType> *globalData,
RNG &rngState) override { // collect data for this hit
}
NumericType getSourceDistributionPower() const override { return 1.; }
Expand Down Expand Up @@ -138,7 +140,7 @@ class DiffuseParticle
surfaceReflection(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primID, const int materialId,
const TracingData<NumericType> *globalData,
const PointData<NumericType> *globalData,
RNG &rngState) final {
auto direction = ReflectionDiffuse<NumericType, D>(geomNormal, rngState);
return std::pair<NumericType, Vec3D<NumericType>>{stickingProbability_,
Expand All @@ -148,11 +150,11 @@ class DiffuseParticle
void surfaceCollision(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primID, const int materialId,
TracingData<NumericType> &localData,
const TracingData<NumericType> *globalData,
PointData<NumericType> &localData,
const PointData<NumericType> *globalData,
RNG &rngState) final {
// collect data for this hit
localData.getVectorData(0)[primID] += rayWeight;
localData.addToScalarData(0, primID, rayWeight);
}

NumericType getSourceDistributionPower() const final { return 1.; }
Expand All @@ -179,7 +181,7 @@ class SpecularParticle
surfaceReflection(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primID, const int materialId,
const TracingData<NumericType> *globalData,
const PointData<NumericType> *globalData,
RNG &rngState) final {
auto direction = ReflectionSpecular<NumericType, D>(rayDir, geomNormal);
return std::pair<NumericType, Vec3D<NumericType>>{stickingProbability_,
Expand All @@ -189,11 +191,11 @@ class SpecularParticle
void surfaceCollision(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primID, const int materialId,
TracingData<NumericType> &localData,
const TracingData<NumericType> *globalData,
PointData<NumericType> &localData,
const PointData<NumericType> *globalData,
RNG &rngState) final {
// collect data for this hit
localData.getVectorData(0)[primID] += rayWeight;
localData.addToScalarData(0, primID, rayWeight);
}

NumericType getSourceDistributionPower() const final { return sourcePower_; }
Expand Down
14 changes: 7 additions & 7 deletions include/viennaray/rayTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ template <class NumericType, int D> class Trace {
virtual void smoothFlux(std::vector<NumericType> &flux,
int numNeighbors = 1) = 0;

[[nodiscard]] TracingData<NumericType> &getLocalData() { return localData_; }
[[nodiscard]] PointData<NumericType> &getLocalData() { return localData_; }

[[nodiscard]] TracingData<NumericType> *getGlobalData() {
return pGlobalData_;
}
[[nodiscard]] auto getGlobalData() { return pGlobalData_; }

void setGlobalData(TracingData<NumericType> &data) { pGlobalData_ = &data; }
void setGlobalData(SmartPointer<PointData<NumericType>> data) {
pGlobalData_ = data;
}

[[nodiscard]] TraceInfo getRayTraceInfo() const { return RTInfo_; }

Expand Down Expand Up @@ -173,8 +173,8 @@ template <class NumericType, int D> class Trace {

rayInternal::KernelConfig config_;

TracingData<NumericType> localData_;
TracingData<NumericType> *pGlobalData_ = nullptr;
PointData<NumericType> localData_;
SmartPointer<PointData<NumericType>> pGlobalData_ = nullptr;
TraceInfo RTInfo_;
DataLog<NumericType> dataLog_;
};
Expand Down
7 changes: 3 additions & 4 deletions include/viennaray/rayTraceDisk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ class TraceDisk final : public Trace<NumericType, D> {

auto localDataLabels = this->pParticle_->getLocalDataLabels();
if (!localDataLabels.empty()) {
this->localData_.setNumberOfVectorData(localDataLabels.size());
auto numPoints = geometry_.getNumPrimitives();
for (int i = 0; i < localDataLabels.size(); ++i) {
this->localData_.setVectorData(i, numPoints, 0., localDataLabels[i]);
for (const auto &label : localDataLabels) {
this->localData_.insertReplaceScalarData(numPoints, 0., label);
}
}

rayInternal::TraceKernel<NumericType, D, GeometryType::DISK> tracer(
this->device_, geometry_, boundary, this->pSource_, this->pParticle_,
this->config_, this->dataLog_, this->RTInfo_);
tracer.setTracingData(&this->localData_, this->pGlobalData_);
tracer.setTracingData(&this->localData_, this->pGlobalData_.get());
tracer.apply();
++this->config_.runNumber;

Expand Down
73 changes: 9 additions & 64 deletions include/viennaray/rayTraceKernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template <typename NumericType, int D, GeometryType geoType> class TraceKernel {
#endif

// thread local data storage
std::vector<TracingData<NumericType>> threadLocalData(numThreads);
std::vector<PointData<NumericType>> threadLocalData(numThreads);
for (auto &data : threadLocalData) {
data = *pLocalData_;
}
Expand Down Expand Up @@ -344,66 +344,11 @@ template <typename NumericType, int D, GeometryType geoType> class TraceKernel {
for (int i = 0; i < numThreads; ++i) {
dataLog_.merge(threadLocalDataLog[i]);
}
// merge local data
if (!pLocalData_->getVectorData().empty()) {
// merge vector data
#pragma omp parallel for
for (int i = 0; i < pLocalData_->getVectorData().size(); ++i) {
switch (pLocalData_->getVectorMergeType(i)) {
case TracingDataMergeEnum::SUM: {
for (size_t j = 0; j < pLocalData_->getVectorData(i).size(); ++j) {
for (int k = 0; k < numThreads; ++k) {
pLocalData_->getVectorData(i)[j] +=
threadLocalData[k].getVectorData(i)[j];
}
}
break;
}

case TracingDataMergeEnum::APPEND: {
pLocalData_->getVectorData(i).clear();
for (int k = 0; k < numThreads; ++k) {
pLocalData_->appendVectorData(i,
threadLocalData[k].getVectorData(i));
}
break;
}

default: {
VIENNACORE_LOG_WARNING("Invalid merge type in local vector data.");
break;
}
}
}
}

if (!pLocalData_->getScalarData().empty()) {
// merge scalar data
for (int i = 0; i < pLocalData_->getScalarData().size(); ++i) {
switch (pLocalData_->getScalarMergeType(i)) {
case TracingDataMergeEnum::SUM: {
for (int j = 0; j < numThreads; ++j) {
pLocalData_->getScalarData(i) +=
threadLocalData[j].getScalarData(i);
}
break;
}

case TracingDataMergeEnum::AVERAGE: {
for (int j = 0; j < numThreads; ++j) {
pLocalData_->getScalarData(i) +=
threadLocalData[j].getScalarData(i);
}
pLocalData_->getScalarData(i) /= static_cast<NumericType>(numThreads);
break;
}

default: {
VIENNACORE_LOG_WARNING("Invalid merge type in local scalar data.");
break;
}
}
}
// merge local data
for (int i = 0; i < numThreads; ++i) {
pLocalData_->mergeScalarData(threadLocalData[i],
std::plus<NumericType>());
}

traceInfo_.numRays = numRays;
Expand All @@ -425,8 +370,8 @@ template <typename NumericType, int D, GeometryType geoType> class TraceKernel {
rtcReleaseScene(rtcScene);
}

void setTracingData(TracingData<NumericType> *pLocalData,
const TracingData<NumericType> *pGlobalData) {
void setTracingData(PointData<NumericType> *pLocalData,
const PointData<NumericType> *pGlobalData) {
pLocalData_ = pLocalData;
pGlobalData_ = pGlobalData;
}
Expand Down Expand Up @@ -520,8 +465,8 @@ template <typename NumericType, int D, GeometryType geoType> class TraceKernel {

const KernelConfig config_;

TracingData<NumericType> *pLocalData_ = nullptr;
TracingData<NumericType> const *pGlobalData_ = nullptr;
PointData<NumericType> *pLocalData_ = nullptr;
PointData<NumericType> const *pGlobalData_ = nullptr;
TraceInfo &traceInfo_;
DataLog<NumericType> &dataLog_;
};
Expand Down
7 changes: 3 additions & 4 deletions include/viennaray/rayTraceTriangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ class TraceTriangle final : public Trace<NumericType, D> {

auto localDataLabels = this->pParticle_->getLocalDataLabels();
if (!localDataLabels.empty()) {
this->localData_.setNumberOfVectorData(localDataLabels.size());
auto numPoints = geometry_.getNumPrimitives();
for (int i = 0; i < localDataLabels.size(); ++i) {
this->localData_.setVectorData(i, numPoints, 0., localDataLabels[i]);
for (const auto &label : localDataLabels) {
this->localData_.insertReplaceScalarData(numPoints, 0., label);
}
}

rayInternal::TraceKernel<NumericType, D, GeometryType::TRIANGLE> tracer(
this->device_, geometry_, boundary, this->pSource_, this->pParticle_,
this->config_, this->dataLog_, this->RTInfo_);
tracer.setTracingData(&this->localData_, this->pGlobalData_);
tracer.setTracingData(&this->localData_, this->pGlobalData_.get());
tracer.apply();
++this->config_.runNumber;

Expand Down
Loading
Loading