Added simple volume generation into sphere.h for debugging
This commit is contained in:
parent
f68d6eb6a9
commit
08b6131825
|
|
@ -20,4 +20,62 @@ struct Sphere {
|
|||
t = -b - h;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// A function to generate two concentric spherical shells
|
||||
__host__ void generateVolume(float* hostVolume, int volW, int volH, int volD) {
|
||||
int cx = volW / 2;
|
||||
int cy = volH / 2;
|
||||
int cz = volD / 2;
|
||||
float maxRadius = static_cast<float>(volW) * 0.5f;
|
||||
|
||||
// Let's define two shells:
|
||||
float shell1Inner = 0.2f * maxRadius;
|
||||
float shell1Outer = 0.3f * maxRadius;
|
||||
float shell2Inner = 0.4f * maxRadius;
|
||||
float shell2Outer = 0.5f * maxRadius;
|
||||
|
||||
// Intensities
|
||||
float shell1Intensity = 0.8f;
|
||||
float shell2Intensity = 0.6f;
|
||||
|
||||
for (int z = 0; z < volD; ++z) {
|
||||
for (int y = 0; y < volH; ++y) {
|
||||
for (int x = 0; x < volW; ++x) {
|
||||
float dx = (float)(x - cx);
|
||||
float dy = (float)(y - cy);
|
||||
float dz = (float)(z - cz);
|
||||
float dist = sqrtf(dx*dx + dy*dy + dz*dz);
|
||||
|
||||
float intensity = 0.0f;
|
||||
|
||||
// Shell 1
|
||||
if (dist >= shell1Inner && dist <= shell1Outer) {
|
||||
float mid = 0.5f * (shell1Inner + shell1Outer);
|
||||
if (dist < mid) {
|
||||
float inFactor = (dist - shell1Inner) / (mid - shell1Inner);
|
||||
intensity += shell1Intensity * inFactor;
|
||||
} else {
|
||||
float outFactor = (shell1Outer - dist) / (shell1Outer - mid);
|
||||
intensity += shell1Intensity * outFactor;
|
||||
}
|
||||
}
|
||||
|
||||
// Shell 2
|
||||
if (dist >= shell2Inner && dist <= shell2Outer) {
|
||||
float mid = 0.5f * (shell2Inner + shell2Outer);
|
||||
if (dist < mid) {
|
||||
float inFactor = (dist - shell2Inner) / (mid - shell2Inner);
|
||||
intensity += shell2Intensity * inFactor;
|
||||
} else {
|
||||
float outFactor = (shell2Outer - dist) / (shell2Outer - mid);
|
||||
intensity += shell2Intensity * outFactor;
|
||||
}
|
||||
}
|
||||
|
||||
if (intensity > 1.0f) intensity = 1.0f;
|
||||
hostVolume[z * volW * volH + y * volW + x] = intensity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue