File failed to load: https://isis.astrogeology.usgs.gov/9.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
unitTest_disabled.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7#include <iostream>
8
9#include <QFileInfo>
10#include <QDebug>
11
12#include "IException.h"
13#include "Brick.h"
14#include "Cube.h"
15#include "CubeAttribute.h"
16#include "FileName.h"
17#include "LineManager.h"
18#include "Pvl.h"
19#include "Preference.h"
20#include "Histogram.h"
21#include "SpecialPixel.h"
22#include "Statistics.h"
23
24using namespace std;
25using namespace Isis;
26
27
28int main(int argc, char *argv[]) {
29 Preference::Preferences(true);
30
31 try {
32 void Report(Cube & c);
33 cerr << "Unit test for Cube" << endl;
34
35 cerr << "Constructing cube ... " << endl;
36 Cube out;
37 Report(out);
38
39 // Test create and write methods
40 cerr << "Creating 32-bit cube ... " << endl;
41 out.setDimensions(150, 200, 2);
42 out.create("$TMP/IsisCube_00");
43 Report(out);
44
45 cerr << "Write cube ... " << endl;
46 LineManager line(out);
47 long j = 0;
48 for(line.begin(); !line.end(); line++) {
49 for(int i = 0; i < line.size(); i++) {
50 line[i] = (double) j;
51 j++;
52 }
53 j--;
54 out.write(line);
55 }
56
57 // Copy returns the resulting Cube, we don't care about it (but we need it to flush) so delete
58 delete out.copy("$TMP/IsisCube_01", CubeAttributeOutput());
59 out.close();
60
61 // Test the open and read methods
62 cerr << "Opening cube ... " << endl;
63 Cube in("$TMP/IsisCube_01");
64 Report(in);
65
66 cerr << "Comparing cube ... " << endl;
67 LineManager inLine(in);
68 j = 0;
69 for(inLine.begin(); !inLine.end(); inLine++) {
70 in.read(inLine);
71 for(int i = 0; i < inLine.size(); i++) {
72 if(inLine[i] != (double) j) {
73 cerr << "Problem at"
74 << " line " << inLine.Line()
75 << " sample " << i + 1
76 << " band " << inLine.Band() << ": "
77 << inLine[i] << " != " << double(j) << endl;
78 return 1;
79 }
80 j++;
81 }
82 j--;
83 }
84 in.close();
85 cerr << endl;
86
87 // Test other options for output
88 cerr << "Creating 8-bit cube ... " << endl;
89 Cube out2;
90 out2.setDimensions(150, 200, 1);
91 out2.setLabelsAttached(false);
92 out2.setBaseMultiplier(200.0, -1.0);
93// out2.SetByteOrder(Msb);
94 out2.setByteOrder(ISIS_LITTLE_ENDIAN ? Msb : Lsb);
95 out2.setFormat(Cube::Bsq);
96 out2.setLabelSize(1000);
97 out2.setPixelType(UnsignedByte);
98 out2.create("$TMP/IsisCube_02");
99
100 j = 0;
101 LineManager oline(out2);
102 for(oline.begin(); !oline.end(); oline++) {
103 for(int i = 0; i < oline.size(); i++) {
104 oline[i] = (double) j;
105 }
106 out2.clearIoCache();
107 out2.write(oline);
108 j++;
109 }
110 out2.close();
111
112 cerr << "Comparing cube ... " << endl;
113 Cube in2;
114 try {
115 in2.open("$TMP/IsisCube_02");
116 }
117 catch (IException &e) {
118 e.print();
119 }
120 Report(in2);
121 j = 0;
122 LineManager inLine2(in2);
123 for(inLine2.begin(); !inLine2.end(); inLine2++) {
124 in2.read(inLine2);
125 for(int i = 0; i < inLine2.size(); i++) {
126 if(inLine2[i] != (double) j) {
127 cerr << "Problem at line " << inLine2.Line()
128 << " sample " << i + 1 << ": "
129 << inLine2[i] << " != " << double(j) << endl;
130 return 1;
131 }
132 }
133 in2.clearIoCache();
134 j++;
135 }
136 in2.close();
137
138
139 // Test other options for output
140 cerr << "Creating 16-bit cube ... " << endl;
141 Cube out3;
142 out3.setDimensions(150, 200, 2);
143 out3.setBaseMultiplier(30000.0, -1.0);
144// out3.SetByteOrder(Msb);
145 out2.setByteOrder(ISIS_LITTLE_ENDIAN ? Msb : Lsb);
146 out3.setPixelType(SignedWord);
147 out3.create("$TMP/IsisCube_03");
148
149 j = 0;
150 LineManager oline3(out3);
151 for(oline3.begin(); !oline3.end(); oline3++) {
152 for(int i = 0; i < oline3.size(); i++) {
153 oline3[i] = (double) j;
154 j++;
155 }
156 out3.write(oline3);
157 }
158 out3.close();
159
160 cerr << "Comparing cube ... " << endl;
161 Cube in3;
162 in3.open("$TMP/IsisCube_03");
163 Report(in3);
164 j = 0;
165 LineManager inLine3(in3);
166 for(inLine3.begin(); !inLine3.end(); inLine3++) {
167 in3.read(inLine3);
168 in3.clearIoCache();
169 for(int i = 0; i < inLine3.size(); i++) {
170 if(inLine3[i] != (double) j) {
171 cerr << "Problem at line " << inLine3.Line()
172 << " sample " << i + 1 << " band " << inLine3.Band() << ": "
173 << inLine3[i] << " != " << double(j) << endl;
174 return 1;
175 }
176 j++;
177 }
178 }
179 in3.close();
180
181
182 in.open("$TMP/IsisCube_01");
183
184 // Test Histogram object on a single band, 1 by default
185 cerr << "Testing histogram method, band 1 ... " << endl;
186 Histogram *bandOneHist = in.histogram();
187 cerr << "Average: " << bandOneHist->Average() << endl;
188 cerr << "Standard Dev: " << bandOneHist->StandardDeviation() << endl;
189 cerr << "Mode: " << bandOneHist->Mode() << endl;
190 cerr << "Total Pixels: " << bandOneHist->TotalPixels() << endl;
191 cerr << "Null Pixels: " << bandOneHist->NullPixels() << endl;
192 cerr << endl;
193 delete bandOneHist;
194 bandOneHist = NULL;
195
196 // Test histogram object on all bands
197 cerr << "Testing histogram method, all bands ... " << endl;
198 Histogram *allBandsHistogram = in.histogram(0);
199 cerr << "Average: " << allBandsHistogram->Average() << endl;
200 cerr << "Standard Dev: " << allBandsHistogram->StandardDeviation() << endl;
201 cerr << "Mode: " << allBandsHistogram->Mode() << endl;
202 cerr << "Total Pixels: " << allBandsHistogram->TotalPixels() << endl;
203 cerr << "Null Pixels: " << allBandsHistogram->NullPixels() << endl;
204 cerr << endl;
205 delete allBandsHistogram;
206 allBandsHistogram = NULL;
207
208 // Check error for too few (negative) bands
209 try {
210 in.histogram(-1);
211 }
212 catch (IException &e) {
213 e.print();
214 }
215
216 // Check error for histogram object on a closed cube
217 try {
218 // out has already been closed
219 out.histogram(0);
220 }
221 catch (IException &e)
222 {
223 e.print();
224 }
225
226 cerr << endl;
227
228 // Test statistics object on a single band, 1 by default
229 cerr << "Testing statistics method, band 1 ... " << endl;
230 Statistics *bandOneStats = in.statistics();
231 cerr << "Average: " << bandOneStats->Average() << endl;
232 cerr << "Standard Dev: " << bandOneStats->StandardDeviation() << endl;
233 cerr << "Total Pixels: " << bandOneStats->TotalPixels() << endl;
234 cerr << "Null Pixels: " << bandOneStats->NullPixels() << endl;
235 cerr << endl;
236 delete bandOneStats;
237 bandOneStats = NULL;
238
239 // Test statistics object on all bands
240 cerr << "Testing statistics method, all bands ... " << endl;
241 Statistics *allBandsStats = in.statistics(0);
242 cerr << "Average: " << allBandsStats->Average() << endl;
243 cerr << "Standard Dev: " << allBandsStats->StandardDeviation() << endl;
244 cerr << "Total Pixels: " << allBandsStats->TotalPixels() << endl;
245 cerr << "Null Pixels: " << allBandsStats->NullPixels() << endl;
246 cerr << endl;
247 delete allBandsStats;
248 allBandsStats = NULL;
249
250 // Check error for too few (negative) bands
251 try {
252 in.statistics(-1);
253 }
254 catch (IException &e) {
255 e.print();
256 }
257
258 // Check error for statistics object on a closed cube
259 try {
260 // out has already been closed
261 out.statistics(0);
262 }
263 catch (IException &e)
264 {
265 e.print();
266 }
267
268 cerr << endl;
269
270 cerr << "Virtual band tests" << endl; // Virtual Band tests
271
272 cerr << "Nbands = " << in.bandCount() << endl;
273 cerr << "Band 1 = " << in.physicalBand(1) << endl;
274 cerr << "Band 2 = " << in.physicalBand(2) << endl;
275 in.close();
276 cerr << endl;
277
278 QList<QString> vbands;
279 vbands.push_back("2");
280 in.setVirtualBands(vbands);
281 in.open("$TMP/IsisCube_01");
282 cerr << "Nbands = " << in.bandCount() << endl;
283 cerr << "Band 1 = " << in.physicalBand(1) << endl;
284 cerr << endl;
285
286 // Test ReOpen
287 cerr << "ReOpen tests" << endl;
288 Report(in);
289 in.reopen("rw");
290 Report(in);
291 in.reopen("r");
292 Report(in);
293
294 // Test reading past cube boundaries.
295 // First create a new cube for us to test and fill it with ones.
296 cerr << "Testing reading past cube boundaries ... " << endl;
297 cerr << "Constructing cube ... " << endl << endl;
298 Cube boundaryTestCube;
299 boundaryTestCube.setDimensions(10, 10, 4);
300 boundaryTestCube.create("$TMP/IsisCube_boundary");
301 Report(boundaryTestCube);
302 LineManager boundaryLine(boundaryTestCube);
303
304 for(boundaryLine.begin(); !boundaryLine.end(); boundaryLine++) {
305 for(int i = 0; i < boundaryLine.size(); i++) {
306 boundaryLine[i] = 1.0;
307 }
308 boundaryTestCube.write(boundaryLine);
309 }
310
311 // Now read past the cube boundaries and compare the results to what we
312 // expect. All valid positions in the brick should be filled with ones since
313 // our cube is entirely filled with ones, and any parts that fall outside of
314 // the cube should be nulls.
315 cerr << "Reading completely within cube boundaries ... " << endl;
316 Brick readBrick(1, 1, 2, boundaryTestCube.pixelType());
317 readBrick.SetBasePosition(1, 1, 1);
318 boundaryTestCube.read(readBrick);
319
320 cerr << "\tComparing results ... " << endl;
321 for(int i = 0; i < readBrick.size(); i++) {
322 if (readBrick[i] != 1.0) {
323 cerr << "\tNot all values in brick were 1.0." << endl;
324 return 1;
325 }
326 }
327
328 cerr << "Reading completely outside band boundaries ... " << endl;
329 readBrick.SetBasePosition(1, 1, -1);
330 boundaryTestCube.read(readBrick);
331
332 cerr << "\tComparing results ... " << endl;
333 for(int i = 0; i < readBrick.size(); i++) {
334 if (readBrick[i] != Null) {
335 cerr << "\tNot all values in brick were Null." << endl;
336 return 1;
337 }
338 }
339 cerr << endl;
340
341 // Read before the bands start in the cube.
342 cerr << "Reading partially within band boundaries ... " << endl;
343 cerr << "\t Reading bands 0 (should be null) and 1 (should be 1.0)... " << endl;
344 cerr << "\t\t Comparing results ... " << endl;
345 readBrick.SetBasePosition(1, 1, 0);
346 boundaryTestCube.read(readBrick);
347
348 if (readBrick[0] != Null) {
349 cerr << "\t\t Value outside cube boundary was not Null." << endl;
350 return 1;
351 }
352 if (readBrick[1] != 1.0) {
353 cerr << "\t\t Value inside cube boundary was not 1.0." << endl;
354 return 1;
355 }
356
357 cerr << "\t Reading bands 4 (should be 1.0) and 5 (should be null)... " << endl;
358 cerr << "\t\t Comparing results ... " << endl;
359 // Read after the bands start in the cube.
360 readBrick.SetBasePosition(1, 1, 4);
361 boundaryTestCube.read(readBrick);
362
363 if (readBrick[0] != 1.0) {
364 cerr << "\t\t Value inside cube boundary was not 1.0." << endl;
365 return 1;
366 }
367 if (readBrick[1] != Null) {
368 cerr << "\t\t Value outside cube boundary was not Null." << endl;
369 return 1;
370 }
371 cerr << endl;
372
373 boundaryTestCube.close();
374
375 // Test reading outside a cube with virtual bands.
376 cerr << "Testing reading past cube boundaries with virtual bands (2, 1, 3, 4, 2)... " << endl;
377 QList<QString> virtualBands;
378 virtualBands.push_back("2");
379 virtualBands.push_back("1");
380 virtualBands.push_back("3");
381 virtualBands.push_back("4");
382 virtualBands.push_back("2");
383 boundaryTestCube.setVirtualBands(virtualBands);
384 boundaryTestCube.open("$TMP/IsisCube_boundary");
385
386 cerr << "Reading completely outside virtual band boundaries ... " << endl;
387 readBrick.SetBasePosition(1, 1, 6);
388 boundaryTestCube.read(readBrick);
389
390 cerr << "\tComparing results starting at band 6... " << endl;
391 for(int i = 0; i < readBrick.size(); i++) {
392 if (readBrick[i] != Null) {
393 cerr << "\tNot all values in brick (outside cube boundary) were Null. " << i << endl;
394 return 1;
395 }
396 }
397
398 cerr << "\tComparing results starting at band 1000... " << endl;
399 readBrick.SetBasePosition(1, 1, 1000);
400 boundaryTestCube.read(readBrick);
401 for(int i = 0; i < readBrick.size(); i++) {
402 if (readBrick[i] != Null) {
403 cerr << "\tNot all values in brick (outside cube boundary) were Null." << endl;
404 return 1;
405 }
406 }
407
408 cerr << "\tComparing results starting at band -1... " << endl;
409 readBrick.SetBasePosition(1, 1, -1);
410 boundaryTestCube.read(readBrick);
411 for(int i = 0; i < readBrick.size(); i++) {
412 if (readBrick[i] != Null) {
413 cerr << "Not all values in brick (outside cube boundary) were Null. " << endl;
414 return 1;
415 }
416 }
417 cerr << endl;
418
419 // Read before the bands start in the cube.
420 cerr << "Reading partially within virtual band boundaries ... " << endl;
421 readBrick.SetBasePosition(1, 1, 0);
422 boundaryTestCube.read(readBrick);
423
424 cerr << "Comparing results ... " << endl;
425 if (readBrick[0] != Null) {
426 cerr << "Value outside cube boundary (band 0) was not Null." << endl;
427 return 1;
428 }
429 if (readBrick[1] != 1.0) {
430 cerr << "Value inside cube boundary (band 1) was not 1.0." << endl;
431 return 1;
432 }
433
434 // Read after the bands start in the cube.
435 readBrick.SetBasePosition(1, 1, 5);
436 boundaryTestCube.read(readBrick);
437
438 if (readBrick[0] != 1.0) {
439 cerr << "Value inside cube boundary (band 5) was not 1.0." << endl;
440 return 1;
441 }
442 if (readBrick[1] != Null) {
443 cerr << "Value outside cube boundary (band 6) was not Null." << endl;
444 return 1;
445 }
446
447 // Resize the brick to be have many more bands than the cube, and position
448 // it before the start of the bands. We should get nulls, then some values,
449 // then more nulls.
450 readBrick.Resize(1, 1, 20);
451 readBrick.SetBasePosition(1, 1, -10);
452 boundaryTestCube.read(readBrick);
453 for (int i = 0; i < readBrick.size(); i++) {
454 if (i >= 11 && i <= 15) {
455 if (readBrick[i] != 1.0) {
456 cerr << "Value inside cube boundary, at brick band " << i + 1 << " was not 1.0." << endl;
457 return 1;
458 }
459 }
460 else {
461 if (readBrick[i] != Null) {
462 cerr << "Value outside cube boundary, at brick band " << i + 1
463 << " was not Null." << endl;
464 return 1;
465 }
466 }
467 }
468 cerr << endl;
469 boundaryTestCube.close();
470
471
472 // Test cube where its chunk size is the same as its buffer shape
473 cerr << "Testing one line BSQ cube (where chunk dimensions == buffer shape) ... " << endl;
474 cerr << "Constructing cube ... " << endl << endl;
475 Cube bsqOneLineTestCube;
476 bsqOneLineTestCube.setDimensions(3, 1, 3);
477 bsqOneLineTestCube.setFormat(Cube::Bsq);
478 bsqOneLineTestCube.create("$TMP/IsisCube_bsqOneLine");
479 Report(bsqOneLineTestCube);
480 LineManager oneLine(bsqOneLineTestCube);
481
482 // our cube will be 1, 2, 3
483 // 2, 3, 4
484 // 3, 4, 5
485 for (oneLine.begin(); !oneLine.end(); oneLine++) {
486 for (int i = 0; i < oneLine.size(); i++) {
487 oneLine[i] = 1 * i + oneLine.Band();
488 }
489 bsqOneLineTestCube.write(oneLine);
490 }
491 bsqOneLineTestCube.close();
492
493 // Simulate reading of an S x 1 x B cube
494 Brick readLineBrick(3, 1, 1, bsqOneLineTestCube.pixelType());
495
496 // Test reading repeated ascending virtual bands
497 cerr << "Testing reading ascending repeating virtual bands (1, 2, 2, 3)... " << endl;
498 virtualBands.clear();
499 virtualBands.push_back("1");
500 virtualBands.push_back("2");
501 virtualBands.push_back("2");
502 virtualBands.push_back("3");
503 bsqOneLineTestCube.setVirtualBands(virtualBands);
504 bsqOneLineTestCube.open("$TMP/IsisCube_bsqOneLine");
505 for (int sb = 1; sb <= virtualBands.size(); sb++) {
506 readLineBrick.SetBasePosition(1, 1, sb);
507 bsqOneLineTestCube.read(readLineBrick);
508 for (int i = 0; i < readLineBrick.size(); i++) {
509 if (readLineBrick[i] != (i + virtualBands[readLineBrick.Band()-1].toInt())) {
510 cerr << "Virtual bands accessed incorrectly at brick band "
511 << readLineBrick.Band() << endl;
512 return 1;
513 }
514 }
515 }
516 cerr << endl;
517 bsqOneLineTestCube.close();
518
519 // Test reading skipped ascending virtual bands
520 cerr << "Testing reading skipped ascending virtual bands (1, 3, 3)... " << endl;
521 virtualBands.clear();
522 virtualBands.push_back("1");
523 virtualBands.push_back("3");
524 virtualBands.push_back("3");
525 bsqOneLineTestCube.setVirtualBands(virtualBands);
526 bsqOneLineTestCube.open("$TMP/IsisCube_bsqOneLine");
527 for (int sb = 1; sb <= virtualBands.size(); sb++) {
528 readLineBrick.SetBasePosition(1, 1, sb);
529 bsqOneLineTestCube.read(readLineBrick);
530 for (int i = 0; i < readLineBrick.size(); i++) {
531 if (readLineBrick[i] != (i + virtualBands[readLineBrick.Band()-1].toInt())) {
532 cerr << "Virtual bands accessed incorrectly at virtual band "
533 << virtualBands[readLineBrick.Band() - 1] << endl;
534 return 1;
535 }
536 }
537 }
538 cerr << endl;
539 bsqOneLineTestCube.close();
540
541 // Test reading outside boundaries
542 cerr << "Testing reading outside of cube boundaries with virtual bands (1, 5)... " << endl;
543 virtualBands.clear();
544 virtualBands.push_back("1");
545 virtualBands.push_back("5");
546 bsqOneLineTestCube.setVirtualBands(virtualBands);
547 bsqOneLineTestCube.open("$TMP/IsisCube_bsqOneLine");
548 for (int sb = 1; sb <= virtualBands.size(); sb++) {
549 readLineBrick.SetBasePosition(1, 1, sb);
550 bsqOneLineTestCube.read(readLineBrick);
551 for (int i = 0; i < readLineBrick.size(); i++) {
552 if (readLineBrick.Band() == 1) {
553 if (readLineBrick[i] != (i + virtualBands[readLineBrick.Band()-1].toInt())) {
554 cerr << "Virtual bands accessed incorrectly at virtual band "
555 << virtualBands[readLineBrick.Band() - 1] << endl;
556 return 1;
557 }
558 }
559 else {
560 if (readLineBrick[i] != Null) {
561 cerr << "Value outside cube boundary at virtual band "
562 << virtualBands[readLineBrick.Band() - 1] << endl;
563 }
564 }
565 }
566 }
567 cerr << endl;
568 bsqOneLineTestCube.close();
569
570 // Test reading descending bands
571 cerr << "Testing reading descending virtual bands (3, 1, 3)... " << endl;
572 virtualBands.clear();
573 virtualBands.push_back("3");
574 virtualBands.push_back("1");
575 virtualBands.push_back("3");
576 bsqOneLineTestCube.setVirtualBands(virtualBands);
577 bsqOneLineTestCube.open("$TMP/IsisCube_bsqOneLine");
578 for (int sb = 1; sb <= virtualBands.size(); sb++) {
579 readLineBrick.SetBasePosition(1, 1, sb);
580 bsqOneLineTestCube.read(readLineBrick);
581 for (int i = 0; i < readLineBrick.size(); i++) {
582 if (readLineBrick[i] != (i + virtualBands[readLineBrick.Band()-1].toInt())) {
583 cerr << "Virtual bands accessed incorrectly at virtual band "
584 << virtualBands[readLineBrick.Band() - 1] << endl;
585 return 1;
586 }
587 }
588 }
589 cerr << endl;
590 bsqOneLineTestCube.close();
591
592
593 // Test creating a bsq cube that exceeds 1GB sample size limit to test CubeBsqHandler
594 cerr << "Testing creating large BSQ where samples exceed 1GB chunk size limit ... " << endl;
595 cerr << "Constructing cube ... " << endl << endl;
596 Cube largebsqTestCube;
597 // 2^28 x 2 x 1 cube -> 2^28 + 1 > 2^30 / (4*2^28), exceeds limit
598 int limitExceeded = (1 << 28) + 1;
599 largebsqTestCube.setDimensions(limitExceeded, 2, 1);
600 largebsqTestCube.setFormat(Cube::Bsq);
601 largebsqTestCube.create("$TMP/IsisCube_largebsq");
602 Report(largebsqTestCube);
603
604 cerr << endl;
605 largebsqTestCube.close();
606
607
608 // Test bsq cube that has a linecount > maximum chunk line size to test CubeBsqHandler
609 cerr << "Testing creating BSQ cube where size of sample pixels exceeds cube's lineCount ... "
610 << endl;
611 cerr << "Constructing cube ... " << endl << endl;
612 Cube bsqTestCube;
613 // maxLineSize = 2^30 / (4 * 15000) = 17895 < 18000
614 bsqTestCube.setDimensions(15000, 18000, 1);
615 bsqTestCube.setFormat(Cube::Bsq);
616 bsqTestCube.create("$TMP/IsisCube_bsq");
617 Report(bsqTestCube);
618
619 cerr << endl;
620 bsqTestCube.close();
621
622
623 // Check errors
624 cerr << "Testing errors ... " << endl;
625 try {
626 in.open("blah");
627 }
628 catch (IException &e) {
629 e.print();
630 }
631
632 try {
633 in.create("blah");
634 }
635 catch (IException &e) {
636 e.print();
637 }
638
639 try {
640 in.write(inLine3);
641 }
642 catch (IException &e) {
643 e.print();
644 }
645
646 try {
647 Cube in;
648 in.open("blah");
649 }
650 catch (IException &e) {
651 e.print();
652 }
653
654 try {
655 in.physicalBand(2);
656 }
657 catch (IException &e) {
658 e.print();
659 }
660
661 try {
662 in.physicalBand(0);
663 }
664 catch (IException &e) {
665 e.print();
666 }
667
668 try {
669 Cube in;
670 in.read(inLine3);
671 }
672 catch (IException &e) {
673 e.print();
674 }
675
676 try {
677 Cube in;
678 in.write(inLine3);
679 }
680 catch (IException &e) {
681 e.print();
682 }
683
684 try {
685 Cube out;
686 out.create("$TMP/IsisCube_04");
687 out.close();
688 }
689 catch (IException &e) {
690 e.print();
691 }
692
693 try {
694 Cube out;
695 out.setLabelSize(15);
696 out.setDimensions(1, 1, 1);
697 out.create("$TMP/IsisCube_04");
698 out.close();
699 }
700 catch (IException &e) {
701 e.print();
702 }
703
704 try {
705 Cube out;
706 out.setDimensions(1000000, 1000000, 9);
707 out.create("$TMP/IsisCube_05");
708 out.close();
709 }
710 catch (IException &e) {
711 e.print();
712 }
713 try {
714 Cube in;
715 in.open("$TMP/IsisCube_01", "a");
716 }
717 catch (IException &e) {
718 e.print();
719 }
720 try {
721 Cube in;
722 in.setDimensions(0, 0, 0);
723 }
724 catch (IException &e) {
725 e.print();
726 }
727 try {
728 Cube in;
729 in.setDimensions(1, 0, 0);
730 }
731 catch (IException &e) {
732 e.print();
733 }
734 try {
735 Cube in;
736 in.setDimensions(1, 1, 0);
737 }
738 catch (IException &e) {
739 e.print();
740 }
741
742 Cube in4;
743 try {
744 in4.open("$ISISTESTDATA/isis/src/base/unitTestData/$TMP/isisTruth.cub");
745 }
746 catch (IException &e) {
747 e.print();
748 }
749
750 try {
751 in4.reopen("rw");
752 }
753 catch (IException &e) {
754 QString error = e.toString();
755 error = error.replace(QRegExp("\\[[^\\]]*\\]"), "[...]");
756 cerr << error.toStdString() << endl;
757 }
758
759 in4.setPixelType(None);
760 try {
761 in4.setDimensions(1, 1, 1);
762 in4.create("shouldntExist.cub");
763 }
764 catch (IException &e) {
765 e.print();
766 }
767 try {
768 Cube externalData;
769 externalData.setDimensions(1024, 1024, 1);
770 externalData.create("$TMP/IsisCube_06");
771 externalData.reopen("r");
772 externalData.putGroup(PvlGroup("TestGroup2"));
773 }
774 catch (IException &e) {
775 e.print();
776 }
777 }
778 catch (IException &e) {
779 e.print();
780 }
781
782 cerr << endl << "Test creating an ecub" << endl;
783 {
784 Cube externalData;
785 externalData.setExternalDnData("$ISISTESTDATA/isis/src/base/unitTestData/$TMP/isisTruth.cub");
786 externalData.create("$TMP/isisTruth_external.ecub");
787 externalData.putGroup(PvlGroup("TestGroup"));
788 cerr << *externalData.label() << endl;
789
790 Brick readBrick(3, 3, 2, externalData.pixelType());
791 readBrick.SetBasePosition(1, 1, 1);
792 externalData.read(readBrick);
793 for (int index = 0; index < readBrick.size(); index++) {
794 if (readBrick[index] == Null) {
795 cerr << "N ";
796 }
797 else {
798 cerr << readBrick[index] << " ";
799 }
800 }
801 cerr << endl;
802
803 try {
804 externalData.write(readBrick);
805 }
806 catch (IException &e) {
807 e.print();
808 }
809 }
810
811 cerr << endl << "Test creating an ecub from an ecub" << endl;
812 {
813 Cube externalData;
814 externalData.setExternalDnData("$TMP/isisTruth_external.ecub");
815 externalData.create("$TMP/isisTruth_external2.ecub");
816 cerr << *externalData.label() << endl;
817
818 Brick readBrick(3, 3, 2, externalData.pixelType());
819 readBrick.SetBasePosition(1, 1, 1);
820 externalData.read(readBrick);
821 for (int index = 0; index < readBrick.size(); index++) {
822 if (readBrick[index] == Null) {
823 cerr << "N ";
824 }
825 else {
826 cerr << readBrick[index] << " ";
827 }
828 }
829 cerr << endl;
830
831 try {
832 externalData.write(readBrick);
833 }
834 catch (IException &e) {
835 e.print();
836 }
837 }
838
839 cerr << endl << "Test reading an ecub" << endl;
840 {
841 Cube externalData;
842 externalData.open("$TMP/isisTruth_external", "rw");
843 externalData.putGroup(PvlGroup("TestGroup2"));
844 externalData.reopen("r");
845 cerr << *externalData.label() << endl;
846
847 Brick readBrick(3, 3, 2, externalData.pixelType());
848 readBrick.SetBasePosition(1, 1, 1);
849 externalData.read(readBrick);
850 for (int index = 0; index < readBrick.size(); index++) {
851 if (readBrick[index] == Null) {
852 cerr << "N ";
853 }
854 else {
855 cerr << readBrick[index] << " ";
856 }
857 }
858 cerr << endl;
859
860 try {
861 externalData.write(readBrick);
862 }
863 catch (IException &e) {
864 e.print();
865 }
866 }
867
868 cerr << endl << "Test reading an ecub that points to another ecub" << endl;
869 {
870 Cube externalData;
871 externalData.open("$TMP/isisTruth_external2");
872 cerr << *externalData.label() << endl;
873
874 Brick readBrick(3, 3, 2, externalData.pixelType());
875 readBrick.SetBasePosition(1, 1, 1);
876 externalData.read(readBrick);
877 for (int index = 0; index < readBrick.size(); index++) {
878 if (readBrick[index] == Null) {
879 cerr << "N ";
880 }
881 else {
882 cerr << readBrick[index] << " ";
883 }
884 }
885 cerr << endl;
886
887 try {
888 externalData.write(readBrick);
889 }
890 catch (IException &e) {
891 e.print();
892 }
893 }
894
895//cerr << endl << "Test reading an ecub that points to detached lbl" << endl;
896//{
897// Cube externalData;
898// externalData.setExternalDnData("$TMP/IsisCube_02.lbl");
899// externalData.create("$TMP/isisTruth_external3.ecub");
900// cerr << *externalData.label() << endl;
901//
902// Brick readBrick(3, 3, 2, externalData.pixelType());
903// readBrick.SetBasePosition(1, 1, 1);
904// externalData.read(readBrick);
905// for (int index = 0; index < readBrick.size(); index++) {
906// if (readBrick[index] == Null) {
907// cerr << "N ";
908// }
909// else {
910// cerr << readBrick[index] << " ";
911// }
912// }
913// cerr << endl;
914//
915// try {
916// externalData.write(readBrick);
917// }
918// catch (IException &e) {
919// e.print();
920// }
921//}
922//
923//cerr << endl << "Test copying an ecub that points to detached lbl" << endl;
924//{
925// Cube externalData;
926// externalData.open("$TMP/isisTruth_external3.ecub");
927// Cube *copiedCube = externalData.copy("$TMP/isisTruth_external3.copy.ecub",
928// CubeAttributeOutput("+External"));
929// cerr << *copiedCube->label() << endl;
930//
931// Brick readBrick(3, 3, 2, copiedCube->pixelType());
932// readBrick.SetBasePosition(1, 1, 1);
933// copiedCube->read(readBrick);
934// for (int index = 0; index < readBrick.size(); index++) {
935// if (readBrick[index] == Null) {
936// cerr << "N ";
937// }
938// else {
939// cerr << readBrick[index] << " ";
940// }
941// }
942// cerr << endl;
943//
944// try {
945// copiedCube->write(readBrick);
946// }
947// catch (IException &e) {
948// e.print();
949// }
950// // need to deallocate our copied cube
951// copiedCube->close();
952// delete copiedCube;
953// copiedCube = NULL;
954//
955//}
956
957 remove("$TMP/IsisCube_00.cub");
958 remove("$TMP/IsisCube_01.cub");
959 remove("$TMP/IsisCube_02.cub");
960 remove("$TMP/IsisCube_02.lbl");
961 remove("$TMP/IsisCube_03.cub");
962 remove("$TMP/IsisCube_04.cub");
963 remove("$TMP/IsisCube_05.cub");
964 remove("$TMP/IsisCube_06.cub");
965 remove("$TMP/IsisCube_boundary.cub");
966 remove("$TMP/IsisCube_bsq.cub");
967 remove("$TMP/IsisCube_bsqOneLine.cub");
968 remove("$TMP/IsisCube_largebsq.cub");
969 remove("$TMP/isisTruth_external.ecub");
970 remove("$TMP/isisTruth_external2.ecub");
971 // remove("$TMP/isisTruth_external3.ecub");
972 // remove("$TMP/isisTruth_external3.copy.ecub");
973
974 return 0;
975}
976
977
978void Report(Cube &c) {
979 cerr << "File = " << IString(QFileInfo(c.fileName()).fileName()) << endl;
980 cerr << "Samps = " << c.sampleCount() << endl;
981 cerr << "Lines = " << c.lineCount() << endl;
982 cerr << "Bands = " << c.bandCount() << endl;
983 cerr << "Base = " << c.base() << endl;
984 cerr << "Mult = " << c.multiplier() << endl;
985 cerr << "Type = " << c.pixelType() << endl;
986// cerr << "Order = " << c.ByteOrder() << endl; // Needs to be system independent
987 cerr << "Atchd = " << c.labelsAttached() << endl;
988 cerr << "Format = " << c.format() << endl;
989 cerr << "Open = " << c.isOpen() << endl;
990 try {
991 cerr << "R/O = ";
992 cerr.flush();
993 cerr << c.isReadOnly();
994 }
995 catch (IException &e) {
996 cerr << "N/A";
997 }
998
999 cerr << endl;
1000
1001 try {
1002 cerr << "R/W = ";
1003 cerr.flush();
1004 cerr << c.isReadWrite();
1005 }
1006 catch (IException &e) {
1007 cerr << "N/A";
1008 }
1009
1010 cerr << endl;
1011 cerr << "Lbytes = " << c.labelSize() << endl;
1012 cerr << endl;
1013}
Buffer for containing a three dimensional section of an image.
Definition Brick.h:45
Manipulate and parse attributes of output cube filenames.
IO Handler for Isis Cubes.
Definition Cube.h:168
void clearIoCache()
This will clear excess RAM used for quicker IO in the cube.
Definition Cube.cpp:1971
void setPixelType(PixelType pixelType)
Used prior to the Create method, this will specify the output pixel type.
Definition Cube.cpp:1317
void setFormat(Format format)
Used prior to the Create method, this will specify the format of the cube, either band,...
Definition Cube.cpp:1279
Format format() const
Definition Cube.cpp:1608
virtual Histogram * histogram(const int &band=1, QString msg="Gathering histogram")
This method returns a pointer to a Histogram object which allows the program to obtain and use variou...
Definition Cube.cpp:1632
int lineCount() const
Definition Cube.cpp:1767
double multiplier() const
Returns the multiplier value for converting 8-bit/16-bit pixels to 32-bit.
Definition Cube.cpp:1781
void setLabelsAttached(bool attached)
Use prior to calling create, this sets whether or not to use separate label and data files.
Definition Cube.cpp:1291
Statistics * statistics(const int &band=1, QString msg="Gathering statistics")
This method returns a pointer to a Statistics object which allows the program to obtain and use vario...
Definition Cube.cpp:1863
void setDimensions(int ns, int nl, int nb)
Used prior to the Create method to specify the size of the cube.
Definition Cube.cpp:1230
int sampleCount() const
Definition Cube.cpp:1840
void putGroup(const PvlGroup &group)
Adds a group in a Label to the cube.
Definition Cube.cpp:2089
bool isOpen() const
Test if a cube file has been opened/created.
Definition Cube.cpp:189
void setBaseMultiplier(double base, double mult)
Used prior to the Create method, this will specify the base and multiplier for converting 8-bit/16-bi...
Definition Cube.cpp:1164
bool isReadOnly() const
Test if the opened cube is read-only, that is write operations will fail if this is true.
Definition Cube.cpp:215
double base() const
Returns the base value for converting 8-bit/16-bit pixels to 32-bit.
Definition Cube.cpp:1440
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
Definition Cube.cpp:278
void create(const QString &cfile)
This method will create an isis cube for writing.
Definition Cube.cpp:416
bool labelsAttached() const
Test if labels are attached.
Definition Cube.cpp:250
void open(const QString &cfile, QString access="r")
This method will open an existing isis cube for reading or reading/writing.
Definition Cube.cpp:629
PixelType pixelType() const
Definition Cube.cpp:1791
void setVirtualBands(const QList< QString > &vbands)
This allows the programmer to specify a subset of bands to work with.
Definition Cube.cpp:1334
void read(Blob &blob, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
This method will read data from the specified Blob object.
Definition Cube.cpp:820
@ Bsq
Cubes are stored in band-sequential format, that is the order of the pixels in the file (on disk) is:
Definition Cube.h:200
virtual int physicalBand(const int &virtualBand) const
This method will return the physical band number given a virtual band number.
Definition Cube.cpp:1806
void setLabelSize(int labelBytes)
Used prior to the Create method, this will allocate a specific number of bytes in the label area for ...
Definition Cube.cpp:1304
virtual QString fileName() const
Returns the opened cube's filename.
Definition Cube.cpp:1596
void write(Blob &blob, bool overwrite=true)
This method will write a blob of data (e.g.
Definition Cube.cpp:984
bool isReadWrite() const
Test if the opened cube is read-write, that is read and write operations should succeed if this is tr...
Definition Cube.cpp:237
void setExternalDnData(FileName cubeFileWithDnData)
Used to set external dn data to cube.
Definition Cube.cpp:1247
void close(bool remove=false)
Closes the cube and updates the labels.
Definition Cube.cpp:262
int labelSize(bool actual=false) const
Returns the number of bytes used by the label.
Definition Cube.cpp:1746
virtual int bandCount() const
Returns the number of virtual bands for the cube.
Definition Cube.cpp:1423
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition Cube.cpp:1734
void reopen(QString access="r")
This method will reopen an isis sube for reading or reading/writing.
Definition Cube.cpp:787
void setByteOrder(ByteOrder byteOrder)
Used prior to the Create method, this will specify the byte order of pixels, either least or most sig...
Definition Cube.cpp:1215
Container of a cube histogram.
Definition Histogram.h:74
double Mode() const
Returns the mode.
Isis exception class.
Definition IException.h:91
QString toString() const
Returns a string representation of this exception.
void print() const
Prints a string representation of this exception to stderr.
Adds specific functionality to C++ strings.
Definition IString.h:165
Buffer manager, for moving through a cube in lines.
Definition LineManager.h:39
Contains multiple PvlContainers.
Definition PvlGroup.h:41
This class is used to accumulate statistics on double arrays.
Definition Statistics.h:93
BigInt NullPixels() const
Returns the total number of NULL pixels encountered.
double Average() const
Computes and returns the average.
BigInt TotalPixels() const
Returns the total number of pixels processed (valid and invalid).
double StandardDeviation() const
Computes and returns the standard deviation.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
const double Null
Value for an Isis Null pixel.
Namespace for the standard library.