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 | { "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 | { "measure_type", 0, 0, "Type of similarity measure", "d 0 2 0 ~Greedy (flexible criteria order and optimal matching)~Hungarian (vertex degree order and greedy matching)~Distribution (EMD on a histogram of descriptor values)", FIELD(measure_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 | double SimilMeasure::evaluateDistance(const Geno* G0, const Geno* G1) |
---|

27 | { |
---|

28 | SimilMeasureBase *measures[] = { &simil_measure_greedy,&simil_measure_hungarian,&simil_measure_distribution }; |
---|

29 | if (measure_type >= 0 && measure_type <= 2) |
---|

30 | return measures[measure_type]->evaluateDistance(G0, G1); |
---|

31 | logPrintf("SimilarityMeasure", "evaluateDistance", LOG_ERROR, "Measure type '%d' not supported", measure_type); |
---|

32 | return -1; |
---|

33 | } |
---|

34 | |
---|

35 | void SimilMeasure::p_evaldistance(ExtValue *args, ExtValue *ret) |
---|

36 | { |
---|

37 | Geno *g1 = GenoObj::fromObject(args[1]); |
---|

38 | Geno *g2 = GenoObj::fromObject(args[0]); |
---|

39 | if ((!g1) || (!g2)) |
---|

40 | ret->setEmpty(); |
---|

41 | else |
---|

42 | ret->setDouble(evaluateDistance(g1, g2)); |
---|

43 | } |
---|

44 | |
---|