MeshLink
Computational geometry access
GeomKernel_Geode.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 GEOM_KERNEL_GEODE
13 #define GEOM_KERNEL_GEODE
14 
15 #include "Types.h"
16 #include "GeometryKernel.h"
17 
18 #include <geom/Curve.h>
19 
20 #include <map>
21 #include <set>
22 #include <string>
23 
24 namespace GE {
25  class CharString;
26  class Entity;
27  class EntityError;
28  class IsectProjPoint;
29  class ProjectionBSPTree;
30  class Vector3D;
31 }
32 
33 #include <geom/EntityError.h>
34 #include <geom/Database.h>
35 #include <nmb/NativeTopologyReader.h>
36 #include <geom/Plane.h>
37 #include <nmb/CurvedFace.h>
38 #include <nmb/CurvedModel.h>
39 
40 
41 /****************************************************************************
42  *
43  * GEErrorHandler class
44  *
45  * A custom handler for Geode messages.
46  *
47  ***************************************************************************/
48 class GeodeErrorHandler : public GE::ErrorHandler {
49 public:
50  virtual void HandleDebug(const GE::EntityError &e) {}
51  virtual void HandleDebug(const GE::CharString &errorMessage) {}
52  virtual void HandleInfo(const GE::EntityError &e) {}
53  virtual void HandleInfo(const GE::CharString &errorMessage) {}
54  virtual void HandleWarning(const GE::EntityError &e) {}
55  virtual void HandleWarning(const GE::CharString &errorMessage) {}
56  virtual void HandleError(const GE::EntityError &e) {}
57  virtual void HandleError(const GE::CharString &errorMessage) {}
58 };
59 
60 /****************************************************************************
61 * GeometryKernelGeode class
62 ***************************************************************************/
71 public:
72  friend class ProjectionData;
74 
76 
77  // Read the geometry data file
78  bool read(const char *filename);
79 
80  const char * getName() const
81  {
82  return "Geode";
83  }
84 
85  // Project a point onto the Geometry group
86  bool projectPoint(const GeometryGroup *group,
87  const MLVector3D point,
88  ProjectionData &projectionData);
89 
90  bool getProjectionXYZ(ProjectionData &projectionData, MLVector3D point);
91 
92  bool getProjectionUV(ProjectionData &projectionData, MLVector2D UV);
93 
94  bool getProjectionEntityName(ProjectionData &projectionData, std::string &name);
95 
96  bool getProjectionTolerance(ProjectionData &projectionData, MLREAL &tolerance);
97 
98  bool getProjectionDistance(ProjectionData &projectionData, MLREAL &distance);
99 
100  bool evalXYZ(MLVector3D UV, const std::string &entityName, MLVector3D xyz);
101 
102  bool evalRadiusOfCurvature(MLVector2D UV, const std::string &entityName,
103  MLREAL *minRadiusOfCurvature, MLREAL *maxRadiusOfCurvature );
104 
106  MLVector2D UV,
107  const std::string &entityName,
108  MLVector3D XYZ, // Evaluated location on curve
109  MLVector3D Tangent, // tangent to curve
110  MLVector3D PrincipalNormal, // principal normal (pointing towards the center of curvature)
111  MLVector3D Binormal, // binormal (tangent x principal normal)
112  // curvature in radians per unit length
113  // ALWAYS non-negative and in the direction of the principal normal
114  // Radius of curvature = 1 / Curvature
115  MLREAL *Curvature,
116  bool *Linear // If true, the curve is linear and has no unique normal
117  );
118 
120  const std::string &entityName,
121  MLREAL &minTolerance,
122  MLREAL &maxTolerance);
123 
125  MLVector2D UV, // Parametric location
126  const std::string &entityName,
127  MLVector3D XYZ, // Evaluated location on curve
128  MLVector3D dXYZdU, // First derivative
129  MLVector3D d2XYZdU2 // Second derivative
130  );
131 
133  MLVector2D UV,
134  const std::string &entityName,
135  MLVector3D XYZ, // Evaluated location on surface
136  MLVector3D dXYZdU, // First partial derivative
137  MLVector3D dXYZdV, // First partial derivative
138  MLVector3D d2XYZdU2, // Second partial derivative
139  MLVector3D d2XYZdUdV, // Second partial derivative
140  MLVector3D d2XYZdV2, // Second partial derivative
141  MLVector3D surfaceNormal, // Surface normal - unit vector
142  // Unit vector tangent to surface where curvature = min
143  // surfaceNormal cross principalV yields the direction where curvature = max
144  // if the surface is locally planar (min and max are 0.0) or if the
145  // surface is locally spherical (min and max are equal),
146  // this will be an arbitrary vector tangent to the surface
147  MLVector3D principalV,
148  // Minimum and maximum curvature, in radians per unit length
149  // Defined so that positive values indicate the surface bends
150  // in the direction of surfaceNormal, and negative values indicate
151  // the surface bends away from surfaceNormal
152  MLREAL *minCurvature,
153  MLREAL *maxCurvature,
154 
155  // The average or mean curvature is defined as :
156  // avg = (min + max) / 2
157  // The Gaussian curvature is defined as :
158  // gauss = min * max
159  MLREAL *avg, // Average curvature
160  MLREAL *gauss, // Gaussian curvature
161  MLORIENT *orientation // Orientation of surface in model
162  );
163 
165  MLTYPE entityType(const char* name);
166 
168  bool entityExists(const char* name) const;
169 
171  // Used to define tolerances within the geometry kernel
172  void setModelSize(MLREAL size);
173 
175  MLREAL getModelSize() const;
176 
177 
178 
179 private:
182 
184  void deleteProjectionDataObject(ProjectionDataObj projectionData);
185 
186  GE::Entity* getEntity(const std::string &name) const;
187 
189  void buildEntityMap();
190 
196  GE::ProjectionBSPTree *getBSPTree(const GeometryGroup *group);
197 
198  GeodeErrorHandler errorHandler_;
199  GE::Database database_;
200  GE::EntityList<GE::Entity> usable_entities_;
201  std::map<std::string, GE::Entity*> usable_entity_map_;
202  std::map<const GeometryGroup *, GE::ProjectionBSPTree *> BSPTreeMap_;
203 };
204 #endif
205 
206 /****************************************************************************
207  *
208  * DISCLAIMER:
209  * TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, POINTWISE DISCLAIMS
210  * ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
211  * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
212  * PURPOSE, WITH REGARD TO THIS SCRIPT. TO THE MAXIMUM EXTENT PERMITTED
213  * BY APPLICABLE LAW, IN NO EVENT SHALL POINTWISE BE LIABLE TO ANY PARTY
214  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
215  * WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
216  * BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE
217  * USE OF OR INABILITY TO USE THIS SCRIPT EVEN IF POINTWISE HAS BEEN
218  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF THE
219  * FAULT OR NEGLIGENCE OF POINTWISE.
220  *
221  ***************************************************************************/
bool getProjectionTolerance(ProjectionData &projectionData, MLREAL &tolerance)
Return the projection tolerance.
std::map< const GeometryGroup *, GE::ProjectionBSPTree * > BSPTreeMap_
GE::ProjectionBSPTree * getBSPTree(const GeometryGroup *group)
MeshLinkObject ProjectionDataObj
Opaque pointer to a ProjectionData object.
Definition: Types.h:219
Base class for geometry kernel interface.
MLREAL getModelSize() const
Return the geometry model size.
bool projectPoint(const GeometryGroup *group, const MLVector3D point, ProjectionData &projectionData)
Project a Cartesian point onto the Geometry group.
const char * getName() const
Return the name of the geometry kernel.
ProjectionDataObj getProjectionDataObject()
Construct a point projection data object for use by the geometry kernel.
int MLORIENT
Geometry orientation with respect to container entity.
Definition: Types.h:240
MLTYPE entityType(const char *name)
Determine entity type.
MLREAL MLVector3D[3]
3D vector of MLREAL
Definition: Types.h:154
bool evalXYZ(MLVector3D UV, const std::string &entityName, MLVector3D xyz)
void buildEntityMap()
Construct map of entity names to Geode entities.
bool getProjectionUV(ProjectionData &projectionData, MLVector2D UV)
Return the projection hit entity parametric coordinates.
std::map< std::string, GE::Entity * > usable_entity_map_
GeodeErrorHandler errorHandler_
bool evalSurfaceTolerance(const std::string &entityName, MLREAL &minTolerance, MLREAL &maxTolerance)
Evaluate the model assembly tolerance on a surface entity.
void setModelSize(MLREAL size)
Set the model size of the geometry.
bool read(const char *filename)
Read the geometry data file.
Provide computational geometry access using the Geode kernel.
bool evalDerivativesOnCurve(MLVector2D UV, const std::string &entityName, MLVector3D XYZ, MLVector3D dXYZdU, MLVector3D d2XYZdU2)
Evaluate the parametric derivatives on a curve entity at the parametric coordinates.
Opaque container for geometry kernel point projection specific data.
bool entityExists(const char *name) const
Determine if entity matching name exists.
MLREAL MLVector2D[2]
2D vector of MLREAL
Definition: Types.h:156
bool evalCurvatureOnSurface(MLVector2D UV, const std::string &entityName, MLVector3D XYZ, MLVector3D dXYZdU, MLVector3D dXYZdV, MLVector3D d2XYZdU2, MLVector3D d2XYZdUdV, MLVector3D d2XYZdV2, MLVector3D surfaceNormal, MLVector3D principalV, MLREAL *minCurvature, MLREAL *maxCurvature, MLREAL *avg, MLREAL *gauss, MLORIENT *orientation)
Evaluate the curvature on a surface entity at the parametric coordinates.
bool evalCurvatureOnCurve(MLVector2D UV, const std::string &entityName, MLVector3D XYZ, MLVector3D Tangent, MLVector3D PrincipalNormal, MLVector3D Binormal, MLREAL *Curvature, bool *Linear)
Evaluate the curvature on a curve entity at the parametric coordinates.
bool evalRadiusOfCurvature(MLVector2D UV, const std::string &entityName, MLREAL *minRadiusOfCurvature, MLREAL *maxRadiusOfCurvature)
Evaluate the radius of curvature at the entity parametric coordinates.
double MLREAL
64-bit real
Definition: Types.h:115
bool getProjectionDistance(ProjectionData &projectionData, MLREAL &distance)
Return the projection distance.
GE::EntityList< GE::Entity > usable_entities_
void deleteProjectionDataObject(ProjectionDataObj projectionData)
Delete (and free) a point projection data object.
int MLTYPE
Basic geometry type.
Definition: Types.h:252
bool getProjectionXYZ(ProjectionData &projectionData, MLVector3D point)
Return the projection hit Cartesian coordinates.
GE::Entity * getEntity(const std::string &name) const
bool getProjectionEntityName(ProjectionData &projectionData, std::string &name)
Return the projection hit entity name.
Storage for geometry association by entity reference.
Definition: GeometryGroup.h:38