00001 #ifndef FlowDataWorker_H 00002 #define FlowDataWorker_H 00003 00004 #include <QString> 00005 #include <QObject> 00006 #include <QSize> 00007 #include <QThread> 00008 #include <QMutex> 00009 #include <QMutexLocker> 00010 00011 #include "FlowData.h" 00012 #include "Vector3.h" 00013 00014 template<class T> class FlowDataWorker : public QThread 00015 { 00016 public: 00017 FlowDataWorker(QObject *object); 00018 ~FlowDataWorker(); 00019 00020 void setFlowData(FlowData *flowData); 00021 void setSize(QSize size); 00022 00023 T* getData(); 00024 00025 protected: 00026 void stopCalculate(); 00027 00028 QObject *object; 00029 FlowData *flowData; 00030 QSize size; 00031 T *data; 00032 QMutex mutex; 00033 }; 00034 00035 class FlowDataWorkerVector : public FlowDataWorker<Vector3> 00036 { 00037 public: 00038 FlowDataWorkerVector(QObject *object); 00039 00040 void calculate(); 00041 00042 private: 00043 void run(); 00044 }; 00045 00046 class FlowDataWorkerScalar : public FlowDataWorker<float> 00047 { 00048 public: 00049 FlowDataWorkerScalar(QObject *object); 00050 00051 void setScalarIndex(int scalarIndex); 00052 00053 void calculate(); 00054 00055 private: 00056 void run(); 00057 00058 int scalarIndex; 00059 bool calculating; 00060 }; 00061 00062 // ### FlowDataWorker ### 00063 00064 template<class T> FlowDataWorker<T>::FlowDataWorker(QObject *object) 00065 { 00066 this->object = object; 00067 flowData = 0; 00068 data = 0; 00069 } 00070 00071 template<class T> FlowDataWorker<T>::~FlowDataWorker() 00072 { 00073 QMutexLocker locker(&mutex); 00074 if(data != 0) 00075 { 00076 delete [] data; 00077 data = 0; 00078 } 00079 } 00080 00081 template<class T> void FlowDataWorker<T>::setFlowData(FlowData *flowData) 00082 { 00083 QMutexLocker locker(&mutex); 00084 this->flowData = flowData; 00085 } 00086 00087 template<class T> void FlowDataWorker<T>::setSize(QSize size) 00088 { 00089 QMutexLocker locker(&mutex); 00090 this->size = size; 00091 } 00092 00093 template<class T> T* FlowDataWorker<T>::getData() 00094 { 00095 QMutexLocker locker(&mutex); 00096 T *tempData = data; 00097 data = 0; 00098 00099 return tempData; 00100 } 00101 00102 template<class T> void FlowDataWorker<T>::stopCalculate() 00103 { 00104 // TODO: stop threads 00105 /*if(newData != 0) 00106 { 00107 delete [] newData; 00108 newData = 0; 00109 }*/ 00110 } 00111 00112 #endif // FlowDataWorker_H