/// Constructor /// @param M :: A matrix to copy. GSLMatrix::GSLMatrix(const Kernel::Matrix<double> &M) { m_matrix = gsl_matrix_alloc(M.numRows(), M.numCols()); for (size_t i = 0; i < size1(); ++i) for (size_t j = 0; j < size2(); ++j) { set(i, j, M[i][j]); } }
std::vector<Kernel::V3D> PeakShapeEllipsoid::getDirectionInSpecificFrame( Kernel::Matrix<double> &invertedGoniometerMatrix) const { std::vector<Kernel::V3D> directionsInFrame; if ((invertedGoniometerMatrix.numCols() != m_directions.size()) || (invertedGoniometerMatrix.numRows() != m_directions.size())) { throw std::invalid_argument("The inverted goniometer matrix is not " "compatible with the direction vector"); } for (const auto &direction : m_directions) { directionsInFrame.push_back(invertedGoniometerMatrix * direction); } return directionsInFrame; }
/** * Checks the normalization workspace against the indices of the original * dimensions. * If not found, the corresponding dimension is integrated * @param otherDimValues Values from non-HKL dimensions * @param skipNormalization [InOut] Sets the flag true if normalization values * are outside of original inputs * @return Affine trasform matrix */ Kernel::Matrix<coord_t> MDNormDirectSC::findIntergratedDimensions( const std::vector<coord_t> &otherDimValues, bool &skipNormalization) { // Get indices of the original dimensions in the output workspace, // and if not found, the corresponding dimension is integrated Kernel::Matrix<coord_t> affineMat = m_normWS->getTransformFromOriginal(0)->makeAffineMatrix(); const size_t nrm1 = affineMat.numRows() - 1; const size_t ncm1 = affineMat.numCols() - 1; for (size_t row = 0; row < nrm1; row++) // affine matrix, ignore last row { const auto dimen = m_normWS->getDimension(row); const auto dimMin(dimen->getMinimum()), dimMax(dimen->getMaximum()); if (affineMat[row][0] == 1.) { m_hIntegrated = false; m_hIdx = row; m_hmin = std::max(m_hmin, dimMin); m_hmax = std::min(m_hmax, dimMax); if (m_hmin > dimMax || m_hmax < dimMin) { skipNormalization = true; } } if (affineMat[row][1] == 1.) { m_kIntegrated = false; m_kIdx = row; m_kmin = std::max(m_kmin, dimMin); m_kmax = std::min(m_kmax, dimMax); if (m_kmin > dimMax || m_kmax < dimMin) { skipNormalization = true; } } if (affineMat[row][2] == 1.) { m_lIntegrated = false; m_lIdx = row; m_lmin = std::max(m_lmin, dimMin); m_lmax = std::min(m_lmax, dimMax); if (m_lmin > dimMax || m_lmax < dimMin) { skipNormalization = true; } } if (affineMat[row][3] == 1.) { m_dEIntegrated = false; m_eIdx = row; m_dEmin = std::max(m_dEmin, dimMin); m_dEmax = std::min(m_dEmax, dimMax); if (m_dEmin > dimMax || m_dEmax < dimMin) { skipNormalization = true; } } for (size_t col = 4; col < ncm1; col++) // affine matrix, ignore last column { if (affineMat[row][col] == 1.) { double val = otherDimValues.at(col - 3); if (val > dimMax || val < dimMin) { skipNormalization = true; } } } } return affineMat; }
/// Constructor /// @param M :: A matrix to copy. GSLMatrix::GSLMatrix(const Kernel::Matrix<double> &M) : m_data(M.getVector()), m_view(gsl_matrix_view_array(m_data.data(), M.numRows(), M.numCols())) {}
/** * This function will create the skew matrix and basis for a non-orthogonal * representation. * * @param ol : The oriented lattice containing B matrix and crystal basis *vectors * @param w : The tranform requested when MDworkspace was created * @param aff : The affine matrix taking care of coordinate transformations */ void vtkDataSetToNonOrthogonalDataSet::createSkewInformation( Geometry::OrientedLattice &ol, Kernel::DblMatrix &w, Kernel::Matrix<coord_t> &aff) { // Get the B matrix Kernel::DblMatrix bMat = ol.getB(); // Apply the W tranform matrix bMat *= w; // Create G* Kernel::DblMatrix gStar = bMat.Tprime() * bMat; Geometry::UnitCell uc(ol); uc.recalculateFromGstar(gStar); m_skewMat = uc.getB(); // Calculate the column normalisation std::vector<double> bNorm; for (std::size_t i = 0; i < m_skewMat.numCols(); i++) { double sum = 0.0; for (std::size_t j = 0; j < m_skewMat.numRows(); j++) { sum += m_skewMat[j][i] * m_skewMat[j][i]; } bNorm.push_back(std::sqrt(sum)); } // Apply column normalisation to skew matrix Kernel::DblMatrix scaleMat(3, 3, true); scaleMat[0][0] /= bNorm[0]; scaleMat[1][1] /= bNorm[1]; scaleMat[2][2] /= bNorm[2]; m_skewMat *= scaleMat; // Setup basis normalisation array // Intel and MSBuild can't handle this // m_basisNorm = {ol.astar(), ol.bstar(), ol.cstar()}; m_basisNorm.push_back(ol.astar()); m_basisNorm.push_back(ol.bstar()); m_basisNorm.push_back(ol.cstar()); // Expand matrix to 4 dimensions if necessary if (4 == m_numDims) { m_basisNorm.push_back(1.0); Kernel::DblMatrix temp(4, 4, true); for (std::size_t i = 0; i < 3; i++) { for (std::size_t j = 0; j < 3; j++) { temp[i][j] = m_skewMat[i][j]; } } m_skewMat = temp; } // Convert affine matrix to similar type as others Kernel::DblMatrix affMat(aff.numRows(), aff.numCols()); for (std::size_t i = 0; i < aff.numRows(); i++) { for (std::size_t j = 0; j < aff.numCols(); j++) { affMat[i][j] = aff[i][j]; } } // Strip affine matrix down to correct dimensions this->stripMatrix(affMat); // Perform similarity transform to get coordinate orientation correct m_skewMat = affMat.Tprime() * (m_skewMat * affMat); m_basisNorm = affMat * m_basisNorm; if (4 == m_numDims) { this->stripMatrix(m_skewMat); } this->findSkewBasis(m_basisX, m_basisNorm[0]); this->findSkewBasis(m_basisY, m_basisNorm[1]); this->findSkewBasis(m_basisZ, m_basisNorm[2]); }