Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "CadWorkThread.hh"
- #include <iostream>
- using namespace std;
- CadWorkThread::CadWorkThread(QObject *parent) : QObject(parent)
- {
- threadcount=QThread::idealThreadCount();
- for (int i=0; i < threadcount; ++i) {
- QThread * thread = new QThread;
- //connect(thread, SIGNAL(finished()), SLOT(threadDone()));
- //thread->start();
- threads << thread;
- }
- tfinished = 0;
- /*
- void poolObject(QObject* obj) const {
- if (nextThread >= threads.count()) nextThread = 0;
- QThread* thread = threads.at(nextThread);
- obj->moveToThread(thread);
- }
- */
- }
- void CadWorkThread::startCadThread(int model,
- MeshStructureLayers layers,
- Handle_AIS_InteractiveContext theContext,
- Handle_TDocStd_Document aDoc,
- MyMesh & mesh,
- int detail_vertex,
- double insulation_thickness,
- OpenMesh::VPropHandleT<MyMesh::Scalar> _max_beam_offset,
- double podatki[20],
- int genType,
- int meshNum,
- CadPanel *&paneli,
- int npanelov)
- {
- myContext=theContext;
- tfinished=0;
- //razdeli mrežo na enake dele
- MyMesh::ConstFaceIter f_end = mesh.faces_end();
- int f_e=f_end.handle().idx();
- MyMesh::ConstEdgeIter e_end = mesh.edges_end();
- int e_e=e_end.handle().idx();
- MyMesh::ConstVertexIter v_end = mesh.vertices_end();
- int v_e=v_end.handle().idx();
- cout<<f_e<<endl;
- cout<<e_e<<endl;
- cout<<v_e<<endl;
- int f1,f2,e1,e2,v1,v2;
- f1=f_e/threadcount+f_e%threadcount;
- f2=f_e/threadcount;
- e1=e_e/threadcount+e_e%threadcount;
- e2=e_e/threadcount;
- v1=v_e/threadcount+v_e%threadcount;
- v2=v_e/threadcount;
- cout<<"threadcount= "<<threadcount<<endl;
- for(int i=0;i<threadcount;i++){
- int minmax[6];
- if(i==0){
- minmax[0]=0;
- minmax[1]=f1-1;
- minmax[2]=0;
- minmax[3]=e1-1;
- minmax[4]=0;
- minmax[5]=v1-1;
- }
- else{
- minmax[0]=f1+(i-1)*f2;
- minmax[1]=minmax[0]+f2-1;
- minmax[2]=e1+(i-1)*e2;
- minmax[3]=minmax[2]+e2-1;
- minmax[4]=v1+(i-1)*v2;
- minmax[5]=minmax[4]+v2-1;
- }
- CadThread * cThread = new CadThread(this);
- cThreads<<cThread;
- cout<<minmax[0]<<", "<<minmax[1]<<", "<<minmax[2]<<", "<<minmax[3]<<", "<<minmax[4]<<", "<<minmax[5]<<endl;
- cadData aCadData;
- aCadData.model=model;
- aCadData.minmax[0]=minmax[0];
- aCadData.minmax[1]=minmax[1];
- aCadData.minmax[2]=minmax[2];
- aCadData.minmax[3]=minmax[3];
- aCadData.minmax[4]=minmax[4];
- aCadData.minmax[5]=minmax[5];
- aCadData.layers=layers;
- aCadData.theContext=theContext;
- aCadData.aDoc=aDoc;
- aCadData.mesh=mesh;
- aCadData.detail_vertex=detail_vertex;
- aCadData.insulation_thickness=insulation_thickness;
- aCadData._max_beam_offset=_max_beam_offset;
- for(int j=0;j<20;j++) aCadData.podatki[j]=podatki[j];
- aCadData.genType=genType;
- aCadData.meshNum=meshNum;
- aCadData.paneli=paneli;
- aCadData.npanelov=npanelov;
- aCadDatas<<aCadData;
- //QThread* thread = threads.at(i);
- //connect(this, SIGNAL(startMake()), cThread, SLOT(MakeMesh()));
- //connect(cThread, SIGNAL(done()), this, SLOT(threadDone()));
- //cThread->moveToThread(thread);
- //thread->start();
- }
- connect(this, SIGNAL(startMake1(cadData)), cThreads.at(0), SLOT(MakeMesh(cadData)));
- connect(this, SIGNAL(startMake2(cadData)), cThreads.at(1), SLOT(MakeMesh(cadData)));
- connect(this, SIGNAL(startMake3(cadData)), cThreads.at(2), SLOT(MakeMesh(cadData)));
- connect(this, SIGNAL(startMake4(cadData)), cThreads.at(3), SLOT(MakeMesh(cadData)));
- cThreads.at(0)->moveToThread(threads.at(0));
- cThreads.at(1)->moveToThread(threads.at(1));
- cThreads.at(2)->moveToThread(threads.at(2));
- cThreads.at(3)->moveToThread(threads.at(3));
- threads.at(0)->start();
- threads.at(1)->start();
- threads.at(2)->start();
- threads.at(3)->start();
- emit startMake1(aCadDatas.at(0));
- emit startMake2(aCadDatas.at(1));
- emit startMake3(aCadDatas.at(2));
- emit startMake4(aCadDatas.at(3));
- }
- void CadWorkThread::threadDone()
- {
- tfinished++;
- cout<<"I finished"<<endl;
- if(tfinished==threadcount){
- }
- }
- CadThread::CadThread(QObject* parent) : QObject(parent)
- {
- }
- void CadThread::MakeMesh(cadData aCadData)
- {
- cout<<" I am working"<<endl;
- if (aCadData.model == 1)
- MeshStructure1::MakeMeshStructure(aCadData.minmax,
- aCadData.layers,
- aCadData.theContext,
- aCadData.aDoc,
- aCadData.mesh,
- aCadData.detail_vertex,
- aCadData.insulation_thickness,
- aCadData._max_beam_offset);
- if (aCadData.model == 2)
- MeshStructure2::MakeMeshStructure(aCadData.minmax,
- aCadData.layers,
- aCadData.theContext,
- aCadData.aDoc,
- aCadData.mesh,
- aCadData.detail_vertex,
- aCadData.insulation_thickness,
- aCadData._max_beam_offset);
- if (aCadData.model == 3)
- MeshStructure3::MakeMeshStructure(aCadData.minmax,
- aCadData.layers,
- aCadData.theContext,
- aCadData.aDoc,
- aCadData.mesh,
- aCadData.detail_vertex,
- aCadData.insulation_thickness,
- aCadData._max_beam_offset);
- if (aCadData.model == 4)
- MeshStructure4::MakeMeshStructure(aCadData.minmax,
- aCadData.layers,
- aCadData.theContext,
- aCadData.aDoc,
- aCadData.mesh,
- aCadData.detail_vertex,
- aCadData.insulation_thickness,
- aCadData._max_beam_offset,
- aCadData.podatki,aCadData.genType, aCadData.meshNum, aCadData.paneli,aCadData.npanelov);
- emit done();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement