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

#include <cctwtransformer.h>

Inheritance diagram for CctwTransformer:
Inheritance graph
Collaboration diagram for CctwTransformer:
Collaboration graph

Public Slots

void transform ()
 
void simpleTransform ()
 
void checkTransform ()
 
void saveDependencies (QString path)
 
void loadDependencies (QString path)
 
QcepIntList dependencies (int n)
 
QList< CctwIntVector3Ddependencies (int cx, int cy, int cz)
 
void runTransformChunkNumber (int n)
 
void transformChunkNumber (int chunkId)
 
void transformChunkData (int chunkId, CctwDataChunk *inputChunk, QMap< int, CctwDataChunk * > &outputChunks)
 
void clearDependencies (int use)
 
void addDependency (int f, int t)
 
- 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

 CctwTransformer (CctwApplication *application, CctwChunkedData *input, CctwChunkedData *output, CctwTransformInterface *xform, QString name, QObject *parent)
 
virtual ~CctwTransformer ()
 
virtual void writeSettings (QSettings *set, QString section)
 
virtual void readSettings (QSettings *set, QString section)
 
- Public Member Functions inherited from CctwObject
 CctwObject (QString name, QObject *parent=0)
 

Properties

double wallTime
 
int blocksLimit
 
int transformOptions
 
int oversampleX
 
int oversampleY
 
int oversampleZ
 
bool projectX
 
bool projectY
 
bool projectZ
 
QString projectDestination
 
int normalization
 
int compression
 
QString subset
 
int useDependencies
 
int skipped
 
- Properties inherited from CctwObject
QString name
 

Private Member Functions

void markInputChunkNeeded (CctwIntVector3D idx)
 
bool parseSubset (CctwChunkedData *data=NULL)
 

Private Attributes

CctwApplicationm_Application
 
CctwChunkedDatam_InputData
 
CctwChunkedDatam_OutputData
 
CctwTransformInterfacem_Transform
 
QMutex m_LockX
 
QMutex m_LockY
 
QMutex m_LockZ
 
QcepImageData< double > * m_ImageX
 
QcepImageData< double > * m_ImageY
 
QcepImageData< double > * m_ImageZ
 
QcepImageData< double > * m_WeightX
 
QcepImageData< double > * m_WeightY
 
QcepImageData< double > * m_WeightZ
 
double m_MinData
 
double m_MaxData
 
double m_MinWeight
 
double m_MaxWeight
 
CctwIntVector3D m_SubsetStart
 
CctwIntVector3D m_SubsetEnd
 

Detailed Description

Definition at line 14 of file cctwtransformer.h.

Constructor & Destructor Documentation

CctwTransformer::CctwTransformer ( CctwApplication application,
CctwChunkedData input,
CctwChunkedData output,
CctwTransformInterface xform,
QString  name,
QObject *  parent 
)

Definition at line 22 of file cctwtransformer.cpp.

26  :
27  CctwObject(name, parent),
28  m_Application(application),
29  m_InputData(input),
30  m_OutputData(output),
31  m_Transform(xform),
32 // m_OversampleX(osx),
33 // m_OversampleY(osy),
34 // m_OversampleZ(osz),
35  m_ImageX(NULL),
36  m_ImageY(NULL),
37  m_ImageZ(NULL),
38  m_WeightX(NULL),
39  m_WeightY(NULL),
40  m_WeightZ(NULL),
41  m_WallTime(QcepSettingsSaverWPtr(), this, "wallTime", 0, "Wall Time of last command"),
42  m_BlocksLimit(m_Application->saver(), this, "blocksLimit", 1000, "Blocks Limit"),
43  m_TransformOptions(m_Application->saver(), this, "transformOptions", 0, "Transform Options"),
44  m_OversampleX(m_Application->saver(), this, "oversampleX", 1, "Oversampling along X"),
45  m_OversampleY(m_Application->saver(), this, "oversampleY", 1, "Oversampling along Y"),
46  m_OversampleZ(m_Application->saver(), this, "oversampleZ", 1, "Oversampling along Z"),
47  m_ProjectX(m_Application->saver(), this, "projectX", true, "Project along X"),
48  m_ProjectY(m_Application->saver(), this, "projectY", true, "Project along Y"),
49  m_ProjectZ(m_Application->saver(), this, "projectZ", true, "Project along Z"),
50  m_ProjectDestination(m_Application->saver(), this, "projectDestination", "", "Output path for projected images"),
51  m_Normalization(m_Application->saver(), this, "normalization", 1, "Normalize output data?"),
52  m_Compression(m_Application->saver(), this, "compression", 2, "Compression level for output data"),
53  m_Subset(QcepSettingsSaverWPtr(), this, "subset", "", "Subset specifier"),
54  m_UseDependencies(QcepSettingsSaverWPtr(), this, "useDependencies", 0, "Use dependencies in transform"),
55  m_Skipped(QcepSettingsSaverWPtr(), this, "skipped", 0, "Number of skipped pixels")
56 {
57 }
QString name
Definition: cctwobject.h:32
QcepImageData< double > * m_WeightZ
QcepImageData< double > * m_ImageY
QcepImageData< double > * m_WeightX
CctwApplication * m_Application
QcepImageData< double > * m_WeightY
QcepImageData< double > * m_ImageZ
CctwTransformInterface * m_Transform
QcepSettingsSaverWPtr saver() const
CctwChunkedData * m_OutputData
QcepImageData< double > * m_ImageX
CctwObject(QString name, QObject *parent=0)
Definition: cctwobject.cpp:7
CctwChunkedData * m_InputData
CctwTransformer::~CctwTransformer ( )
virtual

