Ignore:
Timestamp:
12/11/20 21:36:41 (4 years 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

Location:
cpp/frams/model/similarity
Files:
2 added
8 edited

Legend:

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

    r1044 r1048  
    66#define DISTRIBUTION_MEASURE_H
    77
    8 #include "simil-measure.h"
     8#include "simil-measure-base.h"
    99#include "EMD/emd.h"
    1010
    11 class SimilMeasureDistribution : public SimilMeasure
     11class SimilMeasureDistribution : public SimilMeasureBase
    1212{
    1313public:
  • cpp/frams/model/similarity/measure-greedy.cpp

    r1044 r1048  
    44
    55#include "measure-greedy.h"
     6#include <assert.h>
    67
    78#define DB(x)  //define as x if you want to print debug information
    89
    910const int SimilMeasureGreedy::iNOFactors = 4;
    10 int fuzzDepth = 0; //TODO make local, but "fuzzy vertex degree" is not activated by default
     11int fuzzDepth = 0; //TODO make local, but not crucial because currently "fuzzy vertex degree" is not activated by default
    1112
    1213#define FIELDSTRUCT SimilMeasureGreedy
     
    2021                { "simil_fixedZaxis", 0, 0, "Fix 'z' (vertical) axis?", "d 0 1 0", FIELD(fixedZaxis), "", },
    2122                { "simil_weightedMDS", 0, 0, "Should weighted MDS be used?", "d 0 1 0", FIELD(wMDS), "If activated, weighted MDS with vertex (i.e., Part) degrees as weights is used for 3D alignment of body structure.", },
    22                 { "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.", },
     23                { "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.", },
    2324                { 0, },
    2425};
  • cpp/frams/model/similarity/measure-greedy.h

    r1044 r1048  
    1010#include "frams/model/model.h"
    1111#include "simil-match.h"
    12 #include "measure-greedy.h"
    1312
    1413#define TDN_SIZE 5
  • cpp/frams/model/similarity/measure-hungarian.cpp

    r1044 r1048  
    1010
    1111static ParamEntry simil_hungarian_paramtab[] = {
    12                 { "Similarity: hungarian", 1, 7, "similHungarianMeasure", "Evaluates morphological dissimilarity using hungarian measure. 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", },
     12                { "Similarity: hungarian", 1, 7, "SimilMeasureHungarian", "Evaluates morphological dissimilarity using hungarian measure. 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", },
    1313                { "simil_parts", 0, 0, "Weight of parts count", "f 0 100 0", FIELD(m_adFactors[0]), "Differing number of parts is also handled by the 'part degree' similarity component.", },
    1414                { "simil_partdeg", 0, 0, "Weight of parts' degree", "f 0 100 1", FIELD(m_adFactors[1]), "", },
     
    1717                { "simil_fixedZaxis", 0, 0, "Fix 'z' (vertical) axis?", "d 0 1 0", FIELD(fixedZaxis), "", },
    1818                { "simil_weightedMDS", 0, 0, "Should weighted MDS be used?", "d 0 1 0", FIELD(wMDS), "If activated, weighted MDS with vertex (i.e., Part) degrees as weights is used for 3D alignment of body structure.", },
    19                 { "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.", },
     19                { "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.", },
    2020                { 0, },
    2121};
  • cpp/frams/model/similarity/measure-mds-based.cpp

    r1044 r1048  
    55#include "measure-mds-based.h"
    66#include "SVD/matrix_tools.h"
     7#include <assert.h>
    78
    89SimilMeasureMDSBased::SimilMeasureMDSBased()
  • cpp/frams/model/similarity/measure-mds-based.h

    r1044 r1048  
    66#define _SIMIL_MEASURE_MDS_BASED_H
    77
    8 #include "simil-measure.h"
     8#include "simil-measure-base.h"
    99
    10 class SimilMeasureMDSBased : public SimilMeasure
     10class SimilMeasureMDSBased : public SimilMeasureBase
    1111{
    1212public:
  • 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 }
  • cpp/frams/model/similarity/simil-measure.h

    r1044 r1048  
    66#define _SIMIL_MEASURE_H
    77
    8 #include "frams/genetics/geno.h"
    9 #include "frams/model/model.h"
    10 #include <assert.h>
     8#include "frams/model/similarity/measure-greedy.h"
     9#include "frams/model/similarity/measure-hungarian.h"
     10#include "frams/model/similarity/measure-distribution.h"
    1111
    1212class SimilMeasure
    1313{
    1414public:
    15         SimilMeasure();
    1615        int measure_type;
     16
     17        SimilMeasureGreedy simil_measure_greedy;
     18        SimilMeasureHungarian simil_measure_hungarian;
     19        SimilMeasureDistribution simil_measure_distribution;
     20
    1721        /// Interface to local parameters
    1822        Param localpar;
    1923
    20         virtual ~SimilMeasure(){};
    21         virtual double getDistance() = 0;
     24        SimilMeasure();
     25        virtual ~SimilMeasure() {};
    2226        double evaluateDistance(const Geno *G0, const Geno *G1);
    23         virtual int setParams(std::vector<double> params) = 0;
    24     Model sampleSurface(Model *M, double density);
    2527
    2628        #define STATRICKCLASS SimilMeasure
    2729        PARAMPROCDEF(p_evaldistance);
    2830        #undef STATRICKCLASS
    29 
    30 protected:
    31         /// Genotypes between which distance is evaluated.
    32         const Geno *genos[2];
    33         /// Models created from the genotypes array
    34         Model *models[2];
    35         Model* newModel(const Geno *g);
    3631};
    3732
    3833#endif
    39 
Note: See TracChangeset for help on using the changeset viewer.