#include "EIMInterface.h" #include "EIMBase.h" #include "scale.h" #include "../Container/ExtendedImage.h" #include "../IO/DicomIO.h" #include "../Mouchard/Mouchard.h" #include 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(); }