Advertisement
mzagar

CadWorkThread.cc

Jun 25th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "CadWorkThread.hh"
  2. #include <iostream>
  3.  
  4. using namespace  std;
  5.  
  6.  
  7.  
  8.  
  9.  
  10. CadWorkThread::CadWorkThread(QObject *parent) : QObject(parent)
  11. {
  12.  
  13.     threadcount=QThread::idealThreadCount();
  14.     for (int i=0; i < threadcount; ++i) {
  15.         QThread * thread = new QThread;
  16.         //connect(thread, SIGNAL(finished()), SLOT(threadDone()));
  17.         //thread->start();
  18.         threads << thread;
  19.     }
  20.  
  21.     tfinished = 0;
  22.  
  23.    
  24.  
  25.  
  26.     /*
  27.     void poolObject(QObject* obj) const {
  28.         if (nextThread >= threads.count()) nextThread = 0;
  29.         QThread* thread = threads.at(nextThread);
  30.         obj->moveToThread(thread);
  31.     }
  32.     */
  33.  
  34. }
  35.  
  36. void CadWorkThread::startCadThread(int model,
  37.     MeshStructureLayers layers,
  38.     Handle_AIS_InteractiveContext theContext,
  39.     Handle_TDocStd_Document aDoc,
  40.     MyMesh & mesh,
  41.     int detail_vertex,
  42.     double insulation_thickness,
  43.     OpenMesh::VPropHandleT<MyMesh::Scalar> _max_beam_offset,
  44.     double podatki[20],
  45.     int genType,
  46.     int meshNum,
  47.     CadPanel *&paneli,
  48.     int npanelov)
  49. {
  50.  
  51.  
  52.     myContext=theContext;
  53.     tfinished=0;
  54.     //razdeli mrežo na enake dele
  55.     MyMesh::ConstFaceIter f_end = mesh.faces_end();
  56.     int f_e=f_end.handle().idx();
  57.     MyMesh::ConstEdgeIter e_end = mesh.edges_end();
  58.     int e_e=e_end.handle().idx();
  59.     MyMesh::ConstVertexIter v_end = mesh.vertices_end();
  60.     int v_e=v_end.handle().idx();
  61.  
  62.     cout<<f_e<<endl;
  63.     cout<<e_e<<endl;
  64.     cout<<v_e<<endl;
  65.  
  66.     int f1,f2,e1,e2,v1,v2;
  67.  
  68.     f1=f_e/threadcount+f_e%threadcount;
  69.     f2=f_e/threadcount;
  70.     e1=e_e/threadcount+e_e%threadcount;
  71.     e2=e_e/threadcount;
  72.     v1=v_e/threadcount+v_e%threadcount;
  73.     v2=v_e/threadcount;
  74.  
  75.     cout<<"threadcount= "<<threadcount<<endl;
  76.  
  77.  
  78.     for(int i=0;i<threadcount;i++){
  79.  
  80.         int minmax[6];
  81.         if(i==0){
  82.  
  83.             minmax[0]=0;
  84.             minmax[1]=f1-1;
  85.             minmax[2]=0;
  86.             minmax[3]=e1-1;
  87.             minmax[4]=0;
  88.             minmax[5]=v1-1;
  89.         }
  90.         else{
  91.  
  92.             minmax[0]=f1+(i-1)*f2;
  93.             minmax[1]=minmax[0]+f2-1;
  94.             minmax[2]=e1+(i-1)*e2;
  95.             minmax[3]=minmax[2]+e2-1;
  96.             minmax[4]=v1+(i-1)*v2;
  97.             minmax[5]=minmax[4]+v2-1;
  98.         }
  99.  
  100.         CadThread * cThread = new CadThread(this);
  101.         cThreads<<cThread;
  102.  
  103.         cout<<minmax[0]<<", "<<minmax[1]<<", "<<minmax[2]<<", "<<minmax[3]<<", "<<minmax[4]<<", "<<minmax[5]<<endl;
  104.        
  105.         cadData aCadData;
  106.         aCadData.model=model;
  107.         aCadData.minmax[0]=minmax[0];
  108.         aCadData.minmax[1]=minmax[1];
  109.         aCadData.minmax[2]=minmax[2];
  110.         aCadData.minmax[3]=minmax[3];
  111.         aCadData.minmax[4]=minmax[4];
  112.         aCadData.minmax[5]=minmax[5];
  113.         aCadData.layers=layers;
  114.         aCadData.theContext=theContext;
  115.         aCadData.aDoc=aDoc;
  116.         aCadData.mesh=mesh;
  117.         aCadData.detail_vertex=detail_vertex;
  118.         aCadData.insulation_thickness=insulation_thickness;
  119.         aCadData._max_beam_offset=_max_beam_offset;
  120.         for(int j=0;j<20;j++) aCadData.podatki[j]=podatki[j];
  121.         aCadData.genType=genType;
  122.         aCadData.meshNum=meshNum;
  123.         aCadData.paneli=paneli;
  124.         aCadData.npanelov=npanelov;
  125.  
  126.         aCadDatas<<aCadData;
  127.         //QThread* thread = threads.at(i);
  128.         //connect(this, SIGNAL(startMake()), cThread, SLOT(MakeMesh()));
  129.         //connect(cThread, SIGNAL(done()), this, SLOT(threadDone()));
  130.        
  131.         //cThread->moveToThread(thread);
  132.         //thread->start();
  133.  
  134.  
  135.        
  136.        
  137.        
  138.     }
  139.  
  140.  
  141.     connect(this, SIGNAL(startMake1(cadData)), cThreads.at(0), SLOT(MakeMesh(cadData)));
  142.     connect(this, SIGNAL(startMake2(cadData)), cThreads.at(1), SLOT(MakeMesh(cadData)));
  143.     connect(this, SIGNAL(startMake3(cadData)), cThreads.at(2), SLOT(MakeMesh(cadData)));
  144.     connect(this, SIGNAL(startMake4(cadData)), cThreads.at(3), SLOT(MakeMesh(cadData)));
  145.  
  146.     cThreads.at(0)->moveToThread(threads.at(0));
  147.     cThreads.at(1)->moveToThread(threads.at(1));
  148.     cThreads.at(2)->moveToThread(threads.at(2));
  149.     cThreads.at(3)->moveToThread(threads.at(3));
  150.  
  151.     threads.at(0)->start();
  152.     threads.at(1)->start();
  153.     threads.at(2)->start();
  154.     threads.at(3)->start();
  155.  
  156.    
  157.     emit startMake1(aCadDatas.at(0));
  158.     emit startMake2(aCadDatas.at(1));
  159.     emit startMake3(aCadDatas.at(2));
  160.     emit startMake4(aCadDatas.at(3));
  161.  
  162.  
  163.  
  164. }
  165.  
  166. void CadWorkThread::threadDone()
  167. {
  168.     tfinished++;
  169.  
  170.     cout<<"I finished"<<endl;
  171.     if(tfinished==threadcount){
  172.  
  173.        
  174.        
  175.        
  176.        
  177.         }
  178. }
  179.  
  180.  
  181. CadThread::CadThread(QObject* parent) : QObject(parent)
  182. {
  183.  
  184.    
  185.    
  186. }
  187.  
  188. void CadThread::MakeMesh(cadData aCadData)
  189. {
  190.     cout<<" I am working"<<endl;
  191.  
  192.  
  193.     if (aCadData.model == 1)
  194.         MeshStructure1::MakeMeshStructure(aCadData.minmax,
  195.         aCadData.layers,
  196.         aCadData.theContext,
  197.         aCadData.aDoc,
  198.         aCadData.mesh,
  199.         aCadData.detail_vertex,
  200.         aCadData.insulation_thickness,
  201.         aCadData._max_beam_offset);
  202.     if (aCadData.model == 2)
  203.         MeshStructure2::MakeMeshStructure(aCadData.minmax,
  204.         aCadData.layers,
  205.         aCadData.theContext,
  206.         aCadData.aDoc,
  207.         aCadData.mesh,
  208.         aCadData.detail_vertex,
  209.         aCadData.insulation_thickness,
  210.         aCadData._max_beam_offset);
  211.     if (aCadData.model == 3)
  212.         MeshStructure3::MakeMeshStructure(aCadData.minmax,
  213.         aCadData.layers,
  214.         aCadData.theContext,
  215.         aCadData.aDoc,
  216.         aCadData.mesh,
  217.         aCadData.detail_vertex,
  218.         aCadData.insulation_thickness,
  219.         aCadData._max_beam_offset);
  220.  
  221.     if (aCadData.model == 4)
  222.         MeshStructure4::MakeMeshStructure(aCadData.minmax,
  223.         aCadData.layers,
  224.         aCadData.theContext,
  225.         aCadData.aDoc,
  226.         aCadData.mesh,
  227.         aCadData.detail_vertex,
  228.         aCadData.insulation_thickness,
  229.         aCadData._max_beam_offset,
  230.         aCadData.podatki,aCadData.genType, aCadData.meshNum, aCadData.paneli,aCadData.npanelov);
  231.  
  232.  
  233.     emit done();
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement