From b1daaffc7557c79898f1da8d50ddea22d8c4f202 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 25 Aug 2010 11:46:28 +0000 Subject: [PATCH] fix extrusion sources in ReplaceDuplicates (very old bug) + remove all the status messages that slow down the mac gui --- Geo/Geo.cpp | 150 +++++++++++++++++++++++++------- Mesh/BoundaryLayers.cpp | 3 +- Mesh/Generator.cpp | 2 +- Mesh/meshGEdgeExtruded.cpp | 5 +- Mesh/meshGFace.cpp | 4 +- Mesh/meshGFaceExtruded.cpp | 2 +- Mesh/meshGFaceTransfinite.cpp | 2 +- Mesh/meshGRegion.cpp | 8 +- Mesh/meshGRegionExtruded.cpp | 2 +- Mesh/meshGRegionTransfinite.cpp | 2 +- 10 files changed, 133 insertions(+), 47 deletions(-) diff --git a/Geo/Geo.cpp b/Geo/Geo.cpp index 565aded654..2858441b15 100644 --- a/Geo/Geo.cpp +++ b/Geo/Geo.cpp @@ -771,39 +771,54 @@ static int compare2Lists(List_T *List1, List_T *List2, return 0; } -Vertex *FindPoint(int inum) +static Vertex *FindPoint(int inum, Tree_T *t) { Vertex C, *pc; pc = &C; pc->Num = inum; - if(Tree_Query(GModel::current()->getGEOInternals()->Points, &pc)) { + if(Tree_Query(t, &pc)) { return pc; } return NULL; } -Curve *FindCurve(int inum) +Vertex *FindPoint(int inum) +{ + return FindPoint(inum, GModel::current()->getGEOInternals()->Points); +} + +static Curve *FindCurve(int inum, Tree_T *t) { Curve C, *pc; pc = &C; pc->Num = inum; - if(Tree_Query(GModel::current()->getGEOInternals()->Curves, &pc)) { + if(Tree_Query(t, &pc)) { return pc; } return NULL; } -Surface *FindSurface(int inum) +Curve *FindCurve(int inum) +{ + return FindCurve(inum, GModel::current()->getGEOInternals()->Curves); +} + +static Surface *FindSurface(int inum, Tree_T *t) { Surface S, *ps; ps = &S; ps->Num = inum; - if(Tree_Query(GModel::current()->getGEOInternals()->Surfaces, &ps)) { + if(Tree_Query(t, &ps)) { return ps; } return NULL; } +Surface *FindSurface(int inum) +{ + return FindSurface(inum, GModel::current()->getGEOInternals()->Surfaces); +} + Volume *FindVolume(int inum) { Volume V, *pv; @@ -2712,18 +2727,18 @@ static void ReplaceDuplicatePoints() // routine would break backward compatibility with old .geo // files. This will be fixed in the new abstract GModel CAD creation // routines. - Vertex *v, **pv, **pv2; + Vertex *v, *v2, **pv, **pv2; Curve *c; Surface *s; Volume *vol; - std::vector<Vertex*> points2delete; + Tree_T *points2delete = Tree_Create(sizeof(Vertex *), compareVertex); + Tree_T *allNonDuplicatedPoints = Tree_Create(sizeof(Vertex *), compareTwoPoints); // Create unique points int start = Tree_Nbr(GModel::current()->getGEOInternals()->Points); List_T *All = Tree2List(GModel::current()->getGEOInternals()->Points); - Tree_T *allNonDuplicatedPoints = Tree_Create(sizeof(Vertex *), compareTwoPoints); for(int i = 0; i < List_Nbr(All); i++) { List_Read(All, i, &v); if(!Tree_Search(allNonDuplicatedPoints, &v)) { @@ -2731,7 +2746,7 @@ static void ReplaceDuplicatePoints() } else { Tree_Suppress(GModel::current()->getGEOInternals()->Points, &v); - points2delete.push_back(v); + Tree_Insert(points2delete, &v); } } List_Delete(All); @@ -2739,6 +2754,7 @@ static void ReplaceDuplicatePoints() int end = Tree_Nbr(GModel::current()->getGEOInternals()->Points); if(start == end) { + Tree_Delete(points2delete); Tree_Delete(allNonDuplicatedPoints); return; } @@ -2755,10 +2771,12 @@ static void ReplaceDuplicatePoints() All = Tree2List(GModel::current()->getGEOInternals()->Curves); for(int i = 0; i < List_Nbr(All); i++) { List_Read(All, i, &c); + // replace begin/end points if(!Tree_Query(allNonDuplicatedPoints, &c->beg)) Msg::Error("Weird point %d in Coherence", c->beg->Num); if(!Tree_Query(allNonDuplicatedPoints, &c->end)) Msg::Error("Weird point %d in Coherence", c->end->Num); + // replace control points for(int j = 0; j < List_Nbr(c->Control_Points); j++) { pv = (Vertex **)List_Pointer(c->Control_Points, j); if(!(pv2 = (Vertex **)Tree_PQuery(allNonDuplicatedPoints, pv))) @@ -2766,6 +2784,16 @@ static void ReplaceDuplicatePoints() else List_Write(c->Control_Points, j, pv2); } + // replace extrusion sources + if(c->Extrude && c->Extrude->geo.Mode == EXTRUDED_ENTITY){ + v2 = FindPoint(std::abs(c->Extrude->geo.Source), points2delete); + if(v2){ + if(!(pv2 = (Vertex **)Tree_PQuery(allNonDuplicatedPoints, &v2))) + Msg::Error("Weird point %d in Coherence", v2->Num); + else + c->Extrude->geo.Source = (*pv2)->Num; + } + } } List_Delete(All); @@ -2774,6 +2802,7 @@ static void ReplaceDuplicatePoints() All = Tree2List(GModel::current()->getGEOInternals()->Surfaces); for(int i = 0; i < List_Nbr(All); i++) { List_Read(All, i, &s); + // replace transfinite corners for(int j = 0; j < List_Nbr(s->TrsfPoints); j++){ pv = (Vertex **)List_Pointer(s->TrsfPoints, j); if(!(pv2 = (Vertex **)Tree_PQuery(allNonDuplicatedPoints, pv))) @@ -2789,6 +2818,7 @@ static void ReplaceDuplicatePoints() All = Tree2List(GModel::current()->getGEOInternals()->Volumes); for(int i = 0; i < List_Nbr(All); i++) { List_Read(All, i, &vol); + // replace transfinite corners for(int j = 0; j < List_Nbr(vol->TrsfPoints); j++){ pv = (Vertex **)List_Pointer(vol->TrsfPoints, j); if(!(pv2 = (Vertex **)Tree_PQuery(allNonDuplicatedPoints, pv))) @@ -2799,9 +2829,8 @@ static void ReplaceDuplicatePoints() } List_Delete(All); - for(unsigned int k = 0; k < points2delete.size(); k++) - Free_Vertex(&points2delete[k], 0); - + Tree_Action(points2delete, Free_Vertex); + Tree_Delete(points2delete); Tree_Delete(allNonDuplicatedPoints); } @@ -2809,14 +2838,14 @@ static void ReplaceDuplicateCurves() { Curve *c, *c2, **pc, **pc2; Surface *s; - std::vector<Curve*> curves2delete; - + Tree_T *curves2delete = Tree_Create(sizeof(Curve *), compareCurve); + Tree_T *allNonDuplicatedCurves = Tree_Create(sizeof(Curve *), compareTwoCurves); + // Create unique curves int start = Tree_Nbr(GModel::current()->getGEOInternals()->Curves); List_T *All = Tree2List(GModel::current()->getGEOInternals()->Curves); - Tree_T *allNonDuplicatedCurves = Tree_Create(sizeof(Curve *), compareTwoCurves); for(int i = 0; i < List_Nbr(All); i++) { List_Read(All, i, &c); if(c->Num > 0) { @@ -2833,12 +2862,11 @@ static void ReplaceDuplicateCurves() Tree_Suppress(GModel::current()->getGEOInternals()->Curves, &c); if(!(c2 = FindCurve(-c->Num))) { Msg::Error("Unknown curve %d", -c->Num); - List_Delete(All); - return; + break; } Tree_Suppress(GModel::current()->getGEOInternals()->Curves, &c2); - curves2delete.push_back(c); - curves2delete.push_back(c2); + Tree_Insert(curves2delete, &c); + Tree_Insert(curves2delete, &c2); } } } @@ -2847,6 +2875,7 @@ static void ReplaceDuplicateCurves() int end = Tree_Nbr(GModel::current()->getGEOInternals()->Curves); if(start == end) { + Tree_Delete(curves2delete); Tree_Delete(allNonDuplicatedCurves); return; } @@ -2858,42 +2887,70 @@ static void ReplaceDuplicateCurves() Tree_Action(GModel::current()->getGEOInternals()->Curves, MaxNumCurve); } + // Replace old curves in curves + + All = Tree2List(GModel::current()->getGEOInternals()->Curves); + for(int i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &c); + // replace extrusion sources + if(c->Extrude && c->Extrude->geo.Mode == COPIED_ENTITY){ + c2 = FindCurve(std::abs(c->Extrude->geo.Source), curves2delete); + if(c2){ + if(!(pc2 = (Curve **)Tree_PQuery(allNonDuplicatedCurves, &c2))) + Msg::Error("Weird curve %d in Coherence", c2->Num); + else + c->Extrude->geo.Source = (*pc2)->Num; + } + } + } + List_Delete(All); + // Replace old curves in surfaces All = Tree2List(GModel::current()->getGEOInternals()->Surfaces); for(int i = 0; i < List_Nbr(All); i++) { List_Read(All, i, &s); + // replace bounding curves for(int j = 0; j < List_Nbr(s->Generatrices); j++) { pc = (Curve **)List_Pointer(s->Generatrices, j); if(!(pc2 = (Curve **)Tree_PQuery(allNonDuplicatedCurves, pc))) Msg::Error("Weird curve %d in Coherence", (*pc)->Num); else { List_Write(s->Generatrices, j, pc2); - // Arghhh. Revoir compareTwoCurves ! + // arghhh: check compareTwoCurves! End_Curve(*pc2); } } + // replace extrusion sources + if(s->Extrude && s->Extrude->geo.Mode == EXTRUDED_ENTITY){ + c2 = FindCurve(std::abs(s->Extrude->geo.Source), curves2delete); + if(c2){ + if(!(pc2 = (Curve **)Tree_PQuery(allNonDuplicatedCurves, &c2))) + Msg::Error("Weird curve %d in Coherence", c2->Num); + else + s->Extrude->geo.Source = (*pc2)->Num; + } + } } List_Delete(All); - for(unsigned int k = 0; k < curves2delete.size(); k++) - Free_Curve(&curves2delete[k], 0); - + Tree_Action(curves2delete, Free_Curve); + Tree_Delete(curves2delete); Tree_Delete(allNonDuplicatedCurves); } static void ReplaceDuplicateSurfaces() { - Surface *s, **ps, **ps2; + Surface *s, *s2, **ps, **ps2; Volume *vol; - std::vector<Surface*> surfaces2delete; + Tree_T *surfaces2delete = Tree_Create(sizeof(Surface *), compareSurface); + Tree_T *allNonDuplicatedSurfaces = Tree_Create(sizeof(Surface *), compareTwoSurfaces); // Create unique surfaces int start = Tree_Nbr(GModel::current()->getGEOInternals()->Surfaces); List_T *All = Tree2List(GModel::current()->getGEOInternals()->Surfaces); - Tree_T *allNonDuplicatedSurfaces = Tree_Create(sizeof(Surface *), compareTwoSurfaces); for(int i = 0; i < List_Nbr(All); i++) { List_Read(All, i, &s); if(s->Num > 0) { @@ -2902,7 +2959,7 @@ static void ReplaceDuplicateSurfaces() } else { Tree_Suppress(GModel::current()->getGEOInternals()->Surfaces, &s); - surfaces2delete.push_back(s); + Tree_Insert(surfaces2delete, &s); } } } @@ -2911,6 +2968,7 @@ static void ReplaceDuplicateSurfaces() int end = Tree_Nbr(GModel::current()->getGEOInternals()->Surfaces); if(start == end) { + Tree_Delete(surfaces2delete); Tree_Delete(allNonDuplicatedSurfaces); return; } @@ -2922,11 +2980,30 @@ static void ReplaceDuplicateSurfaces() Tree_Action(GModel::current()->getGEOInternals()->Surfaces, MaxNumSurface); } + // Replace old surfaces in surfaces + + All = Tree2List(GModel::current()->getGEOInternals()->Surfaces); + for(int i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &s); + // replace extrusion sources + if(s->Extrude && s->Extrude->geo.Mode == COPIED_ENTITY){ + s2 = FindSurface(std::abs(s->Extrude->geo.Source), surfaces2delete); + if(s2){ + if(!(ps2 = (Surface **)Tree_PQuery(allNonDuplicatedSurfaces, &s2))) + Msg::Error("Weird surface %d in Coherence", s2->Num); + else + s->Extrude->geo.Source = (*ps2)->Num; + } + } + } + List_Delete(All); + // Replace old surfaces in volumes All = Tree2List(GModel::current()->getGEOInternals()->Volumes); for(int i = 0; i < List_Nbr(All); i++) { List_Read(All, i, &vol); + // replace bounding surfaces for(int j = 0; j < List_Nbr(vol->Surfaces); j++) { ps = (Surface **)List_Pointer(vol->Surfaces, j); if(!(ps2 = (Surface **)Tree_PQuery(allNonDuplicatedSurfaces, ps))) @@ -2934,12 +3011,21 @@ static void ReplaceDuplicateSurfaces() else List_Write(vol->Surfaces, j, ps2); } + // replace extrusion sources + if(vol->Extrude && vol->Extrude->geo.Mode == EXTRUDED_ENTITY){ + s2 = FindSurface(std::abs(vol->Extrude->geo.Source), surfaces2delete); + if(s2){ + if(!(ps2 = (Surface **)Tree_PQuery(allNonDuplicatedSurfaces, &s2))) + Msg::Error("Weird surface %d in Coherence", s2->Num); + else + vol->Extrude->geo.Source = (*ps2)->Num; + } + } } List_Delete(All); - for(unsigned int k = 0; k < surfaces2delete.size(); k++) - Free_Surface(&surfaces2delete[k], 0); - + Tree_Action(surfaces2delete, Free_Surface); + Tree_Delete(surfaces2delete); Tree_Delete(allNonDuplicatedSurfaces); } @@ -3082,7 +3168,7 @@ bool SplitCurve(int line_id, List_T *vertices_id, List_T *shapes) Msg::Error("Cannot split curve %i with type %i", line_id, c->Typ); return false; } - std::set<int>v_break; + std::set<int> v_break; for(int i = 0; i < List_Nbr(vertices_id); i++){ int id; List_Read(vertices_id, i, &id); diff --git a/Mesh/BoundaryLayers.cpp b/Mesh/BoundaryLayers.cpp index 094c6cb1fb..f5165b0c30 100644 --- a/Mesh/BoundaryLayers.cpp +++ b/Mesh/BoundaryLayers.cpp @@ -132,8 +132,7 @@ int Mesh2DWithBoundaryLayers(GModel *m) for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){ GFace *gf = *it; if(gf->geomType() == GEntity::BoundaryLayerSurface){ - Msg::StatusBar(2, true, "Meshing surface %d (%s)", gf->tag(), - gf->getTypeString().c_str()); + Msg::Info("Meshing surface %d (%s)", gf->tag(), gf->getTypeString().c_str()); deMeshGFace dem; dem(gf); MeshExtrudedSurface(gf); diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp index 4dd8684583..33d53fc7e6 100644 --- a/Mesh/Generator.cpp +++ b/Mesh/Generator.cpp @@ -477,7 +477,7 @@ static void Mesh2D(GModel *m) if(gfc->getNbSplit() != 0) continue; } int recombine = gf->meshAttributes.recombine; - Msg::StatusBar(2, true, "Lloyd optimization for face %d", gf->tag()); + Msg::Info("Lloyd optimization for face %d", gf->tag()); gf->lloyd(25, recombine); if(recombine) recombineIntoQuads(gf); } diff --git a/Mesh/meshGEdgeExtruded.cpp b/Mesh/meshGEdgeExtruded.cpp index b2e6b59abf..32273b60e2 100644 --- a/Mesh/meshGEdgeExtruded.cpp +++ b/Mesh/meshGEdgeExtruded.cpp @@ -54,14 +54,14 @@ int MeshExtrudedCurve(GEdge *ge) if(!ep || !ep->mesh.ExtrudeMesh) return 0; - Msg::StatusBar(2, true, "Meshing curve %d (extruded)", ge->tag()); + Msg::Info("Meshing curve %d (extruded)", ge->tag()); - GEdge *from = ge->model()->getEdgeByTag(std::abs(ep->geo.Source)); if(ep->geo.Mode == EXTRUDED_ENTITY) { // curve is extruded from a point extrudeMesh(ge->getBeginVertex(), ge); } else { + GEdge *from = ge->model()->getEdgeByTag(std::abs(ep->geo.Source)); // curve is a copy of another curve (the "top" of the extrusion) if(!from){ Msg::Error("Unknown source curve %d for extrusion", ep->geo.Source); @@ -85,6 +85,7 @@ int MeshExtrudedCurve(GEdge *ge) if(ep->geo.Mode == COPIED_ENTITY) { // Extrusion information is only stored for copied edges // (the source of extruded edge is a vertex, not an element) + GEdge *from = ge->model()->getEdgeByTag(std::abs(ep->geo.Source)); MElement* sourceElem = from->getMeshElement(i); ep->elementMap.addExtrudedElem(sourceElem, newElem); } diff --git a/Mesh/meshGFace.cpp b/Mesh/meshGFace.cpp index d43aa11379..fac8ccfa4a 100644 --- a/Mesh/meshGFace.cpp +++ b/Mesh/meshGFace.cpp @@ -1526,8 +1526,8 @@ void meshGFace::operator() (GFace *gf) else algo = "MeshAdapt"; - Msg::StatusBar(2, true, "Meshing surface %d (%s, %s)", - gf->tag(), gf->getTypeString().c_str(), algo); + Msg::Info("Meshing surface %d (%s, %s)", gf->tag(), + gf->getTypeString().c_str(), algo); // compute loops on the fly (indices indicate start and end points // of a loop; loops are not yet oriented) diff --git a/Mesh/meshGFaceExtruded.cpp b/Mesh/meshGFaceExtruded.cpp index 9d22d9f7c9..13dbc2dddf 100644 --- a/Mesh/meshGFaceExtruded.cpp +++ b/Mesh/meshGFaceExtruded.cpp @@ -192,7 +192,7 @@ int MeshExtrudedSurface(GFace *gf, if(!ep || !ep->mesh.ExtrudeMesh) return 0; - Msg::StatusBar(2, true, "Meshing surface %d (extruded)", gf->tag()); + Msg::Info("Meshing surface %d (extruded)", gf->tag()); // build a set with all the vertices on the boundary of the face gf double old_tol = MVertexLessThanLexicographic::tolerance; diff --git a/Mesh/meshGFaceTransfinite.cpp b/Mesh/meshGFaceTransfinite.cpp index 1116add001..e94cfb20bb 100644 --- a/Mesh/meshGFaceTransfinite.cpp +++ b/Mesh/meshGFaceTransfinite.cpp @@ -136,7 +136,7 @@ int MeshTransfiniteSurface(GFace *gf) { if(gf->meshAttributes.Method != MESH_TRANSFINITE) return 0; - Msg::StatusBar(2, true, "Meshing surface %d (transfinite)", gf->tag()); + Msg::Info("Meshing surface %d (transfinite)", gf->tag()); std::vector<MVertex*> corners; findTransfiniteCorners(gf, corners); diff --git a/Mesh/meshGRegion.cpp b/Mesh/meshGRegion.cpp index 008eb286df..ab61ddceb2 100644 --- a/Mesh/meshGRegion.cpp +++ b/Mesh/meshGRegion.cpp @@ -249,7 +249,7 @@ void MeshDelaunayVolume(std::vector<GRegion*> ®ions) #else for(unsigned int i = 0; i < regions.size(); i++) - Msg::StatusBar(2, true, "Meshing volume %d (Delaunay)", regions[i]->tag()); + Msg::Info("Meshing volume %d (Delaunay)", regions[i]->tag()); // put all the faces in the same model GRegion *gr = regions[0]; @@ -626,7 +626,7 @@ void meshGRegion::operator() (GRegion *gr) #if !defined(HAVE_NETGEN) Msg::Error("Netgen is not compiled in this version of Gmsh"); #else - Msg::StatusBar(2, true, "Meshing volume %d (Frontal)", gr->tag()); + Msg::Info("Meshing volume %d (Frontal)", gr->tag()); // orient the triangles of with respect to this region meshNormalsPointOutOfTheRegion(gr); std::vector<MVertex*> numberedV; @@ -653,7 +653,7 @@ void optimizeMeshGRegionNetgen::operator() (GRegion *gr) #if !defined(HAVE_NETGEN) Msg::Error("Netgen is not compiled in this version of Gmsh"); #else - Msg::StatusBar(2, true, "Optimizing volume %d", gr->tag()); + Msg::Info("Optimizing volume %d", gr->tag()); // import mesh into netgen, including volume tets std::vector<MVertex*> numberedV; Ng_Mesh *ngmesh = buildNetgenStructure(gr, true, numberedV); @@ -679,7 +679,7 @@ void optimizeMeshGRegionGmsh::operator() (GRegion *gr) ExtrudeParams *ep = gr->meshAttributes.extrude; if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY) return; - Msg::StatusBar(2, true, "Optimizing volume %d", gr->tag()); + Msg::Info("Optimizing volume %d", gr->tag()); optimizeMesh(gr, QMTET_2); } diff --git a/Mesh/meshGRegionExtruded.cpp b/Mesh/meshGRegionExtruded.cpp index 50c76ae6dc..2bb55f4d30 100644 --- a/Mesh/meshGRegionExtruded.cpp +++ b/Mesh/meshGRegionExtruded.cpp @@ -229,7 +229,7 @@ void meshGRegionExtruded::operator() (GRegion *gr) if(!ep || !ep->mesh.ExtrudeMesh || ep->geo.Mode != EXTRUDED_ENTITY) return; - Msg::StatusBar(2, true, "Meshing volume %d (extruded)", gr->tag()); + Msg::Info("Meshing volume %d (extruded)", gr->tag()); // destroy the mesh if it exists deMeshGRegion dem; diff --git a/Mesh/meshGRegionTransfinite.cpp b/Mesh/meshGRegionTransfinite.cpp index 51a021178e..54c06268e0 100644 --- a/Mesh/meshGRegionTransfinite.cpp +++ b/Mesh/meshGRegionTransfinite.cpp @@ -302,7 +302,7 @@ int MeshTransfiniteVolume(GRegion *gr) { if(gr->meshAttributes.Method != MESH_TRANSFINITE) return 0; - Msg::StatusBar(2, true, "Meshing volume %d (transfinite)", gr->tag()); + Msg::Info("Meshing volume %d (transfinite)", gr->tag()); std::list<GFace*> faces = gr->faces(); if(faces.size() != 5 && faces.size() != 6){ -- GitLab