1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #include "simil-measure.h" |
---|
6 | #include <frams/vm/classes/genoobj.h> |
---|
7 | #include <frams/model/geometry/meshbuilder.h> |
---|
8 | #include <frams/_demos/geometry/geometrytestutils.h> |
---|
9 | |
---|
10 | #define FIELDSTRUCT SimilMeasure |
---|
11 | |
---|
12 | static ParamEntry simil_measure_paramtab[] = { |
---|
13 | { "Creature: Similarity", 1, 2, "SimilMeasure", "Evaluates morphological dissimilarity. More information:\nhttp://www.framsticks.com/bib/Komosinski-et-al-2001\nhttp://www.framsticks.com/bib/Komosinski-and-Kubiak-2011\nhttp://www.framsticks.com/bib/Komosinski-2016\nhttps://doi.org/10.1007/978-3-030-16692-2_8", }, |
---|
14 | { "simil_type", 0, 0, "Type of similarity measure", "d 0 2 1 ~Graph greedy (vertex degree order and greedy matching)~Graph optimal (flexible criteria order and optimal matching)~Descriptor distribution (EMD on a histogram of descriptor values)", FIELD(type), "", }, |
---|
15 | { "evaluateDistance", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "Evaluate model dissimilarity", "p f(oGeno,oGeno)", PROCEDURE(p_evaldistance), "Calculates dissimilarity between two models created from Geno objects.", }, |
---|
16 | { 0, }, |
---|
17 | }; |
---|
18 | |
---|
19 | #undef FIELDSTRUCT |
---|
20 | |
---|
21 | SimilMeasure::SimilMeasure() : localpar(simil_measure_paramtab, this) |
---|
22 | { |
---|
23 | localpar.setDefault(); |
---|
24 | } |
---|
25 | |
---|
26 | SimilMeasureBase *SimilMeasure::currentMeasure() |
---|
27 | { |
---|
28 | SimilMeasureBase *measures[] = { &simil_measure_greedy,&simil_measure_hungarian,&simil_measure_distribution }; |
---|
29 | if (type >= 0 && type <= (int)std::size(measures)) |
---|
30 | return measures[type]; |
---|
31 | logPrintf("SimilarityMeasure", "currentMeasure", LOG_ERROR, "Measure type '%d' not supported", type); |
---|
32 | return nullptr; |
---|
33 | } |
---|
34 | |
---|
35 | double SimilMeasure::evaluateDistance(const Geno* G0, const Geno* G1) |
---|
36 | { |
---|
37 | SimilMeasureBase *measure = currentMeasure(); |
---|
38 | if (measure) |
---|
39 | return measure->evaluateDistance(G0, G1); |
---|
40 | return -1; |
---|
41 | } |
---|
42 | |
---|
43 | void SimilMeasure::p_evaldistance(ExtValue *args, ExtValue *ret) |
---|
44 | { |
---|
45 | Geno *g1 = GenoObj::fromObject(args[1]); |
---|
46 | Geno *g2 = GenoObj::fromObject(args[0]); |
---|
47 | if ((!g1) || (!g2)) |
---|
48 | ret->setEmpty(); |
---|
49 | else |
---|
50 | ret->setDouble(evaluateDistance(g1, g2)); |
---|
51 | } |
---|
52 | |
---|