source: cpp/frams/genetics/fF/conv_fF.cpp @ 157

Last change on this file since 157 was 157, checked in by sz, 6 years ago

f9 and Ff converters can now detect an invalid input genotype and react appropriately

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include "conv_fF.h"
6#include "fF_genotype.h"
7#include <frams/model/model.h>
8#include <common/nonstd_stl.h>
9
10GenoConv_fF0::GenoConv_fF0()
11{
12        name = "7-value Foraminifera encoding";
13        in_format = 'F';
14        out_format = '0';
15        mapsupport = 0;
16}
17
18SString GenoConv_fF0::convert(SString &in, MultiMap *map)
19{
20        fF_growth_params gp;
21        if (!gp.load(in)) //invalid input genotype?
22                return ""; //so we return an invalid f0 genotype
23        Model m;
24        m.open();
25        // subsequent parts (chambers) are placed relative to the previous part's orientation and location
26        Part *p1, *p2;
27        p1 = m.addNewPart(Part::SHAPE_ELLIPSOID); //initial part
28        Pt3D scaling(gp.scalex, gp.scaley, gp.scalez);
29        p1->scale = scaling;
30
31        Orient rotation = Orient_1; //must be initialized explicitly because the default Orient constructor does not initialize anything
32        rotation.rotate(Pt3D(0, gp.angle1, gp.angle2)); //assumed rotation around x is 0, which is limiting if we use assymetrical shapes (i.e., not spheres). But the original model had only two angles...
33
34        for (int i = 1; i < gp.number_of_chambers; i++, p1 = p2)
35        {
36                p2 = m.addNewPart(Part::SHAPE_ELLIPSOID);
37                p2->scale = p1->scale.entrywiseProduct(scaling); //each part's scale is its predecessor's scale * scaling
38
39                p2->setOrient(p1->o.transform(rotation)); //rotation transformed by p1 orientation
40
41                // Part's tip (offset from the center) is the point at (scale.x,0,0) in part's local coordinates.
42                // Get the offset in global coordinates by transforming it by the part's orientation.
43                p2->p = p1->p
44                        + p1->o.transform(Pt3D(p1->scale.x*gp.translation,0,0))  // p1's tip transformed
45                        + p2->o.transform(Pt3D(p2->scale.x*gp.translation,0,0)); // p2's tip transformed
46
47                m.addNewJoint(p1, p2, Joint::SHAPE_SOLID); //all parts must be connected
48        }
49        m.close();
50        return m.getF0Geno().getGene();
51}
Note: See TracBrowser for help on using the repository browser.