Clipper
nxmap.h
1
4//C Copyright (C) 2000-2006 Kevin Cowtan and University of York
5//L
6//L This library is free software and is distributed under the terms
7//L and conditions of version 2.1 of the GNU Lesser General Public
8//L Licence (LGPL) with the following additional clause:
9//L
10//L `You may also combine or link a "work that uses the Library" to
11//L produce a work containing portions of the Library, and distribute
12//L that work under terms of your choice, provided that you give
13//L prominent notice with each copy of the work that the specified
14//L version of the Library is used in it, and that you include or
15//L provide public access to the complete corresponding
16//L machine-readable source code for the Library including whatever
17//L changes were used in the work. (i.e. If you make changes to the
18//L Library you must distribute those, but you do not need to
19//L distribute source or object code to those portions of the work
20//L not covered by this licence.)'
21//L
22//L Note that this clause grants an additional right and does not impose
23//L any additional restriction, and so does not affect compatibility
24//L with the GNU General Public Licence (GPL). If you wish to negotiate
25//L other terms, please contact the maintainer.
26//L
27//L You can redistribute it and/or modify the library under the terms of
28//L the GNU Lesser General Public License as published by the Free Software
29//L Foundation; either version 2.1 of the License, or (at your option) any
30//L later version.
31//L
32//L This library is distributed in the hope that it will be useful, but
33//L WITHOUT ANY WARRANTY; without even the implied warranty of
34//L MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35//L Lesser General Public License for more details.
36//L
37//L You should have received a copy of the CCP4 licence and/or GNU
38//L Lesser General Public License along with this library; if not, write
39//L to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
40//L The GNU Lesser General Public can also be obtained by writing to the
41//L Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
42//L MA 02111-1307 USA
43
44
45#ifndef CLIPPER_NXMAP
46#define CLIPPER_NXMAP
47
48
49#include "derivs.h"
50
51
52namespace clipper
53{
54
56
67 {
68 public:
70 bool is_null() const;
71
73 const Grid& grid() const { return grid_; }
75 const RTop<>& operator_orth_grid() const { return rt_orth_grid; }
77 const RTop<>& operator_grid_orth() const { return rt_grid_orth; }
79
81 inline Coord_orth coord_orth( const Coord_map& cm ) const
82 { return Coord_orth( rt_grid_orth*cm ); }
84
86 inline Coord_map coord_map( const Coord_orth& co ) const
87 { return Coord_map ( rt_orth_grid*co ); }
88
90 bool in_map( const Coord_grid& pos ) const { return grid_.in_grid( pos ); }
92 template<class I> bool in_map( const Coord_map& cm ) const;
93
95 int multiplicity( const Coord_grid& ) const { return 1; }
96
98
103 {
104 public:
106 inline const NXmap_base& base_nxmap() const { return *map_; }
108 inline const int& index() const { return index_; }
110 inline bool last() const { return ( index_ >= map_->grid_.size() ); }
111 protected:
116 };
117
119
130 {
131 public:
135 explicit Map_reference_index( const NXmap_base& map )
136 { map_ = &map; index_ = 0; }
138 Map_reference_index( const NXmap_base& map, const Coord_grid& pos )
139 { map_ = &map; index_ = map_->grid_.index( pos ); }
141 inline Coord_grid coord() const
142 { return map_->grid_.deindex(index_); }
144 inline const Coord_orth coord_orth() const
145 { return map_->coord_orth( coord().coord_map() ); }
148 { index_ = map_->grid_.index( pos ); return *this; }
150 inline Map_reference_index& next() { index_++; return *this; }
152 /* Use for e.g. peak search. Valid for -1 <= du/dv/dw <= 1 only.
153 \param du/dv/dw Coordinate offset. \return Map index. */
154 inline int index_offset(const int& du,const int& dv,const int& dw) const {
155 return index_ + du*map_->du + dv*map_->dv + dw*map_->dw;
156 }
157 // inherited functions listed for documentation purposes
158 //-- const NXmap_base& base_nxmap() const;
159 //-- const int& index() const;
160 //-- bool last() const;
161 };
162
164
175 {
176 public:
180 explicit Map_reference_coord( const NXmap_base& map )
181 { map_ = &map; }
183 Map_reference_coord( const NXmap_base& map, const Coord_grid& pos )
184 { map_ = &map; set_coord( pos ); }
186 inline Coord_grid coord() const { return pos_; }
188 inline const Coord_orth coord_orth() const
189 { return map_->coord_orth( coord().coord_map() ); }
192 { pos_ = pos; index_ = map_->grid_.index( pos_ ); return *this; }
194
196 index_++;
198 return *this;
199 }
200 // Increment u,v,w
201 inline Map_reference_coord& next_u() { pos_.u()++; index_ += map_->du; return *this; }
202 inline Map_reference_coord& next_v() { pos_.v()++; index_ += map_->dv; return *this; }
203 inline Map_reference_coord& next_w() { pos_.w()++; index_ += map_->dw; return *this; }
204 inline Map_reference_coord& prev_u() { pos_.u()--; index_ -= map_->du; return *this; }
205 inline Map_reference_coord& prev_v() { pos_.v()--; index_ -= map_->dv; return *this; }
206 inline Map_reference_coord& prev_w() { pos_.w()--; index_ -= map_->dw; return *this; }
209 { return set_coord( pos ); }
210 // inherited functions listed for documentation purposes
211 //-- const NXmap_base& base_nxmap() const;
212 //-- const int& index() const;
213 //-- bool last() const;
214 protected:
217 };
218
220 Map_reference_index first() const { return Map_reference_index( *this ); }
223
224 protected:
228 int du, dv, dw;
229
231 NXmap_base();
233 void init( const Grid& grid, const RTop<>& rt );
235 void init( const Cell& cell, const Grid_sampling& grid, const Grid_range& grid_extent );
236
240 };
241
242
243
244
246
260 template<class T> class NXmap : public NXmap_base
261 {
262 public:
264 NXmap() {}
266 NXmap( const Grid& grid, const RTop<>& rt );
268 NXmap( const Cell& cell, const Grid_sampling& grid, const Grid_range& grid_extent );
270 void init( const Grid& grid, const RTop<>& rt );
272 void init( const Cell& cell, const Grid_sampling& grid, const Grid_range& grid_extent );
273
275 inline const T& operator[] (const NXmap_base::Map_reference_index i) const
276 { return list[i.index()]; }
279 { return list[i.index()]; }
280
282 inline const T& operator[] (const NXmap_base::Map_reference_coord i) const
283 { return list[i.index()]; }
286 { return list[i.index()]; }
287
289 inline const T& get_data( const Coord_grid& pos ) const
290 { return list[ grid_.index( pos ) ]; }
292 inline void set_data( const Coord_grid& pos, const T& val )
293 { list[ grid_.index( pos ) ] = val; }
294
296 template<class I> T interp( const Coord_map& pos ) const;
298 template<class I> void interp_grad( const Coord_map& pos, T& val, Grad_map<T>& grad ) const;
300 template<class I> void interp_curv( const Coord_map& pos, T& val, Grad_map<T>& grad, Curv_map<T>& curv ) const;
301
302 // inherited functions listed for documentation purposes
303 //-- const Grid& grid() const;
304 //-- const RTop<> operator_orth_grid() const;
305 //-- const RTop<> operator_grid_orth() const;
306 //-- const Coord_orth coord_orth( const Coord_map& cg ) const;
307 //-- const Coord_map coord_map ( const Coord_orth& co ) const;
308 //-- const Map_reference_index first();
309 //-- const Map_reference_coord first_coord();
310
312 const T& operator =( const T& value );
314 const NXmap<T>& operator +=( const NXmap<T>& other );
316 const NXmap<T>& operator -=( const NXmap<T>& other );
317
318 private:
319 std::vector<T> list;
320 };
321
322
323
324 // template fucntion definitions
325
330 template<class I> bool NXmap_base::in_map( const Coord_map& cm ) const
331 { return I::can_interp( *this, cm ); }
332
338 template<class T> NXmap<T>::NXmap( const Grid& grid, const RTop<>& rt )
339 { init( grid, rt ); }
340
348 template<class T> NXmap<T>::NXmap( const Cell& cell, const Grid_sampling& grid, const Grid_range& grid_extent )
349 { init( cell, grid, grid_extent ); }
350
356 template<class T> void NXmap<T>::init( const Grid& grid, const RTop<>& rt )
357 { NXmap_base::init( grid, rt ); list.resize( grid.size() ); }
358
366 template<class T> void NXmap<T>::init( const Cell& cell, const Grid_sampling& grid, const Grid_range& grid_extent )
367 { NXmap_base::init( cell, grid, grid_extent ); list.resize( grid_extent.size() ); }
368
369
376 template<class T> template<class I> T NXmap<T>::interp( const Coord_map& pos ) const
377 {
378 T val;
379 I::interp( *this, pos, val );
380 return val;
381 }
382
383
393 template<class T> template<class I> void NXmap<T>::interp_grad( const Coord_map& pos, T& val, Grad_map<T>& grad ) const
394 {
395 I::interp_grad( *this, pos, val, grad );
396 }
397
398
408 template<class T> template<class I> void NXmap<T>::interp_curv( const Coord_map& pos, T& val, Grad_map<T>& grad, Curv_map<T>& curv ) const
409 {
410 I::interp_curv( *this, pos, val, grad, curv );
411 }
412
413
416 template<class T> const T& NXmap<T>::operator =( const T& value )
417 {
418 // copy value into map
420 for ( im = first(); !im.last(); im.next() ) list[im.index()] = value;
421 return value;
422 }
423
424
426 template<class T> const NXmap<T>& NXmap<T>::operator +=( const NXmap<T>& other )
427 {
428 if ( grid() != other.grid() )
429 Message::message( Message_fatal( "NXmap: map mismatch in +=" ) );
431 for ( im = first(); !im.last(); im.next() ) list[im.index()] += other[im];
432 return (*this);
433 }
434
436 template<class T> const NXmap<T>& NXmap<T>::operator -=( const NXmap<T>& other )
437 {
438 if ( grid() != other.grid() )
439 Message::message( Message_fatal( "NXmap: map mismatch in -=" ) );
441 for ( im = first(); !im.last(); im.next() ) list[im.index()] -= other[im];
442 return (*this);
443 }
444
445
446} // namespace clipper
447
448#endif
Cell object.
Definition: cell.h:122
Grid coordinate.
Definition: coords.h:237
const int & v() const
get v
Definition: coords.h:249
const int & w() const
get w
Definition: coords.h:250
const int & u() const
get u
Definition: coords.h:248
map coordinate: this is like Coord_grid, but non-integer
Definition: coords.h:388
orthogonal (Angstrom) coordinates
Definition: coords.h:303
map coordinate curvatures, with respect to grid u,v,w
Definition: derivs.h:146
map coordinate gradient, with respect to grid u,v,w
Definition: derivs.h:102
Grid range class: defines array limits for a grid.
Definition: coords.h:585
Grid sampling of a unit cell.
Definition: coords.h:516
generic grid
Definition: coords.h:480
bool in_grid(Coord_grid g) const
determine if a point is in the grid
Definition: coords.h:491
Coord_grid deindex(const int &index) const
grid deindexing operator
Definition: coords.h:496
int index(const Coord_grid &c) const
grid indexing operator
Definition: coords.h:494
int size() const
return size of grid array
Definition: coords.h:489
Fatal message (level = 9)
Definition: clipper_message.h:129
static void message(const T &message)
pass a message
Definition: clipper_message.h:93
Map reference base class.
Definition: nxmap.h:103
const NXmap_base & base_nxmap() const
return the parent NXmap
Definition: nxmap.h:106
const NXmap_base * map_
pointer to map for which this Map_reference_index is defined
Definition: nxmap.h:113
bool last() const
Check for end of map.
Definition: nxmap.h:110
int index_
integer index into map data array
Definition: nxmap.h:115
const int & index() const
Get the index into the map data array.
Definition: nxmap.h:108
Map reference with coordinate-like behaviour.
Definition: nxmap.h:175
Map_reference_coord & prev_w()
decrement w
Definition: nxmap.h:206
Map_reference_coord()
Null constructor.
Definition: nxmap.h:178
Coord_grid pos_
Current coord.
Definition: nxmap.h:216
Coord_grid coord() const
Get current value of coordinate.
Definition: nxmap.h:186
Map_reference_coord & prev_v()
decrement v
Definition: nxmap.h:205
const Coord_orth coord_orth() const
Get current value of orthogonal coordinate.
Definition: nxmap.h:188
Map_reference_coord & next()
Simple increment.
Definition: nxmap.h:195
Map_reference_coord & operator=(const Coord_grid &pos)
Assignment operator from a coord.
Definition: nxmap.h:208
Map_reference_coord(const NXmap_base &map, const Coord_grid &pos)
Constructor: need parent map and coord.
Definition: nxmap.h:183
Map_reference_coord(const NXmap_base &map)
Constructor: need parent map.
Definition: nxmap.h:180
Map_reference_coord & prev_u()
decrement u
Definition: nxmap.h:204
Map_reference_coord & set_coord(const Coord_grid &pos)
Set current value of coordinate - optimised for nearby coords.
Definition: nxmap.h:191
Map_reference_coord & next_u()
increment u
Definition: nxmap.h:201
Map_reference_coord & next_v()
increment v
Definition: nxmap.h:202
Map_reference_coord & next_w()
increment w
Definition: nxmap.h:203
Map reference with index-like behaviour.
Definition: nxmap.h:130
int index_offset(const int &du, const int &dv, const int &dw) const
Index of neighbouring point.
Definition: nxmap.h:154
Map_reference_index(const NXmap_base &map, const Coord_grid &pos)
Constructor: need parent map and coord.
Definition: nxmap.h:138
Map_reference_index(const NXmap_base &map)
Constructor: need parent map.
Definition: nxmap.h:135
Coord_grid coord() const
Get current grid coordinate.
Definition: nxmap.h:141
Map_reference_index & set_coord(const Coord_grid &pos)
Set current value of coordinate - optimised for nearby coords.
Definition: nxmap.h:147
Map_reference_index()
Null constructor.
Definition: nxmap.h:133
const Coord_orth coord_orth() const
Get current value of orthogonal coordinate.
Definition: nxmap.h:144
Map_reference_index & next()
Simple increment.
Definition: nxmap.h:150
NXmap_base: base for non-crystallographic map class.
Definition: nxmap.h:67
Map_reference_coord first_coord() const
return a coord Map_reference_index for this map
Definition: nxmap.h:222
const Grid & grid() const
return the grid dimensions for this map
Definition: nxmap.h:73
bool in_map(const Coord_grid &pos) const
is the given coord available in the map?
Definition: nxmap.h:90
RTop rt_orth_grid
orth->grid operator
Definition: nxmap.h:226
int multiplicity(const Coord_grid &) const
get multiplicity of a map grid point (always 1 for NXmap)
Definition: nxmap.h:95
RTop rt_grid_orth
grid->orth operator
Definition: nxmap.h:227
const RTop & operator_orth_grid() const
return the orthogonal-to-grid coordinate operator
Definition: nxmap.h:75
Coord_map coord_map(const Coord_orth &co) const
convert orthogonal coordinate to map
Definition: nxmap.h:86
const RTop & operator_grid_orth() const
return the grid-to-orthogonal coordinate operator
Definition: nxmap.h:77
int dw
steps for shifts along u,v,w
Definition: nxmap.h:228
Map_reference_index first() const
return a basic Map_reference_index for this map
Definition: nxmap.h:220
NXmap_base()
Null constructor, for later initialisation.
Definition: nxmap.cpp:53
Coord_orth coord_orth(const Coord_map &cm) const
convert map coordinate to orthogonal
Definition: nxmap.h:81
Grid grid_
grid for the map
Definition: nxmap.h:225
bool is_null() const
test if object has been initialised
Definition: nxmap.cpp:94
void init(const Grid &grid, const RTop<> &rt)
initialiser: takes grid and orthogonal->grid coordinate operator
Definition: nxmap.cpp:65
NXmap<T>: actual non-crystallographic map class.
Definition: nxmap.h:261
const T & get_data(const Coord_grid &pos) const
get a density value for an arbitrary position
Definition: nxmap.h:289
const T & operator[](const NXmap_base::Map_reference_index i) const
get data by Map_reference_index
Definition: nxmap.h:275
const T & operator=(const T &value)
assignment operator: assigns a single value to the whole map
Definition: nxmap.h:416
void set_data(const Coord_grid &pos, const T &val)
set a density value for an arbitrary position
Definition: nxmap.h:292
void interp_curv(const Coord_map &pos, T &val, Grad_map< T > &grad, Curv_map< T > &curv) const
get map value and curv for map coord using supplied interpolator
Definition: nxmap.h:408
const NXmap< T > & operator-=(const NXmap< T > &other)
subtract another map from this one
Definition: nxmap.h:436
void interp_grad(const Coord_map &pos, T &val, Grad_map< T > &grad) const
get map value and grad for map coord using supplied interpolator
Definition: nxmap.h:393
NXmap()
Null constructor, for later initialisation.
Definition: nxmap.h:264
const NXmap< T > & operator+=(const NXmap< T > &other)
add another map to this one
Definition: nxmap.h:426
T interp(const Coord_map &pos) const
get map value for map coord using supplied interpolator
Definition: nxmap.h:376
void init(const Grid &grid, const RTop<> &rt)
initialiser: takes grid and orthogonal->grid coordinate operator
Definition: nxmap.h:356
Rotation-translation operator.
Definition: clipper_types.h:323