MeshLink
Computational geometry access
MeshTopo.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019-2020 Pointwise, Inc.
4  * All rights reserved.
5  *
6  * This sample Pointwise source code is not supported by Pointwise, Inc.
7  * It is provided freely for demonstration purposes only.
8  * SEE THE WARRANTY DISCLAIMER AT THE BOTTOM OF THIS FILE.
9  *
10  ***************************************************************************/
11 
12 #ifndef MESH_TOPO_CLASS
13 #define MESH_TOPO_CLASS
14 
15 #include "Types.h"
16 
17 #include <algorithm>
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 #define MESH_TOPO_INVALID_REF -101
23 #define MESH_TOPO_INDEX_UNUSED -101
24 
25 /****************************************************************************
26  *
27  * pwiFnvHash class
28  *
29  * A simple hashing routine used to uniquely identify mesh topology entities.
30  * Fowler-Noll-Vo Hash Function
31  * Designed to be fast with decent dispersion.
32  * https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
33  *
34  ***************************************************************************/
35 class pwiFnvHash {
36 public:
38  typedef MLUINT FNVHash;
39 
40  static FNVHash hashInit();
41 
43  static FNVHash hash(MLINT data, FNVHash hash);
44 
45 private:
46  const static FNVHash fnv_init_;
47  const static FNVHash fnv_prime_;
48  const static FNVHash fnv_num_octets_;
49 };
50 
51 
52 #define FNV1_32_INIT ((pwiFnvHash::FNVHash)0x811c9dc5)
53 #define FNV1_64_INIT ((pwiFnvHash::FNVHash)0xcbf29ce484222325ULL)
54 #define FNV1_32_PRIME ((pwiFnvHash::FNVHash)0x01000193)
55 #define FNV1_64_PRIME ((pwiFnvHash::FNVHash)0x100000001b3ULL)
56 
57 
58 /****************************************************************************
59  * ParamVertex class
60  ***************************************************************************/
69 class ParamVertex {
70 public:
73  gref_(MESH_TOPO_INVALID_REF),
74  mid_(MESH_TOPO_INVALID_REF),
75  u_(0.0),
76  v_(0.0) {}
77 
85  ParamVertex(const std::string & vref, MLINT gref, MLINT mid, MLREAL u, MLREAL v) :
86  vref_(vref),
87  gref_(gref),
88  mid_(mid),
89  u_(u),
90  v_(v) {}
91 
93  const std::string &getVref() const { return vref_; }
95  MLINT getGref() const { return gref_; }
97  MLINT getID() const { return mid_; }
101  void getUV(MLREAL *u, MLREAL *v) const { *u = u_; *v = v_; }
102 private:
104  std::string vref_; // required attr
106  MLINT gref_; // required attr
108  MLINT mid_; // optional attr
113 };
114 
115 typedef std::map<std::string /*vref*/, ParamVertex *> ParamVertVrefMap;
116 typedef std::map<MLINT /*mid*/, std::string /*vref*/> ParamVertIDToVrefMap;
117 
118 class MeshAssociativity;
119 
120 /****************************************************************************
121  * MeshTopo class
122  ***************************************************************************/
132 class ML_STORAGE_CLASS MeshTopo {
133 public:
134  friend class MeshAssociativity;
135 
142  MeshTopo(
143  MLINT mid,
144  MLINT aref,
145  MLINT gref,
146  const std::string &name );
147 
155  MeshTopo(
156  const std::string &ref,
157  MLINT mid,
158  MLINT aref,
159  MLINT gref,
160  const std::string &name );
161 
163  virtual MLINT getID() const;
164 
166  virtual MLINT getGref() const;
167 
169  virtual MLINT getAref() const;
170 
176  virtual void getName(const char **name) const;
177 
179  virtual const std::string & getName() const;
180 
182  virtual const std::string & getRef() const;
183 
188  virtual void addParamVertex(ParamVertex *pv, bool mapID);
189 
193  virtual ParamVertex * getParamVertByVref(const std::string & vref) const;
194 
198  virtual ParamVertex * getParamVertByID(MLINT id) const;
199 
201  virtual MLINT getNumParamVerts() const;
202 
204  void getParamVerts(std::vector<const ParamVertex *> &pv) const;
205 
208  virtual const ParamVertVrefMap & getParamVertVrefMap() const;
209 
213  virtual void setID( MLINT id );
214 
218  virtual void setGref( MLINT gref );
219 
223  virtual void setAref( MLINT aref );
224 
226  //
228  virtual void setRef(const char *ref);
229 
236  void setName(const std::string &name);
237 
242  //
244  void setName(const char *name);
245 
247  bool hasID() const;
248 
250  bool hasGref() const;
251 
253  bool hasAref() const;
254 
256  std::vector<MLINT> getAttributeIDs(const MeshAssociativity &meshAssoc) const;
257 
259  std::string getNextName();
260 
262  virtual const std::string &getBaseName() const;
264  virtual MLUINT &getNameCounter();
265 
267  void setOrderCounter(MLUINT counter);
268 
270  MLUINT getOrderCounter() const ;
271 
272  static bool OrderCompare(const MeshTopo *topo1, const MeshTopo *topo2);
273 
275  MeshTopo();
277  ~MeshTopo();
278 protected:
280  std::string ref_;
281 
282  // MeshLink schema: MeshElementAttributes
290  std::string name_;
293 
298 
299 private:
302 };
303 
304 typedef std::map<MLINT, std::string> MeshTopoIDToNameMap;
305 
306 typedef std::vector<MeshTopo *> MeshTopoArray;
307 
308 typedef std::map<std::string, std::string> MeshTopoRefToNameMap;
309 
310 
311 
312 /****************************************************************************
313  * MeshPoint class
314  ***************************************************************************/
323 class MeshPoint : public MeshTopo {
324 public:
325  friend class MeshAssociativity;
326  friend class MeshModel;
327  friend class MeshSheet;
328  friend class MeshString;
329 
338  MeshPoint(MLINT i1,
339  MLINT mid,
340  MLINT aref,
341  MLINT gref,
342  const std::string &name,
343  ParamVertex *pv1
344  );
345 
354  MeshPoint(
355  const std::string &ref,
356  MLINT mid,
357  MLINT aref,
358  MLINT gref,
359  const std::string &name,
360  ParamVertex *pv1
361  );
362 
364  ParamVertex * const getParamVert() const {
365  return paramVert_;
366  }
367 
373  MLINT getParamVerts(ParamVertex * const ** pvs) const {
374  *pvs = &(paramVert_);
375  return 1;
376  }
377 
379  ~MeshPoint();
380 
382  virtual const std::string &getBaseName() const;
384  virtual MLUINT &getNameCounter();
385 
386 private:
389 
392  i1_(-1),
393  paramVert_(NULL)
394  {};
395 
397  static pwiFnvHash::FNVHash computeHash(MLINT i1);
398 
400  pwiFnvHash::FNVHash getHash() const;
401 
406 };
407 
408 typedef std::map<std::string, MeshPoint *> MeshPointNameMap;
409 
410 
411 /****************************************************************************
412  * MeshEdge class
413  ***************************************************************************/
421 class MeshEdge : public MeshTopo {
422 public:
423  friend class MeshAssociativity;
424  friend class MeshModel;
425  friend class MeshSheet;
426  friend class MeshString;
427 
436  MeshEdge(MLINT i1, MLINT i2,
437  MLINT mid,
438  MLINT aref,
439  MLINT gref,
440  const std::string &name,
441  ParamVertex *pv1, ParamVertex *pv2);
442 
444  //
451  MeshEdge(
452  const std::string &ref,
453  MLINT mid,
454  MLINT aref,
455  MLINT gref,
456  const std::string &name,
457  ParamVertex *pv1, ParamVertex *pv2);
458 
460  ~MeshEdge();
461 
463  MeshEdge(const MeshEdge &other);
464 
466  MeshEdge & operator=(const MeshEdge &other);
467 
469  virtual const std::string &getBaseName() const;
471  virtual MLUINT &getNameCounter();
472 
479  void getInds(MLINT *inds, MLINT *numInds) const;
480 
485  MLINT getParamVerts( ParamVertex * const ** pvs) const {
486  *pvs = &(paramVerts_[0]);
487  return getNumParamVerts();
488  }
489 
491  void getParamVerts(std::vector<ParamVertex*> &pvs) const {
492  pvs.clear();
493  for (int i = 0; i < 2; ++i) {
494  if (NULL != paramVerts_[i]) pvs.push_back(paramVerts_[i]);
495  }
496  return;
497  }
498 
501  {
502  MLINT count = 0;
503  for (int i = 0; i < 2; ++i) {
504  if (NULL != paramVerts_[i]) ++count;
505  }
506  return count;
507  }
508 
509 private:
512 
515  i1_(-1),
516  i2_(-1)
517  {
518  paramVerts_[0] = paramVerts_[1] = NULL;
519  };
520 
522  pwiFnvHash::FNVHash getHash() const;
523 
525  static pwiFnvHash::FNVHash computeHash(MLINT i1, MLINT i2);
526 
533 };
534 typedef std::map<std::string, MeshEdge *> MeshEdgeNameMap;
535 
536 
537 
538 /****************************************************************************
539  * MeshFace class
540  ***************************************************************************/
548 class MeshFace : public MeshTopo {
549 public:
550  friend class MeshAssociativity;
551  friend class MeshModel;
552  friend class MeshSheet;
553  friend class MeshString;
554 
563  MeshFace(MLINT i1, MLINT i2, MLINT i3,
564  MLINT mid,
565  MLINT aref,
566  MLINT gref,
567  const std::string &name,
568  ParamVertex *pv1, ParamVertex *pv2,
569  ParamVertex *pv3);
570 
572  //
579  MeshFace(
580  const std::string &ref,
581  MLINT mid,
582  MLINT aref,
583  MLINT gref,
584  const std::string &name,
585  ParamVertex *pv1, ParamVertex *pv2,
586  ParamVertex *pv3);
587 
596  MeshFace(MLINT i1, MLINT i2, MLINT i3, MLINT i4,
597  MLINT mid,
598  MLINT aref,
599  MLINT gref,
600  const std::string &name,
601  ParamVertex *pv1, ParamVertex *pv2,
602  ParamVertex *pv3, ParamVertex *pv4);
603 
612  MeshFace(
613  const std::string &ref,
614  MLINT mid,
615  MLINT aref,
616  MLINT gref,
617  const std::string &name,
618  ParamVertex *pv1, ParamVertex *pv2,
619  ParamVertex *pv3, ParamVertex *pv4);
620 
622  ~MeshFace();
623 
625  virtual const std::string &getBaseName() const;
627  virtual MLUINT &getNameCounter();
628 
635  void getInds(MLINT *inds, MLINT *numInds) const;
636 
639  MLINT getParamVerts(ParamVertex * const ** pvs) const {
640  *pvs = &(paramVerts_[0]);
641  return getNumParamVerts();
642  }
643 
645  void getParamVerts(std::vector<ParamVertex*> &pvs) const {
646  pvs.clear();
647  for (int i = 0; i < 4; ++i) {
648  if (NULL != paramVerts_[i]) pvs.push_back(paramVerts_[i]);
649  }
650  return;
651  }
652 
655  {
656  MLINT count = 0;
657  for (int i = 0; i < 4; ++i) {
658  if (NULL != paramVerts_[i]) ++count;
659  }
660  return count;
661  }
662 
663 private:
666 
669  i1_(-1),
670  i2_(-1),
671  i3_(-1),
672  i4_(-1)
673  {
674  paramVerts_[0] = paramVerts_[1] = paramVerts_[2] = paramVerts_[3] = NULL;
675  };
676 
678  pwiFnvHash::FNVHash getHash() const;
679 
681  static pwiFnvHash::FNVHash computeHash(MLINT i1, MLINT i2, MLINT i3,
682  MLINT i4 = MESH_TOPO_INDEX_UNUSED);
683 
694 };
695 
696 typedef std::map<std::string, MeshFace *> MeshFaceNameMap;
697 
698 #endif
699 
700 /****************************************************************************
701  *
702  * DISCLAIMER:
703  * TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, POINTWISE DISCLAIMS
704  * ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
705  * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
706  * PURPOSE, WITH REGARD TO THIS SCRIPT. TO THE MAXIMUM EXTENT PERMITTED
707  * BY APPLICABLE LAW, IN NO EVENT SHALL POINTWISE BE LIABLE TO ANY PARTY
708  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
709  * WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
710  * BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE
711  * USE OF OR INABILITY TO USE THIS SCRIPT EVEN IF POINTWISE HAS BEEN
712  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF THE
713  * FAULT OR NEGLIGENCE OF POINTWISE.
714  *
715  ***************************************************************************/
MLINT getID() const
Return this entity's ID.
Definition: MeshTopo.h:97
std::map< MLINT, std::string > ParamVertIDToVrefMap
Definition: MeshTopo.h:116
MLINT i2_
The index of the second point.
Definition: MeshTopo.h:687
virtual const std::string & getBaseName() const
Return the base name used for generating unique names for edges.
MLINT i1_
The index of this point.
Definition: MeshTopo.h:403
ParamVertVrefMap paramVertVrefMap_
ParamVertex objects mapped to this entity by application-defined reference string.
Definition: MeshTopo.h:295
MLREAL v_
The parametric V value.
Definition: MeshTopo.h:112
MeshEdge & operator=(const MeshEdge &other)
Copy operator.
MLINT gref_
The geometry reference ID.
Definition: MeshTopo.h:106
~MeshPoint()
Destructor.
std::map< std::string, MeshEdge * > MeshEdgeNameMap
Definition: MeshTopo.h:534
static MLUINT nameCounter_
The unique name counter for points.
Definition: MeshTopo.h:388
static pwiFnvHash::FNVHash computeHash(MLINT i1)
Compute a point hash value for the given index value.
std::map< std::string, ParamVertex * > ParamVertVrefMap
Definition: MeshTopo.h:115
MLUINT orderCounter_
creation order counter in parent entity
Definition: MeshTopo.h:292
ParamVertex()
Default constructor.
Definition: MeshTopo.h:72
std::string name_
The name of the mesh entity.
Definition: MeshTopo.h:290
Storage for mesh topology and geometry associativity data.
MLUINT64 MLUINT
Standard unsigned integer - value depends on IS64BIT macro.
Definition: Types.h:122
virtual const std::string & getBaseName() const
Return the base name used for generating unique names for points.
MLINT getNumParamVerts() const
Return number of ParamVertices associated with the MeshFace.
Definition: MeshTopo.h:654
std::map< std::string, MeshFace * > MeshFaceNameMap
Definition: MeshTopo.h:696
std::vector< MeshTopo * > MeshTopoArray
Definition: MeshTopo.h:306
ParamVertex *const getParamVert() const
Return ParamVertex associated with the MeshPoint.
Definition: MeshTopo.h:364
MeshEdge()
Hidden default constructor.
Definition: MeshTopo.h:514
static MLUINT nameCounter_
The unique name counter for faces.
Definition: MeshTopo.h:665
~MeshEdge()
Destructor.
3D (volume) mesh topology
Definition: MeshModel.h:38
MeshFace()
Hidden default constructor.
Definition: MeshTopo.h:668
0-D (point) mesh entity
Definition: MeshTopo.h:323
MLINT i4_
The index of the fourth point.
Definition: MeshTopo.h:691
2D (surface) mesh topology
Definition: MeshSheet.h:35
MLINT getParamVerts(ParamVertex *const **pvs) const
Return array of ParamVertices associated with the MeshPoint.
Definition: MeshTopo.h:373
virtual const std::string & getBaseName() const
Return the base name used for generating unique names for faces.
1D (curve) mesh topology
Definition: MeshString.h:33
std::string ref_
The application-defined reference string.
Definition: MeshTopo.h:280
MLINT getNumParamVerts() const
Return number of ParamVertices associated with the MeshEdge.
Definition: MeshTopo.h:500
std::map< std::string, std::string > MeshTopoRefToNameMap
Definition: MeshTopo.h:308
static MLUINT nameCounter_
The unique name counter.
Definition: MeshTopo.h:301
MLINT getParamVerts(ParamVertex *const **pvs) const
Return array of ParamVertices associated with the MeshFace.
Definition: MeshTopo.h:639
MLINT i2_
The index of the ending point in the edge.
Definition: MeshTopo.h:530
ParamVertIDToVrefMap paramVertIDToVrefMap_
ParamVertex objects mapped to this entity by unique entity ID.
Definition: MeshTopo.h:297
void getInds(MLINT *inds, MLINT *numInds) const
Return array of vertex indices associated with the MeshFace.
static pwiFnvHash::FNVHash computeHash(MLINT i1, MLINT i2, MLINT i3, MLINT i4=MESH_TOPO_INDEX_UNUSED)
Return a hash value for the given point indices.
static pwiFnvHash::FNVHash computeHash(MLINT i1, MLINT i2)
Return a hash value for the given point indices.
std::map< MLINT, std::string > MeshTopoIDToNameMap
Definition: MeshTopo.h:304
1-D (edge) mesh entity
Definition: MeshTopo.h:421
virtual MLUINT & getNameCounter()
Return the current value used for generating unique names for faces.
const std::string & getVref() const
Return the MeshPoint vertex reference.
Definition: MeshTopo.h:93
pwiFnvHash::FNVHash getHash() const
Return the hash value for this face.
MeshPoint()
Hidden default constructor.
Definition: MeshTopo.h:391
MLINT aref_
The attribute reference ID (AttID)
Definition: MeshTopo.h:286
ParamVertex * paramVerts_[4]
The array of ParamVertex objects associated with the face points.
Definition: MeshTopo.h:693
MLINT i1_
The index of the first point.
Definition: MeshTopo.h:685
MLINT gref_
The geometry reference ID.
Definition: MeshTopo.h:288
2-D (face) mesh entity
Definition: MeshTopo.h:548
std::map< std::string, MeshPoint * > MeshPointNameMap
Definition: MeshTopo.h:408
ParamVertex * paramVert_
The ParamVertex associated with this point.
Definition: MeshTopo.h:405
MLINT getGref() const
Return the associated geometry GID.
Definition: MeshTopo.h:95
static MLUINT nameCounter_
The unique name counter for edges.
Definition: MeshTopo.h:511
MLINT mid_
The unique ID.
Definition: MeshTopo.h:108
virtual MLUINT & getNameCounter()
Return the current value used for generating unique names for points.
void getInds(MLINT *inds, MLINT *numInds) const
Return array of vertex indices associated with the MeshEdge.
MLREAL u_
The parametric U value.
Definition: MeshTopo.h:110
double MLREAL
64-bit real
Definition: Types.h:115
ParamVertex(const std::string &vref, MLINT gref, MLINT mid, MLREAL u, MLREAL v)
Definition: MeshTopo.h:85
~MeshFace()
Destructor.
ParamVertex * paramVerts_[2]
The ParamVertex objects associated with the points in the edge.
Definition: MeshTopo.h:532
pwiFnvHash::FNVHash getHash() const
Return the hash value for this point.
MLINT getParamVerts(ParamVertex *const **pvs) const
Return pointer to array of ParamVertices associated with the MeshEdge.
Definition: MeshTopo.h:485
MLINT i1_
The index of the starting point in the edge.
Definition: MeshTopo.h:528
virtual MLUINT & getNameCounter()
Return the current value used for generating unique names for edges.
void getParamVerts(std::vector< ParamVertex * > &pvs) const
Return vector of pointers to ParamVertices associated with the MeshEdge.
Definition: MeshTopo.h:491
MLINT i3_
The index of the third point.
Definition: MeshTopo.h:689
MLINT mid_
The unique entity ID.
Definition: MeshTopo.h:284
std::string vref_
The application-defined reference string.
Definition: MeshTopo.h:104
Base class for mesh topology entities.
Definition: MeshTopo.h:132
Parametric geometry data.
Definition: MeshTopo.h:69
MLINT64 MLINT
Standard integer - value depends on IS64BIT macro.
Definition: Types.h:120
pwiFnvHash::FNVHash getHash() const
Return the hash value for this edge.
void getParamVerts(std::vector< ParamVertex * > &pvs) const
Return vector of pointers to ParamVertices associated with the MeshFace.
Definition: MeshTopo.h:645
void getUV(MLREAL *u, MLREAL *v) const
Return the associated geometry parametric coordinates.
Definition: MeshTopo.h:101