cctw  0.2.1
cctwchunkeddata.h
Go to the documentation of this file.
1 #ifndef CCTWCHUNKEDDATA_H
2 #define CCTWCHUNKEDDATA_H
3 
4 #include <QVector>
5 #include "cctwobject.h"
6 #include "cctwvector3d.h"
8 #include "qcepproperty.h"
9 #include "hdf5.h"
10 
11 #define NEXUS_ENABLED 0
12 #if NEXUS_ENABLED == 1
13 #include <nexus/NeXusFile.hpp>
14 #endif
15 
16 class CctwDataChunk;
17 class CctwApplication;
18 class CctwTransformer;
19 
21 {
22  Q_OBJECT
23 public:
24  explicit CctwChunkedData(CctwApplication *application,
25  CctwIntVector3D dim, // Data set dimension
26  CctwIntVector3D chunkSize, // Chunk size
27  bool isInput, // is it an input
28  QString name,
29  QObject *parent);
30  void allocateChunks();
31 
32  typedef float MergeDataType;
33 #define CCTW_H5T_INTERNAL_TYPE H5T_NATIVE_FLOAT
34 
35 signals:
39 
40 public:
43 
45  void setChunkSize(CctwIntVector3D cksz);
46 
47  void setMaskDimensions(int mx, int my);
48  void setAnglesDimensions(int n);
49  void setWeightsDimensions(int n);
50 
51  void incChunksRead(int n);
52  void incChunksWritten(int n);
53  void incChunksHeld(int n);
54 
55 public slots:
56  void sizingChanged();
57  virtual void setDataSource(QString desc);
58  virtual void setDims(QString desc);
59  virtual void setChunks(QString desc);
60  virtual void setDataset(QString desc);
61  virtual void setMaskSource(QString desc);
62  virtual void setMaskDataset(QString desc);
63  virtual void setAnglesSource(QString desc);
64  virtual void setAnglesDataset(QString desc);
65  virtual void setWeightsSource(QString desc);
66  virtual void setWeightsDataset(QString desc);
67  bool containsPixel(CctwIntVector3D pixelCoord);
68  bool containsChunk(int ix, int iy, int iz);
69  int allocatedChunkCount();
70 
71  void setAngle(int n, double v);
72  double angle(int n);
73 
74  void setWeight(int n, double v);
75  double weight(int n);
76 
77  CctwIntVector3D chunkStart(int n); // Return pixel coords of start of chunk chunkIdx
78  int chunkContaining(CctwIntVector3D pixelCoord); // Return index of chunk containing given pixel
79  int chunkContaining(CctwDoubleVector3D fracPixelCoord); // Return index of chunk containing fractional pixel coords
81 
84 
85  void clearDependencies();
86  void addDependency(int f, int t);
87 
88  CctwDataChunk *chunk(int n);
90 
91  CctwDataChunk *readChunk(int n);
92  void writeChunk(int n);
93  void releaseChunk(int n);
94  void releaseChunkData(int n);
95  void normalizeChunk(int n);
97  void clearMergeCounters();
98 
99  bool beginTransform(bool isInput, int transformOptions);
100  void endTransform();
101 
102  bool openOutputFile();
103  bool checkInputFile();
104  bool openInputFile(bool quietly = false);
105  bool openInputNeXusFile();
106  void flushOutputFile();
107  void closeOutputFile();
108  void closeInputFile();
109  void closeInputNeXusFile();
110 
111  bool checkMaskFile();
112  bool openMaskFile(bool quietly = false);
113  void closeMaskFile();
114  bool readMaskFile();
115 
116  bool checkAnglesFile();
117  bool openAnglesFile(bool quietly = false);
118  void closeAnglesFile();
119  bool readAnglesFile();
120 
121  bool checkWeightsFile();
122  bool openWeightsFile(bool quietly = false);
123  void closeWeightsFile();
124  bool readWeightsFile();
125 
126 private slots:
127  void onDataFileNameChanged();
128  void onMaskFileNameChanged();
129  void onAnglesChanged();
130 
131 protected:
133 
134  QVector< CctwDataChunk* > m_DataChunks;
136  bool m_IsNeXus;
137 #if NEXUS_ENABLED == 1
138  NeXus::File *m_NeXusFile;
139 #endif
140 
141 private:
142  QMutex m_ChunkLock;
146 
147  Q_PROPERTY(QString dataFileName READ get_DataFileName WRITE set_DataFileName)
148  QCEP_STRING_PROPERTY(DataFileName)
149 
150  Q_PROPERTY(QString dataSetName READ get_DataSetName WRITE set_DataSetName)
151  QCEP_STRING_PROPERTY(DataSetName)
152 
153  Q_PROPERTY(QString maskDataFileName READ get_MaskDataFileName WRITE set_MaskDataFileName)
154  QCEP_STRING_PROPERTY(MaskDataFileName)
155 
156  Q_PROPERTY(QString maskDataSetName READ get_MaskDataSetName WRITE set_MaskDataSetName)
157  QCEP_STRING_PROPERTY(MaskDataSetName)
158 
159  Q_PROPERTY(QcepIntVector mask READ get_Mask WRITE set_Mask STORED false)
160  QCEP_INTEGER_VECTOR_PROPERTY(Mask)
161 
162  Q_PROPERTY(QString anglesDataFileName READ get_AnglesDataFileName WRITE set_AnglesDataFileName)
163  QCEP_STRING_PROPERTY(AnglesDataFileName)
164 
165  Q_PROPERTY(QString anglesDataSetName READ get_AnglesDataSetName WRITE set_AnglesDataSetName)
166  QCEP_STRING_PROPERTY(AnglesDataSetName)
167 
168  Q_PROPERTY(QcepDoubleVector angles READ get_Angles WRITE set_Angles STORED false)
169  QCEP_DOUBLE_VECTOR_PROPERTY(Angles)
170 
171  Q_PROPERTY(QString weightsDataFileName READ get_WeightsDataFileName WRITE set_WeightsDataFileName)
172  QCEP_STRING_PROPERTY(WeightsDataFileName)
173 
174  Q_PROPERTY(QString weightsDataSetName READ get_WeightsDataSetName WRITE set_WeightsDataSetName)
175  QCEP_STRING_PROPERTY(WeightsDataSetName)
176 
177  Q_PROPERTY(QcepDoubleVector weights READ get_Weights WRITE set_Weights STORED false)
178  QCEP_DOUBLE_VECTOR_PROPERTY(Weights)
179 
180  Q_PROPERTY(CctwIntVector3D dimensions READ get_Dimensions WRITE set_Dimensions)
181  CCTW_INTVECTOR3D_PROPERTY(Dimensions)
182 
183  Q_PROPERTY(CctwIntVector3D chunkSize READ get_ChunkSize WRITE set_ChunkSize)
184  CCTW_INTVECTOR3D_PROPERTY(ChunkSize)
185 
186  Q_PROPERTY(CctwIntVector3D chunkCount READ get_ChunkCount WRITE set_ChunkCount STORED false)
187  CCTW_INTVECTOR3D_PROPERTY(ChunkCount)
188 
189  Q_PROPERTY(int compression READ get_Compression WRITE set_Compression)
190  QCEP_INTEGER_PROPERTY(Compression)
191 
192  Q_PROPERTY(int normalization READ get_Normalization WRITE set_Normalization)
193  QCEP_INTEGER_PROPERTY(Normalization)
194 
195  Q_PROPERTY(CctwIntVector3D hdfChunkSize READ get_HDFChunkSize WRITE set_HDFChunkSize)
196  CCTW_INTVECTOR3D_PROPERTY(HDFChunkSize)
197 
198  Q_PROPERTY(int chunksRead READ get_ChunksRead WRITE set_ChunksRead STORED false)
199  QCEP_INTEGER_PROPERTY(ChunksRead)
200 
201  Q_PROPERTY(int chunksWritten READ get_ChunksWritten WRITE set_ChunksWritten STORED false)
202  QCEP_INTEGER_PROPERTY(ChunksWritten)
203 
204  Q_PROPERTY(int chunksHeld READ get_ChunksHeld WRITE set_ChunksHeld STORED false)
205  QCEP_INTEGER_PROPERTY(ChunksHeld)
206 
207  Q_PROPERTY(int chunksHeldMax READ get_ChunksHeldMax WRITE set_ChunksHeldMax STORED false)
208  QCEP_INTEGER_PROPERTY(ChunksHeldMax)
209 
210  bool m_IsInput;
212  hid_t m_FileId;
213  hid_t m_DatasetId;
217 
218  bool m_MaskSameFile; // If mask is in input data file
222 
223  bool m_AnglesSameFile; // If angles are in input data file
227 
228  bool m_WeightsSameFile; // If weights are in input data file
232 
233  static QMutex m_FileAccessMutex;
234 };
235 
236 #endif // CCTWCHUNKEDDATA_H
void incChunksHeld(int n)
bool beginTransform(bool isInput, int transformOptions)
virtual void setMaskDataset(QString desc)
virtual void setWeightsSource(QString desc)
QcepIntVector mask
double angle(int n)
CctwIntVector3D chunkIndexFromNumber(int n)
virtual void setAnglesSource(QString desc)
CctwIntVector3D chunkStart(int n)
void releaseChunkData(int n)
void writeChunk(int n)
QString name
Definition: cctwobject.h:32
virtual void setWeightsDataset(QString desc)
CctwDataChunk * chunk(int n)
bool containsChunk(int ix, int iy, int iz)
void releaseChunk(int n)
void setMaskDimensions(int mx, int my)
void addDependency(int f, int t)
CctwIntVector3D m_DimensionsCache
void setDimensions(CctwIntVector3D dim)
virtual void setChunks(QString desc)
bool openInputFile(bool quietly=false)
CctwIntVector3D chunkSize() const
virtual void setDataset(QString desc)
void setWeightsDimensions(int n)
bool openMaskFile(bool quietly=false)
void mergeChunk(CctwDataChunk *chunk)
QString maskDataFileName
void setAnglesDimensions(int n)
void chunkSizeChanged(CctwIntVector3D sz)
#define CCTW_INTVECTOR3D_PROPERTY(propname)
virtual void setDataSource(QString desc)
QcepDoubleVector weights
CctwIntVector3D m_ChunkCountCache
virtual void setDims(QString desc)
void normalizeChunk(int n)
CctwIntVector3D dimensions() const
int chunkContaining(CctwIntVector3D pixelCoord)
CctwChunkedData(CctwApplication *application, CctwIntVector3D dim, CctwIntVector3D chunkSize, bool isInput, QString name, QObject *parent)
void setChunkSize(CctwIntVector3D cksz)
QString anglesDataFileName
void chunkCountChanged(CctwIntVector3D ct)
CctwIntVector3D chunkCount() const
void incChunksRead(int n)
bool openWeightsFile(bool quietly=false)
QVector< CctwDataChunk * > m_DataChunks
bool containsPixel(CctwIntVector3D pixelCoord)
QString anglesDataSetName
QString weightsDataFileName
QcepDoubleVector angles
bool openAnglesFile(bool quietly=false)
CctwIntVector3D hdfChunkSize
CctwIntVector3D m_ChunkSizeCache
void incChunksWritten(int n)
double weight(int n)
void setWeight(int n, double v)
void dimensionsChanged(CctwIntVector3D dm)
static QMutex m_FileAccessMutex
void setAngle(int n, double v)
QString weightsDataSetName
CctwApplication * m_Application
virtual void setMaskSource(QString desc)
int chunkNumberFromIndex(CctwIntVector3D chunkIdx)
virtual void setAnglesDataset(QString desc)
CctwDataChunk * readChunk(int n)