cctw  0.2.1
Public Slots | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CctwDataChunk Class Reference

#include <cctwdatachunk.h>

Inheritance diagram for CctwDataChunk:
Inheritance graph
Collaboration diagram for CctwDataChunk:
Collaboration graph

Public Slots

int allocateData ()
 
int allocateWeights ()
 
int deallocateData ()
 
int deallocateWeights ()
 
int detachData ()
 
int detachWeights ()
 
bool dataAllocated () const
 
bool weightsAllocated () const
 
CctwChunkedData::MergeDataType data (int lx, int ly, int lz)
 
CctwChunkedData::MergeDataType weight (int lx, int ly, int lz)
 
void setData (int lx, int ly, int lz, CctwChunkedData::MergeDataType val)
 
void setWeight (int lx, int ly, int lz, CctwChunkedData::MergeDataType val)
 
int pixelOffset (int lx, int ly, int lz)
 
CctwChunkedData::MergeDataTypedataPointer ()
 
CctwChunkedData::MergeDataTypeweightsPointer ()
 
CctwIntVector3D chunkStart ()
 
void resetChunkStart ()
 
CctwIntVector3D chunkSize ()
 
void setChunkSize (CctwIntVector3D size)
 
void clearDependencies ()
 
void addDependency (int dep)
 
void sortDependencies ()
 
int dependencyCount () const
 
int dependency (int n) const
 
void reportDependencies ()
 
int index () const
 
void mergeChunk (CctwDataChunk *c)
 
void clearMergeCounters ()
 
void incMergeCounters ()
 
int mergeCount ()
 
bool popMergeData (CctwChunkedData::MergeDataType **data, CctwChunkedData::MergeDataType **weights)
 
void pushMergeData (CctwChunkedData::MergeDataType *data, CctwChunkedData::MergeDataType *weights)
 
void normalizeChunk ()
 
static void resetAllocationLimits (int nmax)
 
static int maxAllocated ()
 
void setBuffer (void *buffer)
 
void mergeData (CctwChunkedData::MergeDataType *id, CctwChunkedData::MergeDataType *iw, int n)
 
static int allocatedChunkCount ()
 
- Public Slots inherited from CctwObject
virtual void printLine (QString line)
 
virtual void printMessage (QString msg, QDateTime dt=QDateTime::currentDateTime())
 
virtual QString settingsScript ()
 
QString scriptValueLiteral (QVariant v)
 

Public Member Functions

 CctwDataChunk (CctwChunkedData *data, int index, QString name, QObject *parent)
 
virtual ~CctwDataChunk ()
 
- Public Member Functions inherited from CctwObject
 CctwObject (QString name, QObject *parent=0)
 
virtual void writeSettings (QSettings *set, QString section)
 
virtual void readSettings (QSettings *set, QString section)
 

Private Member Functions

CctwChunkedData::MergeDataTypeallocateBuffer ()
 
void releaseBuffer (CctwChunkedData::MergeDataType *)
 
CctwIntVector3D calculateChunkStart ()
 
CctwIntVector3D calculateChunkSize ()
 

Private Attributes

CctwChunkedDatam_Data
 
int m_ChunkIndex
 
CctwIntVector3D m_ChunkStart
 
CctwIntVector3D m_ChunkSize
 
CctwChunkedData::MergeDataTypem_ChunkData
 
CctwChunkedData::MergeDataTypem_ChunkWeights
 
int m_Normalized
 
int m_DataWritten
 
int m_WeightsWritten
 
QVector< int > m_Dependencies
 
QMutex m_DependenciesLock
 
QMutex m_MergeLock
 
int m_MergeCounter
 
QList< CctwChunkedData::MergeDataType * > m_MergeData
 
QList< CctwChunkedData::MergeDataType * > m_MergeWeights
 
bool m_OwnData
 

Additional Inherited Members

- Properties inherited from CctwObject
QString name
 

Detailed Description

Definition at line 11 of file cctwdatachunk.h.

Constructor & Destructor Documentation

CctwDataChunk::CctwDataChunk ( CctwChunkedData data,
int  index,
QString  name,
QObject *  parent 
)

Definition at line 8 of file cctwdatachunk.cpp.

References g_ChunkCount.

