You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

656 lines
27 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "deviceNodeSensor.h"
  2. #include "../../components/object/objectSystemAnchor.h"
  3. #include <opencv2/opencv.hpp>
  4. #define LOG( X ) deviceNode::m_pLog->Log( "NODSEN", this, X )
  5. #define LOG_ERROR( X ) deviceNode::m_pLog->Log( "NODSEN", this, _LOG_ERROR, X )
  6. deviceNodeSensor::deviceNodeSensor( uint32_t id ):deviceNode( id ),m_oPosition(){
  7. m_pEventHeap = basicEventHeap::getInstance();
  8. switch( m_sNodeData.type ){
  9. case ARGUS_CLD_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_CLD; break;
  10. case ARGUS_LGS_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_LGS; break;
  11. case ARGUS_ALS_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_ALS; break;
  12. case ARGUS_LFS_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_LFS; break;
  13. case ARGUS_PLS_200_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_PLS_210; break;
  14. case ARGUS_PLS_360_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_PLS_360; break;
  15. case ARGUS_3D_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_3D; break;
  16. default: m_eEventClass = EVT_CLASS_SYSTEM; break;
  17. };
  18. m_pTargetFilter = NULL;
  19. memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
  20. if( m_pDBC ){
  21. DBC_LRF_DATA *tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id);
  22. if( tDATA != NULL ) {
  23. memcpy( &m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA));
  24. free( tDATA );
  25. };
  26. };
  27. systemAnchor *SA = systemAnchor::getInstance();
  28. if( SA ){
  29. LOG("SysAnchor OK");
  30. if ( SA->beLocal() ) {
  31. LOG("SysAnchor beLocal!");
  32. m_oPosition.setPositionXYZ( m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z, 0 ); //SA->getUTMZone() );
  33. m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
  34. } else {
  35. LOG("SysAnchor is Global Position System!");
  36. C3D_DECART LD = SA->getXYZ();
  37. m_oPosition.setPositionXYZ( LD.x + m_sLRF_DATA.x, LD.y + m_sLRF_DATA.y, LD.z + m_sLRF_DATA.z, SA->getUTMZone() );
  38. m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
  39. };
  40. } else {
  41. LOG("No SysAnchor!");
  42. m_oPosition.setPositionXYZ( m_sLRF_DATA.x , m_sLRF_DATA.y, m_sLRF_DATA.z );
  43. m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
  44. };
  45. m_oPosition.updateMatrix();
  46. #ifdef DEBUG
  47. char tB[128];
  48. sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
  49. LOG( tB );
  50. sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
  51. LOG( tB );
  52. sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() );
  53. LOG( tB );
  54. #endif
  55. };
  56. deviceNodeSensor::deviceNodeSensor( DBC_NODE_DATA *Data ):deviceNode( Data ),m_oPosition(){
  57. m_pTargetFilter = NULL;
  58. m_pLog = basicLogCollection::getInstance();
  59. memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
  60. if( m_pDBC ){
  61. DBC_LRF_DATA *tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id);
  62. if( tDATA != NULL ) {
  63. memcpy( &m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA));
  64. free( tDATA );
  65. };
  66. };
  67. systemAnchor *SA = systemAnchor::getInstance();
  68. if( SA ){
  69. LOG("SysAnchor OK");
  70. if ( SA->beLocal() ) {
  71. LOG("SysAnchor beLocal!");
  72. m_oPosition.setPositionXYZ( m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z, 0 ); //SA->getUTMZone() );
  73. m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
  74. } else {
  75. LOG("SysAnchor is Global Position System!");
  76. C3D_DECART LD = SA->getXYZ();
  77. m_oPosition.setPositionXYZ( LD.x + m_sLRF_DATA.x, LD.y + m_sLRF_DATA.y, LD.z + m_sLRF_DATA.z, SA->getUTMZone() );
  78. m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
  79. };
  80. } else {
  81. LOG("No SysAnchor!");
  82. m_oPosition.setPositionXYZ( m_sLRF_DATA.x , m_sLRF_DATA.y, m_sLRF_DATA.z );
  83. m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
  84. };
  85. m_oPosition.updateMatrix();
  86. #ifdef DEBUG
  87. char tB[128];
  88. sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
  89. LOG( tB );
  90. sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
  91. LOG( tB );
  92. sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() );
  93. LOG( tB );
  94. #endif
  95. };
  96. deviceNodeSensor::~deviceNodeSensor(){
  97. };
  98. #define SKIP_LINE_PIXELS 28
  99. #define HEIGHT 512
  100. #define WIDTH 1024
  101. // scale factor -> 4/9
  102. uint8_t *deviceNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum ){
  103. uint8_t *RetVal = NULL;
  104. *out_size = 0;
  105. LOG("C2DD");
  106. if( th_data != NULL && th_size != 0 ) {
  107. if ( fileExist( tpl ) ) {
  108. LOG(tpl);
  109. cv::Mat tImage = cv::imread( tpl, cv::IMREAD_UNCHANGED );
  110. int psize = th_size / ( sizeof( uint32_t ));
  111. float stp = 2.0f * ( M_PI / (float) psize );
  112. //float MR = m_sLRF_DATA.max_range;
  113. float S = ( M_PI / 3000.0f) * (float) radial_shift;
  114. int x0 = (tImage.cols >> 1);
  115. int y0 = (tImage.rows >> 1);
  116. float maxR = ((float) x0 ) * 0.98f;
  117. LOG("C2DD - Start");
  118. cv::Point pts[(psize << 1)];
  119. cv::Point ptt[(psize+2)];
  120. const cv::Point * ppt[1];
  121. int npp[1];
  122. const cv::Point * ppz[1];
  123. int npz[1];
  124. float rst;
  125. int rpt;
  126. uint16_t RANGE = 0;
  127. ptt[0].x = x0;
  128. ptt[0].y = y0;
  129. rst = maxR / ((float)(max_digital+1));
  130. rpt = 1;
  131. for( int i=0; i < psize; i++ ){
  132. if( byMinimum ) {
  133. RANGE = ( th_data[i] >> 16 ) & 0xFFFF;
  134. } else {
  135. RANGE = th_data[i] & 0xFFFF;
  136. };
  137. float ca = 0.0 - ( S + i * stp );
  138. if( RANGE > 0 ){
  139. pts[psize+i].x = x0 + maxR * cosf( ca );
  140. pts[psize+i].y = y0 + maxR * sinf( ca );
  141. if( RANGE > max_digital ){
  142. pts[i].x = pts[psize+i].x;
  143. pts[i].y = pts[psize+i].y;
  144. } else {
  145. float cr = (rst * RANGE);
  146. pts[i].x = x0 + cr * cosf( ca );
  147. pts[i].y = y0 + cr * sinf( ca );
  148. };
  149. } else {
  150. ptt[rpt].x = pts[psize+i].x = pts[i].x = x0 + maxR * cosf( ca );
  151. ptt[rpt].y = pts[psize+i].y = pts[i].y = y0 + maxR * sinf( ca );
  152. rpt++;
  153. };
  154. };
  155. ppt[0] = pts;
  156. npp[0] = ( psize<<1 );
  157. ppz[0] = ptt;
  158. npz[0] = ( rpt - 1);
  159. LOG("C2DD -> draw finish");
  160. cv::Mat ttMOMO = cv::imread( tpl, cv::IMREAD_UNCHANGED );
  161. LOG("C2DD -> read tpl2 finish");
  162. cv::fillPoly( ttMOMO, ppt, npp, 1, cv::Scalar( 0, 128, 255, 50 ), cv::LINE_8 );
  163. LOG("C2DD -> poly1 finish");
  164. //try {
  165. // cv::fillPoly(ttMOMO, ppz, npz, 1, cv::Scalar(0, 0, 0, 100), cv::LINE_8);
  166. // LOG("C2DD -> poly2 finish");
  167. //} catch ( cv::Exception& e ) {
  168. // LOG("C2DD -> poly2 Error!");
  169. // LOG( e.what() );
  170. //};
  171. cv::addWeighted( tImage, 0.5, ttMOMO, 0.5, 0.0, tImage );
  172. LOG("C2DD -> add img finish");
  173. ttMOMO.release();
  174. LOG("C2DD -> img release finish");
  175. vector<int> compression_params;
  176. compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION );
  177. compression_params.push_back(9);
  178. vector<uchar> buf;
  179. cv::imencode( ".png", tImage, buf, compression_params );
  180. tImage.release();
  181. LOG("C2DD -> compress finish");
  182. *out_size = buf.size();
  183. RetVal = (uint8_t *) malloc( *out_size );
  184. if( RetVal ) {
  185. memcpy( RetVal, buf.data(), *out_size );
  186. } else *out_size =0;
  187. buf.clear();
  188. };
  189. };
  190. return RetVal;
  191. };
  192. bool deviceNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum ){
  193. if( th_data == NULL ) return false;
  194. if( th_size == 0 ) return false;
  195. if( m_pDBC == NULL ) return false;
  196. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_RAW_DATA, kID, th_data, th_size );
  197. /*
  198. //Clear Old Draw
  199. CSTR old = m_pDBC->getLRFDraw( getNodeID() );
  200. if ( old ) {
  201. // delete old draw
  202. char filename[256];
  203. sprintf( filename, "data/device_draws/%s_100.png", old );
  204. if( fileExist( filename ) ){
  205. unlink( filename );
  206. };
  207. sprintf( filename, "data/device_draws/%s_50.png", old );
  208. if( fileExist( filename ) ){
  209. unlink( filename );
  210. };
  211. sprintf( filename, "data/device_draws/%s_25.png", old );
  212. if( fileExist( filename ) ){
  213. unlink( filename );
  214. };
  215. sprintf( filename, "data/device_draws/%s_12.png", old );
  216. if( fileExist( filename ) ){
  217. unlink( filename );
  218. };
  219. sprintf( filename, "data/device_draws/%s_map.png", old );
  220. if( fileExist( filename ) ){
  221. unlink( filename );
  222. };
  223. free( old );
  224. };
  225. */
  226. CSTR uid = getUniqID_MD5();
  227. if( uid == NULL ) return false;
  228. switch( getNodeType() ){
  229. case ARGUS_ALS_SENSOR:
  230. case ARGUS_LFS_SENSOR:
  231. case ARGUS_PLS_200_SENSOR:
  232. case ARGUS_PLS_360_SENSOR:
  233. case ARGUS_NET_PLS_200:{
  234. uint32_t tSize;
  235. uint8_t *tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 1024, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_100.png" );
  236. if ( tBuff ) {
  237. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_100, kID, tBuff, tSize );
  238. free( tBuff );
  239. };
  240. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 512, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_50.png" );
  241. if ( tBuff ) {
  242. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_50, kID, tBuff, tSize );
  243. free( tBuff );
  244. };
  245. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 256, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_25.png" );
  246. if ( tBuff ) {
  247. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_25, kID, tBuff, tSize );
  248. free( tBuff );
  249. };
  250. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 128, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_12.png" );
  251. if ( tBuff ) {
  252. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_12, kID, tBuff, tSize );
  253. free( tBuff );
  254. };
  255. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 1024, m_sLRF_DATA.base_shift, "data/assets/images/2d_MAP.png" );
  256. if ( tBuff ) {
  257. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_MAP, kID, tBuff, tSize );
  258. free( tBuff );
  259. };
  260. break;
  261. };
  262. case ARGUS_3D_SENSOR:{
  263. char * emptyBG = "data/assets/images/empty_3d.png";
  264. thresholdNode * ptr = (thresholdNode *) th_data;
  265. if ( fileExist( emptyBG ) ) {
  266. cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED );
  267. if( tImage.rows != 512 || tImage.cols != 1024 ){
  268. LOG_ERROR( "Background Image wrong size (should be 1024x512)!" );
  269. free( uid );
  270. return false;
  271. };
  272. uint8_t * tMemory = tImage.data;
  273. thresholdNode * cNode = NULL;
  274. uint8_t * cPixel = NULL;
  275. int pix = 0;
  276. int mem = 0;
  277. bool s_bit = false;
  278. bool no_data = false;
  279. float tVal;
  280. bool master = ( kID < 16 );
  281. for( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
  282. if( ( idx % 4 ) == 0 ){
  283. mem++;
  284. if ( master ) {
  285. cNode = ptr + TH_SIZE_NODES - mem - 1;
  286. } else {
  287. cNode = ptr + mem - 1;
  288. };
  289. if( !s_bit ) s_bit = cNode->values.sbit;
  290. if( !no_data ) no_data = ( cNode->values.cnt == 0 );
  291. if( !s_bit && !no_data ){
  292. if( byMinimum ) {
  293. tVal = ((float)cNode->values.min) / 4096.f;
  294. } else {
  295. tVal = ((float)cNode->values.max) / 4096.f;
  296. };
  297. };
  298. };
  299. if( ( idx % 9 ) == 0 ){
  300. if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
  301. cPixel = tMemory + (pix << 2);
  302. pix++;
  303. if( s_bit ) { // Set Red
  304. cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
  305. } else {
  306. if( no_data ) { // Set Blue
  307. cPixel[0] = 0xff; cPixel[1] = 0x00; cPixel[2] = 0x00; cPixel[3] = 0xff;
  308. } else {
  309. uint32_t tColor;
  310. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  311. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  312. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  313. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  314. cPixel[3] = tColor & 0xFF;
  315. };
  316. };
  317. s_bit = false;
  318. no_data = false;
  319. };
  320. };
  321. };
  322. char filename[256];
  323. sprintf( filename, "data/device_draws/%s_100.png", uid );
  324. //int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
  325. vector<int> compression_params;
  326. compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION );
  327. compression_params.push_back(9);
  328. if(! cv::imwrite( filename, tImage, compression_params ) ){
  329. tImage.release();
  330. free( uid );
  331. return false;
  332. };
  333. tImage.release();
  334. #ifdef DEBUG_EXTRA
  335. LOG("Draw Saved!");
  336. #endif
  337. cv::Mat tMap( Q_SCAN_COUNT, TH_LINE_NODES, CV_8UC4 );
  338. #ifdef DEBUG_EXTRA
  339. LOG("Map Creating");
  340. #endif
  341. tMemory = tMap.data;
  342. for( int j = 0; j < Q_SCAN_COUNT; j++ ){
  343. for( int i = 0; i < TH_LINE_NODES; i++ ){
  344. //cNode = ptr+(j*i);
  345. //cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
  346. int ids = 0;
  347. int idd = 0;
  348. if ( master ) {
  349. //cNode = ptr+makeIds( i, j , true );
  350. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  351. ids = makeIds( i, j , true );
  352. idd = 4 * makeIds( i, j , false );
  353. //cNode = ptr + ( i * j );
  354. //cPixel = tMemory + ( cSpace * i * j );
  355. } else {
  356. //cNode = ptr+makeIds( i, j , false );
  357. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  358. ids = makeIds( i, j , false );
  359. idd = 4 * makeIds( i, j , false );
  360. };
  361. cNode = ptr + ids ;
  362. cPixel = tMemory + idd;
  363. if( 0 ) { // Monochrome
  364. #ifdef CHECK_SUN_BIT
  365. if( cNode->values.sbit ) {
  366. cPixel[0] = 0;
  367. } else {
  368. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  369. };
  370. #else
  371. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  372. #endif
  373. } else {
  374. #ifdef CHECK_SUN_BIT
  375. if( cNode->values.sbit ) {
  376. // Set Red
  377. cPixel[0] = 0x00;
  378. cPixel[1] = 0x00;
  379. cPixel[2] = 0xff;
  380. cPixel[3] = 0xff;
  381. } else {
  382. if( cNode->values.cnt == 0 ) {
  383. // Set Blue
  384. cPixel[0] = 0xff;
  385. cPixel[1] = 0x00;
  386. cPixel[2] = 0x00;
  387. cPixel[3] = 0xff;
  388. } else {
  389. uint32_t tColor;
  390. float tVal = ((float) cNode->values.min ) / 4096.f;
  391. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  392. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  393. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  394. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  395. cPixel[3] = tColor & 0xFF;
  396. };
  397. };
  398. #else
  399. if( cNode->values.cnt == 0 ) {
  400. // Set Blue
  401. cPixel[0] = 0xff;
  402. cPixel[1] = 0x00;
  403. cPixel[2] = 0x00;
  404. cPixel[3] = 0xff;
  405. } else {
  406. uint32_t tColor;
  407. float tVal = ((float) cNode->values.min ) / 4096.f;
  408. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  409. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  410. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  411. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  412. cPixel[3] = tColor & 0xFF;
  413. };
  414. #endif
  415. };
  416. };
  417. };
  418. sprintf( filename, "data/device_draws/%s_map.png", uid );
  419. LOG(filename);
  420. if(! cv::imwrite( filename, tMap, compression_params ) ){
  421. tMap.release();
  422. free( uid );
  423. return false;
  424. };
  425. tMap.release();
  426. m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true );
  427. } else {
  428. LOG_ERROR( "Background Image is Not Found!" );
  429. free( uid );
  430. return false;
  431. };
  432. break;
  433. };
  434. };
  435. free( uid );
  436. return true;
  437. };
  438. /*
  439. #define STB_IMAGE_IMPLEMENTATION
  440. #include "../data/stbi/stb_image.h"
  441. #define STB_IMAGE_WRITE_IMPLEMENTATION
  442. #include "../data/stbi/stb_image_write.h"
  443. #undef STB_IMAGE_WRITE_IMPLEMENTATION
  444. #undef STB_IMAGE_IMPLEMENTATION
  445. bool argus3DLIDAR::saveTHPicture( thresholdNode *ptr, CSTR uid, bool master, bool byMinimum, bool monochrome ){
  446. uint8_t *tMemory = NULL;
  447. thresholdNode *cNode = NULL;
  448. uint8_t *cPixel = NULL;
  449. int cSpace;
  450. int x, y;
  451. tMemory = stbi_load( "data/assets/images/empty_3d.png", &x, &y, &cSpace, STBI_default );
  452. if( tMemory == NULL ){
  453. LOG_ERROR("Draw Memory Alloc Eror!");
  454. return false;
  455. };
  456. if( x != 1024 || y != 512 ){
  457. LOG("Wrong IMG Size!");
  458. free( tMemory );
  459. return NULL;
  460. };
  461. int pix = 0;
  462. int mem = 0;
  463. bool s_bit = false;
  464. bool no_data = false;
  465. float tVal;
  466. for ( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
  467. if( ( idx % 4 ) == 0 ){
  468. mem++;
  469. if ( master ) {
  470. cNode = ptr + TH_SIZE_NODES - mem - 1;
  471. } else {
  472. cNode = ptr + mem - 1;
  473. };
  474. if( !s_bit ) s_bit = cNode->values.sbit;
  475. if( !no_data ) no_data = ( cNode->values.cnt == 0 );
  476. if( !s_bit && !no_data ){
  477. if( byMinimum ) {
  478. tVal = ((float)cNode->values.min) / 4096.f;
  479. } else {
  480. tVal = ((float)cNode->values.max) / 4096.f;
  481. };
  482. };
  483. };
  484. if( ( idx % 9 ) == 0 ){
  485. if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
  486. cPixel = tMemory + (pix << 2);
  487. pix++;
  488. if( s_bit ) { // Set Red
  489. cPixel[0] = 0x00; cPixel[1] = 0xff; cPixel[2] = 0x00; cPixel[3] = 0xff;
  490. } else {
  491. if( no_data ) { // Set Blue
  492. cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
  493. } else {
  494. uint32_t tColor;
  495. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  496. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  497. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  498. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  499. cPixel[3] = tColor & 0xFF;
  500. };
  501. };
  502. s_bit = false;
  503. no_data = false;
  504. }
  505. };
  506. };
  507. char filename[256];
  508. sprintf( filename, "data/device_draws/%s_100.png", uid );
  509. int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
  510. free( tMemory );
  511. if( RetVal == 0 ) return false;
  512. if( monochrome ) {
  513. cSpace = 1;
  514. } else {
  515. cSpace = 4;
  516. };
  517. tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace );
  518. if( tMemory == NULL ){
  519. LOG_ERROR("Map Memory Alloc Eror!");
  520. return false;
  521. };
  522. for (int j = 0; j < Q_SCAN_COUNT; j++) {
  523. for ( int i = 0; i < TH_LINE_NODES; i++ ) {
  524. //cNode = ptr+(j*i);
  525. //cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
  526. int ids = 0;
  527. int idd = 0;
  528. if ( master ) {
  529. //cNode = ptr+makeIds( i, j , true );
  530. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  531. ids = makeIds( i, j , true );
  532. idd = cSpace * makeIds( i, j , false );
  533. //cNode = ptr + ( i * j );
  534. //cPixel = tMemory + ( cSpace * i * j );
  535. } else {
  536. //cNode = ptr+makeIds( i, j , false );
  537. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  538. ids = makeIds( i, j , false );
  539. idd = cSpace * makeIds( i, j , false );
  540. };
  541. cNode = ptr + ids ;
  542. cPixel = tMemory + idd;
  543. if( monochrome ) {
  544. #ifdef CHECK_SUN_BIT
  545. if( cNode->values.sbit ) {
  546. cPixel[0] = 0;
  547. } else {
  548. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  549. };
  550. #else
  551. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  552. #endif
  553. } else {
  554. #ifdef CHECK_SUN_BIT
  555. if( cNode->values.sbit ) {
  556. // Set Red
  557. cPixel[0] = 0x00;
  558. cPixel[1] = 0xff;
  559. cPixel[2] = 0x00;
  560. cPixel[3] = 0xff;
  561. } else {
  562. if( cNode->values.cnt == 0 ) {
  563. // Set Blue
  564. cPixel[0] = 0x00;
  565. cPixel[1] = 0x00;
  566. cPixel[2] = 0xff;
  567. cPixel[3] = 0xff;
  568. } else {
  569. uint32_t tColor;
  570. float tVal = ((float) cNode->values.min ) / 4096.f;
  571. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  572. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  573. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  574. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  575. cPixel[3] = tColor & 0xFF;
  576. };
  577. };
  578. #else
  579. if( cNode->values.cnt == 0 ) {
  580. // Set Blue
  581. cPixel[0] = 0x00;
  582. cPixel[1] = 0x00;
  583. cPixel[2] = 0xff;
  584. cPixel[3] = 0xff;
  585. } else {
  586. uint32_t tColor;
  587. float tVal = ((float) cNode->values.min ) / 4096.f;
  588. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  589. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  590. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  591. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  592. cPixel[3] = tColor & 0xFF;
  593. };
  594. #endif
  595. };
  596. };
  597. };
  598. sprintf( filename, "data/device_draws/%s_map.png", uid );
  599. RetVal = stbi_write_png( filename, TH_LINE_NODES, Q_SCAN_COUNT, cSpace, tMemory, TH_LINE_NODES * cSpace );
  600. free( tMemory );
  601. if( RetVal == 0 ) return false;
  602. return true;
  603. };
  604. */
  605. #undef LOG
  606. #undef LOG_ERROR