/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
}
-void
-Trajectory::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc * /* pbc */,
- TrajectoryAnalysisModuleData *pdata)
+//! Helper function for Trajectory::analyzeFrame
+template<typename T> void
+analyzeFrameImpl(int frnr, const t_trxframe &fr,
+ AnalysisDataHandle* dh, const SelectionList &sel, T getField)
{
- const SelectionList &sel = pdata->parallelSelections(sel_);
-
- // There is some duplication here, but cppcheck cannot handle function
- // types that return rvec references, and MSVC also apparently segfaults
- // when using std::function with a member function here...
+ if (dh->isValid())
{
- AnalysisDataHandle dh = pdata->dataHandle(xdata_);
- if (dh.isValid())
+ dh->startFrame(frnr, fr.time);
+ for (size_t g = 0; g < sel.size(); ++g)
{
- dh.startFrame(frnr, fr.time);
- for (size_t g = 0; g < sel.size(); ++g)
+ dh->selectDataSet(g);
+ for (int i = 0; i < sel[g].posCount(); ++i)
{
- dh.selectDataSet(g);
- for (int i = 0; i < sel[g].posCount(); ++i)
- {
- const SelectionPosition &pos = sel[g].position(i);
- dh.setPoints(i*3, 3, pos.x(), pos.selected());
- }
+ const SelectionPosition &pos = sel[g].position(i);
+ dh->setPoints(i*3, 3, getField(pos), pos.selected());
}
- dh.finishFrame();
}
+ dh->finishFrame();
}
+}
+
+void
+Trajectory::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc * /* pbc */,
+ TrajectoryAnalysisModuleData *pdata)
+{
+ AnalysisDataHandle dh = pdata->dataHandle(xdata_);
+ const SelectionList &sel = pdata->parallelSelections(sel_);
+ analyzeFrameImpl(frnr, fr, &dh, sel, [](const SelectionPosition &pos) { return pos.x(); });
if (fr.bV)
{
- AnalysisDataHandle dh = pdata->dataHandle(xdata_);
- if (dh.isValid())
- {
- dh.startFrame(frnr, fr.time);
- for (size_t g = 0; g < sel.size(); ++g)
- {
- dh.selectDataSet(g);
- for (int i = 0; i < sel[g].posCount(); ++i)
- {
- const SelectionPosition &pos = sel[g].position(i);
- dh.setPoints(i*3, 3, pos.v(), pos.selected());
- }
- }
- dh.finishFrame();
- }
+ analyzeFrameImpl(frnr, fr, &dh, sel, [](const SelectionPosition &pos) { return pos.v(); });
}
if (fr.bF)
{
- AnalysisDataHandle dh = pdata->dataHandle(xdata_);
- if (dh.isValid())
- {
- dh.startFrame(frnr, fr.time);
- for (size_t g = 0; g < sel.size(); ++g)
- {
- dh.selectDataSet(g);
- for (int i = 0; i < sel[g].posCount(); ++i)
- {
- const SelectionPosition &pos = sel[g].position(i);
- dh.setPoints(i*3, 3, pos.f(), pos.selected());
- }
- }
- dh.finishFrame();
- }
+ analyzeFrameImpl(frnr, fr, &dh, sel, [](const SelectionPosition &pos) { return pos.f(); });
}
+
}