41 *retReal = (*r1)*(*r2) - (*i1)*(*i2);
42 *retImag = (*r1)*(*i2) + (*i1)*(*r2);
65 *retReal = (*r1)*(*r2) + (*i1)*(*i2);
66 *retImag = -(*r1)*(*i2) + (*i1)*(*r2);
86 proshade_double ret = (*r1)*(*r2) - (*i1)*(*i2);
106 proshade_double ret = (*r1)*(*r2) + (*i1)*(*i2);
124 ret[0] = std::accumulate ( vec->begin(), vec->end(), 0.0 ) /
static_cast<proshade_double
> ( vec->size() );
127 proshade_double squaredSum = std::inner_product ( vec->begin(), vec->end(), vec->begin(), 0.0 );
128 ret[1] = std::sqrt ( ( squaredSum /
static_cast<proshade_double
> ( vec->size() ) ) - std::pow ( ret[0], 2.0 ) );
131 const FloatingPoint< proshade_double > lhs1 ( ret[0] );
132 const FloatingPoint< proshade_double > lhs2 ( ret[1] );
133 if ( !lhs1.AlmostEquals ( lhs1 ) ) { ret[0] = 0.0; }
134 if ( !lhs2.AlmostEquals ( lhs2 ) ) { ret[1] = 0.0; }
152 if ( vec->size() < 3 ) { ret[0] = 0.0; ret[1] = 0.0;
return; }
155 std::sort ( vec->begin(), vec->end() );
158 if (
static_cast<proshade_unsign
> ( vec->size() ) % 2 == 0)
160 ret[0] = ( vec->at( (
static_cast<proshade_unsign
> ( vec->size() ) / 2 ) - 1 ) +
161 vec->at(
static_cast<proshade_unsign
> ( vec->size() ) / 2 ) ) / 2.0;
165 ret[0] = vec->at(
static_cast<proshade_unsign
> ( vec->size() ) / 2 );
169 proshade_double Q1, Q3;
170 if (
static_cast<proshade_unsign
> ( vec->size() ) % 2 == 0)
172 Q1 = ( vec->at( (
static_cast<proshade_unsign
> ( vec->size() ) / 4 ) - 1 ) +
173 vec->at(
static_cast<proshade_unsign
> ( vec->size() ) / 4 ) ) / 2.0;
174 Q3 = ( vec->at( ( (
static_cast<proshade_unsign
> ( vec->size() ) / 4 ) * 3 ) - 1 ) +
175 vec->at( (
static_cast<proshade_unsign
> ( vec->size() ) / 4 ) * 3 ) ) / 2.0;
179 Q1 = vec->at(
static_cast<proshade_unsign
> ( vec->size() ) / 4 );
180 Q3 = vec->at( (
static_cast<proshade_unsign
> ( vec->size() ) / 4 ) * 3 );
203 std::sort ( vec, vec + vecSize );
206 if ( vecSize % 2 == 0)
208 ret[0] = ( vec[ ( vecSize / 2 ) - 1 ] + vec[ vecSize / 2 ] ) / 2.0;
212 ret[0] = vec[ vecSize / 2 ];
216 proshade_double Q1, Q3;
217 if ( vecSize % 2 == 0)
219 Q1 = ( vec[ ( vecSize / 4 ) - 1 ] + vec[ vecSize / 4 ] ) / 2.0;
220 Q3 = ( vec[ ( ( vecSize / 4 ) * 3 ) - 1 ] + vec[ ( vecSize / 4 ) * 3 ] ) / 2.0;
224 Q1 = vec[ vecSize / 4 ];
225 Q3 = vec[ ( vecSize / 4 ) * 3 ];
249 proshade_double xMean = 0.0;
250 proshade_double yMean = 0.0;
251 proshade_double zeroCount = 0.0;
252 for ( proshade_unsign iter = 0; iter < length; iter++ )
254 xMean += valSet1[iter];
255 yMean += valSet2[iter];
257 xMean /=
static_cast<proshade_double
> ( length ) - zeroCount;
258 yMean /=
static_cast<proshade_double
> ( length ) - zeroCount;
261 proshade_double xmmymm = 0.0;
262 proshade_double xmmsq = 0.0;
263 proshade_double ymmsq = 0.0;
264 for ( proshade_unsign iter = 0; iter < length; iter++ )
266 xmmymm += ( valSet1[iter] - xMean ) * ( valSet2[iter] - yMean );
267 xmmsq += pow( valSet1[iter] - xMean, 2.0 );
268 ymmsq += pow( valSet2[iter] - yMean, 2.0 );
271 proshade_double ret = xmmymm / ( sqrt(xmmsq) * sqrt(ymmsq) );
274 if ( std::isnan ( ret ) ) {
return ( 0.0 ); }
294 throw ProSHADE_exception (
"The integration order is too low.",
"EI00019", __FILE__, __LINE__, __func__,
"The Gauss-Legendre integration order is less than 2. This\n : seems very low; if you have a very small structure or very\n : low resolution, please manually increase the integration\n : order. Otherwise, please report this as a bug." );
298 proshade_double polyValue = 0.0;
299 proshade_double deriValue = 0.0;
300 proshade_double weightSum = 0.0;
308 if ( order % 2 == 1 )
310 abscissas[((order-1)/2)] = polyValue;
311 weights[((order-1)/2)] = deriValue;
316 getGLFirstEvenRoot ( polyValue, order, &abscissas[(order/2)], &weights[(order/2)], taylorSeriesCap );
323 for ( proshade_unsign iter = 0; iter < order; iter++ )
325 weights[iter] = 2.0 / ( 1.0 - abscissas[iter] ) / ( 1.0 + abscissas[iter] ) / weights[iter] / weights[iter];
326 weightSum = weightSum + weights[iter];
330 for ( proshade_unsign iter = 0; iter < order; iter++ )
332 weights[iter] = 2.0 * weights[iter] / weightSum;
352 proshade_double hlpVal = 0.0;
353 proshade_double prevPoly = 1.0;
354 proshade_double prevPrevPoly = 0.0;
355 proshade_double prevDeri = 0.0;
356 proshade_double prevPrevDeri = 0.0;
358 for ( proshade_unsign ordIt = 0; ordIt < order; ordIt++ )
360 hlpVal =
static_cast<proshade_double
> ( ordIt );
361 *polyValue = -hlpVal * prevPrevPoly / ( hlpVal + 1.0 );
362 *deriValue = ( ( 2.0 * hlpVal + 1.0 ) * prevPoly - hlpVal * prevPrevDeri ) / ( hlpVal + 1.0 );
363 prevPrevPoly = prevPoly;
364 prevPoly = *polyValue;
365 prevPrevDeri = prevDeri;
366 prevDeri = *deriValue;
389 if ( taylorSeriesCap < 2 )
391 throw ProSHADE_exception (
"The Taylor series cap is too low.",
"EI00020", __FILE__, __LINE__, __func__,
"The Taylor series expansion limit is less than 2. This\n : seems very low; if you have a very small structure or very\n : low resolution, please manually increase the integration\n : order. Otherwise, please report this as a bug." );
396 proshade_double hlp = 0.0;
397 proshade_double hlpVal =
static_cast<proshade_double
> ( order );
398 proshade_double *abscSteps;
399 proshade_double *weightSteps;
402 abscSteps =
new proshade_double [taylorSeriesCap+2];
403 weightSteps =
new proshade_double [taylorSeriesCap+1];
407 abscSteps[1] = polyAtZero;
408 weightSteps[0] = 0.0;
411 for ( proshade_unsign iter = 0; iter <= taylorSeriesCap - 2; iter = iter + 2 )
413 hlp =
static_cast<proshade_double
> ( iter );
415 abscSteps[iter+2] = 0.0;
416 abscSteps[iter+3] = ( hlp * ( hlp + 1.0 ) - hlpVal * ( hlpVal + 1.0 ) ) * abscSteps[iter+1] / (hlp + 1.0) / (hlp + 2.0 );
418 weightSteps[iter+1] = 0.0;
419 weightSteps[iter+2] = ( hlp + 2.0 ) * abscSteps[iter+3];
423 for ( proshade_double iter = 0; iter < 5; iter++ )
425 *abscAtZero = *abscAtZero -
evaluateGLSeries ( abscSteps, *abscAtZero, taylorSeriesCap ) /
evaluateGLSeries ( weightSteps, *abscAtZero, taylorSeriesCap-1 );
427 *weighAtZero =
evaluateGLSeries ( weightSteps, *abscAtZero, taylorSeriesCap-1 );
452 proshade_double factorialValue = 1.0;
453 proshade_double value = 0.0;
456 for ( proshade_unsign iter = 1; iter <= terms; iter++ )
458 value = value + series[iter] * factorialValue;
459 factorialValue = factorialValue * target;
482 proshade_double hlpVal = 0.0;
483 proshade_double stepSize = 0.0;
484 proshade_double valChange = 0.0;
485 proshade_double valSecChange = 0.0;
486 proshade_double squareSteps = 0.0;
487 proshade_double curVal = 0.0;
490 stepSize = ( to - from ) /
static_cast<proshade_double
> ( taylorSeriesCap );
491 squareSteps = sqrt (
static_cast<proshade_double
> ( noSteps * ( noSteps + 1 ) ) );
495 for ( proshade_unsign iter = 0; iter < taylorSeriesCap; iter++ )
497 hlpVal = ( 1.0 - valAtFrom ) * ( 1.0 + valAtFrom );
498 valChange = - stepSize * hlpVal / ( squareSteps * sqrt ( hlpVal ) - 0.5 * valAtFrom * sin ( 2.0 * curVal ) );
499 valAtFrom = valAtFrom + valChange;
501 curVal = curVal + stepSize;
503 hlpVal = ( 1.0 - valAtFrom ) * ( 1.0 + valAtFrom );
504 valSecChange = - stepSize * hlpVal / ( squareSteps * sqrt ( hlpVal ) - 0.5 * valAtFrom * sin ( 2.0 * curVal ) );
505 valAtFrom = valAtFrom + 0.5 * ( valSecChange - valChange );
526 proshade_double hlpTaylorVal = 0.0;
527 proshade_double hlpOrderVal =
static_cast<proshade_double
> ( order );
528 proshade_double abscValueChange = 0.0;
529 proshade_double prevAbsc = 0.0;
530 proshade_double *hlpAbscSeries;
531 proshade_double *hlpWeightSeries;
532 proshade_unsign noSeriesElems = 0;
533 proshade_unsign oddEvenSwitch = 0;
536 if ( order % 2 == 1 )
538 noSeriesElems = ( order - 1 ) / 2 - 1;
543 noSeriesElems = order / 2 - 1;
548 hlpAbscSeries =
new proshade_double[taylorSeriesCap+2];
549 hlpWeightSeries =
new proshade_double[taylorSeriesCap+1];
552 for ( proshade_unsign serIt = noSeriesElems + 1; serIt < order - 1; serIt++ )
555 prevAbsc = abscissas[serIt];
556 abscValueChange =
advanceGLPolyValue ( M_PI/2.0, -M_PI/2.0, prevAbsc, order, taylorSeriesCap ) - prevAbsc;
559 hlpAbscSeries[0] = 0.0;
560 hlpAbscSeries[1] = 0.0;
561 hlpAbscSeries[2] = weights[serIt];
564 hlpWeightSeries[0] = 0.0;
565 hlpWeightSeries[1] = hlpAbscSeries[2];
568 for ( proshade_unsign tayIt = 0; tayIt <= taylorSeriesCap - 2; tayIt++ )
570 hlpTaylorVal =
static_cast<proshade_double
> ( tayIt );
572 hlpAbscSeries[tayIt+3] = ( 2.0 * prevAbsc * ( hlpTaylorVal + 1.0 ) * hlpAbscSeries[tayIt+2] + ( hlpTaylorVal * ( hlpTaylorVal + 1.0 ) - hlpOrderVal *
573 ( hlpOrderVal + 1.0 ) ) * hlpAbscSeries[tayIt+1] / ( hlpTaylorVal + 1.0 ) ) / ( 1.0 - prevAbsc ) / ( 1.0 + prevAbsc ) /
574 ( hlpTaylorVal + 2.0 );
576 hlpWeightSeries[tayIt+2] = ( hlpTaylorVal + 2.0 ) * hlpAbscSeries[tayIt+3];
580 for ( proshade_unsign iter = 0; iter < 5; iter++ )
582 abscValueChange = abscValueChange -
evaluateGLSeries ( hlpAbscSeries, abscValueChange, taylorSeriesCap ) /
587 abscissas[serIt+1] = prevAbsc + abscValueChange;
588 weights[serIt+1] =
evaluateGLSeries ( hlpWeightSeries, abscValueChange, taylorSeriesCap - 1 );
591 for ( proshade_unsign serIt = 0; serIt <= noSeriesElems + oddEvenSwitch; serIt++ )
593 abscissas[serIt] = -abscissas[order-serIt-1];
594 weights[serIt] = weights[order-serIt-1];
598 delete hlpAbscSeries;
599 delete hlpWeightSeries;
624 proshade_double ret = 0.0;
625 proshade_complex* intData =
new proshade_complex[order];
627 proshade_complex posVals;
628 proshade_unsign lesserPos = 0;
629 proshade_unsign upperPos = 0;
630 proshade_double lesserWeight = 0.0;
631 proshade_double upperWeight = 0.0;
634 for ( proshade_unsign absIter = 0; absIter < order; absIter++ )
641 posVals[0] = ( ( abscissas[absIter] + 1.0 ) / 2.0 ) * integralOverRange;
645 for ( proshade_unsign valIt = 0; valIt < valsSize; valIt++ )
647 if ( ( (
static_cast< proshade_double
> ( valIt ) * maxSphereDists ) <= posVals[0] ) && ( ( (
static_cast< proshade_double
> ( valIt ) + 1.0 ) * maxSphereDists ) > posVals[0] ) )
649 lesserPos =
static_cast<proshade_unsign
> ( valIt );
650 upperPos =
static_cast<proshade_unsign
> ( valIt + 1 );
658 if ( lesserPos != 0 )
661 lesserWeight =
static_cast< proshade_double
> ( upperPos ) - ( posVals[0] / maxSphereDists );
662 upperWeight = 1.0 - lesserWeight;
664 posVals[1] = ( lesserWeight * vals[lesserPos-1] ) + ( upperWeight * vals[upperPos-1] );
669 upperWeight = 1.0 - (
static_cast< proshade_double
> ( upperPos ) - ( posVals[0] / maxSphereDists ) );
671 posVals[1] = ( upperWeight * vals[upperPos-1] );
674 intData[absIter][0] = posVals[0];
675 intData[absIter][1] = posVals[1];
679 for ( proshade_unsign absPoint = 0; absPoint < order; absPoint++ )
681 ret += ( weights[absPoint] * intData[absPoint][1] );
685 ret *= ( integralOverRange / 2.0 );
711 void ProSHADE_internal_maths::gaussLegendreIntegration ( proshade_complex* vals, proshade_unsign valsSize, proshade_unsign order, proshade_double* abscissas, proshade_double* weights, proshade_double integralOverRange, proshade_double maxSphereDists, proshade_double* retReal, proshade_double* retImag )
714 proshade_triplet* intData =
new proshade_triplet [order];
716 proshade_triplet posVals;
717 proshade_unsign lesserPos = 0;
718 proshade_unsign upperPos = 0;
719 proshade_double lesserWeight = 0.0;
720 proshade_double upperWeight = 0.0;
723 for ( proshade_unsign absIter = 0; absIter < order; absIter++ )
731 posVals[0] = ( ( abscissas[absIter] + 1.0 ) / 2.0 ) * integralOverRange;
735 for ( proshade_unsign valIt = 0; valIt < valsSize; valIt++ )
737 if ( ( (
static_cast< proshade_double
> ( valIt ) * maxSphereDists ) <= posVals[0] ) && ( ( (
static_cast< proshade_double
> ( valIt ) + 1.0 ) * maxSphereDists ) > posVals[0] ) )
739 lesserPos =
static_cast<proshade_unsign
> ( valIt );
740 upperPos =
static_cast<proshade_unsign
> ( valIt + 1 );
748 if ( lesserPos != 0 )
751 lesserWeight =
static_cast< proshade_double
> ( upperPos ) - ( posVals[0] / maxSphereDists );
752 upperWeight = 1.0 - lesserWeight;
754 posVals[1] = ( lesserWeight * vals[lesserPos-1][0] ) + ( upperWeight * vals[upperPos-1][0] );
755 posVals[2] = ( lesserWeight * vals[lesserPos-1][1] ) + ( upperWeight * vals[upperPos-1][1] );
760 upperWeight = 1.0 - (
static_cast< proshade_double
> ( upperPos ) - ( posVals[0] / maxSphereDists ) );
762 posVals[1] = ( upperWeight * vals[upperPos-1][0] );
763 posVals[2] = ( upperWeight * vals[upperPos-1][1] );
766 intData[absIter][0] = posVals[0];
767 intData[absIter][1] = posVals[1];
768 intData[absIter][2] = posVals[2];
774 for ( proshade_unsign absPoint = 0; absPoint < order; absPoint++ )
776 *retReal += ( weights[absPoint] * intData[absPoint][1] );
777 *retImag += ( weights[absPoint] * intData[absPoint][2] );
781 *retReal *= ( integralOverRange / 2.0 );
782 *retImag *= ( integralOverRange / 2.0 );
808 std::complex<double> *rotMatU =
new std::complex<double> [dim*dim];
809 std::complex<double> *rotMatV =
new std::complex<double> [dim*dim];
810 std::complex<double> *work =
new std::complex<double> [( 4 * dim)];
811 int workDim = ( 4 * dim);
812 double* rwork =
new double[(7 * dim)];
813 int* iwork =
new int[(8 * dim)];
824 std::complex<double> *matrixToDecompose =
new std::complex<double>[dim*dim];
826 for (
int rowIt = 0; rowIt < dim; rowIt++ )
828 for (
int colIt = 0; colIt < dim; colIt++ )
830 matrixToDecompose[(colIt*dim)+rowIt] = std::complex<double> ( mat[rowIt][colIt][0], mat[rowIt][colIt][1] );
835 zgesdd_ ( &job, &dim, &dim, matrixToDecompose, &dim, singularValues, rotMatU, &dim, rotMatV, &dim,
836 work, &workDim, rwork, iwork, &returnValue );
844 delete[] matrixToDecompose;
847 if ( returnValue != 0 )
849 throw ProSHADE_exception (
"The LAPACK complex SVD algorithm did not converge!",
"EL00021", __FILE__, __LINE__, __func__,
"LAPACK algorithm for computing the singular value\n : decomposition of complex matrices did not converge and\n : therefore it was not possible to combine SH coefficients\n : from multiple shells. Changing the resolution may help,\n : contact me if this error persists." );
875 double* singularValues =
new double[dim];
876 double *rotMatU =
new double [dim*dim];
877 double *rotMatV =
new double [dim*dim];
878 double *work =
new double [
static_cast< proshade_unsign
>( ( 3 * dim ) + pow( dim, 2 ) * dim)];
879 int workDim =
static_cast< int > ( 2 * ( ( 4 * dim * dim ) + ( 7 * dim ) ) );
880 double* rwork =
new double[
static_cast<proshade_unsign
>((5 * dim) + 5 * pow(dim,2))];
881 int* iwork =
new int[(8 * dim)];
891 double *matrixToDecompose =
new double[dim*dim];
893 for (
int rowIt = 0; rowIt < dim; rowIt++ )
895 for (
int colIt = 0; colIt < dim; colIt++ )
897 matrixToDecompose[(colIt*dim)+rowIt] = mat[(rowIt*dim)+colIt];
902 dgesdd_ ( &job, &dim, &dim, matrixToDecompose, &dim, singularValues, rotMatU, &dim, rotMatV, &dim,
903 work, &workDim, rwork, iwork, &returnValue );
909 delete[] matrixToDecompose;
910 delete[] singularValues;
913 if ( ( returnValue != 0 ) && ( fail ) )
915 throw ProSHADE_exception (
"The LAPACK complex SVD algorithm did not converge!",
"EL00022", __FILE__, __LINE__, __func__,
"LAPACK algorithm for computing the singular value\n : decomposition of complex matrices did not converge and\n : therefore it was not possible to optimise the peak\n : positions in the (self-)rotation function. Changing the\n : resolution may help, contact me if this error persists." );
917 if ( ( returnValue != 0 ) && ( !fail ) )
924 for ( proshade_signed rowIt = 0; rowIt < dim; rowIt++ )
926 for ( proshade_signed colIt = 0; colIt < dim; colIt++ )
928 uAndV[(rowIt*3)+colIt] = rotMatU[( rowIt * 3 ) + colIt];
933 for ( proshade_signed rowIt = 0; rowIt < dim; rowIt++ )
935 for ( proshade_signed colIt = 0; colIt < dim; colIt++ )
937 uAndV[(rowIt*3)+colIt+9] = rotMatV[( rowIt * 3 ) + colIt];
966 *eulerAlpha = M_PI *
static_cast<proshade_double
> ( y ) / (
static_cast<proshade_double
> ( band ) ) ;
967 *eulerBeta = M_PI * ( 2.0 *
static_cast<proshade_double
> ( x ) ) / ( 4.0 *
static_cast<proshade_double
> ( band ) ) ;
968 *eulerGamma = M_PI *
static_cast<proshade_double
> ( z ) / (
static_cast<proshade_double
> ( band ) ) ;
991 *x = ( eulerBeta *
static_cast<proshade_double
> ( band ) * 2.0 ) / M_PI;
992 *y = ( eulerGamma *
static_cast<proshade_double
> ( band ) ) / M_PI;
993 *z = ( eulerAlpha *
static_cast<proshade_double
> ( band ) ) / M_PI;
996 if ( eulerBeta > ( M_PI - 0.05 ) )
999 *z = ( ( eulerAlpha - eulerGamma ) *
static_cast<proshade_double
> ( band ) ) / M_PI;
1004 if ( *x >= ( 2 * band ) ) { *x = ( 2 * band ) - 1; }
1005 if ( *y >= ( 2 * band ) ) { *y = ( 2 * band ) - 1; }
1006 if ( *z >= ( 2 * band ) ) { *z = ( 2 * band ) - 1; }
1023 matrix[0] = cos ( eulerAlpha ) * cos ( eulerBeta ) * cos ( eulerGamma ) - sin ( eulerAlpha ) * sin ( eulerGamma );
1024 matrix[1] = sin ( eulerAlpha ) * cos ( eulerBeta ) * cos ( eulerGamma ) + cos ( eulerAlpha ) * sin ( eulerGamma );
1025 matrix[2] = -sin ( eulerBeta ) * cos ( eulerGamma );
1028 matrix[3] = -cos ( eulerAlpha ) * cos ( eulerBeta ) * sin ( eulerGamma ) - sin ( eulerAlpha ) * cos ( eulerGamma );
1029 matrix[4] = -sin ( eulerAlpha ) * cos ( eulerBeta ) * sin ( eulerGamma ) + cos ( eulerAlpha ) * cos ( eulerGamma );
1030 matrix[5] = sin ( eulerBeta ) * sin ( eulerGamma );
1033 matrix[6] = cos ( eulerAlpha ) * sin ( eulerBeta );
1034 matrix[7] = sin ( eulerAlpha ) * sin ( eulerBeta );
1035 matrix[8] = cos ( eulerBeta );
1052 matrix[0] = cos ( eulerAlpha ) * cos ( eulerBeta ) * cos ( eulerGamma ) - sin ( eulerAlpha ) * sin ( eulerGamma );
1053 matrix[1] = sin ( eulerAlpha ) * cos ( eulerBeta ) * cos ( eulerGamma ) + cos ( eulerAlpha ) * sin ( eulerGamma );
1054 matrix[2] = -sin ( eulerBeta ) * cos ( eulerGamma );
1057 matrix[3] = -cos ( eulerAlpha ) * cos ( eulerBeta ) * sin ( eulerGamma ) - sin ( eulerAlpha ) * cos ( eulerGamma );
1058 matrix[4] = -sin ( eulerAlpha ) * cos ( eulerBeta ) * sin ( eulerGamma ) + cos ( eulerAlpha ) * cos ( eulerGamma );
1059 matrix[5] = sin ( eulerBeta ) * sin ( eulerGamma );
1062 matrix[6] = cos ( eulerAlpha ) * sin ( eulerBeta );
1063 matrix[7] = sin ( eulerAlpha ) * sin ( eulerBeta );
1064 matrix[8] = cos ( eulerBeta );
1087 proshade_double angleTolerance = 0.01;
1088 proshade_double closeToZero = 0.0000001;
1091 *ang = std::acos ( ( std::max ( -1.0, std::min ( 3.0, rotMat[0] + rotMat[4] + rotMat[8] ) ) - 1.0 ) / 2.0 );
1094 if ( std::abs ( std::sin ( *ang ) ) < angleTolerance )
1097 char jobLeftEigs =
'N';
1098 char jobRightEigs =
'V';
1100 double* eigValReal =
new double[dim];
1101 double* eigValImag =
new double[dim];
1102 double* leftEigVectors =
new double[dim*dim*2];
1103 double* rightEigVectors =
new double[dim*dim*2];
1104 double* work =
new double[10*4*dim];
1105 int workSize = 10*4*dim;
1106 int returnValue = 0;
1116 double* matrixToDecompose =
new double[dim*dim];
1118 for (
int rowIt = 0; rowIt < dim; rowIt++ )
1120 for (
int colIt = 0; colIt < dim; colIt++ )
1122 matrixToDecompose[(colIt*dim)+rowIt] =
static_cast< double > ( rotMat[(rowIt*dim)+colIt] );
1127 dgeev_ ( &jobLeftEigs, &jobRightEigs, &dim, matrixToDecompose, &dim, eigValReal, eigValImag, leftEigVectors, &dim,
1128 rightEigVectors, &dim, work, &workSize, &returnValue );
1131 if ( returnValue != 0 )
1140 delete[] eigValReal;
1141 delete[] eigValImag;
1142 delete[] leftEigVectors;
1143 delete[] rightEigVectors;
1145 delete[] matrixToDecompose;
1152 for (
int i = 0; i < 9; i++ ) {
if ( std::abs(rightEigVectors[i]) < closeToZero ) { rightEigVectors[i] = 0.0; } }
1153 for (
int i = 0; i < 3; i++ ) {
if ( std::abs(eigValReal[i]) < closeToZero ) { eigValReal[i] = 0.0; }
if ( std::abs(eigValImag[i]) < closeToZero ) { eigValImag[i] = 0.0; } }
1156 proshade_signed eigIt = -1;
1157 for (
size_t it = 0; it < 3; it++ )
1159 if ( ( eigValReal[it] > ( 1.0 - closeToZero ) ) && ( eigValReal[it] < ( 1.0 + closeToZero ) ) )
1161 if ( ( eigValImag[it] > ( 0.0 - closeToZero ) ) && ( eigValImag[it] < ( 0.0 + closeToZero ) ) )
1163 eigIt =
static_cast< proshade_signed
> ( it );
1181 for(
int rowIt = 0; rowIt < dim; rowIt++ )
1184 while( colIt < dim )
1186 if( std::abs ( eigValImag[colIt] ) < closeToZero )
1188 if ( colIt == eigIt ) {
if ( rowIt == 0 ) { *x = rightEigVectors[rowIt+colIt*dim]; }
if ( rowIt == 1 ) { *y = rightEigVectors[rowIt+colIt*dim]; }
if ( rowIt == 2 ) { *z = rightEigVectors[rowIt+colIt*dim]; } }
1204 proshade_double normFactor = std::sqrt ( pow ( *x, 2.0 ) + pow ( *y, 2.0 ) + pow ( *z, 2.0 ) );
1211 delete[] eigValReal;
1212 delete[] eigValImag;
1213 delete[] leftEigVectors;
1214 delete[] rightEigVectors;
1216 delete[] matrixToDecompose;
1221 *x = rotMat[7] - rotMat[5];
1222 *y = rotMat[2] - rotMat[6];
1223 *z = rotMat[3] - rotMat[1];
1225 proshade_double normFactor = std::sqrt ( pow ( *x, 2.0 ) + pow ( *y, 2.0 ) + pow ( *z, 2.0 ) );
1231 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( *x ), std::max ( std::abs ( *y ), std::abs ( *z ) ) ) );
1232 const FloatingPoint< proshade_double > rhs1 ( std::abs ( *x ) );
1233 const FloatingPoint< proshade_double > rhs2 ( std::abs ( *y ) );
1234 const FloatingPoint< proshade_double > rhs3 ( std::abs ( *z ) );
1235 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( *x < 0.0 ) ) ||
1236 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( *y < 0.0 ) ) ||
1237 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( *z < 0.0 ) ) )
1247 if ( *ang < 0.0 ) { *ang = ( 2.0 * M_PI ) + *ang; }
1270 proshade_double angleTolerance = 0.01;
1271 proshade_double closeToZero = 0.0000001;
1274 *ang = std::acos ( ( std::max ( -1.0, std::min ( 3.0, rotMat->at(0) + rotMat->at(4) + rotMat->at(8) ) ) - 1.0 ) / 2.0 );
1277 if ( std::abs ( std::sin ( *ang ) ) < angleTolerance )
1280 char jobLeftEigs =
'N';
1281 char jobRightEigs =
'V';
1283 double* eigValReal =
new double[dim];
1284 double* eigValImag =
new double[dim];
1285 double* leftEigVectors =
new double[dim*dim*2];
1286 double* rightEigVectors =
new double[dim*dim*2];
1287 double* work =
new double[10*4*dim];
1288 int workSize = 10*4*dim;
1289 int returnValue = 0;
1299 double* matrixToDecompose =
new double[dim*dim];
1301 for (
int rowIt = 0; rowIt < dim; rowIt++ )
1303 for (
int colIt = 0; colIt < dim; colIt++ )
1305 matrixToDecompose[(colIt*dim)+rowIt] =
static_cast< double > ( rotMat->at(
static_cast< size_t > ( ( rowIt * dim ) + colIt ) ) );
1310 dgeev_ ( &jobLeftEigs, &jobRightEigs, &dim, matrixToDecompose, &dim, eigValReal, eigValImag, leftEigVectors, &dim,
1311 rightEigVectors, &dim, work, &workSize, &returnValue );
1314 if ( returnValue != 0 )
1323 delete[] eigValReal;
1324 delete[] eigValImag;
1325 delete[] leftEigVectors;
1326 delete[] rightEigVectors;
1328 delete[] matrixToDecompose;
1335 for (
int i = 0; i < 9; i++ ) {
if ( std::abs(rightEigVectors[i]) < closeToZero ) { rightEigVectors[i] = 0.0; } }
1336 for (
int i = 0; i < 3; i++ ) {
if ( std::abs(eigValReal[i]) < closeToZero ) { eigValReal[i] = 0.0; }
if ( std::abs(eigValImag[i]) < closeToZero ) { eigValImag[i] = 0.0; } }
1339 proshade_signed eigIt = -1;
1340 for (
size_t it = 0; it < 3; it++ )
1342 if ( ( eigValReal[it] > ( 1.0 - closeToZero ) ) && ( eigValReal[it] < ( 1.0 + closeToZero ) ) )
1344 if ( ( eigValImag[it] > ( 0.0 - closeToZero ) ) && ( eigValImag[it] < ( 0.0 + closeToZero ) ) )
1346 eigIt =
static_cast< proshade_signed
> ( it );
1364 for(
int rowIt = 0; rowIt < dim; rowIt++ )
1367 while( colIt < dim )
1369 if( std::abs ( eigValImag[colIt] ) < closeToZero )
1371 if ( colIt == eigIt ) {
if ( rowIt == 0 ) { *x = rightEigVectors[rowIt+colIt*dim]; }
if ( rowIt == 1 ) { *y = rightEigVectors[rowIt+colIt*dim]; }
if ( rowIt == 2 ) { *z = rightEigVectors[rowIt+colIt*dim]; } }
1387 proshade_double normFactor = std::sqrt ( pow ( *x, 2.0 ) + pow ( *y, 2.0 ) + pow ( *z, 2.0 ) );
1393 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( *x ), std::max ( std::abs ( *y ), std::abs ( *z ) ) ) );
1394 const FloatingPoint< proshade_double > rhs1 ( std::abs ( *x ) );
1395 const FloatingPoint< proshade_double > rhs2 ( std::abs ( *y ) );
1396 const FloatingPoint< proshade_double > rhs3 ( std::abs ( *z ) );
1397 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( *x < 0.0 ) ) ||
1398 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( *y < 0.0 ) ) ||
1399 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( *z < 0.0 ) ) )
1408 delete[] eigValReal;
1409 delete[] eigValImag;
1410 delete[] leftEigVectors;
1411 delete[] rightEigVectors;
1413 delete[] matrixToDecompose;
1418 *x = rotMat->at(7) - rotMat->at(5);
1419 *y = rotMat->at(2) - rotMat->at(6);
1420 *z = rotMat->at(3) - rotMat->at(1);
1422 proshade_double normFactor = std::sqrt ( pow ( *x, 2.0 ) + pow ( *y, 2.0 ) + pow ( *z, 2.0 ) );
1428 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( *x ), std::max ( std::abs ( *y ), std::abs ( *z ) ) ) );
1429 const FloatingPoint< proshade_double > rhs1 ( std::abs ( *x ) );
1430 const FloatingPoint< proshade_double > rhs2 ( std::abs ( *y ) );
1431 const FloatingPoint< proshade_double > rhs3 ( std::abs ( *z ) );
1432 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( *x < 0.0 ) ) ||
1433 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( *y < 0.0 ) ) ||
1434 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( *z < 0.0 ) ) )
1444 if ( *ang < 0.0 ) { *ang = ( 2.0 * M_PI ) + *ang; }
1462 if ( ( ang == 0.0 ) || ( std::isinf ( ang ) ) )
1465 for ( proshade_unsign i = 0; i < 9; i++ ) { rotMat[i] = 0.0; }
1475 proshade_double cAng = cos ( ang );
1476 proshade_double sAng = sin ( ang );
1477 proshade_double tAng = 1.0 - cAng;
1479 rotMat[0] = cAng + x * x * tAng;
1480 rotMat[4] = cAng + y * y * tAng;
1481 rotMat[8] = cAng + z * z * tAng;
1483 proshade_double tmp1 = x * y * tAng;
1484 proshade_double tmp2 = z * sAng;
1485 rotMat[3] = tmp1 + tmp2;
1486 rotMat[1] = tmp1 - tmp2;
1488 tmp1 = x * z * tAng;
1490 rotMat[6] = tmp1 - tmp2;
1491 rotMat[2] = tmp1 + tmp2;
1493 tmp1 = y * z * tAng;
1495 rotMat[7] = tmp1 + tmp2;
1496 rotMat[5] = tmp1 - tmp2;
1514 if ( ( ang == 0.0 ) || ( std::isinf ( ang ) ) )
1517 for (
size_t i = 0; i < 9; i++ ) { rotMat[i] = 0.0f; }
1527 proshade_single cAng = cos (
static_cast< proshade_single
> ( ang ) );
1528 proshade_single sAng = sin (
static_cast< proshade_single
> ( ang ) );
1529 proshade_single tAng = 1.0f - cAng;
1531 rotMat[0] = cAng +
static_cast< proshade_single
> ( x ) *
static_cast< proshade_single
> ( x ) * tAng;
1532 rotMat[4] = cAng +
static_cast< proshade_single
> ( y ) *
static_cast< proshade_single
> ( y ) * tAng;
1533 rotMat[8] = cAng +
static_cast< proshade_single
> ( z ) *
static_cast< proshade_single
> ( z ) * tAng;
1535 proshade_single tmp1 =
static_cast< proshade_single
> ( x ) *
static_cast< proshade_single
> ( y ) * tAng;
1536 proshade_single tmp2 =
static_cast< proshade_single
> ( z ) * sAng;
1537 rotMat[3] = tmp1 + tmp2;
1538 rotMat[1] = tmp1 - tmp2;
1540 tmp1 =
static_cast< proshade_single
> ( x ) *
static_cast< proshade_single
> ( z ) * tAng;
1541 tmp2 =
static_cast< proshade_single
> ( y ) * sAng;
1542 rotMat[6] = tmp1 - tmp2;
1543 rotMat[2] = tmp1 + tmp2;
1545 tmp1 =
static_cast< proshade_single
> ( y ) *
static_cast< proshade_single
> ( z ) * tAng;
1546 tmp2 =
static_cast< proshade_single
> ( x ) * sAng;
1547 rotMat[7] = tmp1 + tmp2;
1548 rotMat[5] = tmp1 - tmp2;
1565 if ( std::abs( rotMat[8] ) < 0.99999 )
1568 *eA = std::atan2 ( rotMat[7], rotMat[6] );
1569 *eB = std::acos ( rotMat[8] );
1570 *eG = std::atan2 ( rotMat[5], -rotMat[2] );
1575 if ( rotMat[8] >= 0.99999 )
1578 *eA = std::atan2 ( rotMat[3], rotMat[0] );
1582 if ( rotMat[8] <= -0.99999 )
1585 *eA = std::atan2 ( rotMat[3], rotMat[0] );
1592 if ( *eA < 0.0 ) { *eA = 2.0 * M_PI + *eA; }
1593 if ( *eB < 0.0 ) { *eB = M_PI + *eB; }
1594 if ( *eG < 0.0 ) { *eG = 2.0 * M_PI + *eG; }
1616 if ( ( axAng == 0.0 ) || ( std::isinf ( axAng ) ) )
1628 proshade_double cAng = std::cos ( axAng );
1629 proshade_double sAng = std::sin ( axAng );
1630 proshade_double tAng = 1.0 - cAng;
1632 proshade_double element22 = cAng + axZ * axZ * tAng;
1634 proshade_double tmp1 = axX * axZ * tAng;
1635 proshade_double tmp2 = axY * sAng;
1636 proshade_double element20 = tmp1 - tmp2;
1637 proshade_double element02 = tmp1 + tmp2;
1639 tmp1 = axY * axZ * tAng;
1641 proshade_double element21 = tmp1 + tmp2;
1642 proshade_double element12 = tmp1 - tmp2;
1645 if ( std::abs( element22 ) <= 0.99999 )
1648 *eA = std::atan2 ( element21, element20 );
1649 *eB = std::acos ( element22 );
1650 *eG = std::atan2 ( element12, -element02 );
1655 tmp1 = axX * axY * tAng;
1657 proshade_double element10 = tmp1 + tmp2;
1658 proshade_double element00 = cAng + axX * axX * tAng;
1661 if ( element22 >= 0.99999 )
1664 *eA = std::atan2 ( element10, element00 );
1668 if ( element22 <= -0.99999 )
1671 *eA = std::atan2 ( element10, element00 );
1678 if ( *eA < 0.0 ) { *eA = 2.0 * M_PI + *eA; }
1679 if ( *eB < 0.0 ) { *eB = M_PI + *eB; }
1680 if ( *eG < 0.0 ) { *eG = 2.0 * M_PI + *eG; }
1699 for ( proshade_unsign iter = 0; iter < 9; iter++ ) { res[iter] = 0.0; }
1702 for ( proshade_unsign row = 0; row < dim; row++ )
1704 for ( proshade_unsign col = 0; col < dim; col++ )
1706 for ( proshade_unsign inner = 0; inner < dim; inner++ )
1708 res[(row*dim)+col] += A[(inner*dim)+row] * B[(col*dim)+inner];
1725 std::vector < proshade_signed > ret;
1728 bool changeSign =
false;
1729 if ( number < 0 ) { changeSign =
true; number = -number; }
1736 while ( number % 2 == 0 )
1739 number = number / 2;
1743 for ( proshade_double posDiv = 3; posDiv <= sqrt ( static_cast< proshade_double > ( number ) ); posDiv += 2.0 )
1746 while ( number %
static_cast< proshade_signed
> ( posDiv ) == 0 )
1749 number = number /
static_cast< proshade_signed
> ( posDiv );
1757 if ( changeSign ) { ret.at(0) = -ret.at(0); }
1774 return ( ( 1.0 / sqrt ( 2.0 * M_PI * pow(standardDev,2.0) ) ) * std::exp ( - pow( value - mean, 2.0 ) / 2.0 * pow(standardDev,2.0) ) );
1791 return ( (*x1 * *x2) + (*y1 * *y2) + (*z1 * *z2) );
1807 return ( (x1 * x2) + (y1 * y2) + (z1 * z2) );
1823 proshade_double* crossProd =
new proshade_double[3];
1827 crossProd[0] = ( (*y1) * (*z2) ) - ( (*z1) * (*y2) );
1828 crossProd[1] = ( (*z1) * (*x2) ) - ( (*x1) * (*z2) );
1829 crossProd[2] = ( (*x1) * (*y2) ) - ( (*y1) * (*x2) );
1832 return ( crossProd );
1849 proshade_double* crossProd =
new proshade_double[3];
1853 crossProd[0] = ( y1 * z2 ) - ( z1 * y2 );
1854 crossProd[1] = ( z1 * x2 ) - ( x1 * z2 );
1855 crossProd[2] = ( x1 * y2 ) - ( y1 * x2 );
1858 return ( crossProd );
1871 proshade_double* ret =
new proshade_double[9];
1875 ret[0] = ( mat1[0] * mat2[0] ) + ( mat1[1] * mat2[3] ) + ( mat1[2] * mat2[6] );
1876 ret[1] = ( mat1[0] * mat2[1] ) + ( mat1[1] * mat2[4] ) + ( mat1[2] * mat2[7] );
1877 ret[2] = ( mat1[0] * mat2[2] ) + ( mat1[1] * mat2[5] ) + ( mat1[2] * mat2[8] );
1878 ret[3] = ( mat1[3] * mat2[0] ) + ( mat1[4] * mat2[3] ) + ( mat1[5] * mat2[6] );
1879 ret[4] = ( mat1[3] * mat2[1] ) + ( mat1[4] * mat2[4] ) + ( mat1[5] * mat2[7] );
1880 ret[5] = ( mat1[3] * mat2[2] ) + ( mat1[4] * mat2[5] ) + ( mat1[5] * mat2[8] );
1881 ret[6] = ( mat1[6] * mat2[0] ) + ( mat1[7] * mat2[3] ) + ( mat1[8] * mat2[6] );
1882 ret[7] = ( mat1[6] * mat2[1] ) + ( mat1[7] * mat2[4] ) + ( mat1[8] * mat2[7] );
1883 ret[8] = ( mat1[6] * mat2[2] ) + ( mat1[7] * mat2[5] ) + ( mat1[8] * mat2[8] );
1901 proshade_double* ret =
new proshade_double[3];
1905 ret[0] = ( x * mat[0] ) + ( y * mat[1] ) + ( z * mat[2] );
1906 ret[1] = ( x * mat[3] ) + ( y * mat[4] ) + ( z * mat[5] );
1907 ret[2] = ( x * mat[6] ) + ( y * mat[7] ) + ( z * mat[8] );
1925 proshade_single* ret =
new proshade_single[3];
1929 ret[0] = ( x * mat[0] ) + ( y * mat[1] ) + ( z * mat[2] );
1930 ret[1] = ( x * mat[3] ) + ( y * mat[4] ) + ( z * mat[5] );
1931 ret[2] = ( x * mat[6] ) + ( y * mat[7] ) + ( z * mat[8] );
1946 proshade_double* inverse =
new proshade_double[9];
1950 proshade_double matDet = ( mat[0] * mat[4] * mat[8] ) +
1951 ( mat[1] * mat[5] * mat[6] ) +
1952 ( mat[2] * mat[3] * mat[7] ) -
1953 ( mat[0] * mat[5] * mat[7] ) -
1954 ( mat[1] * mat[3] * mat[8] ) -
1955 ( mat[2] * mat[4] * mat[6] );
1958 inverse[0] = ( mat[4] * mat[8] - mat[5] * mat[7] ) / matDet;
1959 inverse[1] = ( mat[2] * mat[7] - mat[1] * mat[8] ) / matDet;
1960 inverse[2] = ( mat[1] * mat[5] - mat[2] * mat[4] ) / matDet;
1961 inverse[3] = ( mat[5] * mat[6] - mat[3] * mat[8] ) / matDet;
1962 inverse[4] = ( mat[0] * mat[8] - mat[2] * mat[6] ) / matDet;
1963 inverse[5] = ( mat[2] * mat[3] - mat[0] * mat[5] ) / matDet;
1964 inverse[6] = ( mat[3] * mat[7] - mat[4] * mat[6] ) / matDet;
1965 inverse[7] = ( mat[1] * mat[6] - mat[0] * mat[7] ) / matDet;
1966 inverse[8] = ( mat[0] * mat[4] - mat[1] * mat[3] ) / matDet;
1979 proshade_double tmp;
2007 proshade_double* ret =
new proshade_double[9];
2036 proshade_double* ret =
new proshade_double[9];
2037 proshade_double* XRM =
new proshade_double[9];
2038 proshade_double* YRM =
new proshade_double[9];
2039 proshade_double* ZRM =
new proshade_double[9];
2046 proshade_double xRad = xRot * ( M_PI / 180.0 );
2047 proshade_double yRad = yRot * ( M_PI / 180.0 );
2048 proshade_double zRad = zRot * ( M_PI / 180.0 );
2051 XRM[0] = 1.0; XRM[1] = 0.0; XRM[2] = 0.0;
2052 XRM[3] = 0.0; XRM[4] = std::cos ( xRad ); XRM[5] = -std::sin ( xRad );
2053 XRM[6] = 0.0; XRM[7] = std::sin ( xRad ); XRM[8] = std::cos ( xRad );
2055 YRM[0] = std::cos ( yRad ); YRM[1] = 0.0; YRM[2] = std::sin ( yRad );
2056 YRM[3] = 0.0; YRM[4] = 1.0; YRM[5] = 0.0;
2057 YRM[6] = -std::sin ( yRad ); YRM[7] = 0.0; YRM[8] = std::cos ( yRad );
2059 ZRM[0] = std::cos ( zRad ); ZRM[1] = -std::sin ( zRad ); ZRM[2] = 0.0;
2060 ZRM[3] = std::sin ( zRad ); ZRM[4] = std::cos ( zRad ); ZRM[5] = 0.0;
2061 ZRM[6] = 0.0; ZRM[7] = 0.0; ZRM[8] = 1.0;
2098 proshade_double* inPlaneRotation =
new proshade_double[9];
2099 proshade_double* basisChangeMat =
new proshade_double[9];
2104 proshade_double normF = std::sqrt( std::pow( x1, 2.0 ) + std::pow ( y1, 2.0 ) + std::pow ( z1, 2.0 ) );
2105 x1 /= normF; y1 /= normF; z1 /= normF;
2107 normF = std::sqrt( std::pow( x2, 2.0 ) + std::pow ( y2, 2.0 ) + std::pow ( z2, 2.0 ) );
2108 x2 /= normF; y2 /= normF; z2 /= normF;
2112 proshade_double crossProdMag = std::sqrt( std::pow( crossProd[0], 2.0 ) + std::pow ( crossProd[1], 2.0 ) + std::pow ( crossProd[2], 2.0 ) );
2119 inPlaneRotation[0] = dotProd; inPlaneRotation[1] = -crossProdMag; inPlaneRotation[2] = 0.0;
2120 inPlaneRotation[3] = crossProdMag; inPlaneRotation[4] = dotProd; inPlaneRotation[5] = 0.0;
2121 inPlaneRotation[6] = 0.0; inPlaneRotation[7] = 0.0; inPlaneRotation[8] = 1.0;
2125 normF = std::sqrt ( std::pow ( x2 - ( dotProd * x1 ), 2.0 ) + std::pow ( y2 - ( dotProd * y1 ), 2.0 ) + std::pow ( z2 - ( dotProd * z1 ), 2.0 ) );
2127 basisChangeMat[0] = x1; basisChangeMat[1] = ( x2 - ( dotProd * x1 ) ) / normF; basisChangeMat[2] = crossProd[0];
2128 basisChangeMat[3] = y1; basisChangeMat[4] = ( y2 - ( dotProd * y1 ) ) / normF; basisChangeMat[5] = crossProd[1];
2129 basisChangeMat[6] = z1; basisChangeMat[7] = ( z2 - ( dotProd * z1 ) ) / normF; basisChangeMat[8] = crossProd[2];
2140 delete[] inPlaneRotation;
2141 delete[] basisChangeMat;
2142 delete[] basisChangeMatInverse;
2167 double *singularValues =
new double[dim];
2168 double *rotMatU =
new double [dim*dim];
2169 double *rotMatV =
new double [dim*dim];
2170 double *work =
new double [
static_cast< proshade_unsign
>( ( 3 * dim ) + pow( dim, 2 ) * dim)];
2171 int workDim =
static_cast< int > ( 2 * ( ( 4 * dim * dim ) + ( 7 * dim ) ) );
2172 double* rwork =
new double[
static_cast<proshade_unsign
>((5 * dim) + 5 * pow(dim,2))];
2173 int* iwork =
new int[(8 * dim)];
2174 int returnValue = 0;
2175 double *matrixToDecompose =
new double[dim*dim];
2187 for (
int rowIt = 0; rowIt < dim; rowIt++ )
2189 for (
int colIt = 0; colIt < dim; colIt++ )
2191 if ( rowIt == colIt ) { matrixToDecompose[(colIt*dim)+rowIt] = 1.0 - rMat->at(
static_cast< size_t > ( ( rowIt * dim ) + colIt ) ); }
2192 else { matrixToDecompose[(colIt*dim)+rowIt] = 0.0 - rMat->at(
static_cast< size_t > ( ( rowIt * dim ) + colIt ) ); }
2197 dgesdd_ ( &job, &dim, &dim, matrixToDecompose, &dim, singularValues, rotMatU, &dim, rotMatV, &dim,
2198 work, &workDim, rwork, iwork, &returnValue );
2201 if ( returnValue != 0 )
2207 bool anyPositive =
false;
2208 std::vector< bool > positivityTest;
2209 for ( proshade_unsign it = 0; it < static_cast< proshade_unsign > ( dim ); it++ )
2211 positivityTest.push_back ( singularValues[it] > 0.001 );
2212 if ( positivityTest.at(it) ) { anyPositive =
true; }
2216 proshade_double* pseudoInverseMat;
2220 if ( !positivityTest.at(0) )
2222 singularValues[0] = 0.0;
2230 else { singularValues[0] = 1.0 / singularValues[0]; }
2232 if ( !positivityTest.at(1) )
2234 singularValues[1] = 0.0;
2242 else { singularValues[1] = 1.0 / singularValues[1]; }
2244 if ( !positivityTest.at(2) )
2246 singularValues[2] = 0.0;
2254 else { singularValues[2] = 1.0 / singularValues[2]; }
2268 pseudoInverseMat =
new proshade_double[9];
2271 for (
size_t mIt = 0; mIt < 9; mIt++ ) { pseudoInverseMat[mIt] = 0.0; }
2278 delete[] matrixToDecompose;
2279 delete[] singularValues;
2284 return ( pseudoInverseMat );
2312 std::vector < proshade_double > ret;
2315 proshade_double solX = ( -sqrt ( pow ( 2.0 * x1 * y1 * dot2 * y2 + 2.0 * x1 * z1 * dot2 * z2 - 2.0 * x1 * dot1 * pow ( y2, 2.0 ) - 2.0 * x1 * dot1 * pow ( z2, 2.0 ) - 2.0 * pow ( y1, 2.0 ) * dot2 * x2 + 2.0 * y1 * dot1 * x2 * y2 - 2.0 * pow ( z1, 2.0 ) * dot2 * x2 + 2.0 * z1 * dot1 * x2 * z2, 2.0 ) -
2316 4.0 * ( pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * x1 * y1 * x2 * y2 - 2.0 * x1 * z1 * x2 * z2 + pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) ) *
2317 ( pow ( y1, 2.0 ) * pow ( dot2, 2.0 ) - pow ( y1, 2.0 ) * pow ( z2, 2.0 ) + 2.0 * y1 * z1 * y2 * z2 - 2.0 * y1 * dot1 * dot2 * y2 + pow ( z1, 2.0 ) * pow ( dot2, 2.0 ) - pow ( z1, 2.0 ) * pow ( y2, 2.0 ) - 2.0 * z1 * dot1 * dot2 * z2 + pow ( dot1, 2.0 ) * pow ( y2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( z2, 2.0 ) ) ) -
2318 2.0 * x1 * y1 * dot2 * y2 - 2.0 * x1 * z1 * dot2 * z2 + 2.0 * x1 * dot1 * pow ( y2, 2.0 ) + 2.0 * x1 * dot1 * pow ( z2, 2.0 ) + 2.0 * pow ( y1, 2.0 ) * dot2 * x2 - 2.0 * y1 * dot1 * x2 * y2 + 2.0 * pow ( z1, 2.0 ) * dot2 * x2 - 2.0 * z1 * dot1 * x2 * z2 ) /
2319 ( 2.0 * ( pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * x1 * y1 * x2 * y2 - 2.0 * x1 * z1 * x2 * z2 + pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) ) );
2320 proshade_double solY = ( ( dot2 * pow ( x2, 2.0 ) * pow ( z1, 3.0 ) ) /
2321 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2322 ( dot1 * pow ( x2, 2.0 ) * z2 * pow ( z1, 2.0 ) ) /
2323 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2324 ( 2.0 * x1 * dot2 * x2 * z2 * pow ( z1, 2.0 ) ) /
2325 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) - dot2 * z1 -
2326 ( x2 * sqrt ( pow ( - 2.0 * dot2 * x2 * pow ( y1, 2.0 ) + 2.0 * x1 * dot2 * y2 * y1 + 2.0 * dot1 * x2 * y2 * y1 - 2.0 * x1 * dot1 * pow ( y2, 2.0 ) - 2.0 * x1 * dot1 * pow ( z2, 2.0 ) - 2.0 * pow ( z1, 2.0 ) * dot2 * x2 + 2.0 * x1 * z1 * dot2 * z2 + 2.0 * z1 * dot1 * x2 * z2, 2.0 ) -
2327 4.0 * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) *
2328 ( pow ( y1, 2.0 ) * pow ( dot2, 2.0 ) + pow ( z1, 2.0 ) * pow ( dot2, 2.0 ) - 2.0 * y1 * dot1 * y2 * dot2 - 2.0 * z1 * dot1 * z2 * dot2 - pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( y2, 2.0 ) - pow ( y1, 2.0 ) * pow ( z2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( z2, 2.0 ) + 2.0 * y1 * z1 * y2 * z2 ) ) * z1 ) /
2329 ( 2.0 * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) +
2330 ( pow ( y1, 2.0 ) * dot2 * pow ( x2, 2.0 ) * z1 ) /
2331 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2332 ( x1 * dot1 * x2 * pow ( y2, 2.0 ) * z1 ) /
2333 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2334 ( pow ( x1, 2.0 ) * dot2 * pow ( z2, 2.0 ) * z1 ) /
2335 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2336 ( 2.0 * x1 * dot1 * x2 * pow ( z2, 2.0 ) * z1 ) /
2337 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2338 ( y1 * dot1 * pow ( x2, 2.0 ) * y2 * z1 ) /
2339 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2340 ( x1 * y1 * dot2 * x2 * y2 * z1 ) /
2341 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) + dot1 * z2 +
2342 ( x1 * z2 * sqrt ( pow ( -2.0 * dot2 * x2 * pow ( y1, 2.0 ) + 2.0 * x1 * dot2 * y2 * y1 + 2.0 * dot1 * x2 * y2 * y1 - 2.0 * x1 * dot1 * pow ( y2, 2.0 ) - 2.0 * x1 * dot1 * pow ( z2, 2.0 ) - 2.0 * pow ( z1, 2.0 ) * dot2 * x2 + 2.0 * x1 * z1 * dot2 * z2 + 2.0 * z1 * dot1 * x2 * z2, 2.0 ) -
2343 4.0 * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) *
2344 ( pow ( y1, 2.0 ) * pow ( dot2, 2.0 ) + pow ( z1, 2.0 ) * pow ( dot2, 2.0 ) - 2.0 * y1 * dot1 * y2 * dot2 - 2.0 * z1 * dot1 * z2 * dot2 - pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( y2, 2.0 ) - pow ( y1, 2.0 ) * pow ( z2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( z2, 2.0 ) + 2.0 * y1 * z1 * y2 * z2 ) ) ) /
2345 ( 2.0 * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2346 ( pow ( x1, 2.0 ) * dot1 * pow ( z2, 3.0 ) ) /
2347 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2348 ( pow ( x1, 2.0 ) * dot1 * pow ( y2, 2.0 ) * z2 ) /
2349 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2350 ( x1 * pow ( y1, 2.0 ) * dot2 * x2 * z2 ) /
2351 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2352 ( pow ( x1, 2.0 ) * y1 * dot2 * y2 * z2 ) /
2353 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2354 ( x1 * y1 * dot1 * x2 * y2 * z2 ) /
2355 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) / ( y1 * z2 - z1 * y2 );
2356 proshade_double solZ = ( - ( dot2 * pow ( x2, 2.0 ) * y2 * pow ( z1, 3.0 ) ) /
2357 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2358 ( dot2 * pow ( x2, 2.0 ) * pow ( z1, 2.0 ) ) /
2359 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2360 ( dot1 * pow ( x2, 2.0 ) * y2 * z2 * pow ( z1, 2.0 ) ) /
2361 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) +
2362 ( 2.0 * x1 * dot2 * x2 * y2 * z2 * pow ( z1, 2.0 ) ) /
2363 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) +
2364 ( x2 * y2 * sqrt ( pow ( -2.0 * dot2 * x2 * pow ( y1, 2.0 ) + 2.0 * x1 * dot2 * y2 * y1 + 2.0 * dot1 * x2 * y2 * y1 - 2.0 * x1 * dot1 * pow ( y2, 2.0 ) - 2.0 * x1 * dot1 * pow ( z2, 2.0 ) - 2.0 * pow ( z1, 2.0 ) * dot2 * x2 + 2.0 * x1 * z1 * dot2 * z2 + 2.0 * z1 * dot1 * x2 * z2, 2.0 ) -
2365 4.0 * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) *
2366 ( pow ( y1, 2.0 ) * pow ( dot2, 2.0 ) + pow ( z1, 2.0 ) * pow ( dot2, 2.0 ) - 2.0 * y1 * dot1 * y2 * dot2 - 2.0 * z1 * dot1 * z2 * dot2 - pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( y2, 2.0 ) - pow ( y1, 2.0 ) * pow ( z2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( z2, 2.0 ) + 2.0 * y1 * z1 * y2 * z2 ) ) * z1 ) /
2367 ( 2.0 * ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) +
2368 ( dot2 * y2 * z1 ) / ( y1 * z2 - z1 * y2 ) +
2369 ( dot1 * pow ( x2, 2.0 ) * z2 * z1 ) /
2370 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2371 ( x1 * dot2 * x2 * z2 * z1 ) /
2372 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2373 ( x1 * dot1 * x2 * pow ( y2, 3.0 ) * z1 ) /
2374 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) +
2375 ( y1 * dot1 * pow ( x2, 2.0 ) * pow ( y2, 2.0 ) * z1 ) /
2376 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) +
2377 ( x1 * y1 * dot2 * x2 * pow ( y2, 2.0 ) * z1 ) /
2378 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2379 ( pow ( x1, 2.0 ) * dot2 * y2 * pow ( z2, 2.0 ) * z1 ) /
2380 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2381 ( 2.0 * x1 * dot1 * x2 * y2 * pow ( z2, 2.0 ) * z1 ) /
2382 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2383 ( pow ( y1, 2.0 ) * dot2 * pow ( x2, 2.0 ) * y2 * z1 ) /
2384 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) + dot2 +
2385 ( x2 * sqrt ( pow ( - 2.0 * dot2 * x2 * pow ( y1, 2.0 ) + 2.0 * x1 * dot2 * y2 * y1 + 2.0 * dot1 * x2 * y2 * y1 - 2.0 * x1 * dot1 * pow ( y2, 2.0 ) - 2.0 * x1 * dot1 * pow ( z2, 2.0 ) - 2.0 * pow ( z1, 2.0 ) * dot2 * x2 + 2.0 * x1 * z1 * dot2 * z2 + 2.0 * z1 * dot1 * x2 * z2, 2.0 ) -
2386 4.0 * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) *
2387 ( pow ( y1, 2.0 ) * pow ( dot2, 2.0 ) + pow ( z1, 2.0 ) * pow ( dot2, 2.0 ) - 2.0 * y1 * dot1 * y2 * dot2 - 2.0 * z1 * dot1 * z2 * dot2 - pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( y2, 2.0 ) - pow ( y1, 2.0 ) * pow ( z2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( z2, 2.0 ) + 2.0 * y1 * z1 * y2 * z2 ) ) ) /
2388 ( 2.0 * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2389 ( x1 * y2 * z2 * sqrt ( pow ( - 2.0 * dot2 * x2 * pow ( y1, 2.0 ) + 2.0 * x1 * dot2 * y2 * y1 + 2.0 * dot1 * x2 * y2 * y1 - 2.0 * x1 * dot1 * pow ( y2, 2.0 ) - 2.0 * x1 * dot1 * pow ( z2, 2.0 ) - 2.0 * pow ( z1, 2.0 ) * dot2 * x2 + 2.0 * x1 * z1 * dot2 * z2 + 2.0 * z1 * dot1 * x2 * z2, 2.0 ) -
2390 4.0 * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) *
2391 ( pow ( y1, 2.0 ) * pow ( dot2, 2.0 ) + pow ( z1, 2.0 ) * pow ( dot2, 2.0 ) - 2.0 * y1 * dot1 * y2 * dot2 - 2.0 * z1 * dot1 * z2 * dot2 - pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( y2, 2.0 ) - pow ( y1, 2.0 ) * pow ( z2, 2.0 ) + pow ( dot1, 2.0 ) * pow ( z2, 2.0 ) + 2.0 * y1 * z1 * y2 * z2 ) ) ) /
2392 ( 2.0 * ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2393 ( dot1 * y2 * z2 ) / ( y1 * z2 - z1 * y2 ) -
2394 ( pow ( y1, 2.0 ) * dot2 * pow ( x2, 2.0 ) ) /
2395 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2396 ( x1 * dot1 * x2 * pow ( y2, 2.0 ) ) /
2397 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) -
2398 ( x1 * dot1 * x2 * pow ( z2, 2.0 ) ) /
2399 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2400 ( y1 * dot1 * pow ( x2, 2.0 ) * y2 ) /
2401 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2402 ( x1 * y1 * dot2 * x2 * y2 ) /
2403 ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) +
2404 ( pow ( x1, 2.0 ) * dot1 * y2 * pow ( z2, 3.0 ) ) /
2405 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) +
2406 ( pow ( x1, 2.0 ) * dot1 * pow ( y2, 3.0 ) * z2 ) /
2407 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2408 ( pow ( x1, 2.0 ) * y1 * dot2 * pow ( y2, 2.0 ) * z2 ) /
2409 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) -
2410 ( x1 * y1 * dot1 * x2 * pow ( y2, 2.0 ) * z2 ) /
2411 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) +
2412 ( x1 * pow ( y1, 2.0 ) * dot2 * x2 * y2 * z2 ) /
2413 ( ( y1 * z2 - z1 * y2 ) * ( pow ( y1, 2.0 ) * pow ( x2, 2.0 ) + pow ( z1, 2.0 ) * pow ( x2, 2.0 ) - 2.0 * x1 * y1 * y2 * x2 - 2.0 * x1 * z1 * z2 * x2 + pow ( x1, 2.0 ) * pow ( y2, 2.0 ) + pow ( z1, 2.0 ) * pow ( y2, 2.0 ) + pow ( x1, 2.0 ) * pow ( z2, 2.0 ) + pow ( y1, 2.0 ) * pow ( z2, 2.0 ) - 2.0 * y1 * z1 * y2 * z2 ) ) ) / z2;
2416 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( solX ), std::max( std::abs ( solY ), std::abs ( solZ ) ) ) );
2417 const FloatingPoint< proshade_double > rhs1 ( std::abs ( solX ) );
2418 const FloatingPoint< proshade_double > rhs2 ( std::abs ( solY ) );
2419 const FloatingPoint< proshade_double > rhs3 ( std::abs ( solZ ) );
2420 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( solX < 0.0 ) ) ||
2421 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( solY < 0.0 ) ) ||
2422 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( solZ < 0.0 ) ) ) { solX *= -1.0; solY *= -1.0; solZ *= -1.0; }
2455 std::vector < proshade_double >
ProSHADE_internal_maths::findVectorFromThreeVAndThreeD ( proshade_double x1, proshade_double y1, proshade_double z1, proshade_double x2, proshade_double y2, proshade_double z2, proshade_double x3, proshade_double y3, proshade_double z3, proshade_double dot1, proshade_double dot2, proshade_double dot3 )
2458 std::vector < proshade_double > ret;
2461 proshade_double solX = - ( y1 * dot2 * z3 - y1 * dot3 * z2 - z1 * dot2 * y3 + z1 * dot3 * y2 + dot1 * y3 * z2 - dot1 * z3 * y2 ) /
2462 ( -x1 * y3 * z2 + x1 * z3 * y2 + y1 * x3 * z2 - y1 * z3 * x2 - z1 * x3 * y2 + z1 * y3 * x2 );
2463 proshade_double solY = - ( x1 * dot2 * z3 - x1 * dot3 * z2 - z1 * dot2 * x3 + z1 * dot3 * x2 + dot1 * x3 * z2 - dot1 * z3 * x2 ) /
2464 ( x1 * y3 * z2 - x1 * z3 * y2 - y1 * x3 * z2 + y1 * z3 * x2 + z1 * x3 * y2 - z1 * y3 * x2 );
2465 proshade_double solZ = - ( x1 * dot2 * y3 - x1 * dot3 * y2 - y1 * dot2 * x3 + y1 * dot3 * x2 + dot1 * x3 * y2 - dot1 * y3 * x2 ) /
2466 ( -x1 * y3 * z2 + x1 * z3 * y2 + y1 * x3 * z2 - y1 * z3 * x2 - z1 * x3 * y2 + z1 * y3 * x2 );
2469 proshade_double normFactor = sqrt ( pow ( solX, 2.0 ) + pow ( solY, 2.0 ) + pow ( solZ, 2.0 ) );
2475 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( solX ), std::max( std::abs ( solY ), std::abs ( solZ ) ) ) );
2476 const FloatingPoint< proshade_double > rhs1 ( std::abs ( solX ) );
2477 const FloatingPoint< proshade_double > rhs2 ( std::abs ( solY ) );
2478 const FloatingPoint< proshade_double > rhs3 ( std::abs ( solZ ) );
2479 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( solX < 0.0 ) ) ||
2480 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( solY < 0.0 ) ) ||
2481 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( solZ < 0.0 ) ) ) { solX *= -1.0; solY *= -1.0; solZ *= -1.0; }
2502 std::vector< proshade_double > ret;
2506 ( el1->at(1) * el2->at(3) ) +
2507 ( el1->at(2) * el2->at(6) ) );
2509 ( el1->at(1) * el2->at(4) ) +
2510 ( el1->at(2) * el2->at(7) ) );
2512 ( el1->at(1) * el2->at(5) ) +
2513 ( el1->at(2) * el2->at(8) ) );
2516 ( el1->at(4) * el2->at(3) ) +
2517 ( el1->at(5) * el2->at(6) ) );
2519 ( el1->at(4) * el2->at(4) ) +
2520 ( el1->at(5) * el2->at(7) ) );
2522 ( el1->at(4) * el2->at(5) ) +
2523 ( el1->at(5) * el2->at(8) ) );
2526 ( el1->at(7) * el2->at(3) ) +
2527 ( el1->at(8) * el2->at(6) ) );
2529 ( el1->at(7) * el2->at(4) ) +
2530 ( el1->at(8) * el2->at(7) ) );
2532 ( el1->at(7) * el2->at(5) ) +
2533 ( el1->at(8) * el2->at(8) ) );
2558 proshade_double trace = ( mat1->at(0) * mat2->at(0) ) + ( mat1->at(1) * mat2->at(1) ) + ( mat1->at(2) * mat2->at(2) );
2559 trace += ( mat1->at(3) * mat2->at(3) ) + ( mat1->at(4) * mat2->at(4) ) + ( mat1->at(5) * mat2->at(5) );
2560 trace += ( mat1->at(6) * mat2->at(6) ) + ( mat1->at(7) * mat2->at(7) ) + ( mat1->at(8) * mat2->at(8) );
2566 if ( tolerance > std::abs ( trace ) ) { ret =
true; }
2595 proshade_double cosDist = ( ( a1 * b1 ) + ( a2 * b2 ) + ( a3 * b3 ) ) /
2596 ( sqrt( pow( a1, 2.0 ) + pow( a2, 2.0 ) + pow( a3, 2.0 ) ) *
2597 sqrt( pow( b1, 2.0 ) + pow( b2, 2.0 ) + pow( b3, 2.0 ) ) );
2600 if ( std::abs( cosDist ) > ( 1.0 - tolerance ) ) { ret =
true; }
2629 proshade_double cosDist = ( ( a1 * b1 ) + ( a2 * b2 ) + ( a3 * b3 ) ) /
2630 ( sqrt( pow( a1, 2.0 ) + pow( a2, 2.0 ) + pow( a3, 2.0 ) ) *
2631 sqrt( pow( b1, 2.0 ) + pow( b2, 2.0 ) + pow( b3, 2.0 ) ) );
2634 if ( cosDist > ( 1.0 - tolerance ) ) { ret =
true; }
2653 void ProSHADE_internal_maths::optimiseAxisBiCubicInterpolation ( proshade_double* bestLattitude, proshade_double* bestLongitude, proshade_double* bestSum, std::vector<proshade_unsign>* sphereList, std::vector<ProSHADE_internal_spheres::ProSHADE_rotFun_sphere*>* sphereMappedRotFun, proshade_double step )
2656 proshade_double lonM, lonP, latM, latP, movSum;
2657 std::vector<proshade_double> latVals ( 3 );
2658 std::vector<proshade_double> lonVals ( 3 );
2659 proshade_double learningRate = 0.1;
2660 proshade_double prevVal = *bestSum;
2661 proshade_double valChange = 999.9;
2662 proshade_double origBestLat = std::round ( *bestLattitude );
2663 proshade_double origBestLon = std::round ( *bestLongitude );
2664 proshade_double tmpVal;
2667 std::vector<ProSHADE_internal_maths::BicubicInterpolator*> interpolsMinusMinus;
2668 std::vector<ProSHADE_internal_maths::BicubicInterpolator*> interpolsMinusPlus;
2669 std::vector<ProSHADE_internal_maths::BicubicInterpolator*> interpolsPlusMinus;
2670 std::vector<ProSHADE_internal_maths::BicubicInterpolator*> interpolsPlusPlus;
2677 while ( valChange > 0.0001 )
2680 lonM = *bestLongitude - step;
2681 lonP = *bestLongitude + step;
2682 latM = *bestLattitude - step;
2683 latP = *bestLattitude + step;
2686 const FloatingPoint< proshade_double > lhs1 ( *bestLattitude ), rhs1 ( origBestLat - 1.0 );
2687 const FloatingPoint< proshade_double > lhs2 ( *bestLattitude ), rhs2 ( origBestLat + 1.0 );
2688 const FloatingPoint< proshade_double > lhs3 ( *bestLongitude ), rhs3 ( origBestLon - 1.0 );
2689 const FloatingPoint< proshade_double > lhs4 ( *bestLongitude ), rhs4 ( origBestLon + 1.0 );
2690 if ( latM < ( origBestLat - 1.0 ) ) { tmpVal = *bestLattitude; *bestLattitude = origBestLat - 1.0;
optimiseAxisBiCubicInterpolation ( bestLattitude, bestLongitude, bestSum, sphereList, sphereMappedRotFun, step );
if ( lhs1.AlmostEquals ( rhs1 ) ) { *bestLattitude = tmpVal; }
break; }
2691 if ( latP > ( origBestLat + 1.0 ) ) { tmpVal = *bestLattitude; *bestLattitude = origBestLat + 1.0;
optimiseAxisBiCubicInterpolation ( bestLattitude, bestLongitude, bestSum, sphereList, sphereMappedRotFun, step );
if ( lhs2.AlmostEquals ( rhs2 ) ) { *bestLattitude = tmpVal; }
break; }
2692 if ( lonM < ( origBestLon - 1.0 ) ) { tmpVal = *bestLongitude; *bestLongitude = origBestLon - 1.0;
optimiseAxisBiCubicInterpolation ( bestLattitude, bestLongitude, bestSum, sphereList, sphereMappedRotFun, step );
if ( lhs3.AlmostEquals ( rhs3 ) ) { *bestLongitude = tmpVal; }
break; }
2693 if ( lonP > ( origBestLon + 1.0 ) ) { tmpVal = *bestLongitude; *bestLongitude = origBestLon + 1.0;
optimiseAxisBiCubicInterpolation ( bestLattitude, bestLongitude, bestSum, sphereList, sphereMappedRotFun, step );
if ( lhs4.AlmostEquals ( rhs4 ) ) { *bestLongitude = tmpVal; }
break; }
2696 latVals.at(0) = latM; latVals.at(1) = *bestLattitude; latVals.at(2) = latP;
2697 lonVals.at(0) = lonM; lonVals.at(1) = *bestLongitude; lonVals.at(2) = lonP;
2700 for ( proshade_unsign laIt = 0; laIt < static_cast<proshade_unsign> ( latVals.size() ); laIt++ )
2702 for ( proshade_unsign loIt = 0; loIt < static_cast<proshade_unsign> ( lonVals.size() ); loIt++ )
2706 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( sphereList->size() ); iter++ )
2709 if ( ( latVals.at(laIt) <= origBestLat ) && ( lonVals.at(loIt) <= origBestLon ) ) { movSum += interpolsMinusMinus.at(iter)->getValue ( latVals.at(laIt), lonVals.at(loIt) ); }
2710 if ( ( latVals.at(laIt) <= origBestLat ) && ( lonVals.at(loIt) > origBestLon ) ) { movSum += interpolsMinusPlus.at(iter)->getValue ( latVals.at(laIt), lonVals.at(loIt) ); }
2711 if ( ( latVals.at(laIt) > origBestLat ) && ( lonVals.at(loIt) <= origBestLon ) ) { movSum += interpolsPlusMinus.at(iter)->getValue ( latVals.at(laIt), lonVals.at(loIt) ); }
2712 if ( ( latVals.at(laIt) > origBestLat ) && ( lonVals.at(loIt) > origBestLon ) ) { movSum += interpolsPlusPlus.at(iter)->getValue ( latVals.at(laIt), lonVals.at(loIt) ); }
2716 if ( *bestSum < movSum )
2719 *bestLongitude = lonVals.at(loIt);
2720 *bestLattitude = latVals.at(laIt);
2726 valChange = std::floor ( 100000.0 * ( *bestSum - prevVal ) ) / 100000.0;
2727 prevVal = std::floor ( 100000.0 * ( *bestSum ) ) / 100000.0;
2728 step = std::max ( ( valChange / step ) * learningRate, 0.01 );
2729 if ( learningRate >= 0.02 ) { learningRate -= 0.01; }
2734 for ( proshade_unsign intIt = 0; intIt < static_cast<proshade_unsign> ( interpolsMinusMinus.size() ); intIt++ ) {
delete interpolsMinusMinus.at(intIt); }
2735 for ( proshade_unsign intIt = 0; intIt < static_cast<proshade_unsign> ( interpolsMinusPlus.size() ); intIt++ ) {
delete interpolsMinusPlus.at(intIt); }
2736 for ( proshade_unsign intIt = 0; intIt < static_cast<proshade_unsign> ( interpolsPlusMinus.size() ); intIt++ ) {
delete interpolsPlusMinus.at(intIt); }
2737 for ( proshade_unsign intIt = 0; intIt < static_cast<proshade_unsign> ( interpolsPlusPlus.size() ); intIt++ ) {
delete interpolsPlusPlus.at(intIt); }
2754 void ProSHADE_internal_maths::prepareBiCubicInterpolatorsMinusMinus ( proshade_double bestLattitude, proshade_double bestLongitude, std::vector<proshade_unsign>* sphereList, std::vector<ProSHADE_internal_maths::BicubicInterpolator*>* interpols, std::vector<ProSHADE_internal_spheres::ProSHADE_rotFun_sphere*>* sphereMappedRotFun )
2757 proshade_signed latHlp, lonHlp;
2758 proshade_signed angDim =
static_cast< proshade_signed
> ( sphereMappedRotFun->at(0)->getAngularDim() );
2761 for ( proshade_unsign sphereIt = 0; sphereIt < static_cast<proshade_unsign> ( sphereList->size() ); sphereIt++ )
2764 proshade_double** interpGrid =
new proshade_double*[4];
2768 for ( proshade_unsign iter = 0; iter < 4; iter++ )
2770 interpGrid[iter] =
new proshade_double[4];
2775 for ( proshade_signed latIt = 0; latIt < 4; latIt++ )
2777 for ( proshade_signed lonIt = 0; lonIt < 4; lonIt++ )
2779 latHlp =
static_cast< proshade_signed
> ( bestLattitude - 2.0 +
static_cast< proshade_double
> ( latIt ) );
if ( latHlp < 0 ) { latHlp += angDim; }
if ( latHlp >= angDim ) { latHlp -= angDim; }
2780 lonHlp =
static_cast< proshade_signed
> ( bestLongitude - 2.0 +
static_cast< proshade_double
> ( lonIt ) );
if ( lonHlp < 0 ) { lonHlp += angDim; }
if ( lonHlp >= angDim ) { lonHlp -= angDim; }
2781 interpGrid[latIt][lonIt] = sphereMappedRotFun->at(sphereList->at(sphereIt))->getSphereLatLonPosition (
static_cast< proshade_unsign
> ( latHlp ),
static_cast< proshade_unsign
> ( lonHlp ) );
2787 interpols->emplace_back ( biCubInterp );
2790 for ( proshade_unsign iter = 0; iter < 4; iter++ ) {
delete[] interpGrid[iter]; }
2791 delete[] interpGrid;
2809 void ProSHADE_internal_maths::prepareBiCubicInterpolatorsMinusPlus ( proshade_double bestLattitude, proshade_double bestLongitude, std::vector<proshade_unsign>* sphereList, std::vector<ProSHADE_internal_maths::BicubicInterpolator*>* interpols, std::vector<ProSHADE_internal_spheres::ProSHADE_rotFun_sphere*>* sphereMappedRotFun )
2812 proshade_signed latHlp, lonHlp;
2813 proshade_signed angDim =
static_cast< proshade_signed
> ( sphereMappedRotFun->at(0)->getAngularDim() );
2816 for ( proshade_unsign sphereIt = 0; sphereIt < static_cast<proshade_unsign> ( sphereList->size() ); sphereIt++ )
2819 proshade_double** interpGrid =
new proshade_double*[4];
2823 for ( proshade_unsign iter = 0; iter < 4; iter++ )
2825 interpGrid[iter] =
new proshade_double[4];
2830 for ( proshade_unsign latIt = 0; latIt < 4; latIt++ )
2832 for ( proshade_unsign lonIt = 0; lonIt < 4; lonIt++ )
2834 latHlp =
static_cast< proshade_signed
> ( bestLattitude - 2 +
static_cast< proshade_double
> ( latIt ) );
if ( latHlp < 0 ) { latHlp += angDim; }
if ( latHlp >= angDim ) { latHlp -= angDim; }
2835 lonHlp =
static_cast< proshade_signed
> ( bestLongitude - 1 +
static_cast< proshade_double
> ( lonIt ) );
if ( lonHlp < 0 ) { lonHlp += angDim; }
if ( lonHlp >= angDim ) { lonHlp -= angDim; }
2836 interpGrid[latIt][lonIt] = sphereMappedRotFun->at(sphereList->at(sphereIt))->getSphereLatLonPosition (
static_cast< proshade_unsign
> ( latHlp ) ,
static_cast< proshade_unsign
> ( lonHlp ) );
2842 interpols->emplace_back ( biCubInterp );
2845 for ( proshade_unsign iter = 0; iter < 4; iter++ ) {
delete[] interpGrid[iter]; }
2846 delete[] interpGrid;
2864 void ProSHADE_internal_maths::prepareBiCubicInterpolatorsPlusMinus ( proshade_double bestLattitude, proshade_double bestLongitude, std::vector<proshade_unsign>* sphereList, std::vector<ProSHADE_internal_maths::BicubicInterpolator*>* interpols, std::vector<ProSHADE_internal_spheres::ProSHADE_rotFun_sphere*>* sphereMappedRotFun )
2867 proshade_signed latHlp, lonHlp;
2868 proshade_signed angDim =
static_cast< proshade_signed
> ( sphereMappedRotFun->at(0)->getAngularDim() );
2871 for ( proshade_unsign sphereIt = 0; sphereIt < static_cast<proshade_unsign> ( sphereList->size() ); sphereIt++ )
2874 proshade_double** interpGrid =
new proshade_double*[4];
2878 for ( proshade_unsign iter = 0; iter < 4; iter++ )
2880 interpGrid[iter] =
new proshade_double[4];
2885 for ( proshade_unsign latIt = 0; latIt < 4; latIt++ )
2887 for ( proshade_unsign lonIt = 0; lonIt < 4; lonIt++ )
2889 latHlp =
static_cast< proshade_signed
> ( bestLattitude - 1 +
static_cast< proshade_double
> ( latIt ) );
if ( latHlp < 0 ) { latHlp += angDim; }
if ( latHlp >= angDim ) { latHlp -= angDim; }
2890 lonHlp =
static_cast< proshade_signed
> ( bestLongitude - 2 +
static_cast< proshade_double
> ( lonIt ) );
if ( lonHlp < 0 ) { lonHlp += angDim; }
if ( lonHlp >= angDim ) { lonHlp -= angDim; }
2891 interpGrid[latIt][lonIt] = sphereMappedRotFun->at(sphereList->at(sphereIt))->getSphereLatLonPosition (
static_cast< proshade_unsign
> ( latHlp ),
static_cast< proshade_unsign
> ( lonHlp ) );
2897 interpols->emplace_back ( biCubInterp );
2900 for ( proshade_unsign iter = 0; iter < 4; iter++ ) {
delete[] interpGrid[iter]; }
2901 delete[] interpGrid;
2919 void ProSHADE_internal_maths::prepareBiCubicInterpolatorsPlusPlus ( proshade_double bestLattitude, proshade_double bestLongitude, std::vector<proshade_unsign>* sphereList, std::vector<ProSHADE_internal_maths::BicubicInterpolator*>* interpols, std::vector<ProSHADE_internal_spheres::ProSHADE_rotFun_sphere*>* sphereMappedRotFun )
2922 proshade_signed latHlp, lonHlp;
2923 proshade_signed angDim =
static_cast< proshade_signed
> ( sphereMappedRotFun->at(0)->getAngularDim() );
2926 for ( proshade_unsign sphereIt = 0; sphereIt < static_cast<proshade_unsign> ( sphereList->size() ); sphereIt++ )
2929 proshade_double** interpGrid =
new proshade_double*[4];
2933 for ( proshade_unsign iter = 0; iter < 4; iter++ )
2935 interpGrid[iter] =
new proshade_double[4];
2940 for ( proshade_unsign latIt = 0; latIt < 4; latIt++ )
2942 for ( proshade_unsign lonIt = 0; lonIt < 4; lonIt++ )
2944 latHlp =
static_cast< proshade_signed
> ( bestLattitude - 1 +
static_cast< proshade_double
> ( latIt ) );
if ( latHlp < 0 ) { latHlp += angDim; }
if ( latHlp >= angDim ) { latHlp -= angDim; }
2945 lonHlp =
static_cast< proshade_signed
> ( bestLongitude - 1 +
static_cast< proshade_double
> ( lonIt ) );
if ( lonHlp < 0 ) { lonHlp += angDim; }
if ( lonHlp >= angDim ) { lonHlp -= angDim; }
2946 interpGrid[latIt][lonIt] = sphereMappedRotFun->at(sphereList->at(sphereIt))->getSphereLatLonPosition (
static_cast< proshade_unsign
> ( latHlp ),
static_cast< proshade_unsign
> ( lonHlp ) );
2952 interpols->emplace_back ( biCubInterp );
2955 for ( proshade_unsign iter = 0; iter < 4; iter++ ) {
delete[] interpGrid[iter]; }
2956 delete[] interpGrid;
2978 proshade_unsign whichImprove = 0;
2981 for ( proshade_unsign grIt = 0; grIt < static_cast<proshade_unsign> ( CSymList->size() ); grIt++ )
2984 const FloatingPoint< proshade_double > lhs ( CSymList->at(grIt)[0] ), rhs ( axis[0] );
2985 if ( lhs.AlmostEquals ( rhs ) )
2990 whichImprove = grIt;
2997 if ( improve && !ret )
2999 if ( axis[5] > CSymList->at(whichImprove)[5] )
3001 CSymList->at(whichImprove)[1] = axis[1];
3002 CSymList->at(whichImprove)[2] = axis[2];
3003 CSymList->at(whichImprove)[3] = axis[3];
3004 CSymList->at(whichImprove)[4] = axis[4];
3005 CSymList->at(whichImprove)[5] = axis[5];
3032 for ( proshade_unsign grIt = 0; grIt < static_cast<proshade_unsign> ( CSymList->size() ); grIt++ )
3034 const FloatingPoint< proshade_double > lhs ( fold ), rhs ( CSymList->at(grIt)[0] );
3035 if ( lhs.AlmostEquals ( rhs ) )
3061 std::vector< proshade_unsign > ret;
3062 std::vector< std::pair< proshade_unsign, bool > > sieveOfEratosthenesArray;
3065 if ( upTo < 2 ) {
return ( ret ); }
3068 for ( proshade_unsign iter = 2; iter <= upTo; iter++ ) { sieveOfEratosthenesArray.emplace_back ( std::pair< proshade_unsign, bool > ( iter,
true ) ); }
3071 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( sieveOfEratosthenesArray.size() ); iter++ )
3074 if ( sieveOfEratosthenesArray.at(iter).second )
3077 for ( proshade_unsign it = iter + sieveOfEratosthenesArray.at(iter).first; it < static_cast<proshade_unsign> ( sieveOfEratosthenesArray.size() ); it += sieveOfEratosthenesArray.at(iter).first )
3079 sieveOfEratosthenesArray.at(it).second =
false;
3085 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( sieveOfEratosthenesArray.size() ); iter++ )
3106 proshade_double zScore = ( val / sigma );
3107 proshade_double cumulativeProbability = 0.5 * std::erfc ( zScore * M_SQRT1_2 );
3110 if ( cumulativeProbability > 0.5 ) { cumulativeProbability = 1.0 - cumulativeProbability; }
3113 return ( cumulativeProbability );
3132 proshade_signed windowHalf = ( windowSize - 1 ) / 2;
3133 proshade_signed totSize =
static_cast< proshade_signed
> ( ( 1.0 / step ) + 1 );
3134 std::vector< proshade_double > smoothened (
static_cast< size_t > ( totSize - ( windowSize - 1 ) ), 0.0 );
3135 std::vector< proshade_double > winWeights (
static_cast< size_t > ( windowSize ), 0.0 );
3138 for ( proshade_double winIt = 0.0; winIt < static_cast< proshade_double > ( windowSize ); winIt += 1.0 ) { winWeights.at(
static_cast< proshade_unsign
> ( winIt ) ) =
ProSHADE_internal_maths::computeGaussian ( ( winIt -
static_cast< proshade_double
> ( windowHalf ) ) * step, sigma ); }
3141 for ( proshade_unsign it = 0; it < static_cast< proshade_unsign > ( smoothened.size() ); it++ )
3144 for ( proshade_signed winIt = 0; winIt < windowSize; winIt++ )
3146 smoothened.at(it) += winWeights.at(
static_cast< size_t > ( winIt ) ) * data.at(
static_cast< size_t > (
static_cast< proshade_signed
> ( it ) + winIt ) );
3151 return ( smoothened );
3168 proshade_single vol = ( xDim * yDim * zDim );
3169 proshade_single sa = ( yDim * zDim ) / vol;
3170 proshade_single sb = ( xDim * zDim ) / vol;
3171 proshade_single sc = ( xDim * yDim ) / vol;
3174 proshade_single s2 = ( std::pow ( h * sa, 2.0f ) +
3175 std::pow ( k * sb, 2.0f ) +
3176 std::pow ( l * sc, 2.0f ) ) / 4.0f;
3179 if ( s2 == 0.0f ) { s2 = 0.0000000001f; }
3182 return ( 1.0f / ( 2.0f * std::sqrt ( s2 ) ) );
3202 binIndexing =
new proshade_signed [xInds * yInds * zInds];
3204 for (
size_t iter = 0; iter < static_cast< size_t > ( xInds * yInds * zInds ); iter++ ) { binIndexing[iter] = -100; }
3205 proshade_single xIndsF =
static_cast< proshade_single
> ( xInds ), yIndsF =
static_cast< proshade_single
> ( yInds ), zIndsF =
static_cast< proshade_single
> ( zInds );
3208 proshade_single *mins =
new proshade_single[3];
3209 proshade_single *maxs =
new proshade_single[3];
3210 proshade_single *resMins =
new proshade_single[3];
3211 proshade_signed *resMinLoc =
new proshade_signed[3];
3212 proshade_single *steps =
new proshade_single[3];
3222 proshade_single resol = 0.0f;
3223 proshade_signed reciX, reciY, reciZ, arrPos = 0, minLoc = -1;
3227 mins[0] = std::floor ( xIndsF / -2.0f );
3228 mins[1] = std::floor ( yIndsF / -2.0f );
3229 mins[2] = std::floor ( zIndsF / -2.0f );
3235 if ( xInds % 2 == 0 ) { mins[0] += 1.0f; }
3236 if ( yInds % 2 == 0 ) { mins[1] += 1.0f; }
3237 if ( zInds % 2 == 0 ) { mins[2] += 1.0f; }
3245 resMinLoc[0] = 0; resMinLoc[1] = 0; resMinLoc[2] = 0;
3246 const FloatingPoint< proshade_single > lhs1 ( resMins[0] ), lhs2 ( resMins[1] ), lhs3 ( resMins[2] ), rhs1 ( std::min( resMins[0], std::min( resMins[1], resMins[2] ) ) );
3247 if ( lhs1.AlmostEquals ( rhs1 ) ) { resMinLoc[0] = 1; minLoc = 0; }
3248 if ( lhs2.AlmostEquals ( rhs1 ) ) { resMinLoc[1] = 1; minLoc = 1; }
3249 if ( lhs3.AlmostEquals ( rhs1 ) ) { resMinLoc[2] = 1; minLoc = 2; }
3252 std::vector< proshade_single > resArray (
static_cast< size_t > ( maxs[minLoc] - 1 ), 0.0f );
3253 std::vector< proshade_single > binArray (
static_cast< size_t > ( maxs[minLoc] - 1 ), 0.0f );
3254 for ( proshade_signed dimIt = 0; dimIt < static_cast< proshade_signed > ( maxs[minLoc] - 1 ); dimIt++ )
3257 steps[0] = (
static_cast< proshade_single
> ( dimIt ) + 2.5f ) *
static_cast< proshade_single
> ( resMinLoc[0] );
3258 steps[1] = (
static_cast< proshade_single
> ( dimIt ) + 2.5f ) *
static_cast< proshade_single
> ( resMinLoc[1] );
3259 steps[2] = (
static_cast< proshade_single
> ( dimIt ) + 2.5f ) *
static_cast< proshade_single
> ( resMinLoc[2] );
3265 resArray.at(
static_cast< size_t > ( dimIt ) ) = resol;
3266 binArray.at(
static_cast< size_t > ( dimIt ) ) =
static_cast< proshade_single
> ( dimIt ) + 2.5f;
3271 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xInds ); xIt++ )
3273 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yInds ); yIt++ )
3275 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zInds / 2 ) + 1; zIt++ )
3278 reciX = xIt;
if ( reciX >
static_cast< proshade_signed
> ( maxs[0] ) ) { reciX -=
static_cast< proshade_signed
> ( xInds ); }
3279 reciY = yIt;
if ( reciY >
static_cast< proshade_signed
> ( maxs[1] ) ) { reciY -=
static_cast< proshade_signed
> ( yInds ); }
3280 reciZ = zIt;
if ( reciZ >
static_cast< proshade_signed
> ( maxs[2] ) ) { reciZ -=
static_cast< proshade_signed
> ( zInds ); }
3283 for ( proshade_signed binIt = 0; binIt < (*noBin); binIt++ )
3286 if ( std::sqrt ( std::pow (
static_cast< proshade_single
> ( reciX ), 2.0f ) +
3287 std::pow (
static_cast< proshade_single
> ( reciY ), 2.0f ) +
3288 std::pow (
static_cast< proshade_single
> ( reciZ ), 2.0f ) ) <= binArray.at(
static_cast< size_t > ( binIt ) ) )
3291 arrPos = zIt +
static_cast< proshade_signed
> ( zInds ) * ( yIt +
static_cast< proshade_signed
> ( yInds ) * xIt );
3292 binIndexing[
static_cast< size_t > ( arrPos ) ] = binIt;
3295 if ( reciX ==
static_cast< proshade_signed
> ( mins[0] ) || -reciX ==
static_cast< proshade_signed
> ( mins[0] ) ) {
break; }
3296 if ( reciY ==
static_cast< proshade_signed
> ( mins[1] ) || -reciY ==
static_cast< proshade_signed
> ( mins[1] ) ) {
break; }
3297 if ( reciZ ==
static_cast< proshade_signed
> ( mins[2] ) || -reciZ ==
static_cast< proshade_signed
> ( mins[2] ) ) {
break; }
3300 reciX *= -1;
if ( reciX < 0 ) { reciX +=
static_cast< proshade_signed
> ( xInds ); }
3301 reciY *= -1;
if ( reciY < 0 ) { reciY +=
static_cast< proshade_signed
> ( yInds ); }
3302 reciZ *= -1;
if ( reciZ < 0 ) { reciZ +=
static_cast< proshade_signed
> ( zInds ); }
3305 arrPos = reciZ +
static_cast< proshade_signed
> ( zInds ) * ( reciY +
static_cast< proshade_signed
> ( yInds ) * reciX );
3306 binIndexing[
static_cast< size_t > ( arrPos ) ] = binIt;
3347 proshade_double
ProSHADE_internal_maths::computeFSC ( fftw_complex *fCoeffs1, fftw_complex *fCoeffs2, proshade_unsign xInds, proshade_unsign yInds, proshade_unsign zInds, proshade_signed noBins, proshade_signed* binIndexing, proshade_double**& binData, proshade_signed*& binCounts, proshade_double*& fscByBin )
3350 proshade_double realOrig, realRot, imagOrig, imagRot, fsc = 0.0;;
3351 proshade_signed indx, arrPos;
3352 std::vector< proshade_double > covarByBin (
static_cast< size_t > ( noBins ), 0.0 );
3355 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ ) {
for (
size_t valIt = 0; valIt < 12; valIt++ ) { binData[binIt][valIt] = 0.0; } }
3356 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ ) { binCounts[binIt] = 0; }
3359 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xInds ); xIt++ )
3361 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yInds ); yIt++ )
3363 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zInds ); zIt++ )
3366 arrPos = zIt +
static_cast< proshade_signed
> ( zInds ) * ( yIt +
static_cast< proshade_signed
> ( yInds ) * xIt );
3369 indx = binIndexing[
static_cast< size_t > ( arrPos ) ];
3370 if ( ( indx < 0 ) || ( indx > noBins ) ) {
continue; }
3373 realOrig = fCoeffs1[arrPos][0];
3374 imagOrig = fCoeffs1[arrPos][1];
3375 realRot = fCoeffs2[arrPos][0];
3376 imagRot = fCoeffs2[arrPos][1];
3378 binData[indx][0] += realOrig;
3379 binData[indx][1] += imagOrig;
3380 binData[indx][2] += realRot;
3381 binData[indx][3] += imagRot;
3382 binData[indx][4] += realOrig * realRot;
3383 binData[indx][5] += imagOrig * imagRot;
3384 binData[indx][6] += std::pow ( realOrig, 2.0 );
3385 binData[indx][7] += std::pow ( imagOrig, 2.0 );
3386 binData[indx][8] += std::pow ( realRot, 2.0 );
3387 binData[indx][9] += std::pow ( imagRot, 2.0 );
3390 binCounts[indx] += 1;
3396 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ )
3398 covarByBin.at(binIt) = ( ( binData[binIt][4] + binData[binIt][5] ) /
static_cast< proshade_double
> ( binCounts[binIt] ) -
3399 ( ( binData[binIt][0] /
static_cast< proshade_double
> ( binCounts[binIt] ) *
3400 binData[binIt][2] /
static_cast< proshade_double
> ( binCounts[binIt] ) ) +
3401 ( binData[binIt][1] /
static_cast< proshade_double
> ( binCounts[binIt] ) *
3402 binData[binIt][3] /
static_cast< proshade_double
> ( binCounts[binIt] ) ) ) );
3406 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ )
3408 binData[binIt][10] = ( binData[binIt][6] + binData[binIt][7] ) /
static_cast< proshade_double
> ( binCounts[binIt] ) -
3409 ( std::pow ( binData[binIt][0] /
static_cast< proshade_double
> ( binCounts[binIt] ), 2.0 ) +
3410 std::pow ( binData[binIt][1] /
static_cast< proshade_double
> ( binCounts[binIt] ), 2.0 ) );
3411 binData[binIt][11] = ( binData[binIt][8] + binData[binIt][9] ) /
static_cast< proshade_double
> ( binCounts[binIt] ) -
3412 ( std::pow ( binData[binIt][2] /
static_cast< proshade_double
> ( binCounts[binIt] ), 2.0 ) +
3413 std::pow ( binData[binIt][3] /
static_cast< proshade_double
> ( binCounts[binIt] ), 2.0 ) );
3414 fscByBin[binIt] = covarByBin.at(binIt) / ( std::sqrt ( binData[binIt][10] ) * std::sqrt ( binData[binIt][11] ) );
3418 proshade_double binSizeSum = 0.0;
3419 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ )
3421 fsc += fscByBin[binIt] *
static_cast< proshade_double
> ( binCounts[binIt] );
3422 binSizeSum +=
static_cast< proshade_double
> ( binCounts[binIt] );
3424 fsc /=
static_cast< proshade_double
> ( binSizeSum );
3446 void ProSHADE_internal_maths::computeFSCWeightByBin ( proshade_double*& weights1, proshade_double*& weights2, proshade_signed* binIndexing, proshade_double* fscByBin, proshade_signed noBins, proshade_signed xDim, proshade_signed yDim, proshade_signed zDim )
3449 proshade_signed indx, arrPos, reciX, reciY, reciZ;
3452 weights1 =
new proshade_double[xDim * yDim * zDim];
3453 weights2 =
new proshade_double[xDim * yDim * zDim];
3454 proshade_single *mins =
new proshade_single[3];
3455 proshade_single *maxs =
new proshade_single[3];
3464 for (
size_t iter = 0; iter < static_cast< size_t > ( xDim * yDim * zDim ); iter++ ) { weights1[iter] = -100.0; weights2[iter] = -100.0; }
3467 mins[0] = std::floor (
static_cast< proshade_single
> ( xDim ) / -2.0f );
3468 mins[1] = std::floor (
static_cast< proshade_single
> ( yDim ) / -2.0f );
3469 mins[2] = std::floor (
static_cast< proshade_single
> ( zDim ) / -2.0f );
3475 if ( xDim % 2 == 0 ) { mins[0] += 1.0f; }
3476 if ( yDim % 2 == 0 ) { mins[1] += 1.0f; }
3477 if ( zDim % 2 == 0 ) { mins[2] += 1.0f; }
3480 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
3482 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
3484 for ( proshade_signed zIt = 0; zIt < ( ( zDim / 2 ) + 1 ); zIt++ )
3487 reciX = xIt;
if ( reciX >
static_cast< proshade_signed
> ( maxs[0] ) ) { reciX -=
static_cast< proshade_signed
> ( xDim ); }
3488 reciY = yIt;
if ( reciY >
static_cast< proshade_signed
> ( maxs[1] ) ) { reciY -=
static_cast< proshade_signed
> ( yDim ); }
3489 reciZ = zIt;
if ( reciZ >
static_cast< proshade_signed
> ( maxs[2] ) ) { reciZ -=
static_cast< proshade_signed
> ( zDim ); }
3492 arrPos = zIt + zDim * ( yIt + yDim * xIt );
3493 indx = binIndexing[
static_cast< size_t > ( arrPos ) ];
3496 if ( ( indx < 0 ) || ( indx > noBins ) ) {
continue; }
3499 weights1[arrPos] = fscByBin[indx];
3500 weights2[arrPos] = std::pow ( fscByBin[indx], 2.0 );
3503 if ( reciX ==
static_cast< proshade_signed
> ( mins[0] ) || -reciX ==
static_cast< proshade_signed
> ( mins[0] ) ) {
break; }
3504 if ( reciY ==
static_cast< proshade_signed
> ( mins[1] ) || -reciY ==
static_cast< proshade_signed
> ( mins[1] ) ) {
break; }
3505 if ( reciZ ==
static_cast< proshade_signed
> ( mins[2] ) || -reciZ ==
static_cast< proshade_signed
> ( mins[2] ) ) {
break; }
3508 reciX *= -1;
if ( reciX < 0 ) { reciX += xDim; }
3509 reciY *= -1;
if ( reciY < 0 ) { reciY += yDim; }
3510 reciZ *= -1;
if ( reciZ < 0 ) { reciZ += zDim; }
3513 arrPos = reciZ + zDim * ( reciY + yDim * reciX );
3514 weights1[arrPos] = fscByBin[indx];
3515 weights2[arrPos] = std::pow ( fscByBin[indx], 2.0 );
3541 proshade_double sum = 0.0;
3542 proshade_signed arrPos;
3545 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
3547 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
3549 for ( proshade_signed zIt = 0; zIt < ( ( zDim / 2 ) + 1 ); zIt++ )
3552 arrPos = zIt + zDim * ( yIt + yDim * xIt );
3555 if ( weights[arrPos] > -2.0 ) { sum += fCoeffs[arrPos][0]; }
3576 void ProSHADE_internal_maths::computeTrFunDerivatives ( proshade_complex* fCoeffs, proshade_double* weights1, proshade_double* weights2, proshade_signed xDim, proshade_signed yDim, proshade_signed zDim, proshade_double*& firstDers, proshade_double*& secondDers )
3579 firstDers =
new proshade_double[3];
3580 secondDers =
new proshade_double[9];
3581 proshade_single *mins =
new proshade_single[3];
3582 proshade_single *maxs =
new proshade_single[3];
3591 std::complex< proshade_double > piConstFirst ( 2.0 * M_PI, 1.0 );
3592 proshade_double piConstSecond = std::pow ( 2.0 * M_PI, 2.0 );
3593 for (
size_t iter = 0; iter < 3; iter++ ) { firstDers[iter] = 0.0; }
3594 for (
size_t iter = 0; iter < 9; iter++ ) { secondDers[iter] = 0.0; }
3595 proshade_signed reciX, reciY, reciZ, arrPos;
3598 mins[0] = std::floor (
static_cast< proshade_single
> ( xDim ) / -2.0f );
3599 mins[1] = std::floor (
static_cast< proshade_single
> ( yDim ) / -2.0f );
3600 mins[2] = std::floor (
static_cast< proshade_single
> ( zDim ) / -2.0f );
3606 if ( xDim % 2 == 0 ) { mins[0] += 1.0f; }
3607 if ( yDim % 2 == 0 ) { mins[1] += 1.0f; }
3608 if ( zDim % 2 == 0 ) { mins[2] += 1.0f; }
3611 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
3613 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
3615 for ( proshade_signed zIt = 0; zIt < ( ( zDim / 2 ) + 1 ); zIt++ )
3618 reciX = xIt;
if ( reciX >
static_cast< proshade_signed
> ( maxs[0] ) ) { reciX -=
static_cast< proshade_signed
> ( xDim ); }
3619 reciY = yIt;
if ( reciY >
static_cast< proshade_signed
> ( maxs[1] ) ) { reciY -=
static_cast< proshade_signed
> ( yDim ); }
3620 reciZ = zIt;
if ( reciZ >
static_cast< proshade_signed
> ( maxs[2] ) ) { reciZ -=
static_cast< proshade_signed
> ( zDim ); }
3623 arrPos = zIt + zDim * ( yIt + yDim * xIt );
3626 if ( weights1[arrPos] < -2.0 ) {
continue; }
3629 firstDers[0] += ( weights1[arrPos] * fCoeffs[arrPos][0] * std::conj( fCoeffs[arrPos][1] * piConstFirst *
static_cast< proshade_double
> ( reciX ) ) ).real();
3630 firstDers[1] += ( weights1[arrPos] * fCoeffs[arrPos][0] * std::conj( fCoeffs[arrPos][1] * piConstFirst *
static_cast< proshade_double
> ( reciY ) ) ).real();
3631 firstDers[2] += ( weights1[arrPos] * fCoeffs[arrPos][0] * std::conj( fCoeffs[arrPos][1] * piConstFirst *
static_cast< proshade_double
> ( reciZ ) ) ).real();
3634 secondDers[0] += weights2[arrPos] * reciX * reciX;
3635 secondDers[1] += weights2[arrPos] * reciX * reciY;
3636 secondDers[2] += weights2[arrPos] * reciX * reciZ;
3637 secondDers[4] += weights2[arrPos] * reciY * reciY;
3638 secondDers[5] += weights2[arrPos] * reciY * reciZ;
3639 secondDers[8] += weights2[arrPos] * reciZ * reciZ;
3645 secondDers[3] = secondDers[1];
3646 secondDers[6] = secondDers[2];
3647 secondDers[7] = secondDers[5];
3648 for (
size_t iter = 0; iter < 9; iter++ ) { secondDers[iter] *= -piConstSecond; }
3668 std::vector < proshade_double > tmpMap ( 9, 0.0 );
3669 for (
size_t iter = 0; iter < 9; iter++ ) { tmpMap.at(iter) = secondDers[iter]; }
3670 tmpMap.at(0) += 1.0; tmpMap.at(4) += 1.0; tmpMap.at(8) += 1.0;
3696 std::vector< proshade_signed > ret;
3699 for ( proshade_signed index = 0; index < static_cast< proshade_signed > ( data.size() ); index++ )
3709 if ( index ==
static_cast< proshade_signed
> ( data.size() - 1 ) )
3716 if ( ( data.at(
static_cast< size_t > ( index ) ) > data.at(
static_cast< size_t > ( index ) - 1 ) ) &&
3720 if ( index <
static_cast< proshade_signed
> ( data.size() - 2 ) ) {
if ( data.at(
static_cast< size_t > ( index ) ) >= data.at(
static_cast< size_t > ( index ) - 1 ) ) {
if ( data.at(
static_cast< size_t > ( index ) ) >= data.at(
static_cast< size_t > ( index ) + 1 ) ) {
if ( data.at(
static_cast< size_t > ( index ) ) > data.at(
static_cast< size_t > ( index ) + 2 ) ) {
ProSHADE_internal_misc::addToSignedVector ( &ret, index ); } } } }
3746 proshade_double threshold = 0.0;
3747 proshade_signed totSize =
static_cast< proshade_signed
> ( ( 1.0 / step ) + 1 );
3748 std::vector< std::pair < proshade_double, proshade_unsign > > vals;
3749 std::vector< proshade_double > hist (
static_cast< unsigned long int > ( totSize ), 0.0 );
3750 proshade_unsign histPos = 0;
3753 if ( windowSize % 2 == 0 ) { windowSize += 1; }
3756 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( CSym->size() ); symIt++ ) { vals.emplace_back ( std::pair < proshade_double, proshade_unsign > ( CSym->at(symIt)[peakPos], symIt ) ); }
3759 for ( proshade_unsign vIt = 0; vIt < static_cast< proshade_unsign > ( vals.size() ); vIt++ ) {
if ( vals.at(vIt).first > maxLim ) { vals.at(vIt).first = maxLim; } }
3762 for ( proshade_double it = 0.0; it <= 1.0; it = it + step )
3764 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( vals.size() ); symIt++ )
3767 if ( ( vals.at(symIt).first > it ) && ( vals.at(symIt).first <= ( it + step ) ) ) { hist.at(histPos) += 1.0; }
3781 proshade_signed bestHistPos;
3782 if ( peaks.size() > 0 ) { bestHistPos = peaks.at(peaks.size()-1) + ( ( windowSize - 1 ) / 2 ); }
3783 else { bestHistPos = 0.0; }
3785 threshold = (
static_cast< proshade_double
> ( bestHistPos ) * step ) - (
static_cast< proshade_double
> ( windowSize - 1 ) * step );
3788 return ( threshold );
3809 proshade_double threshold = 0.0;
3810 proshade_signed totSize =
static_cast< proshade_signed
> ( ( 1.0 / step ) + 1 );
3811 std::vector< std::pair < proshade_double, proshade_unsign > > vals;
3812 std::vector< proshade_double > hist (
static_cast< unsigned long int > ( totSize ), 0.0 );
3813 proshade_unsign histPos = 0;
3816 if ( windowSize % 2 == 0 ) { windowSize += 1; }
3819 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( CSym->size() ); symIt++ ) { vals.emplace_back ( std::pair < proshade_double, proshade_unsign > ( CSym->at(symIt).at(peakPos), symIt ) ); }
3822 for ( proshade_unsign vIt = 0; vIt < static_cast< proshade_unsign > ( vals.size() ); vIt++ ) {
if ( vals.at(vIt).first > maxLim ) { vals.at(vIt).first = maxLim; } }
3826 for ( proshade_double it = 0.0; it <= 1.0; it = it + step )
3828 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( vals.size() ); symIt++ )
3831 if ( ( vals.at(symIt).first > it ) && ( vals.at(symIt).first <= ( it + step ) ) ) { hist.at(histPos) += 1.0; }
3845 proshade_signed bestHistPos;
3846 if ( peaks.size() > 0 ) { bestHistPos = peaks.at(peaks.size()-1) + ( ( windowSize - 1 ) / 2 ); }
3847 else { bestHistPos = 0.0; }
3849 threshold = (
static_cast< proshade_double
> ( bestHistPos ) * step ) - (
static_cast< proshade_double
> ( windowSize ) * step );
3852 return ( threshold );
3868 double normFactor =
static_cast<double> ( xD * yD * zD );
3869 proshade_signed arrPos;
3872 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xD ); xIt++ )
3874 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yD ); yIt++ )
3876 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zD ); zIt++ )
3879 arrPos = zIt +
static_cast< proshade_signed
> ( zD ) * ( yIt +
static_cast< proshade_signed
> ( yD ) * xIt );
3883 &tmpOut1[arrPos][1],
3884 &tmpOut2[arrPos][0],
3885 &tmpOut2[arrPos][1],
3887 &resOut[arrPos][1] );
3890 resOut[arrPos][0] /= normFactor;
3891 resOut[arrPos][1] /= normFactor;
3915 proshade_signed arrPos;
3919 for ( proshade_signed uIt = 0; uIt < static_cast<proshade_signed> ( xD ); uIt++ )
3921 for ( proshade_signed vIt = 0; vIt < static_cast<proshade_signed> ( yD ); vIt++ )
3923 for ( proshade_signed wIt = 0; wIt < static_cast<proshade_signed> ( zD ); wIt++ )
3925 arrPos = wIt +
static_cast< proshade_signed
> ( zD ) * ( vIt +
static_cast< proshade_signed
> ( yD ) * uIt );
3926 if ( resIn[arrPos][0] > *mapPeak )
3928 *mapPeak = resIn[arrPos][0];
3929 *trsX =
static_cast< proshade_double
> ( uIt );
3930 *trsY =
static_cast< proshade_double
> ( vIt );
3931 *trsZ =
static_cast< proshade_double
> ( wIt );