SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
ForEachTypes.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 
11 #ifndef smtk_mesh_core_ForEachTypes_h
12 #define smtk_mesh_core_ForEachTypes_h
13 
14 #include "smtk/CoreExports.h"
15 #include "smtk/PublicPointerDefs.h"
16 
17 #include "smtk/mesh/core/CellTypes.h"
18 #include "smtk/mesh/core/Handle.h"
19 
20 namespace smtk
21 {
22 namespace mesh
23 {
24 
25 //forward declare of CellSet and MeshSet
26 class CellSet;
27 class MeshSet;
28 
29 class SMTKCORE_EXPORT MeshForEach
30 {
31 public:
32  virtual ~MeshForEach();
33 
34  virtual void forMesh(smtk::mesh::MeshSet& singleMesh) = 0;
35 
36  smtk::mesh::ResourcePtr m_resource;
37 };
38 
39 class SMTKCORE_EXPORT CellForEach
40 {
41 public:
42  CellForEach(bool wantCoordinates = true);
43 
44  virtual ~CellForEach();
45 
46  virtual void
47  forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType cellType, int numPointIds) = 0;
48 
49  //returns true if the CellForEach visitor wants its coordinates member
50  //variable filled
51  bool wantsCoordinates() const { return m_wantsCoordinates; }
52 
53  const smtk::mesh::Handle* pointIds() const { return m_pointIds; }
54 
55  smtk::mesh::Handle pointId(int index) const { return m_pointIds[index]; }
56 
57  const std::vector<double>& coordinates() const { return *m_coords; }
58 
59  smtk::mesh::ResourcePtr resource() const { return m_resource; }
60 
61  //Set the coords for the visitor. This should be only be called by
62  //smtk::mesh::Interface implementations
63  void coordinates(std::vector<double>* coords) { m_coords = coords; }
64 
65  //Set the pointIds for the visitor. This should be only be called by
66  //smtk::mesh::Interface implementations
67  void pointIds(const smtk::mesh::Handle* ptIds) { m_pointIds = ptIds; }
68 
69  //Set the resource() for the visitor. This should be only be called by
70  //smtk::mesh::Interface implementations
71  void resource(smtk::mesh::ResourcePtr r) { m_resource = r; }
72 
73 private:
74  smtk::mesh::ResourcePtr m_resource;
75  const smtk::mesh::Handle* m_pointIds{ nullptr };
76  std::vector<double>* m_coords{ nullptr };
77  bool m_wantsCoordinates;
78 };
79 
80 class SMTKCORE_EXPORT PointForEach
81 {
82 public:
83  virtual ~PointForEach();
84 
85  // PointForEach allows read access to the point ids and coordinates and write
86  // access to the coordinates ( x, y, z ) it is iterating. This is different
87  // than Cell and Mesh iteration which are read only.
88  //
89  // If the forPoints needs to modify the coordinates, you have to explicitly
90  // set coordinatesModified to be true, otherwise the modified coordinates will
91  // be ignored.
92  //
93  // Note: by default coordinatesModified is set to false
94  //
95  //
96  virtual void forPoints(
97  const smtk::mesh::HandleRange& pointIds,
98  std::vector<double>& xyz,
99  bool& coordinatesModified) = 0;
100 
101  smtk::mesh::ResourcePtr m_resource;
102 };
103 } // namespace mesh
104 } // namespace smtk
105 
106 #endif
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
PublicPointerDefs.h
smtk::mesh::CellType
CellType
Enum types used for querying the interface.
Definition: CellTypes.h:29
smtk::mesh::ResourcePtr
smtk::shared_ptr< smtk::mesh::Resource > ResourcePtr
Definition: PublicPointerDefs.h:356
smtk::model::CellSet
std::set< smtk::model::CellEntity > CellSet
Definition: PublicPointerDefs.h:158
smtk::mesh::MeshSet
Definition: MeshSet.h:42
smtk::mesh::PointForEach
Definition: ForEachTypes.h:80
smtk::mesh::MeshForEach
Definition: ForEachTypes.h:29
smtk::mesh::CellForEach
Definition: ForEachTypes.h:39