#include "HYDROData_Document.h"
#include "HYDROData_Lambert93.h"
#include "HYDROData_OperationsFactory.h"
+#include "HYDROData_Tool.h"
#include <TDataStd_RealArray.hxx>
#include <TDataStd_ByteArray.hxx>
#include <TDataStd_UAttribute.hxx>
#include <TDataStd_AsciiString.hxx>
+#include <NCSDefs.h>
+#include <NCSFile.h>
+
#ifdef WIN32
#pragma warning ( disable: 4251 )
#endif
#include <QStringList>
#include <QFile>
+#include <QFileInfo>
#ifdef WIN32
#pragma warning ( default: 4251 )
#endif
-#include <boost/math/special_functions/fpclassify.hpp>
-
static const Standard_GUID GUID_SELF_SPLIT("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
HYDROData_Image::HYDROData_Image()
if ( !aFilePath.isEmpty() )
{
aResList << QString( "" );
- aResList << QString( "%1.LoadImage( \"%2\" );" )
+ aResList << QString( "if not(%1.LoadImage( \"%2\" )):" )
.arg( anImageName ).arg( aFilePath );
+ aResList << QString( " raise ValueError('problem while loading image')" );
aResList << QString( "" );
// Dump transformation points for image
if ( !anIsByTwoPoints )
{
aResList.last().append( "," );
- aResList << QString( aGap + "QPoint( %1, %2 ) );" )
+ aResList << QString( aGap + "QPoint( %1, %2 ) )" )
.arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
}
else
{
- aResList.last().append( " );" );
+ aResList.last().append( " )" );
}
aResList << QString( "" );
}
aResList << QString( "%1.SetGlobalPoints( %2," )
.arg( anImageName ).arg( aTransformationMode );
aResList << QString( aGap + "QPointF( %1, %2 )," )
- .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
+ .arg( aTrsfPointA.x(), 0, 'f', 3 ).arg( aTrsfPointA.y(), 0, 'f', 3 );
aResList << QString( aGap + "QPointF( %1, %2 )" )
- .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
+ .arg( aTrsfPointB.x(), 0, 'f', 3 ).arg( aTrsfPointB.y(), 0, 'f', 3 );
if ( !anIsByTwoPoints )
{
aResList.last().append( "," );
- aResList << QString( aGap + "QPointF( %1, %2 ) );" )
- .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
+ aResList << QString( aGap + "QPointF( %1, %2 ) )" )
+ .arg( aTrsfPointC.x(), 0, 'f', 3 ).arg( aTrsfPointC.y(), 0, 'f', 3 );
}
else
{
- aResList.last().append( " );" );
+ aResList.last().append( " )" );
}
if ( aTransformationMode == ReferenceImage )
{
aResList << QString( "" );
- aResList << QString( "%1.SetOperatorName( \"%2\" );" )
+ aResList << QString( "%1.SetOperatorName( \"%2\" )" )
.arg( anImageName ).arg( anOperatorName );
ImageComposer_Operator* anImageOp =
aResList << anOpArgs;
aResList << QString( "" );
- aResList << QString( "%1.SetArgs( %2 );" )
+ aResList << QString( "%1.SetArgs( %2 )" )
.arg( anImageName ).arg( anOpArgsArrayName );
}
}
}
aResList << QString( "" );
- aResList << QString( "%1.Update();" ).arg( anImageName );
+ aResList << QString( "%1.Update()" ).arg( anImageName );
return aResList;
}
bool HYDROData_Image::LoadImage( const QString& theFilePath )
{
- QImage anImage( theFilePath );
+ QFileInfo aFI(theFilePath);
+ QImage anImage;
+ HYDROData_Image::ECW_FileInfo* theECWInfo;
+ if (aFI.suffix().toLower() == "ecw")
+ {
+ theECWInfo = new HYDROData_Image::ECW_FileInfo;
+ HYDROData_Image::OpenECW(theFilePath.toLatin1().data(), anImage, theECWInfo);
+ }
+ else
+ anImage = QImage(theFilePath);
SetImage( anImage );
-
SetFilePath( theFilePath );
+ return !anImage.isNull();
+}
+
+bool HYDROData_Image::OpenECW(char* theFileName, QImage& theImage, ECW_FileInfo* theECWInfo)
+{
+ NCSFileView *pNCSFileView;
+ NCSFileViewFileInfo *pNCSFileInfo;
+ NCSError eError = NCS_SUCCESS;
+ UINT32 band, nBands;
+ UINT32 XSize, YSize;
+ NCSecwInit();
+
+ eError = NCScbmOpenFileView(theFileName, &pNCSFileView, NULL);
+ if(eError != NCS_SUCCESS)
+ return false;
+
+ eError = NCScbmGetViewFileInfo(pNCSFileView, &pNCSFileInfo);
+ if(eError != NCS_SUCCESS)
+ return false;
+
+ XSize = pNCSFileInfo->nSizeX;
+ YSize = pNCSFileInfo->nSizeY;
+ nBands = pNCSFileInfo->nBands;
+ if (theECWInfo)
+ {
+ //ECW_CellUnits myCellSizeUnits;
+ CellSizeUnits aCellUnits = pNCSFileInfo->eCellSizeUnits;
+ if (aCellUnits == ECW_CELL_UNITS_METERS)
+ theECWInfo->myCellSizeUnits = ECW_CellUnits_Meters;
+ else if (aCellUnits == ECW_CELL_UNITS_DEGREES)
+ theECWInfo->myCellSizeUnits = ECW_CellUnits_Deg;
+ else if (aCellUnits == ECW_CELL_UNITS_FEET)
+ theECWInfo->myCellSizeUnits = ECW_CellUnits_Feet;
+ else
+ theECWInfo->myCellSizeUnits = ECW_CellUnits_Unknown;
+ theECWInfo->myCellIncrementX = pNCSFileInfo->fCellIncrementX;
+ theECWInfo->myCellIncrementY = pNCSFileInfo->fCellIncrementY;
+ theECWInfo->myOriginX = pNCSFileInfo->fOriginX;
+ theECWInfo->myOriginY = pNCSFileInfo->fOriginY;
+ theECWInfo->myXSize = pNCSFileInfo->nSizeX;
+ theECWInfo->myYSize = pNCSFileInfo->nSizeY;
+ }
+
+ std::vector<UINT32> band_list(nBands);
+ for( band = 0; band < nBands; band++ )
+ band_list[band] = band;
+
+ eError = NCScbmSetFileView(pNCSFileView, nBands, &band_list[0], 0, 0, XSize - 1, YSize - 1, XSize, YSize); //view an image into the original size
+
+ if(eError != NCS_SUCCESS)
+ {
+ NCScbmCloseFileView(pNCSFileView);
+ return false;
+ }
+
+ UINT8 *pRGBTriplets;
+ pRGBTriplets = (UINT8 *) malloc(XSize*3);
+
+ QImage anImage(XSize, YSize, QImage::Format_RGB32);
+
+ for(UINT32 line = 0; line < YSize; line++)
+ {
+ NCSEcwReadStatus eStatus;
+ eStatus = NCScbmReadViewLineRGB(pNCSFileView, pRGBTriplets);
+ if(eStatus == NCSECW_READ_OK)
+ {
+ QRgb* crp = (QRgb*)anImage.scanLine(line);
+ for(UINT32 j = 0; j < XSize; j++)
+ {
+ QRgb val = qRgb((int)pRGBTriplets[j*3],(int)pRGBTriplets[j*3+1],(int)pRGBTriplets[j*3+2]);
+ memcpy((void*)(crp+j), &val, sizeof(QRgb));
+ }
+ }
+ else
+ {
+ free(pRGBTriplets);
+ NCScbmCloseFileView(pNCSFileView);
+ return false;
+ }
+ }
+
+ free(pRGBTriplets);
+ NCScbmCloseFileView(pNCSFileView);
+ theImage = anImage;
+ return true;
+}
+bool HYDROData_Image::LoadImageECW( const QString& theFilePath )
+{
+ QImage anImage;
+ if (HYDROData_Image::OpenECW(theFilePath.toLatin1().data(), anImage, NULL))
+ {
+ SetImage( anImage );
+ SetFilePath( theFilePath );
+ }
return !anImage.isNull();
}
// Check the result
if ( !isDoubleOk ||
- boost::math::isnan( aDoubleValue ) ||
- boost::math::isinf( aDoubleValue ) ) {
+ HYDROData_Tool::IsNan( aDoubleValue ) ||
+ HYDROData_Tool::IsInf( aDoubleValue ) ) {
continue;
}