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 
21 #include <map>
22 #include <vector>
23 #include <iostream>
24 #include <string.h>
25 #include <cmath>
26 #include "../parisoobject.h"
27 #include "ND/Matrix4D.h"
28 #include <qthread.h>
29 using std::string;
30 
31 struct   ParStruct
32 {
33     std::string fx;
34     std::string fy;
35     std::string fz;
36     std::string fw;
37     std::string cnd;
38     std::string umin;
39     std::string umax;
40     std::string vmin;
41     std::string vmax;
42     std::string grid;
43     int  index;
44 };
45 
46 class ParWorkerThread : public WorkerThread
47 {
48     Q_OBJECT
49 public :
50     uint Ugrid, Vgrid;
51     FunctionParser *myParserZ, *myParserW, *myParserX, *myParserY, *Fct;
52     FunctionParser_cd *myParserZ_C, *myParserW_C, *myParserX_C, *myParserY_C, *Fct_C;
53     std::vector<double>  v_inf, v_sup,u_inf,u_sup,dif_v,dif_u;
54     int param4D;
55     bool param3d_C, param4d_C;
56     uint CurrentIndex;
57 
58 public :
59     void ParCompute(uint component =0, uint idx=0);
60     void AllocateParsersForWorkerThread(uint, uint);
61     void DeleteWorkerParsers();
62     void run() Q_DECL_OVERRIDE;
63     ParWorkerThread();
64     ~ParWorkerThread() override;
65     void emitMySignal();
66 signals:
67     void mySignal(int);
68 
69 };
70 
71 class ParMasterThread : public MasterThread, public ParWorkerThread
72 {
73 public :
74     FunctionParser *myParserUmin,*myParserUmax,
75                    *myParserVmin,*myParserVmax;
76     std::vector<ParStruct> ParamStructs;
77     uint componentsNumber;
78     std::string  expression_X, expression_Y, expression_Z, expression_W, expression_CND, inf_u, sup_u, inf_v, sup_v;
79     int expression_YSize, expression_ZSize, expression_WSize,
80         inf_uSize, sup_uSize, inf_vSize, sup_vSize;
81 public :
82     void InitMasterParsers();
83     void  HowManyParamSurface(std::string, int);
84     uint  HowManyVariables(std::string, int);
85     ErrorMessage parse_expression();
86     void AllocateParsersForMasterThread();
87     void AllocateParsersForThread();
88     void DeleteMasterParsers();
89     ParMasterThread();
90     ~ParMasterThread();
91 };
92 
93 /** The representation of a 3D model */
94 class Par3D : public ParisoObject
95 {
96     Q_OBJECT
97 public:
98     ParMasterThread *masterthread;
99     ParWorkerThread *workerthreads;
100     uint Ugrid, Vgrid;
101     uint CutV, CutU;
102     float MINX,MINY,MINZ,MINW,
103           MAXX,MAXY,MAXZ,MAXW,
104           DIFX,DIFY,DIFZ,DIFW,
105           DIFMAXIMUM;
106     Matrix4D mat4D, mat_rotation4D, mat_rotation_save4D,
107              mat_homothetie4D, mat_translation4D, mat_inversetranslation4D;
108     double tetaxy, tetaxz, tetayz, tetaxw, tetayw, tetazw;
109     int tetaxy_ok, tetaxz_ok, tetayz_ok, tetaxw_ok, tetayw_ok, tetazw_ok, param4D;
110 public:
111     Par3D(uint nbThreads, uint nbGrid);
112     ~Par3D()  override;
113     void rotation4();
114     void calcul_points4(uint idx=0);
115     void Anim_Rot4D (uint idx=0);
116     void project_4D_to_3D(uint idx=0);
117     void Invert_boite_englobante4D(uint idx=0);
118     void boite_englobante4D(uint index=0);
119     void initialiser_parametres(uint, uint);
120     void initialiser_LineColumn(uint, uint);
121     void calcul_Norm(uint i=0);
122     void make_PolyIndexTri(uint);
123     void make_PolyIndexMin(uint, ComponentInfos *);
124     uint CNDCalculation(uint &, struct ComponentInfos *);
125     void CalculateColorsPoints(struct ComponentInfos *, uint);
126     void ParamBuild(float **, uint **, uint *,
127                     uint *, ComponentInfos *,
128                     uint **,
129                     uint *,
130                     uint *);
131 
132     void InitShowComponent(struct ComponentInfos *);
133     void BuildPar();
134     void UpdateThredsNumber(uint);
135     void stopcalculations(bool);
136     void WorkerThreadCopy(ParWorkerThread *);
137     void MasterThreadCopy(ParMasterThread *);
138     ErrorMessage ThreadParsersCopy();
139     ErrorMessage  parse_expression2();
140     ErrorMessage  parse_expression2_C();
141     ErrorMessage  ParMorph();
142     void copycomponent(struct ComponentInfos*, struct ComponentInfos*);
143     void run() Q_DECL_OVERRIDE;
144 public :
145     void emitErrorSignal();
146     void emitUpdateMessageSignal();
147 signals:
148     void ErrorSignal(int);
149     void UpdateMessageSignal(QString);
150 };
151