/
GraphComparer.h
68 lines (51 loc) · 2.04 KB
/
GraphComparer.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
#pragma once
#include <string>
#include <list>
#include <map>
#include <memory>
#include "inode.h"
#include "imap.h"
#include "itextstream.h"
#include "ComparisonResult.h"
namespace scene
{
namespace merge
{
/**
* Static utility class to compare two scenes given by their root nodes.
* The Source is considered to be the "newer" graph with the changes,
* the Base resembles the "older" or unchanged graph the Source graph is based on.
*/
class GraphComparer
{
private:
using Fingerprints = std::map<std::string, INodePtr>;
public:
struct EntityMismatch
{
std::string fingerPrint;
INodePtr node;
std::string entityName;
};
using EntityMismatchByName = std::map<std::string, EntityMismatch>;
public:
// Compares the two graphs and returns the result
static ComparisonResult::Ptr Compare(const IMapRootNodePtr& source, const IMapRootNodePtr& base);
private:
static void processDifferingEntities(ComparisonResult& result, const EntityMismatchByName& sourceMismatches,
const EntityMismatchByName& baseMismatches);
static Fingerprints collectEntityFingerprints(const INodePtr& root);
static Fingerprints collectPrimitiveFingerprints(const INodePtr& parent);
static Fingerprints collectNodeFingerprints(const INodePtr& parent,
const std::function<bool(const INodePtr& node)>& nodePredicate);
static std::list<ComparisonResult::KeyValueDifference> compareKeyValues(
const INodePtr& sourceNode, const INodePtr& baseNode);
static std::list<ComparisonResult::PrimitiveDifference> compareChildNodes(
const INodePtr& sourceNode, const INodePtr& baseNode);
static void compareSelectionGroups(ComparisonResult& result);
static void compareSelectionGroups(ComparisonResult& result, const INodePtr& sourceNode, const INodePtr& baseNode);
static void compareSelectionGroupsOfPrimitives(ComparisonResult& result, const INodePtr& sourceNode, const INodePtr& baseNode);
static std::string calculateGroupFingerprint(const selection::ISelectionGroupPtr& group);
};
}
}