TransformFactory.cxx
Go to the documentation of this file.
1 
12 // for wcslib
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16 
17 #ifdef _MSC_VER
18 // for truncation warning
19 // for CLONE_DEFECT
20 #include "msdevstudio/MSconfig.h"
21 #endif //_MSC_VER
22 
24 
25 // List of default Transforms
26 #include "HammerAito.h"
27 #include "HammerAito2.h"
28 #include "Lambert.h"
29 #include "Lambert2.h"
30 #include "Mercator.h"
31 #include "Mercator2.h"
32 #include "Cartesian.h"
33 #include "Cartesian2.h"
34 #include "GlobalSinusoidal.h"
35 #include "GlobalSinusoidal2.h"
36 #include "ARC.h"
37 #include "ARC2.h"
38 #include "TAN.h"
39 #include "TAN2.h"
40 #include "SIN.h"
41 #include "SIN2.h"
42 #include "STG.h"
43 #include "STG2.h"
44 #include "AIR.h"
45 #include "AIR2.h"
46 #include "LinearTransform.h"
47 #include "LogTransform.h"
48 #include "XYTransform.h"
49 #include "XYZTransform.h"
50 
51 #include <iostream>
52 
53 #include <cassert>
54 
55 using std::cout;
56 using std::endl;
57 using std::string;
58 
59 namespace hippodraw {
60 
61 TransformFactory * TransformFactory::s_instance = 0;
62 
64 {
65 }
66 
68 {
69  if ( s_instance == 0 ) {
72  }
73  return s_instance;
74 }
75 
77 {
78  LinearTransform * lt = new LinearTransform ();
79  add ( lt );
80  add ( new LogTransform () );
81  add ( new XYTransform ( lt, lt, lt ) );
82 #ifdef HAVE_WCSLIB
83  add ( new HammerAito ( lt ) );
84  add ( new HammerAito2 ( lt ) );
85  add ( new Lambert ( lt ) );
86  add ( new Lambert2 ( lt ) );
87  add ( new Mercator ( lt ) );
88  add ( new Mercator2 ( lt ) );
89  add ( new Cartesian ( lt ) );
90  add ( new Cartesian2 ( lt ) );
91  add ( new GlobalSinusoidal ( lt ) );
92  add ( new GlobalSinusoidal2 ( lt ) );
93  add ( new ARC ( lt ) );
94  add ( new ARC2 ( lt ));
95  add ( new TAN ( lt ) );
96  add ( new TAN2 ( lt ));
97  add ( new SIN ( lt ) );
98  add ( new SIN2 ( lt ));
99  add ( new STG ( lt ) );
100  add ( new STG2 ( lt ));
101  add ( new AIR ( lt ) );
102  add ( new AIR2 ( lt ));
103 #endif
104 }
105 
111 createTransform ( const std::string & name )
112 {
113 
114  // size_type could be 32 or 64 bit unsigned int
115  string::size_type pos = name.find_first_of ( " -" );
116 
117  if ( pos == string::npos ) { // no space, so regular name
118  TransformBase * transform = prototype ( name );
119  assert ( transform != 0 );
120  return transform->clone ();
121  }
122 
123  // else construct XYTransform
124  string name1 = name.substr ( 0, pos );
125  string name2 = name.substr ( pos+1 );
126 
127  string::size_type pos2 = name2.find_first_of ( " -" );
128 
129  if ( pos2 == string::npos ) {
130  // no space, so 2D transform. Z is linear
131  // by default
132  return createXY ( name1, name2, "Linear" );
133  }
134 
135  string name21 = name2.substr ( 0, pos2 );
136  string name22 = name2.substr ( pos2+1 );
137 
138  return createXY ( name1, name21, name22 );
139 }
140 
141 TransformBase * TransformFactory::createXY ( const std::string & x,
142  const std::string & y,
143  const std::string & z )
144 {
145  TransformBase * x_obj = prototype ( x );
146  TransformBase * y_obj = prototype ( y );
147  TransformBase * z_obj = prototype ( z );
148 
149  UnaryTransform * x_unary = dynamic_cast < UnaryTransform * > ( x_obj );
150  UnaryTransform * y_unary = dynamic_cast < UnaryTransform * > ( y_obj );
151  UnaryTransform * z_unary = dynamic_cast < UnaryTransform * > ( z_obj );
152 
153  if ( x_unary == 0 || y_unary == 0 || z_unary == 0 ) {
154  cout << "Could not create XYTransform" << x << " "
155  << y << " " << z << endl;
156  return 0;
157  }
158 
159 #ifdef CLONE_DEFECT
160  UnaryTransform * xt
161  = dynamic_cast < UnaryTransform * > ( x_unary->clone () );
162  UnaryTransform * yt
163  = dynamic_cast < UnaryTransform * > ( y_unary->clone () );
164  UnaryTransform * zt
165  = dynamic_cast < UnaryTransform * > ( z_unary->clone () );
166 #else
167  UnaryTransform * xt = x_unary->clone ();
168  UnaryTransform * yt = y_unary->clone ();
169  UnaryTransform * zt = z_unary->clone ();
170 #endif
171 
172  return new XYTransform ( xt, yt, zt );
173 }
174 
175 TransformBase * TransformFactory::createXYZ ( const std::string & x,
176  const std::string & y,
177  const std::string & z )
178 {
179  TransformBase * x_obj = prototype ( x );
180  TransformBase * y_obj = prototype ( y );
181  TransformBase * z_obj = prototype ( z );
182 
183  UnaryTransform * xut = dynamic_cast < UnaryTransform * > ( x_obj );
184  UnaryTransform * yut = dynamic_cast < UnaryTransform * > ( y_obj );
185  UnaryTransform * zut = dynamic_cast < UnaryTransform * > ( z_obj );
186 
187  if ( xut == 0 || yut == 0 || zut == 0 ) {
188  cout << "Could not create XYZTransform"
189  << x << " " << y << " " << z << endl;
190  return 0;
191  }
192 
193 #ifdef CLONE_DEFECT
194  UnaryTransform * xt
195  = dynamic_cast < UnaryTransform * > ( xut->clone () );
196  UnaryTransform * yt
197  = dynamic_cast < UnaryTransform * > ( yut->clone () );
198  UnaryTransform * zt
199  = dynamic_cast < UnaryTransform * > ( zut->clone () );
200 #else
201  UnaryTransform * xt = xut->clone ();
202  UnaryTransform * yt = yut->clone ();
203  UnaryTransform * zt = zut->clone ();
204 #endif
205 
206  return new XYZTransform ( xt, yt, zt );
207 }
208 
209 } // namespace hippodraw

Generated for HippoDraw Class Library by doxygen