Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix leak in test_coregistration and attends various warnings #849

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions applications/mne_analyze/libs/anShared/Model/eventmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void EventModel::setSamplePos(int iSamplePos)
int EventModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_EventManager.getEventsInGroups(m_selectedEventGroups)->size();
return static_cast<int>(m_EventManager.getEventsInGroups(m_selectedEventGroups)->size());
}

//=============================================================================================================
Expand Down Expand Up @@ -628,7 +628,7 @@ std::unique_ptr<std::vector<EVENTSLIB::Event> > EventModel::getEventsToDisplay(i
void EventModel::eventsUpdated()
{
emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
emit headerDataChanged(Qt::Vertical, 0, m_EventManager.getAllEvents()->size());
emit headerDataChanged(Qt::Vertical, 0, static_cast<int>(m_EventManager.getAllEvents()->size()));
}

//=============================================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void CoRegistration::onFitFiducials()
Matrix3f matMri(digSetFidMRI.size(),3);
Matrix4f matTrans;
Vector3f vecWeights; // LPA, Nasion, RPA
float fScale = 0.0;
float fScale = 1.0f;

// get coordinates
for(int i = 0; i< digSetFidHead.size(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion examples/ex_averaging/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int main(int argc, char *argv[])
fTMin,
fTMax,
event,
-1.0f,
true,
-1.0f,
true,
mapReject,
Expand Down
2 changes: 1 addition & 1 deletion examples/ex_clustered_inverse_mne_raw/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ int main(int argc, char *argv[])
// Cluster forward solution;
//
MatrixXd D;
MNEForwardSolution t_clusteredFwd = t_Fwd.cluster_forward_solution(t_annotationSet, 20, D, noise_cov, evoked.info);
MNEForwardSolution t_clusteredFwd = t_Fwd.cluster_forward_solution(t_annotationSet, 20, D, noise_cov, evoked.info, "citiblock");

//
// make an inverse operators
Expand Down
2 changes: 1 addition & 1 deletion examples/ex_connectivity_comparison/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ int main(int argc, char *argv[])
lNetworks);

for(int j = 0; j < lNetworkTreeItems.size(); ++j) {
lNetworkTreeItems.at(j)->setThresholds(QVector3D(0.9,0.95,1.0));
lNetworkTreeItems.at(j)->setThresholds(QVector3D(0.9f, 0.95f, 1.0f));
}

//Read and show sensor helmets
Expand Down
3 changes: 3 additions & 0 deletions examples/ex_connectivity_performance/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ void customMessageHandler(QtMsgType type, const QMessageLogContext &context, con
*/
int main(int argc, char *argv[])
{
Q_UNUSED(argc);
Q_UNUSED(argv);

#ifdef STATICBUILD
Q_INIT_RESOURCE(disp3d);
#endif
Expand Down
4 changes: 2 additions & 2 deletions examples/ex_coreg/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int main(int argc, char *argv[])
Matrix3f matDst(digSetDst.size(),3);
Matrix4f matTrans;
Vector3f vecWeights(digSetSrc.size()); // LPA, Nasion, RPA
float fScale;
float fScale = 1.0f;

// get coordinates
for(int i = 0; i< digSetSrc.size(); ++i) {
Expand Down Expand Up @@ -227,7 +227,7 @@ int main(int argc, char *argv[])
AbstractView::SPtr p3DAbstractView = AbstractView::SPtr(new AbstractView());
Data3DTreeModel::SPtr p3DDataModel = p3DAbstractView->getTreeModel();
DigitizerSetTreeItem* pDigSrcSetTreeItem = p3DDataModel->addDigitizerData("Sample", "Fiducials Transformed", digSetSrc);
DigitizerSetTreeItem* pDigHspSetTreeItem = p3DDataModel->addDigitizerData("Sample", "Digitizer", digSetHsp);
// DigitizerSetTreeItem* pDigHspSetTreeItem = p3DDataModel->addDigitizerData("Sample", "Digitizer", digSetHsp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you want to visualise Digitizer date?

pDigSrcSetTreeItem->setTransform(transHeadMri,true);

BemTreeItem* pBemItem = p3DDataModel->addBemData("Sample", "Head", bemHead);
Expand Down
12 changes: 6 additions & 6 deletions examples/ex_roi_clustered_inverse_pwl_rap_music/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,12 @@ int main(int argc, char *argv[])

p3DDataModel->addSurfaceSet(parser.value(subjectOption), "HemiLRSet", t_surfSet, t_annotationSet);

MneDataTreeItem* pRTDataItem = p3DDataModel->addSourceData(parser.value(subjectOption),
"HemiLRSet",
sourceEstimate,
t_clusteredFwd,
t_surfSet,
t_annotationSet);
// MneDataTreeItem* pRTDataItem = p3DDataModel->addSourceData(parser.value(subjectOption),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you comment out this call, the 3D view will be empty

// "HemiLRSet",
// sourceEstimate,
// t_clusteredFwd,
// t_surfSet,
// t_annotationSet);

p3DAbstractView->show();

Expand Down
12 changes: 6 additions & 6 deletions examples/ex_st_clustered_inverse_pwl_rap_music/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,12 @@ int main(int argc, char *argv[])

p3DDataModel->addSurfaceSet(parser.value(subjectOption), "HemiLRSet", t_surfSet, t_annotationSet);

MneDataTreeItem* pRTDataItem = p3DDataModel->addSourceData(parser.value(subjectOption),
"HemiLRSet",
sourceEstimate,
t_clusteredFwd,
t_surfSet,
t_annotationSet);
p3DDataModel->addSourceData(parser.value(subjectOption),
"HemiLRSet",
sourceEstimate,
t_clusteredFwd,
t_surfSet,
t_annotationSet);

p3DAbstractView->show();

Expand Down
2 changes: 1 addition & 1 deletion libraries/disp3D/engine/view/view3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void View3D::initMultiView()

updateMultiViewAspectRatio();

auto noDraw = new Qt3DRender::QNoDraw(clearBuffers);
juangpc marked this conversation as resolved.
Show resolved Hide resolved
// auto noDraw = new Qt3DRender::QNoDraw(clearBuffers);
}

//=============================================================================================================
Expand Down
5 changes: 5 additions & 0 deletions libraries/inverse/hpiFit/hpifit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ void HPIFit::fitHPI(const MatrixXd& t_mat,
int iMaxIterations,
float fAbortError)
{
if(bDoDebug)
{
std::cout << "Debug mode ON\n";
}

//Check if data was passed
if(t_mat.rows() == 0 || t_mat.cols() == 0 ) {
std::cout<<std::endl<< "HPIFit::fitHPI - No data passed. Returning.";
Expand Down
1 change: 0 additions & 1 deletion libraries/mne/mne.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ bool MNE::read_events(QString t_sEventName,
{
QFile t_EventFile;
qint32 p;
bool status = false;

if (t_sEventName.isEmpty()) {
p = t_fileRawName.indexOf(".fif");
Expand Down
24 changes: 18 additions & 6 deletions libraries/mne/mne_forwardsolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ void MNEForwardSolution::clear()

//=============================================================================================================

MNEForwardSolution MNEForwardSolution::cluster_forward_solution(const AnnotationSet &p_AnnotationSet,
qint32 p_iClusterSize) const
{
const FIFFLIB::FiffCov p_pNoise_cov;
const FIFFLIB::FiffInfo p_pInfo;
Eigen::MatrixXd p_D;

return cluster_forward_solution(p_AnnotationSet, p_iClusterSize, p_D, p_pNoise_cov, p_pInfo, "cityblock");
}

//=============================================================================================================

MNEForwardSolution MNEForwardSolution::cluster_forward_solution(const AnnotationSet &p_AnnotationSet,
qint32 p_iClusterSize,
MatrixXd& p_D,
Expand Down Expand Up @@ -266,7 +278,7 @@ MNEForwardSolution MNEForwardSolution::cluster_forward_solution(const Annotation
if (label_ids[i] != 0)
{
QString curr_name = t_CurrentColorTable.struct_names[i];//obj.label2AtlasName(label(i));
printf("\tCluster %d / %ld %s...", i+1, label_ids.rows(), curr_name.toUtf8().constData());
printf("\tCluster %d / %ld %s...", i+1, static_cast<long int>(label_ids.rows()), curr_name.toUtf8().constData());

//
// Get source space indeces
Expand Down Expand Up @@ -875,7 +887,7 @@ FiffCov MNEForwardSolution::compute_depth_prior(const MatrixXd &Gain, const Fiff
}
}

printf("\tlimit = %d/%ld = %f", n_limit + 1, d.size(), sqrt(limit / ws[0]));
printf("\tlimit = %d/%ld = %f", n_limit + 1, static_cast<long int>(d.size()), sqrt(limit / ws[0]));
double scale = 1.0 / limit;
printf("\tscale = %g exp = %g", scale, exp);

Expand Down Expand Up @@ -1773,7 +1785,7 @@ void MNEForwardSolution::restrict_gain_matrix(MatrixXd &G, const FiffInfo &info)
// Figure out which ones have been used
if(info.chs.size() != G.rows())
{
printf("Error G.rows() and length of info.chs do not match: %ld != %i", G.rows(), info.chs.size()); //ToDo throw
printf("Error G.rows() and length of info.chs do not match: %ld != %i", static_cast<long int>(G.rows()), info.chs.size()); //ToDo throw
return;
}

Expand All @@ -1783,7 +1795,7 @@ void MNEForwardSolution::restrict_gain_matrix(MatrixXd &G, const FiffInfo &info)
for(qint32 i = 0; i < sel.size(); ++i)
G.row(i) = G.row(sel[i]);
G.conservativeResize(sel.size(), G.cols());
printf("\t%ld planar channels", sel.size());
printf("\t%ld planar channels", static_cast<long int>(sel.size()));
}
else
{
Expand All @@ -1793,7 +1805,7 @@ void MNEForwardSolution::restrict_gain_matrix(MatrixXd &G, const FiffInfo &info)
for(qint32 i = 0; i < sel.size(); ++i)
G.row(i) = G.row(sel[i]);
G.conservativeResize(sel.size(), G.cols());
printf("\t%ld magnetometer or axial gradiometer channels", sel.size());
printf("\t%ld magnetometer or axial gradiometer channels", static_cast<long int>(sel.size()));
}
else
{
Expand All @@ -1803,7 +1815,7 @@ void MNEForwardSolution::restrict_gain_matrix(MatrixXd &G, const FiffInfo &info)
for(qint32 i = 0; i < sel.size(); ++i)
G.row(i) = G.row(sel[i]);
G.conservativeResize(sel.size(), G.cols());
printf("\t%ld EEG channels\n", sel.size());
printf("\t%ld EEG channels\n", static_cast<long int>(sel.size()));
}
else
printf("Could not find MEG or EEG channels\n");
Expand Down
31 changes: 21 additions & 10 deletions libraries/mne/mne_forwardsolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ struct RegionData
}
};

const static FIFFLIB::FiffCov defaultCov;
const static FIFFLIB::FiffInfo defaultInfo;
static Eigen::MatrixXd defaultD;


//=============================================================================================================
/**
Expand Down Expand Up @@ -225,19 +223,32 @@ class MNESHARED_EXPORT MNEForwardSolution
*
* @param[in] p_AnnotationSet Annotation set containing the annotation of left & right hemisphere.
* @param[in] p_iClusterSize Maximal cluster size per roi.
* @param[out] p_D The cluster operator.
* @param[in] p_pNoise_cov.
* @param[in] p_pInfo.
* @param[out] p_D The cluster operator.
* @param[in] p_pNoise_cov
* @param[in] p_pInfo
* @param[in] p_sMethod "cityblock" or "sqeuclidean".
*
* @return clustered MNE forward solution.
*/
MNEForwardSolution cluster_forward_solution(const FSLIB::AnnotationSet &p_AnnotationSet,
qint32 p_iClusterSize,
Eigen::MatrixXd& p_D = defaultD,
const FIFFLIB::FiffCov &p_pNoise_cov = defaultCov,
const FIFFLIB::FiffInfo &p_pInfo = defaultInfo,
QString p_sMethod = "cityblock") const;
Eigen::MatrixXd& p_D,
const FIFFLIB::FiffCov &p_pNoise_cov,
const FIFFLIB::FiffInfo &p_pInfo,
QString p_sMethod) const;

//=========================================================================================================
/**
* Cluster the forward solution and stores the result to p_fwdOut.
* The clustering is done by using the provided annotations
*
* @param[in] p_AnnotationSet Annotation set containing the annotation of left & right hemisphere.
* @param[in] p_iClusterSize Maximal cluster size per roi.
*
* @return clustered MNE forward solution.
*/
MNEForwardSolution cluster_forward_solution(const FSLIB::AnnotationSet &p_AnnotationSet,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why creating a new function instead of leaving the old one with the default parameters? Do you maybe have a good reference if this is best practice? Or is it just a personal preference?

qint32 p_iClusterSize) const;

//=========================================================================================================
/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/mne/mne_inverse_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ MatrixXd MNEInverseOperator::cluster_kernel(const AnnotationSet &p_AnnotationSet
if (label_ids[i] != 0)
{
QString curr_name = t_CurrentColorTable.struct_names[i];//obj.label2AtlasName(label(i));
printf("\tCluster %d / %ld %s...", i+1, label_ids.rows(), curr_name.toUtf8().constData());
printf("\tCluster %d / %ld %s...", i+1, static_cast<long int>(label_ids.rows()), curr_name.toUtf8().constData());

//
// Get source space indeces
Expand Down
6 changes: 3 additions & 3 deletions libraries/rtprocessing/icp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ bool RTPROCESSINGLIB::performIcp(const MNEProjectToSurface::SPtr mneSurfacePoint

// Initialization
int iNP = matPointCloud.rows(); // The number of points
float fMSEPrev,fMSE = 0.0; // The mean square error
float fScale = 1.0;
float fMSEPrev = 0.0f; // The mean square error of previous iteration.
float fMSE = 0.0f; // The mean square error
float fScale = 1.0f;
MatrixXf matP0 = matPointCloud; // Initial Set of points
MatrixXf matPk = matP0; // Transformed Set of points
MatrixXf matYk(matPk.rows(),matPk.cols()); // Iterative closest points on the surface
Expand Down Expand Up @@ -175,7 +176,6 @@ bool RTPROCESSINGLIB::fitMatchedPoints(const MatrixXf& matSrcPoint,
Matrix3f matRot = Matrix3f::Identity(3,3);
Vector3f vecTrans;
float fTrace = 0.0;
fScale = 1.0;

// test size of point clouds
if(matSrcPoint.size() != matDstPoint.size()) {
Expand Down
6 changes: 2 additions & 4 deletions testframes/test_coregistration/test_coregistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ private slots:

private:
// declare your thresholds, variables and error values here
double dEpsilon;
FiffCoordTrans transFitMatched;
FiffCoordTrans transPerformICP;
FiffCoordTrans transFitMatchedRef;
Expand All @@ -107,7 +106,6 @@ private slots:
//=============================================================================================================

TestCoregistration::TestCoregistration()
: dEpsilon(0.000001)
{
}

Expand Down Expand Up @@ -149,7 +147,7 @@ void TestCoregistration::initTestCase()
Matrix3f matDst(digSetDst.size(),3);
Matrix4f matTrans;
Vector3f vecWeights(digSetSrc.size()); // LPA, Nasion, RPA
float fScale;
float fScale = 1.0f;
bool bScale = true;

// get coordinates
Expand All @@ -173,7 +171,7 @@ void TestCoregistration::initTestCase()
fiff_int_t iFrom = digSetSrc[0].coord_frame;
fiff_int_t iTo = bemSurface.data()->coord_frame;
transFitMatched = FiffCoordTrans::make(iFrom, iTo, matTrans);
transPerformICP = *new FiffCoordTrans(transFitMatched);
transPerformICP = FiffCoordTrans(transFitMatched);

// Prepare Icp:
VectorXf vecWeightsICP(digSetHsp.size()); // Weigths vector
Expand Down
2 changes: 1 addition & 1 deletion testframes/test_filtering/test_filtering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void TestFiltering::initTestCase()
fiff_int_t to = rawFirstInRaw.last_samp;

// initialize filter settings
QString sFilterName = "example_cosine";
// QString sFilterName = "example_cosine";
juangpc marked this conversation as resolved.
Show resolved Hide resolved
int type = FilterKernel::m_filterTypes.indexOf(FilterParameter("BPF"));
double dSFreq = rawFirstInRaw.info.sfreq;
double dCenterfreq = 10;
Expand Down
4 changes: 2 additions & 2 deletions testframes/test_geometryinfo/test_geometryinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void TestGeometryInfo::testBadChannelFiltering() {
return;
}
QVector<Vector3f> vMegSensors;
for( const FiffChInfo &info : evoked.info.chs) {
for( const FiffChInfo &info : qAsConst(evoked.info.chs)) {
juangpc marked this conversation as resolved.
Show resolved Hide resolved
if(info.kind == FIFFV_MEG_CH) {
vMegSensors.push_back(info.chpos.r0);
}
Expand All @@ -166,7 +166,7 @@ void TestGeometryInfo::testBadChannelFiltering() {
// filter for bad MEG channels:
QVector<int> vErasedColums = GeometryInfo::filterBadChannels(pDistanceMatrix, evoked.info, FIFFV_MEG_CH);

for (qint32 col : vErasedColums) {
for (qint32 col : qAsConst(vErasedColums)) {
qint64 iNotInfCount = 0;
for (qint32 row = 0; row < pDistanceMatrix->rows(); ++row) {
if (pDistanceMatrix->coeff(row, col) != FLOAT_INFINITY) {
Expand Down
6 changes: 4 additions & 2 deletions testframes/test_hpiFit/test_hpiFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ void TestHpiFit::initTestCase()
FiffDigPointSet fittedPointSet;
Eigen::MatrixXd mProjectors = Eigen::MatrixXd::Identity(pFiffInfo->chs.size(), pFiffInfo->chs.size());
QString sHPIResourceDir = QCoreApplication::applicationDirPath() + "/HPIFittingDebug";
bool bDoDebug = true;

HPIFit HPI = HPIFit(pFiffInfo, true);

Expand Down Expand Up @@ -212,6 +211,9 @@ void TestHpiFit::initTestCase()
}

qInfo() << "HPI-Fit...";

bool bDoDebug = false;

HPI.fitHPI(mData,
mProjectors,
pFiffInfo->dev_head_t,
Expand All @@ -220,7 +222,7 @@ void TestHpiFit::initTestCase()
vGoF,
fittedPointSet,
pFiffInfo,
bDoDebug = 0,
bDoDebug,
sHPIResourceDir,
200,
1e-5f);
Expand Down
2 changes: 1 addition & 1 deletion testframes/test_interpolation/test_interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void TestInterpolation::initTestCase()
if(evoked.isEmpty()) {
return;
}
for( const FiffChInfo &info : evoked.info.chs) {
for( const FiffChInfo &info : qAsConst(evoked.info.chs)) {
if(info.kind == FIFFV_MEG_CH && info.unit == FIFF_UNIT_T) {
vMegSensors.push_back(info.chpos.r0);
}
Expand Down
Loading