forked from nical/kiwi
/
ChannelOffsetFilter.hpp
84 lines (62 loc) · 2.23 KB
/
ChannelOffsetFilter.hpp
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
#pragma once
#ifndef KIWI_IMAGE_CHANNELOFFSETFILTER_HPP
#define KIWI_IMAGE_CHANNELOFFSETFILTER_HPP
#include "kiwi/core/Filter.hpp"
#include "kiwi/generic/PointAccessContainerInterface.hpp"
#include "kiwi/generic/PointVectorContainer.hpp"
#include "kiwi/generic/ArrayContainer.hpp"
namespace kiwi{
namespace image{
class ChannelOffsetFilter : public kiwi::core::Filter
{
public:
ChannelOffsetFilter(){
addReaderInputPort(); // Channel
addReaderInputPort(); // displacement vector
// Result (channel)
kiwi::portIndex_t w_in = addWriterInputPort();
kiwi::portIndex_t r_out = addReaderOutputPort();
associateWriterToReader( writerInputPort(w_in) , readerOutputPort(r_out) );
}
void process(){
ScopedBlockMacro(scop,"ChannelOffsetFilter::process")
typedef kiwi::generic::PointAccessContainerInterface<kiwi::uint8_t,2> ColorBuffer;
typedef kiwi::generic::PointVectorContainer<kiwi::uint32_t, 2> PointVectorContainer;
typedef kiwi::generic::Point<kiwi::uint32_t, 2> CoordinateVector;
ColorBuffer* chan
= readerInputPort(0).connectedOutput()
->getContainer<ColorBuffer>();
PointVectorContainer* vect
= readerInputPort(1).connectedOutput()
->getContainer<PointVectorContainer>();
ColorBuffer* result
= writerInputPort(0).connectedOutput()
->getContainer<ColorBuffer>();
if(!chan) Debug::print() << "input channel not found\n";
if(!vect) Debug::print() << "input offset vector not found\n";
if(!result) Debug::print() << "output channel not found\n";
Debug::print() << vect->toStr() <<"\n";
if(!result){
Debug::print() << "Allocate result container\n";
CoordinateVector size;
if(chan) {
result = new kiwi::generic::ArrayContainer<kiwi::uint8_t,2>(chan->spanSize());
setPortContainer(readerOutputPort(0), result );
}else { return; }
}
CoordinateVector pos;
for(pos(0) = 0; pos(0) < result->spanSize()[0]; ++pos(0))
for(pos(1) = 0; pos(1) < result->spanSize()[1]; ++pos(1)){
kiwi::uint32_t val = chan->getValue(pos);
CoordinateVector newpos = (pos+*vect) % result->spanSize();
result->setValue(newpos, val);
}
}
kiwi::Tags readerInputTags(kiwi::portIndex_t index) const{
return kiwi::Tags("#any");// TODO
}
protected:
};
}//namespace
}//namespace
#endif