forked from nical/kiwi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing image::ChannelOffsetFilter (right now it has a segfault relat…
…ed to writer subport stuff...)
- Loading branch information
Showing
13 changed files
with
242 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
#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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
#include "kiwi/image/ChannelOffsetFilter.hpp" | ||
#include "kiwi/image/cairo/ImageContainer.hpp" | ||
#include "kiwi/core/Commons.hpp" | ||
#include "kiwi/core/Filter.hpp" | ||
#include <assert.h> | ||
|
||
|
||
|
||
using namespace kiwi; | ||
using namespace kiwi::image; | ||
|
||
void ChannelOffsetTest() | ||
{ | ||
typedef cairo::RGBAImageContainer::CoordinateVector CoordinateVector; | ||
|
||
cairo::RGBAImageContainer inputData("inputImageTransp.png"); | ||
kiwi::core::Node inputDataNode(&inputData); | ||
|
||
kiwi::generic::PointVectorContainer<kiwi::uint32_t, 2> displacement1(CoordinateVector(100,15)); | ||
kiwi::core::Node displacement1Node(&displacement1); | ||
|
||
cairo::RGBAImageContainer result("inputImageTransp.png" ); | ||
|
||
kiwi::core::Node resultNode(&result); | ||
|
||
kiwi::image::ChannelOffsetFilter f1; | ||
|
||
Debug::print() << "plop\n" << endl(); | ||
|
||
assert( inputDataNode.writerOutputPort(0).isComposite() ); | ||
assert( inputDataNode.writerOutputPort(0).nbSubPorts() == 4 ); | ||
|
||
inputDataNode.readerOutputPort(0).subPort(0) >> f1.readerInputPort(0); | ||
displacement1Node.readerOutputPort(0) >> f1.readerInputPort(1); | ||
resultNode.writerOutputPort(0).subPort(0) >> f1.writerInputPort(0); | ||
|
||
//typedef kiwi::core::Container TestType; | ||
typedef kiwi::generic::ArrayContainerInterface<kiwi::uint8_t,2> TestType; | ||
TestType* ptr = resultNode.writerOutputPort(0).subPort(0).getContainer<TestType>() ; | ||
assert( ptr ); | ||
|
||
assert( f1.readerInputPort(0).isConnected() ); | ||
assert( f1.readerInputPort(1).isConnected() ); | ||
assert( f1.writerInputPort(0).isConnected() ); | ||
|
||
f1.process(); | ||
|
||
result.saveToPng("OffsetFilterOutputImage.png"); | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
ScopedBlockMacro(scop, "ChannelOffsetFilter::Test") | ||
ChannelOffsetTest(); | ||
} |
Oops, something went wrong.