Nektar++
ProcessIsoContour.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessIsoContour.h
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Generate isocontours from field data.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef FIELDUTILS_PROCESSISOCONTOUR
36 #define FIELDUTILS_PROCESSISOCONTOUR
37 
38 #include "../Module.h"
40 
41 namespace Nektar
42 {
43 namespace FieldUtils
44 {
45 
46 class Iso
47 {
48  public:
49  void Condense(void);
50  void GlobalCondense(std::vector<std::shared_ptr<Iso> > &iso, bool verbose);
51  void SeparateRegions(std::vector<std::shared_ptr<Iso> > &iso, int minsize, bool verbose);
52 
53  void Smooth(int n_iter, NekDouble lambda, NekDouble mu);
54 
55  int GetNVert(void)
56  {
57  return m_nvert;
58  }
59 
60  void SetNVert(int n)
61  {
62  m_nvert = n;
63  }
64 
65  int GetNTris(void)
66  {
67  return m_ntris;
68  }
69 
70  void SetNTris(int n)
71  {
72  m_ntris = n;
73  }
74 
75  void SetFields(const int loc,
76  const Array<OneD,Array<OneD, NekDouble> > &intfields,
77  const int j)
78  {
79  m_x[loc] = intfields[0][j];
80  m_y[loc] = intfields[1][j];
81  m_z[loc] = intfields[2][j];
82 
83  for(int i = 0; i < intfields.num_elements()-3; ++i)
84  {
85  m_fields[i][loc] = intfields[i+3][j];
86  }
87  }
88 
89  NekDouble GetFields(const int i, const int j)
90  {
91  return m_fields[i][j];
92  }
93 
94  void SetX(int loc, NekDouble val)
95  {
96  m_x[loc] = val;
97  }
98 
99  void SetY(int loc, NekDouble val)
100  {
101  m_y[loc] = val;
102  }
103 
104  void SetZ(int loc, NekDouble val)
105  {
106  m_z[loc] = val;
107  }
108 
110  {
111  return m_x[loc];
112  }
113 
115  {
116  return m_y[loc];
117  }
118 
120  {
121  return m_z[loc];
122  }
123 
124  int GetVId(int i)
125  {
126  return m_vid[i];
127  }
128 
129  void ResizeVId(int nconn)
130  {
131  m_vid = Array<OneD, int>(nconn);
132  }
133 
134  void SetVId(int i, int j)
135  {
136  m_vid[i] = j;
137  }
138 
139  void ResizeFields(int size)
140  {
141  if(size > m_x.size()) // add 1000 element to vectors
142  {
143  m_x.resize(size+100);
144  m_y.resize(size+100);
145  m_z.resize(size+100);;
146  for(int i = 0; i < m_fields.size(); ++i)
147  {
148  m_fields[i].resize(size+1000);
149  }
150 
151  }
152  m_nvert = size;
153  }
154 
155  Iso(int nfields)
156  {
157  m_condensed = false;
158  m_nvert = 0;
159  m_fields.resize(nfields);
160  // set up initial vectors to be 1000 long
161  m_x.resize(1000);
162  m_y.resize(1000);
163  m_z.resize(1000);
164  for(int i = 0; i < m_fields.size(); ++i)
165  {
166  m_fields[i].resize(1000);
167  }
168  };
169 
170  ~Iso(void)
171  {
172  }
173 
174  private:
176  int m_nvert; // number of vertices
177  int m_ntris; // number of triangles introduced.
178  std::vector<NekDouble> m_x;
179  std::vector<NekDouble> m_y;
180  std::vector<NekDouble> m_z;
181  std::vector<std::vector<NekDouble> > m_fields;
182  Array<OneD, int> m_vid; // used when condensing field
183 
184 };
185 
186 typedef std::shared_ptr<Iso> IsoSharedPtr;
187 
189 {
190  public:
191  friend class Iso;
192 
193  IsoVertex (void)
194  {
195  m_id = -1;
196  m_x = m_y = m_z = -99999;
197  }
198 
200 
202  {
203  return m_iso_id;
204  }
205 
207  {
208  return m_iso_vert_id;
209  }
210 
211  friend bool operator == (const IsoVertex& x, const IsoVertex& y);
212  friend bool operator != (const IsoVertex& x, const IsoVertex& y);
213 
214  private:
215  int m_id;
216  int m_iso_id;
219  std::vector<NekDouble > m_fields;
220 
221 };
222 
223 /**
224  * @brief This processing module extracts an isocontour
225  */
227 {
228  public:
229  /// Creates an instance of this class
230  static std::shared_ptr<Module> create(FieldSharedPtr f)
231  {
233  }
235 
237  virtual ~ProcessIsoContour();
238 
239  /// Write mesh to output file.
240  virtual void Process(po::variables_map &vm);
241 
242  virtual std::string GetModuleName()
243  {
244  return "ProcessIsoContour";
245  }
246 
247  virtual std::string GetModuleDescription()
248  {
249  return "Extracting contour";
250  }
251 
253  {
254  return eModifyPts;
255  }
256 
257  protected:
259  void ResetFieldPts(std::vector<IsoSharedPtr> &iso);
260  void SetupIsoFromFieldPts(std::vector<IsoSharedPtr> &isovec);
261 
262  private:
263 
264  std::vector<IsoSharedPtr> ExtractContour(
265  const int fieldid,
266  const NekDouble val);
267 };
268 
269 }
270 }
271 
272 #endif
NekDouble GetX(int loc)
bool operator==(TriFaceIDs const &p1, TriFaceIDs const &p2)
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
void SetX(int loc, NekDouble val)
NekDouble GetFields(const int i, const int j)
NekDouble GetY(int loc)
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
std::vector< NekDouble > m_z
bool operator!=(const IsoVertex &x, const IsoVertex &y)
void SetFields(const int loc, const Array< OneD, Array< OneD, NekDouble > > &intfields, const int j)
std::pair< ModuleType, std::string > ModuleKey
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::vector< std::vector< NekDouble > > m_fields
std::vector< NekDouble > m_y
double NekDouble
void Smooth(int n_iter, NekDouble lambda, NekDouble mu)
void SetVId(int i, int j)
std::vector< NekDouble > m_x
void SetZ(int loc, NekDouble val)
Array< OneD, int > m_vid
NekDouble GetZ(int loc)
void GlobalCondense(std::vector< std::shared_ptr< Iso > > &iso, bool verbose)
void SetY(int loc, NekDouble val)
std::vector< NekDouble > m_fields
void SeparateRegions(std::vector< std::shared_ptr< Iso > > &iso, int minsize, bool verbose)
This processing module extracts an isocontour.
virtual ModulePriority GetModulePriority()
Abstract base class for processing modules.
std::shared_ptr< Iso > IsoSharedPtr