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

Last change on this file since 325 was 325, checked in by Sanahuja Guillaume, 3 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 <dspcv_gpp.h>
21#include <typeinfo>
22
23using std::string;
24using namespace flair::core;
25using namespace flair::gui;
26
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
85namespace flair { namespace filter {
86
87ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
88 pimpl_=new ImgThreshold_impl(this,position,name);
89}
90
91ImgThreshold::~ImgThreshold(void) {
92 delete pimpl_;
93}
94
95Image* ImgThreshold::Output(void) {
96 return pimpl_->output;
97}
98
99void ImgThreshold::UpdateFrom(const io_data *data) {
100 pimpl_->UpdateFrom(data);
101 ProcessUpdate(pimpl_->output);
102}
103
104DataType const &ImgThreshold::GetOutputDataType() const {
105 if(pimpl_->output!=NULL) {
106 return pimpl_->output->GetDataType();
107 } else {
108 return dummyType;
109 }
110}
111
112} // end namespace filter
113} // end namespace flair
Note: See TracBrowser for help on using the repository browser.