Definition at line 59 of file cctwtransformer.cpp.

60 {
61 }

Member Function Documentation

void CctwTransformer::addDependency ( int  f,
int  t 
)
slot

Definition at line 780 of file cctwtransformer.cpp.

References CctwChunkedData::addDependency(), m_InputData, and m_OutputData.

Referenced by CctwApplication::calculateChunkDependencies(), and loadDependencies().

781 {
782  m_InputData->addDependency(f, t);
784 }
void addDependency(int f, int t)
CctwChunkedData * m_OutputData
CctwChunkedData * m_InputData
void CctwTransformer::checkTransform ( )
slot

Definition at line 678 of file cctwtransformer.cpp.

References CctwChunkedData::chunk(), CctwChunkedData::chunkCount, CctwDataChunk::dataPointer(), CctwDataChunk::dependencyCount(), m_OutputData, CctwDataChunk::mergeCount(), CctwObject::printMessage(), CctwVector3D< T >::volume(), and CctwDataChunk::weightsPointer().

Referenced by CctwqtMainWindow::doCheckTransform().

679 {
680  int chunks = m_OutputData->chunkCount().volume();
681 
682  for (int i = 0; i<chunks; i++) {
683  CctwDataChunk *chunk = m_OutputData->chunk(i);
684 
685  if (chunk) {
686  if (chunk->dependencyCount() != chunk->mergeCount()) {
687  printMessage(tr("Anomaly in chunk [%1] : deps %2, merge %3")
688  .arg(i)
689  .arg(chunk->dependencyCount())
690  .arg(chunk->mergeCount()));
691  }
692 
693  if (chunk->dataPointer()) {
694  printMessage(tr("Chunk [%1] still has allocated data").arg(i));
695  }
696 
697  if (chunk->weightsPointer()) {
698  printMessage(tr("Chunk [%1] still has allocated weights").arg(i));
699  }
700  }
701  }
702 }
int dependencyCount() const
CctwDataChunk * chunk(int n)
CctwIntVector3D chunkCount
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
CctwChunkedData::MergeDataType * weightsPointer()
CctwChunkedData::MergeDataType * dataPointer()
CctwChunkedData * m_OutputData
T volume() const
void CctwTransformer::clearDependencies ( int  use)
slot

Definition at line 772 of file cctwtransformer.cpp.

References CctwChunkedData::clearDependencies(), m_InputData, and m_OutputData.

Referenced by CctwApplication::calculateDependencies(), loadDependencies(), and CctwApplication::noDependencies().

773 {
776 
777  set_UseDependencies(use);
778 }
CctwChunkedData * m_OutputData
CctwChunkedData * m_InputData
QcepIntList CctwTransformer::dependencies ( int  n)
slot

Definition at line 704 of file cctwtransformer.cpp.

References CctwChunkedData::chunk(), CctwChunkedData::chunkContaining(), CctwChunkedData::chunkIndexFromNumber(), CctwDataChunk::chunkSize(), CctwDataChunk::chunkStart(), CctwChunkedData::containsChunk(), CctwChunkedData::containsPixel(), m_Application, m_InputData, m_OutputData, CctwApplication::parameters(), transform(), CctwVector3D< T >::x(), CctwVector3D< T >::y(), and CctwVector3D< T >::z().

Referenced by dependencies(), and CctwApplication::dependencies().

705 {
706  QcepDoubleVector anglesvec = m_InputData->get_Angles();
707  double *angs = (anglesvec.count()<=0 ? NULL : anglesvec.data());
708 
709  CctwCrystalCoordinateTransform transform(m_Application->parameters(), tr("transform-%1").arg(n), angs, NULL);
710 
712 
713  int lastChunkIndex = -1;
714 
715  CctwDataChunk *chunk = m_InputData->chunk(n);
716 
717  QList<int> outputChunks;
718  QcepIntList result;
719 
720  if (chunk) {
721  CctwIntVector3D chStart = chunk->chunkStart();
722  CctwIntVector3D chSize = chunk->chunkSize();
723  CctwDoubleVector3D dblStart(chStart.x(), chStart.y(), chStart.z());
724 
725  if (m_InputData->containsChunk(idx.x(), idx.y(), idx.z())) {
726  for (int z=0; z<chSize.z(); z++) {
727  for (int y=0; y<chSize.y(); y++) {
728  for (int x=0; x<chSize.x(); x++) {
729  CctwDoubleVector3D coords = dblStart+CctwDoubleVector3D(x,y,z);
730  CctwDoubleVector3D xfmcoord = transform.forward(coords);
731  CctwIntVector3D pixels(xfmcoord);
732 
733  if (m_OutputData->containsPixel(pixels)) {
734  int opchunk = m_OutputData->chunkContaining(pixels);
735 
736  if (opchunk != lastChunkIndex) {
737  lastChunkIndex = opchunk;
738 
739  if (!outputChunks.contains(lastChunkIndex)) {
740  outputChunks.append(opchunk);
741  }
742  }
743  }
744  }
745  }
746  }
747  }
748  }
749 
750  foreach(int chk, outputChunks) {
751  result.append(chk);
752  }
753 
754  qSort(result);
755 
756  return result;
757 }
CctwIntVector3D chunkIndexFromNumber(int n)
CctwIntVector3D chunkSize()
CctwDataChunk * chunk(int n)
bool containsChunk(int ix, int iy, int iz)
T x() const
Definition: cctwvector3d.h:17
int chunkContaining(CctwIntVector3D pixelCoord)
CctwApplication * m_Application
bool containsPixel(CctwIntVector3D pixelCoord)
CctwIntVector3D chunkStart()
T z() const
Definition: cctwvector3d.h:19
CctwChunkedData * m_OutputData
CctwChunkedData * m_InputData
T y() const
Definition: cctwvector3d.h:18
CctwVector3D< double > CctwDoubleVector3D
Definition: cctwvector3d.h:71
CctwCrystalCoordinateParameters * parameters() const
QList< CctwIntVector3D > CctwTransformer::dependencies ( int  cx,
int  cy,
int  cz 
)
slot

