Changeset 177
 Timestamp:
 03/15/14 22:59:10 (8 years ago)
 Location:
 cpp/frams/genetics/fF
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/genetics/fF/conv_fF.cpp
r176 r177 8 8 #include <common/nonstd_stl.h> 9 9 10 GenoConv_fF0::GenoConv_fF0() 10 GenoConv_fF0::GenoConv_fF0() 11 11 { 12 12 name = "7value Foraminifera encoding"; … … 19 19 } 20 20 21 GenoConv_fF0::~GenoConv_fF0() 21 GenoConv_fF0::~GenoConv_fF0() 22 22 { 23 23 delete[] cosines; … … 31 31 return ""; //so we return an invalid f0 genotype 32 32 33 double div_radius_length = 1; //div_radius_length=1 or kx=ky=kz=133 double div_radius_length = 1; //div_radius_length=1 or kx=ky=kz=1 34 34 double radius = 1; 35 35 36 36 Model m; 37 37 m.open(); 38 39 m.vis_style = "foram"; //dedicated visual look for Foraminifera 40 38 41 // subsequent parts (chambers) are placed relative to the previous part's orientation and location 39 42 Part *p1, *p2; … … 41 44 fF_chamber3d **chambers = new fF_chamber3d*[gp.number_of_chambers]; 42 45 43 for (int i = 0; i < gp.number_of_chambers; i++) {46 for (int i = 0; i < gp.number_of_chambers; i++) 44 47 createSphere(i, chambers, radius, div_radius_length, gp.translation, gp.angle1, gp.angle2, gp.scalex, gp.scaley, gp.scalez); 45 }46 48 47 49 p1 = m.addNewPart(Part::SHAPE_ELLIPSOID); … … 49 51 50 52 51 for (int i = 1; i < gp.number_of_chambers; i++, p1 = p2) { 53 for (int i = 1; i < gp.number_of_chambers; i++, p1 = p2) 54 { 52 55 p2 = m.addNewPart(Part::SHAPE_ELLIPSOID); 53 56 p2>scale = p1>scale.entrywiseProduct(Pt3D(gp.scalex, gp.scaley, gp.scalez)); //each part's scale is its predecessor's scale * scaling … … 106 109 double ppz; 107 110 108 if (which == 1) { 111 if (which == 1) 112 { 109 113 ppx = pcx; 110 114 ppy = pcy; 111 115 ppz = pcz; 112 116 } 113 else { 117 else 118 { 114 119 ppx = chambers[which  2]>holeX; 115 120 ppy = chambers[which  2]>holeY; … … 189 194 double kz = 1; 190 195 191 if (which > 0) { 192 for (int kt = 1; kt < (which + 1); kt++) { 196 if (which > 0) 197 { 198 for (int kt = 1; kt < (which + 1); kt++) 199 { 193 200 kx = kx * kx_; 194 201 ky = ky * ky_; … … 197 204 } 198 205 199 int i, j; 200 double x, y, z; 206 bool all_k_ones = kx_ == 1 && ky_ == 1 && kz_ == 1; 207 208 double rx = all_k_ones ? radius : kx; 209 double ry = all_k_ones ? radius : ky; 210 double rz = all_k_ones ? radius : kz; 201 211 202 212 double **points = new double*[fF_SIZE]; 203 for (int i = 0; i < fF_SIZE; i++) { 213 for (int i = 0; i < fF_SIZE; i++) 214 { 204 215 points[i] = new double[4]; 205 216 } 206 217 207 for (i = 0; i < fF_LONGITUDE_NUM; i++) { 208 if (kx_ == 1 && ky_ == 1 && kz_ == 1) { 209 y = ceny + radius * cosines[i]; 210 } 211 else { 212 y = ceny + ky * cosines[i]; 213 } 214 for (j = 0; j < fF_LATITUDE_NUM; j++) { 215 if (kx_ == 1 && ky_ == 1 && kz_ == 1) { 216 points[(i * fF_LATITUDE_NUM) + j][0] = x = cenx + radius * cosines[j] * sines[i]; 217 points[(i * fF_LATITUDE_NUM) + j][1] = y; 218 points[(i * fF_LATITUDE_NUM) + j][2] = z = cenz + radius * sines[j] * sines[i]; 219 } 220 else { 221 points[(i * fF_LATITUDE_NUM) + j][0] = x = cenx + kx * cosines[j] * sines[i]; 222 points[(i * fF_LATITUDE_NUM) + j][1] = y; 223 points[(i * fF_LATITUDE_NUM) + j][2] = z = cenz + kz * sines[j] * sines[i]; 224 } 225 226 points[(i * fF_LATITUDE_NUM) + j][3] = 1.0; 218 for (int i = 0; i < fF_LONGITUDE_NUM; i++) 219 { 220 double y = ceny + ry * cosines[i]; 221 222 for (int j = 0; j < fF_LATITUDE_NUM; j++) 223 { 224 double x = cenx + rx * cosines[j] * sines[i]; 225 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; 231 227 232 if (x < minX) minX = x; 228 233 if (x > maxX) maxX = x; … … 231 236 232 237 if (z < minZ) minZ = z; 233 } ;234 } ;238 } 239 } 235 240 return points; 236 241 … … 244 249 void GenoConv_fF0::search_hid(int nr, fF_chamber3d **spheres, double kx_, double ky_, double kz_) 245 250 { 246 int i, j; 247 if (nr != 0) { 248 for (i = 0; i < nr; i++) { 249 for (j = 0; j < fF_AMOUNT; j++) { 250 double X = spheres[nr]>points[j][0]; 251 double Y = spheres[nr]>points[j][1]; 252 double Z = spheres[nr]>points[j][2]; 253 254 double srX0 = spheres[i]>centerX; 255 double srY0 = spheres[i]>centerY; 256 double srZ0 = spheres[i]>centerZ; 257 258 double a2; 259 double b2; 260 double c2; 261 262 if (kx_ != 1) { 263 a2 = (kx_ * kx_); 264 } 265 else { 266 a2 = (spheres[i]>radius * spheres[i]>radius); 267 } 268 269 if (ky_ != 1) { 270 b2 = (ky_ * ky_); 271 272 } 273 else { 274 b2 = (spheres[i]>radius * spheres[i]>radius); 275 } 276 277 c2 = (kz_ * spheres[i]>radius) * (kz_ * spheres[i]>radius); 278 279 double up1 = (X  srX0) * (X  srX0); 280 double up2 = (Y  srY0) * (Y  srY0); 281 double up3 = (Z  srZ0) * (Z  srZ0); 282 283 double exp = up1 / a2; 284 double exp2 = up2 / b2; 285 double exp3 = up3 / c2; 286 287 double result = exp + exp2 + exp3; 288 289 if (result < (fF_THICK_RATIO) 290 ) { 291 spheres[nr]>points[j][3] = 0; 292 } 251 double kxsq = kx_*kx_; 252 double kysq = ky_*ky_; 253 double kzsq = kz_*kz_; 254 255 for (int i = 0; i < nr; i++) 256 { 257 double srX0 = spheres[i]>centerX; 258 double srY0 = spheres[i]>centerY; 259 double srZ0 = spheres[i]>centerZ; 260 261 double radsq = spheres[i]>radius * spheres[i]>radius; 262 263 double a2 = kx_ != 1 ? kxsq : radsq; 264 double b2 = ky_ != 1 ? kysq : radsq; 265 double c2 = kzsq * radsq; 266 267 for (int j = 0; j < fF_AMOUNT; j++) 268 { 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); 277 278 double exp1 = up1 / a2; 279 double exp2 = up2 / b2; 280 double exp3 = up3 / c2; 281 282 double result = exp1 + exp2 + exp3; 283 284 if (result < fF_THICK_RATIO) 285 { 286 p[3] = 0.0; 293 287 } 294 288 } … … 298 292 int GenoConv_fF0::find_hole(int which, double x, double y, double z, fF_chamber3d **chambers, double kx_, double ky_, double kz_) 299 293 { 300 int i; 301 double distance; 302 int found = 0; 303 double dist_found = 0; 304 int first = 1; 305 306 for (i = 0; i < fF_AMOUNT; i++) { 307 if (chambers[which]>points[i][3] != 0) //it is not inside another chamber 308 { 309 distance = sqrt((chambers[which]>points[i][0]  x)*(chambers[which]>points[i][0]  x) + 310 (chambers[which]>points[i][1]  y)*(chambers[which]>points[i][1]  y) + 311 (chambers[which]>points[i][2]  z)*(chambers[which]>points[i][2]  z)); 312 if (first != 0) { 294 int found = 1; 295 double distsq_found; 296 297 double kxsq = kx_*kx_; 298 double kysq = ky_*ky_; 299 double kzsq = kz_*kz_; 300 301 for (int i = 0; i < fF_AMOUNT; i++) 302 { 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); 307 if (found < 0) 308 { 313 309 found = i; 314 dist_found = distance; 315 first = 0; 310 distsq_found = distancesq; 316 311 } 317 if (distance < dist_found) { 318 if (which != 0) { 312 if (distancesq < distsq_found) 313 { 314 if (which != 0) 315 { 316 double X = p[0]; 317 double Y = p[1]; 318 double Z = p[2]; 319 319 bool good = true; 320 for (int j = 0; j < which; j++) { 320 for (int j = 0; j < which && good; j++) 321 { 322 double srX0 = chambers[j]>centerX; 323 double srY0 = chambers[j]>centerY; 324 double srZ0 = chambers[j]>centerZ; 325 326 double radsq = chambers[j]>radius * chambers[j]>radius; 327 328 double a2 = kxsq * radsq; 329 double b2 = kysq * radsq; 330 double c2 = kzsq * radsq; 331 332 double up1 = (X  srX0) * (X  srX0); 333 double up2 = (Y  srY0) * (Y  srY0); 334 double up3 = (Z  srZ0) * (Z  srZ0); 335 336 double exp1 = up1 / a2; 337 double exp2 = up2 / b2; 338 double exp3 = up3 / c2; 339 340 double result = exp1 + exp2 + exp3; 341 if (result < 1.0) 321 342 { 322 double X = chambers[which]>points[i][0]; 323 double Y = chambers[which]>points[i][1]; 324 double Z = chambers[which]>points[i][2]; 325 326 double srX0 = chambers[j]>centerX; 327 double srY0 = chambers[j]>centerY; 328 double srZ0 = chambers[j]>centerZ; 329 330 double a2 = (kx_ * chambers[j]>radius) * (kx_ * chambers[j]>radius); 331 double b2 = (ky_ * chambers[j]>radius) * (ky_ * chambers[j]>radius); 332 double c2 = (kz_ * chambers[j]>radius) * (kz_ * chambers[j]>radius); 333 334 double up1 = (X  srX0) * (X  srX0); 335 double up2 = (Y  srY0) * (Y  srY0); 336 double up3 = (Z  srZ0) * (Z  srZ0); 337 338 double exp1 = up1 / a2; 339 double exp2 = up2 / b2; 340 double exp3 = up3 / c2; 341 342 double result = exp1 + exp2 + exp3; 343 if (result < 1.0) 344 { 345 good = false; 346 } 343 good = false; 347 344 } 348 345 } 349 if (good) { 346 if (good) 347 { 350 348 found = i; 351 dist _found = distance;349 distsq_found = distancesq; 352 350 } 353 351 } … … 356 354 } 357 355 358 return (found);359 } 356 return found; 357 } 
cpp/frams/genetics/fF/fF_genotype.cpp
r176 r177 9 9 { 10 10 { "fF", 1, 7, "fF" }, 11 { "n", 0, PARAM_CANOMITNAME, "number of chambers", "d 1 15 1", FIELD(number_of_chambers), },11 { "n", 0, PARAM_CANOMITNAME, "number of chambers", "d 1 15 6", FIELD(number_of_chambers), }, 12 12 { "sx", 0, PARAM_CANOMITNAME, "scale x", "f 1.0 1.1 1.05", FIELD(scalex), }, 13 13 { "sy", 0, PARAM_CANOMITNAME, "scale y", "f 1.0 1.1 1.05", FIELD(scaley), },
Note: See TracChangeset
for help on using the changeset viewer.