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/ImgThreshold.cpp

    r324 r325  
    1313
    1414#include "ImgThreshold.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 ImgThreshold_impl {
     28public:
     29    ImgThreshold_impl(flair::filter::ImgThreshold *self,const LayoutPosition* position,string name):output(0) {
     30        this->self=self;
     31       
     32        GroupBox* reglages_groupbox=new GroupBox(position,name);
     33        threshold=new SpinBox(reglages_groupbox->NewRow(),"threshold:",0,255,1,127);
     34
     35        Printf("todo: pouvoir reutiliser la meme image en sortie\n");
     36        try{
     37            Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType());
     38            if(imageType.GetFormat()==Image::Type::Format::Gray) {
     39                output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold");
     40                //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
     41                //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
     42            } else {
     43                self->Err("input image is not gray\n");
     44            }
     45        } catch(std::bad_cast& bc) {
     46            self->Err("io type mismatch\n");
     47        }
     48
     49       
     50    }
     51
     52    ~ImgThreshold_impl() {
     53        //FreeFunction((char*)(inIplImage));
     54        //FreeFunction((char*)(outIplImage));
     55    }
     56   
     57    void UpdateFrom(const io_data *data){
     58        Image *img=(Image*)data;
     59/*
     60        data->GetMutex();
     61        inIplImage->width=img->GetDataType().GetWidth();
     62        inIplImage->height=img->GetDataType().GetHeight();
     63        inIplImage->imageData=img->buffer;
     64       
     65        output->GetMutex();
     66        outIplImage->width=output->GetDataType().GetWidth();
     67        outIplImage->height=output->GetDataType().GetHeight();
     68        outIplImage->imageData=output->buffer;
     69               
     70        dspThreshold(inIplImage,outIplImage, threshold->Value(), 255, CV_THRESH_BINARY);
     71        output->ReleaseMutex();
     72        data->ReleaseMutex();
     73*/
     74        output->SetDataTime(data->DataTime());
     75    };
     76   
     77    Image *output;
     78
     79private:
     80    flair::filter::ImgThreshold *self;
     81    SpinBox *threshold;
     82    //IplImage *inIplImage,*outIplImage;
     83};
     84
    2585namespace flair { namespace filter {
    2686
    27 ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name),output(0) {
    28     GroupBox* reglages_groupbox=new GroupBox(position,name);
    29     threshold=new SpinBox(reglages_groupbox->NewRow(),"threshold:",0,255,1,127);
    30 
    31     Printf("todo: pouvoir reutiliser la meme image en sortie\n");
    32     try{
    33         Image::Type const &imageType=dynamic_cast<Image::Type const &>(parent->GetOutputDataType());
    34         if(imageType.GetFormat()==Image::Type::Format::Gray) {
    35             output=new Image(this,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold");
    36         } else {
    37             Err("input image is not gray\n");
    38             return;
    39         }
    40     } catch(std::bad_cast& bc) {
    41         Err("io type mismatch\n");
    42         return;
    43     }
    44     SetIsReady(true);
     87ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
     88    pimpl_=new ImgThreshold_impl(this,position,name);
    4589}
    4690
    4791ImgThreshold::~ImgThreshold(void) {
     92    delete pimpl_;
    4893}
    4994
    5095Image* ImgThreshold::Output(void) {
    51     return output;
     96    return pimpl_->output;
    5297}
    5398
    5499void ImgThreshold::UpdateFrom(const io_data *data) {
    55  /*   Image *cvImage=(Image*)data;
    56     IplImage *gimg=cvImage->img;
    57 
    58     data->GetMutex();
    59     output->GetMutex();
    60     dspThreshold(gimg, output->img, threshold->Value(), 255, CV_THRESH_BINARY);
    61     output->ReleaseMutex();
    62     data->ReleaseMutex();
    63 */
    64     output->SetDataTime(data->DataTime());
    65     ProcessUpdate(output);
     100    pimpl_->UpdateFrom(data);
     101    ProcessUpdate(pimpl_->output);
    66102}
    67103
    68104DataType const &ImgThreshold::GetOutputDataType() const {
    69     if(output!=NULL) {
    70         return output->GetDataType();
     105    if(pimpl_->output!=NULL) {
     106        return pimpl_->output->GetDataType();
    71107    } else {
    72108        return dummyType;
Note: See TracChangeset for help on using the changeset viewer.