8  :
9  CctwObject(name, parent),
10  m_Data(data),
14  m_ChunkData(NULL),
15  m_ChunkWeights(NULL),
16  m_Normalized(0),
17  m_DataWritten(0),
19  m_MergeCounter(0),
20  m_OwnData(true)
21 {
22  g_ChunkCount.fetchAndAddOrdered(1);
23 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
int index() const
CctwIntVector3D m_ChunkStart
Definition: cctwdatachunk.h:87
QString name
Definition: cctwobject.h:32
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
CctwChunkedData * m_Data
Definition: cctwdatachunk.h:85
CctwIntVector3D calculateChunkStart()
static QAtomicInt g_ChunkCount
CctwIntVector3D calculateChunkSize()
CctwObject(QString name, QObject *parent=0)
Definition: cctwobject.cpp:7
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
CctwDataChunk::~CctwDataChunk ( )
virtual

Definition at line 62 of file cctwdatachunk.cpp.

References dependencyCount(), g_ChunkCount, m_ChunkData, m_ChunkWeights, m_OwnData, CctwObject::printMessage(), and releaseBuffer().

63 {
64  if (dependencyCount()) {
65  printMessage("Deleting chunk with deps");
66  }
67 
68  if (m_OwnData) {
71  }
72 
73  m_ChunkData = NULL;
74  m_ChunkWeights = NULL;
75 
76  g_ChunkCount.fetchAndAddOrdered(-1);
77 }
int dependencyCount() const
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
void releaseBuffer(CctwChunkedData::MergeDataType *)
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
static QAtomicInt g_ChunkCount

Member Function Documentation

void CctwDataChunk::addDependency ( int  dep)
slot

Definition at line 337 of file cctwdatachunk.cpp.

References m_Dependencies, and m_DependenciesLock.

338 {
339  QMutexLocker lock(&m_DependenciesLock);
340 
341  if (!m_Dependencies.contains(dep)) {
342 // printMessage(tr("Added dependency from chunk [%1,%2,%3] to chunk [%4,%5,%6]")
343 // .arg(m_ChunkIndex.x()).arg(m_ChunkIndex.y()).arg(m_ChunkIndex.z())
344 // .arg(dep.x()).arg(dep.y()).arg(dep.z()));
345 
346  m_Dependencies.append(dep);
347  }
348 }
QMutex m_DependenciesLock
Definition: cctwdatachunk.h:95
QVector< int > m_Dependencies
Definition: cctwdatachunk.h:94
CctwChunkedData::MergeDataType * CctwDataChunk::allocateBuffer ( )
private

Definition at line 260 of file cctwdatachunk.cpp.

References g_Allocated(), g_MaxAllocated(), m_ChunkSize, and CctwVector3D< T >::volume().

Referenced by allocateData(), and allocateWeights().

261 {
262  int cksz = m_ChunkSize.volume();
263 
264  int nalloc = g_Allocated.fetchAndAddOrdered(1);
265 
266  if (nalloc > g_MaxAllocated.fetchAndAddOrdered(0)) {
267  g_MaxAllocated.fetchAndStoreOrdered(nalloc);
268  }
269 
270 // printMessage(tr("Acquired 1 blocks, %1 allocated, %2 max")
271 // .arg(nalloc).arg(g_MaxAllocated.fetchAndAddOrdered(0)));
272 
273 // CctwChunkedData::MergeDataType *res = new CctwChunkedData::MergeDataType[cksz];
274 
275 // for (int i=0; i<cksz; i++) {
276 // res[i] = 0;
277 // }
278 
280 
281  return res;
282 }
static QAtomicInt g_Allocated(0)
static QAtomicInt g_MaxAllocated(0)
T volume() const
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
int CctwDataChunk::allocateData ( )
slot

Definition at line 130 of file cctwdatachunk.cpp.

References allocateBuffer(), m_ChunkData, m_ChunkSize, releaseBuffer(), and CctwVector3D< T >::volume().

Referenced by mergeData(), CctwChunkedData::readChunk(), and CctwTransformer::transformChunkData().

131 {
132  int cksz = m_ChunkSize.volume();
133 
135 
137 
138  m_ChunkData = newData;
139 
140  return cksz*sizeof(CctwChunkedData::MergeDataType);
141 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
void releaseBuffer(CctwChunkedData::MergeDataType *)
CctwChunkedData::MergeDataType * allocateBuffer()
T volume() const
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
int CctwDataChunk::allocatedChunkCount ( )
staticslot

Definition at line 79 of file cctwdatachunk.cpp.

References g_ChunkCount.

Referenced by CctwChunkedData::allocatedChunkCount(), CctwTransformer::simpleTransform(), CctwTransformer::transform(), and CctwTransformer::transformChunkData().

80 {
81  return g_ChunkCount.fetchAndAddOrdered(0);
82 }
static QAtomicInt g_ChunkCount
int CctwDataChunk::allocateWeights ( )
slot

Definition at line 143 of file cctwdatachunk.cpp.

References allocateBuffer(), m_ChunkSize, m_ChunkWeights, releaseBuffer(), and CctwVector3D< T >::volume().

Referenced by mergeData(), CctwChunkedData::readChunk(), and CctwTransformer::transformChunkData().

144 {
145  int cksz = m_ChunkSize.volume();
146 
148 
150 
151  m_ChunkWeights = newWeights;
152 
153  return cksz*sizeof(CctwChunkedData::MergeDataType);
154 }
void releaseBuffer(CctwChunkedData::MergeDataType *)
CctwChunkedData::MergeDataType * allocateBuffer()
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
T volume() const
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
CctwIntVector3D CctwDataChunk::calculateChunkSize ( )
private

Definition at line 36 of file cctwdatachunk.cpp.

References CctwChunkedData::chunkSize, CctwChunkedData::dimensions, m_ChunkIndex, m_ChunkStart, m_Data, CctwObject::printMessage(), CctwVector3D< T >::x(), CctwVector3D< T >::y(), and CctwVector3D< T >::z().

37 {
38  if (m_Data) {
39  CctwIntVector3D chksize = m_Data->chunkSize();
40  CctwIntVector3D chkend = m_ChunkStart + chksize;
42 
43  if (chkend.x() > dim.x()) {
44  chksize.x() = dim.x() - m_ChunkStart.x();
45  }
46 
47  if (chkend.y() > dim.y()) {
48  chksize.y() = dim.y() - m_ChunkStart.y();
49  }
50 
51  if (chkend.z() > dim.z()) {
52  chksize.z() = dim.z() - m_ChunkStart.z();
53  }
54 
55  return chksize;
56  } else {
57  printMessage(tr("Chunk %1, m_Data == NULL").arg(m_ChunkIndex));
58  return CctwIntVector3D(0,0,0);
59  }
60 }
CctwIntVector3D m_ChunkStart
Definition: cctwdatachunk.h:87
CctwIntVector3D dimensions
CctwChunkedData * m_Data
Definition: cctwdatachunk.h:85
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
T x() const
Definition: cctwvector3d.h:17
T z() const
Definition: cctwvector3d.h:19
CctwVector3D< int > CctwIntVector3D
Definition: cctwvector3d.h:70
CctwIntVector3D chunkSize
T y() const
Definition: cctwvector3d.h:18
CctwIntVector3D CctwDataChunk::calculateChunkStart ( )
private

Definition at line 25 of file cctwdatachunk.cpp.

References chunkStart(), m_ChunkIndex, m_Data, and CctwObject::printMessage().

Referenced by resetChunkStart().

26 {
27 // printMessage(tr("calculateChunkStart(): %1").arg(m_ChunkIndex));
28  if (m_Data) {
29  return m_Data -> chunkStart(m_ChunkIndex);
30  } else {
31  printMessage(tr("Chunk %1, m_Data == NULL").arg(m_ChunkIndex));
32  return CctwIntVector3D(0,0,0);
33  }
34 }
CctwChunkedData * m_Data
Definition: cctwdatachunk.h:85
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
CctwIntVector3D chunkStart()
CctwVector3D< int > CctwIntVector3D
Definition: cctwvector3d.h:70
CctwIntVector3D CctwDataChunk::chunkSize ( )
slot
CctwIntVector3D CctwDataChunk::chunkStart ( )
slot
void CctwDataChunk::clearDependencies ( )
slot

Definition at line 309 of file cctwdatachunk.cpp.

References m_Dependencies, and m_DependenciesLock.

Referenced by CctwChunkedData::clearDependencies().

310 {
311  QMutexLocker lock(&m_DependenciesLock);
312 
313  m_Dependencies.resize(0);
314 }
QMutex m_DependenciesLock
Definition: cctwdatachunk.h:95
QVector< int > m_Dependencies
Definition: cctwdatachunk.h:94
void CctwDataChunk::clearMergeCounters ( )
slot

Definition at line 479 of file cctwdatachunk.cpp.

References m_MergeCounter, and m_Normalized.

480 {
481  m_MergeCounter = 0;
482  m_Normalized = 0;
483 }
CctwChunkedData::MergeDataType CctwDataChunk::data ( int  lx,
int  ly,
int  lz 
)
slot

Definition at line 206 of file cctwdatachunk.cpp.

References m_ChunkData, and pixelOffset().

Referenced by pushMergeData(), and CctwTransformer::transformChunkData().

207 {
208  int offset = pixelOffset(lx, ly, lz);
209 
210  if (offset >= 0 && m_ChunkData) {
211  return m_ChunkData[offset];
212  } else {
213  return 0;
214  }
215 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
int pixelOffset(int lx, int ly, int lz)
bool CctwDataChunk::dataAllocated ( ) const
slot

Definition at line 99 of file cctwdatachunk.cpp.

References m_ChunkData.

100 {
101  return m_ChunkData;
102 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
CctwChunkedData::MergeDataType * CctwDataChunk::dataPointer ( )
slot

Definition at line 89 of file cctwdatachunk.cpp.

References m_ChunkData.

Referenced by Cctwtcl_Input_Cmd(), Cctwtcl_Transform_Cmd(), CctwTransformer::checkTransform(), CctwChunkedData::readChunk(), and CctwChunkedData::writeChunk().

90 {
91  return m_ChunkData;
92 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
int CctwDataChunk::deallocateData ( )
slot

Definition at line 156 of file cctwdatachunk.cpp.

References m_ChunkData, m_ChunkSize, releaseBuffer(), and CctwVector3D< T >::volume().

Referenced by CctwChunkedData::releaseChunkData(), and CctwTransformer::transformChunkNumber().

157 {
159 
161 
162  m_ChunkData = NULL;
163 
164  return res;
165 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
void releaseBuffer(CctwChunkedData::MergeDataType *)
T volume() const
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
int CctwDataChunk::deallocateWeights ( )
slot

Definition at line 167 of file cctwdatachunk.cpp.

References m_ChunkSize, m_ChunkWeights, releaseBuffer(), and CctwVector3D< T >::volume().

Referenced by normalizeChunk(), CctwChunkedData::releaseChunkData(), and CctwTransformer::transformChunkNumber().

168 {
170 
172 
173  m_ChunkWeights = NULL;
174 
175  return res;
176 }
void releaseBuffer(CctwChunkedData::MergeDataType *)
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
T volume() const
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
int CctwDataChunk::dependency ( int  n) const
slot

Definition at line 330 of file cctwdatachunk.cpp.

References m_Dependencies, and m_DependenciesLock.

Referenced by CctwqtMainWindow::reportDependencies(), CctwTransformer::saveDependencies(), and CctwTransformer::transform().

331 {
332  QMutexLocker lock(&m_DependenciesLock);
333 
334  return m_Dependencies.value(n);
335 }
QMutex m_DependenciesLock
Definition: cctwdatachunk.h:95
QVector< int > m_Dependencies
Definition: cctwdatachunk.h:94
int CctwDataChunk::dependencyCount ( ) const
slot
int CctwDataChunk::detachData ( )
slot

Definition at line 178 of file cctwdatachunk.cpp.

References m_ChunkData.

Referenced by Cctwtcl_Input_Cmd(), and Cctwtcl_Transform_Cmd().

179 {
180  m_ChunkData = NULL;
181 
182  return 0;
183 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
int CctwDataChunk::detachWeights ( )
slot

Definition at line 185 of file cctwdatachunk.cpp.

References m_ChunkWeights.

Referenced by Cctwtcl_Input_Cmd(), and Cctwtcl_Transform_Cmd().

186 {
187  m_ChunkWeights = NULL;
188 
189  return 0;
190 }
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
void CctwDataChunk::incMergeCounters ( )
slot

Definition at line 485 of file cctwdatachunk.cpp.

References m_MergeCounter.

Referenced by mergeChunk().

486 {
487  m_MergeCounter++;
488 }
int CctwDataChunk::index ( ) const
slot
int CctwDataChunk::maxAllocated ( )
staticslot

Definition at line 255 of file cctwdatachunk.cpp.

References g_MaxAllocated().

256 {
257  return g_MaxAllocated.fetchAndAddOrdered(0);
258 }
static QAtomicInt g_MaxAllocated(0)
void CctwDataChunk::mergeChunk ( CctwDataChunk c)
slot

Definition at line 400 of file cctwdatachunk.cpp.

References chunkSize(), dependencyCount(), CctwChunkedData::incChunksHeld(), CctwChunkedData::incChunksWritten(), incMergeCounters(), index(), m_ChunkIndex, m_Data, mergeCount(), popMergeData(), CctwObject::printMessage(), pushMergeData(), releaseBuffer(), CctwVector3D< T >::volume(), and CctwChunkedData::writeChunk().

401 {
402 // printMessage(tr("Merging chunk [%1]")
403 // .arg(index()));
404 
405  if (c) {
406  if (mergeCount() == 0) {
407 // printMessage(tr("Output chunk [%1] started")
408 // .arg(index()));
409  }
410 
411  if (c->index() != index()) {
412  printMessage(tr("Merging anomaly [%1] != [%2]")
413  .arg(index()).arg(c->index()));
414  }
415 
416  CctwChunkedData::MergeDataType *d, *w, *id, *iw;
417  c -> popMergeData(&id, &iw);
418 
419  while (popMergeData(&d, &w)) {
420 // printMessage(tr("Pop Merge"));
421 
422  CctwIntVector3D cks = chunkSize();
423  CctwIntVector3D icks = c->chunkSize();
424 
425  if (cks == icks) {
426  int n = cks.volume();
427 
428  if (d && id) {
429  for (int i=0; i<n; i++) {
430  if ((w && w[i] != 0) || !w) {
431  id[i] += d[i];
432  }
433  }
434  } else if (d) {
435  id = d;
436  d = NULL;
437  }
438 
439  if (w && iw) {
440  for (int i=0; i<n; i++) {
441  iw[i] += w[i];
442  }
443  } else if (w) {
444  iw = w;
445  w = NULL;
446  }
447  } else {
448  printMessage(tr("Anomaly merging data chunk %1").arg(m_ChunkIndex));
449  }
450 
451  releaseBuffer(d);
452  releaseBuffer(w);
453  }
454 
455  pushMergeData(id, iw);
456 
458 
459  if (mergeCount() == dependencyCount()) {
460 // printMessage(tr("Output chunk [%1] completed")
461 // .arg(index()));
462 
463  if (m_Data) {
464  m_Data->writeChunk(index());
466  m_Data->incChunksHeld(-1);
467  }
468  } else if (mergeCount() == 1) {
469  if (m_Data) {
470  m_Data->incChunksHeld(1);
471  }
472  } else if (mergeCount() > dependencyCount() && dependencyCount()) {
473  printMessage(tr("Exceeded expected number of merges for chunk [%1] %2 > %3")
474  .arg(index()).arg(mergeCount()).arg(dependencyCount()));
475  }
476  }
477 }
void incChunksHeld(int n)
int dependencyCount() const
int index() const
void releaseBuffer(CctwChunkedData::MergeDataType *)
void writeChunk(int n)
CctwIntVector3D chunkSize()
void incMergeCounters()
CctwChunkedData * m_Data
Definition: cctwdatachunk.h:85
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
bool popMergeData(CctwChunkedData::MergeDataType **data, CctwChunkedData::MergeDataType **weights)
void pushMergeData(CctwChunkedData::MergeDataType *data, CctwChunkedData::MergeDataType *weights)
void incChunksWritten(int n)
T volume() const
int CctwDataChunk::mergeCount ( )
slot

Definition at line 490 of file cctwdatachunk.cpp.

References m_MergeCounter.

Referenced by CctwTransformer::checkTransform(), and mergeChunk().

491 {
492  return m_MergeCounter;
493 }
void CctwDataChunk::mergeData ( CctwChunkedData::MergeDataType id,
CctwChunkedData::MergeDataType iw,
int  n 
)
slot

Definition at line 365 of file cctwdatachunk.cpp.

References allocateData(), allocateWeights(), index(), m_ChunkData, m_ChunkWeights, m_MergeLock, and CctwObject::printMessage().

Referenced by Cctwtcl_Merge_Cmd().

368 {
369  QMutexLocker lock(&m_MergeLock);
370 
371  if (m_ChunkData == NULL) {
372  allocateData();
373  }
374 
375  if (m_ChunkWeights == NULL) {
376  allocateWeights();
377  }
378 
380 
381  if (d && id) {
382  for (int i=0; i<n; i++) {
383  if ((iw && iw[i] != 0 && iw[i] == iw[i]) || !iw) {
384  d[i] += id[i];
385  }
386  }
387  } else {
388  printMessage(tr("Couldn't merge data for chunk [%1]").arg(index()));
389  }
390 
391  if (w && iw) {
392  for (int i=0; i<n; i++) {
393  if ((iw && iw[i] != 0 && iw[i] == iw[i]) || !iw) {
394  w[i] += iw[i];
395  }
396  }
397  }
398 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
int index() const
QMutex m_MergeLock
Definition: cctwdatachunk.h:96
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
void CctwDataChunk::normalizeChunk ( )
slot

Definition at line 541 of file cctwdatachunk.cpp.

References deallocateWeights(), index(), m_ChunkData, m_ChunkSize, m_ChunkWeights, m_Normalized, CctwObject::printMessage(), and CctwVector3D< T >::volume().

Referenced by CctwChunkedData::normalizeChunk().

542 {
543  if (m_Normalized) {
544  printMessage(tr("Chunk %1 - Already normalized").arg(index()));
545  } else if (m_ChunkData && m_ChunkWeights) {
546  int cksz = m_ChunkSize.volume();
547 
548  for (int i=0; i<cksz; i++) {
549  if (m_ChunkWeights[i] != 0.0) {
550  m_ChunkData[i] /= m_ChunkWeights[i];
551  }
552  }
553 
555  }
556 
557  m_Normalized = true;
558 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
int index() const
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
T volume() const
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
int CctwDataChunk::pixelOffset ( int  lx,
int  ly,
int  lz 
)
slot

Definition at line 192 of file cctwdatachunk.cpp.

References m_ChunkSize, CctwVector3D< T >::x(), CctwVector3D< T >::y(), and CctwVector3D< T >::z().

Referenced by data(), setData(), setWeight(), and weight().

193 {
194  if (lx < 0 || lx >= m_ChunkSize.x()) {
195  return -1;
196  } else if (ly < 0 || ly >= m_ChunkSize.y()) {
197  return -1;
198  } else if (lz < 0 || lz >= m_ChunkSize.z()) {
199  return -1;
200  } else {
201  int offset = (lz * m_ChunkSize.y() + ly)*m_ChunkSize.x() + lx;
202  return offset;
203  }
204 }
T x() const
Definition: cctwvector3d.h:17
T z() const
Definition: cctwvector3d.h:19
T y() const
Definition: cctwvector3d.h:18
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
bool CctwDataChunk::popMergeData ( CctwChunkedData::MergeDataType **  data,
CctwChunkedData::MergeDataType **  weights 
)
slot

Definition at line 495 of file cctwdatachunk.cpp.

References m_ChunkData, m_ChunkWeights, m_MergeData, m_MergeLock, and m_MergeWeights.

Referenced by mergeChunk().

497 {
498  QMutexLocker lock(&m_MergeLock);
499 
500  if (data && weights) {
501  *data = m_ChunkData;
502 
503  if (m_MergeData.isEmpty()) {
504  m_ChunkData = NULL;
505  } else {
506  m_ChunkData = m_MergeData.takeLast();
507  }
508 
509  *weights = m_ChunkWeights;
510 
511  if (m_MergeWeights.isEmpty()) {
512  m_ChunkWeights = NULL;
513  } else {
514  m_ChunkWeights = m_MergeWeights.takeLast();
515  }
516 
517  return *data || *weights;
518  } else {
519  return false;
520  }
521 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
QMutex m_MergeLock
Definition: cctwdatachunk.h:96
QList< CctwChunkedData::MergeDataType * > m_MergeWeights
Definition: cctwdatachunk.h:99
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
QList< CctwChunkedData::MergeDataType * > m_MergeData
Definition: cctwdatachunk.h:98
CctwChunkedData::MergeDataType data(int lx, int ly, int lz)
void CctwDataChunk::pushMergeData ( CctwChunkedData::MergeDataType data,
CctwChunkedData::MergeDataType weights 
)
slot

Definition at line 523 of file cctwdatachunk.cpp.

References data(), m_ChunkData, m_ChunkWeights, m_MergeData, m_MergeLock, and m_MergeWeights.

Referenced by mergeChunk().

525 {
526  QMutexLocker lock(&m_MergeLock);
527 
528  if (m_ChunkData == NULL) {
529  m_ChunkData = data;
530  } else {
531  m_MergeData.push_back(data);
532  }
533 
534  if (m_ChunkWeights == NULL) {
535  m_ChunkWeights = weights;
536  } else {
537  m_MergeWeights.push_back(weights);
538  }
539 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
QMutex m_MergeLock
Definition: cctwdatachunk.h:96
QList< CctwChunkedData::MergeDataType * > m_MergeWeights
Definition: cctwdatachunk.h:99
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
QList< CctwChunkedData::MergeDataType * > m_MergeData
Definition: cctwdatachunk.h:98
CctwChunkedData::MergeDataType data(int lx, int ly, int lz)
void CctwDataChunk::releaseBuffer ( CctwChunkedData::MergeDataType buffer)
private

Definition at line 291 of file cctwdatachunk.cpp.

References g_Allocated().

Referenced by allocateData(), allocateWeights(), deallocateData(), deallocateWeights(), mergeChunk(), and ~CctwDataChunk().

292 {
293  if (buffer) {
294  int nalloc = g_Allocated.fetchAndAddOrdered(-1);
295 
296 // printMessage(tr("Releasing 1 blocks, %1 allocated").arg(nalloc));
297 
298 // delete [] buffer;
299 
300  free(buffer);
301  }
302 }
static QAtomicInt g_Allocated(0)
void CctwDataChunk::reportDependencies ( )
slot

Definition at line 350 of file cctwdatachunk.cpp.

References m_ChunkIndex, m_Dependencies, m_DependenciesLock, CctwObject::printMessage(), and sortDependencies().

Referenced by CctwApplication::reportDependencies(), CctwApplication::reportInputDependencies(), and CctwApplication::reportOutputDependencies().

351 {
352  QMutexLocker lock(&m_DependenciesLock);
353 
354  QString msg(tr("[%1] ->").arg(m_ChunkIndex));
355 
357 
358  foreach (int dep, m_Dependencies) {
359  msg += tr(" [%1]").arg(dep);
360  }
361 
362  printMessage(msg);
363 }
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
QMutex m_DependenciesLock
Definition: cctwdatachunk.h:95
void sortDependencies()
QVector< int > m_Dependencies
Definition: cctwdatachunk.h:94
void CctwDataChunk::resetAllocationLimits ( int  nmax)
staticslot

Definition at line 246 of file cctwdatachunk.cpp.

References g_Allocated(), g_AllocationLimit(), g_Available(), and g_MaxAllocated().

Referenced by CctwTransformer::transform().

247 {
248  g_Allocated.fetchAndStoreOrdered(0);
249  g_MaxAllocated.fetchAndStoreOrdered(0);
250  g_AllocationLimit.fetchAndStoreOrdered(nmax);
251  g_Available.acquire(g_Available.available());
252  g_Available.release(nmax);
253 }
static QAtomicInt g_Allocated(0)
static QSemaphore g_Available(1000)
static QAtomicInt g_AllocationLimit(1000)
static QAtomicInt g_MaxAllocated(0)
void CctwDataChunk::resetChunkStart ( )
slot

Definition at line 114 of file cctwdatachunk.cpp.

References calculateChunkStart(), m_ChunkStart, and CctwVector3D< T >::toString().

115 {
117  qDebug("CctwDataChunk::resetChunkStart(): %s", qPrintable(m_ChunkStart.toString()));
118 }
CctwIntVector3D m_ChunkStart
Definition: cctwdatachunk.h:87
QString toString()
CctwIntVector3D calculateChunkStart()
void CctwDataChunk::setBuffer ( void *  buffer)
slot

Definition at line 284 of file cctwdatachunk.cpp.

References m_ChunkData, m_OwnData, and CctwObject::printMessage().

285 {
286  printMessage(tr("Setting buffer to: %1").arg((long long) buffer));
288  m_OwnData = false;
289 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
void CctwDataChunk::setChunkSize ( CctwIntVector3D  size)
slot

Definition at line 125 of file cctwdatachunk.cpp.

References m_ChunkSize.

126 {
127  m_ChunkSize = size;
128 }
CctwIntVector3D m_ChunkSize
Definition: cctwdatachunk.h:88
void CctwDataChunk::setData ( int  lx,
int  ly,
int  lz,
CctwChunkedData::MergeDataType  val 
)
slot

Definition at line 228 of file cctwdatachunk.cpp.

References m_ChunkData, and pixelOffset().

229 {
230  int offset = pixelOffset(lx, ly, lz);
231 
232  if (offset >= 0 && m_ChunkData) {
233  m_ChunkData[offset] = val;
234  }
235 }
CctwChunkedData::MergeDataType * m_ChunkData
Definition: cctwdatachunk.h:89
int pixelOffset(int lx, int ly, int lz)
void CctwDataChunk::setWeight ( int  lx,
int  ly,
int  lz,
CctwChunkedData::MergeDataType  val 
)
slot

Definition at line 237 of file cctwdatachunk.cpp.

References m_ChunkWeights, and pixelOffset().

238 {
239  int offset = pixelOffset(lx, ly, lz);
240 
241  if (offset >= 0 && m_ChunkWeights) {
242  m_ChunkWeights[offset] = val;
243  }
244 }
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
int pixelOffset(int lx, int ly, int lz)
void CctwDataChunk::sortDependencies ( )
slot

Definition at line 316 of file cctwdatachunk.cpp.

References m_Dependencies, and m_DependenciesLock.

Referenced by reportDependencies(), and CctwTransformer::saveDependencies().

317 {
318  QMutexLocker lock(&m_DependenciesLock);
319 
320  qSort(m_Dependencies.begin(), m_Dependencies.end());
321 }
QMutex m_DependenciesLock
Definition: cctwdatachunk.h:95
QVector< int > m_Dependencies
Definition: cctwdatachunk.h:94
CctwChunkedData::MergeDataType CctwDataChunk::weight ( int  lx,
int  ly,
int  lz 
)
slot

Definition at line 217 of file cctwdatachunk.cpp.

References m_ChunkWeights, and pixelOffset().

Referenced by CctwTransformer::transformChunkData().

218 {
219  int offset = pixelOffset(lx, ly, lz);
220 
221  if (offset >= 0 && m_ChunkWeights) {
222  return m_ChunkWeights[offset];
223  } else {
224  return 1;
225  }
226 }
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
int pixelOffset(int lx, int ly, int lz)
bool CctwDataChunk::weightsAllocated ( ) const
slot

Definition at line 104 of file cctwdatachunk.cpp.

References m_ChunkWeights.

105 {
106  return m_ChunkWeights;
107 }
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90
CctwChunkedData::MergeDataType * CctwDataChunk::weightsPointer ( )
slot

Definition at line 94 of file cctwdatachunk.cpp.

References m_ChunkWeights.

Referenced by Cctwtcl_Input_Cmd(), Cctwtcl_Transform_Cmd(), CctwTransformer::checkTransform(), CctwChunkedData::readChunk(), and CctwChunkedData::writeChunk().

95 {
96  return m_ChunkWeights;
97 }
CctwChunkedData::MergeDataType * m_ChunkWeights
Definition: cctwdatachunk.h:90

Member Data Documentation

CctwChunkedData::MergeDataType* CctwDataChunk::m_ChunkData
private
int CctwDataChunk::m_ChunkIndex
private
CctwIntVector3D CctwDataChunk::m_ChunkSize
private
CctwIntVector3D CctwDataChunk::m_ChunkStart
private

Definition at line 87 of file cctwdatachunk.h.

Referenced by calculateChunkSize(), chunkStart(), and resetChunkStart().

CctwChunkedData::MergeDataType* CctwDataChunk::m_ChunkWeights
private
CctwChunkedData* CctwDataChunk::m_Data
private

Definition at line 85 of file cctwdatachunk.h.

Referenced by calculateChunkSize(), calculateChunkStart(), and mergeChunk().

int CctwDataChunk::m_DataWritten
private

Definition at line 92 of file cctwdatachunk.h.

QVector< int > CctwDataChunk::m_Dependencies
private
QMutex CctwDataChunk::m_DependenciesLock
mutableprivate
int CctwDataChunk::m_MergeCounter
private

Definition at line 97 of file cctwdatachunk.h.

Referenced by clearMergeCounters(), incMergeCounters(), and mergeCount().

QList< CctwChunkedData::MergeDataType* > CctwDataChunk::m_MergeData
private

Definition at line 98 of file cctwdatachunk.h.

Referenced by popMergeData(), and pushMergeData().

QMutex CctwDataChunk::m_MergeLock
private

Definition at line 96 of file cctwdatachunk.h.

Referenced by mergeData(), popMergeData(), and pushMergeData().

QList< CctwChunkedData::MergeDataType* > CctwDataChunk::m_MergeWeights
private

Definition at line 99 of file cctwdatachunk.h.

Referenced by popMergeData(), and pushMergeData().

int CctwDataChunk::m_Normalized
private

Definition at line 91 of file cctwdatachunk.h.

Referenced by clearMergeCounters(), and normalizeChunk().

bool CctwDataChunk::m_OwnData
private

True iff this object owns the chunk memory

Definition at line 101 of file cctwdatachunk.h.

Referenced by setBuffer(), and ~CctwDataChunk().

int CctwDataChunk::m_WeightsWritten
private

Definition at line 93 of file cctwdatachunk.h.


The documentation for this class was generated from the following files: