TheTest & test_mask() { Data<R> dataA, dataB, dataC, dataD(1), dataE(2); dataA[1] *= (LaneType)-1; dataC *= (LaneType)-1; R a = dataA, b = dataB, c = dataC, d = dataD, e = dataE; int m = v_signmask(a); EXPECT_EQ(2, m); EXPECT_EQ(false, v_check_all(a)); EXPECT_EQ(false, v_check_all(b)); EXPECT_EQ(true, v_check_all(c)); EXPECT_EQ(true, v_check_any(a)); EXPECT_EQ(false, v_check_any(b)); EXPECT_EQ(true, v_check_any(c)); typedef V_TypeTraits<LaneType> Traits; typedef typename Traits::int_type int_type; R f = v_select(b, d, e); Data<R> resF = f; for (int i = 0; i < R::nlanes; ++i) { int_type m2 = Traits::reinterpret_int(dataB[i]); EXPECT_EQ((Traits::reinterpret_int(dataD[i]) & m2) | (Traits::reinterpret_int(dataE[i]) & ~m2), Traits::reinterpret_int(resF[i])); } return *this; }
/** * Convert to the output dimensions * @param inputWs : Input Matrix workspace * @return workspace group containing output matrix workspaces of ki and kf */ Mantid::API::MatrixWorkspace_sptr ReflectometryTransform::execute( Mantid::API::MatrixWorkspace_const_sptr inputWs) const { auto ws = boost::make_shared<Mantid::DataObjects::Workspace2D>(); ws->initialize(m_d1NumBins, m_d0NumBins, m_d0NumBins); // Create the output workspace as a distribution // Mapping so that d0 and d1 values calculated can be added to the matrix // workspace at the correct index. const double gradD0 = double(m_d0NumBins) / (m_d0Max - m_d0Min); // The x - axis const double gradD1 = double(m_d1NumBins) / (m_d1Max - m_d1Min); // Actually the y-axis const double cxToIndex = -gradD0 * m_d0Min; const double cyToIndex = -gradD1 * m_d1Min; const double cxToD0 = m_d0Min - (1 / gradD0); const double cyToD1 = m_d1Min - (1 / gradD1); // Create an X - Axis. MantidVec xAxisVec = createXAxis(ws.get(), gradD0, cxToD0, m_d0NumBins, m_d0Label, "1/Angstroms"); // Create a Y (vertical) Axis createVerticalAxis(ws.get(), xAxisVec, gradD1, cyToD1, m_d1NumBins, m_d1Label, "1/Angstroms"); // Loop over all entries in the input workspace and calculate d0 and d1 // for each. auto spectraAxis = inputWs->getAxis(1); for (size_t index = 0; index < inputWs->getNumberHistograms(); ++index) { auto counts = inputWs->readY(index); auto wavelengths = inputWs->readX(index); auto errors = inputWs->readE(index); const size_t nInputBins = wavelengths.size() - 1; const double theta_final = spectraAxis->getValue(index); m_calculator->setThetaFinal(theta_final); // Loop over all bins in spectra for (size_t binIndex = 0; binIndex < nInputBins; ++binIndex) { const double wavelength = 0.5 * (wavelengths[binIndex] + wavelengths[binIndex + 1]); double _d0 = m_calculator->calculateDim0(wavelength); double _d1 = m_calculator->calculateDim1(wavelength); if (_d0 >= m_d0Min && _d0 <= m_d0Max && _d1 >= m_d1Min && _d1 <= m_d1Max) // Check that the calculated ki and kf are in range { const int outIndexX = static_cast<int>((gradD0 * _d0) + cxToIndex); const int outIndexZ = static_cast<int>((gradD1 * _d1) + cyToIndex); ws->dataY(outIndexZ)[outIndexX] += counts[binIndex]; ws->dataE(outIndexZ)[outIndexX] += errors[binIndex]; } } } return ws; }
/** Apply dead time correction to spectra in inputWs and create temporary workspace with corrected spectra * @param inputWs :: [input] input workspace containing spectra to correct * @param deadTimeTable :: [input] table containing dead times * @param tempWs :: [output] workspace containing corrected spectra */ void PhaseQuadMuon::deadTimeCorrection(API::MatrixWorkspace_sptr inputWs, API::ITableWorkspace_sptr deadTimeTable, API::MatrixWorkspace_sptr& tempWs) { // Apply correction only from t = m_tPulseOver // To do so, we first apply corrections to the whole spectrum (ApplyDeadTimeCorr // does not allow to select a range in the spectrum) // Then we recover counts from 0 to m_tPulseOver auto alg = this->createChildAlgorithm("ApplyDeadTimeCorr",-1,-1); alg->initialize(); alg->setProperty("DeadTimeTable", deadTimeTable); alg->setPropertyValue("InputWorkspace", inputWs->getName()); alg->setPropertyValue("OutputWorkspace", inputWs->getName()+"_deadtime"); bool sucDeadTime = alg->execute(); if (!sucDeadTime) { g_log.error() << "PhaseQuad: Unable to apply dead time corrections" << std::endl; throw std::runtime_error("PhaseQuad: Unable to apply dead time corrections"); } tempWs = alg->getProperty("OutputWorkspace"); // Now recover counts from t=0 to m_tPulseOver // Errors are set to m_bigNumber for (int h=0; h<m_nHist; h++) { auto specOld = inputWs->getSpectrum(h); auto specNew = tempWs->getSpectrum(h); for (int t=0; t<m_tPulseOver; t++) { specNew->dataY()[t] = specOld->dataY()[t]; specNew->dataE()[t] = m_bigNumber; } } }
/// Construct from ISpectrum. Histogram1D::Histogram1D(const ISpectrum &other) : ISpectrum(other) { dataY() = other.readY(); dataE() = other.readE(); }
/// Assignment from ISpectrum. Histogram1D &Histogram1D::operator=(const ISpectrum &rhs) { ISpectrum::operator=(rhs); dataY() = rhs.readY(); dataE() = rhs.readE(); return *this; }
// Load a joint void skeleton::loadJoint(MDagPath& jointDag,joint* parent) { int i; joint newJoint; joint* parentJoint = parent; if (jointDag.hasFn(MFn::kJoint)) { MFnIkJoint jointFn(jointDag); // Get parent index int idx=-1; if (parent) { idx = parent->id; } // Get joint matrix MMatrix worldMatrix = jointDag.inclusiveMatrix(); /*float translation1[3]; float rotation1[4]; float scale1[3]; extractTranMatrix(worldMatrix,translation1,rotation1,scale1); Quaternion q(rotation1[0],rotation1[1],rotation1[2],rotation1[3]); float angle; Vector3 axis; q.ToAngleAxis(angle,axis); Vector3 x,y,z; q.ToAxes(x,y,z);*/ //printMatrix(worldMatrix); // Calculate scaling factor inherited by parent // Calculate Local Matrix MMatrix localMatrix = worldMatrix; if (parent) localMatrix = worldMatrix * parent->worldMatrix.inverse(); float translation2[3]; float rotation2[4]; float scale2[3]; extractTranMatrix(worldMatrix,translation2,rotation2,scale2); //printMatrix(localMatrix); // Set joint info newJoint.name = jointFn.partialPathName(); newJoint.id = m_joints.size(); newJoint.parentIndex = idx; newJoint.jointDag = jointDag; newJoint.worldMatrix = worldMatrix; newJoint.localMatrix = localMatrix; for (int iRow = 0; iRow < 4; iRow++) for (int iCol = 0; iCol < 3; iCol++) newJoint.tran.m_mat[iRow][iCol] = (FLOAT)worldMatrix[iRow][iCol]; //printMatrix(worldMatrix); /*MQuaternion q; q = worldMatrix; newJoint.tran.q[0] = (float)q.x; newJoint.tran.q[1] = (float)q.y; newJoint.tran.q[2] = (float)q.z; newJoint.tran.q[3] = (float)q.w; newJoint.tran.t[0] = (float)worldMatrix[3][0]; newJoint.tran.t[1] = (float)worldMatrix[3][1]; newJoint.tran.t[2] = (float)worldMatrix[3][2];*/ MPlug plug = jointFn.findPlug("unRibbonEnabled"); if(!plug.isNull()) { bool enabled; plug.getValue(enabled); if(enabled) { plug = jointFn.findPlug("unRibbonVisible"); bool visible; plug.getValue(visible); plug = jointFn.findPlug("unRibbonAbove"); float above; plug.getValue(above); plug = jointFn.findPlug("unRibbonBelow"); float below; plug.getValue(below); plug = jointFn.findPlug("unRibbonEdgesPerSecond"); short edgePerSecond; plug.getValue(edgePerSecond); plug = jointFn.findPlug("unRibbonEdgeLife"); float edgeLife; plug.getValue(edgeLife); plug = jointFn.findPlug("unRibbonGravity"); float gravity; plug.getValue(gravity); plug = jointFn.findPlug("unRibbonTextureRows"); short rows; plug.getValue(rows); plug = jointFn.findPlug("unRibbonTextureCols"); short cols; plug.getValue(cols); plug = jointFn.findPlug("unRibbonTextureSlot"); short slot; plug.getValue(slot); plug = jointFn.findPlug("unRibbonVertexColor"); MObject object; plug.getValue(object); MFnNumericData data(object); float r,g,b; data.getData(r,g,b); plug = jointFn.findPlug("unRibbonVertexAlpha"); float alpha; plug.getValue(alpha); plug = jointFn.findPlug("unRibbonBlendMode"); short blendMode; plug.getValue(blendMode); plug = jointFn.findPlug("unRibbonTextureFilename"); MItDependencyGraph dgIt(plug, MFn::kFileTexture, MItDependencyGraph::kUpstream, MItDependencyGraph::kBreadthFirst, MItDependencyGraph::kNodeLevel); dgIt.disablePruningOnFilter(); MString textureName; if (!dgIt.isDone()) { MObject textureNode = dgIt.thisNode(); MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName"); filenamePlug.getValue(textureName); } else { char str[256]; sprintf(str,"%s ribbon system must has file-texture",newJoint.name.asChar()); MessageBox(0,str,0,0); } newJoint.hasRibbonSystem = true; newJoint.ribbon.visible = visible; newJoint.ribbon.above = above; newJoint.ribbon.below = below; newJoint.ribbon.gravity = gravity; newJoint.ribbon.edgePerSecond = edgePerSecond; newJoint.ribbon.edgeLife = edgeLife; newJoint.ribbon.rows = rows; newJoint.ribbon.cols = cols; newJoint.ribbon.slot = slot; newJoint.ribbon.color[0] = r; newJoint.ribbon.color[1] = g; newJoint.ribbon.color[2] = b; newJoint.ribbon.alpha = alpha; newJoint.ribbon.blendMode = blendMode; newJoint.ribbon.textureFilename = textureName.asChar(); } } plug = jointFn.findPlug("unParticleEnabled"); if(!plug.isNull()) { bool enabled; plug.getValue(enabled); if(enabled) { newJoint.hasParticleSystem = true; plug = jointFn.findPlug("unParticleVisible"); bool visible; plug.getValue(visible); plug = jointFn.findPlug("unParticleSpeed"); float speed; plug.getValue(speed); plug = jointFn.findPlug("unParticleVariationPercent"); float variation; plug.getValue(variation); plug = jointFn.findPlug("unParticleConeAngle"); float coneAngle; plug.getValue(coneAngle); plug = jointFn.findPlug("unParticleGravity"); float gravity; plug.getValue(gravity); plug = jointFn.findPlug("unParticleExplosiveForce"); float explosiveForce = 0.0f; if(!plug.isNull()) { plug.getValue(explosiveForce); } plug = jointFn.findPlug("unParticleLife"); float life; plug.getValue(life); plug = jointFn.findPlug("unParticleLifeVariation"); float lifeVar; if(plug.isNull()) { lifeVar = 0.0f; } else { plug.getValue(lifeVar); } plug = jointFn.findPlug("unParticleEmissionRate"); float emissionRate; plug.getValue(emissionRate); plug = jointFn.findPlug("unParticleLimitNum"); short limitNum; plug.getValue(limitNum); plug = jointFn.findPlug("unParticleInitialNum"); short initialNum = 0; if(!plug.isNull())plug.getValue(initialNum); plug = jointFn.findPlug("unParticleAttachToEmitter"); bool attachToEmitter; plug.getValue(attachToEmitter); plug = jointFn.findPlug("unParticleMoveWithEmitter"); bool moveWithEmitter = false; if(!plug.isNull())plug.getValue(moveWithEmitter); //23 plug = jointFn.findPlug("unParticleForTheSword"); bool forTheSword = false; if(!plug.isNull())plug.getValue(forTheSword); //24 plug = jointFn.findPlug("unParticleForTheSwordInitialAngle"); float forTheSwordInitialAngle = 0; if(!plug.isNull())plug.getValue(forTheSwordInitialAngle); //25 plug = jointFn.findPlug("unParticleWander"); bool wander = false; if(!plug.isNull())plug.getValue(wander); //25 plug = jointFn.findPlug("unParticleWanderRadius"); float wanderRadius = 0.0f; if(!plug.isNull())plug.getValue(wanderRadius); //25 plug = jointFn.findPlug("unParticleWanderSpeed"); float wanderSpeed = 0.0f; if(!plug.isNull())plug.getValue(wanderSpeed); plug = jointFn.findPlug("unParticleAspectRatio"); float aspectRatio; if(plug.isNull()) { aspectRatio = 1.0f; } else { plug.getValue(aspectRatio); } plug = jointFn.findPlug("unParticleInitialAngleBegin"); float angleBegin; if(plug.isNull()) { angleBegin = 0.0f; } else { plug.getValue(angleBegin); } plug = jointFn.findPlug("unParticleInitialAngleEnd"); float angleEnd; if(plug.isNull()) { angleEnd = 0.0f; } else { plug.getValue(angleEnd); } plug = jointFn.findPlug("unParticleRotationSpeed"); float rotationSpeed; if(plug.isNull()) { rotationSpeed = 0; } else { plug.getValue(rotationSpeed); } plug = jointFn.findPlug("unParticleRotationSpeedVar"); float rotationSpeedVar; if(plug.isNull()) { rotationSpeedVar = 0; } else { plug.getValue(rotationSpeedVar); } plug = jointFn.findPlug("unParticleEmitterWidth"); float width; plug.getValue(width); plug = jointFn.findPlug("unParticleEmitterLength"); float length; plug.getValue(length); plug = jointFn.findPlug("unParticleEmitterHeight"); float height = 0.0f; if(!plug.isNull()) { plug.getValue(height); } plug = jointFn.findPlug("unParticleBlendMode"); short blendMode; plug.getValue(blendMode); plug = jointFn.findPlug("unParticleTextureFilename"); MItDependencyGraph dgIt(plug, MFn::kFileTexture, MItDependencyGraph::kUpstream, MItDependencyGraph::kBreadthFirst, MItDependencyGraph::kNodeLevel); dgIt.disablePruningOnFilter(); MString textureName; if (!dgIt.isDone()) { MObject textureNode = dgIt.thisNode(); MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName"); filenamePlug.getValue(textureName); } else { char str[256]; sprintf(str,"%s particle system must has file-texture",newJoint.name.asChar()); MessageBox(0,str,0,0); } plug = jointFn.findPlug("unParticleTextureRows"); short rows; plug.getValue(rows); plug = jointFn.findPlug("unParticleTextureCols"); short cols; plug.getValue(cols); plug = jointFn.findPlug("unParticleTextureChangeStyle"); short changeStyle; if(plug.isNull()) { //0 - 顺序 //1 - 随机 changeStyle = 0; } else { plug.getValue(changeStyle); } plug = jointFn.findPlug("unParticleTextureChangeInterval"); short changeInterval; if(plug.isNull()) { //默认30ms换一个 changeInterval = 30; } else { plug.getValue(changeInterval); } plug = jointFn.findPlug("unParticleTailLength"); float tailLength; plug.getValue(tailLength); plug = jointFn.findPlug("unParticleTimeMiddle"); float timeMiddle; plug.getValue(timeMiddle); plug = jointFn.findPlug("unParticleColorStart"); MObject object; plug.getValue(object); MFnNumericData dataS(object); float colorStart[3]; dataS.getData(colorStart[0],colorStart[1],colorStart[2]); plug = jointFn.findPlug("unParticleColorMiddle"); plug.getValue(object); MFnNumericData dataM(object); float colorMiddle[3]; dataM.getData(colorMiddle[0],colorMiddle[1],colorMiddle[2]); plug = jointFn.findPlug("unParticleColorEnd"); plug.getValue(object); MFnNumericData dataE(object); float colorEnd[3]; dataE.getData(colorEnd[0],colorEnd[1],colorEnd[2]); plug = jointFn.findPlug("unParticleAlpha"); plug.getValue(object); MFnNumericData dataAlpha(object); float alpha[3]; dataAlpha.getData(alpha[0],alpha[1],alpha[2]); //Scale plug = jointFn.findPlug("unParticleScale"); plug.getValue(object); MFnNumericData dataScale(object); float scale[3]; dataScale.getData(scale[0],scale[1],scale[2]); //ScaleVar plug = jointFn.findPlug("unParticleScaleVar"); float scaleVar[3] = {0.0f,0.0f,0.0f}; if(!plug.isNull()) { plug.getValue(object); MFnNumericData dataScaleVar(object); dataScaleVar.getData(scaleVar[0],scaleVar[1],scaleVar[2]); } //FixedSize plug = jointFn.findPlug("unParticleFixedSize"); bool fixedSize = false; if(!plug.isNull()) { plug.getValue(fixedSize); } //HeadLifeSpan plug = jointFn.findPlug("unParticleHeadLifeSpan"); plug.getValue(object); MFnNumericData dataHeadLifeSpan(object); short headLifeSpan[3]; dataHeadLifeSpan.getData(headLifeSpan[0],headLifeSpan[1],headLifeSpan[2]); plug = jointFn.findPlug("unParticleHeadDecay"); plug.getValue(object); MFnNumericData dataHeadDecay(object); short headDecay[3]; dataHeadDecay.getData(headDecay[0],headDecay[1],headDecay[2]); plug = jointFn.findPlug("unParticleTailLifeSpan"); plug.getValue(object); MFnNumericData dataTailLifeSpan(object); short tailLifeSpan[3]; dataTailLifeSpan.getData(tailLifeSpan[0],tailLifeSpan[1],tailLifeSpan[2]); plug = jointFn.findPlug("unParticleTailDecay"); plug.getValue(object); MFnNumericData dataTailDecay(object); short tailDecay[3]; dataTailDecay.getData(tailDecay[0],tailDecay[1],tailDecay[2]); plug = jointFn.findPlug("unParticleHead"); bool head; plug.getValue(head); plug = jointFn.findPlug("unParticleTail"); bool tail; plug.getValue(tail); plug = jointFn.findPlug("unParticleUnShaded"); bool unshaded; plug.getValue(unshaded); plug = jointFn.findPlug("unParticleUnFogged"); bool unfogged; plug.getValue(unfogged); plug = jointFn.findPlug("unParticleBlockByY0"); bool blockByY0 = false; if(!plug.isNull()) plug.getValue(blockByY0); newJoint.particle.visible = visible; newJoint.particle.speed = speed; newJoint.particle.variation = variation / 100.0f; newJoint.particle.coneAngle = coneAngle; newJoint.particle.gravity = gravity; newJoint.particle.explosiveForce = explosiveForce; newJoint.particle.life = life; newJoint.particle.lifeVar = lifeVar; newJoint.particle.emissionRate = emissionRate; newJoint.particle.initialNum = initialNum; newJoint.particle.limitNum = limitNum; newJoint.particle.attachToEmitter = attachToEmitter; newJoint.particle.moveWithEmitter = moveWithEmitter; newJoint.particle.forTheSword = forTheSword; newJoint.particle.forTheSwordInitialAngle = forTheSwordInitialAngle; newJoint.particle.wander = wander; newJoint.particle.wanderRadius = wanderRadius; newJoint.particle.wanderSpeed = wanderSpeed; newJoint.particle.aspectRatio = aspectRatio; newJoint.particle.initialAngleBegin = angleBegin; newJoint.particle.initialAngleEnd = angleEnd; newJoint.particle.rotationSpeed = rotationSpeed; newJoint.particle.rotationSpeedVar = rotationSpeedVar; newJoint.particle.width = width; newJoint.particle.length = length; newJoint.particle.height = height; newJoint.particle.blendMode = blendMode; newJoint.particle.textureFilename = textureName.asChar(); newJoint.particle.textureRows = rows; newJoint.particle.textureCols = cols; newJoint.particle.changeStyle = changeStyle; newJoint.particle.changeInterval = changeInterval; newJoint.particle.tailLength = tailLength; newJoint.particle.timeMiddle = timeMiddle; newJoint.particle.colorStart[0] = colorStart[0]; newJoint.particle.colorStart[1] = colorStart[1]; newJoint.particle.colorStart[2] = colorStart[2]; newJoint.particle.colorMiddle[0] = colorMiddle[0]; newJoint.particle.colorMiddle[1] = colorMiddle[1]; newJoint.particle.colorMiddle[2] = colorMiddle[2]; newJoint.particle.colorEnd[0] = colorEnd[0]; newJoint.particle.colorEnd[1] = colorEnd[1]; newJoint.particle.colorEnd[2] = colorEnd[2]; newJoint.particle.alpha[0] = alpha[0]; newJoint.particle.alpha[1] = alpha[1]; newJoint.particle.alpha[2] = alpha[2]; newJoint.particle.scale[0] = scale[0]; newJoint.particle.scale[1] = scale[1]; newJoint.particle.scale[2] = scale[2]; newJoint.particle.scaleVar[0] = scaleVar[0]; newJoint.particle.scaleVar[1] = scaleVar[1]; newJoint.particle.scaleVar[2] = scaleVar[2]; newJoint.particle.fixedSize = fixedSize; newJoint.particle.headLifeSpan[0] = headLifeSpan[0]; newJoint.particle.headLifeSpan[1] = headLifeSpan[1]; newJoint.particle.headLifeSpan[2] = headLifeSpan[2]; newJoint.particle.headDecay[0] = headDecay[0]; newJoint.particle.headDecay[1] = headDecay[1]; newJoint.particle.headDecay[2] = headDecay[2]; newJoint.particle.tailLifeSpan[0] = tailLifeSpan[0]; newJoint.particle.tailLifeSpan[1] = tailLifeSpan[1]; newJoint.particle.tailLifeSpan[2] = tailLifeSpan[2]; newJoint.particle.tailDecay[0] = tailDecay[0]; newJoint.particle.tailDecay[1] = tailDecay[1]; newJoint.particle.tailDecay[2] = tailDecay[2]; newJoint.particle.head = head; newJoint.particle.tail = tail; newJoint.particle.unshaded = unshaded; newJoint.particle.unfogged = unfogged; newJoint.particle.blockByY0 = blockByY0; } } m_joints.push_back(newJoint); // Get pointer to newly created joint parentJoint = &newJoint; } // Load children joints for (i=0; i<jointDag.childCount();i++) { MObject child; child = jointDag.child(i); MDagPath childDag = jointDag; childDag.push(child); loadJoint(childDag,parentJoint); } }