00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef CLIPPER_NXMAP_OPERATOR
00046 #define CLIPPER_NXMAP_OPERATOR
00047
00048 #include "xmap.h"
00049 #include "nxmap.h"
00050
00051
00052 namespace clipper
00053 {
00054
00056
00067 class NX_operator
00068 {
00069 public:
00071 NX_operator();
00073 NX_operator( const Xmap_base& xmap, const NXmap_base& nxmap, const RTop_orth& rtop );
00075 NX_operator( const Cell& cell, const Grid_sampling& grid, const NXmap_base& nxmap, const RTop_orth& rtop );
00077 void init( const Xmap_base& xmap, const NXmap_base& nxmap, const RTop_orth& rtop );
00079 void init( const Cell& cell, const Grid_sampling& grid, const NXmap_base& nxmap, const RTop_orth& rtop );
00080
00082 inline Coord_map coord_map( const Coord_frac& c ) const
00083 { return Coord_map( xfrac_nxgrid * c ); }
00085 inline Coord_frac coord_frac( const Coord_map& c ) const
00086 { return Coord_frac( nxgrid_xfrac * c ); }
00088 template<class I, class T, class M> T nxmap_data( const M& nxmap, const Coord_grid& c ) const;
00090 template<class I, class T, class M> T xmap_data( const M& xmap, const Coord_grid& c ) const;
00091
00093 bool is_null() const;
00094
00095 void debug() const;
00096
00097 protected:
00098 RTop<> xfrac_nxgrid;
00099 RTop<> nxgrid_xfrac;
00100 RTop<> xgrid_nxgrid;
00101 RTop<> nxgrid_xgrid;
00102 RTop<int> xgrid_nxgrid_int;
00103 RTop<int> nxgrid_xgrid_int;
00104 bool x_nx_is_int;
00105 bool x_nx_is_trn;
00106 bool nx_x_is_int;
00107 bool nx_x_is_trn;
00108 };
00109
00110
00112
00127 template<class T> class NXmap_operator : public NX_operator
00128 {
00129 public:
00131 NXmap_operator() {}
00133 NXmap_operator( const Xmap_base& xmap, const NXmap<T>& nxmap, const RTop_orth& rtop ) { init( xmap, nxmap, rtop ); }
00135 NXmap_operator( const Cell& cell, const Grid_sampling& grid, const NXmap<T>& nxmap, const RTop_orth& rtop ) { init( cell, grid, nxmap, rtop ); }
00137 void init( const Xmap_base& xmap, const NXmap<T>& nxmap, const RTop_orth& rtop ) { init( xmap.cell(), xmap.grid_sampling(), nxmap, rtop ); }
00139 void init( const Cell& cell, const Grid_sampling& grid, const NXmap<T>& nxmap, const RTop_orth& rtop ) { nxmap_ = &nxmap; NX_operator::init( cell, grid, nxmap, rtop ); }
00140
00142 template<class I> T nxmap_data( const Coord_grid& c ) const
00143 { return NX_operator::nxmap_data<I,T>( *nxmap_, c ); }
00144
00146 const NXmap<T>& nxmap() const { return *nxmap_; }
00147
00148 private:
00149 const NXmap<T>* nxmap_;
00150 };
00151
00152
00153
00154
00155
00165 template<class I, class T, class M> T NX_operator::nxmap_data( const M& nxmap, const Coord_grid& c ) const
00166 {
00167 if ( x_nx_is_trn ) {
00168 return T( nxmap.get_data( Coord_grid( c + xgrid_nxgrid_int.trn() ) ) );
00169 } else if ( x_nx_is_int ) {
00170 return T( nxmap.get_data( Coord_grid( xgrid_nxgrid_int * c ) ) );
00171 } else {
00172 T val;
00173 I::interp( nxmap, Coord_map( xgrid_nxgrid * c.coord_map() ), val );
00174 return val;
00175 }
00176 }
00177
00178
00187 template<class I, class T, class M> T NX_operator::xmap_data( const M& xmap, const Coord_grid& c ) const
00188 {
00189 if ( nx_x_is_trn ) {
00190 return T( xmap.get_data( Coord_grid( c + nxgrid_xgrid_int.trn() ) ) );
00191 } else if ( nx_x_is_int ) {
00192 return T( xmap.get_data( Coord_grid( nxgrid_xgrid_int * c ) ) );
00193 } else {
00194 T val;
00195 I::interp( xmap, Coord_map( nxgrid_xgrid * c.coord_map() ), val );
00196 return val;
00197 }
00198 }
00199
00200
00201 }
00202
00203 #endif