Blender V4.3
SceneHash.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "SceneHash.h"
10
11#include "BLI_sys_types.h"
12
13#include <sstream>
14
15namespace Freestyle {
16
18{
19 stringstream ss;
20 ss << hex << _sum;
21 return ss.str();
22}
23
24void SceneHash::visitNodeViewLayer(NodeViewLayer &node)
25{
26 RenderData *r = &node.scene().r;
27 adler32((uchar *)&r->xsch, sizeof(r->xsch)); // resolution_x
28 adler32((uchar *)&r->ysch, sizeof(r->ysch)); // resolution_y
29 adler32((uchar *)&r->size, sizeof(r->size)); // resolution_percentage
30
31 FreestyleConfig *config = &node.sceneLayer().freestyle_config;
32 adler32((uchar *)&config->flags, sizeof(config->flags));
33 adler32((uchar *)&config->crease_angle, sizeof(config->crease_angle));
34 adler32((uchar *)&config->sphere_radius, sizeof(config->sphere_radius));
35 adler32((uchar *)&config->dkr_epsilon, sizeof(config->dkr_epsilon));
36}
37
38void SceneHash::visitNodeCamera(NodeCamera &cam)
39{
40 double *proj = cam.projectionMatrix();
41 for (int i = 0; i < 16; i++) {
42 adler32((uchar *)&proj[i], sizeof(double));
43 }
44}
45
46void SceneHash::visitIndexedFaceSet(IndexedFaceSet &ifs)
47{
48 const float *v = ifs.vertices();
49 const uint n = ifs.vsize();
50
51 for (uint i = 0; i < n; i++) {
52 adler32((uchar *)&v[i], sizeof(v[i]));
53 }
54}
55
56static const int MOD_ADLER = 65521;
57
58void SceneHash::adler32(const uchar *data, int size)
59{
60 uint32_t sum1 = _sum & 0xffff;
61 uint32_t sum2 = (_sum >> 16) & 0xffff;
62
63 for (int i = 0; i < size; i++) {
64 sum1 = (sum1 + data[i]) % MOD_ADLER;
65 sum2 = (sum1 + sum2) % MOD_ADLER;
66 }
67 _sum = sum1 | (sum2 << 16);
68}
69
70} /* namespace Freestyle */
unsigned char uchar
unsigned int uint
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
inherits from class Rep
Definition AppCanvas.cpp:20
static const int MOD_ADLER
Definition SceneHash.cpp:56
unsigned int uint32_t
Definition stdint.h:80
static const char hex[17]
Definition thumbs.cc:159