Example #1
0
 ///
 public void Invalidate()
 {
     l.I1()    = -1;
     l.I2()    = -1;
     lineclass = 1000;
 }
//C++ TO C# CONVERTER WARNING: The original C++ declaration of the following method implementation was not found:
        public void LoadRule(istream ist)
        {
            string      buf = new string(new char[256]);
            char        ch;
            Point2d     p   = new Point2d();
            INDEX_2     lin = new INDEX_2();
            int         i;
            int         j;
            DenseMatrix tempoldutonewu          = new DenseMatrix(20, 20);
            DenseMatrix tempoldutofreearea      = new DenseMatrix(20, 20);
            DenseMatrix tempoldutofreearealimit = new DenseMatrix(20, 20);

            tempoldutonewu          = 0;
            tempoldutofreearea      = 0;
            tempoldutofreearealimit = 0;

            noldp = 0;
            noldl = 0;

            ist.get(buf, sizeof(char), '"');
            ist.get(ch);
            ist.get(buf, sizeof(char), '"');
            ist.get(ch);

            // if(name != NULL)
            name = null;
            name = new char[buf.Length + 1];
            name = buf;
            //(*testout) << "name " << name << endl;
            //  (*mycout) << "Rule " << name << " found." << endl;

            do
            {
                ist >> buf;

                //(*testout) << "buf " << buf << endl;

                if (string.Compare(buf, "quality") == 0)

                {
                    ist >> quality;
                }

                else if (string.Compare(buf, "mappoints") == 0)
                {
                    ist >> ch;

                    while (ch == '(')
                    {
                        ist >> p.X();
                        ist >> ch;           // ','
                        ist >> p.Y();
                        ist >> ch;           // ')'

                        points.Append(p);
                        noldp++;

                        tolerances.SetSize(noldp);
                        tolerances.Elem(noldp).f1 = 1.0;
                        tolerances.Elem(noldp).f2 = 0;
                        tolerances.Elem(noldp).f3 = 1.0;

                        ist >> ch;
                        while (ch != ';')
                        {
                            if (ch == '{')
                            {
                                ist >> tolerances.Elem(noldp).f1;
                                ist >> ch;           // ','
                                ist >> tolerances.Elem(noldp).f2;
                                ist >> ch;           // ','
                                ist >> tolerances.Elem(noldp).f3;
                                ist >> ch;           // '}'
                            }
                            else if (ch == 'd')
                            {
                                //            delpoints.Append (noldp);
                                ist >> ch;           // 'e'
                                ist >> ch;           // 'l'
                            }

                            ist >> ch;
                        }

                        ist >> ch;
                    }

                    ist.putback(ch);
                }


                else if (string.Compare(buf, "maplines") == 0)
                {
                    ist >> ch;

                    while (ch == '(')
                    {
                        ist >> lin.I1();
                        ist >> ch;           // ','
                        ist >> lin.I2();
                        ist >> ch;           // ')'


                        //(*testout) << "read line " << lin.I1() << " " << lin.I2() << endl;
                        lines.Append(lin);
                        linevecs.Append(points.Get(lin.I2()) - points.Get(lin.I1()));
                        noldl++;
                        linetolerances.SetSize(noldl);
                        linetolerances.Elem(noldl).f1 = 0;
                        linetolerances.Elem(noldl).f2 = 0;
                        linetolerances.Elem(noldl).f3 = 0;

                        //(*testout) << "mapl1" << endl;
                        ist >> ch;
                        while (ch != ';')
                        {
                            //(*testout) << "working on character \""<<ch<<"\""<< endl;
                            if (ch == '{')
                            {
                                ist >> linetolerances.Elem(noldl).f1;
                                ist >> ch;           // ','
                                ist >> linetolerances.Elem(noldl).f2;
                                ist >> ch;           // ','
                                ist >> linetolerances.Elem(noldl).f3;
                                ist >> ch;           // '}'
                            }
                            else if (ch == 'd')
                            {
                                dellines.Append(noldl);
                                ist >> ch;           // 'e'
                                ist >> ch;           // 'l'
                                //(*testout) << "read del" << endl;
                            }

                            ist >> ch;
                            //(*testout) << "read character \""<<ch<<"\""<< endl;
                        }

                        ist >> ch;
                        //(*testout) << "read next character \""<<ch<<"\""<< endl;
                    }


                    ist.putback(ch);
                }

                else if (string.Compare(buf, "newpoints") == 0)
                {
                    ist >> ch;

                    while (ch == '(')
                    {
                        ist >> p.X();
                        ist >> ch;           // ','
                        ist >> p.Y();
                        ist >> ch;           // ')'

                        points.Append(p);

                        ist >> ch;
                        while (ch != ';')
                        {
                            if (ch == '{')
                            {
                                LoadMatrixLine(ist, tempoldutonewu.functorMethod, 2 * (points.Size() - noldp) - 1);

                                ist >> ch;           // '{'
                                LoadMatrixLine(ist, tempoldutonewu.functorMethod, 2 * (points.Size() - noldp));
                            }

                            ist >> ch;
                        }

                        ist >> ch;
                    }

                    ist.putback(ch);
                }

                else if (string.Compare(buf, "newlines") == 0)
                {
                    ist >> ch;

                    while (ch == '(')
                    {
                        ist >> lin.I1();
                        ist >> ch;           // ','
                        ist >> lin.I2();
                        ist >> ch;           // ')'

                        lines.Append(lin);
                        linevecs.Append(points.Get(lin.I2()) - points.Get(lin.I1()));

                        ist >> ch;
                        while (ch != ';')
                        {
                            ist >> ch;
                        }

                        ist >> ch;
                    }

                    ist.putback(ch);
                }

                else if (string.Compare(buf, "freearea") == 0)
                {
                    ist >> ch;

                    while (ch == '(')
                    {
                        ist >> p.X();
                        ist >> ch;           // ','
                        ist >> p.Y();
                        ist >> ch;           // ')'

                        freezone.Append(p);
                        freezonelimit.Append(p);

                        ist >> ch;
                        while (ch != ';')
                        {
                            if (ch == '{')
                            {
                                LoadMatrixLine(ist, tempoldutofreearea.functorMethod, 2 * freezone.Size() - 1);

                                ist >> ch;           // '{'
                                LoadMatrixLine(ist, tempoldutofreearea.functorMethod, 2 * freezone.Size());
                            }

                            ist >> ch;
                        }

                        ist >> ch;
                    }

                    for (i = 1; i <= tempoldutofreearealimit.Height(); i++)
                    {
                        for (j = 1; j <= tempoldutofreearealimit.Width(); j++)
                        {
                            tempoldutofreearealimit.Elem(i, j) = tempoldutofreearea.Elem(i, j);
                        }
                    }


                    ist.putback(ch);
                }
                else if (string.Compare(buf, "freearea2") == 0)
                {
                    ist >> ch;
                    int freepi = 0;
                    tempoldutofreearealimit = 0;

                    while (ch == '(')
                    {
                        freepi++;

                        ist >> p.X();
                        ist >> ch;           // ','
                        ist >> p.Y();
                        ist >> ch;           // ')'

                        freezonelimit.Elem(freepi) = p;

                        ist >> ch;
                        while (ch != ';')
                        {
                            if (ch == '{')
                            {
                                LoadMatrixLine(ist, tempoldutofreearealimit.functorMethod, 2 * freepi - 1);

                                ist >> ch;           // '{'
                                LoadMatrixLine(ist, tempoldutofreearealimit.functorMethod, 2 * freepi);
                            }

                            ist >> ch;
                        }

                        ist >> ch;
                    }

                    ist.putback(ch);
                }

                else if (string.Compare(buf, "elements") == 0)
                {
                    ist >> ch;

                    while (ch == '(')
                    {
                        elements.Append(new Element2d(ELEMENT_TYPE.TRIG));

                        ist >> elements.Last().PNum(1);
                        ist >> ch;           // ','

                        if (ch == DefineConstants.COMMASIGN)
                        {
                            ist >> elements.Last().PNum(2);
                            ist >> ch;       // ','
                        }
                        if (ch == DefineConstants.COMMASIGN)
                        {
                            ist >> elements.Last().PNum(3);
                            ist >> ch;       // ','
                        }
                        if (ch == DefineConstants.COMMASIGN)
                        {
                            elements.Last().SetType(ELEMENT_TYPE.QUAD);
                            ist >> elements.Last().PNum(4);
                            ist >> ch;       // ','

                            // const Element2d & el = elements.Last();

                            /*
                             * orientations.Append (threeint(el.PNum(1), el.PNum(2), el.PNum(3)));
                             * orientations.Append (threeint(el.PNum(2), el.PNum(3), el.PNum(4)));
                             * orientations.Append (threeint(el.PNum(3), el.PNum(4), el.PNum(1)));
                             * orientations.Append (threeint(el.PNum(4), el.PNum(1), el.PNum(2)));
                             */
                        }

                        ist >> ch;
                        while (ch != ';')
                        {
                            ist >> ch;
                        }

                        ist >> ch;
                    }

                    ist.putback(ch);
                }

                else if (string.Compare(buf, "orientations") == 0)

                {
                    ist >> ch;

                    while (ch == '(')
                    {
                        //        threeint a = threeint();
                        orientations.Append(new threeint());

                        ist >> orientations.Last().i1;
                        ist >> ch;           // ','
                        ist >> orientations.Last().i2;
                        ist >> ch;           // ','
                        ist >> orientations.Last().i3;
                        ist >> ch;           // ','

                        ist >> ch;
                        while (ch != ';')
                        {
                            ist >> ch;
                        }

                        ist >> ch;
                    }

                    ist.putback(ch);
                }

                else if (string.Compare(buf, "endrule") != 0)
                {
                    PrintSysError("Parser error, unknown token ", buf);
                }
            } while (!ist.eof() && string.Compare(buf, "endrule") != 0);

            oldutonewu.SetSize(2 * (points.Size() - noldp), 2 * noldp);
            oldutofreearea.SetSize(2 * freezone.Size(), 2 * noldp);
            oldutofreearealimit.SetSize(2 * freezone.Size(), 2 * noldp);

            for (i = 1; i <= oldutonewu.Height(); i++)
            {
                for (j = 1; j <= oldutonewu.Width(); j++)
                {
                    oldutonewu.Elem(i, j) = tempoldutonewu.Elem(i, j);
                }
            }

            for (i = 1; i <= oldutofreearea.Height(); i++)
            {
                for (j = 1; j <= oldutofreearea.Width(); j++)
                {
                    oldutofreearea.Elem(i, j) = tempoldutofreearea.Elem(i, j);
                }
            }

            for (i = 1; i <= oldutofreearea.Height(); i++)
            {
                for (j = 1; j <= oldutofreearea.Width(); j++)
                {
                    oldutofreearealimit.Elem(i, j) = tempoldutofreearealimit.Elem(i, j);
                }
            }

            freesetinequ.SetSize(freezone.Size());


            {
                char        ok;
                int         minn;
                Array <int> pnearness = new Array <int>(noldp);

                for (i = 1; i <= pnearness.Size(); i++)
                {
                    pnearness.Elem(i) = 1000;
                }

                for (j = 1; j <= 2; j++)
                {
                    pnearness.Elem(GetPointNr(1, j)) = 0;
                }

                do
                {
                    ok = 1;

                    for (i = 1; i <= noldl; i++)
                    {
                        minn = 1000;
                        for (j = 1; j <= 2; j++)
                        {
                            minn = min2(minn, pnearness.Get(GetPointNr(i, j)));
                        }

                        for (j = 1; j <= 2; j++)
                        {
                            if (pnearness.Get(GetPointNr(i, j)) > minn + 1)
                            {
                                ok = 0;
                                pnearness.Elem(GetPointNr(i, j)) = minn + 1;
                            }
                        }
                    }
                } while (!ok);

                lnearness.SetSize(noldl);

                for (i = 1; i <= noldl; i++)
                {
                    lnearness.Elem(i) = 0;
                    for (j = 1; j <= 2; j++)
                    {
                        lnearness.Elem(i) += pnearness.Get(GetPointNr(i, j));
                    }
                }
            }

            oldutofreearea_i.SetSize(10);
            freezone_i.SetSize(10);

            for (i = 0; i < oldutofreearea_i.Size(); i++)
            {
                double lam1 = 1.0 / (i + 1);

                oldutofreearea_i[i] = new DenseMatrix(oldutofreearea.Height(), oldutofreearea.Width());
                DenseMatrix mati = *oldutofreearea_i[i];
                for (j = 0; j < oldutofreearea.Height(); j++)
                {
                    for (int k = 0; k < oldutofreearea.Width(); k++)
                    {
                        mati.functorMethod(j, k) = lam1 * oldutofreearea(j, k) + (1 - lam1) * oldutofreearealimit(j, k);
                    }
                }

                freezone_i[i] = new Array <Point2d> (freezone.Size());
                Array <Point2d> fzi = *freezone_i[i];
                for (int j = 0; j < freezone.Size(); j++)
                {
                    fzi[j] = freezonelimit[j] + lam1 * (freezone[j] - freezonelimit[j]);
                }
            }
        }
//C++ TO C# CONVERTER WARNING: The original C++ declaration of the following method implementation was not found:
        public int ApplyRules(Array <Point2d> lpoints, Array <int> legalpoints, int maxlegalpoint, Array <INDEX_2> llines1, int maxlegalline, Array <Element2d> elements, Array <int> dellines, int tolerance, MeshingParameters mp)
        {
            //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
            //	static int timer = NgProfiler::CreateTimer("meshing2::ApplyRules");
            NgProfiler.RegionTimer reg = new NgProfiler.RegionTimer(ApplyRules_timer);



            double maxerr   = 0.5 + 0.3 * tolerance;
            double minelerr = 2 + 0.5 * tolerance * tolerance;

            int noldlp = lpoints.Size();
            int noldll = llines1.Size();


            ArrayMem <int, 100> pused     = new ArrayMem <int, 100>((uint)maxlegalpoint);
            ArrayMem <int, 100> lused     = new ArrayMem <int, 100>((uint)maxlegalline);
            ArrayMem <int, 100> pnearness = new ArrayMem <int, 100>((uint)noldlp);
            ArrayMem <int, 100> lnearness = new ArrayMem <int, 100>(llines1.Size());

            ArrayMem <int, 20> pmap   = new ArrayMem <int, 20>();
            ArrayMem <int, 20> pfixed = new ArrayMem <int, 20>();
            ArrayMem <int, 20> lmap   = new ArrayMem <int, 20>();

            ArrayMem <Point2d, 100>   tempnewpoints = new ArrayMem <Point2d, 100>();
            ArrayMem <INDEX_2, 100>   tempnewlines  = new ArrayMem <INDEX_2, 100>();
            ArrayMem <int, 100>       tempdellines  = new ArrayMem <int, 100>();
            ArrayMem <Element2d, 100> tempelements  = new ArrayMem <Element2d, 100>();


            elements.SetSize(0);
            dellines.SetSize(0);

            testmode = debugparam.debugoutput;

                #if LOCDEBUG
            int loctestmode = testmode;

            if (loctestmode != 0)
            {
                (*testout) << "\n" << "\n" << "Check new environment" << "\n";
                (*testout) << "tolerance = " << tolerance << "\n";
                for (int i = 1; i <= lpoints.Size(); i++)
                {
                    (*testout) << "P" << i << " = " << lpoints.Get(i) << "\n";
                }
                (*testout) << "\n";
                for (int i = 1; i <= llines1.Size(); i++)
                {
                    (*testout) << "(" << llines1.Get(i).I1() << "-" << llines1.Get(i).I2() << ")" << "\n";
                }
            }
                #endif

            // check every rule

            int found = 0;             // rule number

            pnearness = 1000;

            for (int j = 0; j < 2; j++)
            {
                pnearness.Set(llines1[0][j], 0);
            }



            for (int cnt = 0; cnt < MAX_NEARNESS; cnt++)
            {
                bool ok = true;
                for (int i = 0; i < maxlegalline; i++)
                {
                    INDEX_2 hline = llines1[i];

                    int minn = min2(pnearness.Get(hline[0]), pnearness.Get(hline[1]));

                    for (int j = 0; j < 2; j++)
                    {
                        if (pnearness.Get(hline[j]) > minn + 1)
                        {
                            ok = false;
                            pnearness.Set(hline[j], minn + 1);
                        }
                    }
                }
                if (!ok)
                {
                    break;
                }
            }


            for (int i = 0; i < maxlegalline; i++)
            {
                lnearness[i] = pnearness.Get(llines1[i][0]) + pnearness.Get(llines1[i][1]);
            }


            // resort lines after lnearness
            Array <INDEX_2> llines          = new Array <INDEX_2>(llines1.Size());
            Array <int>     sortlines       = new Array <int>(llines1.Size());
            int[]           lnearness_class = new int[MAX_NEARNESS];

            for (int j = 0; j < MAX_NEARNESS; j++)
            {
                lnearness_class[j] = 0;
            }
            for (int i = 0; i < maxlegalline; i++)
            {
                if (lnearness[i] < MAX_NEARNESS)
                {
                    lnearness_class[lnearness[i]]++;
                }
            }

            int cumm = 0;
            for (int j = 0; j < MAX_NEARNESS; j++)
            {
                int hcnt = lnearness_class[j];
                lnearness_class[j] = cumm;
                cumm += hcnt;
            }

            for (int i = 0; i < maxlegalline; i++)
            {
                if (lnearness[i] < MAX_NEARNESS)
                {
                    llines[lnearness_class[lnearness[i]]]    = llines1[i];
                    sortlines[lnearness_class[lnearness[i]]] = i + 1;
                    lnearness_class[lnearness[i]]++;
                }
                else
                {
                    llines[cumm]    = llines1[i];
                    sortlines[cumm] = i + 1;
                    cumm++;
                }
            }

            for (int i = maxlegalline; i < llines1.Size(); i++)
            {
                llines[cumm]    = llines1[i];
                sortlines[cumm] = i + 1;
                cumm++;
            }

            for (int i = 0; i < maxlegalline; i++)
            {
                lnearness[i] = pnearness.Get(llines[i][0]) + pnearness.Get(llines[i][1]);
            }



            //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
            //	static bool firsttime = true;
            // static int timers[100];
            // static int timers2[100];
            // static int timers3[100];
            if (ApplyRules_firsttime)
            {
                /*
                 * for (int ri = 0; ri < rules.Size(); ri++)
                 * timers[ri] = NgProfiler::CreateTimer (string("netrule ")+rules[ri]->Name());
                 * for (int ri = 0; ri < rules.Size(); ri++)
                 * timers2[ri] = NgProfiler::CreateTimer (string("netrule,mapped ")+rules[ri]->Name());
                 * for (int ri = 0; ri < rules.Size(); ri++)
                 * timers3[ri] = NgProfiler::CreateTimer (string("netrule,lines mapped ")+rules[ri]->Name());
                 */
                ApplyRules_firsttime = false;
            }

            lused = 0;
            pused = 0;


            //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
            //	static int timer1 = NgProfiler::CreateTimer("meshing2::ApplyRules 1");
            NgProfiler.RegionTimer reg1 = new NgProfiler.RegionTimer(ApplyRules_timer1);


            for (int ri = 1; ri <= rules.Size(); ri++)
            {
                // NgProfiler::RegionTimer reg(timers[ri-1]);
                netrule rule = rules.Get(ri);

                #if LOCDEBUG
                if (loctestmode != 0)
                {
                    (*testout) << "Rule " << rule.Name() << "\n";
                }
                #endif

                if (rule.GetQuality() > tolerance)
                {
                    continue;
                }

                pmap.SetSize(rule.GetNP());
                lmap.SetSize(rule.GetNL());

                pmap = 0;
                lmap = 0;

                lused[0] = 1;
                lmap[0]  = 1;

                for (int j = 0; j < 2; j++)
                {
                    pmap.Elem(rule.GetLine 1[j]) = llines[0][j];
                    pused.Elem(llines[0][j])++;
                }



                int nlok = 2;


                bool ok = false;

                while (nlok >= 2)
                {
                    if (nlok <= rule.GetNOldL())

                    {
                        ok = false;

                        int maxline = (rule.GetLNearness(nlok) < MAX_NEARNESS) ? lnearness_class[rule.GetLNearness(nlok)] : maxlegalline;
                        // int maxline = maxlegalline;

                        while (!ok && lmap.Get(nlok) < maxline)
                        {
                            lmap.Elem(nlok)++;
                            int locli = lmap.Get(nlok);

                            if (lnearness.Get(locli) > rule.GetLNearness(nlok))
                            {
                                continue;
                            }
                            if (lused.Get(locli))
                            {
                                continue;
                            }


                            ok = true;

                            INDEX_2 loclin  = llines.Get(locli);
                            Vec2d   linevec = lpoints.Get(loclin.I2()) - lpoints.Get(loclin.I1());

                            if (rule.CalcLineError(nlok, linevec) > maxerr)
                            {
                                ok = false;
                #if LOCDEBUG
                                if (loctestmode != 0)
                                {
                                    (*testout) << "not ok pos1" << "\n";
                                }
                #endif
                                continue;
                            }

                            for (int j = 0; j < 2; j++)
                            {
                                int refpi = rule.GetLine(nlok)[j];

                                if (pmap.Get(refpi) != 0)
                                {
                                    if (pmap.Get(refpi) != loclin[j])
                                    {
                                        ok = false;
                #if LOCDEBUG
                                        if (loctestmode != 0)
                                        {
                                            (*testout) << "not ok pos2" << "\n";
                                        }
                #endif
                                        break;
                                    }
                                }
                                else
                                {
                                    if (rule.CalcPointDist(refpi, lpoints.Get(loclin[j])) > maxerr || !legalpoints.Get(loclin[j]) || pused.Get(loclin[j]))
                                    {
                                        ok = false;
                #if LOCDEBUG
                                        if (loctestmode != 0)
                                        {
                                            (*testout) << "nok pos3" << "\n";
                                            //if(rule->CalcPointDist (refpi, lpoints.Get(loclin[j])) > maxerr)
                                            //(*testout) << "r1" << endl;
                                            //if(!legalpoints.Get(loclin[j]))
                                            //(*testout) << "r2 legalpoints " << legalpoints << " loclin " << loclin << " j " << j << endl;
                                            //if(pused.Get(loclin[j]))
                                            //(*testout) << "r3" << endl;
                                        }
                #endif
                                        break;
                                    }
                                }
                            }
                        }

                        if (ok)
                        {
                            int     locli  = lmap.Get(nlok);
                            INDEX_2 loclin = llines.Get(locli);

                            lused.Elem(locli) = 1;
                            for (int j = 0; j < 2; j++)
                            {
                                pmap.Set(rule.GetLine nlok[j], loclin[j]);