Index: /cpp/frams/model/similarity/measure-distribution.h
===================================================================
--- /cpp/frams/model/similarity/measure-distribution.h	(revision 1047)
+++ /cpp/frams/model/similarity/measure-distribution.h	(revision 1048)
@@ -6,8 +6,8 @@
 #define DISTRIBUTION_MEASURE_H
 
-#include "simil-measure.h"
+#include "simil-measure-base.h"
 #include "EMD/emd.h"
 
-class SimilMeasureDistribution : public SimilMeasure
+class SimilMeasureDistribution : public SimilMeasureBase
 {
 public:
Index: /cpp/frams/model/similarity/measure-greedy.cpp
===================================================================
--- /cpp/frams/model/similarity/measure-greedy.cpp	(revision 1047)
+++ /cpp/frams/model/similarity/measure-greedy.cpp	(revision 1048)
@@ -4,9 +4,10 @@
 
 #include "measure-greedy.h"
+#include <assert.h>
 
 #define DB(x)  //define as x if you want to print debug information
 
 const int SimilMeasureGreedy::iNOFactors = 4;
-int fuzzDepth = 0; //TODO make local, but "fuzzy vertex degree" is not activated by default
+int fuzzDepth = 0; //TODO make local, but not crucial because currently "fuzzy vertex degree" is not activated by default
 
 #define FIELDSTRUCT SimilMeasureGreedy
@@ -20,5 +21,5 @@
 		{ "simil_fixedZaxis", 0, 0, "Fix 'z' (vertical) axis?", "d 0 1 0", FIELD(fixedZaxis), "", },
 		{ "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.", },
-		{ "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.", },
+		{ "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.", },
 		{ 0, },
 };
Index: /cpp/frams/model/similarity/measure-greedy.h
===================================================================
--- /cpp/frams/model/similarity/measure-greedy.h	(revision 1047)
+++ /cpp/frams/model/similarity/measure-greedy.h	(revision 1048)
@@ -10,5 +10,4 @@
 #include "frams/model/model.h"
 #include "simil-match.h"
-#include "measure-greedy.h"
 
 #define TDN_SIZE 5
Index: /cpp/frams/model/similarity/measure-hungarian.cpp
===================================================================
--- /cpp/frams/model/similarity/measure-hungarian.cpp	(revision 1047)
+++ /cpp/frams/model/similarity/measure-hungarian.cpp	(revision 1048)
@@ -10,5 +10,5 @@
 
 static ParamEntry simil_hungarian_paramtab[] = {
-		{ "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", },
+		{ "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", },
 		{ "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.", },
 		{ "simil_partdeg", 0, 0, "Weight of parts' degree", "f 0 100 1", FIELD(m_adFactors[1]), "", },
@@ -17,5 +17,5 @@
 		{ "simil_fixedZaxis", 0, 0, "Fix 'z' (vertical) axis?", "d 0 1 0", FIELD(fixedZaxis), "", },
 		{ "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.", },
-		{ "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.", },
+		{ "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.", },
 		{ 0, },
 };
Index: /cpp/frams/model/similarity/measure-mds-based.cpp
===================================================================
--- /cpp/frams/model/similarity/measure-mds-based.cpp	(revision 1047)
+++ /cpp/frams/model/similarity/measure-mds-based.cpp	(revision 1048)
@@ -5,4 +5,5 @@
 #include "measure-mds-based.h"
 #include "SVD/matrix_tools.h"
+#include <assert.h>
 
 SimilMeasureMDSBased::SimilMeasureMDSBased()
Index: /cpp/frams/model/similarity/measure-mds-based.h
===================================================================
--- /cpp/frams/model/similarity/measure-mds-based.h	(revision 1047)
+++ /cpp/frams/model/similarity/measure-mds-based.h	(revision 1048)
@@ -6,7 +6,7 @@
 #define _SIMIL_MEASURE_MDS_BASED_H
 
-#include "simil-measure.h"
+#include "simil-measure-base.h"
 
