bool CstrategyScans::bSetScans(Cimage_header* poHeader, const Cstring& sStrategyPrefix) { if( !poHeader ) return false; // safety vClearScans(); ///////////////////////////////////////////////////////////////////////////////// // Figure out how many scans are there int iScanMax = -1; while(true) { iScanMax++; Crotation oRotation(*poHeader, sBuildStrategyScanPrefix(sStrategyPrefix, D_K_ScanPrefix, iScanMax)); oRotation.ms_nVerbose = 0; // so that when it fails at the end of this while loop, it does not say it's an error, because we do want it to fail. if( !oRotation.bIsAvailable() ) break; } iScanMax--; // last valid scan index ///////////////////////////////////////////////////////////////////////////////// if( iScanMax < 0 ) return false; for(int iScan=0; iScan <= iScanMax; iScan++) vAddScan(poHeader, iScan, m_aoAxes.size(), sStrategyPrefix); return true; }
CstrategyScan::CstrategyScan(Cimage_header* poHeader, int nScanIndex, int nNumAxes, const Cstring& sStrategyPrefix) { vInit(); // Get gonio values // Build scan prefix Cstring strScanCrystalPrefix = sBuildStrategyScanPrefix(sStrategyPrefix, D_K_CrystalPrefix, nScanIndex); double* pdGonioValues = new double[nNumAxes]; int nStat = poHeader->nGetValue(strScanCrystalPrefix + D_K_GonioValues, nNumAxes, pdGonioValues); if( 0 != nStat ) { delete [] pdGonioValues; return; } // Add axes objects for(int ii=0; ii < nNumAxes; ii++) { m_aoAxes.push_back(CstrategyAxis(ii, pdGonioValues[ii])); } delete [] pdGonioValues; /////////////////////////// Cstring sScanPrefix = sBuildStrategyScanPrefix(sStrategyPrefix, D_K_ScanPrefix, nScanIndex); Crotation oRotation(*poHeader, sScanPrefix); m_dRot_Begin[enSingleScan] = m_dRot_Begin[enMultipleScan] = (double)oRotation.fGetRotStart(); m_dRot_End [enSingleScan] = m_dRot_End [enMultipleScan] = (double)oRotation.fGetRotEnd(); m_dMaxRotRange = (double)oRotation.fGetRotRange(); m_segRotLimits.vSet((double)oRotation.fGetRotMin(), (double)oRotation.fGetRotMax()); m_nOriginalScanIndex = nScanIndex; ///////////////////////////////////////////////////////////////////////////////////////////////// // See if the header uses D_K_ScanDetDatum keyword to specify the detector position. If it does not - no problem, // the detector position will be read by the container class CstrategyScans using detector D_K_GonioValues keyword. Cstring sScanDetRelZero(D_K_ScanDetDatum); double dDetRelZero[3] = {0.0}; if( 0 == poHeader->nGetValue(sScanPrefix + sScanDetRelZero, 3, dDetRelZero) ) // the first value should be equal to 2, then two theta and distance { m_dDetRelZero[enStratScanDetRelZero_TwoTheta] = dDetRelZero[1]; m_dDetRelZero[enStratScanDetRelZero_Distance] = dDetRelZero[2]; } /////////////////////////// //shijie yao : 2008.03.12 //Noticed there was a var m_fImageRotWidth defined, which should server the //same as m_dIncrementalWidth. But the original code didn't set its value //properly. It's value was set from the STRATEGY_INPUT_S*_SCAN_ROTATION, //which only keeps the original copy of the SCAN_ROTATION values, even the //-rotimage option is provided. //After adding code in CDTMainMultiStrategy::bGetImageRotationWidth() to //update the STRATEGY_INPUT_S*_SCAN_ entries together with the SCAN_ROTATION, //for the new imagewidth value, m_fImageRotWidth and m_dIncrementalWidth are //sequal now. // m_fImageRotWidth = oRotation.fGetIncrement(); m_dCryGonioValMax = oRotation.fGetRotMax(); m_dCryGonioValMin = oRotation.fGetRotMin(); //Crotation oScanRot(*poHeader, D_K_ScanPrefix); // use SCAN_ROTATION values for rotImageWidth //m_dIncrementalWidth = oScanRot.fGetIncrement(); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // This function updates scans in the header object. Return value - number of scans updated. int CstrategyScans::nUpdateHeader(Cimage_header* poHeader, int nScanNumberOffset, const Cstring& sStrategyPrefix, bool bUpdateDetectorPosition) { if( !poHeader ) return 0; //safety check int nScansUpdated = 0; int nScanNumberForRecord = -1; CstrategyScan::enStrategyScanType eScanType = !m_bMultipleScanSolution ? CstrategyScan::enSingleScan : CstrategyScan::enMultipleScan; // Let's create a rotation object based on scan 0, then substitute variable fields in a loop. Cstring sScanPrefix(D_K_ScanPrefix); Cstring sScanDetRelZero(D_K_ScanDetDatum); Crotation oRotation(*poHeader, sScanPrefix); if( !oRotation.bIsAvailable() ) // The scan must be in the header. { printf("\nERROR: Cannot create rotation object for writing a header\n"); return 0; } CSegment segRotLimits(0.0, 0.0); Cstring sScanCrystalPrefix(""); int nNumAxes = nGetNumAxes(); double* pdGonioValues = new double[nNumAxes]; int nUsed = -1; double dDetRelZero[3] = {2.0}; // 2, because there will be two values: 2Theta and Distance double fExposureTime = -1.0; for(int ii=0; ii < (int)m_aoScans.size(); ii++) { if( !bIsScanUsed(ii, eScanType) ) continue; nUsed++; nScanNumberForRecord = nUsed + nScanNumberOffset; oRotation.vSetRotStart((float)dGetScanRotBegin(ii, eScanType)); oRotation.vSetRotEnd((float)dGetScanRotEnd(ii, eScanType)); /////////////////////////////////////////////////////////////////////////////////////////////////////////// //Check if the the rotation limits have been set. If not, they will be both 0. m_aoScans[ii].vGetRotLimits(segRotLimits); if( !segRotLimits.bIsEmpty() ) oRotation.vSetRotMinMaxRange((float)segRotLimits.dGetBeg(), (float)segRotLimits.dGetEnd(), (float)segRotLimits.dGetWidth()); /////////////////////////////////////////////////////////////////////////////////////////////////////////// fExposureTime = m_aoScans[ii].fGetImageExposureTime(); if( fExposureTime > 0.0 ) oRotation.vSetExposureTime(fExposureTime); /////////////////////////////////////////////////////////////////////////////////////////////////////////// sScanPrefix = sBuildStrategyScanPrefix(sStrategyPrefix, D_K_ScanPrefix, nScanNumberForRecord); if( 0 != oRotation.nUpdateHeader(poHeader, sScanPrefix) ) continue; // Now update detector position if( bUpdateDetectorPosition ) { dDetRelZero[1] = dGetTwoTheta(); dDetRelZero[2] = dGetDistance(); poHeader->nReplaceValue(sScanPrefix + sScanDetRelZero, 3, dDetRelZero); } ///////////////////////////////////////////////////////////////////////// // Now update setting angles sScanCrystalPrefix = sBuildStrategyScanPrefix(sStrategyPrefix, D_K_CrystalPrefix, nScanNumberForRecord); for(int jj=0; jj < nNumAxes; jj++) { pdGonioValues[jj] = dGetScanAxisValue(ii, jj); } poHeader->nReplaceValue(sScanCrystalPrefix + D_K_GonioValues, nNumAxes, pdGonioValues); nScansUpdated++; } delete [] pdGonioValues; return nScansUpdated; }
void TransformationComponent::RotateAround( const Vec3& i_Axis, const real i_Angle ) { Quaternion oRotation(Ogre::Radian(Ogre::Degree(i_Angle).valueRadians()),i_Axis); SetRotation(oRotation * m_oOrientation); }