Definition at line 759 of file cctwtransformer.cpp.

References CctwChunkedData::chunkIndexFromNumber(), CctwChunkedData::chunkNumberFromIndex(), dependencies(), m_InputData, and m_OutputData.

760 {
761  QcepIntList deps = dependencies(m_InputData->chunkNumberFromIndex(CctwIntVector3D(cx,cy,cz)));
762 
763  QList<CctwIntVector3D> res;
764 
765  foreach(int dep, deps) {
766  res.append(m_OutputData->chunkIndexFromNumber(dep));
767  }
768 
769  return res;
770 }
CctwIntVector3D chunkIndexFromNumber(int n)
QcepIntList dependencies(int n)
CctwChunkedData * m_OutputData
CctwChunkedData * m_InputData
int chunkNumberFromIndex(CctwIntVector3D chunkIdx)
void CctwTransformer::loadDependencies ( QString  path)
slot

Definition at line 114 of file cctwtransformer.cpp.

References addDependency(), and clearDependencies().

Referenced by CctwApplication::loadDependencies().

115 {
117 
118  QFile f(path);
119 
120  if (f.open(QFile::ReadOnly)) {
121  QTextStream s(&f);
122  int i,o;
123 
124  while (!s.atEnd()) {
125  s >> i >> o;
126 
127  addDependency(i, o);
128  }
129  }
130 }
void addDependency(int f, int t)
void clearDependencies(int use)
void CctwTransformer::markInputChunkNeeded ( CctwIntVector3D  idx)
private
bool CctwTransformer::parseSubset ( CctwChunkedData data = NULL)
private

Definition at line 132 of file cctwtransformer.cpp.

References CctwChunkedData::chunkCount, m_Application, m_InputData, m_SubsetEnd, m_SubsetStart, CctwObject::printMessage(), subset, CctwVector3D< T >::x(), CctwVector3D< T >::y(), and CctwVector3D< T >::z().

Referenced by simpleTransform().

133 {
134  if (data == NULL) data = m_InputData;
135 
136  QString subset = get_Subset();
137 
138  if (subset.length() == 0) {
140  m_SubsetEnd = data->chunkCount();
141 
142  return true;
143  } else {
145  m_SubsetEnd = CctwIntVector3D(0,0,0);
146 
147  CctwIntVector3D chunks = data->chunkCount();
148 
149  QRegExp r("(\\d+)/(\\d+)");
150 
151  if (r.exactMatch(subset)) {
152  int index = r.cap(1).toInt();
153  int nsubs = r.cap(2).toInt();
154  int nbest = 0, bestdx = 0, bestdy = 0, bestdz = 0;
155  int bestnx = 0, bestny = 0, bestnz = 0;
156 
157  if (m_Application->get_Verbosity() >= 2) {
158  printMessage(tr("Subset matched : index = %1 of %2").arg(index).arg(nsubs));
159  }
160 
161  int szx = chunks.x(), szy = chunks.y(), szz = chunks.z();
162 
163  if (m_Application->get_Verbosity() >= 2) {
164  printMessage(tr("Size %1,%2,%3 - total %4")
165  .arg(szx).arg(szy).arg(szz).arg(szx*szy*szz));
166  }
167 
168  for (int dx=1; dx<=szx; dx++) {
169  int nx = (szx + dx - 1)/dx;
170 
171  if (m_Application->get_Verbosity() >= 3) {
172  printMessage(tr("DX:%1:NX:%2").arg(dx).arg(nx));
173  }
174 
175  if (nx > 0) {
176 
177  for (int dy=1; dy <= szy; dy++) {
178  int ny = (szy + dy - 1)/dy;
179 
180  if (m_Application->get_Verbosity() >= 3) {
181  printMessage(tr("DY:%1:NY:%2").arg(dy).arg(ny));
182  }
183 
184  if (ny > 0) {
185  for (int dz=1; dz <= szz; dz++) {
186  int nz = (szz + dz - 1)/dz;
187 
188  if (m_Application->get_Verbosity() >= 3) {
189  printMessage(tr("DZ:%1:NZ:%2").arg(dz).arg(nz));
190  }
191 
192  if (nz > 0) {
193  int ntot = nx*ny*nz;
194 
195  if (m_Application->get_Verbosity() >= 3) {
196  printMessage(tr("SZ:%1,%2,%3; NUM:%4,%5,%6; NSUB:%7; NTOT:%8; NBEST:%9")
197  .arg(dx).arg(dy).arg(dz)
198  .arg(nx).arg(ny).arg(nz)
199  .arg(nsubs).arg(ntot).arg(nbest));
200  }
201 
202  if (ntot <= nsubs) {
203  if (ntot > nbest) {
204  nbest = ntot;
205  bestdx = dx; bestnx = nx;
206  bestdy = dy; bestny = ny;
207  bestdz = dz; bestnz = nz;
208  } else if (ntot == nbest) {
209  int bestmax = qMax(qMax(bestdx,bestdy),bestdz);
210  int newmax = qMax(qMax(dx,dy),dz);
211 
212  if (newmax < bestmax) {
213  bestdx = dx; bestnx = nx;
214  bestdy = dy; bestny = ny;
215  bestdz = dz; bestnz = nz;
216  }
217  }
218  }
219  }
220  }
221  }
222  }
223  }
224  }
225 
226  if (nbest > 0) {
227  if (m_Application->get_Verbosity() >= 2) {
228  printMessage(tr("Best subdivision found: %1,%2,%3 - total %4")
229  .arg(bestdx).arg(bestdy).arg(bestdz).arg(bestnx*bestny*bestnz));
230  }
231 
232  if ((index >= nbest) || (index < 0)) {
233  if (m_Application->get_Verbosity() >= 2) {
234  printMessage(tr("Skipping subset %1 of %2").arg(index).arg(nbest));
235  }
236  return false;
237  } else {
238  // for (int index=0; index<nbest; index++) {
239  int xstride = 1,
240  ystride = bestnx,
241  zstride = bestnx*bestny;
242 
243  int n = index;
244 
245  int z = n / zstride;
246 
247  n %= zstride;
248 
249  int y = n / ystride;
250 
251  n %= ystride;
252 
253  int x = n / xstride;
254 
255  int x0 = x*bestdx, x1 = x0+bestdx;
256  int y0 = y*bestdy, y1 = y0+bestdy;
257  int z0 = z*bestdz, z1 = z0+bestdz;
258 
259  if (x1 > chunks.x()) x1 = chunks.x();
260  if (y1 > chunks.y()) y1 = chunks.y();
261  if (z1 > chunks.z()) z1 = chunks.z();
262 
263  if (m_Application->get_Verbosity() >= 2) {
264  printMessage(tr("Subset %1 : [%2..%3) [%4..%5) [%6..%7)")
265  .arg(index)
266  .arg(x0).arg(x1).arg(y0).arg(y1).arg(z0).arg(z1));
267  }
268 
269  m_SubsetStart = CctwIntVector3D(x0,y0,z0);
270  m_SubsetEnd = CctwIntVector3D(x1,y1,z1);
271 
272  return true;
273  }
274  }
275  } else {
276  printMessage("Subset mismatch");
277  return false;
278  }
279  }
280 
281  return false;
282 }
CctwIntVector3D m_SubsetStart
CctwIntVector3D chunkCount
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
CctwIntVector3D m_SubsetEnd
T x() const
Definition: cctwvector3d.h:17
CctwApplication * m_Application
T z() const
Definition: cctwvector3d.h:19
CctwVector3D< int > CctwIntVector3D
Definition: cctwvector3d.h:70
CctwChunkedData * m_InputData
T y() const
Definition: cctwvector3d.h:18
void CctwTransformer::readSettings ( QSettings *  set,
QString  section 
)
virtual

