00001
00010 #include "RangeDataViewer.h"
00011
00012 #if __cplusplus >= 201103L
00013 using std::isinf;
00014 #endif
00015
00016
00017
00018 static const char* cameraimageviewercomponent_spec[] =
00019 {
00020 "implementation_id", "RangeDataViewer",
00021 "type_name", "RangeDataViewer",
00022 "description", "range data viewer component",
00023 "version", HRPSYS_PACKAGE_VERSION,
00024 "vendor", "AIST",
00025 "category", "example",
00026 "activity_type", "DataFlowComponent",
00027 "max_instance", "10",
00028 "language", "C++",
00029 "lang_type", "compile",
00030
00031 "conf.default.maxRange", "2.0",
00032
00033
00034 ""
00035 };
00036
00037
00038 RangeDataViewer::RangeDataViewer(RTC::Manager* manager)
00039 : RTC::DataFlowComponentBase(manager),
00040
00041 m_rangeIn("rangeIn", m_range),
00042
00043 m_cvImage(NULL),
00044 dummy(0)
00045 {
00046 }
00047
00048 RangeDataViewer::~RangeDataViewer()
00049 {
00050 }
00051
00052
00053
00054 RTC::ReturnCode_t RangeDataViewer::onInitialize()
00055 {
00056 std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
00057
00058
00059 bindParameter("maxRange", m_maxRange, "2.0");
00060
00061
00062
00063
00064
00065
00066 addInPort("rangeIn", m_rangeIn);
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 RTC::Properties& prop = getProperties();
00079
00080 return RTC::RTC_OK;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 #define WSIZE 640
00107 RTC::ReturnCode_t RangeDataViewer::onActivated(RTC::UniqueId ec_id)
00108 {
00109 std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
00110 m_cvImage = cvCreateImage(cvSize(WSIZE, WSIZE), IPL_DEPTH_8U, 3);
00111 cvNamedWindow("Range",CV_WINDOW_AUTOSIZE);
00112 return RTC::RTC_OK;
00113 }
00114
00115 RTC::ReturnCode_t RangeDataViewer::onDeactivated(RTC::UniqueId ec_id)
00116 {
00117 std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
00118 if (m_cvImage) {
00119 cvReleaseImage(&m_cvImage);
00120 m_cvImage = NULL;
00121 }
00122 cvDestroyWindow("Range");
00123 return RTC::RTC_OK;
00124 }
00125
00126 RTC::ReturnCode_t RangeDataViewer::onExecute(RTC::UniqueId ec_id)
00127 {
00128
00129
00130 if (1){
00131 do {
00132 m_rangeIn.read();
00133 }while(m_rangeIn.isNew());
00134
00135 cvSetZero(m_cvImage);
00136
00137 CvPoint center = cvPoint(WSIZE/2,WSIZE/2);
00138 CvScalar green = cvScalar(0,255,0);
00139 double th,d,x,y;
00140 #if 0
00141 std::cout << "minAngle:" << m_range.config.minAngle << std::endl;
00142 std::cout << "maxAngle:" << m_range.config.maxAngle << std::endl;
00143 std::cout << "angularRes:" << m_range.config.angularRes << std::endl;
00144 std::cout << "minRange:" << m_range.config.minRange << std::endl;
00145 std::cout << "maxRange:" << m_range.config.maxRange << std::endl;
00146 std::cout << "rangeRes:" << m_range.config.rangeRes << std::endl;
00147 std::cout << "frequency:" << m_range.config.frequency << std::endl;
00148 std::cout << "ndata = " << m_range.ranges.length() << std::endl;
00149 #endif
00150 for (unsigned int i=0; i<m_range.ranges.length(); i++){
00151 d = m_range.ranges[i];
00152 if (isinf(d)) continue;
00153 th = m_range.config.minAngle + m_range.config.angularRes*i;
00154 x = -d*sin(th)/m_maxRange*WSIZE/2 + WSIZE/2;
00155 y = -d*cos(th)/m_maxRange*WSIZE/2 + WSIZE/2;
00156 cvLine(m_cvImage, center, cvPoint(x, y), green, 1, 8, 0);
00157 }
00158
00159 cvShowImage("Range",m_cvImage);
00160 cvWaitKey(10);
00161 }
00162
00163 return RTC::RTC_OK;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 extern "C"
00204 {
00205
00206 void RangeDataViewerInit(RTC::Manager* manager)
00207 {
00208 RTC::Properties profile(cameraimageviewercomponent_spec);
00209 manager->registerFactory(profile,
00210 RTC::Create<RangeDataViewer>,
00211 RTC::Delete<RangeDataViewer>);
00212 }
00213
00214 };
00215
00216