Skip to content

Commit 89a9a48

Browse files
committed
switch to combined color/opacity array on tf1D volumes in tsdVolumeViewer
1 parent 2747714 commit 89a9a48

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

tsd/apps/interactive/volume_viewer/tsdVolumeViewer.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,23 @@ class Application : public BaseApplication
5454
m = manipulator,
5555
tf = tfeditor,
5656
core = core]() {
57-
auto colorArray = core->tsd.ctx.createArray(ANARI_FLOAT32_VEC3, 256);
58-
auto opacityArray = core->tsd.ctx.createArray(ANARI_FLOAT32, 256);
57+
auto colorMapArray = core->tsd.ctx.createArray(ANARI_FLOAT32_VEC4, 256);
5958

6059
tsd::VolumeRef volume;
6160

6261
if (!g_filename.empty()) {
6362
volume = tsd::import_volume(
64-
core->tsd.ctx, g_filename.c_str(), colorArray, opacityArray);
63+
core->tsd.ctx, g_filename.c_str(), colorMapArray);
6564
}
6665

6766
if (!volume) {
6867
if (!g_filename.empty())
6968
tsd::logWarning("unable to load volume from file, using placeholder");
7069

71-
auto tx1 =
72-
core->tsd.ctx.insertChildTransformNode(core->tsd.ctx.defaultLayer()->root());
70+
auto tx1 = core->tsd.ctx.insertChildTransformNode(
71+
core->tsd.ctx.defaultLayer()->root());
7372

74-
volume = tsd::generate_noiseVolume(
75-
core->tsd.ctx, tx1, colorArray, opacityArray);
73+
volume = tsd::generate_noiseVolume(core->tsd.ctx, tx1, colorMapArray);
7674
}
7775

7876
core->tsd.selectedObject = volume.data();
@@ -90,7 +88,8 @@ class Application : public BaseApplication
9088
light->setName("mainLight");
9189
light->setParameter("direction", tsd::float2(0.f, 240.f));
9290

93-
core->tsd.ctx.defaultLayer()->insert_first_child(core->tsd.ctx.defaultLayer()->root(),
91+
core->tsd.ctx.defaultLayer()->insert_first_child(
92+
core->tsd.ctx.defaultLayer()->root(),
9493
tsd::utility::Any(ANARI_LIGHT, light.index()));
9594
}
9695

@@ -102,18 +101,9 @@ class Application : public BaseApplication
102101

103102
tf->setUpdateCallback([=](const tsd::float2 &valueRange,
104103
const std::vector<tsd::float4> &co) mutable {
105-
auto *colors = colorArray->mapAs<tsd::float3>();
106-
auto *opacities = opacityArray->mapAs<float>();
107-
std::transform(co.begin(), co.end(), colors, [](const tsd::float4 &v) {
108-
return tsd::float3(v.x, v.y, v.z);
109-
});
110-
std::transform(
111-
co.begin(), co.end(), opacities, [](const tsd::float4 &v) {
112-
return v.w;
113-
});
114-
colorArray->unmap();
115-
opacityArray->unmap();
116-
104+
auto *colorMap = colorMapArray->mapAs<tsd::float4>();
105+
std::copy(co.begin(), co.end(), colorMap);
106+
colorMapArray->unmap();
117107
volume->setParameter("valueRange", ANARI_FLOAT32_BOX1, &valueRange);
118108
});
119109
});

tsd/src/tsd/authoring/importers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SpatialFieldRef import_NVDB(Context &ctx, const char *filename);
2424
VolumeRef import_volume(Context &ctx,
2525
const char *filename,
2626
ArrayRef colors,
27-
ArrayRef opacities);
27+
ArrayRef opacities = {});
2828

2929
// clang-format on
3030

tsd/src/tsd/authoring/importers/import_volume.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ VolumeRef import_volume(Context &ctx,
4646
volume->setName(fileOf(filepath).c_str());
4747
volume->setParameterObject("value", *field);
4848
volume->setParameterObject("color", *colorArray);
49-
volume->setParameterObject("opacity", *opacityArray);
49+
if (opacityArray)
50+
volume->setParameterObject("opacity", *opacityArray);
5051
volume->setParameter("valueRange", ANARI_FLOAT32_BOX1, &valueRange);
5152

5253
return volume;

tsd/src/tsd/authoring/procedural/generate_noiseVolume.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ VolumeRef generate_noiseVolume(Context &ctx,
4444
location, tokens::volume::transferFunction1D);
4545
volume->setName("noise_volume");
4646

47-
if (!(colorArray && opacityArray)) {
47+
if (!colorArray) {
4848
colorArray = ctx.createArray(ANARI_FLOAT32_VEC3, 3);
4949
opacityArray = ctx.createArray(ANARI_FLOAT32, 2);
5050

@@ -60,11 +60,13 @@ VolumeRef generate_noiseVolume(Context &ctx,
6060

6161
colorArray->setData(colors.data());
6262
opacityArray->setData(opacities.data());
63+
} else {
64+
volume->setParameterObject("color"_t, *colorArray);
65+
if (opacityArray)
66+
volume->setParameterObject("opacity"_t, *opacityArray);
6367
}
6468

6569
volume->setParameterObject("value"_t, *field);
66-
volume->setParameterObject("color"_t, *colorArray);
67-
volume->setParameterObject("opacity"_t, *opacityArray);
6870

6971
return volume;
7072
}

0 commit comments

Comments
 (0)