1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_Bathymetry.h"
20 #include "HYDROData_Document.h"
21 #include "HYDROData_Tool.h"
22 #include "HYDROData_PolylineXY.h"
27 #include <TDataStd_RealArray.hxx>
28 #include <TDataStd_AsciiString.hxx>
29 #include <TDataStd_Integer.hxx>
36 #include <QStringList>
42 #include <OSD_Timer.hxx>
46 #include "HYDRO_trace.hxx"
48 IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
49 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
51 //HYDROData_QuadtreeNode* HYDROData_Bathymetry::myQuadtree = 0;
52 std::map<int, HYDROData_QuadtreeNode*> HYDROData_Bathymetry::myQuadtrees;
54 HYDROData_Bathymetry::HYDROData_Bathymetry()
55 : HYDROData_IAltitudeObject()
57 //DEBTRACE("HYDROData_Bathymetry constructor start " << this);
59 // myQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
60 //DEBTRACE("HYDROData_Bathymetry constructor end " << this);
63 HYDROData_Bathymetry::~HYDROData_Bathymetry()
65 //DEBTRACE("HYDROData_Bathymetry destructor start " << this);
68 // Nodes_3D::iterator it = myListOfNodes.begin();
69 // for( ; it != myListOfNodes.end(); ++it)
71 // myListOfNodes.clear();
74 QStringList HYDROData_Bathymetry::DumpToPython( const QString& thePyScriptPath,
75 MapOfTreatedObjects& theTreatedObjects ) const
77 QStringList aResList = dumpObjectCreation( theTreatedObjects );
78 QString aBathymetryName = GetObjPyName();
80 aResList << QString( "%1.SetAltitudesInverted( %2 )" )
81 .arg( aBathymetryName ).arg( IsAltitudesInverted() );
83 TCollection_AsciiString aFilePath = GetFilePath();
84 aResList << QString( "if not(%1.ImportFromFile( \"%2\" )):" )
85 .arg( aBathymetryName ).arg( aFilePath.ToCString() );
86 aResList << QString( " raise ValueError('problem while loading bathymetry')" );
87 aResList << QString( "" );
88 aResList << QString( "%1.Update()" ).arg( aBathymetryName );
89 aResList << QString( "" );
94 void HYDROData_Bathymetry::SetAltitudePoints( const AltitudePoints& thePoints )
96 RemoveAltitudePoints();
98 if ( thePoints.IsEmpty() )
102 Handle(TDataStd_RealArray) aCoordsArray =
103 TDataStd_RealArray::Set( myLab.FindChild( DataTag_AltitudePoints ), 0, thePoints.Length() * 3 - 1 );
105 AltitudePoints::Iterator anIter( thePoints );
106 for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
108 const AltitudePoint& aPoint = anIter.Value();
110 aCoordsArray->SetValue( i * 3, aPoint.X() );
111 aCoordsArray->SetValue( i * 3 + 1, aPoint.Y() );
112 aCoordsArray->SetValue( i * 3 + 2, aPoint.Z() );
118 HYDROData_Bathymetry::AltitudePoints HYDROData_Bathymetry::GetAltitudePoints(bool IsConvertToGlobal) const
120 AltitudePoints aPoints;
122 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
123 if ( aLabel.IsNull() )
126 Handle(TDataStd_RealArray) aCoordsArray;
127 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aCoordsArray ) )
130 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
131 for ( int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n; )
136 AltitudePoint aPoint;
137 aPoint.SetX( aCoordsArray->Value( i++ ) );
138 aPoint.SetY( aCoordsArray->Value( i++ ) );
139 aPoint.SetZ( aCoordsArray->Value( i++ ) );
141 if( IsConvertToGlobal )
142 aDoc->Transform( aPoint, false );
143 aPoints.Append( aPoint );
149 HYDROData_QuadtreeNode* HYDROData_Bathymetry::GetQuadtreeNodes() const
151 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
154 int labkey = myLab.Tag();
155 int altkey = aLabel.Tag();
156 //DEBTRACE("GetQuadtreeNodes this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
157 // if (myQuadtree->isEmpty() )
158 if (myQuadtrees.find(labkey) == myQuadtrees.end())
160 DEBTRACE("GetQuadtreeNodes init " << this << " " << labkey);
161 HYDROData_QuadtreeNode* aQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
162 myQuadtrees[labkey] = aQuadtree;
163 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
167 Handle(TDataStd_RealArray) aCoordsArray;
168 if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
171 Nodes_3D* aListOfNodes = new Nodes_3D();
173 for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
178 double x = aCoordsArray->Value(i++);
179 double y = aCoordsArray->Value(i++);
180 double z = aCoordsArray->Value(i++);
181 gp_XYZ* aPoint = new gp_XYZ(x, y, z);
182 aListOfNodes->push_back(aPoint);
184 DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
185 aQuadtree->setNodesAndCompute(aListOfNodes);
189 return myQuadtrees[labkey];
192 void HYDROData_Bathymetry::RemoveAltitudePoints()
194 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
195 if ( !aLabel.IsNull() )
197 aLabel.ForgetAllAttributes();
202 void interpolateAltitudeForPoints( const gp_XY& thePoint,
203 const HYDROData_Bathymetry::AltitudePoint& theFirstPoint,
204 const HYDROData_Bathymetry::AltitudePoint& theSecPoint,
205 HYDROData_Bathymetry::AltitudePoint& theResPoint,
206 const bool& theIsVertical )
208 double aCoordX = thePoint.X();
209 double aCoordY = thePoint.Y();
213 aCoordX = theFirstPoint.X();
215 if ( !ValuesEquals( theFirstPoint.X(), theSecPoint.X() ) )
217 // Recalculate X coordinate by equation of line from two points
218 aCoordX = ( ( ( thePoint.Y() - theFirstPoint.Y() ) * ( theSecPoint.X() - theFirstPoint.X() ) ) /
219 ( theSecPoint.Y() - theFirstPoint.Y() ) ) + theFirstPoint.X();
224 aCoordY = theFirstPoint.Y();
226 if ( !ValuesEquals( theFirstPoint.Y(), theSecPoint.Y() ) )
228 // Recalculate y by equation of line from two points
229 aCoordY = ( ( ( thePoint.X() - theFirstPoint.X() ) * ( theSecPoint.Y() - theFirstPoint.Y() ) ) /
230 ( theSecPoint.X() - theFirstPoint.X() ) ) + theFirstPoint.Y();
234 theResPoint.SetX( aCoordX );
235 theResPoint.SetY( aCoordY );
237 // Calculate coefficient for interpolation
238 double aLength = Sqrt( Pow( theSecPoint.Y() - theFirstPoint.Y(), 2 ) +
239 Pow( theSecPoint.X() - theFirstPoint.X(), 2 ) );
241 double aInterCoeff = 0;
243 aInterCoeff = ( theSecPoint.Z() - theFirstPoint.Z() ) / aLength;
246 double aNewLength = Sqrt( Pow( theResPoint.Y() - theFirstPoint.Y(), 2 ) +
247 Pow( theResPoint.X() - theFirstPoint.X(), 2 ) );
249 // Calculate interpolated value
250 double aResVal = theFirstPoint.Z() + aInterCoeff * aNewLength;
252 theResPoint.SetZ( aResVal );
255 double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint) const
257 DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")");
258 double anInvalidAltitude = GetInvalidAltitude();
259 double aResAltitude = anInvalidAltitude;
261 HYDROData_QuadtreeNode* aQuadtree = GetQuadtreeNodes();
264 DEBTRACE(" no Quadtree");
268 std::map<double, const gp_XYZ*> dist2nodes;
269 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
270 while (dist2nodes.size() == 0)
272 aQuadtree->setPrecision(aQuadtree->getPrecision() *2);
273 DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
274 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
276 aQuadtree->NodesAround(thePoint, dist2nodes, 5.0);
277 if (dist2nodes.size())
279 std::map<double, const gp_XYZ*>::const_iterator it = dist2nodes.begin();
280 aResAltitude = it->second->Z();
281 DEBTRACE(" number of points found: " << dist2nodes.size() << " nearest z: " << aResAltitude);
285 DEBTRACE(" number of points found: 0");
291 // AltitudePoints anAltitudePoints = GetAltitudePoints();
292 // if ( anAltitudePoints.IsEmpty() )
293 // return aResAltitude;
295 // QPolygonF aBoundingRect;
298 // // [ 0 (top-left) ] [ 1 (top-right) ]
300 // // [ 2 (bot-left) ] [ 3 (bot-right) ]
301 // AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, anInvalidAltitude ),
302 // AltitudePoint( DBL_MAX, -DBL_MAX, anInvalidAltitude ),
303 // AltitudePoint( -DBL_MAX, DBL_MAX, anInvalidAltitude ),
304 // AltitudePoint( DBL_MAX, DBL_MAX, anInvalidAltitude ) };
306 // AltitudePoints::Iterator anIter( anAltitudePoints );
307 // for ( ; anIter.More(); anIter.Next() )
309 // const AltitudePoint& aPoint = anIter.Value();
311 // double aDeltaX = Abs( aPoint.X() ) - Abs( thePoint.X() );
312 // double aDeltaY = Abs( aPoint.Y() ) - Abs( thePoint.Y() );
314 // if ( ValuesEquals( aDeltaX, 0.0 ) ) // Both left and right sides
316 // if ( ValuesEquals( aDeltaY, 0.0 ) ) // Both top and bottom sides
318 // aResAltitude = aPoint.Z();
319 // return aResAltitude;
321 // else if ( aDeltaY < 0 ) // top side
324 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
325 // aBounds[ 0 ] = aPoint;
326 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
327 // aBounds[ 1 ] = aPoint;
332 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
333 // aBounds[ 2 ] = aPoint;
334 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
335 // aBounds[ 3 ] = aPoint;
338 // else if ( aDeltaX < 0 ) // left side
340 // if ( ValuesEquals( aDeltaY, 0.0 ) )
343 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
344 // aBounds[ 0 ] = aPoint;
345 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
346 // aBounds[ 2 ] = aPoint;
348 // else if ( aDeltaY < 0 )
350 // // top left corner
351 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
352 // aBounds[ 0 ] = aPoint;
356 // // bottom left corner
357 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
358 // aBounds[ 2 ] = aPoint;
361 // else // right side
363 // if ( ValuesEquals( aDeltaY, 0.0 ) )
366 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
367 // aBounds[ 1 ] = aPoint;
368 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
369 // aBounds[ 3 ] = aPoint;
371 // else if ( aDeltaY < 0 )
373 // // top right corner
374 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
375 // aBounds[ 1 ] = aPoint;
379 // // bottom right corner
380 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
381 // aBounds[ 3 ] = aPoint;
385 // // Update bounding rectangle of our global grid
386 // aBoundingRect << QPointF( aPoint.X(), aPoint.Y() );
389 // const double LIMIT = 1E300;
390 // if( fabs( aBounds[ 0 ].X() ) > LIMIT || fabs( aBounds[ 0 ].Y() ) > LIMIT ||
391 // fabs( aBounds[ 1 ].X() ) > LIMIT || fabs( aBounds[ 1 ].Y() ) > LIMIT ||
392 // fabs( aBounds[ 2 ].X() ) > LIMIT || fabs( aBounds[ 2 ].Y() ) > LIMIT ||
393 // fabs( aBounds[ 3 ].X() ) > LIMIT || fabs( aBounds[ 3 ].Y() ) > LIMIT )
394 // return anInvalidAltitude;
397 // // Check if requested point is inside of our bounding rectangle
398 // if ( !aBoundingRect.boundingRect().contains( thePoint.X(), thePoint.Y() ) )
399 // return aResAltitude;
401 // // Calculate result altitude for point
402 // AltitudePoint aFirstPoint( aBounds[ 0 ] ), aSecPoint( aBounds[ 1 ] );
404 // // At first we merge top and bottom borders
405 // if ( aBounds[ 0 ].Y() != aBounds[ 2 ].Y() || aBounds[ 0 ].X() != aBounds[ 2 ].X() )
406 // interpolateAltitudeForPoints( thePoint, aBounds[ 0 ], aBounds[ 2 ], aFirstPoint, true );
408 // if ( aBounds[ 1 ].Y() != aBounds[ 3 ].Y() || aBounds[ 1 ].X() != aBounds[ 3 ].X() )
409 // interpolateAltitudeForPoints( thePoint, aBounds[ 1 ], aBounds[ 3 ], aSecPoint, true );
411 // AltitudePoint aResPoint( aFirstPoint );
413 // // At last we merge left and right borders
414 // if ( aFirstPoint.Y() != aSecPoint.Y() || aFirstPoint.X() != aSecPoint.X() )
415 // interpolateAltitudeForPoints( thePoint, aFirstPoint, aSecPoint, aResPoint, false );
417 // aResAltitude = aResPoint.Z();
419 // return aResAltitude;
422 void HYDROData_Bathymetry::SetFilePath( const TCollection_AsciiString& theFilePath )
424 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
427 TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const
429 TCollection_AsciiString aRes;
431 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
432 if ( !aLabel.IsNull() )
434 Handle(TDataStd_AsciiString) anAsciiStr;
435 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
436 aRes = anAsciiStr->Get();
442 void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted,
443 const bool theIsUpdate )
445 bool anIsAltitudesInverted = IsAltitudesInverted();
446 if ( anIsAltitudesInverted == theIsInverted )
449 TDataStd_Integer::Set( myLab.FindChild( DataTag_AltitudesInverted ), (Standard_Integer)theIsInverted );
456 // Update altitude points
457 AltitudePoints anAltitudePoints = GetAltitudePoints();
458 if ( anAltitudePoints.IsEmpty() )
461 AltitudePoints::Iterator anIter( anAltitudePoints );
462 for ( ; anIter.More(); anIter.Next() )
464 AltitudePoint& aPoint = anIter.ChangeValue();
465 aPoint.SetZ( aPoint.Z() * -1 );
468 SetAltitudePoints( anAltitudePoints );
471 bool HYDROData_Bathymetry::IsAltitudesInverted() const
475 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudesInverted, false );
476 if ( !aLabel.IsNull() )
478 Handle(TDataStd_Integer) anIntVal;
479 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
480 aRes = (bool)anIntVal->Get();
486 bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName )
488 // Try to open the file
489 QFile aFile( theFileName.ToCString() );
490 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
495 QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
497 AltitudePoints aPoints;
499 // Try to import the file
500 if ( aFileSuf == "xyz" )
501 aRes = importFromXYZFile( aFile, aPoints );
502 else if ( aFileSuf == "asc" )
503 aRes = importFromASCFile( aFile, aPoints );
509 // Convert from global to local CS
510 Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
511 AltitudePoints::Iterator anIter( aPoints );
512 for ( ; anIter.More(); anIter.Next() )
514 AltitudePoint& aPoint = anIter.ChangeValue();
515 aDoc->Transform( aPoint, true );
520 // Update file path and altitude points of this Bathymetry
521 SetFilePath( theFileName );
522 SetAltitudePoints( aPoints );
525 return aRes && !aPoints.IsEmpty();
528 bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,
529 AltitudePoints& thePoints ) const
531 if ( !theFile.isOpen() )
534 // Strings in file is written as:
535 // 1. X(float) Y(float) Z(float)
536 // 2. X(float) Y(float) Z(float)
544 bool anIsAltitudesInverted = IsAltitudesInverted();
545 while ( !theFile.atEnd() )
547 QString aLine = theFile.readLine().simplified();
548 if ( aLine.isEmpty() )
551 QStringList aValues = aLine.split( ' ', QString::SkipEmptyParts );
552 if ( aValues.length() < 3 )
555 AltitudePoint aPoint;
557 QString anX = aValues.value( 0 );
558 QString anY = aValues.value( 1 );
559 QString aZ = aValues.value( 2 );
561 bool isXOk = false, isYOk = false, isZOk = false;
563 aPoint.SetX( anX.toDouble( &isXOk ) );
564 aPoint.SetY( anY.toDouble( &isYOk ) );
565 aPoint.SetZ( aZ.toDouble( &isZOk ) );
567 if ( !isXOk || !isYOk || !isZOk )
570 if ( HYDROData_Tool::IsNan( aPoint.X() ) || HYDROData_Tool::IsInf( aPoint.X() ) ||
571 HYDROData_Tool::IsNan( aPoint.Y() ) || HYDROData_Tool::IsInf( aPoint.Y() ) ||
572 HYDROData_Tool::IsNan( aPoint.Z() ) || HYDROData_Tool::IsInf( aPoint.Z() ) )
575 // Invert the z value if requested
576 if ( anIsAltitudesInverted )
577 aPoint.SetZ( -aPoint.Z() );
579 thePoints.Append( aPoint );
584 std::ofstream stream( "W:/HYDRO/WORK/log.txt", std::ofstream::out );
585 aTimer.Show( stream );
591 bool HYDROData_Bathymetry::importFromASCFile( QFile& theFile,
592 AltitudePoints& thePoints ) const
594 if ( !theFile.isOpen() )
598 QStringList aStrList;
607 aLine = theFile.readLine().simplified();
608 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
609 if ( aStrList.length() != 2 && aStrList[0].toLower() != "ncols" )
611 aNCols = aStrList[1].toInt();
613 aLine = theFile.readLine().simplified();
614 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
615 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nrows" )
617 aNRows = aStrList[1].toInt();
619 aLine = theFile.readLine().simplified();
620 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
621 if ( aStrList.length() != 2 && aStrList[0].toLower() != "xllcorner" )
623 anXllCorner = aStrList[1].toDouble();
625 aLine = theFile.readLine().simplified();
626 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
627 if ( aStrList.length() != 2 && aStrList[0].toLower() != "yllcorner" )
629 anYllCorner = aStrList[1].toDouble();
631 aLine = theFile.readLine().simplified();
632 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
633 if ( aStrList.length() != 2 && aStrList[0].toLower() != "cellsize" )
635 aCellSize = aStrList[1].toDouble();
637 aLine = theFile.readLine().simplified();
638 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
639 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nodata_value" )
641 aNoDataValue = aStrList[1].toDouble();
643 bool anIsAltitudesInverted = IsAltitudesInverted();
647 while ( !theFile.atEnd() )
649 aLine = theFile.readLine().simplified();
650 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
652 aStrLength = aStrList.length();
653 if ( aStrLength == 0 )
656 if ( aStrLength != aNRows )
659 for (int j = 0; j < aNCols; j++)
661 if (aStrList[j].toDouble() != aNoDataValue)
663 AltitudePoint aPoint;
664 aPoint.SetX(anXllCorner + aCellSize*(j + 0.5));
665 aPoint.SetY(anYllCorner + aCellSize*(aNRows - i + 0.5));
666 aPoint.SetZ(aStrList[j].toDouble());
668 if ( anIsAltitudesInverted )
669 aPoint.SetZ( -aPoint.Z() );
671 thePoints.Append(aPoint);
683 Handle_HYDROData_PolylineXY HYDROData_Bathymetry::CreateBoundaryPolyline() const
685 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
686 Handle_HYDROData_PolylineXY aResult =
687 Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
689 if( aResult.IsNull() )
693 QString aPolylinePref = GetName() + "_Boundary";
694 QString aPolylineName = HYDROData_Tool::GenerateObjectName( aDocument, aPolylinePref );
695 aResult->SetName( aPolylineName );
697 double Xmin = 0.0, Xmax = 0.0, Ymin = 0.0, Ymax = 0.0;
699 AltitudePoints aPoints = GetAltitudePoints();
701 AltitudePoints::Iterator anIter( aPoints );
702 for ( ; anIter.More(); anIter.Next() )
704 const AltitudePoint& aPoint = anIter.Value();
706 double x = aPoint.X(), y = aPoint.Y();
707 if( isFirst || x<Xmin )
709 if( isFirst || x>Xmax )
711 if( isFirst || y<Ymin )
713 if( isFirst || y>Ymax )
718 aResult->AddSection( "bound", HYDROData_IPolyline::SECTION_POLYLINE, true );
719 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymin ) );
720 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymax ) );
721 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymax ) );
722 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymin ) );
724 aResult->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
731 void HYDROData_Bathymetry::UpdateLocalCS( double theDx, double theDy )
733 gp_XYZ aDelta( theDx, theDy, 0 );
734 AltitudePoints aPoints = GetAltitudePoints();
735 AltitudePoints::Iterator anIter( aPoints );
736 for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
738 AltitudePoint& aPoint = anIter.ChangeValue();
741 SetAltitudePoints( aPoints );