StenoseInterface.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. #include "StenoseInterface.h"
  2. #include "StenoseBase.h"
  3. #include "StenoseNBBase.h"
  4. #include "scale.h"
  5. #include "../Container/extendedimage.h"
  6. #include "../IO/DicomIO.h"
  7. #include "../Mouchard/Mouchard.h"
  8. #include <cmath>
  9. const CScale *g_pCurrentScale;
  10. #define SQR( x ) ( ( x ) * ( x ) )
  11. StenoseInterface::StenoseInterface()
  12. : Singleton< StenoseInterface >()
  13. {
  14. }
  15. bool StenoseInterface::initialize( std::string fileName, double pixelSizeX, double pixelSizeY )
  16. {
  17. bool status = false;
  18. if ( Mouchard::getInstance().IsDLLValid() )
  19. {
  20. m_image.Destroy();
  21. double m_pixelSizeX = pixelSizeX;
  22. double m_pixelSizeY = pixelSizeY;
  23. if (0)// DicomIO::getInstance().read( fileName, m_image ) )
  24. {
  25. if ( ( pixelSizeX < 0.0 ) && ( pixelSizeY < 0.0 ) )
  26. {
  27. m_pixelSizeX = m_image.GetResolutionX();
  28. m_pixelSizeY = m_image.GetResolutionY();
  29. }
  30. status = true;
  31. }
  32. else
  33. {
  34. status = false;
  35. }
  36. if ( status && ( m_pixelSizeX > 0.0 ) && ( m_pixelSizeY > 0.0 ) )
  37. {
  38. double pixelSize = m_pixelSizeX < m_pixelSizeY ? m_pixelSizeX : m_pixelSizeY;
  39. g_pCurrentScale = new CScale("DLL scale", pixelSize, pixelSize);
  40. }
  41. }
  42. return status;
  43. }
  44. bool StenoseInterface::initialize( const char* buffer, int width, int height, int bpp, bool upsideDown, double pixelSizeX, double pixelSizeY )
  45. {
  46. if ( Mouchard::getInstance().IsDLLValid() && buffer &&
  47. ( pixelSizeX > 0.0 ) && ( pixelSizeY > 0.0 ) &&
  48. ( ( bpp == 8 ) || ( bpp == 24 ) || ( bpp == 32 ) ) )
  49. {
  50. bool padding = false;
  51. const unsigned long destWidth = 3 * width;
  52. const long nextRow = upsideDown ? -2 * width * bpp / 8 : 0;
  53. register const char* p = buffer + ( upsideDown ? ( height - 1 ) * width * bpp / 8 : 0 );
  54. const int gap = padding ? ( 4 - destWidth & 0x3 ) & 0x3 : 0;
  55. //const unsigned long count = ( destWidth + gap ) * height;
  56. m_image.Destroy();
  57. if ( m_image.Create( width, height, 24 ) )
  58. {
  59. if ( bpp == 8 )
  60. {
  61. register char* q = (char*)m_image.GetBits();
  62. register int x;
  63. register int y;
  64. register char value;
  65. for ( y = height; y--; p += nextRow, q += gap )
  66. {
  67. x = width;
  68. while ( x-- )
  69. {
  70. value = *p++;
  71. *q++ = value;
  72. *q++ = value;
  73. *q++ = value;
  74. }
  75. }
  76. }
  77. else if ( bpp == 24 )
  78. {
  79. register char* q = (char*)m_image.GetBits();
  80. register int x;
  81. register int y;
  82. for ( y = height; y--; p += nextRow, q += gap )
  83. {
  84. x = destWidth;
  85. while ( x-- )
  86. {
  87. *q++ = *p++;
  88. }
  89. }
  90. }
  91. else if ( bpp == 32 )
  92. {
  93. register char* q = (char*)m_image.GetBits();
  94. register int x;
  95. register int y;
  96. for ( y = height; y--; p += nextRow, q += gap )
  97. {
  98. x = width;
  99. while ( x-- )
  100. {
  101. // Pour version Flex / Alchemy
  102. /*
  103. *q++ = *( p + 1 );
  104. *q++ = *( p + 2 );
  105. *q++ = *( p + 3 );
  106. p += 4;
  107. */
  108. *q++ = *( p + 0 );
  109. *q++ = *( p + 1 );
  110. *q++ = *( p + 2 );
  111. p += 4;
  112. }
  113. }
  114. }
  115. double pixelSize = ( pixelSizeX < pixelSizeY ) ? pixelSizeX : pixelSizeY;
  116. g_pCurrentScale = new CScale("DLL scale", pixelSize, pixelSize);
  117. return true;
  118. }
  119. }
  120. return false;
  121. }
  122. bool StenoseInterface::Threshold_2(int iMax, int left, int top, int right, int bottom, int ptx, int pty, CStenoseResult* result )
  123. {
  124. int retour;
  125. int i;
  126. Rect rcEllipse;
  127. retour = 0;
  128. if ( !m_image.IsNull() && result )
  129. {
  130. CStenoseNBBase cstenose;
  131. rcEllipse.left = left;
  132. rcEllipse.top = top; // Le top doit être inférieur au bottom
  133. rcEllipse.right = right;
  134. rcEllipse.bottom = bottom;
  135. retour = cstenose.Threshold_2(&m_image, iMax, rcEllipse, ptx, pty);
  136. // Remplissage des valeurs dans result
  137. result->resultNB->code_retour = retour;
  138. result->resultNB->code_debug1 = cstenose.m_debug1;
  139. result->resultNB->code_debug2 = cstenose.m_debug2;
  140. result->resultNB->code_debug3 = cstenose.m_debug3;
  141. result->resultNB->code_debug4 = cstenose.m_debug4;
  142. result->resultNB->code_debug5 = cstenose.m_debug5;
  143. result->resultNB->m_dblSurface = cstenose.Surface();
  144. result->resultNB->m_dblVesselArea = cstenose.m_dblVesselArea;
  145. result->resultNB->m_dblRatio = cstenose.Ratio();
  146. result->resultNB->m_dblDensity = cstenose.Density();
  147. result->resultNB->m_dwMean = cstenose.m_dwMean;
  148. if ( result->resultNB->m_dwPoints )
  149. {
  150. delete[] result->resultNB->m_pPoints;
  151. }
  152. result->resultNB->m_pPoints = new stenose::Point[ cstenose.m_dwPoints ];
  153. result->resultNB->m_dwPoints = cstenose.m_dwPoints;
  154. for ( i = 0; i < cstenose.m_dwPoints; i++ )
  155. {
  156. result->resultNB->m_pPoints[ i ].x = cstenose.m_pPoints[ i ].x;
  157. result->resultNB->m_pPoints[ i ].y = cstenose.m_pPoints[ i ].y;
  158. }
  159. return 1;
  160. }
  161. else
  162. {
  163. result->resultNB->code_retour = -1;
  164. }
  165. return 0;
  166. }
  167. bool StenoseInterface::Measure( int left, int top, int right, int bottom, CStenoseResult* result )
  168. {
  169. bool retour;
  170. int i;
  171. Rect rcEllipse;
  172. retour = false;
  173. if ( !m_image.IsNull() && result )
  174. {
  175. CStenoseBase cstenose;
  176. rcEllipse.left = left;
  177. rcEllipse.top = top; // Le top doit être inférieur au bottom
  178. rcEllipse.right = right;
  179. rcEllipse.bottom = bottom;
  180. retour = cstenose.Measure(&m_image, rcEllipse);
  181. // Remplissage des valeurs dans result
  182. result->result->code_retour = retour;
  183. result->result->code_debug1 = cstenose.m_debug1;
  184. result->result->code_debug2 = cstenose.m_debug2;
  185. result->result->code_debug3 = cstenose.m_debug3;
  186. result->result->code_debug4 = cstenose.m_debug4;
  187. result->result->code_debug5 = cstenose.m_debug5;
  188. result->result->m_dblEllipse = cstenose.SurfaceEllipse();
  189. result->result->m_dblStenose = cstenose.SurfaceStenose();
  190. result->result->m_dblRatio = cstenose.Ratio();
  191. if ( result->result->m_dwPoints )
  192. {
  193. delete[] result->result->m_pPoints;
  194. }
  195. result->result->m_pPoints = new stenose::Point[ cstenose.m_dwPoints ];
  196. result->result->m_dwPoints = cstenose.m_dwPoints;
  197. for ( i = 0; i < cstenose.m_dwPoints; i++ )
  198. {
  199. result->result->m_pPoints[ i ].x = cstenose.m_pPoints[ i ].x;
  200. result->result->m_pPoints[ i ].y = cstenose.m_pPoints[ i ].y;
  201. }
  202. return retour;
  203. }
  204. else
  205. {
  206. result->result->code_retour = -1;
  207. }
  208. return retour;
  209. }
  210. int StenoseInterface::getImageWidth()
  211. {
  212. return m_image.GetWidth();
  213. }
  214. int StenoseInterface::getImageHeight()
  215. {
  216. return m_image.GetHeight();
  217. }
  218. int StenoseInterface::getImageBitsPerPixel()
  219. {
  220. return m_image.GetBPP();
  221. }
  222. char* StenoseInterface::getPixelArray()
  223. {
  224. return (char*)m_image.GetBits();
  225. }