Skip to content

Commit

Permalink
Rename step size to gradient delta
Browse files Browse the repository at this point in the history
  • Loading branch information
szellmann committed Nov 2, 2024
1 parent ab381f0 commit 066748b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
14 changes: 7 additions & 7 deletions DeviceCopyableObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ struct SpatialField
enum Type { StructuredRegular, Unstructured, BlockStructured, Unknown, };
Type type{Unknown};
unsigned fieldID{UINT_MAX};
float baseDT{0.5f};
float delta{0.5f};
GridAccel gridAccel;
mat4x3 voxelSpaceTransform;

Expand Down Expand Up @@ -455,12 +455,12 @@ inline bool sampleField(const SpatialField &sf, vec3 P, float &value) {
VSNRAY_FUNC
inline bool sampleGradient(const SpatialField &sf, vec3 P, float3 &value) {
float x0=0, x1=0, y0=0, y1=0, z0=0, z1=0;
bool b0 = sampleField(sf, P+float3{sf.baseDT, 0.f, 0.f}, x1);
bool b1 = sampleField(sf, P-float3{sf.baseDT, 0.f, 0.f}, x0);
bool b2 = sampleField(sf, P+float3{0.f, sf.baseDT, 0.f}, y1);
bool b3 = sampleField(sf, P-float3{0.f, sf.baseDT, 0.f}, y0);
bool b4 = sampleField(sf, P+float3{0.f, 0.f, sf.baseDT}, z1);
bool b5 = sampleField(sf, P-float3{0.f, 0.f, sf.baseDT}, z0);
bool b0 = sampleField(sf, P+float3{sf.delta, 0.f, 0.f}, x1);
bool b1 = sampleField(sf, P-float3{sf.delta, 0.f, 0.f}, x0);
bool b2 = sampleField(sf, P+float3{0.f, sf.delta, 0.f}, y1);
bool b3 = sampleField(sf, P-float3{0.f, sf.delta, 0.f}, y0);
bool b4 = sampleField(sf, P+float3{0.f, 0.f, sf.delta}, z1);
bool b5 = sampleField(sf, P-float3{0.f, 0.f, sf.delta}, z0);
if (b0 && b1 && b2 && b3 && b4 && b5) {
value = float3{x1,y1,z1}-float3{x0,y0,z0};
return true; // TODO
Expand Down
2 changes: 1 addition & 1 deletion scene/volume/spatial_field/BlockStructuredField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void BlockStructuredField::commit()
vec3 T = voxelBounds.min-m_bounds.min;
vfield.voxelSpaceTransform = mat4x3(S,T);

setStepSize(1.f); // used for (gradient) shading ISO's
setGradientDelta(1.f);

buildGrid();

Expand Down
9 changes: 2 additions & 7 deletions scene/volume/spatial_field/SpatialField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,9 @@ void SpatialField::buildGrid()
"buildGrid() not implemented for field type");
}

float SpatialField::stepSize() const
void SpatialField::setGradientDelta(float delta)
{
return vfield.baseDT;
}

void SpatialField::setStepSize(float size)
{
vfield.baseDT = size;
vfield.delta = delta;
}

void SpatialField::dispatch()
Expand Down
4 changes: 1 addition & 3 deletions scene/volume/spatial_field/SpatialField.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ struct SpatialField : public Object

virtual void buildGrid();

float stepSize() const;

protected:
dco::SpatialField vfield;

GridAccel m_gridAccel;

void setStepSize(float size);
void setGradientDelta(float delta);
void dispatch();
};

Expand Down
2 changes: 1 addition & 1 deletion scene/volume/spatial_field/StructuredRegularField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void StructuredRegularField::commit()
vec3 T = -bounds().min;
vfield.voxelSpaceTransform = mat4x3(S,T);

setStepSize(min_element(m_spacing / 2.f));
setGradientDelta(min_element(m_spacing / 2.f));

#if defined(WITH_CUDA) || defined(WITH_HIP)
texture<float, 3> tex(m_dims.x, m_dims.y, m_dims.z);
Expand Down
10 changes: 5 additions & 5 deletions scene/volume/spatial_field/UnstructuredField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void UnstructuredField::commit()
#endif

vfield.voxelSpaceTransform = mat4x3(mat3::identity(),vec3f(0.f));
setStepSize(minCellDiagonal);
setGradientDelta(minCellDiagonal);

buildGrid();

Expand Down Expand Up @@ -248,7 +248,7 @@ __global__ void UnstructuredField_buildGridGPU(dco::GridAccel vaccel,
const vec4f *vertices,
const dco::UElem *elements,
size_t numElems,
float baseDT)
float delta)
{
size_t cellID = blockIdx.x * size_t(blockDim.x) + threadIdx.x;

Expand Down Expand Up @@ -282,7 +282,7 @@ __global__ void UnstructuredField_buildGridGPU(dco::GridAccel vaccel,
// a macrocell neighborhood:
//updateMCStepSize(
// mcID,vaccel.dims,length(cellBounds.max-cellBounds.min),vaccel.stepSizes);
updateMCStepSize(mcID,vaccel.dims,baseDT,vaccel.stepSizes);
updateMCStepSize(mcID,vaccel.dims,delta,vaccel.stepSizes);
}
}
}
Expand All @@ -301,7 +301,7 @@ void UnstructuredField::buildGrid()
size_t numThreads = 1024;
size_t numElems = m_elements.size();
UnstructuredField_buildGridGPU<<<div_up(numElems, numThreads), numThreads>>>(
vaccel, m_vertices.devicePtr(), m_elements.devicePtr(), numElems, vfield.baseDT);
vaccel, m_vertices.devicePtr(), m_elements.devicePtr(), numElems, vfield.delta);
#else
int3 dims{64, 64, 64};
box3f worldBounds = {bounds().min,bounds().max};
Expand Down Expand Up @@ -351,7 +351,7 @@ void UnstructuredField::buildGrid()
//updateMCStepSize(
// mcID,vaccel.dims,length(cellBounds.max-cellBounds.min),vaccel.stepSizes);
updateMCStepSize(
mcID,vaccel.dims,vfield.baseDT,vaccel.stepSizes);
mcID,vaccel.dims,vfield.delta,vaccel.stepSizes);
}
}
}
Expand Down

0 comments on commit 066748b

Please sign in to comment.