-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaskFunctions.cpp
More file actions
190 lines (164 loc) · 5.84 KB
/
Copy pathMaskFunctions.cpp
File metadata and controls
190 lines (164 loc) · 5.84 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* Copyright (C) 2010 Ion Torrent Systems, Inc. All Rights Reserved */
#include "MaskFunctions.h"
//@TODO: Please do not use inline #ifdefs to rewrite code
// this should only be done >at the function level< to maintain readability.
// if you believe the function is too long to do this, >then rewrite the function to be shorter or more than one piece<.
//Uncomment next line to revert to old exclusion mask file usage. Remove once it is passed.
#define OLDWAY
#ifdef OLDWAY
void SetExcludeMask (SpatialContext &loc_context, Mask *maskPtr, char *chipType, int rows, int cols)
{
bool applyExclusionMask = true;
/*
* Determine if this is a cropped dataset
* 3 types:
* wholechip image dataset - rows,cols should be == to chip_len_x,chip_len_y
* cropped image dataset - above test is false AND chip_offset_x == -1
* blocked image dataset - above test is false AND chip_offset_x != -1
*/
if ( (rows == loc_context.chip_len_y) && (cols == loc_context.chip_len_x))
{
//This is a wholechip dataset
applyExclusionMask = true;
fprintf (stderr, "This is a wholechip dataset so the exclusion mask will be applied Chip %s\n",chipType);
}
else
{
if (loc_context.chip_offset_x == -1)
{
applyExclusionMask = false;
fprintf (stderr, "This is a cropped dataset so the exclusion mask will not be applied\n");
fprintf (stderr, "rows=%d, chip_rows=%d,cols=%d, chip_cols=%d for chip %s\n",rows, loc_context.chip_len_y,cols, loc_context.chip_len_x, chipType);
}
else
{
applyExclusionMask = false;
fprintf (stderr, "This is a block dataset so the exclusion mask will not be applied\n");
}
}
/*
* If we get a cropped region definition from the command line, we want the whole chip to be MaskExclude
* except for the defined crop region(s) which are marked MaskEmpty. If no cropRegion defined on command line,
* then we proceed with marking the entire chip MaskEmpty
*/
if (loc_context.numCropRegions == 0)
{
maskPtr->Init (cols, rows, MaskEmpty);
}
else
{
maskPtr->Init (cols, rows, MaskExclude);
// apply one or more cropRegions, mark them MaskEmpty
for (int q = 0; q < loc_context.numCropRegions; q++)
{
maskPtr->MarkRegion (loc_context.cropRegions[q], MaskEmpty);
}
}
/*
* Apply exclude mask from file
*/
loc_context.exclusionMaskSet = false;
if (chipType && applyExclusionMask)
{
char *exclusionMaskFileName = NULL;
char filename[64] = { 0 };
sprintf (filename, "exclusionMask_%s.bin", chipType);
exclusionMaskFileName = GetIonConfigFile (filename);
fprintf (stderr, "Exclusion Mask File = '%s'\n", exclusionMaskFileName);
if (exclusionMaskFileName)
{
loc_context.exclusionMaskSet = true;
Mask excludeMask (1, 1);
excludeMask.SetMask (exclusionMaskFileName);
free (exclusionMaskFileName);
//--- Mark beadfind masks with MaskExclude bits from exclusionMaskFile
maskPtr->SetThese (&excludeMask, MaskExclude);
}
else
{
fprintf (stderr, "WARNING: Exclusion Mask %s not applied\n", filename);
}
}
}
#else
void SetExcludeMask (SpatialContext &loc_context, Mask *maskPtr, char *chipType, int rows, int cols)
{
bool applyExclusionMask = true;
/*
* Determine if this is a cropped dataset
* 3 types:
* wholechip image dataset - rows,cols should be == to chip_len_x,chip_len_y
* cropped image dataset - above test is false AND chip_offset_x == -1
* blocked image dataset - above test is false AND chip_offset_x != -1
*/
if ( (rows == loc_context.chip_len_y) && (cols == loc_context.chip_len_x))
{
//This is a wholechip dataset
applyExclusionMask = true;
fprintf (stderr, "This is a wholechip dataset so the exclusion mask will be applied\n");
}
else
{
if (loc_context.chip_offset_x == -1)
{
applyExclusionMask = false;
fprintf (stderr, "This is a cropped dataset so the exclusion mask will not be applied\n");
}
else
{
applyExclusionMask = true;
fprintf (stderr, "This is a block dataset so the exclusion mask will be applied\n");
}
}
/*
* If we get a cropped region definition from the command line, we want the whole chip to be MaskExclude
* except for the defined crop region(s) which are marked MaskEmpty. If no cropRegion defined on command line,
* then we proceed with marking the entire chip MaskEmpty
*/
if (loc_context.numCropRegions == 0)
{
maskPtr->Init (cols, rows, MaskEmpty);
}
else
{
maskPtr->Init (cols, rows, MaskExclude);
// apply one or more cropRegions, mark them MaskEmpty
for (int q = 0; q < loc_context.numCropRegions; q++)
{
maskPtr->MarkRegion (loc_context.cropRegions[q], MaskEmpty);
}
}
/*
* Apply exclude mask from file
*/
loc_context.exclusionMaskSet = false;
if (chipType && applyExclusionMask)
{
char *exclusionMaskFileName = NULL;
char filename[64] = { 0 };
sprintf (filename, "excludeMask_%s", chipType);
exclusionMaskFileName = GetIonConfigFile (filename);
fprintf (stderr, "Exclusion Mask File = '%s'\n", exclusionMaskFileName);
if (exclusionMaskFileName)
{
loc_context.exclusionMaskSet = true;
FILE *excludeFile = NULL;
excludeFile = fopen (exclusionMaskFileName,"rb");
assert (excludeFile != NULL);
uint16_t x = 0;
uint16_t y = 0;
while (1)
{
if (fread (&x, sizeof (x), 1, excludeFile) != 1) break;
if (fread (&y, sizeof (y), 1, excludeFile) != 1) break;
//fprintf (stderr, "Excluding %d %d (%d %d)\n",x,y,(int) x - chip_offset_x,(int) y - chip_offset_y);
maskPtr->Set ( (int) x - loc_context.chip_offset_x, (int) y - loc_context.chip_offset_y,MaskExclude);
}
}
else
{
fprintf (stderr, "WARNING: Exclusion Mask %s not applied\n", filename);
}
}
}
#endif