#include <ImageComposer_MetaTypes.h>
#include <QStringList>
+#include <QFile>
+
+#include <boost/math/special_functions/fpclassify.hpp>
static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
{
UpdateTrsf();
}
+
+ SetToUpdate( false );
}
QVariant HYDROData_Image::GetDataVariant()
}
else
{
+ QImage anImage;
+
+ // convert 8-bits images
+ if ( theImage.format() == QImage::Format_Indexed8 ) {
+ anImage = theImage.convertToFormat( QImage::Format_RGB32 );
+ } else {
+ anImage = theImage;
+ }
+
// store width, height, bytes per line and format in integer array
Handle(TDataStd_IntegerArray) aParams;
if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
}
- aParams->SetValue(1, theImage.width());
- aParams->SetValue(2, theImage.height());
- aParams->SetValue(3, theImage.bytesPerLine());
- aParams->SetValue(4, (int)(theImage.format()));
+ aParams->SetValue(1, anImage.width());
+ aParams->SetValue(2, anImage.height());
+ aParams->SetValue(3, anImage.bytesPerLine());
+ aParams->SetValue(4, (int)(anImage.format()));
// store data of image in byte array
- const char* aData = (const char*)(theImage.bits());
- SaveByteArray(0, aData, theImage.byteCount());
+ const char* aData = (const char*)(anImage.bits());
+ SaveByteArray(0, aData, anImage.byteCount());
}
SetToUpdate( true );
return true;
}
+bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
+{
+ bool aRes = false;
+
+ // Try to open the file
+ QFile aFile( theFileName );
+ if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
+ return aRes;
+ }
+
+ QPointF aPointA, aPointB;
+ double aXmin, anYmin, aXmax, anYmax;
+ aXmin = anYmin = aXmax = anYmax = -1;
+
+ while ( !aFile.atEnd() &&
+ ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
+ // Read line
+ QString aLine = aFile.readLine().simplified();
+ aLine.replace( " ", "" );
+ if ( aLine.isEmpty() ) {
+ continue;
+ }
+
+ // Try to read double value after ":"
+ bool isDoubleOk = false;
+ double aDoubleValue = -1;
+ QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
+ if ( aValues.count() == 2 ) {
+ aDoubleValue = aValues.last().toDouble( &isDoubleOk );
+ }
+
+ // Check the result
+ if ( !isDoubleOk ||
+ boost::math::isnan( aDoubleValue ) ||
+ boost::math::isinf( aDoubleValue ) ) {
+ continue;
+ }
+
+ // Set the value
+ if ( aLine.startsWith( "Xminimum" ) ) {
+ aXmin = aDoubleValue;
+ }
+ else if ( aLine.startsWith( "Yminimum" ) ) {
+ anYmin = aDoubleValue;
+ }
+ else if ( aLine.startsWith( "Xmaximum" ) ) {
+ aXmax = aDoubleValue;
+ }
+ else if ( aLine.startsWith( "Ymaximum" ) ) {
+ anYmax = aDoubleValue;
+ }
+ }
+
+ // Close the file
+ aFile.close();
+
+ if ( aXmin >= 0 && anYmin >= 0 ) {
+ aPointA.setX( aXmin );
+ aPointA.setY( anYmin );
+ }
+
+ if ( aXmax >= 0 && anYmax >= 0 ) {
+ aPointB.setX( aXmax );
+ aPointB.setY( anYmax );
+ }
+
+ if ( !aPointA.isNull() && !aPointB.isNull() ) {
+ SetGlobalPoints( ManualCartesian, aPointA, aPointB );
+ aRes = true;
+ }
+
+ return aRes;
+}
+
bool HYDROData_Image::HasGlobalPoints() const
{
TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );