Skip to content

Commit

Permalink
[visual-debugger] Adding functions to query the number of spatial cac…
Browse files Browse the repository at this point in the history
…hes and some info about them
  • Loading branch information
sherholz-intel committed Sep 26, 2024
1 parent 4ffef33 commit eab09d9
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 1 deletion.
82 changes: 82 additions & 0 deletions openpgl/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,88 @@ extern "C" OPENPGL_DLLEXPORT PGLFieldStatistics pglFieldGetVolumeStatistics(PGLF
return (PGLFieldStatistics)gField->getVolumeStatistics();
}

extern "C" OPENPGL_DLLEXPORT size_t pglFieldGetNumSurfaceCaches(PGLField field)
{
const auto *gField = (const IGuidingField *)field;
return gField->getNumSurfaceCaches();
}

extern "C" OPENPGL_DLLEXPORT size_t pglFieldGetNumVolumeCaches(PGLField field)
{
const auto *gField = (const IGuidingField *)field;
return gField->getNumVolumeCaches();
}

extern "C" OPENPGL_DLLEXPORT pgl_vec3f pglFieldGetSurfaceCachePosition(PGLField field, size_t idx)
{
const auto *gField = (const IGuidingField *)field;
Vector3 cPos = gField->getSurfaceCachePosition(idx);
pgl_vec3f pglCPos;
pglVec3f(pglCPos, cPos[0], cPos[1], cPos[2]);
return pglCPos;
}

extern "C" OPENPGL_DLLEXPORT pgl_vec3f pglFieldGetVolumeCachePosition(PGLField field, size_t idx)
{
const auto *gField = (const IGuidingField *)field;
Vector3 cPos = gField->getVolumeCachePosition(idx);
pgl_vec3f pglCPos;
pglVec3f(pglCPos, cPos[0], cPos[1], cPos[2]);
return pglCPos;
}

extern "C" OPENPGL_DLLEXPORT pgl_box3f pglFieldGetSurfaceCacheSampleBounds(PGLField field, size_t idx)
{
const auto *gField = (const IGuidingField *)field;
BBox csBounds = gField->getSurfaceCacheSampleBounds(idx);
pgl_box3f pglBBox;
pglVec3f(pglBBox.lower, csBounds.lower[0], csBounds.lower[1], csBounds.lower[2]);
pglVec3f(pglBBox.upper, csBounds.upper[0], csBounds.upper[1], csBounds.upper[2]);
return pglBBox;
}

extern "C" OPENPGL_DLLEXPORT pgl_box3f pglFieldGetVolumeCacheSampleBounds(PGLField field, size_t idx)
{
const auto *gField = (const IGuidingField *)field;
BBox csBounds = gField->getVolumeCacheSampleBounds(idx);
pgl_box3f pglBBox;
pglVec3f(pglBBox.lower, csBounds.lower[0], csBounds.lower[1], csBounds.lower[2]);
pglVec3f(pglBBox.upper, csBounds.upper[0], csBounds.upper[1], csBounds.upper[2]);
return pglBBox;
}

extern "C" OPENPGL_DLLEXPORT pgl_cacheInfo pglFieldGetSurfaceCacheInfo(PGLField field, size_t idx)
{
const auto *gField = (const IGuidingField *)field;
CacheInfo ci = gField->getSurfaceCacheInfo(idx);
pgl_cacheInfo pglCI;
pglVec3f(pglCI.cacheBounds.lower, ci.cacheBounds.lower[0], ci.cacheBounds.lower[1], ci.cacheBounds.lower[2]);
pglVec3f(pglCI.cacheBounds.upper, ci.cacheBounds.upper[0], ci.cacheBounds.upper[1], ci.cacheBounds.upper[2]);
pglVec3f(pglCI.sampleBounds.lower, ci.sampleBounds.lower[0], ci.sampleBounds.lower[1], ci.sampleBounds.lower[2]);
pglVec3f(pglCI.sampleBounds.upper, ci.sampleBounds.upper[0], ci.sampleBounds.upper[1], ci.sampleBounds.upper[2]);

pglVec3f(pglCI.sampleMean, ci.sampleMean[0], ci.sampleMean[1], ci.sampleMean[2]);
pglVec3f(pglCI.distributionPivot, ci.distributionPivot[0], ci.distributionPivot[1], ci.distributionPivot[2]);
pglVec3f(pglCI.sampleVariance, ci.sampleVariance[0], ci.sampleVariance[1], ci.sampleVariance[2]);
return pglCI;
}

