23 #include "atlas/grid/detail/grid/Grid.h" 24 #include "atlas/runtime/Exception.h" 38 struct ComputePointXY {
39 void update_value(
idx_t n ) {}
40 void compute_value(
idx_t n,
PointXY& point ) { grid_.xy( n, point.data() ); }
41 const PointXY& get_reference(
idx_t n )
const {
return grid_.xy( n ); }
43 ComputePointXY(
const Unstructured& grid ) : grid_( grid ) {}
47 struct ComputePointLonLat {
48 void update_value(
idx_t n ) {
50 grid_.lonlat( n, point_.data() );
53 void compute_value(
idx_t n,
PointLonLat& point ) { grid_.lonlat( n, point.data() ); }
56 ComputePointLonLat(
const Unstructured& grid ) : grid_( grid ), size_( grid_.size() ) {}
62 template <
typename Base,
typename ComputePo
int>
63 class UnstructuredIterator :
public Base {
65 UnstructuredIterator(
const Unstructured& grid,
bool begin =
true ) :
67 size_( static_cast<idx_t>( grid_.points_->size() ) ),
68 n_( begin ? 0 : size_ ),
69 point_computer_{grid_} {
70 point_computer_.update_value( n_ );
73 virtual bool next(
typename Base::value_type& point ) {
75 point_computer_.compute_value( n_, point );
84 virtual typename Base::reference operator*()
const {
return point_computer_.get_reference( n_ ); }
86 virtual const Base& operator++() {
88 point_computer_.update_value( n_ );
93 virtual const Base& operator+=(
typename Base::difference_type distance ) {
95 point_computer_.update_value( n_ );
99 virtual bool operator==(
const Base& other )
const {
100 return n_ ==
static_cast<const UnstructuredIterator&
>( other ).n_;
103 virtual bool operator!=(
const Base& other )
const {
104 return n_ !=
static_cast<const UnstructuredIterator&
>( other ).n_;
107 virtual typename Base::difference_type distance(
const Base& other )
const {
108 const auto& _other =
static_cast<const UnstructuredIterator&
>( other );
109 return _other.n_ - n_;
112 virtual std::unique_ptr<Base> clone()
const {
113 auto result =
new UnstructuredIterator( grid_,
false );
115 result->point_computer_.update_value( n_ );
116 return std::unique_ptr<Base>( result );
123 ComputePoint point_computer_;
127 using IteratorXY = UnstructuredIterator<Grid::IteratorXY, ComputePointXY>;
128 using IteratorLonLat = UnstructuredIterator<Grid::IteratorLonLat, ComputePointLonLat>;
131 static std::string static_type() {
return "unstructured"; }
132 virtual std::string
name()
const override;
133 virtual std::string type()
const override {
return static_type(); }
160 virtual Spec spec()
const override;
166 void xy(
idx_t n,
double crd[] )
const {
172 void lonlat(
idx_t n,
double crd[] )
const {
174 projection_.xy2lonlat( crd );
177 virtual std::unique_ptr<Grid::IteratorXY> xy_begin()
const override {
178 return std::unique_ptr<Grid::IteratorXY>(
new IteratorXY( *
this ) );
180 virtual std::unique_ptr<Grid::IteratorXY> xy_end()
const override {
181 return std::unique_ptr<Grid::IteratorXY>(
new IteratorXY( *
this,
false ) );
183 virtual std::unique_ptr<Grid::IteratorLonLat> lonlat_begin()
const override {
184 return std::unique_ptr<Grid::IteratorLonLat>(
new IteratorLonLat( *
this ) );
186 virtual std::unique_ptr<Grid::IteratorLonLat> lonlat_end()
const override {
187 return std::unique_ptr<Grid::IteratorLonLat>(
new IteratorLonLat( *
this,
false ) );
190 Config meshgenerator()
const override;
191 Config partitioner()
const override;
194 virtual void print( std::ostream& )
const override;
197 virtual void hash( eckit::Hash& )
const override;
204 std::unique_ptr<std::vector<PointXY>>
points_;
214 const Unstructured* atlas__grid__Unstructured__points(
const double lonlat[],
int shapef[],
int stridesf[] );
std::string hash() const
Definition: Grid.cc:127
Unstructured(const Grid &, Domain)
Constructor converting any Grid with domain to an unstructured grid.
Definition: Unstructured.cc:79
Definition: Unstructured.h:36
This file contains classes and functions working on points.
Point in longitude-latitude coordinate system.
Definition: Point.h:103
virtual idx_t size() const override
Definition: Unstructured.cc:192
std::string shortName_
Cache for the shortName.
Definition: Unstructured.h:207
std::unique_ptr< Grid::Spec > cached_spec_
Cache for the spec since may be quite heavy to compute.
Definition: Unstructured.h:210
std::unique_ptr< std::vector< PointXY > > points_
Storage of coordinate points.
Definition: Unstructured.h:204
virtual std::string name() const override
Human readable name (may not be unique)
Definition: Unstructured.cc:165
Point in arbitrary XY-coordinate system.
Definition: Point.h:40
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42
Configuration class used to construct various atlas components.
Definition: Config.h:27