Reimplemented from CctwObject.

Definition at line 68 of file cctwtransformer.cpp.

References CctwObject::readSettings().

Referenced by CctwApplication::readSettings().

69 {
70  CctwObject::readSettings(set, section);
71 }
virtual void readSettings(QSettings *set, QString section)
Definition: cctwobject.cpp:52
void CctwTransformer::runTransformChunkNumber ( int  n)
slot

Definition at line 73 of file cctwtransformer.cpp.

References CctwChunkedData::chunkCount, m_Application, m_InputData, transformChunkNumber(), CctwVector3D< T >::volume(), and CctwApplication::workCompleted().

Referenced by simpleTransform(), and transform().

74 {
75  if (m_Application && !m_Application->get_Halting()) {
77  }
78 
79  if (m_Application) {
80  m_Application->prop_Progress()->incValue(1);
82  int nchunks = m_InputData->chunkCount().volume();
83 
84 // m_Application->printMessage(tr("Chunk %1/%2 transform complete").arg(n).arg(nchunks));
85  }
86 }
CctwIntVector3D chunkCount
void transformChunkNumber(int chunkId)
CctwApplication * m_Application
void workCompleted(int amt)
T volume() const
CctwChunkedData * m_InputData
void CctwTransformer::saveDependencies ( QString  path)
slot

Definition at line 89 of file cctwtransformer.cpp.

References CctwChunkedData::chunk(), CctwChunkedData::chunkCount, CctwDataChunk::dependency(), CctwDataChunk::dependencyCount(), m_InputData, CctwDataChunk::sortDependencies(), and CctwVector3D< T >::volume().

Referenced by CctwApplication::saveDependencies().

90 {
91  QFile f(path);
92 
93  if (f.open(QFile::WriteOnly | QFile::Truncate)) {
94  QTextStream s(&f);
95 
96  int nchunk = m_InputData->chunkCount().volume();
97 
98  for (int i=0; i<nchunk; i++) {
99  CctwDataChunk *chunk = m_InputData->chunk(i);
100 
101  chunk->sortDependencies();
102 
103  int n = chunk->dependencyCount();
104 
105  for (int j=0; j<n; j++) {
106  int o = chunk->dependency(j);
107 
108  s << i << "\t" << o << endl;
109  }
110  }
111  }
112 }
int dependencyCount() const
CctwDataChunk * chunk(int n)
CctwIntVector3D chunkCount
int dependency(int n) const
void sortDependencies()
T volume() const
CctwChunkedData * m_InputData
void CctwTransformer::simpleTransform ( )
slot

Definition at line 573 of file cctwtransformer.cpp.

References CctwApplication::addWorkOutstanding(), CctwDataChunk::allocatedChunkCount(), CctwChunkedData::chunkCount, CctwChunkedData::chunkNumberFromIndex(), CctwChunkedData::chunkSize, CctwChunkedData::dimensions, m_Application, m_InputData, m_OutputData, m_SubsetEnd, m_SubsetStart, parseSubset(), CctwObject::printMessage(), runTransformChunkNumber(), CctwVector3D< T >::toString(), CctwVector3D< T >::volume(), CctwApplication::waitCompleted(), CctwVector3D< T >::x(), CctwVector3D< T >::y(), and CctwVector3D< T >::z().

