MeshLink
Computational geometry access
MeshAssociativity.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_ASSOCIATIVITY_CLASS
13 #define MESH_ASSOCIATIVITY_CLASS
14 
76 #include "Types.h"
77 #include "GeometryGroup.h"
78 #include "GeometryKernel.h"
79 #include "MeshModel.h"
80 
81 #include <stdio.h>
82 #include <string>
83 #include <vector>
84 
86 class MeshAssociativity;
87 
88 /****************************************************************************
89  * MeshLinkTransform class
90  ***************************************************************************/
105 class ML_STORAGE_CLASS MeshLinkTransform {
106 public:
107  friend class MeshAssociativity;
108 
111 
114  MeshLinkTransform(MLINT xid, std::string &name, std::string &contents,
115  MeshAssociativity &meshAssoc);
116 
120  virtual void setAref(MLINT aref);
121 
123  bool hasAref() const;
124 
126  MLINT getAref() const;
127 
129  MLINT getXID() const;
130 
132  const std::string & getName() const;
133 
135  const std::string & getContents() const;
136 
139  bool isValid() const { return is_valid_; }
140 
144  void getQuaternion(MLREAL xform_quaternion[4][4]) const;
145 
146 private:
150  std::string name_;
154  std::string contents_;
156  MLREAL xform_[4][4];
158  bool is_valid_;
159 };
160 
161 
162 /****************************************************************************
163  * MeshElementLinkage class
164  ***************************************************************************/
179 class ML_STORAGE_CLASS MeshElementLinkage {
180 public:
181  friend class MeshAssociativity;
182 
185 
188  MeshElementLinkage(std::string &name,
189  std::string &sourceEntityRef,
190  std::string &targetEntityRef,
191  MeshAssociativity &meshAssoc);
192 
196  virtual void setAref(MLINT aref);
197 
199  bool hasAref() const;
200 
202  MLINT getAref() const;
203 
207  virtual bool setXref(MLINT xref, MeshAssociativity &meshAssoc);
208 
210  bool hasXref() const;
211 
215  virtual bool getXref(MLINT *xref) const;
216 
220  const MeshLinkTransform * getTransform(const MeshAssociativity &meshAssoc) const;
221 
224  bool isValid() const { return is_valid_; }
225 
231  virtual void getName(const char **name) const;
232 
234  virtual const std::string & getName() const;
235 
242  void setName(const std::string &name);
243 
248  //
250  void setName(const char *name);
251 
253  std::string getNextName();
254 
259  void getEntityRefs(std::string &sourceEntityRef, std::string &targetEntityRef) const;
260 
262  virtual const std::string &getBaseName() const;
264  virtual MLUINT &getNameCounter();
265 
266 private:
269 
271  std::string name_;
277  std::string sourceEntityRef_;
279  std::string targetEntityRef_;
281  bool is_valid_;
282 };
283 
284 /****************************************************************************
285  * MeshLinkAttribute class
286  ***************************************************************************/
301 class ML_STORAGE_CLASS MeshLinkAttribute {
302 public:
303  friend class MeshAssociativity;
304 
307 
310  MeshLinkAttribute(MLINT attid, std::string &name, std::string &contents,
311  bool is_group, MeshAssociativity &meshAssoc);
312 
314  MLINT getAttID() const;
315 
317  bool isGroup() const;
318 
321  bool isValid() const;
322 
327  const std::vector<MLINT> & getAttributeIDs() const;
328 private:
329 
336  bool buildGroupArefs(MeshAssociativity &meshAssoc);
337 
341  std::string name_;
343  std::string contents_;
345  bool is_group_;
347  bool is_valid_;
350  std::vector<MLINT> group_arefs_;
351 };
352 
353 
354 /****************************************************************************
355  * MeshLinkFile class
356  ***************************************************************************/
363 class ML_STORAGE_CLASS MeshLinkFile {
364 public:
365  friend class MeshAssociativity;
366 
369 
371  MeshLinkFile(std::string &filename, std::string &arefString):
372  filename_(filename),
373  arefString_(arefString)
374  {};
375 
378 
380  virtual const char *getFilename() const { return filename_.c_str(); }
381 
383  std::vector<MLINT> getAttributeIDs(const MeshAssociativity &meshAssoc) const;
384 
386  bool hasAref() const { return !arefString_.empty(); }
387 
389  bool getArefID(MLINT *aref) const {
390  if (!hasAref()) { return false; }
391  if (1 == sscanf(arefString_.c_str(), "%" MLINT_FORMAT, aref)) {
392  return true;
393  }
394  return false;
395  }
396 
397 protected:
399  std::string filename_;
400 
402  std::string arefString_;
403 };
404 
405 /****************************************************************************
406 * GeometryFile class
407 ***************************************************************************/
422 class ML_STORAGE_CLASS GeometryFile : public MeshLinkFile {
423 public:
426 
429  GeometryFile(std::string &filename, std::string &arefString) :
430  MeshLinkFile(filename, arefString)
431  {};
432 
435 
439  groupIDs_.push_back(gid);
440  }
441 
444  const std::vector<MLINT> &getGeometryGroupIDs() const
445  {
446  return groupIDs_;
447  }
448 private:
450  std::vector<MLINT> groupIDs_;
451 };
452 
453 /****************************************************************************
454 * MeshFile class
455 ***************************************************************************/
471 class ML_STORAGE_CLASS MeshFile : public MeshLinkFile {
472 public:
474  MeshFile() {};
475 
477  MeshFile(std::string &filename, std::string &arefString) :
478  MeshLinkFile(filename, arefString)
479  {};
480 
482  ~MeshFile() {};
483 
488  void addModelRef(const std::string &refName) {
489  modelRefs_.push_back(refName);
490  }
491 
492  // \brief Return the list of mesh model references associated with this mesh file
493  const std::vector<std::string> &getModelRefs() {
494  return modelRefs_;
495  }
496 
497 private:
499  std::vector<std::string> modelRefs_;
500 };
501 
502 
503 typedef std::map<std::string, MLINT> MeshAttributeNameToIDMap;
504 typedef std::map<MLINT, MeshLinkAttribute> MeshAttributeIDMap;
505 
506 typedef std::map<std::string, MLINT> MeshTransformNameToIDMap;
507 typedef std::map<MLINT, MeshLinkTransform> MeshTransformIDMap;
508 typedef std::map<std::string, MeshElementLinkage *> MeshElementLinkageNameMap;
509 
510 
511 /****************************************************************************
512  * MeshAssociativity class
513  ***************************************************************************/
523 class ML_STORAGE_CLASS MeshAssociativity {
524 public:
527 
530 
535  bool addGeometryGroup(GeometryGroup &geometry_group);
536 
540  MLINT getGeometryGroupCount() const;
541 
545  void getGeometryGroupIDs(std::vector<MLINT> &gids) const;
546 
551  GeometryGroup * getGeometryGroupByName(const char *name);
552 
557  GeometryGroup * getGeometryGroupByID(MLINT id);
558 
563  bool addMeshModel(MeshModel *model, bool mapID);
564 
569  MeshModel * getMeshModelByID(MLINT id) const;
570 
575  MeshModel * getMeshModelByName(const std::string &name) const;
576 
581  MeshModel* getMeshModelByRef(const char * ref) const;
582 
591  bool getMeshSheetByName(const std::string &name,
592  MeshModel **model, MeshSheet **sheet) const;
593 
602  bool getMeshStringByName(const std::string &name,
603  MeshModel **model, MeshString **string) const;
604 
612  void addGeometryKernel(GeometryKernel *kernel);
613 
617  void removeGeometryKernel(GeometryKernel *kernel);
618 
623  GeometryKernel * getGeometryKernelByName(const char *name);
624 
628  GeometryKernel * getActiveGeometryKernel();
629 
637  bool setActiveGeometryKernelByName(const char *name);
638 
643  const MeshLinkAttribute * getAttributeByID(const MLINT id) const;
644 
646  void clearAttributes();
647 
652  bool addAttribute(MeshLinkAttribute &att);
653 
655  std::vector<const MeshLinkAttribute *> getAttributes() const;
656 
657 
662  const MeshLinkTransform * getTransformByID(const MLINT id) const;
663 
665  void clearTransforms();
666 
671  bool addTransform(MeshLinkTransform &att);
672 
674  void getTransforms(std::vector<const MeshLinkTransform *> &xforms) const;
675 
677  size_t getTransformCount() const;
678 
679 
681  void clearMeshElementLinkages();
682 
687  bool addMeshElementLinkage(MeshElementLinkage *linkage);
688 
689 
695  getMeshElementLinkageByName(const std::string &name) const;
696 
697 
699  void getMeshElementLinkages(std::vector<MeshElementLinkage *> &linkages) const;
700 
702  size_t getMeshElementLinkageCount() const;
703 
705  MLINT getNumGeometryFiles() const;
706 
710  void addGeometryFile(GeometryFile &file);
711 
713  MLINT getNumMeshFiles() const;
714 
718  void addMeshFile(MeshFile &file);
719 
726  bool getAttribute(MLINT attID, const char **name, const char **value) const;
727 
729  const std::vector<GeometryFile> & getGeometryFiles() const;
730 
732  const std::vector<MeshFile> & getMeshFiles() const;
733 
735  void getMeshModels(std::vector<MeshModel *> &models) const;
736 
738  size_t getMeshModelCount() const;
739 
740 private:
742  std::vector<GeometryFile> geometryFiles_;
744  std::vector<MeshFile> meshFiles_;
745 
748 
751 
756 
761 
764 
765 
772 };
773 
774 
775 
776 /****************************************************************************
777  * GeometryKernelManager class
778  ***************************************************************************/
790 using GeometryKernelArray = std::vector<GeometryKernel *>;
791 
793 public:
794  friend class MeshAssociativity;
797  active_(NULL)
798  {};
799 
800 private:
804  void addKernel(GeometryKernel *kernel);
805 
809  void removeKernel(GeometryKernel *kernel);
810 
815  GeometryKernel * getByName(const char *name);
816 
821 
826  bool setActiveByName(const char *name);
827 
832 };
833 
834 #endif
835 
836 /****************************************************************************
837  *
838  * DISCLAIMER:
839  * TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, POINTWISE DISCLAIMS
840  * ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
841  * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
842  * PURPOSE, WITH REGARD TO THIS SCRIPT. TO THE MAXIMUM EXTENT PERMITTED
843  * BY APPLICABLE LAW, IN NO EVENT SHALL POINTWISE BE LIABLE TO ANY PARTY
844  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
845  * WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
846  * BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE
847  * USE OF OR INABILITY TO USE THIS SCRIPT EVEN IF POINTWISE HAS BEEN
848  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF THE
849  * FAULT OR NEGLIGENCE OF POINTWISE.
850  *
851  ***************************************************************************/
void addModelRef(const std::string &refName)
Add a MeshModel reference to this mesh file. Typically used by a MeshLinkParser when a new "MeshModel...
MeshTopoRefToNameMap meshModelRefToNameMap_
Map of mesh model reference string to MeshModel name.
GeometryKernel * active_
The active GeometryKernel.
Base class for geometry kernel interface.
std::map< MLINT, MeshLinkTransform > MeshTransformIDMap
const std::vector< MLINT > & getGeometryGroupIDs() const
Return a list of all geometry group IDs associated with this GeometryFile.
static MLUINT nameCounter_
The unique name counter for linkages.
void removeKernel(GeometryKernel *kernel)
MeshAssociativity()
Default constructor.
GeometryFile()
Default constructor.
std::vector< GeometryKernel * > GeometryKernelArray
const std::vector< std::string > & getModelRefs()
Storage for mesh topology and geometry associativity data.
MeshFile(std::string &filename, std::string &arefString)
Explicit constructor with mesh file name and attribute reference string.
std::vector< std::string > modelRefs_
The model references associated with a mesh file.
std::string name_
The name of this linkage.
MLUINT64 MLUINT
Standard unsigned integer - value depends on IS64BIT macro.
Definition: Types.h:122
std::map< std::string, MeshElementLinkage * > MeshElementLinkageNameMap
bool setActiveByName(const char *name)
std::vector< GeometryFile > geometryFiles_
Geometry files.
3D (volume) mesh topology
Definition: MeshModel.h:38
std::string sourceEntityRef_
The source entity reference.
MLINT aref_
The attribute reference ID (AttID)
std::map< std::string, MeshModel * > MeshModelNameMap
Definition: MeshModel.h:572
std::string targetEntityRef_
The target entity reference.
GeometryFile(std::string &filename, std::string &arefString)
Explicit constructor with file name (path) of geometry file and the attribute reference string.
2D (surface) mesh topology
Definition: MeshSheet.h:35
GeometryKernel * getActive()
std::vector< MeshFile > meshFiles_
Mesh files.
1D (curve) mesh topology
Definition: MeshString.h:33
Storage for MeshLink schema MeshFile data.
std::map< std::string, std::string > MeshTopoRefToNameMap
Definition: MeshTopo.h:308
Storage for MeshLink schema GeometryFile data.
Storage for geometry groups.
GeometryKernel * getByName(const char *name)
std::vector< MLINT > groupIDs_
The geometry group IDs in this file.
MeshAttributeIDMap meshAttributeIDMap_
Map of MeshAttribute to associated ID (aref)
static GeometryKernelManager geometry_kernel_manager_
The Singleton geometry kernel manager.
std::map< MLINT, std::string > MeshTopoIDToNameMap
Definition: MeshTopo.h:304
std::map< std::string, MLINT > MeshTransformNameToIDMap
MeshModelNameMap meshModelNameMap_
Map of mesh model name to MeshModel.
bool is_valid_
Whether this linkage is valid.
GeometryGroupManager geometry_group_manager_
The associativity geometry group manager.
~MeshFile()
Destructor.
MeshTransformNameToIDMap meshTransformNameToIDMap_
Map of MeshTransform name to associated XID (xref)
Management of geometry kernel interfaces.
std::map< MLINT, MeshLinkAttribute > MeshAttributeIDMap
GeometryKernelManager()
Default constructor, no active GeometryKernel by default.
~GeometryFile()
Destructor.
MeshTopoIDToNameMap meshModelIDToNameMap_
Map of mesh model ID to MeshModel name.
void addGeometryGroupID(MLINT gid)
Add a geometry group ID to the geometry file. Typically used by the MeshLinkParser when a new "Geomet...
Storage for MeshLink ElementLinkage data.
void addKernel(GeometryKernel *kernel)
MeshTransformIDMap meshTransformIDMap_
Map of MeshTransform to associated XID (xref)
double MLREAL
64-bit real
Definition: Types.h:115
MeshElementLinkageNameMap meshElementLinkageNameMap_
Map of element linkage name to MeshElementLinkage.
GeometryKernelArray geometry_kernels_
The list of managed GeometryKernel objects.
MeshAttributeNameToIDMap meshAttributeNameToIDMap_
Map of MeshAttribute name to associated ID (aref)
MLINT xref_
The transform reference ID (XID)
MeshFile()
Default constructor.
std::map< std::string, MLINT > MeshAttributeNameToIDMap
MLINT64 MLINT
Standard integer - value depends on IS64BIT macro.
Definition: Types.h:120
Storage for geometry association by entity reference.
Definition: GeometryGroup.h:38