Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add topo model support for gmi_is_in_closure #369

Open
cwsmith opened this issue Jul 22, 2022 · 1 comment
Open

add topo model support for gmi_is_in_closure #369

cwsmith opened this issue Jul 22, 2022 · 1 comment

Comments

@cwsmith
Copy link
Contributor

cwsmith commented Jul 22, 2022

Thanks to @KennethEJansen for providing an initiail implementation of the topo model's function for gmi_is_in_closure_of. I think it could be added to gmi_base.c. test/inClosureOf_test.cc should then be supported by Simmetrix SimModSuite models and dmg models (it currently crashes when a .dmg model is loaded).

Below is closure test that replaces the calls with adjacencies and gives the same results. I have left the calls to gmi_is_in_closure_of commented with my replacement code just above it. The face check is trivial. The edge check is a single loop and finally the vertex check is a double loop. I am sure a reasonably skilled C++ programmer could make a function like that found in gmi_sim.cc to take these branches based on the dim of the entity being checked.

43   gmi_ent* g;
 44   int ff;
 45 
 46   // go through the model vertexes and check if they are in closure of gf
 47   printf("checking verts against face with tag %d\n",
 48       gmi_tag(model, gf));
 49   gi = gmi_begin(model, 0);
 50   while( (g = gmi_next(model, gi)) ){
 51     ff=-1;
 52     gmi_set* Edges = gmi_adjacent(model,gf,1);
 53     for (int i = 0; i < ((Edges->n)); i++) {
 54       gmi_set* Verts = gmi_adjacent(model,Edges->e[i],0);
 55       for (int j = 0; j < Verts->n; j++)  
 56         if(g==Verts->e[j]) ff=j;
 57     }
 58 //    int res = gmi_is_in_closure_of(model, g, gf);
 59     if (ff!=-1)
 60       printf("vertex with tag %d IS inside the face with tag %d\n",
 61           gmi_tag(model, g), gmi_tag(model, gf));
 62     else  
 63       printf("vertex with tag %d IS NOT inside the face with tag %d\n",
 64           gmi_tag(model, g), gmi_tag(model, gf));
 65   }       
 66   gmi_end(model, gi); // end the iterator
 67 
 68   // go through the model edges and check if they are in closure of gf
 69   printf("checking edges against face with tag %d\n",
 70       gmi_tag(model, gf));
 71   gi = gmi_begin(model, 1);
 72   while( (g = gmi_next(model, gi)) ){
 73     ff=-1;
 74     gmi_set* Edges = gmi_adjacent(model,gf,1);
 75     for (int i = 0; i < ((Edges->n)); i++) 
 76         if(g==Edges->e[i]) ff=i;
 77 //    int res = gmi_is_in_closure_of(model, g, gf);
 78     
 79     if (ff!=-1)
 80       printf("edge with tag %d IS inside the face with tag %d\n",
 81         gmi_tag(model, g), gmi_tag(model, gf));
 82     else
 83       printf("edge with tag %d IS NOT inside the face with tag %d\n",
 84         gmi_tag(model, g), gmi_tag(model, gf));
 85   }
 86   gmi_end(model, gi); // end the iterator
 87   
 88   // go through the model faces and check if they are in closure of gf
 89   printf("checking faces against face with tag %d\n",
 90       gmi_tag(model, gf));
 91   gi = gmi_begin(model, 2);
 92   int ifcnt=0;
 93   while( (g = gmi_next(model, gi)) ){
 94     ff=-1;
 95     if(g==gf) ff=ifcnt;
 96     ifcnt++;
 97 //    int res = gmi_is_in_closure_of(model, g, gf);
 98     if (ff!=-1)
 99       printf("face with tag %d IS inside the face with tag %d\n",
100           gmi_tag(model, g), gmi_tag(model, gf));
101     else
102       printf("face with tag %d IS NOT inside the face with tag %d\n",
103           gmi_tag(model, g), gmi_tag(model, gf));
104   }
105   gmi_end(model, gi); // end the iterator
106   
107   gmi_destroy(model); // deleting the model
@KennethEJansen
Copy link
Contributor

KennethEJansen commented Jul 23, 2022

Here is something closer to the final form inputs: dimi (dimension of entity), tagi (tag of entity), gf (model face whose closure is to be checked) output: ff is -1 if not in closure or the counted closure match (not tag though that could be added).


269          gmi_ent* gf;
270           gmi_ent* gt;
271            int dimi,ff,tagi,k;
279           ff=-1;
284           if(dimi ==2 && gf==gt) ff=ifaceS;
285           else if(dimi < 2) { // check this face's edges and those edges vertices
286             gmi_ent* ge=gmi_find(model,dimi,tagi);
287             gmi_set* Edges = gmi_adjacent(model,gf,1);
288             k=0;
289             while(k<((Edges->n)) && ff==-1){ // check all edges until one found
290               if(dimi==1) {
291                 if(ge==Edges->e[k]) ff=k;  // edges must be checked. 
292               } else {
293                 gmi_set* Verts = gmi_adjacent(model,Edges->e[k],0);
294                 for (int j = 0; j < Verts->n; j++)  
295                    if(ge==Verts->e[j]) ff=j;
296               }    
297               k++;
298             }  

@cwsmith cwsmith mentioned this issue Jan 20, 2023
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants