00001
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015
00016 #ifdef _MSC_VER
00017
00018
00019 #include "msdevstudio/MSconfig.h"
00020 #endif //_MSC_VER
00021
00022 #include "transforms/TransformFactory.h"
00023
00024
00025 #include "HammerAito.h"
00026 #include "Lambert.h"
00027 #include "LinearTransform.h"
00028 #include "LogTransform.h"
00029 #include "XYTransform.h"
00030 #include "XYZTransform.h"
00031
00032 #include <iostream>
00033
00034 #include <cassert>
00035
00036 using std::cout;
00037 using std::endl;
00038 using std::string;
00039
00040 TransformFactory * TransformFactory::s_instance = 0;
00041
00042 TransformFactory::TransformFactory ()
00043 {
00044 }
00045
00046 TransformFactory * TransformFactory::instance ()
00047 {
00048 if ( s_instance == 0 ) {
00049 s_instance = new TransformFactory ();
00050 s_instance->initialize ();
00051 }
00052 return s_instance;
00053 }
00054
00055 void TransformFactory::initialize ()
00056 {
00057 LinearTransform * lt = new LinearTransform ();
00058 add ( lt );
00059 add ( new LogTransform () );
00060 add ( new XYTransform ( lt, lt, lt ) );
00061 add ( new HammerAito ( lt ) );
00062 add ( new Lambert ( lt ) );
00063 }
00064
00068 TransformBase *
00069 TransformFactory::
00070 createTransform ( const std::string & name )
00071 {
00072
00073
00074 string::size_type pos = name.find_first_of ( " -" );
00075
00076 if ( pos == string::npos ) {
00077 TransformBase * transform = prototype ( name );
00078 assert ( transform != 0 );
00079 return transform->clone ();
00080 }
00081
00082
00083 string name1 = name.substr ( 0, pos );
00084 string name2 = name.substr ( pos+1 );
00085
00086 string::size_type pos2 = name2.find_first_of ( " -" );
00087
00088 if ( pos2 == string::npos ) {
00089
00090
00091 return createXY ( name1, name2, "Linear" );
00092 }
00093
00094 string name21 = name2.substr ( 0, pos2 );
00095 string name22 = name2.substr ( pos2+1 );
00096
00097 return createXY ( name1, name21, name22 );
00098 }
00099
00100 TransformBase * TransformFactory::createXY ( const std::string & x,
00101 const std::string & y,
00102 const std::string & z )
00103 {
00104 TransformBase * x_obj = prototype ( x );
00105 TransformBase * y_obj = prototype ( y );
00106 TransformBase * z_obj = prototype ( z );
00107
00108 UnaryTransform * x_unary = dynamic_cast < UnaryTransform * > ( x_obj );
00109 UnaryTransform * y_unary = dynamic_cast < UnaryTransform * > ( y_obj );
00110 UnaryTransform * z_unary = dynamic_cast < UnaryTransform * > ( z_obj );
00111
00112 if ( x_unary == 0 || y_unary == 0 || z_unary == 0 ) {
00113 cout << "Could not create XYTransform" << x << " "
00114 << y << " " << z << endl;
00115 return 0;
00116 }
00117
00118 #ifdef CLONE_DEFECT
00119 UnaryTransform * xt
00120 = dynamic_cast < UnaryTransform * > ( x_unary->clone () );
00121 UnaryTransform * yt
00122 = dynamic_cast < UnaryTransform * > ( y_unary->clone () );
00123 UnaryTransform * zt
00124 = dynamic_cast < UnaryTransform * > ( z_unary->clone () );
00125 #else
00126 UnaryTransform * xt = x_unary->clone ();
00127 UnaryTransform * yt = y_unary->clone ();
00128 UnaryTransform * zt = z_unary->clone ();
00129 #endif
00130
00131 return new XYTransform ( xt, yt, zt );
00132 }
00133
00134 TransformBase * TransformFactory::createXYZ ( const std::string & x,
00135 const std::string & y,
00136 const std::string & z )
00137 {
00138 TransformBase * x_obj = prototype ( x );
00139 TransformBase * y_obj = prototype ( y );
00140 TransformBase * z_obj = prototype ( z );
00141
00142 UnaryTransform * xut = dynamic_cast < UnaryTransform * > ( x_obj );
00143 UnaryTransform * yut = dynamic_cast < UnaryTransform * > ( y_obj );
00144 UnaryTransform * zut = dynamic_cast < UnaryTransform * > ( z_obj );
00145
00146 if ( xut == 0 || yut == 0 || zut == 0 ) {
00147 cout << "Could not create XYZTransform"
00148 << x << " " << y << " " << z << endl;
00149 return 0;
00150 }
00151
00152 #ifdef CLONE_DEFECT
00153 UnaryTransform * xt
00154 = dynamic_cast < UnaryTransform * > ( xut->clone () );
00155 UnaryTransform * yt
00156 = dynamic_cast < UnaryTransform * > ( yut->clone () );
00157 UnaryTransform * zt
00158 = dynamic_cast < UnaryTransform * > ( zut->clone () );
00159 #else
00160 UnaryTransform * xt = xut->clone ();
00161 UnaryTransform * yt = yut->clone ();
00162 UnaryTransform * zt = zut->clone ();
00163 #endif
00164
00165 return new XYZTransform ( xt, yt, zt );
00166 }