PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkFcsvReader.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 
11 // STL includes
12 #include <sstream>
13 #include <string>
14 #include <vector>
15 
16 // VTK includes
17 #include <vtkObjectFactory.h>
18 
19 #define MAXFLDS 30 // maximum possible number of fields
20 #define MAXFLDSIZE 150 // longest possible field + 1 = 31 byte field
21 
22 //----------------------------------------------------------------------------
23 
25 
26 //----------------------------------------------------------------------------
28 {
29 }
30 
31 //----------------------------------------------------------------------------
33 {
34 }
35 
36 //----------------------------------------------------------------------------
37 void vtkFcsvReader::PrintSelf(ostream& os, vtkIndent indent)
38 {
39  os << indent << "Filename: " << FileName << std::endl;
40  os << indent << "FcsvDataObject.filePath: " << FcsvDataObject.filePath << std::endl;
41  os << indent << "FcsvDataObject.name: " << FcsvDataObject.name << std::endl;
42  os << indent << "FcsvDataObject.numPoints: " << FcsvDataObject.numPoints << std::endl;
43  os << indent << "FcsvDataObject.symbolScale: " << FcsvDataObject.symbolScale << std::endl;
44  os << indent << "FcsvDataObject.symbolType: " << FcsvDataObject.symbolType << std::endl;
45  os << indent << "FcsvDataObject.visibility: " << FcsvDataObject.visibility << std::endl;
46  os << indent << "FcsvDataObject.version: " << FcsvDataObject.version << std::endl;
47  os << indent << "FcsvDataObject.textScale: " << FcsvDataObject.textScale << std::endl;
48  os << indent << "FcsvDataObject.color[3]: " << FcsvDataObject.color[0] << ", " << FcsvDataObject.color[1] << ", " << FcsvDataObject.color[2] << std::endl;
49  os << indent << "FcsvDataObject.selectedColor[3]: " << FcsvDataObject.selectedColor[0] << ", " << FcsvDataObject.selectedColor[1] << ", " << FcsvDataObject.selectedColor[2] << std::endl;
50  os << indent << "FcsvDataObject.opacity: " << FcsvDataObject.opacity << std::endl;
51  os << indent << "FcsvDataObject.ambient: " << FcsvDataObject.ambient << std::endl;
52  os << indent << "FcsvDataObject.diffuse: " << FcsvDataObject.diffuse << std::endl;
53  os << indent << "FcsvDataObject.specular: " << FcsvDataObject.specular << std::endl;
54  os << indent << "FcsvDataObject.power: " << FcsvDataObject.power << std::endl;
55  os << indent << "FcsvDataObject.locked: " << FcsvDataObject.locked << std::endl;
56  os << indent << "FcsvDataObject.numberingScheme: " << FcsvDataObject.numberingScheme << std::endl;
57  for (unsigned int i = 0; i < FcsvDataObject.columns.size(); ++i)
58  {
59  os << indent << "FcsvDataObject.column " << i + 1 << ": " << FcsvDataObject.columns[i] << std::endl;
60  }
61  for (unsigned int i = 0; i < FcsvDataObject.points.size(); ++i)
62  {
63  os << indent << "FcsvDataObject.point " << FcsvDataObject.points[i].label << ": " << FcsvDataObject.points[i].position[0] << ", " << FcsvDataObject.points[i].position[1] << ", " << FcsvDataObject.points[i].position[2] << std::endl;
64  }
65 }
66 
67 //----------------------------------------------------------------------------
69 {
70  std::ifstream in(FileName.c_str());
71  if (!in.is_open())
72  {
73  LOG_ERROR("Failed to open file " << FileName);
74  }
75 
77 
78  std::string line;
79  while (std::getline(in, line))
80  {
81  if (line[0] == '#' && line.find('=') != std::string::npos)
82  {
83  // Header, process it
84  std::vector<std::string> elems;
85  igsioCommon::SplitStringIntoTokens(line, '=', elems);
86  this->StripCharsFromString(elems[0], " #");
87  elems[1] = igsioCommon::Trim(elems[1]);
88  this->ProcessHeaderEntry(elems[0], elems[1]);
89  }
90  else if (line[0] == '#')
91  {
92  // Fiducial List file entry
93  std::vector<std::string> elems;
94  igsioCommon::SplitStringIntoTokens(line, ' ', elems);
95  FcsvDataObject.filePath = elems[4];
96  }
97  else
98  {
99  // It's a record, read it as such
100  std::vector<std::string> elems;
101  igsioCommon::SplitStringIntoTokens(line, ',', elems);
102 
103  FcsvPoint point;
104  point.label = elems[0];
105  point.position[0] = atof(elems[1].c_str());
106  point.position[1] = atof(elems[2].c_str());
107  point.position[2] = atof(elems[3].c_str());
108  point.selected = atoi(elems[4].c_str());
109  point.visibility = atoi(elems[5].c_str());
110 
111  FcsvDataObject.points.push_back(point);
112  }
113  }
114 
115  in.close();
116 }
117 
118 //----------------------------------------------------------------------------
119 void vtkFcsvReader::ProcessHeaderEntry(const std::string& headerEntry, const std::string& headerEntryValue)
120 {
121  if (igsioCommon::IsEqualInsensitive(headerEntry, "numPoints"))
122  {
123  FcsvDataObject.numPoints = atof(headerEntryValue.c_str());
124  }
125  else if (igsioCommon::IsEqualInsensitive(headerEntry, "version"))
126  {
127  FcsvDataObject.version = atof(headerEntryValue.c_str());
128  }
129  else if (igsioCommon::IsEqualInsensitive(headerEntry, "name"))
130  {
131  FcsvDataObject.name = headerEntryValue;
132  }
133  else if (igsioCommon::IsEqualInsensitive(headerEntry, "symbolScale"))
134  {
135  FcsvDataObject.symbolScale = atof(headerEntryValue.c_str());
136  }
137  else if (igsioCommon::IsEqualInsensitive(headerEntry, "symbolType"))
138  {
139  FcsvDataObject.symbolType = atof(headerEntryValue.c_str());
140  }
141  else if (igsioCommon::IsEqualInsensitive(headerEntry, "visibility"))
142  {
143  FcsvDataObject.visibility = atof(headerEntryValue.c_str());
144  }
145  else if (igsioCommon::IsEqualInsensitive(headerEntry, "textScale"))
146  {
147  FcsvDataObject.textScale = atof(headerEntryValue.c_str());
148  }
149  else if (igsioCommon::IsEqualInsensitive(headerEntry, "opacity"))
150  {
151  FcsvDataObject.opacity = atof(headerEntryValue.c_str());
152  }
153  else if (igsioCommon::IsEqualInsensitive(headerEntry, "ambient"))
154  {
155  FcsvDataObject.ambient = atof(headerEntryValue.c_str());
156  }
157  else if (igsioCommon::IsEqualInsensitive(headerEntry, "diffuse"))
158  {
159  FcsvDataObject.diffuse = atof(headerEntryValue.c_str());
160  }
161  else if (igsioCommon::IsEqualInsensitive(headerEntry, "specular"))
162  {
163  FcsvDataObject.specular = atof(headerEntryValue.c_str());
164  }
165  else if (igsioCommon::IsEqualInsensitive(headerEntry, "power"))
166  {
167  FcsvDataObject.power = atof(headerEntryValue.c_str());
168  }
169  else if (igsioCommon::IsEqualInsensitive(headerEntry, "locked"))
170  {
171  FcsvDataObject.locked = atof(headerEntryValue.c_str());
172  }
173  else if (igsioCommon::IsEqualInsensitive(headerEntry, "numberingScheme"))
174  {
175  FcsvDataObject.numberingScheme = atof(headerEntryValue.c_str());
176  }
177  else if (igsioCommon::IsEqualInsensitive(headerEntry, "color"))
178  {
179  std::vector<std::string> elems;
180  igsioCommon::SplitStringIntoTokens(headerEntryValue, ',', elems);
181 
182  FcsvDataObject.color[0] = atof(elems[0].c_str());
183  FcsvDataObject.color[1] = atof(elems[1].c_str());
184  FcsvDataObject.color[2] = atof(elems[2].c_str());
185  }
186  else if (igsioCommon::IsEqualInsensitive(headerEntry, "selectedColor"))
187  {
188  std::vector<std::string> elems;
189  igsioCommon::SplitStringIntoTokens(headerEntryValue, ',', elems);
190 
191  FcsvDataObject.selectedColor[0] = atof(elems[0].c_str());
192  FcsvDataObject.selectedColor[1] = atof(elems[1].c_str());
193  FcsvDataObject.selectedColor[2] = atof(elems[2].c_str());
194  }
195  else if (igsioCommon::IsEqualInsensitive(headerEntry, "columns"))
196  {
197  std::vector<std::string> elems;
198  igsioCommon::SplitStringIntoTokens(headerEntryValue, ' ', elems);
199  }
200 }
201 
202 //----------------------------------------------------------------------------
203 void vtkFcsvReader::StripCharsFromString(std::string& str, const std::string& chars)
204 {
205  for (unsigned int i = 0; i < chars.size(); ++i)
206  {
207  // you need include <algorithm> to use general algorithms like std::remove()
208  str.erase(std::remove(str.begin(), str.end(), chars[i]), str.end());
209  }
210 }
int numPoints
Definition: vtkFcsvReader.h:43
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
void ProcessHeaderEntry(const std::string &headerEntry, const std::string &headerEntryValue)
float opacity
Definition: vtkFcsvReader.h:51
int numberingScheme
Definition: vtkFcsvReader.h:58
const char int line
Definition: phidget22.h:2458
void Update(void)
virtual ~vtkFcsvReader()
double position[3]
Definition: vtkFcsvReader.h:29
std::string name
Definition: vtkFcsvReader.h:42
void StripCharsFromString(std::string &str, const std::string &chars)
float diffuse
Definition: vtkFcsvReader.h:53
float version
Definition: vtkFcsvReader.h:47
float color[3]
Definition: vtkFcsvReader.h:49
float specular
Definition: vtkFcsvReader.h:54
for i
float power
Definition: vtkFcsvReader.h:55
int visibility
Definition: vtkFcsvReader.h:31
int symbolScale
Definition: vtkFcsvReader.h:44
int visibility
Definition: vtkFcsvReader.h:46
float selectedColor[3]
Definition: vtkFcsvReader.h:50
std::vector< std::string > columns
Definition: vtkFcsvReader.h:57
std::string FileName
std::vector< FcsvPoint > points
Definition: vtkFcsvReader.h:59
float textScale
Definition: vtkFcsvReader.h:48
std::string label
Definition: vtkFcsvReader.h:28
Describes a single fiducial point.
Definition: vtkFcsvReader.h:25
#define MAXFLDS
float ambient
Definition: vtkFcsvReader.h:52
std::string filePath
Definition: vtkFcsvReader.h:41
FcsvData FcsvDataObject
int symbolType
Definition: vtkFcsvReader.h:45
vtkStandardNewMacro(vtkFcsvReader)