#include <TDataStd_RealArray.hxx>
#include <TDataStd_AsciiString.hxx>
+#include <TDataStd_Integer.hxx>
#include <QFile>
#include <QFileInfo>
#include <QPolygonF>
#include <QStringList>
+#include <math.h>
+
+#define _TIMER
+#ifdef _TIMER
+#include <OSD_Timer.hxx>
+#endif
+
#define PYTHON_BATHYMETRY_ID "KIND_BATHYMETRY"
{
QStringList aResList;
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
if ( aDocument.IsNull() )
return aResList;
aResList << QString( "%1.SetName( \"%2\" );" )
.arg( aBathymetryName ).arg( aBathymetryName );
+ aResList << QString( "%1.SetAltitudesInverted( %2 );" )
+ .arg( aBathymetryName ).arg( IsAltitudesInverted() );
+
QString aFilePath = GetFilePath();
if ( !aFilePath.isEmpty() )
{
aCoordsArray->SetValue( i * 3 + 1, aPoint.Y() );
aCoordsArray->SetValue( i * 3 + 2, aPoint.Z() );
}
+
+ SetToUpdate( true );
}
HYDROData_Bathymetry::AltitudePoints HYDROData_Bathymetry::GetAltitudePoints() const
{
AltitudePoints aPoints;
+ TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
+ if ( aLabel.IsNull() )
+ return aPoints;
+
Handle(TDataStd_RealArray) aCoordsArray;
- if ( !myLab.FindChild( DataTag_AltitudePoints ).FindAttribute( TDataStd_RealArray::GetID(), aCoordsArray ) )
+ if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aCoordsArray ) )
return aPoints;
for ( int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n; )
void HYDROData_Bathymetry::RemoveAltitudePoints()
{
- TDF_Label aLab = myLab.FindChild( DataTag_AltitudePoints );
- aLab.ForgetAllAttributes();
+ TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
+ if ( !aLabel.IsNull() )
+ {
+ aLabel.ForgetAllAttributes();
+ SetToUpdate( true );
+ }
}
void interpolateAltitudeForPoints( const gp_XY& thePoint,
double HYDROData_Bathymetry::GetAltitudeForPoint( const gp_XY& thePoint ) const
{
- double aResAltitude = GetInvalidAltitude();
+ double anInvalidAltitude = GetInvalidAltitude();
+ double aResAltitude = anInvalidAltitude;
AltitudePoints anAltitudePoints = GetAltitudePoints();
if ( anAltitudePoints.isEmpty() )
// [ 0 (top-left) ] [ 1 (top-right) ]
// thePoint
// [ 2 (bot-left) ] [ 3 (bot-right) ]
- AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, GetInvalidAltitude() ),
- AltitudePoint( DBL_MAX, -DBL_MAX, GetInvalidAltitude() ),
- AltitudePoint( -DBL_MAX, DBL_MAX, GetInvalidAltitude() ),
- AltitudePoint( DBL_MAX, DBL_MAX, GetInvalidAltitude() ) };
+ AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, anInvalidAltitude ),
+ AltitudePoint( DBL_MAX, -DBL_MAX, anInvalidAltitude ),
+ AltitudePoint( -DBL_MAX, DBL_MAX, anInvalidAltitude ),
+ AltitudePoint( DBL_MAX, DBL_MAX, anInvalidAltitude ) };
AltitudePoints::const_iterator aListItBeg = anAltitudePoints.constBegin();
AltitudePoints::const_iterator aListItEnd = anAltitudePoints.constEnd();
aBoundingRect << QPointF( aPoint.X(), aPoint.Y() );
}
+ const double LIMIT = 1E300;
+ if( fabs( aBounds[ 0 ].X() ) > LIMIT || fabs( aBounds[ 0 ].Y() ) > LIMIT ||
+ fabs( aBounds[ 1 ].X() ) > LIMIT || fabs( aBounds[ 1 ].Y() ) > LIMIT ||
+ fabs( aBounds[ 2 ].X() ) > LIMIT || fabs( aBounds[ 2 ].Y() ) > LIMIT ||
+ fabs( aBounds[ 3 ].X() ) > LIMIT || fabs( aBounds[ 3 ].Y() ) > LIMIT )
+ return anInvalidAltitude;
+
+
// Check if requested point is inside of our bounding rectangle
if ( !aBoundingRect.boundingRect().contains( thePoint.X(), thePoint.Y() ) )
return aResAltitude;
{
QString aRes;
- Handle(TDataStd_AsciiString) anAsciiStr;
- if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
- aRes = QString( anAsciiStr->Get().ToCString() );
+ TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
+ if ( !aLabel.IsNull() )
+ {
+ Handle(TDataStd_AsciiString) anAsciiStr;
+ if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
+ aRes = QString( anAsciiStr->Get().ToCString() );
+ }
+
+ return aRes;
+}
+
+void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted,
+ const bool theIsUpdate )
+{
+ bool anIsAltitudesInverted = IsAltitudesInverted();
+ if ( anIsAltitudesInverted == theIsInverted )
+ return;
+
+ TDataStd_Integer::Set( myLab.FindChild( DataTag_AltitudesInverted ), (Standard_Integer)theIsInverted );
+
+ SetToUpdate( true );
+
+ if ( !theIsUpdate )
+ return;
+
+ // Update altitude points
+ AltitudePoints anAltitudePoints = GetAltitudePoints();
+ if ( anAltitudePoints.isEmpty() )
+ return;
+
+ AltitudePoints::iterator aListItBeg = anAltitudePoints.begin();
+ AltitudePoints::iterator aListItEnd = anAltitudePoints.end();
+ for ( ; aListItBeg != aListItEnd; ++aListItBeg )
+ {
+ AltitudePoint& aPoint = *aListItBeg;
+ aPoint.SetZ( aPoint.Z() * -1 );
+ }
+
+ SetAltitudePoints( anAltitudePoints );
+}
+
+bool HYDROData_Bathymetry::IsAltitudesInverted() const
+{
+ bool aRes = false;
+
+ TDF_Label aLabel = myLab.FindChild( DataTag_AltitudesInverted, false );
+ if ( !aLabel.IsNull() )
+ {
+ Handle(TDataStd_Integer) anIntVal;
+ if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
+ aRes = (bool)anIntVal->Get();
+ }
return aRes;
}
}
bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,
- AltitudePoints& thePoints )
+ AltitudePoints& thePoints ) const
{
if ( !theFile.isOpen() )
return false;
// 2. X(float) Y(float) Z(float)
// ...
+#ifdef _TIMER
+ OSD_Timer aTimer;
+ aTimer.Start();
+#endif
+
+ bool anIsAltitudesInverted = IsAltitudesInverted();
while ( !theFile.atEnd() )
{
QString aLine = theFile.readLine().simplified();
if ( aLine.isEmpty() )
continue;
- QStringList aValues = aLine.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
+ QStringList aValues = aLine.split( ' ', QString::SkipEmptyParts );
if ( aValues.length() < 3 )
return false;
aPoint.SetX( anX.toDouble( &isXOk ) );
aPoint.SetY( anY.toDouble( &isYOk ) );
- aPoint.SetZ( aZ.toDouble( &isZOk ) );
+ aPoint.SetZ( aZ.toDouble( &isZOk ) );
if ( !isXOk || !isYOk || !isZOk )
return false;
+ // Invert the z value if requested
+ if ( anIsAltitudesInverted )
+ aPoint.SetZ( -aPoint.Z() );
+
thePoints << aPoint;
}
+#ifdef _TIMER
+ aTimer.Stop();
+ std::ofstream stream( "W:/HYDRO/WORK/log.txt", std::ofstream::out );
+ aTimer.Show( stream );
+#endif
+
return true;
}