StreamImageProvider.cpp
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package TabletTeleoperation::ArmarXObjects::StreamImageProvider
19  * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
20  * @date 2013
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "StreamImageProvider.h"
26 
27 // VisionX
29 
30 using namespace armarx;
31 
32 void
34 {
35  this->streamReceiver = receiver;
36 }
37 
38 void
40 {
41 
42  setNumberImages(streamReceiver->getNumberOfImages());
43 
44  int imgWidth = 0;
45  int imgHeight = 0;
46  int imgType = 0;
47 
48  streamReceiver->getImageInformation(imgWidth, imgHeight, imgType);
49 
50  // ARMARX_WARNING << "image imformation : w: " << imgWidth << " h: " << imgHeight << " t: " << imgType ;
51 
52  visionx::ImageType colorType = visionx::ImageType(imgType);
53  CByteImage::ImageType byteType = visionx::tools::convert(colorType);
54 
55 
56  //ARMARX_WARNING << "expected : x: " << visionx::eRgb << " y: " << CByteImage::eRGB24;
57  //ARMARX_WARNING << "colorType : " << colorType << " byteType " << byteType ;
58 
59  setImageFormat(visionx::ImageDimension(imgWidth, imgHeight), colorType);
60  ARMARX_INFO << "Images: " << getNumberImages();
61  for (int i = 0; i < getNumberImages(); ++i)
62  {
63  images.push_back(new CByteImage(imgWidth, imgHeight, byteType));
64  }
65 
66 
67  ImageProvider::onConnectComponent();
68 }
69 
70 void
72 {
73  // set imageprovider properties
74  imagePullTask = new PeriodicTask<StreamImageProvider>(
75  this, &StreamImageProvider::pullImages, 30, true, "PullImages");
76  usingProxy("StreamReceiver");
77 }
78 
79 void
81 {
82  imagePullTask->start();
83 }
84 
85 void
87 {
88  imagePullTask->stop();
89 
90  for (auto& i : images)
91  {
92  delete i;
93  }
94 }
95 
96 void
97 StreamImageProvider::pullImages()
98 {
99  ARMARX_INFO << deactivateSpam(1) << "Pulling images";
100  streamReceiver->getImages(images);
101  provideImages(&images[0]);
102 }
StreamImageProvider.h
visionx::ImageProvider::getNumberImages
int getNumberImages(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve number of images handled by this provider.
Definition: ImageProvider.cpp:82
visionx::ImageProvider::setImageFormat
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
Definition: ImageProvider.cpp:305
armarx::StreamImageProvider::onConnectImageProvider
void onConnectImageProvider()
This is called when the Component::onConnectComponent() setup is called.
Definition: StreamImageProvider.cpp:80
IceInternal::Handle< StreamReceiver >
visionx::tools::convert
CByteImage::ImageType convert(const ImageType visionxImageType)
Converts a VisionX image type into an image type of IVT's ByteImage.
Definition: TypeMapping.cpp:97
armarx::StreamImageProvider::onExitImageProvider
void onExitImageProvider()
This is called when the Component::onExitComponent() setup is called.
Definition: StreamImageProvider.cpp:86
armarx::StreamImageProvider::onInitImageProvider
void onInitImageProvider()
This is called when the Component::onInitComponent() is called.
Definition: StreamImageProvider.cpp:71
visionx::ImageProvider::provideImages
void provideImages(void **inputBuffers, const IceUtil::Time &imageTimestamp=IceUtil::Time())
send images raw.
Definition: ImageProvider.cpp:351
visionx::ImageProvider::setNumberImages
void setNumberImages(int numberImages)
Sets the number of images on each capture.
Definition: ImageProvider.cpp:344
armarx::StreamImageProvider::setReceiver
void setReceiver(StreamReceiverPtr receiver)
Definition: StreamImageProvider.cpp:33
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:99
TypeMapping.h
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::StreamImageProvider::onConnectComponent
void onConnectComponent()
Pure virtual hook for the subclass.
Definition: StreamImageProvider.cpp:39
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27