1 #include "ForwardMappingNearestNeighbour.hh"
2 #include <Base/Common/BIASpragma.hh>
8 template <
class InputStorageType,
class OutputStorageType>
12 fillAreaWindowSize_=5;
15 template <
class InputStorageType,
class OutputStorageType>
21 template <
class InputStorageType,
class OutputStorageType>
27 template <
class InputStorageType,
class OutputStorageType>
43 template <
class InputStorageType,
class OutputStorageType>
47 bool withTex_= (texin == NULL) ?
false :
true;
52 out.
Init(dTargetWidth_, dTargetHeight_);
55 intermediate_.FillImageWithConstValue((OutputStorageType)0);
59 const InputStorageType** idaTexIn_ = NULL;
60 OutputStorageType** idaTexOut_ = NULL;
61 OutputStorageType** idaIntermediate_=intermediate_.GetImageDataArray();
62 OutputStorageType** idaIntermediateTex_=intermediateTex_.GetImageDataArray();
66 texout.
Init(dTargetWidth_, dTargetHeight_, dTexChannels_);
69 intermediateTex_.FillImageWithConstValue((OutputStorageType)0);
73 int cornerpos[8] = { ulx_,uly_, lrx_,uly_, ulx_,lry_, lrx_,lry_ };
75 for (
int i=0;i<4;i++) {
77 p2d[0]=cornerpos[2*i];
78 p2d[1]=cornerpos[2*i+1];
80 float fDepth = idaSource_[ cornerpos[2*i+1] ][ cornerpos[2*i] ];
84 if (SinkP_.DoesPointProjectIntoImage(p3d, p2d)) {
93 if (p2d[0] >= dTargetWidth_)
94 p2d[0] = dTargetWidth_ -1;
97 if (p2d[1] >= dTargetHeight_)
98 p2d[1] = dTargetHeight_ -1;
105 boundMin_[0]=dTargetWidth_; boundMin_[1]=dTargetHeight_; boundMin_[2] = 1;
106 boundMax_[0]=0; boundMax_[1]=0; boundMax_[2] = 1;
107 for (
unsigned int j=0;j<2;j++) {
108 for (
unsigned int i=0;i<4;i++) {
109 if (corners[i][j] < boundMin_[j]) {
110 boundMin_[j] = corners[i][j];
112 if (corners[i][j]> boundMax_[j]) {
113 boundMax_[j] = corners[i][j];
130 bool wrapAround =
false;
133 if(boundMax_[1] > boundMin_[1] &&
134 boundMax_[1]-dTargetHeight_/2 > boundMin_[1]){
135 cout<<
"wrap around detected!"<<endl;
138 boundMinWrap_[0] = boundMin_[0];
139 boundMaxWrap_[0] = boundMax_[0];
140 boundMin_[0] = boundMin_[0];
141 boundMax_[0] = boundMax_[0];
144 boundMinWrap_[1] = boundMax_[1];
145 boundMaxWrap_[1] = dTargetHeight_-2;
147 boundMax_[1] = boundMin_[1];
159 for (
int y=uly_;y<lry_;y++) {
160 for (
int x=ulx_;x<lrx_;x++) {
164 depth_src = idaSource_[y][x];
165 if (depth_src > 500) {
167 if (SinkP_.DoesPointProjectIntoImage(point3d, point2d_dst)) {
170 int xdst = point2d_dst[0];
171 int ydst = point2d_dst[1];
172 idaIntermediate_[ydst][xdst] = depth_src;
174 for (
unsigned int i=0;i<dTexChannels_;i++)
175 idaIntermediateTex_[ydst][xdst*dTexChannels_+i] = idaTexIn_[y][x*dTexChannels_+i];
186 for (
unsigned int y=boundMin_[1]+fillAreaWindowSize_;
187 y<boundMax_[1]-fillAreaWindowSize_;y++) {
188 for (
unsigned int x=boundMin_[0]+fillAreaWindowSize_;
189 x<boundMax_[0]-fillAreaWindowSize_;x++) {
190 if (idaIntermediate_[y][x] == 0) {
191 for (
unsigned int mod=1;mod<fillAreaWindowSize_;mod++) {
192 if (idaIntermediate_[y][x+mod] != 0) {
193 idaTarget_[y][x] = idaIntermediate_[y][x+mod];
196 if (idaIntermediate_[y][x-mod] != 0) {
197 idaTarget_[y][x] = idaIntermediate_[y][x-mod];
200 if (idaIntermediate_[y+mod][x+mod] != 0) {
201 idaTarget_[y][x] = idaIntermediate_[y+mod][x+mod];
204 if (idaIntermediate_[y+mod][x] != 0) {
205 idaTarget_[y][x] = idaIntermediate_[y+mod][x];
208 if (idaIntermediate_[y+mod][x-mod] != 0) {
209 idaTarget_[y][x] = idaIntermediate_[y+mod][x-mod];
212 if (idaIntermediate_[y-mod][x+mod] != 0) {
213 idaTarget_[y][x] = idaIntermediate_[y-mod][x+mod];
216 if (idaIntermediate_[y-mod][x] != 0) {
217 idaTarget_[y][x] = idaIntermediate_[y-mod][x];
220 if (idaIntermediate_[y-mod][x-mod] != 0) {
221 idaTarget_[y][x] = idaIntermediate_[y-mod][x-mod];
226 idaTarget_[y][x] = idaIntermediate_[y][x];
233 for (
unsigned int y=boundMinWrap_[1]+fillAreaWindowSize_;
234 y<boundMaxWrap_[1]-fillAreaWindowSize_;y++) {
235 for (
unsigned int x=boundMinWrap_[0]+fillAreaWindowSize_;
236 x<boundMaxWrap_[0]-fillAreaWindowSize_;x++) {
237 if (idaIntermediate_[y][x] == 0) {
238 for (
unsigned int mod=1;mod<fillAreaWindowSize_;mod++) {
239 if (idaIntermediate_[y][x+mod] != 0) {
240 idaTarget_[y][x] = idaIntermediate_[y][x+mod];
243 if (idaIntermediate_[y][x-mod] != 0) {
244 idaTarget_[y][x] = idaIntermediate_[y][x-mod];
247 if (idaIntermediate_[y+mod][x+mod] != 0) {
248 idaTarget_[y][x] = idaIntermediate_[y+mod][x+mod];
251 if (idaIntermediate_[y+mod][x] != 0) {
252 idaTarget_[y][x] = idaIntermediate_[y+mod][x];
255 if (idaIntermediate_[y+mod][x-mod] != 0) {
256 idaTarget_[y][x] = idaIntermediate_[y+mod][x-mod];
259 if (idaIntermediate_[y-mod][x+mod] != 0) {
260 idaTarget_[y][x] = idaIntermediate_[y-mod][x+mod];
263 if (idaIntermediate_[y-mod][x] != 0) {
264 idaTarget_[y][x] = idaIntermediate_[y-mod][x];
267 if (idaIntermediate_[y-mod][x-mod] != 0) {
268 idaTarget_[y][x] = idaIntermediate_[y-mod][x-mod];
273 idaTarget_[y][x] = idaIntermediate_[y][x];
280 if (withTex_ && fillblack_) {
281 if (dTexChannels_ == 1) {
282 for (
unsigned int y=boundMin_[1]+fillAreaWindowSize_;
283 y<boundMax_[1]-fillAreaWindowSize_;y++) {
284 for (
unsigned int x=boundMin_[0]+fillAreaWindowSize_;
285 x<boundMax_[0]-fillAreaWindowSize_;x++) {
286 if (idaIntermediate_[y][x] == 0) {
287 for (
unsigned int mod=1;mod<fillAreaWindowSize_;mod++) {
288 if (idaIntermediateTex_[y][x+mod] != 0) {
289 idaTexOut_[y][x] = idaIntermediateTex_[y][x+mod];
292 if (idaIntermediateTex_[y][x-mod] != 0) {
293 idaTexOut_[y][x] = idaIntermediateTex_[y][x-mod];
296 if (idaIntermediateTex_[y+mod][x+mod] != 0) {
297 idaTexOut_[y][x] = idaIntermediateTex_[y+mod][x+mod];
300 if (idaIntermediateTex_[y+mod][x] != 0) {
301 idaTexOut_[y][x] = idaIntermediateTex_[y+mod][x];
304 if (idaIntermediateTex_[y+mod][x-mod] != 0) {
305 idaTexOut_[y][x] = idaIntermediateTex_[y+mod][x-mod];
308 if (idaIntermediateTex_[y-mod][x+mod] != 0) {
309 idaTexOut_[y][x] = idaIntermediateTex_[y-mod][x+mod];
312 if (idaIntermediateTex_[y-mod][x] != 0) {
313 idaTexOut_[y][x] = idaIntermediateTex_[y-mod][x];
316 if (idaIntermediateTex_[y-mod][x-mod] != 0) {
317 idaTexOut_[y][x] = idaIntermediateTex_[y-mod][x-mod];
322 idaTexOut_[y][x] = idaIntermediateTex_[y][x];
327 for (
unsigned int y=boundMin_[1]+fillAreaWindowSize_;
328 y<boundMax_[1]-fillAreaWindowSize_;y++) {
329 for (
unsigned int x=((
int)boundMin_[0]+fillAreaWindowSize_)*dTexChannels_;
330 x<((int)boundMax_[0]-fillAreaWindowSize_)*dTexChannels_;
332 unsigned int val = 0;
333 val = GetSummedValue_(&(idaIntermediateTex_[y][x]));
335 for (
unsigned int mod=1;mod<fillAreaWindowSize_;mod++) {
336 unsigned int xmod = mod * dTexChannels_;
337 if (GetSummedValue_(&(idaIntermediateTex_[y][x+xmod])) != 0) {
338 SetValue_(&(idaIntermediateTex_[y][x+xmod]), &(idaTexOut_[y][x]));
341 if (GetSummedValue_(&(idaIntermediateTex_[y][x-xmod])) != 0) {
342 SetValue_(&(idaIntermediateTex_[y][x-xmod]), &(idaTexOut_[y][x]));
345 if (GetSummedValue_(&(idaIntermediateTex_[y+mod][x+xmod])) != 0) {
346 SetValue_(&(idaIntermediateTex_[y+mod][x+xmod]), &(idaTexOut_[y][x]));
349 if (GetSummedValue_(&(idaIntermediateTex_[y+mod][x])) != 0) {
350 SetValue_(&(idaIntermediateTex_[y+mod][x]), &(idaTexOut_[y][x]));
353 if (GetSummedValue_(&(idaIntermediateTex_[y+mod][x-xmod])) != 0) {
354 SetValue_(&(idaIntermediateTex_[y+mod][x-xmod]), &(idaTexOut_[y][x]));
357 if (GetSummedValue_(&(idaIntermediateTex_[y-mod][x+xmod])) != 0) {
358 SetValue_(&(idaIntermediateTex_[y-mod][x+xmod]), &(idaTexOut_[y][x]));
361 if (GetSummedValue_(&(idaIntermediateTex_[y-mod][x])) != 0) {
362 SetValue_(&(idaIntermediateTex_[y-mod][x]), &(idaTexOut_[y][x]));
365 if (GetSummedValue_(&(idaIntermediateTex_[y-mod][x-xmod])) != 0) {
366 SetValue_(&(idaIntermediateTex_[y-mod][x-xmod]), &(idaTexOut_[y][x]));
371 SetValue_(&(idaIntermediateTex_[y][x]), &(idaTexOut_[y][x]));
379 if (dTexChannels_ == 1) {
380 for (
unsigned int y=boundMinWrap_[1]+fillAreaWindowSize_;
381 y<boundMaxWrap_[1]-fillAreaWindowSize_;y++) {
382 for (
unsigned int x=boundMinWrap_[0]+fillAreaWindowSize_;
383 x<boundMaxWrap_[0]-fillAreaWindowSize_;x++) {
384 if (idaIntermediate_[y][x] == 0) {
385 for (
unsigned int mod=1;mod<fillAreaWindowSize_;mod++) {
386 if (idaIntermediateTex_[y][x+mod] != 0) {
387 idaTexOut_[y][x] = idaIntermediateTex_[y][x+mod];
390 if (idaIntermediateTex_[y][x-mod] != 0) {
391 idaTexOut_[y][x] = idaIntermediateTex_[y][x-mod];
394 if (idaIntermediateTex_[y+mod][x+mod] != 0) {
395 idaTexOut_[y][x] = idaIntermediateTex_[y+mod][x+mod];
398 if (idaIntermediateTex_[y+mod][x] != 0) {
399 idaTexOut_[y][x] = idaIntermediateTex_[y+mod][x];
402 if (idaIntermediateTex_[y+mod][x-mod] != 0) {
403 idaTexOut_[y][x] = idaIntermediateTex_[y+mod][x-mod];
406 if (idaIntermediateTex_[y-mod][x+mod] != 0) {
407 idaTexOut_[y][x] = idaIntermediateTex_[y-mod][x+mod];
410 if (idaIntermediateTex_[y-mod][x] != 0) {
411 idaTexOut_[y][x] = idaIntermediateTex_[y-mod][x];
414 if (idaIntermediateTex_[y-mod][x-mod] != 0) {
415 idaTexOut_[y][x] = idaIntermediateTex_[y-mod][x-mod];
420 idaTexOut_[y][x] = idaIntermediateTex_[y][x];
425 for (
unsigned int y=boundMinWrap_[1]+fillAreaWindowSize_;
426 y<boundMaxWrap_[1]-fillAreaWindowSize_;y++) {
427 for (
unsigned int x=((
int)boundMinWrap_[0]+fillAreaWindowSize_)*dTexChannels_;
428 x<((int)boundMaxWrap_[0]-fillAreaWindowSize_)*dTexChannels_;
430 unsigned int val = 0;
431 val = GetSummedValue_(&(idaIntermediateTex_[y][x]));
433 for (
unsigned int mod=1;mod<fillAreaWindowSize_;mod++) {
434 unsigned int xmod = mod * dTexChannels_;
435 if (GetSummedValue_(&(idaIntermediateTex_[y][x+xmod])) != 0) {
436 SetValue_(&(idaIntermediateTex_[y][x+xmod]), &(idaTexOut_[y][x]));
439 if (GetSummedValue_(&(idaIntermediateTex_[y][x-xmod])) != 0) {
440 SetValue_(&(idaIntermediateTex_[y][x-xmod]), &(idaTexOut_[y][x]));
443 if (GetSummedValue_(&(idaIntermediateTex_[y+mod][x+xmod])) != 0) {
444 SetValue_(&(idaIntermediateTex_[y+mod][x+xmod]), &(idaTexOut_[y][x]));
447 if (GetSummedValue_(&(idaIntermediateTex_[y+mod][x])) != 0) {
448 SetValue_(&(idaIntermediateTex_[y+mod][x]), &(idaTexOut_[y][x]));
451 if (GetSummedValue_(&(idaIntermediateTex_[y+mod][x-xmod])) != 0) {
452 SetValue_(&(idaIntermediateTex_[y+mod][x-xmod]), &(idaTexOut_[y][x]));
455 if (GetSummedValue_(&(idaIntermediateTex_[y-mod][x+xmod])) != 0) {
456 SetValue_(&(idaIntermediateTex_[y-mod][x+xmod]), &(idaTexOut_[y][x]));
459 if (GetSummedValue_(&(idaIntermediateTex_[y-mod][x])) != 0) {
460 SetValue_(&(idaIntermediateTex_[y-mod][x]), &(idaTexOut_[y][x]));
463 if (GetSummedValue_(&(idaIntermediateTex_[y-mod][x-xmod])) != 0) {
464 SetValue_(&(idaIntermediateTex_[y-mod][x-xmod]), &(idaTexOut_[y][x]));
469 SetValue_(&(idaIntermediateTex_[y][x]), &(idaTexOut_[y][x]));
481 template <
class InputStorageType,
class OutputStorageType>
485 for (
unsigned int i=0;i<dTexChannels_;i++) {
491 template <
class InputStorageType,
class OutputStorageType>
493 SetValue_(
const OutputStorageType* in, OutputStorageType* out) {
494 for (
unsigned int i=0;i<dTexChannels_;i++) {
unsigned int dTargetWidth_
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
BIAS::Projection SourceP_
unsigned int dSourceHeight_
void GetCorners(unsigned &UpperLeftX, unsigned &UpperLeftY, unsigned &LowerRightX, unsigned &LowerRightY) const
Return the region of interest, by saving the coordinates within the variables defined by the paramete...
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
unsigned int dSourceWidth_
~ForwardMappingNearestNeighbour()
ROI * GetROI()
Returns a pointer to the roi object.
ForwardMappingNearestNeighbour()
void FillImageWithConstValue(StorageType Value)
fill grey images
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
int Map(const BIAS::Image< InputStorageType > *in, BIAS::Image< OutputStorageType > &out, const BIAS::Image< InputStorageType > *texin, BIAS::Image< OutputStorageType > &texout)
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
BIAS::Image< OutputStorageType > intermediateTex_
ForwardMappingNearestNeighbour< InputStorageType, OutputStorageType > & operator=(const ForwardMappingNearestNeighbour< InputStorageType, OutputStorageType > &src)
unsigned int dTargetHeight_
class BIASGeometryBase_EXPORT HomgPoint3D
BIAS::Image< OutputStorageType > intermediate_
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase