libsurf
Programmer's Documentation

product.h (r6227/r5385)
1 
2 /* Copyright (C) 2015 David Eller <david@larosterna.com>
3  *
4  * Commercial License Usage
5  * Licensees holding valid commercial licenses may use this file in accordance
6  * with the terms contained in their respective non-exclusive license agreement.
7  * For further information contact david@larosterna.com .
8  *
9  * GNU General Public License Usage
10  * Alternatively, this file may be used under the terms of the GNU General
11  * Public License version 3.0 as published by the Free Software Foundation and
12  * appearing in the file gpl.txt included in the packaging of this file.
13  */
14 
15 #ifndef SURF_PRODUCT_H
16 #define SURF_PRODUCT_H
17 
18 #include "forward.h"
19 #include "producttree.h"
20 #include "surface.h"
21 #include "abstractcurve.h"
22 #include "igesentity.h"
23 
29 class Product
30 {
31 public:
32 
33  enum SurfaceStatus {TopLevel = 0, BaseSurface = 1,
34  Referenced = 4, MeshOnly = 8};
35 
37  Product() {}
38 
40  CgMeshPtr insert(uint index, SurfacePtr psf) {
41  EntityIndex idx;
42  idx.psf = psf;
43  idx.cgr = boost::make_shared<CgMesh>();
44  m_entities.insert( std::make_pair(index,idx) );
45  return idx.cgr;
46  }
47 
49  CgMeshPtr insert(uint index, AbstractCurvePtr psf) {
50  EntityIndex idx;
51  idx.pcv = psf;
52  idx.cgr = boost::make_shared<CgMesh>();
53  m_entities.insert( std::make_pair(index,idx) );
54  return idx.cgr;
55  }
56 
58  void insert(uint index, CgMeshPtr pcg, int status = MeshOnly) {
59  EntityIndex idx;
60  idx.cgr = pcg;
61  idx.status = MeshOnly | status;
62  m_entities.insert( std::make_pair(index,idx) );
63  }
64 
66  uint nsurfaces() const {return m_entities.size();}
67 
69  SurfacePtr findSurface(uint k) const {
70  EntityMap::const_iterator itr = m_entities.find(k);
71  if (itr != m_entities.end())
72  return itr->second.psf;
73  else
74  return SurfacePtr();
75  }
76 
78  void fromIges(const IgesFile & file, int importScope = IgesEntity::AnyClass);
79 
81  void fromStep(const StepFile & file);
82 
84  uint tessellate(uint maxtri=2000000);
85 
87  void fromSTL(const StringArray & files);
88 
90  ProductTreePtr rootNode() const {return m_ptree;}
91 
93  void collapseMesh();
94 
96  void toMx(MxMesh & mx) const;
97 
99  void fromMx(const MxMesh & mx);
100 
102  template <class Functor>
103  void foreachSurface(Functor & srfFunction) const {
104  EntityMap::const_iterator itr, last = m_entities.end();
105  for (itr = m_entities.begin(); itr != last; ++itr)
106  srfFunction( itr->first, itr->second.psf );
107  }
108 
110  template <class Functor>
111  void foreachMesh(Functor & cgmFunction) const {
112  EntityMap::const_iterator itr, last = m_entities.end();
113  for (itr = m_entities.begin(); itr != last; ++itr)
114  cgmFunction( itr->first, itr->second.cgr );
115  }
116 
118  XmlElement toXml(bool share = false) const;
119 
121  void fromXml(const XmlElement & xe);
122 
124  void clear();
125 
127  void print() const;
128 
129 protected:
130 
132  void assignSurfaces(ProductTreePtr subtree);
133 
135  void importElements(int id, const std::string &meshName,
136  const PointList<3> &vtx, const Indices &tri);
137 
138 protected:
139 
141  struct EntityIndex {
142 
144  EntityIndex() : status(TopLevel) {}
145 
147  void tesselate(uint maxtri=60000) {
148  if (psf and cgr)
149  psf->tessellate(*cgr, maxtri);
150  else if (pcv and cgr)
151  pcv->tessellate(*cgr);
152  }
153 
155  XmlElement toXml(bool share) const;
156 
158  void fromXml(const XmlElement &xe);
159 
161  SurfacePtr psf;
162 
164  AbstractCurvePtr pcv;
165 
167  CgMeshPtr cgr;
168 
170  int status;
171  };
172 
173  typedef std::map<uint,EntityIndex> EntityMap;
174 
176  EntityMap m_entities;
177 
179  ProductTreePtr m_ptree;
180 };
181 
182 #endif // PRODUCT_H
SurfacePtr findSurface(uint k) const
locate surface with key k
Definition: product.h:69
uint nsurfaces() const
number of referenced surfaces stored
Definition: product.h:66
EntityIndex()
create default empty index
Definition: product.h:144
void foreachSurface(Functor &srfFunction) const
iteration over each surface object
Definition: product.h:103
void fromStep(const StepFile &file)
populate product tree by reading STEP AP203 file (very limited support)
Definition: product.cpp:231
void insert(uint index, CgMeshPtr pcg, int status=MeshOnly)
insert a discrete surface, detached from product structure
Definition: product.h:58
void toMx(MxMesh &mx) const
convert top-level tree nodes to MxMesh for visualization in scope
Definition: product.cpp:333
ProductTreePtr rootNode() const
access root node
Definition: product.h:90
Main interface to IGES files.
Definition: igesfile.h:32
CgMeshPtr insert(uint index, AbstractCurvePtr psf)
insert a surface, detached from product structure
Definition: product.h:49
uint tessellate(uint maxtri=2000000)
(re-) generate all surface discretizations, return number of triangles
Definition: product.cpp:280
Internal entity data.
Definition: product.h:141
XmlElement toXml(bool share=false) const
generate an XML representation
Definition: product.cpp:461
void fromIges(const IgesFile &file, int importScope=IgesEntity::AnyClass)
populate product tree by reading IGES file
Definition: product.cpp:122
ProductTreePtr m_ptree
tree structure
Definition: product.h:179
Structure, surface geometry and tessellation of surface model.
Definition: product.h:29
void fromSTL(const StringArray &files)
import from multiple STL files
Definition: product.cpp:32
SurfacePtr psf
pointer to surface
Definition: product.h:161
void fromXml(const XmlElement &xe)
recover from XML representation
Definition: product.cpp:519
CgMeshPtr insert(uint index, SurfacePtr psf)
insert a surface, detached from product structure
Definition: product.h:40
void importElements(int id, const std::string &meshName, const PointList< 3 > &vtx, const Indices &tri)
utility used for mesh element import
Definition: product.cpp:413
void fromMx(const MxMesh &mx)
import an MxMesh and create a tree node from each section
Definition: product.cpp:342
void clear()
erase all data
Definition: product.cpp:432
CgMeshPtr cgr
tessellation (may be null)
Definition: product.h:167
AbstractCurvePtr pcv
pointer to curve
Definition: product.h:164
Product()
create empty product
Definition: product.h:37
void fromXml(const XmlElement &xe)
recover from XML representation
Definition: product.cpp:478
void tesselate(uint maxtri=60000)
update discretization
Definition: product.h:147
XmlElement toXml(bool share) const
create XML representation
Definition: product.cpp:508
void collapseMesh()
collapse complete discrete geometry into root node
Definition: product.cpp:327
EntityMap m_entities
surface-to-index mapping
Definition: product.h:176
void foreachMesh(Functor &cgmFunction) const
iteration over each mesh object
Definition: product.h:111
STEP File.
Definition: stepfile.h:44
void assignSurfaces(ProductTreePtr subtree)
assign surfaces to children of subtree
Definition: product.cpp:260
int status
indicates how the surface is referenced
Definition: product.h:170
void print() const
write out structure (debugging)
Definition: product.cpp:440
Generated on Wed Jan 19 2022 03:03:15 for libsurf by   doxygen 1.8.5