xmsstamper  1.0
XmStamperIo.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
5 //
8 //------------------------------------------------------------------------------
9 
10 //----- Included files ---------------------------------------------------------
11 
12 // 1. Precompiled header
13 
14 // 2. My own header
16 
17 // 3. Standard library headers
18 #include <array>
19 #include <fstream> // std::ofstream
20 #include <sstream> // std::stringstream
21 
22 // 4. External library headers
23 #include <boost/archive/text_iarchive.hpp>
24 #include <boost/archive/text_oarchive.hpp>
25 
26 // 5. Shared code headers
27 #include <xmscore/misc/StringUtil.h> // stEqualNoCase
28 #include <xmscore/misc/XmError.h> // XM_ENSURE_TRUE
29 #include <xmscore/misc/xmstype.h> // XM_NODATA
31 
32 // 6. Non-shared code headers
33 
34 //----- Forward declarations ---------------------------------------------------
35 
36 //----- External globals -------------------------------------------------------
37 
38 //----- Namespace declaration --------------------------------------------------
39 namespace xms
40 {
41 //----- Constants / Enumerations -----------------------------------------------
42 
43 //----- Classes / Structs ------------------------------------------------------
44 
45 //----- Internal functions -----------------------------------------------------
46 namespace
47 {
48 void iWriteVecIntToFile(std::ofstream &a_file, const std::string &a_cardName, const VecInt &a_vals);
49 bool iReadVecIntFromFile(std::ifstream &a_file, VecInt &a_vals);
50 }
51 
52 //----- Class / Function definitions -------------------------------------------
53 namespace
54 {
55 //------------------------------------------------------------------------------
58 //------------------------------------------------------------------------------
59 int& iPrecision()
60 {
61  static int m_precision(10);
62  return m_precision;
63 } // iPrecision
64 //------------------------------------------------------------------------------
69 //------------------------------------------------------------------------------
70 std::string iDblToStr(double a_)
71 {
72  return STRstd(a_, -1, iPrecision(), STR_FULLWIDTH);
73 } // iDblToStr
74 //------------------------------------------------------------------------------
76 //------------------------------------------------------------------------------
77 void iWriteVecDblToFile(std::ofstream &a_file, const std::string &a_cardName, const VecDbl &a_vals)
78 {
79  XM_ENSURE_TRUE(a_file.is_open());
80  a_file << a_cardName + " " << a_vals.size() << " ";
81  for (const auto &val : a_vals)
82  {
83  a_file << iDblToStr(val) << " ";
84  }
85  a_file << "\n";
86 } // iWriteVecDblToFile
87 //------------------------------------------------------------------------------
89 //------------------------------------------------------------------------------
90 bool iReadVecDblFromFile(std::ifstream &a_file, VecDbl &a_vals)
91 {
92  XM_ENSURE_TRUE(a_file.is_open(), false);
93  int num(0);
94  XM_ENSURE_TRUE(a_file >> num, false);
95  a_vals.assign(num, 0);
96  for (auto &val : a_vals)
97  {
98  XM_ENSURE_TRUE(a_file >> val, false);
99  }
100  return true;
101 } // iReadVecDblFromFile
102 //------------------------------------------------------------------------------
104 //------------------------------------------------------------------------------
105 void iWriteVecPt3dToFile(std::ofstream &a_file, const std::string &a_cardName, const VecPt3d &a_pts)
106 {
107  XM_ENSURE_TRUE(a_file.is_open());
108  a_file << a_cardName + " " << a_pts.size() << "\n";
109  for (const auto &pt : a_pts)
110  {
111  a_file << iDblToStr(pt.x) << " " << iDblToStr(pt.y) << " " << iDblToStr(pt.z) << "\n";
112  }
113 } // iWriteVecPt3dToFile
114 //------------------------------------------------------------------------------
116 //------------------------------------------------------------------------------
117 bool iReadVecPt3dFromFile(std::ifstream &a_file, VecPt3d &a_pts)
118 {
119  XM_ENSURE_TRUE(a_file.is_open(), false);
120  int numPts(0);
121  XM_ENSURE_TRUE(a_file >> numPts, false);
122  a_pts.assign(numPts, xms::Pt3d());
123  for (auto &pt : a_pts)
124  {
125  XM_ENSURE_TRUE(a_file >> pt.x >> pt.y, false);
126  if (a_file.peek() != '\n')
127  {
128  XM_ENSURE_TRUE(a_file >> pt.z, false);
129  }
130  }
131  return true;
132 } // iReadVecPt3dFromFile
133 //------------------------------------------------------------------------------
135 //------------------------------------------------------------------------------
136 void iWriteVecInt2dToFile(std::ofstream &a_file, const std::string &a_cardName, const VecInt2d &a_vals)
137 {
138  XM_ENSURE_TRUE(a_file.is_open());
139  a_file << a_cardName + " " << a_vals.size() << "\n";
140  for (const auto &valArray : a_vals)
141  {
142  iWriteVecIntToFile(a_file, "", valArray);
143  }
144 } // iWriteVecInt2dToFile
145 //------------------------------------------------------------------------------
147 //------------------------------------------------------------------------------
148 bool iReadVecInt2dFromFile(std::ifstream &a_file, VecInt2d &a_vals)
149 {
150  XM_ENSURE_TRUE(a_file.is_open(), false);
151  int num(0);
152  XM_ENSURE_TRUE(a_file >> num, false);
153  a_vals.assign(num, VecInt());
154  for (auto &valArray : a_vals)
155  {
156  XM_ENSURE_TRUE(iReadVecIntFromFile(a_file, valArray), false);
157  }
158  return true;
159 } // iReadVecInt2dFromFile
160 //------------------------------------------------------------------------------
162 //------------------------------------------------------------------------------
163 void iWriteVecIntToFile(std::ofstream &a_file, const std::string &a_cardName, const VecInt &a_vals)
164 {
165  XM_ENSURE_TRUE(a_file.is_open());
166  const std::string card(a_cardName.empty() ? "" : a_cardName + " ");
167  a_file << card << a_vals.size() << " ";
168  for (const auto &val : a_vals)
169  {
170  a_file << val << " ";
171  }
172  a_file << "\n";
173 } // iWriteVecIntToFile
174 //------------------------------------------------------------------------------
176 //------------------------------------------------------------------------------
177 bool iReadVecIntFromFile(std::ifstream &a_file, VecInt &a_vals)
178 {
179  XM_ENSURE_TRUE(a_file.is_open(), false);
180  int num(0);
181  XM_ENSURE_TRUE(a_file >> num, false);
182  a_vals.assign(num, 0);
183  for (auto &val : a_vals)
184  {
185  XM_ENSURE_TRUE(a_file >> val, false);
186  }
187  return true;
188 } // iReadVecIntFromFile
189 //------------------------------------------------------------------------------
191 //------------------------------------------------------------------------------
192 void iWriteTinToFile(std::ofstream &a_file, const std::string &a_cardName, const BSHP<const TrTin> &a_tin)
193 {
194  XM_ENSURE_TRUE(a_file.is_open());
195  a_file << a_cardName + "\n";
196  const VecPt3d& points = a_tin->Points();
197  iWriteVecPt3dToFile(a_file, "POINTS", points);
198 
199  VecInt vTri = a_tin->Triangles();
200  std::vector<std::array<int, 3>> sortableTris;
201  // sort the triangles so that the point with the lowest index is first and then sort all
202  // triangles
203  for (size_t i = 0; i < vTri.size(); i += 3)
204  {
205  std::array<int, 3> tri = { -1, -1, -1 };
206  tri[0] = vTri[i + 0];
207  tri[1] = vTri[i + 1];
208  tri[2] = vTri[i + 2];
209  auto minIter = tri.begin();
210  if (tri[1] < tri[0] && tri[1] < tri[2])
211  minIter += 1;
212  else if (tri[2] < tri[0] && tri[2] < tri[1])
213  minIter += 2;
214  std::rotate(tri.begin(), minIter, tri.begin() + 3);
215  sortableTris.push_back(tri);
216  }
217  std::sort(sortableTris.begin(), sortableTris.end());
218  auto it = sortableTris.begin();
219  for (size_t i = 0; i < vTri.size(); i += 3, ++it)
220  {
221  vTri[i + 0] = (*it)[0];
222  vTri[i + 1] = (*it)[1];
223  vTri[i + 2] = (*it)[2];
224  }
225  a_file << "TRIANGLES " << vTri.size() << "\n";
226  for (size_t i = 0; i < vTri.size(); i += 3)
227  {
228  a_file << std::setw(10) << vTri[i + 0] << " "
229  << std::setw(10) << vTri[i + 1] << " "
230  << std::setw(10) << vTri[i + 2] << "\n";
231  }
232  //const VecInt2d& trisAdjToPts = a_tin->TrisAdjToPts();
233  a_file << "TRIS_ADJ_TO_PTS 0\n";
234  //iWriteVecInt2dToFile(a_file, "TRIS_ADJ_TO_PTS", trisAdjToPts);
235 } // iWriteTinToFile
236 //------------------------------------------------------------------------------
238 //------------------------------------------------------------------------------
239 bool iReadTinFromFile(std::ifstream &a_file, const BSHP<TrTin> &a_tin)
240 {
241  XM_ENSURE_TRUE(a_file.is_open(), false);
242  std::string card;
243  XM_ENSURE_TRUE(a_file >> card, false);
244  XM_ENSURE_TRUE(stEqualNoCase(card, "POINTS"), false);
245  XM_ENSURE_TRUE(iReadVecPt3dFromFile(a_file, a_tin->Points()), false);
246  XM_ENSURE_TRUE(a_file >> card, false);
247  XM_ENSURE_TRUE(stEqualNoCase(card, "TRIANGLES"), false);
248  XM_ENSURE_TRUE(iReadVecIntFromFile(a_file, a_tin->Triangles()), false);
249  XM_ENSURE_TRUE(a_file >> card, false);
250  XM_ENSURE_TRUE(stEqualNoCase(card, "TRIS_ADJ_TO_PTS"), false);
251  XM_ENSURE_TRUE(iReadVecInt2dFromFile(a_file, a_tin->TrisAdjToPts()), false);
252  // always just build this. The default behavior is to not write this array to the file
253  a_tin->BuildTrisAdjToPts();
254  return true;
255 } // iReadTinFromFile
256 }
257 //------------------------------------------------------------------------------
267 //------------------------------------------------------------------------------
268 XmStampRaster::XmStampRaster(const int a_numPixelsX, const int a_numPixelsY, const double a_pixelSizeX,
269  const double a_pixelSizeY, const Pt3d &a_min, const std::vector<double> &a_vals, const int a_noData)
270  : m_numPixelsX(a_numPixelsX)
271  , m_numPixelsY(a_numPixelsY)
272  , m_pixelSizeX(a_pixelSizeX)
273  , m_pixelSizeY(a_pixelSizeY)
274  , m_min(a_min)
275  , m_vals(a_vals)
276  , m_noData(a_noData)
277 {
278 } // XmStampRaster::XmStampRaster
279 //------------------------------------------------------------------------------
281 //------------------------------------------------------------------------------
283  : m_numPixelsX(0)
284  , m_numPixelsY(0)
285  , m_pixelSizeX(0.0)
286  , m_pixelSizeY(0.0)
287  , m_min()
288  , m_vals()
289  , m_noData(XM_NODATA)
290 {
291 } // XmStampRaster::XmStampRaster
292 //------------------------------------------------------------------------------
297 //------------------------------------------------------------------------------
298 int XmStampRaster::GetCellIndexFromColRow(const int a_col, const int a_row) const
299 {
300  if (a_col >= 0 && a_col < m_numPixelsX && a_row >= 0 && a_row < m_numPixelsY)
301  {
302  return a_row * m_numPixelsX + a_col;
303  }
304  return -1;
305 } // XmStampRaster::GetCellIndexFromColRow
306 //------------------------------------------------------------------------------
311 //------------------------------------------------------------------------------
312 void XmStampRaster::GetColRowFromCellIndex(const int a_index, int &a_col, int &a_row) const
313 {
314  a_row = a_col = -1;
315  if (a_index > 0 && a_index < m_numPixelsX * m_numPixelsY)
316  {
317  a_col = a_index % m_numPixelsX;
318  a_row = a_index / m_numPixelsX;
319  }
320 } // XmStampRaster::GetColRowFromCellIndex
321  //------------------------------------------------------------------------------
325 //------------------------------------------------------------------------------
327 {
328  int col, row;
329  GetColRowFromCellIndex(a_index, col, row);
330  if (col >= 0 && row >= 0)
331  {
332  Pt3d loc;
333  loc.x = m_min.x + col * m_pixelSizeX;
334  loc.y = m_min.y + (m_numPixelsY - 1 - row) * m_pixelSizeY;
335  return loc;
336  }
337  return m_min;
338 } // XmStampRaster::GetLocationFromCellIndex
339 //------------------------------------------------------------------------------
343 //------------------------------------------------------------------------------
344 void XmStampRaster::WriteGridFile(const std::string &a_fileName,
345  const XmRasterFormatEnum a_format)
346 {
347  std::ofstream outGrid(a_fileName, std::ofstream::trunc);
348  XM_ENSURE_TRUE(outGrid.is_open());
349  switch (a_format)
350  {
351  case RS_ARCINFO_ASCII:
352  outGrid << "ncols " << m_numPixelsX << std::endl;
353  outGrid << "nrows " << m_numPixelsY << std::endl;
354  outGrid << "xllcorner " << std::fixed << std::setprecision(13) << m_min.x - m_pixelSizeX / 2.0 << std::endl;
355  outGrid << "yllcorner " << m_min.y - m_pixelSizeY / 2.0 << std::endl;
356  outGrid << "cellsize " << m_pixelSizeX << std::endl;
357  outGrid << "NODATA_value " << m_noData << std::endl;
358  outGrid << std::setprecision(2);
359  int count = 0;
360  for (const double v : m_vals)
361  {
362  outGrid << v << " ";
363  ++count;
364  if (count % m_numPixelsX == 0)
365  outGrid << std::endl;
366  }
367  break;
368  }
369 } // XmStampRaster::WriteGridFile
370 //------------------------------------------------------------------------------
374 //------------------------------------------------------------------------------
375 void XmStampRaster::WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
376 {
377  XM_ENSURE_TRUE(a_file.is_open());
378  a_file << a_cardName + "\n"; // Not sure we should be writing this since we don't read it.
379  a_file << "NUM_PIXELS_X " << m_numPixelsX << "\n";
380  a_file << "NUM_PIXELS_Y " << m_numPixelsY << "\n";
381  a_file << "PIXEL_SIZE_X " << std::fixed << std::setprecision(13) << m_pixelSizeX << "\n";
382  a_file << "PIXEL_SIZE_Y " << m_pixelSizeY << "\n";
383  a_file << "MIN_X " << m_min.x << "\n";
384  a_file << "MIN_Y " << m_min.y << "\n";
385  iWriteVecDblToFile(a_file, "VALS", m_vals);
386  a_file << "NODATA " << m_noData;
387 } // XmStampRaster::WriteToFile
388 //------------------------------------------------------------------------------
392 //------------------------------------------------------------------------------
393 bool XmStampRaster::ReadFromFile(std::ifstream &a_file)
394 {
395  XM_ENSURE_TRUE(a_file.is_open(), false);
396  std::string card;
397  XM_ENSURE_TRUE(a_file >> card, false);
398  XM_ENSURE_TRUE(stEqualNoCase(card, "NUM_PIXELS_X"), false);
399  XM_ENSURE_TRUE(a_file >> m_numPixelsX, false);
400  XM_ENSURE_TRUE(a_file >> card, false);
401  XM_ENSURE_TRUE(stEqualNoCase(card, "NUM_PIXELS_Y"), false);
402  XM_ENSURE_TRUE(a_file >> m_numPixelsY, false);
403  XM_ENSURE_TRUE(a_file >> card, false);
404  XM_ENSURE_TRUE(stEqualNoCase(card, "PIXEL_SIZE_X"), false);
405  XM_ENSURE_TRUE(a_file >> m_pixelSizeX, false);
406  XM_ENSURE_TRUE(a_file >> card, false);
407  XM_ENSURE_TRUE(stEqualNoCase(card, "PIXEL_SIZE_Y"), false);
408  XM_ENSURE_TRUE(a_file >> m_pixelSizeY, false);
409  XM_ENSURE_TRUE(a_file >> card, false);
410  XM_ENSURE_TRUE(stEqualNoCase(card, "MIN_X"), false);
411  XM_ENSURE_TRUE(a_file >> m_min.x, false);
412  XM_ENSURE_TRUE(a_file >> card, false);
413  XM_ENSURE_TRUE(stEqualNoCase(card, "MIN_Y"), false);
414  XM_ENSURE_TRUE(a_file >> m_min.y, false);
415  XM_ENSURE_TRUE(a_file >> card, false);
416  XM_ENSURE_TRUE(stEqualNoCase(card, "VALS"), false);
417  XM_ENSURE_TRUE(iReadVecDblFromFile(a_file, m_vals), false);
418  XM_ENSURE_TRUE(a_file >> card, false);
419  XM_ENSURE_TRUE(stEqualNoCase(card, "NODATA"), false);
420  XM_ENSURE_TRUE(a_file >> m_noData, false);
421  return true;
422 } // XmStampRaster::ReadFromFile
423 //------------------------------------------------------------------------------
427 //------------------------------------------------------------------------------
428 void XmWingWall::WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
429 {
430  XM_ENSURE_TRUE(a_file.is_open());
431  a_file << a_cardName + "\n";
432  a_file << "WING_WALL_ANGLE " << std::fixed << std::setprecision(13) << m_wingWallAngle << "\n";
433 } // XmWingWall::WriteToFile
434 //------------------------------------------------------------------------------
438 //------------------------------------------------------------------------------
439 bool XmWingWall::ReadFromFile(std::ifstream &a_file)
440 {
441  XM_ENSURE_TRUE(a_file.is_open(), false);
442  std::string card;
443  XM_ENSURE_TRUE(a_file >> card, false);
444  XM_ENSURE_TRUE(stEqualNoCase(card, "WING_WALL_ANGLE"), false);
445  XM_ENSURE_TRUE(a_file >> m_wingWallAngle, false);
446  return true;
447 } // XmWingWall::ReadFromFile
448 //------------------------------------------------------------------------------
452 //------------------------------------------------------------------------------
453 void XmSlopedAbutment::WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
454 {
455  XM_ENSURE_TRUE(a_file.is_open());
456  a_file << a_cardName + "\n";
457  a_file << "MAX_X " << std::fixed << std::setprecision(13) << m_maxX << "\n";
458  iWriteVecPt3dToFile(a_file, "SLOPE", m_slope);
459 } // XmSlopedAbutment::WriteToFile
460 //------------------------------------------------------------------------------
464 //------------------------------------------------------------------------------
465 bool XmSlopedAbutment::ReadFromFile(std::ifstream &a_file)
466 {
467  XM_ENSURE_TRUE(a_file.is_open(), false);
468  std::string card;
469  XM_ENSURE_TRUE(a_file >> card, false);
470  XM_ENSURE_TRUE(stEqualNoCase(card, "MAX_X"), false);
471  XM_ENSURE_TRUE(a_file >> m_maxX, false);
472  XM_ENSURE_TRUE(a_file >> card, false);
473  XM_ENSURE_TRUE(stEqualNoCase(card, "SLOPE"), false);
474  XM_ENSURE_TRUE(iReadVecPt3dFromFile(a_file, m_slope), false);
475  return true;
476 } // XmSlopedAbutment::ReadFromFile
477 //------------------------------------------------------------------------------
481 //------------------------------------------------------------------------------
482 void XmGuidebank::WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
483 {
484  XM_ENSURE_TRUE(a_file.is_open());
485  a_file << a_cardName + "\n";
486  a_file << "SIDE " << m_side << "\n";
487  a_file << "RADIUS_1 " << std::fixed << std::setprecision(13) << m_radius1 << "\n";
488  a_file << "RADIUS_2 " << m_radius2 << "\n";
489  a_file << "WIDTH " << m_width << "\n";
490  a_file << "N_PTS " << m_nPts << "\n";
491 } // XmGuidebank::WriteToFile
492 //------------------------------------------------------------------------------
496 //------------------------------------------------------------------------------
497 bool XmGuidebank::ReadFromFile(std::ifstream &a_file)
498 {
499  XM_ENSURE_TRUE(a_file.is_open(), false);
500  std::string card;
501  XM_ENSURE_TRUE(a_file >> card, false);
502  XM_ENSURE_TRUE(stEqualNoCase(card, "SIDE"), false);
503  XM_ENSURE_TRUE(a_file >> m_side, false);
504  XM_ENSURE_TRUE(a_file >> card, false);
505  XM_ENSURE_TRUE(stEqualNoCase(card, "RADIUS_1"), false);
506  XM_ENSURE_TRUE(a_file >> m_radius1, false);
507  XM_ENSURE_TRUE(a_file >> card, false);
508  XM_ENSURE_TRUE(stEqualNoCase(card, "RADIUS_2"), false);
509  XM_ENSURE_TRUE(a_file >> m_radius2, false);
510  XM_ENSURE_TRUE(a_file >> card, false);
511  XM_ENSURE_TRUE(stEqualNoCase(card, "WIDTH"), false);
512  XM_ENSURE_TRUE(a_file >> m_width, false);
513  XM_ENSURE_TRUE(a_file >> card, false);
514  XM_ENSURE_TRUE(stEqualNoCase(card, "N_PTS"), false);
515  XM_ENSURE_TRUE(a_file >> m_nPts, false);
516  return true;
517 } // XmGuidebank::ReadFromFile
518 //------------------------------------------------------------------------------
522 //------------------------------------------------------------------------------
523 void XmStamperEndCap::WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
524 {
525  XM_ENSURE_TRUE(a_file.is_open());
526  a_file << a_cardName + "\n";
527  a_file << "TYPE " << m_type << "\n";
528  a_file << "ANGLE " << std::fixed << std::setprecision(13) << m_angle << "\n";
529  m_guidebank.WriteToFile(a_file, "GUIDEBANK");
530  m_slopedAbutment.WriteToFile(a_file, "SLOPED_ABUTMENT");
531  m_wingWall.WriteToFile(a_file, "WING_WALL");
532 } // XmStamperEndCap::WriteToFile
533 //------------------------------------------------------------------------------
537 //------------------------------------------------------------------------------
538 bool XmStamperEndCap::ReadFromFile(std::ifstream &a_file)
539 {
540  XM_ENSURE_TRUE(a_file.is_open(), false);
541  std::string card;
542  XM_ENSURE_TRUE(a_file >> card, false);
543  XM_ENSURE_TRUE(stEqualNoCase(card, "TYPE"), false);
544  XM_ENSURE_TRUE(a_file >> m_type, false);
545  XM_ENSURE_TRUE(a_file >> card, false);
546  XM_ENSURE_TRUE(stEqualNoCase(card, "ANGLE"), false);
547  XM_ENSURE_TRUE(a_file >> m_angle, false);
548  XM_ENSURE_TRUE(a_file >> card, false);
549  XM_ENSURE_TRUE(stEqualNoCase(card, "GUIDEBANK"), false);
550  XM_ENSURE_TRUE(m_guidebank.ReadFromFile(a_file), false);
551  XM_ENSURE_TRUE(a_file >> card, false);
552  XM_ENSURE_TRUE(stEqualNoCase(card, "SLOPED_ABUTMENT"), false);
554  XM_ENSURE_TRUE(a_file >> card, false);
555  XM_ENSURE_TRUE(stEqualNoCase(card, "WING_WALL"), false);
556  XM_ENSURE_TRUE(m_wingWall.ReadFromFile(a_file), false);
557  return true;
558 } // XmStamperEndCap::ReadFromFile
559 //------------------------------------------------------------------------------
563 //------------------------------------------------------------------------------
564 void XmStampCrossSection::WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
565 {
566  XM_ENSURE_TRUE(a_file.is_open());
567  a_file << a_cardName + "\n";
568  iWriteVecPt3dToFile(a_file, "LEFT", m_left);
569  a_file << "LEFT_MAX " << std::fixed << std::setprecision(13) << m_leftMax << "\n";
570  a_file << "IDX_LEFT_SHOULDER " << m_idxLeftShoulder << "\n";
571  iWriteVecPt3dToFile(a_file, "RIGHT", m_right);
572  a_file << "RIGHT_MAX " << std::fixed << std::setprecision(13) << m_rightMax << "\n";
573  a_file << "IDX_RIGHT_SHOULDER " << m_idxRightShoulder << "\n";
574 } // XmStampCrossSection::WriteToFile
575 //------------------------------------------------------------------------------
579 //------------------------------------------------------------------------------
580 bool XmStampCrossSection::ReadFromFile(std::ifstream &a_file)
581 {
582  XM_ENSURE_TRUE(a_file.is_open(), false);
583  std::string card;
584  XM_ENSURE_TRUE(a_file >> card, false);
585  XM_ENSURE_TRUE(stEqualNoCase(card, "CS"), false);
586  XM_ENSURE_TRUE(a_file >> card, false);
587  XM_ENSURE_TRUE(stEqualNoCase(card, "LEFT"), false);
588  XM_ENSURE_TRUE(iReadVecPt3dFromFile(a_file, m_left), false);
589  XM_ENSURE_TRUE(a_file >> card, false);
590  XM_ENSURE_TRUE(stEqualNoCase(card, "LEFT_MAX"), false);
591  XM_ENSURE_TRUE(a_file >> m_leftMax, false);
592  XM_ENSURE_TRUE(a_file >> card, false);
593  XM_ENSURE_TRUE(stEqualNoCase(card, "IDX_LEFT_SHOULDER"), false);
594  XM_ENSURE_TRUE(a_file >> m_idxLeftShoulder, false);
595  XM_ENSURE_TRUE(a_file >> card, false);
596  XM_ENSURE_TRUE(stEqualNoCase(card, "RIGHT"), false);
597  XM_ENSURE_TRUE(iReadVecPt3dFromFile(a_file, m_right), false);
598  XM_ENSURE_TRUE(a_file >> card, false);
599  XM_ENSURE_TRUE(stEqualNoCase(card, "RIGHT_MAX"), false);
600  XM_ENSURE_TRUE(a_file >> m_rightMax, false);
601  XM_ENSURE_TRUE(a_file >> card, false);
602  XM_ENSURE_TRUE(stEqualNoCase(card, "IDX_RIGHT_SHOULDER"), false);
603  XM_ENSURE_TRUE(a_file >> m_idxRightShoulder, false);
604  return true;
605 } // XmStampCrossSection::ReadFromFile
606 //------------------------------------------------------------------------------
610 //------------------------------------------------------------------------------
611 void XmStamperIo::WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
612 {
613  XM_ENSURE_TRUE(a_file.is_open());
614  a_file << a_cardName + "\n";
615  iWriteVecPt3dToFile(a_file, "CENTER_LINE", m_centerLine);
616  a_file << "STAMPING_TYPE " << m_stampingType << "\n";
617  a_file << "CROSS_SECTIONS " << m_cs.size() << "\n";
618  for (const auto &cs : m_cs)
619  {
620  cs.WriteToFile(a_file, "CS");
621  }
622  m_firstEndCap.WriteToFile(a_file, "FIRST_END_CAP");
623  m_lastEndCap.WriteToFile(a_file, "LAST_END_CAP");
624  if (m_bathymetry)
625  {
626  iWriteTinToFile(a_file, "BATHYMETRY", m_bathymetry);
627  }
628  if (m_outTin)
629  {
630  iWriteTinToFile(a_file, "OUT_TIN", m_outTin);
631  }
632  iWriteVecInt2dToFile(a_file, "OUT_BREAK_LINES", m_outBreakLines);
633  m_raster.WriteToFile(a_file, "RASTER");
634 } // XmStamperIo::WriteToFile
635 //------------------------------------------------------------------------------
639 //------------------------------------------------------------------------------
640 bool XmStamperIo::ReadFromFile(std::ifstream &a_file)
641 {
642  XM_ENSURE_TRUE(a_file.is_open(), false);
643  std::string card;
644  while (a_file >> card)
645  {
646  if (stEqualNoCase(card, "CENTER_LINE"))
647  {
648  XM_ENSURE_TRUE(iReadVecPt3dFromFile(a_file, m_centerLine), false);
649  }
650  else if (stEqualNoCase(card, "STAMPING_TYPE"))
651  {
652  XM_ENSURE_TRUE(a_file >> m_stampingType, false);
653  }
654  else if (stEqualNoCase(card, "CROSS_SECTIONS"))
655  {
656  int numCs(0);
657  XM_ENSURE_TRUE(a_file >> numCs, false);
658  m_cs.assign(numCs, XmStampCrossSection());
659  for (auto &cs : m_cs)
660  {
661  XM_ENSURE_TRUE(cs.ReadFromFile(a_file), false);
662  }
663  }
664  else if (stEqualNoCase(card, "FIRST_END_CAP"))
665  {
666  XM_ENSURE_TRUE(m_firstEndCap.ReadFromFile(a_file), false);
667  }
668  else if (stEqualNoCase(card, "LAST_END_CAP"))
669  {
670  XM_ENSURE_TRUE(m_lastEndCap.ReadFromFile(a_file), false);
671  }
672  else if (stEqualNoCase(card, "BATHYMETRY"))
673  {
675  XM_ENSURE_TRUE(iReadTinFromFile(a_file, m_bathymetry), false);
676  }
677  else if (stEqualNoCase(card, "OUT_TIN"))
678  {
679  m_outTin = TrTin::New();
680  XM_ENSURE_TRUE(iReadTinFromFile(a_file, m_outTin), false);
681  }
682  else if (stEqualNoCase(card, "OUT_BREAK_LINES"))
683  {
684  XM_ENSURE_TRUE(iReadVecInt2dFromFile(a_file, m_outBreakLines), false);
685  }
686  else if (stEqualNoCase(card, "RASTER"))
687  {
688  XM_ENSURE_TRUE(m_raster.ReadFromFile(a_file), false);
689  }
690  else
691  {
692  XM_ASSERT(0);
693  }
694  }
695  return true;
696 } // XmStamperIo::ReadFromFile
697 //------------------------------------------------------------------------------
700 //------------------------------------------------------------------------------
702 {
703  iPrecision() = a_precision;
704 } // XmStamperIo::SetPrecisionForOutput
705 
706 } // namespace xms
bool ReadFromFile(std::ifstream &a_file)
Reads the XmStampCrossSection class information to a file.
std::vector< int > VecInt
BSHP< TrTin > m_bathymetry
underlying bathymetry
Definition: XmStamperIo.h:199
int m_numPixelsY
Number of pixels in the Y-direction (Required)
Definition: XmStamperIo.h:42
VecPt3d m_left
left side of the cross section
Definition: XmStamperIo.h:156
int m_idxRightShoulder
index to the shoulder point in the m_right vector
Definition: XmStamperIo.h:162
VecInt2d m_outBreakLines
break lines that are honored in the TIN
Definition: XmStamperIo.h:205
double m_radius2
second radius (R2) for guidebank creation
Definition: XmStamperIo.h:110
std::string STRstd(double a_value, int a_n, int width, int flags)
void WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
Writes the XmStamperEndCap class information to a file.
std::vector< double > VecDbl
void WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
Writes the XmWingWall class information to a file.
void WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
Writes the XmStampCrossSection class information to a file.
Pt3d GetLocationFromCellIndex(const int a_index) const
Gets the location of the cell center from the zero-based cell index.
XmStamperEndCap m_firstEndCap
end cap at beginnig of polyline
Definition: XmStamperIo.h:195
double m_leftMax
max x value for left side
Definition: XmStamperIo.h:157
bool ReadFromFile(std::ifstream &a_file)
Reads the XmStampRaster class information to a file.
void GetColRowFromCellIndex(const int a_index, int &a_col, int &a_row) const
Gets the zero-based column and row from the cell index.
double m_pixelSizeX
Pixel size in the X-direction (Required)
Definition: XmStamperIo.h:43
XmStampRaster m_raster
Input/output raster to stamp the resulting elevations onto this raster.
Definition: XmStamperIo.h:207
void WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
Writes the XmSlopedAbutment class information to a file.
int GetCellIndexFromColRow(const int a_col, const int a_row) const
Gets the zero-based cell index from the given column and row.
int m_numPixelsX
Number of pixels in the X-direction (Required)
Definition: XmStamperIo.h:41
bool ReadFromFile(std::ifstream &a_file)
Reads the XmWingWall class information to a file.
double m_maxX
max distance from center line
Definition: XmStamperIo.h:86
std::vector< VecInt > VecInt2d
XmStamperEndCap m_lastEndCap
end cap at end of polyline
Definition: XmStamperIo.h:197
void WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
Writes the XmGuidebank class information to a file.
void WriteGridFile(const std::string &a_fileName, const XmRasterFormatEnum a_format)
Writes the raster in the given format to the given filename.
static BSHP< TrTin > New()
double m_pixelSizeY
Pixel size in the Y-direction (Required)
Definition: XmStamperIo.h:44
bool ReadFromFile(std::ifstream &a_file)
Reads the XmStamperIo class information from a file.
int m_noData
NO DATA value for the raster (typically XM_NODATA)
Definition: XmStamperIo.h:48
#define XM_ENSURE_TRUE(...)
int m_side
position of guidebank relative to center line, 0-left, 1-right
Definition: XmStamperIo.h:108
Pt3d m_min
Minimum (lower left) X, Y coordinate of the raster at the center of the raster cell (Required) ...
Definition: XmStamperIo.h:45
XmWingWall m_wingWall
wing wall definition
Definition: XmStamperIo.h:133
XmGuidebank m_guidebank
guidebank definition
Definition: XmStamperIo.h:131
double m_wingWallAngle
degrees from 0 to 60
Definition: XmStamperIo.h:68
std::vector< double > m_vals
Definition: XmStamperIo.h:46
double m_rightMax
max x value for right side
Definition: XmStamperIo.h:161
#define XM_NODATA
BSHP< TrTin > m_outTin
Definition: XmStamperIo.h:203
VecPt3d m_right
right side of the cross section
Definition: XmStamperIo.h:160
int m_type
type of end cap: 0- guidebank, 1- sloped abutment, 2- wing wall
Definition: XmStamperIo.h:129
#define XM_ASSERT(x)
XmStampRaster()
Default Constructor.
void WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
Writes the XmStamperIo class information to a file.
bool stEqualNoCase(const std::string &a, const std::string &b)
void SetPrecisionForOutput(int a_precision)
Sets the precision for stamper output.
int m_nPts
number of points created along the center line to create the guidebank
Definition: XmStamperIo.h:112
void WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
Writes the XmStampRaster class information to a file.
Cross section definition for stamping.
Definition: XmStamperIo.h:142
std::vector< XmStampCrossSection > m_cs
cross sections along the polyLine
Definition: XmStamperIo.h:193
double m_angle
degrees from -45 to 45
Definition: XmStamperIo.h:130
VecPt3d m_slope
x,y pairs defining slope from center line
Definition: XmStamperIo.h:87
bool ReadFromFile(std::ifstream &a_file)
Reads the XmSlopedAbutment class information to a file.
bool ReadFromFile(std::ifstream &a_file)
Reads the XmGuidebank class information to a file.
XmRasterFormatEnum
/breif enum the identify the format of the raster
Definition: XmStamperIo.h:40
double m_width
width of guidebank about the center line
Definition: XmStamperIo.h:111
int m_stampingType
Stamping type 0 - Cut, 1 - Fill, 2 - Both.
Definition: XmStamperIo.h:191
XmSlopedAbutment m_slopedAbutment
sloped abutment definition
Definition: XmStamperIo.h:132
bool ReadFromFile(std::ifstream &a_file)
Reads the XmStamperEndCap class information to a file.
std::vector< Pt3d > VecPt3d
double m_radius1
first radius (R1) for guidebank creation
Definition: XmStamperIo.h:109
VecPt3d m_centerLine
Definition: XmStamperIo.h:189