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>
37 #include <QStringList>
43 #include <OSD_Timer.hxx>
47 #include "HYDRO_trace.hxx"
49 IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
50 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
52 //HYDROData_QuadtreeNode* HYDROData_Bathymetry::myQuadtree = 0;
53 std::map<int, HYDROData_QuadtreeNode*> HYDROData_Bathymetry::myQuadtrees;
55 HYDROData_Bathymetry::HYDROData_Bathymetry()
56 : HYDROData_IAltitudeObject()
58 //DEBTRACE("HYDROData_Bathymetry constructor start " << this);
60 // myQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
61 //DEBTRACE("HYDROData_Bathymetry constructor end " << this);
64 HYDROData_Bathymetry::~HYDROData_Bathymetry()
66 //DEBTRACE("HYDROData_Bathymetry destructor start " << this);
69 // Nodes_3D::iterator it = myListOfNodes.begin();
70 // for( ; it != myListOfNodes.end(); ++it)
72 // myListOfNodes.clear();
75 QStringList HYDROData_Bathymetry::DumpToPython( 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( "%1.ImportFromFile( \"%2\" );" )
85 .arg( aBathymetryName ).arg( aFilePath.ToCString() );
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() 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 for ( int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n; )
135 AltitudePoint aPoint;
136 aPoint.SetX( aCoordsArray->Value( i++ ) );
137 aPoint.SetY( aCoordsArray->Value( i++ ) );
138 aPoint.SetZ( aCoordsArray->Value( i++ ) );
140 aPoints.Append( aPoint );
146 HYDROData_QuadtreeNode* HYDROData_Bathymetry::GetQuadtreeNodes() const
148 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
151 int labkey = myLab.Tag();
152 int altkey = aLabel.Tag();
153 //DEBTRACE("GetQuadtreeNodes this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
154 // if (myQuadtree->isEmpty() )
155 if (myQuadtrees.find(labkey) == myQuadtrees.end())
157 DEBTRACE("GetQuadtreeNodes init " << this << " " << labkey);
158 HYDROData_QuadtreeNode* aQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
159 myQuadtrees[labkey] = aQuadtree;
160 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
164 Handle(TDataStd_RealArray) aCoordsArray;
165 if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
168 Nodes_3D* aListOfNodes = new Nodes_3D();
170 for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
175 double x = aCoordsArray->Value(i++);
176 double y = aCoordsArray->Value(i++);
177 double z = aCoordsArray->Value(i++);
178 gp_XYZ* aPoint = new gp_XYZ(x, y, z);
179 aListOfNodes->push_back(aPoint);
181 DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
182 aQuadtree->setNodesAndCompute(aListOfNodes);
186 return myQuadtrees[labkey];
189 void HYDROData_Bathymetry::RemoveAltitudePoints()
191 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
192 if (!aLabel.IsNull())
194 aLabel.ForgetAllAttributes();
199 void interpolateAltitudeForPoints( const gp_XY& thePoint,
200 const HYDROData_Bathymetry::AltitudePoint& theFirstPoint,
201 const HYDROData_Bathymetry::AltitudePoint& theSecPoint,
202 HYDROData_Bathymetry::AltitudePoint& theResPoint,
203 const bool& theIsVertical )
205 double aCoordX = thePoint.X();
206 double aCoordY = thePoint.Y();
210 aCoordX = theFirstPoint.X();
212 if ( !ValuesEquals( theFirstPoint.X(), theSecPoint.X() ) )
214 // Recalculate X coordinate by equation of line from two points
215 aCoordX = ( ( ( thePoint.Y() - theFirstPoint.Y() ) * ( theSecPoint.X() - theFirstPoint.X() ) ) /
216 ( theSecPoint.Y() - theFirstPoint.Y() ) ) + theFirstPoint.X();
221 aCoordY = theFirstPoint.Y();
223 if ( !ValuesEquals( theFirstPoint.Y(), theSecPoint.Y() ) )
225 // Recalculate y by equation of line from two points
226 aCoordY = ( ( ( thePoint.X() - theFirstPoint.X() ) * ( theSecPoint.Y() - theFirstPoint.Y() ) ) /
227 ( theSecPoint.X() - theFirstPoint.X() ) ) + theFirstPoint.Y();
231 theResPoint.SetX( aCoordX );
232 theResPoint.SetY( aCoordY );
234 // Calculate coefficient for interpolation
235 double aLength = Sqrt( Pow( theSecPoint.Y() - theFirstPoint.Y(), 2 ) +
236 Pow( theSecPoint.X() - theFirstPoint.X(), 2 ) );
238 double aInterCoeff = 0;
240 aInterCoeff = ( theSecPoint.Z() - theFirstPoint.Z() ) / aLength;
243 double aNewLength = Sqrt( Pow( theResPoint.Y() - theFirstPoint.Y(), 2 ) +
244 Pow( theResPoint.X() - theFirstPoint.X(), 2 ) );
246 // Calculate interpolated value
247 double aResVal = theFirstPoint.Z() + aInterCoeff * aNewLength;
249 theResPoint.SetZ( aResVal );
252 double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint) const
254 //DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")");
255 double anInvalidAltitude = GetInvalidAltitude();
256 double aResAltitude = anInvalidAltitude;
258 HYDROData_QuadtreeNode* aQuadtree = GetQuadtreeNodes();
261 DEBTRACE(" no Quadtree");
265 std::map<double, const gp_XYZ*> dist2nodes;
266 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
267 while (dist2nodes.size() == 0)
269 aQuadtree->setPrecision(aQuadtree->getPrecision() *2);
270 DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
271 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
273 aQuadtree->NodesAround(thePoint, dist2nodes, 5.0);
274 if (dist2nodes.size())
276 std::map<double, const gp_XYZ*>::const_iterator it = dist2nodes.begin();
277 aResAltitude = it->second->Z();
278 DEBTRACE(" number of points found: " << dist2nodes.size() << " nearest z: " << aResAltitude);
282 DEBTRACE(" number of points found: 0");
288 // AltitudePoints anAltitudePoints = GetAltitudePoints();
289 // if ( anAltitudePoints.IsEmpty() )
290 // return aResAltitude;
292 // QPolygonF aBoundingRect;
295 // // [ 0 (top-left) ] [ 1 (top-right) ]
297 // // [ 2 (bot-left) ] [ 3 (bot-right) ]
298 // AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, anInvalidAltitude ),
299 // AltitudePoint( DBL_MAX, -DBL_MAX, anInvalidAltitude ),
300 // AltitudePoint( -DBL_MAX, DBL_MAX, anInvalidAltitude ),
301 // AltitudePoint( DBL_MAX, DBL_MAX, anInvalidAltitude ) };
303 // AltitudePoints::Iterator anIter( anAltitudePoints );
304 // for ( ; anIter.More(); anIter.Next() )
306 // const AltitudePoint& aPoint = anIter.Value();
308 // double aDeltaX = Abs( aPoint.X() ) - Abs( thePoint.X() );
309 // double aDeltaY = Abs( aPoint.Y() ) - Abs( thePoint.Y() );
311 // if ( ValuesEquals( aDeltaX, 0.0 ) ) // Both left and right sides
313 // if ( ValuesEquals( aDeltaY, 0.0 ) ) // Both top and bottom sides
315 // aResAltitude = aPoint.Z();
316 // return aResAltitude;
318 // else if ( aDeltaY < 0 ) // top side
321 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
322 // aBounds[ 0 ] = aPoint;
323 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
324 // aBounds[ 1 ] = aPoint;
329 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
330 // aBounds[ 2 ] = aPoint;
331 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
332 // aBounds[ 3 ] = aPoint;
335 // else if ( aDeltaX < 0 ) // left side
337 // if ( ValuesEquals( aDeltaY, 0.0 ) )
340 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
341 // aBounds[ 0 ] = aPoint;
342 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
343 // aBounds[ 2 ] = aPoint;
345 // else if ( aDeltaY < 0 )
347 // // top left corner
348 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
349 // aBounds[ 0 ] = aPoint;
353 // // bottom left corner
354 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
355 // aBounds[ 2 ] = aPoint;
358 // else // right side
360 // if ( ValuesEquals( aDeltaY, 0.0 ) )
363 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
364 // aBounds[ 1 ] = aPoint;
365 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
366 // aBounds[ 3 ] = aPoint;
368 // else if ( aDeltaY < 0 )
370 // // top right corner
371 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
372 // aBounds[ 1 ] = aPoint;
376 // // bottom right corner
377 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
378 // aBounds[ 3 ] = aPoint;
382 // // Update bounding rectangle of our global grid
383 // aBoundingRect << QPointF( aPoint.X(), aPoint.Y() );
386 // const double LIMIT = 1E300;
387 // if( fabs( aBounds[ 0 ].X() ) > LIMIT || fabs( aBounds[ 0 ].Y() ) > LIMIT ||
388 // fabs( aBounds[ 1 ].X() ) > LIMIT || fabs( aBounds[ 1 ].Y() ) > LIMIT ||
389 // fabs( aBounds[ 2 ].X() ) > LIMIT || fabs( aBounds[ 2 ].Y() ) > LIMIT ||
390 // fabs( aBounds[ 3 ].X() ) > LIMIT || fabs( aBounds[ 3 ].Y() ) > LIMIT )
391 // return anInvalidAltitude;
394 // // Check if requested point is inside of our bounding rectangle
395 // if ( !aBoundingRect.boundingRect().contains( thePoint.X(), thePoint.Y() ) )
396 // return aResAltitude;
398 // // Calculate result altitude for point
399 // AltitudePoint aFirstPoint( aBounds[ 0 ] ), aSecPoint( aBounds[ 1 ] );
401 // // At first we merge top and bottom borders
402 // if ( aBounds[ 0 ].Y() != aBounds[ 2 ].Y() || aBounds[ 0 ].X() != aBounds[ 2 ].X() )
403 // interpolateAltitudeForPoints( thePoint, aBounds[ 0 ], aBounds[ 2 ], aFirstPoint, true );
405 // if ( aBounds[ 1 ].Y() != aBounds[ 3 ].Y() || aBounds[ 1 ].X() != aBounds[ 3 ].X() )
406 // interpolateAltitudeForPoints( thePoint, aBounds[ 1 ], aBounds[ 3 ], aSecPoint, true );
408 // AltitudePoint aResPoint( aFirstPoint );
410 // // At last we merge left and right borders
411 // if ( aFirstPoint.Y() != aSecPoint.Y() || aFirstPoint.X() != aSecPoint.X() )
412 // interpolateAltitudeForPoints( thePoint, aFirstPoint, aSecPoint, aResPoint, false );
414 // aResAltitude = aResPoint.Z();
416 // return aResAltitude;
419 void HYDROData_Bathymetry::SetFilePath( const TCollection_AsciiString& theFilePath )
421 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
424 TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const
426 TCollection_AsciiString aRes;
428 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
429 if ( !aLabel.IsNull() )
431 Handle(TDataStd_AsciiString) anAsciiStr;
432 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
433 aRes = anAsciiStr->Get();
439 void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted,
440 const bool theIsUpdate )
442 bool anIsAltitudesInverted = IsAltitudesInverted();
443 if ( anIsAltitudesInverted == theIsInverted )
446 TDataStd_Integer::Set( myLab.FindChild( DataTag_AltitudesInverted ), (Standard_Integer)theIsInverted );
453 // Update altitude points
454 AltitudePoints anAltitudePoints = GetAltitudePoints();
455 if ( anAltitudePoints.IsEmpty() )
458 AltitudePoints::Iterator anIter( anAltitudePoints );
459 for ( ; anIter.More(); anIter.Next() )
461 AltitudePoint& aPoint = anIter.ChangeValue();
462 aPoint.SetZ( aPoint.Z() * -1 );
465 SetAltitudePoints( anAltitudePoints );
468 bool HYDROData_Bathymetry::IsAltitudesInverted() const
472 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudesInverted, false );
473 if ( !aLabel.IsNull() )
475 Handle(TDataStd_Integer) anIntVal;
476 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
477 aRes = (bool)anIntVal->Get();
483 bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName )
485 // Try to open the file
486 QFile aFile( theFileName.ToCString() );
487 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
492 QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
494 AltitudePoints aPoints;
496 // Try to import the file
497 if ( aFileSuf == "xyz" )
498 aRes = importFromXYZFile( aFile, aPoints );
499 else if ( aFileSuf == "asc" )
500 aRes = importFromASCFile( aFile, aPoints );
506 // Convert from global to local CS
507 Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
508 AltitudePoints::Iterator anIter( aPoints );
509 for ( ; anIter.More(); anIter.Next() )
511 AltitudePoint& aPoint = anIter.ChangeValue();
512 aDoc->Transform( aPoint, true );
517 // Update file path and altitude points of this Bathymetry
518 SetFilePath( theFileName );
519 SetAltitudePoints( aPoints );
522 return aRes && !aPoints.IsEmpty();
525 bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,
526 AltitudePoints& thePoints ) const
528 if ( !theFile.isOpen() )
531 // Strings in file is written as:
532 // 1. X(float) Y(float) Z(float)
533 // 2. X(float) Y(float) Z(float)
541 bool anIsAltitudesInverted = IsAltitudesInverted();
542 while ( !theFile.atEnd() )
544 QString aLine = theFile.readLine().simplified();
545 if ( aLine.isEmpty() )
548 QStringList aValues = aLine.split( ' ', QString::SkipEmptyParts );
549 if ( aValues.length() < 3 )
552 AltitudePoint aPoint;
554 QString anX = aValues.value( 0 );
555 QString anY = aValues.value( 1 );
556 QString aZ = aValues.value( 2 );
558 bool isXOk = false, isYOk = false, isZOk = false;
560 aPoint.SetX( anX.toDouble( &isXOk ) );
561 aPoint.SetY( anY.toDouble( &isYOk ) );
562 aPoint.SetZ( aZ.toDouble( &isZOk ) );
564 if ( !isXOk || !isYOk || !isZOk )
567 if ( boost::math::isnan( aPoint.X() ) || boost::math::isinf( aPoint.X() ) ||
568 boost::math::isnan( aPoint.Y() ) || boost::math::isinf( aPoint.Y() ) ||
569 boost::math::isnan( aPoint.Z() ) || boost::math::isinf( aPoint.Z() ) )
572 // Invert the z value if requested
573 if ( anIsAltitudesInverted )
574 aPoint.SetZ( -aPoint.Z() );
576 thePoints.Append( aPoint );
581 std::ofstream stream( "W:/HYDRO/WORK/log.txt", std::ofstream::out );
582 aTimer.Show( stream );
588 bool HYDROData_Bathymetry::importFromASCFile( QFile& theFile,
589 AltitudePoints& thePoints ) const
591 if ( !theFile.isOpen() )
595 QStringList aStrList;
604 aLine = theFile.readLine().simplified();
605 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
606 if ( aStrList.length() != 2 && aStrList[0].toLower() != "ncols" )
608 aNCols = aStrList[1].toInt();
610 aLine = theFile.readLine().simplified();
611 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
612 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nrows" )
614 aNRows = aStrList[1].toInt();
616 aLine = theFile.readLine().simplified();
617 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
618 if ( aStrList.length() != 2 && aStrList[0].toLower() != "xllcorner" )
620 anXllCorner = aStrList[1].toDouble();
622 aLine = theFile.readLine().simplified();
623 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
624 if ( aStrList.length() != 2 && aStrList[0].toLower() != "yllcorner" )
626 anYllCorner = aStrList[1].toDouble();
628 aLine = theFile.readLine().simplified();
629 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
630 if ( aStrList.length() != 2 && aStrList[0].toLower() != "cellsize" )
632 aCellSize = aStrList[1].toDouble();
634 aLine = theFile.readLine().simplified();
635 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
636 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nodata_value" )
638 aNoDataValue = aStrList[1].toDouble();
640 bool anIsAltitudesInverted = IsAltitudesInverted();
644 while ( !theFile.atEnd() )
646 aLine = theFile.readLine().simplified();
647 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
649 aStrLength = aStrList.length();
650 if ( aStrLength == 0 )
653 if ( aStrLength != aNRows )
656 for (int j = 0; j < aNCols; j++)
658 if (aStrList[j].toDouble() != aNoDataValue)
660 AltitudePoint aPoint;
661 aPoint.SetX(anXllCorner + aCellSize*(j + 0.5));
662 aPoint.SetY(anYllCorner + aCellSize*(aNRows - i + 0.5));
663 aPoint.SetZ(aStrList[j].toDouble());
665 if ( anIsAltitudesInverted )
666 aPoint.SetZ( -aPoint.Z() );
668 thePoints.Append(aPoint);
680 Handle_HYDROData_PolylineXY HYDROData_Bathymetry::CreateBoundaryPolyline() const
682 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
683 Handle_HYDROData_PolylineXY aResult =
684 Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
686 if( aResult.IsNull() )
690 QString aPolylinePref = GetName() + "_Boundary";
691 QString aPolylineName = HYDROData_Tool::GenerateObjectName( aDocument, aPolylinePref );
692 aResult->SetName( aPolylineName );
694 double Xmin = 0.0, Xmax = 0.0, Ymin = 0.0, Ymax = 0.0;
696 AltitudePoints aPoints = GetAltitudePoints();
698 AltitudePoints::Iterator anIter( aPoints );
699 for ( ; anIter.More(); anIter.Next() )
701 const AltitudePoint& aPoint = anIter.Value();
703 double x = aPoint.X(), y = aPoint.Y();
704 if( isFirst || x<Xmin )
706 if( isFirst || x>Xmax )
708 if( isFirst || y<Ymin )
710 if( isFirst || y>Ymax )
715 aResult->AddSection( "bound", HYDROData_IPolyline::SECTION_POLYLINE, true );
716 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymin ) );
717 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymax ) );
718 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymax ) );
719 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymin ) );
725 void HYDROData_Bathymetry::UpdateLocalCS( double theDx, double theDy )
727 gp_XYZ aDelta( theDx, theDy, 0 );
728 AltitudePoints aPoints = GetAltitudePoints();
729 AltitudePoints::Iterator anIter( aPoints );
730 for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
732 AltitudePoint& aPoint = anIter.ChangeValue();
735 SetAltitudePoints( aPoints );