source: flair-src/branches/sanscv/lib/FlairVisionFilter/src/ImgThreshold.cpp @ 326

Last change on this file since 326 was 326, checked in by Sanahuja Guillaume, 2 years ago

using pimpl

File size: 3.2 KB
Line 
1//  created:    2015/10/07
2//  filename:   ImgThreshold.cpp
3//
4//  author:     Guillaume Sanahuja
5//              Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7//  version:    $Id: $
8//
9//  purpose:    ImgThreshold
10//
11//
12/*********************************************************************/
13
14#include "ImgThreshold.h"
15#include "VisionFilter.h"
16#include <Image.h>
17#include <Layout.h>
18#include <GroupBox.h>
19#include <SpinBox.h>
20#include <typeinfo>
21
22using std::string;
23using namespace flair::core;
24using namespace flair::gui;
25
26class ImgThreshold_impl {
27public:
28    ImgThreshold_impl(flair::filter::ImgThreshold *self,const LayoutPosition* position,string name):output(0) {
29        this->self=self;
30       
31        GroupBox* reglages_groupbox=new GroupBox(position,name);
32        threshold=new SpinBox(reglages_groupbox->NewRow(),"threshold:",0,255,1,127);
33
34        Printf("todo: pouvoir reutiliser la meme image en sortie\n");
35        try{
36            Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType());
37            if(imageType.GetFormat()==Image::Type::Format::Gray) {
38                output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold");
39                //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
40                //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
41            } else {
42                self->Err("input image is not gray\n");
43            }
44        } catch(std::bad_cast& bc) {
45            self->Err("io type mismatch\n");
46        }
47
48       
49    }
50
51    ~ImgThreshold_impl() {
52        //FreeFunction((char*)(inIplImage));
53        //FreeFunction((char*)(outIplImage));
54    }
55   
56    void UpdateFrom(const io_data *data){
57        Image *img=(Image*)data;
58/*
59        data->GetMutex();
60        inIplImage->width=img->GetDataType().GetWidth();
61        inIplImage->height=img->GetDataType().GetHeight();
62        inIplImage->imageData=img->buffer;
63       
64        output->GetMutex();
65        outIplImage->width=output->GetDataType().GetWidth();
66        outIplImage->height=output->GetDataType().GetHeight();
67        outIplImage->imageData=output->buffer;
68               
69        dspThreshold(inIplImage,outIplImage, threshold->Value(), 255, CV_THRESH_BINARY);
70        output->ReleaseMutex();
71        data->ReleaseMutex();
72*/
73        output->SetDataTime(data->DataTime());
74    };
75   
76    Image *output;
77
78private:
79    flair::filter::ImgThreshold *self;
80    SpinBox *threshold;
81    //IplImage *inIplImage,*outIplImage;
82};
83
84namespace flair { namespace filter {
85
86ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
87    pimpl_=new ImgThreshold_impl(this,position,name);
88}
89
90ImgThreshold::~ImgThreshold(void) {
91    delete pimpl_;
92}
93
94Image* ImgThreshold::Output(void) {
95    return pimpl_->output;
96}
97
98void ImgThreshold::UpdateFrom(const io_data *data) {
99    pimpl_->UpdateFrom(data);
100    ProcessUpdate(pimpl_->output);
101}
102
103DataType const &ImgThreshold::GetOutputDataType() const {
104    if(pimpl_->output!=NULL) {
105        return pimpl_->output->GetDataType();
106    } else {
107        return dummyType;
108    }
109}
110
111} // end namespace filter
112} // end namespace flair
Note: See TracBrowser for help on using the repository browser.