UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sim_vel_model_impl.hpp
1 /* sim_vel_model_impl.hpp */
2 /* $Id$ */
3 #ifndef __sim_vel_model_impl_hpp
4 #define __sim_vel_model_impl_hpp
5 
6 #include <iterator>
7 #include <stdio.h>
8 
9 //------------------------------------------------------------------------------------------
10 
11 template <typename ParamsT>
13 
14 template <typename ParamsT>
16 
17 template <typename ParamsT>
18 const ParamsT& sim::VelModel1D2D<ParamsT>::operator()(const Point2D &coords) const
19 {
20  // no layers => no parameters
21  if (m_lays.empty())
22  {
23  fprintf(stderr, "sim::VelModel1D2D<>::(): error, no layers present.\n");
24  return m_dummy_params;
25  }
26 
27  // try to find correspondent parameters
28  typename std::list<std::pair<VmLayer1D2D, ParamsT> >::const_reverse_iterator rit =
29  m_lays.rbegin();
30  for (;rit != m_lays.rend(); ++rit)
31  {
32  if (coords.z >= rit->first.zCoord(coords.x))
33  break;
34  }
35 
36  // if z < than z of the first layer => continue parameters upwards
37  if (rit == m_lays.rend())
38  --rit;
39 
40  return rit->second;
41 }
42 
43 template <typename ParamsT>
45  const ParamsT &params)
46 {
47  // layers are sorted by z-ascending
48  typename std::list<std::pair<VmLayer1D2D, ParamsT> >::iterator it = m_lays.begin();
49  bool replaced = false;
50  for (;it != m_lays.end(); ++it)
51  {
52  if (layer.coords().z == it->first.coords().z)
53  {
54  it->first = layer;
55  it->second = params;
56  replaced = true;
57  break;
58  }
59 
60  if (layer.coords().z < it->first.coords().z)
61  break;
62  }
63 
64  // add new layer if it is not replaced on one with equal z
65  if (!replaced)
66  m_lays.insert(it, std::pair<VmLayer1D2D, ParamsT>(layer, params));
67 }
68 
69 template <typename ParamsT>
71 {
72  return m_lays.size();
73 }
74 
75 template <typename ParamsT>
77 {
78  if (id >= m_lays.size())
79  {
80  fprintf(stderr,
81  "sim::VelModel1D2D<>::layer: error, id=%zu out of range (%zu layers presents).\n",
82  id, m_lays.size());
83  return m_dummy_layer;
84  }
85 
86  typename std::list<std::pair<VmLayer1D2D, ParamsT> >::const_iterator it = m_lays.begin();
87  std::advance(it, id);
88  return it->first;
89 }
90 
91 template <typename ParamsT>
92 const ParamsT& sim::VelModel1D2D<ParamsT>::params(const size_t id) const
93 {
94  if (id >= m_lays.size())
95  {
96  fprintf(stderr,
97  "sim::VelModel1D2D<>::params: error, id=%zu out of range (%zu layers presents).\n",
98  id, m_lays.size());
99  return m_dummy_params;
100  }
101 
102  typename std::list<std::pair<VmLayer1D2D, ParamsT> >::const_iterator it = m_lays.begin();
103  std::advance(it, id);
104  return it->second;
105 }
106 
107 template <typename ParamsT>
109 {
110  size_t size = m_lays.size();
111 
112  if (id >= size)
113  {
114  fprintf(stderr,
115  "sim::VelModel1D2D<>::removeLayer: warning, id=%zu out of range (%zu layers presents).",
116  id, m_lays.size());
117 
118  if (size > 0)
119  {
120  m_lays.pop_back();
121  fprintf(stderr,
122  "sim::VelModel1D2D<>::removeLayer: warning, the last layer is deleted.\n");
123  }
124  return;
125  }
126 
127  typename std::list<std::pair<VmLayer1D2D, ParamsT> >::iterator it = m_lays.begin();
128  std::advance(it, id);
129  m_lays.erase(it);
130 }
131 
132 template <typename ParamsT>
134 {
135  m_lays.clear();
136 }
137 
138 #endif /* sim_vel_model_impl.hpp */
virtual size_t layersNum() const
Definition: sim_vel_model_impl.hpp:70
Definition: sim_vm_layers.hpp:16
virtual const ParamsT & operator()(const Point2D &coords) const
Definition: sim_vel_model_impl.hpp:18
virtual const ParamsT & params(const size_t id) const
Definition: sim_vel_model_impl.hpp:92
Definition: sim_vel_model.hpp:89
virtual void clear()
Definition: sim_vel_model_impl.hpp:133
Definition: sim_point_2d.hpp:16
virtual void removeLayer(const size_t id)
Definition: sim_vel_model_impl.hpp:108
const Point2D & coords() const
Definition: sim_vm_layers.hpp:31
virtual void appendLayer(const VmLayer1D2D &layer, const ParamsT &params)
Definition: sim_vel_model_impl.hpp:44
virtual const VmLayer1D2D & layer(const size_t id) const
Definition: sim_vel_model_impl.hpp:76