photon map updates
parent
70656037bf
commit
d59bd71c14
|
@ -39,13 +39,13 @@ public:
|
|||
/* ===================================================================== */
|
||||
|
||||
/**
|
||||
* Create an empty photon map and reserve memory for a specified
|
||||
* number of photons.
|
||||
* \brief Create an empty photon map and reserve memory
|
||||
* for a specified number of photons.
|
||||
*/
|
||||
PhotonMap(size_t amount = 0);
|
||||
PhotonMap(size_t photonCount = 0);
|
||||
|
||||
/**
|
||||
* Unserialize a photon map from a binary data stream
|
||||
* \brief Unserialize a photon map from a binary data stream
|
||||
*/
|
||||
PhotonMap(Stream *stream, InstanceManager *manager);
|
||||
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
// =============================================================
|
||||
|
||||
/**
|
||||
* Try to append a photon to the photon map
|
||||
* \brief Try to append a photon to the photon map
|
||||
*
|
||||
* \return \c false If the photon map is full
|
||||
*/
|
||||
|
|
|
@ -23,39 +23,27 @@
|
|||
|
||||
MTS_NAMESPACE_BEGIN
|
||||
|
||||
PhotonMap::PhotonMap(size_t maxPhotons)
|
||||
: m_photonCount(0), m_maxPhotons(maxPhotons), m_balanced(false), m_scale(1.0f) {
|
||||
PhotonMap::PhotonMap(size_t photonCount) : m_kdtree(photonCount), m_scale(1.0f) {
|
||||
Assert(Photon::m_precompTableReady);
|
||||
|
||||
/* For convenient heap addressing, the the photon list
|
||||
entries start with number 1 */
|
||||
m_photons = (Photon *) allocAligned(sizeof(Photon) * (maxPhotons+1));
|
||||
}
|
||||
|
||||
|
||||
PhotonMap::PhotonMap(Stream *stream, InstanceManager *manager) {
|
||||
m_aabb = AABB(stream);
|
||||
m_balanced = stream->readBool();
|
||||
m_maxPhotons = stream->readSize();
|
||||
m_lastInnerNode = stream->readSize();
|
||||
m_lastRChildNode = stream->readSize();
|
||||
m_scale = (Float) stream->readFloat();
|
||||
m_photonCount = stream->readSize();
|
||||
m_photons = new Photon[m_maxPhotons + 1];
|
||||
for (size_t i=1; i<=m_maxPhotons; ++i)
|
||||
m_photons[i] = Photon(stream);
|
||||
m_kdtree.resize(stream->readSize());
|
||||
for (size_t i=0; i<m_kdtree.size(); ++i)
|
||||
m_kdtree[i] = Photon(stream);
|
||||
}
|
||||
|
||||
PhotonMap::~PhotonMap() {
|
||||
freeAligned(m_photons);
|
||||
}
|
||||
|
||||
std::string PhotonMap::toString() const {
|
||||
std::ostringstream oss;
|
||||
oss << "PhotonMap[" << endl
|
||||
<< " aabb = " << m_aabb.toString() << "," << endl
|
||||
<< " photonCount = " << m_photonCount << "," << endl
|
||||
<< " maxPhotons = " << m_maxPhotons << "," << endl
|
||||
<< " balanced = " << m_balanced << "," << endl
|
||||
<< " size = " << m_kdtree.size() << "," << endl
|
||||
<< " capacity = " << m_kdtree.capacity() << "," << endl
|
||||
<< " scale = " << m_scale << endl
|
||||
<< "]";
|
||||
return oss.str();
|
||||
|
@ -63,28 +51,24 @@ std::string PhotonMap::toString() const {
|
|||
|
||||
void PhotonMap::serialize(Stream *stream, InstanceManager *manager) const {
|
||||
Log(EDebug, "Serializing a photon map (%.2f KB)",
|
||||
m_photonCount * 20.0f / 1024.0f);
|
||||
m_photonCount * sizeof(Photon) / 1024.0f);
|
||||
m_aabb.serialize(stream);
|
||||
stream->writeBool(m_balanced);
|
||||
stream->writeSize(m_maxPhotons);
|
||||
stream->writeSize(m_lastInnerNode);
|
||||
stream->writeSize(m_lastRChildNode);
|
||||
stream->writeFloat(m_scale);
|
||||
stream->writeSize(m_photonCount);
|
||||
for (size_t i=1; i<=m_maxPhotons; ++i)
|
||||
stream->writeSize(m_tree.size());
|
||||
for (size_t i=0; i<m_tree.size(); ++i)
|
||||
m_photons[i].serialize(stream);
|
||||
}
|
||||
|
||||
void PhotonMap::dumpOBJ(const std::string &filename) {
|
||||
std::ofstream os(filename.c_str());
|
||||
os << "o Photons" << endl;
|
||||
for (size_t i=1; i<=getPhotonCount(); i++) {
|
||||
Point p = getPhoton(i).getPosition();
|
||||
for (size_t i=0; i<m_tree.size(); ++i) {
|
||||
const Point &p = m_tree[i].getPosition();
|
||||
os << "v " << p.x << " " << p.y << " " << p.z << endl;
|
||||
}
|
||||
|
||||
/// Need to generate some fake geometry so that blender will import the points
|
||||
for (size_t i=3; i<=getPhotonCount(); i++)
|
||||
for (size_t i=3; i<=m_tree.size(); i++)
|
||||
os << "f " << i << " " << i-1 << " " << i-2 << endl;
|
||||
os.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue