[Jderobot-admin] jderobot-r938 - in trunk/src/libs: . parallelIce

frivas en jderobot.org frivas en jderobot.org
Mar Jul 9 12:08:05 CEST 2013


Author: frivas
Date: 2013-07-09 12:07:04 +0200 (Tue, 09 Jul 2013)
New Revision: 938

Added:
   trunk/src/libs/parallelIce/
   trunk/src/libs/parallelIce/CMakeLists.txt
   trunk/src/libs/parallelIce/cameraClient.cpp
   trunk/src/libs/parallelIce/cameraClient.h
   trunk/src/libs/parallelIce/pointcloudClient.cpp
   trunk/src/libs/parallelIce/pointcloudClient.h
Log:
a?\195?\177adido parallelIce independiente


Added: trunk/src/libs/parallelIce/CMakeLists.txt
===================================================================
--- trunk/src/libs/parallelIce/CMakeLists.txt	                        (rev 0)
+++ trunk/src/libs/parallelIce/CMakeLists.txt	2013-07-09 10:07:04 UTC (rev 938)
@@ -0,0 +1,28 @@
+include_directories(${SLICE_DIR}) # Aquí se alojan las cabeceras de las interfaces ICE en C++
+include_directories(${INTERFACES_CPP_DIR}) # Aquí se alojan las cabeceras de las interfaces ICE en C++
+include_directories(${LIBS_DIR}) # Aquí se alojan las cabeceras de las interfaces ICE en C++
+
+
+include_directories(
+    ${INTERFACES_CPP_DIR}
+    ${LIBS_DIR}/
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}/cameras
+)
+
+add_library (parallelIce STATIC cameraClient.cpp  cameraClient.h  pointcloudClient.cpp  pointcloudClient.h)
+TARGET_LINK_LIBRARIES(parallelIce 
+   	${OpenCV_LIBRARIES}
+    ${LIBS_DIR}/colorspaces/libcolorspacesmm.so
+    ${ZeroCIce_LIBRARIES}
+)
+
+add_library (parallelIceshare SHARED cameraClient.cpp  cameraClient.h  pointcloudClient.cpp  pointcloudClient.h)
+TARGET_LINK_LIBRARIES(parallelIceshare 
+   	${OpenCV_LIBRARIES}
+    ${LIBS_DIR}/colorspaces/libcolorspacesmm.so
+    ${ZeroCIce_LIBRARIES}
+)
+
+
+set_target_properties(parallelIceshare PROPERTIES OUTPUT_NAME parallelIce)

