xmsstamper  1.0
XmStampTests.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
15 
16 // 3. Standard library headers
17 
18 // 4. External library headers
19 
20 // 5. Shared code headers
21 
22 // 6. Non-shared code headers
23 
24 //----- Forward declarations ---------------------------------------------------
25 
26 //----- External globals -------------------------------------------------------
27 
28 //----- Namespace declaration --------------------------------------------------
29 
30 //----- Constants / Enumerations -----------------------------------------------
31 
32 //----- Classes / Structs ------------------------------------------------------
33 
34 //----- Internal functions -----------------------------------------------------
35 
36 //----- Class / Function definitions -------------------------------------------
37 
38 #ifdef CXX_TEST
39 //------------------------------------------------------------------------------
40 // Unit Tests
41 //------------------------------------------------------------------------------
43 
44 #include <fstream>
45 
46 #include <xmscore/misc/StringUtil.h> // stEqualNoCase
47 #include <xmscore/misc/XmError.h> // XM_ENSURE_TRUE
48 #include <xmscore/misc/xmstype.h> // XM_NODATA
50 
55 
56 using namespace xms;
57 namespace
58 {
59 //------------------------------------------------------------------------------
61 //------------------------------------------------------------------------------
62 static void iBuildStamperIo(const std::string& a_path, XmStamperIo& a_io)
63 {
64  std::string fname(a_path + "xmsng_StamperIo.txt");
65  std::ifstream is(fname.c_str());
66  XM_ENSURE_TRUE(is.is_open());
67  std::string card;
68  XM_ENSURE_TRUE(is >> card);
69  XM_ENSURE_TRUE(stEqualNoCase(card, "STAMPER_IO_VERSION_1"));
70  XM_ENSURE_TRUE(a_io.ReadFromFile(is));
71  // Test to make sure we are reading the XmStamperIo files correctly
72  std::ofstream outFile(a_path + "StamperIo_out.txt");
73  a_io.WriteToFile(outFile, "STAMPER_IO_VERSION_1");
74  outFile.close();
75  TS_ASSERT_TXT_FILES_EQUAL(a_path + "StamperIo_out.txt", fname);
76 } // iBuildStamperIo
77 //------------------------------------------------------------------------------
79 //------------------------------------------------------------------------------
80 static void iOutputToFile(const std::string& a_fileName, const XmStamperIo &a_io)
81 {
82  std::ofstream ofs(a_fileName);
83  a_io.WriteToFile(ofs, "STAMPER_IO_VERSION_1");
84 } // iOutputToFile
85 //------------------------------------------------------------------------------
87 //------------------------------------------------------------------------------
88 static void iDoTest(const std::string& a_relPath)
89 {
90  std::string path(XMS_TEST_PATH);
91  path += "stamping/" + a_relPath;
92  XmStamperIo io;
93  iBuildStamperIo(path, io);
94  BSHP<XmStamper> s = XmStamper::New();
95  s->DoStamp(io);
96  std::string baseFile(path + "xmsng_base.txt");
97  std::string outFile(path + "xmsng_out.txt");
98  iOutputToFile(outFile, io);
99  std::string outTin(path + "tin_out.tin");
100  if (io.m_outTin && io.m_outTin->NumPoints() > 0)
101  {
102  std::fstream os;
103  os.open(outTin.c_str(), std::fstream::out);
104  io.m_outTin->ExportTinFile(os);
105  }
106  TS_ASSERT_TXT_FILES_EQUAL(baseFile, outFile);
107 } // iDoTest
108 
109 } // unnamed namespace
110 
111 //------------------------------------------------------------------------------
113 //------------------------------------------------------------------------------
115 {
116  iDoTest("test_WingWall01/");
117 } // XmStampIntermediateTests::test_WingWall01
118 //------------------------------------------------------------------------------
120 //------------------------------------------------------------------------------
122 {
123  iDoTest("test_WingWall02/");
124 } // XmStampIntermediateTests::test_WingWall02
125 //------------------------------------------------------------------------------
127 //------------------------------------------------------------------------------
129 {
130  iDoTest("test_WingWall03/");
131 } // XmStampIntermediateTests::test_WingWall03
132 //------------------------------------------------------------------------------
134 //------------------------------------------------------------------------------
136 {
137  iDoTest("test_wingWall04_cut/");
138 } // XmStampIntermediateTests::test_wingWall04_cut
139 //------------------------------------------------------------------------------
141 //------------------------------------------------------------------------------
143 {
144  iDoTest("test_SlopedAbutment01/");
145 } // XmStampIntermediateTests::test_SlopedAbutment01
146 //------------------------------------------------------------------------------
148 //------------------------------------------------------------------------------
150 {
151  iDoTest("test_SlopedAbutment02/");
152 } // XmStampIntermediateTests::test_SlopedAbutment02
153 //------------------------------------------------------------------------------
155 //------------------------------------------------------------------------------
157 {
158  iDoTest("test_SlopedAbutment03/");
159 } // XmStampIntermediateTests::test_SlopedAbutment03
160 //------------------------------------------------------------------------------
162 //------------------------------------------------------------------------------
164 {
165  iDoTest("test_SlopedAbutment04_cut/");
166 } // XmStampIntermediateTests::test_SlopedAbutment04_cut
167 //------------------------------------------------------------------------------
169 //------------------------------------------------------------------------------
171 {
172  std::string path(XMS_TEST_PATH);
173  path += "/stamping/test_intersections/";
174  XmStamperIo io;
175  iBuildStamperIo(path, io);
176  BSHP<XmStamper> s = XmStamper::New();
177  s->DoStamp(io);
178  TS_ASSERT(!io.m_outTin);
179  TS_ASSERT(io.m_outBreakLines.empty());
180  // clear the warning
182  "---Intersection found in stamp outputs. Stamping operation aborted.\n\n");
183 } // XmStampIntermediateTests::test_SelfIntersect
184 //------------------------------------------------------------------------------
186 //------------------------------------------------------------------------------
188 {
189 #ifndef __APPLE__
190  iDoTest("test_GuideBank01/");
191 #endif
192 } // XmStampIntermediateTests::test_GuideBank01
193 //------------------------------------------------------------------------------
195 //------------------------------------------------------------------------------
197 {
198  iDoTest("test_GuideBank02/");
199 } // XmStampIntermediateTests::test_GuideBank02
200 //------------------------------------------------------------------------------
202 //------------------------------------------------------------------------------
204 {
205  iDoTest("test_GuideBank03/");
206 } // XmStampIntermediateTests::test_GuideBank03
207 //------------------------------------------------------------------------------
209 //------------------------------------------------------------------------------
211 {
212  iDoTest("test_GuideBank04/");
213 } // XmStampIntermediateTests::test_GuideBank04
214 //------------------------------------------------------------------------------
216 //------------------------------------------------------------------------------
218 {
219  iDoTest("test_GuideBank05/");
220 } // XmStampIntermediateTests::test_GuideBank05
221 //------------------------------------------------------------------------------
223 //------------------------------------------------------------------------------
225 {
226  iDoTest("test_GuideBank06/");
227 } // XmStampIntermediateTests::test_GuideBank06
228 //------------------------------------------------------------------------------
230 //------------------------------------------------------------------------------
232 {
233  iDoTest("test_GuideBank07/");
234 } // XmStampIntermediateTests::test_GuideBank07
235 //------------------------------------------------------------------------------
237 //------------------------------------------------------------------------------
239 {
240  iDoTest("test_GuideBank08_cut/");
241 } // XmStampIntermediateTests::test_GuideBank08_cut
242 //------------------------------------------------------------------------------
245 //------------------------------------------------------------------------------
247 {
248  iDoTest("test_intersectBathymetry01/");
249 } // XmStampIntermediateTests::test_IntersectBathymetry01
250 //------------------------------------------------------------------------------
252 //------------------------------------------------------------------------------
254 {
255  iDoTest("test_intersectBathymetry02/");
256 } // XmStampIntermediateTests::test_IntersectBathymetry02
257 //------------------------------------------------------------------------------
260 //------------------------------------------------------------------------------
262 {
263  iDoTest("test_intersectBathymetry03/");
264 } // XmStampIntermediateTests::test_IntersectBathymetry03
265 //------------------------------------------------------------------------------
267 //------------------------------------------------------------------------------
269 {
270  iDoTest("test_intersectBathymetry04/");
271 } // XmStampIntermediateTests::test_IntersectBathymetry04
272 //------------------------------------------------------------------------------
274 //------------------------------------------------------------------------------
276 {
277  iDoTest("test_intersectBathymetry05/");
278 } // XmStampIntermediateTests::test_IntersectBathymetry05
279 //------------------------------------------------------------------------------
282 //------------------------------------------------------------------------------
284 {
285  iDoTest("test_intersectBathymetry06/");
286 } // XmStampIntermediateTests::test_IntersectBathymetry06
287 //------------------------------------------------------------------------------
290 //------------------------------------------------------------------------------
292 {
293  iDoTest("test_intersectBathymetry07/");
294 } // XmStampIntermediateTests::test_IntersectBathymetry07
295 //------------------------------------------------------------------------------
298 //------------------------------------------------------------------------------
300 {
301  iDoTest("test_intersectBathymetry08/");
302 } // XmStampIntermediateTests::test_IntersectBathymetry08
303 //------------------------------------------------------------------------------
306 //------------------------------------------------------------------------------
308 {
309 #ifndef __APPLE__
310  iDoTest("test_intersectBathymetry09/");
311 #endif
312 } // XmStampIntermediateTests::test_IntersectBathymetry09
313 //------------------------------------------------------------------------------
316 //------------------------------------------------------------------------------
318 {
319  iDoTest("test_intersectBathymetry10/");
320 } // XmStampIntermediateTests::test_IntersectBathymetry10
321 //------------------------------------------------------------------------------
323 //------------------------------------------------------------------------------
325 {
326  std::vector<double> rasterVals = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
327  XmStampRaster raster(2, 3, 2.0, 1.0, Pt3d(0.0, 0.0), rasterVals, XM_NODATA);
328  TS_ASSERT_EQUALS(raster.GetCellIndexFromColRow(2, 3), -1);
329  const int lastCell = raster.GetCellIndexFromColRow(1, 2);
330  TS_ASSERT_EQUALS(lastCell, 5);
331  TS_ASSERT_EQUALS(raster.m_vals[lastCell], 5.0);
332 } // XmStampIntermediateTests::test_BuildRasterAndGetCellValue
333 #endif
void test_SlopedAbutment02()
Tests stamp operation.
void test_IntersectBathymetry01()
Tests stamp operation. Intersection between shoulder and outer edge of a cross section.
static BSHP< XmStamper > New()
Creates a XmStamper class.
Definition: XmStamper.cpp:558
void test_GuideBank03()
Tests stamp operation.
void test_WingWall03()
Tests stamp operation.
void test_GuideBank06()
Tests stamp operation.
void test_IntersectBathymetry03()
Tests stamp operation. Intersection between center line and shoulder with a more complex cross sectio...
VecInt2d m_outBreakLines
break lines that are honored in the TIN
Definition: XmStamperIo.h:205
void test_WingWall02()
Tests stamp operation.
void test_WingWall01()
Tests stamp operation.
void test_GuideBank04()
Tests stamp operation.
void test_IntersectBathymetry10()
Tests stamp operation. Intersection with guidebank centerline. Cuts off the guidebank right before th...
void test_IntersectBathymetry07()
Tests stamp operation. Intersection with guidebank centerline. Cuts off the guidebank so no guidebank...
void test_GuideBank05()
Tests stamp operation.
void test_SlopedAbutment04_cut()
Tests stamp operation.
int GetCellIndexFromColRow(const int a_col, const int a_row) const
Gets the zero-based cell index from the given column and row.
#define TS_ASSERT_TXT_FILES_EQUAL(a, b)
bool ReadFromFile(std::ifstream &a_file)
Reads the XmStamperIo class information from a file.
void test_GuideBank08_cut()
Tests stamp operation.
#define XM_ENSURE_TRUE(...)
std::vector< double > m_vals
Definition: XmStamperIo.h:46
#define XM_NODATA
BSHP< TrTin > m_outTin
Definition: XmStamperIo.h:203
void test_IntersectBathymetry06()
Tests stamp operation. Both end caps are sloped abutments and they intersect the bathymetry.
Stamping inputs/outputs class.
Definition: XmStamperIo.h:171
void test_GuideBank02()
Tests stamp operation.
void test_IntersectBathymetry04()
Tests stamp operation. Center line intersects bathymetry.
void WriteToFile(std::ofstream &a_file, const std::string &a_cardName) const
Writes the XmStamperIo class information to a file.
#define TS_ASSERT_STACKED_ERRORS(expected)
bool stEqualNoCase(const std::string &a, const std::string &b)
void test_GuideBank07()
Tests stamp operation. angle on the guidebank end cap.
void test_IntersectBathymetry08()
Tests stamp operation. Intersection with guidebank centerline. Cuts off the guidebank partially down ...
void test_SelfIntersect()
Tests stamp operation.
void test_GuideBank01()
Tests stamp operation.
void test_SlopedAbutment01()
Tests stamp operation.
Raster defined using a non-rotated cartesian axis for use in XmStamper.
Definition: XmStamperIo.h:33
void test_IntersectBathymetry02()
Tests stamp operation. Intersection between center line and shoulder.
void test_wingWall04_cut()
Tests stamp operation. Tests a cut stamp.
void test_BuildRasterAndGetCellValue()
Tests building a stamping raster and getting a cell value.
void test_IntersectBathymetry09()
Tests stamp operation. Intersection with guidebank cross section beyond the shoulder.
void test_SlopedAbutment03()
Tests stamp operation.
void test_IntersectBathymetry05()
Tests stamp operation. Center line intersects bathymetry twice.