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

move common helide array impl to helium #163

Merged
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

## Establish project

project(anari VERSION 0.7.3 LANGUAGES C CXX)
project(anari VERSION 0.8.0 LANGUAGES C CXX)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
Expand Down
64 changes: 36 additions & 28 deletions libs/anari/include/anari/anari_cpp/ext/linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
// Stan Melax <http://github.com/melax/>
// Dimitri Diakopoulos <http://github.com/ddiakopoulos/>
//
// Some features are deprecated. Define LINALG_FORWARD_COMPATIBLE to remove them.


// Some features are deprecated. Define LINALG_FORWARD_COMPATIBLE to remove
// them.

// This is free and unencumbered software released into the public domain.
//
Expand All @@ -43,7 +42,7 @@
//
// For more information, please refer to <http://unlicense.org/>


// clang-format off

#pragma once
#ifndef LINALG_H
Expand Down Expand Up @@ -721,37 +720,46 @@ template<class T> linalg::mat<T,4,4> linalg::frustum_matrix(T x0, T x1, T y0, T
return {{2*n/(x1-x0),0,0,0}, {0,2*n/(y1-y0),0,0}, {-s*(x0+x1)/(x1-x0),-s*(y0+y1)/(y1-y0),s*(f+o)/(f-n),s}, {0,0,-(n+o)*f/(f-n),0}};
}

