//Here, I basically find the midpoint of the four pts intersecting at the middle of the face facemidpts midpoint(headmarkers markers) { xm = 0.25 * (markers.foreo.x + markers.lefto.x + markers.righto.x + markers.chino.x); ym = 0.25 * (markers.foreo.y + markers.lefto.y + markers.righto.y + markers.chino.y); zm = 0.25 * (markers.foreo.z + markers.lefto.z + markers.righto.z + markers.chino.z); if (save) { savepoints(/*xm, ym, zm*/); } facepoints = {xm, ym, zm}; modgramschmidt(markers, facepoints); //compute stable orthogonalization and normalization return facepoints; }
int main (int argc, char **argv) { int norun; char *startbrk, *endbrk; char *indir, *outdir, *outprefix; int attr; int splicemode; float digits; int bboxflag; startbrk = (char *) sbrk (0); indir = "."; outdir = "."; outprefix = "tiger"; attr = T_EATTR_STATE; splicemode = 1; digits = 6; bboxflag = 0; savemask = 15; norun = 0; for (;;) { switch (optget (argv, usage)) { case -100: indir = opt_info.arg; continue; case -101: outdir = opt_info.arg; continue; case -200: splicemode = opt_info.num; continue; case -201: if ((digits = atof (opt_info.arg)) < 0) digits = -1; continue; case -300: if (strcmp (opt_info.arg, "zip") == 0) attr = T_EATTR_ZIP; else if (strcmp (opt_info.arg, "npanxxloc") == 0) attr = T_EATTR_NPANXXLOC; else if (strcmp (opt_info.arg, "state") == 0) attr = T_EATTR_STATE; else if (strcmp (opt_info.arg, "county") == 0) attr = T_EATTR_COUNTY; else if (strcmp (opt_info.arg, "ctbna") == 0) attr = T_EATTR_CTBNA; else if (strcmp (opt_info.arg, "blkg") == 0) attr = T_EATTR_BLKG; else if (strcmp (opt_info.arg, "blk") == 0) attr = T_EATTR_BLK; else if (strcmp (opt_info.arg, "blks") == 0) attr = T_EATTR_BLKS; else if (strcmp (opt_info.arg, "country") == 0) attr = T_EATTR_COUNTRY; else SUerror ("tiger2ps", "bad argument for -a option"); continue; case -302: outprefix = opt_info.arg; continue; case -306: bboxflag = 1; continue; case -600: savemask &= 14; continue; case -601: savemask &= 13; continue; case -602: savemask &= 11; continue; case -603: savemask &= 7; continue; case -999: SUwarnlevel++; continue; case '?': SUusage (0, "tiger2ps", opt_info.arg); norun = 1; continue; case ':': SUusage (1, "tiger2ps", opt_info.arg); norun = 2; continue; } break; } if (norun) return norun - 1; argc -= opt_info.index, argv += opt_info.index; initrecords (); if (!(itemdict = dtopen (&itemdisc, Dtset))) SUerror ("tiger2ps", "dtopen failed"); if (loaddata (indir) == -1) SUerror ("tiger2ps", "loaddata failed"); if (splicemode > 0 && removedegree2vertices (splicemode) == -1) SUerror ("tiger2ps", "removedegree2vertices"); if (digits >= 0 && simplifyxys (digits) == -1) SUerror ("tiger2ps", "simplifyxys failed"); if (genpoints (attr) == -1) SUerror ("tiger2ps", "genpoints failed"); calcbbox (); if (bboxflag) printbbox (); if ((savemask & 1) && savepoints (outdir, outprefix) == -1) SUerror ("tiger2ps", "savepoints failed for %s/%s", outdir, outprefix); if ((savemask & 2) && savelines (outdir, outprefix) == -1) SUerror ("tiger2ps", "savelines failed for %s/%s", outdir, outprefix); if ((savemask & 4) && savepolys (outdir, outprefix) == -1) SUerror ("tiger2ps", "savepolys failed for %s/%s", outdir, outprefix); if ((savemask & 8) && gentris () == -1) SUerror ("tiger2ps", "gentris failed"); if ((savemask & 8) && savetris (outdir, outprefix) == -1) SUerror ("tiger2ps", "savetris failed for %s/%s", outdir, outprefix); printstats (); endbrk = (char *) sbrk (0); SUmessage (1, "tiger2ps", "memory usage %d", endbrk - startbrk); return 0; }
void MeshOptimize2d :: ImproveVolumeMesh (Mesh & mesh) { if (!faceindex) { PrintMessage (3, "Smoothing"); for (faceindex = 1; faceindex <= mesh.GetNFD(); faceindex++) { ImproveVolumeMesh (mesh); if (multithread.terminate) throw NgException ("Meshing stopped"); } faceindex = 0; return; } static int timer = NgProfiler::CreateTimer ("MeshSmoothing 2D"); NgProfiler::RegionTimer reg (timer); CheckMeshApproximation (mesh); int i, j, k; SurfaceElementIndex sei; Array<SurfaceElementIndex> seia; mesh.GetSurfaceElementsOfFace (faceindex, seia); bool mixed = 0; for (i = 0; i < seia.Size(); i++) if (mesh[seia[i]].GetNP() != 3) { mixed = 1; break; } int loci; double fact; bool moveisok; PointGeomInfo ngi; Point<3> origp; Vector x(3); Array<MeshPoint, PointIndex::BASE> savepoints(mesh.GetNP()); Array<int, PointIndex::BASE> nelementsonpoint(mesh.GetNP()); nelementsonpoint = 0; for (i = 0; i < seia.Size(); i++) { const Element2d & el = mesh[seia[i]]; for (j = 0; j < el.GetNP(); j++) nelementsonpoint[el[j]]++; } TABLE<SurfaceElementIndex,PointIndex::BASE> elementsonpoint(nelementsonpoint); for (i = 0; i < seia.Size(); i++) { const Element2d & el = mesh[seia[i]]; for (j = 0; j < el.GetNP(); j++) elementsonpoint.Add (el[j], seia[i]); } JacobianPointFunction pf(mesh.Points(),mesh.VolumeElements()); // Opti2SurfaceMinFunction surfminf(mesh); // Opti2EdgeMinFunction edgeminf(mesh); // Opti2SurfaceMinFunctionJacobian surfminfj(mesh); OptiParameters par; par.maxit_linsearch = 8; par.maxit_bfgs = 5; int np = mesh.GetNP(); int ne = mesh.GetNE(); BitArray badnodes(np); badnodes.Clear(); for (i = 1; i <= ne; i++) { const Element & el = mesh.VolumeElement(i); double bad = el.CalcJacobianBadness (mesh.Points()); if (bad > 1) for (j = 1; j <= el.GetNP(); j++) badnodes.Set (el.PNum(j)); } bool printeddot = 0; char plotchar = '.'; int modplot = 1; if (mesh.GetNP() > 1000) { plotchar = '+'; modplot = 10; } if (mesh.GetNP() > 10000) { plotchar = 'o'; modplot = 100; } int cnt = 0; Array<SurfaceElementIndex> locelements(0); Array<int> locrots(0); for (PointIndex pi = mesh.Points().Begin(); pi < mesh.Points().End(); pi++) { if (mesh[pi].Type() != SURFACEPOINT) continue; if (multithread.terminate) throw NgException ("Meshing stopped"); int surfi(-1); if(elementsonpoint[pi].Size() == 0) continue; Element2d & hel = mesh[elementsonpoint[pi][0]]; if(hel.GetIndex() != faceindex) continue; cnt++; if (cnt % modplot == 0 && writestatus) { printeddot = 1; PrintDot (plotchar); } int hpi = 0; for (j = 1; j <= hel.GetNP(); j++) if (hel.PNum(j) == pi) { hpi = j; break; } PointGeomInfo gi1 = hel.GeomInfoPi(hpi); locelements.SetSize(0); locrots.SetSize (0); for (j = 0; j < elementsonpoint[pi].Size(); j++) { sei = elementsonpoint[pi][j]; const Element2d & bel = mesh[sei]; surfi = mesh.GetFaceDescriptor(bel.GetIndex()).SurfNr(); locelements.Append (sei); for (k = 1; k <= bel.GetNP(); k++) if (bel.PNum(k) == pi) { locrots.Append (k); break; } } double lh = mesh.GetH(mesh.Point(pi)); par.typx = lh; pf.SetPointIndex(pi); x = 0; bool pok = (pf.Func (x) < 1e10); if (pok) { BFGS (x, pf, par); origp = mesh[pi]; loci = 1; fact = 1; moveisok = false; //optimizer loop (if whole distance is not possible, move only a bit!!!!) while (loci <= 5 && !moveisok) { loci ++; mesh[pi](0) = origp(0) + x(0)*fact; mesh[pi](1) = origp(1) + x(1)*fact; mesh[pi](2) = origp(2) + x(2)*fact; fact = fact/2.; //cout << "origp " << origp << " newp " << mesh[pi]; ngi = gi1; moveisok = (ProjectPointGI (surfi, mesh[pi], ngi) != 0); //cout << " projected " << mesh[pi] << endl; // point lies on same chart in stlsurface if (moveisok) { for (j = 0; j < locelements.Size(); j++) mesh[locelements[j]].GeomInfoPi(locrots[j]) = ngi; //cout << "moved " << origp << " to " << mesh[pi] << endl; } else { mesh[pi] = origp; } } } else { cout << "el not ok (point " << pi << ": " << mesh[pi] << ")" << endl; } } if (printeddot) PrintDot ('\n'); CheckMeshApproximation (mesh); mesh.SetNextTimeStamp(); }