forked from atsommer/Simplicio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageData.cpp
More file actions
123 lines (113 loc) · 3.16 KB
/
Copy pathImageData.cpp
File metadata and controls
123 lines (113 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "stdafx.h"
#include "ImageData.h"
namespace forms2{
void ImageData::init(UInt16* b, int r, int c, int l, bool d, bool sf, DateTime datetime){
//copies b to imageBuffer
rows = r; cols = c; layers = l; singleFrame=sf;
dateTime = datetime;
dbl = d ? 2 : 1;
length = dbl*r*c*l;
imageBuffer = gcnew array<UInt16>(length);
for (int i=0; i<length;i++)
imageBuffer[i] = b[i];
saved = false;
seqVars = gcnew LinkedList<Variable^>();
}
UInt16 ImageData::getValue(int i){
return imageBuffer[i];
}
UInt16 ImageData::getValue(int r,int c,int l,int frame){
if (dbl==1 && frame!=0)
return 0;
else if (frame !=0 && frame !=1)
return 0;
int i = c + (r+frame*rows)*cols + l*dbl*rows*cols;
return getValue(i);
}
UInt16 ImageData::getMaxValue(int layer, int frame){
UInt16 max = 0;
UInt16 v;
for(int r=0;r<rows;r++)
for(int c=0;c<cols;c++){
v = getValue(r,c,layer,frame);
if (v > max)
max = v;
}
return max;
}
UInt16 ImageData::getMaxValue(int layer){
int max0 = getMaxValue(layer,0);
int max = max0;
if (dbl==2){
int max1 = getMaxValue(layer,1);
if (max1>max0)
max = max1;
}
return max;
}
String^ ImageData::getDateTimeString(){
DateTime dt = dateTime;
return String::Format("{0:d4}-{1:d2}-{2:d2}-{3:d2};{4:d2};{5:d2}",dt.Year,dt.Month,dt.Day,dt.Hour,dt.Minute,dt.Second);
}
void ImageData::saveFile(String^ filePath)
{ //saves a 16-bit AIA file in little endian
String^ extension =".aia";
String^ basename = String::Format("{0}\\{1}",filePath,getDateTimeString());
String^ filename = String::Copy(basename);
//prevent overwrite by renaming
for (int i=0; (i<1000) && File::Exists(String::Concat(filename,extension));i++){
filename =String::Format("{0} Copy {1}",basename,i);
}
filename = String::Concat(filename,extension);
//if (File::Exists(filename)) return;
FileStream^ fs = File::Open(filename,FileMode::Create);
BinaryWriter^ bw = gcnew BinaryWriter(fs);
try{
Byte b0 = 0x41;
Byte b1 = 0x49;
Byte b2 = 0x41;
bw->Write(b0);
bw->Write(b1);
bw->Write(b2);
UInt16 intLength = 2;
bw->Write(intLength);
int rows2 = (getRows())*(getDoubler());
//int cols = getCols();
//int layers = getLayers();
bw->Write((UInt16)rows2);
bw->Write((UInt16)cols);
int templayers=layers;
if (singleFrame)
templayers=3;
bw->Write((UInt16)templayers);
//write data
//for (int i=0;i<rows2*cols*layers;i++)
// bw->Write(getValue(i));
for (int l(0); l<layers; l++)
if (!(singleFrame && (l==0 || l > 3)))
for (int r(0);r<rows2;r++)
for (int c(0);c<cols;c++)
bw->Write(getValue(r,c,l,0));
//save sequence variables:
for each(Variable^ var in seqVars){
bw->Write(var->VariableName->ToCharArray());
bw->Write((Byte)0);
bw->Write((Double)var->VariableValue);
}
saved=true;
}
finally{
bw->Close();
fs->Close();
}
}
void ImageData::setSeqVars(LinkedList<Variable^>^ vars){
seqVars->Clear();
for each(Variable^ var in vars){
Variable^ newvar = gcnew Variable();
newvar->VariableValue = var->VariableValue;
newvar->VariableName = var->VariableName;
seqVars->AddLast(newvar);
}
}
}