namespace anari {
// clang-format on

namespace anari::math {

using namespace linalg::aliases;
using namespace linalg;
using mat3 = float3x3;
using mat4 = float4x4;

ANARI_TYPEFOR_SPECIALIZATION(float2, ANARI_FLOAT32_VEC2);
ANARI_TYPEFOR_SPECIALIZATION(float3, ANARI_FLOAT32_VEC3);
ANARI_TYPEFOR_SPECIALIZATION(float4, ANARI_FLOAT32_VEC4);
ANARI_TYPEFOR_SPECIALIZATION(byte2, ANARI_UINT8_VEC2);
ANARI_TYPEFOR_SPECIALIZATION(byte3, ANARI_UINT8_VEC3);
ANARI_TYPEFOR_SPECIALIZATION(byte4, ANARI_UINT8_VEC4);
ANARI_TYPEFOR_SPECIALIZATION(int2, ANARI_INT32_VEC2);
ANARI_TYPEFOR_SPECIALIZATION(int3, ANARI_INT32_VEC3);
ANARI_TYPEFOR_SPECIALIZATION(int4, ANARI_INT32_VEC4);
ANARI_TYPEFOR_SPECIALIZATION(uint2, ANARI_UINT32_VEC2);
ANARI_TYPEFOR_SPECIALIZATION(uint3, ANARI_UINT32_VEC3);
ANARI_TYPEFOR_SPECIALIZATION(uint4, ANARI_UINT32_VEC4);
ANARI_TYPEFOR_SPECIALIZATION(mat4, ANARI_FLOAT32_MAT4);
} // namespace anari::math

namespace anari {

ANARI_TYPEFOR_SPECIALIZATION(math::float2, ANARI_FLOAT32_VEC2);
ANARI_TYPEFOR_SPECIALIZATION(math::float3, ANARI_FLOAT32_VEC3);
ANARI_TYPEFOR_SPECIALIZATION(math::float4, ANARI_FLOAT32_VEC4);
ANARI_TYPEFOR_SPECIALIZATION(math::byte2, ANARI_UINT8_VEC2);
ANARI_TYPEFOR_SPECIALIZATION(math::byte3, ANARI_UINT8_VEC3);
ANARI_TYPEFOR_SPECIALIZATION(math::byte4, ANARI_UINT8_VEC4);
ANARI_TYPEFOR_SPECIALIZATION(math::int2, ANARI_INT32_VEC2);
ANARI_TYPEFOR_SPECIALIZATION(math::int3, ANARI_INT32_VEC3);
ANARI_TYPEFOR_SPECIALIZATION(math::int4, ANARI_INT32_VEC4);
ANARI_TYPEFOR_SPECIALIZATION(math::uint2, ANARI_UINT32_VEC2);
ANARI_TYPEFOR_SPECIALIZATION(math::uint3, ANARI_UINT32_VEC3);
ANARI_TYPEFOR_SPECIALIZATION(math::uint4, ANARI_UINT32_VEC4);
ANARI_TYPEFOR_SPECIALIZATION(math::mat3, ANARI_FLOAT32_MAT3);
ANARI_TYPEFOR_SPECIALIZATION(math::mat4, ANARI_FLOAT32_MAT4);

#ifdef ANARI_LINALG_DEFINITIONS
ANARI_TYPEFOR_DEFINITION(float2);
ANARI_TYPEFOR_DEFINITION(float3);
ANARI_TYPEFOR_DEFINITION(float4);
ANARI_TYPEFOR_DEFINITION(int2);
ANARI_TYPEFOR_DEFINITION(int3);
ANARI_TYPEFOR_DEFINITION(int4);
ANARI_TYPEFOR_DEFINITION(uint2);
ANARI_TYPEFOR_DEFINITION(uint3);
ANARI_TYPEFOR_DEFINITION(uint4);
ANARI_TYPEFOR_DEFINITION(mat4);
ANARI_TYPEFOR_DEFINITION(math::float2);
ANARI_TYPEFOR_DEFINITION(math::float3);
ANARI_TYPEFOR_DEFINITION(math::float4);
ANARI_TYPEFOR_DEFINITION(math::int2);
ANARI_TYPEFOR_DEFINITION(math::int3);
ANARI_TYPEFOR_DEFINITION(math::int4);
ANARI_TYPEFOR_DEFINITION(math::uint2);
ANARI_TYPEFOR_DEFINITION(math::uint3);
ANARI_TYPEFOR_DEFINITION(math::uint4);
ANARI_TYPEFOR_DEFINITION(math::mat3);
ANARI_TYPEFOR_DEFINITION(math::mat4);
#endif

inline float radians(float degrees)
Expand Down
12 changes: 6 additions & 6 deletions libs/anari_test_scenes/anari_test_scenes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ namespace anari {
namespace scenes {

using Any = helium::AnariAny;
using mat4 = anari::mat4;
using mat4 = math::mat4;

struct Camera
{
anari::float3 position;
anari::float3 direction;
anari::float3 at;
anari::float3 up;
math::float3 position;
math::float3 direction;
math::float3 at;
math::float3 up;
};

struct ParameterInfo
Expand Down Expand Up @@ -58,7 +58,7 @@ ParameterInfo makeParameterInfo(const char *name,
const char *value,
std::vector<std::string> stringValues);

using Bounds = std::array<anari::float3, 2>;
using Bounds = std::array<math::float3, 2>;

struct TestScene;
using SceneHandle = TestScene *;
Expand Down
16 changes: 8 additions & 8 deletions libs/anari_test_scenes/scenes/demo/cornell_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace anari {
namespace scenes {

// quad mesh data
static std::vector<anari::float3> vertices = {
static std::vector<math::float3> vertices = {
// Floor
{1.00f, -1.00f, -1.00f},
{-1.00f, -1.00f, -1.00f},
Expand Down Expand Up @@ -94,7 +94,7 @@ static std::vector<anari::float3> vertices = {
{0.14f, -1.00f, 0.67f},
{0.71f, -1.00f, 0.49f}};

static std::vector<anari::uint3> indices = {
static std::vector<math::uint3> indices = {
{0, 1, 2}, // Floor
{0, 2, 3}, // Floor
{4, 5, 6}, // Ceiling
Expand Down Expand Up @@ -131,7 +131,7 @@ static std::vector<anari::uint3> indices = {
{64, 66, 67}, // TallBox Bottom Face
};

static std::vector<anari::float4> colors = {
static std::vector<math::float4> colors = {
// Floor
{0.725f, 0.710f, 0.68f, 1.0f},
{0.725f, 0.710f, 0.68f, 1.0f},
Expand Down Expand Up @@ -275,14 +275,14 @@ void CornellBox::commit()
// fix this up with new check
if (false/*anari::deviceImplements(d, "ANARI_KHR_AREA_LIGHTS")*/) {
light = anari::newObject<anari::Light>(d, "quad");
anari::setParameter(d, light, "color", anari::float3(0.78f, 0.551f, 0.183f));
anari::setParameter(d, light, "color", math::float3(0.78f, 0.551f, 0.183f));
anari::setParameter(d, light, "intensity", 47.f);
anari::setParameter(d, light, "position", anari::float3(-0.23f, 0.98f, -0.16f));
anari::setParameter(d, light, "edge1", anari::float3(0.47f, 0.0f, 0.0f));
anari::setParameter(d, light, "edge2", anari::float3(0.0f, 0.0f, 0.38f));
anari::setParameter(d, light, "position", math::float3(-0.23f, 0.98f, -0.16f));
anari::setParameter(d, light, "edge1", math::float3(0.47f, 0.0f, 0.0f));
anari::setParameter(d, light, "edge2", math::float3(0.0f, 0.0f, 0.38f));
} else {
light = anari::newObject<anari::Light>(d, "directional");
anari::setParameter(d, light, "direction", anari::float3(0.f, -0.5f, 1.f));
anari::setParameter(d, light, "direction", math::float3(0.f, -0.5f, 1.f));
}

anari::commitParameters(d, light);
Expand Down
20 changes: 10 additions & 10 deletions libs/anari_test_scenes/scenes/demo/gravity_spheres_volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace scenes {

struct Point
{
anari::float3 center;
math::float3 center;
float weight;
};

Expand All @@ -37,12 +37,12 @@ static std::vector<Point> generatePoints(size_t numPoints)
}

static std::vector<float> generateVoxels(
const std::vector<Point> &points, anari::int3 dims)
const std::vector<Point> &points, math::int3 dims)
{
// get world coordinate in [-1.f, 1.f] from logical coordinates in [0,
// volumeDimension)
auto logicalToWorldCoordinates = [&](int i, int j, int k) {
return anari::float3(-1.f + float(i) / float(dims.x - 1) * 2.f,
return math::float3(-1.f + float(i) / float(dims.x - 1) * 2.f,
-1.f + float(j) / float(dims.y - 1) * 2.f,
-1.f + float(k) / float(dims.z - 1) * 2.f);
};
Expand All @@ -61,8 +61,8 @@ static std::vector<float> generateVoxels(
float value = 0.f;

for (auto &p : points) {
anari::float3 pointCoordinate = logicalToWorldCoordinates(i, j, k);
const float distance = anari::length(pointCoordinate - p.center);
math::float3 pointCoordinate = logicalToWorldCoordinates(i, j, k);
const float distance = math::length(pointCoordinate - p.center);

// contribution proportional to weighted inverse-square distance
// (i.e. gravity)
Expand Down Expand Up @@ -111,11 +111,11 @@ void GravityVolume::commit()
const float voxelRange[2] = {0.f, 10.f};

auto points = generatePoints(numPoints);
auto voxels = generateVoxels(points, anari::int3(volumeDims));
auto voxels = generateVoxels(points, math::int3(volumeDims));

auto field = anari::newObject<anari::SpatialField>(d, "structuredRegular");
anari::setParameter(d, field, "origin", anari::float3(-1.f));
anari::setParameter(d, field, "spacing", anari::float3(2.f / volumeDims));
anari::setParameter(d, field, "origin", math::float3(-1.f));
anari::setParameter(d, field, "spacing", math::float3(2.f / volumeDims));
anari::setParameterArray3D(
d, field, "data", voxels.data(), volumeDims, volumeDims, volumeDims);
anari::commitParameters(d, field);
Expand All @@ -124,7 +124,7 @@ void GravityVolume::commit()
anari::setAndReleaseParameter(d, volume, "field", field);

{
std::vector<anari::float3> colors;
std::vector<math::float3> colors;
std::vector<float> opacities;

colors.emplace_back(0.f, 0.f, 1.f);
Expand All @@ -146,7 +146,7 @@ void GravityVolume::commit()
anari::commitParameters(d, volume);

if (withGeometry) {
std::vector<anari::float3> positions(numPoints);
std::vector<math::float3> positions(numPoints);
std::transform(
points.begin(), points.end(), positions.begin(), [](const Point &p) {
return p.center;
Expand Down
6 changes: 3 additions & 3 deletions libs/anari_test_scenes/scenes/file/obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void loadObj(

auto defaultMaterial = anari::newObject<anari::Material>(d, "matte");
anari::setParameter(
d, defaultMaterial, "color", anari::float3(0.f, 1.f, 0.f));
d, defaultMaterial, "color", math::float3(0.f, 1.f, 0.f));
anari::commitParameters(d, defaultMaterial);

TextureCache cache;
Expand Down Expand Up @@ -154,8 +154,8 @@ static void loadObj(
auto *vertices = objdata.attrib.vertices.data();
auto *texcoords = objdata.attrib.texcoords.data();

std::vector<anari::float3> v;
std::vector<anari::float2> vt;
std::vector<math::float3> v;
std::vector<math::float2> vt;

for (auto &shape : objdata.shapes) {
v.clear();
Expand Down
16 changes: 8 additions & 8 deletions libs/anari_test_scenes/scenes/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ Camera TestScene::createDefaultCameraFromWorld(anari::World w)

anari::getProperty(m_device, w, "bounds", bounds);

const anari::float3 bounds_size = bounds[1] - bounds[0];
const anari::float3 bounds_center = 0.5f * (bounds[0] + bounds[1]);
const float distance = anari::length(bounds_size) * 0.8f;
const math::float3 bounds_size = bounds[1] - bounds[0];
const math::float3 bounds_center = 0.5f * (bounds[0] + bounds[1]);
const float distance = math::length(bounds_size) * 0.8f;

const anari::float3 eye_pos = bounds_center + anari::float3(0, 0, -distance);
const math::float3 eye_pos = bounds_center + math::float3(0, 0, -distance);

Camera cam;

cam.position = eye_pos;
cam.direction = anari::normalize(bounds_center - eye_pos);
cam.direction = math::normalize(bounds_center - eye_pos);
cam.at = bounds_center;
cam.up = anari::float3(0, 1, 0);
cam.up = math::float3(0, 1, 0);

return cam;
}

box3 TestScene::bounds()
{
box3 retval = {anari::float3(-5), anari::float3(5)};
box3 retval = {math::float3(-5), math::float3(5)};
anari::getProperty(m_device, world(), "bounds", retval);
return retval;
}
Expand Down Expand Up @@ -70,7 +70,7 @@ void TestScene::computeNextFrame()
void TestScene::setDefaultLight(anari::World w)
{
auto light = anari::newObject<anari::Light>(m_device, "directional");
anari::setParameter(m_device, light, "direction", anari::float3(0, -1, 0));
anari::setParameter(m_device, light, "direction", math::float3(0, -1, 0));
anari::setParameter(m_device, light, "irradiance", 4.f);
anari::commitParameters(m_device, light);
anari::setAndReleaseParameter(
Expand Down
2 changes: 1 addition & 1 deletion libs/anari_test_scenes/scenes/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace anari {
namespace scenes {

using box3 = std::array<anari::float3, 2>; // bounds_lower, bounds_upper;
using box3 = std::array<math::float3, 2>; // bounds_lower, bounds_upper;

struct ANARI_TEST_SCENES_INTERFACE TestScene
: public helium::ParameterizedObject
Expand Down
10 changes: 5 additions & 5 deletions libs/anari_test_scenes/scenes/test/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,10 @@ void Attributes::commit()
int y = i/4;

auto inst = anari::newObject<anari::Instance>(d, "transform");
auto tl = anari::translation_matrix(2.0f*anari::float3(x-3.5f, y-3.5f, 0.f));
auto tl = math::translation_matrix(2.0f*math::float3(x-3.5f, y-3.5f, 0.f));

{ // NOTE: exercise anari::setParameter with C-array type
anari::mat4 _xfm = tl;
math::mat4 _xfm = tl;
float xfm[16];
std::memcpy(xfm, &_xfm, sizeof(_xfm));
anari::setParameter(d, inst, "transform", xfm);
Expand Down Expand Up @@ -613,10 +613,10 @@ void Attributes::commit()
int y = i/4;

auto inst = anari::newObject<anari::Instance>(d, "transform");
auto tl = anari::translation_matrix(2.0f*anari::float3(x+0.5f, y-3.5f, 0.f));
auto tl = math::translation_matrix(2.0f*math::float3(x+0.5f, y-3.5f, 0.f));

{ // NOTE: exercise anari::setParameter with C-array type
anari::mat4 _xfm = tl;
math::mat4 _xfm = tl;
float xfm[16];
std::memcpy(xfm, &_xfm, sizeof(_xfm));
anari::setParameter(d, inst, "transform", xfm);
Expand Down Expand Up @@ -663,7 +663,7 @@ void Attributes::commit()
anari::release(d, i);

auto light = anari::newObject<anari::Light>(d, "directional");
anari::setParameter(d, light, "direction", anari::float3(0, 0, 1));
anari::setParameter(d, light, "direction", math::float3(0, 0, 1));
anari::setParameter(d, light, "irradiance", 1.f);
anari::commitParameters(d, light);
anari::setAndReleaseParameter(
Expand Down
Loading