cctw  0.2.1
cctwcomparer.cpp
Go to the documentation of this file.
1 #include "cctwcomparer.h"
2 #include "cctwapplication.h"
3 #include "cctwinputdatah5.h"
4 
5 CctwComparer::CctwComparer(CctwApplication *application, QString name, QObject *parent) :
6  CctwObject(name, parent),
7  m_Application(application),
8  m_FilePath1(m_Application->saver(), this, "filePath1", "", "Path to 1st file"),
9  m_Dataset1(m_Application->saver(), this, "dataset1", "data", "Name of dataset within 1st file"),
10  m_FilePath2(m_Application->saver(), this, "filePath2", "", "Path to 2nd file"),
11  m_Dataset2(m_Application->saver(), this, "dataset2", "data", "Name of dataset within 2nd file"),
12  m_CompareRigorously(m_Application->saver(), this, "compareRigorously", false, "Perform rigorous compare (every element) of imported data"),
13  m_CompareApproximately(m_Application->saver(), this, "compareApproximately", true, "Perform approximate compare (about 30 seconds) of imported data")
14 {
15 }
16 
18 {
19 }
20 
22 {
23  printMessage("Compare datasets");
24 
25  if (get_CompareRigorously()) {
27  }
28 
29  if (get_CompareApproximately()) {
31  }
32 }
33 
35 {
36  printMessage("Compare datasets rigorously");
37 }
38 
39 static int randomIndex(int n)
40 {
41  return qrand()%n;
42 }
43 
45 {
46  printMessage("Compare datasets approximately");
47 
48  CctwInputDataH5 d1(get_FilePath1(), get_Dataset1(), "d1", this);
49  CctwInputDataH5 d2(get_FilePath2(), get_Dataset2(), "d2", this);
50 
51  CctwIntVector3D dim1 = d1.dimensions();
52  CctwIntVector3D dim2 = d2.dimensions();
53 
54  if (dim1 != dim2) {
55  printMessage(tr("Dataset dimensions are not the same (%1 vs %2)")
56  .arg(dim1.toString()).arg(dim2.toString()));
57 
58  return;
59  }
60 
61  QTime startAt;
62  startAt.start();
63  int n=0;
64 
65  while (startAt.elapsed() < 60*1000
66  && !m_Application->get_Halting()
67  && n < 100) {
68  int nx = randomIndex(12)+4;
69  int ny = randomIndex(12)+4;
70  int nz = randomIndex(12)+4;
71 
72  int ix = randomIndex(dim1.x()-nx);
73  int iy = randomIndex(dim1.y()-ny);
74  int iz = randomIndex(dim1.z()-nz);
75 
76  QVector<double> c1 = d1.readChunk(ix, iy, iz, nx, ny, nz);
77  QVector<double> c2 = d2.readChunk(ix, iy, iz, nx, ny, nz);
78 
79  if (c1.count() != c2.count()) {
80  n++;
81  printMessage(tr("Chunk data lengths are not the same for chunk %1 :: %2: (%3 vs %4)")
82  .arg(CctwIntVector3D(ix,iy,iz).toString())
83  .arg(CctwIntVector3D(nx,ny,nz).toString())
84  .arg(c1.count()).arg(c2.count()));
85  } else {
86  for (int i=0; i<c1.count(); i++) {
87  if (c1[i] != c2[i]) {
88  n++;
89  printMessage(tr("Chunk values differ in chunk %1 :: %2: at %3 (%4 vs %5)")
90  .arg(CctwIntVector3D(ix,iy,iz).toString())
91  .arg(CctwIntVector3D(nx,ny,nz).toString())
92  .arg(i).arg(c1[i]).arg(c2[i]));
93  break;
94  }
95  }
96  }
97  }
98 
99  printMessage(tr("Compare completed, %1 errors found").arg(n));
100 }
QVector< double > readChunk(int ix, int iy, int iz, int nx, int ny, int nz)
virtual ~CctwComparer()
QString toString()
CctwApplication * m_Application
Definition: cctwcomparer.h:23
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
CctwComparer(CctwApplication *application, QString name, QObject *parent=0)
Definition: cctwcomparer.cpp:5
T x() const
Definition: cctwvector3d.h:17
CctwIntVector3D dimensions() const
void compareDatasetsApproximately()
T z() const
Definition: cctwvector3d.h:19
CctwVector3D< int > CctwIntVector3D
Definition: cctwvector3d.h:70
void compareDatasetsRigorously()
T y() const
Definition: cctwvector3d.h:18
static int randomIndex(int n)
void compareDatasets()