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

Last change on this file since 140 was 140, checked in by sz, 10 years ago

introducing the Foraminifera encoding (format 'F')

  • Property svn:eol-style set to native
File size: 1.9 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        gp.load(in);
22        Model m;
23        m.open();
24        // subsequent parts (chambers) are placed relative to the previous part's orientation and location
25        Part *p1, *p2;
26        p1 = m.addNewPart(Part::SHAPE_ELLIPSOID); //initial part
27        Pt3D scaling(gp.scalex, gp.scaley, gp.scalez);
28        p1->scale = scaling;
29
30        Orient rotation = Orient_1; //must be initialized explicitly because the default Orient constructor does not initialize anything
31        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...
32
33        for (int i = 0; i < gp.number_of_chambers; i++, p1 = p2)
34        {
35                p2 = m.addNewPart(Part::SHAPE_ELLIPSOID);
36                p2->scale = p1->scale.entrywiseProduct(scaling); //each part's scale is its predecessor's scale * scaling
37
38                p2->setOrient(p1->o.transform(rotation)); //rotation transformed by p1 orientation
39
40                // Part's tip (offset from the center) is the point at (scale.x,0,0) in part's local coordinates.
41                // Get the offset in global coordinates by transforming it by the part's orientation.
42                p2->p = p1->p
43                        + p1->o.transform(Pt3D(p1->scale.x*gp.translation,0,0))  // p1's tip transformed
44                        + p2->o.transform(Pt3D(p2->scale.x*gp.translation,0,0)); // p2's tip transformed
45
46                m.addNewJoint(p1, p2, Joint::SHAPE_SOLID); //all parts must be connected
47        }
48        m.close();
49        return m.getF0Geno().getGene();
50}
Note: See TracBrowser for help on using the repository browser.