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( MapOfTreatedObjects& theTreatedObjects ) const
78 QStringList aResList = dumpObjectCreation( theTreatedObjects );
79 QString aBathymetryName = GetObjPyName();
81 aResList << QString( "%1.SetAltitudesInverted( %2 );" )
82 .arg( aBathymetryName ).arg( IsAltitudesInverted() );
84 TCollection_AsciiString aFilePath = GetFilePath();
85 aResList << QString( "%1.ImportFromFile( \"%2\" );" )
86 .arg( aBathymetryName ).arg( aFilePath.ToCString() );
88 aResList << QString( "" );
89 aResList << QString( "%1.Update();" ).arg( aBathymetryName );
90 aResList << QString( "" );
95 void HYDROData_Bathymetry::SetAltitudePoints( const AltitudePoints& thePoints )
97 RemoveAltitudePoints();
99 if ( thePoints.IsEmpty() )
103 Handle(TDataStd_RealArray) aCoordsArray =
104 TDataStd_RealArray::Set( myLab.FindChild( DataTag_AltitudePoints ), 0, thePoints.Length() * 3 - 1 );
106 AltitudePoints::Iterator anIter( thePoints );
107 for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
109 const AltitudePoint& aPoint = anIter.Value();
111 aCoordsArray->SetValue( i * 3, aPoint.X() );
112 aCoordsArray->SetValue( i * 3 + 1, aPoint.Y() );
113 aCoordsArray->SetValue( i * 3 + 2, aPoint.Z() );
119 HYDROData_Bathymetry::AltitudePoints HYDROData_Bathymetry::GetAltitudePoints() const
121 AltitudePoints aPoints;
123 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
124 if ( aLabel.IsNull() )
127 Handle(TDataStd_RealArray) aCoordsArray;
128 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aCoordsArray ) )
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 aPoints.Append( aPoint );
147 HYDROData_QuadtreeNode* HYDROData_Bathymetry::GetQuadtreeNodes() const
149 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
152 int labkey = myLab.Tag();
153 int altkey = aLabel.Tag();
154 //DEBTRACE("GetQuadtreeNodes this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
155 // if (myQuadtree->isEmpty() )
156 if (myQuadtrees.find(labkey) == myQuadtrees.end())
158 DEBTRACE("GetQuadtreeNodes init " << this << " " << labkey);
159 HYDROData_QuadtreeNode* aQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
160 myQuadtrees[labkey] = aQuadtree;
161 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
165 Handle(TDataStd_RealArray) aCoordsArray;
166 if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
169 Nodes_3D* aListOfNodes = new Nodes_3D();
171 for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
176 double x = aCoordsArray->Value(i++);
177 double y = aCoordsArray->Value(i++);
178 double z = aCoordsArray->Value(i++);
179 gp_XYZ* aPoint = new gp_XYZ(x, y, z);
180 aListOfNodes->push_back(aPoint);
182 DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
183 aQuadtree->setNodesAndCompute(aListOfNodes);
187 return myQuadtrees[labkey];
190 void HYDROData_Bathymetry::RemoveAltitudePoints()
192 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
193 if (!aLabel.IsNull())
195 aLabel.ForgetAllAttributes();
200 void interpolateAltitudeForPoints( const gp_XY& thePoint,
201 const HYDROData_Bathymetry::AltitudePoint& theFirstPoint,
202 const HYDROData_Bathymetry::AltitudePoint& theSecPoint,
203 HYDROData_Bathymetry::AltitudePoint& theResPoint,
204 const bool& theIsVertical )
206 double aCoordX = thePoint.X();
207 double aCoordY = thePoint.Y();
211 aCoordX = theFirstPoint.X();
213 if ( !ValuesEquals( theFirstPoint.X(), theSecPoint.X() ) )
215 // Recalculate X coordinate by equation of line from two points
216 aCoordX = ( ( ( thePoint.Y() - theFirstPoint.Y() ) * ( theSecPoint.X() - theFirstPoint.X() ) ) /
217 ( theSecPoint.Y() - theFirstPoint.Y() ) ) + theFirstPoint.X();
222 aCoordY = theFirstPoint.Y();
224 if ( !ValuesEquals( theFirstPoint.Y(), theSecPoint.Y() ) )
226 // Recalculate y by equation of line from two points
227 aCoordY = ( ( ( thePoint.X() - theFirstPoint.X() ) * ( theSecPoint.Y() - theFirstPoint.Y() ) ) /
228 ( theSecPoint.X() - theFirstPoint.X() ) ) + theFirstPoint.Y();
232 theResPoint.SetX( aCoordX );
233 theResPoint.SetY( aCoordY );
235 // Calculate coefficient for interpolation
236 double aLength = Sqrt( Pow( theSecPoint.Y() - theFirstPoint.Y(), 2 ) +
237 Pow( theSecPoint.X() - theFirstPoint.X(), 2 ) );
239 double aInterCoeff = 0;
241 aInterCoeff = ( theSecPoint.Z() - theFirstPoint.Z() ) / aLength;
244 double aNewLength = Sqrt( Pow( theResPoint.Y() - theFirstPoint.Y(), 2 ) +
245 Pow( theResPoint.X() - theFirstPoint.X(), 2 ) );
247 // Calculate interpolated value
248 double aResVal = theFirstPoint.Z() + aInterCoeff * aNewLength;
250 theResPoint.SetZ( aResVal );
253 double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint) const
255 DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")");
256 double anInvalidAltitude = GetInvalidAltitude();
257 double aResAltitude = anInvalidAltitude;
259 HYDROData_QuadtreeNode* aQuadtree = GetQuadtreeNodes();
262 DEBTRACE(" no Quadtree");
266 std::map<double, const gp_XYZ*> dist2nodes;
267 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
268 while (dist2nodes.size() == 0)
270 aQuadtree->setPrecision(aQuadtree->getPrecision() *2);
271 DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
272 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
274 aQuadtree->NodesAround(thePoint, dist2nodes, 5.0);
275 if (dist2nodes.size())
277 std::map<double, const gp_XYZ*>::const_iterator it = dist2nodes.begin();
278 aResAltitude = it->second->Z();
279 DEBTRACE(" number of points found: " << dist2nodes.size() << " nearest z: " << aResAltitude);
283 DEBTRACE(" number of points found: 0");
289 // AltitudePoints anAltitudePoints = GetAltitudePoints();
290 // if ( anAltitudePoints.IsEmpty() )
291 // return aResAltitude;
293 // QPolygonF aBoundingRect;
296 // // [ 0 (top-left) ] [ 1 (top-right) ]
298 // // [ 2 (bot-left) ] [ 3 (bot-right) ]
299 // AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, anInvalidAltitude ),
300 // AltitudePoint( DBL_MAX, -DBL_MAX, anInvalidAltitude ),
301 // AltitudePoint( -DBL_MAX, DBL_MAX, anInvalidAltitude ),
302 // AltitudePoint( DBL_MAX, DBL_MAX, anInvalidAltitude ) };
304 // AltitudePoints::Iterator anIter( anAltitudePoints );
305 // for ( ; anIter.More(); anIter.Next() )
307 // const AltitudePoint& aPoint = anIter.Value();
309 // double aDeltaX = Abs( aPoint.X() ) - Abs( thePoint.X() );
310 // double aDeltaY = Abs( aPoint.Y() ) - Abs( thePoint.Y() );
312 // if ( ValuesEquals( aDeltaX, 0.0 ) ) // Both left and right sides
314 // if ( ValuesEquals( aDeltaY, 0.0 ) ) // Both top and bottom sides
316 // aResAltitude = aPoint.Z();
317 // return aResAltitude;
319 // else if ( aDeltaY < 0 ) // top side
322 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
323 // aBounds[ 0 ] = aPoint;
324 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
325 // aBounds[ 1 ] = aPoint;
330 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
331 // aBounds[ 2 ] = aPoint;
332 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
333 // aBounds[ 3 ] = aPoint;
336 // else if ( aDeltaX < 0 ) // left side
338 // if ( ValuesEquals( aDeltaY, 0.0 ) )
341 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
342 // aBounds[ 0 ] = aPoint;
343 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
344 // aBounds[ 2 ] = aPoint;
346 // else if ( aDeltaY < 0 )
348 // // top left corner
349 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
350 // aBounds[ 0 ] = aPoint;
354 // // bottom left corner
355 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
356 // aBounds[ 2 ] = aPoint;
359 // else // right side
361 // if ( ValuesEquals( aDeltaY, 0.0 ) )
364 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
365 // aBounds[ 1 ] = aPoint;
366 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
367 // aBounds[ 3 ] = aPoint;
369 // else if ( aDeltaY < 0 )
371 // // top right corner
372 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
373 // aBounds[ 1 ] = aPoint;
377 // // bottom right corner
378 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
379 // aBounds[ 3 ] = aPoint;
383 // // Update bounding rectangle of our global grid
384 // aBoundingRect << QPointF( aPoint.X(), aPoint.Y() );
387 // const double LIMIT = 1E300;
388 // if( fabs( aBounds[ 0 ].X() ) > LIMIT || fabs( aBounds[ 0 ].Y() ) > LIMIT ||
389 // fabs( aBounds[ 1 ].X() ) > LIMIT || fabs( aBounds[ 1 ].Y() ) > LIMIT ||
390 // fabs( aBounds[ 2 ].X() ) > LIMIT || fabs( aBounds[ 2 ].Y() ) > LIMIT ||
391 // fabs( aBounds[ 3 ].X() ) > LIMIT || fabs( aBounds[ 3 ].Y() ) > LIMIT )
392 // return anInvalidAltitude;
395 // // Check if requested point is inside of our bounding rectangle
396 // if ( !aBoundingRect.boundingRect().contains( thePoint.X(), thePoint.Y() ) )
397 // return aResAltitude;
399 // // Calculate result altitude for point
400 // AltitudePoint aFirstPoint( aBounds[ 0 ] ), aSecPoint( aBounds[ 1 ] );
402 // // At first we merge top and bottom borders
403 // if ( aBounds[ 0 ].Y() != aBounds[ 2 ].Y() || aBounds[ 0 ].X() != aBounds[ 2 ].X() )
404 // interpolateAltitudeForPoints( thePoint, aBounds[ 0 ], aBounds[ 2 ], aFirstPoint, true );
406 // if ( aBounds[ 1 ].Y() != aBounds[ 3 ].Y() || aBounds[ 1 ].X() != aBounds[ 3 ].X() )
407 // interpolateAltitudeForPoints( thePoint, aBounds[ 1 ], aBounds[ 3 ], aSecPoint, true );
409 // AltitudePoint aResPoint( aFirstPoint );
411 // // At last we merge left and right borders
412 // if ( aFirstPoint.Y() != aSecPoint.Y() || aFirstPoint.X() != aSecPoint.X() )
413 // interpolateAltitudeForPoints( thePoint, aFirstPoint, aSecPoint, aResPoint, false );
415 // aResAltitude = aResPoint.Z();
417 // return aResAltitude;
420 void HYDROData_Bathymetry::SetFilePath( const TCollection_AsciiString& theFilePath )
422 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
425 TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const
427 TCollection_AsciiString aRes;
429 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
430 if ( !aLabel.IsNull() )
432 Handle(TDataStd_AsciiString) anAsciiStr;
433 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
434 aRes = anAsciiStr->Get();
440 void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted,
441 const bool theIsUpdate )
443 bool anIsAltitudesInverted = IsAltitudesInverted();
444 if ( anIsAltitudesInverted == theIsInverted )
447 TDataStd_Integer::Set( myLab.FindChild( DataTag_AltitudesInverted ), (Standard_Integer)theIsInverted );
454 // Update altitude points
455 AltitudePoints anAltitudePoints = GetAltitudePoints();
456 if ( anAltitudePoints.IsEmpty() )
459 AltitudePoints::Iterator anIter( anAltitudePoints );
460 for ( ; anIter.More(); anIter.Next() )
462 AltitudePoint& aPoint = anIter.ChangeValue();
463 aPoint.SetZ( aPoint.Z() * -1 );
466 SetAltitudePoints( anAltitudePoints );
469 bool HYDROData_Bathymetry::IsAltitudesInverted() const
473 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudesInverted, false );
474 if ( !aLabel.IsNull() )
476 Handle(TDataStd_Integer) anIntVal;
477 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
478 aRes = (bool)anIntVal->Get();
484 bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName )
486 // Try to open the file
487 QFile aFile( theFileName.ToCString() );
488 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
493 QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
495 AltitudePoints aPoints;
497 // Try to import the file
498 if ( aFileSuf == "xyz" )
499 aRes = importFromXYZFile( aFile, aPoints );
500 else if ( aFileSuf == "asc" )
501 aRes = importFromASCFile( aFile, aPoints );
507 // Convert from global to local CS
508 Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
509 AltitudePoints::Iterator anIter( aPoints );
510 for ( ; anIter.More(); anIter.Next() )
512 AltitudePoint& aPoint = anIter.ChangeValue();
513 aDoc->Transform( aPoint, true );
518 // Update file path and altitude points of this Bathymetry
519 SetFilePath( theFileName );
520 SetAltitudePoints( aPoints );
523 return aRes && !aPoints.IsEmpty();
526 bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,
527 AltitudePoints& thePoints ) const
529 if ( !theFile.isOpen() )
532 // Strings in file is written as:
533 // 1. X(float) Y(float) Z(float)
534 // 2. X(float) Y(float) Z(float)
542 bool anIsAltitudesInverted = IsAltitudesInverted();
543 while ( !theFile.atEnd() )
545 QString aLine = theFile.readLine().simplified();
546 if ( aLine.isEmpty() )
549 QStringList aValues = aLine.split( ' ', QString::SkipEmptyParts );
550 if ( aValues.length() < 3 )
553 AltitudePoint aPoint;
555 QString anX = aValues.value( 0 );
556 QString anY = aValues.value( 1 );
557 QString aZ = aValues.value( 2 );
559 bool isXOk = false, isYOk = false, isZOk = false;
561 aPoint.SetX( anX.toDouble( &isXOk ) );
562 aPoint.SetY( anY.toDouble( &isYOk ) );
563 aPoint.SetZ( aZ.toDouble( &isZOk ) );
565 if ( !isXOk || !isYOk || !isZOk )
568 if ( boost::math::isnan( aPoint.X() ) || boost::math::isinf( aPoint.X() ) ||
569 boost::math::isnan( aPoint.Y() ) || boost::math::isinf( aPoint.Y() ) ||
570 boost::math::isnan( aPoint.Z() ) || boost::math::isinf( aPoint.Z() ) )
573 // Invert the z value if requested
574 if ( anIsAltitudesInverted )
575 aPoint.SetZ( -aPoint.Z() );
577 thePoints.Append( aPoint );
582 std::ofstream stream( "W:/HYDRO/WORK/log.txt", std::ofstream::out );
583 aTimer.Show( stream );
589 bool HYDROData_Bathymetry::importFromASCFile( QFile& theFile,
590 AltitudePoints& thePoints ) const
592 if ( !theFile.isOpen() )
596 QStringList aStrList;
605 aLine = theFile.readLine().simplified();
606 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
607 if ( aStrList.length() != 2 && aStrList[0].toLower() != "ncols" )
609 aNCols = aStrList[1].toInt();
611 aLine = theFile.readLine().simplified();
612 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
613 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nrows" )
615 aNRows = aStrList[1].toInt();
617 aLine = theFile.readLine().simplified();
618 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
619 if ( aStrList.length() != 2 && aStrList[0].toLower() != "xllcorner" )
621 anXllCorner = aStrList[1].toDouble();
623 aLine = theFile.readLine().simplified();
624 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
625 if ( aStrList.length() != 2 && aStrList[0].toLower() != "yllcorner" )
627 anYllCorner = aStrList[1].toDouble();
629 aLine = theFile.readLine().simplified();
630 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
631 if ( aStrList.length() != 2 && aStrList[0].toLower() != "cellsize" )
633 aCellSize = aStrList[1].toDouble();
635 aLine = theFile.readLine().simplified();
636 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
637 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nodata_value" )
639 aNoDataValue = aStrList[1].toDouble();
641 bool anIsAltitudesInverted = IsAltitudesInverted();
645 while ( !theFile.atEnd() )
647 aLine = theFile.readLine().simplified();
648 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
650 aStrLength = aStrList.length();
651 if ( aStrLength == 0 )
654 if ( aStrLength != aNRows )
657 for (int j = 0; j < aNCols; j++)
659 if (aStrList[j].toDouble() != aNoDataValue)
661 AltitudePoint aPoint;
662 aPoint.SetX(anXllCorner + aCellSize*(j + 0.5));
663 aPoint.SetY(anYllCorner + aCellSize*(aNRows - i + 0.5));
664 aPoint.SetZ(aStrList[j].toDouble());
666 if ( anIsAltitudesInverted )
667 aPoint.SetZ( -aPoint.Z() );
669 thePoints.Append(aPoint);
681 Handle_HYDROData_PolylineXY HYDROData_Bathymetry::CreateBoundaryPolyline() const
683 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
684 Handle_HYDROData_PolylineXY aResult =
685 Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
687 if( aResult.IsNull() )
691 QString aPolylinePref = GetName() + "_Boundary";
692 QString aPolylineName = HYDROData_Tool::GenerateObjectName( aDocument, aPolylinePref );
693 aResult->SetName( aPolylineName );
695 double Xmin = 0.0, Xmax = 0.0, Ymin = 0.0, Ymax = 0.0;
697 AltitudePoints aPoints = GetAltitudePoints();
699 AltitudePoints::Iterator anIter( aPoints );
700 for ( ; anIter.More(); anIter.Next() )
702 const AltitudePoint& aPoint = anIter.Value();
704 double x = aPoint.X(), y = aPoint.Y();
705 if( isFirst || x<Xmin )
707 if( isFirst || x>Xmax )
709 if( isFirst || y<Ymin )
711 if( isFirst || y>Ymax )
716 aResult->AddSection( "bound", HYDROData_IPolyline::SECTION_POLYLINE, true );
717 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymin ) );
718 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymax ) );
719 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymax ) );
720 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymin ) );
722 aResult->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
729 void HYDROData_Bathymetry::UpdateLocalCS( double theDx, double theDy )
731 gp_XYZ aDelta( theDx, theDy, 0 );
732 AltitudePoints aPoints = GetAltitudePoints();
733 AltitudePoints::Iterator anIter( aPoints );
734 for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
736 AltitudePoint& aPoint = anIter.ChangeValue();
739 SetAltitudePoints( aPoints );