source: cpp/frams/model/similarity/simil-measure.cpp @ 1048

Last change on this file since 1048 was 1048, checked in by Maciej Komosinski, 3 months ago

SimilMeasure? -> SimilMeasureBase?; introduced a new class (SimilMeasure?) that allows scripts to access all similarity measures; a number of minor fixes and improvements

File size: 1.9 KB
Line 
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
12static 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
21SimilMeasure::SimilMeasure() : localpar(simil_measure_paramtab, this)
22{
23        localpar.setDefault();
24}
25
26double 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
35void 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
Note: See TracBrowser for help on using the repository browser.