[324] | 1 | // created: 2015/10/07
|
---|
| 2 | // filename: Sobel.cpp
|
---|
| 3 | //
|
---|
| 4 | // author: Gildas Bayard
|
---|
| 5 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 6 | //
|
---|
| 7 | // version: $Id: $
|
---|
| 8 | //
|
---|
| 9 | // purpose: Sobel
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 | /*********************************************************************/
|
---|
| 13 |
|
---|
| 14 | #include "Sobel.h"
|
---|
[325] | 15 | #include "VisionFilter.h"
|
---|
[324] | 16 | #include <Image.h>
|
---|
| 17 | #include <Layout.h>
|
---|
| 18 | #include <GroupBox.h>
|
---|
| 19 | #include <SpinBox.h>
|
---|
| 20 | #include <typeinfo>
|
---|
| 21 |
|
---|
| 22 | using std::string;
|
---|
| 23 | using namespace flair::core;
|
---|
| 24 | using namespace flair::gui;
|
---|
| 25 |
|
---|
[325] | 26 | class Sobel_impl {
|
---|
| 27 | public:
|
---|
| 28 | Sobel_impl(flair::filter::Sobel *self,const LayoutPosition* position,string name):output(0) {
|
---|
| 29 | this->self=self;
|
---|
| 30 |
|
---|
| 31 | GroupBox* reglages_groupbox=new GroupBox(position,name);
|
---|
| 32 | dx=new SpinBox(reglages_groupbox->NewRow(),"dx:",0,1,1,1);
|
---|
| 33 | dy=new SpinBox(reglages_groupbox->NewRow(),"dy:",0,1,1,1);
|
---|
[324] | 34 |
|
---|
[325] | 35 | Printf("TODO: IODevice doit faire un check de GetInputDataType et GetOutputDataType\n");
|
---|
| 36 | //Image devrait accepter un type dans son constructeur pour construire un type identique
|
---|
| 37 | try{
|
---|
| 38 | Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType());
|
---|
| 39 | if(imageType.GetFormat()==Image::Type::Format::Gray) {
|
---|
| 40 | output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"sobel");
|
---|
| 41 | //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
|
---|
| 42 | //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
|
---|
| 43 | } else {
|
---|
| 44 | self->Err("input image is not gray\n");
|
---|
| 45 | }
|
---|
[324] | 46 |
|
---|
[325] | 47 | } catch(std::bad_cast& bc) {
|
---|
| 48 | self->Err("io type mismatch\n");
|
---|
[324] | 49 | }
|
---|
[325] | 50 | }
|
---|
[324] | 51 |
|
---|
[325] | 52 | ~Sobel_impl() {
|
---|
| 53 | //FreeFunction((char*)(inIplImage));
|
---|
| 54 | //FreeFunction((char*)(outIplImage));
|
---|
[324] | 55 | }
|
---|
[325] | 56 |
|
---|
| 57 | void UpdateFrom(const io_data *data){
|
---|
| 58 | Image *image=(Image*)data;
|
---|
| 59 | /*
|
---|
| 60 | data->GetMutex();
|
---|
| 61 | inIplImage->width=image->GetDataType().GetWidth();
|
---|
| 62 | inIplImage->height=image->GetDataType().GetHeight();
|
---|
| 63 | inIplImage->imageData=image->buffer;
|
---|
| 64 |
|
---|
| 65 | output->GetMutex();
|
---|
| 66 | outIplImage->width=output->GetDataType().GetWidth();
|
---|
| 67 | outIplImage->height=output->GetDataType().GetHeight();
|
---|
| 68 | outIplImage->imageData=output->buffer;
|
---|
| 69 |
|
---|
| 70 | dspSobel(inIplImage,outIplImage,dx->Value(),dy->Value());
|
---|
| 71 | output->ReleaseMutex();
|
---|
| 72 | data->ReleaseMutex();
|
---|
| 73 | */
|
---|
| 74 | output->SetDataTime(data->DataTime());
|
---|
| 75 |
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | Image *output;
|
---|
| 79 |
|
---|
| 80 | private:
|
---|
| 81 | flair::filter::Sobel *self;
|
---|
| 82 | SpinBox *dx;
|
---|
| 83 | SpinBox *dy;
|
---|
| 84 | //IplImage *inIplImage,*outIplImage;
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | namespace flair { namespace filter {
|
---|
| 88 |
|
---|
| 89 | Sobel::Sobel(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
|
---|
| 90 | pimpl_=new Sobel_impl(this,position,name);
|
---|
[324] | 91 | }
|
---|
| 92 |
|
---|
| 93 | Sobel::~Sobel(void) {
|
---|
[325] | 94 | delete pimpl_;
|
---|
[324] | 95 | }
|
---|
| 96 |
|
---|
| 97 | Image* Sobel::Output(void) {
|
---|
[325] | 98 | return pimpl_->output;
|
---|
[324] | 99 | }
|
---|
| 100 |
|
---|
[325] | 101 | void Sobel::UpdateFrom(const io_data *data) {
|
---|
| 102 | pimpl_->UpdateFrom(data);
|
---|
| 103 | ProcessUpdate(pimpl_->output);
|
---|
[324] | 104 | }
|
---|
| 105 |
|
---|
| 106 | DataType const &Sobel::GetOutputDataType() const {
|
---|
[325] | 107 | if(pimpl_->output!=NULL) {
|
---|
| 108 | return pimpl_->output->GetDataType();
|
---|
[324] | 109 | } else {
|
---|
| 110 | return dummyType;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | } // end namespace filter
|
---|
| 115 | } // end namespace flair
|
---|