-
Notifications
You must be signed in to change notification settings - Fork 0
/
highpass.cpp
305 lines (245 loc) · 8.96 KB
/
highpass.cpp
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
* The information in this file is
* Copyright(c) 2007 Ball Aerospace & Technologies Corporation
* and is subject to the terms and conditions of the
* GNU Lesser General Public License Version 2.1
* The license text is available from
* http://www.gnu.org/licenses/lgpl.html
*/
#include "DataAccessor.h"
#include "DataAccessorImpl.h"
#include "DataRequest.h"
#include "DesktopServices.h"
#include "MessageLogResource.h"
#include "ObjectResource.h"
#include "PlugInArgList.h"
#include "PlugInManagerServices.h"
#include "PlugInRegistration.h"
#include "Progress.h"
#include "RasterDataDescriptor.h"
#include "RasterElement.h"
#include "RasterUtilities.h"
#include "SpatialDataView.h"
#include "SpatialDataWindow.h"
#include "switchOnEncoding.h"
#include "HIGHPASS.h"
#include <limits>
#include <string>
using namespace std;
REGISTER_PLUGIN_BASIC(OpticksTutorial, HIGHPASS);
namespace
{
template<typename T>
void conversion(T* pData, double number)
{
*pData=number;
}
};
double edgeDetection7(DataAccessor pSrcAcc, int row, int col, int rowSize, int colSize)
{
int prevCol = std::max(col - 1, 0);
int prevRow = std::max(row - 1, 0);
int nextCol = std::min(col + 1, colSize - 1);
int nextRow = std::min(row + 1, rowSize - 1);
int prevCol1 = std::max(col-2,0);
int prevRow1= std::max(row-2,0);
int nextCol1= std::min(col+2,colSize-1);
int nextRow1= std::min(row+2,rowSize-1);
pSrcAcc->toPixel(prevRow1, prevCol1);
int row1col1 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow1, prevCol);
int row1col2 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow1, col);
int row1col3 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow1, nextCol);
int row1col4 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow1, nextCol1);
int row1col5 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow, prevCol1);
int row2col1 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow, prevCol);
int row2col2 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow, col);
int row2col3 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow, nextCol);
int row2col4 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(prevRow, nextCol1);
int row2col5 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(row, prevCol1);
int row3col1 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(row, prevCol);
int row3col2 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(row, col);
int row3col3 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(row, nextCol);
int row3col4 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(row, nextCol1);
int row3col5 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow, prevCol1);
int row4col1 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow, prevCol);
int row4col2 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow, col);
int row4col3 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow, nextCol);
int row4col4 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow, nextCol1);
int row4col5 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow1, prevCol1);
int row5col1 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow1, prevCol);
int row5col2 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow1, col);
int row5col3 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow1, nextCol);
int row5col4 = pSrcAcc->getColumnAsInteger();
pSrcAcc->toPixel(nextRow1, nextCol1);
int row5col5 = pSrcAcc->getColumnAsInteger();
int g = row1col1 + row1col2 + row1col3 + row1col4 + row1col5 + row2col1 + row2col2 + row2col3 + row2col4
+ row2col5 + row3col1 + row3col2 + 24*row3col3 + row3col4 + row3col5 + row4col1 + row4col2 + row4col3
+ row4col4 + row4col5 + row5col1 + row5col2 + row5col3 + row5col4 + row5col5;
double value = g/159.0;
return value;
};
HIGHPASS::HIGHPASS()
{
setDescriptorId("{489C28A1-2261-4D41-AB7B-DACBFA61B0EC}");
setName("HIGHPASS");
setVersion("Sample");
setDescription("Calculate and return an edge detection raster element for first band "
"of the provided raster element.");
setCreator("Opticks Community");
setCopyright("Copyright (C) 2008, Ball Aerospace & Technologies Corp.");
setProductionStatus(false);
setType("Sample");
setSubtype("Edge Detection");
setMenuLocation("[Tutorial]/HIGHPASS");
setAbortSupported(true);
}
HIGHPASS::~HIGHPASS()
{
}
bool HIGHPASS::getInputSpecification(PlugInArgList*& pInArgList)
{
VERIFY(pInArgList = Service<PlugInManagerServices>()->getPlugInArgList());
pInArgList->addArg<Progress>(Executable::ProgressArg(), NULL, "Progress reporter");
pInArgList->addArg<RasterElement>(Executable::DataElementArg(), "Denoise detection of image");
return true;
}
bool HIGHPASS::getOutputSpecification(PlugInArgList*& pOutArgList)
{
VERIFY(pOutArgList = Service<PlugInManagerServices>()->getPlugInArgList());
pOutArgList->addArg<RasterElement>("Result", NULL);
return true;
}
bool HIGHPASS::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
StepResource pStep("Tutorial 5", "app", "219F1882-A59F-4835-BE2A-E83C0C8111EB");
if (pInArgList == NULL || pOutArgList == NULL)
{
return false;
}
Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg());
RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg());
if (pCube == NULL)
{
std::string msg = "A raster cube must be specified.";
pStep->finalize(Message::Failure, msg);
if (pProgress != NULL)
{
pProgress->updateProgress(msg, 0, ERRORS);
}
return false;
}
RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor());
VERIFY(pDesc != NULL);
FactoryResource<DataRequest> pRequest;
pRequest->setInterleaveFormat(BSQ);
DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release());
ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() +
"DResult", pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType()));
if (pResultCube.get() == NULL)
{
std::string msg = "A raster cube could not be created.";
pStep->finalize(Message::Failure, msg);
if (pProgress != NULL)
{
pProgress->updateProgress(msg, 0, ERRORS);
}
return false;
}
FactoryResource<DataRequest> pResultRequest;
pResultRequest->setWritable(true);
DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release());
int rowSize= pDesc->getRowCount();
int colSize = pDesc->getColumnCount();
int zero=0;
int prevCol = 0;
int prevRow = 0;
int nextCol = 0;
int nextRow = 0;
int prevCol1 = 0;
int prevRow1= 0;
int nextCol1= 0;
int nextRow1= 0;
for (unsigned int row = 0; row < pDesc->getRowCount(); ++row)
{
if (pProgress != NULL)
{
pProgress->updateProgress("Calculating result", row * 100 / pDesc->getRowCount(), NORMAL);
}
if (isAborted())
{
std::string msg = getName() + " has been aborted.";
pStep->finalize(Message::Abort, msg);
if (pProgress != NULL)
{
pProgress->updateProgress(msg, 0, ABORT);
}
return false;
}
if (!pDestAcc.isValid())
{
std::string msg = "Unable to access the cube data.";
pStep->finalize(Message::Failure, msg);
if (pProgress != NULL)
{
pProgress->updateProgress(msg, 0, ERRORS);
}
return false;
}
for (unsigned int col = 0; col < pDesc->getColumnCount(); ++col)
{
double value=edgeDetection7(pSrcAcc, row, col, pDesc->getRowCount(), pDesc->getColumnCount());
switchOnEncoding(pDesc->getDataType(), conversion, pDestAcc->getColumn(), value);
pDestAcc->nextColumn();
}
pDestAcc->nextRow();
}
if (!isBatch())
{
Service<DesktopServices> pDesktop;
SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(),
SPATIAL_DATA_WINDOW));
SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView();
if (pView == NULL)
{
std::string msg = "Unable to create view.";
pStep->finalize(Message::Failure, msg);
if (pProgress != NULL)
{
pProgress->updateProgress(msg, 0, ERRORS);
}
return false;
}
pView->setPrimaryRasterElement(pResultCube.get());
pView->createLayer(RASTER, pResultCube.get());
}
if (pProgress != NULL)
{
pProgress->updateProgress("HighPass is compete.", 100, NORMAL);
}
pOutArgList->setPlugInArgValue("Result", pResultCube.release());
pStep->finalize();
return true;
}