PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkFcsvWriterTest1.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 // Local includes
8 #include "PlusConfigure.h"
9 #include "vtkFcsvReader.h"
10 #include "vtkFcsvWriter.h"
11 
12 // STL includes
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string>
16 
17 // ITK includes
18 #include <itkLandmarkSpatialObject.h>
19 
20 int main(int argc, char* argv[])
21 {
22  vtkPlusLogger::Instance()->SetLogLevel(vtkPlusLogger::LOG_LEVEL_UNDEFINED);
23 
24  vtkSmartPointer<vtkFcsvReader> reader = vtkSmartPointer<vtkFcsvReader>::New();
25 
26  reader->SetFileName(argv[1]);
27  reader->Update();
28 
29  LOG_DEBUG("Number Of Points: " << reader->GetFcsvDataObject().points.size());
30  if (reader->GetFcsvDataObject().points.size() != 18)
31  {
32  LOG_ERROR("Number Of Points: mismatch");
33  return EXIT_FAILURE;
34  }
35 
36  try
37  {
38  reader->GetFcsvPoint(2).position[0] = 100;
39  reader->GetFcsvPoint(2).position[1] = 200;
40  reader->GetFcsvPoint(2).position[2] = 300;
41  reader->GetFcsvPoint(2).selected = 0;
42  reader->GetFcsvPoint(2).visibility = 1;
43  }
44  catch (const std::out_of_range& ex)
45  {
46  LOG_ERROR(ex.what());
47  return EXIT_FAILURE;
48  }
49 
50  // Write the updated fcsv data
51  vtkSmartPointer<vtkFcsvWriter> writer = vtkSmartPointer<vtkFcsvWriter>::New();
52  writer->SetFileName(argv[2]);
53  writer->CopyFcsvDataObject(reader->GetFcsvDataObject());
54  writer->Update();
55 
56  // Read the updated fcsv data
57  vtkSmartPointer<vtkFcsvReader> reader2 = vtkSmartPointer<vtkFcsvReader>::New();
58  reader2->SetFileName(argv[2]);
59  reader2->Update();
60 
61  LOG_DEBUG("Number Of Points: " << reader2->GetFcsvDataObject().points.size());
62  if (reader2->GetFcsvDataObject().points.size() != 18)
63  {
64  LOG_ERROR("Number Of Points: mismatch");
65  return EXIT_FAILURE;
66  }
67 
68  int fidIndex = 0;
69  std::vector<FcsvPoint>::const_iterator it = reader2->GetFcsvDataObject().points.begin();
70  while (it != reader2->GetFcsvDataObject().points.end())
71  {
72  LOG_DEBUG("Point position: " << (*it).position);
73  if (fidIndex == 2)
74  {
75  if ((*it).position[0] != 100)
76  {
77  LOG_ERROR("Position[0] mismatch");
78  return EXIT_FAILURE;
79  }
80  if ((*it).position[1] != 200)
81  {
82  LOG_ERROR("Position[1] mismatch");
83  return EXIT_FAILURE;
84  }
85  if ((*it).position[2] != 300)
86  {
87  LOG_ERROR("Position[2] mismatch");
88  return EXIT_FAILURE;
89  }
90  if ((*it).selected != 0)
91  {
92  LOG_ERROR("selected mismatch");
93  return EXIT_FAILURE;
94  }
95  if ((*it).visibility != 1)
96  {
97  LOG_ERROR("visibility mismatch");
98  return EXIT_FAILURE;
99  }
100  }
101  ++it;
102  fidIndex++;
103  }
104 
105  return EXIT_SUCCESS;
106 }
static vtkIGSIOLogger * Instance()
int main(int argc, char *argv[])