Skip to content

Commit dd78b2a

Browse files
committed
Merge branch 'feature/FI/overlappingScars' into development
2 parents e50a0fe + e694fae commit dd78b2a

4 files changed

Lines changed: 123 additions & 155 deletions

File tree

Version2.0/Modules/CemrgAppModule/include/CemrgScarAdvanced.h

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,12 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgScarAdvanced {
101101
std::string _prefix;
102102
std::string _leftrightpre;
103103

104-
double fandi1_largestSurfaceArea;
105-
double fandi1_scarScore;
106-
double fandi2_percentage;
107-
double fandi2_largestSurfaceArea;
108-
double fandi2_corridorSurfaceArea;
109-
int fandi2_connectedAreasTotal;
110-
double fandi3_preSurfacePercentage;
111-
double fandi3_postSurfacePercentage;
112-
double fandi3_preScarScore;
113-
double fandi3_postScarScore;
114-
std::string fandi1_fname, fandi2_fname, fandi3_fname;
104+
double fi1_largestSurfaceArea, fi1_scarScore;
105+
double fi2_percentage, fi2_largestSurfaceArea, fi2_corridorSurfaceArea;
106+
int fi2_connectedAreasTotal;
107+
double fi3_preScarScoreSimple, fi3_postScarScoreSimple;
108+
double fi3_totalPoints, fi3_emptyPoints, fi3_healthy, fi3_preScar, fi3_postScar, fi3_overlapScar;
109+
std::string fi1_fname, fi2_fname, fi3_fname;
115110

116111
std::vector<std::pair<int, int> > _visited_point_list; // stores the neighbours around a point
117112
std::vector<vtkSmartPointer<vtkPolyData> > _paths; // container to store shortest paths between points
@@ -133,8 +128,8 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgScarAdvanced {
133128
inline bool IsDebug(){return _debugScarAdvanced;};
134129

135130
inline bool IsWeighted() {return _weightedcorridor;};
136-
inline bool PreScoresExist(){return (fandi3_preSurfacePercentage>=0 && fandi3_preScarScore>=0);};
137-
inline bool PostScoresExist(){return (fandi3_postSurfacePercentage>=0 && fandi3_postScarScore>=0);};
131+
inline bool PreScoresExist(){return (fi3_preScarScoreSimple>=0);};
132+
inline bool PostScoresExist(){return (fi3_postScarScoreSimple>=0);};
138133
inline int GetThresholdValue(){return _fill_threshold;};
139134
inline vtkSmartPointer<vtkPolyData> GetSourcePolyData(){return _SourcePolyData;};
140135

@@ -158,14 +153,14 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgScarAdvanced {
158153
inline void SetLeftRightPrefix(std::string lrpre){_leftrightpre = lrpre;};
159154
inline void SetOutputPrefix(std::string prefixname){_prefix = _leftrightpre + prefixname;};
160155

161-
inline void SetSurfaceAreaFilename(std::string fn1){fandi1_fname = fn1;};
162-
inline void SetGapsFilename(std::string fn2){fandi2_fname = fn2;};
163-
inline void SetComparisonFilename(std::string fn3){fandi3_fname = fn3;};
156+
inline void SetSurfaceAreaFilename(std::string fn1){fi1_fname = fn1;};
157+
inline void SetGapsFilename(std::string fn2){fi2_fname = fn2;};
158+
inline void SetComparisonFilename(std::string fn3){fi3_fname = fn3;};
164159

165160
inline std::string GetOutputPath(){return _outPath;};
166-
inline std::string GetSurfaceAreaFilename(){return fandi1_fname;};
167-
inline std::string GetGapsFilename(){return fandi2_fname;};
168-
inline std::string GetComparisonFilename(){return fandi3_fname;};
161+
inline std::string GetSurfaceAreaFilename(){return fi1_fname;};
162+
inline std::string GetGapsFilename(){return fi2_fname;};
163+
inline std::string GetComparisonFilename(){return fi3_fname;};
169164
inline std::string GetPrefix() {return (_leftrightpre + _prefix);};
170165
inline std::string PathAndPrefix() {return (GetOutputPath()+ GetPrefix());};
171166

@@ -184,7 +179,7 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgScarAdvanced {
184179
std::string PrintAblationGapsResults(double mean, double stdv, double val);
185180
std::string PrintThresholdResults(double mean, double stdv, double val);
186181
std::string PrintScarOverlapResults(double valpre, double valpost);
187-
std::string num2str(double num, int precision);
182+
std::string num2str(double num, int precision=2);
188183

189184
// F&I T1
190185
//void GetSurfaceAreaFromThreshold();
@@ -198,7 +193,7 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgScarAdvanced {
198193
void GetNeighboursAroundPoint2(int pointID, std::vector<std::pair<int, int>>& pointNeighbourAndOrder, int max_order);
199194
void getCorridorPoints(std::vector<vtkSmartPointer<vtkDijkstraGraphGeodesicPath>> allShortestPaths);
200195
bool InsertPointIntoVisitedList2(vtkIdType id, int order);
201-
void CorridorFromPointList(std::vector<int> points);
196+
void CorridorFromPointList(std::vector<int> points, bool circleToStart=true);
202197

203198
// F&I T3
204199
void SetSourceAndTarget(vtkSmartPointer<vtkPolyData> sc, vtkSmartPointer<vtkPolyData> tg);

Version2.0/Modules/CemrgAppModule/src/CemrgScarAdvanced.cpp

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,19 @@ CemrgScarAdvanced::CemrgScarAdvanced() {
7777
_fill_threshold = 0.5;
7878
_max_scalar = -1;
7979
_run_count = 0;
80-
fandi1_largestSurfaceArea=-1;
81-
fandi2_percentage=-1;
82-
fandi2_largestSurfaceArea=-1;
83-
fandi2_corridorSurfaceArea=-1;
84-
fandi2_connectedAreasTotal=-1;
85-
fandi3_preSurfacePercentage=-1;
86-
fandi3_postSurfacePercentage=-1;
87-
fandi3_preScarScore=-1;
88-
fandi3_postScarScore=-1;
80+
fi1_largestSurfaceArea=-1;
81+
fi2_percentage=-1;
82+
fi2_largestSurfaceArea=-1;
83+
fi2_corridorSurfaceArea=-1;
84+
fi2_connectedAreasTotal=-1;
85+
fi3_preScarScoreSimple=-1;
86+
fi3_postScarScoreSimple=-1;
87+
fi3_totalPoints=-1;
88+
fi3_emptyPoints=-1;
89+
fi3_healthy = -1;
90+
fi3_preScar = -1;
91+
fi3_postScar = -1;
92+
fi3_overlapScar = -1;
8993
_debugScarAdvanced = false;
9094
}
9195

@@ -158,12 +162,34 @@ std::string CemrgScarAdvanced::ScarOverlap(
158162
temp->DeepCopy(prepd);
159163

160164
int valueassigned = 0;
165+
fi3_totalPoints = (double) prepd->GetNumberOfPoints();
166+
fi3_emptyPoints=0.0;
167+
fi3_healthy=0.0;
168+
fi3_preScar=0.0;
169+
fi3_postScar=0.0;
170+
fi3_overlapScar=0.0;
161171
for (int i=0;i<prepd->GetNumberOfPoints();i++) {
162-
if (scalars_pre->GetTuple1(i)>=prethresh)
163-
valueassigned +=1;
172+
if(scalars_post->GetTuple1(i)==0){ // Veins were clipped here, no value
173+
valueassigned=-1;
174+
fi3_emptyPoints++;
175+
} else{
176+
if (scalars_pre->GetTuple1(i)>=prethresh){
177+
valueassigned +=1;
178+
}
179+
if (scalars_post->GetTuple1(i)>=postthresh){
180+
valueassigned +=2;
181+
}
164182

165-
if (scalars_post->GetTuple1(i)>=postthresh)
166-
valueassigned +=2;
183+
if(valueassigned==0){
184+
fi3_healthy++;
185+
} else if(valueassigned==1){
186+
fi3_preScar++;
187+
} else if(valueassigned==2){
188+
fi3_postScar++;
189+
} else if(valueassigned==3){
190+
fi3_overlapScar++;
191+
}
192+
}
167193

168194
exploration_values->InsertNextTuple1(valueassigned);
169195
valueassigned = 0;
@@ -205,8 +231,8 @@ std::string CemrgScarAdvanced::PrintThresholdResults(double mean, double stdv, d
205231
"\t STDev: " + num2str(stdv, 2) +
206232
"\n\n Value chosen: " + num2str(val,1) + "\n"
207233
"Threshold value: " + num2str(this->_fill_threshold,2) + "\n\n" +
208-
"Surface Area of Ablation: " + num2str(this->fandi1_largestSurfaceArea,2) + " mm^2 \n" +
209-
"Scar Score: " + num2str(this->fandi1_scarScore,2) + "%";
234+
"Surface Area of Ablation: " + num2str(this->fi1_largestSurfaceArea,2) + " mm^2 \n" +
235+
"Scar Score: " + num2str(this->fi1_scarScore,2) + "%";
210236

211237
SaveStrToFile(GetOutputPath(), _prefix + "_"+ GetSurfaceAreaFilename(), out);
212238

@@ -220,10 +246,10 @@ std::string CemrgScarAdvanced::PrintAblationGapsResults(double mean, double stdv
220246
"\t STDev: " + num2str(stdv, 2) +
221247
"\n\n Value chosen: " + num2str(val,1) + "\n"
222248
"Threshold value: " + num2str(this->_fill_threshold,2) + "\n\n" +
223-
"Num connected sections: " + num2str(this->fandi2_connectedAreasTotal,0) + "\n" +
224-
"Percentage of scar in corridor : " + num2str(this->fandi2_percentage,2) + "%\t\n" +
225-
"Largest thresholded area in corridor: " + num2str(this->fandi2_largestSurfaceArea,0) + "mm^2 \n" +
226-
"Area of corridor: " + num2str(this->fandi2_corridorSurfaceArea,0) + " mm^2 \n" ;
249+
"Num connected sections: " + num2str(this->fi2_connectedAreasTotal,0) + "\n" +
250+
"Percentage of scar in corridor : " + num2str(this->fi2_percentage,2) + "%\t\n" +
251+
"Largest thresholded area in corridor: " + num2str(this->fi2_largestSurfaceArea,0) + "mm^2 \n" +
252+
"Area of corridor: " + num2str(this->fi2_corridorSurfaceArea,0) + " mm^2 \n" ;
227253
std::string strisweighted = (_weightedcorridor) ? "Weighted path" : "Geodesic";
228254
out = out + "\nShortest path calculation: " + strisweighted + "\n";
229255

@@ -233,24 +259,31 @@ std::string CemrgScarAdvanced::PrintAblationGapsResults(double mean, double stdv
233259
}
234260
std::string CemrgScarAdvanced::PrintScarOverlapResults(double valpre, double valpost) {
235261

236-
double ros = this->fandi3_preScarScore / this->fandi3_postScarScore;
237-
std::string out = "RESULTS:\n\n Scar Score in PRE-ablation: ";
262+
std::string out = "RESULTS:\n\n Simple Scar Score in PRE-ablation: ";
238263
if (valpre != valpost) {
239-
out += num2str(this->fandi3_preScarScore,2) + "% \t(" +
264+
out += num2str(this->fi3_preScarScoreSimple,2) + "% \t(" +
240265
"Threshold value: " + num2str(valpre,1) + ")\n" +
241-
"Scar Score in POST-ablation: " +
242-
num2str(this->fandi3_postScarScore,2) + "% \t(" +
266+
"Simple Scar Score in POST-ablation: " +
267+
num2str(this->fi3_postScarScoreSimple,2) + "% \t(" +
243268
"Threshold value: " + num2str(valpost,1) + ")\n\n";
244269
} else {
245-
out += num2str(this->fandi3_preScarScore,2) + "% \n" +
246-
"Scar Score in POST-ablation: " +
247-
num2str(this->fandi3_postScarScore,2) + "% \n " +
270+
out += num2str(this->fi3_preScarScoreSimple,2) + "% \n" +
271+
"Simple Scar Score in POST-ablation: " +
272+
num2str(this->fi3_postScarScoreSimple,2) + "% \n " +
248273
"(Both at threshold value: " + num2str(valpre,1) +")" + "\n\n";
249274
}
250-
out += "Percentage of PRE scar in POST scar: " + num2str(ros*100,3) + "%\n";
251275

276+
double total = fi3_totalPoints - fi3_emptyPoints;
277+
if(total>0){
278+
out += "\nOVERLAP RESULTS:\n\nHEALTHY % : " +
279+
num2str(100*(fi3_healthy/total)) +
280+
"\nPRE-SCAR % : " + num2str(100*(fi3_preScar/total)) +
281+
"\nPOST-SCAR %: " + num2str(100*(fi3_postScar/total)) +
282+
"\nOVERLAP % : " + num2str(100*(fi3_overlapScar/total));
283+
} else{
284+
MITK_WARN << ("Points: " + QString::number(total)).toStdString();
285+
}
252286
SaveStrToFile(GetOutputPath(), GetComparisonFilename(), out);
253-
254287
return out;
255288
}
256289

@@ -290,12 +323,8 @@ void CemrgScarAdvanced::GetSurfaceAreaFromThreshold(double thres, double maxscal
290323
MITK_INFO << "MASS PROPERTIES (threshold):";
291324
MITK_INFO << mp->GetSurfaceArea();
292325

293-
this->fandi1_largestSurfaceArea = mp->GetSurfaceArea();
326+
this->fi1_largestSurfaceArea = mp->GetSurfaceArea();
294327

295-
if (QString::fromStdString(_prefix).compare("pre", Qt::CaseInsensitive)==0)
296-
this->fandi3_preSurfacePercentage = mp->GetSurfaceArea();
297-
else
298-
this->fandi3_postSurfacePercentage = mp->GetSurfaceArea();
299328
}
300329

301330
void CemrgScarAdvanced::ScarScore(double thres) {
@@ -315,14 +344,14 @@ void CemrgScarAdvanced::ScarScore(double thres) {
315344
}
316345
double percentage = (ctr2*100.0) / (scalars->GetNumberOfTuples() - ctr1);
317346

318-
fandi1_scarScore = percentage;
347+
fi1_scarScore = percentage;
319348

320349
if (QString::fromStdString(_prefix).compare("pre", Qt::CaseInsensitive)==0) {
321-
this->fandi3_preScarScore = percentage;
350+
this->fi3_preScarScoreSimple = percentage;
322351
MITK_INFO << "PRE SCAR SCORE (" + _prefix + "): " + num2str(percentage,2);
323352
}
324353
else {
325-
this->fandi3_postScarScore = percentage;
354+
this->fi3_postScarScoreSimple = percentage;
326355
MITK_INFO << "POST SCAR SCORE (" + _prefix + "): " + num2str(percentage,2);
327356
}
328357
}
@@ -464,7 +493,7 @@ void CemrgScarAdvanced::ExtractCorridorData(
464493
MITK_INFO << connectivityFilter->GetNumberOfExtractedRegions();
465494
connectivityFilter->SetExtractionModeToLargestRegion();
466495
connectivityFilter->Update();
467-
fandi2_connectedAreasTotal = connectivityFilter->GetNumberOfExtractedRegions();
496+
fi2_connectedAreasTotal = connectivityFilter->GetNumberOfExtractedRegions();
468497

469498
vtkSmartPointer<vtkPolyDataConnectivityFilter> cf =
470499
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
@@ -490,13 +519,13 @@ void CemrgScarAdvanced::ExtractCorridorData(
490519
mp->SetInputConnection(cf->GetOutputPort());
491520
MITK_INFO << "SURFACE AREA IN CORRIDOR (threshold):";
492521
MITK_INFO << mp->GetSurfaceArea();
493-
fandi2_largestSurfaceArea = mp->GetSurfaceArea();
522+
fi2_largestSurfaceArea = mp->GetSurfaceArea();
494523

495524
vtkSmartPointer<vtkMassProperties> mp2 = vtkSmartPointer<vtkMassProperties>::New();
496525
mp2->SetInputConnection(cf2->GetOutputPort());
497526
MITK_INFO << "SURFACE AREA IN CORRIDOR (full):";
498527
MITK_INFO << mp2->GetSurfaceArea();
499-
fandi2_corridorSurfaceArea = mp2->GetSurfaceArea();
528+
fi2_corridorSurfaceArea = mp2->GetSurfaceArea();
500529

501530
vtkSmartPointer<vtkPolyDataWriter> writercf =
502531
vtkSmartPointer<vtkPolyDataWriter>::New();
@@ -524,7 +553,7 @@ void CemrgScarAdvanced::NeighbourhoodFillingPercentage(std::vector<int> points)
524553
}
525554

526555
double percentage_in_neighbourhood = 100*(fillingcounter/total);
527-
this->fandi2_percentage = percentage_in_neighbourhood;
556+
this->fi2_percentage = percentage_in_neighbourhood;
528557
MITK_INFO << ("[INFO] % scar in this neighbourhood = "
529558
+ QString::number(percentage_in_neighbourhood) + ", threshold satisfy? "
530559
+ (percentage_in_neighbourhood > _neighbourhood_size ? "Yes":"No")).toStdString();
@@ -643,7 +672,7 @@ void CemrgScarAdvanced::getCorridorPoints(
643672
this->_corridoridarray = pointIDsInCorridor;
644673
}
645674

646-
void CemrgScarAdvanced::CorridorFromPointList(std::vector<int> points) {
675+
void CemrgScarAdvanced::CorridorFromPointList(std::vector<int> points, bool circleToStart) {
647676

648677
vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New();
649678
poly_data = this->GetSourcePolyData();
@@ -654,16 +683,17 @@ void CemrgScarAdvanced::CorridorFromPointList(std::vector<int> points) {
654683
vtkSmartPointer<vtkDijkstraGraphGeodesicPath> dijkstra = vtkSmartPointer<vtkDijkstraGraphGeodesicPath>::New();
655684
dijkstra->SetInputData(poly_data);
656685

657-
if (this->IsWeighted())
686+
if (this->IsWeighted()){
658687
dijkstra->UseScalarWeightsOn();
688+
}
659689

660690
dijkstra->Update();
661691

662692
if (i<lim-1) {
663693
dijkstra->SetStartVertex(this->_pointidarray[i]);
664694
dijkstra->SetEndVertex(this->_pointidarray[i+1]);
665695
}
666-
else {
696+
else if(circleToStart){
667697
dijkstra->SetStartVertex(this->_pointidarray[i]);
668698
dijkstra->SetEndVertex(this->_pointidarray[0]);
669699
}

0 commit comments

Comments
 (0)