00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 # ifndef shape_cell2d_factory_hpp
00013 # define shape_cell2d_factory_hpp
00014
00015 # include <shape/list.hpp>
00016 # include <shape/curve.hpp>
00017 # include <shape/algebraic_curve.hpp>
00018 # include <shape/parametric_curve.hpp>
00019 # include <shape/semialgebraic_curve.hpp>
00020 # include <shape/bcell2d_list.hpp>
00021 # include <shape/bcell2d_intersection.hpp>
00022 # include <shape/bcell2d_algebraic_curve.hpp>
00023 # include <shape/bcell2d_parametric_curve.hpp>
00024 # include <shape/bcell2d_semialgebraic_curve.hpp>
00025
00026
00027
00028
00029 # define TMPL template<class C, class V>
00030 # define TMPL1 template<class V>
00031 # define REF REF_OF(V)
00032
00033 # define AlgebraicCurve algebraic_curve<C,V>
00034 # define SemiAlgebraicCurve semialgebraic_curve<C,REF>
00035 # define ParametricCurve parametric_curve<C,REF>
00036
00037 # define Cell2dAlgebraicCurve bcell2d_algebraic_curve<C,REF>
00038 # define Cell2dParametricCurve bcell2d_parametric_curve<C,REF>
00039 # define Cell2dSemiAlgebraicCurve bcell2d_semialgebraic_curve<C,REF>
00040
00041
00042 # define Cell2dList bcell2d_list<C,REF>
00043 # define Cell2dInter bcell2d_intersection<C,REF>
00044 # define Cell2dFactory bcell2d_factory<C,V>
00045
00046 namespace mmx { namespace shape {
00047
00048 TMPL
00049 struct bcell2d_factory {
00050 public:
00051 typedef typename SHAPE_OF(V) Shape;
00052 typedef bounding_box<C,REF> BoundingBox;
00053 typedef bcell<C,REF> Cell ;
00054
00055 static Cell2dFactory * instance(void) {
00056
00057 if(!m_instance)
00058 m_instance = new Cell2dFactory ;
00059
00060 return m_instance ;
00061 }
00062
00063 Cell * create(Shape * curve, const BoundingBox& bx) {
00064
00065
00066 Cell* bcell = NULL ;
00067 if(SemiAlgebraicCurve * isemialg = dynamic_cast<SemiAlgebraicCurve *>(curve))
00068 {
00069 bcell = new Cell2dSemiAlgebraicCurve(isemialg,bx);
00070
00071 }
00072
00073
00074
00075
00076
00077 else if(AlgebraicCurve * icurve = dynamic_cast<AlgebraicCurve *>(curve))
00078 {
00079 bcell = new Cell2dAlgebraicCurve(icurve,bx);
00080
00081 }
00082 else if(ParametricCurve * pcurve = dynamic_cast<ParametricCurve *>(curve))
00083 {
00084 bcell = new Cell2dParametricCurve(pcurve,bx);
00085
00086 }
00087
00088 if(bcell==NULL) std::cout<<"no dynamic cast bcell2d_factory"<<std::endl;
00089 return bcell ;
00090
00091 }
00092
00093 Cell * create(const Seq<Shape*>& s, const BoundingBox& bx) {
00094 Cell * bcell = NULL ;
00095
00096 if (s.size()==0) return NULL;
00097 if (s.size()==1) return create(s[0],bx);
00098
00099 if( dynamic_cast<SemiAlgebraicCurve *>(s[0]) )
00100 {
00101 Cell2dInter* l= new Cell2dInter(bx);
00102
00103 foreach(Shape* o, s) l->push_back(create(o,bx)) ;
00104 bcell = l;
00105 }
00106
00107
00108
00109
00110
00111
00112 else {
00113 Cell2dList* l= new Cell2dList(bx);
00114
00115 foreach(Shape* o, s) l->push_back(create(o,bx)) ;
00116 bcell = l;
00117 }
00118
00119 return bcell;
00120 }
00121
00122 private:
00123 bcell2d_factory(void) {} ;
00124
00125 private:
00126 static Cell2dFactory * m_instance;
00127 } ;
00128
00129 TMPL Cell2dFactory* Cell2dFactory::m_instance = NULL;
00130
00131
00132 }
00133 }
00134
00135 # undef TMPL
00136 # undef AlgebraicCurve
00137 # undef SemiAlgebraicCurve
00138 # undef Cell
00139 # undef Cell2dAlgebraicCurve
00140 # undef Cell2dParametricCurve
00141 # undef Cell2dSemiAlgebraicCurve
00142 # undef Cell2dList
00143 # undef Cell2dInter
00144 # undef Cell2dFactory
00145 # undef Curve
00146 # undef SELF
00147
00148 # undef ParametricCurve
00149
00150 # undef Cell2dAlgebraicCurve
00151 #endif
00152
00153
00154
00155
00156