testCoordinateSystemRegistry.cc
Go to the documentation of this file.
1 
11 #include <fwk/CentralConfig.h>
12 #include <fwk/CoordinateSystemRegistry.h>
13 #include <utl/CoordinateSystem.h>
14 #include <utl/AugerException.h>
15 #include <utl/ReferenceEllipsoid.h>
16 #include <utl/UTMPoint.h>
17 #include <utl/Point.h>
18 #include <utl/AugerUnits.h>
19 #include <cmath>
20 
21 #include <tst/Verify.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 
24 using namespace fwk;
25 using namespace utl;
26 using namespace tst;
27 
28 
29 class CoordinateSystemRegistryTest : public CppUnit::TestFixture {
30 
31  CPPUNIT_TEST_SUITE(CoordinateSystemRegistryTest);
32  CPPUNIT_TEST(testFactory);
33  CPPUNIT_TEST(testPampaAmarilla);
34  CPPUNIT_TEST_EXCEPTION(testInvalidCoordinateSystemException,
36  CPPUNIT_TEST_EXCEPTION(testInitSequenceException, utl::InitSequenceException);
37  CPPUNIT_TEST_SUITE_END();
38 
39 public:
40  void setUp() { }
41 
42  void tearDown() { }
43 
44  void
46  {
47  CentralConfig::GetInstance(BOOTSTRAPFILE);
50  CoordinateSystemRegistry::Get("PampaAmarilla");
53 
55  }
56 
57  void
59  {
60  CentralConfig::GetInstance(BOOTSTRAPFILE);
61  const ReferenceEllipsoid wgs84 = ReferenceEllipsoid::GetWGS84();
62  const CoordinateSystemPtr pampaAmarillaCS =
63  CoordinateSystemRegistry::Get("PampaAmarilla");
64 
65  // Verify the origin of the CS
66  const Point pampaAmarillaOrigin(0, 0, 0, pampaAmarillaCS);
67  const UTMPoint po(pampaAmarillaOrigin, wgs84);
68 
69  CPPUNIT_ASSERT(Verify<CloseTo>(po.GetNorthing(), 6099203.68*m));
70  CPPUNIT_ASSERT(Verify<CloseTo>(po.GetEasting(), 477256.66*m));
71  CPPUNIT_ASSERT(Verify<CloseTo>(po.GetHeight(), 1400*m));
72  CPPUNIT_ASSERT(Verify<Equal>(po.GetZone(), 19));
73  CPPUNIT_ASSERT(Verify<Equal>(po.GetBand(), 'H'));
74 
75  // verify coords in pampaAmarillaCS
76  // fd UTM positions as used in CDAS (ints!)
77  const int fdUTM[][3] = {
78  { 6071872, 459208, 1416 }, // LL
79  { 6094570, 498902, 1415 }, // LM
80  { 6134066, 480747, 1455 }, // LA
81  { 6114142, 445346, 1714 } // CO
82  };
83  // corresponding CDAS XYZ result
84  const double fdXYZ[][3] = {
85  { -18127.757064, -27301.999633, -68.24021981845 }, // LL
86  { 21647.377378, -4690.341619, -23.48079981265 }, // LM
87  { 3580.959833, 34875.225069, -41.4046727005 }, // LA
88  { -31891.59545, 15028.421417, 216.51114439687 } // CO
89  };
90  const double absTolerance[] = { /*X*/ 2*meter, /*Y*/ 2*meter, /*Z*/ 25*centimeter };
91 
92  for (int i = 0; i < 4; ++i) {
93  const UTMPoint fdUTMPos(fdUTM[i][0]*meter, fdUTM[i][1]*meter, fdUTM[i][2]*meter, 19, 'H', wgs84);
94  const Point fdPos(fdUTMPos.GetPoint());
95  const double xDiff = fdPos.GetX(pampaAmarillaCS) - fdXYZ[i][0]*meter;
96  const double yDiff = fdPos.GetY(pampaAmarillaCS) - fdXYZ[i][1]*meter;
97  const double zDiff = fdPos.GetZ(pampaAmarillaCS) - fdXYZ[i][2]*meter;
98  std::cout << i << ". diff X: " << xDiff << " Y: " << yDiff << " Z: " << zDiff << std::endl;
99  CPPUNIT_ASSERT(Verify<CloseTo>(fdPos.GetX(pampaAmarillaCS), fdXYZ[i][0]*meter, absTolerance[0]));
100  CPPUNIT_ASSERT(Verify<CloseTo>(fdPos.GetY(pampaAmarillaCS), fdXYZ[i][1]*meter, absTolerance[1]));
101  CPPUNIT_ASSERT(Verify<CloseTo>(fdPos.GetZ(pampaAmarillaCS), fdXYZ[i][2]*meter, absTolerance[2]));
102  }
103  }
104 
105  void
107  {
108  CentralConfig::GetInstance(BOOTSTRAPFILE);
109  std::cout << "The coordinate system 'XYZ' should not exist and produce an expected error:" << std::endl;
111  }
112 
113  void
115  {
116  std::cout << "Since initialization was already done, we expect an error that ReferenceEllipsoidRegistry is already initialized." << std::endl;
117  CentralConfig::GetInstance(BOOTSTRAPFILE);
119  }
120 
121 };
122 
123 
125 
126 
127 // Configure (x)emacs for this file ...
128 // Local Variables:
129 // mode: c++
130 // End:
constexpr double centimeter
Definition: AugerUnits.h:89
Point object.
Definition: Point.h:32
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
int GetZone() const
Get the zone.
Definition: UTMPoint.h:215
const double meter
Definition: GalacticUnits.h:29
char GetBand() const
Get the band.
Definition: UTMPoint.h:218
void Init()
Initialise the registry.
double GetNorthing() const
Get the northing.
Definition: UTMPoint.h:206
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Exception to use if sequence of initialisations violated.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Reference ellipsoids for UTM transformations.
double GetHeight() const
Get the height.
Definition: UTMPoint.h:212
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
Base class for exceptions in the CoordinateSystemRegistry.
double GetEasting() const
Get the easting.
Definition: UTMPoint.h:209
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
Point GetPoint(const CoordinateSystemPtr &theCS=CoordinateSystemPtr()) const
Get a cartesian point from an UTMPoint.
Definition: UTMPoint.cc:45
constexpr double m
Definition: AugerUnits.h:121

, generated on Tue Sep 26 2023.