-class SimilMeasureMDSBased : public SimilMeasure
+class SimilMeasureMDSBased : public SimilMeasureBase
 {
 public:
Index: /cpp/frams/model/similarity/simil-measure-base.cpp
===================================================================
--- /cpp/frams/model/similarity/simil-measure-base.cpp	(revision 1048)
+++ /cpp/frams/model/similarity/simil-measure-base.cpp	(revision 1048)
@@ -0,0 +1,84 @@
+// This file is a part of Framsticks SDK.  http://www.framsticks.com/
+// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
+// See LICENSE.txt for details.
+
+#include "simil-measure-base.h"
+#include <frams/vm/classes/genoobj.h>
+#include <frams/model/geometry/meshbuilder.h>
+#include <frams/model/geometry/geometryutils.h>
+
+SimilMeasureBase::SimilMeasureBase()
+{
+	for (int i = 0; i < 2; i++)
+	{
+		genos[i] = nullptr;
+		models[i] = nullptr;
+	}
+}
+
+double SimilMeasureBase::evaluateDistance(const Geno* G0, const Geno* G1)
+{
+	genos[0] = G0;
+	genos[1] = G1;
+
+	// create models of objects to compare
+	models[0] = newModel(genos[0]);
+	models[1] = newModel(genos[1]);
+
+	if (models[0] == NULL || models[1] == NULL)
+	{
+		logPrintf("SimilarityMeasure", "EvaluateDistance", LOG_ERROR, "Unable to create model from one of the genotypes.");
+		return -1;
+	}
+	
+	double distance = getDistance();
+	SAFEDELETE(models[0]);
+	SAFEDELETE(models[1]);
+	return distance;
+}
+
+void SimilMeasureBase::p_evaldistance(ExtValue * args, ExtValue * ret)
+{
+	Geno * g1 = GenoObj::fromObject(args[1]);
+	Geno * g2 = GenoObj::fromObject(args[0]);
+	if ((!g1) || (!g2))
+		ret->setEmpty();
+	else
+		ret->setDouble(evaluateDistance(g1, g2));
+}
+
+Model* SimilMeasureBase::newModel(const Geno *g)
+{
+	if (g == NULL)
+	{
+		logPrintf("SimilarityMeasure", "newModel", LOG_ERROR, "NULL genotype pointer");
+		return NULL;
+	}
+	Model *m = new Model(*g, ModelEnum::SHAPETYPE_UNKNOWN);
+	if (!m->isValid())
+	{
+		logPrintf("SimilarityMeasure", "newModel", LOG_ERROR, "Invalid model for the genotype of '%s'", g->getName().c_str());
+		delete m;
+		return NULL;
+	}
+	return m;
+}
+
+Model SimilMeasureBase::sampleSurface(Model* M, double density)
+{
+    Model resultModel;
+    resultModel.open();
+    GeometryUtils::addAnchorToModel(resultModel);
+
+    MeshBuilder::ModelSurface iterator(density);
+    iterator.initialize(M);
+
+    Pt3D point;
+    while (iterator.tryGetNext(point))
+    {
+        GeometryUtils::addPointToModel(point, resultModel);
+    }
+
+    resultModel.close();
+    return resultModel;
+}
Index: /cpp/frams/model/similarity/simil-measure-base.h
===================================================================
--- /cpp/frams/model/similarity/simil-measure-base.h	(revision 1048)
+++ /cpp/frams/model/similarity/simil-measure-base.h	(revision 1048)
@@ -0,0 +1,34 @@
+// This file is a part of Framsticks SDK.  http://www.framsticks.com/
+// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
+// See LICENSE.txt for details.
+
+#ifndef _SIMIL_MEASURE_BASE_H
+#define _SIMIL_MEASURE_BASE_H
+
+#include "frams/genetics/geno.h"
+#include "frams/model/model.h"
+
+class SimilMeasureBase
+{
+public:
+	SimilMeasureBase();
+	virtual ~SimilMeasureBase() {};
+
+	virtual double getDistance() = 0;
+	double evaluateDistance(const Geno *G0, const Geno *G1);
+	virtual int setParams(std::vector<double> params) = 0;
+    Model sampleSurface(Model *M, double density);
+
+#define STATRICKCLASS SimilMeasureBase
+	PARAMPROCDEF(p_evaldistance);
+#undef STATRICKCLASS 
+
+protected:
+	/// Genotypes between which distance is evaluated.
+	const Geno *genos[2];
+	/// Models created from the genotypes array
+	Model *models[2];
+	Model* newModel(const Geno *g);
+};
+
+#endif
Index: /cpp/frams/model/similarity/simil-measure.cpp
===================================================================
--- /cpp/frams/model/similarity/simil-measure.cpp	(revision 1047)
+++ /cpp/frams/model/similarity/simil-measure.cpp	(revision 1048)
@@ -5,13 +5,13 @@
 #include "simil-measure.h"
 #include <frams/vm/classes/genoobj.h>
-#include <frams/model/geometry/geometryutils.h>
 #include <frams/model/geometry/meshbuilder.h>
+#include <frams/_demos/geometry/geometrytestutils.h>
 
 #define FIELDSTRUCT SimilMeasure
 
 static ParamEntry simil_measure_paramtab[] = {
-	{ "Similarity", 1, 2, "SimilMeasure", "Evaluates morphological dissimilarity.", },
-	{ "measure_type", 0, 0, "Type of similarity measure", "d 1 3 1", FIELD(measure_type), "", },
-	{ "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.", },
+	{ "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", },
+	{ "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), "", },
+	{ "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.", },
 	{ 0, },
 };
@@ -21,9 +21,4 @@
 SimilMeasure::SimilMeasure() : localpar(simil_measure_paramtab, this)
 {
-	for (int i = 0; i < 2; i++)
-	{
-		genos[i] = nullptr;
-		models[i] = nullptr;
-	}
 	localpar.setDefault();
 }
@@ -31,38 +26,9 @@
 double SimilMeasure::evaluateDistance(const Geno* G0, const Geno* G1)
 {
-	genos[0] = G0;
-	genos[1] = G1;
-
-	// create models of objects to compare
-	models[0] = newModel(genos[0]);
-	models[1] = newModel(genos[1]);
-
-	if (models[0] == NULL || models[1] == NULL)
-	{
-		logPrintf("SimilarityMeasure", "EvaluateDistance", LOG_ERROR, "Unable to create model from one of the genotypes.");
-		return -1;
-	}
-	
-	double distance = getDistance();
-	SAFEDELETE(models[0]);
-	SAFEDELETE(models[1]);
-	return distance;
-}
-
-Model* SimilMeasure::newModel(const Geno *g)
-{
-	if (g == NULL)
-	{
-		logPrintf("SimilarityMeasure", "newModel", LOG_ERROR, "NULL genotype pointer");
-		return NULL;
-	}
-	Model *m = new Model(*g, ModelEnum::SHAPETYPE_UNKNOWN);
-	if (!m->isValid())
-	{
-		logPrintf("SimilarityMeasure", "newModel", LOG_ERROR, "Invalid model for the genotype of '%s'", g->getName().c_str());
-		delete m;
-		return NULL;
-	}
-	return m;
+	SimilMeasureBase *measures[] = { &simil_measure_greedy,&simil_measure_hungarian,&simil_measure_distribution };
+	if (measure_type >= 0 && measure_type <= 2)
+		return measures[measure_type]->evaluateDistance(G0, G1);
+	logPrintf("SimilarityMeasure", "evaluateDistance", LOG_ERROR, "Measure type '%d' not supported", measure_type);
+	return -1;
 }
 
@@ -77,20 +43,2 @@
 }
 
-Model SimilMeasure::sampleSurface(Model* M, double density)
-{
-    Model resultModel;
-    resultModel.open();
-    GeometryUtils::addAnchorToModel(resultModel);
-
-    MeshBuilder::ModelSurface iterator(density);
-    iterator.initialize(M);
-
-    Pt3D point;
-    while (iterator.tryGetNext(point))
-    {
-        GeometryUtils::addPointToModel(point, resultModel);
-    }
-
-    resultModel.close();
-    return resultModel;
-}
Index: /cpp/frams/model/similarity/simil-measure.h
===================================================================
--- /cpp/frams/model/similarity/simil-measure.h	(revision 1047)
+++ /cpp/frams/model/similarity/simil-measure.h	(revision 1048)
@@ -6,34 +6,28 @@
 #define _SIMIL_MEASURE_H
 
-#include "frams/genetics/geno.h"
-#include "frams/model/model.h"
-#include <assert.h>
+#include "frams/model/similarity/measure-greedy.h"
+#include "frams/model/similarity/measure-hungarian.h"
+#include "frams/model/similarity/measure-distribution.h"
 
 class SimilMeasure
 {
 public:
-	SimilMeasure();
 	int measure_type;
+
+	SimilMeasureGreedy simil_measure_greedy;
+	SimilMeasureHungarian simil_measure_hungarian;
+	SimilMeasureDistribution simil_measure_distribution;
+
 	/// Interface to local parameters
 	Param localpar;
 
-	virtual ~SimilMeasure(){};
-	virtual double getDistance() = 0;
+	SimilMeasure();
+	virtual ~SimilMeasure() {};
 	double evaluateDistance(const Geno *G0, const Geno *G1);
-	virtual int setParams(std::vector<double> params) = 0;
-    Model sampleSurface(Model *M, double density);
 
 	#define STATRICKCLASS SimilMeasure
 	PARAMPROCDEF(p_evaldistance);
 	#undef STATRICKCLASS
-
-protected:
-	/// Genotypes between which distance is evaluated.
-	const Geno *genos[2];
-	/// Models created from the genotypes array
-	Model *models[2];
-	Model* newModel(const Geno *g);
 };
 
 #endif
-
