Fraxinus  18.10
An IGT application
MethodTests.cpp
Go to the documentation of this file.
1 
9 #include <vector>
10 #include <vtkSmartPointer.h>
11 #include "AngleCorrection.h"
12 #include <vtkPolyDataWriter.h>
13 #include <vtkPolyDataReader.h>
14 #include <vtkPolyData.h>
15 #include <vtkPointData.h>
16 #include <cstdio>
17 #include <time.h>
18 
19 #include "catch.hpp"
20 
21 
22 using namespace std;
23 
24 
25 char * appendTestFolder(const char * filename){
26  char anglecorrection_test_data_dir[]=ANGLECORRECTION_TEST_DATA_DIR;
27  char * newArray = new char[std::strlen(anglecorrection_test_data_dir)+std::strlen(filename)+1];
28  std::strcpy(newArray,anglecorrection_test_data_dir);
29  std::strcat(newArray,filename);
30 
31  return newArray;
32 }
33 
34 
35 void validateVtkPD(vtkSmartPointer<vtkPolyData> leftHandSide,vtkSmartPointer<vtkPolyData> rightHandSide, bool shouldBeEqual = true){
36  unsigned int numberOfPointsRight = rightHandSide->GetNumberOfPoints();
37  unsigned int numberOfPointsLeft = leftHandSide->GetNumberOfPoints();
38  if(shouldBeEqual){
39  REQUIRE(numberOfPointsLeft==numberOfPointsRight);
40  }
41  if(!shouldBeEqual && numberOfPointsLeft!=numberOfPointsRight){
42  return;
43  }
44 
45  bool all_equal = true;
46  double pointOne[3];
47  double pointTwo[3];
48  for( unsigned int i( 0 ); i < numberOfPointsRight; i++ )
49  {
50  rightHandSide->GetPoint(i, pointOne);
51  leftHandSide->GetPoint(i, pointTwo);
52 
53  double x = pointOne[0] - pointTwo[0];
54  double y = pointOne[1] - pointTwo[1];
55  double z = pointOne[2] - pointTwo[2];
56  double distance = x*x + y*y + z*z;
57  if( distance > 0.001 ) all_equal=false;
58  }
59 
60  unsigned int numberOfArraysRight = rightHandSide->GetPointData()->GetNumberOfArrays();
61  unsigned int numberOfArraysLeft = leftHandSide->GetPointData()->GetNumberOfArrays();
62  if(shouldBeEqual){
63  REQUIRE(numberOfArraysLeft==numberOfArraysRight);
64  }
65  if(!shouldBeEqual && numberOfArraysLeft!=numberOfArraysRight){
66  return;
67  }
68 
69 
70  double pointRight;
71  double pointLeft;
72  for(int k=0; k < numberOfArraysRight; k++)
73  {
74  unsigned int numberRight = rightHandSide->GetPointData()->GetArray(k)->GetDataSize()/ rightHandSide->GetPointData()->GetArray(k)->GetNumberOfComponents();
75  unsigned int numberLeft = leftHandSide->GetPointData()->GetArray(k)->GetDataSize()/ leftHandSide->GetPointData()->GetArray(k)->GetNumberOfComponents();
76  if(shouldBeEqual){
77  REQUIRE(numberLeft==numberRight);
78  }
79  if(!shouldBeEqual && numberLeft!=numberRight){
80  return;
81  }
82 
83 
84  for(int m=0; m < rightHandSide->GetPointData()->GetArray(k)->GetNumberOfComponents() ; m++){
85  for(int l=0; l < numberRight ; l++){
86  pointRight= rightHandSide->GetPointData()->GetArray(k)->GetComponent(l,m);
87  pointLeft= leftHandSide->GetPointData()->GetArray(k)->GetComponent(l,m);
88  if( abs(pointRight-pointLeft) > 0.001 ) all_equal=false;
89  }
90  }
91  }
92  REQUIRE(all_equal== shouldBeEqual);
93 }
94 
95 void validateFiles(const char* filename_a,const char* filename_b, bool shouldBeEqual = true){
96  vtkSmartPointer<ErrorObserver> errorObserver = vtkSmartPointer<ErrorObserver>::New();
97 
98  vtkSmartPointer<vtkPolyDataReader> reader2 = vtkSmartPointer<vtkPolyDataReader>::New();
99  reader2->AddObserver(vtkCommand::ErrorEvent,errorObserver);
100  reader2->SetFileName(filename_b);
101  reader2->Update();
102 
103  vtkSmartPointer<vtkPolyDataReader> reader1 = vtkSmartPointer<vtkPolyDataReader>::New();
104  reader1->AddObserver(vtkCommand::ErrorEvent,errorObserver);
105  reader1->SetFileName(filename_a);
106  reader1->Update();
107 
108  bool readFilesSuccesfully = true;
109  if (errorObserver->GetError() ||errorObserver->GetWarning()){
110  readFilesSuccesfully = false;
111 
112  }
113  REQUIRE(readFilesSuccesfully);
114 
115  vtkSmartPointer<vtkPolyData> leftHandSide = reader1->GetOutput();
116  vtkSmartPointer<vtkPolyData> rightHandSide = reader2->GetOutput();
117 
118  validateVtkPD(leftHandSide, rightHandSide, shouldBeEqual);
119 }
120 
121 void testFlow(char centerline[], char image_prefix[], double Vnyq, double cutoff, int nConvolutions, char true_output[]){
122  const char testFile[] = "/flowdirection_test_1.vtk";
123 
124  AngleCorrection angleCorr = AngleCorrection();
125  REQUIRE_NOTHROW(angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions));
126  bool res;
127  REQUIRE_NOTHROW(res = angleCorr.calculate());
128  REQUIRE(res);
129 
130  REQUIRE_NOTHROW(angleCorr.getClSpline());
131 
133  validateFiles(appendTestFolder(testFile), appendTestFolder(true_output));
134  std::remove(appendTestFolder(testFile));
135 }
136 
137 void validateFlowDirection_FlowVel(vectorSpline3dDouble splines, double *true_flow)
138 {
139  int k=0;
140  for(auto &spline: splines)
141  {
142  double flow_vel = spline.getIntersections().getEstimatedVelocity();
143  double flow_direction = spline.getIntersections().getEstimatedDirection();
144  REQUIRE( (flow_vel) == Approx(true_flow[k]).epsilon(0.005));
145  REQUIRE(sgn(flow_direction) == sgn(true_flow[k++]));
146  }
147 }
148 
149 void testFlowDirection_FlowVel(char centerline[], char image_prefix[], double Vnyq, double cutoff, int nConvolutions, double *true_flow){
150  AngleCorrection angleCorr = AngleCorrection();
151  REQUIRE_NOTHROW(angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions));
152  bool res;
153  REQUIRE_NOTHROW(res = angleCorr.calculate());
154  REQUIRE(res);
155 
156  validateFlowDirection_FlowVel(angleCorr.getClSpline(), true_flow);
157 }
158 
159 
160 
161 
162 TEST_CASE("AngleCorrection: Test flow direction estimation 1", "[angle_correction]")
163  {
164  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_01_20150527T125724_Angio_1_tsf_cl1.vtk";
165  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_01_20150527T125724_raw/US-Acq_01_20150527T125724_Velocity_";
166 
167  double Vnyq = 0.312;
168  double cutoff = 0.18;
169  int nConvolutions = 6;
170 
171  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_1.vtk";
172 
173  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
174 }
175 
176 //TODO: Test disabled from now. Duplicate test in testing/cxtestAngleCorr
177 TEST_CASE("AngleCorrection: Test flow direction estimation 1 unit", "[angle_correction]")
178 {
179  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_01_20150527T125724_Angio_1_tsf_cl1.vtk";
180  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_01_20150527T125724_raw/US-Acq_01_20150527T125724_Velocity_";
181 
182  double Vnyq = 0.312;
183  double cutoff = 0.18;
184  int nConvolutions = 6;
185 
186  double true_flow [1]={-0.465};
187 
188  testFlowDirection_FlowVel(centerline, image_prefix, Vnyq, cutoff, nConvolutions,true_flow);
189 }
190 
191 
192 
193 //TODO: Duplicate test in testing/cxtestAngleCorr
194 TEST_CASE("AngleCorrection: Test flow direction estimation 2", "[angle_correction][flow_dir][not_integration]")
195 {
196  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_02_20150527T125751_Angio_1_tsf_cl1.vtk";
197  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_02_20150527T125751/US-Acq_02_20150527T125751_Velocity_";
198 
199  double Vnyq = 0.312;
200  double cutoff = 0.18;
201  int nConvolutions = 6;
202 
203  // double true_flow [1]={-0.557};
204  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_2.vtk";
205 
206  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
207 }
208 
209 
210 //TODO: Duplicate test in testing/cxtestAngleCorr
211 TEST_CASE("AngleCorrection: Test flow direction estimation 3", "[angle_correction][not_integration][flow_dir][not_apple]")
212 {
213  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_03_20150527T130026_Angio_1_tsf_cl1.vtk";
214  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_03_20150527T130026/US-Acq_03_20150527T130026_Velocity_";
215 
216  double Vnyq = 0.312;
217  double cutoff = 0.18;
218  int nConvolutions = 6;
219 
220  // double true_flow [1]={-0.534};
221  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_3.vtk";
222 
223  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
224 }
225 
226 
227 //TODO: Duplicate test in testing/cxtestAngleCorr
228 TEST_CASE("AngleCorrection: Test flow direction estimation 4", "[angle_correction][not_integration][flow_dir]")
229 {
230  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_04_20150527T130043_Angio_1_tsf_cl1.vtk";
231  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_04_20150527T130043/US-Acq_04_20150527T130043_Velocity_";
232 
233  double Vnyq = 0.312;
234  double cutoff = 0.18;
235  int nConvolutions = 6;
236 
237  // double true_flow [1]={-0.577};
238  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_4.vtk";
239 
240  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
241 }
242 
243 
244 //TODO: Duplicate test in testing/cxtestAngleCorr
245 TEST_CASE("AngleCorrection: Test flow direction estimation 5", "[angle_correction][not_integration][flow_dir]")
246 {
247  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_05_20150527T130229_Angio_1_tsf_cl1.vtk";
248  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_05_20150527T130229/US-Acq_05_20150527T130229_Velocity_";
249 
250  double Vnyq = 0.312;
251  double cutoff = 0.18;
252  int nConvolutions = 6;
253 
254  // double true_flow [2]={-0.933,0.239};
255  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_5.vtk";
256 
257  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
258 }
259 
260 
261 //TODO: Duplicate test in testing/cxtestAngleCorr
262 TEST_CASE("AngleCorrection: Test flow direction estimation 5 unit", "[angle_correction][flow_dir]")
263 {
264  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_05_20150527T130229_Angio_1_tsf_cl1.vtk";
265  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_05_20150527T130229/US-Acq_05_20150527T130229_Velocity_";
266 
267  double Vnyq = 0.312;
268  double cutoff = 0.18;
269  int nConvolutions = 6;
270 
271  double true_flow [2]={-0.933,0.239};
272 
273  testFlowDirection_FlowVel(centerline, image_prefix, Vnyq, cutoff, nConvolutions,true_flow);
274 }
275 
276 
277 
278 //TODO: Duplicate test in testing/cxtestAngleCorr
279 TEST_CASE("AngleCorrection: Test flow direction estimation 6", "[angle_correction][not_integration][flow_dir]")
280 {
281  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_06_20150527T130329_Angio_1_tsf_cl1.vtk";
282  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_06_20150527T130329/US-Acq_06_20150527T130329_Velocity_";
283 
284  double Vnyq = 0.312;
285  double cutoff = 0.18;
286  int nConvolutions = 6;
287 
288  // double true_flow [2]={0.651,-2.50};
289  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_6.vtk";
290 
291  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
292 }
293 
294 
295 //TODO: Duplicate test in testing/cxtestAngleCorr
296 TEST_CASE("AngleCorrection: Test flow direction estimation 7, aliasing", "[angle_correction][not_integration][aliasing][not_apple]")
297 {
298  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_07_20150527T130532_Angio_1_tsf_cl1.vtk";
299  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_07_20150527T130532/US-Acq_07_20150527T130532_Velocity_";
300 
301  double Vnyq = 0.156;
302  double cutoff = 0.18;
303  int nConvolutions = 6;
304 
305  // double true_flow [1]={-0.314};
306  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_7.vtk";
307 
308  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
309 }
310 
311 
312 //TODO: Duplicate test in testing/cxtestAngleCorr
313 TEST_CASE("AngleCorrection: Test flow direction estimation 8, aliasing", "[angle_correction][not_integration][aliasing]")
314 {
315  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_08_20150527T130558_Angio_1_tsf_cl1.vtk";
316  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_08_20150527T130558/US-Acq_08_20150527T130558_Velocity_";
317 
318  double Vnyq = 0.156;
319  double cutoff = 0.18;
320  int nConvolutions = 6;
321 
322  // double true_flow [1]={0.403};
323  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_8.vtk";
324 
325  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
326 }
327 
328 //TODO: Duplicate test in testing/cxtestAngleCorr
329 TEST_CASE("AngleCorrection: Test flow direction estimation 8, aliasing, unit", "[angle_correction][aliasing]")
330 {
331  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_08_20150527T130558_Angio_1_tsf_cl1.vtk";
332  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_08_20150527T130558/US-Acq_08_20150527T130558_Velocity_";
333 
334  double Vnyq = 0.156;
335  double cutoff = 0.18;
336  int nConvolutions = 6;
337 
338  double true_flow [1]={0.403};
339 
340  testFlowDirection_FlowVel(centerline, image_prefix, Vnyq, cutoff, nConvolutions,true_flow);
341 }
342 
343 
344 //TODO: Duplicate test in testing/cxtestAngleCorr
345 TEST_CASE("AngleCorrection: Test flow direction estimation 9, cross movement", "[angle_correction][not_integration]")
346 {
347  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_09_20150527T131009_Angio_1_tsf_cl1.vtk";
348  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_09_20150527T131009/US-Acq_09_20150527T131009_Velocity_";
349 
350  double Vnyq = 0.312;
351  double cutoff = 0.18;
352  int nConvolutions = 6;
353 
354  // double true_flow [1]={-0.625};
355  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_9.vtk";
356 
357  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
358 }
359 
360 
361 TEST_CASE("AngleCorrection: Test flow direction estimation 10, cross movement", "[angle_correction]")
362 {
363  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_10_20150527T131055_Angio_1_tsf_cl1.vtk";
364  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-Acq_10_20150527T131055_Velocity_";
365 
366  double Vnyq = 0.312;
367  double cutoff = 0.18;
368  int nConvolutions = 6;
369 
370  // double true_flow [1]={0.5847};
371  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk";
372 
373  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
374 }
375 
376 
377 //TODO: Duplicate test in testing/cxtestAngleCorr
378 TEST_CASE("AngleCorrection: Test Invalid parameters", "[angle_correction]")
379 {
380 
381  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/NonExisting.vtk";
382  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-Acq_10_20150527T131055_Velocity_";
383 
384  double Vnyq = 0.312;
385  double cutoff = 0.18;
386  int nConvolutions = 6;
387  double uncertainty_limit = 0.5;
388  double minArrowDist = 1.0;
389 
390  bool res;
391 
392  AngleCorrection angleCorr = AngleCorrection();
393  REQUIRE_THROWS(angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions,uncertainty_limit,minArrowDist));
394  REQUIRE_NOTHROW(res = angleCorr.calculate());
395  REQUIRE(!res);
396 
397  char centerline2[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_10_20150527T131055_Angio_1_tsf_cl1.vtk";
398  char image_prefix2[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-NonExisting";
399  REQUIRE_THROWS(angleCorr.setInput(appendTestFolder(centerline2), appendTestFolder(image_prefix2), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
400  REQUIRE_NOTHROW(res = angleCorr.calculate());
401  REQUIRE(!res);
402 
403  char centerline3[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_10_20150527T131055_Angio_1_tsf_cl1.vtk";
404  char image_prefix3[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-Acq_10_20150527T131055_Velocity_";
405  REQUIRE_NOTHROW(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
406  REQUIRE_NOTHROW(res = angleCorr.calculate());
407  REQUIRE(res);
408 
409  Vnyq = -0.312;
410  REQUIRE_THROWS(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
411  REQUIRE_NOTHROW(res = angleCorr.calculate());
412  REQUIRE(!res);
413 
414  Vnyq = 0.0;
415  REQUIRE_NOTHROW(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
416  REQUIRE_NOTHROW(res = angleCorr.calculate());
417  REQUIRE(res);
418 
419  nConvolutions = -1;
420  REQUIRE_THROWS(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
421  REQUIRE_NOTHROW(res = angleCorr.calculate());
422  REQUIRE(!res);
423 
424  nConvolutions = 2;
425  REQUIRE_NOTHROW(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
426  REQUIRE_NOTHROW(res = angleCorr.calculate());
427  REQUIRE(res);
428 
429  uncertainty_limit = 0;
430  REQUIRE_NOTHROW(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
431  REQUIRE_NOTHROW(res = angleCorr.calculate());
432  REQUIRE(res);
433 
434  uncertainty_limit = -0.5;
435  REQUIRE_THROWS(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
436  REQUIRE_NOTHROW(res = angleCorr.calculate());
437  REQUIRE(!res);
438 
439  uncertainty_limit = 0.5;
440  REQUIRE_NOTHROW(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
441  REQUIRE_NOTHROW(res = angleCorr.calculate());
442  REQUIRE(res);
443 
444  minArrowDist = -0.5;
445  REQUIRE_THROWS(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
446  REQUIRE_NOTHROW(res = angleCorr.calculate());
447  REQUIRE(!res);
448 
449  minArrowDist = 1.5;
450  REQUIRE_NOTHROW(angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
451  REQUIRE_NOTHROW(res = angleCorr.calculate());
452  REQUIRE(res);
453 }
454 
455 
456 //TODO: Duplicate test in testing/cxtestAngleCorr
457 TEST_CASE("AngleCorrection: Test several runs", "[angle_correction][not_integration]")
458 {
459  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_10_20150527T131055_Angio_1_tsf_cl1.vtk";
460  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-Acq_10_20150527T131055_Velocity_";
461 
462  double Vnyq = 0.312;
463  double cutoff = 0.18;
464  int nConvolutions = 6;
465  double uncertainty_limit = 0.5;
466  double minArrowDist = 1.0;
467 
468 
469  char centerline2[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_06_20150527T130329_Angio_1_tsf_cl1.vtk";
470  char image_prefix2[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_06_20150527T130329/US-Acq_06_20150527T130329_Velocity_";
471 
472  double Vnyq2 = 0.312;
473  double cutoff2 = 0.18;
474  int nConvolutions2 = 6;
475 
476  const char* filename_a ="/flowdirection_test_11_a.vtk";
477  const char* filename_b ="/flowdirection_test_11_b.vtk";
478 
479  bool res;
480  AngleCorrection angleCorr = AngleCorrection();
481 
482  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
483  res = angleCorr.calculate();
484  REQUIRE(res);
485 
486  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
487  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
488  validateFiles(appendTestFolder(filename_a), appendTestFolder(filename_b));
489  std::remove(appendTestFolder(filename_b));
490 
491  angleCorr.setInput(appendTestFolder(centerline2), appendTestFolder(image_prefix2), Vnyq2, cutoff2, nConvolutions2);
492  res = angleCorr.calculate();
493  REQUIRE(res);
494  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
495  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_6.vtk"));
496 
497  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
498  res = angleCorr.calculate();
499  REQUIRE(res);
500  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
501 
502  validateFiles(appendTestFolder(filename_a), appendTestFolder(filename_b));
503  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
504 
505  std::remove(appendTestFolder(filename_a));
506  std::remove(appendTestFolder(filename_b));
507 
508  cutoff = 1;
509  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
510  res = angleCorr.calculate();
511  REQUIRE(res);
512  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
513  validateFiles(appendTestFolder(filename_a), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"),false);
514  std::remove(appendTestFolder(filename_a));
515 
516 
517  cutoff = 0.18;
518  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
519  res = angleCorr.calculate();
520  REQUIRE(res);
521  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
522  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
523  std::remove(appendTestFolder(filename_b));
524 
525  nConvolutions = 50;
526  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
527  res = angleCorr.calculate();
528  REQUIRE(res);
529  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
530  validateFiles(appendTestFolder(filename_a), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"),false);
531  std::remove(appendTestFolder(filename_a));
532 
533  nConvolutions = 6;
534  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
535  res = angleCorr.calculate();
536  REQUIRE(res);
537  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
538  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
539  std::remove(appendTestFolder(filename_b));
540 
541  minArrowDist = 5.0;
542  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
543  res = angleCorr.calculate();
544  REQUIRE(res);
545  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
546  validateFiles(appendTestFolder(filename_a), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"),false);
547  std::remove(appendTestFolder(filename_a));
548 
549  minArrowDist = 1.0;
550  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
551  res = angleCorr.calculate();
552  REQUIRE(res);
553  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
554  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
555  std::remove(appendTestFolder(filename_b));
556 
557  REQUIRE(angleCorr.getBloodVessels()==8);
558  REQUIRE(angleCorr.getIntersections()==924);
559  REQUIRE(angleCorr.getNumOfStepsRan()==1);
560 }
561 
562 
563 //TODO: Duplicate test in testing/cxtestAngleCorr
564 TEST_CASE("AngleCorrection: Test several runs cl pointer input", "[angle_correction][not_integration][not_apple]")
565 {
566 
567  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_10_20150527T131055_Angio_1_tsf_cl1.vtk";
568  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-Acq_10_20150527T131055_Velocity_";
569 
570  double Vnyq = 0.312;
571  double cutoff = 0.18;
572  int nConvolutions = 6;
573  double uncertainty_limit = 0.5;
574  double minArrowDist = 1.0;
575 
576  vtkSmartPointer<vtkPolyDataReader> clReader1 = vtkSmartPointer<vtkPolyDataReader>::New();
577  clReader1->SetFileName(appendTestFolder(centerline));
578  clReader1->Update();
579  vtkSmartPointer<vtkPolyData> vpd_centerline1 = clReader1->GetOutput();
580  const char* filename_a ="/flowdirection_test_11_a.vtk";
581  const char* filename_b ="/flowdirection_test_11_b.vtk";
582 
583  bool res;
584  AngleCorrection angleCorr = AngleCorrection();
585 
586  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
587  res = angleCorr.calculate();
588  REQUIRE(res);
589 
590  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
591  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
592  validateFiles(appendTestFolder(filename_a), appendTestFolder(filename_b));
593  std::remove(appendTestFolder(filename_b));
594 
595  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions);
596  res = angleCorr.calculate();
597  REQUIRE(res);
598  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
599  validateFiles(appendTestFolder(filename_b), appendTestFolder(filename_a));
600 
601  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
602  res = angleCorr.calculate();
603  REQUIRE(res);
604  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
605 
606  validateFiles(appendTestFolder(filename_a), appendTestFolder(filename_b));
607  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
608 
609  std::remove(appendTestFolder(filename_a));
610  std::remove(appendTestFolder(filename_b));
611 
612  cutoff = 1;
613  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
614  res = angleCorr.calculate();
615  REQUIRE(res);
616  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
617  validateFiles(appendTestFolder(filename_a), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"),false);
618  std::remove(appendTestFolder(filename_a));
619 
620  cutoff = 0.18;
621  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
622  res = angleCorr.calculate();
623  REQUIRE(res);
624  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
625  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
626  std::remove(appendTestFolder(filename_b));
627 
628  nConvolutions = 50;
629  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
630  res = angleCorr.calculate();
631  REQUIRE(res);
632  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
633  validateFiles(appendTestFolder(filename_a), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"),false);
634  std::remove(appendTestFolder(filename_a));
635 
636  nConvolutions = 6;
637  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
638  res = angleCorr.calculate();
639  REQUIRE(res);
640  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
641  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
642  std::remove(appendTestFolder(filename_b));
643 
644  minArrowDist = 5.0;
645  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
646  res = angleCorr.calculate();
647  REQUIRE(res);
648  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
649  validateFiles(appendTestFolder(filename_a), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"),false);
650  std::remove(appendTestFolder(filename_a));
651 
652  minArrowDist = 1.0;
653  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
654  res = angleCorr.calculate();
655  REQUIRE(res);
656  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
657  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
658  std::remove(appendTestFolder(filename_b));
659 
660  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
661  vpd_centerline1=vtkSmartPointer<vtkPolyData>::New();
662  res = angleCorr.calculate();
663  REQUIRE(res);
664  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
665  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"));
666  std::remove(appendTestFolder(filename_b));
667 
668  vpd_centerline1=vtkSmartPointer<vtkPolyData>::New();
669  REQUIRE_THROWS(angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist));
670  res = angleCorr.calculate();
671  REQUIRE(!res);
672  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
673  validateFiles(appendTestFolder(filename_b), appendTestFolder("/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_10.vtk"),false);
674  std::remove(appendTestFolder(filename_b));
675 }
676 
677 
678 TEST_CASE("AngleCorrection: Benchmark", "[angle_correction][Benchmark]")
679 {
680  clock_t start, stop;
681  double run_time = 0.0;
682  start = clock();
683 
684  bool res;
685 
686  char centerline1[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_01_20150527T125724_Angio_1_tsf_cl1.vtk";
687  char image_prefix1[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_01_20150527T125724_raw/US-Acq_01_20150527T125724_Velocity_";
688  double Vnyq1 = 0.312;
689  double cutoff1 = 0.18;
690  int nConvolutions1 = 6;
691 
692  AngleCorrection angleCorr = AngleCorrection();
693  angleCorr.setInput(appendTestFolder(centerline1), appendTestFolder(image_prefix1), Vnyq1, cutoff1, nConvolutions1);
694  res = angleCorr.calculate();
695  REQUIRE(res);
696 
697 
698  char centerline2[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_02_20150527T125751_Angio_1_tsf_cl1.vtk";
699  char image_prefix2[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_02_20150527T125751/US-Acq_02_20150527T125751_Velocity_";
700  double Vnyq2 = 0.312;
701  double cutoff2 = 0.18;
702  int nConvolutions2 = 6;
703 
704  angleCorr.setInput(appendTestFolder(centerline2), appendTestFolder(image_prefix2), Vnyq2, cutoff2, nConvolutions2);
705  res = angleCorr.calculate();
706  REQUIRE(res);
707 
708 
709  char centerline3[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_03_20150527T130026_Angio_1_tsf_cl1.vtk";
710  char image_prefix3[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_03_20150527T130026/US-Acq_03_20150527T130026_Velocity_";
711  double Vnyq3 = 0.312;
712  double cutoff3 = 0.18;
713  int nConvolutions3 = 6;
714 
715  angleCorr.setInput(appendTestFolder(centerline3), appendTestFolder(image_prefix3), Vnyq3, cutoff3, nConvolutions3);
716  res = angleCorr.calculate();
717  REQUIRE(res);
718 
719 
720  char centerline4[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_04_20150527T130043_Angio_1_tsf_cl1.vtk";
721  char image_prefix4[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_04_20150527T130043/US-Acq_04_20150527T130043_Velocity_";
722  double Vnyq4 = 0.312;
723  double cutoff4 = 0.18;
724  int nConvolutions4 = 6;
725 
726  angleCorr.setInput(appendTestFolder(centerline4), appendTestFolder(image_prefix4), Vnyq4, cutoff4, nConvolutions4);
727  res = angleCorr.calculate();
728  REQUIRE(res);
729 
730 
731  char centerline5[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_05_20150527T130229_Angio_1_tsf_cl1.vtk";
732  char image_prefix5[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_05_20150527T130229/US-Acq_05_20150527T130229_Velocity_";
733  double Vnyq5 = 0.312;
734  double cutoff5 = 0.18;
735  int nConvolutions5 = 6;
736 
737  angleCorr.setInput(appendTestFolder(centerline5), appendTestFolder(image_prefix5), Vnyq5, cutoff5, nConvolutions5);
738  res = angleCorr.calculate();
739  REQUIRE(res);
740 
741 
742  char centerline6[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_06_20150527T130329_Angio_1_tsf_cl1.vtk";
743  char image_prefix6[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_06_20150527T130329/US-Acq_06_20150527T130329_Velocity_";
744  double Vnyq6 = 0.312;
745  double cutoff6 = 0.18;
746  int nConvolutions6 = 6;
747 
748  angleCorr.setInput(appendTestFolder(centerline6), appendTestFolder(image_prefix6), Vnyq6, cutoff6, nConvolutions6);
749  res = angleCorr.calculate();
750  REQUIRE(res);
751 
752 
753  char centerline7[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_07_20150527T130532_Angio_1_tsf_cl1.vtk";
754  char image_prefix7[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_07_20150527T130532/US-Acq_07_20150527T130532_Velocity_";
755  double Vnyq7 = 0.156;
756  double cutoff7 = 0.18;
757  int nConvolutions7 = 6;
758 
759 
760  angleCorr.setInput(appendTestFolder(centerline7), appendTestFolder(image_prefix7), Vnyq7, cutoff7, nConvolutions7);
761  res = angleCorr.calculate();
762  REQUIRE(res);
763 
764  char centerline8[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_08_20150527T130558_Angio_1_tsf_cl1.vtk";
765  char image_prefix8[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_08_20150527T130558/US-Acq_08_20150527T130558_Velocity_";
766  double Vnyq8 = 0.156;
767  double cutoff8 = 0.18;
768  int nConvolutions8 = 6;
769 
770 
771  angleCorr.setInput(appendTestFolder(centerline8), appendTestFolder(image_prefix8), Vnyq8, cutoff8, nConvolutions8);
772  res = angleCorr.calculate();
773  REQUIRE(res);
774 
775  char centerline9[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_09_20150527T131009_Angio_1_tsf_cl1.vtk";
776  char image_prefix9[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_09_20150527T131009/US-Acq_09_20150527T131009_Velocity_";
777  double Vnyq9 = 0.312;
778  double cutoff9 = 0.18;
779  int nConvolutions9 = 6;
780 
781  angleCorr = AngleCorrection();
782  angleCorr.setInput(appendTestFolder(centerline9), appendTestFolder(image_prefix9), Vnyq9, cutoff9, nConvolutions9);
783  res = angleCorr.calculate();
784  REQUIRE(res);
785 
786 
787  char centerline10[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_10_20150527T131055_Angio_1_tsf_cl1.vtk";
788  char image_prefix10[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-Acq_10_20150527T131055_Velocity_";
789  double Vnyq10 = 0.312;
790  double cutoff10 = 0.18;
791  int nConvolutions10 = 6;
792 
793 
794  angleCorr.setInput(appendTestFolder(centerline10), appendTestFolder(image_prefix10), Vnyq10, cutoff10, nConvolutions10);
795  res = angleCorr.calculate();
796  REQUIRE(res);
797 
798  stop = clock();
799  run_time = (double) (stop-start)/CLOCKS_PER_SEC;
800  REQUIRE(run_time<30);
801 
802  cerr << "Run time: " << run_time <<"\n";
803 }
804 
805 
806 //TODO: Duplicate test in testing/cxtestAngleCorr
807 TEST_CASE("AngleCorrection: Test several runs cl pointer input simple", "[angle_correction][not_integration][simple]")
808 {
809 
810  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_10_20150527T131055_Angio_1_tsf_cl1.vtk";
811  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-Acq_10_20150527T131055_Velocity_";
812 
813  double Vnyq = 0.312;
814  double cutoff = 0.18;
815  int nConvolutions = 6;
816  double uncertainty_limit = 0.5;
817  double minArrowDist = 1.0;
818 
819  vtkSmartPointer<vtkPolyDataReader> clReader1 = vtkSmartPointer<vtkPolyDataReader>::New();
820  clReader1->SetFileName(appendTestFolder(centerline));
821  clReader1->Update();
822  vtkSmartPointer<vtkPolyData> vpd_centerline1 = clReader1->GetOutput();
823  const char* filename_a ="/flowdirection_test_11_a.vtk";
824  const char* filename_b ="/flowdirection_test_11_b.vtk";
825 
826  bool res;
827  AngleCorrection angleCorr = AngleCorrection();
828 
829  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
830  res = angleCorr.calculate();
831  REQUIRE(res);
832 
833  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_a));
834  angleCorr.writeDirectionToVtkFile(appendTestFolder(filename_b));
835  validateFiles(appendTestFolder(filename_a), appendTestFolder(filename_b));
836  std::remove(appendTestFolder(filename_b));
837 
838  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions);
839  res = angleCorr.calculate();
840  REQUIRE(res);
842  validateFiles(appendTestFolder(filename_b), appendTestFolder(filename_a));
843 
844  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
845  res = angleCorr.calculate();
846  REQUIRE(res);
848 
849  validateFiles(appendTestFolder(filename_a), appendTestFolder(filename_b));
850 
851  std::remove(appendTestFolder(filename_a));
852  std::remove(appendTestFolder(filename_b));
853 
854  cutoff = 1;
855  angleCorr.setInput(vpd_centerline1, appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
856  res = angleCorr.calculate();
857  REQUIRE(res);
859  std::remove(appendTestFolder(filename_a));
860 }
861 
862 
863 //TODO: Duplicate test in testing/cxtestAngleCorr
864 TEST_CASE("AngleCorrection: Test flow direction estimation tumour data", "[angle_correction][not_integration]")
865 {
866  const char* filename_a ="/flowdirection_test_11_a.vtk";
867 
868  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_02_20150625T105554_Angio_1_tsf_cl1.vtk";
869  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_02_20150625T105554/US-Acq_02_20150625T105554_Velocity_";
870 
871  double Vnyq = 0.0;
872  double cutoff = 0;
873  int nConvolutions = 5;
874 
875  // double true_flow [4]={0.082484, 0.146338, 0.119538, 0.322488};
876  char true_output[] ="/2015-05-27_12-02_AngelCorr_tets.cx3/trueOutputAngleCorr/output_flowdirection_test_tumour.vtk";
877 
878  testFlow(centerline, image_prefix, Vnyq, cutoff, nConvolutions, true_output);
879 
880 
881  AngleCorrection angleCorr = AngleCorrection();
882 
883  double uncertainty_limit = 0;
884  double minArrowDist =2;
885 
886  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
887  bool res = angleCorr.calculate();
888  REQUIRE(res);
889 
890  REQUIRE(angleCorr.getBloodVessels()==219);
891  REQUIRE(angleCorr.getIntersections()==1420);
892  REQUIRE(angleCorr.getNumOfStepsRan()==2);
893 
894 
895  uncertainty_limit = 0.5;
896 
897  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
898  res = angleCorr.calculate();
899  REQUIRE(res);
900 
901  REQUIRE(angleCorr.getBloodVessels()==120);
902  REQUIRE(angleCorr.getIntersections()==1420);
903  REQUIRE(angleCorr.getNumOfStepsRan()==1);
904 }
905 
906 //TODO: Duplicate test in testing/cxtestAngleCorr
907 TEST_CASE("AngleCorrection: Test flow direction estimation tumour data, unit", "[angle_correction]")
908 {
909  char centerline[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/Images/US_02_20150625T105554_Angio_1_tsf_cl1.vtk";
910  char image_prefix[] = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_02_20150625T105554/US-Acq_02_20150625T105554_Velocity_";
911 
912  double Vnyq = 0.0;
913  double cutoff = 0;
914  int nConvolutions = 5;
915 
916  AngleCorrection angleCorr = AngleCorrection();
917 
918  double uncertainty_limit = 0;
919  double minArrowDist =2;
920 
921  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
922  bool res = angleCorr.calculate();
923  REQUIRE(res);
924 
925  REQUIRE(angleCorr.getBloodVessels()==219);
926  REQUIRE(angleCorr.getIntersections()==1420);
927  REQUIRE(angleCorr.getNumOfStepsRan()==2);
928 
929 
930 
931  vectorSpline3dDouble outSpline;
932  REQUIRE_NOTHROW(outSpline = angleCorr.getClSpline());
933  REQUIRE(outSpline.size()==angleCorr.getBloodVessels());
934  REQUIRE(outSpline.at(0).getTransform());
935 
936  uncertainty_limit = 0.5;
937 
938  angleCorr.setInput(appendTestFolder(centerline), appendTestFolder(image_prefix), Vnyq, cutoff, nConvolutions, uncertainty_limit,minArrowDist);
939  res = angleCorr.calculate();
940  REQUIRE(res);
941 
942  REQUIRE(angleCorr.getBloodVessels()==120);
943  REQUIRE(angleCorr.getIntersections()==1420);
944  REQUIRE(angleCorr.getNumOfStepsRan()==1);
945 
946  vtkSmartPointer<vtkPolyData> out;
947  REQUIRE_NOTHROW(out = angleCorr.getOutput());
948  if(out ==NULL) REQUIRE(false);
949 
950 
951  const char* filename_a ="/flowdirection_test_11_a.vtk";
953 
954  vtkSmartPointer<ErrorObserver> errorObserver = vtkSmartPointer<ErrorObserver>::New();
955 
956  vtkSmartPointer<vtkPolyDataReader> reader1 = vtkSmartPointer<vtkPolyDataReader>::New();
957  reader1->AddObserver(vtkCommand::ErrorEvent,errorObserver);
958  reader1->SetFileName(appendTestFolder(filename_a));
959  reader1->Update();
960 
961  bool readFilesSuccesfully = true;
962  if (errorObserver->GetError() ||errorObserver->GetWarning()){
963  readFilesSuccesfully = false;
964 
965  }
966  REQUIRE(readFilesSuccesfully);
967 
968  vtkSmartPointer<vtkPolyData> leftHandSide = reader1->GetOutput();
969 
970  validateVtkPD(leftHandSide, out, true);
971 
972  std::remove(appendTestFolder(filename_a));
973 
974 }
975 
976 //TODO: Duplicate test in testing/cxtestAngleCorr
977 TEST_CASE("AngleCorrection: Test error handler", "[angle_correction]")
978 {
979  vtkSmartPointer<ErrorObserver> errorObserver = vtkSmartPointer<ErrorObserver>::New();
980 
981  REQUIRE_NOTHROW(errorObserver->Clear());
982  REQUIRE(!errorObserver->GetError());
983  REQUIRE(!errorObserver->GetWarning());
984  REQUIRE(errorObserver->GetErrorMessage().length()==0);
985  REQUIRE(errorObserver->GetWarningMessage().length()==0);
986 
987  const char* filename_a = "/2015-05-27_12-02_AngelCorr_tets.cx3/US_Acq/US-Acq_10_20150527T131055/US-NonExisting";
988  vtkSmartPointer<vtkPolyDataReader> reader1 = vtkSmartPointer<vtkPolyDataReader>::New();
989  reader1->AddObserver(vtkCommand::ErrorEvent,errorObserver);
990  reader1->SetFileName(appendTestFolder(filename_a));
991  reader1->Update();
992 
993  REQUIRE(errorObserver->GetError());
994  REQUIRE(!errorObserver->GetWarning());
995  REQUIRE(errorObserver->GetErrorMessage().length()>0);
996  REQUIRE(errorObserver->GetWarningMessage().length()==0);
997 
998  REQUIRE_NOTHROW(errorObserver->Clear());
999 
1000  REQUIRE(!errorObserver->GetError());
1001  REQUIRE(!errorObserver->GetWarning());
1002  REQUIRE(errorObserver->GetErrorMessage().length()==0);
1003  REQUIRE(errorObserver->GetWarningMessage().length()==0);
1004 
1005 }
#define REQUIRE(expr)
Definition: catch.hpp:7784
void setInput(vtkSmartPointer< vtkPolyData > vpd_centerline, const char *image_prefix, double Vnyq, double cutoff, int nConvolutions, double uncertainty_limit=0.0, double minArrowDist=1.0)
int sgn(T val)
Definition: helpers.hpp:9
void validateFlowDirection_FlowVel(vectorSpline3dDouble splines, double *true_flow)
void testFlow(char centerline[], char image_prefix[], double Vnyq, double cutoff, int nConvolutions, char true_output[])
vector< Spline3D< double > > vectorSpline3dDouble
void writeDirectionToVtkFile(const char *filename)
char * appendTestFolder(const char *filename)
Definition: MethodTests.cpp:25
vtkSmartPointer< vtkPolyData > getOutput()
#define REQUIRE_THROWS(expr)
Definition: catch.hpp:7787
vectorSpline3dDouble getClSpline()
void validateFiles(const char *filename_a, const char *filename_b, bool shouldBeEqual=true)
Definition: MethodTests.cpp:95
#define REQUIRE_NOTHROW(expr)
Definition: catch.hpp:7789
TEST_CASE("AngleCorrection: Test flow direction estimation 1","[angle_correction]")
void testFlowDirection_FlowVel(char centerline[], char image_prefix[], double Vnyq, double cutoff, int nConvolutions, double *true_flow)
void validateVtkPD(vtkSmartPointer< vtkPolyData > leftHandSide, vtkSmartPointer< vtkPolyData > rightHandSide, bool shouldBeEqual=true)
Definition: MethodTests.cpp:35