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.

686 lines
28 KiB

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