Ignore:
Timestamp:
12/11/20 21:36:41 (3 months ago)
Author:
Maciej Komosinski
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/similarity/simil-measure.cpp

    r1045 r1048  
    55#include "simil-measure.h"
    66#include <frams/vm/classes/genoobj.h>
    7 #include <frams/model/geometry/geometryutils.h>
    87#include <frams/model/geometry/meshbuilder.h>
     8#include <frams/_demos/geometry/geometrytestutils.h>
    99
    1010#define FIELDSTRUCT SimilMeasure
    1111
    1212static ParamEntry simil_measure_paramtab[] = {
    13         { "Similarity", 1, 2, "SimilMeasure", "Evaluates morphological dissimilarity.", },
    14         { "measure_type", 0, 0, "Type of similarity measure", "d 1 3 1", 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.", },
     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.", },
    1616        { 0, },
    1717};
     
    2121SimilMeasure::SimilMeasure() : localpar(simil_measure_paramtab, this)
    2222{
    23         for (int i = 0; i < 2; i++)
    24         {
    25                 genos[i] = nullptr;
    26                 models[i] = nullptr;
    27         }
    2823        localpar.setDefault();
    2924}
     
    3126double SimilMeasure::evaluateDistance(const Geno* G0, const Geno* G1)
    3227{
    33         genos[0] = G0;
    34         genos[1] = G1;
    35 
    36         // create models of objects to compare
    37         models[0] = newModel(genos[0]);
    38         models[1] = newModel(genos[1]);
    39 
    40         if (models[0] == NULL || models[1] == NULL)
    41         {
    42                 logPrintf("SimilarityMeasure", "EvaluateDistance", LOG_ERROR, "Unable to create model from one of the genotypes.");
    43                 return -1;
    44         }
    45        
    46         double distance = getDistance();
    47         SAFEDELETE(models[0]);
    48         SAFEDELETE(models[1]);
    49         return distance;
    50 }
    51 
    52 Model* SimilMeasure::newModel(const Geno *g)
    53 {
    54         if (g == NULL)
    55         {
    56                 logPrintf("SimilarityMeasure", "newModel", LOG_ERROR, "NULL genotype pointer");
    57                 return NULL;
    58         }
    59         Model *m = new Model(*g, ModelEnum::SHAPETYPE_UNKNOWN);
    60         if (!m->isValid())
    61         {
    62                 logPrintf("SimilarityMeasure", "newModel", LOG_ERROR, "Invalid model for the genotype of '%s'", g->getName().c_str());
    63                 delete m;
    64                 return NULL;
    65         }
    66         return m;
     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;
    6733}
    6834
     
    7743}
    7844
    79 Model SimilMeasure::sampleSurface(Model* M, double density)
    80 {
    81     Model resultModel;
    82     resultModel.open();
    83     GeometryUtils::addAnchorToModel(resultModel);
    84 
    85     MeshBuilder::ModelSurface iterator(density);
    86     iterator.initialize(M);
    87 
    88     Pt3D point;
    89     while (iterator.tryGetNext(point))
    90     {
    91         GeometryUtils::addPointToModel(point, resultModel);
    92     }
    93 
    94     resultModel.close();
    95     return resultModel;
    96 }
Note: See TracChangeset for help on using the changeset viewer.