"Fossies" - the Fresh Open Source Software Archive

Member "mathmod-branches-r508-trunk/ui_modules/mathmod.cpp" (8 Mar 2021, 71980 Bytes) of package /linux/misc/mathmod-11.0-source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mathmod.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 10.1_vs_11.0.

    1 /***************************************************************************
    2  *   Copyright (C) 2021 by Abderrahman Taha                                *
    3  *                                                                         *
    4  *                                                                         *
    5  *   This program is free software; you can redistribute it and/or modify  *
    6  *   it under the terms of the GNU General Public License as published by  *
    7  *   the Free Software Foundation; either version 2 of the License, or     *
    8  *   (at your option) any later version.                                   *
    9  *                                                                         *
   10  *   This program is distributed in the hope that it will be useful,       *
   11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
   12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
   13  *   GNU General Public License for more details.                          *
   14  *                                                                         *
   15  *   You should have received a copy of the GNU General Public License     *
   16  *   along with this program; if not, write to the                         *
   17  *   Free Software Foundation, Inc.,                                       *
   18  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
   19  ***************************************************************************/
   20 #include "mathmod.h"
   21 
   22 void MathMod::CalculateTexturePoints(int type)
   23 {
   24     double tmp, val[6]={0,0,0,0,0,0};
   25     uint Jprime;
   26     if (type == 1)
   27     {
   28         LocalScene.componentsinfos.ThereisRGBA[0] = true;
   29         LocalScene.componentsinfos.NoiseParam[0].NoiseType = 1;
   30         LocalScene.componentsinfos.NoiseParam[0].RgbtParser =
   31             IsoObjet->masterthread->RgbtParser;
   32         LocalScene.componentsinfos.NoiseParam[0].NoiseParser =
   33             IsoObjet->masterthread->NoiseParser;
   34         IsoObjet->masterthread->Noise == ""
   35         ? LocalScene.componentsinfos.NoiseParam[0].NoiseShape = 0
   36                 : LocalScene.componentsinfos.NoiseParam[0].NoiseShape = 1;
   37     }
   38     if (type == 0)
   39     {
   40         LocalScene.componentsinfos.ThereisRGBA[0] = true;
   41         LocalScene.componentsinfos.NoiseParam[0].NoiseType = 1;
   42         LocalScene.componentsinfos.NoiseParam[0].RgbtParser =
   43             ParObjet->masterthread->RgbtParser;
   44         LocalScene.componentsinfos.NoiseParam[0].NoiseParser =
   45             ParObjet->masterthread->NoiseParser;
   46         ParObjet->masterthread->Noise == ""
   47         ? LocalScene.componentsinfos.NoiseParam[0].NoiseShape = 0
   48                 : LocalScene.componentsinfos.NoiseParam[0].NoiseShape = 1;
   49     }
   50     for (uint i = 0; i < LocalScene.VertxNumber; i++)
   51     {
   52         val[0] = difMaximum *
   53                  double(LocalScene.ArrayNorVer_localPt[i * 10 + 7]) /
   54                  hauteur_fenetre -
   55                  decalage_xo;
   56         val[1] = difMaximum *
   57                  double(LocalScene.ArrayNorVer_localPt[i * 10 + 8]) /
   58                  hauteur_fenetre -
   59                  decalage_yo;
   60         val[2] = difMaximum *
   61                  double(LocalScene.ArrayNorVer_localPt[i * 10 + 9]) /
   62                  hauteur_fenetre -
   63                  decalage_zo;
   64         if (type != 1)
   65         {
   66             Jprime = (i) % (ParObjet->Vgrid);
   67             val[3] = double(Jprime) / double(ParObjet->Vgrid);
   68             val[3] = val[3] * ParObjet->masterthread->dif_u[0] +
   69                      ParObjet->masterthread->u_inf[0];
   70             Jprime = (i) / (ParObjet->Ugrid);
   71             val[4] = double(Jprime) / double(ParObjet->Ugrid);
   72             val[4] = val[4] * ParObjet->masterthread->dif_v[0] +
   73                      ParObjet->masterthread->v_inf[0];
   74         }
   75         if (LocalScene.componentsinfos.NoiseParam[0].NoiseShape != 0)
   76         {
   77             tmp = LocalScene.componentsinfos.NoiseParam[0].NoiseParser->Eval(val);
   78         }
   79         else
   80         {
   81             tmp = 1.0;
   82         }
   83         val[0] *= tmp;
   84         val[1] *= tmp;
   85         val[2] *= tmp;
   86         // val[3] and val[4] uninitialized!
   87         val[3] *= tmp;
   88         val[4] *= tmp;
   89         LocalScene.ArrayNorVer_localPt[i * 10] =
   90             float(LocalScene.componentsinfos.NoiseParam[0].RgbtParser[0].Eval(val));
   91         LocalScene.ArrayNorVer_localPt[i * 10 + 1] =
   92             float(LocalScene.componentsinfos.NoiseParam[0].RgbtParser[1].Eval(val));
   93         LocalScene.ArrayNorVer_localPt[i * 10 + 2] =
   94             float(LocalScene.componentsinfos.NoiseParam[0].RgbtParser[2].Eval(val));
   95         LocalScene.ArrayNorVer_localPt[i * 10 + 3] =
   96             float(LocalScene.componentsinfos.NoiseParam[0].RgbtParser[3].Eval(val));
   97     }
   98 }
   99 
  100 void MathMod::CalculatePigmentPoints(int type)
  101 {
  102     double tmp, ValCol[100], val[4];
  103     if (type == 1)
  104     {
  105         LocalScene.componentsinfos.ThereisRGBA[0] = true;
  106         LocalScene.componentsinfos.NoiseParam[0].NoiseType = 0; // Pigments
  107         LocalScene.componentsinfos.NoiseParam[0].VRgbtParser =
  108             IsoObjet->masterthread->VRgbtParser;
  109         LocalScene.componentsinfos.NoiseParam[0].GradientParser =
  110             IsoObjet->masterthread->GradientParser;
  111         LocalScene.componentsinfos.NoiseParam[0].Nb_vrgbts =
  112             IsoObjet->masterthread->VRgbtSize;
  113         LocalScene.componentsinfos.NoiseParam[0].NoiseParser =
  114             IsoObjet->masterthread->NoiseParser;
  115         IsoObjet->masterthread->Noise == ""
  116         ? LocalScene.componentsinfos.NoiseParam[0].NoiseShape = 0
  117                 : LocalScene.componentsinfos.NoiseParam[0].NoiseShape = 1;
  118     }
  119     if (type == 0)
  120     {
  121         LocalScene.componentsinfos.ThereisRGBA[0] = true;
  122         LocalScene.componentsinfos.NoiseParam[0].NoiseType = 0; // Pigments
  123         LocalScene.componentsinfos.NoiseParam[0].VRgbtParser =
  124             ParObjet->masterthread->VRgbtParser;
  125         LocalScene.componentsinfos.NoiseParam[0].GradientParser =
  126             ParObjet->masterthread->GradientParser;
  127         LocalScene.componentsinfos.NoiseParam[0].Nb_vrgbts =
  128             ParObjet->masterthread->VRgbtSize;
  129         LocalScene.componentsinfos.NoiseParam[0].NoiseParser =
  130             ParObjet->masterthread->NoiseParser;
  131         ParObjet->masterthread->Noise == ""
  132         ? LocalScene.componentsinfos.NoiseParam[0].NoiseShape = 0
  133                 : LocalScene.componentsinfos.NoiseParam[0].NoiseShape = 1;
  134     }
  135     for (uint i = 0;
  136             i < LocalScene.componentsinfos.NoiseParam[0].Nb_vrgbts && i < 100; i++)
  137     {
  138         ValCol[i] =
  139             LocalScene.componentsinfos.NoiseParam[0].VRgbtParser[i].Eval(val);
  140     }
  141     for (uint i = 0; i < LocalScene.VertxNumber; i++)
  142     {
  143         val[0] = difMaximum *
  144                  double(LocalScene.ArrayNorVer_localPt[i * 10 + 7]) /
  145                  hauteur_fenetre -
  146                  decalage_xo;
  147         val[1] = difMaximum *
  148                  double(LocalScene.ArrayNorVer_localPt[i * 10 + 8]) /
  149                  hauteur_fenetre -
  150                  decalage_yo;
  151         val[2] = difMaximum *
  152                  double(LocalScene.ArrayNorVer_localPt[i * 10 + 9]) /
  153                  hauteur_fenetre -
  154                  decalage_zo;
  155         if (LocalScene.componentsinfos.NoiseParam[0].NoiseShape != 0)
  156             tmp = LocalScene.componentsinfos.NoiseParam[0].NoiseParser->Eval(val);
  157         else
  158             tmp = 1.0;
  159         val[0] *= tmp;
  160         val[1] *= tmp;
  161         val[2] *= tmp;
  162         tmp = LocalScene.componentsinfos.NoiseParam[0].GradientParser->Eval(val);
  163         int c = int(tmp);
  164         tmp = std::abs(tmp - double(c));
  165         for (uint j = 0;
  166                 j < LocalScene.componentsinfos.NoiseParam[0].Nb_vrgbts && j < 100;
  167                 j += 5)
  168             if (tmp <= ValCol[j])
  169             {
  170                 LocalScene.ArrayNorVer_localPt[i*10  ] = float(ValCol[j+1]);
  171                 LocalScene.ArrayNorVer_localPt[i*10+1] = float(ValCol[j+2]);
  172                 LocalScene.ArrayNorVer_localPt[i*10+2] = float(ValCol[j+3]);
  173                 LocalScene.ArrayNorVer_localPt[i*10+3] = float(ValCol[j+4]);
  174                 j = 100;
  175             }
  176     }
  177 }
  178 
  179 int MathMod::memoryallocation(uint nbthreads,
  180                                    uint initparGrid, uint initisoGrid,
  181                                    uint FactX, uint FactY, uint FactZ)
  182 {
  183     try
  184     {
  185         IsoObjet = new Iso3D(nbthreads, initisoGrid, FactX, FactY, FactZ);
  186         ParObjet = new Par3D(nbthreads, initparGrid);
  187         return 1;
  188     }
  189     catch (std::bad_alloc &)
  190     {
  191         message.setText("Not enough memory available to complete this operation");
  192         message.adjustSize();
  193         message.exec();
  194         return -1;
  195     }
  196 }
  197 
  198 void MathMod::SaveSceneAsObjPoly(int type)
  199 {
  200     int startpl = 0;
  201     uint actualpointindice;
  202     QString fileName = QFileDialog::getSaveFileName(this, tr("Save OBJ file"), "",
  203                        tr("OBJ Files (*.obj)"));
  204     QFile data(fileName);
  205     if (data.open(QFile::ReadWrite | QFile::Truncate))
  206     {
  207         uint i;
  208         QTextStream stream(&data);
  209         stream.setRealNumberNotation(QTextStream::FixedNotation);
  210         stream.setRealNumberPrecision(3);
  211         // save vertices:
  212         if (type == 1)
  213         {
  214             for (i = 0; i < LocalScene.VertxNumber; i++)
  215             {
  216                 (stream) << "v "
  217                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) *
  218                                   (difMaximum*factx/ hauteur_fenetre) - decalage_xo)
  219                          << "  "
  220                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) *
  221                                   (difMaximum*facty / hauteur_fenetre) - decalage_yo)
  222                          << "  "
  223                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) *
  224                                   (difMaximum*factz / hauteur_fenetre) - decalage_zo)
  225                          << "  " << LocalScene.ArrayNorVer_localPt[10 * i] << "  "
  226                          << LocalScene.ArrayNorVer_localPt[10 * i + 1] << "  "
  227                          << LocalScene.ArrayNorVer_localPt[10 * i + 2] << "\n";
  228             }
  229         }
  230         else
  231         {
  232             for (i = 0; i < LocalScene.VertxNumber; i++)
  233             {
  234                 (stream) << "v "
  235                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) *
  236                                   (difMaximum*factx / hauteur_fenetre) - decalage_xo)
  237                          << "  "
  238                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) *
  239                                   (difMaximum*facty / hauteur_fenetre) - decalage_yo)
  240                          << "  "
  241                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) *
  242                                   (difMaximum*factz / hauteur_fenetre) - decalage_zo)
  243                          << "\n";
  244             }
  245         }
  246         // save faces:
  247         startpl = LocalScene.PolyNumber;
  248         for (i = 0; i < LocalScene.NbPolygnNbVertexPtMin; i++)
  249         {
  250             uint polysize = LocalScene.PolyIndices_localPtMin[i];
  251             (stream) << "f";
  252             for (uint j = 0; j < polysize; j++)
  253             {
  254                 actualpointindice = LocalScene.PolyIndices_localPt[startpl++]+1;
  255                 (stream) << "  " << actualpointindice;
  256             }
  257             (stream) << "\n";
  258         }
  259     }
  260 }
  261 
  262 void MathMod::SaveSceneAsObjTrian(int type)
  263 {
  264     QString fileName = QFileDialog::getSaveFileName(this, tr("Save OBJ file"), "",
  265                        tr("OBJ Files (*.obj)"));
  266     QFile data(fileName);
  267     if (data.open(QFile::ReadWrite | QFile::Truncate))
  268     {
  269         uint i;
  270         QTextStream stream(&data);
  271         stream.setRealNumberNotation(QTextStream::FixedNotation);
  272         stream.setRealNumberPrecision(3);
  273         // save vertices:
  274         if (type == 1)
  275         {
  276             for (i = 0; i < LocalScene.VertxNumber; i++)
  277             {
  278                 (stream) << "v "
  279                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) *
  280                                   (difMaximum*factx / hauteur_fenetre) - decalage_xo)
  281                          << "  "
  282                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) *
  283                                   (difMaximum*facty / hauteur_fenetre) - decalage_yo)
  284                          << "  "
  285                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) *
  286                                   (difMaximum*factz / hauteur_fenetre) - decalage_zo)
  287                          << "  " << LocalScene.ArrayNorVer_localPt[10 * i] << "  "
  288                          << LocalScene.ArrayNorVer_localPt[10 * i + 1] << "  "
  289                          << LocalScene.ArrayNorVer_localPt[10 * i + 2] << "\n";
  290             }
  291         }
  292         else
  293         {
  294             for (i = 0; i < LocalScene.VertxNumber; i++)
  295             {
  296                 (stream) << "v "
  297                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) *
  298                                   (difMaximum*factx / hauteur_fenetre) - decalage_xo)
  299                          << "  "
  300                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) *
  301                                   (difMaximum*facty / hauteur_fenetre) - decalage_yo)
  302                          << "  "
  303                          << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) *
  304                                   (difMaximum*factz / hauteur_fenetre) - decalage_zo)
  305                          << "\n";
  306             }
  307         }
  308         for (i = 0; i < LocalScene.PolyNumber; i += 3)
  309         {
  310             (stream) << "f "
  311                      << "  " << LocalScene.PolyIndices_localPt[i] + 1 << "  "
  312                      << LocalScene.PolyIndices_localPt[i + 1] + 1 << "  "
  313                      << LocalScene.PolyIndices_localPt[i + 2] + 1 << "\n";
  314         }
  315     }
  316 }
  317 
  318 MathMod::~MathMod()
  319 {
  320     delete (timer);
  321     delete ParObjet;
  322     delete IsoObjet;
  323 }
  324 
  325 void MathMod::PutObjectInsideCube()
  326 {
  327     minx = 999999999.0;
  328     miny = 999999999.0;
  329     minz = 999999999.0;
  330     maxx = -999999999.0;
  331     maxy = -999999999.0;
  332     maxz = -999999999.0;
  333     if ((LocalScene.morph != 1 ||
  334             (LocalScene.morph == 1 && FistTimecalibrate == 1)) &&
  335             LocalScene.slider != 1)
  336     {
  337         for (uint i = 0; i < LocalScene.VertxNumber; i++)
  338         {
  339             if (minx > LocalScene.ArrayNorVer_localPt[10 * i + 3 + 4])
  340                 minx = LocalScene.ArrayNorVer_localPt[10 * i + 3 + 4];
  341             if (miny > LocalScene.ArrayNorVer_localPt[10 * i + 4 + 4])
  342                 miny = LocalScene.ArrayNorVer_localPt[10 * i + 4 + 4];
  343             if (minz > LocalScene.ArrayNorVer_localPt[10 * i + 5 + 4])
  344                 minz = LocalScene.ArrayNorVer_localPt[10 * i + 5 + 4];
  345 
  346             if (maxx < LocalScene.ArrayNorVer_localPt[10 * i + 3 + 4])
  347                 maxx = LocalScene.ArrayNorVer_localPt[10 * i + 3 + 4];
  348             if (maxy < LocalScene.ArrayNorVer_localPt[10 * i + 4 + 4])
  349                 maxy = LocalScene.ArrayNorVer_localPt[10 * i + 4 + 4];
  350             if (maxz < LocalScene.ArrayNorVer_localPt[10 * i + 5 + 4])
  351                 maxz = LocalScene.ArrayNorVer_localPt[10 * i + 5 + 4];
  352         }
  353         FistTimecalibrate = -1;
  354         oldminx = minx; oldminy = miny; oldminz=minz;
  355         oldmaxx = maxx; oldmaxy = maxy; oldmaxz=maxz;
  356         difX = maxx - minx;
  357         difY = maxy - miny;
  358         difZ = maxz - minz;
  359         // Recherche du maximum :
  360         difMaximum = double(difX);
  361         if (difY > float(difMaximum))
  362         {
  363             difMaximum = double(difY);
  364         }
  365         if (difZ > float(difMaximum))
  366         {
  367             difMaximum = double(difZ);
  368         }
  369         /// On va inclure cet objet dans un cube de langueur maximum
  370         /// egale a "hauteur_fenetre"
  371         decalage_xo = -double(minx + maxx) / 2;
  372         decalage_yo = -double(miny + maxy) / 2;
  373         decalage_zo = -double(minz + maxz) / 2;
  374     }
  375     for (uint i = 0; i < LocalScene.VertxNumber; i++)
  376     {
  377         LocalScene.ArrayNorVer_localPt[10 * i + 7] = float(
  378                     hauteur_fenetre *
  379                     (double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) + decalage_xo) /
  380                     difMaximum);
  381         LocalScene.ArrayNorVer_localPt[10 * i + 8] = float(
  382                     hauteur_fenetre *
  383                     (double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) + decalage_yo) /
  384                     difMaximum);
  385         LocalScene.ArrayNorVer_localPt[10 * i + 9] = float(
  386                     hauteur_fenetre *
  387                     (double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) + decalage_zo) /
  388                     difMaximum);
  389     }
  390 
  391     // Cube vertices and indexes
  392     float longX = wh * float(difX / float(difMaximum)),
  393           longY = wh * (difY / float(difMaximum)),
  394           longZ = wh * (difZ / float(difMaximum));
  395     uint NbVert = LocalScene.VertxNumber;
  396     CubeStartIndex=NbVert;
  397     for(uint id=0; id<12; id++)
  398     {
  399         LocalScene.ArrayNorVer_localPt[10 * (NbVert+id) + 0] = 0.8f;
  400         LocalScene.ArrayNorVer_localPt[10 * (NbVert+id) + 1] = 0.8f;
  401         LocalScene.ArrayNorVer_localPt[10 * (NbVert+id) + 2] = 0.8f;
  402         LocalScene.ArrayNorVer_localPt[10 * (NbVert+id) + 3] = 1.0f;
  403     }
  404 
  405     LocalScene.ArrayNorVer_localPt[10 * NbVert + 7] = -longX;
  406     LocalScene.ArrayNorVer_localPt[10 * NbVert + 8] = -longY;
  407     LocalScene.ArrayNorVer_localPt[10 * NbVert + 9] = -longZ;
  408 
  409     LocalScene.ArrayNorVer_localPt[10 * (NbVert+1) + 7] =  longX;
  410     LocalScene.ArrayNorVer_localPt[10 * (NbVert+1) + 8] = -longY;
  411     LocalScene.ArrayNorVer_localPt[10 * (NbVert+1) + 9] = -longZ;
  412 
  413     LocalScene.ArrayNorVer_localPt[10 * (NbVert+2) + 7] =  longX;
  414     LocalScene.ArrayNorVer_localPt[10 * (NbVert+2) + 8] =  longY;
  415     LocalScene.ArrayNorVer_localPt[10 * (NbVert+2) + 9] = -longZ;
  416 
  417     LocalScene.ArrayNorVer_localPt[10 * (NbVert+3) + 7] = -longX;
  418     LocalScene.ArrayNorVer_localPt[10 * (NbVert+3) + 8] =  longY;
  419     LocalScene.ArrayNorVer_localPt[10 * (NbVert+3) + 9] = -longZ;
  420 
  421     LocalScene.ArrayNorVer_localPt[10 * (NbVert+4) + 7] = -longX;
  422     LocalScene.ArrayNorVer_localPt[10 * (NbVert+4) + 8] = -longY;
  423     LocalScene.ArrayNorVer_localPt[10 * (NbVert+4) + 9] = -longZ;
  424 
  425     LocalScene.ArrayNorVer_localPt[10 * (NbVert+5) + 7] = -longX;
  426     LocalScene.ArrayNorVer_localPt[10 * (NbVert+5) + 8] = -longY;
  427     LocalScene.ArrayNorVer_localPt[10 * (NbVert+5) + 9] =  longZ;
  428 
  429     LocalScene.ArrayNorVer_localPt[10 * (NbVert+6) + 7] = -longX;
  430     LocalScene.ArrayNorVer_localPt[10 * (NbVert+6) + 8] =  longY;
  431     LocalScene.ArrayNorVer_localPt[10 * (NbVert+6) + 9] =  longZ;
  432 
  433     LocalScene.ArrayNorVer_localPt[10 * (NbVert+7) + 7] = -longX;
  434     LocalScene.ArrayNorVer_localPt[10 * (NbVert+7) + 8] =  longY;
  435     LocalScene.ArrayNorVer_localPt[10 * (NbVert+7) + 9] = -longZ;
  436 
  437     LocalScene.ArrayNorVer_localPt[10 * (NbVert+8) + 7] = -longX;
  438     LocalScene.ArrayNorVer_localPt[10 * (NbVert+8) + 8] = -longY;
  439     LocalScene.ArrayNorVer_localPt[10 * (NbVert+8) + 9] = -longZ;
  440 
  441     LocalScene.ArrayNorVer_localPt[10 * (NbVert+9) + 7] = -longX;
  442     LocalScene.ArrayNorVer_localPt[10 * (NbVert+9) + 8] = -longY;
  443     LocalScene.ArrayNorVer_localPt[10 * (NbVert+9) + 9] =  longZ;
  444 
  445     LocalScene.ArrayNorVer_localPt[10 * (NbVert+10) + 7] =  longX;
  446     LocalScene.ArrayNorVer_localPt[10 * (NbVert+10) + 8] = -longY;
  447     LocalScene.ArrayNorVer_localPt[10 * (NbVert+10) + 9] =  longZ;
  448 
  449     LocalScene.ArrayNorVer_localPt[10 * (NbVert+11) + 7] =  longX;
  450     LocalScene.ArrayNorVer_localPt[10 * (NbVert+11) + 8] = -longY;
  451     LocalScene.ArrayNorVer_localPt[10 * (NbVert+11) + 9] = -longZ;
  452 
  453     // Plan vertices and indexes
  454     PlanStartIndex=NbVert+12;
  455     for(uint id=0; id<60; id++)
  456     {
  457         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+id)+0] = 0.6f;
  458         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+id)+1] = 0.6f;
  459         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+id)+2] = 0.6f;
  460         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+id)+3] = 1.0f;
  461         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+id)+7] = PlanArray[3*id  ];
  462         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+id)+8] = PlanArray[3*id+1];
  463         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+id)+9] = PlanArray[3*id+2];
  464     }
  465 
  466     // Axes vertices and indexes
  467     AxesStartIndex = NbVert+12+60;
  468     for(uint id=0; id<6; id++)
  469     {
  470         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+id)+0] = (id<2)?2.0f:0.0;
  471         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+id)+1] = (id>1)&&(id<4)?2.0f:0.0;
  472         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+id)+2] = (id>3)?2.0f:0.0;
  473         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+id)+3] = 1.0f;
  474         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+id)+7] = AxeArray[3*id  ];
  475         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+id)+8] = AxeArray[3*id+1];
  476         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+id)+9] = AxeArray[3*id+2];
  477     }
  478 
  479     // Head of the X Axe
  480     XStartIndex = NbVert+12+60+6;
  481     for(uint id=0; id<6; id++)
  482     {
  483         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+6+id)+0] = (id<2)?2.0f:0.3;
  484         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+6+id)+1] = 0.0;
  485         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+6+id)+2] = 0.0;
  486         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+6+id)+3] = 1.0f;
  487         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+6+id)+7] = AxeArray[3*(id+6)  ];
  488         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+6+id)+8] = AxeArray[3*(id+6)+1];
  489         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+6+id)+9] = AxeArray[3*(id+6)+2];
  490     }
  491 
  492     // Head of the Y Axe
  493     YStartIndex = NbVert+12+60+12;
  494     for(uint id=0; id<6; id++)
  495     {
  496         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+12+id)+0] = 0.0;
  497         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+12+id)+1] = (id<2)?2.0f:0.3;
  498         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+12+id)+2] = 0.0;
  499         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+12+id)+3] = 1.0f;
  500         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+12+id)+7] = AxeArray[3*(id+12)  ];
  501         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+12+id)+8] = AxeArray[3*(id+12)+1];
  502         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+12+id)+9] = AxeArray[3*(id+12)+2];
  503     }
  504 
  505     // Head of the Z Axe
  506     ZStartIndex = NbVert+12+60+18;
  507     for(uint id=0; id<6; id++)
  508     {
  509         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+18+id)+0] = 0.0;
  510         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+18+id)+1] = 0.0;
  511         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+18+id)+2] = (id<2)?2.0f:0.3;
  512         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+18+id)+3] = 1.0f;
  513         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+18+id)+7] = AxeArray[3*(id+18)  ];
  514         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+18+id)+8] = AxeArray[3*(id+18)+1];
  515         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+18+id)+9] = AxeArray[3*(id+18)+2];
  516     }
  517 
  518     // Letter X Axe
  519     XletterIndex = NbVert+12+60+24;
  520     for(uint id=0; id<4; id++)
  521     {
  522         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+24+id)+0] = 2.0;
  523         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+24+id)+1] = 0.0;
  524         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+24+id)+2] = 0.0;
  525         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+24+id)+3] = 1.0f;
  526         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+24+id)+7] = AxeArray[3*(id+24)  ];
  527         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+24+id)+8] = AxeArray[3*(id+24)+1];
  528         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+24+id)+9] = AxeArray[3*(id+24)+2];
  529     }
  530     // Letter Y Axe
  531     YletterIndex = NbVert+12+60+28;
  532     for(uint id=0; id<4; id++)
  533     {
  534         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+28+id)+0] = 0.0;
  535         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+28+id)+1] = 2.0;
  536         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+28+id)+2] = 0.0;
  537         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+28+id)+3] = 1.0f;
  538         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+28+id)+7] = AxeArray[3*(id+28)  ];
  539         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+28+id)+8] = AxeArray[3*(id+28)+1];
  540         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+28+id)+9] = AxeArray[3*(id+28)+2];
  541     }
  542     // Letter Y Axe
  543     ZletterIndex = NbVert+12+60+32;
  544     for(uint id=0; id<4; id++)
  545     {
  546         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+0] = 0.0;
  547         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+1] = 0.0;
  548         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+2] = 2.0;
  549         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+3] = 1.0f;
  550         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+7] = AxeArray[3*(id+32)  ];
  551         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+8] = AxeArray[3*(id+32)+1];
  552         LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+9] = AxeArray[3*(id+32)+2];
  553     }
  554 
  555     labelinfos = "  \n Grid     : ";
  556     (LocalScene.typedrawing == 1)
  557     ? labelinfos += QString::number(Xgrid - CutX) + "x" +
  558             QString::number(Ygrid - CutY) + "x" +
  559             QString::number(Zgrid - CutZ) +" \n"
  560             : labelinfos += QString::number(Ugrid - CutU) + "x" +
  561                     QString::number(Vgrid - CutV) +" \n";
  562     labelinfos+=" Vertices : "+QString::number(LocalScene.VertxNumber)+" \n"+
  563                            " Triangles: "+QString::number(LocalScene.PolyNumber/3)+" \n"
  564                            " Polygons : "+QString::number(LocalScene.NbPolygnNbVertexPtMin)+" \n";
  565    if(LocalScene.morph==-1)
  566        labelinfos+=" X["+QString::number(minx,'g',3)+","+QString::number(maxx,'g',3)+"]\n\
  567  Y["+QString::number(miny,'g',3)+","+QString::number(maxy,'g',3)+"]\n\
  568  Z["+QString::number(minz,'g',3)+","+QString::number(maxz,'g',3)+"]\n";
  569 else
  570        labelinfos+=" X["+QString::number(oldminx,'g',3)+","+QString::number(oldmaxx,'g',3)+"]\n\
  571  Y["+QString::number(oldminy,'g',3)+","+QString::number(oldmaxy,'g',3)+"]\n\
  572  Z["+QString::number(oldminz,'g',3)+","+QString::number(oldmaxz,'g',3)+"]\n";
  573 
  574     if(LocalScene.morph==1)
  575     {
  576         if(LocalScene.anim==-1)
  577             LabelInfos.setText(labelinfos+" Morph: ON \n");
  578         else
  579             LabelInfos.setText(labelinfos+" Rotation/Morph: ON \n");
  580     }
  581     else
  582     {
  583         if(LocalScene.anim==-1)
  584             LabelInfos.setText(labelinfos);
  585         else
  586             LabelInfos.setText(labelinfos+" Rotation: ON \n");
  587     }
  588 }
  589 
  590 void MathMod::png()
  591 {
  592     LocalScene.png_ok *= -1;
  593 }
  594 
  595 void MathMod::jpg()
  596 {
  597     LocalScene.jpg_ok *= -1;
  598 }
  599 
  600 void MathMod::bmp()
  601 {
  602     LocalScene.bmp_ok *= -1;
  603 }
  604 
  605 void MathMod::quality(int c)
  606 {
  607     LocalScene.quality_image = c;
  608 }
  609 
  610 void MathMod::colorstype(int c)
  611 {
  612     LocalScene.colortype = c;
  613 }
  614 
  615 void MathMod::colorstypeParIso(int c)
  616 {
  617     LocalScene.colortype = LocalScene.colortypeParam = c;
  618 }
  619 
  620 void MathMod::colorstypeParam(int c)
  621 {
  622     LocalScene.colortypeParam = c;
  623 }
  624 
  625 void MathMod::redSpec(int cl)
  626 {
  627     lightSpecular[0] = (cl/ 100.0f);
  628     LocalScene.ShininessValUpdated=true;
  629     update();
  630 }
  631 
  632 void MathMod::greenSpec(int cl)
  633 {
  634     lightSpecular[1] = (cl/ 100.0f);
  635     LocalScene.ShininessValUpdated=true;
  636     update();
  637 }
  638 
  639 void MathMod::blueSpec(int cl)
  640 {
  641     lightSpecular[2] = (cl/ 100.0f);
  642     LocalScene.ShininessValUpdated=true;
  643     update();
  644 }
  645 
  646 void MathMod::redAmb(int cl)
  647 {
  648     lightAmbient[0] = (cl/ 100.0f);
  649     LocalScene.AmbientValUpdated=true;
  650     update();
  651 }
  652 
  653 void MathMod::greenAmb(int cl)
  654 {
  655     lightAmbient[1] = (cl/ 100.0f);
  656     LocalScene.AmbientValUpdated=true;
  657     update();
  658 }
  659 
  660 void MathMod::blueAmb(int cl)
  661 {
  662     lightAmbient[2] = (cl/100.0f);
  663     LocalScene.AmbientValUpdated=true;
  664     update();
  665 }
  666 
  667 void MathMod::transAmb(int cl)
  668 {
  669     lightAmbient[3] = (cl/100.0f);
  670     LocalScene.AmbientValUpdated=true;
  671     update();
  672 }
  673 
  674 void MathMod::redDiff(int cl)
  675 {
  676     lightDiffuse[0] = (cl/100.0f);
  677     LocalScene.DiffuseValUpdated=true;
  678     update();
  679 }
  680 
  681 void MathMod::greenDiff(int cl)
  682 {
  683     lightDiffuse[1] = (cl/100.0f);
  684     LocalScene.DiffuseValUpdated=true;
  685     update();
  686 }
  687 
  688 void MathMod::blueDiff(int cl)
  689 {
  690     lightDiffuse[2] = (cl/100.0f);
  691     LocalScene.DiffuseValUpdated=true;
  692     update();
  693 }
  694 
  695 void MathMod::transDiff(int cl)
  696 {
  697     lightDiffuse[3] = (cl/ 100.0f);
  698     LocalScene.DiffuseValUpdated=true;
  699     update();
  700 }
  701 
  702 void MathMod::drawCube()
  703 {
  704     glLineWidth(1.0);
  705     glUniform1i(uniformThereisRGBA, 0);
  706     glDrawArrays(GL_LINE_STRIP,CubeStartIndex, 12);
  707 }
  708 
  709 void MathMod::DrawPariso(ObjectProperties *scene, uint ParisoTypeIndex)
  710 {
  711     uint idx = 0;
  712     for (uint i = 0; i < ParisoTypeIndex; i++)
  713         idx += scene->componentsinfos.NbComponentsType[i];
  714     int start_triangle = scene->componentsinfos.ParisoTriangle[2 * idx];
  715     float frontcl[4], backcl[4];
  716     glEnable(GL_POLYGON_OFFSET_FILL);
  717     glPolygonOffset(scene->polyfactor, scene->polyunits);
  718     if (!scene->componentsinfos.ThereisRGBA[ParisoTypeIndex])
  719     {
  720         for (uint j = 0; j < 4; j++)
  721         {
  722             frontcl[j] = scene->frontcols[j];
  723             backcl[j] = scene->backcols[j];
  724         }
  725         glUniform4fv(uniformFrontColor, 1, frontcl);
  726         glUniform4fv(uniformBackColor, 1, backcl);
  727         glUniform1i(uniformThereisRGBA, 1);
  728     }
  729 
  730     if (scene->componentsinfos.ThereisCND[ParisoTypeIndex])
  731     {
  732         size_t Offset0 = start_triangle*sizeof( GL_FLOAT);
  733         glDrawElements(
  734             GL_TRIANGLES,
  735             int(3 * (scene->componentsinfos.NbTrianglesNoCND[ParisoTypeIndex])),
  736             GL_UNSIGNED_INT, (void *)(Offset0));
  737 
  738         if (scene->cndoptions[0])
  739         {
  740             size_t Offset1 = (3 * scene->componentsinfos.NbTrianglesNoCND[ParisoTypeIndex] +start_triangle)*sizeof( GL_FLOAT);
  741             glDrawElements(
  742                 GL_TRIANGLES,
  743                 int(3 * (scene->componentsinfos.NbTrianglesVerifyCND[ParisoTypeIndex])),
  744                 GL_UNSIGNED_INT, (void *)(Offset1));
  745         }
  746 
  747         if (scene->cndoptions[1])
  748         {
  749             size_t Offset2 = (3 * scene->componentsinfos.NbTrianglesNoCND[ParisoTypeIndex] +
  750                               3 * scene->componentsinfos.NbTrianglesVerifyCND[ParisoTypeIndex] +
  751                               start_triangle)*sizeof( GL_FLOAT);
  752             glDrawElements(
  753                 GL_TRIANGLES,
  754                 int(3 * (scene->componentsinfos.NbTrianglesNotVerifyCND[ParisoTypeIndex])),
  755                 GL_UNSIGNED_INT,
  756                 (void *)(Offset2));
  757         }
  758     }
  759     else
  760     {
  761         for (uint i = 0; i < scene->componentsinfos.NbComponentsType[ParisoTypeIndex]; i++)
  762         {
  763             uint cmpIndex = (ParisoTypeIndex==1) ? (scene->componentsinfos.NbComponentsType[0]+i):i;
  764             if (scene->componentsinfos.ShowParIsoCmp[cmpIndex])
  765             {
  766                 if (!scene->componentsinfos.ThereisRGBA[ParisoTypeIndex])
  767                 {
  768                     for (uint j = 0; j < 4; j++)
  769                     {
  770                         frontcl[j] = scene->frontcols[4 * (i % 10) + j];
  771                         backcl[j] = scene->backcols[4 * (i % 10) + j];
  772                     }
  773                     glUniform4fv(uniformFrontColor, 1, frontcl);
  774                     glUniform4fv(uniformBackColor, 1, backcl);
  775                     glUniform1i(uniformThereisRGBA, 1);
  776                 }
  777                 else
  778                     glUniform1i(uniformThereisRGBA, 0);
  779                 {
  780                     size_t Offset = scene->componentsinfos.ParisoTriangle[2*(i+idx)]*sizeof( GL_FLOAT);
  781                     glDrawElements(
  782                         GL_TRIANGLES,
  783                         int(3 * scene->componentsinfos.ParisoTriangle[2 * (i + idx) + 1]),GL_UNSIGNED_INT,(void *)(Offset));
  784                 }
  785             }
  786         }
  787     }
  788     glDisable(GL_POLYGON_OFFSET_FILL);
  789     glUniform1i(uniformThereisRGBA, 0);
  790 }
  791 
  792 void MathMod::normOk()
  793 {
  794     LocalScene.norm *= -1;
  795     update();
  796 }
  797 
  798 void MathMod::boundingboxOk()
  799 {
  800     LocalScene.boundingbox *= -1;
  801 }
  802 
  803 void MathMod::run() {
  804     update();
  805 }
  806 
  807 bool MathMod::timeractif()
  808 {
  809     return (LocalScene.anim == 1);
  810 }
  811 
  812 void MathMod::stoptimer()
  813 {
  814     timer->stop();
  815     update();
  816 }
  817 
  818 void MathMod::starttimer()
  819 {
  820     timer->start(latence,this);
  821 }
  822 
  823 void MathMod::restarttimer(int newlatence)
  824 {
  825     latence = newlatence;
  826     if (LocalScene.anim == 1)
  827     {
  828         timer->stop();
  829         timer->start(latence, this);
  830     }
  831 }
  832 
  833 void MathMod::CreateShaderProgram()
  834 {
  835     int IsCompiled_VS, IsCompiled_FS;
  836     GLuint vertexshader, fragmentshader;
  837     char *vertexInfoLog;
  838     char *fragmentInfoLog;
  839     char *shaderProgramInfoLog;
  840     int IsLinked;
  841     int maxLength;
  842     const int MAX_LENGTH = 2048;
  843     char log[MAX_LENGTH];
  844     int logLength = 0;
  845     vertexshader = glCreateShader(GL_VERTEX_SHADER);
  846     bool shaderValid = glIsShader(vertexshader);
  847     if (!shaderValid)
  848     {
  849         std::cout << "Could not create Vertex Shader!";
  850     }
  851     fragmentshader = glCreateShader(GL_FRAGMENT_SHADER);
  852 
  853     static const char *c_str_vertex =
  854             R"(
  855             // GLSL version
  856             //#version 120
  857             #ifdef GL_ES
  858             precision mediump float;
  859             #endif
  860             // uniforms
  861             uniform mat4 matrixModelView;
  862             uniform mat4 matrixNormal;
  863             uniform mat4 matrixModelViewProjection;
  864             // vertex attribs (input)
  865             attribute vec3 vertexPosition;
  866             attribute vec3 vertexNormal;
  867             attribute vec4 vertexColor;
  868             //attribute vec2 vertexTexCoord;
  869             // varyings (output)
  870             varying vec3 esVertex, esNormal;
  871             varying vec4 color;
  872             void main()
  873             {
  874                 esVertex = vec3(matrixModelView * vec4(vertexPosition, 1.0));
  875                 esNormal = vec3(matrixNormal * vec4(vertexNormal, 1.0));
  876                 color = vertexColor;
  877                 gl_Position = matrixModelViewProjection * vec4(vertexPosition, 1.0);
  878             }
  879             )";
  880 
  881     static const char *c_str_fragment =
  882             R"(
  883             // GLSL version
  884             //#version 120
  885             #ifdef GL_ES
  886             precision mediump float;
  887             #endif
  888             // uniforms
  889             uniform vec4 frontColor;
  890             uniform vec4 backColor;
  891             uniform vec4 gridColor;
  892             uniform vec4 lightPosition;
  893             uniform vec4 lightAmbient;
  894             uniform vec4 lightDiffuse;
  895             uniform vec4 lightSpecular;
  896             uniform int thereisRGBA;
  897             uniform int drawgridColor;
  898             uniform float shininess;
  899             // varyings
  900             varying vec3 esVertex, esNormal;
  901             varying vec4 color;
  902             void main()
  903             {
  904                 vec4 color1=color;
  905                 vec3 normal = normalize(esNormal);
  906                 if(!gl_FrontFacing)
  907                 {
  908                     normal *= -1.0;
  909                 }
  910 
  911                 if(drawgridColor == 1)
  912                 {
  913                     color1=gridColor;
  914                 if(!gl_FrontFacing)
  915                 {
  916                     normal *= -1.0;
  917                 }
  918                 }
  919                 if(thereisRGBA ==1)
  920                 {
  921                     if(!gl_FrontFacing)
  922                     {
  923                         color1=backColor;
  924                     }
  925                     else
  926                         color1=frontColor;
  927                 }
  928 
  929                 vec3 light;
  930                 if(lightPosition.w == 0.0)
  931                 {
  932                     light = normalize(lightPosition.xyz);
  933                 }
  934                 else
  935                 {
  936                     light = normalize(lightPosition.xyz - esVertex);
  937                 }
  938                 vec3 view = normalize(-esVertex);
  939                 vec3 halfv = normalize(light + view);
  940 
  941                 vec4 fragColor = lightAmbient * color1;              // begin with ambient
  942                 float dotNL = max(dot(normal, light), 0.0);
  943                 fragColor += lightDiffuse* color1 * dotNL;              // add diffuse
  944                 float dotNH = max(dot(normal, halfv), 0.0);
  945                 fragColor += (pow(dotNH, shininess) * lightSpecular) * color1; // add specular
  946                 // set frag color
  947                 gl_FragColor = fragColor;
  948             }
  949             )";
  950     glShaderSource(vertexshader, 1, &c_str_vertex, NULL);
  951     glCompileShader(vertexshader);
  952     glGetShaderiv(vertexshader, GL_COMPILE_STATUS, &IsCompiled_VS);
  953     if(IsCompiled_VS==GL_FALSE)
  954     {
  955        QMessageBox msgBox;
  956        glGetShaderiv(vertexshader, GL_INFO_LOG_LENGTH, &maxLength);
  957        vertexInfoLog = (char *)malloc(maxLength);
  958        glGetShaderInfoLog(vertexshader, maxLength, &maxLength, vertexInfoLog);
  959        std::string vertexInfoLogString = std::string(vertexInfoLog);
  960        msgBox.setText("Error : " +QString::fromStdString(std::string(vertexInfoLog)));
  961        msgBox.adjustSize();
  962        msgBox.exec();
  963     }
  964     glShaderSource(fragmentshader, 1, &c_str_fragment, NULL);
  965     glCompileShader(fragmentshader);
  966     glGetShaderiv(fragmentshader, GL_COMPILE_STATUS, &IsCompiled_FS);
  967     if(IsCompiled_FS==GL_FALSE)
  968     {
  969         QMessageBox msgBox;
  970        glGetShaderiv(fragmentshader, GL_INFO_LOG_LENGTH, &maxLength);
  971        fragmentInfoLog = (char *)malloc(maxLength);
  972        glGetShaderInfoLog(fragmentshader, maxLength, &maxLength, fragmentInfoLog);
  973        std::string vertexInfoLogString = std::string(fragmentInfoLog);
  974        msgBox.setText("Error : " +QString::fromStdString(std::string(fragmentInfoLog)));
  975        msgBox.adjustSize();
  976        msgBox.exec();
  977        //return;
  978     }
  979     shaderprogramId = glCreateProgram();
  980     glAttachShader(shaderprogramId, vertexshader);
  981     glAttachShader(shaderprogramId, fragmentshader);
  982     glBindAttribLocation(shaderprogramId, 0, "in_Position");
  983     glBindAttribLocation(shaderprogramId, 1, "in_Color");
  984     glLinkProgram(shaderprogramId);
  985     glGetProgramiv(shaderprogramId, GL_LINK_STATUS, (int *)&IsLinked);
  986     if(!IsLinked)
  987     {
  988        glGetProgramiv(shaderprogramId, GL_INFO_LOG_LENGTH, &maxLength);
  989        shaderProgramInfoLog = (char *)malloc(maxLength);
  990        glGetProgramInfoLog(shaderprogramId, maxLength, &maxLength, shaderProgramInfoLog);
  991     }
  992     glUseProgram(shaderprogramId);
  993     uniformMatrixModelView           = glGetUniformLocation(shaderprogramId, "matrixModelView");
  994     uniformMatrixModelViewProjection = glGetUniformLocation(shaderprogramId, "matrixModelViewProjection");
  995     uniformMatrixNormal              = glGetUniformLocation(shaderprogramId, "matrixNormal");
  996     uniformLightPosition             = glGetUniformLocation(shaderprogramId, "lightPosition");
  997     uniformLightAmbient              = glGetUniformLocation(shaderprogramId, "lightAmbient");
  998     uniformLightDiffuse              = glGetUniformLocation(shaderprogramId, "lightDiffuse");
  999     uniformLightSpecular             = glGetUniformLocation(shaderprogramId, "lightSpecular");
 1000     uniformFrontColor                = glGetUniformLocation(shaderprogramId, "frontColor");
 1001     uniformBackColor                 = glGetUniformLocation(shaderprogramId, "backColor");
 1002     uniformGridColor                 = glGetUniformLocation(shaderprogramId, "gridColor");
 1003     uniformThereisRGBA               = glGetUniformLocation(shaderprogramId, "thereisRGBA");
 1004     uniformShininess                 = glGetUniformLocation(shaderprogramId, "shininess");
 1005     uniformdrawgridColor             = glGetUniformLocation(shaderprogramId, "drawgridColor");
 1006     attribVertexPosition             = glGetAttribLocation(shaderprogramId, "vertexPosition");
 1007     attribVertexNormal               = glGetAttribLocation(shaderprogramId, "vertexNormal");
 1008     attribVertexColor                = glGetAttribLocation(shaderprogramId, "vertexColor");
 1009     glUniform4fv(uniformLightPosition, 1, lightPosition);
 1010     glUniform4fv(uniformLightAmbient, 1, lightAmbient);
 1011     glUniform4fv(uniformLightDiffuse, 1, lightDiffuse);
 1012     glUniform4fv(uniformLightSpecular, 1, lightSpecular);
 1013     glUniform4fv(uniformFrontColor, 1, frontColor);
 1014     glUniform4fv(uniformBackColor, 1, backColor);
 1015     glUniform4fv(uniformGridColor, 1, gridcol);
 1016     glUniform1f(uniformShininess, shininessVal);
 1017     glUniform1i(uniformThereisRGBA, 1);
 1018     glUniform1i(uniformdrawgridColor, 0);
 1019 
 1020     int linkStatus;
 1021     glGetProgramiv(shaderprogramId, GL_LINK_STATUS, &linkStatus);
 1022     if(linkStatus == GL_FALSE)
 1023     {
 1024         glGetProgramiv(shaderprogramId, GL_INFO_LOG_LENGTH, &logLength);
 1025         glGetProgramInfoLog(shaderprogramId, MAX_LENGTH, &logLength, log);
 1026         std::cout << "===== GLSL Program Log =====\n" << log << std::endl;
 1027         return;
 1028     }
 1029     else
 1030     {
 1031         return;
 1032     }
 1033 }
 1034 
 1035 void MathMod::proj()
 1036 {
 1037     qreal aspect = qreal(screenWidth) / qreal(screenHeight ? screenHeight : 1);
 1038     const qreal zNear = 0.01, zFar = 15, fov = 60.0;
 1039     matrixProjectionx.setToIdentity();
 1040     matrixProjectionx.perspective(fov, aspect, zNear, zFar);
 1041 }
 1042 
 1043 void MathMod::LoadShadersFiles()
 1044 {
 1045     CreateShaderProgram();
 1046 }
 1047 
 1048 void MathMod::initializeGL()
 1049 {
 1050     initializeOpenGLFunctions();
 1051     glEnable(GL_DEPTH_TEST);
 1052     glEnable(GL_BLEND);
 1053     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 1054     glFrontFace(GL_CCW);
 1055     glClearColor(0, 0, 0, 0);
 1056     //initCamera();
 1057     proj();
 1058 }
 1059 
 1060 void MathMod::resizeGL(int newwidth, int newheight)
 1061 {
 1062     screenWidth = newwidth;
 1063     screenHeight = newheight;
 1064     proj();
 1065 }
 1066 
 1067 void MathMod::anim()
 1068 {
 1069     LocalScene.anim *= -1;
 1070     if (LocalScene.anim == 1)
 1071     {
 1072         timer->start(latence, this);
 1073         if (LocalScene.morph == -1)
 1074         {
 1075             LabelInfos.setText(labelinfos+" Rotation: ON \n");
 1076         }
 1077     }
 1078     else
 1079     {
 1080         oldRotation = rotation;
 1081         if (LocalScene.morph == -1)
 1082         {
 1083             LabelInfos.setText(labelinfos);
 1084             stoptimer();
 1085         }
 1086     }
 1087 }
 1088 
 1089 void MathMod::morph()
 1090 {
 1091     LocalScene.morph *= -1;
 1092     FistTimecalibrate *= -1;
 1093     if (LocalScene.typedrawing == 1)
 1094     {
 1095         // Isosurfaces:
 1096         IsoObjet->masterthread->activeMorph = LocalScene.morph;
 1097         for (uint nbthreads = 0; nbthreads < IsoObjet->WorkerThreadsNumber - 1;
 1098                 nbthreads++)
 1099             IsoObjet->workerthreads[nbthreads].activeMorph = LocalScene.morph;
 1100         IsoObjet->IsoMorph();
 1101     }
 1102     else if (LocalScene.typedrawing == -1)
 1103     {
 1104         // Parametric surfaces:
 1105         ParObjet->masterthread->activeMorph = LocalScene.morph;
 1106         for (uint nbthreads = 0; nbthreads < ParObjet->WorkerThreadsNumber - 1;
 1107                 nbthreads++)
 1108             ParObjet->workerthreads[nbthreads].activeMorph = LocalScene.morph;
 1109         ParObjet->ParMorph();
 1110     }
 1111     else   // Pariso objects
 1112     {
 1113         // Parametric surfaces:
 1114         ParObjet->masterthread->activeMorph = LocalScene.morph;
 1115         for (uint nbthreads = 0; nbthreads < ParObjet->WorkerThreadsNumber - 1;
 1116                 nbthreads++)
 1117             ParObjet->workerthreads[nbthreads].activeMorph = LocalScene.morph;
 1118         ParObjet->ParMorph();
 1119         // Isosurfaces:
 1120         IsoObjet->masterthread->activeMorph = LocalScene.morph;
 1121         for (uint nbthreads = 0; nbthreads < IsoObjet->WorkerThreadsNumber - 1;
 1122                 nbthreads++)
 1123             IsoObjet->workerthreads[nbthreads].activeMorph = LocalScene.morph;
 1124         IsoObjet->IsoMorph();
 1125     }
 1126     if (LocalScene.morph == 1)
 1127     {
 1128         timer->start(latence, this);
 1129     }
 1130     else
 1131     {
 1132         if (LocalScene.anim == -1)
 1133         {
 1134             LabelInfos.setText(labelinfos);
 1135             stoptimer();
 1136         }
 1137         else
 1138         {
 1139             LabelInfos.setText(labelinfos+" Rotation: ON \n");
 1140         }
 1141     }
 1142 }
 1143 
 1144 void MathMod::keyPressEvent(QKeyEvent *e)
 1145 {
 1146     int key = e->key();
 1147     switch (key)
 1148     {
 1149     case Qt::CTRL+Qt::Key_A:
 1150         anim();
 1151         break;
 1152     case Qt::CTRL+Qt::Key_P:
 1153         morph();
 1154         break;
 1155      case   Qt::CTRL+Qt::Key_C:
 1156         Parent->show();
 1157         break;
 1158     }
 1159     update();
 1160 }
 1161 void MathMod::FillOk()
 1162 {
 1163     LocalScene.fill *= -1;
 1164     update();
 1165 }
 1166 
 1167 void MathMod::DrawAxe()
 1168 {
 1169     glLineWidth(1.0);
 1170     glUniform1i(uniformThereisRGBA, 0);
 1171     // Draw the three axes (lines without head)
 1172     glDrawArrays(GL_LINES,AxesStartIndex,6);
 1173     // Head of the X Axe:
 1174     glDrawArrays(GL_TRIANGLE_FAN,XStartIndex,6);
 1175     // Head of the Y Axe:
 1176     glDrawArrays(GL_TRIANGLE_FAN,YStartIndex,6);
 1177     // Head of the Z Axe:
 1178     glDrawArrays(GL_TRIANGLE_FAN,ZStartIndex,6);
 1179     glLineWidth(3.0);
 1180     // Draw the X axe
 1181     glDrawArrays(GL_LINES,XletterIndex,4);
 1182     // Draw the Y axe
 1183     glDrawArrays(GL_LINES,YletterIndex,4);
 1184     // Draw the Z axe
 1185     glDrawArrays(GL_LINE_STRIP,ZletterIndex,4);
 1186 }
 1187 
 1188 void MathMod::DrawNormals(ObjectProperties *)
 1189 {
 1190     /*
 1191     uint j = 0;
 1192     glColor4f(0.8f, 0., 0.7f, 1.0);
 1193     for (uint i = 0; i < scene->PolyNumber; i += 4)
 1194     {
 1195         j = 10 * scene->PolyIndices_localPt[i];
 1196         glBegin(GL_LINES);
 1197         glVertex3f(scene->ArrayNorVer_localPt[j + 7],
 1198                    scene->ArrayNorVer_localPt[j + 8],
 1199                    scene->ArrayNorVer_localPt[j + 9]);
 1200         glVertex3f(scene->ArrayNorVer_localPt[j + 7] +
 1201                    40 * scene->ArrayNorVer_localPt[j + 4],
 1202                    scene->ArrayNorVer_localPt[j + 8] +
 1203                    40 * scene->ArrayNorVer_localPt[j + 5],
 1204                    scene->ArrayNorVer_localPt[j + 9] +
 1205                    40 * scene->ArrayNorVer_localPt[j + 6]);
 1206         glEnd();
 1207     }
 1208     */
 1209 }
 1210 
 1211 void MathMod::Winitialize_GL()
 1212 {
 1213     if (LocalScene.componentsinfos.updateviewer)
 1214     {
 1215         PutObjectInsideCube();
 1216         PutObjectInsideCubeOk=true;
 1217     }
 1218 }
 1219 
 1220 void MathMod::UpdateGL()
 1221 {
 1222     if (LocalScene.updategl)
 1223     {
 1224         Winitialize_GL();
 1225         update();
 1226     }
 1227     else
 1228         LocalScene.updategl = true;
 1229 }
 1230 
 1231 void MathMod::DrawParisoCND(ObjectProperties *scene, uint compindex)
 1232 {
 1233     uint idx = 0;
 1234     for (uint i = 0; i < compindex; i++)
 1235         idx += scene->componentsinfos.NbComponentsType[i];
 1236     int start_triangle = scene->componentsinfos.ParisoTriangle[2 * idx];
 1237     if (scene->cndoptions[3])
 1238     {
 1239         size_t Offset0 = (3 * scene->componentsinfos.NbTrianglesNoCND[compindex] + start_triangle)*sizeof( GL_FLOAT);
 1240         glLineWidth(0.3);
 1241         for (uint i = 0; i < (3 * scene->componentsinfos.NbTrianglesVerifyCND[compindex]); i += 3)
 1242         {
 1243             glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset0));
 1244             Offset0+=(3*sizeof( GL_FLOAT));
 1245         }
 1246     }
 1247 
 1248     if (scene->cndoptions[4])
 1249     {
 1250         size_t Offset1 = (3 * scene->componentsinfos
 1251                           .NbTrianglesNoCND[compindex] + 3 * scene->componentsinfos
 1252                                                  .NbTrianglesVerifyCND[compindex] +
 1253                                                  start_triangle)*sizeof(GL_FLOAT);
 1254         glLineWidth(0.3);
 1255         for (uint i = 0; i < (3 * scene->componentsinfos.NbTrianglesNotVerifyCND[compindex]); i += 3)
 1256         {
 1257             glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset1));
 1258             Offset1+=(3*sizeof( GL_FLOAT));
 1259         }
 1260     }
 1261     if (scene->cndoptions[2])
 1262     {
 1263         size_t Offset2 = (3*scene->componentsinfos.NbTrianglesNoCND[compindex]+3*(scene->componentsinfos.NbTrianglesVerifyCND[compindex] +
 1264                           scene->componentsinfos.NbTrianglesNotVerifyCND[compindex])+start_triangle)*sizeof( GL_FLOAT);
 1265         glLineWidth(4.0);
 1266         for (uint i = 0; i < (3 * scene->componentsinfos.NbTrianglesBorderCND[compindex]); i += 3)
 1267         {
 1268             glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset2));
 1269             Offset2+=(3*sizeof( GL_FLOAT));
 1270         }
 1271     }
 1272 }
 1273 
 1274 void MathMod::DrawMeshIso(ObjectProperties *scene)
 1275 {
 1276     size_t Offset = 0;
 1277     uint st = 0;
 1278     glUniform4fv(uniformGridColor, 1, scene->gridcol);
 1279     glUniform1i(uniformdrawgridColor, 1);
 1280     glLineWidth(0.3);
 1281     for (uint i = 0; i < scene->PolyNumber; i += 3)
 1282     {
 1283         Offset = st*sizeof( GL_FLOAT);
 1284         glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset));
 1285         st+=3;
 1286     }
 1287     glUniform1i(uniformdrawgridColor, 0);
 1288 }
 1289 
 1290 void MathMod::DrawMinimalTopology(ObjectProperties *scene)
 1291 {
 1292     glUniform4fv(uniformGridColor, 1,scene->gridcol);
 1293     glUniform1i(uniformdrawgridColor, 1);
 1294     glLineWidth(0.4);
 1295     uint st = scene->PolyNumber;
 1296     uint polysize=0;
 1297     size_t Offset;
 1298     for (uint i = 0; i < scene->NbPolygnNbVertexPtMin; i++)
 1299     {
 1300         polysize = scene->PolyIndices_localPtMin[i];
 1301         Offset = st*sizeof( GL_FLOAT);
 1302         glDrawElements(
 1303             GL_LINE_LOOP,
 1304             polysize,
 1305             GL_UNSIGNED_INT,
 1306             (void *)(Offset));
 1307         st+=(polysize);
 1308     }
 1309     glUniform1i(uniformdrawgridColor, 0);
 1310 }
 1311 
 1312 void MathMod::plan()
 1313 {
 1314     glUniform1i(uniformThereisRGBA, 0);
 1315     glLineWidth(0.3);
 1316     glDrawArrays(GL_LINES,PlanStartIndex,60);
 1317 }
 1318 
 1319 void MathMod::CopyData(ObjectProperties *scene)
 1320 {
 1321     static int firstaction=0;
 1322     static uint previousVertxNumber=0;
 1323     static uint previousPolyNumberNbPolygnNbVertexPtMin=0;
 1324     if(firstaction==0)
 1325     {
 1326         vbo[0]=vbo[1]=0;
 1327         glGenBuffers(2, vbo);
 1328         /* Bind our first VBO as being the active buffer and storing vertex attributes (coordinates) */
 1329         glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
 1330         glBufferData(GL_ARRAY_BUFFER, sizeof(float)*10*(scene->VertxNumber+(12+60+36)),scene->ArrayNorVer_localPt, GL_STATIC_DRAW);
 1331         glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
 1332         /* Bind our first VBO as being the active buffer and storing vertex attributes (coordinates) */
 1333         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
 1334         glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(uint)*(scene->PolyNumber + scene->NbPolygnNbVertexPtMinSize), scene->PolyIndices_localPt, GL_STATIC_DRAW);
 1335         size_t cOffset = 0;
 1336         size_t nOffset = cOffset + 4*sizeof( GL_FLOAT);
 1337         size_t vOffset = nOffset + 3*sizeof (GL_FLOAT);
 1338         // activate attribs
 1339         glEnableVertexAttribArray(attribVertexColor);
 1340         glEnableVertexAttribArray(attribVertexNormal);
 1341         glEnableVertexAttribArray(attribVertexPosition);
 1342         // set attrib arrays using glVertexAttribPointer()
 1343         glVertexAttribPointer(attribVertexPosition, 3, GL_FLOAT, false, 10*sizeof( GL_FLOAT), (void*)vOffset);
 1344         glVertexAttribPointer(attribVertexNormal, 3, GL_FLOAT, false, 10*sizeof( GL_FLOAT), (void*)nOffset);
 1345         glVertexAttribPointer(attribVertexColor,4, GL_FLOAT, false, 10*sizeof( GL_FLOAT), (void*)cOffset);
 1346         previousVertxNumber = scene->VertxNumber;
 1347         previousPolyNumberNbPolygnNbVertexPtMin = (scene->PolyNumber + scene->NbPolygnNbVertexPtMinSize);
 1348         firstaction++;
 1349     }
 1350     else{
 1351         if(scene->VertxNumber>previousVertxNumber)
 1352         {
 1353             glBufferData(GL_ARRAY_BUFFER, sizeof(float)*10*(scene->VertxNumber+(12+60+36)), scene->ArrayNorVer_localPt, GL_STATIC_DRAW);
 1354             previousVertxNumber = scene->VertxNumber;
 1355         }
 1356         else
 1357         {
 1358             glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*10*(scene->VertxNumber+(12+60+36)), scene->ArrayNorVer_localPt);
 1359             previousVertxNumber = scene->VertxNumber;
 1360         }
 1361         if((scene->PolyNumber + scene->NbPolygnNbVertexPtMinSize)>previousPolyNumberNbPolygnNbVertexPtMin)
 1362         {
 1363            glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(uint)*(scene->PolyNumber + scene->NbPolygnNbVertexPtMinSize), scene->PolyIndices_localPt, GL_STATIC_DRAW);
 1364            previousPolyNumberNbPolygnNbVertexPtMin =  (scene->PolyNumber + scene->NbPolygnNbVertexPtMinSize);
 1365         }
 1366         else
 1367         {
 1368             glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,0, sizeof(uint)*(scene->PolyNumber + scene->NbPolygnNbVertexPtMinSize), scene->PolyIndices_localPt);
 1369             previousPolyNumberNbPolygnNbVertexPtMin =  (scene->PolyNumber + scene->NbPolygnNbVertexPtMinSize);
 1370         }
 1371     }
 1372 }
 1373 
 1374 void MathMod::draw(ObjectProperties *scene)
 1375 {
 1376     if(!PutObjectInsideCubeOk)
 1377         return;
 1378     if (scene->componentsinfos.Interleave)
 1379     {
 1380         CopyData(scene);
 1381         scene->componentsinfos.Interleave = false;
 1382     }
 1383     // clear buffer
 1384     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 1385     // set modelview matrix
 1386     matrixViewx.setToIdentity();
 1387     matrixViewx.translate(0.0, 0.0, -cameraDistance);
 1388     matrixViewx.rotate(rotation);
 1389     matrixModelViewProjectionx = matrixProjectionx * matrixViewx;
 1390     matrixNormalx=matrixViewx;
 1391     matrixNormalx.setColumn(3, QVector4D(0,0,0,1));
 1392     glUniformMatrix4fv(uniformMatrixModelView, 1, false, matrixViewx.data());
 1393     glUniformMatrix4fv(uniformMatrixModelViewProjection, 1, false, matrixModelViewProjectionx.data());
 1394     glUniformMatrix4fv(uniformMatrixNormal, 1, false, matrixNormalx.data());
 1395     if(LocalScene.ShininessValUpdated)
 1396     {
 1397         glUniform1f(uniformShininess, shininessVal);
 1398         glUniform4fv(uniformLightSpecular, 1, lightSpecular);
 1399         LocalScene.ShininessValUpdated =false;
 1400     }
 1401     if(LocalScene.AmbientValUpdated)
 1402     {
 1403         glUniform4fv(uniformLightAmbient, 1, lightAmbient);
 1404         LocalScene.AmbientValUpdated =false;
 1405     }
 1406     if(LocalScene.DiffuseValUpdated)
 1407     {
 1408         glUniform4fv(uniformLightDiffuse, 1, lightDiffuse);
 1409         LocalScene.DiffuseValUpdated =false;
 1410     }
 1411     // We draw the Plan first because we don't want it to spin around X,Y and Z axes
 1412     if (scene->plan == 1)
 1413         plan();
 1414     if(LocalScene.animx==1)
 1415         matrixViewx.rotate(rotationx);
 1416     if(LocalScene.animy==1)
 1417         matrixViewx.rotate(rotationy);
 1418     if(LocalScene.animz==1)
 1419         matrixViewx.rotate(rotationz);
 1420     if(LocalScene.animx==1 || LocalScene.animy==1 || LocalScene.animz==1)
 1421     {
 1422         matrixModelViewProjectionx = matrixProjectionx * matrixViewx;
 1423         matrixNormalx=matrixViewx;
 1424         matrixNormalx.setColumn(3, QVector4D(0,0,0,1));
 1425         glUniformMatrix4fv(uniformMatrixModelView, 1, false, matrixViewx.data());
 1426         glUniformMatrix4fv(uniformMatrixModelViewProjection, 1, false, matrixModelViewProjectionx.data());
 1427         glUniformMatrix4fv(uniformMatrixNormal, 1, false, matrixNormalx.data());
 1428     }
 1429     // Blend Effect activation:
 1430     if (scene->transparency == 1)
 1431         glDepthMask(GL_FALSE);
 1432 
 1433     // Axe :
 1434     if (scene->axe == 1)
 1435         DrawAxe();
 1436 
 1437     if (scene->fill == 1 && scene->componentsinfos.updateviewer)
 1438         for (uint i = 0; i < scene->componentsinfos.NbComponentsType.size(); i++)
 1439             DrawPariso(scene, i);
 1440 
 1441     // Draw Mesh Object:
 1442     if (scene->triangles == 1 && scene->componentsinfos.updateviewer)
 1443         DrawMeshIso(scene);
 1444 
 1445     // Bounding Box:
 1446     if (scene->boundingbox == 1)
 1447         drawCube();
 1448 
 1449     // Draw Minimal topology for isosurfaces:
 1450     if (scene->mesh == 1 && scene->componentsinfos.updateviewer)
 1451         DrawMinimalTopology(scene);
 1452 
 1453     if (scene->activarecnd && scene->componentsinfos.updateviewer)
 1454         for (uint i = 0; i < scene->componentsinfos.NbComponentsType.size(); i++)
 1455             if (scene->componentsinfos.ThereisCND[i])
 1456                 DrawParisoCND(scene, i);
 1457 
 1458     // Draw Normales:
 1459     if (scene->norm == 1 && scene->componentsinfos.updateviewer)
 1460         DrawNormals(scene);
 1461 
 1462     if (scene->transparency == 1)
 1463         glDepthMask(GL_TRUE);
 1464 }
 1465 
 1466 void MathMod::paintGL()
 1467 {
 1468     if (LocalScene.morph == 1)
 1469     {
 1470         if (LocalScene.typedrawing == -1)
 1471         {
 1472             ParObjet->ParamBuild(
 1473                 &(LocalScene.ArrayNorVer_localPt), &(LocalScene.PolyIndices_localPt),
 1474                 &LocalScene.PolyNumber, &LocalScene.VertxNumber,
 1475                 &(LocalScene.componentsinfos), &(LocalScene.PolyIndices_localPtMin),
 1476                 &(LocalScene.NbPolygnNbVertexPtMin),
 1477                 &(LocalScene.NbPolygnNbVertexPtMinSize));
 1478         }
 1479         else if (LocalScene.typedrawing == 1)
 1480         {
 1481             IsoObjet->IsoBuild(
 1482                 &(LocalScene.ArrayNorVer_localPt), &(LocalScene.PolyIndices_localPt),
 1483                 &(LocalScene.PolyNumber), &(LocalScene.VertxNumber),
 1484                 &(LocalScene.PolyIndices_localPtMin),
 1485                 &(LocalScene.NbPolygnNbVertexPtMin),
 1486                 &(LocalScene.NbPolygnNbVertexPtMinSize),
 1487                 &(LocalScene.componentsinfos));
 1488         }
 1489         else
 1490         {
 1491             ParObjet->ParamBuild(
 1492                 &(LocalScene.ArrayNorVer_localPt), &(LocalScene.PolyIndices_localPt),
 1493                 &LocalScene.PolyNumber, &LocalScene.VertxNumber,
 1494                 &(LocalScene.componentsinfos), &(LocalScene.PolyIndices_localPtMin),
 1495                 &(LocalScene.NbPolygnNbVertexPtMin),
 1496                 &(LocalScene.NbPolygnNbVertexPtMinSize));
 1497             IsoObjet->IsoBuild(
 1498                 &(LocalScene.ArrayNorVer_localPt), &(LocalScene.PolyIndices_localPt),
 1499                 &(LocalScene.PolyNumber), &(LocalScene.VertxNumber),
 1500                 &(LocalScene.PolyIndices_localPtMin),
 1501                 &(LocalScene.NbPolygnNbVertexPtMin),
 1502                 &(LocalScene.NbPolygnNbVertexPtMinSize),
 1503                 &(LocalScene.componentsinfos));
 1504         }
 1505         Winitialize_GL();
 1506     }
 1507     draw(&LocalScene);
 1508     if (LocalScene.morph == 1 && LocalScene.frame == 1)
 1509         FramesSave();
 1510 }
 1511 
 1512 void MathMod::timerEvent(QTimerEvent *)
 1513 {
 1514     if(LocalScene.anim == 1)
 1515     {
 1516         if(LocalScene.animx==1)
 1517         {
 1518             rotationx = rotationx*QQuaternion::fromAxisAndAngle(QVector3D(1.0,0.0,0.0), LocalScene.animxValueStep);
 1519         }
 1520         if(LocalScene.animy==1)
 1521         {
 1522             rotationy = rotationy*QQuaternion::fromAxisAndAngle(QVector3D(0.0,1.0,0.0), LocalScene.animyValueStep);
 1523         }
 1524         if(LocalScene.animz==1)
 1525         {
 1526             rotationz = rotationz*QQuaternion::fromAxisAndAngle(QVector3D(0.0,0.0,1.0), LocalScene.animzValueStep);
 1527         }
 1528         if(LocalScene.animxyz == 1)
 1529             rotation = QQuaternion::fromAxisAndAngle(n, acc/10) * rotation;
 1530         oldRotation = rotation;
 1531     }
 1532     update();
 1533 }
 1534 
 1535 void MathMod::mouseReleaseEvent(QMouseEvent *)
 1536 {
 1537     if(LocalScene.anim != 1)
 1538         oldRotation = rotation;
 1539 }
 1540 
 1541 void MathMod::mousePressEvent(QMouseEvent *e)
 1542 {
 1543     // Save mouse press position
 1544     mousePressPosition = QVector2D(e->localPos());
 1545     if(LocalScene.anim != 1)
 1546         rotation = oldRotation;
 1547     if (e->button() == Qt::LeftButton)
 1548     {
 1549         btgauche = 1;
 1550         mouseLeftDown =true;
 1551     }
 1552     else
 1553     {
 1554         btgauche = 0;
 1555         mouseLeftDown =false;
 1556     }
 1557     if (e->button() == Qt::RightButton)
 1558     {
 1559         btdroit = 1;
 1560         mouseRightDown =true;
 1561     }
 1562     else
 1563     {
 1564         btdroit = 0;
 1565         mouseRightDown =false;
 1566     }
 1567     if (e->button() == Qt::MidButton)
 1568         btmilieu = 1;
 1569     else
 1570         btmilieu = 0;
 1571 
 1572     mouseY = e->y()/2;
 1573 }
 1574 
 1575 void MathMod::mouseMoveEvent(QMouseEvent *e)
 1576 {
 1577     static int oldx=0, oldy=0;
 1578     static QVector3D oldn=QVector3D(0,0,1);
 1579     static qreal oldacc;
 1580     if(mouseLeftDown)
 1581     {
 1582         QVector2D diff = QVector2D(e->localPos()) - mousePressPosition;
 1583         // Rotation axis is perpendicular to the mouse position difference
 1584         n = QVector3D(diff.y(), diff.x(), 0.0).normalized();
 1585         // Accelerate angular speed relative to the length of the mouse sweep
 1586         acc =std::sqrt((diff.y()-oldy)*(diff.y()-oldy)+ float(diff.x()-oldx)*(diff.x()-oldx))/ /*(double)(LocalScene.viewport[2]+1)*/3.0;
 1587         // Calculate new rotation axis
 1588         rotation = QQuaternion::fromAxisAndAngle(n, acc)*oldRotation;
 1589         oldacc= acc;
 1590         oldn = n;
 1591     }
 1592     if(mouseRightDown)
 1593     {
 1594         cameraDistance -= (e->y()/2 - mouseY) * 0.02f;
 1595         mouseY = e->y()/2;
 1596     }
 1597     update();
 1598 }
 1599 
 1600 void MathMod::screenshot()
 1601 {
 1602     QImage image = QOpenGLWidget::grabFramebuffer();
 1603     if (LocalScene.png_ok == 1)
 1604         image.save("GLscreenshot.png", "PNG", LocalScene.quality_image);
 1605     if (LocalScene.bmp_ok == 1)
 1606         image.save("GLscreenshot.bmp", "BMP", LocalScene.quality_image);
 1607 }
 1608 
 1609 void MathMod::FramesShot()
 1610 {
 1611     LocalScene.frame *= -1;
 1612     if (LocalScene.frame == 1)
 1613     {
 1614         FramesDir = QFileDialog::getExistingDirectory(
 1615                         this, tr("Choose Or Create Directory"), FramesDir,
 1616                         QFileDialog::DontResolveSymlinks);
 1617         if (FramesDir != "" && !FramesDir.endsWith("/"))
 1618             FramesDir += "/";
 1619     }
 1620 }
 1621 
 1622 void MathMod::FramesSave()
 1623 {
 1624     static int Index = 0;
 1625     if (LocalScene.frame == 1)
 1626     {
 1627         QImage image = QOpenGLWidget::grabFramebuffer();   //:grabFrameBuffer();
 1628         QString FileName =
 1629             FramesDir + QString("%1").arg(Index, 5, 10, QChar('0')) + ".png";
 1630         Index += 1;
 1631         image.save(FileName, "PNG", 1);
 1632     }
 1633 }
 1634 
 1635 QImage MathMod::Copyscreenshot()
 1636 {
 1637     return (QOpenGLWidget::grabFramebuffer());
 1638 }
 1639 
 1640 void MathMod::transparency(int cl, int currentposition)
 1641 {
 1642     switch (LocalScene.colortype)
 1643     {
 1644     case 1:
 1645         LocalScene.frontcols[(currentposition % 10) * 4 + 3] = (cl / 255.0f);
 1646         break;
 1647     case 0:
 1648         LocalScene.backcols[(currentposition % 10) * 4 + 3] = (cl / 255.0f);
 1649         break;
 1650     case 2:
 1651         LocalScene.gridcol[3] = (cl / 255.0f);
 1652         break;
 1653     case 3:
 1654         LocalScene.groundcol[3] = (cl / 255.0f);
 1655         glClearColor(LocalScene.groundcol[0], LocalScene.groundcol[1],
 1656                      LocalScene.groundcol[2], LocalScene.groundcol[3]);
 1657         break;
 1658     }
 1659     update();
 1660 }
 1661 
 1662 void MathMod::red(int cl, int currentposition)
 1663 {
 1664     switch (LocalScene.colortype)
 1665     {
 1666     case 1:
 1667         LocalScene.frontcols[(currentposition % 10) * 4 + 0] = (cl / 255.0f);
 1668         break;
 1669     case 0:
 1670         LocalScene.backcols[(currentposition % 10) * 4 + 0] = (cl / 255.0f);
 1671         break;
 1672     case 2:
 1673         LocalScene.gridcol[0] = (cl / 255.0f);
 1674         break;
 1675     case 3:
 1676         LocalScene.groundcol[0] = (cl / 255.0f);
 1677         glClearColor(LocalScene.groundcol[0], LocalScene.groundcol[1],
 1678                      LocalScene.groundcol[2], LocalScene.groundcol[3]);
 1679         break;
 1680     }
 1681     update();
 1682 }
 1683 
 1684 void MathMod::green(int cl, int currentposition)
 1685 {
 1686     switch (LocalScene.colortype)
 1687     {
 1688     case 1:
 1689         LocalScene.frontcols[(currentposition % 10) * 4 + 1] = (cl / 255.0f);
 1690         break;
 1691     case 0:
 1692         LocalScene.backcols[(currentposition % 10) * 4 + 1] = (cl / 255.0f);
 1693         break;
 1694     case 2:
 1695         LocalScene.gridcol[1] = (cl / 255.0f);
 1696         break;
 1697     case 3:
 1698         LocalScene.groundcol[1] = (cl / 255.0f);
 1699         glClearColor(LocalScene.groundcol[0], LocalScene.groundcol[1],
 1700                      LocalScene.groundcol[2], LocalScene.groundcol[3]);
 1701         break;
 1702     }
 1703     update();
 1704 }
 1705 
 1706 void MathMod::blue(int cl, int currentposition)
 1707 {
 1708     switch (LocalScene.colortype)
 1709     {
 1710     case 1:
 1711         LocalScene.frontcols[(currentposition % 10) * 4 + 2] = (cl / 255.0f);
 1712         break;
 1713     case 0:
 1714         LocalScene.backcols[(currentposition % 10) * 4 + 2] = (cl / 255.0f);
 1715         break;
 1716     case 2:
 1717         LocalScene.gridcol[2] = (cl / 255.0f);
 1718         break;
 1719     case 3:
 1720         LocalScene.groundcol[2] = (cl / 255.0f);
 1721         glClearColor(LocalScene.groundcol[0], LocalScene.groundcol[1],
 1722                      LocalScene.groundcol[2], LocalScene.groundcol[3]);
 1723         break;
 1724     }
 1725     update();
 1726 }
 1727 
 1728 void MathMod::transSpec(int cl)
 1729 {
 1730     lightSpecular[3] = (cl/ 100.0f);
 1731     LocalScene.ShininessValUpdated=true;
 1732     update();
 1733 }
 1734 
 1735 void MathMod::Shininess(int cl)
 1736 {
 1737     shininessVal= GLfloat(cl);
 1738     LocalScene.ShininessValUpdated=true;
 1739     update();
 1740 }
 1741 
 1742 void MathMod::InitSpecularParameters()
 1743 {
 1744     glEnable(GL_DEPTH_TEST);
 1745     glFrontFace(GL_CCW);
 1746     update();
 1747 }
 1748 
 1749 MathMod::MathMod(QWidget *parent, uint nbthreads,
 1750                  uint initparGrid, uint initisoGrid, uint FactX, uint FactY,
 1751                  uint FactZ) :QOpenGLWidget(parent)
 1752 {
 1753     //MathMod::context();
 1754     //makeCurrent();
 1755     PerlinNoise = new ImprovedNoise(4., 4., 4.);
 1756     latence = 10;
 1757     Vgrid = Ugrid = 64;
 1758     CutV = CutU = 0;
 1759     Xgrid = Ygrid = Zgrid = 64;
 1760     CutX = CutY = CutZ = 0;
 1761     LocalScene.VertxNumber = 0;
 1762     LabelInfos.setWindowFlags(Qt::WindowStaysOnTopHint| Qt::FramelessWindowHint);
 1763     LabelInfos.setAttribute(Qt::WA_TranslucentBackground);
 1764     LabelInfos.setAttribute(Qt::WA_NoSystemBackground);
 1765     LabelInfos.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 1766     LabelInfos.setWindowOpacity(0.8);
 1767     FramesDir = "/home";
 1768     hauteur_fenetre = 2*wh;
 1769     timer = new QBasicTimer();
 1770     xyzactivated = uvactivated = uvactivated4D = 1;
 1771     if (memoryallocation(nbthreads, initparGrid, initisoGrid,
 1772                                FactX, FactY, FactZ) != 1)
 1773         exit(0);
 1774 }
 1775 
 1776 void MathMod::attachinfos()
 1777 {
 1778     if(LocalScene.attachwininfos ==1)
 1779     {
 1780         QRect r = geometry();
 1781         LabelInfos.move(r.left(), r.top());
 1782         LabelInfos.setWindowFlags(Qt::WindowStaysOnTopHint| Qt::FramelessWindowHint);
 1783         LabelInfos.setAttribute(Qt::WA_TranslucentBackground);
 1784         LabelInfos.setAttribute(Qt::WA_NoSystemBackground);
 1785         if(LocalScene.infos == 1)
 1786             LabelInfos.show();
 1787     }
 1788     else
 1789     {
 1790         Qt::WindowFlags flags0 = LabelInfos.windowFlags();
 1791         flags0 &= ~Qt::FramelessWindowHint;
 1792         LabelInfos.setWindowFlags(flags0);
 1793         LabelInfos.setAttribute(Qt::WA_TranslucentBackground, false);
 1794         LabelInfos.setAttribute(Qt::WA_NoSystemBackground, false);
 1795         LabelInfos.setStyleSheet("QLabel { background-color : black; color : white; }");
 1796         LabelInfos.setAutoFillBackground(true);
 1797         if(LocalScene.infos == 1)
 1798             LabelInfos.show();
 1799     }
 1800 }
 1801 
 1802 void MathMod::closeEvent(QCloseEvent *)
 1803 {
 1804     LabelInfos.close();
 1805 }
 1806 
 1807 void MathMod::moveEvent(QMoveEvent *)
 1808 {
 1809     if(LocalScene.attachwininfos ==1)
 1810     {
 1811         QRect r = geometry();
 1812         LabelInfos.move(r.x(), r.y());
 1813     }
 1814 }
 1815 
 1816 void MathMod::fill()
 1817 {
 1818     FillOk();
 1819     update();
 1820 }
 1821 
 1822 void MathMod::iso_infos()
 1823 {
 1824     LocalScene.infos *= -1;
 1825     if(LocalScene.infos == 1)
 1826     {
 1827         QRect r = geometry();
 1828         LabelInfos.move(r.x(), r.y());
 1829         LabelInfos.show();
 1830     }
 1831     else
 1832         LabelInfos.hide();
 1833     update();
 1834 }
 1835 
 1836 void MathMod::updateGL()
 1837 {
 1838     update();
 1839 }
 1840 
 1841 void MathMod::draw_norm_clicked()
 1842 {
 1843     normOk();
 1844 }
 1845 
 1846 void MathMod::frames_clicked()
 1847 {
 1848     FramesShot();
 1849 }
 1850 
 1851 void MathMod::linecolumn_valueupdate(int cl)
 1852 {
 1853     ParObjet->Vgrid = Vgrid = ParObjet->Ugrid = Ugrid = uint(cl);
 1854     ParObjet->masterthread->Ugrid =
 1855         ParObjet->masterthread->Vgrid = uint(cl);
 1856 
 1857     for (uint nbthreads = 0;
 1858             nbthreads < ParObjet->WorkerThreadsNumber - 1;
 1859             nbthreads++)
 1860     {
 1861         ParObjet->workerthreads[nbthreads].Ugrid =
 1862             ParObjet->workerthreads[nbthreads].Vgrid = uint(cl);
 1863     }
 1864 }
 1865 
 1866 void MathMod::line_valueupdate(int cl)
 1867 {
 1868     ParObjet->Ugrid = Ugrid = ParObjet->masterthread->Ugrid = uint(cl);
 1869     for (uint nbthreads = 0;
 1870             nbthreads < ParObjet->WorkerThreadsNumber - 1;
 1871             nbthreads++)
 1872     {
 1873         ParObjet->workerthreads[nbthreads].Ugrid = uint(cl);
 1874     }
 1875 }
 1876 
 1877 void MathMod::column_valueupdate(int cl)
 1878 {
 1879     ParObjet->Vgrid = Vgrid = ParObjet->masterthread->Vgrid = uint(cl);
 1880 
 1881     for (uint nbthreads = 0;
 1882             nbthreads < ParObjet->WorkerThreadsNumber - 1;
 1883             nbthreads++)
 1884     {
 1885         ParObjet->workerthreads[nbthreads].Vgrid = uint(cl);
 1886     }
 1887 }
 1888 
 1889 void MathMod::linecolumn_valueChanged(int cl, ModelType type)
 1890 {
 1891     linecolumn_valueupdate(cl);
 1892     if (uvactivated == 1)
 1893         (type == PARISO_TYPE) ? ParisoObjectProcess():ParametricSurfaceProcess(1);
 1894     else
 1895         update();
 1896 }
 1897 
 1898 void MathMod::line_valueChanged(int cl)
 1899 {
 1900     line_valueupdate(cl);
 1901     if (uvactivated == 1)
 1902         ParametricSurfaceProcess(1);
 1903     else
 1904         update();
 1905 }
 1906 
 1907 void MathMod::column_valueChanged(int cl)
 1908 {
 1909     column_valueupdate(cl);
 1910     if (uvactivated == 1)
 1911         ParametricSurfaceProcess(1);
 1912     else
 1913         update();
 1914 }
 1915 
 1916 void MathMod::linecolumn_valueChanged_2(int cl)
 1917 {
 1918     linecolumn_valueupdate(cl);
 1919     if (uvactivated4D == 1)
 1920         ParametricSurfaceProcess(3);
 1921     else
 1922         update();
 1923 }
 1924 
 1925 void MathMod::Initparametricpage()
 1926 {
 1927     LocalScene.typedrawing = -1;
 1928 }
 1929 
 1930 void MathMod::xyzg_valueupdate(int cl)
 1931 {
 1932     IsoObjet->masterthread->XYZgrid = uint(cl);
 1933     Xgrid = Ygrid = Zgrid = cl;
 1934 }
 1935 
 1936 void MathMod::xyzg_valueChanged(int cl, ModelType type)
 1937 {
 1938     xyzg_valueupdate(cl);
 1939     // process the new surface
 1940     if (xyzactivated == 1)
 1941         (type == PARISO_TYPE) ? ParisoObjectProcess() : ProcessNewIsoSurface();
 1942 }
 1943 
 1944 void MathMod::ShowErrormessage()
 1945 {
 1946     message.setTextFormat(Qt::RichText);
 1947     int before, after;
 1948     QString sortie = QString::fromStdString(stError.strError);
 1949     if (sortie.length() > (stError.iErrorIndex + 30))
 1950         after = 30;
 1951     else
 1952         after = sortie.length() - stError.iErrorIndex;
 1953     sortie.truncate(stError.iErrorIndex + after);
 1954     if (stError.iErrorIndex - 30 > 0)
 1955         before = 30;
 1956     else
 1957         before = 0;
 1958     sortie = sortie.remove(0, stError.iErrorIndex - before);
 1959     sortie.replace("\t", " ");
 1960     sortie.replace("\n", " ");
 1961     sortie.insert(before, " <font size=14  color=#FF0033>Error => </font>");
 1962     message.setText("Error at position: " + QString::number(stError.iErrorIndex) +
 1963                     "<br><br>" + "..." + sortie + "...");
 1964     message.adjustSize();
 1965     message.exec();
 1966     return;
 1967 }
 1968 
 1969 int MathMod::ParsePar()
 1970 {
 1971     stError = ParObjet->masterthread->parse_expression();
 1972     if (stError.iErrorIndex >= 0)
 1973     {
 1974         ShowErrormessage();
 1975         return -1;
 1976     }
 1977     else
 1978         ParObjet->ThreadParsersCopy();
 1979     return 1;
 1980 }
 1981 
 1982 void MathMod::ParametricSurfaceProcess(int type)
 1983 {
 1984     if (!ParObjet->isRunning())
 1985     {
 1986         if (type == 3)
 1987         {
 1988             ParObjet->masterthread->param4D = 1;
 1989             ParObjet->param4D = 1;
 1990         }
 1991         else
 1992         {
 1993             ParObjet->masterthread->param4D = -1;
 1994             ParObjet->param4D = -1;
 1995         }
 1996         int result = ParsePar();
 1997         if (result == -1)
 1998             return;
 1999         LocalScene.typedrawing = -1;
 2000         ParObjet->localScene = &(LocalScene);
 2001         ParObjet->start(QThread::LowPriority);
 2002     }
 2003 }
 2004 
 2005 void MathMod::ParisoObjectProcess()
 2006 {
 2007     LocalScene.typedrawing = 0;
 2008     LocalScene.updategl = false;
 2009     LocalScene.componentsinfos.pariso = true;
 2010 
 2011     if (!ParObjet->isRunning())
 2012     {
 2013         ParObjet->masterthread->param4D =
 2014             ParObjet->param4D = -1;
 2015 
 2016         int result = ParsePar();
 2017         if (result == -1)
 2018             return;
 2019         ParObjet->localScene = &(LocalScene);
 2020         ParObjet->start(QThread::LowPriority);
 2021         ParObjet->wait();
 2022     }
 2023     if (!IsoObjet->isRunning())
 2024     {
 2025         int result = ParseIso();
 2026         if (result == -1)
 2027             return;
 2028         IsoObjet->localScene = &(LocalScene);
 2029         IsoObjet->start(QThread::LowPriority);
 2030     }
 2031 }
 2032 
 2033 int MathMod::ParseIso()
 2034 {
 2035     stError = IsoObjet->masterthread->ParserIso();
 2036     if (stError.iErrorIndex >= 0)
 2037     {
 2038         ShowErrormessage();
 2039         return -1;
 2040     }
 2041     else
 2042         IsoObjet->ThreadParsersCopy();
 2043     return 1;
 2044 }
 2045 
 2046 void MathMod::ProcessNewIsoSurface()
 2047 {
 2048     if (!IsoObjet->isRunning())
 2049     {
 2050         int result = ParseIso();
 2051         if (result == -1)
 2052             return;
 2053         LocalScene.typedrawing = 1;
 2054         IsoObjet->localScene = &(LocalScene);
 2055         IsoObjet->start(QThread::LowPriority);
 2056     }
 2057 }
 2058 
 2059 void MathMod::slot_checkBox73_clicked(ModelType type)
 2060 {
 2061     xyzactivated *= -1;
 2062     // process the new surface
 2063     if (xyzactivated == 1)
 2064         (type == PARISO_TYPE) ? ParisoObjectProcess() : ProcessNewIsoSurface();
 2065 }
 2066 
 2067 void MathMod::slot_uv_clicked(ModelType type)
 2068 {
 2069     uvactivated *= -1;
 2070     // process the new surface
 2071     if (uvactivated == 1)
 2072         (type == PARISO_TYPE) ? ParisoObjectProcess() : ParametricSurfaceProcess(1);
 2073 }
 2074 
 2075 void MathMod::slot_uv4D_clicked()
 2076 {
 2077     uvactivated4D *= -1;
 2078     // process the new surface
 2079     if (uvactivated4D == 1)
 2080         ParametricSurfaceProcess(3);
 2081 }
 2082 
 2083 void MathMod::slot_triangles_clicked()
 2084 {
 2085     LocalScene.triangles *= -1;
 2086     update();
 2087 }
 2088 
 2089 void MathMod::Mesh()
 2090 {
 2091     LocalScene.mesh *= -1;
 2092     update();
 2093 }