TransformFactory.cxx

Go to the documentation of this file.
00001 
00012 // for wcslib
00013 #ifdef HAVE_CONFIG_H
00014 #include "config.h"
00015 #endif
00016 
00017 #ifdef _MSC_VER
00018 // for truncation warning
00019 // for CLONE_DEFECT
00020 #include "msdevstudio/MSconfig.h"
00021 #endif //_MSC_VER
00022 
00023 #include "transforms/TransformFactory.h"
00024 
00025 // List of default Transforms
00026 #include "HammerAito.h"
00027 #include "HammerAito2.h"
00028 #include "Lambert.h"
00029 #include "Lambert2.h"
00030 #include "Mercator.h"
00031 #include "Mercator2.h"
00032 #include "Cartesian.h"
00033 #include "Cartesian2.h"
00034 #include "GlobalSinusoidal.h"
00035 #include "GlobalSinusoidal2.h"
00036 #include "ARC.h"
00037 #include "ARC2.h"
00038 #include "TAN.h"
00039 #include "TAN2.h"
00040 #include "SIN.h"
00041 #include "SIN2.h"
00042 #include "STG.h"
00043 #include "STG2.h"
00044 #include "AIR.h"
00045 #include "AIR2.h"
00046 #include "LinearTransform.h"
00047 #include "LogTransform.h"
00048 #include "XYTransform.h"
00049 #include "XYZTransform.h"
00050 
00051 #include <iostream>
00052 
00053 #include <cassert>
00054 
00055 using std::cout;
00056 using std::endl;
00057 using std::string;
00058 
00059 namespace hippodraw {
00060 
00061 TransformFactory * TransformFactory::s_instance = 0;
00062 
00063 TransformFactory::TransformFactory ()
00064 {
00065 }
00066 
00067 TransformFactory * TransformFactory::instance ()
00068 {
00069   if ( s_instance == 0 ) {
00070     s_instance = new TransformFactory ();
00071     s_instance->initialize ();
00072   }
00073   return s_instance;
00074 }
00075 
00076 void TransformFactory::initialize ()
00077 {
00078   LinearTransform * lt = new LinearTransform ();
00079   add ( lt  );
00080   add ( new LogTransform () );
00081   add ( new XYTransform ( lt, lt, lt ) );
00082 #ifdef HAVE_WCSLIB
00083   add ( new HammerAito ( lt ) );
00084   add ( new HammerAito2 ( lt ) );
00085   add ( new Lambert ( lt ) );
00086   add ( new Lambert2 ( lt ) );
00087   add ( new Mercator ( lt ) );
00088   add ( new Mercator2 ( lt ) );
00089   add ( new Cartesian ( lt ) );
00090   add ( new Cartesian2 ( lt ) );
00091   add ( new GlobalSinusoidal ( lt ) );
00092   add ( new GlobalSinusoidal2 ( lt ) );
00093   add ( new ARC ( lt ) );
00094   add ( new ARC2 ( lt ));
00095   add ( new TAN ( lt ) );
00096   add ( new TAN2 ( lt ));
00097   add ( new SIN ( lt ) );
00098   add ( new SIN2 ( lt ));
00099   add ( new STG ( lt ) );
00100   add ( new STG2 ( lt ));
00101   add ( new AIR ( lt ) );
00102   add ( new AIR2 ( lt ));
00103 #endif
00104 }
00105 
00109 TransformBase *
00110 TransformFactory::
00111 createTransform ( const std::string & name )
00112 {
00113 
00114   // size_type could be 32 or 64 bit unsigned int
00115   string::size_type pos = name.find_first_of ( " -" );
00116 
00117   if ( pos == string::npos ) { // no space, so regular name
00118     TransformBase * transform = prototype ( name );
00119     assert ( transform != 0 );
00120     return transform->clone ();
00121   }
00122 
00123   // else construct XYTransform
00124   string name1 = name.substr ( 0, pos );
00125   string name2 = name.substr ( pos+1 );
00126 
00127   string::size_type pos2 = name2.find_first_of ( " -" );
00128 
00129   if ( pos2 == string::npos ) { 
00130     // no space, so 2D transform. Z is linear
00131     // by default
00132     return createXY ( name1, name2, "Linear" );
00133   }
00134 
00135   string name21 = name2.substr ( 0, pos2 );
00136   string name22 = name2.substr ( pos2+1 );
00137 
00138   return createXY ( name1, name21, name22 );
00139 }
00140 
00141 TransformBase * TransformFactory::createXY ( const std::string & x,
00142                                              const std::string & y,
00143                                              const std::string & z )
00144 {
00145   TransformBase * x_obj = prototype ( x );  
00146   TransformBase * y_obj = prototype ( y );
00147   TransformBase * z_obj = prototype ( z );
00148 
00149   UnaryTransform * x_unary = dynamic_cast < UnaryTransform * > ( x_obj );
00150   UnaryTransform * y_unary = dynamic_cast < UnaryTransform * > ( y_obj );
00151   UnaryTransform * z_unary = dynamic_cast < UnaryTransform * > ( z_obj );
00152 
00153   if ( x_unary == 0 || y_unary == 0 || z_unary == 0 ) {
00154     cout << "Could not create XYTransform" << x << " " 
00155          << y << " " << z << endl;
00156     return 0;
00157   }
00158 
00159 #ifdef CLONE_DEFECT
00160   UnaryTransform * xt 
00161           = dynamic_cast < UnaryTransform * > ( x_unary->clone () );
00162   UnaryTransform * yt 
00163           = dynamic_cast < UnaryTransform * > ( y_unary->clone () );
00164   UnaryTransform * zt 
00165           = dynamic_cast < UnaryTransform * > ( z_unary->clone () );
00166 #else
00167   UnaryTransform * xt = x_unary->clone ();
00168   UnaryTransform * yt = y_unary->clone ();
00169   UnaryTransform * zt = z_unary->clone ();
00170 #endif
00171 
00172   return new XYTransform ( xt, yt, zt );
00173 }
00174 
00175 TransformBase * TransformFactory::createXYZ ( const std::string & x,
00176                                               const std::string & y,
00177                                               const std::string & z )
00178 {
00179   TransformBase * x_obj = prototype ( x );  
00180   TransformBase * y_obj = prototype ( y );
00181   TransformBase * z_obj = prototype ( z );
00182 
00183   UnaryTransform * xut = dynamic_cast < UnaryTransform * > ( x_obj );
00184   UnaryTransform * yut = dynamic_cast < UnaryTransform * > ( y_obj );
00185   UnaryTransform * zut = dynamic_cast < UnaryTransform * > ( z_obj );
00186 
00187   if ( xut == 0 || yut == 0 || zut == 0 ) {
00188     cout << "Could not create XYZTransform"
00189          << x << " " << y << " " << z << endl;
00190     return 0;
00191   }
00192 
00193 #ifdef CLONE_DEFECT
00194   UnaryTransform * xt 
00195           = dynamic_cast < UnaryTransform * > ( xut->clone () );
00196   UnaryTransform * yt 
00197           = dynamic_cast < UnaryTransform * > ( yut->clone () );
00198   UnaryTransform * zt 
00199           = dynamic_cast < UnaryTransform * > ( zut->clone () );
00200 #else
00201   UnaryTransform * xt = xut->clone ();
00202   UnaryTransform * yt = yut->clone ();
00203   UnaryTransform * zt = zut->clone ();
00204 #endif
00205 
00206   return new XYZTransform ( xt, yt, zt );
00207 }
00208 
00209 } // namespace hippodraw

Generated for HippoDraw Class Library by doxygen