Skip to content

Commit e7b17b6

Browse files
committed
Implemented canGetClosestPoint and isOnModel
1 parent d783b19 commit e7b17b6

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

apf/apfMesh.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ bool Mesh::canSnap()
175175
return gmi_can_eval(getModel());
176176
}
177177

178+
bool Mesh::canGetClosestPoint()
179+
{
180+
return gmi_can_get_closest_point(getModel());
181+
}
182+
178183
bool Mesh::canGetModelNormal()
179184
{
180185
return gmi_has_normal(getModel());
@@ -252,6 +257,16 @@ bool Mesh::isInClosureOf(ModelEntity* g, ModelEntity* target){
252257
return (res == 1) ? true : false;
253258
}
254259

260+
bool Mesh::isOnModel(ModelEntity* g, Vector3 p, double scale)
261+
{
262+
Vector3 to;
263+
double param[2];
264+
gmi_ent* c = (gmi_ent*)g;
265+
gmi_closest_point(getModel(), c, &p[0], &to[0], param);
266+
double ratio = (to - p).getLength() / scale;
267+
return ratio < 0.001;
268+
}
269+
255270
void Mesh::getPoint(MeshEntity* e, int node, Vector3& p)
256271
{
257272
getVector(coordinateField,e,node,p);

apf/apfMesh.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ class Mesh
285285
ModelEntity* findModelEntity(int type, int tag);
286286
/** \brief return true if the geometric model supports snapping */
287287
bool canSnap();
288+
/** \brief return true if the geometric model supports get closest point */
289+
bool canGetClosestPoint();
288290
/** \brief return true if the geometric model supports normal computation */
289291
bool canGetModelNormal();
290292
/** \brief evaluate parametric coordinate (p) as a spatial point (x) */
@@ -310,6 +312,8 @@ class Mesh
310312
Vector3 const& param, Vector3& x);
311313
/** \brief checks if g is in the closure of the target */
312314
bool isInClosureOf(ModelEntity* g, ModelEntity* target);
315+
/** \brief checks if p is on model g */
316+
bool isOnModel(ModelEntity* g, Vector3 p, double scale);
313317
/** \brief get the distribution of the mesh's coordinate field */
314318
FieldShape* getShape() const;
315319
/** \brief get the mesh's coordinate field */

gmi/gmi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ int gmi_can_eval(struct gmi_model* m)
8585
return m->ops->eval != NULL;
8686
}
8787

88+
int gmi_can_get_closest_point(struct gmi_model* m)
89+
{
90+
return m->ops->closest_point != NULL;
91+
}
92+
8893
int gmi_has_normal(struct gmi_model* m)
8994
{
9095
return m->ops->normal != NULL;

gmi/gmi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ struct gmi_ent* gmi_find(struct gmi_model* m, int dim, int tag);
145145
struct gmi_set* gmi_adjacent(struct gmi_model* m, struct gmi_ent* e, int dim);
146146
/** \brief check whether the model implements gmi_eval */
147147
int gmi_can_eval(struct gmi_model* m);
148+
/** \brief check whether the model gmi_closest_point */
149+
int gmi_can_get_closest_point(struct gmi_model* m);
148150
/** \brief check whether the model implements gmi_normal */
149151
int gmi_has_normal(struct gmi_model* m);
150152
/** \brief evaluate the parametric definition of a model boundary entity

0 commit comments

Comments
 (0)