void Filler::treat_model(){ GRegion* gr; GModel* model = GModel::current(); GModel::riter it; for(it=model->firstRegion();it!=model->lastRegion();it++) { gr = *it; if(gr->getNumMeshElements()>0){ treat_region(gr); } } }
void Centerline::createClosedVolume(GEdge *gin, std::vector<GEdge*> boundEdges) { current->setFactory("Gmsh"); std::vector<std::vector<GFace *> > myFaceLoops; std::vector<GFace *> myFaces; for (unsigned int i = 0; i< boundEdges.size(); i++){ std::vector<std::vector<GEdge *> > myEdgeLoops; std::vector<GEdge *> myEdges; GEdge * gec; if(is_cut) gec = current->getEdgeByTag(NE+boundEdges[i]->tag()); else gec = current->getEdgeByTag(boundEdges[i]->tag()); myEdges.push_back(gec); myEdgeLoops.push_back(myEdges); GFace *newFace = current->addPlanarFace(myEdgeLoops); if (gin==boundEdges[i]) { newFace->addPhysicalEntity(2); current->setPhysicalName("inlet", 2, 2);//tag 2 } else{ newFace->addPhysicalEntity(3); current->setPhysicalName("outlets", 2, 3);//tag 3 } myFaces.push_back(newFace); } Msg::Info("Centerline: action (closeVolume) has created %d in/out planar faces ", (int)boundEdges.size()); for (int i = 0; i < NF; i++){ GFace * gf; if(is_cut) gf = current->getFaceByTag(NF+i+1); else gf = current->getFaceByTag(i+1); myFaces.push_back(gf); } myFaceLoops.push_back(myFaces); GRegion *reg = current->addVolume(myFaceLoops); reg->addPhysicalEntity(reg->tag()); current->setPhysicalName("lumenVolume", 3, reg->tag()); Msg::Info("Centerline: action (closeVolume) has created volume %d ", reg->tag()); }
GRegion::GRegion(GRegion &c) : GRect(c.x1, c.y1, c.x2, c.y2) { Size = Alloc = 0; Current = 0; a = 0; SetSize(c.Length()); for (int i=0; i<Size; i++) { a[i] = c.a[i]; } }
int GModel::importGEOInternals() { if(Tree_Nbr(_geo_internals->Points)) { List_T *points = Tree2List(_geo_internals->Points); for(int i = 0; i < List_Nbr(points); i++){ Vertex *p; List_Read(points, i, &p); GVertex *v = getVertexByTag(p->Num); if(!v){ v = new gmshVertex(this, p); add(v); } if(!p->Visible) v->setVisibility(0); } List_Delete(points); } if(Tree_Nbr(_geo_internals->Curves)) { List_T *curves = Tree2List(_geo_internals->Curves); for(int i = 0; i < List_Nbr(curves); i++){ Curve *c; List_Read(curves, i, &c); if(c->Num >= 0){ GEdge *e = getEdgeByTag(c->Num); if(!e && c->Typ == MSH_SEGM_COMPOUND){ std::vector<GEdge*> comp; for(unsigned int j = 0; j < c->compound.size(); j++){ GEdge *ge = getEdgeByTag(c->compound[j]); if(ge) comp.push_back(ge); } e = new GEdgeCompound(this, c->Num, comp); e->meshAttributes.method = c->Method; e->meshAttributes.nbPointsTransfinite = c->nbPointsTransfinite; e->meshAttributes.typeTransfinite = c->typeTransfinite; e->meshAttributes.coeffTransfinite = c->coeffTransfinite; e->meshAttributes.extrude = c->Extrude; e->meshAttributes.reverseMesh = c->ReverseMesh; add(e); } else if(!e && c->beg && c->end){ e = new gmshEdge(this, c, getVertexByTag(c->beg->Num), getVertexByTag(c->end->Num)); add(e); } else if(!e){ e = new gmshEdge(this, c, 0, 0); add(e); } if(!c->Visible) e->setVisibility(0); if(c->Color.type) e->setColor(c->Color.mesh); if(c->degenerated) { e->setTooSmall(true); } } } List_Delete(curves); } if(Tree_Nbr(_geo_internals->Surfaces)) { List_T *surfaces = Tree2List(_geo_internals->Surfaces); for(int i = 0; i < List_Nbr(surfaces); i++){ Surface *s; List_Read(surfaces, i, &s); GFace *f = getFaceByTag(s->Num); if(!f && s->Typ == MSH_SURF_COMPOUND){ std::list<GFace*> comp; for(unsigned int j = 0; j < s->compound.size(); j++){ GFace *gf = getFaceByTag(s->compound[j]); if(gf) comp.push_back(gf); } std::list<GEdge*> b[4]; for(int j = 0; j < 4; j++){ for(unsigned int k = 0; k < s->compoundBoundary[j].size(); k++){ GEdge *ge = getEdgeByTag(s->compoundBoundary[j][k]); if(ge) b[j].push_back(ge); } } int param = CTX::instance()->mesh.remeshParam; GFaceCompound::typeOfCompound typ = GFaceCompound::HARMONIC_CIRCLE; if (param == 1) typ = GFaceCompound::CONFORMAL_SPECTRAL; if (param == 2) typ = GFaceCompound::RADIAL_BASIS; if (param == 3) typ = GFaceCompound::HARMONIC_PLANE; if (param == 4) typ = GFaceCompound::CONVEX_CIRCLE; if (param == 5) typ = GFaceCompound::CONVEX_PLANE; if (param == 6) typ = GFaceCompound::HARMONIC_SQUARE; if (param == 7) typ = GFaceCompound::CONFORMAL_FE; int algo = CTX::instance()->mesh.remeshAlgo; f = new GFaceCompound(this, s->Num, comp, b[0], b[1], b[2], b[3], typ, algo); f->meshAttributes.recombine = s->Recombine; f->meshAttributes.recombineAngle = s->RecombineAngle; f->meshAttributes.method = s->Method; f->meshAttributes.extrude = s->Extrude; // transfinite import Added by Trevor Strickler. This helps when experimenting // to create compounds from transfinite surfs. Not having it does not break // anything Gmsh *officially* does right now, but maybe it was left out by mistake??? and could // cause problems later? f->meshAttributes.transfiniteArrangement = s->Recombine_Dir; f->meshAttributes.corners.clear(); for(int i = 0; i < List_Nbr(s->TrsfPoints); i++){ Vertex *corn; List_Read(s->TrsfPoints, i, &corn); GVertex *gv = f->model()->getVertexByTag(corn->Num); if(gv) f->meshAttributes.corners.push_back(gv); else Msg::Error("Unknown vertex %d in transfinite attributes", corn->Num); } add(f); if(s->EmbeddedCurves){ for(int i = 0; i < List_Nbr(s->EmbeddedCurves); i++){ Curve *c; List_Read(s->EmbeddedCurves, i, &c); GEdge *e = getEdgeByTag(abs(c->Num)); if(e) f->addEmbeddedEdge(e); else Msg::Error("Unknown curve %d", c->Num); } } if(s->EmbeddedPoints){ for(int i = 0; i < List_Nbr(s->EmbeddedPoints); i++){ Vertex *v; List_Read(s->EmbeddedPoints, i, &v); GVertex *gv = getVertexByTag(v->Num); if(gv) f->addEmbeddedVertex(gv); else Msg::Error("Unknown point %d", v->Num); } } } else if(!f){ f = new gmshFace(this, s); add(f); } else f->resetMeshAttributes(); if(!s->Visible) f->setVisibility(0); if(s->Color.type) f->setColor(s->Color.mesh); } List_Delete(surfaces); } if(Tree_Nbr(_geo_internals->Volumes)) { List_T *volumes = Tree2List(_geo_internals->Volumes); for(int i = 0; i < List_Nbr(volumes); i++){ Volume *v; List_Read(volumes, i, &v); GRegion *r = getRegionByTag(v->Num); if(!r && v->Typ == MSH_VOLUME_COMPOUND){ std::vector<GRegion*> comp; for(unsigned int j = 0; j < v->compound.size(); j++){ GRegion *gr = getRegionByTag(v->compound[j]); if(gr) comp.push_back(gr); } r = new GRegionCompound(this, v->Num, comp); if(v->EmbeddedSurfaces){ for(int i = 0; i < List_Nbr(v->EmbeddedSurfaces); i++){ Surface *s; List_Read(v->EmbeddedSurfaces, i, &s); GFace *gf = getFaceByTag(abs(s->Num)); if(gf) r->addEmbeddedFace(gf); else Msg::Error("Unknown surface %d", s->Num); } } add(r); } else if(!r){ r = new gmshRegion(this, v); add(r); } else r->resetMeshAttributes(); if(!v->Visible) r->setVisibility(0); if(v->Color.type) r->setColor(v->Color.mesh); } List_Delete(volumes); } for(int i = 0; i < List_Nbr(_geo_internals->PhysicalGroups); i++){ PhysicalGroup *p; List_Read(_geo_internals->PhysicalGroups, i, &p); for(int j = 0; j < List_Nbr(p->Entities); j++){ int num; List_Read(p->Entities, j, &num); GEntity *ge = 0; int tag = CTX::instance()->geom.orientedPhysicals ? abs(num) : num; switch(p->Typ){ case MSH_PHYSICAL_POINT: ge = getVertexByTag(tag); break; case MSH_PHYSICAL_LINE: ge = getEdgeByTag(tag); break; case MSH_PHYSICAL_SURFACE: ge = getFaceByTag(tag); break; case MSH_PHYSICAL_VOLUME: ge = getRegionByTag(tag); break; } int pnum = CTX::instance()->geom.orientedPhysicals ? (sign(num) * p->Num) : p->Num; if(ge && std::find(ge->physicals.begin(), ge->physicals.end(), pnum) == ge->physicals.end()) ge->physicals.push_back(pnum); } } // create periodic mesh relationships for (std::map<int,int>::iterator it = _geo_internals->periodicEdges.begin(); it != _geo_internals->periodicEdges.end(); ++it){ GEdge *ge = getEdgeByTag(abs(it->first)); if (ge){ int MASTER = it->second * (it->first > 0 ? 1 : -1); ge->setMeshMaster(MASTER); } } for (std::map<int,int>::iterator it = _geo_internals->periodicFaces.begin(); it != _geo_internals->periodicFaces.end(); ++it){ GFace *gf = getFaceByTag(abs(it->first)); if (gf)gf->setMeshMaster(it->second * (it->first > 0 ? 1 : -1)); } for (eiter it = firstEdge() ; it != lastEdge() ; ++it){ int meshMaster = (*it)->meshMaster(); if (meshMaster != (*it)->tag()){ GEdge *ge_master = getEdgeByTag(abs(meshMaster)); if(ge_master)(*it)->getBeginVertex()->setMeshMaster ( (meshMaster > 0) ? ge_master->getBeginVertex()->tag() : ge_master->getEndVertex()->tag()); if(ge_master)(*it)->getEndVertex()->setMeshMaster ( (meshMaster < 0) ? ge_master->getBeginVertex()->tag() : ge_master->getEndVertex()->tag()); } } Msg::Debug("Gmsh model (GModel) imported:"); Msg::Debug("%d Vertices", vertices.size()); Msg::Debug("%d Edges", edges.size()); Msg::Debug("%d Faces", faces.size()); Msg::Debug("%d Regions", regions.size()); return 1; }
// The function that tests whether a 2D surface is a lateral of a valid QuadToTri // region and whether there are conflicts. If surface is not part of valid QuadToTri region // or if there are QuadToTri conflicts, return 0. Note that RemoveDuplicateSurfaces() // makes this DIFFICULT. Also, the tri_quad_flag determins whether the surface // should be meshed with triangles or quadrangles: // tri_quad_values: 0 = no override, 1 = mesh as quads, 2 = mesh as triangles. // Added 2010-12-09. int IsValidQuadToTriLateral(GFace *face, int *tri_quad_flag, bool *detectQuadToTriLateral ) { (*tri_quad_flag) = 0; (*detectQuadToTriLateral) = false; GModel *model = face->model(); ExtrudeParams *ep = face->meshAttributes.extrude; if( !ep || !ep->mesh.ExtrudeMesh || !ep->geo.Mode == EXTRUDED_ENTITY ){ Msg::Error("In IsValidQuadToTriLateral(), face %d is not a structured extrusion.", face->tag() ); return 0; } GEdge *face_source = model->getEdgeByTag( std::abs( ep->geo.Source ) ); if( !face_source ){ Msg::Error("In IsValidQuadToTriLateral(), face %d has no source edge.", face->tag() ); } // It seems the member pointers to neighboring regions for extruded lateral faces are not set. // For now, have to loop through // ALL the regions to see if the presently considered face belongs to the region and if // any neighboring region is QUADTRI. // The following loop will find all the regions that the face bounds, and determine // whether the face is a lateral of the region (including whether the region is even extruded). // After that information is determined, function can test for QuadToTri neighbor conflicts. std::vector<GRegion *> lateral_regions; std::vector<GRegion *> adjacent_regions; int numRegions = 0; int numLateralRegions = 0; numRegions = GetNeighborRegionsOfFace(face, adjacent_regions); for( int i_reg = 0; i_reg < numRegions; i_reg++ ){ GRegion *region = adjacent_regions[i_reg]; // is region in the current model's region's or is it deleted? if( !FindVolume( ( region->tag() ) ) ) continue; // is the region mesh extruded? if( !region->meshAttributes.extrude || ( region->meshAttributes.extrude && !region->meshAttributes.extrude->mesh.ExtrudeMesh ) ) continue; if( region->meshAttributes.extrude->geo.Mode != EXTRUDED_ENTITY ) continue; // Test whether the face is a lateral if( IsSurfaceALateralForRegion(region, face) ){ lateral_regions.push_back(region); numLateralRegions++; if( region->meshAttributes.extrude->mesh.QuadToTri ) (*detectQuadToTriLateral) = true; } } // MAIN test of whether this is even a quadToTri extrusion lateral // the only return 0 path that is NOT an error if( !(*detectQuadToTriLateral) ) return 0; // now will start conflict checks if(numRegions > 2){ Msg::Error("In IsValidQuadToTriLateral(), too many regions adjacent to surface %d.", face->tag() ); return 0; } bool detect_conflict = false; // Set the tri_quad_flag that lets ExtrudeMesh override ep->Recombine; // tri_quad_values: 0 = no override, 1 = mesh as quads, 2 = mesh as triangles. // if this face is a free surface: if( adjacent_regions.size() == 1 ){ if( lateral_regions[0]->meshAttributes.extrude->mesh.QuadToTri == QUADTRI_NOVERTS_1_RECOMB || lateral_regions[0]->meshAttributes.extrude->mesh.QuadToTri == QUADTRI_ADDVERTS_1_RECOMB ){ (*tri_quad_flag) = 1; } if( lateral_regions[0]->meshAttributes.extrude->mesh.QuadToTri == QUADTRI_NOVERTS_1 || lateral_regions[0]->meshAttributes.extrude->mesh.QuadToTri == QUADTRI_ADDVERTS_1 ){ (*tri_quad_flag) = 2; } else (*tri_quad_flag) = 0; } else if( adjacent_regions.size() > 1 ){ GRegion *adj_region = NULL; ExtrudeParams *adj_ep = NULL; if( lateral_regions[0] == adjacent_regions[0] ) adj_region = adjacent_regions[1]; else adj_region = adjacent_regions[0]; adj_ep = adj_region->meshAttributes.extrude; // if Neighbor is Transfinite, go with the default, non-QuadTri recombine for this surface if( adj_region && adj_region->meshAttributes.method == MESH_TRANSFINITE ) (*tri_quad_flag) = 0; // if a neighbor // has no extrusion structure, // don't even consider QuadToTri Recomb on this face. else if( adj_region && !(adj_ep && adj_ep->mesh.ExtrudeMesh) ) (*tri_quad_flag) = 2; // This face is the source face of a second // neighboring extrusion. else if( adj_ep && adj_ep->mesh.ExtrudeMesh && model->getFaceByTag( std::abs( adj_ep->geo.Source ) ) == face ){ if( lateral_regions[0]->meshAttributes.extrude->mesh.QuadToTri == QUADTRI_NOVERTS_1_RECOMB || lateral_regions[0]->meshAttributes.extrude->mesh.QuadToTri == QUADTRI_ADDVERTS_1_RECOMB ) (*tri_quad_flag) = 1; else if( lateral_regions[0]->meshAttributes.extrude->mesh.QuadToTri == QUADTRI_NOVERTS_1 || lateral_regions[0]->meshAttributes.extrude->mesh.QuadToTri == QUADTRI_ADDVERTS_1 ) (*tri_quad_flag) = 2; else (*tri_quad_flag) = 0; } // if both neighbors are structured but none of the previous apply: else if( adj_ep && adj_ep->mesh.ExtrudeMesh ){ if( (adj_ep && !adj_ep->mesh.QuadToTri && adj_ep->mesh.Recombine) || (ep && !ep->mesh.QuadToTri && ep->mesh.Recombine) ) (*tri_quad_flag) = 1; else if( (adj_ep && !adj_ep->mesh.QuadToTri && !adj_ep->mesh.Recombine) || (ep && !ep->mesh.QuadToTri && !ep->mesh.Recombine) ) (*tri_quad_flag) = 2; // if both are quadToTri ALWAYS try to recombine else if( ep->mesh.QuadToTri && adj_ep && adj_ep->mesh.QuadToTri ) (*tri_quad_flag) = 1; else (*tri_quad_flag) = 0; } // any other adjacent surface, just default to the QuadToTri region's non-QuadToTri // default recombination method. Any mistakes at this point are not this feature's. else (*tri_quad_flag) = 0; } // if this executes, there's a mistake here : else{ detect_conflict = true; (*tri_quad_flag) = 0; } if( detect_conflict ) return 0; else return 1; }
// The function that tests whether a surface is a QuadToTri top surface and whether // there are conflicts. If surface is not a top for a valid QuadToTri region or if // there are QuadToTri conflicts, return 0. // if the surface turns out to be the source of a toroidal loop extrusion (which will then // NOT have geo.Mode == COPIED_ENTITY), return 2 (this will require special meshing considerations). // Note that RemoveDuplicateSurfaces() makes this DIFFICULT. // Also, the type of QuadToTri interface is placed into the // pointer argument quadToTri. . // Added 2010-12-09. int IsValidQuadToTriTop(GFace *face, int *quadToTri, bool *detectQuadToTriTop) { (*quadToTri) = NO_QUADTRI; (*detectQuadToTriTop) = false; int is_toroidal_quadtri = 0; GModel *model = face->model(); // First thing is first: determine if this is a toroidal quadtri extrusion. if so, can skip the rest // It seems the member pointers to neighboring regions for extruded top faces are not set. // For now, have to loop through // ALL the regions to see if the presently considered face belongs to the region. // The following loop will find all the regions that the face bounds, and determine // whether the face is a top face of the region (including whether the region is even extruded). // After that information is determined, function can test for QuadToTri neighbor conflicts. // first determine if this is toroidal quadtotri is_toroidal_quadtri = IsInToroidalQuadToTri(face); if( is_toroidal_quadtri ) (*detectQuadToTriTop) = true; else{ std::vector<GRegion *> top_regions; std::vector<GRegion *> adjacent_regions; std::vector<GRegion *> all_regions; int numRegions = 0; int numTopRegions = 0; std::set<GRegion *, GEntityLessThan>::iterator itreg; for( itreg = model->firstRegion(); itreg != model->lastRegion(); itreg++ ) all_regions.push_back( (*itreg) ); for(unsigned int i_reg = 0; i_reg < all_regions.size(); i_reg++ ){ // save time if( numRegions >= 2 ) break; GRegion *region = all_regions[i_reg]; // is region in the current model's regions or is it deleted? if( !FindVolume( ( region->tag() ) ) ) continue; // does face belong to region? std::list<GFace *> region_faces = std::list<GFace *>( region->faces() ); if( std::find( region_faces.begin(), region_faces.end(), face ) != region_faces.end() ){ adjacent_regions.push_back(region); numRegions++; } else continue; // is region a structured extruded? if( !(region->meshAttributes.extrude && region->meshAttributes.extrude->mesh.ExtrudeMesh && region->meshAttributes.extrude->geo.Mode == EXTRUDED_ENTITY) ) continue; // Test whether the face is a top for the region if( IsSurfaceATopForRegion(region, face) ){ top_regions.push_back(region); numTopRegions++; if( region->meshAttributes.extrude->mesh.QuadToTri ) (*detectQuadToTriTop) = true; } } // MAIN test of whether this is even a quadToTri extrusion lateral // the only return 0 path that is NOT an error if( !(*detectQuadToTriTop) ) return 0; ExtrudeParams *ep = face->meshAttributes.extrude; if(!ep && !is_toroidal_quadtri){ Msg::Error("In IsValidQuadToTriTop(), no extrude info for surface %d.", face->tag() ); return 0; } if( ep->geo.Mode != COPIED_ENTITY ){ Msg::Error("In IsValidQuadToTriTop(), surface %d is not copied from source.", face->tag() ); return 0; } if( ep->mesh.QuadToTri == 0){ Msg::Error("In IsValidQuadToTriTop(), surface %d was determined to be the top surface " "for a QuadToTri extrusion, but does not have QuadToTri parameters set within itself.", face->tag() ); return 0; } GFace *face_source = model->getFaceByTag(std::abs(ep->geo.Source)); if(!face_source){ Msg::Error("In IsValidQuadToTriTop(), unknown source face number %d.", face->meshAttributes.extrude->geo.Source); return 0; } if(numRegions > 2){ Msg::Error("In IsValidQuadToTriTop(), too many regions adjacent to surface %d.", face->tag() ); return 0; } if( top_regions.size() ){ (*quadToTri) = top_regions[0]->meshAttributes.extrude->mesh.QuadToTri; } // Make sure that face is the top for only one region. if not, then there will likely // be conflicts (two regions extruded into each other). if( top_regions.size() > 1 ){ Msg::Error("In IsValidQuadToTriTop(), QuadToTri top surface %d identified as top " "surface for more than one region. Likely conflict.", face->tag() ); return 0; } } // end of else that executes if NOT toroidal extrusion // this is technically redundant...but if changes are made, it's good to keep this here at the end for safety if( !(*detectQuadToTriTop) ) return 0; if( !is_toroidal_quadtri ) return 1; else if( is_toroidal_quadtri == 1 ) { return 2;} // for toroidal extrusion else return 3; }
void GWindow::Pour() { GRect Cli = GetClient(); if (!Cli.Valid()) return; GRegion Client(Cli); GViewI *MenuView = 0; GRegion Update(Client); bool HasTools = false; GViewI *v; List<GViewI>::I Lst = Children.Start(); { GRegion Tools; for (v = *Lst; v; v = *++Lst) { bool IsMenu = MenuView == v; if (!IsMenu && IsTool(v)) { GRect OldPos = v->GetPos(); Update.Union(&OldPos); if (HasTools) { // 2nd and later toolbars if (v->Pour(Tools)) { if (!v->Visible()) { v->Visible(true); } if (OldPos != v->GetPos()) { // position has changed update... v->Invalidate(); } Tools.Subtract(&v->GetPos()); Update.Subtract(&v->GetPos()); } } else { // First toolbar if (v->Pour(Client)) { HasTools = true; if (!v->Visible()) { v->Visible(true); } if (OldPos != v->GetPos()) { v->Invalidate(); } GRect Bar(v->GetPos()); Bar.x2 = GetClient().x2; Tools = Bar; Tools.Subtract(&v->GetPos()); Client.Subtract(&Bar); Update.Subtract(&Bar); } } } } } Lst = Children.Start(); for (GViewI *v = *Lst; v; v = *++Lst) { bool IsMenu = MenuView == v; if (!IsMenu && !IsTool(v)) { GRect OldPos = v->GetPos(); Update.Union(&OldPos); if (v->Pour(Client)) { GRect p = v->GetPos(); if (!v->Visible()) { v->Visible(true); } v->Invalidate(); Client.Subtract(&v->GetPos()); Update.Subtract(&v->GetPos()); } else { // non-pourable } } } for (int i=0; i<Update.Length(); i++) { Invalidate(Update[i]); } }
void GWindow::Pour() { GRegion Client(GetClient()); GRegion Update; bool HasTools = false; GViewI *v; { GRegion Tools; for (v = Children.First(); v; v = Children.Next()) { GView *k = dynamic_cast<GView*>(v); if (k && k->_IsToolBar) { GRect OldPos = v->GetPos(); Update.Union(&OldPos); if (HasTools) { // 2nd and later toolbars if (v->Pour(Tools)) { if (!v->Visible()) { v->Visible(true); } if (OldPos != v->GetPos()) { // position has changed update... v->Invalidate(); } Tools.Subtract(&v->GetPos()); Update.Subtract(&v->GetPos()); } } else { // First toolbar if (v->Pour(Client)) { HasTools = true; if (!v->Visible()) { v->Visible(true); } if (OldPos != v->GetPos()) { v->Invalidate(); } GRect Bar(v->GetPos()); Bar.x2 = GetClient().x2; Tools = Bar; Tools.Subtract(&v->GetPos()); Client.Subtract(&Bar); Update.Subtract(&Bar); } } } } } for (v = Children.First(); v; v = Children.Next()) { GView *k = dynamic_cast<GView*>(v); if (!(k && k->_IsToolBar)) { GRect OldPos = v->GetPos(); Update.Union(&OldPos); if (v->Pour(Client)) { if (!v->Visible()) { v->Visible(true); } if (OldPos != v->GetPos()) { // position has changed update... v->Invalidate(); } Client.Subtract(&v->GetPos()); Update.Subtract(&v->GetPos()); } else { // make the view not visible // v->Visible(FALSE); } } } for (int i=0; i<Update.Length(); i++) { Invalidate(Update[i]); } }
void Centerline::extrudeBoundaryLayerWall(GEdge* gin, std::vector<GEdge*> boundEdges) { Msg::Info("Centerline: extrude boundary layer wall (%d, %g%%R) ", nbElemLayer, hLayer); //orient extrude direction outward int dir = 0; MElement *e = current->getFaceByTag(1)->getMeshElement(0); SVector3 ne = e->getFace(0).normal(); SVector3 ps(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z()); double xyz[3] = {ps.x(), ps.y(), ps.z()}; ANNidx index[1]; ANNdist dist[1]; kdtree->annkSearch(xyz, 1, index, dist); ANNpointArray nodes = kdtree->thePoints(); SVector3 pc(nodes[index[0]][0], nodes[index[0]][1], nodes[index[0]][2]); SVector3 nc = ps-pc; if (dot(ne,nc) < 0) dir = 1; if (dir == 1 && hLayer > 0 ) hLayer *= -1.0; //int shift = 0; //if(is_cut) shift = NE; for (int i= 0; i< NF; i++){ GFace *gfc ; if (is_cut) gfc = current->getFaceByTag(NF+i+1); else gfc = current->getFaceByTag(i+1); current->setFactory("Gmsh"); //view -5 to scale hLayer by radius in BoundaryLayers.cpp std::vector<GEntity*> extrudedE = current->extrudeBoundaryLayer (gfc, nbElemLayer, hLayer, dir, -5); GFace *eFace = (GFace*) extrudedE[0]; eFace->addPhysicalEntity(5); current->setPhysicalName("outerWall", 2, 5);//dim 2 tag 5 GRegion *eRegion = (GRegion*) extrudedE[1]; eRegion->addPhysicalEntity(6); current->setPhysicalName("wallVolume", 3, 6);//dim 3 tag 6 //if double extruded layer if (nbElemSecondLayer > 0){ std::vector<GEntity*> extrudedESec = current->extrudeBoundaryLayer (eFace, nbElemSecondLayer, hSecondLayer, dir, -5); GFace *eFaceSec = (GFace*) extrudedESec[0]; eFaceSec->addPhysicalEntity(9); //tag 9 current->setPhysicalName("outerSecondWall", 2, 9);//dim 2 tag 9 GRegion *eRegionSec = (GRegion*) extrudedESec[1]; eRegionSec->addPhysicalEntity(10); //tag 10 current->setPhysicalName("wallVolume", 3, 10);//dim 3 tag 10 } //end double extrusion for (unsigned int j = 2; j < extrudedE.size(); j++){ GFace *elFace = (GFace*) extrudedE[j]; std::list<GEdge*> l_edges = elFace->edges(); for(std::list<GEdge*>::iterator it = l_edges.begin(); it != l_edges.end(); it++){ GEdge *myEdge = *it; if (is_cut) myEdge = current->getEdgeByTag((*it)->tag()-NE); if( std::find(boundEdges.begin(), boundEdges.end(), myEdge) != boundEdges.end() ){ if (myEdge==gin){ elFace->addPhysicalEntity(7); current->setPhysicalName("inletRing", 2, 7);//tag 7 } else{ elFace->addPhysicalEntity(8); current->setPhysicalName("outletRings", 2, 8);//tag 8 } } } } } }
void GWindow::Pour() { bool SafeToLock = false; if (Wnd->IsLocked()) { // I'm already locked... this could be bad if it's not me thread_id Thread = WindowHandle()->LockingThread(); if (Thread != -1) { if (Thread == find_thread(NULL)) { // it's all ok, I'm locking me SafeToLock = true; } else { // someone else is locking us // ok who is locking me? thread_info Info; if (get_thread_info(Thread, &Info) == B_OK) { printf("Evil locking thread: %i (%s)\n", Thread, Info.name); } else { printf("Couldn't get evil thread info\n"); } } } } else { SafeToLock = true; } if (!SafeToLock) { printf("%s:%i - Not safe to lock for ::Pour.\n", __FILE__, __LINE__); return; } bool Lock = Wnd->Lock(); Wnd->BeginViewTransaction(); GRect r(Handle()->Frame()); r.Offset(-r.x1, -r.y1); GRegion Client(r); GRegion Update; if (Menu) { GRect Mp = Menu->GetPos(); Mp.x2 = 10000; Client.Subtract(&Mp); } for (GViewI *w = Children.First(); w; w = Children.Next()) { GRect OldPos = w->GetPos(); Update.Union(&OldPos); if (w->Pour(Client)) { if (!w->Visible()) { w->Visible(true); } Client.Subtract(&w->GetPos()); Update.Subtract(&w->GetPos()); } else { // non-pourable } } Wnd->EndViewTransaction(); Wnd->Sync(); // Handle()->Invalidate(); if (Lock) Wnd->Unlock(); }
int SubdivideExtrudedMesh(GModel *m) { // get all non-recombined extruded regions and vertices; also, // create a vector of quadToTri regions that have NOT been meshed // yet std::vector<GRegion*> regions, regions_quadToTri; MVertexRTree pos(CTX::instance()->geom.tolerance * CTX::instance()->lc); for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){ ExtrudeParams *ep = (*it)->meshAttributes.extrude; if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY && !ep->mesh.Recombine){ regions.push_back(*it); insertAllVertices(*it, pos); } // create vector of valid quadToTri regions...not all will necessarily be meshed here. if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY && ep->mesh.Recombine && ep->mesh.QuadToTri){ regions_quadToTri.push_back(*it); } } if(regions.empty()) return 0; Msg::Info("Subdividing extruded mesh"); // create edges on lateral sides of "prisms" std::set<std::pair<MVertex*, MVertex*> > edges; for(unsigned int i = 0; i < regions.size(); i++) phase1(regions[i], pos, edges); // swap lateral edges to make them "tet-compatible" int j = 0, swap; std::set<std::pair<MVertex*, MVertex*> > edges_swap; do { swap = 0; for(unsigned int i = 0; i < regions.size(); i++) phase2(regions[i], pos, edges, edges_swap, swap); Msg::Info("Swapping %d", swap); if(j && j == swap) { Msg::Error("Unable to subdivide extruded mesh: change surface mesh or"); Msg::Error("recombine extrusion instead"); return -1; } j = swap; } while(swap); // delete volume elements and create tetrahedra instead for(unsigned int i = 0; i < regions.size(); i++){ GRegion *gr = regions[i]; for(unsigned int i = 0; i < gr->tetrahedra.size(); i++) delete gr->tetrahedra[i]; gr->tetrahedra.clear(); for(unsigned int i = 0; i < gr->hexahedra.size(); i++) delete gr->hexahedra[i]; gr->hexahedra.clear(); for(unsigned int i = 0; i < gr->prisms.size(); i++) delete gr->prisms[i]; gr->prisms.clear(); for(unsigned int i = 0; i < gr->pyramids.size(); i++) delete gr->pyramids[i]; gr->pyramids.clear(); phase3(gr, pos, edges); // re-Extrude bounding surfaces using edges as constraint std::list<GFace*> faces = gr->faces(); for(std::list<GFace*>::iterator it = faces.begin(); it != faces.end(); it++){ ExtrudeParams *ep = (*it)->meshAttributes.extrude; if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY && !ep->mesh.Recombine){ GFace *gf = *it; Msg::Info("Remeshing surface %d", gf->tag()); for(unsigned int i = 0; i < gf->triangles.size(); i++) delete gf->triangles[i]; gf->triangles.clear(); for(unsigned int i = 0; i < gf->quadrangles.size(); i++) delete gf->quadrangles[i]; gf->quadrangles.clear(); MeshExtrudedSurface(gf, &edges); } } } // now mesh the QuadToTri regions. Everything can be done locally // for each quadToTri region, but still use edge set from above just // to make sure laterals get remeshed properly ( // QuadToTriEdgeGenerator detects if the neighbor has been meshed or // if a lateral surface should remain static for any other reason). // If this function detects allNonGlobalSharedLaterals, it won't // mesh the region (should already be done in ExtrudeMesh). for(unsigned int i = 0; i < regions_quadToTri.size(); i++){ GRegion *gr = regions_quadToTri[i]; MVertexRTree pos_local(CTX::instance()->geom.tolerance * CTX::instance()->lc); insertAllVertices(gr, pos_local); meshQuadToTriRegionAfterGlobalSubdivide(gr, &edges, pos_local); } // carve holes if any // TODO: update extrusion information for(unsigned int i = 0; i < regions.size(); i++){ GRegion *gr = regions[i]; ExtrudeParams *ep = gr->meshAttributes.extrude; if(ep->mesh.Holes.size()){ std::map<int, std::pair<double, std::vector<int> > >::iterator it; for(it = ep->mesh.Holes.begin(); it != ep->mesh.Holes.end(); it++) carveHole(gr, it->first, it->second.first, it->second.second); } } for(unsigned int i = 0; i < regions_quadToTri.size(); i++){ GRegion *gr = regions_quadToTri[i]; ExtrudeParams *ep = gr->meshAttributes.extrude; if(ep->mesh.Holes.size()){ std::map<int, std::pair<double, std::vector<int> > >::iterator it; for(it = ep->mesh.Holes.begin(); it != ep->mesh.Holes.end(); it++) carveHole(gr, it->first, it->second.first, it->second.second); } } return 1; }