diff options
Diffstat (limited to 'source/blender/freestyle/intern/scene_graph')
3 files changed, 52 insertions, 6 deletions
diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.h b/source/blender/freestyle/intern/scene_graph/NodeCamera.h index 5d84a624830..78c34fdef6d 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeCamera.h +++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.h @@ -53,7 +53,9 @@ public: /*! Default matrices: Identity for both projection and modelview. */ NodeCamera(CameraType camera_type = GENERIC); +#if 0 /* UNUSED, gives warning in gcc */ NodeCamera(const NodeCamera& iBrother); +#endif virtual ~NodeCamera() {} diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp index 6e8856f1b93..60b95aaf6c5 100644 --- a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp +++ b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp @@ -24,16 +24,47 @@ #include "SceneHash.h" +#include <sstream> + namespace Freestyle { +string SceneHash::toString() +{ + stringstream ss; + ss << hex << _sum; + return ss.str(); +} + +void SceneHash::visitNodeCamera(NodeCamera& cam) +{ + double *proj = cam.projectionMatrix(); + for (int i = 0; i < 16; i++) { + adler32((unsigned char *)&proj[i], sizeof(double)); + } +} + void SceneHash::visitIndexedFaceSet(IndexedFaceSet& ifs) { const real *v = ifs.vertices(); const unsigned n = ifs.vsize(); for (unsigned i = 0; i < n; i++) { - _hashcode += v[i]; + adler32((unsigned char *)&v[i], sizeof(v[i])); + } +} + +static const int MOD_ADLER = 65521; + +void SceneHash::adler32(unsigned char *data, int size) +{ + uint32_t sum1 = _sum & 0xffff; + uint32_t sum2 = (_sum >> 16) & 0xffff; + + for (int i = 0; i < size; i++) { + sum1 = (sum1 + data[i]) % MOD_ADLER; + sum2 = (sum1 + sum2) % MOD_ADLER; } + _sum = sum1 | (sum2 << 16); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.h b/source/blender/freestyle/intern/scene_graph/SceneHash.h index 8f5f847eaab..5521b792e89 100644 --- a/source/blender/freestyle/intern/scene_graph/SceneHash.h +++ b/source/blender/freestyle/intern/scene_graph/SceneHash.h @@ -26,8 +26,11 @@ */ #include "IndexedFaceSet.h" +#include "NodeCamera.h" #include "SceneVisitor.h" +#include "BLI_sys_types.h" + #ifdef WITH_CXX_GUARDEDALLOC #include "MEM_guardedalloc.h" #endif @@ -39,23 +42,33 @@ class SceneHash : public SceneVisitor public: inline SceneHash() : SceneVisitor() { - _hashcode = 0.0; + _sum = 1; } virtual ~SceneHash() {} + VISIT_DECL(NodeCamera) VISIT_DECL(IndexedFaceSet) - inline real getValue() { - return _hashcode; + string toString(); + + inline bool match() { + return _sum == _prevSum; + } + + inline void store() { + _prevSum = _sum; } inline void reset() { - _hashcode = 0.0; + _sum = 1; } private: - real _hashcode; + void adler32(unsigned char *data, int size); + + uint32_t _sum; + uint32_t _prevSum; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SceneHash") |