/
SceneGraphComparer.h
113 lines (86 loc) · 2.47 KB
/
SceneGraphComparer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#pragma once
#include <string>
#include <list>
#include <map>
#include "inode.h"
#include "imap.h"
#include "itextstream.h"
namespace map
{
namespace algorithm
{
struct ComparisonResult
{
using Ptr = std::shared_ptr<ComparisonResult>;
// Represents a matching node pair
struct Match
{
std::string fingerPrint;
scene::INodePtr sourceNode;
scene::INodePtr targetNode;
};
struct KeyValueDifference
{
std::string key;
std::string value;
enum class Type
{
KeyValueAdded, // key is present on the source entity, but not on the target
KeyValueRemoved, // key is present on the target entity, but not on the source
KeyValueChanged, // key present on both, but value is different
};
Type type;
};
struct EntityDifference
{
std::string fingerPrint;
scene::INodePtr node;
std::string entityName;
enum class Type
{
EntityMissingInSource,
EntityMissingInTarget,
EntityPresentButDifferent,
};
Type type;
std::list<KeyValueDifference> differingKeyValues;
};
// The collection of entities with the same fingerprint value
std::list<Match> equivalentEntities;
// The collection of differing entities
std::list<EntityDifference> differingEntities;
};
class SceneGraphComparer
{
private:
scene::IMapRootNodePtr _source;
scene::IMapRootNodePtr _target;
ComparisonResult::Ptr _result;
using Fingerprints = std::map<std::string, scene::INodePtr>;
public:
struct EntityMismatch
{
std::string fingerPrint;
scene::INodePtr node;
std::string entityName;
};
using EntityMismatchByName = std::map<std::string, EntityMismatch>;
public:
SceneGraphComparer(const scene::IMapRootNodePtr& source, const scene::IMapRootNodePtr& target) :
_source(source),
_target(target),
_result(new ComparisonResult)
{}
void compare();
const ComparisonResult::Ptr& getResult() const
{
return _result;
}
private:
void processDifferingEntities(const EntityMismatchByName& sourceMismatches, const EntityMismatchByName& targetMismatches);
Fingerprints collectEntityFingerprints(const scene::INodePtr& root);
std::list<ComparisonResult::KeyValueDifference> compareKeyValues(
const scene::INodePtr& sourceNode, const scene::INodePtr& targetNode);
};
}
}