Changeset 178 for cpp/frams/genetics/fF


Ignore:
Timestamp:
03/17/14 00:57:50 (10 years ago)
Author:
Maciej Komosinski
Message:

Changed cryptic double[4] into a meaningful struct

Location:
cpp/frams/genetics/fF
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fF/conv_fF.cpp

    r177 r178  
    1616        cosines = new double[fF_LATITUDE_NUM];
    1717        sines = new double[fF_LATITUDE_NUM];
    18         fill_cos_and_sin();
     18        precompute_cos_and_sin();
    1919}
    2020
     
    159159                pun = find_hole(which, pzx, pzy, pzz, chambers, kx_, ky_, kz_);
    160160
    161                 chambers[which]->holeX = (float)chambers[which]->points[pun][0];
    162                 chambers[which]->holeY = (float)chambers[which]->points[pun][1];
    163                 chambers[which]->holeZ = (float)chambers[which]->points[pun][2];
    164         }
    165 }
    166 
    167 void GenoConv_fF0::fill_cos_and_sin()
     161                chambers[which]->holeX = (float)chambers[which]->points[pun].x;
     162                chambers[which]->holeY = (float)chambers[which]->points[pun].y;
     163                chambers[which]->holeZ = (float)chambers[which]->points[pun].z;
     164        }
     165}
     166
     167void GenoConv_fF0::precompute_cos_and_sin()
    168168{
    169169        int i;
     
    177177}
    178178
    179 double** GenoConv_fF0::generate_points(fF_chamber3d *chamber, int which, double kx_, double ky_, double kz_)
     179fF_point* GenoConv_fF0::generate_points(fF_chamber3d *chamber, int which, double kx_, double ky_, double kz_)
    180180{
    181181        float radius = chamber->radius;
     
    210210        double rz = all_k_ones ? radius : kz;
    211211
    212         double **points = new double*[fF_SIZE];
    213         for (int i = 0; i < fF_SIZE; i++)
    214         {
    215                 points[i] = new double[4];
    216         }
     212        fF_point *points = new fF_point[fF_SIZE];
    217213
    218214        for (int i = 0; i < fF_LONGITUDE_NUM; i++)
     
    224220                        double x = cenx + rx * cosines[j] * sines[i];
    225221                        double z = cenz + rz * sines[j] * sines[i];
    226                         double *p = points[(i * fF_LATITUDE_NUM) + j];
    227                         p[0] = x;
    228                         p[1] = y;
    229                         p[2] = z;
    230                         p[3] = 1.0;
     222                        fF_point &p = points[(i * fF_LATITUDE_NUM) + j];
     223                        p.x = x;
     224                        p.y = y;
     225                        p.z = z;
     226                        p.inside = false;
    231227
    232228                        if (x < minX) minX = x;
     
    267263                for (int j = 0; j < fF_AMOUNT; j++)
    268264                {
    269                         double *p = spheres[nr]->points[j];
    270                         double X = p[0];
    271                         double Y = p[1];
    272                         double Z = p[2];
    273 
    274                         double up1 = (X - srX0) * (X - srX0);
    275                         double up2 = (Y - srY0) * (Y - srY0);
    276                         double up3 = (Z - srZ0) * (Z - srZ0);
     265                        fF_point &p = spheres[nr]->points[j];
     266
     267                        double up1 = (p.x - srX0) * (p.x - srX0);
     268                        double up2 = (p.y - srY0) * (p.y - srY0);
     269                        double up3 = (p.z - srZ0) * (p.z - srZ0);
    277270
    278271                        double exp1 = up1 / a2;
     
    284277                        if (result < fF_THICK_RATIO)
    285278                        {
    286                                 p[3] = 0.0;
     279                                p.inside = true;
    287280                        }
    288281                }
     
    301294        for (int i = 0; i < fF_AMOUNT; i++)
    302295        {
    303                 double *p = chambers[which]->points[i];
    304                 if (p[3] != 0) //it is not inside another chamber
    305                 {
    306                         double distancesq = (p[0] - x)*(p[0] - x) + (p[1] - y)*(p[1] - y) + (p[2] - z)*(p[2] - z);
     296                fF_point &p = chambers[which]->points[i];
     297                if (!p.inside) //it is not inside another chamber
     298                {
     299                        double distancesq = (p.x - x)*(p.x - x) + (p.y - y)*(p.y - y) + (p.z - z)*(p.z - z);
    307300                        if (found < 0)
    308301                        {
     
    314307                                if (which != 0)
    315308                                {
    316                                         double X = p[0];
    317                                         double Y = p[1];
    318                                         double Z = p[2];
    319309                                        bool good = true;
    320310                                        for (int j = 0; j < which && good; j++)
     
    330320                                                double c2 = kzsq * radsq;
    331321
    332                                                 double up1 = (X - srX0) * (X - srX0);
    333                                                 double up2 = (Y - srY0) * (Y - srY0);
    334                                                 double up3 = (Z - srZ0) * (Z - srZ0);
     322                                                double up1 = (p.x - srX0) * (p.x - srX0);
     323                                                double up2 = (p.y - srY0) * (p.y - srY0);
     324                                                double up3 = (p.z - srZ0) * (p.z - srZ0);
    335325
    336326                                                double exp1 = up1 / a2;
  • cpp/frams/genetics/fF/conv_fF.h

    r176 r178  
    2424#include "fF_chamber3d.h"
    2525
     26
     27//A point on the surface of a chamber
     28struct fF_point
     29{
     30        double x, y, z;
     31        bool inside; //helper field used when computing whether this point is inside some chamber
     32};
     33
     34
    2635// The f9->f0 converter
    2736class GenoConv_fF0 : public GenoConverter {
     
    3342
    3443protected:
    35         double* cosines;
    36         double* sines;
    3744        void createSphere(int ktora, fF_chamber3d **chambers, double radius, double div_radius_length, double div_vector_length,
    3845                double alpha, double gamma, double kx, double ky, double kz);
    39         double** generate_points(fF_chamber3d *chamber, int which, double kx, double ky, double kz);
    40         void fill_cos_and_sin();
     46        fF_point* generate_points(fF_chamber3d *chamber, int which, double kx, double ky, double kz);
    4147        double dist(double x1, double y1, double z1, double x2, double y2, double z2);
    4248        void search_hid(int nr, fF_chamber3d **spheres, double kx_, double ky_, double kz_);
    4349        int find_hole(int which, double x, double y, double z, fF_chamber3d **chambers, double kx_, double ky_, double kz_);
     50
     51private:
     52        double* cosines;
     53        double* sines;
     54        void precompute_cos_and_sin();
    4455};
    4556
  • cpp/frams/genetics/fF/fF_chamber3d.cpp

    r176 r178  
    99fF_chamber3d::~fF_chamber3d()
    1010{
    11         for (int i = 0; i < fF_SIZE; i++)
    12                 delete[] points[i];
    1311        delete[] points;
    1412}
  • cpp/frams/genetics/fF/fF_chamber3d.h

    r176 r178  
    55#ifndef CHAMBER3D_H
    66#define CHAMBER3D_H
     7
     8struct fF_point;
    79
    810//Chamber parameters; see http://www.framsticks.com/foraminifera
     
    2224        float beta;
    2325        float phi;
    24         double **points;
     26        fF_point *points;
    2527
    2628        ~fF_chamber3d();
Note: See TracChangeset for help on using the changeset viewer.