Added: trunk/src/libs/parallelIce/cameraClient.cpp
===================================================================
--- trunk/src/libs/parallelIce/cameraClient.cpp	                        (rev 0)
+++ trunk/src/libs/parallelIce/cameraClient.cpp	2013-07-09 10:07:04 UTC (rev 938)
@@ -0,0 +1,108 @@
+/*
+ *  Copyright (C) 1997-2013 JDE Developers TeamkinectViewer.camRGB
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see http://www.gnu.org/licenses/.
+ *
+ *  Author : Jose María Cañas <jmplaza en gsyc.es>
+			Francisco Miguel Rivas Montero <franciscomiguel.rivas en urjc.es>
+
+ */
+
+#include "cameraClient.h"
+
+
+namespace jderobot {
+
+cameraClient::cameraClient(Ice::CommunicatorPtr ic, std::string prefix, bool debug) {
+	// TODO Auto-generated constructor stubcameraClient* client = new cameraClient;
+	this->prefix=prefix;
+	this->debug=debug;
+	Ice::PropertiesPtr prop;
+	prop = ic->getProperties();
+	Ice::ObjectPrx baseCamera;
+
+
+	int fps=prop->getPropertyAsIntWithDefault(prefix+"Fps",10);
+	this->cycle=(float)(1/(float)fps)*1000000;
+	try{
+		baseCamera = ic->propertyToProxy(prefix+"Proxy");
+		if (0==baseCamera){
+			throw prefix + "Could not create proxy with Camera";
+		}
+		else {
+			this->prx= jderobot::CameraPrx::checkedCast(baseCamera);
+			if (0==this->prx)
+				throw "Invalid " + prefix + ".Proxy";
+		}
+	}catch (const Ice::Exception& ex) {
+		std::cerr << ex << std::endl;
+	}
+	catch (const char* msg) {
+		std::cerr << msg << std::endl;
+		std::cout << prefix + " Not camera provided" << std::endl;
+	}
+}
+
+cameraClient::~cameraClient() {
+	// TODO Auto-generated destructor stub
+}
+
+void
+cameraClient::run(){
+	jderobot::ImageDataPtr dataPtr;
+	colorspaces::Image::FormatPtr fmt;
+	struct timeval post;
+	long long int totalpre=0;
+	long long int totalpost=0;
+	while (this->isAlive()){
+		gettimeofday(&post,NULL);
+		totalpost=post.tv_sec*1000000+post.tv_usec;
+
+		dataPtr = this->prx->getImageData();
+		fmt = colorspaces::Image::Format::searchFormat(dataPtr->description->format);
+		if (!fmt)
+			throw "Format not supported";
+		colorspaces::Image imageRGB(dataPtr->description->width,dataPtr->description->height,fmt,&(dataPtr->pixelData[0]));
+		colorspaces::ImageRGB8 img_rgb888(imageRGB);//conversion will happen if needed
+		cv::Mat localDataPtr = cv::Mat(cvSize(img_rgb888.width,img_rgb888.height), CV_8UC3, img_rgb888.data);
+		cv::Mat localData;
+		localDataPtr.copyTo(localData);
+		this->controlMutex.lock();
+		this->data.release();
+		localData.copyTo(this->data);
+		this->controlMutex.unlock();
+
+		if (totalpre !=0){
+			if ((totalpost - totalpre) > this->cycle ){
+				if (this->debug)
+					std::cout<<"--------" << prefix << " adquisition timeout-" << std::endl;
+			}
+			else{
+				usleep(this->cycle - (totalpost - totalpre));
+			}
+		}
+		totalpre=totalpost;
+	}
+}
+
+cv::Mat cameraClient::getImage(){
+	cv::Mat local;
+	this->controlMutex.lock();
+	this->data.copyTo(local);
+	this->controlMutex.unlock();
+	return local;
+
+}
+
+} /* namespace jderobot */

Added: trunk/src/libs/parallelIce/cameraClient.h
===================================================================
--- trunk/src/libs/parallelIce/cameraClient.h	                        (rev 0)
+++ trunk/src/libs/parallelIce/cameraClient.h	2013-07-09 10:07:04 UTC (rev 938)
@@ -0,0 +1,57 @@
+/*
+ *  Copyright (C) 1997-2013 JDE Developers TeamkinectViewer.camRGB
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see http://www.gnu.org/licenses/.
+ *
+ *  Author : Jose María Cañas <jmplaza en gsyc.es>
+			Francisco Miguel Rivas Montero <franciscomiguel.rivas en urjc.es>
+
+ */
+
+#ifndef CAMERACLIENT_H_
+#define CAMERACLIENT_H_
+
+#include <IceUtil/IceUtil.h>
+#include <iostream>
+#include <Ice/Ice.h>
+#include <colorspaces/colorspacesmm.h>
+#include <jderobot/camera.h>
+#include <cv.h>
+#include <sstream>
+#include <fstream>
+
+
+namespace jderobot {
+
+class cameraClient: public IceUtil::Thread {
+public:
+	cameraClient(Ice::CommunicatorPtr ic, std::string prefix, bool debug);
+	virtual ~cameraClient();
+	virtual void run();
+
+	//callbacks
+	cv::Mat getImage();
+private:
+	cv::Mat data;
+	jderobot::CameraPrx prx;
+	long long int cycle;
+	//int type; //0 color 1 depth
+	IceUtil::Mutex controlMutex;
+	std::string prefix;
+	bool debug;
+
+};
+
+} /* namespace jderobot */
+#endif /* CAMERACLIENT_H_ */

