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 getGLFirstRealRoot ( polyValue, order, &abscissas[(order/2)], &weights[(order/2)], noSteps );
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 += 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;
391 throw ProSHADE_exception (
"The number of steps is too low.",
"EI00020", __FILE__, __LINE__, __func__,
"The number of steps 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 *polyTerms;
399 proshade_double *deriTerms;
402 polyTerms =
new proshade_double [noSteps+2];
403 deriTerms =
new proshade_double [noSteps+1];
409 polyTerms[1] = polyAtZero;
413 for ( proshade_unsign iter = 0; iter <= noSteps - 2; iter = iter + 2 )
415 hlp =
static_cast<proshade_double
> ( iter );
417 polyTerms[iter+2] = 0.0;
418 polyTerms[iter+3] = ( hlp * ( hlp + 1.0 ) - hlpVal * ( hlpVal + 1.0 ) ) * polyTerms[iter+1] / (hlp + 1.0) / (hlp + 2.0 );
420 deriTerms[iter+1] = 0.0;
421 deriTerms[iter+2] = ( hlp + 2.0 ) * polyTerms[iter+3];
425 for ( proshade_double iter = 0; iter < noSteps; iter++ )
453 proshade_double factorialValue = 1.0;
454 proshade_double value = 0.0;
457 for ( proshade_unsign iter = 1; iter <= terms; iter++ )
459 value = value + series[iter] * factorialValue;
460 factorialValue = factorialValue * target;
483 proshade_double hlpVal = 0.0;
484 proshade_double stepSize = 0.0;
485 proshade_double valChange = 0.0;
486 proshade_double valSecChange = 0.0;
487 proshade_double squareOrder = 0.0;
488 proshade_double curPos = from;
489 proshade_double curVal = valAtFrom;
492 stepSize = ( to - from ) /
static_cast<proshade_double
> ( noSteps );
493 squareOrder = sqrt (
static_cast<proshade_double
> ( order * ( order + 1 ) ) );
496 for ( proshade_unsign iter = 0; iter < noSteps; iter++ )
498 hlpVal = ( 1.0 - curVal ) * ( 1.0 + curVal );
499 valChange = - stepSize * hlpVal / ( squareOrder * sqrt ( hlpVal ) - ( curVal * std::sin ( 2.0 * curPos ) / 2.0 ) );
504 hlpVal = ( 1.0 - curVal ) * ( 1.0 + curVal );
505 valSecChange = - stepSize * hlpVal / ( squareOrder * sqrt ( hlpVal ) - ( curVal * std::sin ( 2.0 * curPos ) / 2.0 ) );
506 curVal = curVal + ( valSecChange - valChange ) / 2.0;
527 proshade_double hlpStepVal = 0.0;
528 proshade_double hlpOrderVal =
static_cast<proshade_double
> ( order );
529 proshade_double abscValueChange = 0.0;
530 proshade_double prevAbsc = 0.0;
531 proshade_double *polyDecomposition;
532 proshade_double *deriDecomposition;
533 proshade_unsign knownRootPos = 0;
534 proshade_unsign oddEvenSwitch = 0;
537 if ( order % 2 == 1 )
539 knownRootPos = ( order - 1 ) / 2;
544 knownRootPos = order / 2;
549 polyDecomposition =
new proshade_double[noSteps+2];
550 deriDecomposition =
new proshade_double[noSteps+1];
555 for ( proshade_unsign serIt = knownRootPos + 1; serIt < order; serIt++ )
558 prevAbsc = abscissas[serIt-1];
559 abscValueChange =
advanceGLPolyValue ( M_PI/2.0, -M_PI/2.0, prevAbsc, order, noSteps ) - prevAbsc;
562 polyDecomposition[0] = 0.0;
563 polyDecomposition[1] = 0.0;
564 polyDecomposition[2] = weights[serIt-1];
567 deriDecomposition[0] = 0.0;
568 deriDecomposition[1] = polyDecomposition[2];
571 for ( proshade_unsign stIt = 0; stIt <= noSteps - 2; stIt++ )
573 hlpStepVal =
static_cast<proshade_double
> ( stIt );
575 polyDecomposition[stIt+3] = ( 2.0 * prevAbsc * ( hlpStepVal + 1.0 ) * polyDecomposition[stIt+2] + ( hlpStepVal * ( hlpStepVal + 1.0 ) - hlpOrderVal *
576 ( hlpOrderVal + 1.0 ) ) * polyDecomposition[stIt+1] / ( hlpStepVal + 1.0 ) ) / ( 1.0 - prevAbsc ) / ( 1.0 + prevAbsc ) /
577 ( hlpStepVal + 2.0 );
579 deriDecomposition[stIt+2] = ( hlpStepVal + 2.0 ) * polyDecomposition[stIt+3];
583 for ( proshade_unsign iter = 0; iter < noSteps; iter++ )
589 abscissas[serIt] = prevAbsc + abscValueChange;
594 for ( proshade_unsign serIt = 0; serIt < knownRootPos + oddEvenSwitch; serIt++ )
596 abscissas[serIt] = -abscissas[order-serIt-1];
597 weights[serIt] = weights[order-serIt-1];
601 delete polyDecomposition;
602 delete deriDecomposition;
627 proshade_double ret = 0.0;
628 proshade_complex* intData =
new proshade_complex[order];
630 proshade_complex posVals;
631 proshade_unsign lesserPos = 0;
632 proshade_unsign upperPos = 0;
633 proshade_double lesserWeight = 0.0;
634 proshade_double upperWeight = 0.0;
637 for ( proshade_unsign absIter = 0; absIter < order; absIter++ )
644 posVals[0] = ( ( abscissas[absIter] + 1.0 ) / 2.0 ) * integralOverRange;
648 for ( proshade_unsign valIt = 0; valIt < valsSize; valIt++ )
650 if ( ( (
static_cast< proshade_double
> ( valIt ) * maxSphereDists ) <= posVals[0] ) && ( ( (
static_cast< proshade_double
> ( valIt ) + 1.0 ) * maxSphereDists ) > posVals[0] ) )
652 lesserPos =
static_cast<proshade_unsign
> ( valIt );
653 upperPos =
static_cast<proshade_unsign
> ( valIt + 1 );
661 if ( lesserPos != 0 )
664 lesserWeight =
static_cast< proshade_double
> ( upperPos ) - ( posVals[0] / maxSphereDists );
665 upperWeight = 1.0 - lesserWeight;
667 posVals[1] = ( lesserWeight * vals[lesserPos-1] ) + ( upperWeight * vals[upperPos-1] );
672 upperWeight = 1.0 - (
static_cast< proshade_double
> ( upperPos ) - ( posVals[0] / maxSphereDists ) );
674 posVals[1] = ( upperWeight * vals[upperPos-1] );
677 intData[absIter][0] = posVals[0];
678 intData[absIter][1] = posVals[1];
682 for ( proshade_unsign absPoint = 0; absPoint < order; absPoint++ )
684 ret += ( weights[absPoint] * intData[absPoint][1] );
688 ret *= ( integralOverRange / 2.0 );
714 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 )
717 proshade_triplet* intData =
new proshade_triplet [order];
719 proshade_triplet posVals;
720 proshade_unsign lesserPos = 0;
721 proshade_unsign upperPos = 0;
722 proshade_double lesserWeight = 0.0;
723 proshade_double upperWeight = 0.0;
726 for ( proshade_unsign absIter = 0; absIter < order; absIter++ )
734 posVals[0] = ( ( abscissas[absIter] + 1.0 ) / 2.0 ) * integralOverRange;
738 for ( proshade_unsign valIt = 0; valIt < valsSize; valIt++ )
740 if ( ( (
static_cast< proshade_double
> ( valIt ) * maxSphereDists ) <= posVals[0] ) && ( ( (
static_cast< proshade_double
> ( valIt ) + 1.0 ) * maxSphereDists ) > posVals[0] ) )
742 lesserPos =
static_cast<proshade_unsign
> ( valIt );
743 upperPos =
static_cast<proshade_unsign
> ( valIt + 1 );
751 if ( lesserPos != 0 )
754 lesserWeight =
static_cast< proshade_double
> ( upperPos ) - ( posVals[0] / maxSphereDists );
755 upperWeight = 1.0 - lesserWeight;
757 posVals[1] = ( lesserWeight * vals[lesserPos-1][0] ) + ( upperWeight * vals[upperPos-1][0] );
758 posVals[2] = ( lesserWeight * vals[lesserPos-1][1] ) + ( upperWeight * vals[upperPos-1][1] );
763 upperWeight = 1.0 - (
static_cast< proshade_double
> ( upperPos ) - ( posVals[0] / maxSphereDists ) );
765 posVals[1] = ( upperWeight * vals[upperPos-1][0] );
766 posVals[2] = ( upperWeight * vals[upperPos-1][1] );
769 intData[absIter][0] = posVals[0];
770 intData[absIter][1] = posVals[1];
771 intData[absIter][2] = posVals[2];
777 for ( proshade_unsign absPoint = 0; absPoint < order; absPoint++ )
779 *retReal += ( weights[absPoint] * intData[absPoint][1] );
780 *retImag += ( weights[absPoint] * intData[absPoint][2] );
784 *retReal *= ( integralOverRange / 2.0 );
785 *retImag *= ( integralOverRange / 2.0 );
811 std::complex<double> *rotMatU =
new std::complex<double> [dim*dim];
812 std::complex<double> *rotMatV =
new std::complex<double> [dim*dim];
813 std::complex<double> *work =
new std::complex<double> [( 4 * dim)];
814 int workDim = ( 4 * dim);
815 double* rwork =
new double[(7 * dim)];
816 int* iwork =
new int[(8 * dim)];
827 std::complex<double> *matrixToDecompose =
new std::complex<double>[dim*dim];
829 for (
int rowIt = 0; rowIt < dim; rowIt++ )
831 for (
int colIt = 0; colIt < dim; colIt++ )
833 matrixToDecompose[(colIt*dim)+rowIt] = std::complex<double> ( mat[rowIt][colIt][0], mat[rowIt][colIt][1] );
838 zgesdd_ ( &job, &dim, &dim, matrixToDecompose, &dim, singularValues, rotMatU, &dim, rotMatV, &dim,
839 work, &workDim, rwork, iwork, &returnValue );
847 delete[] matrixToDecompose;
850 if ( returnValue != 0 )
852 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." );
878 double* singularValues =
new double[dim];
879 double *rotMatU =
new double [dim*dim];
880 double *rotMatV =
new double [dim*dim];
881 double *work =
new double [
static_cast< proshade_unsign
>( ( 3 * dim ) + pow( dim, 2 ) * dim)];
882 int workDim =
static_cast< int > ( 2 * ( ( 4 * dim * dim ) + ( 7 * dim ) ) );
883 double* rwork =
new double[
static_cast<proshade_unsign
>((5 * dim) + 5 * pow(dim,2))];
884 int* iwork =
new int[(8 * dim)];
894 double *matrixToDecompose =
new double[dim*dim];
896 for (
int rowIt = 0; rowIt < dim; rowIt++ )
898 for (
int colIt = 0; colIt < dim; colIt++ )
900 matrixToDecompose[(colIt*dim)+rowIt] = mat[(rowIt*dim)+colIt];
905 dgesdd_ ( &job, &dim, &dim, matrixToDecompose, &dim, singularValues, rotMatU, &dim, rotMatV, &dim,
906 work, &workDim, rwork, iwork, &returnValue );
912 delete[] matrixToDecompose;
913 delete[] singularValues;
916 if ( ( returnValue != 0 ) && ( fail ) )
918 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." );
920 if ( ( returnValue != 0 ) && ( !fail ) )
927 for ( proshade_signed rowIt = 0; rowIt < dim; rowIt++ )
929 for ( proshade_signed colIt = 0; colIt < dim; colIt++ )
931 uAndV[(rowIt*3)+colIt] = rotMatU[( rowIt * 3 ) + colIt];
936 for ( proshade_signed rowIt = 0; rowIt < dim; rowIt++ )
938 for ( proshade_signed colIt = 0; colIt < dim; colIt++ )
940 uAndV[(rowIt*3)+colIt+9] = rotMatV[( rowIt * 3 ) + colIt];
969 *eulerAlpha = M_PI *
static_cast<proshade_double
> ( y ) / (
static_cast<proshade_double
> ( band ) ) ;
970 *eulerBeta = M_PI * ( 2.0 *
static_cast<proshade_double
> ( x ) ) / ( 4.0 *
static_cast<proshade_double
> ( band ) ) ;
971 *eulerGamma = M_PI *
static_cast<proshade_double
> ( z ) / (
static_cast<proshade_double
> ( band ) ) ;
994 *x = ( eulerBeta *
static_cast<proshade_double
> ( band ) * 2.0 ) / M_PI;
995 *y = ( eulerGamma *
static_cast<proshade_double
> ( band ) ) / M_PI;
996 *z = ( eulerAlpha *
static_cast<proshade_double
> ( band ) ) / M_PI;
999 if ( *x >= ( 2.0 *
static_cast<proshade_double
> ( band - 1 ) ) ) { *x = ( 2.0 *
static_cast<proshade_double
> ( band ) ) - 1.0; }
1000 if ( *y >= ( 2.0 *
static_cast<proshade_double
> ( band - 1 ) ) ) { *y = ( 2.0 *
static_cast<proshade_double
> ( band ) ) - 1.0; }
1001 if ( *z >= ( 2.0 *
static_cast<proshade_double
> ( band - 1 ) ) ) { *z = ( 2.0 *
static_cast<proshade_double
> ( band ) ) - 1.0; }
1003 if ( *x < 0.0 ) { *x = 0.0; }
1004 if ( *y < 0.0 ) { *y = 0.0; }
1005 if ( *z < 0.0 ) { *z = 0.0; }
1022 matrix[0] = cos ( eulerAlpha ) * cos ( eulerBeta ) * cos ( eulerGamma ) - sin ( eulerAlpha ) * sin ( eulerGamma );
1023 matrix[1] = sin ( eulerAlpha ) * cos ( eulerBeta ) * cos ( eulerGamma ) + cos ( eulerAlpha ) * sin ( eulerGamma );
1024 matrix[2] = -sin ( eulerBeta ) * cos ( eulerGamma );
1027 matrix[3] = -cos ( eulerAlpha ) * cos ( eulerBeta ) * sin ( eulerGamma ) - sin ( eulerAlpha ) * cos ( eulerGamma );
1028 matrix[4] = -sin ( eulerAlpha ) * cos ( eulerBeta ) * sin ( eulerGamma ) + cos ( eulerAlpha ) * cos ( eulerGamma );
1029 matrix[5] = sin ( eulerBeta ) * sin ( eulerGamma );
1032 matrix[6] = cos ( eulerAlpha ) * sin ( eulerBeta );
1033 matrix[7] = sin ( eulerAlpha ) * sin ( eulerBeta );
1034 matrix[8] = cos ( eulerBeta );
1051 matrix[0] = cos ( eulerAlpha ) * cos ( eulerBeta ) * cos ( eulerGamma ) - sin ( eulerAlpha ) * sin ( eulerGamma );
1052 matrix[1] = sin ( eulerAlpha ) * cos ( eulerBeta ) * cos ( eulerGamma ) + cos ( eulerAlpha ) * sin ( eulerGamma );
1053 matrix[2] = -sin ( eulerBeta ) * cos ( eulerGamma );
1056 matrix[3] = -cos ( eulerAlpha ) * cos ( eulerBeta ) * sin ( eulerGamma ) - sin ( eulerAlpha ) * cos ( eulerGamma );
1057 matrix[4] = -sin ( eulerAlpha ) * cos ( eulerBeta ) * sin ( eulerGamma ) + cos ( eulerAlpha ) * cos ( eulerGamma );
1058 matrix[5] = sin ( eulerBeta ) * sin ( eulerGamma );
1061 matrix[6] = cos ( eulerAlpha ) * sin ( eulerBeta );
1062 matrix[7] = sin ( eulerAlpha ) * sin ( eulerBeta );
1063 matrix[8] = cos ( eulerBeta );
1086 proshade_double angleTolerance = 0.01;
1087 proshade_double closeToZero = 0.0000001;
1090 *ang = std::acos ( ( std::max ( -1.0, std::min ( 3.0, rotMat[0] + rotMat[4] + rotMat[8] ) ) - 1.0 ) / 2.0 );
1093 if ( std::abs ( std::sin ( *ang ) ) < angleTolerance )
1096 char jobLeftEigs =
'N';
1097 char jobRightEigs =
'V';
1099 double* eigValReal =
new double[dim];
1100 double* eigValImag =
new double[dim];
1101 double* leftEigVectors =
new double[dim*dim*2];
1102 double* rightEigVectors =
new double[dim*dim*2];
1103 double* work =
new double[10*4*dim];
1104 int workSize = 10*4*dim;
1105 int returnValue = 0;
1115 double* matrixToDecompose =
new double[dim*dim];
1117 for (
int rowIt = 0; rowIt < dim; rowIt++ )
1119 for (
int colIt = 0; colIt < dim; colIt++ )
1121 matrixToDecompose[(colIt*dim)+rowIt] =
static_cast< double > ( rotMat[(rowIt*dim)+colIt] );
1126 dgeev_ ( &jobLeftEigs, &jobRightEigs, &dim, matrixToDecompose, &dim, eigValReal, eigValImag, leftEigVectors, &dim,
1127 rightEigVectors, &dim, work, &workSize, &returnValue );
1130 if ( returnValue != 0 )
1139 delete[] eigValReal;
1140 delete[] eigValImag;
1141 delete[] leftEigVectors;
1142 delete[] rightEigVectors;
1144 delete[] matrixToDecompose;
1151 for (
int i = 0; i < 9; i++ ) {
if ( std::abs(rightEigVectors[i]) < closeToZero ) { rightEigVectors[i] = 0.0; } }
1152 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; } }
1155 proshade_signed eigIt = -1;
1156 for (
size_t it = 0; it < 3; it++ )
1158 if ( ( eigValReal[it] > ( 1.0 - closeToZero ) ) && ( eigValReal[it] < ( 1.0 + closeToZero ) ) )
1160 if ( ( eigValImag[it] > ( 0.0 - closeToZero ) ) && ( eigValImag[it] < ( 0.0 + closeToZero ) ) )
1162 eigIt =
static_cast< proshade_signed
> ( it );
1180 for(
int rowIt = 0; rowIt < dim; rowIt++ )
1183 while( colIt < dim )
1185 if( std::abs ( eigValImag[colIt] ) < closeToZero )
1187 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]; } }
1203 proshade_double normFactor = std::sqrt ( pow ( *x, 2.0 ) + pow ( *y, 2.0 ) + pow ( *z, 2.0 ) );
1210 delete[] eigValReal;
1211 delete[] eigValImag;
1212 delete[] leftEigVectors;
1213 delete[] rightEigVectors;
1215 delete[] matrixToDecompose;
1220 *x = rotMat[7] - rotMat[5];
1221 *y = rotMat[2] - rotMat[6];
1222 *z = rotMat[3] - rotMat[1];
1224 proshade_double normFactor = std::sqrt ( pow ( *x, 2.0 ) + pow ( *y, 2.0 ) + pow ( *z, 2.0 ) );
1230 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( *x ), std::max ( std::abs ( *y ), std::abs ( *z ) ) ) );
1231 const FloatingPoint< proshade_double > rhs1 ( std::abs ( *x ) );
1232 const FloatingPoint< proshade_double > rhs2 ( std::abs ( *y ) );
1233 const FloatingPoint< proshade_double > rhs3 ( std::abs ( *z ) );
1234 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( *x < 0.0 ) ) ||
1235 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( *y < 0.0 ) ) ||
1236 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( *z < 0.0 ) ) )
1246 if ( *ang < 0.0 ) { *ang = ( 2.0 * M_PI ) + *ang; }
1269 proshade_double angleTolerance = 0.01;
1270 proshade_double closeToZero = 0.0000001;
1273 *ang = std::acos ( ( std::max ( -1.0, std::min ( 3.0, rotMat->at(0) + rotMat->at(4) + rotMat->at(8) ) ) - 1.0 ) / 2.0 );
1276 if ( std::abs ( std::sin ( *ang ) ) < angleTolerance )
1279 char jobLeftEigs =
'N';
1280 char jobRightEigs =
'V';
1282 double* eigValReal =
new double[dim];
1283 double* eigValImag =
new double[dim];
1284 double* leftEigVectors =
new double[dim*dim*2];
1285 double* rightEigVectors =
new double[dim*dim*2];
1286 double* work =
new double[10*4*dim];
1287 int workSize = 10*4*dim;
1288 int returnValue = 0;
1298 double* matrixToDecompose =
new double[dim*dim];
1300 for (
int rowIt = 0; rowIt < dim; rowIt++ )
1302 for (
int colIt = 0; colIt < dim; colIt++ )
1304 matrixToDecompose[(colIt*dim)+rowIt] =
static_cast< double > ( rotMat->at(
static_cast< size_t > ( ( rowIt * dim ) + colIt ) ) );
1309 dgeev_ ( &jobLeftEigs, &jobRightEigs, &dim, matrixToDecompose, &dim, eigValReal, eigValImag, leftEigVectors, &dim,
1310 rightEigVectors, &dim, work, &workSize, &returnValue );
1313 if ( returnValue != 0 )
1322 delete[] eigValReal;
1323 delete[] eigValImag;
1324 delete[] leftEigVectors;
1325 delete[] rightEigVectors;
1327 delete[] matrixToDecompose;
1334 for (
int i = 0; i < 9; i++ ) {
if ( std::abs(rightEigVectors[i]) < closeToZero ) { rightEigVectors[i] = 0.0; } }
1335 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; } }
1338 proshade_signed eigIt = -1;
1339 for (
size_t it = 0; it < 3; it++ )
1341 if ( ( eigValReal[it] > ( 1.0 - closeToZero ) ) && ( eigValReal[it] < ( 1.0 + closeToZero ) ) )
1343 if ( ( eigValImag[it] > ( 0.0 - closeToZero ) ) && ( eigValImag[it] < ( 0.0 + closeToZero ) ) )
1345 eigIt =
static_cast< proshade_signed
> ( it );
1363 for(
int rowIt = 0; rowIt < dim; rowIt++ )
1366 while( colIt < dim )
1368 if( std::abs ( eigValImag[colIt] ) < closeToZero )
1370 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]; } }
1386 proshade_double normFactor = std::sqrt ( pow ( *x, 2.0 ) + pow ( *y, 2.0 ) + pow ( *z, 2.0 ) );
1392 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( *x ), std::max ( std::abs ( *y ), std::abs ( *z ) ) ) );
1393 const FloatingPoint< proshade_double > rhs1 ( std::abs ( *x ) );
1394 const FloatingPoint< proshade_double > rhs2 ( std::abs ( *y ) );
1395 const FloatingPoint< proshade_double > rhs3 ( std::abs ( *z ) );
1396 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( *x < 0.0 ) ) ||
1397 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( *y < 0.0 ) ) ||
1398 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( *z < 0.0 ) ) )
1407 delete[] eigValReal;
1408 delete[] eigValImag;
1409 delete[] leftEigVectors;
1410 delete[] rightEigVectors;
1412 delete[] matrixToDecompose;
1417 *x = rotMat->at(7) - rotMat->at(5);
1418 *y = rotMat->at(2) - rotMat->at(6);
1419 *z = rotMat->at(3) - rotMat->at(1);
1421 proshade_double normFactor = std::sqrt ( pow ( *x, 2.0 ) + pow ( *y, 2.0 ) + pow ( *z, 2.0 ) );
1427 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( *x ), std::max ( std::abs ( *y ), std::abs ( *z ) ) ) );
1428 const FloatingPoint< proshade_double > rhs1 ( std::abs ( *x ) );
1429 const FloatingPoint< proshade_double > rhs2 ( std::abs ( *y ) );
1430 const FloatingPoint< proshade_double > rhs3 ( std::abs ( *z ) );
1431 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( *x < 0.0 ) ) ||
1432 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( *y < 0.0 ) ) ||
1433 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( *z < 0.0 ) ) )
1443 if ( *ang < 0.0 ) { *ang = ( 2.0 * M_PI ) + *ang; }
1461 if ( ( ang == 0.0 ) || ( std::isinf ( ang ) ) )
1464 for ( proshade_unsign i = 0; i < 9; i++ ) { rotMat[i] = 0.0; }
1474 proshade_double cAng = cos ( ang );
1475 proshade_double sAng = sin ( ang );
1476 proshade_double tAng = 1.0 - cAng;
1478 rotMat[0] = cAng + x * x * tAng;
1479 rotMat[4] = cAng + y * y * tAng;
1480 rotMat[8] = cAng + z * z * tAng;
1482 proshade_double tmp1 = x * y * tAng;
1483 proshade_double tmp2 = z * sAng;
1484 rotMat[3] = tmp1 + tmp2;
1485 rotMat[1] = tmp1 - tmp2;
1487 tmp1 = x * z * tAng;
1489 rotMat[6] = tmp1 - tmp2;
1490 rotMat[2] = tmp1 + tmp2;
1492 tmp1 = y * z * tAng;
1494 rotMat[7] = tmp1 + tmp2;
1495 rotMat[5] = tmp1 - tmp2;
1513 if ( ( ang == 0.0 ) || ( std::isinf ( ang ) ) )
1516 for (
size_t i = 0; i < 9; i++ ) { rotMat[i] = 0.0f; }
1526 proshade_single cAng = cos (
static_cast< proshade_single
> ( ang ) );
1527 proshade_single sAng = sin (
static_cast< proshade_single
> ( ang ) );
1528 proshade_single tAng = 1.0f - cAng;
1530 rotMat[0] = cAng +
static_cast< proshade_single
> ( x ) *
static_cast< proshade_single
> ( x ) * tAng;
1531 rotMat[4] = cAng +
static_cast< proshade_single
> ( y ) *
static_cast< proshade_single
> ( y ) * tAng;
1532 rotMat[8] = cAng +
static_cast< proshade_single
> ( z ) *
static_cast< proshade_single
> ( z ) * tAng;
1534 proshade_single tmp1 =
static_cast< proshade_single
> ( x ) *
static_cast< proshade_single
> ( y ) * tAng;
1535 proshade_single tmp2 =
static_cast< proshade_single
> ( z ) * sAng;
1536 rotMat[3] = tmp1 + tmp2;
1537 rotMat[1] = tmp1 - tmp2;
1539 tmp1 =
static_cast< proshade_single
> ( x ) *
static_cast< proshade_single
> ( z ) * tAng;
1540 tmp2 =
static_cast< proshade_single
> ( y ) * sAng;
1541 rotMat[6] = tmp1 - tmp2;
1542 rotMat[2] = tmp1 + tmp2;
1544 tmp1 =
static_cast< proshade_single
> ( y ) *
static_cast< proshade_single
> ( z ) * tAng;
1545 tmp2 =
static_cast< proshade_single
> ( x ) * sAng;
1546 rotMat[7] = tmp1 + tmp2;
1547 rotMat[5] = tmp1 - tmp2;
1564 if ( std::abs( rotMat[8] ) < 0.99999 )
1567 *eA = std::atan2 ( rotMat[7], rotMat[6] );
1568 *eB = std::acos ( rotMat[8] );
1569 *eG = std::atan2 ( rotMat[5], -rotMat[2] );
1574 if ( rotMat[8] >= 0.99999 )
1577 *eA = std::atan2 ( rotMat[3], rotMat[0] );
1581 if ( rotMat[8] <= -0.99999 )
1584 *eA = std::atan2 ( rotMat[3], rotMat[0] );
1591 if ( *eA < 0.0 ) { *eA = 2.0 * M_PI + *eA; }
1592 if ( *eB < 0.0 ) { *eB = M_PI + *eB; }
1593 if ( *eG < 0.0 ) { *eG = 2.0 * M_PI + *eG; }
1615 if ( ( axAng == 0.0 ) || ( std::isinf ( axAng ) ) )
1627 proshade_double cAng = std::cos ( axAng );
1628 proshade_double sAng = std::sin ( axAng );
1629 proshade_double tAng = 1.0 - cAng;
1631 proshade_double element22 = cAng + axZ * axZ * tAng;
1633 proshade_double tmp1 = axX * axZ * tAng;
1634 proshade_double tmp2 = axY * sAng;
1635 proshade_double element20 = tmp1 - tmp2;
1636 proshade_double element02 = tmp1 + tmp2;
1638 tmp1 = axY * axZ * tAng;
1640 proshade_double element21 = tmp1 + tmp2;
1641 proshade_double element12 = tmp1 - tmp2;
1644 if ( std::abs( element22 ) <= 0.99999 )
1647 *eA = std::atan2 ( element21, element20 );
1648 *eB = std::acos ( element22 );
1649 *eG = std::atan2 ( element12, -element02 );
1654 proshade_double element10 = ( axX * axY * tAng ) + ( axZ * sAng );
1655 proshade_double element11 = cAng + axY * axY * tAng;
1658 if ( element22 >= 0.99999 )
1661 *eA = std::atan2 ( element10, element11 );
1665 if ( element22 <= -0.99999 )
1668 *eA = -std::atan2 ( element10, element11 );
1675 if ( *eA < 0.0 ) { *eA = 2.0 * M_PI + *eA; }
1676 if ( *eB < 0.0 ) { *eB = M_PI + *eB; }
1677 if ( *eG < 0.0 ) { *eG = 2.0 * M_PI + *eG; }
1696 for ( proshade_unsign iter = 0; iter < 9; iter++ ) { res[iter] = 0.0; }
1699 for ( proshade_unsign row = 0; row < dim; row++ )
1701 for ( proshade_unsign col = 0; col < dim; col++ )
1703 for ( proshade_unsign inner = 0; inner < dim; inner++ )
1705 res[(row*dim)+col] += A[(inner*dim)+row] * B[(col*dim)+inner];
1722 std::vector < proshade_signed > ret;
1725 bool changeSign =
false;
1726 if ( number < 0 ) { changeSign =
true; number = -number; }
1733 while ( number % 2 == 0 )
1736 number = number / 2;
1740 for ( proshade_double posDiv = 3; posDiv <= sqrt ( static_cast< proshade_double > ( number ) ); posDiv += 2.0 )
1743 while ( number %
static_cast< proshade_signed
> ( posDiv ) == 0 )
1746 number = number /
static_cast< proshade_signed
> ( posDiv );
1754 if ( changeSign ) { ret.at(0) = -ret.at(0); }
1771 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) ) );
1788 return ( (*x1 * *x2) + (*y1 * *y2) + (*z1 * *z2) );
1804 return ( (x1 * x2) + (y1 * y2) + (z1 * z2) );
1820 proshade_double* crossProd =
new proshade_double[3];
1824 crossProd[0] = ( (*y1) * (*z2) ) - ( (*z1) * (*y2) );
1825 crossProd[1] = ( (*z1) * (*x2) ) - ( (*x1) * (*z2) );
1826 crossProd[2] = ( (*x1) * (*y2) ) - ( (*y1) * (*x2) );
1829 return ( crossProd );
1846 proshade_double* crossProd =
new proshade_double[3];
1850 crossProd[0] = ( y1 * z2 ) - ( z1 * y2 );
1851 crossProd[1] = ( z1 * x2 ) - ( x1 * z2 );
1852 crossProd[2] = ( x1 * y2 ) - ( y1 * x2 );
1855 return ( crossProd );
1868 proshade_double* ret =
new proshade_double[9];
1872 ret[0] = ( mat1[0] * mat2[0] ) + ( mat1[1] * mat2[3] ) + ( mat1[2] * mat2[6] );
1873 ret[1] = ( mat1[0] * mat2[1] ) + ( mat1[1] * mat2[4] ) + ( mat1[2] * mat2[7] );
1874 ret[2] = ( mat1[0] * mat2[2] ) + ( mat1[1] * mat2[5] ) + ( mat1[2] * mat2[8] );
1875 ret[3] = ( mat1[3] * mat2[0] ) + ( mat1[4] * mat2[3] ) + ( mat1[5] * mat2[6] );
1876 ret[4] = ( mat1[3] * mat2[1] ) + ( mat1[4] * mat2[4] ) + ( mat1[5] * mat2[7] );
1877 ret[5] = ( mat1[3] * mat2[2] ) + ( mat1[4] * mat2[5] ) + ( mat1[5] * mat2[8] );
1878 ret[6] = ( mat1[6] * mat2[0] ) + ( mat1[7] * mat2[3] ) + ( mat1[8] * mat2[6] );
1879 ret[7] = ( mat1[6] * mat2[1] ) + ( mat1[7] * mat2[4] ) + ( mat1[8] * mat2[7] );
1880 ret[8] = ( mat1[6] * mat2[2] ) + ( mat1[7] * mat2[5] ) + ( mat1[8] * mat2[8] );
1898 proshade_double* ret =
new proshade_double[3];
1902 ret[0] = ( x * mat[0] ) + ( y * mat[1] ) + ( z * mat[2] );
1903 ret[1] = ( x * mat[3] ) + ( y * mat[4] ) + ( z * mat[5] );
1904 ret[2] = ( x * mat[6] ) + ( y * mat[7] ) + ( z * mat[8] );
1922 proshade_single* ret =
new proshade_single[3];
1926 ret[0] = ( x * mat[0] ) + ( y * mat[1] ) + ( z * mat[2] );
1927 ret[1] = ( x * mat[3] ) + ( y * mat[4] ) + ( z * mat[5] );
1928 ret[2] = ( x * mat[6] ) + ( y * mat[7] ) + ( z * mat[8] );
1943 proshade_double* inverse =
new proshade_double[9];
1947 proshade_double matDet = ( mat[0] * mat[4] * mat[8] ) +
1948 ( mat[1] * mat[5] * mat[6] ) +
1949 ( mat[2] * mat[3] * mat[7] ) -
1950 ( mat[0] * mat[5] * mat[7] ) -
1951 ( mat[1] * mat[3] * mat[8] ) -
1952 ( mat[2] * mat[4] * mat[6] );
1955 inverse[0] = ( mat[4] * mat[8] - mat[5] * mat[7] ) / matDet;
1956 inverse[1] = ( mat[2] * mat[7] - mat[1] * mat[8] ) / matDet;
1957 inverse[2] = ( mat[1] * mat[5] - mat[2] * mat[4] ) / matDet;
1958 inverse[3] = ( mat[5] * mat[6] - mat[3] * mat[8] ) / matDet;
1959 inverse[4] = ( mat[0] * mat[8] - mat[2] * mat[6] ) / matDet;
1960 inverse[5] = ( mat[2] * mat[3] - mat[0] * mat[5] ) / matDet;
1961 inverse[6] = ( mat[3] * mat[7] - mat[4] * mat[6] ) / matDet;
1962 inverse[7] = ( mat[1] * mat[6] - mat[0] * mat[7] ) / matDet;
1963 inverse[8] = ( mat[0] * mat[4] - mat[1] * mat[3] ) / matDet;
1976 proshade_single tmp;
2003 proshade_double tmp;
2031 proshade_double* ret =
new proshade_double[9];
2060 proshade_double* ret =
new proshade_double[9];
2061 proshade_double* XRM =
new proshade_double[9];
2062 proshade_double* YRM =
new proshade_double[9];
2063 proshade_double* ZRM =
new proshade_double[9];
2070 proshade_double xRad = xRot * ( M_PI / 180.0 );
2071 proshade_double yRad = yRot * ( M_PI / 180.0 );
2072 proshade_double zRad = zRot * ( M_PI / 180.0 );
2075 XRM[0] = 1.0; XRM[1] = 0.0; XRM[2] = 0.0;
2076 XRM[3] = 0.0; XRM[4] = std::cos ( xRad ); XRM[5] = -std::sin ( xRad );
2077 XRM[6] = 0.0; XRM[7] = std::sin ( xRad ); XRM[8] = std::cos ( xRad );
2079 YRM[0] = std::cos ( yRad ); YRM[1] = 0.0; YRM[2] = std::sin ( yRad );
2080 YRM[3] = 0.0; YRM[4] = 1.0; YRM[5] = 0.0;
2081 YRM[6] = -std::sin ( yRad ); YRM[7] = 0.0; YRM[8] = std::cos ( yRad );
2083 ZRM[0] = std::cos ( zRad ); ZRM[1] = -std::sin ( zRad ); ZRM[2] = 0.0;
2084 ZRM[3] = std::sin ( zRad ); ZRM[4] = std::cos ( zRad ); ZRM[5] = 0.0;
2085 ZRM[6] = 0.0; ZRM[7] = 0.0; ZRM[8] = 1.0;
2122 proshade_double* inPlaneRotation =
new proshade_double[9];
2123 proshade_double* basisChangeMat =
new proshade_double[9];
2128 proshade_double normF = std::sqrt( std::pow( x1, 2.0 ) + std::pow ( y1, 2.0 ) + std::pow ( z1, 2.0 ) );
2129 x1 /= normF; y1 /= normF; z1 /= normF;
2131 normF = std::sqrt( std::pow( x2, 2.0 ) + std::pow ( y2, 2.0 ) + std::pow ( z2, 2.0 ) );
2132 x2 /= normF; y2 /= normF; z2 /= normF;
2136 proshade_double crossProdMag = std::sqrt( std::pow( crossProd[0], 2.0 ) + std::pow ( crossProd[1], 2.0 ) + std::pow ( crossProd[2], 2.0 ) );
2143 inPlaneRotation[0] = dotProd; inPlaneRotation[1] = -crossProdMag; inPlaneRotation[2] = 0.0;
2144 inPlaneRotation[3] = crossProdMag; inPlaneRotation[4] = dotProd; inPlaneRotation[5] = 0.0;
2145 inPlaneRotation[6] = 0.0; inPlaneRotation[7] = 0.0; inPlaneRotation[8] = 1.0;
2149 normF = std::sqrt ( std::pow ( x2 - ( dotProd * x1 ), 2.0 ) + std::pow ( y2 - ( dotProd * y1 ), 2.0 ) + std::pow ( z2 - ( dotProd * z1 ), 2.0 ) );
2151 basisChangeMat[0] = x1; basisChangeMat[1] = ( x2 - ( dotProd * x1 ) ) / normF; basisChangeMat[2] = crossProd[0];
2152 basisChangeMat[3] = y1; basisChangeMat[4] = ( y2 - ( dotProd * y1 ) ) / normF; basisChangeMat[5] = crossProd[1];
2153 basisChangeMat[6] = z1; basisChangeMat[7] = ( z2 - ( dotProd * z1 ) ) / normF; basisChangeMat[8] = crossProd[2];
2164 delete[] inPlaneRotation;
2165 delete[] basisChangeMat;
2166 delete[] basisChangeMatInverse;
2191 double *singularValues =
new double[dim];
2192 double *rotMatU =
new double [dim*dim];
2193 double *rotMatV =
new double [dim*dim];
2194 double *work =
new double [
static_cast< proshade_unsign
>( ( 3 * dim ) + pow( dim, 2 ) * dim)];
2195 int workDim =
static_cast< int > ( 2 * ( ( 4 * dim * dim ) + ( 7 * dim ) ) );
2196 double* rwork =
new double[
static_cast<proshade_unsign
>((5 * dim) + 5 * pow(dim,2))];
2197 int* iwork =
new int[(8 * dim)];
2198 int returnValue = 0;
2199 double *matrixToDecompose =
new double[dim*dim];
2211 for (
int rowIt = 0; rowIt < dim; rowIt++ )
2213 for (
int colIt = 0; colIt < dim; colIt++ )
2215 if ( rowIt == colIt ) { matrixToDecompose[(colIt*dim)+rowIt] = 1.0 - rMat->at(
static_cast< size_t > ( ( rowIt * dim ) + colIt ) ); }
2216 else { matrixToDecompose[(colIt*dim)+rowIt] = 0.0 - rMat->at(
static_cast< size_t > ( ( rowIt * dim ) + colIt ) ); }
2221 dgesdd_ ( &job, &dim, &dim, matrixToDecompose, &dim, singularValues, rotMatU, &dim, rotMatV, &dim,
2222 work, &workDim, rwork, iwork, &returnValue );
2225 if ( returnValue != 0 )
2231 bool anyPositive =
false;
2232 std::vector< bool > positivityTest;
2233 for ( proshade_unsign it = 0; it < static_cast< proshade_unsign > ( dim ); it++ )
2235 positivityTest.push_back ( singularValues[it] > 0.001 );
2236 if ( positivityTest.at(it) ) { anyPositive =
true; }
2240 proshade_double* pseudoInverseMat;
2244 if ( !positivityTest.at(0) )
2246 singularValues[0] = 0.0;
2254 else { singularValues[0] = 1.0 / singularValues[0]; }
2256 if ( !positivityTest.at(1) )
2258 singularValues[1] = 0.0;
2266 else { singularValues[1] = 1.0 / singularValues[1]; }
2268 if ( !positivityTest.at(2) )
2270 singularValues[2] = 0.0;
2278 else { singularValues[2] = 1.0 / singularValues[2]; }
2292 pseudoInverseMat =
new proshade_double[9];
2295 for (
size_t mIt = 0; mIt < 9; mIt++ ) { pseudoInverseMat[mIt] = 0.0; }
2302 delete[] matrixToDecompose;
2303 delete[] singularValues;
2308 return ( pseudoInverseMat );
2336 std::vector < proshade_double > ret;
2339 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 ) -
2340 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 ) ) *
2341 ( 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 ) ) ) -
2342 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 ) /
2343 ( 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 ) ) );
2344 proshade_double solY = ( ( dot2 * pow ( x2, 2.0 ) * pow ( z1, 3.0 ) ) /
2345 ( 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 ( dot1 * pow ( x2, 2.0 ) * z2 * pow ( z1, 2.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 ( 2.0 * x1 * dot2 * x2 * z2 * pow ( z1, 2.0 ) ) /
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 ) - dot2 * z1 -
2350 ( 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 ) -
2351 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 ) *
2352 ( 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 ) /
2353 ( 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 ) ) +
2354 ( pow ( y1, 2.0 ) * dot2 * pow ( x2, 2.0 ) * z1 ) /
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 ) +
2356 ( x1 * dot1 * x2 * pow ( y2, 2.0 ) * z1 ) /
2357 ( 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 ( pow ( x1, 2.0 ) * dot2 * pow ( z2, 2.0 ) * z1 ) /
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 ( 2.0 * x1 * dot1 * x2 * pow ( z2, 2.0 ) * z1 ) /
2361 ( 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 ( y1 * dot1 * pow ( x2, 2.0 ) * y2 * z1 ) /
2363 ( 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 ( x1 * y1 * dot2 * x2 * y2 * z1 ) /
2365 ( 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 +
2366 ( 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 ) -
2367 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 ) *
2368 ( 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 ) ) ) /
2369 ( 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 ) ) -
2370 ( pow ( x1, 2.0 ) * dot1 * pow ( z2, 3.0 ) ) /
2371 ( 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 ) -
2372 ( pow ( x1, 2.0 ) * dot1 * pow ( y2, 2.0 ) * z2 ) /
2373 ( 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 ) -
2374 ( x1 * pow ( y1, 2.0 ) * dot2 * x2 * z2 ) /
2375 ( 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 ) +
2376 ( pow ( x1, 2.0 ) * y1 * dot2 * y2 * z2 ) /
2377 ( 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 ) +
2378 ( x1 * y1 * dot1 * x2 * y2 * z2 ) /
2379 ( 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 );
2380 proshade_double solZ = ( - ( dot2 * pow ( x2, 2.0 ) * y2 * pow ( z1, 3.0 ) ) /
2381 ( ( 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 ) ) -
2382 ( dot2 * pow ( x2, 2.0 ) * pow ( z1, 2.0 ) ) /
2383 ( 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 ) +
2384 ( dot1 * pow ( x2, 2.0 ) * y2 * z2 * pow ( z1, 2.0 ) ) /
2385 ( ( 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 ) ) +
2386 ( 2.0 * x1 * dot2 * x2 * y2 * z2 * pow ( z1, 2.0 ) ) /
2387 ( ( 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 ) ) +
2388 ( 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 ) -
2389 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 ) *
2390 ( 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 ) /
2391 ( 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 ) ) +
2392 ( dot2 * y2 * z1 ) / ( y1 * z2 - z1 * y2 ) +
2393 ( dot1 * pow ( x2, 2.0 ) * z2 * z1 ) /
2394 ( 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 ) +
2395 ( x1 * dot2 * x2 * z2 * z1 ) /
2396 ( 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 ) -
2397 ( x1 * dot1 * x2 * pow ( y2, 3.0 ) * z1 ) /
2398 ( ( 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 ) ) +
2399 ( y1 * dot1 * pow ( x2, 2.0 ) * pow ( y2, 2.0 ) * z1 ) /
2400 ( ( 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 ) ) +
2401 ( x1 * y1 * dot2 * x2 * pow ( y2, 2.0 ) * z1 ) /
2402 ( ( 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 ) ) -
2403 ( pow ( x1, 2.0 ) * dot2 * y2 * pow ( z2, 2.0 ) * z1 ) /
2404 ( ( 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 ) ) -
2405 ( 2.0 * x1 * dot1 * x2 * y2 * pow ( z2, 2.0 ) * z1 ) /
2406 ( ( 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 ) ) -
2407 ( pow ( y1, 2.0 ) * dot2 * pow ( x2, 2.0 ) * y2 * z1 ) /
2408 ( ( 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 +
2409 ( 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 ) -
2410 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 ) *
2411 ( 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 ) ) ) /
2412 ( 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 ) ) -
2413 ( 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 ) -
2414 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 ) *
2415 ( 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 ) ) ) /
2416 ( 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 ) ) -
2417 ( dot1 * y2 * z2 ) / ( y1 * z2 - z1 * y2 ) -
2418 ( pow ( y1, 2.0 ) * dot2 * pow ( x2, 2.0 ) ) /
2419 ( 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 ) -
2420 ( x1 * dot1 * x2 * pow ( y2, 2.0 ) ) /
2421 ( 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 ) -
2422 ( x1 * dot1 * x2 * pow ( z2, 2.0 ) ) /
2423 ( 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 ) +
2424 ( y1 * dot1 * pow ( x2, 2.0 ) * y2 ) /
2425 ( 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 ) +
2426 ( x1 * y1 * dot2 * x2 * y2 ) /
2427 ( 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 ) +
2428 ( pow ( x1, 2.0 ) * dot1 * y2 * pow ( z2, 3.0 ) ) /
2429 ( ( 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 ) ) +
2430 ( pow ( x1, 2.0 ) * dot1 * pow ( y2, 3.0 ) * z2 ) /
2431 ( ( 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 ) ) -
2432 ( pow ( x1, 2.0 ) * y1 * dot2 * pow ( y2, 2.0 ) * z2 ) /
2433 ( ( 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 ) ) -
2434 ( x1 * y1 * dot1 * x2 * pow ( y2, 2.0 ) * z2 ) /
2435 ( ( 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 ) ) +
2436 ( x1 * pow ( y1, 2.0 ) * dot2 * x2 * y2 * z2 ) /
2437 ( ( 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;
2440 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( solX ), std::max( std::abs ( solY ), std::abs ( solZ ) ) ) );
2441 const FloatingPoint< proshade_double > rhs1 ( std::abs ( solX ) );
2442 const FloatingPoint< proshade_double > rhs2 ( std::abs ( solY ) );
2443 const FloatingPoint< proshade_double > rhs3 ( std::abs ( solZ ) );
2444 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( solX < 0.0 ) ) ||
2445 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( solY < 0.0 ) ) ||
2446 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( solZ < 0.0 ) ) ) { solX *= -1.0; solY *= -1.0; solZ *= -1.0; }
2479 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 )
2482 std::vector < proshade_double > ret;
2485 proshade_double solX = - ( y1 * dot2 * z3 - y1 * dot3 * z2 - z1 * dot2 * y3 + z1 * dot3 * y2 + dot1 * y3 * z2 - dot1 * z3 * y2 ) /
2486 ( -x1 * y3 * z2 + x1 * z3 * y2 + y1 * x3 * z2 - y1 * z3 * x2 - z1 * x3 * y2 + z1 * y3 * x2 );
2487 proshade_double solY = - ( x1 * dot2 * z3 - x1 * dot3 * z2 - z1 * dot2 * x3 + z1 * dot3 * x2 + dot1 * x3 * z2 - dot1 * z3 * x2 ) /
2488 ( x1 * y3 * z2 - x1 * z3 * y2 - y1 * x3 * z2 + y1 * z3 * x2 + z1 * x3 * y2 - z1 * y3 * x2 );
2489 proshade_double solZ = - ( x1 * dot2 * y3 - x1 * dot3 * y2 - y1 * dot2 * x3 + y1 * dot3 * x2 + dot1 * x3 * y2 - dot1 * y3 * x2 ) /
2490 ( -x1 * y3 * z2 + x1 * z3 * y2 + y1 * x3 * z2 - y1 * z3 * x2 - z1 * x3 * y2 + z1 * y3 * x2 );
2493 proshade_double normFactor = sqrt ( pow ( solX, 2.0 ) + pow ( solY, 2.0 ) + pow ( solZ, 2.0 ) );
2499 const FloatingPoint< proshade_double > lhs1 ( std::max ( std::abs ( solX ), std::max( std::abs ( solY ), std::abs ( solZ ) ) ) );
2500 const FloatingPoint< proshade_double > rhs1 ( std::abs ( solX ) );
2501 const FloatingPoint< proshade_double > rhs2 ( std::abs ( solY ) );
2502 const FloatingPoint< proshade_double > rhs3 ( std::abs ( solZ ) );
2503 if ( ( ( lhs1.AlmostEquals ( rhs1 ) ) && ( solX < 0.0 ) ) ||
2504 ( ( lhs1.AlmostEquals ( rhs2 ) ) && ( solY < 0.0 ) ) ||
2505 ( ( lhs1.AlmostEquals ( rhs3 ) ) && ( solZ < 0.0 ) ) ) { solX *= -1.0; solY *= -1.0; solZ *= -1.0; }
2526 std::vector< proshade_double > ret;
2530 ( el1->at(1) * el2->at(3) ) +
2531 ( el1->at(2) * el2->at(6) ) );
2533 ( el1->at(1) * el2->at(4) ) +
2534 ( el1->at(2) * el2->at(7) ) );
2536 ( el1->at(1) * el2->at(5) ) +
2537 ( el1->at(2) * el2->at(8) ) );
2540 ( el1->at(4) * el2->at(3) ) +
2541 ( el1->at(5) * el2->at(6) ) );
2543 ( el1->at(4) * el2->at(4) ) +
2544 ( el1->at(5) * el2->at(7) ) );
2546 ( el1->at(4) * el2->at(5) ) +
2547 ( el1->at(5) * el2->at(8) ) );
2550 ( el1->at(7) * el2->at(3) ) +
2551 ( el1->at(8) * el2->at(6) ) );
2553 ( el1->at(7) * el2->at(4) ) +
2554 ( el1->at(8) * el2->at(7) ) );
2556 ( el1->at(7) * el2->at(5) ) +
2557 ( el1->at(8) * el2->at(8) ) );
2627 proshade_double ret = ( mat1->at(0) * mat2->at(0) ) + ( mat1->at(1) * mat2->at(1) ) + ( mat1->at(2) * mat2->at(2) );
2628 ret += ( mat1->at(3) * mat2->at(3) ) + ( mat1->at(4) * mat2->at(4) ) + ( mat1->at(5) * mat2->at(5) );
2629 ret += ( mat1->at(6) * mat2->at(6) ) + ( mat1->at(7) * mat2->at(7) ) + ( mat1->at(8) * mat2->at(8) );
2652 proshade_double ret = ( mat1[0] * mat2[0] ) + ( mat1[1] * mat2[1] ) + ( mat1[2] * mat2[2] );
2653 ret += ( mat1[3] * mat2[3] ) + ( mat1[4] * mat2[4] ) + ( mat1[5] * mat2[5] );
2654 ret += ( mat1[6] * mat2[6] ) + ( mat1[7] * mat2[7] ) + ( mat1[8] * mat2[8] );
2686 proshade_double cosDist = ( ( a1 * b1 ) + ( a2 * b2 ) + ( a3 * b3 ) ) /
2687 ( sqrt( pow( a1, 2.0 ) + pow( a2, 2.0 ) + pow( a3, 2.0 ) ) *
2688 sqrt( pow( b1, 2.0 ) + pow( b2, 2.0 ) + pow( b3, 2.0 ) ) );
2691 if ( std::abs( cosDist ) > ( 1.0 - tolerance ) ) { ret =
true; }
2720 proshade_double cosDist = ( ( a1 * b1 ) + ( a2 * b2 ) + ( a3 * b3 ) ) /
2721 ( sqrt( pow( a1, 2.0 ) + pow( a2, 2.0 ) + pow( a3, 2.0 ) ) *
2722 sqrt( pow( b1, 2.0 ) + pow( b2, 2.0 ) + pow( b3, 2.0 ) ) );
2725 if ( cosDist > ( 1.0 - tolerance ) ) { ret =
true; }
2744 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 )
2747 proshade_double lonM, lonP, latM, latP, movSum;
2748 std::vector<proshade_double> latVals ( 3 );
2749 std::vector<proshade_double> lonVals ( 3 );
2750 proshade_double learningRate = 0.1;
2751 proshade_double prevVal = *bestSum;
2752 proshade_double valChange = 999.9;
2753 proshade_double origBestLat = std::round ( *bestLattitude );
2754 proshade_double origBestLon = std::round ( *bestLongitude );
2755 proshade_double tmpVal;
2758 std::vector<ProSHADE_internal_maths::BicubicInterpolator*> interpolsMinusMinus;
2759 std::vector<ProSHADE_internal_maths::BicubicInterpolator*> interpolsMinusPlus;
2760 std::vector<ProSHADE_internal_maths::BicubicInterpolator*> interpolsPlusMinus;
2761 std::vector<ProSHADE_internal_maths::BicubicInterpolator*> interpolsPlusPlus;
2768 while ( valChange > 0.0001 )
2771 lonM = *bestLongitude - step;
2772 lonP = *bestLongitude + step;
2773 latM = *bestLattitude - step;
2774 latP = *bestLattitude + step;
2777 const FloatingPoint< proshade_double > lhs1 ( *bestLattitude ), rhs1 ( origBestLat - 1.0 );
2778 const FloatingPoint< proshade_double > lhs2 ( *bestLattitude ), rhs2 ( origBestLat + 1.0 );
2779 const FloatingPoint< proshade_double > lhs3 ( *bestLongitude ), rhs3 ( origBestLon - 1.0 );
2780 const FloatingPoint< proshade_double > lhs4 ( *bestLongitude ), rhs4 ( origBestLon + 1.0 );
2781 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; }
2782 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; }
2783 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; }
2784 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; }
2787 latVals.at(0) = latM; latVals.at(1) = *bestLattitude; latVals.at(2) = latP;
2788 lonVals.at(0) = lonM; lonVals.at(1) = *bestLongitude; lonVals.at(2) = lonP;
2791 for ( proshade_unsign laIt = 0; laIt < static_cast<proshade_unsign> ( latVals.size() ); laIt++ )
2793 for ( proshade_unsign loIt = 0; loIt < static_cast<proshade_unsign> ( lonVals.size() ); loIt++ )
2797 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( sphereList->size() ); iter++ )
2800 if ( ( latVals.at(laIt) <= origBestLat ) && ( lonVals.at(loIt) <= origBestLon ) ) { movSum += interpolsMinusMinus.at(iter)->getValue ( latVals.at(laIt), lonVals.at(loIt) ); }
2801 if ( ( latVals.at(laIt) <= origBestLat ) && ( lonVals.at(loIt) > origBestLon ) ) { movSum += interpolsMinusPlus.at(iter)->getValue ( latVals.at(laIt), lonVals.at(loIt) ); }
2802 if ( ( latVals.at(laIt) > origBestLat ) && ( lonVals.at(loIt) <= origBestLon ) ) { movSum += interpolsPlusMinus.at(iter)->getValue ( latVals.at(laIt), lonVals.at(loIt) ); }
2803 if ( ( latVals.at(laIt) > origBestLat ) && ( lonVals.at(loIt) > origBestLon ) ) { movSum += interpolsPlusPlus.at(iter)->getValue ( latVals.at(laIt), lonVals.at(loIt) ); }
2807 if ( *bestSum < movSum )
2810 *bestLongitude = lonVals.at(loIt);
2811 *bestLattitude = latVals.at(laIt);
2817 valChange = std::floor ( 100000.0 * ( *bestSum - prevVal ) ) / 100000.0;
2818 prevVal = std::floor ( 100000.0 * ( *bestSum ) ) / 100000.0;
2819 step = std::min ( 0.2, std::max ( ( valChange / step ) * learningRate, 0.01 ) );
2820 if ( learningRate >= 0.02 ) { learningRate -= 0.01; }
2824 for ( proshade_unsign intIt = 0; intIt < static_cast<proshade_unsign> ( interpolsMinusMinus.size() ); intIt++ ) {
delete interpolsMinusMinus.at(intIt); }
2825 for ( proshade_unsign intIt = 0; intIt < static_cast<proshade_unsign> ( interpolsMinusPlus.size() ); intIt++ ) {
delete interpolsMinusPlus.at(intIt); }
2826 for ( proshade_unsign intIt = 0; intIt < static_cast<proshade_unsign> ( interpolsPlusMinus.size() ); intIt++ ) {
delete interpolsPlusMinus.at(intIt); }
2827 for ( proshade_unsign intIt = 0; intIt < static_cast<proshade_unsign> ( interpolsPlusPlus.size() ); intIt++ ) {
delete interpolsPlusPlus.at(intIt); }
2844 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 )
2847 proshade_signed latHlp, lonHlp;
2848 proshade_signed angDim =
static_cast< proshade_signed
> ( sphereMappedRotFun->at(0)->getAngularDim() );
2851 for ( proshade_unsign sphereIt = 0; sphereIt < static_cast<proshade_unsign> ( sphereList->size() ); sphereIt++ )
2854 proshade_double** interpGrid =
new proshade_double*[4];
2858 for ( proshade_unsign iter = 0; iter < 4; iter++ )
2860 interpGrid[iter] =
new proshade_double[4];
2865 for ( proshade_signed latIt = 0; latIt < 4; latIt++ )
2867 for ( proshade_signed lonIt = 0; lonIt < 4; lonIt++ )
2869 latHlp =
static_cast< proshade_signed
> ( bestLattitude - 2.0 +
static_cast< proshade_double
> ( latIt ) );
if ( latHlp < 0 ) { latHlp += angDim; }
if ( latHlp >= angDim ) { latHlp -= angDim; }
2870 lonHlp =
static_cast< proshade_signed
> ( bestLongitude - 2.0 +
static_cast< proshade_double
> ( lonIt ) );
if ( lonHlp < 0 ) { lonHlp += angDim; }
if ( lonHlp >= angDim ) { lonHlp -= angDim; }
2871 interpGrid[latIt][lonIt] = sphereMappedRotFun->at(sphereList->at(sphereIt))->getSphereLatLonPosition (
static_cast< proshade_unsign
> ( latHlp ),
static_cast< proshade_unsign
> ( lonHlp ) );
2877 interpols->emplace_back ( biCubInterp );
2880 for ( proshade_unsign iter = 0; iter < 4; iter++ ) {
delete[] interpGrid[iter]; }
2881 delete[] interpGrid;
2899 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 )
2902 proshade_signed latHlp, lonHlp;
2903 proshade_signed angDim =
static_cast< proshade_signed
> ( sphereMappedRotFun->at(0)->getAngularDim() );
2906 for ( proshade_unsign sphereIt = 0; sphereIt < static_cast<proshade_unsign> ( sphereList->size() ); sphereIt++ )
2909 proshade_double** interpGrid =
new proshade_double*[4];
2913 for ( proshade_unsign iter = 0; iter < 4; iter++ )
2915 interpGrid[iter] =
new proshade_double[4];
2920 for ( proshade_unsign latIt = 0; latIt < 4; latIt++ )
2922 for ( proshade_unsign lonIt = 0; lonIt < 4; lonIt++ )
2924 latHlp =
static_cast< proshade_signed
> ( bestLattitude - 2 +
static_cast< proshade_double
> ( latIt ) );
if ( latHlp < 0 ) { latHlp += angDim; }
if ( latHlp >= angDim ) { latHlp -= angDim; }
2925 lonHlp =
static_cast< proshade_signed
> ( bestLongitude - 1 +
static_cast< proshade_double
> ( lonIt ) );
if ( lonHlp < 0 ) { lonHlp += angDim; }
if ( lonHlp >= angDim ) { lonHlp -= angDim; }
2926 interpGrid[latIt][lonIt] = sphereMappedRotFun->at(sphereList->at(sphereIt))->getSphereLatLonPosition (
static_cast< proshade_unsign
> ( latHlp ) ,
static_cast< proshade_unsign
> ( lonHlp ) );
2932 interpols->emplace_back ( biCubInterp );
2935 for ( proshade_unsign iter = 0; iter < 4; iter++ ) {
delete[] interpGrid[iter]; }
2936 delete[] interpGrid;
2954 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 )
2957 proshade_signed latHlp, lonHlp;
2958 proshade_signed angDim =
static_cast< proshade_signed
> ( sphereMappedRotFun->at(0)->getAngularDim() );
2961 for ( proshade_unsign sphereIt = 0; sphereIt < static_cast<proshade_unsign> ( sphereList->size() ); sphereIt++ )
2964 proshade_double** interpGrid =
new proshade_double*[4];
2968 for ( proshade_unsign iter = 0; iter < 4; iter++ )
2970 interpGrid[iter] =
new proshade_double[4];
2975 for ( proshade_unsign latIt = 0; latIt < 4; latIt++ )
2977 for ( proshade_unsign lonIt = 0; lonIt < 4; lonIt++ )
2979 latHlp =
static_cast< proshade_signed
> ( bestLattitude - 1 +
static_cast< proshade_double
> ( latIt ) );
if ( latHlp < 0 ) { latHlp += angDim; }
if ( latHlp >= angDim ) { latHlp -= angDim; }
2980 lonHlp =
static_cast< proshade_signed
> ( bestLongitude - 2 +
static_cast< proshade_double
> ( lonIt ) );
if ( lonHlp < 0 ) { lonHlp += angDim; }
if ( lonHlp >= angDim ) { lonHlp -= angDim; }
2981 interpGrid[latIt][lonIt] = sphereMappedRotFun->at(sphereList->at(sphereIt))->getSphereLatLonPosition (
static_cast< proshade_unsign
> ( latHlp ),
static_cast< proshade_unsign
> ( lonHlp ) );
2987 interpols->emplace_back ( biCubInterp );
2990 for ( proshade_unsign iter = 0; iter < 4; iter++ ) {
delete[] interpGrid[iter]; }
2991 delete[] interpGrid;
3009 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 )
3012 proshade_signed latHlp, lonHlp;
3013 proshade_signed angDim =
static_cast< proshade_signed
> ( sphereMappedRotFun->at(0)->getAngularDim() );
3016 for ( proshade_unsign sphereIt = 0; sphereIt < static_cast<proshade_unsign> ( sphereList->size() ); sphereIt++ )
3019 proshade_double** interpGrid =
new proshade_double*[4];
3023 for ( proshade_unsign iter = 0; iter < 4; iter++ )
3025 interpGrid[iter] =
new proshade_double[4];
3030 for ( proshade_unsign latIt = 0; latIt < 4; latIt++ )
3032 for ( proshade_unsign lonIt = 0; lonIt < 4; lonIt++ )
3034 latHlp =
static_cast< proshade_signed
> ( bestLattitude - 1 +
static_cast< proshade_double
> ( latIt ) );
if ( latHlp < 0 ) { latHlp += angDim; }
if ( latHlp >= angDim ) { latHlp -= angDim; }
3035 lonHlp =
static_cast< proshade_signed
> ( bestLongitude - 1 +
static_cast< proshade_double
> ( lonIt ) );
if ( lonHlp < 0 ) { lonHlp += angDim; }
if ( lonHlp >= angDim ) { lonHlp -= angDim; }
3036 interpGrid[latIt][lonIt] = sphereMappedRotFun->at(sphereList->at(sphereIt))->getSphereLatLonPosition (
static_cast< proshade_unsign
> ( latHlp ),
static_cast< proshade_unsign
> ( lonHlp ) );
3042 interpols->emplace_back ( biCubInterp );
3045 for ( proshade_unsign iter = 0; iter < 4; iter++ ) {
delete[] interpGrid[iter]; }
3046 delete[] interpGrid;
3068 proshade_unsign whichImprove = 0;
3071 for ( proshade_unsign grIt = 0; grIt < static_cast<proshade_unsign> ( CSymList->size() ); grIt++ )
3074 const FloatingPoint< proshade_double > lhs ( CSymList->at(grIt)[0] ), rhs ( axis[0] );
3075 if ( lhs.AlmostEquals ( rhs ) )
3080 whichImprove = grIt;
3087 if ( improve && !ret )
3089 if ( axis[5] > CSymList->at(whichImprove)[5] )
3091 CSymList->at(whichImprove)[1] = axis[1];
3092 CSymList->at(whichImprove)[2] = axis[2];
3093 CSymList->at(whichImprove)[3] = axis[3];
3094 CSymList->at(whichImprove)[4] = axis[4];
3095 CSymList->at(whichImprove)[5] = axis[5];
3122 for ( proshade_unsign grIt = 0; grIt < static_cast<proshade_unsign> ( CSymList->size() ); grIt++ )
3124 const FloatingPoint< proshade_double > lhs ( fold ), rhs ( CSymList->at(grIt)[0] );
3125 if ( lhs.AlmostEquals ( rhs ) )
3153 proshade_signed ret = -1;
3156 for ( proshade_unsign grIt = 0; grIt < static_cast<proshade_unsign> ( CSymList->size() ); grIt++ )
3159 const FloatingPoint< proshade_double > lhs ( CSymList->at(grIt)[0] ), rhs ( axis[0] );
3160 if ( lhs.AlmostEquals ( rhs ) )
3164 ret =
static_cast< proshade_signed
> ( grIt );
3189 proshade_signed ret = -1;
3192 for ( proshade_unsign grIt = 0; grIt < static_cast<proshade_unsign> ( CSymList->size() ); grIt++ )
3194 const FloatingPoint< proshade_double > lhs ( fold ), rhs ( CSymList->at(grIt)[0] );
3195 if ( lhs.AlmostEquals ( rhs ) )
3199 ret =
static_cast< proshade_signed
> ( grIt );
3221 std::vector< proshade_unsign > ret;
3222 std::vector< std::pair< proshade_unsign, bool > > sieveOfEratosthenesArray;
3225 if ( upTo < 2 ) {
return ( ret ); }
3228 for ( proshade_unsign iter = 2; iter <= upTo; iter++ ) { sieveOfEratosthenesArray.emplace_back ( std::pair< proshade_unsign, bool > ( iter,
true ) ); }
3231 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( sieveOfEratosthenesArray.size() ); iter++ )
3234 if ( sieveOfEratosthenesArray.at(iter).second )
3237 for ( proshade_unsign it = iter + sieveOfEratosthenesArray.at(iter).first; it < static_cast<proshade_unsign> ( sieveOfEratosthenesArray.size() ); it += sieveOfEratosthenesArray.at(iter).first )
3239 sieveOfEratosthenesArray.at(it).second =
false;
3245 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( sieveOfEratosthenesArray.size() ); iter++ )
3265 if ( ( toCheck == 0 ) || ( toCheck == 1 ) ) { ret =
false;
return ( ret ); }
3268 for ( proshade_unsign divider = 2; divider <= static_cast< proshade_unsign > ( std::round( toCheck / 2 ) ); divider++ )
3270 if ( toCheck % divider == 0 ) { ret =
false;
break; }
3289 proshade_double zScore = ( val / sigma );
3290 proshade_double cumulativeProbability = 0.5 * std::erfc ( zScore * M_SQRT1_2 );
3293 if ( cumulativeProbability > 0.5 ) { cumulativeProbability = 1.0 - cumulativeProbability; }
3296 return ( cumulativeProbability );
3313 std::vector < proshade_double >
ProSHADE_internal_maths::smoothen1D ( proshade_double step, proshade_signed windowSize, proshade_double sigma, std::vector< proshade_double > data, proshade_signed decRound )
3316 proshade_signed windowHalf = ( windowSize - 1 ) / 2;
3317 proshade_signed totSize =
static_cast< proshade_signed
> ( ( 1.0 / step ) + 1 );
3318 std::vector< proshade_double > smoothened (
static_cast< size_t > ( totSize - ( windowSize - 1 ) ), 0.0 );
3319 std::vector< proshade_double > winWeights (
static_cast< size_t > ( windowSize ), 0.0 );
3322 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 ); }
3325 for ( proshade_unsign it = 0; it < static_cast< proshade_unsign > ( smoothened.size() ); it++ )
3328 for ( proshade_signed winIt = 0; winIt < windowSize; winIt++ )
3330 smoothened.at(it) += winWeights.at(
static_cast< size_t > ( winIt ) ) * data.at(
static_cast< size_t > (
static_cast< proshade_signed
> ( it ) + winIt ) );
3335 if ( decRound >= 0 )
3337 proshade_double zeroMultip = std::pow ( 10.0, decRound );
3338 for ( proshade_unsign it = 0; it < static_cast< proshade_unsign > ( smoothened.size() ); it++ )
3340 smoothened.at(it) = std::round ( smoothened.at(it) * zeroMultip ) / zeroMultip;
3345 return ( smoothened );
3362 proshade_single vol = ( xDim * yDim * zDim );
3363 proshade_single sa = ( yDim * zDim ) / vol;
3364 proshade_single sb = ( xDim * zDim ) / vol;
3365 proshade_single sc = ( xDim * yDim ) / vol;
3368 proshade_single s2 = ( std::pow ( h * sa, 2.0f ) +
3369 std::pow ( k * sb, 2.0f ) +
3370 std::pow ( l * sc, 2.0f ) ) / 4.0f;
3373 if ( s2 == 0.0f ) { s2 = 0.0000000001f; }
3376 return ( 1.0f / ( 2.0f * std::sqrt ( s2 ) ) );
3397 void ProSHADE_internal_maths::binReciprocalSpaceReflections ( proshade_unsign xInds, proshade_unsign yInds, proshade_unsign zInds, proshade_single xSize, proshade_single ySize, proshade_single zSize, proshade_signed* noBin, proshade_signed*& binIndexing, std::vector< proshade_single >*& resArray )
3400 binIndexing =
new proshade_signed [xInds * yInds * zInds];
3402 for (
size_t iter = 0; iter < static_cast< size_t > ( xInds * yInds * zInds ); iter++ ) { binIndexing[iter] = -100; }
3403 proshade_single xIndsF =
static_cast< proshade_single
> ( xInds ), yIndsF =
static_cast< proshade_single
> ( yInds ), zIndsF =
static_cast< proshade_single
> ( zInds );
3406 proshade_single *mins =
new proshade_single[3];
3407 proshade_single *maxs =
new proshade_single[3];
3408 proshade_single *hkl =
new proshade_single[3];
3409 proshade_single *resMins =
new proshade_single[3];
3410 proshade_signed *resMinLoc =
new proshade_signed[3];
3411 proshade_single *steps =
new proshade_single[3];
3422 proshade_single resVal = 0.0, binVal = 0.0, tmpVal = 0.0, tmpMinVal = 0.0;
3423 proshade_signed reciX, reciY, reciZ, arrPos = 0, binLoc = 0, minLoc = 0;
3427 mins[0] = std::floor ( xIndsF / -2.0f );
3428 mins[1] = std::floor ( yIndsF / -2.0f );
3429 mins[2] = std::floor ( zIndsF / -2.0f );
3431 maxs[0] = -(mins[0] + 1);
3432 maxs[1] = -(mins[1] + 1);
3441 resMinLoc[0] = 0; resMinLoc[1] = 0; resMinLoc[2] = 0;
3442 const FloatingPoint< proshade_single > lhs1 ( resMins[0] ), lhs2 ( resMins[1] ), lhs3 ( resMins[2] ), rhs1 ( std::min( resMins[0], std::min( resMins[1], resMins[2] ) ) );
3443 if ( lhs1.AlmostEquals ( rhs1 ) ) { resMinLoc[0] = 1; minLoc = 0; }
3444 else if ( lhs2.AlmostEquals ( rhs1 ) ) { resMinLoc[1] = 1; minLoc = 1; }
3445 else if ( lhs3.AlmostEquals ( rhs1 ) ) { resMinLoc[2] = 1; minLoc = 2; }
3447 for (
size_t it = 0; it < 3; it++ ) { hkl[it] = 0.0;
if (
static_cast<size_t> ( minLoc ) == it ) { hkl[it] = 1.0; } }
3450 resArray =
new std::vector< proshade_single > (
static_cast< size_t > ( maxs[minLoc] ), 0.0f );
3452 for ( proshade_signed dimIt = 0; dimIt < static_cast< proshade_signed > ( maxs[minLoc] ); dimIt++ )
3455 steps[0] = (
static_cast< proshade_single
> ( dimIt ) + 2.5f ) *
static_cast< proshade_single
> ( resMinLoc[0] ) * hkl[0];
3456 steps[1] = (
static_cast< proshade_single
> ( dimIt ) + 2.5f ) *
static_cast< proshade_single
> ( resMinLoc[1] ) * hkl[1];
3457 steps[2] = (
static_cast< proshade_single
> ( dimIt ) + 2.5f ) *
static_cast< proshade_single
> ( resMinLoc[2] ) * hkl[2];
3463 resArray->at(
static_cast< size_t > ( dimIt )) = resVal;
3468 proshade_single highResLimit = resArray->at (
static_cast< size_t > ( *noBin - 1 ) );
3471 const FloatingPoint< proshade_single > minX ( mins[0] ), minY ( mins[1] ), minZ ( mins[2] );
3474 for ( proshade_single xIt =
static_cast< proshade_single
> ( mins[0] ); xIt <= static_cast< proshade_single > ( maxs[0] ); xIt += 1.0f )
3476 for ( proshade_single yIt =
static_cast< proshade_single
> ( mins[1] ); yIt <= static_cast< proshade_single > ( maxs[1] ); yIt += 1.0f )
3478 for ( proshade_single zIt =
static_cast< proshade_single
> ( mins[2] ); zIt <= 0.0f; zIt += 1.0f )
3484 if ( ( resVal < highResLimit ) || ( resVal > lowResLimit ) ) {
continue; }
3487 for ( proshade_signed binIt = 0; binIt < (*noBin); binIt++ )
3490 binVal = std::sqrt ( std::pow ( resArray->at(
static_cast< size_t > ( binIt ) ) - resVal, 2.0f ) );
3502 if ( tmpVal < tmpMinVal )
3511 reciX =
static_cast< proshade_signed
> ( xIt - mins[0] );
3512 reciY =
static_cast< proshade_signed
> ( yIt - mins[1] );
3513 reciZ =
static_cast< proshade_signed
> ( zIt - mins[2] );
3515 arrPos = reciZ +
static_cast< proshade_signed
> ( zInds ) * ( reciY +
static_cast< proshade_signed
> ( yInds ) * reciX );
3516 binIndexing[
static_cast< size_t > ( arrPos ) ] = binLoc;
3519 const FloatingPoint< proshade_single > itX ( xIt ), itY ( yIt ), itZ ( zIt );
3520 if ( minX.AlmostEquals ( itX ) || minY.AlmostEquals ( itY ) || minZ.AlmostEquals ( itZ ) ) {
continue; }
3522 reciX =
static_cast< proshade_signed
> ( -xIt - mins[0] );
3523 reciY =
static_cast< proshade_signed
> ( -yIt - mins[1] );
3524 reciZ =
static_cast< proshade_signed
> ( -zIt - mins[2] );
3526 arrPos = reciZ +
static_cast< proshade_signed
> ( zInds ) * ( reciY +
static_cast< proshade_signed
> ( yInds ) * reciX );
3527 binIndexing[
static_cast< size_t > ( arrPos ) ] = binLoc;
3563 void ProSHADE_internal_maths::cutIndicesToResolution ( proshade_signed xInds, proshade_signed yInds, proshade_signed zInds, proshade_single resolution, proshade_signed* binIndexing, std::vector< proshade_single >* resArray, proshade_signed* cutXDim, proshade_signed* cutYDim, proshade_signed* cutZDim, proshade_signed*& cutBinIndices, proshade_signed*& noBins )
3566 proshade_single resCut = resolution;
3567 proshade_single minVal = std::numeric_limits < proshade_single >::infinity();
3569 std::vector< proshade_single > resDists;
3573 for (
size_t iter = 0; iter < resDists.size(); iter++ ) {
if ( resDists.at(iter) < minVal ) { minVal = resDists.at(iter); (*noBins) =
static_cast< proshade_signed
> ( iter ); } }
3576 proshade_signed newXFrom =
static_cast< proshade_signed
> ( std::round ( (
static_cast< proshade_signed
> ( xInds ) - 2 * (*noBins) ) / 2 ) );
3577 proshade_signed newYFrom =
static_cast< proshade_signed
> ( std::round ( (
static_cast< proshade_signed
> ( yInds ) - 2 * (*noBins) ) / 2 ) );
3578 proshade_signed newZFrom =
static_cast< proshade_signed
> ( std::round ( (
static_cast< proshade_signed
> ( zInds ) - 2 * (*noBins) ) / 2 ) );
3579 proshade_signed newXTo =
static_cast< proshade_signed
> ( std::round ( newXFrom + 2 * (*noBins) ) );
3580 proshade_signed newYTo =
static_cast< proshade_signed
> ( std::round ( newYFrom + 2 * (*noBins) ) );
3581 proshade_signed newZTo =
static_cast< proshade_signed
> ( std::round ( newZFrom + 2 * (*noBins) ) );
3582 *cutXDim = ( newXTo - newXFrom );
3583 *cutYDim = ( newYTo - newYFrom );
3584 *cutZDim = ( newZTo - newZFrom );
3587 cutBinIndices =
new proshade_signed[(*cutXDim) * (*cutYDim) * (*cutZDim)];
3589 for (
size_t iter = 0; iter < static_cast< size_t > ( (*cutXDim) * (*cutYDim) * (*cutZDim) ); iter++ ) { cutBinIndices[iter] = 0; }
3591 proshade_signed newArrPos = 0, origArrPos = 0;
3592 for ( proshade_signed xIt = newXFrom; xIt < newXTo; xIt++ )
3594 for ( proshade_signed yIt = newYFrom; yIt < newYTo; yIt++ )
3596 for ( proshade_signed zIt = newZFrom; zIt < newZTo; zIt++ )
3599 if ( ( xIt < 0 ) || ( yIt < 0 ) || ( zIt < 0 ) ) {
continue; }
3600 if ( ( xIt >= xInds ) || ( yIt >= yInds ) || ( zIt >= zInds ) ) {
continue; }
3603 newArrPos = (zIt-newZFrom) + (*cutZDim) * ( (yIt-newYFrom) + (*cutYDim) * (xIt-newXFrom) );
3604 origArrPos = zIt +
static_cast< proshade_signed
> ( zInds ) * ( yIt +
static_cast< proshade_signed
> ( yInds ) * xIt );
3607 cutBinIndices[newArrPos] = binIndexing[origArrPos];
3631 proshade_signed newXFrom =
static_cast< proshade_signed
> ( std::round ( (
static_cast< proshade_signed
> ( xInds ) - 2 * noBins ) / 2 ) );
3632 proshade_signed newYFrom =
static_cast< proshade_signed
> ( std::round ( (
static_cast< proshade_signed
> ( yInds ) - 2 * noBins ) / 2 ) );
3633 proshade_signed newZFrom =
static_cast< proshade_signed
> ( std::round ( (
static_cast< proshade_signed
> ( zInds ) - 2 * noBins ) / 2 ) );
3634 proshade_signed newXTo =
static_cast< proshade_signed
> ( std::round ( newXFrom + 2 * noBins ) );
3635 proshade_signed newYTo =
static_cast< proshade_signed
> ( std::round ( newYFrom + 2 * noBins ) );
3636 proshade_signed newZTo =
static_cast< proshade_signed
> ( std::round ( newZFrom + 2 * noBins ) );
3637 proshade_signed cutXDim = ( newXTo - newXFrom );
3638 proshade_signed cutYDim = ( newYTo - newYFrom );
3639 proshade_signed cutZDim = ( newZTo - newZFrom );
3642 cutMap =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) *
static_cast< proshade_unsign
> ( cutXDim * cutYDim * cutZDim ) ) );
3644 for (
size_t iter = 0; iter < static_cast< size_t > ( cutXDim * cutYDim * cutZDim ); iter++ ) { cutMap[iter][0] = 0.0; cutMap[iter][1] = 0.0; }
3646 proshade_signed newArrPos = 0, origArrPos = 0;
3647 for ( proshade_signed xIt = newXFrom; xIt < newXTo; xIt++ )
3649 for ( proshade_signed yIt = newYFrom; yIt < newYTo; yIt++ )
3651 for ( proshade_signed zIt = newZFrom; zIt < newZTo; zIt++ )
3654 if ( ( xIt < 0 ) || ( yIt < 0 ) || ( zIt < 0 ) ) {
continue; }
3655 if ( ( xIt >= xInds ) || ( yIt >= yInds ) || ( zIt >= zInds ) ) {
continue; }
3658 newArrPos = (zIt-newZFrom) + cutZDim * ( (yIt-newYFrom) + cutYDim * (xIt-newXFrom) );
3659 origArrPos = zIt +
static_cast< proshade_signed
> ( zInds ) * ( yIt +
static_cast< proshade_signed
> ( yInds ) * xIt );
3662 cutMap[newArrPos][0] = inputMap[origArrPos][0];
3663 cutMap[newArrPos][1] = inputMap[origArrPos][1];
3693 proshade_double
ProSHADE_internal_maths::computeFSC ( fftw_complex *fCoeffs1, fftw_complex *fCoeffs2, proshade_signed xInds, proshade_signed yInds, proshade_signed zInds, proshade_signed noBins, proshade_signed* binIndexing, proshade_double**& binData, proshade_signed*& binCounts, proshade_double*& fscByBin,
bool averageByBinSize )
3696 proshade_double realOrig, realRot, imagOrig, imagRot, fsc = 0.0;;
3697 proshade_signed indx, arrPos;
3698 std::vector< proshade_double > covarByBin (
static_cast< size_t > ( noBins ), 0.0 );
3701 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; } }
3702 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ ) { binCounts[binIt] = 0; }
3705 for ( proshade_signed xIt = 0; xIt < xInds; xIt++ )
3707 for ( proshade_signed yIt = 0; yIt < yInds; yIt++ )
3709 for ( proshade_signed zIt = 0; zIt < ( zInds / 2 ); zIt++ )
3712 arrPos = zIt +
static_cast< proshade_signed
> ( zInds ) * ( yIt +
static_cast< proshade_signed
> ( yInds ) * xIt );
3715 indx = binIndexing[
static_cast< size_t > ( arrPos ) ];
3716 if ( ( indx < 0 ) || ( indx >= noBins ) ) {
continue; }
3719 realOrig = fCoeffs1[arrPos][0];
3720 imagOrig = fCoeffs1[arrPos][1];
3721 realRot = fCoeffs2[arrPos][0];
3722 imagRot = fCoeffs2[arrPos][1];
3724 binData[indx][0] += realOrig;
3725 binData[indx][1] += imagOrig;
3726 binData[indx][2] += realRot;
3727 binData[indx][3] += imagRot;
3728 binData[indx][4] += realOrig * realRot;
3729 binData[indx][5] += imagOrig * imagRot;
3730 binData[indx][6] += std::pow ( realOrig, 2.0 );
3731 binData[indx][7] += std::pow ( imagOrig, 2.0 );
3732 binData[indx][8] += std::pow ( realRot, 2.0 );
3733 binData[indx][9] += std::pow ( imagRot, 2.0 );
3736 binCounts[indx] += 1;
3742 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ )
3744 covarByBin.at(binIt) = ( ( binData[binIt][4] + binData[binIt][5] ) /
static_cast< proshade_double
> ( binCounts[binIt] ) -
3745 ( ( binData[binIt][0] /
static_cast< proshade_double
> ( binCounts[binIt] ) *
3746 binData[binIt][2] /
static_cast< proshade_double
> ( binCounts[binIt] ) ) +
3747 ( binData[binIt][1] /
static_cast< proshade_double
> ( binCounts[binIt] ) *
3748 binData[binIt][3] /
static_cast< proshade_double
> ( binCounts[binIt] ) ) ) );
3752 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ )
3754 binData[binIt][10] = ( binData[binIt][6] + binData[binIt][7] ) /
static_cast< proshade_double
> ( binCounts[binIt] ) -
3755 ( std::pow ( binData[binIt][0] /
static_cast< proshade_double
> ( binCounts[binIt] ), 2.0 ) +
3756 std::pow ( binData[binIt][1] /
static_cast< proshade_double
> ( binCounts[binIt] ), 2.0 ) );
3757 binData[binIt][11] = ( binData[binIt][8] + binData[binIt][9] ) /
static_cast< proshade_double
> ( binCounts[binIt] ) -
3758 ( std::pow ( binData[binIt][2] /
static_cast< proshade_double
> ( binCounts[binIt] ), 2.0 ) +
3759 std::pow ( binData[binIt][3] /
static_cast< proshade_double
> ( binCounts[binIt] ), 2.0 ) );
3760 fscByBin[binIt] = covarByBin.at(binIt) / ( std::sqrt ( binData[binIt][10] ) * std::sqrt ( binData[binIt][11] ) );
3764 proshade_double binSizeSum = 0.0;
3765 for (
size_t binIt = 0; binIt < static_cast< size_t > ( noBins ); binIt++ )
3767 if ( averageByBinSize )
3769 fsc += fscByBin[binIt] *
static_cast< proshade_double
> ( binCounts[binIt] );
3770 binSizeSum +=
static_cast< proshade_double
> ( binCounts[binIt] );
3774 fsc += fscByBin[binIt];
3778 fsc /=
static_cast< proshade_double
> ( binSizeSum );
3800 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 )
3803 proshade_signed indx, arrPos, reciX, reciY, reciZ;
3806 weights1 =
new proshade_double[xDim * yDim * zDim];
3807 weights2 =
new proshade_double[xDim * yDim * zDim];
3808 proshade_single *mins =
new proshade_single[3];
3809 proshade_single *maxs =
new proshade_single[3];
3818 for (
size_t iter = 0; iter < static_cast< size_t > ( xDim * yDim * zDim ); iter++ ) { weights1[iter] = -100.0; weights2[iter] = -100.0; }
3821 mins[0] = std::floor (
static_cast< proshade_single
> ( xDim ) / -2.0f );
3822 mins[1] = std::floor (
static_cast< proshade_single
> ( yDim ) / -2.0f );
3823 mins[2] = std::floor (
static_cast< proshade_single
> ( zDim ) / -2.0f );
3829 if ( xDim % 2 == 0 ) { mins[0] += 1.0f; }
3830 if ( yDim % 2 == 0 ) { mins[1] += 1.0f; }
3831 if ( zDim % 2 == 0 ) { mins[2] += 1.0f; }
3834 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
3836 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
3838 for ( proshade_signed zIt = 0; zIt < ( ( zDim / 2 ) + 1 ); zIt++ )
3841 reciX = xIt;
if ( reciX >
static_cast< proshade_signed
> ( maxs[0] ) ) { reciX -=
static_cast< proshade_signed
> ( xDim ); }
3842 reciY = yIt;
if ( reciY >
static_cast< proshade_signed
> ( maxs[1] ) ) { reciY -=
static_cast< proshade_signed
> ( yDim ); }
3843 reciZ = zIt;
if ( reciZ >
static_cast< proshade_signed
> ( maxs[2] ) ) { reciZ -=
static_cast< proshade_signed
> ( zDim ); }
3846 arrPos = zIt + zDim * ( yIt + yDim * xIt );
3847 indx = binIndexing[
static_cast< size_t > ( arrPos ) ];
3850 if ( ( indx < 0 ) || ( indx > noBins ) ) {
continue; }
3853 weights1[arrPos] = fscByBin[indx];
3854 weights2[arrPos] = std::pow ( fscByBin[indx], 2.0 );
3857 if ( reciX ==
static_cast< proshade_signed
> ( mins[0] ) || -reciX ==
static_cast< proshade_signed
> ( mins[0] ) ) {
break; }
3858 if ( reciY ==
static_cast< proshade_signed
> ( mins[1] ) || -reciY ==
static_cast< proshade_signed
> ( mins[1] ) ) {
break; }
3859 if ( reciZ ==
static_cast< proshade_signed
> ( mins[2] ) || -reciZ ==
static_cast< proshade_signed
> ( mins[2] ) ) {
break; }
3862 reciX *= -1;
if ( reciX < 0 ) { reciX += xDim; }
3863 reciY *= -1;
if ( reciY < 0 ) { reciY += yDim; }
3864 reciZ *= -1;
if ( reciZ < 0 ) { reciZ += zDim; }
3867 arrPos = reciZ + zDim * ( reciY + yDim * reciX );
3868 weights1[arrPos] = fscByBin[indx];
3869 weights2[arrPos] = std::pow ( fscByBin[indx], 2.0 );
3895 proshade_double sum = 0.0;
3896 proshade_signed arrPos;
3899 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
3901 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
3903 for ( proshade_signed zIt = 0; zIt < ( ( zDim / 2 ) + 1 ); zIt++ )
3906 arrPos = zIt + zDim * ( yIt + yDim * xIt );
3909 if ( weights[arrPos] > -2.0 ) { sum += fCoeffs[arrPos][0]; }
3930 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 )
3933 firstDers =
new proshade_double[3];
3934 secondDers =
new proshade_double[9];
3935 proshade_single *mins =
new proshade_single[3];
3936 proshade_single *maxs =
new proshade_single[3];
3945 std::complex< proshade_double > piConstFirst ( 2.0 * M_PI, 1.0 );
3946 proshade_double piConstSecond = std::pow ( 2.0 * M_PI, 2.0 );
3947 for (
size_t iter = 0; iter < 3; iter++ ) { firstDers[iter] = 0.0; }
3948 for (
size_t iter = 0; iter < 9; iter++ ) { secondDers[iter] = 0.0; }
3949 proshade_signed reciX, reciY, reciZ, arrPos;
3952 mins[0] = std::floor (
static_cast< proshade_single
> ( xDim ) / -2.0f );
3953 mins[1] = std::floor (
static_cast< proshade_single
> ( yDim ) / -2.0f );
3954 mins[2] = std::floor (
static_cast< proshade_single
> ( zDim ) / -2.0f );
3960 if ( xDim % 2 == 0 ) { mins[0] += 1.0f; }
3961 if ( yDim % 2 == 0 ) { mins[1] += 1.0f; }
3962 if ( zDim % 2 == 0 ) { mins[2] += 1.0f; }
3965 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
3967 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
3969 for ( proshade_signed zIt = 0; zIt < ( ( zDim / 2 ) + 1 ); zIt++ )
3972 reciX = xIt;
if ( reciX >
static_cast< proshade_signed
> ( maxs[0] ) ) { reciX -=
static_cast< proshade_signed
> ( xDim ); }
3973 reciY = yIt;
if ( reciY >
static_cast< proshade_signed
> ( maxs[1] ) ) { reciY -=
static_cast< proshade_signed
> ( yDim ); }
3974 reciZ = zIt;
if ( reciZ >
static_cast< proshade_signed
> ( maxs[2] ) ) { reciZ -=
static_cast< proshade_signed
> ( zDim ); }
3977 arrPos = zIt + zDim * ( yIt + yDim * xIt );
3980 if ( weights1[arrPos] < -2.0 ) {
continue; }
3983 firstDers[0] += ( weights1[arrPos] * fCoeffs[arrPos][0] * std::conj( fCoeffs[arrPos][1] * piConstFirst *
static_cast< proshade_double
> ( reciX ) ) ).real();
3984 firstDers[1] += ( weights1[arrPos] * fCoeffs[arrPos][0] * std::conj( fCoeffs[arrPos][1] * piConstFirst *
static_cast< proshade_double
> ( reciY ) ) ).real();
3985 firstDers[2] += ( weights1[arrPos] * fCoeffs[arrPos][0] * std::conj( fCoeffs[arrPos][1] * piConstFirst *
static_cast< proshade_double
> ( reciZ ) ) ).real();
3988 secondDers[0] += weights2[arrPos] *
static_cast< proshade_double
> ( reciX * reciX );
3989 secondDers[1] += weights2[arrPos] *
static_cast< proshade_double
> ( reciX * reciY );
3990 secondDers[2] += weights2[arrPos] *
static_cast< proshade_double
> ( reciX * reciZ );
3991 secondDers[4] += weights2[arrPos] *
static_cast< proshade_double
> ( reciY * reciY );
3992 secondDers[5] += weights2[arrPos] *
static_cast< proshade_double
> ( reciY * reciZ );
3993 secondDers[8] += weights2[arrPos] *
static_cast< proshade_double
> ( reciZ * reciZ );
3999 secondDers[3] = secondDers[1];
4000 secondDers[6] = secondDers[2];
4001 secondDers[7] = secondDers[5];
4002 for (
size_t iter = 0; iter < 9; iter++ ) { secondDers[iter] *= -piConstSecond; }
4022 std::vector < proshade_double > tmpMap ( 9, 0.0 );
4023 for (
size_t iter = 0; iter < 9; iter++ ) { tmpMap.at(iter) = secondDers[iter]; }
4024 tmpMap.at(0) += 1.0; tmpMap.at(4) += 1.0; tmpMap.at(8) += 1.0;
4050 std::vector< proshade_signed > ret;
4051 bool sameValStreak =
false;
4054 for ( proshade_signed index =
static_cast< proshade_signed
> ( data.size() ) - 1; index > 0; index-- )
4057 if ( index == (
static_cast< proshade_signed
> ( data.size() ) - 1 ) )
4071 if ( ( data.at(
static_cast< size_t > ( index ) ) > data.at(
static_cast< size_t > ( index ) - 1 ) ) &&
4075 if ( sameValStreak && ( index >= 1 ) && ( data.at(
static_cast< size_t > ( index ) ) > data.at(
static_cast< size_t > ( index - 1 ) ) ) ) { sameValStreak =
false;
ProSHADE_internal_misc::addToSignedVector ( &ret, index );
continue; }
4077 const FloatingPoint< proshade_double > lhs ( data.at(
static_cast< size_t > ( index ) ) ), rhs ( 0.0 );
4078 if ( lhs.AlmostEquals ( rhs ) ) {
continue; }
4079 if ( ( index > 1 ) && !sameValStreak )
4081 if ( data.at(
static_cast< size_t > ( index ) ) >= data.at(
static_cast< size_t > ( index - 1 ) ) )
4083 if ( data.at(
static_cast< size_t > ( index ) ) >= data.at(
static_cast< size_t > ( index + 1 ) ) )
4085 sameValStreak =
true;
4092 std::sort ( ret.begin(), ret.end() );
4116 proshade_double threshold = 0.0;
4117 proshade_signed totSize =
static_cast< proshade_signed
> ( ( 1.0 / step ) + 1 );
4118 std::vector< std::pair < proshade_double, proshade_unsign > > vals;
4119 std::vector< proshade_double > hist (
static_cast< unsigned long int > ( totSize ), 0.0 );
4120 proshade_unsign histPos = 0;
4123 if ( windowSize % 2 == 0 ) { windowSize += 1; }
4126 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( CSym->size() ); symIt++ ) {
if ( !std::isinf( CSym->at(symIt)[peakPos] ) ) { vals.emplace_back ( std::pair < proshade_double, proshade_unsign > ( CSym->at(symIt)[peakPos], symIt ) ); } }
4129 for ( proshade_unsign vIt = 0; vIt < static_cast< proshade_unsign > ( vals.size() ); vIt++ ) {
if ( vals.at(vIt).first > maxLim ) { vals.at(vIt).first = maxLim; } }
4132 for ( proshade_double it = 0.0; it <= 1.0; it = it + step )
4134 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( vals.size() ); symIt++ )
4137 if ( ( vals.at(symIt).first > it ) && ( vals.at(symIt).first <= ( it + step ) ) ) { hist.at(histPos) += 1.0; }
4152 if ( peaks.size() > 0 ) { bestHistPos = hist.size() - ( ( smoothened.size() -
static_cast< size_t > ( peaks.at(peaks.size()-1) ) ) + ( (
static_cast< size_t > ( windowSize ) + 1 ) / 2 ) ); }
4153 else { bestHistPos = 0; }
4154 threshold = (
static_cast< proshade_double
> ( bestHistPos ) * step );
4157 proshade_double maxVal = 0.0;
4158 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( CSym->size() ); symIt++ ) {
if ( maxVal < CSym->at(symIt)[peakPos] ) { maxVal = CSym->at(symIt)[peakPos]; } }
4159 if ( maxVal < threshold ) { threshold = maxVal - step; }
4162 return ( threshold );
4183 proshade_double threshold = 0.0;
4184 proshade_signed totSize =
static_cast< proshade_signed
> ( ( 1.0 / step ) + 1 );
4185 std::vector< std::pair < proshade_double, proshade_unsign > > vals;
4186 std::vector< proshade_double > hist (
static_cast< unsigned long int > ( totSize ), 0.0 );
4187 proshade_unsign histPos = 0;
4190 if ( windowSize % 2 == 0 ) { windowSize += 1; }
4193 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( CSym->size() ); symIt++ ) {
if ( !std::isinf( CSym->at(symIt).at(peakPos) ) ) { vals.emplace_back ( std::pair < proshade_double, proshade_unsign > ( CSym->at(symIt).at(peakPos), symIt ) ); } }
4196 for ( proshade_unsign vIt = 0; vIt < static_cast< proshade_unsign > ( vals.size() ); vIt++ ) {
if ( vals.at(vIt).first > maxLim ) { vals.at(vIt).first = maxLim; } }
4199 for ( proshade_double it = 0.0; it <= 1.0; it = it + step )
4201 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( vals.size() ); symIt++ )
4204 if ( ( vals.at(symIt).first > it ) && ( vals.at(symIt).first <= ( it + step ) ) ) { hist.at(histPos) += 1.0; }
4219 if ( peaks.size() > 0 ) { bestHistPos = hist.size() - ( ( smoothened.size() -
static_cast< size_t > ( peaks.at(peaks.size()-1) ) ) + ( (
static_cast< size_t > ( windowSize ) + 1 ) / 2 ) ); }
4220 else { bestHistPos = 0; }
4221 threshold = (
static_cast< proshade_double
> ( bestHistPos ) * step );
4224 proshade_double maxVal = 0.0;
4225 for ( proshade_unsign symIt = 0; symIt < static_cast<proshade_unsign> ( CSym->size() ); symIt++ ) {
if ( maxVal < CSym->at(symIt).at(peakPos) ) { maxVal = CSym->at(symIt).at(peakPos); } }
4226 if ( maxVal < threshold ) { threshold = maxVal - step; }
4229 return ( threshold );
4245 double normFactor =
static_cast<double> ( xD * yD * zD );
4246 proshade_signed arrPos;
4249 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xD ); xIt++ )
4251 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yD ); yIt++ )
4253 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zD ); zIt++ )
4256 arrPos = zIt +
static_cast< proshade_signed
> ( zD ) * ( yIt +
static_cast< proshade_signed
> ( yD ) * xIt );
4260 &tmpOut1[arrPos][1],
4261 &tmpOut2[arrPos][0],
4262 &tmpOut2[arrPos][1],
4264 &resOut[arrPos][1] );
4267 resOut[arrPos][0] /= normFactor;
4268 resOut[arrPos][1] /= normFactor;
4292 proshade_signed arrPos;
4296 for ( proshade_signed uIt = 0; uIt < static_cast<proshade_signed> ( xD ); uIt++ )
4298 for ( proshade_signed vIt = 0; vIt < static_cast<proshade_signed> ( yD ); vIt++ )
4300 for ( proshade_signed wIt = 0; wIt < static_cast<proshade_signed> ( zD ); wIt++ )
4302 arrPos = wIt +
static_cast< proshade_signed
> ( zD ) * ( vIt +
static_cast< proshade_signed
> ( yD ) * uIt );
4303 if ( resIn[arrPos][0] > *mapPeak )
4305 *mapPeak = resIn[arrPos][0];
4306 *trsX =
static_cast< proshade_double
> ( uIt );
4307 *trsY =
static_cast< proshade_double
> ( vIt );
4308 *trsZ =
static_cast< proshade_double
> ( wIt );