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"
24 #include <boost/math/special_functions/fpclassify.hpp>
29 #include <TDataStd_RealArray.hxx>
30 #include <TDataStd_AsciiString.hxx>
31 #include <TDataStd_Integer.hxx>
38 #include <QStringList>
44 #include <OSD_Timer.hxx>
48 #include "HYDRO_trace.hxx"
50 IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
51 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
53 //HYDROData_QuadtreeNode* HYDROData_Bathymetry::myQuadtree = 0;
54 std::map<int, HYDROData_QuadtreeNode*> HYDROData_Bathymetry::myQuadtrees;
56 HYDROData_Bathymetry::HYDROData_Bathymetry()
57 : HYDROData_IAltitudeObject()
59 //DEBTRACE("HYDROData_Bathymetry constructor start " << this);
61 // myQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
62 //DEBTRACE("HYDROData_Bathymetry constructor end " << this);
65 HYDROData_Bathymetry::~HYDROData_Bathymetry()
67 //DEBTRACE("HYDROData_Bathymetry destructor start " << this);
70 // Nodes_3D::iterator it = myListOfNodes.begin();
71 // for( ; it != myListOfNodes.end(); ++it)
73 // myListOfNodes.clear();
76 QStringList HYDROData_Bathymetry::DumpToPython( const QString& thePyScriptPath,
77 MapOfTreatedObjects& theTreatedObjects ) const
79 QStringList aResList = dumpObjectCreation( theTreatedObjects );
80 QString aBathymetryName = GetObjPyName();
82 aResList << QString( "%1.SetAltitudesInverted( %2 );" )
83 .arg( aBathymetryName ).arg( IsAltitudesInverted() );
85 TCollection_AsciiString aFilePath = GetFilePath();
86 aResList << QString( "%1.ImportFromFile( \"%2\" );" )
87 .arg( aBathymetryName ).arg( aFilePath.ToCString() );
89 aResList << QString( "" );
90 aResList << QString( "%1.Update();" ).arg( aBathymetryName );
91 aResList << QString( "" );
96 void HYDROData_Bathymetry::SetAltitudePoints( const AltitudePoints& thePoints )
98 RemoveAltitudePoints();
100 if ( thePoints.IsEmpty() )
104 Handle(TDataStd_RealArray) aCoordsArray =
105 TDataStd_RealArray::Set( myLab.FindChild( DataTag_AltitudePoints ), 0, thePoints.Length() * 3 - 1 );
107 AltitudePoints::Iterator anIter( thePoints );
108 for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
110 const AltitudePoint& aPoint = anIter.Value();
112 aCoordsArray->SetValue( i * 3, aPoint.X() );
113 aCoordsArray->SetValue( i * 3 + 1, aPoint.Y() );
114 aCoordsArray->SetValue( i * 3 + 2, aPoint.Z() );
120 HYDROData_Bathymetry::AltitudePoints HYDROData_Bathymetry::GetAltitudePoints(bool IsConvertToGlobal) const
122 AltitudePoints aPoints;
124 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
125 if ( aLabel.IsNull() )
128 Handle(TDataStd_RealArray) aCoordsArray;
129 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aCoordsArray ) )
132 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
133 for ( int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n; )
138 AltitudePoint aPoint;
139 aPoint.SetX( aCoordsArray->Value( i++ ) );
140 aPoint.SetY( aCoordsArray->Value( i++ ) );
141 aPoint.SetZ( aCoordsArray->Value( i++ ) );
143 if( IsConvertToGlobal )
144 aDoc->Transform( aPoint, false );
145 aPoints.Append( aPoint );
151 HYDROData_QuadtreeNode* HYDROData_Bathymetry::GetQuadtreeNodes() const
153 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
156 int labkey = myLab.Tag();
157 int altkey = aLabel.Tag();
158 //DEBTRACE("GetQuadtreeNodes this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
159 // if (myQuadtree->isEmpty() )
160 if (myQuadtrees.find(labkey) == myQuadtrees.end())
162 DEBTRACE("GetQuadtreeNodes init " << this << " " << labkey);
163 HYDROData_QuadtreeNode* aQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
164 myQuadtrees[labkey] = aQuadtree;
165 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
169 Handle(TDataStd_RealArray) aCoordsArray;
170 if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
173 Nodes_3D* aListOfNodes = new Nodes_3D();
175 for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
180 double x = aCoordsArray->Value(i++);
181 double y = aCoordsArray->Value(i++);
182 double z = aCoordsArray->Value(i++);
183 gp_XYZ* aPoint = new gp_XYZ(x, y, z);
184 aListOfNodes->push_back(aPoint);
186 DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
187 aQuadtree->setNodesAndCompute(aListOfNodes);
191 return myQuadtrees[labkey];
194 void HYDROData_Bathymetry::RemoveAltitudePoints()
196 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
197 if ( !aLabel.IsNull() )
199 aLabel.ForgetAllAttributes();
204 void interpolateAltitudeForPoints( const gp_XY& thePoint,
205 const HYDROData_Bathymetry::AltitudePoint& theFirstPoint,
206 const HYDROData_Bathymetry::AltitudePoint& theSecPoint,
207 HYDROData_Bathymetry::AltitudePoint& theResPoint,
208 const bool& theIsVertical )
210 double aCoordX = thePoint.X();
211 double aCoordY = thePoint.Y();
215 aCoordX = theFirstPoint.X();
217 if ( !ValuesEquals( theFirstPoint.X(), theSecPoint.X() ) )
219 // Recalculate X coordinate by equation of line from two points
220 aCoordX = ( ( ( thePoint.Y() - theFirstPoint.Y() ) * ( theSecPoint.X() - theFirstPoint.X() ) ) /
221 ( theSecPoint.Y() - theFirstPoint.Y() ) ) + theFirstPoint.X();
226 aCoordY = theFirstPoint.Y();
228 if ( !ValuesEquals( theFirstPoint.Y(), theSecPoint.Y() ) )
230 // Recalculate y by equation of line from two points
231 aCoordY = ( ( ( thePoint.X() - theFirstPoint.X() ) * ( theSecPoint.Y() - theFirstPoint.Y() ) ) /
232 ( theSecPoint.X() - theFirstPoint.X() ) ) + theFirstPoint.Y();
236 theResPoint.SetX( aCoordX );
237 theResPoint.SetY( aCoordY );
239 // Calculate coefficient for interpolation
240 double aLength = Sqrt( Pow( theSecPoint.Y() - theFirstPoint.Y(), 2 ) +
241 Pow( theSecPoint.X() - theFirstPoint.X(), 2 ) );
243 double aInterCoeff = 0;
245 aInterCoeff = ( theSecPoint.Z() - theFirstPoint.Z() ) / aLength;
248 double aNewLength = Sqrt( Pow( theResPoint.Y() - theFirstPoint.Y(), 2 ) +
249 Pow( theResPoint.X() - theFirstPoint.X(), 2 ) );
251 // Calculate interpolated value
252 double aResVal = theFirstPoint.Z() + aInterCoeff * aNewLength;
254 theResPoint.SetZ( aResVal );
257 double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint) const
259 DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")");
260 double anInvalidAltitude = GetInvalidAltitude();
261 double aResAltitude = anInvalidAltitude;
263 HYDROData_QuadtreeNode* aQuadtree = GetQuadtreeNodes();
266 DEBTRACE(" no Quadtree");
270 std::map<double, const gp_XYZ*> dist2nodes;
271 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
272 while (dist2nodes.size() == 0)
274 aQuadtree->setPrecision(aQuadtree->getPrecision() *2);
275 DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
276 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
278 aQuadtree->NodesAround(thePoint, dist2nodes, 5.0);
279 if (dist2nodes.size())
281 std::map<double, const gp_XYZ*>::const_iterator it = dist2nodes.begin();
282 aResAltitude = it->second->Z();
283 DEBTRACE(" number of points found: " << dist2nodes.size() << " nearest z: " << aResAltitude);
287 DEBTRACE(" number of points found: 0");
293 // AltitudePoints anAltitudePoints = GetAltitudePoints();
294 // if ( anAltitudePoints.IsEmpty() )
295 // return aResAltitude;
297 // QPolygonF aBoundingRect;
300 // // [ 0 (top-left) ] [ 1 (top-right) ]
302 // // [ 2 (bot-left) ] [ 3 (bot-right) ]
303 // AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, anInvalidAltitude ),
304 // AltitudePoint( DBL_MAX, -DBL_MAX, anInvalidAltitude ),
305 // AltitudePoint( -DBL_MAX, DBL_MAX, anInvalidAltitude ),
306 // AltitudePoint( DBL_MAX, DBL_MAX, anInvalidAltitude ) };
308 // AltitudePoints::Iterator anIter( anAltitudePoints );
309 // for ( ; anIter.More(); anIter.Next() )
311 // const AltitudePoint& aPoint = anIter.Value();
313 // double aDeltaX = Abs( aPoint.X() ) - Abs( thePoint.X() );
314 // double aDeltaY = Abs( aPoint.Y() ) - Abs( thePoint.Y() );
316 // if ( ValuesEquals( aDeltaX, 0.0 ) ) // Both left and right sides
318 // if ( ValuesEquals( aDeltaY, 0.0 ) ) // Both top and bottom sides
320 // aResAltitude = aPoint.Z();
321 // return aResAltitude;
323 // else if ( aDeltaY < 0 ) // top side
326 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
327 // aBounds[ 0 ] = aPoint;
328 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
329 // aBounds[ 1 ] = aPoint;
334 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
335 // aBounds[ 2 ] = aPoint;
336 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
337 // aBounds[ 3 ] = aPoint;
340 // else if ( aDeltaX < 0 ) // left side
342 // if ( ValuesEquals( aDeltaY, 0.0 ) )
345 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
346 // aBounds[ 0 ] = aPoint;
347 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
348 // aBounds[ 2 ] = aPoint;
350 // else if ( aDeltaY < 0 )
352 // // top left corner
353 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
354 // aBounds[ 0 ] = aPoint;
358 // // bottom left corner
359 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
360 // aBounds[ 2 ] = aPoint;
363 // else // right side
365 // if ( ValuesEquals( aDeltaY, 0.0 ) )
368 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
369 // aBounds[ 1 ] = aPoint;
370 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
371 // aBounds[ 3 ] = aPoint;
373 // else if ( aDeltaY < 0 )
375 // // top right corner
376 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
377 // aBounds[ 1 ] = aPoint;
381 // // bottom right corner
382 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
383 // aBounds[ 3 ] = aPoint;
387 // // Update bounding rectangle of our global grid
388 // aBoundingRect << QPointF( aPoint.X(), aPoint.Y() );
391 // const double LIMIT = 1E300;
392 // if( fabs( aBounds[ 0 ].X() ) > LIMIT || fabs( aBounds[ 0 ].Y() ) > LIMIT ||
393 // fabs( aBounds[ 1 ].X() ) > LIMIT || fabs( aBounds[ 1 ].Y() ) > LIMIT ||
394 // fabs( aBounds[ 2 ].X() ) > LIMIT || fabs( aBounds[ 2 ].Y() ) > LIMIT ||
395 // fabs( aBounds[ 3 ].X() ) > LIMIT || fabs( aBounds[ 3 ].Y() ) > LIMIT )
396 // return anInvalidAltitude;
399 // // Check if requested point is inside of our bounding rectangle
400 // if ( !aBoundingRect.boundingRect().contains( thePoint.X(), thePoint.Y() ) )
401 // return aResAltitude;
403 // // Calculate result altitude for point
404 // AltitudePoint aFirstPoint( aBounds[ 0 ] ), aSecPoint( aBounds[ 1 ] );
406 // // At first we merge top and bottom borders
407 // if ( aBounds[ 0 ].Y() != aBounds[ 2 ].Y() || aBounds[ 0 ].X() != aBounds[ 2 ].X() )
408 // interpolateAltitudeForPoints( thePoint, aBounds[ 0 ], aBounds[ 2 ], aFirstPoint, true );
410 // if ( aBounds[ 1 ].Y() != aBounds[ 3 ].Y() || aBounds[ 1 ].X() != aBounds[ 3 ].X() )
411 // interpolateAltitudeForPoints( thePoint, aBounds[ 1 ], aBounds[ 3 ], aSecPoint, true );
413 // AltitudePoint aResPoint( aFirstPoint );
415 // // At last we merge left and right borders
416 // if ( aFirstPoint.Y() != aSecPoint.Y() || aFirstPoint.X() != aSecPoint.X() )
417 // interpolateAltitudeForPoints( thePoint, aFirstPoint, aSecPoint, aResPoint, false );
419 // aResAltitude = aResPoint.Z();
421 // return aResAltitude;
424 void HYDROData_Bathymetry::SetFilePath( const TCollection_AsciiString& theFilePath )
426 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
429 TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const
431 TCollection_AsciiString aRes;
433 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
434 if ( !aLabel.IsNull() )
436 Handle(TDataStd_AsciiString) anAsciiStr;
437 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
438 aRes = anAsciiStr->Get();
444 void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted,
445 const bool theIsUpdate )
447 bool anIsAltitudesInverted = IsAltitudesInverted();
448 if ( anIsAltitudesInverted == theIsInverted )
451 TDataStd_Integer::Set( myLab.FindChild( DataTag_AltitudesInverted ), (Standard_Integer)theIsInverted );
458 // Update altitude points
459 AltitudePoints anAltitudePoints = GetAltitudePoints();
460 if ( anAltitudePoints.IsEmpty() )
463 AltitudePoints::Iterator anIter( anAltitudePoints );
464 for ( ; anIter.More(); anIter.Next() )
466 AltitudePoint& aPoint = anIter.ChangeValue();
467 aPoint.SetZ( aPoint.Z() * -1 );
470 SetAltitudePoints( anAltitudePoints );
473 bool HYDROData_Bathymetry::IsAltitudesInverted() const
477 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudesInverted, false );
478 if ( !aLabel.IsNull() )
480 Handle(TDataStd_Integer) anIntVal;
481 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
482 aRes = (bool)anIntVal->Get();
488 bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName )
490 // Try to open the file
491 QFile aFile( theFileName.ToCString() );
492 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
497 QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
499 AltitudePoints aPoints;
501 // Try to import the file
502 if ( aFileSuf == "xyz" )
503 aRes = importFromXYZFile( aFile, aPoints );
504 else if ( aFileSuf == "asc" )
505 aRes = importFromASCFile( aFile, aPoints );
511 // Convert from global to local CS
512 Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
513 AltitudePoints::Iterator anIter( aPoints );
514 for ( ; anIter.More(); anIter.Next() )
516 AltitudePoint& aPoint = anIter.ChangeValue();
517 aDoc->Transform( aPoint, true );
522 // Update file path and altitude points of this Bathymetry
523 SetFilePath( theFileName );
524 SetAltitudePoints( aPoints );
527 return aRes && !aPoints.IsEmpty();
530 bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,
531 AltitudePoints& thePoints ) const
533 if ( !theFile.isOpen() )
536 // Strings in file is written as:
537 // 1. X(float) Y(float) Z(float)
538 // 2. X(float) Y(float) Z(float)
546 bool anIsAltitudesInverted = IsAltitudesInverted();
547 while ( !theFile.atEnd() )
549 QString aLine = theFile.readLine().simplified();
550 if ( aLine.isEmpty() )
553 QStringList aValues = aLine.split( ' ', QString::SkipEmptyParts );
554 if ( aValues.length() < 3 )
557 AltitudePoint aPoint;
559 QString anX = aValues.value( 0 );
560 QString anY = aValues.value( 1 );
561 QString aZ = aValues.value( 2 );
563 bool isXOk = false, isYOk = false, isZOk = false;
565 aPoint.SetX( anX.toDouble( &isXOk ) );
566 aPoint.SetY( anY.toDouble( &isYOk ) );
567 aPoint.SetZ( aZ.toDouble( &isZOk ) );
569 if ( !isXOk || !isYOk || !isZOk )
572 if ( boost::math::isnan( aPoint.X() ) || boost::math::isinf( aPoint.X() ) ||
573 boost::math::isnan( aPoint.Y() ) || boost::math::isinf( aPoint.Y() ) ||
574 boost::math::isnan( aPoint.Z() ) || boost::math::isinf( aPoint.Z() ) )
577 // Invert the z value if requested
578 if ( anIsAltitudesInverted )
579 aPoint.SetZ( -aPoint.Z() );
581 thePoints.Append( aPoint );
586 std::ofstream stream( "W:/HYDRO/WORK/log.txt", std::ofstream::out );
587 aTimer.Show( stream );
593 bool HYDROData_Bathymetry::importFromASCFile( QFile& theFile,
594 AltitudePoints& thePoints ) const
596 if ( !theFile.isOpen() )
600 QStringList aStrList;
609 aLine = theFile.readLine().simplified();
610 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
611 if ( aStrList.length() != 2 && aStrList[0].toLower() != "ncols" )
613 aNCols = aStrList[1].toInt();
615 aLine = theFile.readLine().simplified();
616 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
617 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nrows" )
619 aNRows = aStrList[1].toInt();
621 aLine = theFile.readLine().simplified();
622 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
623 if ( aStrList.length() != 2 && aStrList[0].toLower() != "xllcorner" )
625 anXllCorner = aStrList[1].toDouble();
627 aLine = theFile.readLine().simplified();
628 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
629 if ( aStrList.length() != 2 && aStrList[0].toLower() != "yllcorner" )
631 anYllCorner = aStrList[1].toDouble();
633 aLine = theFile.readLine().simplified();
634 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
635 if ( aStrList.length() != 2 && aStrList[0].toLower() != "cellsize" )
637 aCellSize = aStrList[1].toDouble();
639 aLine = theFile.readLine().simplified();
640 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
641 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nodata_value" )
643 aNoDataValue = aStrList[1].toDouble();
645 bool anIsAltitudesInverted = IsAltitudesInverted();
649 while ( !theFile.atEnd() )
651 aLine = theFile.readLine().simplified();
652 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
654 aStrLength = aStrList.length();
655 if ( aStrLength == 0 )
658 if ( aStrLength != aNRows )
661 for (int j = 0; j < aNCols; j++)
663 if (aStrList[j].toDouble() != aNoDataValue)
665 AltitudePoint aPoint;
666 aPoint.SetX(anXllCorner + aCellSize*(j + 0.5));
667 aPoint.SetY(anYllCorner + aCellSize*(aNRows - i + 0.5));
668 aPoint.SetZ(aStrList[j].toDouble());
670 if ( anIsAltitudesInverted )
671 aPoint.SetZ( -aPoint.Z() );
673 thePoints.Append(aPoint);
685 Handle_HYDROData_PolylineXY HYDROData_Bathymetry::CreateBoundaryPolyline() const
687 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
688 Handle_HYDROData_PolylineXY aResult =
689 Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
691 if( aResult.IsNull() )
695 QString aPolylinePref = GetName() + "_Boundary";
696 QString aPolylineName = HYDROData_Tool::GenerateObjectName( aDocument, aPolylinePref );
697 aResult->SetName( aPolylineName );
699 double Xmin = 0.0, Xmax = 0.0, Ymin = 0.0, Ymax = 0.0;
701 AltitudePoints aPoints = GetAltitudePoints();
703 AltitudePoints::Iterator anIter( aPoints );
704 for ( ; anIter.More(); anIter.Next() )
706 const AltitudePoint& aPoint = anIter.Value();
708 double x = aPoint.X(), y = aPoint.Y();
709 if( isFirst || x<Xmin )
711 if( isFirst || x>Xmax )
713 if( isFirst || y<Ymin )
715 if( isFirst || y>Ymax )
720 aResult->AddSection( "bound", HYDROData_IPolyline::SECTION_POLYLINE, true );
721 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymin ) );
722 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymax ) );
723 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymax ) );
724 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymin ) );
726 aResult->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
733 void HYDROData_Bathymetry::UpdateLocalCS( double theDx, double theDy )
735 gp_XYZ aDelta( theDx, theDy, 0 );
736 AltitudePoints aPoints = GetAltitudePoints();
737 AltitudePoints::Iterator anIter( aPoints );
738 for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
740 AltitudePoint& aPoint = anIter.ChangeValue();
743 SetAltitudePoints( aPoints );