alchemystenose.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/resource.h>
  4. #include "StenoseResult.h"
  5. #include "StenoseInterfaceDLL.h"
  6. // Header file for AS3 interop APIs
  7. // this is linked in by the compiler (when using flacon)
  8. #include "AS3.h"
  9. using namespace stenose;
  10. stenose::StenoseResult m_result;
  11. stenose::StenoseNBResult m_resultNB;
  12. // Mesure de Sténose couleur
  13. static AS3_Val Measure(void* /*self*/, AS3_Val args)
  14. {
  15. bool success = false;
  16. AS3_Val retVal;
  17. unsigned int left, top, right, bottom;
  18. AS3_Val e_data = AS3_Undefined();
  19. double mmPerPixelX;
  20. unsigned int bpp, n;
  21. int i;
  22. //parse the arguments.
  23. AS3_ArrayValue( args, "IntType, IntType, IntType, IntType, DoubleType, AS3ValType", &left, &top, &right, &bottom, &mmPerPixelX, &e_data);
  24. retVal = AS3_Array("AS3ValType", NULL);
  25. bpp = 32 / 8;
  26. n = bpp * 768 * 576;
  27. char *datab = (char *) malloc(sizeof(char) * (n));
  28. AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET);
  29. AS3_ByteArray_readBytes((void *)datab, e_data, n);
  30. // Appel de la fonction de la librairie
  31. success = stenose::initializeFromRaw(datab, 768, 576, 32, 0, mmPerPixelX, mmPerPixelX);
  32. success = stenose::Measure(left, top, right, bottom, &m_result);
  33. AS3_Val data = AS3_Array("DoubleType, DoubleType, DoubleType, IntType, IntType, IntType, IntType, IntType, IntType", m_result.m_dblRatio, m_result.m_dblStenose, m_result.m_dblEllipse, m_result.m_dwPoints, m_result.code_debug1, m_result.code_debug2, m_result.code_debug3, m_result.code_debug4, m_result.code_debug5);
  34. AS3_Set(retVal, AS3_Int(0), data);
  35. for (i = 0; i < m_result.m_dwPoints; i++)
  36. {
  37. AS3_Val data2 = AS3_Array("IntType, IntType", m_result.m_pPoints[i].x, m_result.m_pPoints[i].y);
  38. AS3_Set(retVal, AS3_Int(i+1), data2);
  39. }
  40. free(datab);
  41. return retVal;
  42. }
  43. // Mesure de Sténose N&B
  44. static AS3_Val Threshold_2(void* /*self*/, AS3_Val args)
  45. {
  46. bool success = false;
  47. AS3_Val retVal;
  48. unsigned int imax, ptx, pty, left, top, right, bottom;
  49. AS3_Val e_data = AS3_Undefined();
  50. double mmPerPixelX;
  51. unsigned int bpp, n;
  52. int i;
  53. //parse the arguments.
  54. AS3_ArrayValue( args, "IntType, IntType, IntType, IntType, IntType, IntType, IntType, DoubleType, AS3ValType", &imax, &left, &top, &right, &bottom, &ptx, &pty, &mmPerPixelX, &e_data);
  55. retVal = AS3_Array("AS3ValType", NULL);
  56. bpp = 32 / 8;
  57. n = bpp * 768 * 576;
  58. char *datab = (char *) malloc(sizeof(char) * (n));
  59. AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET);
  60. AS3_ByteArray_readBytes((void *)datab, e_data, n);
  61. // Appel de la fonction de la librairie
  62. success = stenose::initializeFromRaw(datab, 768, 576, 32, 0, mmPerPixelX, mmPerPixelX);
  63. success = stenose::Threshold_2(imax, left, top, right, bottom, ptx, pty, &m_resultNB);
  64. AS3_Val data = AS3_Array("DoubleType, DoubleType, DoubleType, IntType, IntType, IntType, IntType, IntType, IntType", m_resultNB.m_dblRatio, m_resultNB.m_dblVesselArea, m_resultNB.m_dblDensity, m_resultNB.m_dwPoints, m_resultNB.code_debug1, m_resultNB.code_debug2, m_resultNB.code_debug3, m_resultNB.code_debug4, m_resultNB.code_debug5);
  65. AS3_Set(retVal, AS3_Int(0), data);
  66. for (i = 0; i < m_resultNB.m_dwPoints; i++)
  67. {
  68. AS3_Val data2 = AS3_Array("IntType, IntType", m_resultNB.m_pPoints[i].x, m_resultNB.m_pPoints[i].y);
  69. AS3_Set(retVal, AS3_Int(i+1), data2);
  70. }
  71. free(datab);
  72. return retVal;
  73. }
  74. //entry point for code
  75. int main()
  76. {
  77. const rlim_t kStackSize = 32 * 1024 * 1024; // min stack size = 32 MB
  78. struct rlimit rl;
  79. int resultStack;
  80. resultStack = getrlimit(RLIMIT_STACK, &rl);
  81. if (resultStack == 0)
  82. {
  83. if (rl.rlim_cur < kStackSize)
  84. {
  85. rl.rlim_cur = kStackSize;
  86. resultStack = setrlimit(RLIMIT_STACK, &rl);
  87. }
  88. }
  89. //define the methods exposed to ActionScript
  90. //typed as an ActionScript Function instance
  91. AS3_Val MeasureMethod = AS3_Function( NULL, Measure );
  92. AS3_Val Threshold_2Method = AS3_Function( NULL, Threshold_2 );
  93. // construct an object that holds references to the functions
  94. AS3_Val result = AS3_Object( "Measure: AS3ValType, Threshold_2: AS3ValType", MeasureMethod, Threshold_2Method );
  95. // Release
  96. AS3_Release( MeasureMethod );
  97. AS3_Release( Threshold_2Method );
  98. // notify that we initialized -- THIS DOES NOT RETURN!
  99. AS3_LibInit( result );
  100. // should never get here!
  101. return 0;
  102. }