more photon map-related serialization fixes

metadata
Wenzel Jakob 2011-09-02 17:51:49 -04:00
parent f0629482cd
commit ab16dfac21
4 changed files with 54 additions and 43 deletions

View File

@ -117,34 +117,10 @@ public:
}
/// Serialize to a binary data stream
inline void serialize(Stream *stream) const {
position.serialize(stream);
#if defined(SINGLE_PRECISION) && SPECTRUM_SAMPLES == 3
stream->write(data.power, 8);
#else
data.power.serialize(stream);
stream->writeUChar(data.phi);
stream->writeUChar(data.theta);
stream->writeUChar(data.phiN);
stream->writeUChar(data.thetaN);
#endif
stream->writeUShort(data.depth);
stream->writeUChar(flags);
}
void serialize(Stream *stream) const;
/// Return a string representation (for debugging)
std::string toString() const {
std::ostringstream oss;
oss << "Photon[pos = " << getPosition().toString() << ","
<< ", power = " << getPower().toString()
<< ", direction = " << getDirection().toString()
<< ", normal = " << getNormal().toString()
<< ", axis = " << getAxis()
<< ", depth = " << getDepth()
<< "]";
return oss.str();
}
std::string toString() const;
protected:
// ======================================================================
/// @{ \name Precomputed lookup tables

View File

@ -352,7 +352,7 @@ public:
if (isDiffuse || cacheQuery) {
int maxDepth = m_maxDepth == -1 ? INT_MAX : (m_maxDepth-rRec.depth);
if (rRec.type & RadianceQueryRecord::EIndirectSurfaceRadiance)
if (rRec.type & RadianceQueryRecord::EIndirectSurfaceRadiance && m_globalPhotonMap.get())
LiSurf += m_globalPhotonMap->estimateIrradiance(its.p,
its.shFrame.n, m_globalLookupRadius, maxDepth,
m_globalLookupSize) * bsdf->getDiffuseReflectance(its) * INV_PI;

View File

@ -44,6 +44,8 @@ bool Photon::createPrecompTables() {
Photon::Photon(Stream *stream) {
position = Point(stream);
if (!leftBalancedLayout)
setRightIndex(0, stream->readUInt());
#if defined(SINGLE_PRECISION) && SPECTRUM_SAMPLES == 3
stream->read(data.power, 8);
#else
@ -57,6 +59,24 @@ Photon::Photon(Stream *stream) {
flags = stream->readUChar();
}
void Photon::serialize(Stream *stream) const {
position.serialize(stream);
if (!leftBalancedLayout)
stream->writeUInt(getRightIndex(0));
#if defined(SINGLE_PRECISION) && SPECTRUM_SAMPLES == 3
stream->write(data.power, 8);
#else
data.power.serialize(stream);
stream->writeUChar(data.phi);
stream->writeUChar(data.theta);
stream->writeUChar(data.phiN);
stream->writeUChar(data.thetaN);
#endif
stream->writeUShort(data.depth);
stream->writeUChar(flags);
}
Photon::Photon(const Point &p, const Normal &normal,
const Vector &dir, const Spectrum &P,
uint16_t _depth) {
@ -101,4 +121,18 @@ Photon::Photon(const Point &p, const Normal &normal,
#endif
}
std::string Photon::toString() const {
std::ostringstream oss;
oss << "Photon[" << endl
<< " pos = " << getPosition().toString() << "," << endl
<< " power = " << getPower().toString() << "," << endl
<< " direction = " << getDirection().toString() << "," << endl
<< " normal = " << getNormal().toString() << "," << endl
<< " axis = " << getAxis() << "," << endl
<< " depth = " << getDepth() << endl
<< "]";
return oss.str();
}
MTS_NAMESPACE_END

View File

@ -30,7 +30,8 @@ PhotonMap::PhotonMap(size_t photonCount)
}
PhotonMap::PhotonMap(Stream *stream, InstanceManager *manager)
: m_kdtree(0, PhotonTree::ESlidingMidpoint) {
: SerializableObject(stream, manager),
m_kdtree(0, PhotonTree::ESlidingMidpoint) {
Assert(Photon::m_precompTableReady);
m_scale = (Float) stream->readFloat();
m_kdtree.resize(stream->readSize());
@ -40,20 +41,6 @@ PhotonMap::PhotonMap(Stream *stream, InstanceManager *manager)
m_kdtree[i] = Photon(stream);
}
PhotonMap::~PhotonMap() {
}
std::string PhotonMap::toString() const {
std::ostringstream oss;
oss << "PhotonMap[" << endl
<< " aabb = " << m_kdtree.getAABB().toString() << "," << endl
<< " size = " << m_kdtree.size() << "," << endl
<< " capacity = " << m_kdtree.capacity() << "," << endl
<< " scale = " << m_scale << endl
<< "]";
return oss.str();
}
void PhotonMap::serialize(Stream *stream, InstanceManager *manager) const {
Log(EDebug, "Serializing a photon map (%.2f KB)",
m_kdtree.size() * sizeof(Photon) / 1024.0f);
@ -65,6 +52,20 @@ void PhotonMap::serialize(Stream *stream, InstanceManager *manager) const {
m_kdtree[i].serialize(stream);
}
PhotonMap::~PhotonMap() {
}
std::string PhotonMap::toString() const {
std::ostringstream oss;
oss << "PhotonMap[" << endl
<< " size = " << m_kdtree.size() << "," << endl
<< " capacity = " << m_kdtree.capacity() << "," << endl
<< " aabb = " << m_kdtree.getAABB().toString() << "," << endl
<< " depth = " << m_kdtree.getDepth() << "," << endl
<< " scale = " << m_scale << endl
<< "]";
return oss.str();
}
void PhotonMap::dumpOBJ(const std::string &filename) {
std::ofstream os(filename.c_str());
os << "o Photons" << endl;
@ -183,5 +184,5 @@ size_t PhotonMap::estimateRadianceRaw(const Intersection &its,
return count;
}
MTS_IMPLEMENT_CLASS_S(PhotonMap, false, Object)
MTS_IMPLEMENT_CLASS_S(PhotonMap, false, SerializableObject)
MTS_NAMESPACE_END