Referenced by CctwApplication::transform().

574 {
575  QVector < QFuture < void > > futures;
576 
577  if (m_Application) {
579  m_Application->set_Progress(0);
580  m_Application->set_Halting(false);
581  m_Application->set_ExitStatus(0);
582  }
583 
584  int msec;
585 
586  if (m_InputData -> beginTransform(true, 0)) {
587  if (m_OutputData -> beginTransform(false, 0)) {
588 
589  parseSubset();
590 
591  CctwIntVector3D chunkStart = m_SubsetStart;
592  CctwIntVector3D chunkEnd = m_SubsetEnd;
593  CctwIntVector3D nChunks = chunkEnd - chunkStart;
594 
595  if (m_Application) {
596  m_Application->set_ProgressLimit(nChunks.volume());
597  }
598 
599  QTime startAt;
600 
601  startAt.start();
602 
603  set_Skipped(0);
604 
605  if (m_Application->get_Verbosity() >= 0) {
606  printMessage("Starting Transform");
607  }
608 
609  if (m_Application->get_Verbosity() >= 2) {
610  printMessage(tr("Input Dimensions %1, Output Dimensions %2")
611  .arg(m_InputData->dimensions().toString())
612  .arg(m_OutputData->dimensions().toString()));
613  printMessage(tr("Input Chunk Size %1, Output Chunk Size %2")
614  .arg(m_InputData->chunkSize().toString())
615  .arg(m_OutputData->chunkSize().toString()));
616  printMessage(tr("Input Chunk Count %1, Output Chunk Count %2")
617  .arg(m_InputData->chunkCount().toString())
618  .arg(m_OutputData->chunkCount().toString()));
619  printMessage(tr("Input HDF Chunk Size %1, Output HDF Chunk Size %2")
620  .arg(m_InputData->get_HDFChunkSize().toString())
621  .arg(m_OutputData->get_HDFChunkSize().toString()));
622  }
623 
624  for (int z=chunkStart.z(); z<chunkEnd.z(); z++) {
625  for (int y=chunkStart.y(); y<chunkEnd.y(); y++) {
626  for (int x=chunkStart.x(); x<chunkEnd.x(); x++) {
627  if (m_Application && m_Application->get_Halting()) {
628  goto abort;
629  } else {
630  CctwIntVector3D idx(x,y,z);
631 
632  int n = m_InputData->chunkNumberFromIndex(idx);
633 
634  if (m_Application) {
636  }
637 
638  futures.append(
639  QtConcurrent::run(this, &CctwTransformer::runTransformChunkNumber, n));
640  }
641  }
642  }
643  }
644 
645 abort:
646  foreach (QFuture<void> f, futures) {
647  f.waitForFinished();
648  if (m_Application) {
649  m_Application->processEvents();
650  }
651  }
652 
653  msec = startAt.elapsed();
654 
655  m_OutputData -> flushOutputFile();
656 
657  m_OutputData -> endTransform();
658  } else {
659  printMessage("Failed to open output data");
660  m_Application->set_ExitStatus(1);
661  }
662 
663  m_InputData -> endTransform();
664  } else {
665  printMessage("Failed to open input data");
666  m_Application->set_ExitStatus(1);
667  }
668 
669  if (m_Application->get_Verbosity() >= 0) {
670  printMessage(tr("Transform complete after %1 msec, %2 chunks still allocated")
671  .arg(msec)
673 
674  printMessage(tr("%1 pixels skipped by mask").arg(get_Skipped()));
675  }
676 }
CctwIntVector3D m_SubsetStart
QString toString()
void runTransformChunkNumber(int n)
CctwIntVector3D dimensions
bool parseSubset(CctwChunkedData *data=NULL)
CctwIntVector3D chunkCount
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
CctwIntVector3D m_SubsetEnd
T x() const
Definition: cctwvector3d.h:17
static int allocatedChunkCount()
void addWorkOutstanding(int amt)
CctwApplication * m_Application
T z() const
Definition: cctwvector3d.h:19
CctwIntVector3D chunkSize
CctwChunkedData * m_OutputData
T volume() const
CctwChunkedData * m_InputData
int chunkNumberFromIndex(CctwIntVector3D chunkIdx)
T y() const
Definition: cctwvector3d.h:18
void CctwTransformer::transform ( )
slot

Definition at line 461 of file cctwtransformer.cpp.

References CctwApplication::addWorkOutstanding(), CctwDataChunk::allocatedChunkCount(), CctwChunkedData::chunk(), CctwChunkedData::chunkCount, CctwDataChunk::dependency(), CctwDataChunk::dependencyCount(), m_Application, m_InputData, m_OutputData, CctwObject::printMessage(), CctwDataChunk::resetAllocationLimits(), runTransformChunkNumber(), CctwApplication::waitCompleted(), CctwVector3D< T >::x(), CctwVector3D< T >::y(), and CctwVector3D< T >::z().

Referenced by dependencies(), CctwqtMainWindow::doTransform(), CctwApplication::transform(), and transformChunkData().

462 {
463  QVector < QFuture < void > > futures;
464 
465  if (m_Application) {
467  m_Application->set_Progress(0);
468  m_Application->set_Halting(false);
469  m_Application->set_ExitStatus(0);
470  }
471 
472  QTime startAt;
473 
474  startAt.start();
475 
476  set_Skipped(0);
477 
478  if (m_Application->get_Verbosity() >= 0) {
479  printMessage("Starting Transform");
480  }
481 
482  if (m_InputData -> beginTransform(true, get_TransformOptions())) {
483  if (m_OutputData -> beginTransform(false, get_TransformOptions())) {
484 
485  m_InputData -> clearMergeCounters();
486  m_OutputData -> clearMergeCounters();
487 
488  CctwDataChunk::resetAllocationLimits(get_BlocksLimit());
489 
491 
492  QVector < int > inputChunks;
493 
494  for (int z=0; z<chunks.z(); z++) {
495  for (int y=0; y<chunks.y(); y++) {
496  for (int x=0; x<chunks.x(); x++) {
498 
499  if (chunk) {
500  int n = chunk->dependencyCount();
501 
502  for (int i=0; i<n; i++) {
503  int ckidx = chunk->dependency(i);
504 
505  if (!inputChunks.contains(ckidx)) {
506  inputChunks.append(ckidx);
507  }
508  }
509  }
510  }
511  }
512  }
513 
514  if (m_Application->get_Verbosity() >= 2) {
515  printMessage(tr("%1 chunks of input data needed").arg(inputChunks.count()));
516  }
517 
518  if ((get_TransformOptions() & 2)) {
519  if (m_Application->get_Verbosity() >= 2) {
520  printMessage("Sorting input chunk list into input order");
521  }
522 
523  qSort(inputChunks.begin(), inputChunks.end());
524  }
525 
526  if (m_Application) {
527  m_Application->set_ProgressLimit(inputChunks.count());
528  }
529 
530  foreach(int ckidx, inputChunks) {
531  if (m_Application) {
533  }
534 
535  if ((get_TransformOptions() & 1) == 0) {
536  futures.append(
537  QtConcurrent::run(this, &CctwTransformer::runTransformChunkNumber, ckidx));
538  } else {
540  }
541  }
542 
543  foreach (QFuture<void> f, futures) {
544  f.waitForFinished();
545  if (m_Application) {
546  m_Application->processEvents();
547  }
548  }
549 
550  set_WallTime(startAt.elapsed()/1000.0);
551 
552  m_OutputData -> endTransform();
553  } else {
554  printMessage("Failed to open output data");
555  m_Application->set_ExitStatus(1);
556  }
557 
558  m_InputData -> endTransform();
559  } else {
560  printMessage("Failed to open input data");
561  m_Application->set_ExitStatus(1);
562  }
563 
564  if (m_Application->get_Verbosity() >= 0) {
565  printMessage(tr("Transform complete after %1 sec, %2 chunks still allocated")
566  .arg(get_WallTime())
568 
569  printMessage(tr("%1 pixels skipped by mask").arg(get_Skipped()));
570  }
571 }
int dependencyCount() const
CctwDataChunk * chunk(int n)
void runTransformChunkNumber(int n)
CctwIntVector3D chunkCount
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
T x() const
Definition: cctwvector3d.h:17
static int allocatedChunkCount()
int dependency(int n) const
void addWorkOutstanding(int amt)
CctwApplication * m_Application
T z() const
Definition: cctwvector3d.h:19
CctwVector3D< int > CctwIntVector3D
Definition: cctwvector3d.h:70
static void resetAllocationLimits(int nmax)
CctwChunkedData * m_OutputData
CctwChunkedData * m_InputData
T y() const
Definition: cctwvector3d.h:18
void CctwTransformer::transformChunkData ( int  chunkId,
CctwDataChunk inputChunk,
QMap< int, CctwDataChunk * > &  outputChunks 
)
slot

Definition at line 318 of file cctwtransformer.cpp.

References CctwDataChunk::allocateData(), CctwDataChunk::allocatedChunkCount(), CctwDataChunk::allocateWeights(), CctwChunkedData::chunkContaining(), CctwDataChunk::chunkSize(), CctwDataChunk::chunkStart(), CctwChunkedData::chunkStart(), CctwChunkedData::containsPixel(), CctwDataChunk::data(), CctwChunkedData::dimensions, m_Application, m_InputData, m_OutputData, CctwApplication::parameters(), CctwObject::printMessage(), transform(), CctwDataChunk::weight(), CctwVector3D< T >::x(), CctwVector3D< T >::y(), and CctwVector3D< T >::z().

Referenced by Cctwtcl_Transform_Cmd(), and transformChunkNumber().

321 {
322  QTime time;
323  time.start();
324 
325  if (m_Application->get_Verbosity() >= 3) {
326  printMessage(tr("Transforming chunk data: %1").arg(chunkId));
327  }
328 
329  QcepDoubleVector anglesvec = m_InputData->get_Angles();
330  QcepDoubleVector weightsvec= m_InputData->get_Weights();
331  QcepIntVector maskvec = m_InputData->get_Mask();
333 
334  int nMask = maskvec.count();
335  int nAngs = anglesvec.count();
336  int nWgts = weightsvec.count();
337 
338  const int *mask = maskvec.constData();
339  const double *angs = anglesvec.constData();
340  const double *wgts = weightsvec.constData();
341 
342  if (nMask <= 0) mask = NULL;
343  if (nAngs <= 0) angs = NULL;
344  if (nWgts <= 0) wgts = NULL;
345 
347  tr("transform-%1").arg(chunkId),
348  angs,
349  NULL);
350 
351  CctwDataChunk *lastChunk = NULL;
352 
353  CctwIntVector3D chStart = inputChunk->chunkStart();
354  CctwIntVector3D chSize = inputChunk->chunkSize();
355  CctwDoubleVector3D dblStart(chStart.x(), chStart.y(), chStart.z());
356 
357  int lastChunkIndex = -1;
358 
359  int osx = get_OversampleX();
360  int osy = get_OversampleY();
361  int osz = get_OversampleZ();
362 
363  int nused = 0, nskipped = 0;
364 
365  double osxstp = osx >= 1 ? 1.0/osx : 0;
366  double osystp = osy >= 1 ? 1.0/osy : 0;
367  double oszstp = osz >= 1 ? 1.0/osz : 0;
368 
369  for (int z=0; z<chSize.z(); z++) {
370  double angle = anglesvec.value(z+chStart.z());
371  double weight = weightsvec.value(z+chStart.z());
372 
373  if ((angs==NULL || angle==angle) &&
374  (wgts==NULL || weight > 0)) {
375 
376  if (wgts==NULL) weight = 1;
377 
378  for (int oz=0; oz<osz; oz++) {
379  for (int y=0; y<chSize.y(); y++) {
380  for (int oy=0; oy<osy; oy++) {
381  for (int x=0; x<chSize.x(); x++) {
382  CctwIntVector3D globalpix(chStart + CctwIntVector3D(x,y,z));
383 
384 
385  if (mask == NULL || mask[(globalpix.y())*dims.x() + globalpix.x()] == 0) {
386  nused++;
387  CctwIntVector3D iprelat(x,y,z);
388  for (int ox=0; ox<osx; ox++) {
389  CctwDoubleVector3D coords = dblStart+CctwDoubleVector3D(x+ox*osxstp, y+oy*osystp, z+oz*oszstp);
390  CctwDoubleVector3D xfmcoord = transform.forward(coords);
391  CctwIntVector3D pixels(xfmcoord);
392 
393  if (m_OutputData->containsPixel(pixels)) {
394  int opchunk = m_OutputData->chunkContaining(pixels);
395  CctwIntVector3D oprelat = pixels - m_OutputData->chunkStart(opchunk);
396 
397  if (opchunk != lastChunkIndex) {
398 
399  lastChunkIndex = opchunk;
400 
401  if (!outputChunks.contains(lastChunkIndex)) {
402  // printMessage(tr("Input Chunk [%1,%2,%3] -> Output Chunk [%4,%5,%6]")
403  // .arg(idx.x()).arg(idx.y()).arg(idx.z())
404  // .arg(opchunk.x()).arg(opchunk.y()).arg(opchunk.z()));
405 
406  CctwDataChunk *chunk =
407  new CctwDataChunk(m_OutputData, lastChunkIndex,
408  tr("chunk-%1").arg(lastChunkIndex), NULL);
409 
410  if (chunk) {
411  chunk->allocateData();
412  chunk->allocateWeights();
413  }
414 
415  outputChunks[lastChunkIndex] = chunk;
416  }
417 
418  lastChunk = outputChunks[lastChunkIndex];
419  }
420 
421  if (lastChunk) {
422  int ox = oprelat.x(), oy = oprelat.y(), oz = oprelat.z();
423  int ix = iprelat.x(), iy = iprelat.y(), iz = iprelat.z();
424 
425  double oval = lastChunk->data(ox, oy, oz);
426  double owgt = lastChunk->weight(ox, oy, oz);
427  double ival = inputChunk->data(ix, iy, iz);
428  double iwgt = inputChunk->weight(ix, iy, iz)*weight;
429 
430  if (iwgt != 0) {
431  lastChunk->setData(ox, oy, oz, oval+ival);
432  lastChunk->setWeight(ox, oy, oz, owgt+iwgt);
433  }
434  }
435  }
436  }
437  } else {
438  nskipped++;
439  }
440  }
441  }
442  }
443  }
444  }
445  }
446 
447  if (m_Application->get_Verbosity() >= 3) {
448  printMessage(tr("Transform chunk data: %1: done. Time %2 s, %3 output chunks, %4 allocated, used %5, skipped %6")
449  .arg(chunkId)
450  .arg(time.elapsed()/1000.0,5)
451  .arg(outputChunks.count())
453  .arg(nused)
454  .arg(nskipped)
455  );
456  }
457 
458  m_Skipped.incValue(nskipped);
459 }
CctwIntVector3D chunkStart(int n)
CctwIntVector3D chunkSize()
CctwIntVector3D dimensions
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
CctwChunkedData::MergeDataType weight(int lx, int ly, int lz)
T x() const
Definition: cctwvector3d.h:17
static int allocatedChunkCount()
int chunkContaining(CctwIntVector3D pixelCoord)
CctwApplication * m_Application
bool containsPixel(CctwIntVector3D pixelCoord)
CctwIntVector3D chunkStart()
T z() const
Definition: cctwvector3d.h:19
CctwVector3D< int > CctwIntVector3D
Definition: cctwvector3d.h:70
CctwChunkedData * m_OutputData
CctwChunkedData * m_InputData
CctwChunkedData::MergeDataType data(int lx, int ly, int lz)
T y() const
Definition: cctwvector3d.h:18
CctwVector3D< double > CctwDoubleVector3D
Definition: cctwvector3d.h:71
CctwCrystalCoordinateParameters * parameters() const
void CctwTransformer::transformChunkNumber ( int  chunkId)
slot

Definition at line 284 of file cctwtransformer.cpp.

References CctwDataChunk::deallocateData(), CctwDataChunk::deallocateWeights(), CctwDataChunk::dependencyCount(), m_InputData, m_OutputData, CctwChunkedData::mergeChunk(), CctwObject::printMessage(), CctwChunkedData::readChunk(), CctwChunkedData::releaseChunkData(), and transformChunkData().

Referenced by runTransformChunkNumber().

285 {
286  CctwDataChunk *inputChunk = m_InputData->readChunk(chunkId);
287  QMap<int, CctwDataChunk*> outputChunks;
288 
289  if (inputChunk) {
290 
291  transformChunkData(chunkId, inputChunk, outputChunks);
292 
293  inputChunk->deallocateData();
294  inputChunk->deallocateWeights();
295 
296 // printMessage(tr("Need to merge %1 output chunks from input chunk [%2]")
297 // .arg(outputChunks.count())
298 // .arg(chunkId));
299 
300  if (inputChunk->dependencyCount() && inputChunk->dependencyCount() != outputChunks.count()) {
301  printMessage(tr("Discrepancy between numbers of merged chunks : dependencyCount() = %1, chunks.count() = %2")
302  .arg(inputChunk->dependencyCount()).arg(outputChunks.count()));
303  }
304 
305  foreach(CctwDataChunk *outputChunk, outputChunks) {
306  m_OutputData->mergeChunk(outputChunk);
307 
308  delete outputChunk;
309  }
310 
311  m_InputData->releaseChunkData(chunkId);
312  } else {
313  printMessage(tr("Could not read chunk: %1").arg(chunkId));
314 // exit(1);
315  }
316 }
int dependencyCount() const
void releaseChunkData(int n)
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
void mergeChunk(CctwDataChunk *chunk)
void transformChunkData(int chunkId, CctwDataChunk *inputChunk, QMap< int, CctwDataChunk * > &outputChunks)
CctwChunkedData * m_OutputData
CctwChunkedData * m_InputData
CctwDataChunk * readChunk(int n)
void CctwTransformer::writeSettings ( QSettings *  set,
QString  section 
)
virtual

Reimplemented from CctwObject.

Definition at line 63 of file cctwtransformer.cpp.

References CctwObject::writeSettings().

Referenced by CctwApplication::writeSettings().

64 {
65  CctwObject::writeSettings(set, section);
66 }
virtual void writeSettings(QSettings *set, QString section)
Definition: cctwobject.cpp:39

Member Data Documentation

CctwApplication* CctwTransformer::m_Application
private
QcepImageData<double>* CctwTransformer::m_ImageX
private

Definition at line 77 of file cctwtransformer.h.

QcepImageData<double>* CctwTransformer::m_ImageY
private

Definition at line 78 of file cctwtransformer.h.

QcepImageData<double>* CctwTransformer::m_ImageZ
private

Definition at line 79 of file cctwtransformer.h.

CctwChunkedData* CctwTransformer::m_InputData
private
QMutex CctwTransformer::m_LockX
private

Definition at line 73 of file cctwtransformer.h.

QMutex CctwTransformer::m_LockY
private

Definition at line 74 of file cctwtransformer.h.

QMutex CctwTransformer::m_LockZ
private

Definition at line 75 of file cctwtransformer.h.

double CctwTransformer::m_MaxData
private

Definition at line 85 of file cctwtransformer.h.

double CctwTransformer::m_MaxWeight
private

Definition at line 87 of file cctwtransformer.h.

double CctwTransformer::m_MinData
private

Definition at line 84 of file cctwtransformer.h.

double CctwTransformer::m_MinWeight
private

Definition at line 86 of file cctwtransformer.h.

CctwChunkedData* CctwTransformer::m_OutputData
private
CctwIntVector3D CctwTransformer::m_SubsetEnd
private

Definition at line 90 of file cctwtransformer.h.

Referenced by parseSubset(), and simpleTransform().

CctwIntVector3D CctwTransformer::m_SubsetStart
private

Definition at line 89 of file cctwtransformer.h.

Referenced by parseSubset(), and simpleTransform().

CctwTransformInterface* CctwTransformer::m_Transform
private

Definition at line 71 of file cctwtransformer.h.

QcepImageData<double>* CctwTransformer::m_WeightX
private

Definition at line 80 of file cctwtransformer.h.

QcepImageData<double>* CctwTransformer::m_WeightY
private

Definition at line 81 of file cctwtransformer.h.

QcepImageData<double>* CctwTransformer::m_WeightZ
private

Definition at line 82 of file cctwtransformer.h.

Property Documentation

int CctwTransformer::blocksLimit
readwrite

Definition at line 96 of file cctwtransformer.h.

int CctwTransformer::compression
readwrite

Definition at line 126 of file cctwtransformer.h.

int CctwTransformer::normalization
readwrite

Definition at line 123 of file cctwtransformer.h.

int CctwTransformer::oversampleX
readwrite

Definition at line 102 of file cctwtransformer.h.

int CctwTransformer::oversampleY
readwrite

Definition at line 105 of file cctwtransformer.h.

int CctwTransformer::oversampleZ
readwrite

Definition at line 108 of file cctwtransformer.h.

QString CctwTransformer::projectDestination
readwrite

Definition at line 120 of file cctwtransformer.h.

bool CctwTransformer::projectX
readwrite

Definition at line 111 of file cctwtransformer.h.

bool CctwTransformer::projectY
readwrite

Definition at line 114 of file cctwtransformer.h.

bool CctwTransformer::projectZ
readwrite

Definition at line 117 of file cctwtransformer.h.

int CctwTransformer::skipped
readwrite

Definition at line 135 of file cctwtransformer.h.

QString CctwTransformer::subset
readwrite

Definition at line 129 of file cctwtransformer.h.

Referenced by parseSubset().

int CctwTransformer::transformOptions
readwrite

Definition at line 99 of file cctwtransformer.h.

int CctwTransformer::useDependencies
readwrite

Definition at line 132 of file cctwtransformer.h.

double CctwTransformer::wallTime
readwrite

Definition at line 93 of file cctwtransformer.h.


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