Esempio n. 1
0
    bool modify_symmetry(float tSL, float tSH, float ang)
    {
        bool ret = true;
        // rotation about y
        Matrix4x4 r2 = Helper.get_rot_Y((double)(90 - ang));
        // random direction, the remaining 1 dof, rotation about z
        Matrix4x4 r1  = Helper.get_rot_X(Helper.get_random_double(0, 360));
        Matrix4x4 tmp = (r2 * r1);

        float fct = 1.1f;

        //Now keep stretching until the derired assymetry is reached.
        int cntrLmt = 100, cntr = 0;

        while ((modified_obj.degree_of_asymmetry() < tSL && modified_obj.degree_of_asymmetry() < tSH) && cntr < cntrLmt)
        {
            modified_obj.modify_object(tmp, fct);
            cntr++;
        }
        if (cntr >= cntrLmt)
        {
            ret = false;
        }

        return(ret);
    }
Esempio n. 2
0
    bool create_object(int isSym, int isCmp, float tSL, float tSH, float tCL, float tCH)
    {
        bool ret = true;

        m = new Model();

        #region 1) Symmetric and Compact
        /* 1) ***************** Symmetric and Compact ******************/
        if (isSym == 1 && isCmp == 1)
        {
            bool attempt_failed = true;
            int  outCtr = 0, outCtrLmt = 100;
            do
            {
                m.regenerate();
                modified_obj = m.generate_off_obj();
                //The object is symmetric but if it is not compact
                if (modified_obj.compactess() < tCH)
                {
                    attempt_failed = !modify_compactness(tCH, true);
                }
                outCtr++;
            } while (attempt_failed && outCtr < outCtrLmt);
            if (outCtr >= outCtrLmt)
            {
                ret = false;
            }
        }
        #endregion

        #region 2) Symmetric and in between Compact
        /* 2) ***************** Symmetric and in between Compact ******************/
        if (isSym == 1 && isCmp == 0)
        {
            bool attempt_failed = true;
            int  outCtr = 0, outCtrLmt = 100;
            do
            {
                m.regenerate();
                modified_obj = m.generate_off_obj();
                float df = (tCH - tCL);
                //The object is symmetric but if it is not compact
                if (modified_obj.compactess() < tCL)
                {
                    float t = (float)Helper.get_random_double(tCL, tCH - (df / 4.0f));
                    attempt_failed = !modify_compactness(t, true);
                }
                //The object is symmetric but if it is compact
                else if (modified_obj.compactess() > tCH)
                {
                    float t = (float)Helper.get_random_double(tCL + (df / 4.0f), tCH);
                    attempt_failed = !modify_compactness(t, false);
                }
                outCtr++;
            } while (attempt_failed && outCtr < outCtrLmt);
            if (outCtr >= outCtrLmt)
            {
                ret = false;
            }
        }
        #endregion

        #region 3) Symmetric and Non-Compact
        /* 3) ***************** Symmetric and Non-Compact ******************/
        if (isSym == 1 && isCmp == -1)
        {
            bool attempt_failed = true;
            int  outCtr = 0, outCtrLmt = 100;
            do
            {
                m.regenerate();
                modified_obj = m.generate_off_obj();
                //The object is symmetric but if it is compact
                if (modified_obj.compactess() > tCL)
                {
                    attempt_failed = !modify_compactness(tCL, false);
                }
                outCtr++;
                if (modified_obj.compactess() <= 0.11)
                {
                    attempt_failed = true;
                }
            } while (attempt_failed && outCtr < outCtrLmt);
            if (outCtr >= outCtrLmt)
            {
                ret = false;
            }
        }
        #endregion

        #region 4) in between Symmetry and Compact
        /* 4) ***************** in between Symmetry and Compact ******************/
        if (isSym == 0 && isCmp == 1)
        {
            bool isSat = false;
            int  outOutCntr = 0, outOutCntrLmt = 100;
            do
            {
                int  outCntr = 0, outCntrLmt = 100;
                bool tot_attempt_success = true;
                do
                {
                    // First obtain desired compactness
                    bool  attempt_failed = true;
                    int   ctr = 0, ctrLmt = 100;
                    float df = (tSH - tSL);
                    //first we create a highly compact object, a little more compact than was asked for.
                    float nwTCH = tCH + 0.3f * tCH;
                    do
                    {
                        m.regenerate();
                        modified_obj = m.generate_off_obj();

                        if (modified_obj.compactess() < nwTCH)
                        {
                            attempt_failed = !modify_compactness(nwTCH, true);
                        }
                        ctr++;
                    } while (attempt_failed && ctr < ctrLmt);
                    if (ctr >= ctrLmt)
                    {
                        tot_attempt_success = false;
                    }
                    // Now modify Assymettry
                    if (tot_attempt_success)
                    {
                        attempt_failed = true;
                        ctr            = 0; ctrLmt = 100;
                        Matrix4x4 tmp = Matrix4x4.identity;
                        tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f;
                        do
                        {
                            if (modified_obj.degree_of_asymmetry() < tSL || modified_obj.degree_of_asymmetry() > tSH)
                            {
                                float ll = (float)Helper.get_random_double(tSL, tSL + 3.0 * df / 4.0f);
                                attempt_failed = !modify_symmetry(ll, tSH, tmp);
                            }
                            ctr++;
                        } while (attempt_failed && ctr < ctrLmt);
                        if (ctr >= ctrLmt)
                        {
                            tot_attempt_success = false;
                        }
                    }
                    outCntr++;
                } while (!tot_attempt_success && outCntr < outCntrLmt);

                if ((modified_obj.degree_of_asymmetry() >= tSL) && (modified_obj.degree_of_asymmetry() <= tSH) && (modified_obj.compactess() >= tCH))
                {
                    isSat = true;
                }
                outOutCntr++;
            } while (outOutCntr < outOutCntrLmt && !isSat);

            ret = isSat;
        }
        #endregion

        #region 5) in between Symmetry and in between Compactness
        /* 5) ***************** in between Symmetry and in between Compactness ******************/
        if (isSym == 0 && isCmp == 0)
        {
            bool isSat = false;
            int  outOutCntr = 0, outOutCntrLmt = 100;
            do
            {
                int  outCntr = 0, outCntrLmt = 100;
                bool tot_attempt_success = true;
                do
                {
                    // First obtain desired compactness
                    bool attempt_failed = true;
                    tot_attempt_success = true;
                    int   ctr = 0, ctrLmt = 100;
                    float dfS = (tSH - tSL);
                    //first we create a highly compact object, a little more compact than was asked for.
                    do
                    {
                        m.regenerate();
                        modified_obj = m.generate_off_obj();

                        float dfC = (tCH - tCL);
                        //The object is symmetric but if it is not compact
                        if (modified_obj.compactess() < tCH)
                        {
                            //float t = (float)Helper.get_random_double(tCL + (dfC / 2.0f), tCH );
                            attempt_failed = !modify_compactness(tCH - dfC / 5.0f, true);
                        }
                        //The object is symmetric but if it is compact
                        else if (modified_obj.compactess() > tCH)
                        {
                            //float t = (float)Helper.get_random_double(tCL + (dfC / 4.0f), tCH);
                            attempt_failed = !modify_compactness(tCH - dfC / 5.0f, false);
                        }

                        ctr++;
                    } while (attempt_failed && ctr < ctrLmt);
                    if (ctr >= ctrLmt)
                    {
                        tot_attempt_success = false;
                    }
                    // Now modify Assymettry
                    if (tot_attempt_success)
                    {
                        attempt_failed = true;
                        ctr            = 0; ctrLmt = 100;
                        Matrix4x4 tmp = Matrix4x4.identity;
                        tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f;
                        do
                        {
                            if (modified_obj.degree_of_asymmetry() < tSL || modified_obj.degree_of_asymmetry() > tSH)
                            {
                                float ll = (float)Helper.get_random_double(tSL, tSL + 3.0 * dfS / 4.0f);
                                attempt_failed = !modify_symmetry(ll, tSH, tmp);
                            }
                            ctr++;
                        } while (attempt_failed && ctr < ctrLmt);
                        if (ctr >= ctrLmt)
                        {
                            tot_attempt_success = false;
                        }
                    }
                    outCntr++;
                } while (!tot_attempt_success && outCntr < outCntrLmt);

                if ((modified_obj.degree_of_asymmetry() >= tSL) && (modified_obj.degree_of_asymmetry() <= tSH) && (modified_obj.compactess() >= tCL) && (modified_obj.compactess() <= tCH))
                {
                    isSat = true;
                }
                outOutCntr++;
            } while (outOutCntr < outOutCntrLmt && !isSat);

            ret = isSat;
        }
        #endregion

        #region 6) in between Symmetry and not Compact
        /* 5) ***************** in between Symmetry and not Compact ******************/
        if (isSym == 0 && isCmp == -1)
        {
            bool isSat = false;
            int  outOutCntr = 0, outOutCntrLmt = 100;
            do
            {
                int  outCntr = 0, outCntrLmt = 100;
                bool tot_attempt_success = true;
                do
                {
                    // First obtain desired compactness
                    bool attempt_failed = true;
                    tot_attempt_success = true;
                    int   ctr = 0, ctrLmt = 100;
                    float dfS = (tSH - tSL);
                    float dfC = (tCH - tCL);
                    //first we create a non compact object.
                    do
                    {
                        m.regenerate();
                        modified_obj = m.generate_off_obj();
                        float t = tCL;
                        if (modified_obj.compactess() > t)
                        {
                            attempt_failed = !modify_compactness(t, false);
                        }

                        ctr++;
                    } while (attempt_failed && ctr < ctrLmt);
                    if (ctr >= ctrLmt)
                    {
                        tot_attempt_success = false;
                    }
                    // Now modify Assymettry
                    if (tot_attempt_success)
                    {
                        attempt_failed = true;
                        ctr            = 0; ctrLmt = 100;
                        Matrix4x4 tmp = Matrix4x4.identity;
                        tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f;
                        do
                        {
                            if (modified_obj.degree_of_asymmetry() < tSL || modified_obj.degree_of_asymmetry() > tSH)
                            {
                                float ll = (float)Helper.get_random_double(tSL, tSL + 3.0 * dfS / 4.0f);
                                attempt_failed = !modify_symmetry(ll, tSH, tmp);
                            }
                            ctr++;
                        } while (attempt_failed && ctr < ctrLmt);
                        if (ctr >= ctrLmt)
                        {
                            tot_attempt_success = false;
                        }
                    }
                    outCntr++;
                } while (!tot_attempt_success && outCntr < outCntrLmt);

                if ((modified_obj.degree_of_asymmetry() >= tSL) && (modified_obj.degree_of_asymmetry() <= tSH) && (modified_obj.compactess() <= tCL) && (modified_obj.compactess() >= 0.11))
                {
                    isSat = true;
                }
                outOutCntr++;
            } while (outOutCntr < outOutCntrLmt && !isSat);

            ret = isSat;
        }
        #endregion

        #region 7) Asymmetric and Compact
        /* 7) ***************** Asymmetric and Compact ******************/
        if (isSym == -1 && isCmp == 1)
        {
            bool isSat = false;
            int  outOutCntr = 0, outOutCntrLmt = 100;
            do
            {
                int  outCntr = 0, outCntrLmt = 100;
                bool tot_attempt_success = true;
                do
                {
                    // First obtain desired compactness
                    bool attempt_failed = true;
                    tot_attempt_success = true;
                    int   ctr = 0, ctrLmt = 100;
                    float df = (tSH - tSL);
                    //first we create a highly compact object, a little more compact than was asked for.
                    float nwTCH = tCH + 0.4f * tCH;
                    do
                    {
                        m.regenerate();
                        modified_obj = m.generate_off_obj();

                        if (modified_obj.compactess() < nwTCH)
                        {
                            attempt_failed = !modify_compactness(nwTCH, true);
                        }
                        ctr++;
                    } while (attempt_failed && ctr < ctrLmt);
                    if (ctr >= ctrLmt)
                    {
                        tot_attempt_success = false;
                    }
                    // Now modify Assymettry
                    if (tot_attempt_success)
                    {
                        attempt_failed = true;
                        ctr            = 0; ctrLmt = 100;
                        Matrix4x4 tmp = Matrix4x4.identity;
                        tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f;
                        do
                        {
                            if (modified_obj.degree_of_asymmetry() < tSH)
                            {
                                float ll = (float)Helper.get_random_double(tSH, tSH + df / 4.0f);
                                attempt_failed = !modify_symmetry(ll, 1.0f, tmp);
                            }
                            ctr++;
                        } while (attempt_failed && ctr < ctrLmt);
                        if (ctr >= ctrLmt)
                        {
                            tot_attempt_success = false;
                        }
                    }
                    outCntr++;
                } while (!tot_attempt_success && outCntr < outCntrLmt);

                if ((modified_obj.degree_of_asymmetry() >= tSH) && (modified_obj.compactess() >= tCH))
                {
                    isSat = true;
                }
                outOutCntr++;
            } while (outOutCntr < outOutCntrLmt && !isSat);

            ret = isSat;
        }
        #endregion

        #region 8) Asymmetric and in between Compact
        /* 7) ***************** Asymmetric and in between Compact ******************/
        if (isSym == -1 && isCmp == 0)
        {
            bool isSat = false;
            int  outOutCntr = 0, outOutCntrLmt = 100;
            do
            {
                int  outCntr = 0, outCntrLmt = 100;
                bool tot_attempt_success = true;
                do
                {
                    // First obtain desired compactness
                    bool attempt_failed = true;
                    tot_attempt_success = true;
                    int   ctr = 0, ctrLmt = 100;
                    float df = (tSH - tSL);
                    //first we create a highly compact object, a little more compact than was asked for.
                    float nwTCH = tCH + 0.4f * tCH;
                    do
                    {
                        m.regenerate();
                        modified_obj = m.generate_off_obj();

                        float dfC = (tCH - tCL);
                        //The object is symmetric but if it is not compact
                        if (modified_obj.compactess() < tCH)
                        {
                            //float t = (float)Helper.get_random_double(tCL + (dfC / 2.0f), tCH );
                            attempt_failed = !modify_compactness(tCH, true);
                        }
                        //The object is symmetric but if it is compact
                        else if (modified_obj.compactess() > tCH)
                        {
                            //float t = (float)Helper.get_random_double(tCL + (dfC / 4.0f), tCH);
                            attempt_failed = !modify_compactness(tCH + dfC / 8.0f, false);
                        }
                        ctr++;
                    } while (attempt_failed && ctr < ctrLmt);
                    if (ctr >= ctrLmt)
                    {
                        tot_attempt_success = false;
                    }
                    // Now modify Assymettry
                    if (tot_attempt_success)
                    {
                        attempt_failed = true;
                        ctr            = 0; ctrLmt = 100;
                        Matrix4x4 tmp = Matrix4x4.identity;
                        tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f;
                        do
                        {
                            if (modified_obj.degree_of_asymmetry() < tSH)
                            {
                                float ll = (float)Helper.get_random_double(tSH, tSH + df / 4.0f);
                                attempt_failed = !modify_symmetry(ll, 1.0f, tmp);
                            }
                            ctr++;
                        } while (attempt_failed && ctr < ctrLmt);
                        if (ctr >= ctrLmt)
                        {
                            tot_attempt_success = false;
                        }
                    }
                    outCntr++;
                } while (!tot_attempt_success && outCntr < outCntrLmt);

                if ((modified_obj.degree_of_asymmetry() >= tSH) && (modified_obj.compactess() >= tCL) && (modified_obj.compactess() <= tCH))
                {
                    isSat = true;
                }
                outOutCntr++;
            } while (outOutCntr < outOutCntrLmt && !isSat);

            ret = isSat;
        }
        #endregion

        #region 9) Asymmetric and non-Compact
        /* 7) ***************** Asymmetric and non-Compact ******************/
        if (isSym == -1 && isCmp == -1)
        {
            bool isSat = false;
            int  outOutCntr = 0, outOutCntrLmt = 100;
            do
            {
                int  outCntr = 0, outCntrLmt = 100;
                bool tot_attempt_success = true;
                do
                {
                    // First obtain desired compactness
                    bool attempt_failed = true;
                    tot_attempt_success = true;
                    int   ctr = 0, ctrLmt = 100;
                    float df = (tSH - tSL);
                    //first we create a highly compact object, a little more compact than was asked for.
                    float nwTCH = tCH + 0.4f * tCH;
                    do
                    {
                        m.regenerate();
                        modified_obj = m.generate_off_obj();

                        float t = tCL + (tCH - tCL) / 2;
                        if (modified_obj.compactess() > t)
                        {
                            attempt_failed = !modify_compactness(t, false);
                        }
                        ctr++;
                    } while (attempt_failed && ctr < ctrLmt);
                    if (ctr >= ctrLmt)
                    {
                        tot_attempt_success = false;
                    }
                    // Now modify Assymettry
                    if (tot_attempt_success)
                    {
                        attempt_failed = true;
                        ctr            = 0; ctrLmt = 100;
                        Matrix4x4 tmp = Matrix4x4.identity;
                        tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f;
                        do
                        {
                            if (modified_obj.degree_of_asymmetry() < tSH)
                            {
                                float ll = (float)Helper.get_random_double(tSH, tSH + df / 4.0f);
                                attempt_failed = !modify_symmetry(ll, 1.0f, tmp);
                            }
                            ctr++;
                        } while (attempt_failed && ctr < ctrLmt);
                        if (ctr >= ctrLmt)
                        {
                            tot_attempt_success = false;
                        }
                    }
                    outCntr++;
                } while (!tot_attempt_success && outCntr < outCntrLmt);

                if ((modified_obj.degree_of_asymmetry() >= tSH) && (modified_obj.compactess() <= tCL) && (modified_obj.compactess() >= 0.11))
                {
                    isSat = true;
                }
                outOutCntr++;
            } while (outOutCntr < outOutCntrLmt && !isSat);

            ret = isSat;
        }
        #endregion

        return(ret);
    }