extern "C" OPENPGL_DLLEXPORT pgl_cacheInfo pglFieldGetVolumeCacheInfo(PGLField field, size_t idx)
{
const auto *gField = (const IGuidingField *)field;
CacheInfo ci = gField->getVolumeCacheInfo(idx);
pgl_cacheInfo pglCI;
pglVec3f(pglCI.cacheBounds.lower, ci.cacheBounds.lower[0], ci.cacheBounds.lower[1], ci.cacheBounds.lower[2]);
pglVec3f(pglCI.cacheBounds.upper, ci.cacheBounds.upper[0], ci.cacheBounds.upper[1], ci.cacheBounds.upper[2]);
pglVec3f(pglCI.sampleBounds.lower, ci.sampleBounds.lower[0], ci.sampleBounds.lower[1], ci.sampleBounds.lower[2]);
pglVec3f(pglCI.sampleBounds.upper, ci.sampleBounds.upper[0], ci.sampleBounds.upper[1], ci.sampleBounds.upper[2]);

pglVec3f(pglCI.sampleMean, ci.sampleMean[0], ci.sampleMean[1], ci.sampleMean[2]);
pglVec3f(pglCI.distributionPivot, ci.distributionPivot[0], ci.distributionPivot[1], ci.distributionPivot[2]);
pglVec3f(pglCI.sampleVariance, ci.sampleVariance[0], ci.sampleVariance[1], ci.sampleVariance[2]);
return pglCI;
}

///////////////////////////////////////////////////////////////////////////////
// SampleStorage //////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
Expand Down
43 changes: 43 additions & 0 deletions openpgl/field/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,49 @@ struct Field
return stats;
}

size_t getNumCaches() const
{
return m_regionStorageContainer.size();
}

Vector3 getCachePosition(size_t idx) const
{
// std::cout << m_distributionFactorySettings.toString()<<std::endl;
Vector3 cPos;
if (idx < m_regionStorageContainer.size())
{
cPos = m_regionStorageContainer[idx].first.distribution._pivotPosition;
}
return cPos;
}

BBox getCacheSampleBounds(size_t idx) const
{
// std::cout << m_distributionFactorySettings.toString()<<std::endl;
BBox cBBox;
if (idx < m_regionStorageContainer.size())
{
// cBBox = m_regionStorageContainer[idx].first.sampleStatistics.sampleBounds;
cBBox = m_regionStorageContainer[idx].first.regionBounds;
}
return cBBox;
}

CacheInfo getCacheInfo(size_t idx) const
{
CacheInfo ci;
if (idx < m_regionStorageContainer.size())
{
// cBBox = m_regionStorageContainer[idx].first.sampleStatistics.sampleBounds;
ci.cacheBounds = m_regionStorageContainer[idx].first.regionBounds;
ci.sampleBounds = m_regionStorageContainer[idx].first.sampleStatistics.sampleBounds;
ci.sampleMean = m_regionStorageContainer[idx].first.sampleStatistics.getMean();
ci.sampleVariance = m_regionStorageContainer[idx].first.sampleStatistics.getVariance();
ci.distributionPivot = m_regionStorageContainer[idx].first.distribution._pivotPosition;
}
return ci;
}

private:
bool m_isSurface{true};

