source: cpp/frams/model/similarity/simil-measure-base.cpp @ 1277

Last change on this file since 1277 was 1173, checked in by Maciej Komosinski, 3 years ago

Fixed the descriptor distribution similarity measure: we don't want the Geometry's dummy "anchor" Part to be considered in similarity estimation

File size: 2.1 KB
RevLine 
[1048]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[1173]2// Copyright (C) 1999-2022  Maciej Komosinski and Szymon Ulatowski.
[1048]3// See LICENSE.txt for details.
4
5#include "simil-measure-base.h"
6#include <frams/vm/classes/genoobj.h>
7#include <frams/model/geometry/meshbuilder.h>
8#include <frams/model/geometry/geometryutils.h>
9
10SimilMeasureBase::SimilMeasureBase()
11{
12        for (int i = 0; i < 2; i++)
13        {
14                genos[i] = nullptr;
15                models[i] = nullptr;
16        }
17}
18
19double SimilMeasureBase::evaluateDistance(const Geno* G0, const Geno* G1)
20{
21        genos[0] = G0;
22        genos[1] = G1;
23
24        // create models of objects to compare
25        models[0] = newModel(genos[0]);
26        models[1] = newModel(genos[1]);
27
[1065]28        if (models[0] == NULL)
29                logPrintf("SimilMeasureBase", "evaluateDistance", LOG_ERROR, "Unable to create a Model from genotype '%s'.", G0->getGenes().c_str());
30        if (models[1] == NULL)
31                logPrintf("SimilMeasureBase", "evaluateDistance", LOG_ERROR, "Unable to create a Model from genotype '%s'.", G1->getGenes().c_str());
[1048]32        if (models[0] == NULL || models[1] == NULL)
33                return -1;
[1065]34
[1048]35        double distance = getDistance();
36        SAFEDELETE(models[0]);
37        SAFEDELETE(models[1]);
38        return distance;
39}
40
41void SimilMeasureBase::p_evaldistance(ExtValue * args, ExtValue * ret)
42{
43        Geno * g1 = GenoObj::fromObject(args[1]);
44        Geno * g2 = GenoObj::fromObject(args[0]);
45        if ((!g1) || (!g2))
46                ret->setEmpty();
47        else
48                ret->setDouble(evaluateDistance(g1, g2));
49}
50
51Model* SimilMeasureBase::newModel(const Geno *g)
52{
53        if (g == NULL)
54        {
55                logPrintf("SimilarityMeasure", "newModel", LOG_ERROR, "NULL genotype pointer");
56                return NULL;
57        }
58        Model *m = new Model(*g, ModelEnum::SHAPETYPE_UNKNOWN);
59        if (!m->isValid())
60        {
61                logPrintf("SimilarityMeasure", "newModel", LOG_ERROR, "Invalid model for the genotype of '%s'", g->getName().c_str());
62                delete m;
63                return NULL;
64        }
65        return m;
66}
67
68Model SimilMeasureBase::sampleSurface(Model* M, double density)
69{
[1065]70        Model resultModel;
71        resultModel.open();
[1048]72
[1065]73        MeshBuilder::ModelSurface iterator(density);
74        iterator.initialize(M);
[1048]75
[1065]76        Pt3D point;
77        while (iterator.tryGetNext(point))
78        {
79                GeometryUtils::addPointToModel(point, resultModel);
80        }
[1048]81
[1065]82        resultModel.close();
83        return resultModel;
[1048]84}
Note: See TracBrowser for help on using the repository browser.