本文整理汇总了C++中Peak类的典型用法代码示例。如果您正苦于以下问题:C++ Peak类的具体用法?C++ Peak怎么用?C++ Peak使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Peak类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QMag
/**
* Returns selected information for a "peak" at QLabFrame.
*
* @param qFrame An arbitrary position in Q-space. This does not have to
*be the
* position of a peak.
* @param labCoords Set true if the position is in the lab coordinate system,
*false if
* it is in the sample coordinate system.
* @return a vector whose elements contain different information about the
*"peak" at that position.
* each element is a pair of description of information and the string
*form for the corresponding
* value.
*/
int PeaksWorkspace::peakInfoNumber(Kernel::V3D qFrame, bool labCoords) const {
std::vector<std::pair<std::string, std::string>> Result;
std::ostringstream oss;
oss << std::setw(12) << std::fixed << std::setprecision(3) << (qFrame.norm());
std::pair<std::string, std::string> QMag("|Q|", oss.str());
Result.push_back(QMag);
oss.str("");
oss.clear();
oss << std::setw(12) << std::fixed << std::setprecision(3)
<< (2.0 * M_PI / qFrame.norm());
std::pair<std::string, std::string> dspc("d-spacing", oss.str());
oss.str("");
oss.clear();
Result.push_back(dspc);
int seqNum = -1;
double minDist = 10000000;
for (int i = 0; i < getNumberPeaks(); i++) {
Peak pk = getPeak(i);
V3D Q = pk.getQLabFrame();
if (!labCoords)
Q = pk.getQSampleFrame();
double D = qFrame.distance(Q);
if (D < minDist) {
minDist = D;
seqNum = i + 1;
}
}
return seqNum;
}
示例2: TEST
TEST(Peak, Peak2D) {
vector<vector<int> > A = {
{10, 8, 10, 10},
{14, 13, 12, 11},
{15, 9, 11, 21},
{16, 17, 19, 20}
};
Peak peak;
pair<int, int> p = peak.find2d(A);
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int n = A.size();
int m = A[0].size();
bool test = true;
for (int i = 0; i < 4; i++) {
int r = p.first + dr[i];
int c = p.second + dc[i];
if (r >= 0 && r < n && c >= 0 && c < m) {
test &= A[p.first][p.second] >= A[r][c];
}
}
EXPECT_TRUE(test);
}
示例3: setLabel
int LuaPeak::setLabel(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
const char* str = "";
if( lua_gettop(L) > 1 )
str = luaL_checkstring( L, 2 );
obj->getOwner()->setTag( obj, str );
return 0;
}
示例4: getAssig
int LuaPeak::getAssig(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
const Peak::Assig& a = obj->getAssig();
{
for( int i = 0; i < obj->getDimCount(); i++ )
lua_pushnumber( L, a[ i ] );
}
return obj->getDimCount();
}
示例5: getAmp
int LuaPeak::getAmp(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
Spectrum* spec = 0;
if( lua_gettop( L ) > 1 )
{
spec = RefBinding<Spectrum>::cast( L, 2 );
}
lua_pushnumber(L, obj->getAmp( spec ) );
return 1;
}
示例6: lua_gettop
int LuaPeak::setAssig(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
const int n = lua_gettop(L); /* number of arguments */
if( n != ( obj->getDimCount() + 1 ) )
luaL_error( L, "Expecting %d arguments", int( obj->getDimCount() + 1 ) );
Peak::Assig a;
for( int i = 2; i <= n; i++ )
a[ i-1 ] = luaL_checknumber( L, i ); // TEST
obj->getOwner()->setAssig( obj, a );
return 0;
}
示例7: getPos
int LuaPeak::getPos(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
Spectrum* spec = 0;
if( lua_gettop( L ) > 1 )
{
spec = RefBinding<Spectrum>::cast( L, 2 );
}
const PeakPos& a = obj->getPos( spec );
for( int i = 0; i < obj->getDimCount(); i++ )
lua_pushnumber( L, a[ i ] );
return obj->getDimCount();
}
示例8: lua_newtable
int LuaPeak::getGuesses(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
const Peak::GuessMap& sm = obj->getGuesses();
Peak::GuessMap::const_iterator i;
lua_newtable( L );
int t = lua_gettop( L );
for( i = sm.begin(); i != sm.end(); ++i )
{
lua_pushnumber( L, (*i).first );
RefBinding<Peak::Guess>::create( L, (*i).second.deref() );
lua_rawset( L, t );
}
return 1;
}
示例9: setModel
int LuaPeak::setModel(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
const int n = lua_gettop(L); /* number of arguments */
int id = 0;
if( n > 1 )
id = luaL_checknumber( L, 2 );
Spectrum* spec = 0;
if( n > 2 )
{
spec = RefBinding<Spectrum>::cast( L, 3 );
}
obj->getOwner()->setModel( obj, id, spec );
return 0;
}
示例10: setAmp
int LuaPeak::setAmp(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
int n = lua_gettop(L); /* number of arguments */
Amplitude a = 0;
if( n > 1 )
a = luaL_checknumber( L, 2 );
Spectrum* spec = 0;
if( n > 2 )
{
spec = RefBinding<Spectrum>::cast( L, 3 );
}
obj->getOwner()->setAmp( obj, a, spec );
return 0;
}
示例11: setPos
int LuaPeak::setPos(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
const int n = lua_gettop(L); /* number of arguments */
const int dim = obj->getDimCount();
if( n < dim + 1 )
luaL_error( L, "Expecting at least %d arguments", dim );
PpmPoint a;
for( int i = 1; i <= dim; i++ )
a.push_back( luaL_checknumber( L, i + 1 ) );
Spectrum* spec = 0;
if( n > ( dim + 1 ) )
{
spec = RefBinding<Spectrum>::cast( L, n );
}
obj->getOwner()->setPos( obj, a, spec );
return 0;
}
示例12: operator
/** Compare two peaks using the stored criteria */
inline bool operator()(const Peak& a, const Peak& b)
{
for (size_t i = 0; i < criteria.size(); i++)
{
std::string & col = criteria[i].first;
bool ascending = criteria[i].second;
bool lessThan = false;
if (col == "BankName")
{
// If this criterion is equal, move on to the next one
std::string valA = a.getBankName();
std::string valB = b.getBankName();
// Move on to lesser criterion if equal
if (valA == valB)
continue;
lessThan = (valA < valB);
}
else
{
// General double comparison
double valA = a.getValueByColName(col);
double valB = b.getValueByColName(col);
// Move on to lesser criterion if equal
if (valA == valB)
continue;
lessThan = (valA < valB);
}
// Flip the sign of comparison if descending.
if (ascending)
return lessThan;
else
return !lessThan;
}
// If you reach here, all criteria were ==; so not <, so return false
return false;
}
示例13: getNewInstrument
void PeakHKLErrors::functionDeriv1D(Jacobian *out, const double *xValues,
const size_t nData) {
PeaksWorkspace_sptr Peaks =
AnalysisDataService::Instance().retrieveWS<PeaksWorkspace>(
PeakWorkspaceName);
boost::shared_ptr<Geometry::Instrument> instNew = getNewInstrument(Peaks);
const DblMatrix &UB = Peaks->sample().getOrientedLattice().getUB();
DblMatrix UBinv(UB);
UBinv.Invert();
UBinv /= 2 * M_PI;
double GonRotx = getParameter("GonRotx");
double GonRoty = getParameter("GonRoty");
double GonRotz = getParameter("GonRotz");
Matrix<double> InvGonRotxMat = RotationMatrixAboutRegAxis(GonRotx, 'x');
Matrix<double> InvGonRotyMat = RotationMatrixAboutRegAxis(GonRoty, 'y');
Matrix<double> InvGonRotzMat = RotationMatrixAboutRegAxis(GonRotz, 'z');
Matrix<double> GonRot = InvGonRotxMat * InvGonRotyMat * InvGonRotzMat;
InvGonRotxMat.Invert();
InvGonRotyMat.Invert();
InvGonRotzMat.Invert();
std::map<int, Kernel::Matrix<double>> RunNums2GonMatrix;
getRun2MatMap(Peaks, OptRuns, RunNums2GonMatrix);
g_log.debug()
<< "----------------------------Derivative------------------------\n";
V3D samplePosition = instNew->getSample()->getPos();
IPeak &ppeak = Peaks->getPeak(0);
double L0 = ppeak.getL1();
double velocity = (L0 + ppeak.getL2()) / ppeak.getTOF();
double K =
2 * M_PI / ppeak.getWavelength() / velocity; // 2pi/lambda = K* velocity
V3D beamDir = instNew->getBeamDirection();
size_t paramNums[] = {parameterIndex(std::string("SampleXOffset")),
parameterIndex(std::string("SampleYOffset")),
parameterIndex(std::string("SampleZOffset"))};
for (size_t i = 0; i < nData; i += 3) {
int peakNum = boost::math::iround(xValues[i]);
IPeak &peak_old = Peaks->getPeak(peakNum);
Peak peak = createNewPeak(peak_old, instNew, 0, peak_old.getL1());
int runNum = peak_old.getRunNumber();
std::string runNumStr = std::to_string(runNum);
for (int kk = 0; kk < static_cast<int>(nParams()); kk++) {
out->set(i, kk, 0.0);
out->set(i + 1, kk, 0.0);
out->set(i + 2, kk, 0.0);
}
double chi, phi, omega;
size_t chiParamNum, phiParamNum, omegaParamNum;
size_t N = OptRuns.find("/" + runNumStr);
if (N < OptRuns.size()) {
chi = getParameter("chi" + (runNumStr));
phi = getParameter("phi" + (runNumStr));
omega = getParameter("omega" + (runNumStr));
peak.setGoniometerMatrix(GonRot * RunNums2GonMatrix[runNum]);
chiParamNum = parameterIndex("chi" + (runNumStr));
phiParamNum = parameterIndex("phi" + (runNumStr));
omegaParamNum = parameterIndex("omega" + (runNumStr));
} else {
Geometry::Goniometer Gon(peak.getGoniometerMatrix());
std::vector<double> phichiOmega = Gon.getEulerAngles("YZY");
chi = phichiOmega[1];
phi = phichiOmega[2];
omega = phichiOmega[0];
// peak.setGoniometerMatrix( GonRot*Gon.getR());
chiParamNum = phiParamNum = omegaParamNum = nParams() + 10;
peak.setGoniometerMatrix(GonRot * peak.getGoniometerMatrix());
}
V3D sampOffsets(getParameter("SampleXOffset"),
getParameter("SampleYOffset"),
getParameter("SampleZOffset"));
peak.setSamplePos(peak.getSamplePos() + sampOffsets);
// NOTE:Use getQLabFrame except for below.
// For parameters the getGoniometerMatrix should remove GonRot, for derivs
// wrt GonRot*, wrt chi*,phi*,etc.
// Deriv wrt chi phi and omega
if (phiParamNum < nParams()) {
Matrix<double> chiMatrix = RotationMatrixAboutRegAxis(chi, 'z');
Matrix<double> phiMatrix = RotationMatrixAboutRegAxis(phi, 'y');
Matrix<double> omegaMatrix = RotationMatrixAboutRegAxis(omega, 'y');
Matrix<double> dchiMatrix = DerivRotationMatrixAboutRegAxis(chi, 'z');
Matrix<double> dphiMatrix = DerivRotationMatrixAboutRegAxis(phi, 'y');
Matrix<double> domegaMatrix = DerivRotationMatrixAboutRegAxis(omega, 'y');
//.........这里部分代码省略.........
示例14: setColor
int LuaPeak::setColor(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
obj->getOwner()->setColor( obj, luaL_checknumber( L, 2 ) );
return 0;
}
示例15: getLabel
int LuaPeak::getLabel(lua_State *L)
{
Peak* obj = RefBinding<Peak>::check( L, 1);
lua_pushstring(L, obj->getTag().data() );
return 1;
}