Expand Down
16 changes: 16 additions & 0 deletions openpgl/field/ISurfaceVolumeField.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,21 @@ struct ISurfaceVolumeField
virtual FieldStatistics *getSurfaceStatistics() const = 0;

virtual FieldStatistics *getVolumeStatistics() const = 0;

virtual size_t getNumSurfaceCaches() const = 0;

virtual size_t getNumVolumeCaches() const = 0;

virtual Vector3 getSurfaceCachePosition(size_t idx) const = 0;

virtual Vector3 getVolumeCachePosition(size_t idx) const = 0;

virtual BBox getSurfaceCacheSampleBounds(size_t idx) const = 0;

virtual BBox getVolumeCacheSampleBounds(size_t idx) const = 0;

virtual CacheInfo getSurfaceCacheInfo(size_t idx) const = 0;

virtual CacheInfo getVolumeCacheInfo(size_t idx) const = 0;
};
} // namespace openpgl
40 changes: 40 additions & 0 deletions openpgl/field/SurfaceVolumeField.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,46 @@ struct SurfaceVolumeField : public ISurfaceVolumeField
return stats;
}

size_t getNumSurfaceCaches() const
{
return m_surfaceField.getNumCaches();
}

size_t getNumVolumeCaches() const
{
return m_volumeField.getNumCaches();
}

Vector3 getSurfaceCachePosition(size_t idx) const
{
return m_surfaceField.getCachePosition(idx);
}

Vector3 getVolumeCachePosition(size_t idx) const
{
return m_volumeField.getCachePosition(idx);
}

BBox getSurfaceCacheSampleBounds(size_t idx) const
{
return m_surfaceField.getCacheSampleBounds(idx);
}

BBox getVolumeCacheSampleBounds(size_t idx) const
{
return m_volumeField.getCacheSampleBounds(idx);
}

CacheInfo getSurfaceCacheInfo(size_t idx) const
{
return m_surfaceField.getCacheInfo(idx);
}

CacheInfo getVolumeCacheInfo(size_t idx) const
{
return m_volumeField.getCacheInfo(idx);
}

private:
size_t m_iteration{0};
size_t m_totalSPP{0};
Expand Down
11 changes: 10 additions & 1 deletion openpgl/include/openpgl/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,13 @@ struct pgl_spectrum
};
#else
typedef pgl_vec3f pgl_spectrum;
#endif
#endif

typedef struct
{
pgl_box3f cacheBounds;
pgl_box3f sampleBounds;
pgl_vec3f sampleMean;
pgl_vec3f distributionPivot;
pgl_vec3f sampleVariance;
} pgl_cacheInfo;
64 changes: 64 additions & 0 deletions openpgl/include/openpgl/cpp/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ struct Field
/// Checks if the spatial structure and directional distribution of this Field are similar to the ones stored in another Field.
bool operator==(const Field &b) const;

size_t GetNumSurfaceCaches() const;

size_t GetNumVolumeCaches() const;

pgl_vec3f GetSurfaceCachePosition(size_t idx) const;

pgl_vec3f GetVolumeCachePosition(size_t idx) const;

pgl_box3f GetSurfaceCacheSampleBounds(size_t idx) const;

pgl_box3f GetVolumeCacheSampleBounds(size_t idx) const;

pgl_cacheInfo GetSurfaceCacheInfo(size_t idx) const;

pgl_cacheInfo GetVolumeCacheInfo(size_t idx) const;

friend struct openpgl::cpp::SurfaceSamplingDistribution;
friend struct openpgl::cpp::VolumeSamplingDistribution;

Expand Down Expand Up @@ -236,5 +252,53 @@ OPENPGL_INLINE FieldStatistics Field::GetVolumeStatistics() const
return FieldStatistics(fieldStats);
}

OPENPGL_INLINE size_t Field::GetNumSurfaceCaches() const
{
OPENPGL_ASSERT(m_fieldHandle);
return pglFieldGetNumSurfaceCaches(m_fieldHandle);
}

