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(bool IsConvertToGlobal) 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 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
132 for ( int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n; )
137 AltitudePoint aPoint;
138 aPoint.SetX( aCoordsArray->Value( i++ ) );
139 aPoint.SetY( aCoordsArray->Value( i++ ) );
140 aPoint.SetZ( aCoordsArray->Value( i++ ) );
142 if( IsConvertToGlobal )
143 aDoc->Transform( aPoint, false );
144 aPoints.Append( aPoint );
150 HYDROData_QuadtreeNode* HYDROData_Bathymetry::GetQuadtreeNodes() const
152 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
155 int labkey = myLab.Tag();
156 int altkey = aLabel.Tag();
157 //DEBTRACE("GetQuadtreeNodes this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
158 // if (myQuadtree->isEmpty() )
159 if (myQuadtrees.find(labkey) == myQuadtrees.end())
161 DEBTRACE("GetQuadtreeNodes init " << this << " " << labkey);
162 HYDROData_QuadtreeNode* aQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
163 myQuadtrees[labkey] = aQuadtree;
164 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
168 Handle(TDataStd_RealArray) aCoordsArray;
169 if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
172 Nodes_3D* aListOfNodes = new Nodes_3D();
174 for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
179 double x = aCoordsArray->Value(i++);
180 double y = aCoordsArray->Value(i++);
181 double z = aCoordsArray->Value(i++);
182 gp_XYZ* aPoint = new gp_XYZ(x, y, z);
183 aListOfNodes->push_back(aPoint);
185 DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
186 aQuadtree->setNodesAndCompute(aListOfNodes);
190 return myQuadtrees[labkey];
193 void HYDROData_Bathymetry::RemoveAltitudePoints()
195 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
196 if ( !aLabel.IsNull() )
198 aLabel.ForgetAllAttributes();
203 void interpolateAltitudeForPoints( const gp_XY& thePoint,
204 const HYDROData_Bathymetry::AltitudePoint& theFirstPoint,
205 const HYDROData_Bathymetry::AltitudePoint& theSecPoint,
206 HYDROData_Bathymetry::AltitudePoint& theResPoint,
207 const bool& theIsVertical )
209 double aCoordX = thePoint.X();
210 double aCoordY = thePoint.Y();
214 aCoordX = theFirstPoint.X();
216 if ( !ValuesEquals( theFirstPoint.X(), theSecPoint.X() ) )
218 // Recalculate X coordinate by equation of line from two points
219 aCoordX = ( ( ( thePoint.Y() - theFirstPoint.Y() ) * ( theSecPoint.X() - theFirstPoint.X() ) ) /
220 ( theSecPoint.Y() - theFirstPoint.Y() ) ) + theFirstPoint.X();
225 aCoordY = theFirstPoint.Y();
227 if ( !ValuesEquals( theFirstPoint.Y(), theSecPoint.Y() ) )
229 // Recalculate y by equation of line from two points
230 aCoordY = ( ( ( thePoint.X() - theFirstPoint.X() ) * ( theSecPoint.Y() - theFirstPoint.Y() ) ) /
231 ( theSecPoint.X() - theFirstPoint.X() ) ) + theFirstPoint.Y();
235 theResPoint.SetX( aCoordX );
236 theResPoint.SetY( aCoordY );
238 // Calculate coefficient for interpolation
239 double aLength = Sqrt( Pow( theSecPoint.Y() - theFirstPoint.Y(), 2 ) +
240 Pow( theSecPoint.X() - theFirstPoint.X(), 2 ) );
242 double aInterCoeff = 0;
244 aInterCoeff = ( theSecPoint.Z() - theFirstPoint.Z() ) / aLength;
247 double aNewLength = Sqrt( Pow( theResPoint.Y() - theFirstPoint.Y(), 2 ) +
248 Pow( theResPoint.X() - theFirstPoint.X(), 2 ) );
250 // Calculate interpolated value
251 double aResVal = theFirstPoint.Z() + aInterCoeff * aNewLength;
253 theResPoint.SetZ( aResVal );
256 double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint) const
258 DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")");
259 double anInvalidAltitude = GetInvalidAltitude();
260 double aResAltitude = anInvalidAltitude;
262 HYDROData_QuadtreeNode* aQuadtree = GetQuadtreeNodes();
265 DEBTRACE(" no Quadtree");
269 std::map<double, const gp_XYZ*> dist2nodes;
270 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
271 while (dist2nodes.size() == 0)
273 aQuadtree->setPrecision(aQuadtree->getPrecision() *2);
274 DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
275 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
277 aQuadtree->NodesAround(thePoint, dist2nodes, 5.0);
278 if (dist2nodes.size())
280 std::map<double, const gp_XYZ*>::const_iterator it = dist2nodes.begin();
281 aResAltitude = it->second->Z();
282 DEBTRACE(" number of points found: " << dist2nodes.size() << " nearest z: " << aResAltitude);
286 DEBTRACE(" number of points found: 0");
292 // AltitudePoints anAltitudePoints = GetAltitudePoints();
293 // if ( anAltitudePoints.IsEmpty() )
294 // return aResAltitude;
296 // QPolygonF aBoundingRect;
299 // // [ 0 (top-left) ] [ 1 (top-right) ]
301 // // [ 2 (bot-left) ] [ 3 (bot-right) ]
302 // AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, anInvalidAltitude ),
303 // AltitudePoint( DBL_MAX, -DBL_MAX, anInvalidAltitude ),
304 // AltitudePoint( -DBL_MAX, DBL_MAX, anInvalidAltitude ),
305 // AltitudePoint( DBL_MAX, DBL_MAX, anInvalidAltitude ) };
307 // AltitudePoints::Iterator anIter( anAltitudePoints );
308 // for ( ; anIter.More(); anIter.Next() )
310 // const AltitudePoint& aPoint = anIter.Value();
312 // double aDeltaX = Abs( aPoint.X() ) - Abs( thePoint.X() );
313 // double aDeltaY = Abs( aPoint.Y() ) - Abs( thePoint.Y() );
315 // if ( ValuesEquals( aDeltaX, 0.0 ) ) // Both left and right sides
317 // if ( ValuesEquals( aDeltaY, 0.0 ) ) // Both top and bottom sides
319 // aResAltitude = aPoint.Z();
320 // return aResAltitude;
322 // else if ( aDeltaY < 0 ) // top side
325 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
326 // aBounds[ 0 ] = aPoint;
327 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
328 // aBounds[ 1 ] = aPoint;
333 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
334 // aBounds[ 2 ] = aPoint;
335 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
336 // aBounds[ 3 ] = aPoint;
339 // else if ( aDeltaX < 0 ) // left side
341 // if ( ValuesEquals( aDeltaY, 0.0 ) )
344 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
345 // aBounds[ 0 ] = aPoint;
346 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
347 // aBounds[ 2 ] = aPoint;
349 // else if ( aDeltaY < 0 )
351 // // top left corner
352 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 0 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 0 ].Y() ) )
353 // aBounds[ 0 ] = aPoint;
357 // // bottom left corner
358 // if ( ValuesMoreEquals( aPoint.X(), aBounds[ 2 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 2 ].Y() ) )
359 // aBounds[ 2 ] = aPoint;
362 // else // right side
364 // if ( ValuesEquals( aDeltaY, 0.0 ) )
367 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
368 // aBounds[ 1 ] = aPoint;
369 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
370 // aBounds[ 3 ] = aPoint;
372 // else if ( aDeltaY < 0 )
374 // // top right corner
375 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 1 ].X() ) && ValuesMoreEquals( aPoint.Y(), aBounds[ 1 ].Y() ) )
376 // aBounds[ 1 ] = aPoint;
380 // // bottom right corner
381 // if ( ValuesLessEquals( aPoint.X(), aBounds[ 3 ].X() ) && ValuesLessEquals( aPoint.Y(), aBounds[ 3 ].Y() ) )
382 // aBounds[ 3 ] = aPoint;
386 // // Update bounding rectangle of our global grid
387 // aBoundingRect << QPointF( aPoint.X(), aPoint.Y() );
390 // const double LIMIT = 1E300;
391 // if( fabs( aBounds[ 0 ].X() ) > LIMIT || fabs( aBounds[ 0 ].Y() ) > LIMIT ||
392 // fabs( aBounds[ 1 ].X() ) > LIMIT || fabs( aBounds[ 1 ].Y() ) > LIMIT ||
393 // fabs( aBounds[ 2 ].X() ) > LIMIT || fabs( aBounds[ 2 ].Y() ) > LIMIT ||
394 // fabs( aBounds[ 3 ].X() ) > LIMIT || fabs( aBounds[ 3 ].Y() ) > LIMIT )
395 // return anInvalidAltitude;
398 // // Check if requested point is inside of our bounding rectangle
399 // if ( !aBoundingRect.boundingRect().contains( thePoint.X(), thePoint.Y() ) )
400 // return aResAltitude;
402 // // Calculate result altitude for point
403 // AltitudePoint aFirstPoint( aBounds[ 0 ] ), aSecPoint( aBounds[ 1 ] );
405 // // At first we merge top and bottom borders
406 // if ( aBounds[ 0 ].Y() != aBounds[ 2 ].Y() || aBounds[ 0 ].X() != aBounds[ 2 ].X() )
407 // interpolateAltitudeForPoints( thePoint, aBounds[ 0 ], aBounds[ 2 ], aFirstPoint, true );
409 // if ( aBounds[ 1 ].Y() != aBounds[ 3 ].Y() || aBounds[ 1 ].X() != aBounds[ 3 ].X() )
410 // interpolateAltitudeForPoints( thePoint, aBounds[ 1 ], aBounds[ 3 ], aSecPoint, true );
412 // AltitudePoint aResPoint( aFirstPoint );
414 // // At last we merge left and right borders
415 // if ( aFirstPoint.Y() != aSecPoint.Y() || aFirstPoint.X() != aSecPoint.X() )
416 // interpolateAltitudeForPoints( thePoint, aFirstPoint, aSecPoint, aResPoint, false );
418 // aResAltitude = aResPoint.Z();
420 // return aResAltitude;
423 void HYDROData_Bathymetry::SetFilePath( const TCollection_AsciiString& theFilePath )
425 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
428 TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const
430 TCollection_AsciiString aRes;
432 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
433 if ( !aLabel.IsNull() )
435 Handle(TDataStd_AsciiString) anAsciiStr;
436 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
437 aRes = anAsciiStr->Get();
443 void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted,
444 const bool theIsUpdate )
446 bool anIsAltitudesInverted = IsAltitudesInverted();
447 if ( anIsAltitudesInverted == theIsInverted )
450 TDataStd_Integer::Set( myLab.FindChild( DataTag_AltitudesInverted ), (Standard_Integer)theIsInverted );
457 // Update altitude points
458 AltitudePoints anAltitudePoints = GetAltitudePoints();
459 if ( anAltitudePoints.IsEmpty() )
462 AltitudePoints::Iterator anIter( anAltitudePoints );
463 for ( ; anIter.More(); anIter.Next() )
465 AltitudePoint& aPoint = anIter.ChangeValue();
466 aPoint.SetZ( aPoint.Z() * -1 );
469 SetAltitudePoints( anAltitudePoints );
472 bool HYDROData_Bathymetry::IsAltitudesInverted() const
476 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudesInverted, false );
477 if ( !aLabel.IsNull() )
479 Handle(TDataStd_Integer) anIntVal;
480 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
481 aRes = (bool)anIntVal->Get();
487 bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName )
489 // Try to open the file
490 QFile aFile( theFileName.ToCString() );
491 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
496 QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
498 AltitudePoints aPoints;
500 // Try to import the file
501 if ( aFileSuf == "xyz" )
502 aRes = importFromXYZFile( aFile, aPoints );
503 else if ( aFileSuf == "asc" )
504 aRes = importFromASCFile( aFile, aPoints );
510 // Convert from global to local CS
511 Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
512 AltitudePoints::Iterator anIter( aPoints );
513 for ( ; anIter.More(); anIter.Next() )
515 AltitudePoint& aPoint = anIter.ChangeValue();
516 aDoc->Transform( aPoint, true );
521 // Update file path and altitude points of this Bathymetry
522 SetFilePath( theFileName );
523 SetAltitudePoints( aPoints );
526 return aRes && !aPoints.IsEmpty();
529 bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,
530 AltitudePoints& thePoints ) const
532 if ( !theFile.isOpen() )
535 // Strings in file is written as:
536 // 1. X(float) Y(float) Z(float)
537 // 2. X(float) Y(float) Z(float)
545 bool anIsAltitudesInverted = IsAltitudesInverted();
546 while ( !theFile.atEnd() )
548 QString aLine = theFile.readLine().simplified();
549 if ( aLine.isEmpty() )
552 QStringList aValues = aLine.split( ' ', QString::SkipEmptyParts );
553 if ( aValues.length() < 3 )
556 AltitudePoint aPoint;
558 QString anX = aValues.value( 0 );
559 QString anY = aValues.value( 1 );
560 QString aZ = aValues.value( 2 );
562 bool isXOk = false, isYOk = false, isZOk = false;
564 aPoint.SetX( anX.toDouble( &isXOk ) );
565 aPoint.SetY( anY.toDouble( &isYOk ) );
566 aPoint.SetZ( aZ.toDouble( &isZOk ) );
568 if ( !isXOk || !isYOk || !isZOk )
571 if ( boost::math::isnan( aPoint.X() ) || boost::math::isinf( aPoint.X() ) ||
572 boost::math::isnan( aPoint.Y() ) || boost::math::isinf( aPoint.Y() ) ||
573 boost::math::isnan( aPoint.Z() ) || boost::math::isinf( aPoint.Z() ) )
576 // Invert the z value if requested
577 if ( anIsAltitudesInverted )
578 aPoint.SetZ( -aPoint.Z() );
580 thePoints.Append( aPoint );
585 std::ofstream stream( "W:/HYDRO/WORK/log.txt", std::ofstream::out );
586 aTimer.Show( stream );
592 bool HYDROData_Bathymetry::importFromASCFile( QFile& theFile,
593 AltitudePoints& thePoints ) const
595 if ( !theFile.isOpen() )
599 QStringList aStrList;
608 aLine = theFile.readLine().simplified();
609 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
610 if ( aStrList.length() != 2 && aStrList[0].toLower() != "ncols" )
612 aNCols = aStrList[1].toInt();
614 aLine = theFile.readLine().simplified();
615 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
616 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nrows" )
618 aNRows = aStrList[1].toInt();
620 aLine = theFile.readLine().simplified();
621 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
622 if ( aStrList.length() != 2 && aStrList[0].toLower() != "xllcorner" )
624 anXllCorner = aStrList[1].toDouble();
626 aLine = theFile.readLine().simplified();
627 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
628 if ( aStrList.length() != 2 && aStrList[0].toLower() != "yllcorner" )
630 anYllCorner = aStrList[1].toDouble();
632 aLine = theFile.readLine().simplified();
633 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
634 if ( aStrList.length() != 2 && aStrList[0].toLower() != "cellsize" )
636 aCellSize = aStrList[1].toDouble();
638 aLine = theFile.readLine().simplified();
639 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
640 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nodata_value" )
642 aNoDataValue = aStrList[1].toDouble();
644 bool anIsAltitudesInverted = IsAltitudesInverted();
648 while ( !theFile.atEnd() )
650 aLine = theFile.readLine().simplified();
651 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
653 aStrLength = aStrList.length();
654 if ( aStrLength == 0 )
657 if ( aStrLength != aNRows )
660 for (int j = 0; j < aNCols; j++)
662 if (aStrList[j].toDouble() != aNoDataValue)
664 AltitudePoint aPoint;
665 aPoint.SetX(anXllCorner + aCellSize*(j + 0.5));
666 aPoint.SetY(anYllCorner + aCellSize*(aNRows - i + 0.5));
667 aPoint.SetZ(aStrList[j].toDouble());
669 if ( anIsAltitudesInverted )
670 aPoint.SetZ( -aPoint.Z() );
672 thePoints.Append(aPoint);
684 Handle_HYDROData_PolylineXY HYDROData_Bathymetry::CreateBoundaryPolyline() const
686 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
687 Handle_HYDROData_PolylineXY aResult =
688 Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
690 if( aResult.IsNull() )
694 QString aPolylinePref = GetName() + "_Boundary";
695 QString aPolylineName = HYDROData_Tool::GenerateObjectName( aDocument, aPolylinePref );
696 aResult->SetName( aPolylineName );
698 double Xmin = 0.0, Xmax = 0.0, Ymin = 0.0, Ymax = 0.0;
700 AltitudePoints aPoints = GetAltitudePoints();
702 AltitudePoints::Iterator anIter( aPoints );
703 for ( ; anIter.More(); anIter.Next() )
705 const AltitudePoint& aPoint = anIter.Value();
707 double x = aPoint.X(), y = aPoint.Y();
708 if( isFirst || x<Xmin )
710 if( isFirst || x>Xmax )
712 if( isFirst || y<Ymin )
714 if( isFirst || y>Ymax )
719 aResult->AddSection( "bound", HYDROData_IPolyline::SECTION_POLYLINE, true );
720 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymin ) );
721 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymax ) );
722 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymax ) );
723 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymin ) );
725 aResult->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
732 void HYDROData_Bathymetry::UpdateLocalCS( double theDx, double theDy )
734 gp_XYZ aDelta( theDx, theDy, 0 );
735 AltitudePoints aPoints = GetAltitudePoints();
736 AltitudePoints::Iterator anIter( aPoints );
737 for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
739 AltitudePoint& aPoint = anIter.ChangeValue();
742 SetAltitudePoints( aPoints );