Added: trunk/src/libs/parallelIce/pointcloudClient.cpp
===================================================================
--- trunk/src/libs/parallelIce/pointcloudClient.cpp	                        (rev 0)
+++ trunk/src/libs/parallelIce/pointcloudClient.cpp	2013-07-09 10:07:04 UTC (rev 938)
@@ -0,0 +1,97 @@
+/*
+ *  Copyright (C) 1997-2013 JDE Developers TeamkinectViewer.camRGB
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see http://www.gnu.org/licenses/.
+ *
+ *  Author : Jose María Cañas <jmplaza en gsyc.es>
+			Francisco Miguel Rivas Montero <franciscomiguel.rivas en urjc.es>
+
+ */
+#include "pointcloudClient.h"
+
+namespace jderobot {
+
+pointcloudClient::pointcloudClient(Ice::CommunicatorPtr ic, std::string prefix, bool debug) {
+	// TODO Auto-generated constructor stub
+	this->prefix=prefix;
+	this->debug= debug;
+	Ice::PropertiesPtr prop;
+	prop = ic->getProperties();
+
+	int fps=prop->getPropertyAsIntWithDefault(prefix+"Fps",10);
+	this->cycle=(float)(1/(float)fps)*1000000;
+	try{
+		Ice::ObjectPrx basePointCloud = ic->propertyToProxy(prefix+"Proxy");
+		if (0==basePointCloud){
+			throw prefix + " Could not create proxy";
+		}
+		else {
+			this->prx = jderobot::pointCloudPrx::checkedCast(basePointCloud);
+			if (0==this->prx)
+				throw "Invalid proxy" + prefix;
+
+		}
+	}catch (const Ice::Exception& ex) {
+		std::cerr << ex << std::endl;
+	}
+	catch (const char* msg) {
+		std::cerr << msg << std::endl;
+		std::cout <<  prefix + " Not camera provided" << std::endl;
+	}
+
+}
+
+pointcloudClient::~pointcloudClient() {
+	// TODO Auto-generated destructor stub
+}
+
+void pointcloudClient::run(){
+
+	struct timeval post;
+	long long int totalpre=0;
+	long long int totalpost=0;
+	while (1){
+		gettimeofday(&post,NULL);
+		totalpost=post.tv_sec*1000000+post.tv_usec;
+
+		jderobot::pointCloudDataPtr localCloud=this->prx->getCloudData();
+
+		this->controlMutex.lock();
+		this->data.resize(localCloud->p.size());
+		std::copy( localCloud->p.begin(), localCloud->p.end(), this->data.begin() );
+
+		this->controlMutex.unlock();
+		if (totalpre !=0){
+			if ((totalpost - totalpre) > this->cycle ){
+				if (this->debug)
+					std::cout<< prefix << ": pointCloud adquisition timeout-" << std::endl;
+			}
+			else{
+				usleep(this->cycle - (totalpost - totalpre));
+			}
+		}
+		totalpre=totalpost;
+	}
+}
+
+std::vector<jderobot::RGBPoint>  pointcloudClient::getData(){
+	std::vector<jderobot::RGBPoint> cloud;
+	this->controlMutex.lock();
+	cloud.resize(this->data.size());
+	std::copy( this->data.begin(), this->data.end(), cloud.begin() );
+	this->controlMutex.unlock();
+	return cloud;
+}
+
+} /* namespace jderobot */

Added: trunk/src/libs/parallelIce/pointcloudClient.h
===================================================================
--- trunk/src/libs/parallelIce/pointcloudClient.h	                        (rev 0)
+++ trunk/src/libs/parallelIce/pointcloudClient.h	2013-07-09 10:07:04 UTC (rev 938)
@@ -0,0 +1,56 @@
+/*
+ *  Copyright (C) 1997-2013 JDE Developers TeamkinectViewer.camRGB
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see http://www.gnu.org/licenses/.
+ *
+ *  Author : Jose María Cañas <jmplaza en gsyc.es>
+			Francisco Miguel Rivas Montero <franciscomiguel.rivas en urjc.es>
+
+ */
+
+
+#ifndef POINTCLOUDCLIENT_H_
+#define POINTCLOUDCLIENT_H_
+
+#include <IceUtil/IceUtil.h>
+#include <iostream>
+#include <Ice/Ice.h>
+#include <jderobot/pointcloud.h>
+#include <cv.h>
+#include <sstream>
+#include <fstream>
+
+namespace jderobot {
+
+class pointcloudClient: public IceUtil::Thread {
+public:
+	pointcloudClient(Ice::CommunicatorPtr ic, std::string prefix, bool debug);
+	virtual ~pointcloudClient();
+	virtual void run();
+
+	std::vector<jderobot::RGBPoint>  getData();
+
+
+private:
+	std::string prefix;
+	std::vector<jderobot::RGBPoint> data;
+	jderobot::pointCloudPrx prx;
+	long long int cycle;
+	IceUtil::Mutex controlMutex;
+	bool debug;
+
+};
+
+} /* namespace jderobot */
+#endif /* POINTCLOUDCLIENT_H_ */



More information about the Jderobot-admin mailing list