Changeset 1048 for cpp/frams/model/similarity/similmeasure.cpp
 Timestamp:
 12/11/20 21:36:41 (2 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/model/similarity/similmeasure.cpp
r1045 r1048 5 5 #include "similmeasure.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/Komosinskietal2001\nhttp://www.framsticks.com/bib/KomosinskiandKubiak2011\nhttp://www.framsticks.com/bib/Komosinski2016\nhttps://doi.org/10.1007/9783030166922_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 }
Note: See TracChangeset
for help on using the changeset viewer.