| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/resource.h>
- #include "StenoseResult.h"
- #include "StenoseInterfaceDLL.h"
- // Header file for AS3 interop APIs
- // this is linked in by the compiler (when using flacon)
- #include "AS3.h"
- using namespace stenose;
- stenose::StenoseResult m_result;
- stenose::StenoseNBResult m_resultNB;
- // Mesure de Sténose couleur
- static AS3_Val Measure(void* /*self*/, AS3_Val args)
- {
- bool success = false;
- AS3_Val retVal;
- unsigned int left, top, right, bottom;
- AS3_Val e_data = AS3_Undefined();
- double mmPerPixelX;
- unsigned int bpp, n;
- int i;
-
- //parse the arguments.
- AS3_ArrayValue( args, "IntType, IntType, IntType, IntType, DoubleType, AS3ValType", &left, &top, &right, &bottom, &mmPerPixelX, &e_data);
- retVal = AS3_Array("AS3ValType", NULL);
- bpp = 32 / 8;
- n = bpp * 768 * 576;
- char *datab = (char *) malloc(sizeof(char) * (n));
- AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET);
- AS3_ByteArray_readBytes((void *)datab, e_data, n);
- // Appel de la fonction de la librairie
- success = stenose::initializeFromRaw(datab, 768, 576, 32, 0, mmPerPixelX, mmPerPixelX);
-
- success = stenose::Measure(left, top, right, bottom, &m_result);
-
- 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);
- AS3_Set(retVal, AS3_Int(0), data);
-
- for (i = 0; i < m_result.m_dwPoints; i++)
- {
- AS3_Val data2 = AS3_Array("IntType, IntType", m_result.m_pPoints[i].x, m_result.m_pPoints[i].y);
- AS3_Set(retVal, AS3_Int(i+1), data2);
- }
- free(datab);
- return retVal;
- }
- // Mesure de Sténose N&B
- static AS3_Val Threshold_2(void* /*self*/, AS3_Val args)
- {
- bool success = false;
- AS3_Val retVal;
- unsigned int imax, ptx, pty, left, top, right, bottom;
- AS3_Val e_data = AS3_Undefined();
- double mmPerPixelX;
- unsigned int bpp, n;
- int i;
-
- //parse the arguments.
- AS3_ArrayValue( args, "IntType, IntType, IntType, IntType, IntType, IntType, IntType, DoubleType, AS3ValType", &imax, &left, &top, &right, &bottom, &ptx, &pty, &mmPerPixelX, &e_data);
- retVal = AS3_Array("AS3ValType", NULL);
- bpp = 32 / 8;
- n = bpp * 768 * 576;
- char *datab = (char *) malloc(sizeof(char) * (n));
- AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET);
- AS3_ByteArray_readBytes((void *)datab, e_data, n);
- // Appel de la fonction de la librairie
- success = stenose::initializeFromRaw(datab, 768, 576, 32, 0, mmPerPixelX, mmPerPixelX);
-
- success = stenose::Threshold_2(imax, left, top, right, bottom, ptx, pty, &m_resultNB);
-
- 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);
- AS3_Set(retVal, AS3_Int(0), data);
- for (i = 0; i < m_resultNB.m_dwPoints; i++)
- {
- AS3_Val data2 = AS3_Array("IntType, IntType", m_resultNB.m_pPoints[i].x, m_resultNB.m_pPoints[i].y);
- AS3_Set(retVal, AS3_Int(i+1), data2);
- }
-
- free(datab);
-
- return retVal;
- }
-
- //entry point for code
- int main()
- {
- const rlim_t kStackSize = 32 * 1024 * 1024; // min stack size = 32 MB
- struct rlimit rl;
-
- int resultStack;
- resultStack = getrlimit(RLIMIT_STACK, &rl);
- if (resultStack == 0)
- {
- if (rl.rlim_cur < kStackSize)
- {
- rl.rlim_cur = kStackSize;
- resultStack = setrlimit(RLIMIT_STACK, &rl);
- }
- }
-
- //define the methods exposed to ActionScript
- //typed as an ActionScript Function instance
- AS3_Val MeasureMethod = AS3_Function( NULL, Measure );
-
- AS3_Val Threshold_2Method = AS3_Function( NULL, Threshold_2 );
-
- // construct an object that holds references to the functions
- AS3_Val result = AS3_Object( "Measure: AS3ValType, Threshold_2: AS3ValType", MeasureMethod, Threshold_2Method );
- // Release
- AS3_Release( MeasureMethod );
-
- AS3_Release( Threshold_2Method );
-
- // notify that we initialized -- THIS DOES NOT RETURN!
- AS3_LibInit( result );
- // should never get here!
- return 0;
- }
|