diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index aefec844..bcef540d 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -1,1460 +1,1467 @@ -#ifdef OCCGEOMETRY - -#include -#include -#include - - -namespace netgen -{ - -#include "occmeshsurf.hpp" - -#define TCL_OK 0 -#define TCL_ERROR 1 - -#define DIVIDEEDGESECTIONS 1000 -#define IGNORECURVELENGTH 1e-4 -#define VSMALL 1e-10 - - - bool merge_solids = 1; - - - // can you please explain what you intend to compute here (JS) !!! - double Line :: Dist (Line l) - { - Vec<3> n = p1-p0; - Vec<3> q = l.p1-l.p0; - double nq = n*q; - - Point<3> p = p0 + 0.5*n; - double lambda = (p-l.p0)*n / (nq + VSMALL); - - if (lambda >= 0 && lambda <= 1) - { - double d = (p-l.p0-lambda*q).Length(); - // if (d < 1e-3) d = 1e99; - return d; - } - else - return 1e99; - } - - - - double Line :: Length () - { - return (p1-p0).Length(); - } - - - - inline Point<3> occ2ng (const gp_Pnt & p) - { - return Point<3> (p.X(), p.Y(), p.Z()); - } - - - - double ComputeH (double kappa) - { - double hret; - kappa *= mparam.curvaturesafety; - - if (mparam.maxh * kappa < 1) - hret = mparam.maxh; - else - hret = 1 / (kappa + VSMALL); - - if (mparam.maxh < hret) - hret = mparam.maxh; - - return (hret); - } - - - - - void RestrictHTriangle (gp_Pnt2d & par0, gp_Pnt2d & par1, gp_Pnt2d & par2, - BRepLProp_SLProps * prop, Mesh & mesh, int depth, double h = 0) - { - int ls = -1; - - gp_Pnt pnt0,pnt1,pnt2; - - prop->SetParameters (par0.X(), par0.Y()); - pnt0 = prop->Value(); - - prop->SetParameters (par1.X(), par1.Y()); - pnt1 = prop->Value(); - - prop->SetParameters (par2.X(), par2.Y()); - pnt2 = prop->Value(); - - double aux; - double maxside = pnt0.Distance(pnt1); - ls = 2; - aux = pnt1.Distance(pnt2); - if(aux > maxside) - { - maxside = aux; - ls = 0; - } - aux = pnt2.Distance(pnt0); - if(aux > maxside) - { - maxside = aux; - ls = 1; - } - - - - gp_Pnt2d parmid; - - parmid.SetX( (par0.X()+par1.X()+par2.X()) / 3 ); - parmid.SetY( (par0.Y()+par1.Y()+par2.Y()) / 3 ); - - if (depth%3 == 0) - { - double curvature = 0; - - prop->SetParameters (parmid.X(), parmid.Y()); - if (!prop->IsCurvatureDefined()) - { - (*testout) << "curvature not defined!" << endl; - return; - } - curvature = max(fabs(prop->MinCurvature()), - fabs(prop->MaxCurvature())); - - prop->SetParameters (par0.X(), par0.Y()); - if (!prop->IsCurvatureDefined()) - { - (*testout) << "curvature not defined!" << endl; - return; - } - curvature = max(curvature,max(fabs(prop->MinCurvature()), - fabs(prop->MaxCurvature()))); - - prop->SetParameters (par1.X(), par1.Y()); - if (!prop->IsCurvatureDefined()) - { - (*testout) << "curvature not defined!" << endl; - return; - } - curvature = max(curvature,max(fabs(prop->MinCurvature()), - fabs(prop->MaxCurvature()))); - - prop->SetParameters (par2.X(), par2.Y()); - if (!prop->IsCurvatureDefined()) - { - (*testout) << "curvature not defined!" << endl; - return; - } - curvature = max(curvature,max(fabs(prop->MinCurvature()), - fabs(prop->MaxCurvature()))); - - //(*testout) << "curvature " << curvature << endl; - - if (curvature < 1e-3) - { - //(*testout) << "curvature too small (" << curvature << ")!" << endl; - return; - // return war bis 10.2.05 auskommentiert - } - - - - h = ComputeH (curvature+1e-10); - - if(h < 1e-4*maxside) - return; - - - if (h > 30) return; - } - - if (h < maxside && depth < 10) - { - //cout << "\r h " << h << flush; - gp_Pnt2d pm; - - //cout << "h " << h << " maxside " << maxside << " depth " << depth << endl; - //cout << "par0 " << par0.X() << " " << par0.Y() - //<< " par1 " << par1.X() << " " << par1.Y() - // << " par2 " << par2.X() << " " << par2.Y()<< endl; - - if(ls == 0) - { - pm.SetX(0.5*(par1.X()+par2.X())); pm.SetY(0.5*(par1.Y()+par2.Y())); - RestrictHTriangle(pm, par2, par0, prop, mesh, depth+1, h); - RestrictHTriangle(pm, par0, par1, prop, mesh, depth+1, h); - } - else if(ls == 1) - { - pm.SetX(0.5*(par0.X()+par2.X())); pm.SetY(0.5*(par0.Y()+par2.Y())); - RestrictHTriangle(pm, par1, par2, prop, mesh, depth+1, h); - RestrictHTriangle(pm, par0, par1, prop, mesh, depth+1, h); - } - else if(ls == 2) - { - pm.SetX(0.5*(par0.X()+par1.X())); pm.SetY(0.5*(par0.Y()+par1.Y())); - RestrictHTriangle(pm, par1, par2, prop, mesh, depth+1, h); - RestrictHTriangle(pm, par2, par0, prop, mesh, depth+1, h); - } - - } - else - { - gp_Pnt pnt; - Point3d p3d; - - prop->SetParameters (parmid.X(), parmid.Y()); - pnt = prop->Value(); - p3d = Point3d(pnt.X(), pnt.Y(), pnt.Z()); - mesh.RestrictLocalH (p3d, h); - - p3d = Point3d(pnt0.X(), pnt0.Y(), pnt0.Z()); - mesh.RestrictLocalH (p3d, h); - - p3d = Point3d(pnt1.X(), pnt1.Y(), pnt1.Z()); - mesh.RestrictLocalH (p3d, h); - - p3d = Point3d(pnt2.X(), pnt2.Y(), pnt2.Z()); - mesh.RestrictLocalH (p3d, h); - - //(*testout) << "p = " << p3d << ", h = " << h << ", maxside = " << maxside << endl; - - } - } - - - - void DivideEdge (TopoDS_Edge & edge, Array & ps, - Array & params, Mesh & mesh) - { - double s0, s1; - double maxh = mparam.maxh; - int nsubedges = 1; - gp_Pnt pnt, oldpnt; - double svalue[DIVIDEEDGESECTIONS]; - - GProp_GProps system; - BRepGProp::LinearProperties(edge, system); - double L = system.Mass(); - - Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1); - - double hvalue[DIVIDEEDGESECTIONS+1]; - hvalue[0] = 0; - pnt = c->Value(s0); - - double olddist = 0; - double dist = 0; - - int tmpVal = (int)(DIVIDEEDGESECTIONS); - - for (int i = 1; i <= tmpVal; i++) - { - oldpnt = pnt; - pnt = c->Value(s0+(i/double(DIVIDEEDGESECTIONS))*(s1-s0)); - hvalue[i] = hvalue[i-1] + - 1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))* - pnt.Distance(oldpnt); - - //(*testout) << "mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) " << mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) - // << " pnt.Distance(oldpnt) " << pnt.Distance(oldpnt) << endl; - - olddist = dist; - dist = pnt.Distance(oldpnt); - } - - // nsubedges = int(ceil(hvalue[DIVIDEEDGESECTIONS])); - nsubedges = max (1, int(floor(hvalue[DIVIDEEDGESECTIONS]+0.5))); - - ps.SetSize(nsubedges-1); - params.SetSize(nsubedges+1); - - int i = 1; - int i1 = 0; - do - { - if (hvalue[i1]/hvalue[DIVIDEEDGESECTIONS]*nsubedges >= i) - { - params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0); - pnt = c->Value(params[i]); - ps[i-1] = MeshPoint (Point3d(pnt.X(), pnt.Y(), pnt.Z())); - i++; - } - i1++; - if (i1 > DIVIDEEDGESECTIONS) - { - nsubedges = i; - ps.SetSize(nsubedges-1); - params.SetSize(nsubedges+1); - cout << "divide edge: local h too small" << endl; - } - } while (i < nsubedges); - - params[0] = s0; - params[nsubedges] = s1; - - if (params[nsubedges] <= params[nsubedges-1]) - { - cout << "CORRECTED" << endl; - ps.SetSize (nsubedges-2); - params.SetSize (nsubedges); - params[nsubedges] = s1; - } - } - - - - - void OCCFindEdges (OCCGeometry & geom, Mesh & mesh) - { - const char * savetask = multithread.task; - multithread.task = "Edge meshing"; - - (*testout) << "edge meshing" << endl; - - int nvertices = geom.vmap.Extent(); - int nedges = geom.emap.Extent(); - - (*testout) << "nvertices = " << nvertices << endl; - (*testout) << "nedges = " << nedges << endl; - - double eps = 1e-6 * geom.GetBoundingBox().Diam(); - - for (int i = 1; i <= nvertices; i++) - { - gp_Pnt pnt = BRep_Tool::Pnt (TopoDS::Vertex(geom.vmap(i))); - MeshPoint mp( Point<3>(pnt.X(), pnt.Y(), pnt.Z()) ); - - bool exists = 0; - if (merge_solids) - for (PointIndex pi = 1; pi <= mesh.GetNP(); pi++) - if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps) - { - exists = 1; - break; - } - - if (!exists) - mesh.AddPoint (mp); - } - - (*testout) << "different vertices = " << mesh.GetNP() << endl; - - - int first_ep = mesh.GetNP()+1; - - Array face2solid[2]; - for (int i = 0; i<2; i++) - { - face2solid[i].SetSize (geom.fmap.Extent()); - face2solid[i] = 0; - } - - int solidnr = 0; - for (TopExp_Explorer exp0(geom.shape, TopAbs_SOLID); exp0.More(); exp0.Next()) - { - solidnr++; - for (TopExp_Explorer exp1(exp0.Current(), TopAbs_FACE); exp1.More(); exp1.Next()) - { - TopoDS_Face face = TopoDS::Face(exp1.Current()); - int facenr = geom.fmap.FindIndex(face); - - if (face2solid[0][facenr-1] == 0) - face2solid[0][facenr-1] = solidnr; - else - face2solid[1][facenr-1] = solidnr; - } - } - - - int total = 0; - for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++) - for (TopExp_Explorer exp2(geom.fmap(i3), TopAbs_WIRE); exp2.More(); exp2.Next()) - for (TopExp_Explorer exp3(exp2.Current(), TopAbs_EDGE); exp3.More(); exp3.Next()) - total++; - - - int facenr = 0; - int edgenr = 0; - - - (*testout) << "faces = " << geom.fmap.Extent() << endl; - int curr = 0; - - for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++) - { - TopoDS_Face face = TopoDS::Face(geom.fmap(i3)); - facenr = geom.fmap.FindIndex (face); // sollte doch immer == i3 sein ??? JS - - int solidnr0 = face2solid[0][i3-1]; - int solidnr1 = face2solid[1][i3-1]; - - /* auskommentiert am 3.3.05 von robert - for (exp2.Init (geom.somap(solidnr0), TopAbs_FACE); exp2.More(); exp2.Next()) - { - TopoDS_Face face2 = TopoDS::Face(exp2.Current()); - if (geom.fmap.FindIndex(face2) == facenr) - { - // if (face.Orientation() != face2.Orientation()) swap (solidnr0, solidnr1); - } - } - */ - - mesh.AddFaceDescriptor (FaceDescriptor(facenr, solidnr0, solidnr1, 0)); - - // Philippose - 06/07/2009 - // Add the face colour to the mesh data - Quantity_Color face_colour; - - if(!(geom.face_colours.IsNull()) - && (geom.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour))) - { - mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(face_colour.Red(),face_colour.Green(),face_colour.Blue())); - } - else - { - mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(0.0,1.0,0.0)); - } - // ACHTUNG! STIMMT NICHT ALLGEMEIN (RG) - - - Handle(Geom_Surface) occface = BRep_Tool::Surface(face); - - for (TopExp_Explorer exp2 (face, TopAbs_WIRE); exp2.More(); exp2.Next()) - { - TopoDS_Shape wire = exp2.Current(); - - for (TopExp_Explorer exp3 (wire, TopAbs_EDGE); exp3.More(); exp3.Next()) - { - curr++; - (*testout) << "edge nr " << curr << endl; - - multithread.percent = 100 * curr / double (total); - if (multithread.terminate) return; - - TopoDS_Edge edge = TopoDS::Edge (exp3.Current()); - if (BRep_Tool::Degenerated(edge)) - { - //(*testout) << "ignoring degenerated edge" << endl; - continue; - } - - if (geom.vmap.FindIndex(TopExp::FirstVertex (edge)) == - geom.vmap.FindIndex(TopExp::LastVertex (edge))) - { - GProp_GProps system; - BRepGProp::LinearProperties(edge, system); - - if (system.Mass() < eps) - { - cout << "ignoring edge " << geom.emap.FindIndex (edge) - << ". closed edge with length < " << eps << endl; - continue; - } - } - - - Handle(Geom2d_Curve) cof; - double s0, s1; - cof = BRep_Tool::CurveOnSurface (edge, face, s0, s1); - - int geomedgenr = geom.emap.FindIndex(edge); - - Array mp; - Array params; - - DivideEdge (edge, mp, params, mesh); - - Array pnums; - pnums.SetSize (mp.Size()+2); - - if (!merge_solids) - { - pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge)); - pnums[pnums.Size()-1] = geom.vmap.FindIndex (TopExp::LastVertex (edge)); - } - else - { - Point<3> fp = occ2ng (BRep_Tool::Pnt (TopExp::FirstVertex (edge))); - Point<3> lp = occ2ng (BRep_Tool::Pnt (TopExp::LastVertex (edge))); - - pnums[0] = -1; - pnums.Last() = -1; - for (PointIndex pi = 1; pi < first_ep; pi++) - { - if (Dist2 (mesh[pi], fp) < eps*eps) pnums[0] = pi; - if (Dist2 (mesh[pi], lp) < eps*eps) pnums.Last() = pi; - } - } - - - for (int i = 1; i <= mp.Size(); i++) - { - bool exists = 0; - int j; - for (j = first_ep; j <= mesh.GetNP(); j++) - if ((mesh.Point(j)-Point<3>(mp[i-1])).Length() < eps) - { - exists = 1; - break; - } - - if (exists) - pnums[i] = j; - else - { - mesh.AddPoint (mp[i-1]); - (*testout) << "add meshpoint " << mp[i-1] << endl; - pnums[i] = mesh.GetNP(); - } - } - (*testout) << "NP = " << mesh.GetNP() << endl; - - //(*testout) << pnums[pnums.Size()-1] << endl; - - for (int i = 1; i <= mp.Size()+1; i++) - { - edgenr++; - Segment seg; - - seg[0] = pnums[i-1]; - seg[1] = pnums[i]; - seg.edgenr = edgenr; - seg.si = facenr; - seg.epgeominfo[0].dist = params[i-1]; - seg.epgeominfo[1].dist = params[i]; - seg.epgeominfo[0].edgenr = geomedgenr; - seg.epgeominfo[1].edgenr = geomedgenr; - - gp_Pnt2d p2d; - p2d = cof->Value(params[i-1]); - // if (i == 1) p2d = cof->Value(s0); - seg.epgeominfo[0].u = p2d.X(); - seg.epgeominfo[0].v = p2d.Y(); - p2d = cof->Value(params[i]); - // if (i == mp.Size()+1) p2d = cof -> Value(s1); - seg.epgeominfo[1].u = p2d.X(); - seg.epgeominfo[1].v = p2d.Y(); - - /* - if (occface->IsUPeriodic()) - { - cout << "U Periodic" << endl; - if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) > - fabs(seg.epgeominfo[1].u- - (seg.epgeominfo[0].u-occface->UPeriod()))) - seg.epgeominfo[0].u = p2d.X()+occface->UPeriod(); - - if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) > - fabs(seg.epgeominfo[1].u- - (seg.epgeominfo[0].u+occface->UPeriod()))) - seg.epgeominfo[0].u = p2d.X()-occface->UPeriod(); - } - - if (occface->IsVPeriodic()) - { - cout << "V Periodic" << endl; - if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) > - fabs(seg.epgeominfo[1].v- - (seg.epgeominfo[0].v-occface->VPeriod()))) - seg.epgeominfo[0].v = p2d.Y()+occface->VPeriod(); - - if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) > - fabs(seg.epgeominfo[1].v- - (seg.epgeominfo[0].v+occface->VPeriod()))) - seg.epgeominfo[0].v = p2d.Y()-occface->VPeriod(); - } - */ - - if (edge.Orientation() == TopAbs_REVERSED) - { - swap (seg[0], seg[1]); - swap (seg.epgeominfo[0].dist, seg.epgeominfo[1].dist); - swap (seg.epgeominfo[0].u, seg.epgeominfo[1].u); - swap (seg.epgeominfo[0].v, seg.epgeominfo[1].v); - } - - mesh.AddSegment (seg); - - //edgesegments[geomedgenr-1]->Append(mesh.GetNSeg()); - - } - } - } - } - - // for(i=1; i<=mesh.GetNSeg(); i++) - // (*testout) << "edge " << mesh.LineSegment(i).edgenr << " face " << mesh.LineSegment(i).si - // << " p1 " << mesh.LineSegment(i)[0] << " p2 " << mesh.LineSegment(i)[1] << endl; - // exit(10); - - mesh.CalcSurfacesOfNode(); - multithread.task = savetask; - } - - - - - void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend) - { - int i, j, k; - int changed; - - const char * savetask = multithread.task; - multithread.task = "Surface meshing"; - - geom.facemeshstatus = 0; - - int noldp = mesh.GetNP(); - - double starttime = GetTime(); - - Array glob2loc(noldp); - - //int projecttype = PARAMETERSPACE; - - int projecttype = PARAMETERSPACE; - - int notrys = 1; - - int surfmesherror = 0; - - for (k = 1; k <= mesh.GetNFD(); k++) - { - if(1==0 && !geom.fvispar[k-1].IsDrawable()) - { - (*testout) << "ignoring face " << k << endl; - cout << "ignoring face " << k << endl; - continue; - } - - (*testout) << "mesh face " << k << endl; - multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL); - geom.facemeshstatus[k-1] = -1; - - - /* - if (k != 42) - { - cout << "skipped" << endl; - continue; - } - */ - - - FaceDescriptor & fd = mesh.GetFaceDescriptor(k); - - int oldnf = mesh.GetNSE(); - - Box<3> bb = geom.GetBoundingBox(); - - // int projecttype = PLANESPACE; - - Meshing2OCCSurfaces meshing(TopoDS::Face(geom.fmap(k)), bb, projecttype); - - if (meshing.GetProjectionType() == PLANESPACE) - PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (plane space projection)"); - else - PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (parameter space projection)"); - - if (surfmesherror) - cout << "Surface meshing error occured before (in " << surfmesherror << " faces)" << endl; - - // Meshing2OCCSurfaces meshing(f2, bb); - meshing.SetStartTime (starttime); - - //(*testout) << "Face " << k << endl << endl; - - - if (meshing.GetProjectionType() == PLANESPACE) - { - int cntp = 0; - glob2loc = 0; - for (i = 1; i <= mesh.GetNSeg(); i++) - { - Segment & seg = mesh.LineSegment(i); - if (seg.si == k) - { - for (j = 1; j <= 2; j++) - { - int pi = (j == 1) ? seg[0] : seg[1]; - if (!glob2loc.Get(pi)) - { - meshing.AddPoint (mesh.Point(pi), pi); - cntp++; - glob2loc.Elem(pi) = cntp; - } - } - } - } - - for (i = 1; i <= mesh.GetNSeg(); i++) - { - Segment & seg = mesh.LineSegment(i); - if (seg.si == k) - { - PointGeomInfo gi0, gi1; - gi0.trignum = gi1.trignum = k; - gi0.u = seg.epgeominfo[0].u; - gi0.v = seg.epgeominfo[0].v; - gi1.u = seg.epgeominfo[1].u; - gi1.v = seg.epgeominfo[1].v; - - meshing.AddBoundaryElement (glob2loc.Get(seg[0]), glob2loc.Get(seg[1]), gi0, gi1); - //(*testout) << gi0.u << " " << gi0.v << endl; - //(*testout) << gi1.u << " " << gi1.v << endl; - } - } - } - else - { - int cntp = 0; - - for (i = 1; i <= mesh.GetNSeg(); i++) - if (mesh.LineSegment(i).si == k) - cntp+=2; - - - Array< PointGeomInfo > gis; - - gis.SetAllocSize (cntp); - gis.SetSize (0); - - for (i = 1; i <= mesh.GetNSeg(); i++) - { - Segment & seg = mesh.LineSegment(i); - if (seg.si == k) - { - PointGeomInfo gi0, gi1; - gi0.trignum = gi1.trignum = k; - gi0.u = seg.epgeominfo[0].u; - gi0.v = seg.epgeominfo[0].v; - gi1.u = seg.epgeominfo[1].u; - gi1.v = seg.epgeominfo[1].v; - - int locpnum[2] = {0, 0}; - - for (j = 0; j < 2; j++) - { - PointGeomInfo gi = (j == 0) ? gi0 : gi1; - - int l; - for (l = 0; l < gis.Size() && locpnum[j] == 0; l++) - { - double dist = sqr (gis[l].u-gi.u)+sqr(gis[l].v-gi.v); - - if (dist < 1e-10) - locpnum[j] = l+1; - } - - if (locpnum[j] == 0) - { - int pi = (j == 0) ? seg[0] : seg[1]; - meshing.AddPoint (mesh.Point(pi), pi); - - gis.SetSize (gis.Size()+1); - gis[l] = gi; - locpnum[j] = l+1; - } - } - - meshing.AddBoundaryElement (locpnum[0], locpnum[1], gi0, gi1); - //(*testout) << gi0.u << " " << gi0.v << endl; - //(*testout) << gi1.u << " " << gi1.v << endl; - - } - } - } - - - - - - // Philippose - 15/01/2009 - double maxh = geom.face_maxh[k-1]; - //double maxh = mparam.maxh; - mparam.checkoverlap = 0; - // int noldpoints = mesh->GetNP(); - int noldsurfel = mesh.GetNSE(); - - GProp_GProps sprops; - BRepGProp::SurfaceProperties(TopoDS::Face(geom.fmap(k)),sprops); - meshing.SetMaxArea(2.*sprops.Mass()); - - MESHING2_RESULT res; - - try { - res = meshing.GenerateMesh (mesh, mparam, maxh, k); - } - - catch (SingularMatrixException) - { - (*myerr) << "Singular Matrix" << endl; - res = MESHING2_GIVEUP; - } - - catch (UVBoundsException) - { - (*myerr) << "UV bounds exceeded" << endl; - res = MESHING2_GIVEUP; - } - - projecttype = PARAMETERSPACE; - - if (res != MESHING2_OK) - { - if (notrys == 1) - { - for (int i = noldsurfel+1; i <= mesh.GetNSE(); i++) - mesh.DeleteSurfaceElement (i); - - mesh.Compress(); - - cout << "retry Surface " << k << endl; - - k--; - projecttype*=-1; - notrys++; - continue; - } - else - { - geom.facemeshstatus[k-1] = -1; - PrintError ("Problem in Surface mesh generation"); - surfmesherror++; - // throw NgException ("Problem in Surface mesh generation"); - } - } - else - { - geom.facemeshstatus[k-1] = 1; - } - - notrys = 1; - - for (i = oldnf+1; i <= mesh.GetNSE(); i++) - mesh.SurfaceElement(i).SetIndex (k); - - } - -// ofstream problemfile("occmesh.rep"); - -// problemfile << "SURFACEMESHING" << endl << endl; - - if (surfmesherror) - { - cout << "WARNING! NOT ALL FACES HAVE BEEN MESHED" << endl; - cout << "SURFACE MESHING ERROR OCCURED IN " << surfmesherror << " FACES:" << endl; - for (int i = 1; i <= geom.fmap.Extent(); i++) - if (geom.facemeshstatus[i-1] == -1) - { - cout << "Face " << i << endl; -// problemfile << "problem with face " << i << endl; -// problemfile << "vertices: " << endl; - TopExp_Explorer exp0,exp1,exp2; - for ( exp0.Init(TopoDS::Face (geom.fmap(i)), TopAbs_WIRE); exp0.More(); exp0.Next() ) - { - TopoDS_Wire wire = TopoDS::Wire(exp0.Current()); - for ( exp1.Init(wire,TopAbs_EDGE); exp1.More(); exp1.Next() ) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - for ( exp2.Init(edge,TopAbs_VERTEX); exp2.More(); exp2.Next() ) - { - TopoDS_Vertex vertex = TopoDS::Vertex(exp2.Current()); - gp_Pnt point = BRep_Tool::Pnt(vertex); -// problemfile << point.X() << " " << point.Y() << " " << point.Z() << endl; - } - } - } -// problemfile << endl; - - } - cout << endl << endl; - cout << "for more information open IGES/STEP Topology Explorer" << endl; -// problemfile.close(); - throw NgException ("Problem in Surface mesh generation"); - } - else - { -// problemfile << "OK" << endl << endl; -// problemfile.close(); - } - - - - - if (multithread.terminate || perfstepsend < MESHCONST_OPTSURFACE) - return; - - multithread.task = "Optimizing surface"; - - static int timer_opt2d = NgProfiler::CreateTimer ("Optimization 2D"); - NgProfiler::StartTimer (timer_opt2d); - - for (k = 1; k <= mesh.GetNFD(); k++) - { - // if (k != 42) continue; - // if (k != 36) continue; - - // (*testout) << "optimize face " << k << endl; - multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL); - - FaceDescriptor & fd = mesh.GetFaceDescriptor(k); - - PrintMessage (1, "Optimize Surface ", k); - for (i = 1; i <= mparam.optsteps2d; i++) - { - // (*testout) << "optstep " << i << endl; - if (multithread.terminate) return; - - { - MeshOptimize2dOCCSurfaces meshopt(geom); - meshopt.SetFaceIndex (k); - meshopt.SetImproveEdges (0); - meshopt.SetMetricWeight (mparam.elsizeweight); - //meshopt.SetMetricWeight (0.2); - meshopt.SetWriteStatus (0); - - // (*testout) << "EdgeSwapping (mesh, (i > mparam.optsteps2d/2))" << endl; - meshopt.EdgeSwapping (mesh, (i > mparam.optsteps2d/2)); - } - - if (multithread.terminate) return; - { - MeshOptimize2dOCCSurfaces meshopt(geom); - meshopt.SetFaceIndex (k); - meshopt.SetImproveEdges (0); - //meshopt.SetMetricWeight (0.2); - meshopt.SetMetricWeight (mparam.elsizeweight); - meshopt.SetWriteStatus (0); - - // (*testout) << "ImproveMesh (mesh)" << endl; - meshopt.ImproveMesh (mesh, mparam); - } - - { - MeshOptimize2dOCCSurfaces meshopt(geom); - meshopt.SetFaceIndex (k); - meshopt.SetImproveEdges (0); - //meshopt.SetMetricWeight (0.2); - meshopt.SetMetricWeight (mparam.elsizeweight); - meshopt.SetWriteStatus (0); - - // (*testout) << "CombineImprove (mesh)" << endl; - meshopt.CombineImprove (mesh); - } - - if (multithread.terminate) return; - { - MeshOptimize2dOCCSurfaces meshopt(geom); - meshopt.SetFaceIndex (k); - meshopt.SetImproveEdges (0); - //meshopt.SetMetricWeight (0.2); - meshopt.SetMetricWeight (mparam.elsizeweight); - meshopt.SetWriteStatus (0); - - // (*testout) << "ImproveMesh (mesh)" << endl; - meshopt.ImproveMesh (mesh, mparam); - } - } - - } - - - mesh.CalcSurfacesOfNode(); - mesh.Compress(); - - NgProfiler::StopTimer (timer_opt2d); - - multithread.task = savetask; - } - - - - void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh) - { - mesh.SetGlobalH (mparam.maxh); - mesh.SetMinimalH (mparam.minh); - - Array maxhdom; - maxhdom.SetSize (geom.NrSolids()); - maxhdom = mparam.maxh; - - mesh.SetMaxHDomain (maxhdom); - - Box<3> bb = geom.GetBoundingBox(); - bb.Increase (bb.Diam()/10); - - mesh.SetLocalH (bb.PMin(), bb.PMax(), 0.5); - - if (mparam.uselocalh) - { - const char * savetask = multithread.task; - multithread.percent = 0; - - mesh.SetLocalH (bb.PMin(), bb.PMax(), mparam.grading); - - int nedges = geom.emap.Extent(); - - double maxedgelen = 0; - double minedgelen = 1e99; - - multithread.task = "Setting local mesh size (elements per edge)"; - - // setting elements per edge - - for (int i = 1; i <= nedges && !multithread.terminate; i++) - { - TopoDS_Edge e = TopoDS::Edge (geom.emap(i)); - multithread.percent = 100 * (i-1)/double(nedges); - if (BRep_Tool::Degenerated(e)) continue; - - GProp_GProps system; - BRepGProp::LinearProperties(e, system); - double len = system.Mass(); - - if (len < IGNORECURVELENGTH) - { - (*testout) << "ignored" << endl; - continue; - } - - double localh = len/mparam.segmentsperedge; - double s0, s1; - - // Philippose - 23/01/2009 - // Find all the parent faces of a given edge - // and limit the mesh size of the edge based on the - // mesh size limit of the face - TopTools_IndexedDataMapOfShapeListOfShape edge_face_map; - edge_face_map.Clear(); - - TopExp::MapShapesAndAncestors(geom.shape, TopAbs_EDGE, TopAbs_FACE, edge_face_map); - const TopTools_ListOfShape& parent_faces = edge_face_map.FindFromKey(e); - - TopTools_ListIteratorOfListOfShape parent_face_list; - - for(parent_face_list.Initialize(parent_faces); parent_face_list.More(); parent_face_list.Next()) - { - TopoDS_Face parent_face = TopoDS::Face(parent_face_list.Value()); - - int face_index = geom.fmap.FindIndex(parent_face); - - if(face_index >= 1) localh = min(localh,geom.face_maxh[face_index - 1]); - } - - Handle(Geom_Curve) c = BRep_Tool::Curve(e, s0, s1); - - maxedgelen = max (maxedgelen, len); - minedgelen = min (minedgelen, len); - - // Philippose - 23/01/2009 - // Modified the calculation of maxj, because the - // method used so far always results in maxj = 2, - // which causes the localh to be set only at the - // starting, mid and end of the edge. - // Old Algorithm: - // int maxj = 2 * (int) ceil (localh/len); - int maxj = max((int) ceil(len/localh), 2); - - for (int j = 0; j <= maxj; j++) - { - gp_Pnt pnt = c->Value (s0+double(j)/maxj*(s1-s0)); - mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), localh); - } - } - - multithread.task = "Setting local mesh size (edge curvature)"; - - // setting edge curvature - - int nsections = 20; - - for (int i = 1; i <= nedges && !multithread.terminate; i++) - { - double maxcur = 0; - multithread.percent = 100 * (i-1)/double(nedges); - TopoDS_Edge edge = TopoDS::Edge (geom.emap(i)); - if (BRep_Tool::Degenerated(edge)) continue; - double s0, s1; - Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1); - BRepAdaptor_Curve brepc(edge); - BRepLProp_CLProps prop(brepc, 2, 1e-5); - - for (int j = 1; j <= nsections; j++) - { - double s = s0 + j/(double) nsections * (s1-s0); - prop.SetParameter (s); - double curvature = prop.Curvature(); - if(curvature> maxcur) maxcur = curvature; - - if (curvature >= 1e99) - continue; - - gp_Pnt pnt = c->Value (s); - - mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), ComputeH (fabs(curvature))); - } - // (*testout) << "edge " << i << " max. curvature: " << maxcur << endl; - } - - multithread.task = "Setting local mesh size (face curvature)"; - - // setting face curvature - - int nfaces = geom.fmap.Extent(); - - for (int i = 1; i <= nfaces && !multithread.terminate; i++) - { - multithread.percent = 100 * (i-1)/double(nfaces); - TopoDS_Face face = TopoDS::Face(geom.fmap(i)); - TopLoc_Location loc; - Handle(Geom_Surface) surf = BRep_Tool::Surface (face); - Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc); - - if (triangulation.IsNull()) continue; - - BRepAdaptor_Surface sf(face, Standard_True); - BRepLProp_SLProps prop(sf, 2, 1e-5); - - int ntriangles = triangulation -> NbTriangles(); - for (int j = 1; j <= ntriangles; j++) - { - gp_Pnt p[3]; - gp_Pnt2d par[3]; - - for (int k = 1; k <=3; k++) - { - int n = triangulation->Triangles()(j)(k); - p[k-1] = triangulation->Nodes()(n).Transformed(loc); - par[k-1] = triangulation->UVNodes()(n); - } - - //double maxside = 0; - //maxside = max (maxside, p[0].Distance(p[1])); - //maxside = max (maxside, p[0].Distance(p[2])); - //maxside = max (maxside, p[1].Distance(p[2])); - //cout << "\rFace " << i << " pos11 ntriangles " << ntriangles << " maxside " << maxside << flush; - - RestrictHTriangle (par[0], par[1], par[2], &prop, mesh, 0); - //cout << "\rFace " << i << " pos12 ntriangles " << ntriangles << flush; - } - } - - // setting close edges - - if (occparam.resthcloseedgeenable) - { - multithread.task = "Setting local mesh size (close edges)"; - - int sections = 100; - - Array lines(sections*nedges); - - Box3dTree* searchtree = - new Box3dTree (bb.PMin(), bb.PMax()); - - int nlines = 0; - for (int i = 1; i <= nedges && !multithread.terminate; i++) - { - TopoDS_Edge edge = TopoDS::Edge (geom.emap(i)); - if (BRep_Tool::Degenerated(edge)) continue; - - double s0, s1; - Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1); - BRepAdaptor_Curve brepc(edge); - BRepLProp_CLProps prop(brepc, 1, 1e-5); - prop.SetParameter (s0); - - gp_Vec d0 = prop.D1().Normalized(); - double s_start = s0; - int count = 0; - for (int j = 1; j <= sections; j++) - { - double s = s0 + (s1-s0)*(double)j/(double)sections; - prop.SetParameter (s); - gp_Vec d1 = prop.D1().Normalized(); - double cosalpha = fabs(d0*d1); - if ((j == sections) || (cosalpha < cos(10.0/180.0*M_PI))) - { - count++; - gp_Pnt p0 = c->Value (s_start); - gp_Pnt p1 = c->Value (s); - lines[nlines].p0 = Point<3> (p0.X(), p0.Y(), p0.Z()); - lines[nlines].p1 = Point<3> (p1.X(), p1.Y(), p1.Z()); - - Box3d box; - box.SetPoint (Point3d(lines[nlines].p0)); - box.AddPoint (Point3d(lines[nlines].p1)); - - searchtree->Insert (box.PMin(), box.PMax(), nlines+1); - nlines++; - - s_start = s; - d0 = d1; - } - } - } - - Array linenums; - - for (int i = 0; i < nlines; i++) - { - multithread.percent = (100*i)/double(nlines); - Line & line = lines[i]; - - Box3d box; - box.SetPoint (Point3d(line.p0)); - box.AddPoint (Point3d(line.p1)); - double maxhline = max (mesh.GetH(box.PMin()), - mesh.GetH(box.PMax())); - box.Increase(maxhline); - - double mindist = 1e99; - linenums.SetSize(0); - searchtree->GetIntersecting(box.PMin(),box.PMax(),linenums); - - for (int j = 0; j < linenums.Size(); j++) - { - int num = linenums[j]-1; - if (i == num) continue; - if ((line.p0-lines[num].p0).Length2() < 1e-15) continue; - if ((line.p0-lines[num].p1).Length2() < 1e-15) continue; - if ((line.p1-lines[num].p0).Length2() < 1e-15) continue; - if ((line.p1-lines[num].p1).Length2() < 1e-15) continue; - mindist = min (mindist, line.Dist(lines[num])); - } - - mindist /= (occparam.resthcloseedgefac + VSMALL); - - if (mindist < 1e-3) - { - (*testout) << "extremely small local h: " << mindist - << " --> setting to 1e-3" << endl; - (*testout) << "somewhere near " << line.p0 << " - " << line.p1 << endl; - mindist = 1e-3; - } - - mesh.RestrictLocalHLine(line.p0, line.p1, mindist); - } - } - - multithread.task = savetask; - - } - - // Philippose - 09/03/2009 - // Added the capability to load the mesh size from a - // file also for OpenCascade Geometry - // Note: - // ** If the "uselocalh" option is ticked in - // the "mesh options...insider" menu, the mesh - // size will be further modified by the topology - // analysis routines. - // ** To use the mesh size file as the sole source - // for defining the mesh size, uncheck the "uselocalh" - // option. - mesh.LoadLocalMeshSize (mparam.meshsizefilename); - } - - - - int OCCGenerateMesh (OCCGeometry & geom, Mesh *& mesh, MeshingParameters & mparam, - int perfstepsstart, int perfstepsend) - { - multithread.percent = 0; - - if (perfstepsstart <= MESHCONST_ANALYSE) - { - delete mesh; - mesh = new Mesh(); - mesh->geomtype = Mesh::GEOM_OCC; - - OCCSetLocalMeshSize(geom,*mesh); - } - - if (multithread.terminate || perfstepsend <= MESHCONST_ANALYSE) - return TCL_OK; - - if (perfstepsstart <= MESHCONST_MESHEDGES) - { - OCCFindEdges (geom, *mesh); - - /* - cout << "Removing redundant points" << endl; - - int i, j; - int np = mesh->GetNP(); - Array equalto; - - equalto.SetSize (np); - equalto = 0; - - for (i = 1; i <= np; i++) - { - for (j = i+1; j <= np; j++) - { - if (!equalto[j-1] && (Dist2 (mesh->Point(i), mesh->Point(j)) < 1e-12)) - equalto[j-1] = i; - } - } - - for (i = 1; i <= np; i++) - if (equalto[i-1]) - { - cout << "Point " << i << " is equal to Point " << equalto[i-1] << endl; - for (j = 1; j <= mesh->GetNSeg(); j++) - { - Segment & seg = mesh->LineSegment(j); - if (seg[0] == i) seg[0] = equalto[i-1]; - if (seg[1] == i) seg[1] = equalto[i-1]; - } - } - - cout << "Removing degenerated segments" << endl; - for (j = 1; j <= mesh->GetNSeg(); j++) - { - Segment & seg = mesh->LineSegment(j); - if (seg[0] == seg[1]) - { - mesh->DeleteSegment(j); - cout << "Deleting Segment " << j << endl; - } - } - - mesh->Compress(); - */ - - /* - for (int i = 1; i <= geom.fmap.Extent(); i++) - { - Handle(Geom_Surface) hf1 = - BRep_Tool::Surface(TopoDS::Face(geom.fmap(i))); - for (int j = i+1; j <= geom.fmap.Extent(); j++) - { - Handle(Geom_Surface) hf2 = - BRep_Tool::Surface(TopoDS::Face(geom.fmap(j))); - if (hf1 == hf2) cout << "face " << i << " and face " << j << " lie on same surface" << endl; - } - } - */ - -#ifdef LOG_STREAM - (*logout) << "Edges meshed" << endl - << "time = " << GetTime() << " sec" << endl - << "points: " << mesh->GetNP() << endl; -#endif - } - - if (multithread.terminate || perfstepsend <= MESHCONST_MESHEDGES) - return TCL_OK; - - if (perfstepsstart <= MESHCONST_MESHSURFACE) - { - OCCMeshSurface (geom, *mesh, perfstepsend); - if (multithread.terminate) return TCL_OK; - -#ifdef LOG_STREAM - (*logout) << "Surfaces meshed" << endl - << "time = " << GetTime() << " sec" << endl - << "points: " << mesh->GetNP() << endl; -#endif - -#ifdef STAT_STREAM - (*statout) << mesh->GetNSeg() << " & " - << mesh->GetNSE() << " & - &" - << GetTime() << " & " << endl; -#endif - - // MeshQuality2d (*mesh); - mesh->CalcSurfacesOfNode(); - } - - if (multithread.terminate || perfstepsend <= MESHCONST_OPTSURFACE) - return TCL_OK; - - if (perfstepsstart <= MESHCONST_MESHVOLUME) - { - multithread.task = "Volume meshing"; - - MESHING3_RESULT res = MeshVolume (mparam, *mesh); - -/* - ofstream problemfile("occmesh.rep",ios_base::app); - - problemfile << "VOLUMEMESHING" << endl << endl; - if(res != MESHING3_OK) - problemfile << "ERROR" << endl << endl; - else - problemfile << "OK" << endl - << mesh->GetNE() << " elements" << endl << endl; - - problemfile.close(); -*/ - - if (res != MESHING3_OK) return TCL_ERROR; - - if (multithread.terminate) return TCL_OK; - - RemoveIllegalElements (*mesh); - if (multithread.terminate) return TCL_OK; - - MeshQuality3d (*mesh); - -#ifdef STAT_STREAM - (*statout) << GetTime() << " & "; -#endif - -#ifdef LOG_STREAM - (*logout) << "Volume meshed" << endl - << "time = " << GetTime() << " sec" << endl - << "points: " << mesh->GetNP() << endl; -#endif - } - - if (multithread.terminate || perfstepsend <= MESHCONST_MESHVOLUME) - return TCL_OK; - - if (perfstepsstart <= MESHCONST_OPTVOLUME) - { - multithread.task = "Volume optimization"; - - OptimizeVolume (mparam, *mesh); - if (multithread.terminate) return TCL_OK; - -#ifdef STAT_STREAM - (*statout) << GetTime() << " & " - << mesh->GetNE() << " & " - << mesh->GetNP() << " " << '\\' << '\\' << " \\" << "hline" << endl; -#endif - -#ifdef LOG_STREAM - (*logout) << "Volume optimized" << endl - << "time = " << GetTime() << " sec" << endl - << "points: " << mesh->GetNP() << endl; -#endif - - // cout << "Optimization complete" << endl; - - } - - (*testout) << "NP: " << mesh->GetNP() << endl; - for (int i = 1; i <= mesh->GetNP(); i++) - (*testout) << mesh->Point(i) << endl; - - (*testout) << endl << "NSegments: " << mesh->GetNSeg() << endl; - for (int i = 1; i <= mesh->GetNSeg(); i++) - (*testout) << mesh->LineSegment(i) << endl; - - return TCL_OK; - } -} - -#endif +#ifdef OCCGEOMETRY + +#include +#include +#include + + +namespace netgen +{ + +#include "occmeshsurf.hpp" + +#define TCL_OK 0 +#define TCL_ERROR 1 + +#define DIVIDEEDGESECTIONS 1000 +#define IGNORECURVELENGTH 1e-4 +#define VSMALL 1e-10 + + + bool merge_solids = 1; + + + // can you please explain what you intend to compute here (JS) !!! + double Line :: Dist (Line l) + { + Vec<3> n = p1-p0; + Vec<3> q = l.p1-l.p0; + double nq = n*q; + + Point<3> p = p0 + 0.5*n; + double lambda = (p-l.p0)*n / (nq + VSMALL); + + if (lambda >= 0 && lambda <= 1) + { + double d = (p-l.p0-lambda*q).Length(); + // if (d < 1e-3) d = 1e99; + return d; + } + else + return 1e99; + } + + + + double Line :: Length () + { + return (p1-p0).Length(); + } + + + + inline Point<3> occ2ng (const gp_Pnt & p) + { + return Point<3> (p.X(), p.Y(), p.Z()); + } + + + + double ComputeH (double kappa) + { + double hret; + kappa *= mparam.curvaturesafety; + + if (mparam.maxh * kappa < 1) + hret = mparam.maxh; + else + hret = 1 / (kappa + VSMALL); + + if (mparam.maxh < hret) + hret = mparam.maxh; + + return (hret); + } + + + + + void RestrictHTriangle (gp_Pnt2d & par0, gp_Pnt2d & par1, gp_Pnt2d & par2, + BRepLProp_SLProps * prop, Mesh & mesh, int depth, double h = 0) + { + int ls = -1; + + gp_Pnt pnt0,pnt1,pnt2; + + prop->SetParameters (par0.X(), par0.Y()); + pnt0 = prop->Value(); + + prop->SetParameters (par1.X(), par1.Y()); + pnt1 = prop->Value(); + + prop->SetParameters (par2.X(), par2.Y()); + pnt2 = prop->Value(); + + double aux; + double maxside = pnt0.Distance(pnt1); + ls = 2; + aux = pnt1.Distance(pnt2); + if(aux > maxside) + { + maxside = aux; + ls = 0; + } + aux = pnt2.Distance(pnt0); + if(aux > maxside) + { + maxside = aux; + ls = 1; + } + + + + gp_Pnt2d parmid; + + parmid.SetX( (par0.X()+par1.X()+par2.X()) / 3 ); + parmid.SetY( (par0.Y()+par1.Y()+par2.Y()) / 3 ); + + if (depth%3 == 0) + { + double curvature = 0; + + prop->SetParameters (parmid.X(), parmid.Y()); + if (!prop->IsCurvatureDefined()) + { + (*testout) << "curvature not defined!" << endl; + return; + } + curvature = max(fabs(prop->MinCurvature()), + fabs(prop->MaxCurvature())); + + prop->SetParameters (par0.X(), par0.Y()); + if (!prop->IsCurvatureDefined()) + { + (*testout) << "curvature not defined!" << endl; + return; + } + curvature = max(curvature,max(fabs(prop->MinCurvature()), + fabs(prop->MaxCurvature()))); + + prop->SetParameters (par1.X(), par1.Y()); + if (!prop->IsCurvatureDefined()) + { + (*testout) << "curvature not defined!" << endl; + return; + } + curvature = max(curvature,max(fabs(prop->MinCurvature()), + fabs(prop->MaxCurvature()))); + + prop->SetParameters (par2.X(), par2.Y()); + if (!prop->IsCurvatureDefined()) + { + (*testout) << "curvature not defined!" << endl; + return; + } + curvature = max(curvature,max(fabs(prop->MinCurvature()), + fabs(prop->MaxCurvature()))); + + //(*testout) << "curvature " << curvature << endl; + + if (curvature < 1e-3) + { + //(*testout) << "curvature too small (" << curvature << ")!" << endl; + return; + // return war bis 10.2.05 auskommentiert + } + + + + h = ComputeH (curvature+1e-10); + + if(h < 1e-4*maxside) + return; + + + if (h > 30) return; + } + + if (h < maxside && depth < 10) + { + //cout << "\r h " << h << flush; + gp_Pnt2d pm; + + //cout << "h " << h << " maxside " << maxside << " depth " << depth << endl; + //cout << "par0 " << par0.X() << " " << par0.Y() + //<< " par1 " << par1.X() << " " << par1.Y() + // << " par2 " << par2.X() << " " << par2.Y()<< endl; + + if(ls == 0) + { + pm.SetX(0.5*(par1.X()+par2.X())); pm.SetY(0.5*(par1.Y()+par2.Y())); + RestrictHTriangle(pm, par2, par0, prop, mesh, depth+1, h); + RestrictHTriangle(pm, par0, par1, prop, mesh, depth+1, h); + } + else if(ls == 1) + { + pm.SetX(0.5*(par0.X()+par2.X())); pm.SetY(0.5*(par0.Y()+par2.Y())); + RestrictHTriangle(pm, par1, par2, prop, mesh, depth+1, h); + RestrictHTriangle(pm, par0, par1, prop, mesh, depth+1, h); + } + else if(ls == 2) + { + pm.SetX(0.5*(par0.X()+par1.X())); pm.SetY(0.5*(par0.Y()+par1.Y())); + RestrictHTriangle(pm, par1, par2, prop, mesh, depth+1, h); + RestrictHTriangle(pm, par2, par0, prop, mesh, depth+1, h); + } + + } + else + { + gp_Pnt pnt; + Point3d p3d; + + prop->SetParameters (parmid.X(), parmid.Y()); + pnt = prop->Value(); + p3d = Point3d(pnt.X(), pnt.Y(), pnt.Z()); + mesh.RestrictLocalH (p3d, h); + + p3d = Point3d(pnt0.X(), pnt0.Y(), pnt0.Z()); + mesh.RestrictLocalH (p3d, h); + + p3d = Point3d(pnt1.X(), pnt1.Y(), pnt1.Z()); + mesh.RestrictLocalH (p3d, h); + + p3d = Point3d(pnt2.X(), pnt2.Y(), pnt2.Z()); + mesh.RestrictLocalH (p3d, h); + + //(*testout) << "p = " << p3d << ", h = " << h << ", maxside = " << maxside << endl; + + } + } + + + + void DivideEdge (TopoDS_Edge & edge, Array & ps, + Array & params, Mesh & mesh) + { + double s0, s1; + double maxh = mparam.maxh; + int nsubedges = 1; + gp_Pnt pnt, oldpnt; + double svalue[DIVIDEEDGESECTIONS]; + + GProp_GProps system; + BRepGProp::LinearProperties(edge, system); + double L = system.Mass(); + + Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1); + + double hvalue[DIVIDEEDGESECTIONS+1]; + hvalue[0] = 0; + pnt = c->Value(s0); + + double olddist = 0; + double dist = 0; + + int tmpVal = (int)(DIVIDEEDGESECTIONS); + + for (int i = 1; i <= tmpVal; i++) + { + oldpnt = pnt; + pnt = c->Value(s0+(i/double(DIVIDEEDGESECTIONS))*(s1-s0)); + hvalue[i] = hvalue[i-1] + + 1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))* + pnt.Distance(oldpnt); + + //(*testout) << "mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) " << mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) + // << " pnt.Distance(oldpnt) " << pnt.Distance(oldpnt) << endl; + + olddist = dist; + dist = pnt.Distance(oldpnt); + } + + // nsubedges = int(ceil(hvalue[DIVIDEEDGESECTIONS])); + nsubedges = max (1, int(floor(hvalue[DIVIDEEDGESECTIONS]+0.5))); + + ps.SetSize(nsubedges-1); + params.SetSize(nsubedges+1); + + int i = 1; + int i1 = 0; + do + { + if (hvalue[i1]/hvalue[DIVIDEEDGESECTIONS]*nsubedges >= i) + { + params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0); + pnt = c->Value(params[i]); + ps[i-1] = MeshPoint (Point3d(pnt.X(), pnt.Y(), pnt.Z())); + i++; + } + i1++; + if (i1 > DIVIDEEDGESECTIONS) + { + nsubedges = i; + ps.SetSize(nsubedges-1); + params.SetSize(nsubedges+1); + cout << "divide edge: local h too small" << endl; + } + } while (i < nsubedges); + + params[0] = s0; + params[nsubedges] = s1; + + if (params[nsubedges] <= params[nsubedges-1]) + { + cout << "CORRECTED" << endl; + ps.SetSize (nsubedges-2); + params.SetSize (nsubedges); + params[nsubedges] = s1; + } + } + + + + + void OCCFindEdges (OCCGeometry & geom, Mesh & mesh) + { + const char * savetask = multithread.task; + multithread.task = "Edge meshing"; + + (*testout) << "edge meshing" << endl; + + int nvertices = geom.vmap.Extent(); + int nedges = geom.emap.Extent(); + + (*testout) << "nvertices = " << nvertices << endl; + (*testout) << "nedges = " << nedges << endl; + + double eps = 1e-6 * geom.GetBoundingBox().Diam(); + + for (int i = 1; i <= nvertices; i++) + { + gp_Pnt pnt = BRep_Tool::Pnt (TopoDS::Vertex(geom.vmap(i))); + MeshPoint mp( Point<3>(pnt.X(), pnt.Y(), pnt.Z()) ); + + bool exists = 0; + if (merge_solids) + for (PointIndex pi = 1; pi <= mesh.GetNP(); pi++) + if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps) + { + exists = 1; + break; + } + + if (!exists) + mesh.AddPoint (mp); + } + + (*testout) << "different vertices = " << mesh.GetNP() << endl; + + + int first_ep = mesh.GetNP()+1; + + Array face2solid[2]; + for (int i = 0; i<2; i++) + { + face2solid[i].SetSize (geom.fmap.Extent()); + face2solid[i] = 0; + } + + int solidnr = 0; + for (TopExp_Explorer exp0(geom.shape, TopAbs_SOLID); exp0.More(); exp0.Next()) + { + solidnr++; + for (TopExp_Explorer exp1(exp0.Current(), TopAbs_FACE); exp1.More(); exp1.Next()) + { + TopoDS_Face face = TopoDS::Face(exp1.Current()); + int facenr = geom.fmap.FindIndex(face); + + if (face2solid[0][facenr-1] == 0) + face2solid[0][facenr-1] = solidnr; + else + face2solid[1][facenr-1] = solidnr; + } + } + + + int total = 0; + for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++) + for (TopExp_Explorer exp2(geom.fmap(i3), TopAbs_WIRE); exp2.More(); exp2.Next()) + for (TopExp_Explorer exp3(exp2.Current(), TopAbs_EDGE); exp3.More(); exp3.Next()) + total++; + + + int facenr = 0; + int edgenr = 0; + + + (*testout) << "faces = " << geom.fmap.Extent() << endl; + int curr = 0; + + for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++) + { + TopoDS_Face face = TopoDS::Face(geom.fmap(i3)); + facenr = geom.fmap.FindIndex (face); // sollte doch immer == i3 sein ??? JS + + int solidnr0 = face2solid[0][i3-1]; + int solidnr1 = face2solid[1][i3-1]; + + /* auskommentiert am 3.3.05 von robert + for (exp2.Init (geom.somap(solidnr0), TopAbs_FACE); exp2.More(); exp2.Next()) + { + TopoDS_Face face2 = TopoDS::Face(exp2.Current()); + if (geom.fmap.FindIndex(face2) == facenr) + { + // if (face.Orientation() != face2.Orientation()) swap (solidnr0, solidnr1); + } + } + */ + + mesh.AddFaceDescriptor (FaceDescriptor(facenr, solidnr0, solidnr1, 0)); + + // Philippose - 06/07/2009 + // Add the face colour to the mesh data + Quantity_Color face_colour; + + if(!(geom.face_colours.IsNull()) + && (geom.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour))) + { + mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(face_colour.Red(),face_colour.Green(),face_colour.Blue())); + } + else + { + mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(0.0,1.0,0.0)); + } + // ACHTUNG! STIMMT NICHT ALLGEMEIN (RG) + + + Handle(Geom_Surface) occface = BRep_Tool::Surface(face); + + for (TopExp_Explorer exp2 (face, TopAbs_WIRE); exp2.More(); exp2.Next()) + { + TopoDS_Shape wire = exp2.Current(); + + for (TopExp_Explorer exp3 (wire, TopAbs_EDGE); exp3.More(); exp3.Next()) + { + curr++; + (*testout) << "edge nr " << curr << endl; + + multithread.percent = 100 * curr / double (total); + if (multithread.terminate) return; + + TopoDS_Edge edge = TopoDS::Edge (exp3.Current()); + if (BRep_Tool::Degenerated(edge)) + { + //(*testout) << "ignoring degenerated edge" << endl; + continue; + } + + if (geom.vmap.FindIndex(TopExp::FirstVertex (edge)) == + geom.vmap.FindIndex(TopExp::LastVertex (edge))) + { + GProp_GProps system; + BRepGProp::LinearProperties(edge, system); + + if (system.Mass() < eps) + { + cout << "ignoring edge " << geom.emap.FindIndex (edge) + << ". closed edge with length < " << eps << endl; + continue; + } + } + + + Handle(Geom2d_Curve) cof; + double s0, s1; + cof = BRep_Tool::CurveOnSurface (edge, face, s0, s1); + + int geomedgenr = geom.emap.FindIndex(edge); + + Array mp; + Array params; + + DivideEdge (edge, mp, params, mesh); + + Array pnums; + pnums.SetSize (mp.Size()+2); + + if (!merge_solids) + { + pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge)); + pnums[pnums.Size()-1] = geom.vmap.FindIndex (TopExp::LastVertex (edge)); + } + else + { + Point<3> fp = occ2ng (BRep_Tool::Pnt (TopExp::FirstVertex (edge))); + Point<3> lp = occ2ng (BRep_Tool::Pnt (TopExp::LastVertex (edge))); + + pnums[0] = -1; + pnums.Last() = -1; + for (PointIndex pi = 1; pi < first_ep; pi++) + { + if (Dist2 (mesh[pi], fp) < eps*eps) pnums[0] = pi; + if (Dist2 (mesh[pi], lp) < eps*eps) pnums.Last() = pi; + } + } + + + for (int i = 1; i <= mp.Size(); i++) + { + bool exists = 0; + int j; + for (j = first_ep; j <= mesh.GetNP(); j++) + if ((mesh.Point(j)-Point<3>(mp[i-1])).Length() < eps) + { + exists = 1; + break; + } + + if (exists) + pnums[i] = j; + else + { + mesh.AddPoint (mp[i-1]); + (*testout) << "add meshpoint " << mp[i-1] << endl; + pnums[i] = mesh.GetNP(); + } + } + (*testout) << "NP = " << mesh.GetNP() << endl; + + //(*testout) << pnums[pnums.Size()-1] << endl; + + for (int i = 1; i <= mp.Size()+1; i++) + { + edgenr++; + Segment seg; + + seg[0] = pnums[i-1]; + seg[1] = pnums[i]; + seg.edgenr = edgenr; + seg.si = facenr; + seg.epgeominfo[0].dist = params[i-1]; + seg.epgeominfo[1].dist = params[i]; + seg.epgeominfo[0].edgenr = geomedgenr; + seg.epgeominfo[1].edgenr = geomedgenr; + + gp_Pnt2d p2d; + p2d = cof->Value(params[i-1]); + // if (i == 1) p2d = cof->Value(s0); + seg.epgeominfo[0].u = p2d.X(); + seg.epgeominfo[0].v = p2d.Y(); + p2d = cof->Value(params[i]); + // if (i == mp.Size()+1) p2d = cof -> Value(s1); + seg.epgeominfo[1].u = p2d.X(); + seg.epgeominfo[1].v = p2d.Y(); + + /* + if (occface->IsUPeriodic()) + { + cout << "U Periodic" << endl; + if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) > + fabs(seg.epgeominfo[1].u- + (seg.epgeominfo[0].u-occface->UPeriod()))) + seg.epgeominfo[0].u = p2d.X()+occface->UPeriod(); + + if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) > + fabs(seg.epgeominfo[1].u- + (seg.epgeominfo[0].u+occface->UPeriod()))) + seg.epgeominfo[0].u = p2d.X()-occface->UPeriod(); + } + + if (occface->IsVPeriodic()) + { + cout << "V Periodic" << endl; + if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) > + fabs(seg.epgeominfo[1].v- + (seg.epgeominfo[0].v-occface->VPeriod()))) + seg.epgeominfo[0].v = p2d.Y()+occface->VPeriod(); + + if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) > + fabs(seg.epgeominfo[1].v- + (seg.epgeominfo[0].v+occface->VPeriod()))) + seg.epgeominfo[0].v = p2d.Y()-occface->VPeriod(); + } + */ + + if (edge.Orientation() == TopAbs_REVERSED) + { + swap (seg[0], seg[1]); + swap (seg.epgeominfo[0].dist, seg.epgeominfo[1].dist); + swap (seg.epgeominfo[0].u, seg.epgeominfo[1].u); + swap (seg.epgeominfo[0].v, seg.epgeominfo[1].v); + } + + mesh.AddSegment (seg); + + //edgesegments[geomedgenr-1]->Append(mesh.GetNSeg()); + + } + } + } + } + + // for(i=1; i<=mesh.GetNSeg(); i++) + // (*testout) << "edge " << mesh.LineSegment(i).edgenr << " face " << mesh.LineSegment(i).si + // << " p1 " << mesh.LineSegment(i)[0] << " p2 " << mesh.LineSegment(i)[1] << endl; + // exit(10); + + mesh.CalcSurfacesOfNode(); + multithread.task = savetask; + } + + + + + void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend) + { + int i, j, k; + int changed; + + const char * savetask = multithread.task; + multithread.task = "Surface meshing"; + + geom.facemeshstatus = 0; + + int noldp = mesh.GetNP(); + + double starttime = GetTime(); + + Array glob2loc(noldp); + + //int projecttype = PARAMETERSPACE; + + int projecttype = PARAMETERSPACE; + + int notrys = 1; + + int surfmesherror = 0; + + for (k = 1; k <= mesh.GetNFD(); k++) + { + if(1==0 && !geom.fvispar[k-1].IsDrawable()) + { + (*testout) << "ignoring face " << k << endl; + cout << "ignoring face " << k << endl; + continue; + } + + (*testout) << "mesh face " << k << endl; + multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL); + geom.facemeshstatus[k-1] = -1; + + + /* + if (k != 42) + { + cout << "skipped" << endl; + continue; + } + */ + + + FaceDescriptor & fd = mesh.GetFaceDescriptor(k); + + int oldnf = mesh.GetNSE(); + + Box<3> bb = geom.GetBoundingBox(); + + // int projecttype = PLANESPACE; + + Meshing2OCCSurfaces meshing(TopoDS::Face(geom.fmap(k)), bb, projecttype); + + if (meshing.GetProjectionType() == PLANESPACE) + PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (plane space projection)"); + else + PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (parameter space projection)"); + + if (surfmesherror) + cout << "Surface meshing error occured before (in " << surfmesherror << " faces)" << endl; + + // Meshing2OCCSurfaces meshing(f2, bb); + meshing.SetStartTime (starttime); + + //(*testout) << "Face " << k << endl << endl; + + + if (meshing.GetProjectionType() == PLANESPACE) + { + int cntp = 0; + glob2loc = 0; + for (i = 1; i <= mesh.GetNSeg(); i++) + { + Segment & seg = mesh.LineSegment(i); + if (seg.si == k) + { + for (j = 1; j <= 2; j++) + { + int pi = (j == 1) ? seg[0] : seg[1]; + if (!glob2loc.Get(pi)) + { + meshing.AddPoint (mesh.Point(pi), pi); + cntp++; + glob2loc.Elem(pi) = cntp; + } + } + } + } + + for (i = 1; i <= mesh.GetNSeg(); i++) + { + Segment & seg = mesh.LineSegment(i); + if (seg.si == k) + { + PointGeomInfo gi0, gi1; + gi0.trignum = gi1.trignum = k; + gi0.u = seg.epgeominfo[0].u; + gi0.v = seg.epgeominfo[0].v; + gi1.u = seg.epgeominfo[1].u; + gi1.v = seg.epgeominfo[1].v; + + meshing.AddBoundaryElement (glob2loc.Get(seg[0]), glob2loc.Get(seg[1]), gi0, gi1); + //(*testout) << gi0.u << " " << gi0.v << endl; + //(*testout) << gi1.u << " " << gi1.v << endl; + } + } + } + else + { + int cntp = 0; + + for (i = 1; i <= mesh.GetNSeg(); i++) + if (mesh.LineSegment(i).si == k) + cntp+=2; + + + Array< PointGeomInfo > gis; + + gis.SetAllocSize (cntp); + gis.SetSize (0); + + for (i = 1; i <= mesh.GetNSeg(); i++) + { + Segment & seg = mesh.LineSegment(i); + if (seg.si == k) + { + PointGeomInfo gi0, gi1; + gi0.trignum = gi1.trignum = k; + gi0.u = seg.epgeominfo[0].u; + gi0.v = seg.epgeominfo[0].v; + gi1.u = seg.epgeominfo[1].u; + gi1.v = seg.epgeominfo[1].v; + + int locpnum[2] = {0, 0}; + + for (j = 0; j < 2; j++) + { + PointGeomInfo gi = (j == 0) ? gi0 : gi1; + + int l; + for (l = 0; l < gis.Size() && locpnum[j] == 0; l++) + { + double dist = sqr (gis[l].u-gi.u)+sqr(gis[l].v-gi.v); + + if (dist < 1e-10) + locpnum[j] = l+1; + } + + if (locpnum[j] == 0) + { + int pi = (j == 0) ? seg[0] : seg[1]; + meshing.AddPoint (mesh.Point(pi), pi); + + gis.SetSize (gis.Size()+1); + gis[l] = gi; + locpnum[j] = l+1; + } + } + + meshing.AddBoundaryElement (locpnum[0], locpnum[1], gi0, gi1); + //(*testout) << gi0.u << " " << gi0.v << endl; + //(*testout) << gi1.u << " " << gi1.v << endl; + + } + } + } + + + + + + // Philippose - 15/01/2009 + double maxh = geom.face_maxh[k-1]; + //double maxh = mparam.maxh; + mparam.checkoverlap = 0; + // int noldpoints = mesh->GetNP(); + int noldsurfel = mesh.GetNSE(); + + GProp_GProps sprops; + BRepGProp::SurfaceProperties(TopoDS::Face(geom.fmap(k)),sprops); + meshing.SetMaxArea(2.*sprops.Mass()); + + MESHING2_RESULT res; + + try { + res = meshing.GenerateMesh (mesh, mparam, maxh, k); + } + + catch (SingularMatrixException) + { + (*myerr) << "Singular Matrix" << endl; + res = MESHING2_GIVEUP; + } + + catch (UVBoundsException) + { + (*myerr) << "UV bounds exceeded" << endl; + res = MESHING2_GIVEUP; + } + + projecttype = PARAMETERSPACE; + + if (res != MESHING2_OK) + { + if (notrys == 1) + { + for (int i = noldsurfel+1; i <= mesh.GetNSE(); i++) + mesh.DeleteSurfaceElement (i); + + mesh.Compress(); + + cout << "retry Surface " << k << endl; + + k--; + projecttype*=-1; + notrys++; + continue; + } + else + { + geom.facemeshstatus[k-1] = -1; + PrintError ("Problem in Surface mesh generation"); + surfmesherror++; + // throw NgException ("Problem in Surface mesh generation"); + } + } + else + { + geom.facemeshstatus[k-1] = 1; + } + + notrys = 1; + + for (i = oldnf+1; i <= mesh.GetNSE(); i++) + mesh.SurfaceElement(i).SetIndex (k); + + } + +// ofstream problemfile("occmesh.rep"); + +// problemfile << "SURFACEMESHING" << endl << endl; + + if (surfmesherror) + { + cout << "WARNING! NOT ALL FACES HAVE BEEN MESHED" << endl; + cout << "SURFACE MESHING ERROR OCCURED IN " << surfmesherror << " FACES:" << endl; + for (int i = 1; i <= geom.fmap.Extent(); i++) + if (geom.facemeshstatus[i-1] == -1) + { + cout << "Face " << i << endl; +// problemfile << "problem with face " << i << endl; +// problemfile << "vertices: " << endl; + TopExp_Explorer exp0,exp1,exp2; + for ( exp0.Init(TopoDS::Face (geom.fmap(i)), TopAbs_WIRE); exp0.More(); exp0.Next() ) + { + TopoDS_Wire wire = TopoDS::Wire(exp0.Current()); + for ( exp1.Init(wire,TopAbs_EDGE); exp1.More(); exp1.Next() ) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + for ( exp2.Init(edge,TopAbs_VERTEX); exp2.More(); exp2.Next() ) + { + TopoDS_Vertex vertex = TopoDS::Vertex(exp2.Current()); + gp_Pnt point = BRep_Tool::Pnt(vertex); +// problemfile << point.X() << " " << point.Y() << " " << point.Z() << endl; + } + } + } +// problemfile << endl; + + } + cout << endl << endl; + cout << "for more information open IGES/STEP Topology Explorer" << endl; +// problemfile.close(); + throw NgException ("Problem in Surface mesh generation"); + } + else + { +// problemfile << "OK" << endl << endl; +// problemfile.close(); + } + + + + + if (multithread.terminate || perfstepsend < MESHCONST_OPTSURFACE) + return; + + multithread.task = "Optimizing surface"; + + static int timer_opt2d = NgProfiler::CreateTimer ("Optimization 2D"); + NgProfiler::StartTimer (timer_opt2d); + + for (k = 1; k <= mesh.GetNFD(); k++) + { + // if (k != 42) continue; + // if (k != 36) continue; + + // (*testout) << "optimize face " << k << endl; + multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL); + + FaceDescriptor & fd = mesh.GetFaceDescriptor(k); + + PrintMessage (1, "Optimize Surface ", k); + for (i = 1; i <= mparam.optsteps2d; i++) + { + // (*testout) << "optstep " << i << endl; + if (multithread.terminate) return; + + { + MeshOptimize2dOCCSurfaces meshopt(geom); + meshopt.SetFaceIndex (k); + meshopt.SetImproveEdges (0); + meshopt.SetMetricWeight (mparam.elsizeweight); + //meshopt.SetMetricWeight (0.2); + meshopt.SetWriteStatus (0); + + // (*testout) << "EdgeSwapping (mesh, (i > mparam.optsteps2d/2))" << endl; + meshopt.EdgeSwapping (mesh, (i > mparam.optsteps2d/2)); + } + + if (multithread.terminate) return; + { + MeshOptimize2dOCCSurfaces meshopt(geom); + meshopt.SetFaceIndex (k); + meshopt.SetImproveEdges (0); + //meshopt.SetMetricWeight (0.2); + meshopt.SetMetricWeight (mparam.elsizeweight); + meshopt.SetWriteStatus (0); + + // (*testout) << "ImproveMesh (mesh)" << endl; + meshopt.ImproveMesh (mesh, mparam); + } + + { + MeshOptimize2dOCCSurfaces meshopt(geom); + meshopt.SetFaceIndex (k); + meshopt.SetImproveEdges (0); + //meshopt.SetMetricWeight (0.2); + meshopt.SetMetricWeight (mparam.elsizeweight); + meshopt.SetWriteStatus (0); + + // (*testout) << "CombineImprove (mesh)" << endl; + meshopt.CombineImprove (mesh); + } + + if (multithread.terminate) return; + { + MeshOptimize2dOCCSurfaces meshopt(geom); + meshopt.SetFaceIndex (k); + meshopt.SetImproveEdges (0); + //meshopt.SetMetricWeight (0.2); + meshopt.SetMetricWeight (mparam.elsizeweight); + meshopt.SetWriteStatus (0); + + // (*testout) << "ImproveMesh (mesh)" << endl; + meshopt.ImproveMesh (mesh, mparam); + } + } + + } + + + mesh.CalcSurfacesOfNode(); + mesh.Compress(); + + NgProfiler::StopTimer (timer_opt2d); + + multithread.task = savetask; + } + + + + void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh) + { + mesh.SetGlobalH (mparam.maxh); + mesh.SetMinimalH (mparam.minh); + + Array maxhdom; + maxhdom.SetSize (geom.NrSolids()); + maxhdom = mparam.maxh; + + mesh.SetMaxHDomain (maxhdom); + + Box<3> bb = geom.GetBoundingBox(); + bb.Increase (bb.Diam()/10); + + mesh.SetLocalH (bb.PMin(), bb.PMax(), 0.5); + + if (mparam.uselocalh) + { + const char * savetask = multithread.task; + multithread.percent = 0; + + mesh.SetLocalH (bb.PMin(), bb.PMax(), mparam.grading); + + int nedges = geom.emap.Extent(); + + double mincurvelength = IGNORECURVELENGTH; + double maxedgelen = 0; + double minedgelen = 1e99; + + if(occparam.resthminedgelenenable) + { + mincurvelength = occparam.resthminedgelen; + if(mincurvelength < IGNORECURVELENGTH) mincurvelength = IGNORECURVELENGTH; + } + + multithread.task = "Setting local mesh size (elements per edge)"; + + // setting elements per edge + + for (int i = 1; i <= nedges && !multithread.terminate; i++) + { + TopoDS_Edge e = TopoDS::Edge (geom.emap(i)); + multithread.percent = 100 * (i-1)/double(nedges); + if (BRep_Tool::Degenerated(e)) continue; + + GProp_GProps system; + BRepGProp::LinearProperties(e, system); + double len = system.Mass(); + + if (len < mincurvelength) + { + (*testout) << "ignored" << endl; + continue; + } + + double localh = len/mparam.segmentsperedge; + double s0, s1; + + // Philippose - 23/01/2009 + // Find all the parent faces of a given edge + // and limit the mesh size of the edge based on the + // mesh size limit of the face + TopTools_IndexedDataMapOfShapeListOfShape edge_face_map; + edge_face_map.Clear(); + + TopExp::MapShapesAndAncestors(geom.shape, TopAbs_EDGE, TopAbs_FACE, edge_face_map); + const TopTools_ListOfShape& parent_faces = edge_face_map.FindFromKey(e); + + TopTools_ListIteratorOfListOfShape parent_face_list; + + for(parent_face_list.Initialize(parent_faces); parent_face_list.More(); parent_face_list.Next()) + { + TopoDS_Face parent_face = TopoDS::Face(parent_face_list.Value()); + + int face_index = geom.fmap.FindIndex(parent_face); + + if(face_index >= 1) localh = min(localh,geom.face_maxh[face_index - 1]); + } + + Handle(Geom_Curve) c = BRep_Tool::Curve(e, s0, s1); + + maxedgelen = max (maxedgelen, len); + minedgelen = min (minedgelen, len); + + // Philippose - 23/01/2009 + // Modified the calculation of maxj, because the + // method used so far always results in maxj = 2, + // which causes the localh to be set only at the + // starting, mid and end of the edge. + // Old Algorithm: + // int maxj = 2 * (int) ceil (localh/len); + int maxj = max((int) ceil(len/localh), 2); + + for (int j = 0; j <= maxj; j++) + { + gp_Pnt pnt = c->Value (s0+double(j)/maxj*(s1-s0)); + mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), localh); + } + } + + multithread.task = "Setting local mesh size (edge curvature)"; + + // setting edge curvature + + int nsections = 20; + + for (int i = 1; i <= nedges && !multithread.terminate; i++) + { + double maxcur = 0; + multithread.percent = 100 * (i-1)/double(nedges); + TopoDS_Edge edge = TopoDS::Edge (geom.emap(i)); + if (BRep_Tool::Degenerated(edge)) continue; + double s0, s1; + Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1); + BRepAdaptor_Curve brepc(edge); + BRepLProp_CLProps prop(brepc, 2, 1e-5); + + for (int j = 1; j <= nsections; j++) + { + double s = s0 + j/(double) nsections * (s1-s0); + prop.SetParameter (s); + double curvature = prop.Curvature(); + if(curvature> maxcur) maxcur = curvature; + + if (curvature >= 1e99) + continue; + + gp_Pnt pnt = c->Value (s); + + mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), ComputeH (fabs(curvature))); + } + // (*testout) << "edge " << i << " max. curvature: " << maxcur << endl; + } + + multithread.task = "Setting local mesh size (face curvature)"; + + // setting face curvature + + int nfaces = geom.fmap.Extent(); + + for (int i = 1; i <= nfaces && !multithread.terminate; i++) + { + multithread.percent = 100 * (i-1)/double(nfaces); + TopoDS_Face face = TopoDS::Face(geom.fmap(i)); + TopLoc_Location loc; + Handle(Geom_Surface) surf = BRep_Tool::Surface (face); + Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc); + + if (triangulation.IsNull()) continue; + + BRepAdaptor_Surface sf(face, Standard_True); + BRepLProp_SLProps prop(sf, 2, 1e-5); + + int ntriangles = triangulation -> NbTriangles(); + for (int j = 1; j <= ntriangles; j++) + { + gp_Pnt p[3]; + gp_Pnt2d par[3]; + + for (int k = 1; k <=3; k++) + { + int n = triangulation->Triangles()(j)(k); + p[k-1] = triangulation->Nodes()(n).Transformed(loc); + par[k-1] = triangulation->UVNodes()(n); + } + + //double maxside = 0; + //maxside = max (maxside, p[0].Distance(p[1])); + //maxside = max (maxside, p[0].Distance(p[2])); + //maxside = max (maxside, p[1].Distance(p[2])); + //cout << "\rFace " << i << " pos11 ntriangles " << ntriangles << " maxside " << maxside << flush; + + RestrictHTriangle (par[0], par[1], par[2], &prop, mesh, 0); + //cout << "\rFace " << i << " pos12 ntriangles " << ntriangles << flush; + } + } + + // setting close edges + + if (occparam.resthcloseedgeenable) + { + multithread.task = "Setting local mesh size (close edges)"; + + int sections = 100; + + Array lines(sections*nedges); + + Box3dTree* searchtree = + new Box3dTree (bb.PMin(), bb.PMax()); + + int nlines = 0; + for (int i = 1; i <= nedges && !multithread.terminate; i++) + { + TopoDS_Edge edge = TopoDS::Edge (geom.emap(i)); + if (BRep_Tool::Degenerated(edge)) continue; + + double s0, s1; + Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1); + BRepAdaptor_Curve brepc(edge); + BRepLProp_CLProps prop(brepc, 1, 1e-5); + prop.SetParameter (s0); + + gp_Vec d0 = prop.D1().Normalized(); + double s_start = s0; + int count = 0; + for (int j = 1; j <= sections; j++) + { + double s = s0 + (s1-s0)*(double)j/(double)sections; + prop.SetParameter (s); + gp_Vec d1 = prop.D1().Normalized(); + double cosalpha = fabs(d0*d1); + if ((j == sections) || (cosalpha < cos(10.0/180.0*M_PI))) + { + count++; + gp_Pnt p0 = c->Value (s_start); + gp_Pnt p1 = c->Value (s); + lines[nlines].p0 = Point<3> (p0.X(), p0.Y(), p0.Z()); + lines[nlines].p1 = Point<3> (p1.X(), p1.Y(), p1.Z()); + + Box3d box; + box.SetPoint (Point3d(lines[nlines].p0)); + box.AddPoint (Point3d(lines[nlines].p1)); + + searchtree->Insert (box.PMin(), box.PMax(), nlines+1); + nlines++; + + s_start = s; + d0 = d1; + } + } + } + + Array linenums; + + for (int i = 0; i < nlines; i++) + { + multithread.percent = (100*i)/double(nlines); + Line & line = lines[i]; + + Box3d box; + box.SetPoint (Point3d(line.p0)); + box.AddPoint (Point3d(line.p1)); + double maxhline = max (mesh.GetH(box.PMin()), + mesh.GetH(box.PMax())); + box.Increase(maxhline); + + double mindist = 1e99; + linenums.SetSize(0); + searchtree->GetIntersecting(box.PMin(),box.PMax(),linenums); + + for (int j = 0; j < linenums.Size(); j++) + { + int num = linenums[j]-1; + if (i == num) continue; + if ((line.p0-lines[num].p0).Length2() < 1e-15) continue; + if ((line.p0-lines[num].p1).Length2() < 1e-15) continue; + if ((line.p1-lines[num].p0).Length2() < 1e-15) continue; + if ((line.p1-lines[num].p1).Length2() < 1e-15) continue; + mindist = min (mindist, line.Dist(lines[num])); + } + + mindist /= (occparam.resthcloseedgefac + VSMALL); + + if (mindist < 1e-3) + { + (*testout) << "extremely small local h: " << mindist + << " --> setting to 1e-3" << endl; + (*testout) << "somewhere near " << line.p0 << " - " << line.p1 << endl; + mindist = 1e-3; + } + + mesh.RestrictLocalHLine(line.p0, line.p1, mindist); + } + } + + multithread.task = savetask; + + } + + // Philippose - 09/03/2009 + // Added the capability to load the mesh size from a + // file also for OpenCascade Geometry + // Note: + // ** If the "uselocalh" option is ticked in + // the "mesh options...insider" menu, the mesh + // size will be further modified by the topology + // analysis routines. + // ** To use the mesh size file as the sole source + // for defining the mesh size, uncheck the "uselocalh" + // option. + mesh.LoadLocalMeshSize (mparam.meshsizefilename); + } + + + + int OCCGenerateMesh (OCCGeometry & geom, Mesh *& mesh, MeshingParameters & mparam, + int perfstepsstart, int perfstepsend) + { + multithread.percent = 0; + + if (perfstepsstart <= MESHCONST_ANALYSE) + { + delete mesh; + mesh = new Mesh(); + mesh->geomtype = Mesh::GEOM_OCC; + + OCCSetLocalMeshSize(geom,*mesh); + } + + if (multithread.terminate || perfstepsend <= MESHCONST_ANALYSE) + return TCL_OK; + + if (perfstepsstart <= MESHCONST_MESHEDGES) + { + OCCFindEdges (geom, *mesh); + + /* + cout << "Removing redundant points" << endl; + + int i, j; + int np = mesh->GetNP(); + Array equalto; + + equalto.SetSize (np); + equalto = 0; + + for (i = 1; i <= np; i++) + { + for (j = i+1; j <= np; j++) + { + if (!equalto[j-1] && (Dist2 (mesh->Point(i), mesh->Point(j)) < 1e-12)) + equalto[j-1] = i; + } + } + + for (i = 1; i <= np; i++) + if (equalto[i-1]) + { + cout << "Point " << i << " is equal to Point " << equalto[i-1] << endl; + for (j = 1; j <= mesh->GetNSeg(); j++) + { + Segment & seg = mesh->LineSegment(j); + if (seg[0] == i) seg[0] = equalto[i-1]; + if (seg[1] == i) seg[1] = equalto[i-1]; + } + } + + cout << "Removing degenerated segments" << endl; + for (j = 1; j <= mesh->GetNSeg(); j++) + { + Segment & seg = mesh->LineSegment(j); + if (seg[0] == seg[1]) + { + mesh->DeleteSegment(j); + cout << "Deleting Segment " << j << endl; + } + } + + mesh->Compress(); + */ + + /* + for (int i = 1; i <= geom.fmap.Extent(); i++) + { + Handle(Geom_Surface) hf1 = + BRep_Tool::Surface(TopoDS::Face(geom.fmap(i))); + for (int j = i+1; j <= geom.fmap.Extent(); j++) + { + Handle(Geom_Surface) hf2 = + BRep_Tool::Surface(TopoDS::Face(geom.fmap(j))); + if (hf1 == hf2) cout << "face " << i << " and face " << j << " lie on same surface" << endl; + } + } + */ + +#ifdef LOG_STREAM + (*logout) << "Edges meshed" << endl + << "time = " << GetTime() << " sec" << endl + << "points: " << mesh->GetNP() << endl; +#endif + } + + if (multithread.terminate || perfstepsend <= MESHCONST_MESHEDGES) + return TCL_OK; + + if (perfstepsstart <= MESHCONST_MESHSURFACE) + { + OCCMeshSurface (geom, *mesh, perfstepsend); + if (multithread.terminate) return TCL_OK; + +#ifdef LOG_STREAM + (*logout) << "Surfaces meshed" << endl + << "time = " << GetTime() << " sec" << endl + << "points: " << mesh->GetNP() << endl; +#endif + +#ifdef STAT_STREAM + (*statout) << mesh->GetNSeg() << " & " + << mesh->GetNSE() << " & - &" + << GetTime() << " & " << endl; +#endif + + // MeshQuality2d (*mesh); + mesh->CalcSurfacesOfNode(); + } + + if (multithread.terminate || perfstepsend <= MESHCONST_OPTSURFACE) + return TCL_OK; + + if (perfstepsstart <= MESHCONST_MESHVOLUME) + { + multithread.task = "Volume meshing"; + + MESHING3_RESULT res = MeshVolume (mparam, *mesh); + +/* + ofstream problemfile("occmesh.rep",ios_base::app); + + problemfile << "VOLUMEMESHING" << endl << endl; + if(res != MESHING3_OK) + problemfile << "ERROR" << endl << endl; + else + problemfile << "OK" << endl + << mesh->GetNE() << " elements" << endl << endl; + + problemfile.close(); +*/ + + if (res != MESHING3_OK) return TCL_ERROR; + + if (multithread.terminate) return TCL_OK; + + RemoveIllegalElements (*mesh); + if (multithread.terminate) return TCL_OK; + + MeshQuality3d (*mesh); + +#ifdef STAT_STREAM + (*statout) << GetTime() << " & "; +#endif + +#ifdef LOG_STREAM + (*logout) << "Volume meshed" << endl + << "time = " << GetTime() << " sec" << endl + << "points: " << mesh->GetNP() << endl; +#endif + } + + if (multithread.terminate || perfstepsend <= MESHCONST_MESHVOLUME) + return TCL_OK; + + if (perfstepsstart <= MESHCONST_OPTVOLUME) + { + multithread.task = "Volume optimization"; + + OptimizeVolume (mparam, *mesh); + if (multithread.terminate) return TCL_OK; + +#ifdef STAT_STREAM + (*statout) << GetTime() << " & " + << mesh->GetNE() << " & " + << mesh->GetNP() << " " << '\\' << '\\' << " \\" << "hline" << endl; +#endif + +#ifdef LOG_STREAM + (*logout) << "Volume optimized" << endl + << "time = " << GetTime() << " sec" << endl + << "points: " << mesh->GetNP() << endl; +#endif + + // cout << "Optimization complete" << endl; + + } + + (*testout) << "NP: " << mesh->GetNP() << endl; + for (int i = 1; i <= mesh->GetNP(); i++) + (*testout) << mesh->Point(i) << endl; + + (*testout) << endl << "NSegments: " << mesh->GetNSeg() << endl; + for (int i = 1; i <= mesh->GetNSeg(); i++) + (*testout) << mesh->LineSegment(i) << endl; + + return TCL_OK; + } +} + +#endif diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index a363607b..c1a5827a 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -1,1608 +1,1612 @@ - -#ifdef OCCGEOMETRY - -#include -#include -#include "ShapeAnalysis_ShapeTolerance.hxx" -#include "ShapeAnalysis_ShapeContents.hxx" -#include "ShapeAnalysis_CheckSmallFace.hxx" -#include "ShapeAnalysis_DataMapOfShapeListOfReal.hxx" -#include "ShapeAnalysis_Surface.hxx" -#include "BRepAlgoAPI_Fuse.hxx" -#include "BRepCheck_Analyzer.hxx" -#include "BRepLib.hxx" -#include "ShapeBuild_ReShape.hxx" -#include "ShapeFix.hxx" -#include "ShapeFix_FixSmallFace.hxx" -#include "Partition_Spliter.hxx" - - -namespace netgen -{ - void OCCGeometry :: PrintNrShapes () - { - TopExp_Explorer e; - int count = 0; - for (e.Init(shape, TopAbs_COMPSOLID); e.More(); e.Next()) count++; - cout << "CompSolids: " << count << endl; - - cout << "Solids : " << somap.Extent() << endl; - cout << "Shells : " << shmap.Extent() << endl; - cout << "Faces : " << fmap.Extent() << endl; - cout << "Edges : " << emap.Extent() << endl; - cout << "Vertices : " << vmap.Extent() << endl; - } - - - - - void PrintContents (OCCGeometry * geom) - { - ShapeAnalysis_ShapeContents cont; - cont.Clear(); - cont.Perform(geom->shape); - - (*testout) << "OCC CONTENTS" << endl; - (*testout) << "============" << endl; - (*testout) << "SOLIDS : " << cont.NbSolids() << endl; - (*testout) << "SHELLS : " << cont.NbShells() << endl; - (*testout) << "FACES : " << cont.NbFaces() << endl; - (*testout) << "WIRES : " << cont.NbWires() << endl; - (*testout) << "EDGES : " << cont.NbEdges() << endl; - (*testout) << "VERTICES : " << cont.NbVertices() << endl; - - TopExp_Explorer e; - int count = 0; - for (e.Init(geom->shape, TopAbs_COMPOUND); e.More(); e.Next()) - count++; - (*testout) << "Compounds: " << count << endl; - - count = 0; - for (e.Init(geom->shape, TopAbs_COMPSOLID); e.More(); e.Next()) - count++; - (*testout) << "CompSolids: " << count << endl; - - (*testout) << endl; - - cout << "Highest entry in topology hierarchy: " << endl; - if (count) - cout << count << " composite solid(s)" << endl; - else - if (geom->somap.Extent()) - cout << geom->somap.Extent() << " solid(s)" << endl; - else - if (geom->shmap.Extent()) - cout << geom->shmap.Extent() << " shells(s)" << endl; - else - if (geom->fmap.Extent()) - cout << geom->fmap.Extent() << " face(s)" << endl; - else - if (geom->wmap.Extent()) - cout << geom->wmap.Extent() << " wire(s)" << endl; - else - if (geom->emap.Extent()) - cout << geom->emap.Extent() << " edge(s)" << endl; - else - if (geom->vmap.Extent()) - cout << geom->vmap.Extent() << " vertices(s)" << endl; - else - cout << "no entities" << endl; - - } - - - - void OCCGeometry :: HealGeometry () - { - int nrc = 0, nrcs = 0, - nrso = somap.Extent(), - nrsh = shmap.Extent(), - nrf = fmap.Extent(), - nrw = wmap.Extent(), - nre = emap.Extent(), - nrv = vmap.Extent(); - - TopExp_Explorer exp0; - TopExp_Explorer exp1; - - - for (exp0.Init(shape, TopAbs_COMPOUND); exp0.More(); exp0.Next()) nrc++; - for (exp0.Init(shape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nrcs++; - - double surfacecont = 0; - - { - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - rebuild->Apply(shape); - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if ( BRep_Tool::Degenerated(edge) ) - rebuild->Remove(edge, false); - } - shape = rebuild->Apply(shape); - } - - BuildFMap(); - - - for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) - { - TopoDS_Face face = TopoDS::Face(exp0.Current()); - - GProp_GProps system; - BRepGProp::SurfaceProperties(face, system); - surfacecont += system.Mass(); - } - - - cout << "Starting geometry healing procedure (tolerance: " << tolerance << ")" << endl - << "-----------------------------------" << endl; - - { - cout << endl << "- repairing faces" << endl; - - Handle(ShapeFix_Face) sff; - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - rebuild->Apply(shape); - - - for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) - { - // Variable to hold the colour (if there exists one) of - // the current face being processed - Quantity_Color face_colour; - - TopoDS_Face face = TopoDS::Face (exp0.Current()); - - if(face_colours.IsNull() - || (!(face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour)))) - { - // Set the default face colour to green (Netgen Standard) - // if no colour has been defined for the face - face_colour = Quantity_Color(0.0,1.0,0.0,Quantity_TOC_RGB); - } - - sff = new ShapeFix_Face (face); - sff->FixAddNaturalBoundMode() = Standard_True; - sff->FixSmallAreaWireMode() = Standard_True; - sff->Perform(); - - if(sff->Status(ShapeExtend_DONE1) || - sff->Status(ShapeExtend_DONE2) || - sff->Status(ShapeExtend_DONE3) || - sff->Status(ShapeExtend_DONE4) || - sff->Status(ShapeExtend_DONE5)) - { - cout << "repaired face " << fmap.FindIndex(face) << " "; - if(sff->Status(ShapeExtend_DONE1)) - cout << "(some wires are fixed)" <Status(ShapeExtend_DONE2)) - cout << "(orientation of wires fixed)" <Status(ShapeExtend_DONE3)) - cout << "(missing seam added)" <Status(ShapeExtend_DONE4)) - cout << "(small area wire removed)" <Status(ShapeExtend_DONE5)) - cout << "(natural bounds added)" <Face(); - - rebuild->Replace(face, newface, Standard_False); - } - - // Set the original colour of the face to the newly created - // face (after the healing process) - face = TopoDS::Face (exp0.Current()); - face_colours->SetColor(face,face_colour,XCAFDoc_ColorSurf); - } - shape = rebuild->Apply(shape); - } - - - { - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - rebuild->Apply(shape); - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if ( BRep_Tool::Degenerated(edge) ) - rebuild->Remove(edge, false); - } - shape = rebuild->Apply(shape); - } - - - if (fixsmalledges) - { - cout << endl << "- fixing small edges" << endl; - - Handle(ShapeFix_Wire) sfw; - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - rebuild->Apply(shape); - - - for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) - { - TopoDS_Face face = TopoDS::Face(exp0.Current()); - - for (exp1.Init (face, TopAbs_WIRE); exp1.More(); exp1.Next()) - { - TopoDS_Wire oldwire = TopoDS::Wire(exp1.Current()); - sfw = new ShapeFix_Wire (oldwire, face ,tolerance); - sfw->ModifyTopologyMode() = Standard_True; - - sfw->ClosedWireMode() = Standard_True; - - bool replace = false; - - replace = sfw->FixReorder() || replace; - - replace = sfw->FixConnected() || replace; - - - - if (sfw->FixSmall (Standard_False, tolerance) && ! (sfw->StatusSmall(ShapeExtend_FAIL1) || - sfw->StatusSmall(ShapeExtend_FAIL2) || - sfw->StatusSmall(ShapeExtend_FAIL3))) - { - cout << "Fixed small edge in wire " << wmap.FindIndex (oldwire) << endl; - replace = true; - - } - else if (sfw->StatusSmall(ShapeExtend_FAIL1)) - cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire) - << ", edge cannot be checked (no 3d curve and no pcurve)" << endl; - else if (sfw->StatusSmall(ShapeExtend_FAIL2)) - cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire) - << ", edge is null-length and has different vertives at begin and end, and lockvtx is True or ModifiyTopologyMode is False" << endl; - else if (sfw->StatusSmall(ShapeExtend_FAIL3)) - cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire) - << ", CheckConnected has failed" << endl; - - replace = sfw->FixEdgeCurves() || replace; - - replace = sfw->FixDegenerated() || replace; - - replace = sfw->FixSelfIntersection() || replace; - - replace = sfw->FixLacking(Standard_True) || replace; - - if(replace) - { - TopoDS_Wire newwire = sfw->Wire(); - rebuild->Replace(oldwire, newwire, Standard_False); - } - - //delete sfw; sfw = NULL; - - } - } - - shape = rebuild->Apply(shape); - - - - { - BuildFMap(); - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - rebuild->Apply(shape); - - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if (vmap.FindIndex(TopExp::FirstVertex (edge)) == - vmap.FindIndex(TopExp::LastVertex (edge))) - { - GProp_GProps system; - BRepGProp::LinearProperties(edge, system); - if (system.Mass() < tolerance) - { - cout << "removing degenerated edge " << emap.FindIndex(edge) - << " from vertex " << vmap.FindIndex(TopExp::FirstVertex (edge)) - << " to vertex " << vmap.FindIndex(TopExp::LastVertex (edge)) << endl; - rebuild->Remove(edge, false); - } - } - } - shape = rebuild->Apply(shape); - - //delete rebuild; rebuild = NULL; - } - - - - { - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - rebuild->Apply(shape); - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if ( BRep_Tool::Degenerated(edge) ) - rebuild->Remove(edge, false); - } - shape = rebuild->Apply(shape); - } - - - - - Handle(ShapeFix_Wireframe) sfwf = new ShapeFix_Wireframe; - sfwf->SetPrecision(tolerance); - sfwf->Load (shape); - sfwf->ModeDropSmallEdges() = Standard_True; - - sfwf->SetPrecision(boundingbox.Diam()); - - if (sfwf->FixWireGaps()) - { - cout << endl << "- fixing wire gaps" << endl; - if (sfwf->StatusWireGaps(ShapeExtend_OK)) cout << "no gaps found" << endl; - if (sfwf->StatusWireGaps(ShapeExtend_DONE1)) cout << "some 2D gaps fixed" << endl; - if (sfwf->StatusWireGaps(ShapeExtend_DONE2)) cout << "some 3D gaps fixed" << endl; - if (sfwf->StatusWireGaps(ShapeExtend_FAIL1)) cout << "failed to fix some 2D gaps" << endl; - if (sfwf->StatusWireGaps(ShapeExtend_FAIL2)) cout << "failed to fix some 3D gaps" << endl; - } - - sfwf->SetPrecision(tolerance); - - - { - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if ( BRep_Tool::Degenerated(edge) ) - cout << "degenerated edge at position 4" << endl; - } - } - - - - if (sfwf->FixSmallEdges()) - { - cout << endl << "- fixing wire frames" << endl; - if (sfwf->StatusSmallEdges(ShapeExtend_OK)) cout << "no small edges found" << endl; - if (sfwf->StatusSmallEdges(ShapeExtend_DONE1)) cout << "some small edges fixed" << endl; - if (sfwf->StatusSmallEdges(ShapeExtend_FAIL1)) cout << "failed to fix some small edges" << endl; - } - - - - shape = sfwf->Shape(); - - //delete sfwf; sfwf = NULL; - //delete rebuild; rebuild = NULL; - - } - - - - - - { - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if ( BRep_Tool::Degenerated(edge) ) - cout << "degenerated edge at position 5" << endl; - } - } - - - - - if (fixspotstripfaces) - { - - cout << endl << "- fixing spot and strip faces" << endl; - Handle(ShapeFix_FixSmallFace) sffsm = new ShapeFix_FixSmallFace(); - sffsm -> Init (shape); - sffsm -> SetPrecision (tolerance); - sffsm -> Perform(); - - shape = sffsm -> FixShape(); - //delete sffsm; sffsm = NULL; - } - - - { - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if ( BRep_Tool::Degenerated(edge) ) - cout << "degenerated edge at position 6" << endl; - } - } - - - - if (sewfaces) - { - cout << endl << "- sewing faces" << endl; - - BRepOffsetAPI_Sewing sewedObj(tolerance); - - for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) - { - TopoDS_Face face = TopoDS::Face (exp0.Current()); - sewedObj.Add (face); - } - - sewedObj.Perform(); - - if (!sewedObj.SewedShape().IsNull()) - shape = sewedObj.SewedShape(); - else - cout << " not possible"; - } - - - - { - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - rebuild->Apply(shape); - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if ( BRep_Tool::Degenerated(edge) ) - rebuild->Remove(edge, false); - } - shape = rebuild->Apply(shape); - } - - - if (makesolids) - { - cout << endl << "- making solids" << endl; - - BRepBuilderAPI_MakeSolid ms; - int count = 0; - for (exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next()) - { - count++; - ms.Add (TopoDS::Shell(exp0.Current())); - } - - if (!count) - { - cout << " not possible (no shells)" << endl; - } - else - { - BRepCheck_Analyzer ba(ms); - if (ba.IsValid ()) - { - Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; - sfs->Init (ms); - sfs->SetPrecision(tolerance); - sfs->SetMaxTolerance(tolerance); - sfs->Perform(); - shape = sfs->Shape(); - - for (exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next()) - { - TopoDS_Solid solid = TopoDS::Solid(exp0.Current()); - TopoDS_Solid newsolid = solid; - BRepLib::OrientClosedSolid (newsolid); - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - // rebuild->Apply(shape); - rebuild->Replace(solid, newsolid, Standard_False); - TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_COMPSOLID);//, 1); - // TopoDS_Shape newshape = rebuild->Apply(shape); - shape = newshape; - } - - //delete sfs; sfs = NULL; - } - else - cout << " not possible" << endl; - } - } - - - - if (splitpartitions) - { - cout << "- running SALOME partition splitter" << endl; - - TopExp_Explorer e2; - Partition_Spliter ps; - int count = 0; - - for (e2.Init (shape, TopAbs_SOLID); - e2.More(); e2.Next()) - { - count++; - ps.AddShape (e2.Current()); - } - - ps.Compute(); - shape = ps.Shape(); - - cout << " before: " << count << " solids" << endl; - - count = 0; - for (e2.Init (shape, TopAbs_SOLID); - e2.More(); e2.Next()) count++; - - cout << " after : " << count << " solids" << endl; - } - - BuildFMap(); - - - - { - for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if ( BRep_Tool::Degenerated(edge) ) - cout << "degenerated edge at position 8" << endl; - } - } - - - double newsurfacecont = 0; - - - for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) - { - TopoDS_Face face = TopoDS::Face(exp0.Current()); - GProp_GProps system; - BRepGProp::SurfaceProperties(face, system); - newsurfacecont += system.Mass(); - } - - - int nnrc = 0, nnrcs = 0, - nnrso = somap.Extent(), - nnrsh = shmap.Extent(), - nnrf = fmap.Extent(), - nnrw = wmap.Extent(), - nnre = emap.Extent(), - nnrv = vmap.Extent(); - - for (exp0.Init(shape, TopAbs_COMPOUND); exp0.More(); exp0.Next()) nnrc++; - for (exp0.Init(shape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nnrcs++; - - cout << "-----------------------------------" << endl; - cout << "Compounds : " << nnrc << " (" << nrc << ")" << endl; - cout << "Composite solids: " << nnrcs << " (" << nrcs << ")" << endl; - cout << "Solids : " << nnrso << " (" << nrso << ")" << endl; - cout << "Shells : " << nnrsh << " (" << nrsh << ")" << endl; - cout << "Wires : " << nnrw << " (" << nrw << ")" << endl; - cout << "Faces : " << nnrf << " (" << nrf << ")" << endl; - cout << "Edges : " << nnre << " (" << nre << ")" << endl; - cout << "Vertices : " << nnrv << " (" << nrv << ")" << endl; - cout << endl; - cout << "Totol surface area : " << newsurfacecont << " (" << surfacecont << ")" << endl; - cout << endl; - } - - - - - void OCCGeometry :: BuildFMap() - { - somap.Clear(); - shmap.Clear(); - fmap.Clear(); - wmap.Clear(); - emap.Clear(); - vmap.Clear(); - - TopExp_Explorer exp0, exp1, exp2, exp3, exp4, exp5; - - for (exp0.Init(shape, TopAbs_COMPOUND); - exp0.More(); exp0.Next()) - { - TopoDS_Compound compound = TopoDS::Compound (exp0.Current()); - (*testout) << "compound" << endl; - int i = 0; - for (exp1.Init(compound, TopAbs_SHELL); - exp1.More(); exp1.Next()) - { - (*testout) << "shell " << ++i << endl; - } - } - - for (exp0.Init(shape, TopAbs_SOLID); - exp0.More(); exp0.Next()) - { - TopoDS_Solid solid = TopoDS::Solid (exp0.Current()); - - if (somap.FindIndex(solid) < 1) - { - somap.Add (solid); - - for (exp1.Init(solid, TopAbs_SHELL); - exp1.More(); exp1.Next()) - { - TopoDS_Shell shell = TopoDS::Shell (exp1.Current()); - if (shmap.FindIndex(shell) < 1) - { - shmap.Add (shell); - - for (exp2.Init(shell, TopAbs_FACE); - exp2.More(); exp2.Next()) - { - TopoDS_Face face = TopoDS::Face(exp2.Current()); - if (fmap.FindIndex(face) < 1) - { - fmap.Add (face); - (*testout) << "face " << fmap.FindIndex(face) << " "; - (*testout) << ((face.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", "; - (*testout) << ((exp2.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << endl; - for (exp3.Init(exp2.Current(), TopAbs_WIRE); - exp3.More(); exp3.Next()) - { - TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); - if (wmap.FindIndex(wire) < 1) - { - wmap.Add (wire); - - for (exp4.Init(exp3.Current(), TopAbs_EDGE); - exp4.More(); exp4.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if (emap.FindIndex(edge) < 1) - { - emap.Add (edge); - for (exp5.Init(exp4.Current(), TopAbs_VERTEX); - exp5.More(); exp5.Next()) - { - TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if (vmap.FindIndex(vertex) < 1) - vmap.Add (vertex); - } - } - } - } - } - } - } - } - } - } - } - - // Free Shells - for (exp1.Init(shape, TopAbs_SHELL, TopAbs_SOLID); exp1.More(); exp1.Next()) - { - TopoDS_Shell shell = TopoDS::Shell(exp1.Current()); - if (shmap.FindIndex(shell) < 1) - { - shmap.Add (shell); - - (*testout) << "shell " << shmap.FindIndex(shell) << " "; - (*testout) << ((shell.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", "; - (*testout) << ((exp1.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << endl; - - for (exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next()) - { - TopoDS_Face face = TopoDS::Face(exp2.Current()); - if (fmap.FindIndex(face) < 1) - { - fmap.Add (face); - - for (exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()) - { - TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); - if (wmap.FindIndex(wire) < 1) - { - wmap.Add (wire); - - for (exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if (emap.FindIndex(edge) < 1) - { - emap.Add (edge); - for (exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()) - { - TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if (vmap.FindIndex(vertex) < 1) - vmap.Add (vertex); - } - } - } - } - } - } - } - } - } - - - // Free Faces - - for (exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL); exp2.More(); exp2.Next()) - { - TopoDS_Face face = TopoDS::Face(exp2.Current()); - if (fmap.FindIndex(face) < 1) - { - fmap.Add (face); - - for (exp3.Init(exp2.Current(), TopAbs_WIRE); exp3.More(); exp3.Next()) - { - TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); - if (wmap.FindIndex(wire) < 1) - { - wmap.Add (wire); - - for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if (emap.FindIndex(edge) < 1) - { - emap.Add (edge); - for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next()) - { - TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if (vmap.FindIndex(vertex) < 1) - vmap.Add (vertex); - } - } - } - } - } - } - } - - - // Free Wires - - for (exp3.Init(shape, TopAbs_WIRE, TopAbs_FACE); exp3.More(); exp3.Next()) - { - TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); - if (wmap.FindIndex(wire) < 1) - { - wmap.Add (wire); - - for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if (emap.FindIndex(edge) < 1) - { - emap.Add (edge); - for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next()) - { - TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if (vmap.FindIndex(vertex) < 1) - vmap.Add (vertex); - } - } - } - } - } - - - // Free Edges - - for (exp4.Init(shape, TopAbs_EDGE, TopAbs_WIRE); exp4.More(); exp4.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if (emap.FindIndex(edge) < 1) - { - emap.Add (edge); - for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next()) - { - TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if (vmap.FindIndex(vertex) < 1) - vmap.Add (vertex); - } - } - } - - - // Free Vertices - - for (exp5.Init(shape, TopAbs_VERTEX, TopAbs_EDGE); exp5.More(); exp5.Next()) - { - TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if (vmap.FindIndex(vertex) < 1) - vmap.Add (vertex); - } - - - - - facemeshstatus.DeleteAll(); - facemeshstatus.SetSize (fmap.Extent()); - facemeshstatus = 0; - - // Philippose - 15/01/2009 - face_maxh.DeleteAll(); - face_maxh.SetSize (fmap.Extent()); - face_maxh = mparam.maxh; - - // Philippose - 15/01/2010 - face_maxh_modified.DeleteAll(); - face_maxh_modified.SetSize(fmap.Extent()); - face_maxh_modified = 0; - - - // Philippose - 17/01/2009 - face_sel_status.DeleteAll(); - face_sel_status.SetSize (fmap.Extent()); - face_sel_status = 0; - - fvispar.SetSize (fmap.Extent()); - evispar.SetSize (emap.Extent()); - vvispar.SetSize (vmap.Extent()); - - fsingular.SetSize (fmap.Extent()); - esingular.SetSize (emap.Extent()); - vsingular.SetSize (vmap.Extent()); - - fsingular = esingular = vsingular = false; - } - - - - void OCCGeometry :: SewFaces () - { - (*testout) << "Trying to sew faces ..." << endl; - cout << "Trying to sew faces ..." << flush; - - BRepOffsetAPI_Sewing sewedObj(1); - - for (int i = 1; i <= fmap.Extent(); i++) - { - TopoDS_Face face = TopoDS::Face (fmap(i)); - sewedObj.Add (face); - } - - sewedObj.Perform(); - - if (!sewedObj.SewedShape().IsNull()) - { - shape = sewedObj.SewedShape(); - cout << " done" << endl; - } - else - cout << " not possible"; - } - - - - - - void OCCGeometry :: MakeSolid () - { - TopExp_Explorer exp0; - - (*testout) << "Trying to build solids ..." << endl; - cout << "Trying to build solids ..." << flush; - - BRepBuilderAPI_MakeSolid ms; - int count = 0; - for (exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next()) - { - count++; - ms.Add (TopoDS::Shell(exp0.Current())); - } - - if (!count) - { - cout << " not possible (no shells)" << endl; - return; - } - - BRepCheck_Analyzer ba(ms); - if (ba.IsValid ()) - { - Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; - sfs->Init (ms); - - sfs->SetPrecision(1e-5); - sfs->SetMaxTolerance(1e-5); - - sfs->Perform(); - - shape = sfs->Shape(); - - for (exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next()) - { - TopoDS_Solid solid = TopoDS::Solid(exp0.Current()); - TopoDS_Solid newsolid = solid; - BRepLib::OrientClosedSolid (newsolid); - Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; - rebuild->Replace(solid, newsolid, Standard_False); - - TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_SHAPE, 1); - shape = newshape; - } - - cout << " done" << endl; - } - else - cout << " not possible" << endl; - } - - - - - void OCCGeometry :: BuildVisualizationMesh (double deflection) - { - cout << "Preparing visualization (deflection = " << deflection << ") ... " << flush; - - BRepTools::Clean (shape); - // BRepMesh_IncrementalMesh:: - BRepMesh_IncrementalMesh (shape, deflection, true); - cout << "done" << endl; - } - - - - - void OCCGeometry :: CalcBoundingBox () - { - Bnd_Box bb; - BRepBndLib::Add (shape, bb); - - double x1,y1,z1,x2,y2,z2; - bb.Get (x1,y1,z1,x2,y2,z2); - Point<3> p1 = Point<3> (x1,y1,z1); - Point<3> p2 = Point<3> (x2,y2,z2); - - (*testout) << "Bounding Box = [" << p1 << " - " << p2 << "]" << endl; - boundingbox = Box<3> (p1,p2); - SetCenter(); - } - - - - - void OCCGeometry :: Project (int surfi, Point<3> & p) const - { - static int cnt = 0; - if (++cnt % 1000 == 0) cout << "Project cnt = " << cnt << endl; - - gp_Pnt pnt(p(0), p(1), p(2)); - - double u,v; - Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi))); - Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf ); - gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) ); - suval.Coord( u, v); - pnt = thesurf->Value( u, v ); - - - p = Point<3> (pnt.X(), pnt.Y(), pnt.Z()); - - } - - - - - bool OCCGeometry :: FastProject (int surfi, Point<3> & ap, double& u, double& v) const - { - gp_Pnt p(ap(0), ap(1), ap(2)); - - Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi))); - - gp_Pnt x = surface->Value (u,v); - - if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true; - - gp_Vec du, dv; - - surface->D1(u,v,x,du,dv); - - int count = 0; - - gp_Pnt xold; - gp_Vec n; - double det, lambda, mu; - - do { - count++; - - n = du^dv; - - det = Det3 (n.X(), du.X(), dv.X(), - n.Y(), du.Y(), dv.Y(), - n.Z(), du.Z(), dv.Z()); - - if (det < 1e-15) return false; - - lambda = Det3 (n.X(), p.X()-x.X(), dv.X(), - n.Y(), p.Y()-x.Y(), dv.Y(), - n.Z(), p.Z()-x.Z(), dv.Z())/det; - - mu = Det3 (n.X(), du.X(), p.X()-x.X(), - n.Y(), du.Y(), p.Y()-x.Y(), - n.Z(), du.Z(), p.Z()-x.Z())/det; - - u += lambda; - v += mu; - - xold = x; - surface->D1(u,v,x,du,dv); - - } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50); - - // (*testout) << "FastProject count: " << count << endl; - - if (count == 50) return false; - - ap = Point<3> (x.X(), x.Y(), x.Z()); - - return true; - } - - - - - void OCCGeometry :: WriteOCC_STL(char * filename) - { - cout << "writing stl..."; cout.flush(); - StlAPI_Writer writer; - writer.RelativeMode() = Standard_False; - - writer.SetDeflection(0.02); - writer.Write(shape,filename); - - cout << "done" << endl; - } - - - - // Philippose - 23/02/2009 - /* Special IGES File load function including the ability - to extract individual surface colours via the extended - OpenCascade XDE and XCAF Feature set. - */ - OCCGeometry *LoadOCC_IGES(const char *filename) - { - OCCGeometry *occgeo; - occgeo = new OCCGeometry; - - // Initiate a dummy XCAF Application to handle the IGES XCAF Document - static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication(); - - // Create an XCAF Document to contain the IGES file itself - Handle_TDocStd_Document iges_doc; - - // Check if a IGES File is already open under this handle, if so, close it to prevent - // Segmentation Faults when trying to create a new document - if(dummy_app->NbDocuments() > 0) - { - dummy_app->GetDocument(1,iges_doc); - dummy_app->Close(iges_doc); - } - dummy_app->NewDocument ("IGES-XCAF",iges_doc); - - IGESCAFControl_Reader reader; - - Standard_Integer stat = reader.ReadFile((char*)filename); - - if(stat != IFSelect_RetDone) - { - delete occgeo; - return NULL; - } - - // Enable transfer of colours - reader.SetColorMode(Standard_True); - - reader.Transfer(iges_doc); - - // Read in the shape(s) and the colours present in the IGES File - Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main()); - Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main()); - - TDF_LabelSequence iges_shapes; - iges_shape_contents->GetShapes(iges_shapes); - - // List out the available colours in the IGES File as Colour Names - TDF_LabelSequence all_colours; - iges_colour_contents->GetColors(all_colours); - PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length()); - for(int i = 1; i <= all_colours.Length(); i++) - { - Quantity_Color col; - stringstream col_rgb; - iges_colour_contents->GetColor(all_colours.Value(i),col); - col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")"; - PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str()); - } - - - // For the IGES Reader, all the shapes can be exported as one compund shape - // using the "OneShape" member - occgeo->shape = reader.OneShape(); - occgeo->face_colours = iges_colour_contents; - occgeo->changed = 1; - occgeo->BuildFMap(); - - occgeo->CalcBoundingBox(); - PrintContents (occgeo); - - return occgeo; - } - - - - - - // Philippose - 29/01/2009 - /* Special STEP File load function including the ability - to extract individual surface colours via the extended - OpenCascade XDE and XCAF Feature set. - */ - OCCGeometry * LoadOCC_STEP (const char * filename) - { - OCCGeometry * occgeo; - occgeo = new OCCGeometry; - - // Initiate a dummy XCAF Application to handle the STEP XCAF Document - static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication(); - - // Create an XCAF Document to contain the STEP file itself - Handle_TDocStd_Document step_doc; - - // Check if a STEP File is already open under this handle, if so, close it to prevent - // Segmentation Faults when trying to create a new document - if(dummy_app->NbDocuments() > 0) - { - dummy_app->GetDocument(1,step_doc); - dummy_app->Close(step_doc); - } - dummy_app->NewDocument ("STEP-XCAF",step_doc); - - STEPCAFControl_Reader reader; - - // Enable transfer of colours - reader.SetColorMode(Standard_True); - - Standard_Integer stat = reader.ReadFile((char*)filename); - - if(stat != IFSelect_RetDone) - { - delete occgeo; - return NULL; - } - - reader.Transfer(step_doc); - - // Read in the shape(s) and the colours present in the STEP File - Handle_XCAFDoc_ShapeTool step_shape_contents = XCAFDoc_DocumentTool::ShapeTool(step_doc->Main()); - Handle_XCAFDoc_ColorTool step_colour_contents = XCAFDoc_DocumentTool::ColorTool(step_doc->Main()); - - TDF_LabelSequence step_shapes; - step_shape_contents->GetShapes(step_shapes); - - // List out the available colours in the STEP File as Colour Names - TDF_LabelSequence all_colours; - step_colour_contents->GetColors(all_colours); - PrintMessage(1,"Number of colours in STEP File: ",all_colours.Length()); - for(int i = 1; i <= all_colours.Length(); i++) - { - Quantity_Color col; - stringstream col_rgb; - step_colour_contents->GetColor(all_colours.Value(i),col); - col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")"; - PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str()); - } - - - // For the STEP File Reader in OCC, the 1st Shape contains the entire - // compound geometry as one shape - occgeo->shape = step_shape_contents->GetShape(step_shapes.Value(1)); - occgeo->face_colours = step_colour_contents; - occgeo->changed = 1; - occgeo->BuildFMap(); - - occgeo->CalcBoundingBox(); - PrintContents (occgeo); - - return occgeo; - } - - - - - OCCGeometry *LoadOCC_BREP (const char *filename) - { - OCCGeometry * occgeo; - occgeo = new OCCGeometry; - - BRep_Builder aBuilder; - Standard_Boolean result = BRepTools::Read(occgeo->shape, const_cast (filename),aBuilder); - - if(!result) - { - delete occgeo; - return NULL; - } - - // Philippose - 23/02/2009 - // Fixed a bug in the OpenCascade XDE Colour handling when - // opening BREP Files, since BREP Files have no colour data. - // Hence, the face_colours Handle needs to be created as a NULL handle. - occgeo->face_colours = Handle_XCAFDoc_ColorTool(); - occgeo->face_colours.Nullify(); - occgeo->changed = 1; - occgeo->BuildFMap(); - - occgeo->CalcBoundingBox(); - PrintContents (occgeo); - - return occgeo; - } - - - void OCCGeometry :: Save (string sfilename) const - { - const char * filename = sfilename.c_str(); - if (strlen(filename) < 4) - throw NgException ("illegal filename"); - - if (strcmp (&filename[strlen(filename)-3], "igs") == 0) - { - IGESControl_Writer writer("millimeters", 1); - writer.AddShape (shape); - writer.Write (filename); - } - else if (strcmp (&filename[strlen(filename)-3], "stp") == 0) - { - STEPControl_Writer writer; - writer.Transfer (shape, STEPControl_AsIs); - writer.Write (filename); - } - else if (strcmp (&filename[strlen(filename)-3], "stl") == 0) - { - StlAPI_Writer writer; - writer.ASCIIMode() = Standard_True; - writer.Write (shape, filename); - } - else if (strcmp (&filename[strlen(filename)-4], "stlb") == 0) - { - StlAPI_Writer writer; - writer.ASCIIMode() = Standard_False; - writer.Write (shape, filename); - } - } - - - - const char * shapesname[] = - {" ", "CompSolids", "Solids", "Shells", - - "Faces", "Wires", "Edges", "Vertices"}; - - const char * shapename[] = - {" ", "CompSolid", "Solid", "Shell", - "Face", "Wire", "Edge", "Vertex"}; - - const char * orientationstring[] = - {"+", "-"}; - - - - - void OCCGeometry :: RecursiveTopologyTree (const TopoDS_Shape & sh, - stringstream & str, - TopAbs_ShapeEnum l, - bool isfree, - const char * lname) - { - if (l > TopAbs_VERTEX) return; - - TopExp_Explorer e; - int count = 0; - int count2 = 0; - - if (isfree) - e.Init(sh, l, TopAbs_ShapeEnum(l-1)); - else - e.Init(sh, l); - - for (; e.More(); e.Next()) - { - count++; - - stringstream lname2; - lname2 << lname << "/" << shapename[l] << count; - str << lname2.str() << " "; - - switch (e.Current().ShapeType()) - { - case TopAbs_SOLID: - count2 = somap.FindIndex(TopoDS::Solid(e.Current())); break; - case TopAbs_SHELL: - count2 = shmap.FindIndex(TopoDS::Shell(e.Current())); break; - case TopAbs_FACE: - count2 = fmap.FindIndex(TopoDS::Face(e.Current())); break; - case TopAbs_WIRE: - count2 = wmap.FindIndex(TopoDS::Wire(e.Current())); break; - case TopAbs_EDGE: - count2 = emap.FindIndex(TopoDS::Edge(e.Current())); break; - case TopAbs_VERTEX: - count2 = vmap.FindIndex(TopoDS::Vertex(e.Current())); break; - default: - cout << "RecursiveTopologyTree: Case " << e.Current().ShapeType() << " not handeled" << endl; - } - - int nrsubshapes = 0; - - if (l <= TopAbs_WIRE) - { - TopExp_Explorer e2; - for (e2.Init (e.Current(), TopAbs_ShapeEnum (l+1)); - e2.More(); e2.Next()) - nrsubshapes++; - } - - str << "{" << shapename[l] << " " << count2; - - if (l <= TopAbs_EDGE) - { - str << " (" << orientationstring[e.Current().Orientation()]; - if (nrsubshapes != 0) str << ", " << nrsubshapes; - str << ") } "; - } - else - str << " } "; - - RecursiveTopologyTree (e.Current(), str, TopAbs_ShapeEnum (l+1), - false, (char*)lname2.str().c_str()); - - } - } - - - - - void OCCGeometry :: GetTopologyTree (stringstream & str) - { - cout << "Building topology tree ... " << flush; - RecursiveTopologyTree (shape, str, TopAbs_COMPSOLID, false, "CompSolids"); - RecursiveTopologyTree (shape, str, TopAbs_SOLID, true, "FreeSolids"); - RecursiveTopologyTree (shape, str, TopAbs_SHELL, true, "FreeShells"); - RecursiveTopologyTree (shape, str, TopAbs_FACE, true, "FreeFaces"); - RecursiveTopologyTree (shape, str, TopAbs_WIRE, true, "FreeWires"); - RecursiveTopologyTree (shape, str, TopAbs_EDGE, true, "FreeEdges"); - RecursiveTopologyTree (shape, str, TopAbs_VERTEX, true, "FreeVertices"); - str << flush; - // cout << "done" << endl; - } - - - - - void OCCGeometry :: CheckIrregularEntities(stringstream & str) - { - ShapeAnalysis_CheckSmallFace csm; - - csm.SetTolerance (1e-6); - - TopTools_DataMapOfShapeListOfShape mapEdges; - ShapeAnalysis_DataMapOfShapeListOfReal mapParam; - TopoDS_Compound theAllVert; - - int spotfaces = 0; - int stripsupportfaces = 0; - int singlestripfaces = 0; - int stripfaces = 0; - int facessplitbyvertices = 0; - int stretchedpinfaces = 0; - int smoothpinfaces = 0; - int twistedfaces = 0; - // int edgessamebutnotidentified = 0; - - cout << "checking faces ... " << flush; - - int i; - for (i = 1; i <= fmap.Extent(); i++) - { - TopoDS_Face face = TopoDS::Face (fmap(i)); - TopoDS_Edge e1, e2; - - if (csm.CheckSpotFace (face)) - { - if (!spotfaces++) - str << "SpotFace {Spot face} "; - - (*testout) << "Face " << i << " is a spot face" << endl; - str << "SpotFace/Face" << i << " "; - str << "{Face " << i << " } "; - } - - if (csm.IsStripSupport (face)) - { - if (!stripsupportfaces++) - str << "StripSupportFace {Strip support face} "; - - (*testout) << "Face " << i << " has strip support" << endl; - str << "StripSupportFace/Face" << i << " "; - str << "{Face " << i << " } "; - } - - if (csm.CheckSingleStrip(face, e1, e2)) - { - if (!singlestripfaces++) - str << "SingleStripFace {Single strip face} "; - - (*testout) << "Face " << i << " is a single strip (edge " << emap.FindIndex(e1) - << " and edge " << emap.FindIndex(e2) << " are identical)" << endl; - str << "SingleStripFace/Face" << i << " "; - str << "{Face " << i << " (edge " << emap.FindIndex(e1) - << " and edge " << emap.FindIndex(e2) << " are identical)} "; - } - - if (csm.CheckStripFace(face, e1, e2)) - { - if (!stripfaces++) - str << "StripFace {Strip face} "; - - (*testout) << "Face " << i << " is a strip (edge " << emap.FindIndex(e1) - << " and edge " << emap.FindIndex(e2) - << " are identical)" << endl; - str << "StripFace/Face" << i << " "; - str << "{Face " << i << " (edge " << emap.FindIndex(e1) - << " and edge " << emap.FindIndex(e2) << " are identical)} "; - } - - if (int count = csm.CheckSplittingVertices(face, mapEdges, mapParam, theAllVert)) - { - if (!facessplitbyvertices++) - str << "FaceSplitByVertices {Face split by vertices} "; - - (*testout) << "Face " << i << " is split by " << count - << " vertex/vertices " << endl; - str << "FaceSplitByVertices/Face" << i << " "; - str << "{Face " << i << " (split by " << count << "vertex/vertices)} "; - } - - int whatrow, sens; - if (int type = csm.CheckPin (face, whatrow, sens)) - { - if (type == 1) - { - if (!smoothpinfaces++) - str << "SmoothPinFace {Smooth pin face} "; - - (*testout) << "Face " << i << " is a smooth pin" << endl; - str << "SmoothPinFace/Face" << i << " "; - str << "{Face " << i << " } "; - } - else - { - if (!stretchedpinfaces++) - str << "StretchedPinFace {Stretched pin face} "; - - (*testout) << "Face " << i << " is a streched pin" << endl; - str << "StretchedPinFace/Face" << i << " "; - str << "{Face " << i << " } "; - } - } - - double paramu, paramv; - if (csm.CheckTwisted (face, paramu, paramv)) - { - if (!twistedfaces++) - str << "TwistedFace {Twisted face} "; - - (*testout) << "Face " << i << " is twisted" << endl; - str << "TwistedFace/Face" << i << " "; - str << "{Face " << i << " } "; - } - } - - cout << "done" << endl; - cout << "checking edges ... " << flush; - - // double dmax; - // int cnt = 0; - Array edgeLengths; - Array order; - edgeLengths.SetSize (emap.Extent()); - order.SetSize (emap.Extent()); - - for (i = 1; i <= emap.Extent(); i++) - { - TopoDS_Edge edge1 = TopoDS::Edge (emap(i)); - GProp_GProps system; - BRepGProp::LinearProperties(edge1, system); - edgeLengths[i-1] = system.Mass(); - } - - Sort (edgeLengths, order); - - str << "ShortestEdges {Shortest edges} "; - for (i = 1; i <= min(20, emap.Extent()); i++) - { - str << "ShortestEdges/Edge" << i; - str << " {Edge " << order[i-1] << " (L=" << edgeLengths[order[i-1]-1] << ")} "; - } - - str << flush; - - cout << "done" << endl; - } - - - - - void OCCGeometry :: GetUnmeshedFaceInfo (stringstream & str) - { - for (int i = 1; i <= fmap.Extent(); i++) - { - if (facemeshstatus[i-1] == -1) - str << "Face" << i << " {Face " << i << " } "; - } - str << flush; - } - - - - - void OCCGeometry :: GetNotDrawableFaces (stringstream & str) - { - for (int i = 1; i <= fmap.Extent(); i++) - { - if (!fvispar[i-1].IsDrawable()) - str << "Face" << i << " {Face " << i << " } "; - } - str << flush; - } - - - - - bool OCCGeometry :: ErrorInSurfaceMeshing () - { - for (int i = 1; i <= fmap.Extent(); i++) - if (facemeshstatus[i-1] == -1) - return true; - - return false; - } - - - - - int OCCGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, - int perfstepsstart, int perfstepsend) - { - return OCCGenerateMesh (*this, mesh, mparam, perfstepsstart, perfstepsend); - } - - - - - const Refinement & OCCGeometry :: GetRefinement () const - { - return * new OCCRefinementSurfaces (*this); - } - - - - - OCCParameters :: OCCParameters() - { - resthcloseedgefac = 1; - resthcloseedgeenable = 1; - } - - - - - void OCCParameters :: Print(ostream & ost) const - { - ost << "OCC Parameters:" << endl - << "close edges: " << resthcloseedgeenable - << ", fac = " << resthcloseedgefac << endl; - } - - - - - OCCParameters occparam; - -} - - -#endif + +#ifdef OCCGEOMETRY + +#include +#include +#include "ShapeAnalysis_ShapeTolerance.hxx" +#include "ShapeAnalysis_ShapeContents.hxx" +#include "ShapeAnalysis_CheckSmallFace.hxx" +#include "ShapeAnalysis_DataMapOfShapeListOfReal.hxx" +#include "ShapeAnalysis_Surface.hxx" +#include "BRepAlgoAPI_Fuse.hxx" +#include "BRepCheck_Analyzer.hxx" +#include "BRepLib.hxx" +#include "ShapeBuild_ReShape.hxx" +#include "ShapeFix.hxx" +#include "ShapeFix_FixSmallFace.hxx" +#include "Partition_Spliter.hxx" + + +namespace netgen +{ + void OCCGeometry :: PrintNrShapes () + { + TopExp_Explorer e; + int count = 0; + for (e.Init(shape, TopAbs_COMPSOLID); e.More(); e.Next()) count++; + cout << "CompSolids: " << count << endl; + + cout << "Solids : " << somap.Extent() << endl; + cout << "Shells : " << shmap.Extent() << endl; + cout << "Faces : " << fmap.Extent() << endl; + cout << "Edges : " << emap.Extent() << endl; + cout << "Vertices : " << vmap.Extent() << endl; + } + + + + + void PrintContents (OCCGeometry * geom) + { + ShapeAnalysis_ShapeContents cont; + cont.Clear(); + cont.Perform(geom->shape); + + (*testout) << "OCC CONTENTS" << endl; + (*testout) << "============" << endl; + (*testout) << "SOLIDS : " << cont.NbSolids() << endl; + (*testout) << "SHELLS : " << cont.NbShells() << endl; + (*testout) << "FACES : " << cont.NbFaces() << endl; + (*testout) << "WIRES : " << cont.NbWires() << endl; + (*testout) << "EDGES : " << cont.NbEdges() << endl; + (*testout) << "VERTICES : " << cont.NbVertices() << endl; + + TopExp_Explorer e; + int count = 0; + for (e.Init(geom->shape, TopAbs_COMPOUND); e.More(); e.Next()) + count++; + (*testout) << "Compounds: " << count << endl; + + count = 0; + for (e.Init(geom->shape, TopAbs_COMPSOLID); e.More(); e.Next()) + count++; + (*testout) << "CompSolids: " << count << endl; + + (*testout) << endl; + + cout << "Highest entry in topology hierarchy: " << endl; + if (count) + cout << count << " composite solid(s)" << endl; + else + if (geom->somap.Extent()) + cout << geom->somap.Extent() << " solid(s)" << endl; + else + if (geom->shmap.Extent()) + cout << geom->shmap.Extent() << " shells(s)" << endl; + else + if (geom->fmap.Extent()) + cout << geom->fmap.Extent() << " face(s)" << endl; + else + if (geom->wmap.Extent()) + cout << geom->wmap.Extent() << " wire(s)" << endl; + else + if (geom->emap.Extent()) + cout << geom->emap.Extent() << " edge(s)" << endl; + else + if (geom->vmap.Extent()) + cout << geom->vmap.Extent() << " vertices(s)" << endl; + else + cout << "no entities" << endl; + + } + + + + void OCCGeometry :: HealGeometry () + { + int nrc = 0, nrcs = 0, + nrso = somap.Extent(), + nrsh = shmap.Extent(), + nrf = fmap.Extent(), + nrw = wmap.Extent(), + nre = emap.Extent(), + nrv = vmap.Extent(); + + TopExp_Explorer exp0; + TopExp_Explorer exp1; + + + for (exp0.Init(shape, TopAbs_COMPOUND); exp0.More(); exp0.Next()) nrc++; + for (exp0.Init(shape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nrcs++; + + double surfacecont = 0; + + { + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + rebuild->Apply(shape); + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if ( BRep_Tool::Degenerated(edge) ) + rebuild->Remove(edge, false); + } + shape = rebuild->Apply(shape); + } + + BuildFMap(); + + + for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) + { + TopoDS_Face face = TopoDS::Face(exp0.Current()); + + GProp_GProps system; + BRepGProp::SurfaceProperties(face, system); + surfacecont += system.Mass(); + } + + + cout << "Starting geometry healing procedure (tolerance: " << tolerance << ")" << endl + << "-----------------------------------" << endl; + + { + cout << endl << "- repairing faces" << endl; + + Handle(ShapeFix_Face) sff; + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + rebuild->Apply(shape); + + + for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) + { + // Variable to hold the colour (if there exists one) of + // the current face being processed + Quantity_Color face_colour; + + TopoDS_Face face = TopoDS::Face (exp0.Current()); + + if(face_colours.IsNull() + || (!(face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour)))) + { + // Set the default face colour to green (Netgen Standard) + // if no colour has been defined for the face + face_colour = Quantity_Color(0.0,1.0,0.0,Quantity_TOC_RGB); + } + + sff = new ShapeFix_Face (face); + sff->FixAddNaturalBoundMode() = Standard_True; + sff->FixSmallAreaWireMode() = Standard_True; + sff->Perform(); + + if(sff->Status(ShapeExtend_DONE1) || + sff->Status(ShapeExtend_DONE2) || + sff->Status(ShapeExtend_DONE3) || + sff->Status(ShapeExtend_DONE4) || + sff->Status(ShapeExtend_DONE5)) + { + cout << "repaired face " << fmap.FindIndex(face) << " "; + if(sff->Status(ShapeExtend_DONE1)) + cout << "(some wires are fixed)" <Status(ShapeExtend_DONE2)) + cout << "(orientation of wires fixed)" <Status(ShapeExtend_DONE3)) + cout << "(missing seam added)" <Status(ShapeExtend_DONE4)) + cout << "(small area wire removed)" <Status(ShapeExtend_DONE5)) + cout << "(natural bounds added)" <Face(); + + rebuild->Replace(face, newface, Standard_False); + } + + // Set the original colour of the face to the newly created + // face (after the healing process) + face = TopoDS::Face (exp0.Current()); + face_colours->SetColor(face,face_colour,XCAFDoc_ColorSurf); + } + shape = rebuild->Apply(shape); + } + + + { + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + rebuild->Apply(shape); + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if ( BRep_Tool::Degenerated(edge) ) + rebuild->Remove(edge, false); + } + shape = rebuild->Apply(shape); + } + + + if (fixsmalledges) + { + cout << endl << "- fixing small edges" << endl; + + Handle(ShapeFix_Wire) sfw; + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + rebuild->Apply(shape); + + + for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) + { + TopoDS_Face face = TopoDS::Face(exp0.Current()); + + for (exp1.Init (face, TopAbs_WIRE); exp1.More(); exp1.Next()) + { + TopoDS_Wire oldwire = TopoDS::Wire(exp1.Current()); + sfw = new ShapeFix_Wire (oldwire, face ,tolerance); + sfw->ModifyTopologyMode() = Standard_True; + + sfw->ClosedWireMode() = Standard_True; + + bool replace = false; + + replace = sfw->FixReorder() || replace; + + replace = sfw->FixConnected() || replace; + + + + if (sfw->FixSmall (Standard_False, tolerance) && ! (sfw->StatusSmall(ShapeExtend_FAIL1) || + sfw->StatusSmall(ShapeExtend_FAIL2) || + sfw->StatusSmall(ShapeExtend_FAIL3))) + { + cout << "Fixed small edge in wire " << wmap.FindIndex (oldwire) << endl; + replace = true; + + } + else if (sfw->StatusSmall(ShapeExtend_FAIL1)) + cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire) + << ", edge cannot be checked (no 3d curve and no pcurve)" << endl; + else if (sfw->StatusSmall(ShapeExtend_FAIL2)) + cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire) + << ", edge is null-length and has different vertives at begin and end, and lockvtx is True or ModifiyTopologyMode is False" << endl; + else if (sfw->StatusSmall(ShapeExtend_FAIL3)) + cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire) + << ", CheckConnected has failed" << endl; + + replace = sfw->FixEdgeCurves() || replace; + + replace = sfw->FixDegenerated() || replace; + + replace = sfw->FixSelfIntersection() || replace; + + replace = sfw->FixLacking(Standard_True) || replace; + + if(replace) + { + TopoDS_Wire newwire = sfw->Wire(); + rebuild->Replace(oldwire, newwire, Standard_False); + } + + //delete sfw; sfw = NULL; + + } + } + + shape = rebuild->Apply(shape); + + + + { + BuildFMap(); + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + rebuild->Apply(shape); + + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if (vmap.FindIndex(TopExp::FirstVertex (edge)) == + vmap.FindIndex(TopExp::LastVertex (edge))) + { + GProp_GProps system; + BRepGProp::LinearProperties(edge, system); + if (system.Mass() < tolerance) + { + cout << "removing degenerated edge " << emap.FindIndex(edge) + << " from vertex " << vmap.FindIndex(TopExp::FirstVertex (edge)) + << " to vertex " << vmap.FindIndex(TopExp::LastVertex (edge)) << endl; + rebuild->Remove(edge, false); + } + } + } + shape = rebuild->Apply(shape); + + //delete rebuild; rebuild = NULL; + } + + + + { + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + rebuild->Apply(shape); + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if ( BRep_Tool::Degenerated(edge) ) + rebuild->Remove(edge, false); + } + shape = rebuild->Apply(shape); + } + + + + + Handle(ShapeFix_Wireframe) sfwf = new ShapeFix_Wireframe; + sfwf->SetPrecision(tolerance); + sfwf->Load (shape); + sfwf->ModeDropSmallEdges() = Standard_True; + + sfwf->SetPrecision(boundingbox.Diam()); + + if (sfwf->FixWireGaps()) + { + cout << endl << "- fixing wire gaps" << endl; + if (sfwf->StatusWireGaps(ShapeExtend_OK)) cout << "no gaps found" << endl; + if (sfwf->StatusWireGaps(ShapeExtend_DONE1)) cout << "some 2D gaps fixed" << endl; + if (sfwf->StatusWireGaps(ShapeExtend_DONE2)) cout << "some 3D gaps fixed" << endl; + if (sfwf->StatusWireGaps(ShapeExtend_FAIL1)) cout << "failed to fix some 2D gaps" << endl; + if (sfwf->StatusWireGaps(ShapeExtend_FAIL2)) cout << "failed to fix some 3D gaps" << endl; + } + + sfwf->SetPrecision(tolerance); + + + { + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if ( BRep_Tool::Degenerated(edge) ) + cout << "degenerated edge at position 4" << endl; + } + } + + + + if (sfwf->FixSmallEdges()) + { + cout << endl << "- fixing wire frames" << endl; + if (sfwf->StatusSmallEdges(ShapeExtend_OK)) cout << "no small edges found" << endl; + if (sfwf->StatusSmallEdges(ShapeExtend_DONE1)) cout << "some small edges fixed" << endl; + if (sfwf->StatusSmallEdges(ShapeExtend_FAIL1)) cout << "failed to fix some small edges" << endl; + } + + + + shape = sfwf->Shape(); + + //delete sfwf; sfwf = NULL; + //delete rebuild; rebuild = NULL; + + } + + + + + + { + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if ( BRep_Tool::Degenerated(edge) ) + cout << "degenerated edge at position 5" << endl; + } + } + + + + + if (fixspotstripfaces) + { + + cout << endl << "- fixing spot and strip faces" << endl; + Handle(ShapeFix_FixSmallFace) sffsm = new ShapeFix_FixSmallFace(); + sffsm -> Init (shape); + sffsm -> SetPrecision (tolerance); + sffsm -> Perform(); + + shape = sffsm -> FixShape(); + //delete sffsm; sffsm = NULL; + } + + + { + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if ( BRep_Tool::Degenerated(edge) ) + cout << "degenerated edge at position 6" << endl; + } + } + + + + if (sewfaces) + { + cout << endl << "- sewing faces" << endl; + + BRepOffsetAPI_Sewing sewedObj(tolerance); + + for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) + { + TopoDS_Face face = TopoDS::Face (exp0.Current()); + sewedObj.Add (face); + } + + sewedObj.Perform(); + + if (!sewedObj.SewedShape().IsNull()) + shape = sewedObj.SewedShape(); + else + cout << " not possible"; + } + + + + { + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + rebuild->Apply(shape); + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if ( BRep_Tool::Degenerated(edge) ) + rebuild->Remove(edge, false); + } + shape = rebuild->Apply(shape); + } + + + if (makesolids) + { + cout << endl << "- making solids" << endl; + + BRepBuilderAPI_MakeSolid ms; + int count = 0; + for (exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next()) + { + count++; + ms.Add (TopoDS::Shell(exp0.Current())); + } + + if (!count) + { + cout << " not possible (no shells)" << endl; + } + else + { + BRepCheck_Analyzer ba(ms); + if (ba.IsValid ()) + { + Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; + sfs->Init (ms); + sfs->SetPrecision(tolerance); + sfs->SetMaxTolerance(tolerance); + sfs->Perform(); + shape = sfs->Shape(); + + for (exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next()) + { + TopoDS_Solid solid = TopoDS::Solid(exp0.Current()); + TopoDS_Solid newsolid = solid; + BRepLib::OrientClosedSolid (newsolid); + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + // rebuild->Apply(shape); + rebuild->Replace(solid, newsolid, Standard_False); + TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_COMPSOLID);//, 1); + // TopoDS_Shape newshape = rebuild->Apply(shape); + shape = newshape; + } + + //delete sfs; sfs = NULL; + } + else + cout << " not possible" << endl; + } + } + + + + if (splitpartitions) + { + cout << "- running SALOME partition splitter" << endl; + + TopExp_Explorer e2; + Partition_Spliter ps; + int count = 0; + + for (e2.Init (shape, TopAbs_SOLID); + e2.More(); e2.Next()) + { + count++; + ps.AddShape (e2.Current()); + } + + ps.Compute(); + shape = ps.Shape(); + + cout << " before: " << count << " solids" << endl; + + count = 0; + for (e2.Init (shape, TopAbs_SOLID); + e2.More(); e2.Next()) count++; + + cout << " after : " << count << " solids" << endl; + } + + BuildFMap(); + + + + { + for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + if ( BRep_Tool::Degenerated(edge) ) + cout << "degenerated edge at position 8" << endl; + } + } + + + double newsurfacecont = 0; + + + for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next()) + { + TopoDS_Face face = TopoDS::Face(exp0.Current()); + GProp_GProps system; + BRepGProp::SurfaceProperties(face, system); + newsurfacecont += system.Mass(); + } + + + int nnrc = 0, nnrcs = 0, + nnrso = somap.Extent(), + nnrsh = shmap.Extent(), + nnrf = fmap.Extent(), + nnrw = wmap.Extent(), + nnre = emap.Extent(), + nnrv = vmap.Extent(); + + for (exp0.Init(shape, TopAbs_COMPOUND); exp0.More(); exp0.Next()) nnrc++; + for (exp0.Init(shape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nnrcs++; + + cout << "-----------------------------------" << endl; + cout << "Compounds : " << nnrc << " (" << nrc << ")" << endl; + cout << "Composite solids: " << nnrcs << " (" << nrcs << ")" << endl; + cout << "Solids : " << nnrso << " (" << nrso << ")" << endl; + cout << "Shells : " << nnrsh << " (" << nrsh << ")" << endl; + cout << "Wires : " << nnrw << " (" << nrw << ")" << endl; + cout << "Faces : " << nnrf << " (" << nrf << ")" << endl; + cout << "Edges : " << nnre << " (" << nre << ")" << endl; + cout << "Vertices : " << nnrv << " (" << nrv << ")" << endl; + cout << endl; + cout << "Totol surface area : " << newsurfacecont << " (" << surfacecont << ")" << endl; + cout << endl; + } + + + + + void OCCGeometry :: BuildFMap() + { + somap.Clear(); + shmap.Clear(); + fmap.Clear(); + wmap.Clear(); + emap.Clear(); + vmap.Clear(); + + TopExp_Explorer exp0, exp1, exp2, exp3, exp4, exp5; + + for (exp0.Init(shape, TopAbs_COMPOUND); + exp0.More(); exp0.Next()) + { + TopoDS_Compound compound = TopoDS::Compound (exp0.Current()); + (*testout) << "compound" << endl; + int i = 0; + for (exp1.Init(compound, TopAbs_SHELL); + exp1.More(); exp1.Next()) + { + (*testout) << "shell " << ++i << endl; + } + } + + for (exp0.Init(shape, TopAbs_SOLID); + exp0.More(); exp0.Next()) + { + TopoDS_Solid solid = TopoDS::Solid (exp0.Current()); + + if (somap.FindIndex(solid) < 1) + { + somap.Add (solid); + + for (exp1.Init(solid, TopAbs_SHELL); + exp1.More(); exp1.Next()) + { + TopoDS_Shell shell = TopoDS::Shell (exp1.Current()); + if (shmap.FindIndex(shell) < 1) + { + shmap.Add (shell); + + for (exp2.Init(shell, TopAbs_FACE); + exp2.More(); exp2.Next()) + { + TopoDS_Face face = TopoDS::Face(exp2.Current()); + if (fmap.FindIndex(face) < 1) + { + fmap.Add (face); + (*testout) << "face " << fmap.FindIndex(face) << " "; + (*testout) << ((face.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", "; + (*testout) << ((exp2.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << endl; + for (exp3.Init(exp2.Current(), TopAbs_WIRE); + exp3.More(); exp3.Next()) + { + TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); + if (wmap.FindIndex(wire) < 1) + { + wmap.Add (wire); + + for (exp4.Init(exp3.Current(), TopAbs_EDGE); + exp4.More(); exp4.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); + if (emap.FindIndex(edge) < 1) + { + emap.Add (edge); + for (exp5.Init(exp4.Current(), TopAbs_VERTEX); + exp5.More(); exp5.Next()) + { + TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); + if (vmap.FindIndex(vertex) < 1) + vmap.Add (vertex); + } + } + } + } + } + } + } + } + } + } + } + + // Free Shells + for (exp1.Init(shape, TopAbs_SHELL, TopAbs_SOLID); exp1.More(); exp1.Next()) + { + TopoDS_Shell shell = TopoDS::Shell(exp1.Current()); + if (shmap.FindIndex(shell) < 1) + { + shmap.Add (shell); + + (*testout) << "shell " << shmap.FindIndex(shell) << " "; + (*testout) << ((shell.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", "; + (*testout) << ((exp1.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << endl; + + for (exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next()) + { + TopoDS_Face face = TopoDS::Face(exp2.Current()); + if (fmap.FindIndex(face) < 1) + { + fmap.Add (face); + + for (exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()) + { + TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); + if (wmap.FindIndex(wire) < 1) + { + wmap.Add (wire); + + for (exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); + if (emap.FindIndex(edge) < 1) + { + emap.Add (edge); + for (exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()) + { + TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); + if (vmap.FindIndex(vertex) < 1) + vmap.Add (vertex); + } + } + } + } + } + } + } + } + } + + + // Free Faces + + for (exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL); exp2.More(); exp2.Next()) + { + TopoDS_Face face = TopoDS::Face(exp2.Current()); + if (fmap.FindIndex(face) < 1) + { + fmap.Add (face); + + for (exp3.Init(exp2.Current(), TopAbs_WIRE); exp3.More(); exp3.Next()) + { + TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); + if (wmap.FindIndex(wire) < 1) + { + wmap.Add (wire); + + for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); + if (emap.FindIndex(edge) < 1) + { + emap.Add (edge); + for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next()) + { + TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); + if (vmap.FindIndex(vertex) < 1) + vmap.Add (vertex); + } + } + } + } + } + } + } + + + // Free Wires + + for (exp3.Init(shape, TopAbs_WIRE, TopAbs_FACE); exp3.More(); exp3.Next()) + { + TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); + if (wmap.FindIndex(wire) < 1) + { + wmap.Add (wire); + + for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); + if (emap.FindIndex(edge) < 1) + { + emap.Add (edge); + for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next()) + { + TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); + if (vmap.FindIndex(vertex) < 1) + vmap.Add (vertex); + } + } + } + } + } + + + // Free Edges + + for (exp4.Init(shape, TopAbs_EDGE, TopAbs_WIRE); exp4.More(); exp4.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); + if (emap.FindIndex(edge) < 1) + { + emap.Add (edge); + for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next()) + { + TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); + if (vmap.FindIndex(vertex) < 1) + vmap.Add (vertex); + } + } + } + + + // Free Vertices + + for (exp5.Init(shape, TopAbs_VERTEX, TopAbs_EDGE); exp5.More(); exp5.Next()) + { + TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); + if (vmap.FindIndex(vertex) < 1) + vmap.Add (vertex); + } + + + + + facemeshstatus.DeleteAll(); + facemeshstatus.SetSize (fmap.Extent()); + facemeshstatus = 0; + + // Philippose - 15/01/2009 + face_maxh.DeleteAll(); + face_maxh.SetSize (fmap.Extent()); + face_maxh = mparam.maxh; + + // Philippose - 15/01/2010 + face_maxh_modified.DeleteAll(); + face_maxh_modified.SetSize(fmap.Extent()); + face_maxh_modified = 0; + + + // Philippose - 17/01/2009 + face_sel_status.DeleteAll(); + face_sel_status.SetSize (fmap.Extent()); + face_sel_status = 0; + + fvispar.SetSize (fmap.Extent()); + evispar.SetSize (emap.Extent()); + vvispar.SetSize (vmap.Extent()); + + fsingular.SetSize (fmap.Extent()); + esingular.SetSize (emap.Extent()); + vsingular.SetSize (vmap.Extent()); + + fsingular = esingular = vsingular = false; + } + + + + void OCCGeometry :: SewFaces () + { + (*testout) << "Trying to sew faces ..." << endl; + cout << "Trying to sew faces ..." << flush; + + BRepOffsetAPI_Sewing sewedObj(1); + + for (int i = 1; i <= fmap.Extent(); i++) + { + TopoDS_Face face = TopoDS::Face (fmap(i)); + sewedObj.Add (face); + } + + sewedObj.Perform(); + + if (!sewedObj.SewedShape().IsNull()) + { + shape = sewedObj.SewedShape(); + cout << " done" << endl; + } + else + cout << " not possible"; + } + + + + + + void OCCGeometry :: MakeSolid () + { + TopExp_Explorer exp0; + + (*testout) << "Trying to build solids ..." << endl; + cout << "Trying to build solids ..." << flush; + + BRepBuilderAPI_MakeSolid ms; + int count = 0; + for (exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next()) + { + count++; + ms.Add (TopoDS::Shell(exp0.Current())); + } + + if (!count) + { + cout << " not possible (no shells)" << endl; + return; + } + + BRepCheck_Analyzer ba(ms); + if (ba.IsValid ()) + { + Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; + sfs->Init (ms); + + sfs->SetPrecision(1e-5); + sfs->SetMaxTolerance(1e-5); + + sfs->Perform(); + + shape = sfs->Shape(); + + for (exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next()) + { + TopoDS_Solid solid = TopoDS::Solid(exp0.Current()); + TopoDS_Solid newsolid = solid; + BRepLib::OrientClosedSolid (newsolid); + Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; + rebuild->Replace(solid, newsolid, Standard_False); + + TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_SHAPE, 1); + shape = newshape; + } + + cout << " done" << endl; + } + else + cout << " not possible" << endl; + } + + + + + void OCCGeometry :: BuildVisualizationMesh (double deflection) + { + cout << "Preparing visualization (deflection = " << deflection << ") ... " << flush; + + BRepTools::Clean (shape); + // BRepMesh_IncrementalMesh:: + BRepMesh_IncrementalMesh (shape, deflection, true); + cout << "done" << endl; + } + + + + + void OCCGeometry :: CalcBoundingBox () + { + Bnd_Box bb; + BRepBndLib::Add (shape, bb); + + double x1,y1,z1,x2,y2,z2; + bb.Get (x1,y1,z1,x2,y2,z2); + Point<3> p1 = Point<3> (x1,y1,z1); + Point<3> p2 = Point<3> (x2,y2,z2); + + (*testout) << "Bounding Box = [" << p1 << " - " << p2 << "]" << endl; + boundingbox = Box<3> (p1,p2); + SetCenter(); + } + + + + + void OCCGeometry :: Project (int surfi, Point<3> & p) const + { + static int cnt = 0; + if (++cnt % 1000 == 0) cout << "Project cnt = " << cnt << endl; + + gp_Pnt pnt(p(0), p(1), p(2)); + + double u,v; + Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi))); + Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf ); + gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) ); + suval.Coord( u, v); + pnt = thesurf->Value( u, v ); + + + p = Point<3> (pnt.X(), pnt.Y(), pnt.Z()); + + } + + + + + bool OCCGeometry :: FastProject (int surfi, Point<3> & ap, double& u, double& v) const + { + gp_Pnt p(ap(0), ap(1), ap(2)); + + Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi))); + + gp_Pnt x = surface->Value (u,v); + + if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true; + + gp_Vec du, dv; + + surface->D1(u,v,x,du,dv); + + int count = 0; + + gp_Pnt xold; + gp_Vec n; + double det, lambda, mu; + + do { + count++; + + n = du^dv; + + det = Det3 (n.X(), du.X(), dv.X(), + n.Y(), du.Y(), dv.Y(), + n.Z(), du.Z(), dv.Z()); + + if (det < 1e-15) return false; + + lambda = Det3 (n.X(), p.X()-x.X(), dv.X(), + n.Y(), p.Y()-x.Y(), dv.Y(), + n.Z(), p.Z()-x.Z(), dv.Z())/det; + + mu = Det3 (n.X(), du.X(), p.X()-x.X(), + n.Y(), du.Y(), p.Y()-x.Y(), + n.Z(), du.Z(), p.Z()-x.Z())/det; + + u += lambda; + v += mu; + + xold = x; + surface->D1(u,v,x,du,dv); + + } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50); + + // (*testout) << "FastProject count: " << count << endl; + + if (count == 50) return false; + + ap = Point<3> (x.X(), x.Y(), x.Z()); + + return true; + } + + + + + void OCCGeometry :: WriteOCC_STL(char * filename) + { + cout << "writing stl..."; cout.flush(); + StlAPI_Writer writer; + writer.RelativeMode() = Standard_False; + + writer.SetDeflection(0.02); + writer.Write(shape,filename); + + cout << "done" << endl; + } + + + + // Philippose - 23/02/2009 + /* Special IGES File load function including the ability + to extract individual surface colours via the extended + OpenCascade XDE and XCAF Feature set. + */ + OCCGeometry *LoadOCC_IGES(const char *filename) + { + OCCGeometry *occgeo; + occgeo = new OCCGeometry; + + // Initiate a dummy XCAF Application to handle the IGES XCAF Document + static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication(); + + // Create an XCAF Document to contain the IGES file itself + Handle_TDocStd_Document iges_doc; + + // Check if a IGES File is already open under this handle, if so, close it to prevent + // Segmentation Faults when trying to create a new document + if(dummy_app->NbDocuments() > 0) + { + dummy_app->GetDocument(1,iges_doc); + dummy_app->Close(iges_doc); + } + dummy_app->NewDocument ("IGES-XCAF",iges_doc); + + IGESCAFControl_Reader reader; + + Standard_Integer stat = reader.ReadFile((char*)filename); + + if(stat != IFSelect_RetDone) + { + delete occgeo; + return NULL; + } + + // Enable transfer of colours + reader.SetColorMode(Standard_True); + + reader.Transfer(iges_doc); + + // Read in the shape(s) and the colours present in the IGES File + Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main()); + Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main()); + + TDF_LabelSequence iges_shapes; + iges_shape_contents->GetShapes(iges_shapes); + + // List out the available colours in the IGES File as Colour Names + TDF_LabelSequence all_colours; + iges_colour_contents->GetColors(all_colours); + PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length()); + for(int i = 1; i <= all_colours.Length(); i++) + { + Quantity_Color col; + stringstream col_rgb; + iges_colour_contents->GetColor(all_colours.Value(i),col); + col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")"; + PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str()); + } + + + // For the IGES Reader, all the shapes can be exported as one compund shape + // using the "OneShape" member + occgeo->shape = reader.OneShape(); + occgeo->face_colours = iges_colour_contents; + occgeo->changed = 1; + occgeo->BuildFMap(); + + occgeo->CalcBoundingBox(); + PrintContents (occgeo); + + return occgeo; + } + + + + + + // Philippose - 29/01/2009 + /* Special STEP File load function including the ability + to extract individual surface colours via the extended + OpenCascade XDE and XCAF Feature set. + */ + OCCGeometry * LoadOCC_STEP (const char * filename) + { + OCCGeometry * occgeo; + occgeo = new OCCGeometry; + + // Initiate a dummy XCAF Application to handle the STEP XCAF Document + static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication(); + + // Create an XCAF Document to contain the STEP file itself + Handle_TDocStd_Document step_doc; + + // Check if a STEP File is already open under this handle, if so, close it to prevent + // Segmentation Faults when trying to create a new document + if(dummy_app->NbDocuments() > 0) + { + dummy_app->GetDocument(1,step_doc); + dummy_app->Close(step_doc); + } + dummy_app->NewDocument ("STEP-XCAF",step_doc); + + STEPCAFControl_Reader reader; + + // Enable transfer of colours + reader.SetColorMode(Standard_True); + + Standard_Integer stat = reader.ReadFile((char*)filename); + + if(stat != IFSelect_RetDone) + { + delete occgeo; + return NULL; + } + + reader.Transfer(step_doc); + + // Read in the shape(s) and the colours present in the STEP File + Handle_XCAFDoc_ShapeTool step_shape_contents = XCAFDoc_DocumentTool::ShapeTool(step_doc->Main()); + Handle_XCAFDoc_ColorTool step_colour_contents = XCAFDoc_DocumentTool::ColorTool(step_doc->Main()); + + TDF_LabelSequence step_shapes; + step_shape_contents->GetShapes(step_shapes); + + // List out the available colours in the STEP File as Colour Names + TDF_LabelSequence all_colours; + step_colour_contents->GetColors(all_colours); + PrintMessage(1,"Number of colours in STEP File: ",all_colours.Length()); + for(int i = 1; i <= all_colours.Length(); i++) + { + Quantity_Color col; + stringstream col_rgb; + step_colour_contents->GetColor(all_colours.Value(i),col); + col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")"; + PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str()); + } + + + // For the STEP File Reader in OCC, the 1st Shape contains the entire + // compound geometry as one shape + occgeo->shape = step_shape_contents->GetShape(step_shapes.Value(1)); + occgeo->face_colours = step_colour_contents; + occgeo->changed = 1; + occgeo->BuildFMap(); + + occgeo->CalcBoundingBox(); + PrintContents (occgeo); + + return occgeo; + } + + + + + OCCGeometry *LoadOCC_BREP (const char *filename) + { + OCCGeometry * occgeo; + occgeo = new OCCGeometry; + + BRep_Builder aBuilder; + Standard_Boolean result = BRepTools::Read(occgeo->shape, const_cast (filename),aBuilder); + + if(!result) + { + delete occgeo; + return NULL; + } + + // Philippose - 23/02/2009 + // Fixed a bug in the OpenCascade XDE Colour handling when + // opening BREP Files, since BREP Files have no colour data. + // Hence, the face_colours Handle needs to be created as a NULL handle. + occgeo->face_colours = Handle_XCAFDoc_ColorTool(); + occgeo->face_colours.Nullify(); + occgeo->changed = 1; + occgeo->BuildFMap(); + + occgeo->CalcBoundingBox(); + PrintContents (occgeo); + + return occgeo; + } + + + void OCCGeometry :: Save (string sfilename) const + { + const char * filename = sfilename.c_str(); + if (strlen(filename) < 4) + throw NgException ("illegal filename"); + + if (strcmp (&filename[strlen(filename)-3], "igs") == 0) + { + IGESControl_Writer writer("millimeters", 1); + writer.AddShape (shape); + writer.Write (filename); + } + else if (strcmp (&filename[strlen(filename)-3], "stp") == 0) + { + STEPControl_Writer writer; + writer.Transfer (shape, STEPControl_AsIs); + writer.Write (filename); + } + else if (strcmp (&filename[strlen(filename)-3], "stl") == 0) + { + StlAPI_Writer writer; + writer.ASCIIMode() = Standard_True; + writer.Write (shape, filename); + } + else if (strcmp (&filename[strlen(filename)-4], "stlb") == 0) + { + StlAPI_Writer writer; + writer.ASCIIMode() = Standard_False; + writer.Write (shape, filename); + } + } + + + + const char * shapesname[] = + {" ", "CompSolids", "Solids", "Shells", + + "Faces", "Wires", "Edges", "Vertices"}; + + const char * shapename[] = + {" ", "CompSolid", "Solid", "Shell", + "Face", "Wire", "Edge", "Vertex"}; + + const char * orientationstring[] = + {"+", "-"}; + + + + + void OCCGeometry :: RecursiveTopologyTree (const TopoDS_Shape & sh, + stringstream & str, + TopAbs_ShapeEnum l, + bool isfree, + const char * lname) + { + if (l > TopAbs_VERTEX) return; + + TopExp_Explorer e; + int count = 0; + int count2 = 0; + + if (isfree) + e.Init(sh, l, TopAbs_ShapeEnum(l-1)); + else + e.Init(sh, l); + + for (; e.More(); e.Next()) + { + count++; + + stringstream lname2; + lname2 << lname << "/" << shapename[l] << count; + str << lname2.str() << " "; + + switch (e.Current().ShapeType()) + { + case TopAbs_SOLID: + count2 = somap.FindIndex(TopoDS::Solid(e.Current())); break; + case TopAbs_SHELL: + count2 = shmap.FindIndex(TopoDS::Shell(e.Current())); break; + case TopAbs_FACE: + count2 = fmap.FindIndex(TopoDS::Face(e.Current())); break; + case TopAbs_WIRE: + count2 = wmap.FindIndex(TopoDS::Wire(e.Current())); break; + case TopAbs_EDGE: + count2 = emap.FindIndex(TopoDS::Edge(e.Current())); break; + case TopAbs_VERTEX: + count2 = vmap.FindIndex(TopoDS::Vertex(e.Current())); break; + default: + cout << "RecursiveTopologyTree: Case " << e.Current().ShapeType() << " not handeled" << endl; + } + + int nrsubshapes = 0; + + if (l <= TopAbs_WIRE) + { + TopExp_Explorer e2; + for (e2.Init (e.Current(), TopAbs_ShapeEnum (l+1)); + e2.More(); e2.Next()) + nrsubshapes++; + } + + str << "{" << shapename[l] << " " << count2; + + if (l <= TopAbs_EDGE) + { + str << " (" << orientationstring[e.Current().Orientation()]; + if (nrsubshapes != 0) str << ", " << nrsubshapes; + str << ") } "; + } + else + str << " } "; + + RecursiveTopologyTree (e.Current(), str, TopAbs_ShapeEnum (l+1), + false, (char*)lname2.str().c_str()); + + } + } + + + + + void OCCGeometry :: GetTopologyTree (stringstream & str) + { + cout << "Building topology tree ... " << flush; + RecursiveTopologyTree (shape, str, TopAbs_COMPSOLID, false, "CompSolids"); + RecursiveTopologyTree (shape, str, TopAbs_SOLID, true, "FreeSolids"); + RecursiveTopologyTree (shape, str, TopAbs_SHELL, true, "FreeShells"); + RecursiveTopologyTree (shape, str, TopAbs_FACE, true, "FreeFaces"); + RecursiveTopologyTree (shape, str, TopAbs_WIRE, true, "FreeWires"); + RecursiveTopologyTree (shape, str, TopAbs_EDGE, true, "FreeEdges"); + RecursiveTopologyTree (shape, str, TopAbs_VERTEX, true, "FreeVertices"); + str << flush; + // cout << "done" << endl; + } + + + + + void OCCGeometry :: CheckIrregularEntities(stringstream & str) + { + ShapeAnalysis_CheckSmallFace csm; + + csm.SetTolerance (1e-6); + + TopTools_DataMapOfShapeListOfShape mapEdges; + ShapeAnalysis_DataMapOfShapeListOfReal mapParam; + TopoDS_Compound theAllVert; + + int spotfaces = 0; + int stripsupportfaces = 0; + int singlestripfaces = 0; + int stripfaces = 0; + int facessplitbyvertices = 0; + int stretchedpinfaces = 0; + int smoothpinfaces = 0; + int twistedfaces = 0; + // int edgessamebutnotidentified = 0; + + cout << "checking faces ... " << flush; + + int i; + for (i = 1; i <= fmap.Extent(); i++) + { + TopoDS_Face face = TopoDS::Face (fmap(i)); + TopoDS_Edge e1, e2; + + if (csm.CheckSpotFace (face)) + { + if (!spotfaces++) + str << "SpotFace {Spot face} "; + + (*testout) << "Face " << i << " is a spot face" << endl; + str << "SpotFace/Face" << i << " "; + str << "{Face " << i << " } "; + } + + if (csm.IsStripSupport (face)) + { + if (!stripsupportfaces++) + str << "StripSupportFace {Strip support face} "; + + (*testout) << "Face " << i << " has strip support" << endl; + str << "StripSupportFace/Face" << i << " "; + str << "{Face " << i << " } "; + } + + if (csm.CheckSingleStrip(face, e1, e2)) + { + if (!singlestripfaces++) + str << "SingleStripFace {Single strip face} "; + + (*testout) << "Face " << i << " is a single strip (edge " << emap.FindIndex(e1) + << " and edge " << emap.FindIndex(e2) << " are identical)" << endl; + str << "SingleStripFace/Face" << i << " "; + str << "{Face " << i << " (edge " << emap.FindIndex(e1) + << " and edge " << emap.FindIndex(e2) << " are identical)} "; + } + + if (csm.CheckStripFace(face, e1, e2)) + { + if (!stripfaces++) + str << "StripFace {Strip face} "; + + (*testout) << "Face " << i << " is a strip (edge " << emap.FindIndex(e1) + << " and edge " << emap.FindIndex(e2) + << " are identical)" << endl; + str << "StripFace/Face" << i << " "; + str << "{Face " << i << " (edge " << emap.FindIndex(e1) + << " and edge " << emap.FindIndex(e2) << " are identical)} "; + } + + if (int count = csm.CheckSplittingVertices(face, mapEdges, mapParam, theAllVert)) + { + if (!facessplitbyvertices++) + str << "FaceSplitByVertices {Face split by vertices} "; + + (*testout) << "Face " << i << " is split by " << count + << " vertex/vertices " << endl; + str << "FaceSplitByVertices/Face" << i << " "; + str << "{Face " << i << " (split by " << count << "vertex/vertices)} "; + } + + int whatrow, sens; + if (int type = csm.CheckPin (face, whatrow, sens)) + { + if (type == 1) + { + if (!smoothpinfaces++) + str << "SmoothPinFace {Smooth pin face} "; + + (*testout) << "Face " << i << " is a smooth pin" << endl; + str << "SmoothPinFace/Face" << i << " "; + str << "{Face " << i << " } "; + } + else + { + if (!stretchedpinfaces++) + str << "StretchedPinFace {Stretched pin face} "; + + (*testout) << "Face " << i << " is a streched pin" << endl; + str << "StretchedPinFace/Face" << i << " "; + str << "{Face " << i << " } "; + } + } + + double paramu, paramv; + if (csm.CheckTwisted (face, paramu, paramv)) + { + if (!twistedfaces++) + str << "TwistedFace {Twisted face} "; + + (*testout) << "Face " << i << " is twisted" << endl; + str << "TwistedFace/Face" << i << " "; + str << "{Face " << i << " } "; + } + } + + cout << "done" << endl; + cout << "checking edges ... " << flush; + + // double dmax; + // int cnt = 0; + Array edgeLengths; + Array order; + edgeLengths.SetSize (emap.Extent()); + order.SetSize (emap.Extent()); + + for (i = 1; i <= emap.Extent(); i++) + { + TopoDS_Edge edge1 = TopoDS::Edge (emap(i)); + GProp_GProps system; + BRepGProp::LinearProperties(edge1, system); + edgeLengths[i-1] = system.Mass(); + } + + Sort (edgeLengths, order); + + str << "ShortestEdges {Shortest edges} "; + for (i = 1; i <= min(20, emap.Extent()); i++) + { + str << "ShortestEdges/Edge" << i; + str << " {Edge " << order[i-1] << " (L=" << edgeLengths[order[i-1]-1] << ")} "; + } + + str << flush; + + cout << "done" << endl; + } + + + + + void OCCGeometry :: GetUnmeshedFaceInfo (stringstream & str) + { + for (int i = 1; i <= fmap.Extent(); i++) + { + if (facemeshstatus[i-1] == -1) + str << "Face" << i << " {Face " << i << " } "; + } + str << flush; + } + + + + + void OCCGeometry :: GetNotDrawableFaces (stringstream & str) + { + for (int i = 1; i <= fmap.Extent(); i++) + { + if (!fvispar[i-1].IsDrawable()) + str << "Face" << i << " {Face " << i << " } "; + } + str << flush; + } + + + + + bool OCCGeometry :: ErrorInSurfaceMeshing () + { + for (int i = 1; i <= fmap.Extent(); i++) + if (facemeshstatus[i-1] == -1) + return true; + + return false; + } + + + + + int OCCGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, + int perfstepsstart, int perfstepsend) + { + return OCCGenerateMesh (*this, mesh, mparam, perfstepsstart, perfstepsend); + } + + + + + const Refinement & OCCGeometry :: GetRefinement () const + { + return * new OCCRefinementSurfaces (*this); + } + + + + + OCCParameters :: OCCParameters() + { + resthcloseedgefac = 1; + resthcloseedgeenable = 1; + resthminedgelen = 0.001; + resthminedgelenenable = 1; + } + + + + + void OCCParameters :: Print(ostream & ost) const + { + ost << "OCC Parameters:" << endl + << "close edges: " << resthcloseedgeenable + << ", fac = " << resthcloseedgefac << endl + << "minimum edge length: " << resthminedgelenenable + << ", min len = " << resthminedgelen << endl; + } + + + + + OCCParameters occparam; + +} + + +#endif diff --git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp index 16b2f761..2ed92817 100644 --- a/libsrc/occ/occgeom.hpp +++ b/libsrc/occ/occgeom.hpp @@ -1,451 +1,457 @@ -#ifndef FILE_OCCGEOM -#define FILE_OCCGEOM - -/* *************************************************************************/ -/* File: occgeom.hpp */ -/* Author: Robert Gaisbauer */ -/* Date: 26. May 03 */ -/* *************************************************************************/ - -#ifdef OCCGEOMETRY - -#include - -#include "BRep_Tool.hxx" -#include "Geom_Curve.hxx" -#include "Geom2d_Curve.hxx" -#include "Geom_Surface.hxx" -#include "GeomAPI_ProjectPointOnSurf.hxx" -#include "GeomAPI_ProjectPointOnCurve.hxx" -#include "BRepTools.hxx" -#include "TopExp.hxx" -#include "BRepBuilderAPI_MakeVertex.hxx" -#include "BRepBuilderAPI_MakeShell.hxx" -#include "BRepBuilderAPI_MakeSolid.hxx" -#include "BRepOffsetAPI_Sewing.hxx" -#include "BRepLProp_SLProps.hxx" -#include "BRepAdaptor_Surface.hxx" -#include "Poly_Triangulation.hxx" -#include "Poly_Array1OfTriangle.hxx" -#include "TColgp_Array1OfPnt2d.hxx" -#include "Poly_Triangle.hxx" -#include "GProp_GProps.hxx" -#include "BRepGProp.hxx" -#include "Geom_Surface.hxx" -#include "TopExp.hxx" -#include "gp_Pnt.hxx" -#include "TopoDS.hxx" -#include "TopoDS_Solid.hxx" -#include "TopExp_Explorer.hxx" -#include "TopTools_ListIteratorOfListOfShape.hxx" -#include "BRep_Tool.hxx" -#include "Geom_Curve.hxx" -#include "Geom2d_Curve.hxx" -#include "Geom_Surface.hxx" -#include "GeomAPI_ProjectPointOnSurf.hxx" -#include "GeomAPI_ProjectPointOnCurve.hxx" -#include "TopoDS_Wire.hxx" -#include "BRepTools_WireExplorer.hxx" -#include "BRepTools.hxx" -#include "TopTools_IndexedMapOfShape.hxx" -#include "TopExp.hxx" -#include "BRepBuilderAPI_MakeVertex.hxx" -#include "BRepBuilderAPI_MakeShell.hxx" -#include "BRepBuilderAPI_MakeSolid.hxx" -#include "BRepOffsetAPI_Sewing.hxx" -#include "BRepLProp_CLProps.hxx" -#include "BRepLProp_SLProps.hxx" -#include "BRepAdaptor_Surface.hxx" -#include "BRepAdaptor_Curve.hxx" -#include "Poly_Triangulation.hxx" -#include "Poly_Array1OfTriangle.hxx" -#include "TColgp_Array1OfPnt2d.hxx" -#include "Poly_Triangle.hxx" -#include "GProp_GProps.hxx" -#include "BRepGProp.hxx" -#include "TopoDS_Shape.hxx" -#include "TopoDS_Face.hxx" -#include "IGESToBRep_Reader.hxx" -#include "Interface_Static.hxx" -#include "GeomAPI_ExtremaCurveCurve.hxx" -#include "Standard_ErrorHandler.hxx" -#include "Standard_Failure.hxx" -#include "ShapeUpgrade_ShellSewing.hxx" -#include "ShapeFix_Shape.hxx" -#include "ShapeFix_Wireframe.hxx" -#include "BRepMesh.hxx" -#include "BRepMesh_IncrementalMesh.hxx" -#include "BRepBndLib.hxx" -#include "Bnd_Box.hxx" -#include "ShapeAnalysis.hxx" -#include "ShapeBuild_ReShape.hxx" - - -// Philippose - 29/01/2009 -// OpenCascade XDE Support -// Include support for OpenCascade XDE Features -#include "TDocStd_Document.hxx" -#include "Quantity_Color.hxx" -#include "XCAFApp_Application.hxx" -#include "XCAFDoc_ShapeTool.hxx" -#include "XCAFDoc_Color.hxx" -#include "XCAFDoc_ColorTool.hxx" -#include "XCAFDoc_ColorType.hxx" -#include "XCAFDoc_LayerTool.hxx" -#include "XCAFDoc_DimTolTool.hxx" -#include "XCAFDoc_MaterialTool.hxx" -#include "XCAFDoc_DocumentTool.hxx" -#include "TDF_Label.hxx" -#include "TDF_LabelSequence.hxx" -#include "STEPCAFControl_Reader.hxx" -#include "STEPCAFControl_Writer.hxx" -#include "IGESCAFControl_Reader.hxx" -#include "IGESCAFControl_Writer.hxx" - -#include "IGESControl_Reader.hxx" -#include "STEPControl_Reader.hxx" -#include "IGESControl_Writer.hxx" -#include "STEPControl_Writer.hxx" - -#include "StlAPI_Writer.hxx" -#include "STEPControl_StepModelType.hxx" - -namespace netgen -{ -#include "occmeshsurf.hpp" - - extern DLL_HEADER MeshingParameters mparam; - -#define PROJECTION_TOLERANCE 1e-10 - -#define ENTITYISVISIBLE 1 -#define ENTITYISHIGHLIGHTED 2 -#define ENTITYISDRAWABLE 4 - -#define OCCGEOMETRYVISUALIZATIONNOCHANGE 0 -#define OCCGEOMETRYVISUALIZATIONFULLCHANGE 1 // Compute transformation matrices and redraw -#define OCCGEOMETRYVISUALIZATIONHALFCHANGE 2 // Redraw - - - - class EntityVisualizationCode - { - int code; - - public: - - EntityVisualizationCode() - { code = ENTITYISVISIBLE + !ENTITYISHIGHLIGHTED + ENTITYISDRAWABLE;} - - int IsVisible () - { return code & ENTITYISVISIBLE;} - - int IsHighlighted () - { return code & ENTITYISHIGHLIGHTED;} - - int IsDrawable () - { return code & ENTITYISDRAWABLE;} - - void Show () - { code |= ENTITYISVISIBLE;} - - void Hide () - { code &= ~ENTITYISVISIBLE;} - - void Highlight () - { code |= ENTITYISHIGHLIGHTED;} - - void Lowlight () - { code &= ~ENTITYISHIGHLIGHTED;} - - void SetDrawable () - { code |= ENTITYISDRAWABLE;} - - void SetNotDrawable () - { code &= ~ENTITYISDRAWABLE;} - }; - - - - class Line - { - public: - Point<3> p0, p1; - - double Dist (Line l); - - double Length (); - }; - - - - inline double Det3 (double a00, double a01, double a02, - double a10, double a11, double a12, - double a20, double a21, double a22) - { - return a00*a11*a22 + a01*a12*a20 + a10*a21*a02 - a20*a11*a02 - a10*a01*a22 - a21*a12*a00; - } - - - - - class OCCGeometry : public NetgenGeometry - { - Point<3> center; - - public: - TopoDS_Shape shape; - TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap; - Array fsingular, esingular, vsingular; - Box<3> boundingbox; - - // Philippose - 29/01/2009 - // OpenCascade XDE Support - // XCAF Handle to make the face colours available to the rest of - // the system - Handle_XCAFDoc_ColorTool face_colours; - - mutable int changed; - Array facemeshstatus; - - // Philippose - 15/01/2009 - // Maximum mesh size for a given face - // (Used to explicitly define mesh size limits on individual faces) - Array face_maxh; - - // Philippose - 14/01/2010 - // Boolean array to detect whether a face has been explicitly modified - // by the user or not - Array face_maxh_modified; - - // Philippose - 15/01/2009 - // Indicates which faces have been selected by the user in geometry mode - // (Currently handles only selection of one face at a time, but an array would - // help to extend this to multiple faces) - Array face_sel_status; - - Array fvispar, evispar, vvispar; - - double tolerance; - bool fixsmalledges; - bool fixspotstripfaces; - bool sewfaces; - bool makesolids; - bool splitpartitions; - - OCCGeometry() - { - somap.Clear(); - shmap.Clear(); - fmap.Clear(); - wmap.Clear(); - emap.Clear(); - vmap.Clear(); - } - - - virtual void Save (string filename) const; - - - void BuildFMap(); - - Box<3> GetBoundingBox() - { return boundingbox;} - - int NrSolids() - { return somap.Extent();} - - // Philippose - 17/01/2009 - // Total number of faces in the geometry - int NrFaces() - { return fmap.Extent();} - - void SetCenter() - { center = boundingbox.Center();} - - Point<3> Center() - { return center;} - - void Project (int surfi, Point<3> & p) const; - bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const; - - OCCSurface GetSurface (int surfi) - { - cout << "OCCGeometry::GetSurface using PLANESPACE" << endl; - return OCCSurface (TopoDS::Face(fmap(surfi)), PLANESPACE); - } - - void CalcBoundingBox (); - void BuildVisualizationMesh (double deflection); - - void RecursiveTopologyTree (const TopoDS_Shape & sh, - stringstream & str, - TopAbs_ShapeEnum l, - bool free, - const char * lname); - - void GetTopologyTree (stringstream & str); - - void PrintNrShapes (); - - void CheckIrregularEntities (stringstream & str); - - void SewFaces(); - - void MakeSolid(); - - void HealGeometry(); - - // Philippose - 15/01/2009 - // Sets the maximum mesh size for a given face - // (Note: Local mesh size limited by the global max mesh size) - void SetFaceMaxH(int facenr, double faceh) - { - if((facenr> 0) && (facenr <= fmap.Extent())) - { - face_maxh[facenr-1] = min(mparam.maxh,faceh); - - // Philippose - 14/01/2010 - // If the face maxh is greater than or equal to the - // current global maximum, then identify the face as - // not explicitly controlled by the user any more - if(faceh >= mparam.maxh) - { - face_maxh_modified[facenr-1] = 0; - } - else - { - face_maxh_modified[facenr-1] = 1; - } - } - } - - // Philippose - 15/01/2009 - // Returns the local mesh size of a given face - double GetFaceMaxH(int facenr) - { - if((facenr> 0) && (facenr <= fmap.Extent())) - { - return face_maxh[facenr-1]; - } - else - { - return 0.0; - } - } - - // Philippose - 14/01/2010 - // Returns the flag whether the given face - // has a mesh size controlled by the user or not - bool GetFaceMaxhModified(int facenr) - { - return face_maxh_modified[facenr-1]; - } - - // Philippose - 17/01/2009 - // Returns the index of the currently selected face - int SelectedFace() - { - int i; - - for(i = 1; i <= fmap.Extent(); i++) - { - if(face_sel_status[i-1]) - { - return i; - } - } - - return 0; - } - - // Philippose - 17/01/2009 - // Sets the currently selected face - void SetSelectedFace(int facenr) - { - face_sel_status = 0; - - if((facenr >= 1) && (facenr <= fmap.Extent())) - { - face_sel_status[facenr-1] = 1; - } - } - - void LowLightAll() - { - for (int i = 1; i <= fmap.Extent(); i++) - fvispar[i-1].Lowlight(); - for (int i = 1; i <= emap.Extent(); i++) - evispar[i-1].Lowlight(); - for (int i = 1; i <= vmap.Extent(); i++) - vvispar[i-1].Lowlight(); - } - - void GetUnmeshedFaceInfo (stringstream & str); - void GetNotDrawableFaces (stringstream & str); - bool ErrorInSurfaceMeshing (); - - void WriteOCC_STL(char * filename); - - virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, - int perfstepsstart, int perfstepsend); - - virtual const Refinement & GetRefinement () const; - }; - - - - class OCCParameters - { - public: - - /// Factor for meshing close edges - double resthcloseedgefac; - - - /// Enable / Disable detection of close edges - int resthcloseedgeenable; - - - - /*! - Default Constructor for the OpenCascade - Mesh generation parameter set - */ - OCCParameters(); - - - /*! - Dump all the OpenCascade specific meshing parameters - to console - */ - void Print (ostream & ost) const; - }; - - - void PrintContents (OCCGeometry * geom); - - OCCGeometry * LoadOCC_IGES (const char * filename); - OCCGeometry * LoadOCC_STEP (const char * filename); - OCCGeometry * LoadOCC_BREP (const char * filename); - - extern OCCParameters occparam; - - - // Philippose - 31.09.2009 - // External access to the mesh generation functions within the OCC - // subsystem (Not sure if this is the best way to implement this....!!) - extern int OCCGenerateMesh (OCCGeometry & occgeometry, Mesh*& mesh, - MeshingParameters & mparam, - int perfstepsstart, int perfstepsend); - - extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh); - - extern void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend); - - extern void OCCFindEdges (OCCGeometry & geom, Mesh & mesh); -} - -#endif - -#endif +#ifndef FILE_OCCGEOM +#define FILE_OCCGEOM + +/* *************************************************************************/ +/* File: occgeom.hpp */ +/* Author: Robert Gaisbauer */ +/* Date: 26. May 03 */ +/* *************************************************************************/ + +#ifdef OCCGEOMETRY + +#include + +#include "BRep_Tool.hxx" +#include "Geom_Curve.hxx" +#include "Geom2d_Curve.hxx" +#include "Geom_Surface.hxx" +#include "GeomAPI_ProjectPointOnSurf.hxx" +#include "GeomAPI_ProjectPointOnCurve.hxx" +#include "BRepTools.hxx" +#include "TopExp.hxx" +#include "BRepBuilderAPI_MakeVertex.hxx" +#include "BRepBuilderAPI_MakeShell.hxx" +#include "BRepBuilderAPI_MakeSolid.hxx" +#include "BRepOffsetAPI_Sewing.hxx" +#include "BRepLProp_SLProps.hxx" +#include "BRepAdaptor_Surface.hxx" +#include "Poly_Triangulation.hxx" +#include "Poly_Array1OfTriangle.hxx" +#include "TColgp_Array1OfPnt2d.hxx" +#include "Poly_Triangle.hxx" +#include "GProp_GProps.hxx" +#include "BRepGProp.hxx" +#include "Geom_Surface.hxx" +#include "TopExp.hxx" +#include "gp_Pnt.hxx" +#include "TopoDS.hxx" +#include "TopoDS_Solid.hxx" +#include "TopExp_Explorer.hxx" +#include "TopTools_ListIteratorOfListOfShape.hxx" +#include "BRep_Tool.hxx" +#include "Geom_Curve.hxx" +#include "Geom2d_Curve.hxx" +#include "Geom_Surface.hxx" +#include "GeomAPI_ProjectPointOnSurf.hxx" +#include "GeomAPI_ProjectPointOnCurve.hxx" +#include "TopoDS_Wire.hxx" +#include "BRepTools_WireExplorer.hxx" +#include "BRepTools.hxx" +#include "TopTools_IndexedMapOfShape.hxx" +#include "TopExp.hxx" +#include "BRepBuilderAPI_MakeVertex.hxx" +#include "BRepBuilderAPI_MakeShell.hxx" +#include "BRepBuilderAPI_MakeSolid.hxx" +#include "BRepOffsetAPI_Sewing.hxx" +#include "BRepLProp_CLProps.hxx" +#include "BRepLProp_SLProps.hxx" +#include "BRepAdaptor_Surface.hxx" +#include "BRepAdaptor_Curve.hxx" +#include "Poly_Triangulation.hxx" +#include "Poly_Array1OfTriangle.hxx" +#include "TColgp_Array1OfPnt2d.hxx" +#include "Poly_Triangle.hxx" +#include "GProp_GProps.hxx" +#include "BRepGProp.hxx" +#include "TopoDS_Shape.hxx" +#include "TopoDS_Face.hxx" +#include "IGESToBRep_Reader.hxx" +#include "Interface_Static.hxx" +#include "GeomAPI_ExtremaCurveCurve.hxx" +#include "Standard_ErrorHandler.hxx" +#include "Standard_Failure.hxx" +#include "ShapeUpgrade_ShellSewing.hxx" +#include "ShapeFix_Shape.hxx" +#include "ShapeFix_Wireframe.hxx" +#include "BRepMesh.hxx" +#include "BRepMesh_IncrementalMesh.hxx" +#include "BRepBndLib.hxx" +#include "Bnd_Box.hxx" +#include "ShapeAnalysis.hxx" +#include "ShapeBuild_ReShape.hxx" + + +// Philippose - 29/01/2009 +// OpenCascade XDE Support +// Include support for OpenCascade XDE Features +#include "TDocStd_Document.hxx" +#include "Quantity_Color.hxx" +#include "XCAFApp_Application.hxx" +#include "XCAFDoc_ShapeTool.hxx" +#include "XCAFDoc_Color.hxx" +#include "XCAFDoc_ColorTool.hxx" +#include "XCAFDoc_ColorType.hxx" +#include "XCAFDoc_LayerTool.hxx" +#include "XCAFDoc_DimTolTool.hxx" +#include "XCAFDoc_MaterialTool.hxx" +#include "XCAFDoc_DocumentTool.hxx" +#include "TDF_Label.hxx" +#include "TDF_LabelSequence.hxx" +#include "STEPCAFControl_Reader.hxx" +#include "STEPCAFControl_Writer.hxx" +#include "IGESCAFControl_Reader.hxx" +#include "IGESCAFControl_Writer.hxx" + +#include "IGESControl_Reader.hxx" +#include "STEPControl_Reader.hxx" +#include "IGESControl_Writer.hxx" +#include "STEPControl_Writer.hxx" + +#include "StlAPI_Writer.hxx" +#include "STEPControl_StepModelType.hxx" + +namespace netgen +{ +#include "occmeshsurf.hpp" + + extern DLL_HEADER MeshingParameters mparam; + +#define PROJECTION_TOLERANCE 1e-10 + +#define ENTITYISVISIBLE 1 +#define ENTITYISHIGHLIGHTED 2 +#define ENTITYISDRAWABLE 4 + +#define OCCGEOMETRYVISUALIZATIONNOCHANGE 0 +#define OCCGEOMETRYVISUALIZATIONFULLCHANGE 1 // Compute transformation matrices and redraw +#define OCCGEOMETRYVISUALIZATIONHALFCHANGE 2 // Redraw + + + + class EntityVisualizationCode + { + int code; + + public: + + EntityVisualizationCode() + { code = ENTITYISVISIBLE + !ENTITYISHIGHLIGHTED + ENTITYISDRAWABLE;} + + int IsVisible () + { return code & ENTITYISVISIBLE;} + + int IsHighlighted () + { return code & ENTITYISHIGHLIGHTED;} + + int IsDrawable () + { return code & ENTITYISDRAWABLE;} + + void Show () + { code |= ENTITYISVISIBLE;} + + void Hide () + { code &= ~ENTITYISVISIBLE;} + + void Highlight () + { code |= ENTITYISHIGHLIGHTED;} + + void Lowlight () + { code &= ~ENTITYISHIGHLIGHTED;} + + void SetDrawable () + { code |= ENTITYISDRAWABLE;} + + void SetNotDrawable () + { code &= ~ENTITYISDRAWABLE;} + }; + + + + class Line + { + public: + Point<3> p0, p1; + + double Dist (Line l); + + double Length (); + }; + + + + inline double Det3 (double a00, double a01, double a02, + double a10, double a11, double a12, + double a20, double a21, double a22) + { + return a00*a11*a22 + a01*a12*a20 + a10*a21*a02 - a20*a11*a02 - a10*a01*a22 - a21*a12*a00; + } + + + + + class OCCGeometry : public NetgenGeometry + { + Point<3> center; + + public: + TopoDS_Shape shape; + TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap; + Array fsingular, esingular, vsingular; + Box<3> boundingbox; + + // Philippose - 29/01/2009 + // OpenCascade XDE Support + // XCAF Handle to make the face colours available to the rest of + // the system + Handle_XCAFDoc_ColorTool face_colours; + + mutable int changed; + Array facemeshstatus; + + // Philippose - 15/01/2009 + // Maximum mesh size for a given face + // (Used to explicitly define mesh size limits on individual faces) + Array face_maxh; + + // Philippose - 14/01/2010 + // Boolean array to detect whether a face has been explicitly modified + // by the user or not + Array face_maxh_modified; + + // Philippose - 15/01/2009 + // Indicates which faces have been selected by the user in geometry mode + // (Currently handles only selection of one face at a time, but an array would + // help to extend this to multiple faces) + Array face_sel_status; + + Array fvispar, evispar, vvispar; + + double tolerance; + bool fixsmalledges; + bool fixspotstripfaces; + bool sewfaces; + bool makesolids; + bool splitpartitions; + + OCCGeometry() + { + somap.Clear(); + shmap.Clear(); + fmap.Clear(); + wmap.Clear(); + emap.Clear(); + vmap.Clear(); + } + + + virtual void Save (string filename) const; + + + void BuildFMap(); + + Box<3> GetBoundingBox() + { return boundingbox;} + + int NrSolids() + { return somap.Extent();} + + // Philippose - 17/01/2009 + // Total number of faces in the geometry + int NrFaces() + { return fmap.Extent();} + + void SetCenter() + { center = boundingbox.Center();} + + Point<3> Center() + { return center;} + + void Project (int surfi, Point<3> & p) const; + bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const; + + OCCSurface GetSurface (int surfi) + { + cout << "OCCGeometry::GetSurface using PLANESPACE" << endl; + return OCCSurface (TopoDS::Face(fmap(surfi)), PLANESPACE); + } + + void CalcBoundingBox (); + void BuildVisualizationMesh (double deflection); + + void RecursiveTopologyTree (const TopoDS_Shape & sh, + stringstream & str, + TopAbs_ShapeEnum l, + bool free, + const char * lname); + + void GetTopologyTree (stringstream & str); + + void PrintNrShapes (); + + void CheckIrregularEntities (stringstream & str); + + void SewFaces(); + + void MakeSolid(); + + void HealGeometry(); + + // Philippose - 15/01/2009 + // Sets the maximum mesh size for a given face + // (Note: Local mesh size limited by the global max mesh size) + void SetFaceMaxH(int facenr, double faceh) + { + if((facenr> 0) && (facenr <= fmap.Extent())) + { + face_maxh[facenr-1] = min(mparam.maxh,faceh); + + // Philippose - 14/01/2010 + // If the face maxh is greater than or equal to the + // current global maximum, then identify the face as + // not explicitly controlled by the user any more + if(faceh >= mparam.maxh) + { + face_maxh_modified[facenr-1] = 0; + } + else + { + face_maxh_modified[facenr-1] = 1; + } + } + } + + // Philippose - 15/01/2009 + // Returns the local mesh size of a given face + double GetFaceMaxH(int facenr) + { + if((facenr> 0) && (facenr <= fmap.Extent())) + { + return face_maxh[facenr-1]; + } + else + { + return 0.0; + } + } + + // Philippose - 14/01/2010 + // Returns the flag whether the given face + // has a mesh size controlled by the user or not + bool GetFaceMaxhModified(int facenr) + { + return face_maxh_modified[facenr-1]; + } + + // Philippose - 17/01/2009 + // Returns the index of the currently selected face + int SelectedFace() + { + int i; + + for(i = 1; i <= fmap.Extent(); i++) + { + if(face_sel_status[i-1]) + { + return i; + } + } + + return 0; + } + + // Philippose - 17/01/2009 + // Sets the currently selected face + void SetSelectedFace(int facenr) + { + face_sel_status = 0; + + if((facenr >= 1) && (facenr <= fmap.Extent())) + { + face_sel_status[facenr-1] = 1; + } + } + + void LowLightAll() + { + for (int i = 1; i <= fmap.Extent(); i++) + fvispar[i-1].Lowlight(); + for (int i = 1; i <= emap.Extent(); i++) + evispar[i-1].Lowlight(); + for (int i = 1; i <= vmap.Extent(); i++) + vvispar[i-1].Lowlight(); + } + + void GetUnmeshedFaceInfo (stringstream & str); + void GetNotDrawableFaces (stringstream & str); + bool ErrorInSurfaceMeshing (); + + void WriteOCC_STL(char * filename); + + virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, + int perfstepsstart, int perfstepsend); + + virtual const Refinement & GetRefinement () const; + }; + + + + class OCCParameters + { + public: + + /// Factor for meshing close edges + double resthcloseedgefac; + + + /// Enable / Disable detection of close edges + int resthcloseedgeenable; + + + /// Minimum edge length to be used for dividing edges to mesh points + double resthminedgelen; + + + /// Enable / Disable use of the minimum edge length (by default use 1e-4) + int resthminedgelenenable; + + /*! + Default Constructor for the OpenCascade + Mesh generation parameter set + */ + OCCParameters(); + + + /*! + Dump all the OpenCascade specific meshing parameters + to console + */ + void Print (ostream & ost) const; + }; + + + void PrintContents (OCCGeometry * geom); + + OCCGeometry * LoadOCC_IGES (const char * filename); + OCCGeometry * LoadOCC_STEP (const char * filename); + OCCGeometry * LoadOCC_BREP (const char * filename); + + extern OCCParameters occparam; + + + // Philippose - 31.09.2009 + // External access to the mesh generation functions within the OCC + // subsystem (Not sure if this is the best way to implement this....!!) + extern int OCCGenerateMesh (OCCGeometry & occgeometry, Mesh*& mesh, + MeshingParameters & mparam, + int perfstepsstart, int perfstepsend); + + extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh); + + extern void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend); + + extern void OCCFindEdges (OCCGeometry & geom, Mesh & mesh); +} + +#endif + +#endif diff --git a/libsrc/occ/occpkg.cpp b/libsrc/occ/occpkg.cpp index 71695e2c..5220625c 100644 --- a/libsrc/occ/occpkg.cpp +++ b/libsrc/occ/occpkg.cpp @@ -43,6 +43,10 @@ namespace netgen atof (Tcl_GetVar (interp, "::stloptions.resthcloseedgefac", 0)); occparam.resthcloseedgeenable = atoi (Tcl_GetVar (interp, "::stloptions.resthcloseedgeenable", 0)); + occparam.resthminedgelen = + atof (Tcl_GetVar (interp, "::stloptions.resthminedgelen", 0)); + occparam.resthminedgelenenable = + atoi (Tcl_GetVar (interp, "::stloptions.resthminedgelenenable", 0)); } }; diff --git a/ng/dialog.tcl b/ng/dialog.tcl index 9ecfdea0..71ac4728 100644 --- a/ng/dialog.tcl +++ b/ng/dialog.tcl @@ -1,2623 +1,2630 @@ -proc meshingoptionsdialog { } { - - set w .options_dlg - - if {[winfo exists .options_dlg] == 1} { - wm withdraw $w - wm deiconify $w - focus $w - } { - - toplevel $w - -# global options.meshsize - - tixNoteBook $w.nb -ipadx 6 -ipady 6 - - $w.nb add general -label "General" -underline 0 - $w.nb add meshsize -label "Mesh Size" -underline 0 - $w.nb add chartopt -label "STL Charts" -underline 0 - $w.nb add optimizer -label "Optimizer" -underline 0 - $w.nb add insider -label "Insider" -underline 0 - $w.nb add debug -label "Debug" -underline 0 - - - pack $w.nb -expand yes -fill both -padx 5 -pady 5 -side top - - - # General meshing options - - set f [$w.nb subwidget general] - - set finevals { 1 2 3 4 5 6 } - set finelabs(1) "very coarse" - set finelabs(2) "coarse" - set finelabs(3) "moderate" - set finelabs(4) "fine" - set finelabs(5) "very fine" - set finelabs(6) "user defined" - - tixOptionMenu $f.fine -label "Mesh granularity : " \ - -options { - label.width 19 - label.anchor e - menubutton.width 15 - } - - - foreach finev $finevals { - $f.fine add command $finev -label $finelabs($finev) - } - $f.fine config -variable meshoptions.fineness - $f.fine config -command { setgranularity } - global meshoptions.fineness -# setgranularity ${meshoptions.fineness} - pack $f.fine - - - - - - set mgsteps { ag me ms os mv ov } - set mgsteplabel(ag) "Analyze Geometry" - set mgsteplabel(me) "Mesh Edges" - set mgsteplabel(ms) "Mesh Surface" - set mgsteplabel(os) "Optimize Surface" - set mgsteplabel(mv) "Mesh Volume" - set mgsteplabel(ov) "Optimize Volume" - - - tixOptionMenu $f.first -label "First Step : " \ - -options { - label.width 19 - label.anchor e - menubutton.width 15 - } - - tixOptionMenu $f.last -label "Last Step : " \ - -options { - label.width 19 - label.anchor e - menubutton.width 15 - } - - foreach step $mgsteps { - $f.first add command $step -label $mgsteplabel($step) - $f.last add command $step -label $mgsteplabel($step) - } - - $f.first config -variable meshoptions.firststep - $f.last config -variable meshoptions.laststep - - pack $f.first $f.last - - - - - - set msg(0) "None" - set msg(1) "Least" - set msg(2) "Little" - set msg(3) "Moderate" - set msg(4) "Much" - set msg(5) "Most" - - tixOptionMenu $f.msg -label "Print Messages : " \ - -options { - label.width 19 - label.anchor e - menubutton.width 15 - } - - foreach step {0 1 2 3 4 5 } { - $f.msg add command $step -label $msg($step) - } - - $f.msg config -variable options.printmsg - pack $f.msg - - - - - - - - - checkbutton $f.parthread -text "Parallel meshing thread" \ - -variable options.parthread - checkbutton $f.second -text "Second order elements" \ - -variable options.secondorder - checkbutton $f.quad -text "Quad dominated" \ - -variable options.quad -command { - if { ${options.quad} } { - set meshoptions.laststep os - } - } - checkbutton $f.invtets -text "Invert volume elements" \ - -variable options.inverttets - checkbutton $f.invtrigs -text "Invert surface elements" \ - -variable options.inverttrigs - checkbutton $f.azref -text "Automatic Z-refinement" \ - -variable options.autozrefine - - pack $f.parthread $f.second $f.quad $f.invtets $f.invtrigs $f.azref - - - - tixControl $f.elementorder -label "Element order: " -integer true \ - -variable options.elementorder -min 1 -max 20 \ - -options { - entry.width 2 - label.width 20 - label.anchor e - } - - pack $f.elementorder - - -# tixControl $f.memory -label "Large Memory \[MB\]: " -integer true \ -\# -variable options.memory -min 0 -max 2000 \ -\# -options { -# entry.width 5 -# label.width 20 -# label.anchor e -# } - -# global userlevel -# if { $userlevel >= 3} { pack $f.memory } - - - # Mesh - Size options - set f [$w.nb subwidget meshsize] - - tixControl $f.meshsize -label "max mesh-size: " -integer false \ - -variable options.meshsize -min 1e-9 -max 1e6 \ - -options { - entry.width 6 - label.width 25 - label.anchor e - } - - tixControl $f.minmeshsize -label "min mesh-size: " -integer false \ - -variable options.minmeshsize -min 0 -max 1e6 \ - -options { - entry.width 6 - label.width 25 - label.anchor e - } - - tixControl $f.grading -label "mesh-size grading: " -integer false \ - -variable options.grading -min 0.1 -max 1 -step 0.1 \ - -options { - entry.width 6 - label.width 25 - label.anchor e - } - - pack $f.meshsize $f.minmeshsize $f.grading - - - - frame $f.msf - pack $f.msf - - tixLabelEntry $f.msf.ent -label "mesh-size file: " \ - -labelside top \ - -options { - entry.textVariable options.meshsizefilename - entry.width 35 - label.width 25 - label.anchor w - } - button $f.msf.btn -text "Browse" -command { - global options.meshsizefilename - set types { - {"Meshsize file" {.msz} } } - set options.meshsizefilename [tk_getOpenFile -filetypes $types -initialfile ${options.meshsizefilename}] - } - - pack $f.msf.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 - pack $f.msf.btn -side left -anchor s -padx 4 -pady 4 - - - label $f.lab -text "Additional mesh size restrictions:" - - #csg-meshsize options - - frame $f.csg -relief groove -borderwidth 3 - pack $f.csg -fill x - - - frame $f.csg.curv - pack $f.csg.curv -anchor w - - scale $f.csg.curv.sc -orient horizontal -length 200 -from 0.2 -to 5 \ - -resolution 0.1 -variable options.curvaturesafety - label $f.csg.curv.la -text "Elements per curvature radius" - pack $f.csg.curv.sc $f.csg.curv.la -side left - - frame $f.csg.elen - pack $f.csg.elen -anchor w - scale $f.csg.elen.sc -orient horizontal -length 200 -from 0.2 -to 5 \ - -resolution 0.1 -variable options.segmentsperedge - label $f.csg.elen.la -text "Elements per edge" - pack $f.csg.elen.sc $f.csg.elen.la -side left - - - #stl-meshsize options - - frame $f.stl -relief groove -borderwidth 3 - pack $f.stl -fill x - - frame $f.stl.r2 - pack $f.stl.r2 -anchor w - scale $f.stl.r2.sc -orient horizontal -length 200 -from 0.2 -to 5 \ - -resolution 0.1 -variable stloptions.resthchartdistfac - checkbutton $f.stl.r2.bu -text "STL - chart distance" \ - -variable stloptions.resthchartdistenable - pack $f.stl.r2.sc $f.stl.r2.bu -side left - - frame $f.stl.r6 - pack $f.stl.r6 -anchor w - scale $f.stl.r6.sc -orient horizontal -length 200 -from 0.2 -to 5 \ - -resolution 0.1 -variable stloptions.resthlinelengthfac - checkbutton $f.stl.r6.bu -text "STL - line length" \ - -variable stloptions.resthlinelengthenable - pack $f.stl.r6.sc $f.stl.r6.bu -side left - - frame $f.stl.r3 - pack $f.stl.r3 -anchor w - scale $f.stl.r3.sc -orient horizontal -length 200 -from 0.2 -to 8 \ - -resolution 0.1 -variable stloptions.resthcloseedgefac - checkbutton $f.stl.r3.bu -text "STL/IGES/STEP - close edges" \ - -variable stloptions.resthcloseedgeenable - - pack $f.stl.r3.sc $f.stl.r3.bu -side left - - frame $f.stl.r1 - pack $f.stl.r1 -anchor w - scale $f.stl.r1.sc -orient horizontal -length 200 -from 0.2 -to 5 \ - -resolution 0.1 -variable stloptions.resthsurfcurvfac - checkbutton $f.stl.r1.bu -text "STL - surface curvature" \ - -variable stloptions.resthsurfcurvenable - pack $f.stl.r1.sc $f.stl.r1.bu -side left - - frame $f.stl.r3b - pack $f.stl.r3b -anchor w - scale $f.stl.r3b.sc -orient horizontal -length 200 -from 0.2 -to 5 \ - -resolution 0.1 -variable stloptions.resthedgeanglefac - checkbutton $f.stl.r3b.bu -text "STL - edge angle" \ - -variable stloptions.resthedgeangleenable - pack $f.stl.r3b.sc $f.stl.r3b.bu -side left - - frame $f.stl.r5 - pack $f.stl.r5 -anchor w - scale $f.stl.r5.sc -orient horizontal -length 200 -from 0.2 -to 5 \ - -resolution 0.1 -variable stloptions.resthsurfmeshcurvfac - checkbutton $f.stl.r5.bu -text "STL - surface mesh curv" \ - -variable stloptions.resthsurfmeshcurvenable - pack $f.stl.r5.sc $f.stl.r5.bu -side left - - - checkbutton $f.stl.recalch -text "STL - Recalc mesh size for surface optimization" \ - -variable stloptions.recalchopt - pack $f.stl.recalch - - button $f.stl.calch -text "Calc New H" -command { redraw; Ng_STLCalcLocalH } - pack $f.stl.calch - - - - - - - set f [$w.nb subwidget chartopt] - - - label $f.lab1 -text "Yellow Edges Angle ()" - scale $f.scale1 -orient horizontal -length 300 \ - -from 0 -to 90 -resolution 1 -tickinterval 10 \ - -variable stloptions.yangle - - pack $f.lab1 $f.scale1 - - label $f.lab2e -text "Edge Corner Angle ()" - scale $f.scale2e -orient horizontal -length 360 -from 0 -to 180 \ - -resolution 1 -tickinterval 20 \ - -variable stloptions.edgecornerangle - pack $f.lab2e $f.scale2e - - label $f.lab2 -text "Chart Angle ()" - scale $f.scale2 -orient horizontal -length 360 -from 0 -to 180 \ - -resolution 1 -tickinterval 20 \ - -variable stloptions.chartangle - pack $f.lab2 $f.scale2 - - label $f.lab2b -text "Outer Chart Angle ()" - scale $f.scale2b -orient horizontal -length 360 -from 0 -to 180 \ - -resolution 1 -tickinterval 20 \ - -variable stloptions.outerchartangle - pack $f.lab2b $f.scale2b - - - - - # Optimization options - - set f [$w.nb subwidget optimizer] - - - - - tixControl $f.os2d -label "Surface opt steps: " -integer true \ - -variable options.optsteps2d -min 0 -max 99 -step 1 \ - -options { - entry.width 3 - label.width 25 - label.anchor e - } - - tixControl $f.os3d -label "Volume opt steps: " -integer true \ - -variable options.optsteps3d -min 0 -max 99 -step 1 \ - -options { - entry.width 3 - label.width 25 - label.anchor e - } - - tixControl $f.elw -label "Element size weight: " -integer false \ - -variable options.elsizeweight -min 0 -max 1 -step 0.1 \ - -options { - entry.width 3 - label.width 25 - label.anchor e - } - - tixControl $f.wem -label "Worst element measure: " -integer false \ - -variable options.opterrpow -min 1 -max 10 -step 1 \ - -options { - entry.width 3 - label.width 25 - label.anchor e - } - - pack $f.os2d $f.os3d $f.elw $f.wem - - frame $f.badellimit - pack $f.badellimit -fill x - label $f.badellimit.lab -text "bad element criterion"; - scale $f.badellimit.scale -orient horizontal -length 150 \ - -from 160 -to 180 -resolution 1 \ - -variable options.badellimit - pack $f.badellimit.scale $f.badellimit.lab -side right -anchor s - - - # insider options - set f [$w.nb subwidget insider] - - - - checkbutton $f.localh -text "Use Local Meshsize" \ - -variable options.localh - checkbutton $f.delauney -text "Use Delaunay" \ - -variable options.delaunay - checkbutton $f.checkoverlap -text "Check Overlapping" \ - -variable options.checkoverlap - checkbutton $f.checkcb -text "Check Chart Boundary" \ - -variable options.checkchartboundary - checkbutton $f.blockfill -text "Do Blockfilling" \ - -variable options.blockfill - - pack $f.localh $f.delauney $f.checkoverlap $f.blockfill $f.checkcb -anchor w - - - - - # debugging options - set f [$w.nb subwidget debug] - - frame $f.cb - pack $f.cb -side top - - - - checkbutton $f.cb.slowchecks -text "Slow checks" \ - -variable debug.slowchecks -command { Ng_SetDebugParameters } - checkbutton $f.cb.debugoutput -text "Debugging outout" \ - -variable debug.debugoutput -command { Ng_SetDebugParameters } - checkbutton $f.cb.haltexline -text "Halt on exising line" \ - -variable debug.haltexistingline -command { Ng_SetDebugParameters } - checkbutton $f.cb.haltoverlap -text "Halt on Overlap" \ - -variable debug.haltoverlap -command { Ng_SetDebugParameters } - checkbutton $f.cb.haltsuc -text "Halt on success" \ - -variable debug.haltsuccess -command { Ng_SetDebugParameters } - checkbutton $f.cb.haltnosuc -text "Halt on no success" \ - -variable debug.haltnosuccess -command { Ng_SetDebugParameters } - checkbutton $f.cb.haltlargequal -text "Halt on large quality class" \ - -variable debug.haltlargequalclass -command { Ng_SetDebugParameters } - checkbutton $f.cb.haltseg -text "Halt on Segment:" \ - -variable debug.haltsegment -command { Ng_SetDebugParameters } - checkbutton $f.cb.haltnode -text "Halt on Node:" \ - -variable debug.haltnode -command { Ng_SetDebugParameters } - - - pack $f.cb.slowchecks $f.cb.debugoutput $f.cb.haltexline $f.cb.haltoverlap $f.cb.haltsuc $f.cb.haltnosuc $f.cb.haltlargequal $f.cb.haltseg $f.cb.haltnode - - frame $f.cb.hf - pack $f.cb.hf -pady 5 - checkbutton $f.cb.hf.cb -text "Halt on Face:" \ - -variable debug.haltface -command { Ng_SetDebugParameters } - entry $f.cb.hf.ent -textvariable debug.haltfacenr -width 5 - pack $f.cb.hf.cb $f.cb.hf.ent -side left - - checkbutton $f.cb.showactivechart -text "Show Active Meshing-Chart" \ - -variable stloptions.showactivechart -command { Ng_SetVisParameters; redraw } - - - - - pack $f.cb.showactivechart - - - frame $f.segs - pack $f.segs -pady 5 - label $f.segs.lab1 -text "P1:"; - entry $f.segs.ent1 -width 8 -relief sunken \ - -textvariable debug.haltsegmentp1 - label $f.segs.lab2 -text "P2:"; - entry $f.segs.ent2 -width 8 -relief sunken \ - -textvariable debug.haltsegmentp2 - pack $f.segs.lab1 $f.segs.ent1 $f.segs.lab2 $f.segs.ent2 -side left - - - - frame $f.cont -relief groove -borderwidth 3 - pack $f.cont - #-fill x - - checkbutton $f.cont.multidrawing -text "Draw Meshing" \ - -variable multithread_drawing - pack $f.cont.multidrawing - - checkbutton $f.cont.multitestmode -text "Meshing Testmode" \ - -variable multithread_testmode - pack $f.cont.multitestmode - - button $f.cont.goon -text "Go On" -command { set multithread_pause 0 } - pack $f.cont.multidrawing $f.cont.multitestmode $f.cont.goon -side left -expand yes - - - - - global userlevel - if { $userlevel < 3} { - $w.nb delete insider - $w.nb delete debug - } - - - -# tixButtonBox $w.bbox -orientation horizontal -# $w.bbox add ok -text Apply -underline 0 -width 5 \ -# -command { -# [.options_dlg.nb subwidget meshsize].meshsize invoke -# [.options_dlg.nb subwidget meshsize].grading invoke -# [.options_dlg.nb subwidget optimizer].os2d invoke -# [.options_dlg.nb subwidget optimizer].os3d invoke -# [.options_dlg.nb subwidget optimizer].elw invoke -# [.options_dlg.nb subwidget optimizer].wem invoke - -# Ng_SetMeshingParameters -# } - -# $w.bbox add close -text Done -underline 0 -width 5 \ -# -command { -# [.options_dlg.nb subwidget meshsize].meshsize invoke -# [.options_dlg.nb subwidget meshsize].grading invoke -# [.options_dlg.nb subwidget optimizer].os2d invoke -# [.options_dlg.nb subwidget optimizer].os3d invoke -# [.options_dlg.nb subwidget optimizer].elw invoke -# [.options_dlg.nb subwidget optimizer].wem invoke - -# Ng_SetMeshingParameters -# destroy .options_dlg -# } - -# pack $w.bbox -side bottom -fill x - - - frame $w.bu - pack $w.bu -fill x -ipady 3 - - button $w.bu.apl -text "Apply" -command { - [.options_dlg.nb subwidget meshsize].meshsize invoke - [.options_dlg.nb subwidget meshsize].grading invoke - [.options_dlg.nb subwidget optimizer].os2d invoke - [.options_dlg.nb subwidget optimizer].os3d invoke - [.options_dlg.nb subwidget optimizer].elw invoke - [.options_dlg.nb subwidget optimizer].wem invoke - - Ng_SetMeshingParameters - Ng_SetDebugParameters - } - - button $w.bu.ok -text "Done" -command { - [.options_dlg.nb subwidget meshsize].meshsize invoke - [.options_dlg.nb subwidget meshsize].grading invoke - [.options_dlg.nb subwidget optimizer].os2d invoke - [.options_dlg.nb subwidget optimizer].os3d invoke - [.options_dlg.nb subwidget optimizer].elw invoke - [.options_dlg.nb subwidget optimizer].wem invoke - - Ng_SetMeshingParameters - Ng_SetDebugParameters - wm withdraw .options_dlg -# destroy .options_dlg - } - - pack $w.bu.apl $w.bu.ok -side left -expand yes - - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Meshing Options" - focus .options_dlg - } -} - - -meshingoptionsdialog -wm withdraw .options_dlg - - - - - - - - - -# -# -# Viewing dialog -# -# -proc viewingoptionsdialog { } { - - global userlevel - - set w .viewopts_dlg - - if {[winfo exists .viewopts_dlg] == 1} { - wm withdraw $w - wm deiconify $w - focus $w - } { - toplevel $w - - - - - tixNoteBook $w.nb -ipadx 6 -ipady 6 - - $w.nb add general -label "General" -underline 0 - $w.nb add stl -label "STL" -underline 0 - $w.nb add occ -label "IGES/STEP" -underline 0 - $w.nb add mesh -label "Mesh" -underline 0 - $w.nb add light -label "Light" -underline 0 - $w.nb add edges -label "Edges" -underline 0 - $w.nb add misc -label "Misc." -underline 3 - - - pack $w.nb -expand yes -fill both -padx 5 -pady 5 -side top - - - - - - # general - set f [$w.nb subwidget general] - - checkbutton $f.backcol -text "White Background" \ - -variable viewoptions.whitebackground \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $f.cross -text "Draw Coordinate Cross" \ - -variable viewoptions.drawcoordinatecross \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $f.color -text "Draw Color-bar" \ - -variable viewoptions.drawcolorbar \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $f.netgen -text "Draw Netgen-logo" \ - -variable viewoptions.drawnetgenlogo \ - -command { Ng_SetVisParameters; redraw } - - pack $f.backcol $f.cross $f.color $f.netgen - -# checkbutton $f.stereo -text "Stereo View" \ -# -variable viewoptions.stereo \ -# -command { Ng_SetVisParameters; redraw } -# pack $f.stereo - - # stl geometry - set f [$w.nb subwidget stl] - - frame $f.show -relief groove -borderwidth 3 - pack $f.show - checkbutton $f.show.showtrias -text "Show STL-Triangles" \ - -variable stloptions.showtrias -command { Ng_SetVisParameters; redraw } - pack $f.show.showtrias -anchor w - - checkbutton $f.show.showfilledtrias -text "Show Filled Triangles" \ - -variable stloptions.showfilledtrias -command { Ng_SetVisParameters; redraw } - pack $f.show.showfilledtrias -anchor w - - checkbutton $f.show.showactivechart -text "Show Active Meshing-Chart" \ - -variable stloptions.showactivechart -command { Ng_SetVisParameters; redraw } - pack $f.show.showactivechart -anchor w - - checkbutton $f.show.showedges -text "Show Edges" \ - -variable stloptions.showedges -command { Ng_SetVisParameters; redraw } - pack $f.show.showedges -anchor w - - frame $f.special -relief groove -borderwidth 3 - pack $f.special - checkbutton $f.special.showmarktrias -text "Show Chart Triangles" \ - -variable stloptions.showmarktrias \ - -command {set stldoctor.showfaces 0; Ng_STLDoctor; Ng_SetVisParameters; redraw } - pack $f.special.showmarktrias -side left - - checkbutton $f.special.showfaces -text "Show Faces" \ - -variable stldoctor.showfaces \ - -command {set stloptions.showmarktrias 0; Ng_STLDoctor; Ng_SetVisParameters; redraw} - pack $f.special.showfaces -side left - - frame $f.fn -relief groove -borderwidth 3 - pack $f.fn - label $f.fn.lab3 -text "Chart/Face number:" - scale $f.fn.scale3 -orient horizontal -length 200 -from 0 -to 200 \ - -resolution 1 -tickinterval 50 \ - -command { Ng_SetVisParameters; redraw } -variable stloptions.chartnumber - pack $f.fn.lab3 $f.fn.scale3 -side left - - frame $f.fo -relief groove -borderwidth 3 - pack $f.fo - label $f.fo.lab -text "Chart/Face Offset:"; - entry $f.fo.ent -width 5 -relief sunken \ - -textvariable stloptions.chartnumberoffset - pack $f.fo.lab $f.fo.ent -side left - - frame $f.mt - pack $f.mt -fill x - checkbutton $f.mt.bu -text "Show Marked (Dirty) Triangles" \ - -variable stldoctor.showmarkedtrigs \ - -command {Ng_STLDoctor; redraw} - pack $f.mt.bu - - frame $f.ep - pack $f.ep -fill x - checkbutton $f.ep.bu -text "show edge corner points" \ - -variable stldoctor.showedgecornerpoints \ - -command {Ng_STLDoctor; redraw} - pack $f.ep.bu - - frame $f.stt - pack $f.stt -fill x - checkbutton $f.stt.bu -text "show touched triangle chart" \ - -variable stldoctor.showtouchedtrigchart \ - -command {set stldoctor.showfaces 0; set stloptions.showmarktrias 1; \ - Ng_STLDoctor; Ng_SetVisParameters; redraw} - pack $f.stt.bu - - frame $f.sml - pack $f.sml -fill x - checkbutton $f.sml.bu -text "draw meshed edges" \ - -variable stldoctor.drawmeshededges \ - -command {Ng_STLDoctor;} - pack $f.sml.bu - - - frame $f.sm - pack $f.sm -fill x - checkbutton $f.sm.bu -text "select with mouse" \ - -variable stldoctor.selectwithmouse - pack $f.sm.bu - - frame $f.st -relief groove -borderwidth 3 - pack $f.st -fill x - label $f.st.lab -text "Select triangle by number"; - entry $f.st.ent -width 5 -relief sunken \ - -textvariable stldoctor.selecttrig - pack $f.st.ent $f.st.lab -side left -expand yes - - frame $f.vc -relief groove -borderwidth 3 - pack $f.vc -fill x - checkbutton $f.vc.bu -text "show vicinity" \ - -variable stldoctor.showvicinity \ - -command {Ng_STLDoctor vicinity; redraw} - label $f.vc.lab -text "vicinity size"; - scale $f.vc.sc -orient horizontal -length 200 -from 0 -to 200 \ - -resolution 1 -variable stldoctor.vicinity \ - -command { Ng_STLDoctor vicinity; redraw } - pack $f.vc.bu $f.vc.lab $f.vc.sc -expand yes - - - - # IGES/STEP - set f [$w.nb subwidget occ] - - checkbutton $f.occshowsurfaces -text "Show surfaces " \ - -variable occoptions.showsurfaces \ - -command { Ng_SetOCCVisParameters; redraw } - - checkbutton $f.occshowedges -text "Show edges " \ - -variable occoptions.showedges \ - -command { Ng_SetOCCVisParameters; redraw } - - frame $f.deflection -relief groove -borderwidth 3 - pack $f.deflection -fill x - button $f.deflection.lab -text "Rebuild visualization data" \ - -command { - Ng_SetOCCVisParameters - Ng_OCCCommand buildvisualizationmesh - redraw - } - - tixControl $f.deflection.ent -label "Visualization smoothness" -integer false \ - -variable occoptions.deflection -min 0.1 -max 3 -step 0.1 \ - -options { entry.width 3 } \ - -command { Ng_SetOCCVisParameters } - - - - - - pack $f.deflection.ent $f.deflection.lab -side left -expand yes - pack $f.occshowsurfaces $f.occshowedges - - - # ACIS visualization / construction - - tixControl $f.showsolid -label "Show solid (0 for all)" -integer true \ - -variable occoptions.showsolidnr -min 0 -max 999 \ - -options { entry.width 3 } \ - -command { Ng_SetOCCVisParameters; redraw } - - tixControl $f.showsolid2 -label "Show solid 2" -integer true \ - -variable occoptions.showsolidnr2 -min 0 -max 999 \ - -options { entry.width 3 } \ - -command { Ng_SetOCCVisParameters; redraw } - - button $f.subtract -text "Subtract (2 minus 1)" \ - -command { - Ng_ACISCommand subtract ${occoptions.showsolidnr} ${occoptions.showsolidnr2} - redraw - } - - button $f.combine -text "Combine all" \ - -command { - Ng_ACISCommand combineall - redraw - } - - pack $f.showsolid $f.showsolid2 $f.subtract $f.combine - - - - - # mesh options - set f [$w.nb subwidget mesh] - - checkbutton $f.showcolor -text "Colored Meshsize Visualization" \ - -variable viewoptions.colormeshsize \ - -command { Ng_SetVisParameters; redraw } - - - checkbutton $f.showfilledtrigs -text "Show filled triangles" \ - -variable viewoptions.drawfilledtrigs \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $f.showedges -text "Show edges" \ - -variable viewoptions.drawedges \ - -command { Ng_SetVisParameters; redraw } - - - checkbutton $f.showoutline -text "Show Triangle Outline" \ - -variable viewoptions.drawoutline \ - -command { Ng_SetVisParameters; redraw } - - - tixControl $f.subdiv -label "Subdivision" -integer true \ - -variable visoptions.subdivisions -min 0 -max 8 \ - -options { entry.width 2 } \ - -command { Ng_SetVisParameters; Ng_Vis_Set parameters; Ng_SetNextTimeStamp; redraw } - - - checkbutton $f.showbadels -text "Show bad elements" \ - -variable viewoptions.drawbadels \ - -command { Ng_SetVisParameters; redraw } - - - - checkbutton $f.showprisms -text "Show prisms" \ - -variable viewoptions.drawprisms \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $f.showpyramids -text "Show pyramids" \ - -variable viewoptions.drawpyramids \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $f.showhexes -text "Show hexes" \ - -variable viewoptions.drawhexes \ - -command { Ng_SetVisParameters; redraw } - - frame $f.fshrink - label $f.fshrink.lab -text "Shrink elements" - scale $f.fshrink.scale -orient horizontal -length 200 -from 0 -to 1.0001 \ - -resolution 0.01 -tickinterval 0.25 \ - -command { Ng_SetVisParameters; redraw } -variable viewoptions.shrink - - - checkbutton $f.showidentified -text "Show identified points" \ - -variable viewoptions.drawidentified \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $f.showmetispartition -text "Show METIS Partition" \ - -variable viewoptions.drawmetispartition \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $f.showpointnumbers -text "Show Point-numbers" \ - -variable viewoptions.drawpointnumbers \ - -command { Ng_SetVisParameters; redraw } - checkbutton $f.showedgenumbers -text "Show Edge-numbers" \ - -variable viewoptions.drawedgenumbers \ - -command { Ng_SetVisParameters; redraw } - checkbutton $f.showfacenumbers -text "Show Face-numbers" \ - -variable viewoptions.drawfacenumbers \ - -command { Ng_SetVisParameters; redraw } - checkbutton $f.showelementnumbers -text "Show Element-numbers" \ - -variable viewoptions.drawelementnumbers \ - -command { Ng_SetVisParameters; redraw } - - # label $f.showdomainlab -text "Domain Surface" -# scale $f.showdomain -orient horizontal -length 100 -from 0 -to 50 \ - -resolution 1 -variable viewoptions.drawdomainsurf \ - -command { Ng_SetVisParameters; redraw } \ - -label "Domain Surface" - - tixControl $f.showdomain -label "Show surface of domain" -integer true \ - -variable viewoptions.drawdomainsurf -min 0 -max 50 \ - -options { entry.width 2 } \ - -command { Ng_SetVisParameters; Ng_Vis_Set parameters; redraw } - - - - - frame $f.center -relief groove -borderwidth 3 - pack $f.center -fill x - button $f.center.lab -text "Set Center Point" \ - -command { Ng_SetVisParameters; Ng_Center; redraw } - entry $f.center.ent -width 5 -relief sunken \ - -textvariable viewoptions.centerpoint - pack $f.center.ent $f.center.lab -side left -expand yes - - frame $f.drawel -relief groove -borderwidth 3 - pack $f.drawel -fill x - button $f.drawel.lab -text "Draw Element" \ - -command { Ng_SetVisParameters; Ng_ZoomAll; redraw } - entry $f.drawel.ent -width 5 -relief sunken \ - -textvariable viewoptions.drawelement - pack $f.drawel.ent $f.drawel.lab -side left -expand yes - - pack $f.showfilledtrigs - pack $f.showoutline $f.subdiv $f.showedges $f.showbadels - # pack $f.showdomainlab - pack $f.showdomain - pack $f.showpointnumbers - pack $f.showedgenumbers $f.showfacenumbers $f.showelementnumbers - pack $f.showmetispartition - - - frame $f.frametets - checkbutton $f.frametets.showtets -text "Show Tets in domain " \ - -variable viewoptions.drawtets \ - -command { Ng_SetVisParameters; redraw } - tixControl $f.frametets.showtetsdomain -label "" -integer true \ - -variable viewoptions.drawtetsdomain -min 0 -max 500 \ - -options { entry.width 2 } \ - -command { Ng_SetVisParameters; redraw } - - pack $f.frametets - pack $f.frametets.showtets $f.frametets.showtetsdomain -side left - - - pack $f.showcolor $f.showpyramids $f.showprisms $f.showhexes $f.showidentified - - pack $f.fshrink - pack $f.fshrink.lab $f.fshrink.scale -side left - -# if {$userlevel == 3} { -# frame $f.framecurveproj -# checkbutton $f.framecurveproj.showcurveproj -text "Show curved edge projection " \ - -variable viewoptions.drawcurveproj \ - -command { Ng_SetVisParameters; redraw } - # tixControl $f.framecurveproj.showcurveprojedge -label "" -integer true \ - -variable viewoptions.drawcurveprojedge -min 1 -max 99999 \ - -options { entry.width 5 } \ - -command { Ng_SetVisParameters; redraw } - -# pack $f.framecurveproj -# pack $f.framecurveproj.showcurveproj $f.framecurveproj.showcurveprojedge -side left -# } - - - - - - - # light options - set f [$w.nb subwidget light] - - label $f.lab1 -text "Ambient Light" - scale $f.scale1 -orient horizontal -length 300 -from 0 -to 1 \ - -resolution 0.01 -tickinterval 0.2 \ - -command { Ng_SetVisParameters; redraw } -variable viewoptions.light.amb - label $f.lab2 -text "Diffuse Light" - scale $f.scale2 -orient horizontal -length 300 -from 0 -to 1 \ - -resolution 0.01 -tickinterval 0.2 \ - -command { Ng_SetVisParameters; redraw } -variable viewoptions.light.diff - label $f.lab3 -text "Specular Light" - scale $f.scale3 -orient horizontal -length 300 -from 0 -to 1 \ - -resolution 0.01 -tickinterval 0.2 \ - -command { Ng_SetVisParameters; redraw } -variable viewoptions.light.spec - label $f.lab4 -text "Material Shininess" - scale $f.scale4 -orient horizontal -length 300 -from 0 -to 128 \ - -resolution 1 -tickinterval 32 \ - -command { Ng_SetVisParameters; redraw } -variable viewoptions.mat.shininess - label $f.lab5 -text "Material Transparency" - scale $f.scale5 -orient horizontal -length 300 -from 0 -to 1 \ - -resolution 0.01 -tickinterval 0.2 \ - -command { Ng_SetVisParameters; redraw } -variable viewoptions.mat.transp - - pack $f.lab1 $f.scale1 $f.lab2 $f.scale2 $f.lab3 $f.scale3 $f.lab4 $f.scale4 $f.lab5 $f.scale5 - - - - - - # edges options - set f [$w.nb subwidget edges] - - checkbutton $f.showedges -text "Show Edges" \ - -variable viewoptions.drawededges \ - -command { Ng_SetVisParameters; redraw } - checkbutton $f.showpoints -text "Show Points" \ - -variable viewoptions.drawedpoints \ - -command { Ng_SetVisParameters; redraw } - checkbutton $f.showpointnrs -text "Show Points Nrs" \ - -variable viewoptions.drawedpointnrs \ - -command { Ng_SetVisParameters; redraw } - checkbutton $f.showtang -text "Show CP Tangents" \ - -variable viewoptions.drawedtangents \ - -command { Ng_SetVisParameters; redraw } - checkbutton $f.drawedgenrs -text "Show Edge Nrs" \ - -variable viewoptions.drawededgenrs \ - -command { Ng_SetVisParameters; redraw } - - pack $f.showedges $f.showpoints $f.showpointnrs $f.showtang $f.drawedgenrs - - frame $f.center -relief groove -borderwidth 3 - pack $f.center -fill x - button $f.center.lab -text "Set Center Point" \ - -command { Ng_SetVisParameters; Ng_Center; redraw } - entry $f.center.ent -width 5 -relief sunken \ - -textvariable viewoptions.centerpoint - pack $f.center.ent $f.center.lab -side left -expand yes - - - - frame $f.f1 - pack $f.f1 -pady 5 - label $f.f1.lab -text "SpecPoint Veclen" - entry $f.f1.ent -width 5 -relief sunken -textvariable viewoptions.specpointvlen - pack $f.f1.lab $f.f1.ent - - - - - # misc options - set f [$w.nb subwidget misc] - - frame $f.point -relief groove -borderwidth 3 - - frame $f.point.dp - - checkbutton $f.point.dp.drawpoint -text "Draw Point" \ - -variable viewoptions.drawspecpoint \ - -command { Ng_SetVisParameters; redraw } - - entry $f.point.dp.px -width 8 -relief sunken -textvariable viewoptions.specpointx - entry $f.point.dp.py -width 8 -relief sunken -textvariable viewoptions.specpointy - entry $f.point.dp.pz -width 8 -relief sunken -textvariable viewoptions.specpointz - - pack $f.point.dp.drawpoint $f.point.dp.px $f.point.dp.py $f.point.dp.pz -side left - - pack $f.point.dp - - checkbutton $f.point.center -text "Use as Center" \ - -variable viewoptions.usecentercoords \ - -command { - if { ${viewoptions.usecentercoords} } { - set viewoptions.centerx ${viewoptions.specpointx} - set viewoptions.centery ${viewoptions.specpointy} - set viewoptions.centerz ${viewoptions.specpointz} - Ng_SetVisParameters; Ng_Center - redraw - } { - Ng_SetVisParameters - } - - - } - - pack $f.point.center - - pack $f.point -fill x -ipady 3 - - - - frame $w.bu - pack $w.bu -fill x -ipady 3 - - - button $w.bu.done -text "Done" -command { - Ng_SetVisParameters; - redraw - destroy .viewopts_dlg - } - button $w.bu.apply -text "Apply" -command { - Ng_SetVisParameters; - redraw - } - pack $w.bu.apply $w.bu.done -expand yes -side left - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Viewing options" - focus $w - } -} - - - -proc clipplanecommand { { optionalvar 0 } } { - Ng_SetVisParameters - after idle redraw -} - - -set clippingdialog_pop1 0 -set clippingdialog_pop2 0 -set clippingdialog_pop3 0 -set clippingdialog_pop4 0 - - -# -# -# clipping dialog -# -# -proc clippingdialog { } { - - global clippingdialog_pop1 - global clippingdialog_pop2 - global clippingdialog_pop3 - global clippingdialog_pop4 - set clippingdialog_pop1 1 - set clippingdialog_pop2 1 - set clippingdialog_pop3 1 - set clippingdialog_pop4 1 - - set w .clipping_dlg - - if {[winfo exists .clipping_dlg] == 1} { - - wm withdraw $w - wm deiconify $w - focus $w - - } { - toplevel $w - - label $w.lab1 -text "Normal x" - scale $w.scale1 -orient horizontal -length 300 -from -1 -to 1 \ - -resolution 0.01 -tickinterval 0.5 \ - -variable viewoptions.clipping.nx \ - -command { clipplanecommand } -# -command { popupcheckredraw2 clippingdialog_pop1 ${viewoptions.clipping.enable} } - -# Ng_SetVisParameters; -# if { ${viewoptions.clipping.enable} == 1 } { redraw }; -# Ng_SetVisParameters - - label $w.lab2 -text "Normal y" - scale $w.scale2 -orient horizontal -length 300 -from -1 -to 1 \ - -resolution 0.01 -tickinterval 0.5 \ - -variable viewoptions.clipping.ny \ - -command { clipplanecommand } -# -command { popupcheckredraw2 clippingdialog_pop2 ${viewoptions.clipping.enable} } - - label $w.lab3 -text "Normal z" - scale $w.scale3 -orient horizontal -length 300 -from -1 -to 1 \ - -resolution 0.01 -tickinterval 0.5 \ - -variable viewoptions.clipping.nz \ - -command { clipplanecommand } -# -command { popupcheckredraw2 clippingdialog_pop3 ${viewoptions.clipping.enable} } - label $w.lab4 -text "Distance" - scale $w.scale4 -orient horizontal -length 300 -from -1 -to 1.001 \ - -resolution 0.0001 -tickinterval 0.5 \ - -variable viewoptions.clipping.dist \ - -command { clipplanecommand } -# -command { popupcheckredraw2 clippingdialog_pop4 ${viewoptions.clipping.enable} } - - label $w.lab5 -text "Additional Distance" - scale $w.scale5 -orient horizontal -length 300 -from -1 -to 1.001 \ - -resolution 0.0001 -tickinterval 0.5 \ - -variable viewoptions.clipping.dist2 \ - -command { clipplanecommand } - - - - tixControl $w.clipdomain -label "Clip only domain" -integer true \ - -variable viewoptions.clipping.onlydomain -min 0 -max 50 \ - -options { entry.width 2 } \ - -command { clipplanecommand; } -# -command { Ng_SetVisParameters; redraw } - tixControl $w.donotclipdomain -label "Do not clip domain" -integer true \ - -variable viewoptions.clipping.notdomain -min 0 -max 50 \ - -options { entry.width 2 } \ - -command { clipplanecommand; } -# -command { Ng_SetVisParameters; redraw } - - pack $w.lab1 $w.scale1 $w.lab2 $w.scale2 $w.lab3 $w.scale3 $w.lab4 $w.scale4 $w.lab5 $w.scale5 $w.clipdomain $w.donotclipdomain - - - checkbutton $w.cb1 -text "Enable clipping" \ - -variable viewoptions.clipping.enable \ - -command { Ng_SetVisParameters; redraw } - - pack $w.cb1 - - - - frame $w.bu -# pack $w.bu -fill x - pack $w.bu -fill x -ipady 3 - - button $w.bu.cancle -text "Done" -command "destroy $w" - pack $w.bu.cancle -expand yes - - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Clipping Plane" - # grab $w - focus $w - -# $w.scale1 configure -command { puts "call1b"; Ng_SetVisParameters; redraw } -# puts "after" - - clipplanecommand - } -} - - - - - -# -# refinement dialog -# -# -proc refinementdialog { } { - - set w .refinement_dlg - - if {[winfo exists .refinement_dlg] == 1} { - wm withdraw $w - wm deiconify $w - focus $w - } { - - toplevel $w - - - tixControl $w.meshsize -label "max mesh-size: " -integer false \ - -variable options.meshsize -min 1e-6 -max 1e6 \ - -options { - entry.width 6 - label.width 25 - label.anchor e - } - - pack $w.meshsize - - global localh - set localh 1 - tixControl $w.loch -label "local mesh-size: " -integer false \ - -variable localh -min 1e-6 -max 1e6 \ - -options { - entry.width 6 - label.width 25 - label.anchor e - } - - pack $w.loch - - - button $w.restface -text "Restrict H at face" \ - -command { - .refinement_dlg.meshsize invoke - .refinement_dlg.loch invoke - Ng_RestrictH face $localh - } - button $w.restedge -text "Restrict H at edge" \ - -command { - .refinement_dlg.meshsize invoke - .refinement_dlg.loch invoke - Ng_RestrictH edge $localh - } - button $w.restelement -text "Restrict H at element" \ - -command { - .refinement_dlg.meshsize invoke - .refinement_dlg.loch invoke - Ng_RestrictH element $localh - } - button $w.restpoint -text "Restrict H at point" \ - -command { - .refinement_dlg.meshsize invoke - .refinement_dlg.loch invoke - Ng_RestrictH point $localh - } - - - pack $w.restface $w.restedge $w.restelement $w.restpoint - - - - button $w.anisoedge -text "Declare Anisotropic edge" \ - -command { - Ng_Anisotropy edge - } - pack $w.anisoedge - - - frame $w.bu - pack $w.bu -fill x -ipady 3 - - - button $w.bu.cancle -text "Done" -command "destroy .refinement_dlg" - button $w.bu.refine -text "Refine" \ - -command { -# Ng_BisectCopyMesh; - set oldnp 0; set newnp $status_np; - while { $oldnp < $newnp } { - set level [expr $level+1] - Ng_Bisect; - Ng_HighOrder ${options.elementorder} - Ng_ReadStatus; - redraw; - set oldnp $newnp - set newnp $status_np - puts "oldnp $oldnp newnp $newnp" - } - } - button $w.bu.zrefine -text "Z-Refine" \ - -command { Ng_ZRefinement; Ng_ReadStatus; redraw; } - - pack $w.bu.zrefine $w.bu.refine $w.bu.cancle -expand yes -side left - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Select Refinement" - focus $w - } -} - - - - -# -# boundcondessing dialog -# -# -proc bcpropdialog { } { - - set w .bcprop_dlg - - if {[winfo exists .bcprop_dlg] == 1} { - wm withdraw $w - wm deiconify $w - } { - toplevel $w - - frame $w.face -borderwidth 3 - pack $w.face -fill x - label $w.face.lab -text "face index:" - label $w.face.ent -text 1 -padx 4 - button $w.face.next -text "next" -command { - set w .bcprop_dlg; - set facenr [$w.face.ent cget -text] - if {$facenr == [Ng_BCProp getnfd]} { - set facenr 1 - } { - set facenr [expr $facenr + 1] - } - $w.face.ent configure -text $facenr - Ng_BCProp setactive $facenr - set bcnr [Ng_BCProp getbc $facenr] - $w.bc.ent delete 0 end - $w.bc.ent insert 0 $bcnr - - redraw - } - button $w.face.prev -text "prev" -command { - set w .bcprop_dlg; - set facenr [$w.face.ent cget -text] - if {$facenr == 1} { - set facenr [Ng_BCProp getnfd] - } { - set facenr [expr $facenr - 1] - } - $w.face.ent configure -text $facenr - Ng_BCProp setactive $facenr - set bcnr [Ng_BCProp getbc $facenr] - $w.bc.ent delete 0 end - $w.bc.ent insert 0 $bcnr - - redraw - } - - - pack $w.face.lab $w.face.ent $w.face.prev $w.face.next -side left - - frame $w.bc -borderwidth 3 - pack $w.bc -fill x - label $w.bc.lab -text "bc property:" - entry $w.bc.ent -width 5 -relief sunken - button $w.bc.but -text "change" -command { - set w .bcprop_dlg; - Ng_BCProp setbc [$w.face.ent cget -text] [$w.bc.ent get]; - } - button $w.bc.but2 -text "all" -command { - set w .bcprop_dlg; - Ng_BCProp setall [$w.bc.ent get]; - } - pack $w.bc.lab $w.bc.ent $w.bc.but $w.bc.but2 -side left -expand yes - - frame $w.bcname -borderwidth 3 - pack $w.bcname -fill x - label $w.bcname.lab -text "bc name:" - label $w.bcname.ent -text "-" - pack $w.bcname.lab $w.bcname.ent -side left -expand yes - - - frame $w.bu - pack $w.bu -fill x -ipady 3 - - button $w.bu.close -text "Close" -command { destroy .bcprop_dlg } - - pack $w.bu.close -expand yes -side left - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Boundary Conditions" - } - - focus $w - - set facenr [Ng_BCProp getactive] - $w.face.ent configure -text $facenr - - set bcnr [Ng_BCProp getbc $facenr] - $w.bc.ent delete 0 end - $w.bc.ent insert 0 $bcnr - - set bcname [Ng_BCProp getbcname $facenr] - $w.bcname.ent configure -text $bcname - -} - - - - -# -# Philippose - 25/07/2010 -# Display the face colours currently -# available in the mesh -# -proc currmeshcoloursdialog { } { - - set w .currmeshcolours_dlg - - if {[winfo exists .currmeshcolours_dlg] == 1} { - wm withdraw $w - wm deiconify $w - focus $w - } { - toplevel $w - - global facecolslist - - frame $w.facecols -borderwidth 3 - - listbox $w.facecols.list -yscroll "$w.facecols.scroll set" -selectmode single -setgrid 1 -width 32 -height 12 - scrollbar $w.facecols.scroll -command "$w.facecols.list yview" - pack $w.facecols.scroll -side right -fill y - pack $w.facecols.list -side left -expand yes -fill both - - Ng_CurrentFaceColours getcolours facecolslist - set i 1 - foreach el $facecolslist { - set hel [format "%d: (%.4f %.4f %.4f)" $i [ lindex $el 0 ] [ lindex $el 1 ] [ lindex $el 2 ]] - incr i - $w.facecols.list insert end $hel } - - frame $w.bu1 -borderwidth 3 - button $w.bu1.showonly -text "show only" -command { - Ng_CurrentFaceColours showonly [.currmeshcolours_dlg.facecols.list curselection] - redraw - } - button $w.bu1.hideonly -text "hide only" -command { - Ng_CurrentFaceColours hideonly [.currmeshcolours_dlg.facecols.list curselection] - redraw - } - button $w.bu1.showalso -text "show" -command { - Ng_CurrentFaceColours showalso [.currmeshcolours_dlg.facecols.list curselection] - redraw - } - button $w.bu1.hidealso -text "hide" -command { - Ng_CurrentFaceColours hidealso [.currmeshcolours_dlg.facecols.list curselection] - redraw - } - pack $w.bu1.showonly $w.bu1.hideonly $w.bu1.showalso $w.bu1.hidealso -expand yes -fill x -padx 2 -pady 2 -side left - - frame $w.bu2 - button $w.bu2.showall -text "show all" -command { - Ng_CurrentFaceColours showall - redraw - } - button $w.bu2.hideall -text "hide all" -command { - Ng_CurrentFaceColours hideall - redraw - } - pack $w.bu2.showall $w.bu2.hideall -expand yes -fill x -padx 2 -pady 2 -side left - - frame $w.bu3 - button $w.bu3.close -text "close" -command { - destroy .currmeshcolours_dlg - } - pack $w.bu3.close -expand yes -fill x -pady 3 -side right - - - pack $w.facecols -side top -expand yes -fill x -fill y - pack $w.bu3 -side bottom - pack $w.bu2 -side bottom - pack $w.bu1 -expand yes -fill x -side left - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Inspect Mesh Colours" - focus $w - } -} - - - - -# -# Philippose - 30/01/2009 -# Local Surface Mesh Size Selection -# (Currently only supports OCC Geometry) -# -# -proc surfacemeshsizedialog { } { - - set w .surfacemeshsize_dlg - - if {[winfo exists .surfacemeshsize_dlg] == 1} { - wm withdraw $w - wm deiconify $w - } { - toplevel $w - - frame $w.face -borderwidth 3 - pack $w.face -fill x -padx 5 - label $w.face.lab -text "face index:" - label $w.face.ent -text 1 -padx 4 - button $w.face.next -text "next" -command { - set w .surfacemeshsize_dlg; - set facenr [$w.face.ent cget -text] - if {$facenr == [Ng_SurfaceMeshSize getnfd]} { - set facenr 1 - } { - set facenr [expr $facenr + 1] - } - $w.face.ent configure -text $facenr - Ng_SurfaceMeshSize setactive $facenr - set surfms [Ng_SurfaceMeshSize getsurfms $facenr] - $w.sms.ent delete 0 end - $w.sms.ent insert 0 $surfms - - redraw - } - button $w.face.prev -text "prev" -command { - set w .surfacemeshsize_dlg; - set facenr [$w.face.ent cget -text] - if {$facenr == 1} { - set facenr [Ng_SurfaceMeshSize getnfd] - } { - set facenr [expr $facenr - 1] - } - $w.face.ent configure -text $facenr - Ng_SurfaceMeshSize setactive $facenr - set surfms [Ng_SurfaceMeshSize getsurfms $facenr] - $w.sms.ent delete 0 end - $w.sms.ent insert 0 $surfms - - redraw - } - - - pack $w.face.lab $w.face.ent $w.face.prev $w.face.next -side left - - frame $w.sms -borderwidth 3 - pack $w.sms -fill x - label $w.sms.lab -text "max mesh size:" - entry $w.sms.ent -width 8 -relief sunken - button $w.sms.but -text "change" -command { - set w .surfacemeshsize_dlg; - Ng_SurfaceMeshSize setsurfms [$w.face.ent cget -text] [$w.sms.ent get]; - } - button $w.sms.but2 -text "all" -command { - set w .surfacemeshsize_dlg; - Ng_SurfaceMeshSize setall [$w.sms.ent get]; - } - pack $w.sms.lab $w.sms.ent $w.sms.but $w.sms.but2 -side left -padx 5 -expand yes - - frame $w.bu - pack $w.bu -fill x -ipady 3 - - button $w.bu.close -text "Close" -command { destroy .surfacemeshsize_dlg } - - pack $w.bu.close -expand yes -side left - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Edit Surface Mesh Size" - } - - focus $w - - set facenr [Ng_SurfaceMeshSize getactive] - $w.face.ent configure -text $facenr - - set surfms [Ng_SurfaceMeshSize getsurfms $facenr] - $w.sms.ent delete 0 end - $w.sms.ent insert 0 $surfms - -} - - - - -# -# METIS dialog -# -# -proc METISdialog { } { - - set w .metis_dlg - set w.parts 64 - - if {[winfo exists .metis_dlg] == 1} { - wm withdraw $w - wm deiconify $w - } { - toplevel $w - - frame $w.a -borderwidth 0 - frame $w.b -borderwidth 0 - pack $w.a $w.b - - label $w.a.lab -text "Number of partitions:" - entry $w.a.ent -textvariable w.parts -width 4 -relief sunken - - button $w.b.start -text "Start METIS" -command { - Ng_Metis ${w.parts} - redraw - } - button $w.b.cancel -text "Cancel" -command { destroy .metis_dlg } - pack $w.a.lab $w.a.ent -side left -expand yes - pack $w.b.start $w.b.cancel -side left - - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "METIS Partitioning" - focus $w - - } -} - - - -# -# STL dialog -# -proc stloptionsdialog { } { - - set w .stlopts_dlg - - if {[winfo exists .stlopts_dlg] == 1} { - wm withdraw $w - wm deiconify $w - focus $w - } { - toplevel $w - - tixNoteBook $w.nb -ipadx 6 -ipady 6 - # $w config -bg gray - # $w.nb subwidget nbframe config -backpagecolor gray - - # Create the two tabs on the notebook. The -underline option - # puts a underline on the first character of the labels of the tabs. - # Keyboard accelerators will be defined automatically according - # to the underlined character. - # - -# $w.nb add chartopt -label "Chart Options" -underline 0 -# #$w.nb add meshsize -label "Mesh Size" -underline 0 -# pack $w.nb -expand yes -fill both -padx 5 -pady 5 -side top - - -# set f [$w.nb subwidget chartopt] - - -# label $f.lab1 -text "Yellow Edges Angle ()" -# scale $f.scale1 -orient horizontal -length 300 \ -# -from 0 -to 90 -resolution 1 -tickinterval 10 \ -# -variable stloptions.yangle - -# pack $f.lab1 $f.scale1 - -# label $f.lab2e -text "Edge Corner Angle ()" -# scale $f.scale2e -orient horizontal -length 360 -from 0 -to 180 \ -# -resolution 1 -tickinterval 20 \ -# -variable stloptions.edgecornerangle -# pack $f.lab2e $f.scale2e - -# label $f.lab2 -text "Chart Angle ()" -# scale $f.scale2 -orient horizontal -length 360 -from 0 -to 180 \ -# -resolution 1 -tickinterval 20 \ -# -variable stloptions.chartangle -# pack $f.lab2 $f.scale2 - -# label $f.lab2b -text "Outer Chart Angle ()" -# scale $f.scale2b -orient horizontal -length 360 -from 0 -to 180 \ -# -resolution 1 -tickinterval 20 \ -# -variable stloptions.outerchartangle -# pack $f.lab2b $f.scale2b - -# frame $f.r4 -# pack $f.r4 -anchor w -# scale $f.r4.sc -orient horizontal -length 200 -from 0.1 -to 10 \ -# -resolution 0.1 -variable stloptions.resthatlasfac -# checkbutton $f.r4.bu -text "Restrict h for Calc Atlas (Faster)" \ -# -variable stloptions.resthatlasenable -# pack $f.r4.sc $f.r4.bu -side left - - - #set f [$w.nb subwidget meshsize] - - - -# checkbutton $w.seat -text "Use Searchtrees" \ -# -variable stloptions.usesearchtree -# pack $w.seat - - - - - frame $w.bu -# pack $w.bu - pack $w.bu -fill x -ipady 3 - -# -fill x - - button $w.bu.apply -text "Apply" -command { redraw; Ng_GenerateMesh 1 2} - button $w.bu.cancle -text "Done" -command { destroy .stlopts_dlg } - pack $w.bu.cancle $w.bu.apply -side left -expand yes - - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "STL Options" -# grab $w - focus $w - } -} - -proc stldoctordialog { } { - - set wd .stldoctor_dlg - - if {[winfo exists .stldoctor_dlg] == 1} { - wm withdraw $wd - wm deiconify $wd - focus $wd - } { - - toplevel $wd - - tixNoteBook $wd.nb -ipadx 6 -ipady 6 - - $wd.nb add general -label "General" -underline 0 - $wd.nb add topology -label "Edit Topology" -underline 5 - $wd.nb add edges -label "Edit Edges" -underline 5 - $wd.nb add normals -label "Edit Normals" -underline 5 - $wd.nb add advanced -label "Advanced" -underline 0 - - - pack $wd.nb -expand yes -fill both -padx 5 -pady 5 -side top - - - # GENERAL ***************************** - - set f [$wd.nb subwidget general] - - - frame $f.show - pack $f.show -fill x - checkbutton $f.show.showtrias -text "Show STL-Triangles" \ - -variable stloptions.showtrias -command { Ng_SetVisParameters; redraw } - pack $f.show.showtrias -anchor w - - checkbutton $f.show.showfilledtrias -text "Show Filled Triangles" \ - -variable stloptions.showfilledtrias -command { Ng_SetVisParameters; redraw } - pack $f.show.showfilledtrias -anchor w - - set selmodevals { 0 1 2 3 4 } - set selmodelabs(0) "triangle" - set selmodelabs(1) "edge" - set selmodelabs(2) "point" - set selmodelabs(3) "line" - set selmodelabs(4) "line cluster" - - tixOptionMenu $f.selmode -label "Double Click selects :" \ - -options { - label.width 19 - label.anchor e - menubutton.width 15 - } - - foreach selmodev $selmodevals { - $f.selmode add command $selmodev -label $selmodelabs($selmodev) - } - $f.selmode config -variable stldoctor.selectmode - $f.selmode config -command { Ng_STLDoctor } - global stldoctor.selectmode - pack $f.selmode - - frame $f.sm - pack $f.sm -fill x - checkbutton $f.sm.bu -text "select with mouse" \ - -variable stldoctor.selectwithmouse - pack $f.sm.bu - - frame $f.st -relief groove -borderwidth 3 - pack $f.st -fill x - label $f.st.lab -text "Select triangle by number"; - entry $f.st.ent -width 5 -relief sunken \ - -textvariable stldoctor.selecttrig - pack $f.st.ent $f.st.lab -side left -expand yes - - frame $f.vc -relief groove -borderwidth 3 - pack $f.vc -fill x - checkbutton $f.vc.bu -text "show vicinity" \ - -variable stldoctor.showvicinity \ - -command {Ng_STLDoctor vicinity; redraw} - label $f.vc.lab -text "vicinity size"; - scale $f.vc.sc -orient horizontal -length 200 -from 0 -to 200 \ - -resolution 1 -variable stldoctor.vicinity \ - -command { Ng_STLDoctor vicinity; redraw } - pack $f.vc.bu $f.vc.lab $f.vc.sc -expand yes - - frame $f.ge -relief groove -borderwidth 3 - pack $f.ge -fill x - button $f.ge.neighbourangles -text "calc neighbourangles" -command {Ng_STLDoctor neighbourangles} - button $f.ge.showcoords -text "show coords of touched triangle" -command {Ng_STLDoctor showcoords} - button $f.ge.moveptm -text "move point to middle of trianglepoints" -command {Ng_STLDoctor movepointtomiddle; redraw} - button $f.ge.destroy0trigs -text "destroy 0-volume triangles" -command {Ng_STLDoctor destroy0trigs} - pack $f.ge.neighbourangles $f.ge.showcoords $f.ge.moveptm $f.ge.destroy0trigs -expand yes - - - button $f.ge.cancle -text "Done" -command {destroy .stldoctor_dlg } - pack $f.ge.cancle -expand yes - - # TOPOLOGY ******************** - set f [$wd.nb subwidget topology] - - frame $f.oc -relief groove -borderwidth 3 - pack $f.oc -fill x - button $f.oc.bu -text "invert orientation of selected trig" -command {Ng_STLDoctor invertselectedtrig; redraw } - button $f.oc.bu2 -text "orient after selected trig" -command {Ng_STLDoctor orientafterselectedtrig; redraw } - pack $f.oc.bu $f.oc.bu2 -side left -expand yes - - button $f.toperr -text "mark inconsistent triangles" -command {Ng_STLDoctor marktoperrortrigs; redraw } - - button $f.deltrig -text "delete selected triangle" -command {Ng_STLDoctor deleteselectedtrig; redraw } - button $f.geosmooth -text "geometric smoothing" -command {Ng_STLDoctor smoothgeometry; redraw } - - pack $f.toperr $f.deltrig $f.geosmooth - - - - - - # EDGES *********************** - set f [$wd.nb subwidget edges] - - - frame $f.be -relief groove -borderwidth 3 - pack $f.be -fill x - label $f.be.lab -text "build edges with yellow angle:"; - scale $f.be.sc -orient horizontal -length 200 -from 0 -to 100 \ - -resolution 0.5 - $f.be.sc config -variable stloptions.yangle - $f.be.sc config -command { Ng_SetSTLParameters; Ng_STLDoctor buildedges; redraw } - label $f.be.lab2 -text "continue edges with yellow angle:"; - scale $f.be.sc2 -orient horizontal -length 200 -from 0 -to 100 \ - -resolution 0.5 - $f.be.sc2 config -variable stloptions.contyangle - $f.be.sc2 config -command { Ng_SetSTLParameters; Ng_STLDoctor buildedges; redraw } - - - - button $f.be.buildedges -text "Build Edges" -command {Ng_STLDoctor buildedges; redraw} - pack $f.be.lab $f.be.sc $f.be.lab2 $f.be.sc2 $f.be.buildedges -expand yes - - frame $f.se - pack $f.se -fill x - checkbutton $f.se.bu -text "show excluded" \ - -variable stldoctor.showexcluded \ - -command {Ng_STLDoctor; redraw} - pack $f.se.bu - - # edgeselectmode ****** - - set edgeselmodevals { 0 1 2 3 4 } - set edgeselmodelabs(0) "no change" - set edgeselmodelabs(1) "undefined" - set edgeselmodelabs(2) "confirmed" - set edgeselmodelabs(3) "candidate" - set edgeselmodelabs(4) "excluded" - - tixOptionMenu $f.edgeselmode -label "Double Click sets edge :" \ - -options { - label.width 19 - label.anchor e - menubutton.width 15 - } - - foreach edgeselmodev $edgeselmodevals { - $f.edgeselmode add command $edgeselmodev -label $edgeselmodelabs($edgeselmodev) - } - $f.edgeselmode config -variable stldoctor.edgeselectmode - $f.edgeselmode config -command { Ng_STLDoctor } - global stldoctor.edgeselectmode - pack $f.edgeselmode - - # edge buttons - - frame $f.edg -relief groove -borderwidth 3 - pack $f.edg -fill x - -# checkbutton $f.edg.bu -text "use external edges" \ -# -variable stldoctor.useexternaledges \ -# -command {Ng_STLDoctor; redraw} -# pack $f.edg.bu -expand yes - - - frame $f.edg.f0 - pack $f.edg.f0 - button $f.edg.f0.confirmedge -text "confirm" -command {Ng_STLDoctor confirmedge; redraw} - button $f.edg.f0.candidateedge -text "candidate" -command {Ng_STLDoctor candidateedge; redraw} - button $f.edg.f0.excludeedge -text "exclude" -command {Ng_STLDoctor excludeedge; redraw} - button $f.edg.f0.undefinededge -text "undefined" -command {Ng_STLDoctor undefinededge; redraw} - pack $f.edg.f0.confirmedge $f.edg.f0.candidateedge $f.edg.f0.excludeedge $f.edg.f0.undefinededge -side left - - frame $f.edg.fa - pack $f.edg.fa - button $f.edg.fa.setallundefined -text "all undefined" -command {Ng_STLDoctor setallundefinededges; redraw} - button $f.edg.fa.erasecandidates -text "candidates to undefined" -command {Ng_STLDoctor erasecandidateedges; redraw} - pack $f.edg.fa.setallundefined $f.edg.fa.erasecandidates -side left - - - frame $f.edg.fb - pack $f.edg.fb - button $f.edg.fb.confirmcandidates -text "candidates to confirmed" -command {Ng_STLDoctor confirmcandidateedges; redraw} - button $f.edg.fb.confirmedtocandidates -text "confirmed to candidates" -command {Ng_STLDoctor confirmedtocandidateedges; redraw} - pack $f.edg.fb.confirmcandidates $f.edg.fb.confirmedtocandidates -side left - - frame $f.edg.f1 - frame $f.edg.f2 - frame $f.edg.f3 - frame $f.edg.f4 - pack $f.edg.f1 $f.edg.f2 $f.edg.f3 $f.edg.f4 - - button $f.edg.f1.exportedges -text "export edges" -command {Ng_STLDoctor exportedges} - button $f.edg.f1.importedges -text "import edges" -command {Ng_STLDoctor importedges; redraw} - button $f.edg.f1.saveedgedata -text "save edgedata" \ - -command { - set types { - {"Netgen Edgedata" {.ned} } - } - set file [tk_getSaveFile -filetypes $types -defaultextension ".ned"] - if {$file != ""} { - Ng_STLDoctor saveedgedata $file - } - } - - button $f.edg.f1.loadedgedata -text "load edgedata" \ - -command { - set types { - {"Netgen Edgedata" {.ned} } - } - set file [tk_getOpenFile -filetypes $types -defaultextension ".ned"] - if {$file != ""} { - Ng_STLDoctor loadedgedata $file - puts "loading done" - - redraw - -# wm title . [concat "NETGEN - " $file] - } - } - - button $f.edg.f1.importAVLedges -text "import AVL edges" \ - -command { - set types {{"Edge file" {.edg }}} - - set file [tk_getOpenFile -filetypes $types -defaultextension ".edg"] - if {$file != ""} { - Ng_STLDoctor importexternaledges $file; - } - } - - pack $f.edg.f1.importAVLedges $f.edg.f1.loadedgedata $f.edg.f1.saveedgedata -side left - -# button $f.edg.f1.buildedges -text "build external edges" -command {Ng_STLDoctor buildexternaledges; redraw} - frame $f.edg2 -relief groove -borderwidth 3 - pack $f.edg2 -fill x - - -# button $f.edg2.addlonglines -text "make long lines candidates (% of diam)" -command {Ng_STLDoctor addlonglines; redraw} - label $f.edg2.lab -text "length (%):" - scale $f.edg2.sc -orient horizontal -length 200 -from 0 -to 100 \ - -resolution 0.5 \ - -variable stldoctor.longlinefact - - # button $f.edg2.deletedirtyedges -text "make dirty edges candidates" -command {Ng_STLDoctor deletedirtyedges; redraw} - button $f.edg2.undoedge -text "undo last edge change" -command {Ng_STLDoctor undoedgechange; redraw} - - # pack $f.edg2.addlonglines $f.edg2.deletedirtyedges -expand yes - # pack $f.edg2.lab $f.edg2.sc -side left - pack $f.edg2.undoedge -expand yes - - - - # NORMALS *********************** - set f [$wd.nb subwidget normals] - - frame $f.dt -relief groove -borderwidth 3 - pack $f.dt -fill x - label $f.dt.lab -text "dirty triangle factor"; - entry $f.dt.ent -width 5 -relief sunken \ - -textvariable stldoctor.dirtytrigfact - pack $f.dt.ent $f.dt.lab -side left -expand yes - - frame $f.srt -relief groove -borderwidth 3 - pack $f.srt -fill x - button $f.srt.bu -text "smooth reverted triangles geometric" -command {Ng_STLDoctor smoothrevertedtrigs; redraw } - entry $f.srt.ent -width 5 -relief sunken \ - -textvariable stldoctor.smoothangle - pack $f.srt.ent $f.srt.bu -side left -expand yes - - frame $f.bdt -relief groove -borderwidth 3 - pack $f.bdt -fill x - button $f.bdt.bu -text "mark dirty triangles" -command {Ng_STLDoctor markdirtytrigs; redraw } - button $f.bdt.bu2 -text "smooth dirty triangles normal" -command {Ng_STLDoctor smoothdirtytrigs; redraw } - pack $f.bdt.bu $f.bdt.bu2 -side left -expand yes - - - frame $f.sno -relief groove -borderwidth 3 - pack $f.sno - - label $f.sno.labrough -text "rough" - scale $f.sno.scsmooth -orient horizontal -length 100 -from 0 -to 0.8 \ - -resolution 0.01 -variable stldoctor.smoothnormalsweight \ - -command { Ng_SetSTLParameters } - label $f.sno.labsmooth -text "smooth" - button $f.sno.smoothnormals -text "smooth normals" -command { Ng_STLDoctor smoothnormals; redraw} - - - - pack $f.sno.labrough $f.sno.scsmooth $f.sno.labsmooth $f.sno.smoothnormals -side left -padx 5 - - frame $f.no -relief groove -borderwidth 3 - pack $f.no -fill x - - button $f.no.marknonsmoothnormals -text "mark non-smooth triangles" -command {Ng_STLDoctor marknonsmoothnormals; redraw} - button $f.no.calcnormals -text "calculate normals from geometry" -command {Ng_STLDoctor calcnormals; redraw} - - pack $f.no.marknonsmoothnormals $f.no.calcnormals -expand yes - - - # ADVANCED ************************** - set f [$wd.nb subwidget advanced] - - - frame $f.sc - pack $f.sc -fill x - checkbutton $f.sc.bu -text "spiral check" \ - -variable stldoctor.spiralcheck \ - -command {Ng_STLDoctor;} - checkbutton $f.sc.bu2 -text "cone check" \ - -variable stldoctor.conecheck \ - -command {Ng_STLDoctor;} - pack $f.sc.bu $f.sc.bu2 - - - tixControl $f.gtol -label "load-geometry tolerance factor" -integer false \ - -variable stldoctor.geom_tol_fact \ - -options { - entry.width 8 - label.width 30 - label.anchor e - } - pack $f.gtol - - button $f.adap -text "Apply" -command { - [.stldoctor_dlg.nb subwidget advanced].gtol invoke - Ng_STLDoctor; - } - pack $f.adap -expand yes - -# frame $f.gtol -relief groove -borderwidth 3 -# pack $f.gtol -fill x -# label $f.gtol.lab -text "Geometry-Load-Tolerance-Factor"; -# entry $f.gtol.ent -width 5 -relief sunken \ -# -textvariable stldoctor.geom_tol_fact -# pack $f.gtol.lab $f.gtol.ent -side left -expand yes - - #******************************* - wm withdraw $wd - wm geom $wd +100+100 - wm deiconify $wd - wm title $wd "STL Doctor" - - focus $wd -} -} - - - - - -proc meshdoctordialog { } { - - set w .meshdoc_dlg - global meshdoctor.active - - if {[winfo exists .meshdoc_dlg] == 1} { - wm withdraw $w - wm deiconify $w - focus $w - } { - toplevel $w - - set meshdoctor.active 1 - Ng_MeshDoctor; - - - frame $w.vis -relief groove -borderwidth 3 - pack $w.vis - - checkbutton $w.vis.showfilledtrigs -text "Show filled triangles" \ - -variable viewoptions.drawfilledtrigs \ - -command { Ng_SetVisParameters; redraw } - - checkbutton $w.vis.showedges -text "Show edges" \ - -variable viewoptions.drawedges \ - -command { Ng_SetVisParameters; redraw } - - - checkbutton $w.vis.showoutline -text "Show Triangle Outline" \ - -variable viewoptions.drawoutline \ - -command { Ng_SetVisParameters; redraw } - - pack $w.vis.showfilledtrigs $w.vis.showoutline $w.vis.showedges - - tixControl $w.markedgedist -label "Mark edge dist: " -integer true \ - -min 0 -max 999 \ - -variable meshdoc.markedgedist \ - -options { - entry.width 3 - label.width 20 - label.anchor e - } \ - -command { - Ng_MeshDoctor markedgedist ${meshdoc.markedgedist} - redraw - } - pack $w.markedgedist - - button $w.deledge -text "Delete marked segments" -command { - Ng_MeshDoctor deletemarkedsegments - redraw - } - pack $w.deledge - - button $w.close -text "Close" -command { - set meshdoctor.active 0; - Ng_MeshDoctor; - destroy .meshdoc_dlg - } - pack $w.close -expand yes - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Mesh Doctor" - } -} - - - -# -# Quality viewer -# - -proc qualityviewdialog { show } { - - set w .qualityview_dlg - - if {[winfo exists .qualityview_dlg] == 1} { - - if { $show == 1 } { - wm withdraw .qualityview_dlg - wm deiconify $w - focus $w - } { - wm withdraw $w - } - } { - toplevel $w - - set c $w.c - - canvas $c -relief raised -width 450 -height 300 - pack $w.c -side top -fill x - - set plotFont {Helvetica 12} - set smallFont {Helvetica 12} - - $c create line 100 250 400 250 -width 2 - $c create line 100 250 100 50 -width 2 - - for {set i 0} {$i <= 10} {incr i} { - set x [expr {100 + ($i*30)}] - $c create line $x 250 $x 245 -width 2 - if { [expr {$i % 2}] == 0 } { - $c create text $x 254 -text [format %1.1f [expr 0.1*$i]] -anchor n -font $plotFont - } - } - - global qualbar - global qualbarnull - global qualbaraxis - - for {set i 0} {$i <= 5} {incr i} { - set y [expr {250 - ($i*40)}] - $c create line 100 $y 105 $y -width 2 - -# global qualbaraxis($i) - set qualbaraxis($i) \ - [$c create text 96 $y -text [expr $i*50].0 -anchor e -font $plotFont] - } - - for {set i 0} {$i < 20} {incr i} { - set x1 [expr {100 + ($i*15) + 2}] - set x2 [expr {$x1+10}] - set y [expr {250 - 10 * $i}] -# global qualbar($i) - set qualbar($i) [$c create rectangle $x1 250 $x2 245 -fill blue] - set qualbarnull($i) [$c create text [expr {($x1+$x2)/2}] 245 -text 0 -anchor s -font $smallFont -fill blue] - } - - frame $w.bu - pack $w.bu - # -fill x - - button $w.close -text "Close" \ - -command { - wm withdraw .qualityview_dlg - set viewqualityplot 0 - } - pack $w.close - - - if { $show == 1 } { - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Mesh Quality" - focus $w - } - } -} - - - - - - - - - - -# -# Quality viewer -# -proc memusedialog { show } { - - set w .memuse_dlg - - if {[winfo exists .memuse_dlg] == 1} { - - if { $show == 1 } { - wm withdraw .memuse_dlg - wm deiconify $w - focus $w - } { - wm withdraw $w - } - } { - toplevel $w - - set c $w.c - - canvas $c -relief raised -width 600 -height 300 - pack $w.c -side top -fill x - - set plotFont {Helvetica 18} - set smallFont {Helvetica 12} - - - global memmark - for {set i 0} {$i < 512} { incr i } { - set memmark($i) [$c create line [expr 50+$i] 50 [expr 50+$i] 70 -fill blue] - } - - - set plotFont {Helvetica 18} - set smallFont {Helvetica 12} - - $c create text 50 90 -text "0 GB" -anchor n -font $plotFont - $c create text 178 90 -text "1 GB" -anchor n -font $plotFont - $c create text 306 90 -text "2 GB" -anchor n -font $plotFont - $c create text 434 90 -text "3 GB" -anchor n -font $plotFont - $c create text 562 90 -text "4 GB" -anchor n -font $plotFont - - - frame $w.bu - pack $w.bu - # -fill x - - button $w.close -text "Close" \ - -command { - wm withdraw .memuse_dlg - set memuseplot 0 - } - pack $w.close - - if { $show == 1 } { - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Memory Usage" - focus $w - } - } -} - - - - - - - - - - - - - - - -# -# STL INFO dialog -# -proc STLinfodialog { show } { - - set w .STLinfo_dlg - - if {[winfo exists .STLinfo_dlg] == 1} { - - if { $show == 1 } { - wm withdraw .STLinfo_dlg - wm deiconify $w - focus $w - } { - wm withdraw $w - } - } { - toplevel $w - - set c $w.c - - canvas $c -relief raised -width 450 -height 300 - pack $w.c -side top -fill x - - set plotFont {Helvetica 18} - set smallFont {Helvetica 12} - - $c create line 100 250 400 250 -width 2 - $c create line 100 250 100 50 -width 2 - - frame $w.bu - pack $w.bu - # -fill x - - button $w.close -text "Close" \ - -command { - wm withdraw .STLinfo_dlg - #set STLinfoopen 0 - } - pack $w.close - - - if { $show == 1 } { - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "STL Geometry Info" - focus $w - } - } -} - - - - - - - - -proc logwindow { } { - set w .logwindow - - if {[winfo exists .logwindow] == 1} { - wm withdraw $w - wm deiconify $w - focus $w - } { - toplevel $w - - text $w.edit -yscroll "$w.scrolly set" -setgrid 1 -height 12 - scrollbar $w.scrolly -command "$w.edit yview" - pack $w.edit -side left -fill both -expand 1 - pack $w.scrolly -side left -fill both -expand 0 - - .logwindow.edit insert end "Netgen Log Window\n" - - wm withdraw $w - wm geom $w +100+100 - wm deiconify $w - wm title $w "Netgen Log" - focus $w - } -} -# logwindow - - - -# Opens a window with a table. tablevar is a list, the first entry is the title, the second the number of rows, the third the number of columns, -# then the entries follow. - -proc printtable { tablevar } { - set w newtcltable - while {[winfo exists .$w] == 1} {set w 1$w} - set w .$w - toplevel $w - for {set i 0} {$i < [lindex $tablevar 2]} { incr i } { - frame $w.col$i - for {set j 0} {$j < [lindex $tablevar 1]} { incr j } { - frame $w.col$i.row$j - message $w.col$i.row$j.txt -aspect 10000000 -text [lindex $tablevar [expr 3+[lindex $tablevar 2]*$j+$i]] - pack $w.col$i.row$j.txt - pack $w.col$i.row$j -side top - } - pack $w.col$i -side left - } - wm withdraw $w - wm geom $w +200+100; wm deiconify $w - wm title $w [lindex $tablevar 0] - focus $w -} - - -set latestwarning 0 - - -proc printwarning { textvar } { - global latestwarning - set latestwarning $textvar - set w warning - while {[winfo exists .$w] == 1} {set w 1$w} - set w .$w - toplevel $w - message $w.mes -aspect 2000 -text "WARNING:\n$textvar" - button $w.done -text "Done" -command "destroy $w" - pack $w.mes - pack $w.done - wm withdraw $w - wm deiconify $w - wm title $w "Warning" - focus $w -} - - -proc printlatestwarning { } { - global latestwarning - if {$latestwarning != 0} {printwarning $latestwarning} -} - - - -proc runtestdialog { } { - source $::ngdir/ngshell.tcl - set w .runtest_dlg - - if {[winfo exists .runtest_dlg] == 1} { - wm withdraw $w - wm deiconify $w - - focus $w - } { - toplevel $w - -# in2d testing # - frame $w.in2dframe - pack $w.in2dframe - - set in2dlogfile "" - tixLabelEntry $w.in2dframe.ent -label "in2d log-file: console if empty" \ - -labelside top \ - -options { - entry.textVariable in2dlogfile - entry.width 35 - label.width 25 - label.anchor w - } - button $w.in2dframe.btn -text "Browse" -command { - set types { { "Log file" {.log} } } - set in2dlogfile [tk_getOpenFile -filetypes $types -initialfile $in2dlogfile] - } - button $w.in2dframe.test -text "Test in2d meshing" -command { ngtest in2d $in2dlogfile } - - - pack $w.in2dframe.test -side left -anchor s -padx 4 -pady 4 - pack $w.in2dframe.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 - pack $w.in2dframe.btn -side left -anchor s -padx 4 -pady 4 - - -# geo testing # - frame $w.geoframe - pack $w.geoframe - - set geologfile "" - tixLabelEntry $w.geoframe.ent -label "geo log-file: console if empty" \ - -labelside top \ - -options { - entry.textVariable geologfile - entry.width 35 - label.width 25 - label.anchor w - } - button $w.geoframe.btn -text "Browse" -command { - set types { { "Log file" {.log} } } - set geologfile [tk_getOpenFile -filetypes $types -initialfile $geologfile] - } - button $w.geoframe.test -text "Test geo meshing" -command { ngtest geo $geologfile } - - - pack $w.geoframe.test -side left -anchor s -padx 4 -pady 4 - pack $w.geoframe.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 - pack $w.geoframe.btn -side left -anchor s -padx 4 -pady 4 - -# stl testing # - frame $w.stlframe - pack $w.stlframe - - set stllogfile "" - tixLabelEntry $w.stlframe.ent -label "stl log-file: console if empty" \ - -labelside top \ - -options { - entry.textVariable stllogfile - entry.width 35 - label.width 25 - label.anchor w - } - button $w.stlframe.btn -text "Browse" -command { - set types { { "Log file" {.log} } } - set stllogfile [tk_getOpenFile -filetypes $types -initialfile $stllogfile] - } - button $w.stlframe.test -text "Test stl meshing" -command { ngtest stl $stllogfile } - - - pack $w.stlframe.test -side left -anchor s -padx 4 -pady 4 - pack $w.stlframe.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 - pack $w.stlframe.btn -side left -anchor s -padx 4 -pady 4 - -# pde testing # - frame $w.pdeframe - pack $w.pdeframe - - set pdelogfile "" - tixLabelEntry $w.pdeframe.ent -label "pde log-file: console if empty" \ - -labelside top \ - -options { - entry.textVariable pdelogfile - entry.width 35 - label.width 25 - label.anchor w - } - button $w.pdeframe.btn -text "Browse" -command { - set types { { "Log file" {.log} } } - set pdelogfile [tk_getOpenFile -filetypes $types -initialfile $pdelogfile] - } - button $w.pdeframe.test -text "Test ngsolve pde's" -command { ngtest pde $pdelogfile } - - - pack $w.pdeframe.test -side left -anchor s -padx 4 -pady 4 - pack $w.pdeframe.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 - pack $w.pdeframe.btn -side left -anchor s -padx 4 -pady 4 - - wm title $w "Testing" - focus .runtest_dlg - } -} - +proc meshingoptionsdialog { } { + + set w .options_dlg + + if {[winfo exists .options_dlg] == 1} { + wm withdraw $w + wm deiconify $w + focus $w + } { + + toplevel $w + +# global options.meshsize + + tixNoteBook $w.nb -ipadx 6 -ipady 6 + + $w.nb add general -label "General" -underline 0 + $w.nb add meshsize -label "Mesh Size" -underline 0 + $w.nb add chartopt -label "STL Charts" -underline 0 + $w.nb add optimizer -label "Optimizer" -underline 0 + $w.nb add insider -label "Insider" -underline 0 + $w.nb add debug -label "Debug" -underline 0 + + + pack $w.nb -expand yes -fill both -padx 5 -pady 5 -side top + + + # General meshing options + + set f [$w.nb subwidget general] + + set finevals { 1 2 3 4 5 6 } + set finelabs(1) "very coarse" + set finelabs(2) "coarse" + set finelabs(3) "moderate" + set finelabs(4) "fine" + set finelabs(5) "very fine" + set finelabs(6) "user defined" + + tixOptionMenu $f.fine -label "Mesh granularity : " \ + -options { + label.width 19 + label.anchor e + menubutton.width 15 + } + + + foreach finev $finevals { + $f.fine add command $finev -label $finelabs($finev) + } + $f.fine config -variable meshoptions.fineness + $f.fine config -command { setgranularity } + global meshoptions.fineness +# setgranularity ${meshoptions.fineness} + pack $f.fine + + + + + + set mgsteps { ag me ms os mv ov } + set mgsteplabel(ag) "Analyze Geometry" + set mgsteplabel(me) "Mesh Edges" + set mgsteplabel(ms) "Mesh Surface" + set mgsteplabel(os) "Optimize Surface" + set mgsteplabel(mv) "Mesh Volume" + set mgsteplabel(ov) "Optimize Volume" + + + tixOptionMenu $f.first -label "First Step : " \ + -options { + label.width 19 + label.anchor e + menubutton.width 15 + } + + tixOptionMenu $f.last -label "Last Step : " \ + -options { + label.width 19 + label.anchor e + menubutton.width 15 + } + + foreach step $mgsteps { + $f.first add command $step -label $mgsteplabel($step) + $f.last add command $step -label $mgsteplabel($step) + } + + $f.first config -variable meshoptions.firststep + $f.last config -variable meshoptions.laststep + + pack $f.first $f.last + + + + + + set msg(0) "None" + set msg(1) "Least" + set msg(2) "Little" + set msg(3) "Moderate" + set msg(4) "Much" + set msg(5) "Most" + + tixOptionMenu $f.msg -label "Print Messages : " \ + -options { + label.width 19 + label.anchor e + menubutton.width 15 + } + + foreach step {0 1 2 3 4 5 } { + $f.msg add command $step -label $msg($step) + } + + $f.msg config -variable options.printmsg + pack $f.msg + + + + + + + + + checkbutton $f.parthread -text "Parallel meshing thread" \ + -variable options.parthread + checkbutton $f.second -text "Second order elements" \ + -variable options.secondorder + checkbutton $f.quad -text "Quad dominated" \ + -variable options.quad -command { + if { ${options.quad} } { + set meshoptions.laststep os + } + } + checkbutton $f.invtets -text "Invert volume elements" \ + -variable options.inverttets + checkbutton $f.invtrigs -text "Invert surface elements" \ + -variable options.inverttrigs + checkbutton $f.azref -text "Automatic Z-refinement" \ + -variable options.autozrefine + + pack $f.parthread $f.second $f.quad $f.invtets $f.invtrigs $f.azref + + + + tixControl $f.elementorder -label "Element order: " -integer true \ + -variable options.elementorder -min 1 -max 20 \ + -options { + entry.width 2 + label.width 20 + label.anchor e + } + + pack $f.elementorder + + +# tixControl $f.memory -label "Large Memory \[MB\]: " -integer true \ +\# -variable options.memory -min 0 -max 2000 \ +\# -options { +# entry.width 5 +# label.width 20 +# label.anchor e +# } + +# global userlevel +# if { $userlevel >= 3} { pack $f.memory } + + + # Mesh - Size options + set f [$w.nb subwidget meshsize] + + tixControl $f.meshsize -label "max mesh-size: " -integer false \ + -variable options.meshsize -min 1e-9 -max 1e6 \ + -options { + entry.width 6 + label.width 25 + label.anchor e + } + + tixControl $f.minmeshsize -label "min mesh-size: " -integer false \ + -variable options.minmeshsize -min 0 -max 1e6 \ + -options { + entry.width 6 + label.width 25 + label.anchor e + } + + tixControl $f.grading -label "mesh-size grading: " -integer false \ + -variable options.grading -min 0.1 -max 1 -step 0.1 \ + -options { + entry.width 6 + label.width 25 + label.anchor e + } + + pack $f.meshsize $f.minmeshsize $f.grading + + + + frame $f.msf + pack $f.msf + + tixLabelEntry $f.msf.ent -label "mesh-size file: " \ + -labelside top \ + -options { + entry.textVariable options.meshsizefilename + entry.width 35 + label.width 25 + label.anchor w + } + button $f.msf.btn -text "Browse" -command { + global options.meshsizefilename + set types { + {"Meshsize file" {.msz} } } + set options.meshsizefilename [tk_getOpenFile -filetypes $types -initialfile ${options.meshsizefilename}] + } + + pack $f.msf.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 + pack $f.msf.btn -side left -anchor s -padx 4 -pady 4 + + + label $f.lab -text "Additional mesh size restrictions:" + + #csg-meshsize options + + frame $f.csg -relief groove -borderwidth 3 + pack $f.csg -fill x + + + frame $f.csg.curv + pack $f.csg.curv -anchor w + + scale $f.csg.curv.sc -orient horizontal -length 200 -from 0.2 -to 5 \ + -resolution 0.1 -variable options.curvaturesafety + label $f.csg.curv.la -text "Elements per curvature radius" + pack $f.csg.curv.sc $f.csg.curv.la -side left + + frame $f.csg.elen + pack $f.csg.elen -anchor w + scale $f.csg.elen.sc -orient horizontal -length 200 -from 0.2 -to 5 \ + -resolution 0.1 -variable options.segmentsperedge + label $f.csg.elen.la -text "Elements per edge" + pack $f.csg.elen.sc $f.csg.elen.la -side left + + + #stl-meshsize options + + frame $f.stl -relief groove -borderwidth 3 + pack $f.stl -fill x + + frame $f.stl.r2 + pack $f.stl.r2 -anchor w + scale $f.stl.r2.sc -orient horizontal -length 200 -from 0.2 -to 5 \ + -resolution 0.1 -variable stloptions.resthchartdistfac + checkbutton $f.stl.r2.bu -text "STL - chart distance" \ + -variable stloptions.resthchartdistenable + pack $f.stl.r2.sc $f.stl.r2.bu -side left + + frame $f.stl.r6 + pack $f.stl.r6 -anchor w + scale $f.stl.r6.sc -orient horizontal -length 200 -from 0.2 -to 5 \ + -resolution 0.1 -variable stloptions.resthlinelengthfac + checkbutton $f.stl.r6.bu -text "STL - line length" \ + -variable stloptions.resthlinelengthenable + pack $f.stl.r6.sc $f.stl.r6.bu -side left + + frame $f.stl.r3 + pack $f.stl.r3 -anchor w + scale $f.stl.r3.sc -orient horizontal -length 200 -from 0.2 -to 8 \ + -resolution 0.1 -variable stloptions.resthcloseedgefac + checkbutton $f.stl.r3.bu -text "STL/IGES/STEP - close edges" \ + -variable stloptions.resthcloseedgeenable + pack $f.stl.r3.sc $f.stl.r3.bu -side left + + frame $f.stl.r1b + pack $f.stl.r1b -anchor w + scale $f.stl.r1b.sc -orient horizontal -length 200 -from 0.002 -to 10 \ + -resolution 0.002 -variable stloptions.resthminedgelen + checkbutton $f.stl.r1b.bu -text "IGES/STEP - min edge length" \ + -variable stloptions.resthminedgelenenable + pack $f.stl.r1b.sc $f.stl.r1b.bu -side left + + frame $f.stl.r1 + pack $f.stl.r1 -anchor w + scale $f.stl.r1.sc -orient horizontal -length 200 -from 0.2 -to 5 \ + -resolution 0.1 -variable stloptions.resthsurfcurvfac + checkbutton $f.stl.r1.bu -text "STL - surface curvature" \ + -variable stloptions.resthsurfcurvenable + pack $f.stl.r1.sc $f.stl.r1.bu -side left + + frame $f.stl.r3b + pack $f.stl.r3b -anchor w + scale $f.stl.r3b.sc -orient horizontal -length 200 -from 0.2 -to 5 \ + -resolution 0.1 -variable stloptions.resthedgeanglefac + checkbutton $f.stl.r3b.bu -text "STL - edge angle" \ + -variable stloptions.resthedgeangleenable + pack $f.stl.r3b.sc $f.stl.r3b.bu -side left + + frame $f.stl.r5 + pack $f.stl.r5 -anchor w + scale $f.stl.r5.sc -orient horizontal -length 200 -from 0.2 -to 5 \ + -resolution 0.1 -variable stloptions.resthsurfmeshcurvfac + checkbutton $f.stl.r5.bu -text "STL - surface mesh curv" \ + -variable stloptions.resthsurfmeshcurvenable + pack $f.stl.r5.sc $f.stl.r5.bu -side left + + + checkbutton $f.stl.recalch -text "STL - Recalc mesh size for surface optimization" \ + -variable stloptions.recalchopt + pack $f.stl.recalch + + button $f.stl.calch -text "Calc New H" -command { redraw; Ng_STLCalcLocalH } + pack $f.stl.calch + + + + + + + set f [$w.nb subwidget chartopt] + + + label $f.lab1 -text "Yellow Edges Angle ()" + scale $f.scale1 -orient horizontal -length 300 \ + -from 0 -to 90 -resolution 1 -tickinterval 10 \ + -variable stloptions.yangle + + pack $f.lab1 $f.scale1 + + label $f.lab2e -text "Edge Corner Angle ()" + scale $f.scale2e -orient horizontal -length 360 -from 0 -to 180 \ + -resolution 1 -tickinterval 20 \ + -variable stloptions.edgecornerangle + pack $f.lab2e $f.scale2e + + label $f.lab2 -text "Chart Angle ()" + scale $f.scale2 -orient horizontal -length 360 -from 0 -to 180 \ + -resolution 1 -tickinterval 20 \ + -variable stloptions.chartangle + pack $f.lab2 $f.scale2 + + label $f.lab2b -text "Outer Chart Angle ()" + scale $f.scale2b -orient horizontal -length 360 -from 0 -to 180 \ + -resolution 1 -tickinterval 20 \ + -variable stloptions.outerchartangle + pack $f.lab2b $f.scale2b + + + + + # Optimization options + + set f [$w.nb subwidget optimizer] + + + + + tixControl $f.os2d -label "Surface opt steps: " -integer true \ + -variable options.optsteps2d -min 0 -max 99 -step 1 \ + -options { + entry.width 3 + label.width 25 + label.anchor e + } + + tixControl $f.os3d -label "Volume opt steps: " -integer true \ + -variable options.optsteps3d -min 0 -max 99 -step 1 \ + -options { + entry.width 3 + label.width 25 + label.anchor e + } + + tixControl $f.elw -label "Element size weight: " -integer false \ + -variable options.elsizeweight -min 0 -max 1 -step 0.1 \ + -options { + entry.width 3 + label.width 25 + label.anchor e + } + + tixControl $f.wem -label "Worst element measure: " -integer false \ + -variable options.opterrpow -min 1 -max 10 -step 1 \ + -options { + entry.width 3 + label.width 25 + label.anchor e + } + + pack $f.os2d $f.os3d $f.elw $f.wem + + frame $f.badellimit + pack $f.badellimit -fill x + label $f.badellimit.lab -text "bad element criterion"; + scale $f.badellimit.scale -orient horizontal -length 150 \ + -from 160 -to 180 -resolution 1 \ + -variable options.badellimit + pack $f.badellimit.scale $f.badellimit.lab -side right -anchor s + + + # insider options + set f [$w.nb subwidget insider] + + + + checkbutton $f.localh -text "Use Local Meshsize" \ + -variable options.localh + checkbutton $f.delauney -text "Use Delaunay" \ + -variable options.delaunay + checkbutton $f.checkoverlap -text "Check Overlapping" \ + -variable options.checkoverlap + checkbutton $f.checkcb -text "Check Chart Boundary" \ + -variable options.checkchartboundary + checkbutton $f.blockfill -text "Do Blockfilling" \ + -variable options.blockfill + + pack $f.localh $f.delauney $f.checkoverlap $f.blockfill $f.checkcb -anchor w + + + + + # debugging options + set f [$w.nb subwidget debug] + + frame $f.cb + pack $f.cb -side top + + + + checkbutton $f.cb.slowchecks -text "Slow checks" \ + -variable debug.slowchecks -command { Ng_SetDebugParameters } + checkbutton $f.cb.debugoutput -text "Debugging outout" \ + -variable debug.debugoutput -command { Ng_SetDebugParameters } + checkbutton $f.cb.haltexline -text "Halt on exising line" \ + -variable debug.haltexistingline -command { Ng_SetDebugParameters } + checkbutton $f.cb.haltoverlap -text "Halt on Overlap" \ + -variable debug.haltoverlap -command { Ng_SetDebugParameters } + checkbutton $f.cb.haltsuc -text "Halt on success" \ + -variable debug.haltsuccess -command { Ng_SetDebugParameters } + checkbutton $f.cb.haltnosuc -text "Halt on no success" \ + -variable debug.haltnosuccess -command { Ng_SetDebugParameters } + checkbutton $f.cb.haltlargequal -text "Halt on large quality class" \ + -variable debug.haltlargequalclass -command { Ng_SetDebugParameters } + checkbutton $f.cb.haltseg -text "Halt on Segment:" \ + -variable debug.haltsegment -command { Ng_SetDebugParameters } + checkbutton $f.cb.haltnode -text "Halt on Node:" \ + -variable debug.haltnode -command { Ng_SetDebugParameters } + + + pack $f.cb.slowchecks $f.cb.debugoutput $f.cb.haltexline $f.cb.haltoverlap $f.cb.haltsuc $f.cb.haltnosuc $f.cb.haltlargequal $f.cb.haltseg $f.cb.haltnode + + frame $f.cb.hf + pack $f.cb.hf -pady 5 + checkbutton $f.cb.hf.cb -text "Halt on Face:" \ + -variable debug.haltface -command { Ng_SetDebugParameters } + entry $f.cb.hf.ent -textvariable debug.haltfacenr -width 5 + pack $f.cb.hf.cb $f.cb.hf.ent -side left + + checkbutton $f.cb.showactivechart -text "Show Active Meshing-Chart" \ + -variable stloptions.showactivechart -command { Ng_SetVisParameters; redraw } + + + + + pack $f.cb.showactivechart + + + frame $f.segs + pack $f.segs -pady 5 + label $f.segs.lab1 -text "P1:"; + entry $f.segs.ent1 -width 8 -relief sunken \ + -textvariable debug.haltsegmentp1 + label $f.segs.lab2 -text "P2:"; + entry $f.segs.ent2 -width 8 -relief sunken \ + -textvariable debug.haltsegmentp2 + pack $f.segs.lab1 $f.segs.ent1 $f.segs.lab2 $f.segs.ent2 -side left + + + + frame $f.cont -relief groove -borderwidth 3 + pack $f.cont + #-fill x + + checkbutton $f.cont.multidrawing -text "Draw Meshing" \ + -variable multithread_drawing + pack $f.cont.multidrawing + + checkbutton $f.cont.multitestmode -text "Meshing Testmode" \ + -variable multithread_testmode + pack $f.cont.multitestmode + + button $f.cont.goon -text "Go On" -command { set multithread_pause 0 } + pack $f.cont.multidrawing $f.cont.multitestmode $f.cont.goon -side left -expand yes + + + + + global userlevel + if { $userlevel < 3} { + $w.nb delete insider + $w.nb delete debug + } + + + +# tixButtonBox $w.bbox -orientation horizontal +# $w.bbox add ok -text Apply -underline 0 -width 5 \ +# -command { +# [.options_dlg.nb subwidget meshsize].meshsize invoke +# [.options_dlg.nb subwidget meshsize].grading invoke +# [.options_dlg.nb subwidget optimizer].os2d invoke +# [.options_dlg.nb subwidget optimizer].os3d invoke +# [.options_dlg.nb subwidget optimizer].elw invoke +# [.options_dlg.nb subwidget optimizer].wem invoke + +# Ng_SetMeshingParameters +# } + +# $w.bbox add close -text Done -underline 0 -width 5 \ +# -command { +# [.options_dlg.nb subwidget meshsize].meshsize invoke +# [.options_dlg.nb subwidget meshsize].grading invoke +# [.options_dlg.nb subwidget optimizer].os2d invoke +# [.options_dlg.nb subwidget optimizer].os3d invoke +# [.options_dlg.nb subwidget optimizer].elw invoke +# [.options_dlg.nb subwidget optimizer].wem invoke + +# Ng_SetMeshingParameters +# destroy .options_dlg +# } + +# pack $w.bbox -side bottom -fill x + + + frame $w.bu + pack $w.bu -fill x -ipady 3 + + button $w.bu.apl -text "Apply" -command { + [.options_dlg.nb subwidget meshsize].meshsize invoke + [.options_dlg.nb subwidget meshsize].grading invoke + [.options_dlg.nb subwidget optimizer].os2d invoke + [.options_dlg.nb subwidget optimizer].os3d invoke + [.options_dlg.nb subwidget optimizer].elw invoke + [.options_dlg.nb subwidget optimizer].wem invoke + + Ng_SetMeshingParameters + Ng_SetDebugParameters + } + + button $w.bu.ok -text "Done" -command { + [.options_dlg.nb subwidget meshsize].meshsize invoke + [.options_dlg.nb subwidget meshsize].grading invoke + [.options_dlg.nb subwidget optimizer].os2d invoke + [.options_dlg.nb subwidget optimizer].os3d invoke + [.options_dlg.nb subwidget optimizer].elw invoke + [.options_dlg.nb subwidget optimizer].wem invoke + + Ng_SetMeshingParameters + Ng_SetDebugParameters + wm withdraw .options_dlg +# destroy .options_dlg + } + + pack $w.bu.apl $w.bu.ok -side left -expand yes + + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Meshing Options" + focus .options_dlg + } +} + + +meshingoptionsdialog +wm withdraw .options_dlg + + + + + + + + + +# +# +# Viewing dialog +# +# +proc viewingoptionsdialog { } { + + global userlevel + + set w .viewopts_dlg + + if {[winfo exists .viewopts_dlg] == 1} { + wm withdraw $w + wm deiconify $w + focus $w + } { + toplevel $w + + + + + tixNoteBook $w.nb -ipadx 6 -ipady 6 + + $w.nb add general -label "General" -underline 0 + $w.nb add stl -label "STL" -underline 0 + $w.nb add occ -label "IGES/STEP" -underline 0 + $w.nb add mesh -label "Mesh" -underline 0 + $w.nb add light -label "Light" -underline 0 + $w.nb add edges -label "Edges" -underline 0 + $w.nb add misc -label "Misc." -underline 3 + + + pack $w.nb -expand yes -fill both -padx 5 -pady 5 -side top + + + + + + # general + set f [$w.nb subwidget general] + + checkbutton $f.backcol -text "White Background" \ + -variable viewoptions.whitebackground \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $f.cross -text "Draw Coordinate Cross" \ + -variable viewoptions.drawcoordinatecross \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $f.color -text "Draw Color-bar" \ + -variable viewoptions.drawcolorbar \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $f.netgen -text "Draw Netgen-logo" \ + -variable viewoptions.drawnetgenlogo \ + -command { Ng_SetVisParameters; redraw } + + pack $f.backcol $f.cross $f.color $f.netgen + +# checkbutton $f.stereo -text "Stereo View" \ +# -variable viewoptions.stereo \ +# -command { Ng_SetVisParameters; redraw } +# pack $f.stereo + + # stl geometry + set f [$w.nb subwidget stl] + + frame $f.show -relief groove -borderwidth 3 + pack $f.show + checkbutton $f.show.showtrias -text "Show STL-Triangles" \ + -variable stloptions.showtrias -command { Ng_SetVisParameters; redraw } + pack $f.show.showtrias -anchor w + + checkbutton $f.show.showfilledtrias -text "Show Filled Triangles" \ + -variable stloptions.showfilledtrias -command { Ng_SetVisParameters; redraw } + pack $f.show.showfilledtrias -anchor w + + checkbutton $f.show.showactivechart -text "Show Active Meshing-Chart" \ + -variable stloptions.showactivechart -command { Ng_SetVisParameters; redraw } + pack $f.show.showactivechart -anchor w + + checkbutton $f.show.showedges -text "Show Edges" \ + -variable stloptions.showedges -command { Ng_SetVisParameters; redraw } + pack $f.show.showedges -anchor w + + frame $f.special -relief groove -borderwidth 3 + pack $f.special + checkbutton $f.special.showmarktrias -text "Show Chart Triangles" \ + -variable stloptions.showmarktrias \ + -command {set stldoctor.showfaces 0; Ng_STLDoctor; Ng_SetVisParameters; redraw } + pack $f.special.showmarktrias -side left + + checkbutton $f.special.showfaces -text "Show Faces" \ + -variable stldoctor.showfaces \ + -command {set stloptions.showmarktrias 0; Ng_STLDoctor; Ng_SetVisParameters; redraw} + pack $f.special.showfaces -side left + + frame $f.fn -relief groove -borderwidth 3 + pack $f.fn + label $f.fn.lab3 -text "Chart/Face number:" + scale $f.fn.scale3 -orient horizontal -length 200 -from 0 -to 200 \ + -resolution 1 -tickinterval 50 \ + -command { Ng_SetVisParameters; redraw } -variable stloptions.chartnumber + pack $f.fn.lab3 $f.fn.scale3 -side left + + frame $f.fo -relief groove -borderwidth 3 + pack $f.fo + label $f.fo.lab -text "Chart/Face Offset:"; + entry $f.fo.ent -width 5 -relief sunken \ + -textvariable stloptions.chartnumberoffset + pack $f.fo.lab $f.fo.ent -side left + + frame $f.mt + pack $f.mt -fill x + checkbutton $f.mt.bu -text "Show Marked (Dirty) Triangles" \ + -variable stldoctor.showmarkedtrigs \ + -command {Ng_STLDoctor; redraw} + pack $f.mt.bu + + frame $f.ep + pack $f.ep -fill x + checkbutton $f.ep.bu -text "show edge corner points" \ + -variable stldoctor.showedgecornerpoints \ + -command {Ng_STLDoctor; redraw} + pack $f.ep.bu + + frame $f.stt + pack $f.stt -fill x + checkbutton $f.stt.bu -text "show touched triangle chart" \ + -variable stldoctor.showtouchedtrigchart \ + -command {set stldoctor.showfaces 0; set stloptions.showmarktrias 1; \ + Ng_STLDoctor; Ng_SetVisParameters; redraw} + pack $f.stt.bu + + frame $f.sml + pack $f.sml -fill x + checkbutton $f.sml.bu -text "draw meshed edges" \ + -variable stldoctor.drawmeshededges \ + -command {Ng_STLDoctor;} + pack $f.sml.bu + + + frame $f.sm + pack $f.sm -fill x + checkbutton $f.sm.bu -text "select with mouse" \ + -variable stldoctor.selectwithmouse + pack $f.sm.bu + + frame $f.st -relief groove -borderwidth 3 + pack $f.st -fill x + label $f.st.lab -text "Select triangle by number"; + entry $f.st.ent -width 5 -relief sunken \ + -textvariable stldoctor.selecttrig + pack $f.st.ent $f.st.lab -side left -expand yes + + frame $f.vc -relief groove -borderwidth 3 + pack $f.vc -fill x + checkbutton $f.vc.bu -text "show vicinity" \ + -variable stldoctor.showvicinity \ + -command {Ng_STLDoctor vicinity; redraw} + label $f.vc.lab -text "vicinity size"; + scale $f.vc.sc -orient horizontal -length 200 -from 0 -to 200 \ + -resolution 1 -variable stldoctor.vicinity \ + -command { Ng_STLDoctor vicinity; redraw } + pack $f.vc.bu $f.vc.lab $f.vc.sc -expand yes + + + + # IGES/STEP + set f [$w.nb subwidget occ] + + checkbutton $f.occshowsurfaces -text "Show surfaces " \ + -variable occoptions.showsurfaces \ + -command { Ng_SetOCCVisParameters; redraw } + + checkbutton $f.occshowedges -text "Show edges " \ + -variable occoptions.showedges \ + -command { Ng_SetOCCVisParameters; redraw } + + frame $f.deflection -relief groove -borderwidth 3 + pack $f.deflection -fill x + button $f.deflection.lab -text "Rebuild visualization data" \ + -command { + Ng_SetOCCVisParameters + Ng_OCCCommand buildvisualizationmesh + redraw + } + + tixControl $f.deflection.ent -label "Visualization smoothness" -integer false \ + -variable occoptions.deflection -min 0.1 -max 3 -step 0.1 \ + -options { entry.width 3 } \ + -command { Ng_SetOCCVisParameters } + + + + + + pack $f.deflection.ent $f.deflection.lab -side left -expand yes + pack $f.occshowsurfaces $f.occshowedges + + + # ACIS visualization / construction + + tixControl $f.showsolid -label "Show solid (0 for all)" -integer true \ + -variable occoptions.showsolidnr -min 0 -max 999 \ + -options { entry.width 3 } \ + -command { Ng_SetOCCVisParameters; redraw } + + tixControl $f.showsolid2 -label "Show solid 2" -integer true \ + -variable occoptions.showsolidnr2 -min 0 -max 999 \ + -options { entry.width 3 } \ + -command { Ng_SetOCCVisParameters; redraw } + + button $f.subtract -text "Subtract (2 minus 1)" \ + -command { + Ng_ACISCommand subtract ${occoptions.showsolidnr} ${occoptions.showsolidnr2} + redraw + } + + button $f.combine -text "Combine all" \ + -command { + Ng_ACISCommand combineall + redraw + } + + pack $f.showsolid $f.showsolid2 $f.subtract $f.combine + + + + + # mesh options + set f [$w.nb subwidget mesh] + + checkbutton $f.showcolor -text "Colored Meshsize Visualization" \ + -variable viewoptions.colormeshsize \ + -command { Ng_SetVisParameters; redraw } + + + checkbutton $f.showfilledtrigs -text "Show filled triangles" \ + -variable viewoptions.drawfilledtrigs \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $f.showedges -text "Show edges" \ + -variable viewoptions.drawedges \ + -command { Ng_SetVisParameters; redraw } + + + checkbutton $f.showoutline -text "Show Triangle Outline" \ + -variable viewoptions.drawoutline \ + -command { Ng_SetVisParameters; redraw } + + + tixControl $f.subdiv -label "Subdivision" -integer true \ + -variable visoptions.subdivisions -min 0 -max 8 \ + -options { entry.width 2 } \ + -command { Ng_SetVisParameters; Ng_Vis_Set parameters; Ng_SetNextTimeStamp; redraw } + + + checkbutton $f.showbadels -text "Show bad elements" \ + -variable viewoptions.drawbadels \ + -command { Ng_SetVisParameters; redraw } + + + + checkbutton $f.showprisms -text "Show prisms" \ + -variable viewoptions.drawprisms \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $f.showpyramids -text "Show pyramids" \ + -variable viewoptions.drawpyramids \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $f.showhexes -text "Show hexes" \ + -variable viewoptions.drawhexes \ + -command { Ng_SetVisParameters; redraw } + + frame $f.fshrink + label $f.fshrink.lab -text "Shrink elements" + scale $f.fshrink.scale -orient horizontal -length 200 -from 0 -to 1.0001 \ + -resolution 0.01 -tickinterval 0.25 \ + -command { Ng_SetVisParameters; redraw } -variable viewoptions.shrink + + + checkbutton $f.showidentified -text "Show identified points" \ + -variable viewoptions.drawidentified \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $f.showmetispartition -text "Show METIS Partition" \ + -variable viewoptions.drawmetispartition \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $f.showpointnumbers -text "Show Point-numbers" \ + -variable viewoptions.drawpointnumbers \ + -command { Ng_SetVisParameters; redraw } + checkbutton $f.showedgenumbers -text "Show Edge-numbers" \ + -variable viewoptions.drawedgenumbers \ + -command { Ng_SetVisParameters; redraw } + checkbutton $f.showfacenumbers -text "Show Face-numbers" \ + -variable viewoptions.drawfacenumbers \ + -command { Ng_SetVisParameters; redraw } + checkbutton $f.showelementnumbers -text "Show Element-numbers" \ + -variable viewoptions.drawelementnumbers \ + -command { Ng_SetVisParameters; redraw } + + # label $f.showdomainlab -text "Domain Surface" +# scale $f.showdomain -orient horizontal -length 100 -from 0 -to 50 \ + -resolution 1 -variable viewoptions.drawdomainsurf \ + -command { Ng_SetVisParameters; redraw } \ + -label "Domain Surface" + + tixControl $f.showdomain -label "Show surface of domain" -integer true \ + -variable viewoptions.drawdomainsurf -min 0 -max 50 \ + -options { entry.width 2 } \ + -command { Ng_SetVisParameters; Ng_Vis_Set parameters; redraw } + + + + + frame $f.center -relief groove -borderwidth 3 + pack $f.center -fill x + button $f.center.lab -text "Set Center Point" \ + -command { Ng_SetVisParameters; Ng_Center; redraw } + entry $f.center.ent -width 5 -relief sunken \ + -textvariable viewoptions.centerpoint + pack $f.center.ent $f.center.lab -side left -expand yes + + frame $f.drawel -relief groove -borderwidth 3 + pack $f.drawel -fill x + button $f.drawel.lab -text "Draw Element" \ + -command { Ng_SetVisParameters; Ng_ZoomAll; redraw } + entry $f.drawel.ent -width 5 -relief sunken \ + -textvariable viewoptions.drawelement + pack $f.drawel.ent $f.drawel.lab -side left -expand yes + + pack $f.showfilledtrigs + pack $f.showoutline $f.subdiv $f.showedges $f.showbadels + # pack $f.showdomainlab + pack $f.showdomain + pack $f.showpointnumbers + pack $f.showedgenumbers $f.showfacenumbers $f.showelementnumbers + pack $f.showmetispartition + + + frame $f.frametets + checkbutton $f.frametets.showtets -text "Show Tets in domain " \ + -variable viewoptions.drawtets \ + -command { Ng_SetVisParameters; redraw } + tixControl $f.frametets.showtetsdomain -label "" -integer true \ + -variable viewoptions.drawtetsdomain -min 0 -max 500 \ + -options { entry.width 2 } \ + -command { Ng_SetVisParameters; redraw } + + pack $f.frametets + pack $f.frametets.showtets $f.frametets.showtetsdomain -side left + + + pack $f.showcolor $f.showpyramids $f.showprisms $f.showhexes $f.showidentified + + pack $f.fshrink + pack $f.fshrink.lab $f.fshrink.scale -side left + +# if {$userlevel == 3} { +# frame $f.framecurveproj +# checkbutton $f.framecurveproj.showcurveproj -text "Show curved edge projection " \ + -variable viewoptions.drawcurveproj \ + -command { Ng_SetVisParameters; redraw } + # tixControl $f.framecurveproj.showcurveprojedge -label "" -integer true \ + -variable viewoptions.drawcurveprojedge -min 1 -max 99999 \ + -options { entry.width 5 } \ + -command { Ng_SetVisParameters; redraw } + +# pack $f.framecurveproj +# pack $f.framecurveproj.showcurveproj $f.framecurveproj.showcurveprojedge -side left +# } + + + + + + + # light options + set f [$w.nb subwidget light] + + label $f.lab1 -text "Ambient Light" + scale $f.scale1 -orient horizontal -length 300 -from 0 -to 1 \ + -resolution 0.01 -tickinterval 0.2 \ + -command { Ng_SetVisParameters; redraw } -variable viewoptions.light.amb + label $f.lab2 -text "Diffuse Light" + scale $f.scale2 -orient horizontal -length 300 -from 0 -to 1 \ + -resolution 0.01 -tickinterval 0.2 \ + -command { Ng_SetVisParameters; redraw } -variable viewoptions.light.diff + label $f.lab3 -text "Specular Light" + scale $f.scale3 -orient horizontal -length 300 -from 0 -to 1 \ + -resolution 0.01 -tickinterval 0.2 \ + -command { Ng_SetVisParameters; redraw } -variable viewoptions.light.spec + label $f.lab4 -text "Material Shininess" + scale $f.scale4 -orient horizontal -length 300 -from 0 -to 128 \ + -resolution 1 -tickinterval 32 \ + -command { Ng_SetVisParameters; redraw } -variable viewoptions.mat.shininess + label $f.lab5 -text "Material Transparency" + scale $f.scale5 -orient horizontal -length 300 -from 0 -to 1 \ + -resolution 0.01 -tickinterval 0.2 \ + -command { Ng_SetVisParameters; redraw } -variable viewoptions.mat.transp + + pack $f.lab1 $f.scale1 $f.lab2 $f.scale2 $f.lab3 $f.scale3 $f.lab4 $f.scale4 $f.lab5 $f.scale5 + + + + + + # edges options + set f [$w.nb subwidget edges] + + checkbutton $f.showedges -text "Show Edges" \ + -variable viewoptions.drawededges \ + -command { Ng_SetVisParameters; redraw } + checkbutton $f.showpoints -text "Show Points" \ + -variable viewoptions.drawedpoints \ + -command { Ng_SetVisParameters; redraw } + checkbutton $f.showpointnrs -text "Show Points Nrs" \ + -variable viewoptions.drawedpointnrs \ + -command { Ng_SetVisParameters; redraw } + checkbutton $f.showtang -text "Show CP Tangents" \ + -variable viewoptions.drawedtangents \ + -command { Ng_SetVisParameters; redraw } + checkbutton $f.drawedgenrs -text "Show Edge Nrs" \ + -variable viewoptions.drawededgenrs \ + -command { Ng_SetVisParameters; redraw } + + pack $f.showedges $f.showpoints $f.showpointnrs $f.showtang $f.drawedgenrs + + frame $f.center -relief groove -borderwidth 3 + pack $f.center -fill x + button $f.center.lab -text "Set Center Point" \ + -command { Ng_SetVisParameters; Ng_Center; redraw } + entry $f.center.ent -width 5 -relief sunken \ + -textvariable viewoptions.centerpoint + pack $f.center.ent $f.center.lab -side left -expand yes + + + + frame $f.f1 + pack $f.f1 -pady 5 + label $f.f1.lab -text "SpecPoint Veclen" + entry $f.f1.ent -width 5 -relief sunken -textvariable viewoptions.specpointvlen + pack $f.f1.lab $f.f1.ent + + + + + # misc options + set f [$w.nb subwidget misc] + + frame $f.point -relief groove -borderwidth 3 + + frame $f.point.dp + + checkbutton $f.point.dp.drawpoint -text "Draw Point" \ + -variable viewoptions.drawspecpoint \ + -command { Ng_SetVisParameters; redraw } + + entry $f.point.dp.px -width 8 -relief sunken -textvariable viewoptions.specpointx + entry $f.point.dp.py -width 8 -relief sunken -textvariable viewoptions.specpointy + entry $f.point.dp.pz -width 8 -relief sunken -textvariable viewoptions.specpointz + + pack $f.point.dp.drawpoint $f.point.dp.px $f.point.dp.py $f.point.dp.pz -side left + + pack $f.point.dp + + checkbutton $f.point.center -text "Use as Center" \ + -variable viewoptions.usecentercoords \ + -command { + if { ${viewoptions.usecentercoords} } { + set viewoptions.centerx ${viewoptions.specpointx} + set viewoptions.centery ${viewoptions.specpointy} + set viewoptions.centerz ${viewoptions.specpointz} + Ng_SetVisParameters; Ng_Center + redraw + } { + Ng_SetVisParameters + } + + + } + + pack $f.point.center + + pack $f.point -fill x -ipady 3 + + + + frame $w.bu + pack $w.bu -fill x -ipady 3 + + + button $w.bu.done -text "Done" -command { + Ng_SetVisParameters; + redraw + destroy .viewopts_dlg + } + button $w.bu.apply -text "Apply" -command { + Ng_SetVisParameters; + redraw + } + pack $w.bu.apply $w.bu.done -expand yes -side left + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Viewing options" + focus $w + } +} + + + +proc clipplanecommand { { optionalvar 0 } } { + Ng_SetVisParameters + after idle redraw +} + + +set clippingdialog_pop1 0 +set clippingdialog_pop2 0 +set clippingdialog_pop3 0 +set clippingdialog_pop4 0 + + +# +# +# clipping dialog +# +# +proc clippingdialog { } { + + global clippingdialog_pop1 + global clippingdialog_pop2 + global clippingdialog_pop3 + global clippingdialog_pop4 + set clippingdialog_pop1 1 + set clippingdialog_pop2 1 + set clippingdialog_pop3 1 + set clippingdialog_pop4 1 + + set w .clipping_dlg + + if {[winfo exists .clipping_dlg] == 1} { + + wm withdraw $w + wm deiconify $w + focus $w + + } { + toplevel $w + + label $w.lab1 -text "Normal x" + scale $w.scale1 -orient horizontal -length 300 -from -1 -to 1 \ + -resolution 0.01 -tickinterval 0.5 \ + -variable viewoptions.clipping.nx \ + -command { clipplanecommand } +# -command { popupcheckredraw2 clippingdialog_pop1 ${viewoptions.clipping.enable} } + +# Ng_SetVisParameters; +# if { ${viewoptions.clipping.enable} == 1 } { redraw }; +# Ng_SetVisParameters + + label $w.lab2 -text "Normal y" + scale $w.scale2 -orient horizontal -length 300 -from -1 -to 1 \ + -resolution 0.01 -tickinterval 0.5 \ + -variable viewoptions.clipping.ny \ + -command { clipplanecommand } +# -command { popupcheckredraw2 clippingdialog_pop2 ${viewoptions.clipping.enable} } + + label $w.lab3 -text "Normal z" + scale $w.scale3 -orient horizontal -length 300 -from -1 -to 1 \ + -resolution 0.01 -tickinterval 0.5 \ + -variable viewoptions.clipping.nz \ + -command { clipplanecommand } +# -command { popupcheckredraw2 clippingdialog_pop3 ${viewoptions.clipping.enable} } + label $w.lab4 -text "Distance" + scale $w.scale4 -orient horizontal -length 300 -from -1 -to 1.001 \ + -resolution 0.0001 -tickinterval 0.5 \ + -variable viewoptions.clipping.dist \ + -command { clipplanecommand } +# -command { popupcheckredraw2 clippingdialog_pop4 ${viewoptions.clipping.enable} } + + label $w.lab5 -text "Additional Distance" + scale $w.scale5 -orient horizontal -length 300 -from -1 -to 1.001 \ + -resolution 0.0001 -tickinterval 0.5 \ + -variable viewoptions.clipping.dist2 \ + -command { clipplanecommand } + + + + tixControl $w.clipdomain -label "Clip only domain" -integer true \ + -variable viewoptions.clipping.onlydomain -min 0 -max 50 \ + -options { entry.width 2 } \ + -command { clipplanecommand; } +# -command { Ng_SetVisParameters; redraw } + tixControl $w.donotclipdomain -label "Do not clip domain" -integer true \ + -variable viewoptions.clipping.notdomain -min 0 -max 50 \ + -options { entry.width 2 } \ + -command { clipplanecommand; } +# -command { Ng_SetVisParameters; redraw } + + pack $w.lab1 $w.scale1 $w.lab2 $w.scale2 $w.lab3 $w.scale3 $w.lab4 $w.scale4 $w.lab5 $w.scale5 $w.clipdomain $w.donotclipdomain + + + checkbutton $w.cb1 -text "Enable clipping" \ + -variable viewoptions.clipping.enable \ + -command { Ng_SetVisParameters; redraw } + + pack $w.cb1 + + + + frame $w.bu +# pack $w.bu -fill x + pack $w.bu -fill x -ipady 3 + + button $w.bu.cancle -text "Done" -command "destroy $w" + pack $w.bu.cancle -expand yes + + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Clipping Plane" + # grab $w + focus $w + +# $w.scale1 configure -command { puts "call1b"; Ng_SetVisParameters; redraw } +# puts "after" + + clipplanecommand + } +} + + + + + +# +# refinement dialog +# +# +proc refinementdialog { } { + + set w .refinement_dlg + + if {[winfo exists .refinement_dlg] == 1} { + wm withdraw $w + wm deiconify $w + focus $w + } { + + toplevel $w + + + tixControl $w.meshsize -label "max mesh-size: " -integer false \ + -variable options.meshsize -min 1e-6 -max 1e6 \ + -options { + entry.width 6 + label.width 25 + label.anchor e + } + + pack $w.meshsize + + global localh + set localh 1 + tixControl $w.loch -label "local mesh-size: " -integer false \ + -variable localh -min 1e-6 -max 1e6 \ + -options { + entry.width 6 + label.width 25 + label.anchor e + } + + pack $w.loch + + + button $w.restface -text "Restrict H at face" \ + -command { + .refinement_dlg.meshsize invoke + .refinement_dlg.loch invoke + Ng_RestrictH face $localh + } + button $w.restedge -text "Restrict H at edge" \ + -command { + .refinement_dlg.meshsize invoke + .refinement_dlg.loch invoke + Ng_RestrictH edge $localh + } + button $w.restelement -text "Restrict H at element" \ + -command { + .refinement_dlg.meshsize invoke + .refinement_dlg.loch invoke + Ng_RestrictH element $localh + } + button $w.restpoint -text "Restrict H at point" \ + -command { + .refinement_dlg.meshsize invoke + .refinement_dlg.loch invoke + Ng_RestrictH point $localh + } + + + pack $w.restface $w.restedge $w.restelement $w.restpoint + + + + button $w.anisoedge -text "Declare Anisotropic edge" \ + -command { + Ng_Anisotropy edge + } + pack $w.anisoedge + + + frame $w.bu + pack $w.bu -fill x -ipady 3 + + + button $w.bu.cancle -text "Done" -command "destroy .refinement_dlg" + button $w.bu.refine -text "Refine" \ + -command { +# Ng_BisectCopyMesh; + set oldnp 0; set newnp $status_np; + while { $oldnp < $newnp } { + set level [expr $level+1] + Ng_Bisect; + Ng_HighOrder ${options.elementorder} + Ng_ReadStatus; + redraw; + set oldnp $newnp + set newnp $status_np + puts "oldnp $oldnp newnp $newnp" + } + } + button $w.bu.zrefine -text "Z-Refine" \ + -command { Ng_ZRefinement; Ng_ReadStatus; redraw; } + + pack $w.bu.zrefine $w.bu.refine $w.bu.cancle -expand yes -side left + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Select Refinement" + focus $w + } +} + + + + +# +# boundcondessing dialog +# +# +proc bcpropdialog { } { + + set w .bcprop_dlg + + if {[winfo exists .bcprop_dlg] == 1} { + wm withdraw $w + wm deiconify $w + } { + toplevel $w + + frame $w.face -borderwidth 3 + pack $w.face -fill x + label $w.face.lab -text "face index:" + label $w.face.ent -text 1 -padx 4 + button $w.face.next -text "next" -command { + set w .bcprop_dlg; + set facenr [$w.face.ent cget -text] + if {$facenr == [Ng_BCProp getnfd]} { + set facenr 1 + } { + set facenr [expr $facenr + 1] + } + $w.face.ent configure -text $facenr + Ng_BCProp setactive $facenr + set bcnr [Ng_BCProp getbc $facenr] + $w.bc.ent delete 0 end + $w.bc.ent insert 0 $bcnr + + redraw + } + button $w.face.prev -text "prev" -command { + set w .bcprop_dlg; + set facenr [$w.face.ent cget -text] + if {$facenr == 1} { + set facenr [Ng_BCProp getnfd] + } { + set facenr [expr $facenr - 1] + } + $w.face.ent configure -text $facenr + Ng_BCProp setactive $facenr + set bcnr [Ng_BCProp getbc $facenr] + $w.bc.ent delete 0 end + $w.bc.ent insert 0 $bcnr + + redraw + } + + + pack $w.face.lab $w.face.ent $w.face.prev $w.face.next -side left + + frame $w.bc -borderwidth 3 + pack $w.bc -fill x + label $w.bc.lab -text "bc property:" + entry $w.bc.ent -width 5 -relief sunken + button $w.bc.but -text "change" -command { + set w .bcprop_dlg; + Ng_BCProp setbc [$w.face.ent cget -text] [$w.bc.ent get]; + } + button $w.bc.but2 -text "all" -command { + set w .bcprop_dlg; + Ng_BCProp setall [$w.bc.ent get]; + } + pack $w.bc.lab $w.bc.ent $w.bc.but $w.bc.but2 -side left -expand yes + + frame $w.bcname -borderwidth 3 + pack $w.bcname -fill x + label $w.bcname.lab -text "bc name:" + label $w.bcname.ent -text "-" + pack $w.bcname.lab $w.bcname.ent -side left -expand yes + + + frame $w.bu + pack $w.bu -fill x -ipady 3 + + button $w.bu.close -text "Close" -command { destroy .bcprop_dlg } + + pack $w.bu.close -expand yes -side left + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Boundary Conditions" + } + + focus $w + + set facenr [Ng_BCProp getactive] + $w.face.ent configure -text $facenr + + set bcnr [Ng_BCProp getbc $facenr] + $w.bc.ent delete 0 end + $w.bc.ent insert 0 $bcnr + + set bcname [Ng_BCProp getbcname $facenr] + $w.bcname.ent configure -text $bcname + +} + + + + +# +# Philippose - 25/07/2010 +# Display the face colours currently +# available in the mesh +# +proc currmeshcoloursdialog { } { + + set w .currmeshcolours_dlg + + if {[winfo exists .currmeshcolours_dlg] == 1} { + wm withdraw $w + wm deiconify $w + focus $w + } { + toplevel $w + + global facecolslist + + frame $w.facecols -borderwidth 3 + + listbox $w.facecols.list -yscroll "$w.facecols.scroll set" -selectmode single -setgrid 1 -width 32 -height 12 + scrollbar $w.facecols.scroll -command "$w.facecols.list yview" + pack $w.facecols.scroll -side right -fill y + pack $w.facecols.list -side left -expand yes -fill both + + Ng_CurrentFaceColours getcolours facecolslist + set i 1 + foreach el $facecolslist { + set hel [format "%d: (%.4f %.4f %.4f)" $i [ lindex $el 0 ] [ lindex $el 1 ] [ lindex $el 2 ]] + incr i + $w.facecols.list insert end $hel } + + frame $w.bu1 -borderwidth 3 + button $w.bu1.showonly -text "show only" -command { + Ng_CurrentFaceColours showonly [.currmeshcolours_dlg.facecols.list curselection] + redraw + } + button $w.bu1.hideonly -text "hide only" -command { + Ng_CurrentFaceColours hideonly [.currmeshcolours_dlg.facecols.list curselection] + redraw + } + button $w.bu1.showalso -text "show" -command { + Ng_CurrentFaceColours showalso [.currmeshcolours_dlg.facecols.list curselection] + redraw + } + button $w.bu1.hidealso -text "hide" -command { + Ng_CurrentFaceColours hidealso [.currmeshcolours_dlg.facecols.list curselection] + redraw + } + pack $w.bu1.showonly $w.bu1.hideonly $w.bu1.showalso $w.bu1.hidealso -expand yes -fill x -padx 2 -pady 2 -side left + + frame $w.bu2 + button $w.bu2.showall -text "show all" -command { + Ng_CurrentFaceColours showall + redraw + } + button $w.bu2.hideall -text "hide all" -command { + Ng_CurrentFaceColours hideall + redraw + } + pack $w.bu2.showall $w.bu2.hideall -expand yes -fill x -padx 2 -pady 2 -side left + + frame $w.bu3 + button $w.bu3.close -text "close" -command { + destroy .currmeshcolours_dlg + } + pack $w.bu3.close -expand yes -fill x -pady 3 -side right + + + pack $w.facecols -side top -expand yes -fill x -fill y + pack $w.bu3 -side bottom + pack $w.bu2 -side bottom + pack $w.bu1 -expand yes -fill x -side left + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Inspect Mesh Colours" + focus $w + } +} + + + + +# +# Philippose - 30/01/2009 +# Local Surface Mesh Size Selection +# (Currently only supports OCC Geometry) +# +# +proc surfacemeshsizedialog { } { + + set w .surfacemeshsize_dlg + + if {[winfo exists .surfacemeshsize_dlg] == 1} { + wm withdraw $w + wm deiconify $w + } { + toplevel $w + + frame $w.face -borderwidth 3 + pack $w.face -fill x -padx 5 + label $w.face.lab -text "face index:" + label $w.face.ent -text 1 -padx 4 + button $w.face.next -text "next" -command { + set w .surfacemeshsize_dlg; + set facenr [$w.face.ent cget -text] + if {$facenr == [Ng_SurfaceMeshSize getnfd]} { + set facenr 1 + } { + set facenr [expr $facenr + 1] + } + $w.face.ent configure -text $facenr + Ng_SurfaceMeshSize setactive $facenr + set surfms [Ng_SurfaceMeshSize getsurfms $facenr] + $w.sms.ent delete 0 end + $w.sms.ent insert 0 $surfms + + redraw + } + button $w.face.prev -text "prev" -command { + set w .surfacemeshsize_dlg; + set facenr [$w.face.ent cget -text] + if {$facenr == 1} { + set facenr [Ng_SurfaceMeshSize getnfd] + } { + set facenr [expr $facenr - 1] + } + $w.face.ent configure -text $facenr + Ng_SurfaceMeshSize setactive $facenr + set surfms [Ng_SurfaceMeshSize getsurfms $facenr] + $w.sms.ent delete 0 end + $w.sms.ent insert 0 $surfms + + redraw + } + + + pack $w.face.lab $w.face.ent $w.face.prev $w.face.next -side left + + frame $w.sms -borderwidth 3 + pack $w.sms -fill x + label $w.sms.lab -text "max mesh size:" + entry $w.sms.ent -width 8 -relief sunken + button $w.sms.but -text "change" -command { + set w .surfacemeshsize_dlg; + Ng_SurfaceMeshSize setsurfms [$w.face.ent cget -text] [$w.sms.ent get]; + } + button $w.sms.but2 -text "all" -command { + set w .surfacemeshsize_dlg; + Ng_SurfaceMeshSize setall [$w.sms.ent get]; + } + pack $w.sms.lab $w.sms.ent $w.sms.but $w.sms.but2 -side left -padx 5 -expand yes + + frame $w.bu + pack $w.bu -fill x -ipady 3 + + button $w.bu.close -text "Close" -command { destroy .surfacemeshsize_dlg } + + pack $w.bu.close -expand yes -side left + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Edit Surface Mesh Size" + } + + focus $w + + set facenr [Ng_SurfaceMeshSize getactive] + $w.face.ent configure -text $facenr + + set surfms [Ng_SurfaceMeshSize getsurfms $facenr] + $w.sms.ent delete 0 end + $w.sms.ent insert 0 $surfms + +} + + + + +# +# METIS dialog +# +# +proc METISdialog { } { + + set w .metis_dlg + set w.parts 64 + + if {[winfo exists .metis_dlg] == 1} { + wm withdraw $w + wm deiconify $w + } { + toplevel $w + + frame $w.a -borderwidth 0 + frame $w.b -borderwidth 0 + pack $w.a $w.b + + label $w.a.lab -text "Number of partitions:" + entry $w.a.ent -textvariable w.parts -width 4 -relief sunken + + button $w.b.start -text "Start METIS" -command { + Ng_Metis ${w.parts} + redraw + } + button $w.b.cancel -text "Cancel" -command { destroy .metis_dlg } + pack $w.a.lab $w.a.ent -side left -expand yes + pack $w.b.start $w.b.cancel -side left + + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "METIS Partitioning" + focus $w + + } +} + + + +# +# STL dialog +# +proc stloptionsdialog { } { + + set w .stlopts_dlg + + if {[winfo exists .stlopts_dlg] == 1} { + wm withdraw $w + wm deiconify $w + focus $w + } { + toplevel $w + + tixNoteBook $w.nb -ipadx 6 -ipady 6 + # $w config -bg gray + # $w.nb subwidget nbframe config -backpagecolor gray + + # Create the two tabs on the notebook. The -underline option + # puts a underline on the first character of the labels of the tabs. + # Keyboard accelerators will be defined automatically according + # to the underlined character. + # + +# $w.nb add chartopt -label "Chart Options" -underline 0 +# #$w.nb add meshsize -label "Mesh Size" -underline 0 +# pack $w.nb -expand yes -fill both -padx 5 -pady 5 -side top + + +# set f [$w.nb subwidget chartopt] + + +# label $f.lab1 -text "Yellow Edges Angle ()" +# scale $f.scale1 -orient horizontal -length 300 \ +# -from 0 -to 90 -resolution 1 -tickinterval 10 \ +# -variable stloptions.yangle + +# pack $f.lab1 $f.scale1 + +# label $f.lab2e -text "Edge Corner Angle ()" +# scale $f.scale2e -orient horizontal -length 360 -from 0 -to 180 \ +# -resolution 1 -tickinterval 20 \ +# -variable stloptions.edgecornerangle +# pack $f.lab2e $f.scale2e + +# label $f.lab2 -text "Chart Angle ()" +# scale $f.scale2 -orient horizontal -length 360 -from 0 -to 180 \ +# -resolution 1 -tickinterval 20 \ +# -variable stloptions.chartangle +# pack $f.lab2 $f.scale2 + +# label $f.lab2b -text "Outer Chart Angle ()" +# scale $f.scale2b -orient horizontal -length 360 -from 0 -to 180 \ +# -resolution 1 -tickinterval 20 \ +# -variable stloptions.outerchartangle +# pack $f.lab2b $f.scale2b + +# frame $f.r4 +# pack $f.r4 -anchor w +# scale $f.r4.sc -orient horizontal -length 200 -from 0.1 -to 10 \ +# -resolution 0.1 -variable stloptions.resthatlasfac +# checkbutton $f.r4.bu -text "Restrict h for Calc Atlas (Faster)" \ +# -variable stloptions.resthatlasenable +# pack $f.r4.sc $f.r4.bu -side left + + + #set f [$w.nb subwidget meshsize] + + + +# checkbutton $w.seat -text "Use Searchtrees" \ +# -variable stloptions.usesearchtree +# pack $w.seat + + + + + frame $w.bu +# pack $w.bu + pack $w.bu -fill x -ipady 3 + +# -fill x + + button $w.bu.apply -text "Apply" -command { redraw; Ng_GenerateMesh 1 2} + button $w.bu.cancle -text "Done" -command { destroy .stlopts_dlg } + pack $w.bu.cancle $w.bu.apply -side left -expand yes + + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "STL Options" +# grab $w + focus $w + } +} + +proc stldoctordialog { } { + + set wd .stldoctor_dlg + + if {[winfo exists .stldoctor_dlg] == 1} { + wm withdraw $wd + wm deiconify $wd + focus $wd + } { + + toplevel $wd + + tixNoteBook $wd.nb -ipadx 6 -ipady 6 + + $wd.nb add general -label "General" -underline 0 + $wd.nb add topology -label "Edit Topology" -underline 5 + $wd.nb add edges -label "Edit Edges" -underline 5 + $wd.nb add normals -label "Edit Normals" -underline 5 + $wd.nb add advanced -label "Advanced" -underline 0 + + + pack $wd.nb -expand yes -fill both -padx 5 -pady 5 -side top + + + # GENERAL ***************************** + + set f [$wd.nb subwidget general] + + + frame $f.show + pack $f.show -fill x + checkbutton $f.show.showtrias -text "Show STL-Triangles" \ + -variable stloptions.showtrias -command { Ng_SetVisParameters; redraw } + pack $f.show.showtrias -anchor w + + checkbutton $f.show.showfilledtrias -text "Show Filled Triangles" \ + -variable stloptions.showfilledtrias -command { Ng_SetVisParameters; redraw } + pack $f.show.showfilledtrias -anchor w + + set selmodevals { 0 1 2 3 4 } + set selmodelabs(0) "triangle" + set selmodelabs(1) "edge" + set selmodelabs(2) "point" + set selmodelabs(3) "line" + set selmodelabs(4) "line cluster" + + tixOptionMenu $f.selmode -label "Double Click selects :" \ + -options { + label.width 19 + label.anchor e + menubutton.width 15 + } + + foreach selmodev $selmodevals { + $f.selmode add command $selmodev -label $selmodelabs($selmodev) + } + $f.selmode config -variable stldoctor.selectmode + $f.selmode config -command { Ng_STLDoctor } + global stldoctor.selectmode + pack $f.selmode + + frame $f.sm + pack $f.sm -fill x + checkbutton $f.sm.bu -text "select with mouse" \ + -variable stldoctor.selectwithmouse + pack $f.sm.bu + + frame $f.st -relief groove -borderwidth 3 + pack $f.st -fill x + label $f.st.lab -text "Select triangle by number"; + entry $f.st.ent -width 5 -relief sunken \ + -textvariable stldoctor.selecttrig + pack $f.st.ent $f.st.lab -side left -expand yes + + frame $f.vc -relief groove -borderwidth 3 + pack $f.vc -fill x + checkbutton $f.vc.bu -text "show vicinity" \ + -variable stldoctor.showvicinity \ + -command {Ng_STLDoctor vicinity; redraw} + label $f.vc.lab -text "vicinity size"; + scale $f.vc.sc -orient horizontal -length 200 -from 0 -to 200 \ + -resolution 1 -variable stldoctor.vicinity \ + -command { Ng_STLDoctor vicinity; redraw } + pack $f.vc.bu $f.vc.lab $f.vc.sc -expand yes + + frame $f.ge -relief groove -borderwidth 3 + pack $f.ge -fill x + button $f.ge.neighbourangles -text "calc neighbourangles" -command {Ng_STLDoctor neighbourangles} + button $f.ge.showcoords -text "show coords of touched triangle" -command {Ng_STLDoctor showcoords} + button $f.ge.moveptm -text "move point to middle of trianglepoints" -command {Ng_STLDoctor movepointtomiddle; redraw} + button $f.ge.destroy0trigs -text "destroy 0-volume triangles" -command {Ng_STLDoctor destroy0trigs} + pack $f.ge.neighbourangles $f.ge.showcoords $f.ge.moveptm $f.ge.destroy0trigs -expand yes + + + button $f.ge.cancle -text "Done" -command {destroy .stldoctor_dlg } + pack $f.ge.cancle -expand yes + + # TOPOLOGY ******************** + set f [$wd.nb subwidget topology] + + frame $f.oc -relief groove -borderwidth 3 + pack $f.oc -fill x + button $f.oc.bu -text "invert orientation of selected trig" -command {Ng_STLDoctor invertselectedtrig; redraw } + button $f.oc.bu2 -text "orient after selected trig" -command {Ng_STLDoctor orientafterselectedtrig; redraw } + pack $f.oc.bu $f.oc.bu2 -side left -expand yes + + button $f.toperr -text "mark inconsistent triangles" -command {Ng_STLDoctor marktoperrortrigs; redraw } + + button $f.deltrig -text "delete selected triangle" -command {Ng_STLDoctor deleteselectedtrig; redraw } + button $f.geosmooth -text "geometric smoothing" -command {Ng_STLDoctor smoothgeometry; redraw } + + pack $f.toperr $f.deltrig $f.geosmooth + + + + + + # EDGES *********************** + set f [$wd.nb subwidget edges] + + + frame $f.be -relief groove -borderwidth 3 + pack $f.be -fill x + label $f.be.lab -text "build edges with yellow angle:"; + scale $f.be.sc -orient horizontal -length 200 -from 0 -to 100 \ + -resolution 0.5 + $f.be.sc config -variable stloptions.yangle + $f.be.sc config -command { Ng_SetSTLParameters; Ng_STLDoctor buildedges; redraw } + label $f.be.lab2 -text "continue edges with yellow angle:"; + scale $f.be.sc2 -orient horizontal -length 200 -from 0 -to 100 \ + -resolution 0.5 + $f.be.sc2 config -variable stloptions.contyangle + $f.be.sc2 config -command { Ng_SetSTLParameters; Ng_STLDoctor buildedges; redraw } + + + + button $f.be.buildedges -text "Build Edges" -command {Ng_STLDoctor buildedges; redraw} + pack $f.be.lab $f.be.sc $f.be.lab2 $f.be.sc2 $f.be.buildedges -expand yes + + frame $f.se + pack $f.se -fill x + checkbutton $f.se.bu -text "show excluded" \ + -variable stldoctor.showexcluded \ + -command {Ng_STLDoctor; redraw} + pack $f.se.bu + + # edgeselectmode ****** + + set edgeselmodevals { 0 1 2 3 4 } + set edgeselmodelabs(0) "no change" + set edgeselmodelabs(1) "undefined" + set edgeselmodelabs(2) "confirmed" + set edgeselmodelabs(3) "candidate" + set edgeselmodelabs(4) "excluded" + + tixOptionMenu $f.edgeselmode -label "Double Click sets edge :" \ + -options { + label.width 19 + label.anchor e + menubutton.width 15 + } + + foreach edgeselmodev $edgeselmodevals { + $f.edgeselmode add command $edgeselmodev -label $edgeselmodelabs($edgeselmodev) + } + $f.edgeselmode config -variable stldoctor.edgeselectmode + $f.edgeselmode config -command { Ng_STLDoctor } + global stldoctor.edgeselectmode + pack $f.edgeselmode + + # edge buttons + + frame $f.edg -relief groove -borderwidth 3 + pack $f.edg -fill x + +# checkbutton $f.edg.bu -text "use external edges" \ +# -variable stldoctor.useexternaledges \ +# -command {Ng_STLDoctor; redraw} +# pack $f.edg.bu -expand yes + + + frame $f.edg.f0 + pack $f.edg.f0 + button $f.edg.f0.confirmedge -text "confirm" -command {Ng_STLDoctor confirmedge; redraw} + button $f.edg.f0.candidateedge -text "candidate" -command {Ng_STLDoctor candidateedge; redraw} + button $f.edg.f0.excludeedge -text "exclude" -command {Ng_STLDoctor excludeedge; redraw} + button $f.edg.f0.undefinededge -text "undefined" -command {Ng_STLDoctor undefinededge; redraw} + pack $f.edg.f0.confirmedge $f.edg.f0.candidateedge $f.edg.f0.excludeedge $f.edg.f0.undefinededge -side left + + frame $f.edg.fa + pack $f.edg.fa + button $f.edg.fa.setallundefined -text "all undefined" -command {Ng_STLDoctor setallundefinededges; redraw} + button $f.edg.fa.erasecandidates -text "candidates to undefined" -command {Ng_STLDoctor erasecandidateedges; redraw} + pack $f.edg.fa.setallundefined $f.edg.fa.erasecandidates -side left + + + frame $f.edg.fb + pack $f.edg.fb + button $f.edg.fb.confirmcandidates -text "candidates to confirmed" -command {Ng_STLDoctor confirmcandidateedges; redraw} + button $f.edg.fb.confirmedtocandidates -text "confirmed to candidates" -command {Ng_STLDoctor confirmedtocandidateedges; redraw} + pack $f.edg.fb.confirmcandidates $f.edg.fb.confirmedtocandidates -side left + + frame $f.edg.f1 + frame $f.edg.f2 + frame $f.edg.f3 + frame $f.edg.f4 + pack $f.edg.f1 $f.edg.f2 $f.edg.f3 $f.edg.f4 + + button $f.edg.f1.exportedges -text "export edges" -command {Ng_STLDoctor exportedges} + button $f.edg.f1.importedges -text "import edges" -command {Ng_STLDoctor importedges; redraw} + button $f.edg.f1.saveedgedata -text "save edgedata" \ + -command { + set types { + {"Netgen Edgedata" {.ned} } + } + set file [tk_getSaveFile -filetypes $types -defaultextension ".ned"] + if {$file != ""} { + Ng_STLDoctor saveedgedata $file + } + } + + button $f.edg.f1.loadedgedata -text "load edgedata" \ + -command { + set types { + {"Netgen Edgedata" {.ned} } + } + set file [tk_getOpenFile -filetypes $types -defaultextension ".ned"] + if {$file != ""} { + Ng_STLDoctor loadedgedata $file + puts "loading done" + + redraw + +# wm title . [concat "NETGEN - " $file] + } + } + + button $f.edg.f1.importAVLedges -text "import AVL edges" \ + -command { + set types {{"Edge file" {.edg }}} + + set file [tk_getOpenFile -filetypes $types -defaultextension ".edg"] + if {$file != ""} { + Ng_STLDoctor importexternaledges $file; + } + } + + pack $f.edg.f1.importAVLedges $f.edg.f1.loadedgedata $f.edg.f1.saveedgedata -side left + +# button $f.edg.f1.buildedges -text "build external edges" -command {Ng_STLDoctor buildexternaledges; redraw} + frame $f.edg2 -relief groove -borderwidth 3 + pack $f.edg2 -fill x + + +# button $f.edg2.addlonglines -text "make long lines candidates (% of diam)" -command {Ng_STLDoctor addlonglines; redraw} + label $f.edg2.lab -text "length (%):" + scale $f.edg2.sc -orient horizontal -length 200 -from 0 -to 100 \ + -resolution 0.5 \ + -variable stldoctor.longlinefact + + # button $f.edg2.deletedirtyedges -text "make dirty edges candidates" -command {Ng_STLDoctor deletedirtyedges; redraw} + button $f.edg2.undoedge -text "undo last edge change" -command {Ng_STLDoctor undoedgechange; redraw} + + # pack $f.edg2.addlonglines $f.edg2.deletedirtyedges -expand yes + # pack $f.edg2.lab $f.edg2.sc -side left + pack $f.edg2.undoedge -expand yes + + + + # NORMALS *********************** + set f [$wd.nb subwidget normals] + + frame $f.dt -relief groove -borderwidth 3 + pack $f.dt -fill x + label $f.dt.lab -text "dirty triangle factor"; + entry $f.dt.ent -width 5 -relief sunken \ + -textvariable stldoctor.dirtytrigfact + pack $f.dt.ent $f.dt.lab -side left -expand yes + + frame $f.srt -relief groove -borderwidth 3 + pack $f.srt -fill x + button $f.srt.bu -text "smooth reverted triangles geometric" -command {Ng_STLDoctor smoothrevertedtrigs; redraw } + entry $f.srt.ent -width 5 -relief sunken \ + -textvariable stldoctor.smoothangle + pack $f.srt.ent $f.srt.bu -side left -expand yes + + frame $f.bdt -relief groove -borderwidth 3 + pack $f.bdt -fill x + button $f.bdt.bu -text "mark dirty triangles" -command {Ng_STLDoctor markdirtytrigs; redraw } + button $f.bdt.bu2 -text "smooth dirty triangles normal" -command {Ng_STLDoctor smoothdirtytrigs; redraw } + pack $f.bdt.bu $f.bdt.bu2 -side left -expand yes + + + frame $f.sno -relief groove -borderwidth 3 + pack $f.sno + + label $f.sno.labrough -text "rough" + scale $f.sno.scsmooth -orient horizontal -length 100 -from 0 -to 0.8 \ + -resolution 0.01 -variable stldoctor.smoothnormalsweight \ + -command { Ng_SetSTLParameters } + label $f.sno.labsmooth -text "smooth" + button $f.sno.smoothnormals -text "smooth normals" -command { Ng_STLDoctor smoothnormals; redraw} + + + + pack $f.sno.labrough $f.sno.scsmooth $f.sno.labsmooth $f.sno.smoothnormals -side left -padx 5 + + frame $f.no -relief groove -borderwidth 3 + pack $f.no -fill x + + button $f.no.marknonsmoothnormals -text "mark non-smooth triangles" -command {Ng_STLDoctor marknonsmoothnormals; redraw} + button $f.no.calcnormals -text "calculate normals from geometry" -command {Ng_STLDoctor calcnormals; redraw} + + pack $f.no.marknonsmoothnormals $f.no.calcnormals -expand yes + + + # ADVANCED ************************** + set f [$wd.nb subwidget advanced] + + + frame $f.sc + pack $f.sc -fill x + checkbutton $f.sc.bu -text "spiral check" \ + -variable stldoctor.spiralcheck \ + -command {Ng_STLDoctor;} + checkbutton $f.sc.bu2 -text "cone check" \ + -variable stldoctor.conecheck \ + -command {Ng_STLDoctor;} + pack $f.sc.bu $f.sc.bu2 + + + tixControl $f.gtol -label "load-geometry tolerance factor" -integer false \ + -variable stldoctor.geom_tol_fact \ + -options { + entry.width 8 + label.width 30 + label.anchor e + } + pack $f.gtol + + button $f.adap -text "Apply" -command { + [.stldoctor_dlg.nb subwidget advanced].gtol invoke + Ng_STLDoctor; + } + pack $f.adap -expand yes + +# frame $f.gtol -relief groove -borderwidth 3 +# pack $f.gtol -fill x +# label $f.gtol.lab -text "Geometry-Load-Tolerance-Factor"; +# entry $f.gtol.ent -width 5 -relief sunken \ +# -textvariable stldoctor.geom_tol_fact +# pack $f.gtol.lab $f.gtol.ent -side left -expand yes + + #******************************* + wm withdraw $wd + wm geom $wd +100+100 + wm deiconify $wd + wm title $wd "STL Doctor" + + focus $wd +} +} + + + + + +proc meshdoctordialog { } { + + set w .meshdoc_dlg + global meshdoctor.active + + if {[winfo exists .meshdoc_dlg] == 1} { + wm withdraw $w + wm deiconify $w + focus $w + } { + toplevel $w + + set meshdoctor.active 1 + Ng_MeshDoctor; + + + frame $w.vis -relief groove -borderwidth 3 + pack $w.vis + + checkbutton $w.vis.showfilledtrigs -text "Show filled triangles" \ + -variable viewoptions.drawfilledtrigs \ + -command { Ng_SetVisParameters; redraw } + + checkbutton $w.vis.showedges -text "Show edges" \ + -variable viewoptions.drawedges \ + -command { Ng_SetVisParameters; redraw } + + + checkbutton $w.vis.showoutline -text "Show Triangle Outline" \ + -variable viewoptions.drawoutline \ + -command { Ng_SetVisParameters; redraw } + + pack $w.vis.showfilledtrigs $w.vis.showoutline $w.vis.showedges + + tixControl $w.markedgedist -label "Mark edge dist: " -integer true \ + -min 0 -max 999 \ + -variable meshdoc.markedgedist \ + -options { + entry.width 3 + label.width 20 + label.anchor e + } \ + -command { + Ng_MeshDoctor markedgedist ${meshdoc.markedgedist} + redraw + } + pack $w.markedgedist + + button $w.deledge -text "Delete marked segments" -command { + Ng_MeshDoctor deletemarkedsegments + redraw + } + pack $w.deledge + + button $w.close -text "Close" -command { + set meshdoctor.active 0; + Ng_MeshDoctor; + destroy .meshdoc_dlg + } + pack $w.close -expand yes + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Mesh Doctor" + } +} + + + +# +# Quality viewer +# + +proc qualityviewdialog { show } { + + set w .qualityview_dlg + + if {[winfo exists .qualityview_dlg] == 1} { + + if { $show == 1 } { + wm withdraw .qualityview_dlg + wm deiconify $w + focus $w + } { + wm withdraw $w + } + } { + toplevel $w + + set c $w.c + + canvas $c -relief raised -width 450 -height 300 + pack $w.c -side top -fill x + + set plotFont {Helvetica 12} + set smallFont {Helvetica 12} + + $c create line 100 250 400 250 -width 2 + $c create line 100 250 100 50 -width 2 + + for {set i 0} {$i <= 10} {incr i} { + set x [expr {100 + ($i*30)}] + $c create line $x 250 $x 245 -width 2 + if { [expr {$i % 2}] == 0 } { + $c create text $x 254 -text [format %1.1f [expr 0.1*$i]] -anchor n -font $plotFont + } + } + + global qualbar + global qualbarnull + global qualbaraxis + + for {set i 0} {$i <= 5} {incr i} { + set y [expr {250 - ($i*40)}] + $c create line 100 $y 105 $y -width 2 + +# global qualbaraxis($i) + set qualbaraxis($i) \ + [$c create text 96 $y -text [expr $i*50].0 -anchor e -font $plotFont] + } + + for {set i 0} {$i < 20} {incr i} { + set x1 [expr {100 + ($i*15) + 2}] + set x2 [expr {$x1+10}] + set y [expr {250 - 10 * $i}] +# global qualbar($i) + set qualbar($i) [$c create rectangle $x1 250 $x2 245 -fill blue] + set qualbarnull($i) [$c create text [expr {($x1+$x2)/2}] 245 -text 0 -anchor s -font $smallFont -fill blue] + } + + frame $w.bu + pack $w.bu + # -fill x + + button $w.close -text "Close" \ + -command { + wm withdraw .qualityview_dlg + set viewqualityplot 0 + } + pack $w.close + + + if { $show == 1 } { + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Mesh Quality" + focus $w + } + } +} + + + + + + + + + + +# +# Quality viewer +# +proc memusedialog { show } { + + set w .memuse_dlg + + if {[winfo exists .memuse_dlg] == 1} { + + if { $show == 1 } { + wm withdraw .memuse_dlg + wm deiconify $w + focus $w + } { + wm withdraw $w + } + } { + toplevel $w + + set c $w.c + + canvas $c -relief raised -width 600 -height 300 + pack $w.c -side top -fill x + + set plotFont {Helvetica 18} + set smallFont {Helvetica 12} + + + global memmark + for {set i 0} {$i < 512} { incr i } { + set memmark($i) [$c create line [expr 50+$i] 50 [expr 50+$i] 70 -fill blue] + } + + + set plotFont {Helvetica 18} + set smallFont {Helvetica 12} + + $c create text 50 90 -text "0 GB" -anchor n -font $plotFont + $c create text 178 90 -text "1 GB" -anchor n -font $plotFont + $c create text 306 90 -text "2 GB" -anchor n -font $plotFont + $c create text 434 90 -text "3 GB" -anchor n -font $plotFont + $c create text 562 90 -text "4 GB" -anchor n -font $plotFont + + + frame $w.bu + pack $w.bu + # -fill x + + button $w.close -text "Close" \ + -command { + wm withdraw .memuse_dlg + set memuseplot 0 + } + pack $w.close + + if { $show == 1 } { + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Memory Usage" + focus $w + } + } +} + + + + + + + + + + + + + + + +# +# STL INFO dialog +# +proc STLinfodialog { show } { + + set w .STLinfo_dlg + + if {[winfo exists .STLinfo_dlg] == 1} { + + if { $show == 1 } { + wm withdraw .STLinfo_dlg + wm deiconify $w + focus $w + } { + wm withdraw $w + } + } { + toplevel $w + + set c $w.c + + canvas $c -relief raised -width 450 -height 300 + pack $w.c -side top -fill x + + set plotFont {Helvetica 18} + set smallFont {Helvetica 12} + + $c create line 100 250 400 250 -width 2 + $c create line 100 250 100 50 -width 2 + + frame $w.bu + pack $w.bu + # -fill x + + button $w.close -text "Close" \ + -command { + wm withdraw .STLinfo_dlg + #set STLinfoopen 0 + } + pack $w.close + + + if { $show == 1 } { + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "STL Geometry Info" + focus $w + } + } +} + + + + + + + + +proc logwindow { } { + set w .logwindow + + if {[winfo exists .logwindow] == 1} { + wm withdraw $w + wm deiconify $w + focus $w + } { + toplevel $w + + text $w.edit -yscroll "$w.scrolly set" -setgrid 1 -height 12 + scrollbar $w.scrolly -command "$w.edit yview" + pack $w.edit -side left -fill both -expand 1 + pack $w.scrolly -side left -fill both -expand 0 + + .logwindow.edit insert end "Netgen Log Window\n" + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Netgen Log" + focus $w + } +} +# logwindow + + + +# Opens a window with a table. tablevar is a list, the first entry is the title, the second the number of rows, the third the number of columns, +# then the entries follow. + +proc printtable { tablevar } { + set w newtcltable + while {[winfo exists .$w] == 1} {set w 1$w} + set w .$w + toplevel $w + for {set i 0} {$i < [lindex $tablevar 2]} { incr i } { + frame $w.col$i + for {set j 0} {$j < [lindex $tablevar 1]} { incr j } { + frame $w.col$i.row$j + message $w.col$i.row$j.txt -aspect 10000000 -text [lindex $tablevar [expr 3+[lindex $tablevar 2]*$j+$i]] + pack $w.col$i.row$j.txt + pack $w.col$i.row$j -side top + } + pack $w.col$i -side left + } + wm withdraw $w + wm geom $w +200+100; wm deiconify $w + wm title $w [lindex $tablevar 0] + focus $w +} + + +set latestwarning 0 + + +proc printwarning { textvar } { + global latestwarning + set latestwarning $textvar + set w warning + while {[winfo exists .$w] == 1} {set w 1$w} + set w .$w + toplevel $w + message $w.mes -aspect 2000 -text "WARNING:\n$textvar" + button $w.done -text "Done" -command "destroy $w" + pack $w.mes + pack $w.done + wm withdraw $w + wm deiconify $w + wm title $w "Warning" + focus $w +} + + +proc printlatestwarning { } { + global latestwarning + if {$latestwarning != 0} {printwarning $latestwarning} +} + + + +proc runtestdialog { } { + source $::ngdir/ngshell.tcl + set w .runtest_dlg + + if {[winfo exists .runtest_dlg] == 1} { + wm withdraw $w + wm deiconify $w + + focus $w + } { + toplevel $w + +# in2d testing # + frame $w.in2dframe + pack $w.in2dframe + + set in2dlogfile "" + tixLabelEntry $w.in2dframe.ent -label "in2d log-file: console if empty" \ + -labelside top \ + -options { + entry.textVariable in2dlogfile + entry.width 35 + label.width 25 + label.anchor w + } + button $w.in2dframe.btn -text "Browse" -command { + set types { { "Log file" {.log} } } + set in2dlogfile [tk_getOpenFile -filetypes $types -initialfile $in2dlogfile] + } + button $w.in2dframe.test -text "Test in2d meshing" -command { ngtest in2d $in2dlogfile } + + + pack $w.in2dframe.test -side left -anchor s -padx 4 -pady 4 + pack $w.in2dframe.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 + pack $w.in2dframe.btn -side left -anchor s -padx 4 -pady 4 + + +# geo testing # + frame $w.geoframe + pack $w.geoframe + + set geologfile "" + tixLabelEntry $w.geoframe.ent -label "geo log-file: console if empty" \ + -labelside top \ + -options { + entry.textVariable geologfile + entry.width 35 + label.width 25 + label.anchor w + } + button $w.geoframe.btn -text "Browse" -command { + set types { { "Log file" {.log} } } + set geologfile [tk_getOpenFile -filetypes $types -initialfile $geologfile] + } + button $w.geoframe.test -text "Test geo meshing" -command { ngtest geo $geologfile } + + + pack $w.geoframe.test -side left -anchor s -padx 4 -pady 4 + pack $w.geoframe.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 + pack $w.geoframe.btn -side left -anchor s -padx 4 -pady 4 + +# stl testing # + frame $w.stlframe + pack $w.stlframe + + set stllogfile "" + tixLabelEntry $w.stlframe.ent -label "stl log-file: console if empty" \ + -labelside top \ + -options { + entry.textVariable stllogfile + entry.width 35 + label.width 25 + label.anchor w + } + button $w.stlframe.btn -text "Browse" -command { + set types { { "Log file" {.log} } } + set stllogfile [tk_getOpenFile -filetypes $types -initialfile $stllogfile] + } + button $w.stlframe.test -text "Test stl meshing" -command { ngtest stl $stllogfile } + + + pack $w.stlframe.test -side left -anchor s -padx 4 -pady 4 + pack $w.stlframe.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 + pack $w.stlframe.btn -side left -anchor s -padx 4 -pady 4 + +# pde testing # + frame $w.pdeframe + pack $w.pdeframe + + set pdelogfile "" + tixLabelEntry $w.pdeframe.ent -label "pde log-file: console if empty" \ + -labelside top \ + -options { + entry.textVariable pdelogfile + entry.width 35 + label.width 25 + label.anchor w + } + button $w.pdeframe.btn -text "Browse" -command { + set types { { "Log file" {.log} } } + set pdelogfile [tk_getOpenFile -filetypes $types -initialfile $pdelogfile] + } + button $w.pdeframe.test -text "Test ngsolve pde's" -command { ngtest pde $pdelogfile } + + + pack $w.pdeframe.test -side left -anchor s -padx 4 -pady 4 + pack $w.pdeframe.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4 + pack $w.pdeframe.btn -side left -anchor s -padx 4 -pady 4 + + wm title $w "Testing" + focus .runtest_dlg + } +} + diff --git a/ng/parameters.tcl b/ng/parameters.tcl index 6c6b599a..2253ec7d 100644 --- a/ng/parameters.tcl +++ b/ng/parameters.tcl @@ -1,46 +1,50 @@ -proc setgranularity { gran } { -# -# puts "set granularity $gran" -# - if {$gran == 6} { return } - set gran [expr $gran - 1] -# - global options.curvaturesafety - set surfcurvlist { 1 1.5 2 3 5 } - set options.curvaturesafety [lindex $surfcurvlist $gran] - - global options.segmentsperedge - set spelist { 0.3 0.5 1 2 3 } - set options.segmentsperedge [lindex $spelist $gran] - - global stloptions.resthsurfcurvfac - set surfcurvfaclist { 0.25 0.5 1 1.5 3 } - set stloptions.resthsurfcurvfac [lindex $surfcurvfaclist $gran] - - global stloptions.resthchartdistfac - set chartdistfaclist { 0.8 1 1.5 2 5 } - set stloptions.resthchartdistfac [lindex $chartdistfaclist $gran] - - global stloptions.resthlinelengthfac - set linelengthfaclist { 0.2 0.35 0.5 1.5 3 } - set stloptions.resthlinelengthfac [lindex $linelengthfaclist $gran] - - global stloptions.resthcloseedgefac - set closeedgefaclist { 0.5 1 2 3.5 5 } - set stloptions.resthcloseedgefac [lindex $closeedgefaclist $gran] - - global stloptions.resthedgeanglefac - set edgeanglefaclist { 0.25 0.5 1 1.5 3 } - set stloptions.resthedgeanglefac [lindex $edgeanglefaclist $gran] - - - global stloptions.resthsurfmeshcurvfac - set surfmeshcurvlist { 1 1.5 2 3 5 } - set stloptions.resthsurfmeshcurvfac [lindex $surfmeshcurvlist $gran] - - - global options.grading - set gradinglist { 0.7 0.5 0.3 0.2 0.1 } - set options.grading [lindex $gradinglist $gran] - -} +proc setgranularity { gran } { +# +# puts "set granularity $gran" +# + if {$gran == 6} { return } + set gran [expr $gran - 1] +# + global options.curvaturesafety + set surfcurvlist { 1 1.5 2 3 5 } + set options.curvaturesafety [lindex $surfcurvlist $gran] + + global options.segmentsperedge + set spelist { 0.3 0.5 1 2 3 } + set options.segmentsperedge [lindex $spelist $gran] + + global stloptions.resthsurfcurvfac + set surfcurvfaclist { 0.25 0.5 1 1.5 3 } + set stloptions.resthsurfcurvfac [lindex $surfcurvfaclist $gran] + + global stloptions.resthchartdistfac + set chartdistfaclist { 0.8 1 1.5 2 5 } + set stloptions.resthchartdistfac [lindex $chartdistfaclist $gran] + + global stloptions.resthlinelengthfac + set linelengthfaclist { 0.2 0.35 0.5 1.5 3 } + set stloptions.resthlinelengthfac [lindex $linelengthfaclist $gran] + + global stloptions.resthcloseedgefac + set closeedgefaclist { 0.5 1 2 3.5 5 } + set stloptions.resthcloseedgefac [lindex $closeedgefaclist $gran] + + global stloptions.resthminedgelen + set minedgelenlist { 0.002 0.02 0.2 1.0 2.0 5.0 10.0 } + set stloptions.resthminedgelen [lindex $minedgelenlist $gran] + + global stloptions.resthedgeanglefac + set edgeanglefaclist { 0.25 0.5 1 1.5 3 } + set stloptions.resthedgeanglefac [lindex $edgeanglefaclist $gran] + + + global stloptions.resthsurfmeshcurvfac + set surfmeshcurvlist { 1 1.5 2 3 5 } + set stloptions.resthsurfmeshcurvfac [lindex $surfmeshcurvlist $gran] + + + global options.grading + set gradinglist { 0.7 0.5 0.3 0.2 0.1 } + set options.grading [lindex $gradinglist $gran] + +} diff --git a/ng/variables.tcl b/ng/variables.tcl index 300b91a8..d28f912a 100644 --- a/ng/variables.tcl +++ b/ng/variables.tcl @@ -1,702 +1,706 @@ -# netgen global tcl-variables - -set drawmode rotate -set selectvisual geometry - -set dirname . -set loadgeomtypevar "All Geometry types" - -set basefilename filename - -set meshoptions.fineness 3 -set meshoptions.firststep ag -set meshoptions.laststep ov -set options.memory 0 - -set options.localh 1 -set options.delaunay 1 -set options.checkoverlap 1 -set options.checkoverlappingboundary 0 -set options.checkchartboundary 1 -set options.startinsurface 0 -set options.blockfill 1 -set options.debugmode 0 -set options.dooptimize 1 -set options.parthread 1 -set options.elsizeweight 0.2 -set options.secondorder 0 -set options.elementorder 1 -set options.quad 0 -set options.inverttets 0 -set options.inverttrigs 0 -set options.autozrefine 0 - - -set options.meshsize 1000 -set options.minmeshsize 0 - -set options.curvaturesafety 2 -set options.segmentsperedge 2 -set options.meshsizefilename "" -set options.badellimit 175 -set options.optsteps2d 3 -set options.optsteps3d 5 -set options.opterrpow 2 - -set options.grading 0.5 -set options.printmsg 2 - -set debug.slowchecks 0 -set debug.debugoutput 0 -set debug.haltexistingline 0 -set debug.haltoverlap 0 -set debug.haltsuccess 0 -set debug.haltnosuccess 0 -set debug.haltlargequalclass 0 -set debug.haltsegment 0 -set debug.haltnode 0 -set debug.haltface 0 -set debug.haltfacenr 0 -set debug.haltsegmentp1 0 -set debug.haltsegmentp2 0 - -set geooptions.drawcsg 1 -set geooptions.detail 0.001 -set geooptions.accuracy 1e-6 -set geooptions.facets 20 -set geooptions.minx -1000 -set geooptions.miny -1000 -set geooptions.minz -1000 -set geooptions.maxx 1000 -set geooptions.maxy 1000 -set geooptions.maxz 1000 - -set viewqualityplot 0 -set memuseplot 0 -set viewrotatebutton 0 -set showsensitivehelp 0 -set showhelpline 0 - -set viewoptions.specpointvlen 0.3 -set viewoptions.light.amb 0.3 -set viewoptions.light.diff 0.7 -set viewoptions.light.spec 1 -set viewoptions.light.locviewer 0 -set viewoptions.mat.shininess 50 -set viewoptions.mat.transp 0.3 -set viewoptions.colormeshsize 0 -set viewoptions.whitebackground 1 -set viewoptions.drawcoordinatecross 1 -set viewoptions.drawcolorbar 1 -set viewoptions.drawnetgenlogo 1 -set viewoptions.stereo 0 -set viewoptions.shrink 1 - -set viewoptions.drawfilledtrigs 1 -set viewoptions.drawedges 0 -set viewoptions.drawbadels 0 -set viewoptions.centerpoint 0 -set viewoptions.drawelement 0 -set viewoptions.drawoutline 1 -set viewoptions.drawtets 0 -set viewoptions.drawtetsdomain 0 -set viewoptions.drawprisms 0 -set viewoptions.drawpyramids 0 -set viewoptions.drawhexes 0 -set viewoptions.drawidentified 0 -set viewoptions.drawpointnumbers 0 -set viewoptions.drawedgenumbers 0 -set viewoptions.drawfacenumbers 0 -set viewoptions.drawelementnumbers 0 -set viewoptions.drawdomainsurf 0 - -set viewoptions.drawededges 1 -set viewoptions.drawedpoints 1 -set viewoptions.drawedpointnrs 0 -set viewoptions.drawedtangents 0 -set viewoptions.drawededgenrs 0 -set viewoptions.drawmetispartition 0 - -set viewoptions.drawcurveproj 0 -set viewoptions.drawcurveprojedge 1 - -set viewoptions.clipping.nx 0 -set viewoptions.clipping.ny 1 -set viewoptions.clipping.nz 0 -set viewoptions.clipping.dist 0 -set viewoptions.clipping.dist2 0 -set viewoptions.clipping.enable 0 -set viewoptions.clipping.onlydomain 0 -set viewoptions.clipping.notdomain 0 - -set viewoptions.usecentercoords 0 -set viewoptions.centerx 0 -set viewoptions.centery 0 -set viewoptions.centerz 0 - -set viewoptions.drawspecpoint 0 -set viewoptions.specpointx 0 -set viewoptions.specpointy 0 -set viewoptions.specpointz 0 - - -set stloptions.showtrias 0 -set stloptions.showfilledtrias 1 -set stloptions.showedges 1 -set stloptions.showmarktrias 0 -set stloptions.showactivechart 0 -set stloptions.yangle 30 -set stloptions.contyangle 20 -set stloptions.edgecornerangle 60 -set stloptions.chartangle 15 -set stloptions.outerchartangle 70 -set stloptions.usesearchtree 0 -set stloptions.chartnumber 1 -set stloptions.charttrignumber 1 -set stloptions.chartnumberoffset 0 - -set stloptions.atlasminh 0.1 -set stloptions.resthsurfcurvfac 2 -set stloptions.resthsurfcurvenable 0 -set stloptions.resthatlasfac 2 -set stloptions.resthatlasenable 1 -set stloptions.resthchartdistfac 1.2 -set stloptions.resthchartdistenable 1 -set stloptions.resthlinelengthfac 0.5 -set stloptions.resthlinelengthenable 1 -set stloptions.resthcloseedgefac 1 -set stloptions.resthcloseedgeenable 1 -set stloptions.resthedgeanglefac 1 -set stloptions.resthedgeangleenable 0 -set stloptions.resthsurfmeshcurvfac 1 -set stloptions.resthsurfmeshcurvenable 0 -set stloptions.recalchopt 1 - -set stldoctor.drawmeshededges 1 -set stldoctor.geom_tol_fact 0.000001 -set stldoctor.useexternaledges 0 -set stldoctor.showfaces 0 -set stldoctor.conecheck 1 -set stldoctor.spiralcheck 1 -set stldoctor.selecttrig 0 -set stldoctor.selectmode 1 -set stldoctor.longlinefact 0 -set stldoctor.showexcluded 1 -set stldoctor.edgeselectmode 0 -set stldoctor.nodeofseltrig 1 -set stldoctor.showtouchedtrigchart 0 -set stldoctor.showedgecornerpoints 0 -set stldoctor.showmarkedtrigs 1 -set stldoctor.dirtytrigfact 0.01 -set stldoctor.smoothangle 90 -set stldoctor.selectwithmouse 1 -set stldoctor.showvicinity 0 -set stldoctor.vicinity 50 -set stldoctor.smoothnormalsweight 0.2 - -set occoptions.showvolumenr 0 -set occoptions.showsurfaces 1 -set occoptions.showedges 1 -set occoptions.showsolidnr 0 -set occoptions.showsolidnr2 0 -set occoptions.visproblemfaces 0 -set occoptions.zoomtohighlightedentity 0 -set occoptions.deflection 1 -set occoptions.tolerance 1e-3 -set occoptions.fixsmalledges 1 -set occoptions.fixspotstripfaces 1 -set occoptions.sewfaces 1 -set occoptions.makesolids 1 -set occoptions.splitpartitions 0 - -set meshdoctor.active 0 -set meshdoctor.markedgedist 1 - - -# variablenname mit punkt problematisch! -set status_np 0 -set status_ne 0 -set status_nse 0 -set status_working " " -set status_task " " -set status_percent 0 -set status_filename 0 -set status_tetqualclasses "10 20 30 40 10 20 30 40 10 20 30 40 10 20 30 40 10 20 30 40" - -set exportfiletype "Neutral Format" - -set preproc.facenr 0 -set preproc.selectmode query -set preproc.numtrig 0 - -set mem_moveable 0 - - -set multithread_pause 0 -set multithread_testmode 0 -set multithread_redraw 0 -set multithread_drawing 0 -set multithread_terminate 0 -set multithread_running 0 - -set level 0 - - -set tablesforoutput {} - - - -set optlist { - options.localh - options.delaunay - options.checkoverlap - options.startinsurface - options.blockfill - options.dooptimize - options.elsizeweight - options.meshsize - options.minmeshsize - options.curvaturesafety - options.optsteps2d - options.optsteps3d - options.secondorder -} - - -set visoptions.usetexture 1 -set visoptions.invcolor 0 -set visoptions.imaginary 0 -set visoptions.lineartexture 0 -set visoptions.numtexturecols 16 -set visoptions.showclipsolution 1 -set visoptions.showsurfacesolution 0 -set visoptions.drawfieldlines 0 -set visoptions.drawpointcurves 1 -set visoptions.numfieldlines 100 -set visoptions.fieldlinesrandomstart 0 -set visoptions.fieldlinesstartarea box -set visoptions.fieldlinesstartareap1x 1 -set visoptions.fieldlinesstartareap1y 1 -set visoptions.fieldlinesstartareap1z 1 -set visoptions.fieldlinesstartareap2x 0 -set visoptions.fieldlinesstartareap2y 0 -set visoptions.fieldlinesstartareap2z 0 -set visoptions.fieldlinesstartface -1 -set visoptions.fieldlinesfilename none -set visoptions.fieldlinestolerance 0.0005 -set visoptions.fieldlinesrktype crungekutta -set visoptions.fieldlineslength 0.5 -set visoptions.fieldlinesmaxpoints 500 -set visoptions.fieldlinesthickness 0.0015 -set visoptions.fieldlinesvecfunction none -set visoptions.fieldlinesphase 0 -set visoptions.fieldlinesonlyonephase 1 - - -set visoptions.lineplotfile empty -set visoptions.lineplotsource file -set visoptions.lineplotusingx 0 -set visoptions.lineplotusingy 1 -set visoptions.lineplotautoscale 1 -set visoptions.lineplotxmin 0 -set visoptions.lineplotxmax 1 -set visoptions.lineplotymin 0 -set visoptions.lineplotymax 1 -set visoptions.lineplotcurrentnum -1 -set visoptions.lineplotinfos "" -set visoptions.lineplotselected none -set visoptions.lineplotselector "" -set visoptions.lineplotcolor red -set visoptions.lineplotsizex 500 -set visoptions.lineplotsizey 400 -set visoptions.lineplotselectedeval 0 -set visoptions.lineplotdatadescr "column1 column2 column3" -set visoptions.lineplotxcoordselector "" -set visoptions.lineplotycoordselector "" -set visoptions.evaluatefilenames none -set visoptions.evaluatefiledescriptions none - - -set visoptions.clipsolution none -set visoptions.scalfunction none -set visoptions.vecfunction none -set visoptions.evaluate abs -set visoptions.gridsize 20 -set visoptions.xoffset 0 -set visoptions.yoffset 0 -set visoptions.autoscale 1 -set visoptions.redrawperiodic 0 -set visoptions.logscale 0 -set visoptions.mminval 0 -set visoptions.mmaxval 1 -set visoptions.isolines 0 -set visoptions.isosurf 0 -set visoptions.subdivisions 1 -set visoptions.numiso 10 -set visoptions.autoredraw 0 -set visoptions.autoredrawtime 2 -set visoptions.simulationtime 0 -set visoptions.multidimcomponent 0 - -# deform by vector function -set visoptions.deformation 0 -set visoptions.scaledeform1 1 -set visoptions.scaledeform2 1 - -set parallel_netgen 0 - - - - - - - - - - - - - - - -set optfilename [file join $nguserdir ng.opt] -set inifilename [file join $nguserdir ng.ini] -set meshinifilename [file join $nguserdir ngmesh.ini] - -global env -if { [llength [array names env NG_OPT]] == 1 } { - if { [string length $env(NG_OPT)] > 0 } { - set optfilename $env(NG_OPT) - } -} - -if { [file exists $optfilename] == 1 } { - set datei [open $optfilename r] - while { [gets $datei line] >= 0 } { - set [lindex $line 0] [lindex $line 1] - } - close $datei -} { - puts "optfile $optfilename does not exist - using default values" -} - - - - -proc saveoptions { } { - uplevel 1 { - set file $optfilename - - if {$file != ""} { - set datei [open $file w] - puts $datei "dirname ${dirname}" - puts $datei "loadgeomtypevar \"${loadgeomtypevar}\"" - puts $datei "exportfiletype \"${exportfiletype}\"" - puts $datei "meshoptions.fineness ${meshoptions.fineness}" - puts $datei "meshoptions.firststep ${meshoptions.firststep}" - puts $datei "meshoptions.laststep ${meshoptions.laststep}" - puts $datei "options.localh ${options.localh}" - puts $datei "options.delaunay ${options.delaunay}" - puts $datei "options.checkoverlap ${options.checkoverlap}" - puts $datei "options.checkchartboundary ${options.checkchartboundary}" - puts $datei "options.startinsurface ${options.startinsurface}" - puts $datei "options.blockfill ${options.blockfill}" - puts $datei "options.debugmode ${options.debugmode}" - puts $datei "options.dooptimize ${options.dooptimize}" - puts $datei "options.parthread ${options.parthread}" - puts $datei "options.elsizeweight ${options.elsizeweight}" - puts $datei "options.secondorder ${options.secondorder}" - puts $datei "options.elementorder ${options.elementorder}" -# puts $datei "options.memory ${options.memory}" - puts $datei "options.quad ${options.quad}" - puts $datei "options.inverttets ${options.inverttets}" - puts $datei "options.inverttrigs ${options.inverttrigs}" - puts $datei "options.autozrefine ${options.autozrefine}" - puts $datei "options.meshsize ${options.meshsize}" - puts $datei "options.minmeshsize ${options.minmeshsize}" - puts $datei "options.curvaturesafety ${options.curvaturesafety}" - puts $datei "options.segmentsperedge ${options.segmentsperedge}" - puts $datei "options.meshsizefilename ${options.meshsizefilename}" - puts $datei "options.badellimit ${options.badellimit}" - puts $datei "options.optsteps2d ${options.optsteps2d}" - puts $datei "options.optsteps3d ${options.optsteps3d}" - puts $datei "options.opterrpow ${options.opterrpow}" - puts $datei "options.grading ${options.grading}" - puts $datei "options.printmsg ${options.printmsg}" - puts $datei "geooptions.drawcsg ${geooptions.drawcsg}" - puts $datei "geooptions.detail ${geooptions.detail}" - puts $datei "geooptions.accuracy ${geooptions.accuracy}" - puts $datei "geooptions.facets ${geooptions.facets}" - puts $datei "geooptions.minx ${geooptions.minx}" - puts $datei "geooptions.miny ${geooptions.miny}" - puts $datei "geooptions.minz ${geooptions.minz}" - puts $datei "geooptions.maxx ${geooptions.maxx}" - puts $datei "geooptions.maxy ${geooptions.maxy}" - puts $datei "geooptions.maxz ${geooptions.maxz}" - puts $datei "viewoptions.specpointvlen ${viewoptions.specpointvlen}" - puts $datei "viewoptions.light.amb ${viewoptions.light.amb}" - puts $datei "viewoptions.light.diff ${viewoptions.light.diff}" - puts $datei "viewoptions.light.spec ${viewoptions.light.spec}" - puts $datei "viewoptions.light.locviewer ${viewoptions.light.locviewer}" - puts $datei "viewoptions.mat.shininess ${viewoptions.mat.shininess}" - puts $datei "viewoptions.mat.transp ${viewoptions.mat.transp}" - puts $datei "viewoptions.colormeshsize ${viewoptions.colormeshsize}" - puts $datei "viewoptions.whitebackground ${viewoptions.whitebackground}" - puts $datei "viewoptions.drawcolorbar ${viewoptions.drawcolorbar}" - puts $datei "viewoptions.drawcoordinatecross ${viewoptions.drawcoordinatecross}" - puts $datei "viewoptions.drawnetgenlogo ${viewoptions.drawnetgenlogo}" - puts $datei "viewoptions.stereo ${viewoptions.stereo}" - puts $datei "viewoptions.drawfilledtrigs ${viewoptions.drawfilledtrigs}" - puts $datei "viewoptions.drawedges ${viewoptions.drawedges}" - puts $datei "viewoptions.drawbadels ${viewoptions.drawbadels}" - puts $datei "viewoptions.centerpoint ${viewoptions.centerpoint}" - puts $datei "viewoptions.drawelement ${viewoptions.drawelement}" - puts $datei "viewoptions.drawoutline ${viewoptions.drawoutline}" - puts $datei "viewoptions.drawtets ${viewoptions.drawtets}" - puts $datei "viewoptions.drawprisms ${viewoptions.drawprisms}" - puts $datei "viewoptions.drawpyramids ${viewoptions.drawpyramids}" - puts $datei "viewoptions.drawhexes ${viewoptions.drawhexes}" - puts $datei "viewoptions.drawidentified ${viewoptions.drawidentified}" - puts $datei "viewoptions.drawpointnumbers ${viewoptions.drawpointnumbers}" - - puts $datei "viewoptions.drawededges ${viewoptions.drawededges}" - puts $datei "viewoptions.drawedpoints ${viewoptions.drawedpoints}" - puts $datei "viewoptions.drawedpointnrs ${viewoptions.drawedpointnrs}" - puts $datei "viewoptions.drawedtangents ${viewoptions.drawedtangents}" - puts $datei "viewoptions.shrink ${viewoptions.shrink}" - - puts $datei "stloptions.showtrias ${stloptions.showtrias}" - puts $datei "stloptions.showfilledtrias ${stloptions.showfilledtrias}" - puts $datei "stloptions.showedges ${stloptions.showedges}" - puts $datei "stloptions.showmarktrias ${stloptions.showmarktrias}" - puts $datei "stloptions.showactivechart ${stloptions.showactivechart}" - puts $datei "stloptions.yangle ${stloptions.yangle}" - puts $datei "stloptions.contyangle ${stloptions.contyangle}" - puts $datei "stloptions.edgecornerangle ${stloptions.edgecornerangle}" - puts $datei "stloptions.chartangle ${stloptions.chartangle}" - puts $datei "stloptions.outerchartangle ${stloptions.outerchartangle}" - puts $datei "stloptions.usesearchtree ${stloptions.usesearchtree}" - puts $datei "stloptions.chartnumber ${stloptions.chartnumber}" - puts $datei "stloptions.charttrignumber ${stloptions.charttrignumber}" - puts $datei "stloptions.chartnumberoffset ${stloptions.chartnumberoffset}" - puts $datei "stloptions.atlasminh ${stloptions.atlasminh}" - puts $datei "stloptions.resthsurfcurvfac ${stloptions.resthsurfcurvfac}" - puts $datei "stloptions.resthsurfcurvenable ${stloptions.resthsurfcurvenable}" - puts $datei "stloptions.resthatlasfac ${stloptions.resthatlasfac}" - puts $datei "stloptions.resthatlasenable ${stloptions.resthatlasenable}" - puts $datei "stloptions.resthchartdistfac ${stloptions.resthchartdistfac}" - puts $datei "stloptions.resthchartdistenable ${stloptions.resthchartdistenable}" - puts $datei "stloptions.resthlinelengthfac ${stloptions.resthlinelengthfac}" - puts $datei "stloptions.resthlinelengthenable ${stloptions.resthlinelengthenable}" - puts $datei "stloptions.resthcloseedgefac ${stloptions.resthcloseedgefac}" - puts $datei "stloptions.resthcloseedgeenable ${stloptions.resthcloseedgeenable}" - puts $datei "stloptions.resthedgeanglefac ${stloptions.resthedgeanglefac}" - puts $datei "stloptions.resthedgeangleenable ${stloptions.resthedgeangleenable}" - puts $datei "stloptions.resthsurfmeshcurvfac ${stloptions.resthsurfmeshcurvfac}" - puts $datei "stloptions.resthsurfmeshcurvenable ${stloptions.resthsurfmeshcurvenable}" - puts $datei "stloptions.recalchopt ${stloptions.recalchopt}" - - puts $datei "visoptions.subdivisions ${visoptions.subdivisions}" - puts $datei "visoptions.autoredraw ${visoptions.autoredraw}" - puts $datei "visoptions.autoredrawtime ${visoptions.autoredrawtime}" - - - # trafo options - # if exist trafooptions then ... - if { [info exists trafooptions.solver] == 1 } { - puts $datei "trafooptions.solver ${trafooptions.solver}" - puts $datei "trafooptions.levels ${trafooptions.levels}" - puts $datei "trafooptions.linits ${trafooptions.linits}" - puts $datei "trafooptions.nonlinits ${trafooptions.nonlinits}" - puts $datei "trafooptions.stabcurrent ${trafooptions.stabcurrent}" - puts $datei "trafooptions.checkcond ${trafooptions.checkcond}" - puts $datei "trafooptions.maxdirect ${trafooptions.maxdirect}" - puts $datei "trafooptions.secondorder ${trafooptions.secondorder}" - puts $datei "trafooptions.homogenizedcore ${trafooptions.homogenizedcore}" - puts $datei "trafooptions.ordercore ${trafooptions.ordercore}" - puts $datei "trafooptions.simplecurrents ${trafooptions.simplecurrents}" - puts $datei "trafooptions.assemblecomplexmatrix ${trafooptions.assemblecomplexmatrix}" - - puts $datei "trafooptions.meshcasing ${trafooptions.meshcasing}" - puts $datei "trafooptions.meshcore ${trafooptions.meshcore}" - puts $datei "trafooptions.meshclumps ${trafooptions.meshclumps}" - puts $datei "trafooptions.meshshields ${trafooptions.meshshields}" - puts $datei "trafooptions.meshcoils ${trafooptions.meshcoils}" - puts $datei "trafooptions.bcmdirectory ${trafooptions.bcmdirectory}" - puts $datei "trafooptions.lossdensityfile ${trafooptions.lossdensityfile}" - } - - if { [info exists smalltrafomodell.tankheight] == 1 } { - puts $datei "smalltrafomodell.tankheight ${smalltrafomodell.tankheight}" - puts $datei "smalltrafomodell.tankwidth ${smalltrafomodell.tankwidth}" - puts $datei "smalltrafomodell.tanklength ${smalltrafomodell.tanklength}" - puts $datei "smalltrafomodell.corewidth ${smalltrafomodell.corewidth}" - puts $datei "smalltrafomodell.windowheight ${smalltrafomodell.windowheight}" - puts $datei "smalltrafomodell.limbdistance ${smalltrafomodell.limbdistance}" - puts $datei "smalltrafomodell.xposcore ${smalltrafomodell.xposcore}" - puts $datei "smalltrafomodell.yposcore ${smalltrafomodell.yposcore}" - puts $datei "smalltrafomodell.zposcore ${smalltrafomodell.zposcore}" - puts $datei "smalltrafomodell.leakagefluxguidethickness ${smalltrafomodell.leakagefluxguidethickness}" - puts $datei "smalltrafomodell.leakagefluxguidewidth ${smalltrafomodell.leakagefluxguidewidth}" - puts $datei "smalltrafomodell.leakagefluxguidezposition ${smalltrafomodell.leakagefluxguidezposition}" - puts $datei "smalltrafomodell.limbcoil.1 ${smalltrafomodell.limbcoil.1}" - puts $datei "smalltrafomodell.ricoil.1 ${smalltrafomodell.ricoil.1}" - puts $datei "smalltrafomodell.rocoil.1 ${smalltrafomodell.rocoil.1}" - puts $datei "smalltrafomodell.zposcoil.1 ${smalltrafomodell.zposcoil.1}" - puts $datei "smalltrafomodell.heightcoil.1 ${smalltrafomodell.heightcoil.1}" - puts $datei "smalltrafomodell.currentcoil.1 ${smalltrafomodell.currentcoil.1}" - puts $datei "smalltrafomodell.nturnscoil.1 ${smalltrafomodell.nturnscoil.1}" - puts $datei "smalltrafomodell.limbcoil.2 ${smalltrafomodell.limbcoil.2}" - puts $datei "smalltrafomodell.ricoil.2 ${smalltrafomodell.ricoil.2}" - puts $datei "smalltrafomodell.rocoil.2 ${smalltrafomodell.rocoil.2}" - puts $datei "smalltrafomodell.zposcoil.2 ${smalltrafomodell.zposcoil.2}" - puts $datei "smalltrafomodell.heightcoil.2 ${smalltrafomodell.heightcoil.2}" - puts $datei "smalltrafomodell.currentcoil.2 ${smalltrafomodell.currentcoil.2}" - puts $datei "smalltrafomodell.nturnscoil.2 ${smalltrafomodell.nturnscoil.2}" - puts $datei "smalltrafomodell.limbcoil.3 ${smalltrafomodell.limbcoil.3}" - puts $datei "smalltrafomodell.ricoil.3 ${smalltrafomodell.ricoil.3}" - puts $datei "smalltrafomodell.rocoil.3 ${smalltrafomodell.rocoil.3}" - puts $datei "smalltrafomodell.zposcoil.3 ${smalltrafomodell.zposcoil.3}" - puts $datei "smalltrafomodell.heightcoil.3 ${smalltrafomodell.heightcoil.3}" - puts $datei "smalltrafomodell.currentcoil.3 ${smalltrafomodell.currentcoil.3}" - puts $datei "smalltrafomodell.nturnscoil.3 ${smalltrafomodell.nturnscoil.3}" - puts $datei "smalltrafomodell.limbcoil.4 ${smalltrafomodell.limbcoil.4}" - puts $datei "smalltrafomodell.ricoil.4 ${smalltrafomodell.ricoil.4}" - puts $datei "smalltrafomodell.rocoil.4 ${smalltrafomodell.rocoil.4}" - puts $datei "smalltrafomodell.zposcoil.4 ${smalltrafomodell.zposcoil.4}" - puts $datei "smalltrafomodell.heightcoil.4 ${smalltrafomodell.heightcoil.4}" - puts $datei "smalltrafomodell.currentcoil.4 ${smalltrafomodell.currentcoil.4}" - puts $datei "smalltrafomodell.nturnscoil.4 ${smalltrafomodell.nturnscoil.4}" - puts $datei "smalltrafomodell.limbcoil.5 ${smalltrafomodell.limbcoil.5}" - puts $datei "smalltrafomodell.ricoil.5 ${smalltrafomodell.ricoil.5}" - puts $datei "smalltrafomodell.rocoil.5 ${smalltrafomodell.rocoil.5}" - puts $datei "smalltrafomodell.zposcoil.5 ${smalltrafomodell.zposcoil.5}" - puts $datei "smalltrafomodell.heightcoil.5 ${smalltrafomodell.heightcoil.5}" - puts $datei "smalltrafomodell.currentcoil.5 ${smalltrafomodell.currentcoil.5}" - puts $datei "smalltrafomodell.nturnscoil.5 ${smalltrafomodell.nturnscoil.5}" - puts $datei "smalltrafomodell.limbcoil.6 ${smalltrafomodell.limbcoil.6}" - puts $datei "smalltrafomodell.ricoil.6 ${smalltrafomodell.ricoil.6}" - puts $datei "smalltrafomodell.rocoil.6 ${smalltrafomodell.rocoil.6}" - puts $datei "smalltrafomodell.zposcoil.6 ${smalltrafomodell.zposcoil.6}" - puts $datei "smalltrafomodell.heightcoil.6 ${smalltrafomodell.heightcoil.6}" - puts $datei "smalltrafomodell.currentcoil.6 ${smalltrafomodell.currentcoil.6}" - puts $datei "smalltrafomodell.nturnscoil.6 ${smalltrafomodell.nturnscoil.6}" - puts $datei "smalltrafomodell.limbtest.1 ${smalltrafomodell.limbtest.1}" - puts $datei "smalltrafomodell.heighttest.1 ${smalltrafomodell.heighttest.1}" - puts $datei "smalltrafomodell.widthtest.1 ${smalltrafomodell.widthtest.1}" - puts $datei "smalltrafomodell.rtest.1 ${smalltrafomodell.rtest.1}" - puts $datei "smalltrafomodell.zpostest.1 ${smalltrafomodell.zpostest.1}" - puts $datei "smalltrafomodell.edgeradiustest.1 ${smalltrafomodell.edgeradiustest.1}" - puts $datei "smalltrafomodell.finetest.1 ${smalltrafomodell.finetest.1}" - puts $datei "smalltrafomodell.conductivetest.1 ${smalltrafomodell.conductivetest.1}" - puts $datei "smalltrafomodell.limbtest.2 ${smalltrafomodell.limbtest.2}" - puts $datei "smalltrafomodell.heighttest.2 ${smalltrafomodell.heighttest.2}" - puts $datei "smalltrafomodell.widthtest.2 ${smalltrafomodell.widthtest.2}" - puts $datei "smalltrafomodell.rtest.2 ${smalltrafomodell.rtest.2}" - puts $datei "smalltrafomodell.zpostest.2 ${smalltrafomodell.zpostest.2}" - puts $datei "smalltrafomodell.edgeradiustest.2 ${smalltrafomodell.edgeradiustest.2}" - puts $datei "smalltrafomodell.finetest.2 ${smalltrafomodell.finetest.2}" - puts $datei "smalltrafomodell.conductivetest.2 ${smalltrafomodell.conductivetest.2}" - puts $datei "smalltrafomodell.limbtest.3 ${smalltrafomodell.limbtest.3}" - puts $datei "smalltrafomodell.heighttest.3 ${smalltrafomodell.heighttest.3}" - puts $datei "smalltrafomodell.widthtest.3 ${smalltrafomodell.widthtest.3}" - puts $datei "smalltrafomodell.rtest.3 ${smalltrafomodell.rtest.3}" - puts $datei "smalltrafomodell.zpostest.3 ${smalltrafomodell.zpostest.3}" - puts $datei "smalltrafomodell.edgeradiustest.3 ${smalltrafomodell.edgeradiustest.3}" - puts $datei "smalltrafomodell.finetest.3 ${smalltrafomodell.finetest.3}" - puts $datei "smalltrafomodell.conductivetest.3 ${smalltrafomodell.conductivetest.3}" - puts $datei "smalltrafomodell.limbtest.4 ${smalltrafomodell.limbtest.4}" - puts $datei "smalltrafomodell.heighttest.4 ${smalltrafomodell.heighttest.4}" - puts $datei "smalltrafomodell.widthtest.4 ${smalltrafomodell.widthtest.4}" - puts $datei "smalltrafomodell.rtest.4 ${smalltrafomodell.rtest.4}" - puts $datei "smalltrafomodell.zpostest.4 ${smalltrafomodell.zpostest.4}" - puts $datei "smalltrafomodell.edgeradiustest.4 ${smalltrafomodell.edgeradiustest.4}" - puts $datei "smalltrafomodell.finetest.4 ${smalltrafomodell.finetest.4}" - puts $datei "smalltrafomodell.conductivetest.4 ${smalltrafomodell.conductivetest.4}" - puts $datei "smalltrafomodell.nperitest ${smalltrafomodell.nperitest}" - puts $datei "smalltrafomodell.filename ${smalltrafomodell.filename}" - puts $datei "smalltrafomodell.murlfguide ${smalltrafomodell.murlfguide}" - puts $datei "smalltrafomodell.murtestwire ${smalltrafomodell.murtestwire}" - puts $datei "smalltrafomodell.murcore ${smalltrafomodell.murcore}" - puts $datei "smalltrafomodell.kappalfguide ${smalltrafomodell.kappalfguide}" - puts $datei "smalltrafomodell.kappatestwire ${smalltrafomodell.kappatestwire}" - puts $datei "smalltrafomodell.kappacore ${smalltrafomodell.kappacore}" - } - - - close $datei - } - } -} - - - - -# the ini file is saved on demand : -proc saveinifile { } { - global inifilename - if {[catch { set datei [open $inifilename w] } result ]} { - puts "cannot write file $inifilename" - } { - for { set i [.ngmenu.file.recent index last] } { $i >= 1 } { incr i -1 } { - puts $datei "recentfile \"[.ngmenu.file.recent entrycget $i -label]\"" - } - close $datei - } -} - - -proc savemeshinifile { } { - global meshinifilename - if {[catch { set datei [open $meshinifilename w] } result ]} { - puts "cannot write file $meshinifilename" - } { - for { set i [.ngmenu.file.recentmesh index last] } { $i >= 1 } { incr i -1 } { - puts $datei "recentfile \"[.ngmenu.file.recentmesh entrycget $i -label]\"" - } - close $datei - } -} - - - -proc loadinifile { } { - global inifilename - if { [file exists $inifilename] == 1 } { - set datei [open $inifilename r] - while { [gets $datei line] >= 0 } { - if {[lindex $line 0] == "recentfile"} { - set filename [lindex $line 1] - if { [file exists $filename] == 1 } { - AddRecentFile $filename - } - } - } - close $datei - } -} - - -proc loadmeshinifile { } { - global meshinifilename - if { [file exists $meshinifilename] == 1 } { - set datei [open $meshinifilename r] - while { [gets $datei line] >= 0 } { - if {[lindex $line 0] == "recentfile"} { - set filename [lindex $line 1] - if { [file exists $filename] == 1 } { - AddRecentMeshFile $filename - } - } - } - close $datei - } - } - - - - - -set cmdindex {} -set hlpindex {} -set secindex {} +# netgen global tcl-variables + +set drawmode rotate +set selectvisual geometry + +set dirname . +set loadgeomtypevar "All Geometry types" + +set basefilename filename + +set meshoptions.fineness 3 +set meshoptions.firststep ag +set meshoptions.laststep ov +set options.memory 0 + +set options.localh 1 +set options.delaunay 1 +set options.checkoverlap 1 +set options.checkoverlappingboundary 0 +set options.checkchartboundary 1 +set options.startinsurface 0 +set options.blockfill 1 +set options.debugmode 0 +set options.dooptimize 1 +set options.parthread 1 +set options.elsizeweight 0.2 +set options.secondorder 0 +set options.elementorder 1 +set options.quad 0 +set options.inverttets 0 +set options.inverttrigs 0 +set options.autozrefine 0 + + +set options.meshsize 1000 +set options.minmeshsize 0 + +set options.curvaturesafety 2 +set options.segmentsperedge 2 +set options.meshsizefilename "" +set options.badellimit 175 +set options.optsteps2d 3 +set options.optsteps3d 5 +set options.opterrpow 2 + +set options.grading 0.5 +set options.printmsg 2 + +set debug.slowchecks 0 +set debug.debugoutput 0 +set debug.haltexistingline 0 +set debug.haltoverlap 0 +set debug.haltsuccess 0 +set debug.haltnosuccess 0 +set debug.haltlargequalclass 0 +set debug.haltsegment 0 +set debug.haltnode 0 +set debug.haltface 0 +set debug.haltfacenr 0 +set debug.haltsegmentp1 0 +set debug.haltsegmentp2 0 + +set geooptions.drawcsg 1 +set geooptions.detail 0.001 +set geooptions.accuracy 1e-6 +set geooptions.facets 20 +set geooptions.minx -1000 +set geooptions.miny -1000 +set geooptions.minz -1000 +set geooptions.maxx 1000 +set geooptions.maxy 1000 +set geooptions.maxz 1000 + +set viewqualityplot 0 +set memuseplot 0 +set viewrotatebutton 0 +set showsensitivehelp 0 +set showhelpline 0 + +set viewoptions.specpointvlen 0.3 +set viewoptions.light.amb 0.3 +set viewoptions.light.diff 0.7 +set viewoptions.light.spec 1 +set viewoptions.light.locviewer 0 +set viewoptions.mat.shininess 50 +set viewoptions.mat.transp 0.3 +set viewoptions.colormeshsize 0 +set viewoptions.whitebackground 1 +set viewoptions.drawcoordinatecross 1 +set viewoptions.drawcolorbar 1 +set viewoptions.drawnetgenlogo 1 +set viewoptions.stereo 0 +set viewoptions.shrink 1 + +set viewoptions.drawfilledtrigs 1 +set viewoptions.drawedges 0 +set viewoptions.drawbadels 0 +set viewoptions.centerpoint 0 +set viewoptions.drawelement 0 +set viewoptions.drawoutline 1 +set viewoptions.drawtets 0 +set viewoptions.drawtetsdomain 0 +set viewoptions.drawprisms 0 +set viewoptions.drawpyramids 0 +set viewoptions.drawhexes 0 +set viewoptions.drawidentified 0 +set viewoptions.drawpointnumbers 0 +set viewoptions.drawedgenumbers 0 +set viewoptions.drawfacenumbers 0 +set viewoptions.drawelementnumbers 0 +set viewoptions.drawdomainsurf 0 + +set viewoptions.drawededges 1 +set viewoptions.drawedpoints 1 +set viewoptions.drawedpointnrs 0 +set viewoptions.drawedtangents 0 +set viewoptions.drawededgenrs 0 +set viewoptions.drawmetispartition 0 + +set viewoptions.drawcurveproj 0 +set viewoptions.drawcurveprojedge 1 + +set viewoptions.clipping.nx 0 +set viewoptions.clipping.ny 1 +set viewoptions.clipping.nz 0 +set viewoptions.clipping.dist 0 +set viewoptions.clipping.dist2 0 +set viewoptions.clipping.enable 0 +set viewoptions.clipping.onlydomain 0 +set viewoptions.clipping.notdomain 0 + +set viewoptions.usecentercoords 0 +set viewoptions.centerx 0 +set viewoptions.centery 0 +set viewoptions.centerz 0 + +set viewoptions.drawspecpoint 0 +set viewoptions.specpointx 0 +set viewoptions.specpointy 0 +set viewoptions.specpointz 0 + + +set stloptions.showtrias 0 +set stloptions.showfilledtrias 1 +set stloptions.showedges 1 +set stloptions.showmarktrias 0 +set stloptions.showactivechart 0 +set stloptions.yangle 30 +set stloptions.contyangle 20 +set stloptions.edgecornerangle 60 +set stloptions.chartangle 15 +set stloptions.outerchartangle 70 +set stloptions.usesearchtree 0 +set stloptions.chartnumber 1 +set stloptions.charttrignumber 1 +set stloptions.chartnumberoffset 0 + +set stloptions.atlasminh 0.1 +set stloptions.resthsurfcurvfac 2 +set stloptions.resthsurfcurvenable 0 +set stloptions.resthatlasfac 2 +set stloptions.resthatlasenable 1 +set stloptions.resthchartdistfac 1.2 +set stloptions.resthchartdistenable 1 +set stloptions.resthlinelengthfac 0.5 +set stloptions.resthlinelengthenable 1 +set stloptions.resthcloseedgefac 1 +set stloptions.resthcloseedgeenable 1 +set stloptions.resthminedgelen 0.01 +set stloptions.resthminedgelenenable 1 +set stloptions.resthedgeanglefac 1 +set stloptions.resthedgeangleenable 0 +set stloptions.resthsurfmeshcurvfac 1 +set stloptions.resthsurfmeshcurvenable 0 +set stloptions.recalchopt 1 + +set stldoctor.drawmeshededges 1 +set stldoctor.geom_tol_fact 0.000001 +set stldoctor.useexternaledges 0 +set stldoctor.showfaces 0 +set stldoctor.conecheck 1 +set stldoctor.spiralcheck 1 +set stldoctor.selecttrig 0 +set stldoctor.selectmode 1 +set stldoctor.longlinefact 0 +set stldoctor.showexcluded 1 +set stldoctor.edgeselectmode 0 +set stldoctor.nodeofseltrig 1 +set stldoctor.showtouchedtrigchart 0 +set stldoctor.showedgecornerpoints 0 +set stldoctor.showmarkedtrigs 1 +set stldoctor.dirtytrigfact 0.01 +set stldoctor.smoothangle 90 +set stldoctor.selectwithmouse 1 +set stldoctor.showvicinity 0 +set stldoctor.vicinity 50 +set stldoctor.smoothnormalsweight 0.2 + +set occoptions.showvolumenr 0 +set occoptions.showsurfaces 1 +set occoptions.showedges 1 +set occoptions.showsolidnr 0 +set occoptions.showsolidnr2 0 +set occoptions.visproblemfaces 0 +set occoptions.zoomtohighlightedentity 0 +set occoptions.deflection 1 +set occoptions.tolerance 1e-3 +set occoptions.fixsmalledges 1 +set occoptions.fixspotstripfaces 1 +set occoptions.sewfaces 1 +set occoptions.makesolids 1 +set occoptions.splitpartitions 0 + +set meshdoctor.active 0 +set meshdoctor.markedgedist 1 + + +# variablenname mit punkt problematisch! +set status_np 0 +set status_ne 0 +set status_nse 0 +set status_working " " +set status_task " " +set status_percent 0 +set status_filename 0 +set status_tetqualclasses "10 20 30 40 10 20 30 40 10 20 30 40 10 20 30 40 10 20 30 40" + +set exportfiletype "Neutral Format" + +set preproc.facenr 0 +set preproc.selectmode query +set preproc.numtrig 0 + +set mem_moveable 0 + + +set multithread_pause 0 +set multithread_testmode 0 +set multithread_redraw 0 +set multithread_drawing 0 +set multithread_terminate 0 +set multithread_running 0 + +set level 0 + + +set tablesforoutput {} + + + +set optlist { + options.localh + options.delaunay + options.checkoverlap + options.startinsurface + options.blockfill + options.dooptimize + options.elsizeweight + options.meshsize + options.minmeshsize + options.curvaturesafety + options.optsteps2d + options.optsteps3d + options.secondorder +} + + +set visoptions.usetexture 1 +set visoptions.invcolor 0 +set visoptions.imaginary 0 +set visoptions.lineartexture 0 +set visoptions.numtexturecols 16 +set visoptions.showclipsolution 1 +set visoptions.showsurfacesolution 0 +set visoptions.drawfieldlines 0 +set visoptions.drawpointcurves 1 +set visoptions.numfieldlines 100 +set visoptions.fieldlinesrandomstart 0 +set visoptions.fieldlinesstartarea box +set visoptions.fieldlinesstartareap1x 1 +set visoptions.fieldlinesstartareap1y 1 +set visoptions.fieldlinesstartareap1z 1 +set visoptions.fieldlinesstartareap2x 0 +set visoptions.fieldlinesstartareap2y 0 +set visoptions.fieldlinesstartareap2z 0 +set visoptions.fieldlinesstartface -1 +set visoptions.fieldlinesfilename none +set visoptions.fieldlinestolerance 0.0005 +set visoptions.fieldlinesrktype crungekutta +set visoptions.fieldlineslength 0.5 +set visoptions.fieldlinesmaxpoints 500 +set visoptions.fieldlinesthickness 0.0015 +set visoptions.fieldlinesvecfunction none +set visoptions.fieldlinesphase 0 +set visoptions.fieldlinesonlyonephase 1 + + +set visoptions.lineplotfile empty +set visoptions.lineplotsource file +set visoptions.lineplotusingx 0 +set visoptions.lineplotusingy 1 +set visoptions.lineplotautoscale 1 +set visoptions.lineplotxmin 0 +set visoptions.lineplotxmax 1 +set visoptions.lineplotymin 0 +set visoptions.lineplotymax 1 +set visoptions.lineplotcurrentnum -1 +set visoptions.lineplotinfos "" +set visoptions.lineplotselected none +set visoptions.lineplotselector "" +set visoptions.lineplotcolor red +set visoptions.lineplotsizex 500 +set visoptions.lineplotsizey 400 +set visoptions.lineplotselectedeval 0 +set visoptions.lineplotdatadescr "column1 column2 column3" +set visoptions.lineplotxcoordselector "" +set visoptions.lineplotycoordselector "" +set visoptions.evaluatefilenames none +set visoptions.evaluatefiledescriptions none + + +set visoptions.clipsolution none +set visoptions.scalfunction none +set visoptions.vecfunction none +set visoptions.evaluate abs +set visoptions.gridsize 20 +set visoptions.xoffset 0 +set visoptions.yoffset 0 +set visoptions.autoscale 1 +set visoptions.redrawperiodic 0 +set visoptions.logscale 0 +set visoptions.mminval 0 +set visoptions.mmaxval 1 +set visoptions.isolines 0 +set visoptions.isosurf 0 +set visoptions.subdivisions 1 +set visoptions.numiso 10 +set visoptions.autoredraw 0 +set visoptions.autoredrawtime 2 +set visoptions.simulationtime 0 +set visoptions.multidimcomponent 0 + +# deform by vector function +set visoptions.deformation 0 +set visoptions.scaledeform1 1 +set visoptions.scaledeform2 1 + +set parallel_netgen 0 + + + + + + + + + + + + + + + +set optfilename [file join $nguserdir ng.opt] +set inifilename [file join $nguserdir ng.ini] +set meshinifilename [file join $nguserdir ngmesh.ini] + +global env +if { [llength [array names env NG_OPT]] == 1 } { + if { [string length $env(NG_OPT)] > 0 } { + set optfilename $env(NG_OPT) + } +} + +if { [file exists $optfilename] == 1 } { + set datei [open $optfilename r] + while { [gets $datei line] >= 0 } { + set [lindex $line 0] [lindex $line 1] + } + close $datei +} { + puts "optfile $optfilename does not exist - using default values" +} + + + + +proc saveoptions { } { + uplevel 1 { + set file $optfilename + + if {$file != ""} { + set datei [open $file w] + puts $datei "dirname ${dirname}" + puts $datei "loadgeomtypevar \"${loadgeomtypevar}\"" + puts $datei "exportfiletype \"${exportfiletype}\"" + puts $datei "meshoptions.fineness ${meshoptions.fineness}" + puts $datei "meshoptions.firststep ${meshoptions.firststep}" + puts $datei "meshoptions.laststep ${meshoptions.laststep}" + puts $datei "options.localh ${options.localh}" + puts $datei "options.delaunay ${options.delaunay}" + puts $datei "options.checkoverlap ${options.checkoverlap}" + puts $datei "options.checkchartboundary ${options.checkchartboundary}" + puts $datei "options.startinsurface ${options.startinsurface}" + puts $datei "options.blockfill ${options.blockfill}" + puts $datei "options.debugmode ${options.debugmode}" + puts $datei "options.dooptimize ${options.dooptimize}" + puts $datei "options.parthread ${options.parthread}" + puts $datei "options.elsizeweight ${options.elsizeweight}" + puts $datei "options.secondorder ${options.secondorder}" + puts $datei "options.elementorder ${options.elementorder}" +# puts $datei "options.memory ${options.memory}" + puts $datei "options.quad ${options.quad}" + puts $datei "options.inverttets ${options.inverttets}" + puts $datei "options.inverttrigs ${options.inverttrigs}" + puts $datei "options.autozrefine ${options.autozrefine}" + puts $datei "options.meshsize ${options.meshsize}" + puts $datei "options.minmeshsize ${options.minmeshsize}" + puts $datei "options.curvaturesafety ${options.curvaturesafety}" + puts $datei "options.segmentsperedge ${options.segmentsperedge}" + puts $datei "options.meshsizefilename ${options.meshsizefilename}" + puts $datei "options.badellimit ${options.badellimit}" + puts $datei "options.optsteps2d ${options.optsteps2d}" + puts $datei "options.optsteps3d ${options.optsteps3d}" + puts $datei "options.opterrpow ${options.opterrpow}" + puts $datei "options.grading ${options.grading}" + puts $datei "options.printmsg ${options.printmsg}" + puts $datei "geooptions.drawcsg ${geooptions.drawcsg}" + puts $datei "geooptions.detail ${geooptions.detail}" + puts $datei "geooptions.accuracy ${geooptions.accuracy}" + puts $datei "geooptions.facets ${geooptions.facets}" + puts $datei "geooptions.minx ${geooptions.minx}" + puts $datei "geooptions.miny ${geooptions.miny}" + puts $datei "geooptions.minz ${geooptions.minz}" + puts $datei "geooptions.maxx ${geooptions.maxx}" + puts $datei "geooptions.maxy ${geooptions.maxy}" + puts $datei "geooptions.maxz ${geooptions.maxz}" + puts $datei "viewoptions.specpointvlen ${viewoptions.specpointvlen}" + puts $datei "viewoptions.light.amb ${viewoptions.light.amb}" + puts $datei "viewoptions.light.diff ${viewoptions.light.diff}" + puts $datei "viewoptions.light.spec ${viewoptions.light.spec}" + puts $datei "viewoptions.light.locviewer ${viewoptions.light.locviewer}" + puts $datei "viewoptions.mat.shininess ${viewoptions.mat.shininess}" + puts $datei "viewoptions.mat.transp ${viewoptions.mat.transp}" + puts $datei "viewoptions.colormeshsize ${viewoptions.colormeshsize}" + puts $datei "viewoptions.whitebackground ${viewoptions.whitebackground}" + puts $datei "viewoptions.drawcolorbar ${viewoptions.drawcolorbar}" + puts $datei "viewoptions.drawcoordinatecross ${viewoptions.drawcoordinatecross}" + puts $datei "viewoptions.drawnetgenlogo ${viewoptions.drawnetgenlogo}" + puts $datei "viewoptions.stereo ${viewoptions.stereo}" + puts $datei "viewoptions.drawfilledtrigs ${viewoptions.drawfilledtrigs}" + puts $datei "viewoptions.drawedges ${viewoptions.drawedges}" + puts $datei "viewoptions.drawbadels ${viewoptions.drawbadels}" + puts $datei "viewoptions.centerpoint ${viewoptions.centerpoint}" + puts $datei "viewoptions.drawelement ${viewoptions.drawelement}" + puts $datei "viewoptions.drawoutline ${viewoptions.drawoutline}" + puts $datei "viewoptions.drawtets ${viewoptions.drawtets}" + puts $datei "viewoptions.drawprisms ${viewoptions.drawprisms}" + puts $datei "viewoptions.drawpyramids ${viewoptions.drawpyramids}" + puts $datei "viewoptions.drawhexes ${viewoptions.drawhexes}" + puts $datei "viewoptions.drawidentified ${viewoptions.drawidentified}" + puts $datei "viewoptions.drawpointnumbers ${viewoptions.drawpointnumbers}" + + puts $datei "viewoptions.drawededges ${viewoptions.drawededges}" + puts $datei "viewoptions.drawedpoints ${viewoptions.drawedpoints}" + puts $datei "viewoptions.drawedpointnrs ${viewoptions.drawedpointnrs}" + puts $datei "viewoptions.drawedtangents ${viewoptions.drawedtangents}" + puts $datei "viewoptions.shrink ${viewoptions.shrink}" + + puts $datei "stloptions.showtrias ${stloptions.showtrias}" + puts $datei "stloptions.showfilledtrias ${stloptions.showfilledtrias}" + puts $datei "stloptions.showedges ${stloptions.showedges}" + puts $datei "stloptions.showmarktrias ${stloptions.showmarktrias}" + puts $datei "stloptions.showactivechart ${stloptions.showactivechart}" + puts $datei "stloptions.yangle ${stloptions.yangle}" + puts $datei "stloptions.contyangle ${stloptions.contyangle}" + puts $datei "stloptions.edgecornerangle ${stloptions.edgecornerangle}" + puts $datei "stloptions.chartangle ${stloptions.chartangle}" + puts $datei "stloptions.outerchartangle ${stloptions.outerchartangle}" + puts $datei "stloptions.usesearchtree ${stloptions.usesearchtree}" + puts $datei "stloptions.chartnumber ${stloptions.chartnumber}" + puts $datei "stloptions.charttrignumber ${stloptions.charttrignumber}" + puts $datei "stloptions.chartnumberoffset ${stloptions.chartnumberoffset}" + puts $datei "stloptions.atlasminh ${stloptions.atlasminh}" + puts $datei "stloptions.resthsurfcurvfac ${stloptions.resthsurfcurvfac}" + puts $datei "stloptions.resthsurfcurvenable ${stloptions.resthsurfcurvenable}" + puts $datei "stloptions.resthatlasfac ${stloptions.resthatlasfac}" + puts $datei "stloptions.resthatlasenable ${stloptions.resthatlasenable}" + puts $datei "stloptions.resthchartdistfac ${stloptions.resthchartdistfac}" + puts $datei "stloptions.resthchartdistenable ${stloptions.resthchartdistenable}" + puts $datei "stloptions.resthlinelengthfac ${stloptions.resthlinelengthfac}" + puts $datei "stloptions.resthlinelengthenable ${stloptions.resthlinelengthenable}" + puts $datei "stloptions.resthminedgelen ${stloptions.resthminedgelen}" + puts $datei "stloptions.resthminedgelenenable ${stloptions.resthminedgelenenable}" + puts $datei "stloptions.resthcloseedgefac ${stloptions.resthcloseedgefac}" + puts $datei "stloptions.resthcloseedgeenable ${stloptions.resthcloseedgeenable}" + puts $datei "stloptions.resthedgeanglefac ${stloptions.resthedgeanglefac}" + puts $datei "stloptions.resthedgeangleenable ${stloptions.resthedgeangleenable}" + puts $datei "stloptions.resthsurfmeshcurvfac ${stloptions.resthsurfmeshcurvfac}" + puts $datei "stloptions.resthsurfmeshcurvenable ${stloptions.resthsurfmeshcurvenable}" + puts $datei "stloptions.recalchopt ${stloptions.recalchopt}" + + puts $datei "visoptions.subdivisions ${visoptions.subdivisions}" + puts $datei "visoptions.autoredraw ${visoptions.autoredraw}" + puts $datei "visoptions.autoredrawtime ${visoptions.autoredrawtime}" + + + # trafo options + # if exist trafooptions then ... + if { [info exists trafooptions.solver] == 1 } { + puts $datei "trafooptions.solver ${trafooptions.solver}" + puts $datei "trafooptions.levels ${trafooptions.levels}" + puts $datei "trafooptions.linits ${trafooptions.linits}" + puts $datei "trafooptions.nonlinits ${trafooptions.nonlinits}" + puts $datei "trafooptions.stabcurrent ${trafooptions.stabcurrent}" + puts $datei "trafooptions.checkcond ${trafooptions.checkcond}" + puts $datei "trafooptions.maxdirect ${trafooptions.maxdirect}" + puts $datei "trafooptions.secondorder ${trafooptions.secondorder}" + puts $datei "trafooptions.homogenizedcore ${trafooptions.homogenizedcore}" + puts $datei "trafooptions.ordercore ${trafooptions.ordercore}" + puts $datei "trafooptions.simplecurrents ${trafooptions.simplecurrents}" + puts $datei "trafooptions.assemblecomplexmatrix ${trafooptions.assemblecomplexmatrix}" + + puts $datei "trafooptions.meshcasing ${trafooptions.meshcasing}" + puts $datei "trafooptions.meshcore ${trafooptions.meshcore}" + puts $datei "trafooptions.meshclumps ${trafooptions.meshclumps}" + puts $datei "trafooptions.meshshields ${trafooptions.meshshields}" + puts $datei "trafooptions.meshcoils ${trafooptions.meshcoils}" + puts $datei "trafooptions.bcmdirectory ${trafooptions.bcmdirectory}" + puts $datei "trafooptions.lossdensityfile ${trafooptions.lossdensityfile}" + } + + if { [info exists smalltrafomodell.tankheight] == 1 } { + puts $datei "smalltrafomodell.tankheight ${smalltrafomodell.tankheight}" + puts $datei "smalltrafomodell.tankwidth ${smalltrafomodell.tankwidth}" + puts $datei "smalltrafomodell.tanklength ${smalltrafomodell.tanklength}" + puts $datei "smalltrafomodell.corewidth ${smalltrafomodell.corewidth}" + puts $datei "smalltrafomodell.windowheight ${smalltrafomodell.windowheight}" + puts $datei "smalltrafomodell.limbdistance ${smalltrafomodell.limbdistance}" + puts $datei "smalltrafomodell.xposcore ${smalltrafomodell.xposcore}" + puts $datei "smalltrafomodell.yposcore ${smalltrafomodell.yposcore}" + puts $datei "smalltrafomodell.zposcore ${smalltrafomodell.zposcore}" + puts $datei "smalltrafomodell.leakagefluxguidethickness ${smalltrafomodell.leakagefluxguidethickness}" + puts $datei "smalltrafomodell.leakagefluxguidewidth ${smalltrafomodell.leakagefluxguidewidth}" + puts $datei "smalltrafomodell.leakagefluxguidezposition ${smalltrafomodell.leakagefluxguidezposition}" + puts $datei "smalltrafomodell.limbcoil.1 ${smalltrafomodell.limbcoil.1}" + puts $datei "smalltrafomodell.ricoil.1 ${smalltrafomodell.ricoil.1}" + puts $datei "smalltrafomodell.rocoil.1 ${smalltrafomodell.rocoil.1}" + puts $datei "smalltrafomodell.zposcoil.1 ${smalltrafomodell.zposcoil.1}" + puts $datei "smalltrafomodell.heightcoil.1 ${smalltrafomodell.heightcoil.1}" + puts $datei "smalltrafomodell.currentcoil.1 ${smalltrafomodell.currentcoil.1}" + puts $datei "smalltrafomodell.nturnscoil.1 ${smalltrafomodell.nturnscoil.1}" + puts $datei "smalltrafomodell.limbcoil.2 ${smalltrafomodell.limbcoil.2}" + puts $datei "smalltrafomodell.ricoil.2 ${smalltrafomodell.ricoil.2}" + puts $datei "smalltrafomodell.rocoil.2 ${smalltrafomodell.rocoil.2}" + puts $datei "smalltrafomodell.zposcoil.2 ${smalltrafomodell.zposcoil.2}" + puts $datei "smalltrafomodell.heightcoil.2 ${smalltrafomodell.heightcoil.2}" + puts $datei "smalltrafomodell.currentcoil.2 ${smalltrafomodell.currentcoil.2}" + puts $datei "smalltrafomodell.nturnscoil.2 ${smalltrafomodell.nturnscoil.2}" + puts $datei "smalltrafomodell.limbcoil.3 ${smalltrafomodell.limbcoil.3}" + puts $datei "smalltrafomodell.ricoil.3 ${smalltrafomodell.ricoil.3}" + puts $datei "smalltrafomodell.rocoil.3 ${smalltrafomodell.rocoil.3}" + puts $datei "smalltrafomodell.zposcoil.3 ${smalltrafomodell.zposcoil.3}" + puts $datei "smalltrafomodell.heightcoil.3 ${smalltrafomodell.heightcoil.3}" + puts $datei "smalltrafomodell.currentcoil.3 ${smalltrafomodell.currentcoil.3}" + puts $datei "smalltrafomodell.nturnscoil.3 ${smalltrafomodell.nturnscoil.3}" + puts $datei "smalltrafomodell.limbcoil.4 ${smalltrafomodell.limbcoil.4}" + puts $datei "smalltrafomodell.ricoil.4 ${smalltrafomodell.ricoil.4}" + puts $datei "smalltrafomodell.rocoil.4 ${smalltrafomodell.rocoil.4}" + puts $datei "smalltrafomodell.zposcoil.4 ${smalltrafomodell.zposcoil.4}" + puts $datei "smalltrafomodell.heightcoil.4 ${smalltrafomodell.heightcoil.4}" + puts $datei "smalltrafomodell.currentcoil.4 ${smalltrafomodell.currentcoil.4}" + puts $datei "smalltrafomodell.nturnscoil.4 ${smalltrafomodell.nturnscoil.4}" + puts $datei "smalltrafomodell.limbcoil.5 ${smalltrafomodell.limbcoil.5}" + puts $datei "smalltrafomodell.ricoil.5 ${smalltrafomodell.ricoil.5}" + puts $datei "smalltrafomodell.rocoil.5 ${smalltrafomodell.rocoil.5}" + puts $datei "smalltrafomodell.zposcoil.5 ${smalltrafomodell.zposcoil.5}" + puts $datei "smalltrafomodell.heightcoil.5 ${smalltrafomodell.heightcoil.5}" + puts $datei "smalltrafomodell.currentcoil.5 ${smalltrafomodell.currentcoil.5}" + puts $datei "smalltrafomodell.nturnscoil.5 ${smalltrafomodell.nturnscoil.5}" + puts $datei "smalltrafomodell.limbcoil.6 ${smalltrafomodell.limbcoil.6}" + puts $datei "smalltrafomodell.ricoil.6 ${smalltrafomodell.ricoil.6}" + puts $datei "smalltrafomodell.rocoil.6 ${smalltrafomodell.rocoil.6}" + puts $datei "smalltrafomodell.zposcoil.6 ${smalltrafomodell.zposcoil.6}" + puts $datei "smalltrafomodell.heightcoil.6 ${smalltrafomodell.heightcoil.6}" + puts $datei "smalltrafomodell.currentcoil.6 ${smalltrafomodell.currentcoil.6}" + puts $datei "smalltrafomodell.nturnscoil.6 ${smalltrafomodell.nturnscoil.6}" + puts $datei "smalltrafomodell.limbtest.1 ${smalltrafomodell.limbtest.1}" + puts $datei "smalltrafomodell.heighttest.1 ${smalltrafomodell.heighttest.1}" + puts $datei "smalltrafomodell.widthtest.1 ${smalltrafomodell.widthtest.1}" + puts $datei "smalltrafomodell.rtest.1 ${smalltrafomodell.rtest.1}" + puts $datei "smalltrafomodell.zpostest.1 ${smalltrafomodell.zpostest.1}" + puts $datei "smalltrafomodell.edgeradiustest.1 ${smalltrafomodell.edgeradiustest.1}" + puts $datei "smalltrafomodell.finetest.1 ${smalltrafomodell.finetest.1}" + puts $datei "smalltrafomodell.conductivetest.1 ${smalltrafomodell.conductivetest.1}" + puts $datei "smalltrafomodell.limbtest.2 ${smalltrafomodell.limbtest.2}" + puts $datei "smalltrafomodell.heighttest.2 ${smalltrafomodell.heighttest.2}" + puts $datei "smalltrafomodell.widthtest.2 ${smalltrafomodell.widthtest.2}" + puts $datei "smalltrafomodell.rtest.2 ${smalltrafomodell.rtest.2}" + puts $datei "smalltrafomodell.zpostest.2 ${smalltrafomodell.zpostest.2}" + puts $datei "smalltrafomodell.edgeradiustest.2 ${smalltrafomodell.edgeradiustest.2}" + puts $datei "smalltrafomodell.finetest.2 ${smalltrafomodell.finetest.2}" + puts $datei "smalltrafomodell.conductivetest.2 ${smalltrafomodell.conductivetest.2}" + puts $datei "smalltrafomodell.limbtest.3 ${smalltrafomodell.limbtest.3}" + puts $datei "smalltrafomodell.heighttest.3 ${smalltrafomodell.heighttest.3}" + puts $datei "smalltrafomodell.widthtest.3 ${smalltrafomodell.widthtest.3}" + puts $datei "smalltrafomodell.rtest.3 ${smalltrafomodell.rtest.3}" + puts $datei "smalltrafomodell.zpostest.3 ${smalltrafomodell.zpostest.3}" + puts $datei "smalltrafomodell.edgeradiustest.3 ${smalltrafomodell.edgeradiustest.3}" + puts $datei "smalltrafomodell.finetest.3 ${smalltrafomodell.finetest.3}" + puts $datei "smalltrafomodell.conductivetest.3 ${smalltrafomodell.conductivetest.3}" + puts $datei "smalltrafomodell.limbtest.4 ${smalltrafomodell.limbtest.4}" + puts $datei "smalltrafomodell.heighttest.4 ${smalltrafomodell.heighttest.4}" + puts $datei "smalltrafomodell.widthtest.4 ${smalltrafomodell.widthtest.4}" + puts $datei "smalltrafomodell.rtest.4 ${smalltrafomodell.rtest.4}" + puts $datei "smalltrafomodell.zpostest.4 ${smalltrafomodell.zpostest.4}" + puts $datei "smalltrafomodell.edgeradiustest.4 ${smalltrafomodell.edgeradiustest.4}" + puts $datei "smalltrafomodell.finetest.4 ${smalltrafomodell.finetest.4}" + puts $datei "smalltrafomodell.conductivetest.4 ${smalltrafomodell.conductivetest.4}" + puts $datei "smalltrafomodell.nperitest ${smalltrafomodell.nperitest}" + puts $datei "smalltrafomodell.filename ${smalltrafomodell.filename}" + puts $datei "smalltrafomodell.murlfguide ${smalltrafomodell.murlfguide}" + puts $datei "smalltrafomodell.murtestwire ${smalltrafomodell.murtestwire}" + puts $datei "smalltrafomodell.murcore ${smalltrafomodell.murcore}" + puts $datei "smalltrafomodell.kappalfguide ${smalltrafomodell.kappalfguide}" + puts $datei "smalltrafomodell.kappatestwire ${smalltrafomodell.kappatestwire}" + puts $datei "smalltrafomodell.kappacore ${smalltrafomodell.kappacore}" + } + + + close $datei + } + } +} + + + + +# the ini file is saved on demand : +proc saveinifile { } { + global inifilename + if {[catch { set datei [open $inifilename w] } result ]} { + puts "cannot write file $inifilename" + } { + for { set i [.ngmenu.file.recent index last] } { $i >= 1 } { incr i -1 } { + puts $datei "recentfile \"[.ngmenu.file.recent entrycget $i -label]\"" + } + close $datei + } +} + + +proc savemeshinifile { } { + global meshinifilename + if {[catch { set datei [open $meshinifilename w] } result ]} { + puts "cannot write file $meshinifilename" + } { + for { set i [.ngmenu.file.recentmesh index last] } { $i >= 1 } { incr i -1 } { + puts $datei "recentfile \"[.ngmenu.file.recentmesh entrycget $i -label]\"" + } + close $datei + } +} + + + +proc loadinifile { } { + global inifilename + if { [file exists $inifilename] == 1 } { + set datei [open $inifilename r] + while { [gets $datei line] >= 0 } { + if {[lindex $line 0] == "recentfile"} { + set filename [lindex $line 1] + if { [file exists $filename] == 1 } { + AddRecentFile $filename + } + } + } + close $datei + } +} + + +proc loadmeshinifile { } { + global meshinifilename + if { [file exists $meshinifilename] == 1 } { + set datei [open $meshinifilename r] + while { [gets $datei line] >= 0 } { + if {[lindex $line 0] == "recentfile"} { + set filename [lindex $line 1] + if { [file exists $filename] == 1 } { + AddRecentMeshFile $filename + } + } + } + close $datei + } + } + + + + + +set cmdindex {} +set hlpindex {} +set secindex {} diff --git a/nglib/nglib.cpp b/nglib/nglib.cpp index 25b168f0..7576f86b 100644 --- a/nglib/nglib.cpp +++ b/nglib/nglib.cpp @@ -1,1236 +1,1242 @@ -/**************************************************************************/ -/* File: nglib.cpp */ -/* Author: Joachim Schoeberl */ -/* Date: 7. May. 2000 */ -/**************************************************************************/ - -/* - - Interface to the netgen meshing kernel - -*/ -#include -#include - -#include -#include -#include -#include -#include -#include <../visualization/soldata.hpp> - -#ifdef OCCGEOMETRY -#include -#endif - -#include - - -namespace netgen { - extern void MeshFromSpline2D (SplineGeometry2d & geometry, - Mesh *& mesh, - MeshingParameters & mp); -} - - - -#ifdef PARALLEL -#include - -namespace netgen -{ - // int id = 0, ntasks = 1; - MPI_Comm mesh_comm; -} -#endif - - -namespace netgen -{ - int id = 0, ntasks = 1; -} - - - -/* -// should not be needed (occ currently requires it) -namespace netgen { -#include "../libsrc/visualization/vispar.hpp" - VisualizationParameters vispar; - VisualizationParameters :: VisualizationParameters() { ; } -} -*/ - - -namespace nglib { -#include "nglib.h" -} - -using namespace netgen; - -// constants and types: - -namespace nglib -{ - // initialize, deconstruct Netgen library: - DLL_HEADER void Ng_Init () - { - mycout = &cout; - myerr = &cerr; - // netgen::testout->SetOutStream (new ofstream ("test.out")); - testout = new ofstream ("test.out"); - } - - - - - // Clean-up functions before ending usage of nglib - DLL_HEADER void Ng_Exit () - { - ; - } - - - - - // Create a new netgen mesh object - DLL_HEADER Ng_Mesh * Ng_NewMesh () - { - Mesh * mesh = new Mesh; - mesh->AddFaceDescriptor (FaceDescriptor (1, 1, 0, 1)); - return (Ng_Mesh*)(void*)mesh; - } - - - - - // Delete an existing netgen mesh object - DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh) - { - if(mesh != NULL) - { - // Delete the Mesh structures - ((Mesh*)mesh)->DeleteMesh(); - - // Now delete the Mesh class itself - delete (Mesh*)mesh; - - // Set the Ng_Mesh pointer to NULL - mesh = NULL; - } - } - - - - - // Save a netgen mesh in the native VOL format - DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename) - { - ((Mesh*)mesh)->Save(filename); - } - - - - - // Load a netgen native VOL mesh from a given file - DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename) - { - Mesh * mesh = new Mesh; - mesh->Load(filename); - return ( (Ng_Mesh*)mesh ); - } - - - - - // Merge another mesh file into the currently loaded one - DLL_HEADER Ng_Result Ng_MergeMesh( Ng_Mesh* mesh, const char* filename) - { - Ng_Result status = NG_OK; - - ifstream infile(filename); - Mesh * m = (Mesh*)mesh; - - if(!infile.good()) - { - status = NG_FILE_NOT_FOUND; - } - - if(!m) - { - status = NG_ERROR; - } - - if(status == NG_OK) - { - const int num_pts = m->GetNP(); - const int face_offset = m->GetNFD(); - - m->Merge(infile, face_offset); - - if(m->GetNP() > num_pts) - { - status = NG_OK; - } - else - { - status = NG_ERROR; - } - } - - return status; - } - - - - - // Merge another mesh file into the currently loaded one - DLL_HEADER Ng_Result Ng_MergeMesh( Ng_Mesh* mesh1, Ng_Mesh* mesh2) - { - return NG_ERROR; - } - - - - - // Manually add a point to an existing mesh object - DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x) - { - Mesh * m = (Mesh*)mesh; - m->AddPoint (Point3d (x[0], x[1], x[2])); - } - - - - - // Manually add a surface element of a given type to an existing mesh object - DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et, - int * pi) - { - Mesh * m = (Mesh*)mesh; - Element2d el (3); - el.SetIndex (1); - el.PNum(1) = pi[0]; - el.PNum(2) = pi[1]; - el.PNum(3) = pi[2]; - m->AddSurfaceElement (el); - } - - - - - // Manually add a volume element of a given type to an existing mesh object - DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et, - int * pi) - { - Mesh * m = (Mesh*)mesh; - Element el (4); - el.SetIndex (1); - el.PNum(1) = pi[0]; - el.PNum(2) = pi[1]; - el.PNum(3) = pi[2]; - el.PNum(4) = pi[3]; - m->AddVolumeElement (el); - } - - - - - // Obtain the number of points in the mesh - DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh) - { - return ((Mesh*)mesh) -> GetNP(); - } - - - - - // Obtain the number of surface elements in the mesh - DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh) - { - return ((Mesh*)mesh) -> GetNSE(); - } - - - - - // Obtain the number of volume elements in the mesh - DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh) - { - return ((Mesh*)mesh) -> GetNE(); - } - - - - - // Return point coordinates of a given point index in the mesh - DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x) - { - const Point3d & p = ((Mesh*)mesh)->Point(num); - x[0] = p.X(); - x[1] = p.Y(); - x[2] = p.Z(); - } - - - - - // Return the surface element at a given index "pi" - DLL_HEADER Ng_Surface_Element_Type - Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi) - { - const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num); - for (int i = 1; i <= el.GetNP(); i++) - pi[i-1] = el.PNum(i); - Ng_Surface_Element_Type et; - switch (el.GetNP()) - { - case 3: et = NG_TRIG; break; - case 4: et = NG_QUAD; break; - case 6: - switch (el.GetNV()) - { - case 3: et = NG_TRIG6; break; - case 4: et = NG_QUAD6; break; - default: - et = NG_TRIG6; break; - } - break; - case 8: et = NG_QUAD8; break; - default: - et = NG_TRIG; break; // for the compiler - } - return et; - } - - - - - // Return the volume element at a given index "pi" - DLL_HEADER Ng_Volume_Element_Type - Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi) - { - const Element & el = ((Mesh*)mesh)->VolumeElement(num); - for (int i = 1; i <= el.GetNP(); i++) - pi[i-1] = el.PNum(i); - Ng_Volume_Element_Type et; - switch (el.GetNP()) - { - case 4: et = NG_TET; break; - case 5: et = NG_PYRAMID; break; - case 6: et = NG_PRISM; break; - case 10: et = NG_TET10; break; - default: - et = NG_TET; break; // for the compiler - } - return et; - } - - - - - // Set a global limit on the maximum mesh size allowed - DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h) - { - ((Mesh*)mesh) -> SetGlobalH (h); - } - - - - - // Set a local limit on the maximum mesh size allowed around the given point - DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h) - { - ((Mesh*)mesh) -> RestrictLocalH (Point3d (p[0], p[1], p[2]), h); - } - - - - - // Set a local limit on the maximum mesh size allowed within a given box region - DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h) - { - for (double x = pmin[0]; x < pmax[0]; x += h) - for (double y = pmin[1]; y < pmax[1]; y += h) - for (double z = pmin[2]; z < pmax[2]; z += h) - ((Mesh*)mesh) -> RestrictLocalH (Point3d (x, y, z), h); - } - - - - - // Generates volume mesh from an existing surface mesh - DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp) - { - Mesh * m = (Mesh*)mesh; - - // Philippose - 30/08/2009 - // Do not locally re-define "mparam" here... "mparam" is a global - // object - //MeshingParameters mparam; - mp->Transfer_Parameters(); - - m->CalcLocalH(mparam.grading); - - MeshVolume (mparam, *m); - RemoveIllegalElements (*m); - OptimizeVolume (mparam, *m); - - return NG_OK; - } - - - - - /* ------------------ 2D Meshing Functions ------------------------- */ - DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x) - { - Mesh * m = (Mesh*)mesh; - - m->AddPoint (Point3d (x[0], x[1], 0)); - } - - - - - DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2) - { - Mesh * m = (Mesh*)mesh; - - Segment seg; - seg[0] = pi1; - seg[1] = pi2; - m->AddSegment (seg); - } - - - - - DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh) - { - Mesh * m = (Mesh*)mesh; - return m->GetNP(); - } - - - - - DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh) - { - Mesh * m = (Mesh*)mesh; - return m->GetNSE(); - } - - - - - DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh) - { - Mesh * m = (Mesh*)mesh; - return m->GetNSeg(); - } - - - - - DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x) - { - Mesh * m = (Mesh*)mesh; - - Point<3> & p = m->Point(num); - x[0] = p(0); - x[1] = p(1); - } - - - - - DLL_HEADER Ng_Surface_Element_Type - Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum) - { - const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num); - for (int i = 1; i <= el.GetNP(); i++) - pi[i-1] = el.PNum(i); - - Ng_Surface_Element_Type et; - switch (el.GetNP()) - { - case 3: et = NG_TRIG; break; - case 4: et = NG_QUAD; break; - case 6: - switch (el.GetNV()) - { - case 3: et = NG_TRIG6; break; - case 4: et = NG_QUAD6; break; - default: - et = NG_TRIG6; break; - } - break; - case 8: et = NG_QUAD8; break; - default: - et = NG_TRIG; break; // for the compiler - } - - if (matnum) - *matnum = el.GetIndex(); - - return et; - } - - - - - DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum) - { - const Segment & seg = ((Mesh*)mesh)->LineSegment(num); - pi[0] = seg[0]; - pi[1] = seg[1]; - - if (matnum) - *matnum = seg.edgenr; - } - - - - - DLL_HEADER Ng_Geometry_2D * Ng_LoadGeometry_2D (const char * filename) - { - SplineGeometry2d * geom = new SplineGeometry2d(); - geom -> Load (filename); - return (Ng_Geometry_2D *)geom; - } - - - - - DLL_HEADER Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom, - Ng_Mesh ** mesh, - Ng_Meshing_Parameters * mp) - { - // use global variable mparam - // MeshingParameters mparam; - mp->Transfer_Parameters(); - - Mesh * m; - MeshFromSpline2D (*(SplineGeometry2d*)geom, m, mparam); - - cout << m->GetNSE() << " elements, " << m->GetNP() << " points" << endl; - - *mesh = (Ng_Mesh*)m; - return NG_OK; - } - - - - - DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom, - Ng_Mesh * mesh, - int levels) - { - Refinement2d ref(*(SplineGeometry2d*)geom); - HPRefinement (*(Mesh*)mesh, &ref, levels); - } - - - - - DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom, - Ng_Mesh * mesh, - int levels, double parameter) - { - Refinement2d ref(*(SplineGeometry2d*)geom); - HPRefinement (*(Mesh*)mesh, &ref, levels, parameter); - } - - - - - Array readtrias; //only before initstlgeometry - Array > readedges; //only before init stlgeometry - - // loads geometry from STL file - DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary) - { - int i; - STLGeometry geom; - STLGeometry* geo; - ifstream ist(filename); - - if (binary) - { - geo = geom.LoadBinary(ist); - } - else - { - geo = geom.Load(ist); - } - - readtrias.SetSize(0); - readedges.SetSize(0); - - Point3d p; - Vec3d normal; - double p1[3]; - double p2[3]; - double p3[3]; - double n[3]; - - Ng_STL_Geometry * geo2 = Ng_STL_NewGeometry(); - - for (i = 1; i <= geo->GetNT(); i++) - { - const STLTriangle& t = geo->GetTriangle(i); - p = geo->GetPoint(t.PNum(1)); - p1[0] = p.X(); p1[1] = p.Y(); p1[2] = p.Z(); - p = geo->GetPoint(t.PNum(2)); - p2[0] = p.X(); p2[1] = p.Y(); p2[2] = p.Z(); - p = geo->GetPoint(t.PNum(3)); - p3[0] = p.X(); p3[1] = p.Y(); p3[2] = p.Z(); - normal = t.Normal(); - n[0] = normal.X(); n[1] = normal.Y(); n[2] = normal.Z(); - - Ng_STL_AddTriangle(geo2, p1, p2, p3, n); - } - - return geo2; - } - - - - - // generate new STL Geometry - DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry () - { - return (Ng_STL_Geometry*)(void*)new STLGeometry; - } - - - - - // after adding triangles (and edges) initialize - DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom) - { - STLGeometry* geo = (STLGeometry*)geom; - geo->InitSTLGeometry(readtrias); - readtrias.SetSize(0); - - if (readedges.Size() != 0) - { - /* - for (int i = 1; i <= readedges.Size(); i+=2) - { - cout << "e(" << readedges.Get(i) << "," << readedges.Get(i+1) << ")" << endl; - } - */ - geo->AddEdges(readedges); - } - - if (geo->GetStatus() == STLTopology::STL_GOOD || geo->GetStatus() == STLTopology::STL_WARNING) return NG_OK; - return NG_SURFACE_INPUT_ERROR; - } - - - - - // automatically generates edges: - DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom, - Ng_Mesh* mesh, - Ng_Meshing_Parameters * mp) - { - STLGeometry* stlgeometry = (STLGeometry*)geom; - Mesh* me = (Mesh*)mesh; - - // Philippose - 27/07/2009 - // Do not locally re-define "mparam" here... "mparam" is a global - // object - //MeshingParameters mparam; - mp->Transfer_Parameters(); - - me -> SetGlobalH (mparam.maxh); - me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10), - stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10), - 0.3); - - me -> LoadLocalMeshSize (mp->meshsize_filename); - /* - if (mp->meshsize_filename) - { - ifstream infile (mp->meshsize_filename); - if (!infile.good()) return NG_FILE_NOT_FOUND; - me -> LoadLocalMeshSize (infile); - } - */ - - STLMeshing (*stlgeometry, *me); - - stlgeometry->edgesfound = 1; - stlgeometry->surfacemeshed = 0; - stlgeometry->surfaceoptimized = 0; - stlgeometry->volumemeshed = 0; - - return NG_OK; - } - - - - - // generates mesh, empty mesh be already created. - DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom, - Ng_Mesh* mesh, - Ng_Meshing_Parameters * mp) - { - STLGeometry* stlgeometry = (STLGeometry*)geom; - Mesh* me = (Mesh*)mesh; - - // Philippose - 27/07/2009 - // Do not locally re-define "mparam" here... "mparam" is a global - // object - //MeshingParameters mparam; - mp->Transfer_Parameters(); - - - /* - me -> SetGlobalH (mparam.maxh); - me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10), - stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10), - 0.3); - */ - /* - STLMeshing (*stlgeometry, *me); - - stlgeometry->edgesfound = 1; - stlgeometry->surfacemeshed = 0; - stlgeometry->surfaceoptimized = 0; - stlgeometry->volumemeshed = 0; - */ - int retval = STLSurfaceMeshing (*stlgeometry, *me); - if (retval == MESHING3_OK) - { - (*mycout) << "Success !!!!" << endl; - stlgeometry->surfacemeshed = 1; - stlgeometry->surfaceoptimized = 0; - stlgeometry->volumemeshed = 0; - } - else if (retval == MESHING3_OUTERSTEPSEXCEEDED) - { - (*mycout) << "ERROR: Give up because of too many trials. Meshing aborted!" << endl; - } - else if (retval == MESHING3_TERMINATE) - { - (*mycout) << "Meshing Stopped!" << endl; - } - else - { - (*mycout) << "ERROR: Surface meshing not successful. Meshing aborted!" << endl; - } - - - STLSurfaceOptimization (*stlgeometry, *me, mparam); - - return NG_OK; - } - - - - - // fills STL Geometry - // positive orientation - // normal vector may be null-pointer - DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, - double * p1, double * p2, double * p3, - double * nv) - { - Point<3> apts[3]; - apts[0] = Point<3>(p1[0],p1[1],p1[2]); - apts[1] = Point<3>(p2[0],p2[1],p2[2]); - apts[2] = Point<3>(p3[0],p3[1],p3[2]); - - Vec<3> n; - if (!nv) - n = Cross (apts[0]-apts[1], apts[0]-apts[2]); - else - n = Vec<3>(nv[0],nv[1],nv[2]); - - readtrias.Append(STLReadTriangle(apts,n)); - } - - // add (optional) edges: - DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom, - double * p1, double * p2) - { - readedges.Append(Point3d(p1[0],p1[1],p1[2])); - readedges.Append(Point3d(p2[0],p2[1],p2[2])); - } - - - - -#ifdef OCCGEOMETRY - // --------------------- OCC Geometry / Meshing Utility Functions ------------------- - // Create new OCC Geometry Object - DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry () - { - return (Ng_OCC_Geometry*)(void*)new OCCGeometry; - } - - - - - // Delete the OCC Geometry Object - DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry(Ng_OCC_Geometry * geom) - { - if (geom != NULL) - { - delete (OCCGeometry*)geom; - geom = NULL; - return NG_OK; - } - - return NG_ERROR; - } - - - - - // Loads geometry from STEP File - DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename) - { - // Call the STEP File Load function. Note.. the geometry class - // is created and instantiated within the load function - OCCGeometry * occgeo = LoadOCC_STEP(filename); - - return ((Ng_OCC_Geometry *)occgeo); - } - - - - - // Loads geometry from IGES File - DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename) - { - // Call the IGES File Load function. Note.. the geometry class - // is created and instantiated within the load function - OCCGeometry * occgeo = LoadOCC_IGES(filename); - - return ((Ng_OCC_Geometry *)occgeo); - } - - - - - // Loads geometry from BREP File - DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename) - { - // Call the BREP File Load function. Note.. the geometry class - // is created and instantiated within the load function - OCCGeometry * occgeo = LoadOCC_BREP(filename); - - return ((Ng_OCC_Geometry *)occgeo); - } - - - - - // Locally limit the size of the mesh to be generated at various points - // based on the topology of the geometry - DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh, - Ng_Meshing_Parameters * mp) - { - OCCGeometry * occgeom = (OCCGeometry*)geom; - Mesh * me = (Mesh*)mesh; - - me->geomtype = Mesh::GEOM_OCC; - - mp->Transfer_Parameters(); - - occparam.resthcloseedgeenable = mp->closeedgeenable; - occparam.resthcloseedgefac = mp->closeedgefact; - - // Delete the mesh structures in order to start with a clean - // slate - me->DeleteMesh(); - - OCCSetLocalMeshSize(*occgeom, *me); - - return(NG_OK); - } - - - - - // Mesh the edges and add Face descriptors to prepare for surface meshing - DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh, - Ng_Meshing_Parameters * mp) - { - OCCGeometry * occgeom = (OCCGeometry*)geom; - Mesh * me = (Mesh*)mesh; - - mp->Transfer_Parameters(); - - OCCFindEdges(*occgeom, *me); - - if((me->GetNP()) && (me->GetNFD())) - { - return NG_OK; - } - else - { - return NG_ERROR; - } - } - - - - - // Mesh the edges and add Face descriptors to prepare for surface meshing - DLL_HEADER Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh, - Ng_Meshing_Parameters * mp) - { - int numpoints = 0; - - OCCGeometry * occgeom = (OCCGeometry*)geom; - Mesh * me = (Mesh*)mesh; - - // Set the internal meshing parameters structure from the nglib meshing - // parameters structure - mp->Transfer_Parameters(); - - - // Only go into surface meshing if the face descriptors have already been added - if(!me->GetNFD()) - return NG_ERROR; - - numpoints = me->GetNP(); - - // Initially set up only for surface meshing without any optimisation - int perfstepsend = MESHCONST_MESHSURFACE; - - // Check and if required, enable surface mesh optimisation step - if(mp->optsurfmeshenable) - { - perfstepsend = MESHCONST_OPTSURFACE; - } - - OCCMeshSurface(*occgeom, *me, perfstepsend); - - me->CalcSurfacesOfNode(); - - if(me->GetNP() <= numpoints) - return NG_ERROR; - - if(me->GetNSE() <= 0) - return NG_ERROR; - - return NG_OK; - } - - - - - // Extract the face map from the OCC geometry - // The face map basically gives an index to each face in the geometry, - // which can be used to access a specific face - DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, - Ng_OCC_TopTools_IndexedMapOfShape * FMap) - { - OCCGeometry* occgeom = (OCCGeometry*)geom; - TopTools_IndexedMapOfShape *occfmap = (TopTools_IndexedMapOfShape *)FMap; - - // Copy the face map from the geometry to the given variable - occfmap->Assign(occgeom->fmap); - - if(occfmap->Extent()) - { - return NG_OK; - } - else - { - return NG_ERROR; - } - } - - // ------------------ End - OCC Geometry / Meshing Utility Functions ---------------- -#endif - - - - - // ------------------ Begin - Meshing Parameters related functions ------------------ - // Constructor for the local nglib meshing parameters class - DLL_HEADER Ng_Meshing_Parameters :: Ng_Meshing_Parameters() - { - uselocalh = 1; - - maxh = 1000; - minh = 0.0; - - fineness = 0.5; - grading = 0.3; - - elementsperedge = 2.0; - elementspercurve = 2.0; - - closeedgeenable = 0; - closeedgefact = 2.0; - - second_order = 0; - quad_dominated = 0; - - meshsize_filename = 0; - - optsurfmeshenable = 1; - optvolmeshenable = 1; - - optsteps_2d = 3; - optsteps_3d = 3; - - invert_tets = 0; - invert_trigs = 0; - - check_overlap = 1; - check_overlapping_boundary = 1; - } - - - - - // Reset the local meshing parameters to the default values - DLL_HEADER void Ng_Meshing_Parameters :: Reset_Parameters() - { - uselocalh = 1; - - maxh = 1000; - minh = 0; - - fineness = 0.5; - grading = 0.3; - - elementsperedge = 2.0; - elementspercurve = 2.0; - - closeedgeenable = 0; - closeedgefact = 2.0; - - second_order = 0; - quad_dominated = 0; - - meshsize_filename = 0; - - optsurfmeshenable = 1; - optvolmeshenable = 1; - - optsteps_2d = 3; - optsteps_3d = 3; - - invert_tets = 0; - invert_trigs = 0; - - check_overlap = 1; - check_overlapping_boundary = 1; - } - - - - - // - DLL_HEADER void Ng_Meshing_Parameters :: Transfer_Parameters() - { - mparam.uselocalh = uselocalh; - - mparam.maxh = maxh; - mparam.minh = minh; - - mparam.grading = grading; - mparam.curvaturesafety = elementspercurve; - mparam.segmentsperedge = elementsperedge; - - mparam.secondorder = second_order; - mparam.quad = quad_dominated; - - mparam.meshsizefilename = meshsize_filename; - - mparam.optsteps2d = optsteps_2d; - mparam.optsteps3d = optsteps_3d; - - mparam.inverttets = invert_tets; - mparam.inverttrigs = invert_trigs; - - mparam.checkoverlap = check_overlap; - mparam.checkoverlappingboundary = check_overlapping_boundary; - } - // ------------------ End - Meshing Parameters related functions -------------------- - - - - - // ------------------ Begin - Second Order Mesh generation functions ---------------- - DLL_HEADER void Ng_Generate_SecondOrder(Ng_Mesh * mesh) - { - Refinement ref; - ref.MakeSecondOrder(*(Mesh*) mesh); - } - - - - - DLL_HEADER void Ng_2D_Generate_SecondOrder(Ng_Geometry_2D * geom, - Ng_Mesh * mesh) - { - ( (SplineGeometry2d*)geom ) -> GetRefinement().MakeSecondOrder( * (Mesh*) mesh ); - } - - - - - DLL_HEADER void Ng_STL_Generate_SecondOrder(Ng_STL_Geometry * geom, - Ng_Mesh * mesh) - { - ((STLGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh); - } - - - - - DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom, - Ng_Mesh * mesh) - { - ((CSGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh); - } - - - - -#ifdef OCCGEOMETRY - DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh) - { - ((OCCGeometry*)geom )->GetRefinement().MakeSecondOrder(*(Mesh*) mesh); - } -#endif - // ------------------ End - Second Order Mesh generation functions ------------------ - - - - - // ------------------ Begin - Uniform Mesh Refinement functions --------------------- - DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh) - { - Refinement ref; - ref.Refine ( * (Mesh*) mesh ); - } - - - - - DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom, - Ng_Mesh * mesh) - { - ( (SplineGeometry2d*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh ); - } - - - - - DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom, - Ng_Mesh * mesh) - { - ( (STLGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh ); - } - - - - - DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom, - Ng_Mesh * mesh) - { - ( (CSGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh ); - } - - - - -#ifdef OCCGEOMETRY - DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh) - { - ( (OCCGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh ); - } -#endif - // ------------------ End - Uniform Mesh Refinement functions ----------------------- -} // End of namespace nglib - - - - -// compatibility functions: -namespace netgen -{ - char geomfilename[255]; - - DLL_HEADER void MyError (const char * ch) - { - cerr << ch; - } - - - - - //Destination for messages, errors, ... - DLL_HEADER void Ng_PrintDest(const char * s) - { -#ifdef PARALLEL - int id = 0; - MPI_Comm_rank(MPI_COMM_WORLD, &id); - if (id != 0) return; -#endif - (*mycout) << s << flush; - } - - - - - DLL_HEADER double GetTime () - { - return 0; - } - - - - - void ResetTime () - { - ; - } - - - - - void MyBeep (int i) - { - ; - } - - - - - void Render() - { - ; - } -} // End of namespace netgen - - - - -void Ng_Redraw () { ; } -void Ng_ClearSolutionData () { ; } -void Ng_SetSolutionData (Ng_SolutionData * soldata) -{ - delete soldata->solclass; -} -void Ng_InitSolutionData (Ng_SolutionData * soldata) { ; } - - +/**************************************************************************/ +/* File: nglib.cpp */ +/* Author: Joachim Schoeberl */ +/* Date: 7. May. 2000 */ +/**************************************************************************/ + +/* + + Interface to the netgen meshing kernel + +*/ +#include +#include + +#include +#include +#include +#include +#include +#include <../visualization/soldata.hpp> + +#ifdef OCCGEOMETRY +#include +#endif + +#include + + +namespace netgen { + extern void MeshFromSpline2D (SplineGeometry2d & geometry, + Mesh *& mesh, + MeshingParameters & mp); +} + + + +#ifdef PARALLEL +#include + +namespace netgen +{ + // int id = 0, ntasks = 1; + MPI_Comm mesh_comm; +} +#endif + + +namespace netgen +{ + int id = 0, ntasks = 1; +} + + + +/* +// should not be needed (occ currently requires it) +namespace netgen { +#include "../libsrc/visualization/vispar.hpp" + VisualizationParameters vispar; + VisualizationParameters :: VisualizationParameters() { ; } +} +*/ + + +namespace nglib { +#include "nglib.h" +} + +using namespace netgen; + +// constants and types: + +namespace nglib +{ + // initialize, deconstruct Netgen library: + DLL_HEADER void Ng_Init () + { + mycout = &cout; + myerr = &cerr; + // netgen::testout->SetOutStream (new ofstream ("test.out")); + testout = new ofstream ("test.out"); + } + + + + + // Clean-up functions before ending usage of nglib + DLL_HEADER void Ng_Exit () + { + ; + } + + + + + // Create a new netgen mesh object + DLL_HEADER Ng_Mesh * Ng_NewMesh () + { + Mesh * mesh = new Mesh; + mesh->AddFaceDescriptor (FaceDescriptor (1, 1, 0, 1)); + return (Ng_Mesh*)(void*)mesh; + } + + + + + // Delete an existing netgen mesh object + DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh) + { + if(mesh != NULL) + { + // Delete the Mesh structures + ((Mesh*)mesh)->DeleteMesh(); + + // Now delete the Mesh class itself + delete (Mesh*)mesh; + + // Set the Ng_Mesh pointer to NULL + mesh = NULL; + } + } + + + + + // Save a netgen mesh in the native VOL format + DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename) + { + ((Mesh*)mesh)->Save(filename); + } + + + + + // Load a netgen native VOL mesh from a given file + DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename) + { + Mesh * mesh = new Mesh; + mesh->Load(filename); + return ( (Ng_Mesh*)mesh ); + } + + + + + // Merge another mesh file into the currently loaded one + DLL_HEADER Ng_Result Ng_MergeMesh( Ng_Mesh* mesh, const char* filename) + { + Ng_Result status = NG_OK; + + ifstream infile(filename); + Mesh * m = (Mesh*)mesh; + + if(!infile.good()) + { + status = NG_FILE_NOT_FOUND; + } + + if(!m) + { + status = NG_ERROR; + } + + if(status == NG_OK) + { + const int num_pts = m->GetNP(); + const int face_offset = m->GetNFD(); + + m->Merge(infile, face_offset); + + if(m->GetNP() > num_pts) + { + status = NG_OK; + } + else + { + status = NG_ERROR; + } + } + + return status; + } + + + + + // Merge another mesh file into the currently loaded one + DLL_HEADER Ng_Result Ng_MergeMesh( Ng_Mesh* mesh1, Ng_Mesh* mesh2) + { + return NG_ERROR; + } + + + + + // Manually add a point to an existing mesh object + DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x) + { + Mesh * m = (Mesh*)mesh; + m->AddPoint (Point3d (x[0], x[1], x[2])); + } + + + + + // Manually add a surface element of a given type to an existing mesh object + DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et, + int * pi) + { + Mesh * m = (Mesh*)mesh; + Element2d el (3); + el.SetIndex (1); + el.PNum(1) = pi[0]; + el.PNum(2) = pi[1]; + el.PNum(3) = pi[2]; + m->AddSurfaceElement (el); + } + + + + + // Manually add a volume element of a given type to an existing mesh object + DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et, + int * pi) + { + Mesh * m = (Mesh*)mesh; + Element el (4); + el.SetIndex (1); + el.PNum(1) = pi[0]; + el.PNum(2) = pi[1]; + el.PNum(3) = pi[2]; + el.PNum(4) = pi[3]; + m->AddVolumeElement (el); + } + + + + + // Obtain the number of points in the mesh + DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh) + { + return ((Mesh*)mesh) -> GetNP(); + } + + + + + // Obtain the number of surface elements in the mesh + DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh) + { + return ((Mesh*)mesh) -> GetNSE(); + } + + + + + // Obtain the number of volume elements in the mesh + DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh) + { + return ((Mesh*)mesh) -> GetNE(); + } + + + + + // Return point coordinates of a given point index in the mesh + DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x) + { + const Point3d & p = ((Mesh*)mesh)->Point(num); + x[0] = p.X(); + x[1] = p.Y(); + x[2] = p.Z(); + } + + + + + // Return the surface element at a given index "pi" + DLL_HEADER Ng_Surface_Element_Type + Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi) + { + const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num); + for (int i = 1; i <= el.GetNP(); i++) + pi[i-1] = el.PNum(i); + Ng_Surface_Element_Type et; + switch (el.GetNP()) + { + case 3: et = NG_TRIG; break; + case 4: et = NG_QUAD; break; + case 6: + switch (el.GetNV()) + { + case 3: et = NG_TRIG6; break; + case 4: et = NG_QUAD6; break; + default: + et = NG_TRIG6; break; + } + break; + case 8: et = NG_QUAD8; break; + default: + et = NG_TRIG; break; // for the compiler + } + return et; + } + + + + + // Return the volume element at a given index "pi" + DLL_HEADER Ng_Volume_Element_Type + Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi) + { + const Element & el = ((Mesh*)mesh)->VolumeElement(num); + for (int i = 1; i <= el.GetNP(); i++) + pi[i-1] = el.PNum(i); + Ng_Volume_Element_Type et; + switch (el.GetNP()) + { + case 4: et = NG_TET; break; + case 5: et = NG_PYRAMID; break; + case 6: et = NG_PRISM; break; + case 10: et = NG_TET10; break; + default: + et = NG_TET; break; // for the compiler + } + return et; + } + + + + + // Set a global limit on the maximum mesh size allowed + DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h) + { + ((Mesh*)mesh) -> SetGlobalH (h); + } + + + + + // Set a local limit on the maximum mesh size allowed around the given point + DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h) + { + ((Mesh*)mesh) -> RestrictLocalH (Point3d (p[0], p[1], p[2]), h); + } + + + + + // Set a local limit on the maximum mesh size allowed within a given box region + DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h) + { + for (double x = pmin[0]; x < pmax[0]; x += h) + for (double y = pmin[1]; y < pmax[1]; y += h) + for (double z = pmin[2]; z < pmax[2]; z += h) + ((Mesh*)mesh) -> RestrictLocalH (Point3d (x, y, z), h); + } + + + + + // Generates volume mesh from an existing surface mesh + DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp) + { + Mesh * m = (Mesh*)mesh; + + // Philippose - 30/08/2009 + // Do not locally re-define "mparam" here... "mparam" is a global + // object + //MeshingParameters mparam; + mp->Transfer_Parameters(); + + m->CalcLocalH(mparam.grading); + + MeshVolume (mparam, *m); + RemoveIllegalElements (*m); + OptimizeVolume (mparam, *m); + + return NG_OK; + } + + + + + /* ------------------ 2D Meshing Functions ------------------------- */ + DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x) + { + Mesh * m = (Mesh*)mesh; + + m->AddPoint (Point3d (x[0], x[1], 0)); + } + + + + + DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2) + { + Mesh * m = (Mesh*)mesh; + + Segment seg; + seg[0] = pi1; + seg[1] = pi2; + m->AddSegment (seg); + } + + + + + DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh) + { + Mesh * m = (Mesh*)mesh; + return m->GetNP(); + } + + + + + DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh) + { + Mesh * m = (Mesh*)mesh; + return m->GetNSE(); + } + + + + + DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh) + { + Mesh * m = (Mesh*)mesh; + return m->GetNSeg(); + } + + + + + DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x) + { + Mesh * m = (Mesh*)mesh; + + Point<3> & p = m->Point(num); + x[0] = p(0); + x[1] = p(1); + } + + + + + DLL_HEADER Ng_Surface_Element_Type + Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum) + { + const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num); + for (int i = 1; i <= el.GetNP(); i++) + pi[i-1] = el.PNum(i); + + Ng_Surface_Element_Type et; + switch (el.GetNP()) + { + case 3: et = NG_TRIG; break; + case 4: et = NG_QUAD; break; + case 6: + switch (el.GetNV()) + { + case 3: et = NG_TRIG6; break; + case 4: et = NG_QUAD6; break; + default: + et = NG_TRIG6; break; + } + break; + case 8: et = NG_QUAD8; break; + default: + et = NG_TRIG; break; // for the compiler + } + + if (matnum) + *matnum = el.GetIndex(); + + return et; + } + + + + + DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum) + { + const Segment & seg = ((Mesh*)mesh)->LineSegment(num); + pi[0] = seg[0]; + pi[1] = seg[1]; + + if (matnum) + *matnum = seg.edgenr; + } + + + + + DLL_HEADER Ng_Geometry_2D * Ng_LoadGeometry_2D (const char * filename) + { + SplineGeometry2d * geom = new SplineGeometry2d(); + geom -> Load (filename); + return (Ng_Geometry_2D *)geom; + } + + + + + DLL_HEADER Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom, + Ng_Mesh ** mesh, + Ng_Meshing_Parameters * mp) + { + // use global variable mparam + // MeshingParameters mparam; + mp->Transfer_Parameters(); + + Mesh * m; + MeshFromSpline2D (*(SplineGeometry2d*)geom, m, mparam); + + cout << m->GetNSE() << " elements, " << m->GetNP() << " points" << endl; + + *mesh = (Ng_Mesh*)m; + return NG_OK; + } + + + + + DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom, + Ng_Mesh * mesh, + int levels) + { + Refinement2d ref(*(SplineGeometry2d*)geom); + HPRefinement (*(Mesh*)mesh, &ref, levels); + } + + + + + DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom, + Ng_Mesh * mesh, + int levels, double parameter) + { + Refinement2d ref(*(SplineGeometry2d*)geom); + HPRefinement (*(Mesh*)mesh, &ref, levels, parameter); + } + + + + + Array readtrias; //only before initstlgeometry + Array > readedges; //only before init stlgeometry + + // loads geometry from STL file + DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary) + { + int i; + STLGeometry geom; + STLGeometry* geo; + ifstream ist(filename); + + if (binary) + { + geo = geom.LoadBinary(ist); + } + else + { + geo = geom.Load(ist); + } + + readtrias.SetSize(0); + readedges.SetSize(0); + + Point3d p; + Vec3d normal; + double p1[3]; + double p2[3]; + double p3[3]; + double n[3]; + + Ng_STL_Geometry * geo2 = Ng_STL_NewGeometry(); + + for (i = 1; i <= geo->GetNT(); i++) + { + const STLTriangle& t = geo->GetTriangle(i); + p = geo->GetPoint(t.PNum(1)); + p1[0] = p.X(); p1[1] = p.Y(); p1[2] = p.Z(); + p = geo->GetPoint(t.PNum(2)); + p2[0] = p.X(); p2[1] = p.Y(); p2[2] = p.Z(); + p = geo->GetPoint(t.PNum(3)); + p3[0] = p.X(); p3[1] = p.Y(); p3[2] = p.Z(); + normal = t.Normal(); + n[0] = normal.X(); n[1] = normal.Y(); n[2] = normal.Z(); + + Ng_STL_AddTriangle(geo2, p1, p2, p3, n); + } + + return geo2; + } + + + + + // generate new STL Geometry + DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry () + { + return (Ng_STL_Geometry*)(void*)new STLGeometry; + } + + + + + // after adding triangles (and edges) initialize + DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom) + { + STLGeometry* geo = (STLGeometry*)geom; + geo->InitSTLGeometry(readtrias); + readtrias.SetSize(0); + + if (readedges.Size() != 0) + { + /* + for (int i = 1; i <= readedges.Size(); i+=2) + { + cout << "e(" << readedges.Get(i) << "," << readedges.Get(i+1) << ")" << endl; + } + */ + geo->AddEdges(readedges); + } + + if (geo->GetStatus() == STLTopology::STL_GOOD || geo->GetStatus() == STLTopology::STL_WARNING) return NG_OK; + return NG_SURFACE_INPUT_ERROR; + } + + + + + // automatically generates edges: + DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom, + Ng_Mesh* mesh, + Ng_Meshing_Parameters * mp) + { + STLGeometry* stlgeometry = (STLGeometry*)geom; + Mesh* me = (Mesh*)mesh; + + // Philippose - 27/07/2009 + // Do not locally re-define "mparam" here... "mparam" is a global + // object + //MeshingParameters mparam; + mp->Transfer_Parameters(); + + me -> SetGlobalH (mparam.maxh); + me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10), + stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10), + 0.3); + + me -> LoadLocalMeshSize (mp->meshsize_filename); + /* + if (mp->meshsize_filename) + { + ifstream infile (mp->meshsize_filename); + if (!infile.good()) return NG_FILE_NOT_FOUND; + me -> LoadLocalMeshSize (infile); + } + */ + + STLMeshing (*stlgeometry, *me); + + stlgeometry->edgesfound = 1; + stlgeometry->surfacemeshed = 0; + stlgeometry->surfaceoptimized = 0; + stlgeometry->volumemeshed = 0; + + return NG_OK; + } + + + + + // generates mesh, empty mesh be already created. + DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom, + Ng_Mesh* mesh, + Ng_Meshing_Parameters * mp) + { + STLGeometry* stlgeometry = (STLGeometry*)geom; + Mesh* me = (Mesh*)mesh; + + // Philippose - 27/07/2009 + // Do not locally re-define "mparam" here... "mparam" is a global + // object + //MeshingParameters mparam; + mp->Transfer_Parameters(); + + + /* + me -> SetGlobalH (mparam.maxh); + me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10), + stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10), + 0.3); + */ + /* + STLMeshing (*stlgeometry, *me); + + stlgeometry->edgesfound = 1; + stlgeometry->surfacemeshed = 0; + stlgeometry->surfaceoptimized = 0; + stlgeometry->volumemeshed = 0; + */ + int retval = STLSurfaceMeshing (*stlgeometry, *me); + if (retval == MESHING3_OK) + { + (*mycout) << "Success !!!!" << endl; + stlgeometry->surfacemeshed = 1; + stlgeometry->surfaceoptimized = 0; + stlgeometry->volumemeshed = 0; + } + else if (retval == MESHING3_OUTERSTEPSEXCEEDED) + { + (*mycout) << "ERROR: Give up because of too many trials. Meshing aborted!" << endl; + } + else if (retval == MESHING3_TERMINATE) + { + (*mycout) << "Meshing Stopped!" << endl; + } + else + { + (*mycout) << "ERROR: Surface meshing not successful. Meshing aborted!" << endl; + } + + + STLSurfaceOptimization (*stlgeometry, *me, mparam); + + return NG_OK; + } + + + + + // fills STL Geometry + // positive orientation + // normal vector may be null-pointer + DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, + double * p1, double * p2, double * p3, + double * nv) + { + Point<3> apts[3]; + apts[0] = Point<3>(p1[0],p1[1],p1[2]); + apts[1] = Point<3>(p2[0],p2[1],p2[2]); + apts[2] = Point<3>(p3[0],p3[1],p3[2]); + + Vec<3> n; + if (!nv) + n = Cross (apts[0]-apts[1], apts[0]-apts[2]); + else + n = Vec<3>(nv[0],nv[1],nv[2]); + + readtrias.Append(STLReadTriangle(apts,n)); + } + + // add (optional) edges: + DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom, + double * p1, double * p2) + { + readedges.Append(Point3d(p1[0],p1[1],p1[2])); + readedges.Append(Point3d(p2[0],p2[1],p2[2])); + } + + + + +#ifdef OCCGEOMETRY + // --------------------- OCC Geometry / Meshing Utility Functions ------------------- + // Create new OCC Geometry Object + DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry () + { + return (Ng_OCC_Geometry*)(void*)new OCCGeometry; + } + + + + + // Delete the OCC Geometry Object + DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry(Ng_OCC_Geometry * geom) + { + if (geom != NULL) + { + delete (OCCGeometry*)geom; + geom = NULL; + return NG_OK; + } + + return NG_ERROR; + } + + + + + // Loads geometry from STEP File + DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename) + { + // Call the STEP File Load function. Note.. the geometry class + // is created and instantiated within the load function + OCCGeometry * occgeo = LoadOCC_STEP(filename); + + return ((Ng_OCC_Geometry *)occgeo); + } + + + + + // Loads geometry from IGES File + DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename) + { + // Call the IGES File Load function. Note.. the geometry class + // is created and instantiated within the load function + OCCGeometry * occgeo = LoadOCC_IGES(filename); + + return ((Ng_OCC_Geometry *)occgeo); + } + + + + + // Loads geometry from BREP File + DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename) + { + // Call the BREP File Load function. Note.. the geometry class + // is created and instantiated within the load function + OCCGeometry * occgeo = LoadOCC_BREP(filename); + + return ((Ng_OCC_Geometry *)occgeo); + } + + + + + // Locally limit the size of the mesh to be generated at various points + // based on the topology of the geometry + DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp) + { + OCCGeometry * occgeom = (OCCGeometry*)geom; + Mesh * me = (Mesh*)mesh; + + me->geomtype = Mesh::GEOM_OCC; + + mp->Transfer_Parameters(); + + occparam.resthcloseedgeenable = mp->closeedgeenable; + occparam.resthcloseedgefac = mp->closeedgefact; + + // Delete the mesh structures in order to start with a clean + // slate + me->DeleteMesh(); + + OCCSetLocalMeshSize(*occgeom, *me); + + return(NG_OK); + } + + + + + // Mesh the edges and add Face descriptors to prepare for surface meshing + DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp) + { + OCCGeometry * occgeom = (OCCGeometry*)geom; + Mesh * me = (Mesh*)mesh; + + mp->Transfer_Parameters(); + + OCCFindEdges(*occgeom, *me); + + if((me->GetNP()) && (me->GetNFD())) + { + return NG_OK; + } + else + { + return NG_ERROR; + } + } + + + + + // Mesh the edges and add Face descriptors to prepare for surface meshing + DLL_HEADER Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp) + { + int numpoints = 0; + + OCCGeometry * occgeom = (OCCGeometry*)geom; + Mesh * me = (Mesh*)mesh; + + // Set the internal meshing parameters structure from the nglib meshing + // parameters structure + mp->Transfer_Parameters(); + + + // Only go into surface meshing if the face descriptors have already been added + if(!me->GetNFD()) + return NG_ERROR; + + numpoints = me->GetNP(); + + // Initially set up only for surface meshing without any optimisation + int perfstepsend = MESHCONST_MESHSURFACE; + + // Check and if required, enable surface mesh optimisation step + if(mp->optsurfmeshenable) + { + perfstepsend = MESHCONST_OPTSURFACE; + } + + OCCMeshSurface(*occgeom, *me, perfstepsend); + + me->CalcSurfacesOfNode(); + + if(me->GetNP() <= numpoints) + return NG_ERROR; + + if(me->GetNSE() <= 0) + return NG_ERROR; + + return NG_OK; + } + + + + + // Extract the face map from the OCC geometry + // The face map basically gives an index to each face in the geometry, + // which can be used to access a specific face + DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, + Ng_OCC_TopTools_IndexedMapOfShape * FMap) + { + OCCGeometry* occgeom = (OCCGeometry*)geom; + TopTools_IndexedMapOfShape *occfmap = (TopTools_IndexedMapOfShape *)FMap; + + // Copy the face map from the geometry to the given variable + occfmap->Assign(occgeom->fmap); + + if(occfmap->Extent()) + { + return NG_OK; + } + else + { + return NG_ERROR; + } + } + + // ------------------ End - OCC Geometry / Meshing Utility Functions ---------------- +#endif + + + + + // ------------------ Begin - Meshing Parameters related functions ------------------ + // Constructor for the local nglib meshing parameters class + DLL_HEADER Ng_Meshing_Parameters :: Ng_Meshing_Parameters() + { + uselocalh = 1; + + maxh = 1000; + minh = 0.0; + + fineness = 0.5; + grading = 0.3; + + elementsperedge = 2.0; + elementspercurve = 2.0; + + closeedgeenable = 0; + closeedgefact = 2.0; + + minedgelenenable = 0; + minedgelen = 1e-4; + + second_order = 0; + quad_dominated = 0; + + meshsize_filename = 0; + + optsurfmeshenable = 1; + optvolmeshenable = 1; + + optsteps_2d = 3; + optsteps_3d = 3; + + invert_tets = 0; + invert_trigs = 0; + + check_overlap = 1; + check_overlapping_boundary = 1; + } + + + + + // Reset the local meshing parameters to the default values + DLL_HEADER void Ng_Meshing_Parameters :: Reset_Parameters() + { + uselocalh = 1; + + maxh = 1000; + minh = 0; + + fineness = 0.5; + grading = 0.3; + + elementsperedge = 2.0; + elementspercurve = 2.0; + + closeedgeenable = 0; + closeedgefact = 2.0; + + minedgelenenable = 0; + minedgelen = 1e-4; + + second_order = 0; + quad_dominated = 0; + + meshsize_filename = 0; + + optsurfmeshenable = 1; + optvolmeshenable = 1; + + optsteps_2d = 3; + optsteps_3d = 3; + + invert_tets = 0; + invert_trigs = 0; + + check_overlap = 1; + check_overlapping_boundary = 1; + } + + + + + // + DLL_HEADER void Ng_Meshing_Parameters :: Transfer_Parameters() + { + mparam.uselocalh = uselocalh; + + mparam.maxh = maxh; + mparam.minh = minh; + + mparam.grading = grading; + mparam.curvaturesafety = elementspercurve; + mparam.segmentsperedge = elementsperedge; + + mparam.secondorder = second_order; + mparam.quad = quad_dominated; + + mparam.meshsizefilename = meshsize_filename; + + mparam.optsteps2d = optsteps_2d; + mparam.optsteps3d = optsteps_3d; + + mparam.inverttets = invert_tets; + mparam.inverttrigs = invert_trigs; + + mparam.checkoverlap = check_overlap; + mparam.checkoverlappingboundary = check_overlapping_boundary; + } + // ------------------ End - Meshing Parameters related functions -------------------- + + + + + // ------------------ Begin - Second Order Mesh generation functions ---------------- + DLL_HEADER void Ng_Generate_SecondOrder(Ng_Mesh * mesh) + { + Refinement ref; + ref.MakeSecondOrder(*(Mesh*) mesh); + } + + + + + DLL_HEADER void Ng_2D_Generate_SecondOrder(Ng_Geometry_2D * geom, + Ng_Mesh * mesh) + { + ( (SplineGeometry2d*)geom ) -> GetRefinement().MakeSecondOrder( * (Mesh*) mesh ); + } + + + + + DLL_HEADER void Ng_STL_Generate_SecondOrder(Ng_STL_Geometry * geom, + Ng_Mesh * mesh) + { + ((STLGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh); + } + + + + + DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom, + Ng_Mesh * mesh) + { + ((CSGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh); + } + + + + +#ifdef OCCGEOMETRY + DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh) + { + ((OCCGeometry*)geom )->GetRefinement().MakeSecondOrder(*(Mesh*) mesh); + } +#endif + // ------------------ End - Second Order Mesh generation functions ------------------ + + + + + // ------------------ Begin - Uniform Mesh Refinement functions --------------------- + DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh) + { + Refinement ref; + ref.Refine ( * (Mesh*) mesh ); + } + + + + + DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom, + Ng_Mesh * mesh) + { + ( (SplineGeometry2d*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh ); + } + + + + + DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom, + Ng_Mesh * mesh) + { + ( (STLGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh ); + } + + + + + DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom, + Ng_Mesh * mesh) + { + ( (CSGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh ); + } + + + + +#ifdef OCCGEOMETRY + DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh) + { + ( (OCCGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh ); + } +#endif + // ------------------ End - Uniform Mesh Refinement functions ----------------------- +} // End of namespace nglib + + + + +// compatibility functions: +namespace netgen +{ + char geomfilename[255]; + + DLL_HEADER void MyError (const char * ch) + { + cerr << ch; + } + + + + + //Destination for messages, errors, ... + DLL_HEADER void Ng_PrintDest(const char * s) + { +#ifdef PARALLEL + int id = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &id); + if (id != 0) return; +#endif + (*mycout) << s << flush; + } + + + + + DLL_HEADER double GetTime () + { + return 0; + } + + + + + void ResetTime () + { + ; + } + + + + + void MyBeep (int i) + { + ; + } + + + + + void Render() + { + ; + } +} // End of namespace netgen + + + + +void Ng_Redraw () { ; } +void Ng_ClearSolutionData () { ; } +void Ng_SetSolutionData (Ng_SolutionData * soldata) +{ + delete soldata->solclass; +} +void Ng_InitSolutionData (Ng_SolutionData * soldata) { ; } + + diff --git a/nglib/nglib.h b/nglib/nglib.h index be9edb7b..8a78da07 100644 --- a/nglib/nglib.h +++ b/nglib/nglib.h @@ -1,744 +1,747 @@ -#ifndef NGLIB -#define NGLIB - -/**************************************************************************/ -/* File: nglib.h */ -/* Author: Joachim Schoeberl */ -/* Date: 7. May. 2000 */ -/**************************************************************************/ - -/*! - \file nglib.h - \brief Library interface to the netgen meshing kernel - \author Joachim Schoeberl - \date 7. May 2000 - - This header file provides access to the core functionality of the Netgen - Mesher via a library interface, without an interactive User Interface. - - The intention of providing these set of functions is to allow system - developers to integrate Netgen into top-level code, to act as the low - level mesh generation / optimisation kernel. -*/ - -// Philippose - 14.02.2009 -// Modifications for creating a DLL in Windows -#ifdef WIN32 - #ifdef NGLIB_EXPORTS || nglib_EXPORTS - #define DLL_HEADER __declspec(dllexport) - #else - #define DLL_HEADER __declspec(dllimport) - #endif -#else - #define DLL_HEADER -#endif - - - -// ** Constants used within Netgen ********************* -/// Maximum allowed number of nodes per volume element -#define NG_VOLUME_ELEMENT_MAXPOINTS 10 - -/// Maximum allowed number of nodes per surface element -#define NG_SURFACE_ELEMENT_MAXPOINTS 8 - - - -// *** Data-types for accessing Netgen functionality *** -/// Data type for NETGEN mesh -typedef void * Ng_Mesh; - -/// Data type for NETGEN CSG geometry -typedef void * Ng_CSG_Geometry; - -/// Data type for NETGEN 2D geometry -typedef void * Ng_Geometry_2D; - -/// Data type for NETGEN STL geometry -typedef void * Ng_STL_Geometry; - -#ifdef OCCGEOMETRY -/// Data type for NETGEN OpenCascade geometry -typedef void * Ng_OCC_Geometry; -typedef void * Ng_OCC_TopTools_IndexedMapOfShape; -#endif - - -// *** Special Enum types used within Netgen *********** -/// Currently implemented surface element types -enum Ng_Surface_Element_Type - { NG_TRIG = 1, NG_QUAD = 2, NG_TRIG6 = 3, NG_QUAD6 = 4, NG_QUAD8 = 5 }; - -/// Currently implemented volume element types -enum Ng_Volume_Element_Type - { NG_TET = 1, NG_PYRAMID = 2, NG_PRISM = 3, NG_TET10 = 4 }; - -/// Values returned by Netgen functions -enum Ng_Result - { - NG_ERROR = -1, - NG_OK = 0, - NG_SURFACE_INPUT_ERROR = 1, - NG_VOLUME_FAILURE = 2, - NG_STL_INPUT_ERROR = 3, - NG_SURFACE_FAILURE = 4, - NG_FILE_NOT_FOUND = 5 - }; - - - -// *** Classes required for use within Netgen ********** -/// Netgen Meshing Parameters class -class Ng_Meshing_Parameters -{ -public: - int uselocalh; //!< Switch to enable / disable usage of local mesh size modifiers - - double maxh; //!< Maximum global mesh size allowed - double minh; //!< Minimum global mesh size allowed - - double fineness; //!< Mesh density: 0...1 (0 => coarse; 1 => fine) - double grading; //!< Mesh grading: 0...1 (0 => uniform mesh; 1 => aggressive local grading) - - double elementsperedge; //!< Number of elements to generate per edge of the geometry - double elementspercurve; //!< Elements to generate per curvature radius - - int closeedgeenable; //!< Enable / Disable mesh refinement at close edges - double closeedgefact; //!< Factor to use for refinement at close edges (larger => finer) - - int second_order; //!< Generate second-order surface and volume elements - int quad_dominated; //!< Creates a Quad-dominated mesh - - char * meshsize_filename; //!< Optional external mesh size file - - int optsurfmeshenable; //!< Enable / Disable automatic surface mesh optimization - int optvolmeshenable; //!< Enable / Disable automatic volume mesh optimization - - int optsteps_3d; //!< Number of optimize steps to use for 3-D mesh optimization - int optsteps_2d; //!< Number of optimize steps to use for 2-D mesh optimization - - // Philippose - 13/09/2010 - // Added a couple more parameters into the meshing parameters list - // from Netgen into Nglib - int invert_tets; //!< Invert all the volume elements - int invert_trigs; //!< Invert all the surface triangle elements - - int check_overlap; //!< Check for overlapping surfaces during Surface meshing - int check_overlapping_boundary; //!< Check for overlapping surface elements before volume meshing - - - /*! - Default constructor for the Mesh Parameters class - - Note: This constructor initialises the variables in the - class with the following default values - - #uselocalh: 1 - - #maxh: 1000.0 - - #fineness: 0.5 - - #grading: 0.3 - - #elementsperedge: 2.0 - - #elementspercurve: 2.0 - - #closeedgeenable: 0 - - #closeedgefact: 2.0 - - #secondorder: 0 - - #meshsize_filename: null - - #quad_dominated: 0 - - #optsurfmeshenable: 1 - - #optvolmeshenable: 1 - - #optsteps_2d: 3 - - #optsteps_3d: 3 - - #invert_tets: 0 - - #invert_trigs:0 - - #check_overlap: 1 - - #check_overlapping_boundary: 1 - */ - DLL_HEADER Ng_Meshing_Parameters(); - - - - /*! - Reset the meshing parameters to their defaults - - This member function resets all the meshing parameters - of the object to the default values - */ - DLL_HEADER void Reset_Parameters(); - - - - /*! - Transfer local meshing parameters to internal meshing parameters - - This member function transfers all the meshing parameters - defined in the local meshing parameters structure of nglib into - the internal meshing parameters structure used by the Netgen core - */ - DLL_HEADER void Transfer_Parameters(); -}; - - - - -// *** Functions Exported by this Library ************* - -// ------------------------------------------------------------------ -// Netgen library initialisation / destruction functions - -/*! \brief Initialise the Netgen library and prepare for use - - This function needs to be called by the third-party - program before beginning to use the other Netgen - specific functions. -*/ -DLL_HEADER void Ng_Init (); - - -/*! \brief Exit the Netgen meshing kernel in a clean manner - - Use this function to exit the meshing sub-system in - a clean and orderly manner. -*/ -DLL_HEADER void Ng_Exit (); - - -/*! \brief Create a new (and empty) Netgen Mesh Structure - - This function creates a new Netgen Mesh, initialises - it, and returns a pointer to the created mesh structure. - - Use the returned pointer for subsequent operations - which involve mesh operations. - - \return Ng_Mesh Pointer to a Netgen Mesh type #Ng_Mesh -*/ -DLL_HEADER Ng_Mesh * Ng_NewMesh (); - - -/*! \brief Delete an existing Netgen Mesh Structure - - Use this function to delete an existing Netgen mesh - structure and release the used memory. - - \param mesh Pointer to an existing Netgen Mesh structure - of type #Ng_Mesh -*/ -DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh); - - -/*! \brief Save a Netgen Mesh to disk - - This function allows a generated mesh structure to be saved - to disk. - - A Mesh saved using this function, will be written to disk - in the Netgen VOL file format. - - \param mesh Pointer to an existing Netgen Mesh structure - of type #Ng_Mesh - \param filename Pointer to a character array containing the - name of the file to which the mesh should - be saved -*/ -DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename); - - -/*! \brief Load a Netgen VOL Mesh from disk into memory - - A Netgen mesh saved in the internal VOL format can be loaded - into a Netgen Mesh structure using this function. - - \param filename Pointer to a character array containing the - name of the file to load - \return Ng_Mesh Pointer to a Netgen Mesh type #Ng_Mesh containing - the mesh loaded from disk -*/ -DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename); - - -/*! \brief Merge a Netgen VOL Mesh from disk into an existing mesh in memory - - A Netgen mesh saved in the internal VOL format can be merged - into an existing Netgen Mesh structure using this function. - - \param mesh Name of the Mesh structure already existent in memory - \param filename Pointer to a character array containing the - name of the file to load - \return Ng_Result Status of the merge operation -*/ -DLL_HEADER Ng_Result Ng_MergeMesh(Ng_Mesh * mesh, const char* filename); - - -/*! \brief Merge one Netgen Mesh into another Netgen Mesh in the case - when both are already in memory - - (NOTE: FUNCTION STILL WORK IN PROGRESS!!!) - - This function can be used to merge two Netgen meshes already present - in memory. - - \param mesh1 Parent Mesh structure into which the second mesh - will be merged - \param mesh2 Child mesh structure which will get merged into - the parent mesh - \return Ng_Result Status of the merge operation -*/ -DLL_HEADER Ng_Result Ng_MergeMesh(Ng_Mesh * mesh1, Ng_Mesh * mesh2); -// ------------------------------------------------------------------ - - - -// ------------------------------------------------------------------ -// Basic Meshing functions for manually adding points, surface elements -// and volume elements to a Netgen Mesh structure - -/*! \brief Add a point to a given Netgen Mesh Structure - - This function allows points to be directly added to a Netgen - mesh structure by providing the co-ordinates. - - Each call to the function allows only one point to be added. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \param x Pointer to an array of type double containing the co-ordinates - of the point to be added in the form: \n - - x[0] = X co-ordinate - - x[1] = Y co-ordinate - - x[2] = Z co-ordinate -*/ -DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x); - - -/*! \brief Add a surface element to a given Netgen Mesh Structure - - This function allows the top-level code to directly add individual - Surface Elements to a Netgen Mesh Structure by providing the type of - element to be added and the indices of the points which constitute the - element. - - Note: - - The points referred to by the surface elements must have been - added prior to calling this function. - - Currently only triangular elements are supported, and the Surface Element - Type argument is not used. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \param et Surface Element type provided via the enumerated type - #Ng_Surface_Element_Type - \param pi Pointer to an array of integers containing the indices of the - points which constitute the surface element being added -*/ -DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et, int * pi); - - -/*! \brief Add a volume element to a given Netgen Mesh Structure - - This function allows the top-level code to directly add individual - Volume Elements to a Netgen Mesh Structure by providing the type of - element to be added and the indices of the points which constitute the - element. - - Note: - - The points referred to by the volume elements must have been - added prior to calling this function. - - Currently only tetrahedral elements are supported, and the Volume Element - Type argument is not used. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \param et Volume Element type provided via the enumerated type - #Ng_Volume_Element_Type - \param pi Pointer to an array of integers containing the indices of the - points which constitute the volume element being added - -*/ -DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et, int * pi); - -// ------------------------------------------------------------------ - - - -// ------------------------------------------------------------------ -// Local Mesh Size restriction / limiting utilities - -/*! \brief Apply a global restriction on mesh element size - - This utility allows the user to apply a global mesh element - size limitation. - - During mesh creation, in the absence of an explicit local - size restriction around the neighbourhood of a point within - the meshing domain, this global size restriction will be - utilised. - - Note: This function only limits the Maximum - size of an element within the mesh. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \param h Variable of type double, specifying the maximum - allowable mesh size -*/ -DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h); - - -/*! \brief Locally restrict the mesh element size at the given point - - Unlike the function #Ng_RestrictMeshSizeGlobal, this function - allows the user to locally restrict the maximum allowable mesh - size at a given point. - - The point is specified via its three cartesian co-ordinates. - - Note: This function only limits the Maximum size - of the elements around the specified point. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \param p Pointer to an Array of type double, containing - the three co-ordinates of the point in the form: \n - - p[0] = X co-ordinate - - p[1] = Y co-ordinate - - p[2] = Z co-ordinate - \param h Variable of type double, specifying the maximum - allowable mesh size at that point -*/ -DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h); - - -/*! \brief Locally restrict the mesh element size within a specified box - - Similar to the function #Ng_RestrictMeshSizePoint, this function - allows the size of elements within a mesh to be locally limited. - - However, rather than limit the mesh size at a single point, this - utility restricts the local mesh size within a 3D Box region, specified - via the co-ordinates of the two diagonally opposite points of a cuboid. - - Note: This function only limits the Maximum size - of the elements within the specified region. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \param pmin Pointer to an Array of type double, containing - the three co-ordinates of the first point of the cuboid: \n - - pmin[0] = X co-ordinate - - pmin[1] = Y co-ordinate - - pmin[2] = Z co-ordinate - \param pmax Pointer to an Array of type double, containing - the three co-ordinates of the opposite point of the - cuboid: \n - - pmax[0] = X co-ordinate - - pmax[1] = Y co-ordinate - - pmax[2] = Z co-ordinate - \param h Variable of type double, specifying the maximum - allowable mesh size at that point -*/ -DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h); - -// ------------------------------------------------------------------ - - - -// ------------------------------------------------------------------ -// 3D Mesh Generation functions - -/*! \brief Create a 3D Volume Mesh given a Surface Mesh - - After creating a surface mesh, this function can be utilised - to automatically generate the corresponding 3D Volume Mesh. - - Mesh generation parameters (such as grading, maximum element size, - etc.) are specified via the meshing parameters class which also - needs to be passed to this function. - - Note: Currently, Netgen generates pure tetrahedral volume - meshes. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \param mp Pointer to a copy of the Meshing Parameters class - (#Ng_Meshing_Parameters), filled up with the - required values - - \return Ng_Result Status of the Mesh Generation routine. More - details regarding the return value can be - found in the description of #Ng_Result -*/ -DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp); - -// ------------------------------------------------------------------ - - - -// ------------------------------------------------------------------ -// Basic Mesh information functions - -/*! \brief Returns the Number of Points present in the specified Mesh - - Given an already existent Netgen Mesh Structure, this function - returns the number of points currently present within the Mesh. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \return - Integer Data-type with the number of points in the Mesh -*/ -DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh); - - -/*! \brief Returns the Number of Surface Elements present in the specified Mesh - - Given an already existent Netgen Mesh Structure, this function - returns the number of surface elements currently present within - the Mesh. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \return - Integer Data-type with the number of surface elements in the Mesh -*/ -DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh); - - -/*! \brief Returns the Number of Volume Elements present in the specified Mesh - - Given an already existent Netgen Mesh Structure, this function - returns the number of volume elements currently present within - the Mesh. - - \param mesh Pointer to an existing Netgen Mesh structure of - type #Ng_Mesh - \return - Integer Data-type with the number of volume elements in the Mesh -*/ -DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh); - -// ------------------------------------------------------------------ - - - -// ------------------------------------------------------------------ -// Mesh Topology functions -// Use these functions to extract points, surface / volume elements, -// perform topological searches, etc..etc... - -// Return the Point Coordinates of a specified Point -// The x, y and z co-ordinates are returned in the array pointer as -// x[0] = x ; x[1] = y ; x[2] = z -DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x); - - - -// return surface and volume element in pi -DLL_HEADER Ng_Surface_Element_Type -Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi); - -DLL_HEADER Ng_Volume_Element_Type -Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi); - -// ------------------------------------------------------------------ - - - - -// ********************************************************** -// ** 2D Meshing ** -// ********************************************************** - - -// feeds points and boundary to mesh - -DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x); -DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2); - -// ask for number of points, elements and boundary segments -DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh); -DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh); -DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh); - -// return point coordinates -DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x); - -// return 2d elements -DLL_HEADER Ng_Surface_Element_Type -Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL); - -// return 2d boundary segment -DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL); - - -// load 2d netgen spline geometry -DLL_HEADER Ng_Geometry_2D * Ng_LoadGeometry_2D (const char * filename); - -// generate 2d mesh, mesh is allocated by function -DLL_HEADER Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom, - Ng_Mesh ** mesh, - Ng_Meshing_Parameters * mp); - -DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom, - Ng_Mesh * mesh, - int levels); - - - - - -// ********************************************************** -// ** STL Meshing ** -// ********************************************************** - - -// loads geometry from STL file -DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary = 0); - - -// generate new STL Geometry -DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry (); - - -// fills STL Geometry -// positive orientation -// normal vector may be null-pointer -DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, - double * p1, double * p2, double * p3, - double * nv = NULL); - -// add (optional) edges : -DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom, - double * p1, double * p2); - -// after adding triangles (and edges) initialize -DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom); - -// automatically generates edges: -DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom, - Ng_Mesh* mesh, - Ng_Meshing_Parameters * mp); - - -// generates mesh, empty mesh must be already created. -DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom, - Ng_Mesh * mesh, - Ng_Meshing_Parameters * mp); - - -#ifdef ACIS - -// ********************************************************** -// ** ACIS Meshing ** -// ********************************************************** - -/// Data type for NETGEN STL geomty -typedef void * Ng_ACIS_Geometry; - -// loads geometry from STL file -DLL_HEADER Ng_ACIS_Geometry * Ng_ACIS_LoadGeometry (const char * filename); - -// generates mesh, empty mesh must be already created. -DLL_HEADER Ng_Result Ng_ACIS_GenerateSurfaceMesh (Ng_ACIS_Geometry * geom, - Ng_Mesh * mesh, - Ng_Meshing_Parameters * mp); - - -#endif - - - -#ifdef OCCGEOMETRY - -// ********************************************************** -// ** OpenCascade Geometry / Meshing Utilities ** -// ********************************************************** - -// Create new OCC Geometry Object -DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry (); - -// Delete an OCC Geometry Object -DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry (Ng_OCC_Geometry * geom); - -// Loads geometry from STEP file -DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename); - -// Loads geometry from IGES file -DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename); - -// Loads geometry from BREP file -DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename); - -// Set the local mesh size based on geometry / topology -DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh, - Ng_Meshing_Parameters * mp); - -// Mesh the edges and add Face descriptors to prepare for surface meshing -DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh, - Ng_Meshing_Parameters * mp); - -// Mesh the surfaces of an OCC geometry -DLL_HEADER Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh, - Ng_Meshing_Parameters * mp); - -// Get the face map of an already loaded OCC geometry -DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, - Ng_OCC_TopTools_IndexedMapOfShape * FMap); - -#endif // OCCGEOMETRY - - - -// ********************************************************** -// ** Mesh refinement algorithms ** -// ********************************************************** - -// uniform mesh refinement -DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh); - - -// uniform mesh refinement with geometry adaption: - -DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom, - Ng_Mesh * mesh); - -DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom, - Ng_Mesh * mesh); - -DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom, - Ng_Mesh * mesh); - -#ifdef OCCGEOMETRY -DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh); -#endif - - - -// ********************************************************** -// ** Second Order mesh algorithms ** -// ********************************************************** - -// convert mesh to second order -DLL_HEADER void Ng_Generate_SecondOrder (Ng_Mesh * mesh); - - -// convert mesh to second order with geometry adaption: - -DLL_HEADER void Ng_2D_Generate_SecondOrder (Ng_Geometry_2D * geom, - Ng_Mesh * mesh); - -DLL_HEADER void Ng_STL_Generate_SecondOrder (Ng_STL_Geometry * geom, - Ng_Mesh * mesh); - -DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom, - Ng_Mesh * mesh); - -#ifdef OCCGEOMETRY -DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom, - Ng_Mesh * mesh); -#endif - - -#endif // NGLIB +#ifndef NGLIB +#define NGLIB + +/**************************************************************************/ +/* File: nglib.h */ +/* Author: Joachim Schoeberl */ +/* Date: 7. May. 2000 */ +/**************************************************************************/ + +/*! + \file nglib.h + \brief Library interface to the netgen meshing kernel + \author Joachim Schoeberl + \date 7. May 2000 + + This header file provides access to the core functionality of the Netgen + Mesher via a library interface, without an interactive User Interface. + + The intention of providing these set of functions is to allow system + developers to integrate Netgen into top-level code, to act as the low + level mesh generation / optimisation kernel. +*/ + +// Philippose - 14.02.2009 +// Modifications for creating a DLL in Windows +#ifdef WIN32 + #ifdef NGLIB_EXPORTS || nglib_EXPORTS + #define DLL_HEADER __declspec(dllexport) + #else + #define DLL_HEADER __declspec(dllimport) + #endif +#else + #define DLL_HEADER +#endif + + + +// ** Constants used within Netgen ********************* +/// Maximum allowed number of nodes per volume element +#define NG_VOLUME_ELEMENT_MAXPOINTS 10 + +/// Maximum allowed number of nodes per surface element +#define NG_SURFACE_ELEMENT_MAXPOINTS 8 + + + +// *** Data-types for accessing Netgen functionality *** +/// Data type for NETGEN mesh +typedef void * Ng_Mesh; + +/// Data type for NETGEN CSG geometry +typedef void * Ng_CSG_Geometry; + +/// Data type for NETGEN 2D geometry +typedef void * Ng_Geometry_2D; + +/// Data type for NETGEN STL geometry +typedef void * Ng_STL_Geometry; + +#ifdef OCCGEOMETRY +/// Data type for NETGEN OpenCascade geometry +typedef void * Ng_OCC_Geometry; +typedef void * Ng_OCC_TopTools_IndexedMapOfShape; +#endif + + +// *** Special Enum types used within Netgen *********** +/// Currently implemented surface element types +enum Ng_Surface_Element_Type + { NG_TRIG = 1, NG_QUAD = 2, NG_TRIG6 = 3, NG_QUAD6 = 4, NG_QUAD8 = 5 }; + +/// Currently implemented volume element types +enum Ng_Volume_Element_Type + { NG_TET = 1, NG_PYRAMID = 2, NG_PRISM = 3, NG_TET10 = 4 }; + +/// Values returned by Netgen functions +enum Ng_Result + { + NG_ERROR = -1, + NG_OK = 0, + NG_SURFACE_INPUT_ERROR = 1, + NG_VOLUME_FAILURE = 2, + NG_STL_INPUT_ERROR = 3, + NG_SURFACE_FAILURE = 4, + NG_FILE_NOT_FOUND = 5 + }; + + + +// *** Classes required for use within Netgen ********** +/// Netgen Meshing Parameters class +class Ng_Meshing_Parameters +{ +public: + int uselocalh; //!< Switch to enable / disable usage of local mesh size modifiers + + double maxh; //!< Maximum global mesh size allowed + double minh; //!< Minimum global mesh size allowed + + double fineness; //!< Mesh density: 0...1 (0 => coarse; 1 => fine) + double grading; //!< Mesh grading: 0...1 (0 => uniform mesh; 1 => aggressive local grading) + + double elementsperedge; //!< Number of elements to generate per edge of the geometry + double elementspercurve; //!< Elements to generate per curvature radius + + int closeedgeenable; //!< Enable / Disable mesh refinement at close edges + double closeedgefact; //!< Factor to use for refinement at close edges (larger => finer) + + int minedgelenenable; //!< Enable / Disable user defined minimum edge length for edge subdivision + double minedgelen; //!< Minimum edge length to use while subdividing the edges (default = 1e-4) + + int second_order; //!< Generate second-order surface and volume elements + int quad_dominated; //!< Creates a Quad-dominated mesh + + char * meshsize_filename; //!< Optional external mesh size file + + int optsurfmeshenable; //!< Enable / Disable automatic surface mesh optimization + int optvolmeshenable; //!< Enable / Disable automatic volume mesh optimization + + int optsteps_3d; //!< Number of optimize steps to use for 3-D mesh optimization + int optsteps_2d; //!< Number of optimize steps to use for 2-D mesh optimization + + // Philippose - 13/09/2010 + // Added a couple more parameters into the meshing parameters list + // from Netgen into Nglib + int invert_tets; //!< Invert all the volume elements + int invert_trigs; //!< Invert all the surface triangle elements + + int check_overlap; //!< Check for overlapping surfaces during Surface meshing + int check_overlapping_boundary; //!< Check for overlapping surface elements before volume meshing + + + /*! + Default constructor for the Mesh Parameters class + + Note: This constructor initialises the variables in the + class with the following default values + - #uselocalh: 1 + - #maxh: 1000.0 + - #fineness: 0.5 + - #grading: 0.3 + - #elementsperedge: 2.0 + - #elementspercurve: 2.0 + - #closeedgeenable: 0 + - #closeedgefact: 2.0 + - #secondorder: 0 + - #meshsize_filename: null + - #quad_dominated: 0 + - #optsurfmeshenable: 1 + - #optvolmeshenable: 1 + - #optsteps_2d: 3 + - #optsteps_3d: 3 + - #invert_tets: 0 + - #invert_trigs:0 + - #check_overlap: 1 + - #check_overlapping_boundary: 1 + */ + DLL_HEADER Ng_Meshing_Parameters(); + + + + /*! + Reset the meshing parameters to their defaults + + This member function resets all the meshing parameters + of the object to the default values + */ + DLL_HEADER void Reset_Parameters(); + + + + /*! + Transfer local meshing parameters to internal meshing parameters + + This member function transfers all the meshing parameters + defined in the local meshing parameters structure of nglib into + the internal meshing parameters structure used by the Netgen core + */ + DLL_HEADER void Transfer_Parameters(); +}; + + + + +// *** Functions Exported by this Library ************* + +// ------------------------------------------------------------------ +// Netgen library initialisation / destruction functions + +/*! \brief Initialise the Netgen library and prepare for use + + This function needs to be called by the third-party + program before beginning to use the other Netgen + specific functions. +*/ +DLL_HEADER void Ng_Init (); + + +/*! \brief Exit the Netgen meshing kernel in a clean manner + + Use this function to exit the meshing sub-system in + a clean and orderly manner. +*/ +DLL_HEADER void Ng_Exit (); + + +/*! \brief Create a new (and empty) Netgen Mesh Structure + + This function creates a new Netgen Mesh, initialises + it, and returns a pointer to the created mesh structure. + + Use the returned pointer for subsequent operations + which involve mesh operations. + + \return Ng_Mesh Pointer to a Netgen Mesh type #Ng_Mesh +*/ +DLL_HEADER Ng_Mesh * Ng_NewMesh (); + + +/*! \brief Delete an existing Netgen Mesh Structure + + Use this function to delete an existing Netgen mesh + structure and release the used memory. + + \param mesh Pointer to an existing Netgen Mesh structure + of type #Ng_Mesh +*/ +DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh); + + +/*! \brief Save a Netgen Mesh to disk + + This function allows a generated mesh structure to be saved + to disk. + + A Mesh saved using this function, will be written to disk + in the Netgen VOL file format. + + \param mesh Pointer to an existing Netgen Mesh structure + of type #Ng_Mesh + \param filename Pointer to a character array containing the + name of the file to which the mesh should + be saved +*/ +DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename); + + +/*! \brief Load a Netgen VOL Mesh from disk into memory + + A Netgen mesh saved in the internal VOL format can be loaded + into a Netgen Mesh structure using this function. + + \param filename Pointer to a character array containing the + name of the file to load + \return Ng_Mesh Pointer to a Netgen Mesh type #Ng_Mesh containing + the mesh loaded from disk +*/ +DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename); + + +/*! \brief Merge a Netgen VOL Mesh from disk into an existing mesh in memory + + A Netgen mesh saved in the internal VOL format can be merged + into an existing Netgen Mesh structure using this function. + + \param mesh Name of the Mesh structure already existent in memory + \param filename Pointer to a character array containing the + name of the file to load + \return Ng_Result Status of the merge operation +*/ +DLL_HEADER Ng_Result Ng_MergeMesh(Ng_Mesh * mesh, const char* filename); + + +/*! \brief Merge one Netgen Mesh into another Netgen Mesh in the case + when both are already in memory + + (NOTE: FUNCTION STILL WORK IN PROGRESS!!!) + + This function can be used to merge two Netgen meshes already present + in memory. + + \param mesh1 Parent Mesh structure into which the second mesh + will be merged + \param mesh2 Child mesh structure which will get merged into + the parent mesh + \return Ng_Result Status of the merge operation +*/ +DLL_HEADER Ng_Result Ng_MergeMesh(Ng_Mesh * mesh1, Ng_Mesh * mesh2); +// ------------------------------------------------------------------ + + + +// ------------------------------------------------------------------ +// Basic Meshing functions for manually adding points, surface elements +// and volume elements to a Netgen Mesh structure + +/*! \brief Add a point to a given Netgen Mesh Structure + + This function allows points to be directly added to a Netgen + mesh structure by providing the co-ordinates. + + Each call to the function allows only one point to be added. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \param x Pointer to an array of type double containing the co-ordinates + of the point to be added in the form: \n + - x[0] = X co-ordinate + - x[1] = Y co-ordinate + - x[2] = Z co-ordinate +*/ +DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x); + + +/*! \brief Add a surface element to a given Netgen Mesh Structure + + This function allows the top-level code to directly add individual + Surface Elements to a Netgen Mesh Structure by providing the type of + element to be added and the indices of the points which constitute the + element. + + Note: + - The points referred to by the surface elements must have been + added prior to calling this function. + - Currently only triangular elements are supported, and the Surface Element + Type argument is not used. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \param et Surface Element type provided via the enumerated type + #Ng_Surface_Element_Type + \param pi Pointer to an array of integers containing the indices of the + points which constitute the surface element being added +*/ +DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et, int * pi); + + +/*! \brief Add a volume element to a given Netgen Mesh Structure + + This function allows the top-level code to directly add individual + Volume Elements to a Netgen Mesh Structure by providing the type of + element to be added and the indices of the points which constitute the + element. + + Note: + - The points referred to by the volume elements must have been + added prior to calling this function. + - Currently only tetrahedral elements are supported, and the Volume Element + Type argument is not used. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \param et Volume Element type provided via the enumerated type + #Ng_Volume_Element_Type + \param pi Pointer to an array of integers containing the indices of the + points which constitute the volume element being added + +*/ +DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et, int * pi); + +// ------------------------------------------------------------------ + + + +// ------------------------------------------------------------------ +// Local Mesh Size restriction / limiting utilities + +/*! \brief Apply a global restriction on mesh element size + + This utility allows the user to apply a global mesh element + size limitation. + + During mesh creation, in the absence of an explicit local + size restriction around the neighbourhood of a point within + the meshing domain, this global size restriction will be + utilised. + + Note: This function only limits the Maximum + size of an element within the mesh. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \param h Variable of type double, specifying the maximum + allowable mesh size +*/ +DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h); + + +/*! \brief Locally restrict the mesh element size at the given point + + Unlike the function #Ng_RestrictMeshSizeGlobal, this function + allows the user to locally restrict the maximum allowable mesh + size at a given point. + + The point is specified via its three cartesian co-ordinates. + + Note: This function only limits the Maximum size + of the elements around the specified point. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \param p Pointer to an Array of type double, containing + the three co-ordinates of the point in the form: \n + - p[0] = X co-ordinate + - p[1] = Y co-ordinate + - p[2] = Z co-ordinate + \param h Variable of type double, specifying the maximum + allowable mesh size at that point +*/ +DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h); + + +/*! \brief Locally restrict the mesh element size within a specified box + + Similar to the function #Ng_RestrictMeshSizePoint, this function + allows the size of elements within a mesh to be locally limited. + + However, rather than limit the mesh size at a single point, this + utility restricts the local mesh size within a 3D Box region, specified + via the co-ordinates of the two diagonally opposite points of a cuboid. + + Note: This function only limits the Maximum size + of the elements within the specified region. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \param pmin Pointer to an Array of type double, containing + the three co-ordinates of the first point of the cuboid: \n + - pmin[0] = X co-ordinate + - pmin[1] = Y co-ordinate + - pmin[2] = Z co-ordinate + \param pmax Pointer to an Array of type double, containing + the three co-ordinates of the opposite point of the + cuboid: \n + - pmax[0] = X co-ordinate + - pmax[1] = Y co-ordinate + - pmax[2] = Z co-ordinate + \param h Variable of type double, specifying the maximum + allowable mesh size at that point +*/ +DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h); + +// ------------------------------------------------------------------ + + + +// ------------------------------------------------------------------ +// 3D Mesh Generation functions + +/*! \brief Create a 3D Volume Mesh given a Surface Mesh + + After creating a surface mesh, this function can be utilised + to automatically generate the corresponding 3D Volume Mesh. + + Mesh generation parameters (such as grading, maximum element size, + etc.) are specified via the meshing parameters class which also + needs to be passed to this function. + + Note: Currently, Netgen generates pure tetrahedral volume + meshes. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \param mp Pointer to a copy of the Meshing Parameters class + (#Ng_Meshing_Parameters), filled up with the + required values + + \return Ng_Result Status of the Mesh Generation routine. More + details regarding the return value can be + found in the description of #Ng_Result +*/ +DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp); + +// ------------------------------------------------------------------ + + + +// ------------------------------------------------------------------ +// Basic Mesh information functions + +/*! \brief Returns the Number of Points present in the specified Mesh + + Given an already existent Netgen Mesh Structure, this function + returns the number of points currently present within the Mesh. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \return + Integer Data-type with the number of points in the Mesh +*/ +DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh); + + +/*! \brief Returns the Number of Surface Elements present in the specified Mesh + + Given an already existent Netgen Mesh Structure, this function + returns the number of surface elements currently present within + the Mesh. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \return + Integer Data-type with the number of surface elements in the Mesh +*/ +DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh); + + +/*! \brief Returns the Number of Volume Elements present in the specified Mesh + + Given an already existent Netgen Mesh Structure, this function + returns the number of volume elements currently present within + the Mesh. + + \param mesh Pointer to an existing Netgen Mesh structure of + type #Ng_Mesh + \return + Integer Data-type with the number of volume elements in the Mesh +*/ +DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh); + +// ------------------------------------------------------------------ + + + +// ------------------------------------------------------------------ +// Mesh Topology functions +// Use these functions to extract points, surface / volume elements, +// perform topological searches, etc..etc... + +// Return the Point Coordinates of a specified Point +// The x, y and z co-ordinates are returned in the array pointer as +// x[0] = x ; x[1] = y ; x[2] = z +DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x); + + + +// return surface and volume element in pi +DLL_HEADER Ng_Surface_Element_Type +Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi); + +DLL_HEADER Ng_Volume_Element_Type +Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi); + +// ------------------------------------------------------------------ + + + + +// ********************************************************** +// ** 2D Meshing ** +// ********************************************************** + + +// feeds points and boundary to mesh + +DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x); +DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2); + +// ask for number of points, elements and boundary segments +DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh); +DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh); +DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh); + +// return point coordinates +DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x); + +// return 2d elements +DLL_HEADER Ng_Surface_Element_Type +Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL); + +// return 2d boundary segment +DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL); + + +// load 2d netgen spline geometry +DLL_HEADER Ng_Geometry_2D * Ng_LoadGeometry_2D (const char * filename); + +// generate 2d mesh, mesh is allocated by function +DLL_HEADER Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom, + Ng_Mesh ** mesh, + Ng_Meshing_Parameters * mp); + +DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom, + Ng_Mesh * mesh, + int levels); + + + + + +// ********************************************************** +// ** STL Meshing ** +// ********************************************************** + + +// loads geometry from STL file +DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary = 0); + + +// generate new STL Geometry +DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry (); + + +// fills STL Geometry +// positive orientation +// normal vector may be null-pointer +DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, + double * p1, double * p2, double * p3, + double * nv = NULL); + +// add (optional) edges : +DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom, + double * p1, double * p2); + +// after adding triangles (and edges) initialize +DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom); + +// automatically generates edges: +DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom, + Ng_Mesh* mesh, + Ng_Meshing_Parameters * mp); + + +// generates mesh, empty mesh must be already created. +DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp); + + +#ifdef ACIS + +// ********************************************************** +// ** ACIS Meshing ** +// ********************************************************** + +/// Data type for NETGEN STL geomty +typedef void * Ng_ACIS_Geometry; + +// loads geometry from STL file +DLL_HEADER Ng_ACIS_Geometry * Ng_ACIS_LoadGeometry (const char * filename); + +// generates mesh, empty mesh must be already created. +DLL_HEADER Ng_Result Ng_ACIS_GenerateSurfaceMesh (Ng_ACIS_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp); + + +#endif + + + +#ifdef OCCGEOMETRY + +// ********************************************************** +// ** OpenCascade Geometry / Meshing Utilities ** +// ********************************************************** + +// Create new OCC Geometry Object +DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry (); + +// Delete an OCC Geometry Object +DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry (Ng_OCC_Geometry * geom); + +// Loads geometry from STEP file +DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename); + +// Loads geometry from IGES file +DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename); + +// Loads geometry from BREP file +DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename); + +// Set the local mesh size based on geometry / topology +DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp); + +// Mesh the edges and add Face descriptors to prepare for surface meshing +DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp); + +// Mesh the surfaces of an OCC geometry +DLL_HEADER Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp); + +// Get the face map of an already loaded OCC geometry +DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, + Ng_OCC_TopTools_IndexedMapOfShape * FMap); + +#endif // OCCGEOMETRY + + + +// ********************************************************** +// ** Mesh refinement algorithms ** +// ********************************************************** + +// uniform mesh refinement +DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh); + + +// uniform mesh refinement with geometry adaption: + +DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom, + Ng_Mesh * mesh); + +DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom, + Ng_Mesh * mesh); + +DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom, + Ng_Mesh * mesh); + +#ifdef OCCGEOMETRY +DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh); +#endif + + + +// ********************************************************** +// ** Second Order mesh algorithms ** +// ********************************************************** + +// convert mesh to second order +DLL_HEADER void Ng_Generate_SecondOrder (Ng_Mesh * mesh); + + +// convert mesh to second order with geometry adaption: + +DLL_HEADER void Ng_2D_Generate_SecondOrder (Ng_Geometry_2D * geom, + Ng_Mesh * mesh); + +DLL_HEADER void Ng_STL_Generate_SecondOrder (Ng_STL_Geometry * geom, + Ng_Mesh * mesh); + +DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom, + Ng_Mesh * mesh); + +#ifdef OCCGEOMETRY +DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom, + Ng_Mesh * mesh); +#endif + + +#endif // NGLIB