Ignore:
Timestamp:
08/28/19 16:12:11 (5 years ago)
Author:
Sanahuja Guillaume
Message:

using pimpl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/sanscv/lib/FlairVisionFilter/src/Sobel.cpp

    r324 r325  
    1313
    1414#include "Sobel.h"
     15#include "VisionFilter.h"
    1516#include <Image.h>
    1617#include <Layout.h>
    1718#include <GroupBox.h>
    1819#include <SpinBox.h>
     20//#include <dspcv_gpp.h>
    1921#include <typeinfo>
    2022
     
    2325using namespace flair::gui;
    2426
     27class Sobel_impl {
     28public:
     29    Sobel_impl(flair::filter::Sobel *self,const LayoutPosition* position,string name):output(0) {
     30        this->self=self;
     31       
     32        GroupBox* reglages_groupbox=new GroupBox(position,name);
     33        dx=new SpinBox(reglages_groupbox->NewRow(),"dx:",0,1,1,1);
     34        dy=new SpinBox(reglages_groupbox->NewRow(),"dy:",0,1,1,1);
     35
     36        Printf("TODO: IODevice doit faire un check de GetInputDataType et GetOutputDataType\n");
     37        //Image devrait accepter un type dans son constructeur pour construire un type identique
     38        try{
     39            Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType());
     40            if(imageType.GetFormat()==Image::Type::Format::Gray) {
     41                output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"sobel");
     42                //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
     43                //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
     44            } else {
     45                self->Err("input image is not gray\n");
     46            }
     47
     48        } catch(std::bad_cast& bc) {
     49            self->Err("io type mismatch\n");
     50        }
     51    }
     52
     53    ~Sobel_impl() {
     54        //FreeFunction((char*)(inIplImage));
     55        //FreeFunction((char*)(outIplImage));
     56    }
     57   
     58    void UpdateFrom(const io_data *data){
     59        Image *image=(Image*)data;
     60/*
     61        data->GetMutex();
     62        inIplImage->width=image->GetDataType().GetWidth();
     63        inIplImage->height=image->GetDataType().GetHeight();
     64        inIplImage->imageData=image->buffer;
     65       
     66        output->GetMutex();
     67        outIplImage->width=output->GetDataType().GetWidth();
     68        outIplImage->height=output->GetDataType().GetHeight();
     69        outIplImage->imageData=output->buffer;
     70               
     71        dspSobel(inIplImage,outIplImage,dx->Value(),dy->Value());
     72        output->ReleaseMutex();
     73        data->ReleaseMutex();
     74*/
     75        output->SetDataTime(data->DataTime());
     76
     77    };
     78   
     79    Image *output;
     80
     81private:
     82    flair::filter::Sobel *self;
     83    SpinBox *dx;
     84    SpinBox *dy;
     85    //IplImage *inIplImage,*outIplImage;
     86};
     87
    2588namespace flair { namespace filter {
    2689
    27 Sobel::Sobel(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name),output(0) {
    28     GroupBox* reglages_groupbox=new GroupBox(position,name);
    29     dx=new SpinBox(reglages_groupbox->NewRow(),"dx:",0,1,1,1);
    30     dy=new SpinBox(reglages_groupbox->NewRow(),"dy:",0,1,1,1);
    31 
    32     Printf("TODO: IODevice doit faire un check de GetInputDataType et GetOutputDataType\n");
    33     //Image devrait accepter un type dans son constructeur pour construire un type identique
    34     try{
    35         Image::Type const &imageType=dynamic_cast<Image::Type const &>(parent->GetOutputDataType());
    36         if(imageType.GetFormat()==Image::Type::Format::Gray) {
    37             output=new Image(this,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"sobel");
    38         } else {
    39             Err("input image is not gray\n");
    40             return;
    41         }
    42 
    43     } catch(std::bad_cast& bc) {
    44         Err("io type mismatch\n");
    45         return;
    46     }
    47     SetIsReady(true);
     90Sobel::Sobel(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
     91   pimpl_=new Sobel_impl(this,position,name);
    4892}
    4993
    5094Sobel::~Sobel(void) {
     95    delete pimpl_;
    5196}
    5297
    5398Image* Sobel::Output(void) {
    54     return output;
     99    return pimpl_->output;
    55100}
    56101
    57 void Sobel::UpdateFrom(const io_data *data) {/*
    58     Image *cvImage=(Image*)data;
    59     IplImage *gimg=cvImage->img;
    60 
    61     data->GetMutex();
    62     output->GetMutex();
    63     dspSobel(gimg,output->img,dx->Value(),dy->Value());
    64     output->ReleaseMutex();
    65     data->ReleaseMutex();
    66 */
    67     output->SetDataTime(data->DataTime());
    68     ProcessUpdate(output);
     102void Sobel::UpdateFrom(const io_data *data) {
     103    pimpl_->UpdateFrom(data);
     104    ProcessUpdate(pimpl_->output);
    69105}
    70106
    71107DataType const &Sobel::GetOutputDataType() const {
    72     if(output!=NULL) {
    73         return output->GetDataType();
     108    if(pimpl_->output!=NULL) {
     109        return pimpl_->output->GetDataType();
    74110    } else {
    75111        return dummyType;
Note: See TracChangeset for help on using the changeset viewer.