Changeset 1048 for cpp/frams/model/similarity
- Timestamp:
- 12/11/20 21:36:41 (4 years ago)
- Location:
- cpp/frams/model/similarity
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/model/similarity/measure-distribution.h
r1044 r1048 6 6 #define DISTRIBUTION_MEASURE_H 7 7 8 #include "simil-measure .h"8 #include "simil-measure-base.h" 9 9 #include "EMD/emd.h" 10 10 11 class SimilMeasureDistribution : public SimilMeasure 11 class SimilMeasureDistribution : public SimilMeasureBase 12 12 { 13 13 public: -
cpp/frams/model/similarity/measure-greedy.cpp
r1044 r1048 4 4 5 5 #include "measure-greedy.h" 6 #include <assert.h> 6 7 7 8 #define DB(x) //define as x if you want to print debug information 8 9 9 10 const int SimilMeasureGreedy::iNOFactors = 4; 10 int fuzzDepth = 0; //TODO make local, but "fuzzy vertex degree" is not activated by default11 int fuzzDepth = 0; //TODO make local, but not crucial because currently "fuzzy vertex degree" is not activated by default 11 12 12 13 #define FIELDSTRUCT SimilMeasureGreedy … … 20 21 { "simil_fixedZaxis", 0, 0, "Fix 'z' (vertical) axis?", "d 0 1 0", FIELD(fixedZaxis), "", }, 21 22 { "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.", }, 23 24 { 0, }, 24 25 }; -
cpp/frams/model/similarity/measure-greedy.h
r1044 r1048 10 10 #include "frams/model/model.h" 11 11 #include "simil-match.h" 12 #include "measure-greedy.h"13 12 14 13 #define TDN_SIZE 5 -
cpp/frams/model/similarity/measure-hungarian.cpp
r1044 r1048 10 10 11 11 static 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", }, 13 13 { "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.", }, 14 14 { "simil_partdeg", 0, 0, "Weight of parts' degree", "f 0 100 1", FIELD(m_adFactors[1]), "", }, … … 17 17 { "simil_fixedZaxis", 0, 0, "Fix 'z' (vertical) axis?", "d 0 1 0", FIELD(fixedZaxis), "", }, 18 18 { "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.", }, 20 20 { 0, }, 21 21 }; -
cpp/frams/model/similarity/measure-mds-based.cpp
r1044 r1048 5 5 #include "measure-mds-based.h" 6 6 #include "SVD/matrix_tools.h" 7 #include <assert.h> 7 8 8 9 SimilMeasureMDSBased::SimilMeasureMDSBased() -
cpp/frams/model/similarity/measure-mds-based.h
r1044 r1048 6 6 #define _SIMIL_MEASURE_MDS_BASED_H 7 7 8 #include "simil-measure .h"8 #include "simil-measure-base.h" 9 9 10 class SimilMeasureMDSBased : public SimilMeasure 10 class SimilMeasureMDSBased : public SimilMeasureBase 11 11 { 12 12 public: -
cpp/frams/model/similarity/simil-measure.cpp
r1045 r1048 5 5 #include "simil-measure.h" 6 6 #include <frams/vm/classes/genoobj.h> 7 #include <frams/model/geometry/geometryutils.h>8 7 #include <frams/model/geometry/meshbuilder.h> 8 #include <frams/_demos/geometry/geometrytestutils.h> 9 9 10 10 #define FIELDSTRUCT SimilMeasure 11 11 12 12 static 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.", }, 16 16 { 0, }, 17 17 }; … … 21 21 SimilMeasure::SimilMeasure() : localpar(simil_measure_paramtab, this) 22 22 { 23 for (int i = 0; i < 2; i++)24 {25 genos[i] = nullptr;26 models[i] = nullptr;27 }28 23 localpar.setDefault(); 29 24 } … … 31 26 double SimilMeasure::evaluateDistance(const Geno* G0, const Geno* G1) 32 27 { 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; 67 33 } 68 34 … … 77 43 } 78 44 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 6 6 #define _SIMIL_MEASURE_H 7 7 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" 11 11 12 12 class SimilMeasure 13 13 { 14 14 public: 15 SimilMeasure();16 15 int measure_type; 16 17 SimilMeasureGreedy simil_measure_greedy; 18 SimilMeasureHungarian simil_measure_hungarian; 19 SimilMeasureDistribution simil_measure_distribution; 20 17 21 /// Interface to local parameters 18 22 Param localpar; 19 23 20 virtual ~SimilMeasure(){};21 virtual double getDistance() = 0;24 SimilMeasure(); 25 virtual ~SimilMeasure() {}; 22 26 double evaluateDistance(const Geno *G0, const Geno *G1); 23 virtual int setParams(std::vector<double> params) = 0;24 Model sampleSurface(Model *M, double density);25 27 26 28 #define STATRICKCLASS SimilMeasure 27 29 PARAMPROCDEF(p_evaldistance); 28 30 #undef STATRICKCLASS 29 30 protected:31 /// Genotypes between which distance is evaluated.32 const Geno *genos[2];33 /// Models created from the genotypes array34 Model *models[2];35 Model* newModel(const Geno *g);36 31 }; 37 32 38 33 #endif 39
Note: See TracChangeset
for help on using the changeset viewer.