コード例 #1
0
void Compute(const cNineFractals &fractals, const sFractalIn &in, sFractalOut *out)
{
	//QTextStream outStream(stdout);
	//clock_t tim;
	//tim = rdtsc();

	//repeat, move and rotate
	CVector3 point2 = in.point.mod(in.common.repeat) - in.common.fractalPosition;
	point2 = in.common.mRotFractalRotation.RotateVector(point2);

	CVector3 z = point2;
	double r = z.Length();
	CVector3 c = z;
	double minimumR = 100.0;
	double w = 0.0;
	double orbitTrapTotal = 0.0;

	enumFractalFormula formula = fractal::none;

	out->maxiter = true;

	int fractalIndex = 0;
	if (in.forcedFormulaIndex >= 0) fractalIndex = in.forcedFormulaIndex;

	const cFractal *defaultFractal = fractals.GetFractal(fractalIndex);

	sExtendedAux extendedAux[NUMBER_OF_FRACTALS];
	int maxFractal = (in.forcedFormulaIndex >= 0) ? in.forcedFormulaIndex : fractals.GetMaxFractalIndex();
	int minFractal = (in.forcedFormulaIndex >= 0) ? in.forcedFormulaIndex : 0;
	for (int i = minFractal; i <= maxFractal; i++)
	{
		extendedAux[i].r_dz = 1.0;
		extendedAux[i].r = r;
		extendedAux[i].color = 1.0;
		extendedAux[i].actualScale = fractals.GetFractal(i)->mandelbox.scale;
		extendedAux[i].DE = 1.0;
		extendedAux[i].c = c;
		extendedAux[i].cw = 0;
		extendedAux[i].newR = 1e+20;
		extendedAux[i].axisBias = 1e+20;
		extendedAux[i].orbitTraps = 1e+20;
		extendedAux[i].transformSampling = 1e+20;
	}

	//main iteration loop
	int i;
	int sequence = 0;
	int lastSequnce = 0;

	for (i = 0; i < in.maxN; i++)
	{


		//hybrid fractal sequence
		if (in.forcedFormulaIndex >= 0)
		{
			sequence = in.forcedFormulaIndex;
		}
		else
		{
			sequence = fractals.GetSequence(i);
		}

		//for optimized DE calculation
		if(fractals.UseOptimizedDE())
		{
			extendedAux[sequence] = extendedAux[lastSequnce];
			lastSequnce = sequence;
		}

		//foldings
		if (in.common.foldings.boxEnable)
		{
			BoxFolding(z, &in.common.foldings, extendedAux[sequence]);
			r = z.Length();
		}

		if (in.common.foldings.sphericalEnable)
		{
			extendedAux[sequence].r = r;
		  SphericalFolding(z, &in.common.foldings, extendedAux[sequence]);
			r = z.Length();
		}

		const cFractal *fractal = fractals.GetFractal(sequence);
		formula = fractal->formula;

		//temporary vector for weight function
		CVector3 tempZ = z;

		extendedAux[sequence].r = r;

		if (!fractals.IsHybrid() || fractals.GetWeight(sequence) > 0.0)
		{
			//calls for fractal formulas
			switch (formula)
			{
				case mandelbulb:
				{
					MandelbulbIteration(z, fractal, extendedAux[sequence]);
					break;
				}
				case mandelbulb2:
				{
					Mandelbulb2Iteration(z, extendedAux[sequence]);
					break;
				}
				case mandelbulb3:
				{
					Mandelbulb3Iteration(z, extendedAux[sequence]);
					break;
				}
				case mandelbulb4:
				{
					Mandelbulb4Iteration(z, fractal, extendedAux[sequence]);
					break;
				}
				case fast_mandelbulb_power2:
				{
					MandelbulbPower2Iteration(z, extendedAux[sequence]);
					break;
				}
				case xenodreambuie:
				{
					XenodreambuieIteration(z, fractal, extendedAux[sequence]);
					break;
				}
				case mandelbox:
				{
					MandelboxIteration(z, fractal, extendedAux[sequence]);
					break;
				}
				case smoothMandelbox:
				{
					SmoothMandelboxIteration(z, fractal, extendedAux[sequence]);
					break;
				}
				case boxFoldBulbPow2:
				{
					BoxFoldBulbPow2Iteration(z, fractal);
					break;
				}
				case menger_sponge:
				{
					MengerSpongeIteration(z, extendedAux[sequence]);
					break;
				}
				case kaleidoscopicIFS:
				{
					KaleidoscopicIFSIteration(z, fractal, extendedAux[sequence]);
					break;
				}
				case aexion:
				{
					AexionIteration(z, w, i, fractal, extendedAux[sequence]);
					break;
				}
				case hypercomplex:
				{
					HypercomplexIteration(z, w, extendedAux[sequence]);
					break;
				}
				case quaternion:
				{
					QuaternionIteration(z, w, extendedAux[sequence]);
					break;
				}
				case benesi:
				{
					BenesiIteration(z, c, extendedAux[sequence]);
					break;
				}
				case bristorbrot:
				{
					BristorbrotIteration(z, extendedAux[sequence]);
					break;
				}
				case ides:
				{
          IdesIteration(z, fractal);
					break;
				}
				case ides2:
				{
          Ides2Iteration(z, fractal);
					break;
				}
				case buffalo:
				{
					BuffaloIteration(z, fractal, extendedAux[sequence]);
					break;
				}
				case quickdudley:
				{
					QuickDudleyIteration(z);
					break;
				}
        case quickDudleyMod:
        {
          QuickDudleyModIteration(z, fractal);
          break;
        }
				case lkmitch:
				{
					LkmitchIteration(z);
					break;
				}
				case makin3d2:
				{
					Makin3D2Iteration(z);
					break;
				}
        case msltoeDonut:
				{
          MsltoeDonutIteration(z, fractal, extendedAux[sequence]);
					break;
				}
        case msltoesym2Mod:
				{
          MsltoeSym2ModIteration(z, c, fractal, extendedAux[sequence]);
					break;
				}
        case msltoesym3Mod:
        {
          MsltoeSym3ModIteration(z, c, i, fractal, extendedAux[sequence]);
          break;
        }
        case msltoesym3Mod2:
        {
          MsltoeSym3Mod2Iteration(z, c, fractal, extendedAux[sequence]);
          break;
        }
        case msltoesym3Mod3:
        {
          MsltoeSym3Mod3Iteration(z, c, i, fractal, extendedAux[sequence]);
          break;
        }
        case msltoesym4Mod:
        {
          MsltoeSym4ModIteration(z, c, fractal, extendedAux[sequence]);
          break;
        }
				case generalizedFoldBox:
				{
					GeneralizedFoldBoxIteration(z, fractal, extendedAux[sequence]);
					break;
				}
				case mandelbulb5:
				{
					Mandelbulb5Iteration(z, c, minimumR, i, fractal, extendedAux[sequence]);
					break;
				}
				case mandelbox103:
				{
					Mandelbox103Iteration(z, c, minimumR, i, fractal, extendedAux[sequence]);
					break;
				}
				case quaternion104:
				{
					CVector4 z4D(z, w);
					Quaternion104Iteration(z4D, CVector4(c, 0.0), i, fractal, extendedAux[sequence]);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case mengerSponge105:
				{
					MengerSponge105Iteration(z, c, minimumR, i, fractal, extendedAux[sequence]);
					break;
				}
				case mandelbulb6Beta:
				{
					Mandelbulb6BetaIteration(z, c, minimumR, i, fractal, extendedAux[sequence]);
					break;
				}
				case benesiTransforms:
				{
					BenesiTransformsIteration(z, c, minimumR, i, fractal, extendedAux[sequence]);
					break;
				}


        case aboxMod1:
        {
          AboxMod1Iteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case aboxMod2:
        {
          AboxMod2Iteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case aboxModKali:
        {
          AboxModKaliIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case aboxVSIcen1:
        {
          AboxVSIcen1Iteration(z, c, fractal, extendedAux[sequence]);
          break;
        }
        case aexionOctopusMod:
        {
          AexionOctopusModIteration(z, c, fractal);
          break;
        }
        case amazingSurf:
        {
          AmazingSurfIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case amazingSurfMod1:
        {
          AmazingSurfMod1Iteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case benesiPineTree:
        {
          BenesiPineTreeIteration(z, c, fractal, extendedAux[sequence]);
          break;
        }
        case benesiT1PineTree:
        {
          BenesiT1PineTreeIteration(z, c, i, fractal, extendedAux[sequence]);
          break;
        }
        case eiffieMsltoe:
        {
          EiffieMsltoeIteration(z, c, fractal, extendedAux[sequence]);
          break;
        }
        case foldBoxMod1:
        {
          FoldBoxMod1Iteration(z, i, fractal, extendedAux[sequence]);
          break;
        }
        case iqBulb:
        {
          IQbulbIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case kalisets1:
        {
          Kalisets1Iteration(z, c, fractal, extendedAux[sequence]);
          break;
        }
        case mandelbulbMulti:
        {
          MandelbulbMultiIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case mandelbulbVaryPowerV1:
        {
          MandelbulbVaryPowerV1Iteration(z, i, fractal, extendedAux[sequence]);
          break;
        }
        case mengerMod1:
        {
          MengerMod1Iteration(z, i, fractal, extendedAux[sequence]);
          break;
        }
        case riemannSphereMsltoe:
        {
          RiemannSphereMsltoeIteration(z, fractal);
          break;
        }
        case riemannSphereMsltoeV1:
        {
          RiemannSphereMsltoeV1Iteration(z, fractal);
          break;
        }
        case quaternion3D:
        {
          Quaternion3DIteration(z, fractal, extendedAux[sequence]);
          break;
        }



        //transforms ------------------------------------------------------------------------------------------
        case transfAdditionConstant:
        {
        	TransformAdditionConstantIteration(z, fractal);
        	break;
        }
        case transfAdditionConstantVaryV1:
        {
          TransformAdditionConstantVaryV1Iteration(z, i, fractal);
          break;
        }
        case transfAddCpixel:
        {
          TransformAddCpixelIteration(z, c, fractal);
          break;
        }
        case transfAddCpixelAxisSwap:
        {
          TransformAddCpixelAxisSwapIteration(z, c, fractal);
          break;
        }
        case transfAddCpixelCxCyAxisSwap:
        {
          TransformAddCpixelCxCyAxisSwapIteration(z, c, fractal);
          break;
        }
        case transfAddCpixelPosNeg:
        {
          TransformAddCpixelPosNegIteration(z, c, fractal);
          break;
        }
        case transfAddCpixelVaryV1:
        {
          TransformAddCpixelVaryV1Iteration(z, c, i, fractal);
          break;
        }
        case transfBenesiT1:
        {
          TransformBenesiT1Iteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfBenesiT1Mod:
        {
          TransformBenesiT1ModIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfBenesiT2:
        {
          TransformBenesiT2Iteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfBenesiT3:
        {
          TransformBenesiT3Iteration(z, fractal);
          break;
        }
        case transfBenesiT4:
        {
          TransformBenesiT4Iteration(z, fractal);
          break;
        }
        case transfBenesiT5b:
        {
          TransformBenesiT5bIteration(z, fractal);
          break;
        }
        case transfBenesiMagForward:
        {
          TransformBenesiMagForwardIteration(z);
          break;
        }
        case transfBenesiMagBackward:
        {
          TransformBenesiMagBackwardIteration(z);
          break;
        }
        case transfBenesiCubeSphere:
        {
          TransformBenesiCubeSphereIteration(z);
          break;
        }
        case transfBenesiSphereCube:
        {
					TransformBenesiSphereCubeIteration(z);
					break;
        }
        case transfBoxFold:
        {
          TransformBoxFoldIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfBoxFoldXYZ:
        {
          TransformBoxFoldXYZIteration(z, fractal, extendedAux[sequence]);
          break;
        }

        case transfBoxOffset:
        {
          TransformBoxOffsetIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfFabsAddConstant:
        {
          TransformFabsAddConstantIteration(z, fractal);
          break;
        }
        case transfFabsAddConstantV2:
        {
          TransformFabsAddConstantV2Iteration(z, fractal);
          break;
        }
        case transfFabsAddMulti:
        {
          TransformFabsAddMultiIteration(z, fractal);
          break;
        }
        case transfIterationWeight:
        {
          TransformIterationWeightIteration(z, i, fractal);
          break;
        }
        case transfLinCombineCxyz:
        {
          TransformLinCombineCxyz(c, fractal);
          break;
        }
        case transfMultipleAngle:
        {
          TransformMultipleAngle(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfNegFabsAddConstant:
        {
          TransformNegFabsAddConstantIteration(z, fractal);
          break;
        }
        case transfRotation:
        {
        	TransformRotationIteration(z, fractal);
        	break;
        }
        case transfRotationVaryV1:
        {
          TransformRotationVaryV1Iteration(z, i, fractal);
          break;
        }
        case transfScale:
        {
        	TransformScaleIteration(z, fractal, extendedAux[sequence]);
        	break;
        }
        case transfScaleVaryV1:
        {
          TransformScaleVaryV1Iteration(z, i, fractal, extendedAux[sequence]);
          break;
        }
        case transfScale3D:
        {
        	TransformScale3DIteration(z, fractal, extendedAux[sequence]);
        	break;
        }
				case platonicSolid:
				{
					TransformPlatonicSolidIteration(z, fractal);
					break;
				}
				case transfRPower:
				{
					TransformPowerR(z, fractal, extendedAux[sequence]);
					break;
				}
        case transfSphereInvC:
        {
          TransformSphereInvCIteration(z, c, fractal);
          break;
        }
        case transfSphericalOffset:
        {
          TransformSphericalOffsetIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfSphericalFold:
        {
          TransformSphericalFoldIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfSphericalPwrFold:
        {
          TransformSphericalPwrFoldIteration(z, fractal, extendedAux[sequence]);
          break;
        }
        case transfZvectorAxisSwap:
        {
          TransformZvectorAxisSwapIteration(z, fractal );
          break;
        }
        // 4D  ---------------------------------------------------------------------------
        case quaternion4D:
        {
          CVector4 z4D(z, w);
          Quaternion4DIteration(z4D, i, fractal);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }
        case mandelboxVaryScale4D:
        {
          CVector4 z4D(z, w);
          MandelboxVaryScale4DIteration(z4D, i, fractal, extendedAux[sequence]);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }
        case transfAdditionConstant4D:
        {
          CVector4 z4D(z, w);
          TransformAdditionConstant4DIteration(z4D, fractal);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }
        case transfBoxFold4D:
        {
          CVector4 z4D(z, w);
          TransformBoxFold4DIteration(z4D, fractal, extendedAux[sequence]);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }
        case transfFabsAddConstant4D:
        {
          CVector4 z4D(z, w);
          TransformFabsAddConstant4DIteration(z4D, fractal);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }
        case transfFabsAddConstantV24D:
        {
          CVector4 z4D(z, w);
          TransformFabsAddConstantV24DIteration(z4D, fractal);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }
        case transfIterationWeight4D:
        {
          CVector4 z4D(z, w);
          TransformIterationWeight4DIteration(z4D, i, fractal);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }
        case transfScale4D:
        {
          CVector4 z4D(z, w);
          TransformScale4DIteration(z4D, fractal, extendedAux[sequence]);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }
        case transfSphericalFold4D:
        {
          CVector4 z4D(z, w);
          TransformSphericalFold4DIteration(z4D, fractal, extendedAux[sequence]);
          z = z4D.GetXYZ();
          w = z4D.w;
          break;
        }

				default:
					z = CVector3(0.0, 0.0, 0.0);
					break;
			}
		}

		//addition of constant
		if (fractals.IsAddCConstant(sequence))
		{
			switch (formula)
			{
        case aboxMod1:
        case amazingSurf:
        //case amazingSurfMod1:
        {
					if (fractals.IsJuliaEnabled(sequence))
					{
            CVector3 juliaC = fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence);
						z += CVector3(juliaC.y, juliaC.x, juliaC.z);
					}
					else
					{
	          z += CVector3(c.y, c.x, c.z) * fractals.GetConstantMultiplier(sequence);
					}
					break;
        }

				default:
				{
					if (fractals.IsJuliaEnabled(sequence))
					{
						z += fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence);
					}
					else
					{
						z += c * fractals.GetConstantMultiplier(sequence);
					}
					break;
				}
      }
		}

		if (fractals.IsHybrid())
		{
			z = SmoothCVector(tempZ, z, fractals.GetWeight(sequence));
		}

		//r calculation
		r = sqrt(z.x * z.x + z.y * z.y + z.z * z.z + w * w);

		//escape conditions
		if (fractals.IsCheckForBailout(sequence))
		{
			if (Mode == calcModeNormal)
			{
				if (r > fractals.GetBailout(sequence))
				{
					out->maxiter = false;
					break;
				}
			}
			else if (Mode == calcModeDeltaDE1)
			{
				if (r > fractals.GetBailout(sequence))
				{
					out->maxiter = false;
					break;
				}
			}
			else if (Mode == calcModeDeltaDE2)
			{
				if (i == in.maxN) break;
			}
			else if (Mode == calcModeColouring)
			{
				double len = 0.0;
				switch (in.common.fractalColoringAlgorithm)
				{
					case fractalColoringStandard:
					{
						len = r;
						break;
					}
					case fractalColoringZDotPoint:
					{
						len = fabs(z.Dot(in.point));
						break;
					}
					case fractalColoringSphere:
					{
						len = fabs((z - in.point).Length() - in.common.fractalColoringSphereRadius);
						break;
					}
					case fractalColoringCross:
					{
						len = dMin(fabs(z.x), fabs(z.y), fabs(z.z));
						break;
					}
					case fractalColoringLine:
					{
						len = fabs(z.Dot(in.common.fractalColoringLineDirection));
						break;
					}
				}
				if (fractal->formula != mandelbox || in.common.fractalColoringAlgorithm != fractalColoringStandard)
				{
					if (len < minimumR) minimumR = len;
				}
				if (r > 1e15) break;
			}
			else if (Mode == calcModeOrbitTrap)
			{
				CVector3 delta = z - in.common.fakeLightsOrbitTrap;
				double distance = delta.Length();
				if (i >= in.common.fakeLightsMinIter && i <= in.common.fakeLightsMaxIter) orbitTrapTotal +=
						(1.0f / (distance * distance));
				if (distance > 1000)
				{
					out->orbitTrapR = orbitTrapTotal;
					break;
				}
			}
		}
	}

	//final calculations
	if (Mode == calcModeNormal)
	{
		if (fractals.IsHybrid())
		{
			if(extendedAux[sequence].r_dz > 0)
			{
				if (fractals.GetDEFunctionType(0) == fractal::linearDEFunction)
				{
					out->distance = r / fabs(extendedAux[sequence].DE);
				}
				else if (fractals.GetDEFunctionType(0) == fractal::logarithmicDEFunction)
				{
					out->distance = 0.5 * r * log(r) / extendedAux[sequence].r_dz;
				}
			}
			else
			{
				out->distance = r;
			}
		}
		else
		{
			switch (formula)
			{
				case benesi:
				case benesiPineTree:
				case benesiT1PineTree:
				case bristorbrot:
				case buffalo:
				case eiffieMsltoe:
				case fast_mandelbulb_power2:
				case hypercomplex:
				case iqBulb:
				case mandelbulb:
				case mandelbulb2:
				case mandelbulb3:
				case mandelbulb4:
				case mandelbulb5:
				case mandelbulb6Beta:
				case mandelbulbMulti:
        case mandelbulbVaryPowerV1:
        case msltoesym2Mod:
        case msltoesym3Mod:
        case msltoesym3Mod2:
        case msltoesym3Mod3:
        case msltoesym4Mod:
				case quaternion:
        case quaternion3D:
				case xenodreambuie:
				{
					if(extendedAux[sequence].r_dz > 0)
						out->distance = 0.5 * r * log(r) / extendedAux[sequence].r_dz;
					else
						out->distance = r;
					break;
				}
				case mandelbox:
				case smoothMandelbox:
				case mandelboxVaryScale4D:
				case generalizedFoldBox:
				case mandelbox103:
				case mengerSponge105:
        case foldBoxMod1:
				case aboxModKali:
        case mengerMod1:
				case aboxMod1:
        case aboxMod2:
        case amazingSurf:
        case amazingSurfMod1:
        case kalisets1:
        case aboxVSIcen1:
        {
					if(extendedAux[sequence].r_dz > 0)
						out->distance = r / fabs(extendedAux[sequence].DE);
					else
						out->distance = r;
					break;
        }
				case kaleidoscopicIFS:
				case menger_sponge:
        {
					if(extendedAux[sequence].r_dz > 0)
						out->distance = (r - 2.0) / (extendedAux[sequence].DE);
					else
						out->distance = r;
					break;
        }

				default:
					out->distance = -1.0;
					break;
			}
		}
	}
	//color calculation
	else if (Mode == calcModeColouring)
	{
		if (fractals.IsHybrid())
		{
			if (minimumR > 100) minimumR = 100;

			double mboxColor = 0.0;
			double mboxDE = 1.0;
			for (int h = minFractal; h <= maxFractal; h++)
			{
				mboxColor += extendedAux[h].color;
				mboxDE *= extendedAux[h].DE; //mboxDE *= mandelboxAux[h].mboxDE + extendedAux[h].color;
			}

			double r2 = r / fabs(mboxDE);
			if (r2 > 20) r2 = 20;

			if (mboxColor > 1000) mboxColor = 1000;

			out->colorIndex = minimumR * 1000.0 + mboxColor * 100 + r2 * 5000.0;
		}
		else
		{
			switch (formula)
			{
				case mandelbox:
				case smoothMandelbox:
				case mandelboxVaryScale4D:
				case generalizedFoldBox:
				case foldBoxMod1:
					out->colorIndex = extendedAux[fractalIndex].color * 100.0
							+ r * defaultFractal->mandelbox.color.factorR
							+ ((in.common.fractalColoringAlgorithm != fractalColoringStandard) ? minimumR
									* 1000.0 :
									0.0);
					break;

				case mandelbulb5:
				case mandelbox103:
				case mandelbulb6Beta:
				case benesiTransforms:
				case mengerSponge105:
					out->colorIndex = extendedAux[fractalIndex].newR
							+ ((in.common.fractalColoringAlgorithm != fractalColoringStandard) ? minimumR
									* 1000.0 :
									0.0);
					break;

        case mengerMod1:
        case aboxModKali:
        case aboxMod1:
				case menger_sponge:
				case kaleidoscopicIFS:
					out->colorIndex = minimumR * 1000.0;
					break;

				case amazingSurf:
				case amazingSurfMod1:
					out->colorIndex = minimumR * 200.0;
					break;

				case msltoeDonut:
					out->colorIndex = extendedAux[fractalIndex].color * 2000.0 / i;
					break;

				default:
					out->colorIndex = minimumR * 5000.0;
					break;
			}

		}
	}
	else
	{
		out->distance = 0.0;
	}

	out->iters = i + 1;
  out->z = z; // CVector3( z.x, z.y, w);
	//tim = rdtsc() - tim; perf+= tim; perfCount++; outStream << (double)perf/perfCount - 560.0 << endl;
	//------------- 3249 ns for all calculation  ----------------
}
コード例 #2
0
void Compute(const cNineFractals &fractals, const sFractalIn &in, sFractalOut *out)
{
	fractalFormulaFcn fractalFormulaFunction;

	// repeat, move and rotate
	CVector3 pointTransformed = (in.point - in.common.fractalPosition).mod(in.common.repeat);
	pointTransformed = in.common.mRotFractalRotation.RotateVector(pointTransformed);

	CVector4 z = CVector4(pointTransformed, 0.0);

	double colorMin = 1000.0;

	if (in.forcedFormulaIndex >= 0)
	{
		z.w = fractals.GetInitialWAxis(in.forcedFormulaIndex);
	}
	else
	{
		z.w = fractals.GetInitialWAxis(0);
	}

	double r = z.Length();

	double initR = r;

	double initialWAxisColor = z.w;

	double orbitTrapTotal = 0.0;
	out->orbitTrapR = 0.0;

	enumFractalFormula formula = fractal::none;

	out->maxiter = true;

	int fractalIndex = 0;
	if (in.forcedFormulaIndex >= 0) fractalIndex = in.forcedFormulaIndex;

	const sFractal *defaultFractal = fractals.GetFractal(fractalIndex);

	sExtendedAux extendedAux;

	extendedAux.c = z;
	extendedAux.const_c = z;
	extendedAux.old_z = CVector4(0.0, 0.0, 0.0, 0.0);
	extendedAux.sum_z = CVector4(0.0, 0.0, 0.0, 0.0);
	extendedAux.pos_neg = 1.0;
	extendedAux.cw = 0;

	extendedAux.r = r;
	extendedAux.DE = 1.0;
	extendedAux.pseudoKleinianDE = 1.0;

	extendedAux.actualScale = fractals.GetFractal(fractalIndex)->mandelbox.scale;
	extendedAux.actualScaleA = 0.0;

	extendedAux.color = 1.0;
	extendedAux.colorHybrid = 0.0;

	extendedAux.temp100 = 100.0;
	extendedAux.addDist = 0.0;

	// main iteration loop
	int i;
	int sequence = 0;

	CVector4 lastGoodZ;
	CVector4 lastZ;
	CVector4 lastLastZ;

	// main iteration loop
	for (i = 0; i < in.maxN; i++)
	{
		lastGoodZ = lastZ;
		lastLastZ = lastZ;
		;
		lastZ = z;

		// hybrid fractal sequence
		if (in.forcedFormulaIndex >= 0)
		{
			sequence = in.forcedFormulaIndex;
		}
		else
		{
			sequence = fractals.GetSequence(i);
		}

		// foldings
		if (in.common.foldings.boxEnable)
		{
			BoxFolding(z, &in.common.foldings, extendedAux);
			r = z.Length();
		}

		if (in.common.foldings.sphericalEnable)
		{
			extendedAux.r = r;
			SphericalFolding(z, &in.common.foldings, extendedAux);
			r = z.Length();
		}

		const sFractal *fractal = fractals.GetFractal(sequence);
		formula = fractal->formula;

		// temporary vector for weight function
		CVector4 tempZ = z;

		extendedAux.r = r;
		extendedAux.i = i;

		fractalFormulaFunction = fractals.GetFractalFormulaFunction(sequence);

		if (!fractals.IsHybrid() || fractals.GetWeight(sequence) > 0.0)
		{
			// -------------- call for fractal formulas by function pointers ---------------
			if (fractalFormulaFunction)
			{
				fractalFormulaFunction(z, fractal, extendedAux);
			}
			else
			{
				double high = fractals.GetBailout(sequence) * 10.0;
				z = CVector4(high, high, high, high);
				out->distance = 10.0;
				out->iters = 1;
				out->z = z.GetXYZ();
				return;
			}
			// -----------------------------------------------------------------------------
		}

		// addition of constant
		if (fractals.IsAddCConstant(sequence))
		{
			switch (formula)
			{
				case aboxMod1:
				case amazingSurf:
					// case amazingSurfMod1:
					{
						if (fractals.IsJuliaEnabled(sequence))
						{
							CVector3 juliaC =
								fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence);
							z += CVector4(juliaC.y, juliaC.x, juliaC.z, 0.0);
						}
						else
						{
							z +=
								CVector4(extendedAux.const_c.y, extendedAux.const_c.x, extendedAux.const_c.z, 0.0)
								* fractals.GetConstantMultiplier(sequence);
						}
						break;
					}

				default:
				{
					if (fractals.IsJuliaEnabled(sequence))
					{
						z += CVector4(
							fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence), 0.0);
					}
					else
					{
						z += extendedAux.const_c * fractals.GetConstantMultiplier(sequence);
					}
					break;
				}
			}
		}

		if (fractals.IsHybrid())
		{
			z = SmoothCVector(tempZ, z, fractals.GetWeight(sequence));
		}

		// r calculation
		// r = sqrt(z.x * z.x + z.y * z.y + z.z * z.z + w * w);
		switch (fractal->formula)
		{
			case scatorPower2:					// add v2.15
			case scatorPower2Real:			// add v2.15
			case scatorPower2Imaginary: // corrected v2.14
			case testingLog:
			{
				CVector4 z2 = z * z;
				r = sqrt(z2.x + z2.y + z2.z + (z2.y * z2.z) / z2.x);
				// initial condition is normal r, becomes aux.r

				// r = sqrt(z2.x - z2.y - z2.z + (z2.y * z2.z) / (z2.x));
				break;
			}
			// scator magnitudes
			// magnitude in imaginary scator algebra

			// case pseudoKleinian:
			// case pseudoKleinianMod1:
			// case pseudoKleinianMod2:
			case pseudoKleinianStdDE:
			{
				r = sqrt(z.x * z.x + z.y * z.y);
				break;
			}

			default:
			{
				r = z.Length();
				// r = sqrt(z.x * z.x + z.y * z.y + z.z * z.z);
				break;
			}
		}

		if (z.IsNotANumber())
		{
			z = lastZ;
			r = z.Length();
			out->maxiter = true;
			break;
		}

		// escape conditions
		if (fractals.IsCheckForBailout(sequence))
		{
			if (Mode == calcModeNormal || Mode == calcModeDeltaDE1)
			{
				if (r > fractals.GetBailout(sequence))
				{
					out->maxiter = false;
					break;
				}

				if (fractals.UseAdditionalBailoutCond(sequence))
				{
					out->maxiter = false; // maxiter flag has to be always disabled for pseudo klienian
					if ((z - lastZ).Length() / r < 0.1 / fractals.GetBailout(sequence))
					{
						break;
					}
					if ((z - lastLastZ).Length() / r < 0.1 / fractals.GetBailout(sequence))
					{
						break;
					}
				}
			}
			else if (Mode == calcModeDeltaDE2)
			{
				if (i == in.maxN) break;
			}
			else if (Mode == calcModeColouring)
			{
				CVector4 colorZ = z;
				if (!in.material->fractalColoring.color4dEnabledFalse) colorZ.w = 0.0;
				double len = 0.0;
				switch (in.material->fractalColoring.coloringAlgorithm)
				{
					case fractalColoring_Standard:
					{
						len = colorZ.Length();
						break;
					}
					case fractalColoring_ZDotPoint:
					{
						len = fabs(colorZ.Dot(CVector4(pointTransformed, initialWAxisColor)));
						break;
					}
					case fractalColoring_Sphere:
					{
						len = fabs((colorZ - CVector4(pointTransformed, initialWAxisColor)).Length()
											 - in.material->fractalColoring.sphereRadius);
						break;
					}
					case fractalColoring_Cross:
					{

						len = dMin(fabs(colorZ.x), fabs(colorZ.y), fabs(colorZ.z));
						if (in.material->fractalColoring.color4dEnabledFalse) len = min(len, fabs(colorZ.w));
						break;
					}
					case fractalColoring_Line:
					{

						len = fabs(colorZ.Dot(in.material->fractalColoring.lineDirection));
						break;
					}
					case fractalColoring_None:
					{
						len = r;
						break;
					}
				}
				if (!in.material->fractalColoring.colorPreV215False)
				{ // V2.15 code
					if (fractal->formula != mandelbox)
					{
						if (len < colorMin) colorMin = len;
						if (r > fractals.GetBailout(sequence) || (z - lastZ).Length() / r < 1e-15) break;
					}
					else // for Mandelbox. Note in Normal Mode (abox_color) colorMin = 0, else has a value
					{
						if (in.material->fractalColoring.coloringAlgorithm == fractalColoring_Standard)
						{
							if (r > 1e15 || (z - lastZ).Length() / r < 1e-15) break;
						}
						else
						{
							if (len < colorMin) colorMin = len;
							if (r > fractals.GetBailout(sequence) || (z - lastZ).Length() / r < 1e-15) break;
						}
					}
				}
				else // pre-v2.15 mode
				{
					if (fractal->formula != mandelbox
							|| in.material->fractalColoring.coloringAlgorithm != fractalColoring_Standard)
					{
						if (len < colorMin) colorMin = len;
						if (r > 1e15 || (z - lastZ).Length() / r < 1e-15) break; // old, is updated v2.15
					}
					else // for mandbox and fractalColoring_Standard
					{
						if (r > 1e15 || (z - lastZ).Length() / r < 1e-15) break;
					}
				}
			}

			else if (Mode == calcModeOrbitTrap)
			{
				CVector4 delta = z - CVector4(in.common.fakeLightsOrbitTrap, 0.0);
				double distance = delta.Length();
				if (i >= in.common.fakeLightsMinIter && i <= in.common.fakeLightsMaxIter)
					orbitTrapTotal += (1.0 / (distance * distance));
				if (distance > fractals.GetBailout(sequence))
				{
					out->orbitTrapR = orbitTrapTotal;
					break;
				}
			}
			else if (Mode == calcModeCubeOrbitTrap)
			{
				if (i >= in.material->textureFractalizeStartIteration)
				{
					double size = in.material->textureFractalizeCubeSize;
					CVector3 zz = z.GetXYZ() - pointTransformed;
					if (zz.x > -size && zz.x < size && zz.y > -size && zz.y < size && zz.z > -size
							&& zz.z < size)
					{
						out->colorIndex = (fabs(z.x - size) + fabs(z.y - size) + fabs(z.z - size)) * 100.0;
						out->iters = i + 1;
						out->z = z.GetXYZ();
						return;
					}
				}
				if (r > in.material->textureFractalizeCubeSize * 100.0)
				{
					out->colorIndex = 0.0;
					out->iters = i + 1;
					out->z = z.GetXYZ() / z.Length();
					return;
				}
			}
		}

		if (z.IsNotANumber()) // detection of dead computation
		{
			z = lastGoodZ;
			break;
		}
	}

	// final calculations
	if (Mode == calcModeNormal) // analytic
	{
		if (extendedAux.DE > 0.0)
		{
			if (fractals.IsHybrid())
			{
				if (fractals.GetDEFunctionType(0) == fractal::linearDEFunction)
				{
					out->distance = (r - in.common.linearDEOffset) / extendedAux.DE;
				}
				else if (fractals.GetDEFunctionType(0) == fractal::logarithmicDEFunction)
				{
					out->distance = 0.5 * r * log(r) / extendedAux.DE;
				}
				else if (fractals.GetDEFunctionType(0) == fractal::pseudoKleinianDEFunction)
				{
					double rxy = sqrt(z.x * z.x + z.y * z.y);

					out->distance =
						max(rxy - extendedAux.pseudoKleinianDE, fabs(rxy * z.z) / r) / extendedAux.DE;
				}
				else if (fractals.GetDEFunctionType(0) == fractal::josKleinianDEFunction)
				{
					if (fractals.GetFractal(0)->transformCommon.spheresEnabled)
						z.y = min(z.y, fractals.GetFractal(0)->transformCommon.foldingValue - z.y);

					out->distance = min(z.y, fractals.GetFractal(0)->analyticDE.tweak005)
													/ max(extendedAux.DE, fractals.GetFractal(0)->analyticDE.offset1);
				}
				/*else if (fractals.GetDEFunctionType(0) == fractal:: testingDEFunction)
				{
					double logDE = ((0.5 * r * log(r)) - in.common.linearDEOffset) / extendedAux.DE;
					double linDE = (r - in.common.linearDEOffset) / extendedAux.DE;

					out->distance = linDE + (logDE - linDE) * extendedAux.temp100;
				// (logDE, linDE, extendedAux.temp100 / 100)); // temp use of auxtemp100.
				}*/
			}
			else
			{
				switch (fractals.GetDEAnalyticFunction(sequence))
				{
					case analyticFunctionLogarithmic:
					{
						out->distance = 0.5 * r * log(r) / extendedAux.DE;
						break;
					}
					case analyticFunctionLinear:
					{
						out->distance = r / extendedAux.DE;
						break;
					}
					case analyticFunctionIFS:
					{
						out->distance = (r - 2.0) / extendedAux.DE;
						break;
					}
					case analyticFunctionPseudoKleinian:
					{
						double rxy = sqrt(z.x * z.x + z.y * z.y);
						out->distance =
							max(rxy - extendedAux.pseudoKleinianDE, fabs(rxy * z.z) / r) / extendedAux.DE;
						break;
					}
					case analyticFunctionJosKleinian:
					{
						if (fractals.GetFractal(sequence)->transformCommon.spheresEnabled)
							z.y = min(z.y, fractals.GetFractal(sequence)->transformCommon.foldingValue - z.y);

						out->distance =
							min(z.y, fractals.GetFractal(sequence)->analyticDE.tweak005)
							/ max(extendedAux.DE, fractals.GetFractal(sequence)->analyticDE.offset1);
						break;
					}

					case analyticFunctionNone: out->distance = -1.0; break;
					case analyticFunctionUndefined: out->distance = r; break;
				}
			}
			// TEMPORARY CODE.  To be removed afer testing
			if (fractals.GetFractal(sequence)->transformCommon.functionEnabledTempFalse)
			{
				out->distance =
					out->distance * initR * initR
					/ (fractals.GetFractal(sequence)->transformCommon.maxR2d1 + initR * out->distance);
			}
		}
		else
			out->distance = r;
	}

	// color calculation
	else if (Mode == calcModeColouring)
	{
		enumColoringFunction coloringFunction = fractals.GetColoringFunction(sequence);
		out->colorIndex = CalculateColorIndex(fractals.IsHybrid(), r, z, colorMin, extendedAux,
			in.material->fractalColoring, coloringFunction, defaultFractal);
	}
	else
	{
		out->distance = 0.0;

		// needed for JosKleinian fractal to calculate spheres in deltaDE mode
		if (fractals.GetDEFunctionType(0) == fractal::josKleinianDEFunction)
		{
			if (fractals.GetFractal(sequence)->transformCommon.spheresEnabled)
				z.y = min(z.y, fractals.GetFractal(sequence)->transformCommon.foldingValue - z.y);
		}
	}

	out->iters = i + 1;
	out->z = z.GetXYZ();
}
コード例 #3
0
void Compute(const cNineFractals &fractals, const sFractalIn &in, sFractalOut *out)
{
	// QTextStream outStream(stdout);
	// clock_t tim;
	// tim = rdtsc();

	// repeat, move and rotate
	CVector3 point2 = in.point.mod(in.common.repeat) - in.common.fractalPosition;
	point2 = in.common.mRotFractalRotation.RotateVector(point2);

	CVector3 z = point2;
	double r = z.Length();
	CVector3 c = z;
	double minimumR = 100.0;
	double w = 0.0;
	double orbitTrapTotal = 0.0;

	enumFractalFormula formula = fractal::none;

	out->maxiter = true;

	int fractalIndex = 0;
	if (in.forcedFormulaIndex >= 0) fractalIndex = in.forcedFormulaIndex;

	const cFractal *defaultFractal = fractals.GetFractal(fractalIndex);

	sExtendedAux extendedAux;

	extendedAux.r_dz = 1.0;
	extendedAux.r = r;
	extendedAux.color = 1.0;
	extendedAux.actualScale = fractals.GetFractal(fractalIndex)->mandelbox.scale;
	extendedAux.DE = 1.0;
	extendedAux.c = c;
	extendedAux.cw = 0;
	extendedAux.foldFactor = 0.0;
	extendedAux.minRFactor = 0.0;
	extendedAux.scaleFactor = 0.0;
	// extendedAux.newR = 1e+20;
	// extendedAux.axisBias = 1e+20;
	// extendedAux.orbitTraps = 1e+20;
	// extendedAux.transformSampling = 1e+20;

	// main iteration loop
	int i;
	int sequence = 0;

	CVector3 lastGoodZ;
	CVector3 lastZ;

	for (i = 0; i < in.maxN; i++)
	{
		lastGoodZ = lastZ;
		lastZ = z;

		// hybrid fractal sequence
		if (in.forcedFormulaIndex >= 0)
		{
			sequence = in.forcedFormulaIndex;
		}
		else
		{
			sequence = fractals.GetSequence(i);
		}

		// foldings
		if (in.common.foldings.boxEnable)
		{
			BoxFolding(z, &in.common.foldings, extendedAux);
			r = z.Length();
		}

		if (in.common.foldings.sphericalEnable)
		{
			extendedAux.r = r;
			SphericalFolding(z, &in.common.foldings, extendedAux);
			r = z.Length();
		}

		const cFractal *fractal = fractals.GetFractal(sequence);
		formula = fractal->formula;

		// temporary vector for weight function
		CVector3 tempZ = z;

		extendedAux.r = r;

		if (!fractals.IsHybrid() || fractals.GetWeight(sequence) > 0.0)
		{
			// calls for fractal formulas
			switch (formula)
			{
				case mandelbulb:
				{
					MandelbulbIteration(z, fractal, extendedAux);
					break;
				}
				case mandelbulb2:
				{
					Mandelbulb2Iteration(z, extendedAux);
					break;
				}
				case mandelbulb3:
				{
					Mandelbulb3Iteration(z, extendedAux);
					break;
				}
				case mandelbulb4:
				{
					Mandelbulb4Iteration(z, fractal, extendedAux);
					break;
				}
				case fast_mandelbulb_power2:
				{
					MandelbulbPower2Iteration(z, extendedAux);
					break;
				}
				case xenodreambuie:
				{
					XenodreambuieIteration(z, fractal, extendedAux);
					break;
				}
				case mandelbox:
				{
					MandelboxIteration(z, fractal, extendedAux);
					break;
				}
				case smoothMandelbox:
				{
					SmoothMandelboxIteration(z, fractal, extendedAux);
					break;
				}
				case boxFoldBulbPow2:
				{
					BoxFoldBulbPow2Iteration(z, fractal);
					break;
				}
				case menger_sponge:
				{
					MengerSpongeIteration(z, extendedAux);
					break;
				}
				case kaleidoscopicIFS:
				{
					KaleidoscopicIFSIteration(z, fractal, extendedAux);
					break;
				}
				case aexion:
				{
					AexionIteration(z, w, i, fractal, extendedAux);
					break;
				}
				case hypercomplex:
				{
					HypercomplexIteration(z, w, extendedAux);
					break;
				}
				case quaternion:
				{
					QuaternionIteration(z, w, extendedAux);
					break;
				}
				case benesi:
				{
					BenesiIteration(z, c, extendedAux);
					break;
				}
				case bristorbrot:
				{
					BristorbrotIteration(z, extendedAux);
					break;
				}
				case ides:
				{
					IdesIteration(z, fractal);
					break;
				}
				case ides2:
				{
					Ides2Iteration(z, fractal);
					break;
				}
				case buffalo:
				{
					BuffaloIteration(z, fractal, extendedAux);
					break;
				}
				case quickdudley:
				{
					QuickDudleyIteration(z);
					break;
				}
				case quickDudleyMod:
				{
					QuickDudleyModIteration(z, fractal);
					break;
				}
				case lkmitch:
				{
					LkmitchIteration(z);
					break;
				}
				case makin3d2:
				{
					Makin3D2Iteration(z);
					break;
				}
				case msltoeDonut:
				{
					MsltoeDonutIteration(z, fractal, extendedAux);
					break;
				}
				case msltoesym2Mod:
				{
					MsltoeSym2ModIteration(z, c, fractal, extendedAux);
					break;
				}
				case msltoesym3Mod:
				{
					MsltoeSym3ModIteration(z, c, i, fractal, extendedAux);
					break;
				}
				case msltoesym3Mod2:
				{
					MsltoeSym3Mod2Iteration(z, c, fractal, extendedAux);
					break;
				}
				case msltoesym3Mod3:
				{
					MsltoeSym3Mod3Iteration(z, c, i, fractal, extendedAux);
					break;
				}
				case msltoesym4Mod:
				{
					MsltoeSym4ModIteration(z, c, fractal, extendedAux);
					break;
				}
				case msltoeToroidal:
				{
					MsltoeToroidalIteration(z, fractal, extendedAux);
					break;
				}
				case msltoeToroidalMulti:
				{
					MsltoeToroidalMultiIteration(z, fractal, extendedAux);
					break;
				}
				case generalizedFoldBox:
				{
					GeneralizedFoldBoxIteration(z, fractal, extendedAux);
					break;
				}
				case aboxMod1:
				{
					AboxMod1Iteration(z, fractal, extendedAux);
					break;
				}
				case aboxMod2:
				{
					AboxMod2Iteration(z, fractal, extendedAux);
					break;
				}
				case aboxModKali:
				{
					AboxModKaliIteration(z, fractal, extendedAux);
					break;
				}
				case aboxModKaliEiffie:
				{
					AboxModKaliEiffieIteration(z, c, i, fractal, extendedAux);
					break;
				}
				case aboxVSIcen1:
				{
					AboxVSIcen1Iteration(z, c, fractal, extendedAux);
					break;
				}
				case aexionOctopusMod:
				{
					AexionOctopusModIteration(z, c, fractal);
					break;
				}
				case amazingSurf:
				{
					AmazingSurfIteration(z, fractal, extendedAux);
					break;
				}
				case amazingSurfMod1:
				{
					AmazingSurfMod1Iteration(z, fractal, extendedAux);
					break;
				}
				case amazingSurfMulti:
				{
					AmazingSurfMultiIteration(z, i, fractal, extendedAux);
					break;
				}
				case benesiPineTree:
				{
					BenesiPineTreeIteration(z, c, fractal, extendedAux);
					break;
				}
				case benesiT1PineTree:
				{
					BenesiT1PineTreeIteration(z, c, i, fractal, extendedAux);
					break;
        }
        case benesiMagTransforms:
        {
          BenesiMagTransformsIteration(z, c, i, fractal, extendedAux);
           break;
        }
				case collatz:
				{
					CollatzIteration(z, extendedAux);
					break;
				}
				case collatzMod:
				{
					CollatzModIteration(z, c, fractal, extendedAux);
					break;
				}
				case eiffieMsltoe:
				{
					EiffieMsltoeIteration(z, c, fractal, extendedAux);
					break;
				}
				case foldBoxMod1:
				{
					FoldBoxMod1Iteration(z, i, fractal, extendedAux);
					break;
				}
				case iqBulb:
				{
					IQbulbIteration(z, fractal, extendedAux);
					break;
				}
				case kalisets1:
				{
					Kalisets1Iteration(z, c, fractal, extendedAux);
					break;
				}
				case mandelboxMenger:
				{
					MandelboxMengerIteration(z, c, i, fractal, extendedAux);
					break;
				}
				case mandelbulbBermarte:
				{
					MandelbulbBermarteIteration(z, fractal, extendedAux);
					break;
				}
				case mandelbulbKali:
				{
					MandelbulbKaliIteration(z, fractal, extendedAux);
					break;
				}
				case mandelbulbKaliMulti:
				{
					MandelbulbKaliMultiIteration(z, c, fractal, extendedAux);
					break;
				}
				case mandelbulbMulti:
				{
					MandelbulbMultiIteration(z, c, fractal, extendedAux);
					break;
				}
				case mandelbulbVaryPowerV1:
				{
					MandelbulbVaryPowerV1Iteration(z, i, fractal, extendedAux);
					break;
				}
				case mengerMod1:
				{
					MengerMod1Iteration(z, i, fractal, extendedAux);
					break;
				}
				case mengerMiddleMod:
				{
					MengerMiddleModIteration(z, c, i, fractal, extendedAux);
					break;
				}
				case mengerPrismShape:
				{
					MengerPrismShapeIteration(z, i, fractal, extendedAux);
					break;
				}
				case mengerPwr2Poly:
				{
					MengerPwr2PolyIteration(z, c, i, fractal, extendedAux);
					break;
				}
				case riemannSphereMsltoe:
				{
					RiemannSphereMsltoeIteration(z, fractal);
					break;
				}
				case riemannSphereMsltoeV1:
				{
					RiemannSphereMsltoeV1Iteration(z, fractal);
					break;
				}
				case riemannBulbMsltoeMod2:
				{
					RiemannBulbMsltoeMod2Iteration(z, fractal);
					break;
				}
				case quaternion3D:
				{
					Quaternion3DIteration(z, fractal, extendedAux);
					break;
				}
				case fastImagscaPower2:
				{
					FastImagscaPower2Iteration(z);
					break;
				}
				case crossMenger:
				{
					CrossMengerIteration(z, c, i, fractal, extendedAux);
					break;
				}

				// transforms
				// ------------------------------------------------------------------------------------------
				case transfAdditionConstant:
				{
					TransformAdditionConstantIteration(z, fractal);
					break;
				}
				case transfAdditionConstantVaryV1:
				{
					TransformAdditionConstantVaryV1Iteration(z, i, fractal);
					break;
				}
				case transfAddCpixel:
				{
					TransformAddCpixelIteration(z, c, fractal);
					break;
				}
				case transfAddCpixelAxisSwap:
				{
					TransformAddCpixelAxisSwapIteration(z, c, fractal);
					break;
				}
				case transfAddCpixelCxCyAxisSwap:
				{
					TransformAddCpixelCxCyAxisSwapIteration(z, c, fractal);
					break;
				}
				case transfAddCpixelPosNeg:
				{
					TransformAddCpixelPosNegIteration(z, c, fractal);
					break;
				}
				case transfAddCpixelVaryV1:
				{
					TransformAddCpixelVaryV1Iteration(z, c, i, fractal);
					break;
				}
				case transfBenesiT1:
				{
					TransformBenesiT1Iteration(z, fractal, extendedAux);
					break;
				}
				case transfBenesiT1Mod:
				{
					TransformBenesiT1ModIteration(z, fractal, extendedAux);
					break;
				}
				case transfBenesiT2:
				{
					TransformBenesiT2Iteration(z, fractal, extendedAux);
					break;
				}
				case transfBenesiT3:
				{
					TransformBenesiT3Iteration(z, fractal);
					break;
				}
				case transfBenesiT4:
				{
					TransformBenesiT4Iteration(z, fractal);
					break;
				}
				case transfBenesiT5b:
				{
					TransformBenesiT5bIteration(z, fractal);
					break;
				}
				case transfBenesiMagForward:
				{
					TransformBenesiMagForwardIteration(z);
					break;
				}
				case transfBenesiMagBackward:
				{
					TransformBenesiMagBackwardIteration(z);
					break;
				}
				case transfBenesiCubeSphere:
				{
					TransformBenesiCubeSphereIteration(z);
					break;
				}
				case transfBenesiSphereCube:
				{
					TransformBenesiSphereCubeIteration(z);
					break;
				}
				case transfBoxFold:
				{
					TransformBoxFoldIteration(z, fractal, extendedAux);
					break;
				}
				case transfBoxFoldXYZ:
				{
					TransformBoxFoldXYZIteration(z, fractal, extendedAux);
					break;
				}

				case transfBoxOffset:
				{
					TransformBoxOffsetIteration(z, fractal, extendedAux);
					break;
				}
				case transfFabsAddConstant:
				{
					TransformFabsAddConstantIteration(z, fractal);
					break;
				}
				case transfFabsAddConstantV2:
				{
					TransformFabsAddConstantV2Iteration(z, fractal);
					break;
				}
				case transfFabsAddMulti:
				{
					TransformFabsAddMultiIteration(z, fractal);
					break;
				}
        case transfFoldingTetra3D:
        {
          TransformFoldingTetra3DIteration(z, fractal);
          break;
        }
				case transfIterationWeight:
				{
					TransformIterationWeightIteration(z, i, fractal);
					break;
				}
				case transfInvCylindrical:
				{
					TransformInvCylindricalIteration(z, fractal, extendedAux);
					break;
				}

				case transfLinCombineCxyz:
				{
					TransformLinCombineCxyz(c, fractal);
					break;
				}
				case transfMultipleAngle:
				{
					TransformMultipleAngle(z, fractal, extendedAux);
					break;
				}
				case transfNegFabsAddConstant:
				{
					TransformNegFabsAddConstantIteration(z, fractal);
					break;
				}
				case transfPwr2Polynomial:
				{
					TransformPwr2PolynomialIteration(z, fractal, extendedAux);
					break;
				}
				case transfRotation:
				{
					TransformRotationIteration(z, fractal);
					break;
				}
				case transfRotationVaryV1:
				{
					TransformRotationVaryV1Iteration(z, i, fractal);
					break;
				}
        case transfRpow3:
        {
          TransformRpow3Iteration(z, fractal, extendedAux);
          break;
        }
				case transfScale:
				{
					TransformScaleIteration(z, fractal, extendedAux);
					break;
				}
				case transfScaleVaryV1:
				{
					TransformScaleVaryV1Iteration(z, i, fractal, extendedAux);
					break;
				}
				case transfScale3D:
				{
					TransformScale3DIteration(z, fractal, extendedAux);
					break;
				}
				case platonicSolid:
				{
					TransformPlatonicSolidIteration(z, fractal);
					break;
				}
				case transfRPower:
				{
					TransformPowerR(z, fractal, extendedAux);
					break;
				}
				case transfSphereInvC:
				{
					TransformSphereInvCIteration(z, c, fractal);
					break;
				}
        case transfSphereInv:
        {
          TransformSphereInvIteration(z, fractal, extendedAux);
          break;
        }

				case transfSphericalOffset:
				{
					TransformSphericalOffsetIteration(z, fractal, extendedAux);
					break;
				}
				case transfSphericalFold:
				{
					TransformSphericalFoldIteration(z, fractal, extendedAux);
					break;
				}
				case transfSphericalFoldAbox:
				{
					TransformSphericalFoldAboxIteration(z, fractal, extendedAux);
					break;
				}
				case transfSphericalFoldVaryV1:
				{
					TransformSphericalFoldVaryV1Iteration(z, i, fractal, extendedAux);
					break;
				}
				case transfSphericalPwrFold:
				{
					TransformSphericalPwrFoldIteration(z, fractal, extendedAux);
					break;
				}
				case transfSurfFoldMulti:
				{
					TransformSurfFoldMultiIteration(z, fractal, extendedAux);
					break;
				}
				case transfZvectorAxisSwap:
				{
					TransformZvectorAxisSwapIteration(z, fractal);
					break;
				}
				case transfRotationFoldingPlane:
				{
					TransformRotationFoldingPlane(z, fractal, extendedAux);
					break;
				}
				case transfQuaternionFold:
				{
					TransformQuaternionFoldIteration(z, c, fractal, extendedAux);
					break;
				}
				case transfMengerFold:
				{
					TransformMengerFoldIteration(z, fractal, extendedAux);
					break;
				}

				// 4D  ---------------------------------------------------------------------------
				case quaternion4D:
				{
					CVector4 z4D(z, w);
					Quaternion4DIteration(z4D, i, fractal);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case mandelboxVaryScale4D:
				{
					CVector4 z4D(z, w);
					MandelboxVaryScale4DIteration(z4D, i, fractal, extendedAux);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case transfAdditionConstant4D:
				{
					CVector4 z4D(z, w);
					TransformAdditionConstant4DIteration(z4D, fractal);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case transfBoxFold4D:
				{
					CVector4 z4D(z, w);
					TransformBoxFold4DIteration(z4D, fractal, extendedAux);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case transfFabsAddConstant4D:
				{
					CVector4 z4D(z, w);
					TransformFabsAddConstant4DIteration(z4D, fractal);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case transfFabsAddConstantV24D:
				{
					CVector4 z4D(z, w);
					TransformFabsAddConstantV24DIteration(z4D, fractal);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case transfIterationWeight4D:
				{
					CVector4 z4D(z, w);
					TransformIterationWeight4DIteration(z4D, i, fractal);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case transfScale4D:
				{
					CVector4 z4D(z, w);
					TransformScale4DIteration(z4D, fractal, extendedAux);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}
				case transfSphericalFold4D:
				{
					CVector4 z4D(z, w);
					TransformSphericalFold4DIteration(z4D, fractal, extendedAux);
					z = z4D.GetXYZ();
					w = z4D.w;
					break;
				}

				default:
					double high = fractals.GetBailout(sequence) * 10.0;
					z = CVector3(high, high, high);
					break;
			}
		}

		// addition of constant
		if (fractals.IsAddCConstant(sequence))
		{
			switch (formula)
			{
				case aboxMod1:
				case amazingSurf:
					// case amazingSurfMod1:
					{
						if (fractals.IsJuliaEnabled(sequence))
						{
							CVector3 juliaC =
								fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence);
							z += CVector3(juliaC.y, juliaC.x, juliaC.z);
						}
						else
						{
							z += CVector3(c.y, c.x, c.z) * fractals.GetConstantMultiplier(sequence);
						}
						break;
					}

				default:
				{
					if (fractals.IsJuliaEnabled(sequence))
					{
						z += fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence);
					}
					else
					{
						z += c * fractals.GetConstantMultiplier(sequence);
					}
					break;
				}
			}
		}

		if (fractals.IsHybrid())
		{
			z = SmoothCVector(tempZ, z, fractals.GetWeight(sequence));
		}

		// r calculation
		// r = sqrt(z.x * z.x + z.y * z.y + z.z * z.z + w * w);
		switch (fractal->formula)
		{
			case fastImagscaPower2:
			{
				CVector3 z2 = z * z;
				r = sqrt(z2.x + z2.y + z2.z) + (z2.y * z2.z) / (z2.x);
				break;
			}
			// scator magnitudes
			// magnitude in imaginary scator algebra

			default:
			{
				r = sqrt(z.x * z.x + z.y * z.y + z.z * z.z + w * w);
				break;
			}
		}

		if (z.IsNotANumber())
		{
			z = lastZ;
			r = z.Length();
			w = 0.0;
			out->maxiter = true;
			break;
		}

		// escape conditions
		if (fractals.IsCheckForBailout(sequence))
		{
			if (Mode == calcModeNormal)
			{
				if (r > fractals.GetBailout(sequence))
				{
					out->maxiter = false;
					break;
				}
			}
			else if (Mode == calcModeDeltaDE1)
			{
				if (r > fractals.GetBailout(sequence))
				{
					out->maxiter = false;
					break;
				}
			}
			else if (Mode == calcModeDeltaDE2)
			{
				if (i == in.maxN) break;
			}
			else if (Mode == calcModeColouring)
			{
				double len = 0.0;
				switch (in.fractalColoring.coloringAlgorithm)
				{
					case sFractalColoring::fractalColoringStandard:
					{
						len = r;
						break;
					}
					case sFractalColoring::fractalColoringZDotPoint:
					{
						len = fabs(z.Dot(in.point));
						break;
					}
					case sFractalColoring::fractalColoringSphere:
					{
						len = fabs((z - in.point).Length() - in.fractalColoring.sphereRadius);
						break;
					}
					case sFractalColoring::fractalColoringCross:
					{
						len = dMin(fabs(z.x), fabs(z.y), fabs(z.z));
						break;
					}
					case sFractalColoring::fractalColoringLine:
					{
						len = fabs(z.Dot(in.fractalColoring.lineDirection));
						break;
					}
					case sFractalColoring::fractalColoringNone:
					{
						len = r;
						break;
					}
				}
				if (fractal->formula != mandelbox
						|| in.fractalColoring.coloringAlgorithm != sFractalColoring::fractalColoringStandard)
				{
					if (len < minimumR) minimumR = len;
				}
				if (r > 1e15) break;
			}
			else if (Mode == calcModeOrbitTrap)
			{
				CVector3 delta = z - in.common.fakeLightsOrbitTrap;
				double distance = delta.Length();
				if (i >= in.common.fakeLightsMinIter && i <= in.common.fakeLightsMaxIter)
					orbitTrapTotal += (1.0f / (distance * distance));
				if (distance > 1000)
				{
					out->orbitTrapR = orbitTrapTotal;
					break;
				}
			}
		}

		if (z.IsNotANumber()) // detection of dead computation
		{
			// if(Mode != calcModeColouring)
			// qWarning() << "Dead computation\n"
			//		<< "iteration: " << i << "Formula:" << formula << "Sequence:" << sequence
			//		<< "\nPoint:" << in.point.Debug()
			//		<< "\nLast good z:" << lastGoodZ.Debug()
			//		<< "\nPrevious z:" << lastZ.Debug();
			z = lastGoodZ;
			break;
		}
	}

	// final calculations
	if (Mode == calcModeNormal)
	{
		if (fractals.IsHybrid())
		{
			if (extendedAux.r_dz > 0)
			{
				if (fractals.GetDEFunctionType(0) == fractal::linearDEFunction)
				{
					out->distance = r / fabs(extendedAux.DE);
				}
				else if (fractals.GetDEFunctionType(0) == fractal::logarithmicDEFunction)
				{
					out->distance = 0.5 * r * log(r) / extendedAux.r_dz;
				}
			}
			else
			{
				out->distance = r;
			}
		}
		else
		{
			switch (formula)
			{
				case benesi:
				case benesiPineTree:
				case benesiT1PineTree:
				case bristorbrot:
				case buffalo:
				case eiffieMsltoe:
				case fast_mandelbulb_power2:
				case hypercomplex:
				case iqBulb:
				case mandelbulb:
				case mandelbulb2:
				case mandelbulb3:
				case mandelbulb4:
				case mandelbulbBermarte:
				case mandelbulbKali:
				case mandelbulbKaliMulti:
				case mandelbulbMulti:
				case mandelbulbVaryPowerV1:
				case msltoesym2Mod:
				case msltoesym3Mod:
				case msltoesym3Mod2:
				case msltoesym3Mod3:
				case msltoesym4Mod:
				case msltoeToroidal:			// TODO fix??
				case msltoeToroidalMulti: // TODO fix??
				case quaternion:
				case transfQuaternionFold: // hmmm, this issue again
				case quaternion3D:
				case xenodreambuie:
				{
					if (extendedAux.r_dz > 0)
						out->distance = 0.5 * r * log(r) / extendedAux.r_dz;
					else
						out->distance = r;
					break;
				}
				case mandelbox:
				case mandelboxMenger:
				case smoothMandelbox:
				case mandelboxVaryScale4D:
				case generalizedFoldBox:
				case foldBoxMod1:
				case aboxModKali:
				case aboxModKaliEiffie:
				case aboxMod1:
				case aboxMod2:
				case amazingSurf:
				case amazingSurfMod1:
				case amazingSurfMulti:
				case kalisets1:
				case aboxVSIcen1:
				{
          if (extendedAux.DE > 0)
						out->distance = r / fabs(extendedAux.DE);
					else
						out->distance = r;
					break;
				}
				case kaleidoscopicIFS:
				case menger_sponge:
				case crossMenger:
				case mengerPrismShape:
				case collatz:
				case collatzMod:
				case mengerMod1:
				case mengerMiddleMod:
				case transfMengerFold: // hmmm, this issue again
				case mengerPwr2Poly:
				{
          if (extendedAux.DE > 0)
						out->distance = (r - 2.0) / (extendedAux.DE);
					else
						out->distance = r;
					break;
				}

				default: out->distance = -1.0; break;
			}
		}
	}
	// color calculation
  else if (Mode == calcModeColouring)
  {
    double mboxDE = 1.0;
    mboxDE = extendedAux.DE;
    double r2 = r / fabs(mboxDE);
    if (r2 > 20) r2 = 20;

    if (fractals.IsHybrid())
    {
      if (minimumR > 100) minimumR = 100;

      double mboxColor = 0.0;

      mboxColor = extendedAux.color;

      if (mboxColor > 1000) mboxColor = 1000;

      out->colorIndex = minimumR * 1000.0 + mboxColor * 100 + r2 * 5000.0;
      /*out->colorIndex =

        extendedAux.color * 100.0 * extendedAux.foldFactor	 // folds part

        + r * defaultFractal->mandelbox.color.factorR / 1e13 // abs z part

        + 1.0 * r2 * 5000.0 // for backwards compatability

        + extendedAux.scaleFactor * r * i / 1e15						 // scale part conditional on i & r
        + ((in.fractalColoring.coloringAlgorithm != sFractalColoring::fractalColoringStandard)
              ? minimumR * extendedAux.minRFactor * 1000.0
              : 0.0);*/
		}
		else
		{
			switch (formula)
			{
				case mandelbox:
				case smoothMandelbox:
				case mandelboxVaryScale4D:
				case generalizedFoldBox:
				case amazingSurfMod1:
				case foldBoxMod1:
					out->colorIndex =
						extendedAux.color * 100.0														 // folds part
						+ r * defaultFractal->mandelbox.color.factorR / 1e13 // abs z part
						+ ((in.fractalColoring.coloringAlgorithm != sFractalColoring::fractalColoringStandard)
									? minimumR * 1000.0
									: 0.0);
					break;

				case mengerMod1:
				case aboxModKali:
				case aboxMod1:
				case menger_sponge:
				case collatz:
				case collatzMod:
				case kaleidoscopicIFS:
				case mengerPwr2Poly:
				case mengerMiddleMod: out->colorIndex = minimumR * 1000.0; break;

				case amazingSurf: out->colorIndex = minimumR * 200.0; break;

				case amazingSurfMulti:
				case mandelboxMenger:
					// case amazingSurfMod1:

					out->colorIndex =
						extendedAux.color * 100.0 * extendedAux.foldFactor	 // folds part
						+ r * defaultFractal->mandelbox.color.factorR / 1e13 // abs z part
            +  extendedAux.scaleFactor * r2 * 5000.0 // for backwards compatability
            //+ extendedAux.scaleFactor * r * i / 1e15						 // scale part conditional on i & r
						+ ((in.fractalColoring.coloringAlgorithm != sFractalColoring::fractalColoringStandard)
									? minimumR * extendedAux.minRFactor * 1000.0
									: 0.0);
					break;

				case msltoeDonut: out->colorIndex = extendedAux.color * 2000.0 / i; break;

				default: out->colorIndex = minimumR * 5000.0; break;
			}
		}
	}
	else
	{
		out->distance = 0.0;
	}

	out->iters = i + 1;
	out->z = z; // CVector3( z.x, z.y, w);
	// tim = rdtsc() - tim; perf+= tim; perfCount++; outStream << (double)perf/perfCount - 560.0 <<
	// endl;
	//------------- 3249 ns for all calculation  ----------------
}