| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #include "EIMInterface.h"
- #include "EIMBase.h"
- #include "scale.h"
- #include "../Container/ExtendedImage.h"
- #include "../IO/DicomIO.h"
- #include "../Mouchard/Mouchard.h"
- #include <cmath>
- const CScale *g_pCurrentScale;
- #define SQR( x ) ( ( x ) * ( x ) )
- EIMInterface::EIMInterface()
- : Singleton< EIMInterface >(),
- m_p0( 0, 0 ),
- m_p1( 0, 0 )
- {
- }
- bool EIMInterface::initialize( std::string fileName, double pixelSizeX, double pixelSizeY )
- {
- bool status = false;
- if ( Mouchard::getInstance().IsDLLValid() )
- {
- m_image.Destroy();
- double m_pixelSizeX = pixelSizeX;
- double m_pixelSizeY = pixelSizeY;
- if ( DicomIO::getInstance().read( fileName, m_image ) )
- {
- if ( ( pixelSizeX < 0.0 ) && ( pixelSizeY < 0.0 ) )
- {
- m_pixelSizeX = m_image.GetResolutionX();
- m_pixelSizeY = m_image.GetResolutionY();
- }
- status = true;
- }
- else
- {
- status = false;
- }
- if ( status && ( m_pixelSizeX > 0.0 ) && ( m_pixelSizeY > 0.0 ) )
- {
- double pixelSize = m_pixelSizeX < m_pixelSizeY ? m_pixelSizeX : m_pixelSizeY;
- g_pCurrentScale = new CScale("DLL scale", pixelSize, pixelSize);
- }
- }
- return status;
- }
- bool EIMInterface::initialize( const char* buffer, int width, int height, int bpp, bool upsideDown, double pixelSizeX, double pixelSizeY )
- {
- if ( Mouchard::getInstance().IsDLLValid() && buffer &&
- ( pixelSizeX > 0.0 ) && ( pixelSizeY > 0.0 ) &&
- ( ( bpp == 8 ) || ( bpp == 24 ) || ( bpp == 32 ) ) )
- {
- bool padding = false;
- const unsigned long destWidth = 3 * width;
- const long nextRow = upsideDown ? -2 * width * bpp / 8 : 0;
- register const char* p = buffer + ( upsideDown ? ( height - 1 ) * width * bpp / 8 : 0 );
- const int gap = padding ? ( 4 - destWidth & 0x3 ) & 0x3 : 0;
- //const unsigned long count = ( destWidth + gap ) * height;
- m_image.Destroy();
- if ( m_image.Create( width, height, 24 ) )
- {
- if ( bpp == 8 )
- {
- register char* q = m_image.GetBuffer();
- register int x;
- register int y;
- register char value;
- for ( y = height; y--; p += nextRow, q += gap )
- {
- x = width;
- while ( x-- )
- {
- value = *p++;
- *q++ = value;
- *q++ = value;
- *q++ = value;
- }
- }
- }
- else if ( bpp == 24 )
- {
- register char* q = m_image.GetBuffer();
- register int x;
- register int y;
- for ( y = height; y--; p += nextRow, q += gap )
- {
- x = destWidth;
- while ( x-- )
- {
- *q++ = *p++;
- }
- }
- }
- else if ( bpp == 32 )
- {
- register char* q = m_image.GetBuffer();
- register int x;
- register int y;
- for ( y = height; y--; p += nextRow, q += gap )
- {
- x = width;
- while ( x-- )
- {
- *q++ = *p;
- *q++ = *( p + 1 );
- *q++ = *( p + 2 );
- p += 4;
- }
- }
- }
- double pixelSize = ( pixelSizeX < pixelSizeY ) ? pixelSizeX : pixelSizeY;
- g_pCurrentScale = new CScale("DLL scale", pixelSize, pixelSize);
- return true;
- }
- }
- return false;
- }
- bool EIMInterface::setFirstPoint( int x, int y )
- {
- if ( !m_image.IsNull() )
- {
- m_p0.x = x;
- m_p0.y = y;
- return true;
- }
- return false;
- }
- float EIMInterface::getDistanceToFirstPoint( int x, int y )
- {
- if ( g_pCurrentScale && !m_image.IsNull() )
- {
- Point pt( x, y );
- return (float)g_pCurrentScale->Distance( pt, m_p0 );
- }
-
- return 0.0f;
- }
- bool EIMInterface::setSecondPoint( int x, int y, CEIMResult* result )
- {
- if ( !m_image.IsNull() && result )
- {
- m_p1.x = x;
- m_p1.y = y;
- CEIMBase ceim;
- ceim.SetEimAssisted( true );
- ceim.Measure(&m_image, m_p0, m_p1, false, result);
- result->result->p0.x = m_p0.x;
- result->result->p0.y = m_p0.y;
- result->result->p1.x = m_p1.x;
- result->result->p1.y = m_p1.y;
- result->result->distance = g_pCurrentScale->Distance( result->result->numberOfPoints );
- return true;
- }
- return false;
- }
- int EIMInterface::getImageWidth()
- {
- return m_image.GetWidth();
- }
- int EIMInterface::getImageHeight()
- {
- return m_image.GetHeight();
- }
- int EIMInterface::getImageBitsPerPixel()
- {
- return m_image.GetBpp();
- }
- char* EIMInterface::getPixelArray()
- {
- return m_image.GetBuffer();
- }
|