OPENPGL_INLINE size_t Field::GetNumVolumeCaches() const
{
OPENPGL_ASSERT(m_fieldHandle);
return pglFieldGetNumVolumeCaches(m_fieldHandle);
}

OPENPGL_INLINE pgl_vec3f Field::GetSurfaceCachePosition(size_t idx) const
{
OPENPGL_ASSERT(m_fieldHandle);
return pglFieldGetSurfaceCachePosition(m_fieldHandle, idx);
}

OPENPGL_INLINE pgl_vec3f Field::GetVolumeCachePosition(size_t idx) const
{
OPENPGL_ASSERT(m_fieldHandle);
return pglFieldGetVolumeCachePosition(m_fieldHandle, idx);
}

OPENPGL_INLINE pgl_box3f Field::GetSurfaceCacheSampleBounds(size_t idx) const
{
OPENPGL_ASSERT(m_fieldHandle);
return pglFieldGetSurfaceCacheSampleBounds(m_fieldHandle, idx);
}

OPENPGL_INLINE pgl_box3f Field::GetVolumeCacheSampleBounds(size_t idx) const
{
OPENPGL_ASSERT(m_fieldHandle);
return pglFieldGetVolumeCacheSampleBounds(m_fieldHandle, idx);
}

OPENPGL_INLINE pgl_cacheInfo Field::GetSurfaceCacheInfo(size_t idx) const
{
OPENPGL_ASSERT(m_fieldHandle);
return pglFieldGetSurfaceCacheInfo(m_fieldHandle, idx);
}

OPENPGL_INLINE pgl_cacheInfo Field::GetVolumeCacheInfo(size_t idx) const
{
OPENPGL_ASSERT(m_fieldHandle);
return pglFieldGetVolumeCacheInfo(m_fieldHandle, idx);
}

} // namespace cpp
} // namespace openpgl
16 changes: 16 additions & 0 deletions openpgl/include/openpgl/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ typedef ManagedObject Field;

OPENPGL_CORE_INTERFACE PGLFieldStatistics pglFieldGetVolumeStatistics(PGLField field);

OPENPGL_CORE_INTERFACE size_t pglFieldGetNumSurfaceCaches(PGLField field);

OPENPGL_CORE_INTERFACE size_t pglFieldGetNumVolumeCaches(PGLField field);

OPENPGL_CORE_INTERFACE pgl_vec3f pglFieldGetSurfaceCachePosition(PGLField field, size_t idx);

OPENPGL_CORE_INTERFACE pgl_vec3f pglFieldGetVolumeCachePosition(PGLField field, size_t idx);

OPENPGL_CORE_INTERFACE pgl_box3f pglFieldGetSurfaceCacheSampleBounds(PGLField field, size_t idx);

OPENPGL_CORE_INTERFACE pgl_box3f pglFieldGetVolumeCacheSampleBounds(PGLField field, size_t idx);

OPENPGL_CORE_INTERFACE pgl_cacheInfo pglFieldGetSurfaceCacheInfo(PGLField field, size_t idx);

OPENPGL_CORE_INTERFACE pgl_cacheInfo pglFieldGetVolumeCacheInfo(PGLField field, size_t idx);

#ifdef __cplusplus
} // extern "C"
#endif
9 changes: 9 additions & 0 deletions openpgl/openpgl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@ typedef embree::Vec3<int64_t> Vector3i;
typedef embree::BBox<Vector3> BBox;
typedef embree::BBox<Vector3i> BBoxi;

struct CacheInfo
{
BBox cacheBounds;
BBox sampleBounds;
Point3 sampleMean;
Point3 distributionPivot;
Vector3 sampleVariance;
};

inline float dot(Vector2 &a, Vector2 &b)
{
return embree::dot(a, b);
Expand Down

0 comments on commit eab09d9

Please sign in to comment.