Index: cpp/frams/genetics/fF/conv_fF.cpp
===================================================================
--- cpp/frams/genetics/fF/conv_fF.cpp	(revision 176)
+++ cpp/frams/genetics/fF/conv_fF.cpp	(revision 177)
@@ -8,5 +8,5 @@
 #include <common/nonstd_stl.h>
 
-GenoConv_fF0::GenoConv_fF0() 
+GenoConv_fF0::GenoConv_fF0()
 {
 	name = "7-value Foraminifera encoding";
@@ -19,5 +19,5 @@
 }
 
-GenoConv_fF0::~GenoConv_fF0() 
+GenoConv_fF0::~GenoConv_fF0()
 {
 	delete[] cosines;
@@ -31,9 +31,12 @@
 		return ""; //so we return an invalid f0 genotype
 
-	double div_radius_length = 1;//div_radius_length=1 or kx=ky=kz=1
+	double div_radius_length = 1; //div_radius_length=1 or kx=ky=kz=1
 	double radius = 1;
 
 	Model m;
 	m.open();
+
+	m.vis_style = "foram"; //dedicated visual look for Foraminifera
+
 	// subsequent parts (chambers) are placed relative to the previous part's orientation and location
 	Part *p1, *p2;
@@ -41,7 +44,6 @@
 	fF_chamber3d **chambers = new fF_chamber3d*[gp.number_of_chambers];
 
-	for (int i = 0; i < gp.number_of_chambers; i++) {
+	for (int i = 0; i < gp.number_of_chambers; i++)
 		createSphere(i, chambers, radius, div_radius_length, gp.translation, gp.angle1, gp.angle2, gp.scalex, gp.scaley, gp.scalez);
-	}
 
 	p1 = m.addNewPart(Part::SHAPE_ELLIPSOID);
@@ -49,5 +51,6 @@
 
 
-	for (int i = 1; i < gp.number_of_chambers; i++, p1 = p2) {
+	for (int i = 1; i < gp.number_of_chambers; i++, p1 = p2)
+	{
 		p2 = m.addNewPart(Part::SHAPE_ELLIPSOID);
 		p2->scale = p1->scale.entrywiseProduct(Pt3D(gp.scalex, gp.scaley, gp.scalez)); //each part's scale is its predecessor's scale * scaling
@@ -106,10 +109,12 @@
 		double ppz;
 
-		if (which == 1) {
+		if (which == 1)
+		{
 			ppx = pcx;
 			ppy = pcy;
 			ppz = pcz;
 		}
-		else {
+		else
+		{
 			ppx = chambers[which - 2]->holeX;
 			ppy = chambers[which - 2]->holeY;
@@ -189,6 +194,8 @@
 	double kz = 1;
 
-	if (which > 0) {
-		for (int kt = 1; kt < (which + 1); kt++) {
+	if (which > 0)
+	{
+		for (int kt = 1; kt < (which + 1); kt++)
+		{
 			kx = kx * kx_;
 			ky = ky * ky_;
@@ -197,32 +204,30 @@
 	}
 
-	int i, j;
-	double x, y, z;
+	bool all_k_ones = kx_ == 1 && ky_ == 1 && kz_ == 1;
+
+	double rx = all_k_ones ? radius : kx;
+	double ry = all_k_ones ? radius : ky;
+	double rz = all_k_ones ? radius : kz;
 
 	double **points = new double*[fF_SIZE];
-	for (int i = 0; i < fF_SIZE; i++) {
+	for (int i = 0; i < fF_SIZE; i++)
+	{
 		points[i] = new double[4];
 	}
 
-	for (i = 0; i < fF_LONGITUDE_NUM; i++) {
-		if (kx_ == 1 && ky_ == 1 && kz_ == 1) {
-			y = ceny + radius * cosines[i];
-		}
-		else {
-			y = ceny + ky * cosines[i];
-		}
-		for (j = 0; j < fF_LATITUDE_NUM; j++) {
-			if (kx_ == 1 && ky_ == 1 && kz_ == 1) {
-				points[(i * fF_LATITUDE_NUM) + j][0] = x = cenx + radius * cosines[j] * sines[i];
-				points[(i * fF_LATITUDE_NUM) + j][1] = y;
-				points[(i * fF_LATITUDE_NUM) + j][2] = z = cenz + radius * sines[j] * sines[i];
-			}
-			else {
-				points[(i * fF_LATITUDE_NUM) + j][0] = x = cenx + kx * cosines[j] * sines[i];
-				points[(i * fF_LATITUDE_NUM) + j][1] = y;
-				points[(i * fF_LATITUDE_NUM) + j][2] = z = cenz + kz * sines[j] * sines[i];
-			}
-
-			points[(i * fF_LATITUDE_NUM) + j][3] = 1.0;
+	for (int i = 0; i < fF_LONGITUDE_NUM; i++)
+	{
+		double y = ceny + ry * cosines[i];
+
+		for (int j = 0; j < fF_LATITUDE_NUM; j++)
+		{
+			double x = cenx + rx * cosines[j] * sines[i];
+			double z = cenz + rz * sines[j] * sines[i];
+			double *p = points[(i * fF_LATITUDE_NUM) + j];
+			p[0] = x;
+			p[1] = y;
+			p[2] = z;
+			p[3] = 1.0;
+
 			if (x < minX) minX = x;
 			if (x > maxX) maxX = x;
@@ -231,6 +236,6 @@
 
 			if (z < minZ) minZ = z;
-		};
-	};
+		}
+	}
 	return points;
 
@@ -244,51 +249,40 @@
 void GenoConv_fF0::search_hid(int nr, fF_chamber3d **spheres, double kx_, double ky_, double kz_)
 {
-	int i, j;
-	if (nr != 0) {
-		for (i = 0; i < nr; i++) {
-			for (j = 0; j < fF_AMOUNT; j++) {
-				double X = spheres[nr]->points[j][0];
-				double Y = spheres[nr]->points[j][1];
-				double Z = spheres[nr]->points[j][2];
-
-				double srX0 = spheres[i]->centerX;
-				double srY0 = spheres[i]->centerY;
-				double srZ0 = spheres[i]->centerZ;
-
-				double a2;
-				double b2;
-				double c2;
-
-				if (kx_ != 1) {
-					a2 = (kx_ * kx_);
-				}
-				else {
-					a2 = (spheres[i]->radius * spheres[i]->radius);
-				}
-
-				if (ky_ != 1) {
-					b2 = (ky_ * ky_);
-
-				}
-				else {
-					b2 = (spheres[i]->radius * spheres[i]->radius);
-				}
-
-				c2 = (kz_ * spheres[i]->radius) * (kz_ * spheres[i]->radius);
-
-				double up1 = (X - srX0) * (X - srX0);
-				double up2 = (Y - srY0) * (Y - srY0);
-				double up3 = (Z - srZ0) * (Z - srZ0);
-
-				double exp = up1 / a2;
-				double exp2 = up2 / b2;
-				double exp3 = up3 / c2;
-
-				double result = exp + exp2 + exp3;
-
-				if (result < (fF_THICK_RATIO)
-					) {
-					spheres[nr]->points[j][3] = 0;
-				}
+	double kxsq = kx_*kx_;
+	double kysq = ky_*ky_;
+	double kzsq = kz_*kz_;
+
+	for (int i = 0; i < nr; i++)
+	{
+		double srX0 = spheres[i]->centerX;
+		double srY0 = spheres[i]->centerY;
+		double srZ0 = spheres[i]->centerZ;
+
+		double radsq = spheres[i]->radius * spheres[i]->radius;
+
+		double a2 = kx_ != 1 ? kxsq : radsq;
+		double b2 = ky_ != 1 ? kysq : radsq;
+		double c2 = kzsq * radsq;
+
+		for (int j = 0; j < fF_AMOUNT; j++)
+		{
+			double *p = spheres[nr]->points[j];
+			double X = p[0];
+			double Y = p[1];
+			double Z = p[2];
+
+			double up1 = (X - srX0) * (X - srX0);
+			double up2 = (Y - srY0) * (Y - srY0);
+			double up3 = (Z - srZ0) * (Z - srZ0);
+
+			double exp1 = up1 / a2;
+			double exp2 = up2 / b2;
+			double exp3 = up3 / c2;
+
+			double result = exp1 + exp2 + exp3;
+
+			if (result < fF_THICK_RATIO)
+			{
+				p[3] = 0.0;
 			}
 		}
@@ -298,56 +292,60 @@
 int GenoConv_fF0::find_hole(int which, double x, double y, double z, fF_chamber3d **chambers, double kx_, double ky_, double kz_)
 {
-	int i;
-	double distance;
-	int found = 0;
-	double dist_found = 0;
-	int first = 1;
-
-	for (i = 0; i < fF_AMOUNT; i++) {
-		if (chambers[which]->points[i][3] != 0) //it is not inside another chamber
-		{
-			distance = sqrt((chambers[which]->points[i][0] - x)*(chambers[which]->points[i][0] - x) +
-				(chambers[which]->points[i][1] - y)*(chambers[which]->points[i][1] - y) +
-				(chambers[which]->points[i][2] - z)*(chambers[which]->points[i][2] - z));
-			if (first != 0) {
+	int found = -1;
+	double distsq_found;
+
+	double kxsq = kx_*kx_;
+	double kysq = ky_*ky_;
+	double kzsq = kz_*kz_;
+
+	for (int i = 0; i < fF_AMOUNT; i++)
+	{
+		double *p = chambers[which]->points[i];
+		if (p[3] != 0) //it is not inside another chamber
+		{
+			double distancesq = (p[0] - x)*(p[0] - x) + (p[1] - y)*(p[1] - y) + (p[2] - z)*(p[2] - z);
+			if (found < 0)
+			{
 				found = i;
-				dist_found = distance;
-				first = 0;
+				distsq_found = distancesq;
 			}
-			if (distance < dist_found) {
-				if (which != 0) {
+			if (distancesq < distsq_found)
+			{
+				if (which != 0)
+				{
+					double X = p[0];
+					double Y = p[1];
+					double Z = p[2];
 					bool good = true;
-					for (int j = 0; j < which; j++) {
+					for (int j = 0; j < which && good; j++)
+					{
+						double srX0 = chambers[j]->centerX;
+						double srY0 = chambers[j]->centerY;
+						double srZ0 = chambers[j]->centerZ;
+
+						double radsq = chambers[j]->radius * chambers[j]->radius;
+
+						double a2 = kxsq * radsq;
+						double b2 = kysq * radsq;
+						double c2 = kzsq * radsq;
+
+						double up1 = (X - srX0) * (X - srX0);
+						double up2 = (Y - srY0) * (Y - srY0);
+						double up3 = (Z - srZ0) * (Z - srZ0);
+
+						double exp1 = up1 / a2;
+						double exp2 = up2 / b2;
+						double exp3 = up3 / c2;
+
+						double result = exp1 + exp2 + exp3;
+						if (result < 1.0)
 						{
-							double X = chambers[which]->points[i][0];
-							double Y = chambers[which]->points[i][1];
-							double Z = chambers[which]->points[i][2];
-
-							double srX0 = chambers[j]->centerX;
-							double srY0 = chambers[j]->centerY;
-							double srZ0 = chambers[j]->centerZ;
-
-							double a2 = (kx_ * chambers[j]->radius) * (kx_ * chambers[j]->radius);
-							double b2 = (ky_ * chambers[j]->radius) * (ky_ * chambers[j]->radius);
-							double c2 = (kz_ * chambers[j]->radius) * (kz_ * chambers[j]->radius);
-
-							double up1 = (X - srX0) * (X - srX0);
-							double up2 = (Y - srY0) * (Y - srY0);
-							double up3 = (Z - srZ0) * (Z - srZ0);
-
-							double exp1 = up1 / a2;
-							double exp2 = up2 / b2;
-							double exp3 = up3 / c2;
-
-							double result = exp1 + exp2 + exp3;
-							if (result < 1.0)
-							{
-								good = false;
-							}
+							good = false;
 						}
 					}
-					if (good) {
+					if (good)
+					{
 						found = i;
-						dist_found = distance;
+						distsq_found = distancesq;
 					}
 				}
@@ -356,4 +354,4 @@
 	}
 
-	return (found);
-}
+	return found;
+}
Index: cpp/frams/genetics/fF/fF_genotype.cpp
===================================================================
--- cpp/frams/genetics/fF/fF_genotype.cpp	(revision 176)
+++ cpp/frams/genetics/fF/fF_genotype.cpp	(revision 177)
@@ -9,5 +9,5 @@
 {
 	{ "fF", 1, 7, "fF" },
-	{ "n", 0, PARAM_CANOMITNAME, "number of chambers", "d 1 15 1", FIELD(number_of_chambers), },
+	{ "n", 0, PARAM_CANOMITNAME, "number of chambers", "d 1 15 6", FIELD(number_of_chambers), },
 	{ "sx", 0, PARAM_CANOMITNAME, "scale x", "f 1.0 1.1 1.05", FIELD(scalex), },
 	{ "sy", 0, PARAM_CANOMITNAME, "scale y", "f 1.0 1.1 1.05", FIELD(scaley), },
