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"
23 #include "HYDROData_QuadtreeNode.hxx"
28 #include <TDataStd_RealArray.hxx>
29 #include <TDataStd_AsciiString.hxx>
30 #include <TDataStd_Integer.hxx>
31 #include <TDataStd_ExtStringArray.hxx>
38 #include <QStringList>
42 #include <vtkPoints.h>
43 #include <vtkDelaunay2D.h>
44 #include <vtkPolyData.h>
45 #include <vtkSmartPointer.h>
46 #include <vtkIdList.h>
55 #include <OSD_Timer.hxx>
59 #include "HYDRO_trace.hxx"
61 const int BLOCK_SIZE = 1000;
63 IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
64 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
66 //HYDROData_QuadtreeNode* HYDROData_Bathymetry::myQuadtree = 0;
68 std::map<int, HYDROData_QuadtreeNode*> HYDROData_Bathymetry::myQuadtrees;
71 std::map<int, vtkPolyData*> HYDROData_Bathymetry::myDelaunay2D;
74 inline double sqr( double x )
79 HYDROData_Bathymetry::AltitudePoint::AltitudePoint( double x, double y, double z )
84 double HYDROData_Bathymetry::AltitudePoint::SquareDistance( const HYDROData_Bathymetry::AltitudePoint& p ) const
93 HYDROData_Bathymetry::HYDROData_Bathymetry()
94 : HYDROData_IAltitudeObject()
98 HYDROData_Bathymetry::~HYDROData_Bathymetry()
102 QStringList HYDROData_Bathymetry::DumpToPython( const QString& thePyScriptPath,
103 MapOfTreatedObjects& theTreatedObjects ) const
105 QStringList aResList = dumpObjectCreation( theTreatedObjects );
106 QString aBathymetryName = GetObjPyName();
108 aResList << QString( "%1.SetAltitudesInverted( %2 )" )
109 .arg( aBathymetryName ).arg( IsAltitudesInverted() );
111 TCollection_AsciiString aFilePath = GetFilePath();
112 aResList << QString( "if not(%1.ImportFromFile( \"%2\" )):" )
113 .arg( aBathymetryName ).arg( aFilePath.ToCString() );
114 aResList << QString( " raise ValueError('problem while loading bathymetry')" );
115 aResList << QString( "" );
116 aResList << QString( "%1.Update()" ).arg( aBathymetryName );
117 aResList << QString( "" );
122 void HYDROData_Bathymetry::SetAltitudePoints( const HYDROData_Bathymetry::AltitudePoints& thePoints )
124 RemoveAltitudePoints();
126 if ( thePoints.empty() )
130 Handle(TDataStd_RealArray) aCoordsArray =
131 TDataStd_RealArray::Set( myLab.FindChild( DataTag_AltitudePoints ), 0, thePoints.size() * 3 - 1 );
133 HYDROData_Bathymetry::AltitudePoints::const_iterator anIter = thePoints.begin(), aLast = thePoints.end();
134 for ( int i = 0 ; anIter!=aLast; ++i, ++anIter )
136 const HYDROData_Bathymetry::AltitudePoint& aPoint = *anIter;
138 aCoordsArray->SetValue( i * 3, aPoint.X );
139 aCoordsArray->SetValue( i * 3 + 1, aPoint.Y );
140 aCoordsArray->SetValue( i * 3 + 2, aPoint.Z );
146 HYDROData_Bathymetry::AltitudePoints HYDROData_Bathymetry::GetAltitudePoints(bool IsConvertToGlobal) const
148 HYDROData_Bathymetry::AltitudePoints aPoints;
150 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
151 if ( aLabel.IsNull() )
154 Handle(TDataStd_RealArray) aCoordsArray;
155 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aCoordsArray ) )
158 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
159 int q = ( aCoordsArray->Upper() - aCoordsArray->Lower() + 1 ) / 3;
160 aPoints.reserve( q );
161 for ( int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n; )
166 HYDROData_Bathymetry::AltitudePoint aPoint;
167 aPoint.X = aCoordsArray->Value( i++ );
168 aPoint.Y = aCoordsArray->Value( i++ );
169 aPoint.Z = aCoordsArray->Value( i++ );
171 if( IsConvertToGlobal )
172 aDoc->Transform( aPoint.X, aPoint.Y, aPoint.Z, false );
173 aPoints.push_back( aPoint );
179 HYDROData_QuadtreeNode* HYDROData_Bathymetry::GetQuadtreeNodes() const
181 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
184 int labkey = myLab.Tag();
185 //int altkey = aLabel.Tag();
186 //DEBTRACE("GetQuadtreeNodes this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
187 // if (myQuadtree->isEmpty() )
188 if (myQuadtrees.find(labkey) == myQuadtrees.end())
190 //DEBTRACE("GetQuadtreeNodes init " << this << " " << labkey);
191 HYDROData_QuadtreeNode* aQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
192 myQuadtrees[labkey] = aQuadtree;
193 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
197 Handle(TDataStd_RealArray) aCoordsArray;
198 if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
201 Nodes_3D* aListOfNodes = new Nodes_3D();
204 for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
209 double x = aCoordsArray->Value(i++);
210 double y = aCoordsArray->Value(i++);
211 double z = aCoordsArray->Value(i++);
212 gpi_XYZ* aPoint = new gpi_XYZ(x, y, z, index);
214 aListOfNodes->push_back(aPoint);
216 //DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
217 aQuadtree->setNodesAndCompute(aListOfNodes);
221 return myQuadtrees[labkey];
225 vtkPolyData* HYDROData_Bathymetry::GetVtkDelaunay2D() const
227 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
230 int labkey = myLab.Tag();
231 //int altkey = aLabel.Tag();
232 //DEBTRACE("GetVtkDelaunay2D this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
233 if (myDelaunay2D.find(labkey) == myDelaunay2D.end())
235 //DEBTRACE("GetVtkDelaunay2D init " << this << " " << labkey);
237 TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
240 Handle(TDataStd_RealArray) aCoordsArray;
241 if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
244 vtkPoints *points = vtkPoints::New();
245 points->Allocate(aCoordsArray->Upper() +1);
246 for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
250 double x = aCoordsArray->Value(i++);
251 double y = aCoordsArray->Value(i++);
252 double z = aCoordsArray->Value(i++);
253 vtkIdType index = points->InsertNextPoint(x, y, z); // same index than in GetQuadtreeNodes
254 //DEBTRACE(" " << index);
256 vtkPolyData* profile = vtkPolyData::New();
257 profile->SetPoints(points);
258 //DEBTRACE("Number of Points: "<< points->GetNumberOfPoints());
260 vtkDelaunay2D* delaunay2D = vtkDelaunay2D::New();
261 delaunay2D->SetInputData(profile);
262 delaunay2D->Update();
263 vtkPolyData* data = delaunay2D->GetOutput();
265 myDelaunay2D[labkey] = data;
269 return myDelaunay2D[labkey];
273 void HYDROData_Bathymetry::RemoveAltitudePoints()
275 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
276 if ( !aLabel.IsNull() )
278 aLabel.ForgetAllAttributes();
283 void interpolateAltitudeForPoints( const gp_XY& thePoint,
284 const HYDROData_Bathymetry::AltitudePoint& theFirstPoint,
285 const HYDROData_Bathymetry::AltitudePoint& theSecPoint,
286 HYDROData_Bathymetry::AltitudePoint& theResPoint,
287 const bool& theIsVertical )
289 double aCoordX = thePoint.X();
290 double aCoordY = thePoint.Y();
294 aCoordX = theFirstPoint.X;
296 if ( !ValuesEquals( theFirstPoint.X, theSecPoint.X ) )
298 // Recalculate X coordinate by equation of line from two points
299 aCoordX = ( ( ( thePoint.Y() - theFirstPoint.Y ) * ( theSecPoint.X - theFirstPoint.X ) ) /
300 ( theSecPoint.Y - theFirstPoint.Y ) ) + theFirstPoint.X;
305 aCoordY = theFirstPoint.Y;
307 if ( !ValuesEquals( theFirstPoint.Y, theSecPoint.Y ) )
309 // Recalculate y by equation of line from two points
310 aCoordY = ( ( ( thePoint.X() - theFirstPoint.X ) * ( theSecPoint.Y - theFirstPoint.Y ) ) /
311 ( theSecPoint.X - theFirstPoint.X ) ) + theFirstPoint.Y;
315 theResPoint.X = aCoordX;
316 theResPoint.Y = aCoordY;
318 // Calculate coefficient for interpolation
319 double aLength = Sqrt( Pow( theSecPoint.Y - theFirstPoint.Y, 2 ) +
320 Pow( theSecPoint.X - theFirstPoint.X, 2 ) );
322 double aInterCoeff = 0;
324 aInterCoeff = ( theSecPoint.Z - theFirstPoint.Z ) / aLength;
327 double aNewLength = Sqrt( Pow( theResPoint.Y - theFirstPoint.Y, 2 ) +
328 Pow( theResPoint.X - theFirstPoint.X, 2 ) );
330 // Calculate interpolated value
331 double aResVal = theFirstPoint.Z + aInterCoeff * aNewLength;
333 theResPoint.Z = aResVal;
336 bool interpolZtriangle(const gp_XY& point, vtkPolyData* delaunay2D, vtkIdList* triangle, double& z)
339 int nbPts = triangle->GetNumberOfIds();
342 //DEBTRACE("not a triangle ?");
346 double v[3][3]; // v[i][j] = j coordinate of node i
347 for (int i=0; i<3; i++)
349 s[i] = triangle->GetId(i);
350 delaunay2D->GetPoint(s[i],v[i]);
352 //DEBTRACE("triangle node id: " << s[0] << " " << s[1] << " " << s[2]);
353 //DEBTRACE("triangle node 0: " << v[0][0] << " " << v[0][1] << " " << v[0][2]);
354 //DEBTRACE("triangle node 1: " << v[1][0] << " " << v[1][1] << " " << v[1][2]);
355 //DEBTRACE("triangle node 2: " << v[2][0] << " " << v[2][1] << " " << v[2][2]);
357 // compute barycentric coordinates (https://en.wikipedia.org/wiki/Barycentric_coordinate_system)
358 // det = (y2-y3)(x1-x3)+(x3-x2)(y1-y3)
359 double det = (v[1][1]-v[2][1])*(v[0][0]-v[2][0]) + (v[2][0]-v[1][0])*(v[0][1]-v[2][1]);
362 //DEBTRACE("flat triangle ?");
366 // l0 = ((y2-y3)(x -x3)+(x3-x2)(y -y3))/det
367 double l0 = (v[1][1]-v[2][1])*(point.X()-v[2][0]) + (v[2][0]-v[1][0])*(point.Y()-v[2][1]);
370 // l1 = ((y3-y1)(x -x3)+(x1-x3)(y -y3))/det
371 double l1 = (v[2][1]-v[0][1])*(point.X()-v[2][0]) + (v[0][0]-v[2][0])*(point.Y()-v[2][1]);
374 double l2 = 1 -l0 -l1;
375 //DEBTRACE("l0, l1, l2: " << l0 << " " << l1 << " " << l2);
377 if ((l0>=0) && (l0<=1) && (l1>=0) && (l1<=1) && (l2>=0) && (l2<=1))
379 z = l0*v[0][2] + l1*v[1][2] + l2*v[2][2];
386 double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint, int theMethod) const
388 //DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << "), interpolation method: " << theMethod);
389 double anInvalidAltitude = GetInvalidAltitude();
390 double aResAltitude = anInvalidAltitude;
392 // --- find the nearest point in the bathymetry cloud, with quadtree
394 HYDROData_QuadtreeNode* aQuadtree = GetQuadtreeNodes();
397 //DEBTRACE(" no Quadtree");
401 std::map<double, const gpi_XYZ*> dist2nodes;
402 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
403 while (dist2nodes.size() == 0)
405 aQuadtree->setPrecision(aQuadtree->getPrecision() *2);
406 //DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
407 aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
409 std::map<double, const gpi_XYZ*>::const_iterator it = dist2nodes.begin();
410 aResAltitude = it->second->Z();
411 int nodeIndex = it->second->getIndex();
412 //DEBTRACE(" number of points found: " << dist2nodes.size() << " nearest z: " << aResAltitude << " point index: " << nodeIndex);
414 // --- for coarse bathymetry clouds (when the TELEMAC mesh is more refined than the bathymetry cloud)
415 // interpolation is required.
416 // - get a Delaunay2D mesh on the bathymetry cloud,
417 // - get the triangle containing the point in the Delaunay2D mesh,
418 // - interpolate altitude
420 bool isBathyInterpolRequired = false;
422 isBathyInterpolRequired =true;
425 if (isBathyInterpolRequired)
427 vtkPolyData* aDelaunay2D = GetVtkDelaunay2D();
428 vtkIdList* cells= vtkIdList::New();
430 vtkIdList* points= vtkIdList::New();
431 points->Allocate(64);
432 aDelaunay2D->GetPointCells(nodeIndex, cells);
433 vtkIdType nbCells = cells->GetNumberOfIds();
434 //DEBTRACE(" triangles on nearest point: " << nbCells);
435 bool isInside = false;
436 for (int i=0; i<nbCells; i++)
438 aDelaunay2D->GetCellPoints(cells->GetId(i), points);
440 isInside = interpolZtriangle(thePoint, aDelaunay2D, points, z);
444 //DEBTRACE(" interpolated z: " << z);
450 // DEBTRACE(" point outside triangles, nearest z kept");
457 void HYDROData_Bathymetry::SetFilePath( const TCollection_AsciiString& theFilePath )
459 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
462 void HYDROData_Bathymetry::SetFilePaths( const QStringList& theFilePaths )
465 Handle_TDataStd_ExtStringArray TExtStrArr = TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_FilePaths ), 1, theFilePaths.size() );
466 foreach (QString filepath, theFilePaths)
468 std::string sstr = filepath.toStdString();
469 const char* Val = sstr.c_str();
470 TExtStrArr->SetValue(i, TCollection_ExtendedString(Val));
475 TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const
477 TCollection_AsciiString aRes;
479 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
480 if ( !aLabel.IsNull() )
482 Handle(TDataStd_AsciiString) anAsciiStr;
483 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
484 aRes = anAsciiStr->Get();
488 aLabel = myLab.FindChild( DataTag_FilePaths, false );
489 if ( !aLabel.IsNull() )
491 Handle(TDataStd_ExtStringArray) anExtStrArr;
492 if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) )
493 aRes = anExtStrArr->Value(1); //try take the first; convert extstring to asciistring
500 QStringList HYDROData_Bathymetry::GetFilePaths() const
504 TDF_Label aLabel = myLab.FindChild( DataTag_FilePaths, false );
505 if ( !aLabel.IsNull() )
507 Handle(TDataStd_ExtStringArray) anExtStrArr;
508 if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) )
510 for (int i = anExtStrArr->Lower(); i <= anExtStrArr->Upper(); i++ )
512 Standard_ExtString str = anExtStrArr->Value(i).ToExtString();
513 TCollection_AsciiString aText (str);
514 aResL << QString(aText.ToCString());
518 else //backward compatibility
520 TDF_Label anOldLabel = myLab.FindChild( DataTag_FilePath, false );
521 if ( !anOldLabel.IsNull() )
523 Handle(TDataStd_AsciiString) anAsciiStr;
524 if ( anOldLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
525 aResL << QString(anAsciiStr->Get().ToCString());
532 void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted,
533 const bool theIsUpdate )
535 bool anIsAltitudesInverted = IsAltitudesInverted();
536 if ( anIsAltitudesInverted == theIsInverted )
539 TDataStd_Integer::Set( myLab.FindChild( DataTag_AltitudesInverted ), (Standard_Integer)theIsInverted );
546 // Update altitude points
547 HYDROData_Bathymetry::AltitudePoints anAltitudePoints = GetAltitudePoints();
548 if ( anAltitudePoints.empty() )
551 HYDROData_Bathymetry::AltitudePoints::iterator anIter = anAltitudePoints.begin(), aLast = anAltitudePoints.end();
552 for ( ; anIter!=aLast; ++anIter )
554 HYDROData_Bathymetry::AltitudePoint& aPoint = *anIter;
558 SetAltitudePoints( anAltitudePoints );
561 bool HYDROData_Bathymetry::IsAltitudesInverted() const
565 TDF_Label aLabel = myLab.FindChild( DataTag_AltitudesInverted, false );
566 if ( !aLabel.IsNull() )
568 Handle(TDataStd_Integer) anIntVal;
569 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
570 aRes = (bool)anIntVal->Get();
576 bool HYDROData_Bathymetry::ImportFromFile( const QString& theFileName )
578 return ImportFromFiles(QStringList(theFileName));
581 bool HYDROData_Bathymetry::ImportFromFiles( const QStringList& theFileNames )
583 AltitudePoints AllPoints;
586 foreach (QString theFileName, theFileNames)
588 // Try to open the file
589 QFile aFile( theFileName );
590 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
593 QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
595 HYDROData_Bathymetry::AltitudePoints aPoints;
597 // Try to import the file
598 if ( aFileSuf == "xyz" )
599 Stat = importFromXYZFile( aFile, aPoints );
600 else if ( aFileSuf == "asc" )
601 Stat = importFromASCFile( aFile, aPoints );
604 continue; //ignore this points
609 AllPoints.insert(AllPoints.end(), aPoints.begin(), aPoints.end());
612 // Convert from global to local CS
613 Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
614 HYDROData_Bathymetry::AltitudePoints::iterator anIter = AllPoints.begin(), aLast = AllPoints.end();
615 for ( ; anIter!=aLast; ++anIter )
617 HYDROData_Bathymetry::AltitudePoint& aPoint = *anIter;
618 aDoc->Transform( aPoint.X, aPoint.Y, aPoint.Z, true );
623 // Update file path and altitude points of this Bathymetry
624 SetFilePaths (theFileNames );
625 SetAltitudePoints( AllPoints );
628 return Stat && !AllPoints.empty();
631 bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,
632 HYDROData_Bathymetry::AltitudePoints& thePoints ) const
634 if ( !theFile.isOpen() )
637 // Strings in file is written as:
638 // 1. X(float) Y(float) Z(float)
639 // 2. X(float) Y(float) Z(float)
647 bool anIsAltitudesInverted = IsAltitudesInverted();
648 while ( !theFile.atEnd() )
650 QString aLine = theFile.readLine().simplified();
651 if ( aLine.isEmpty() )
654 QStringList aValues = aLine.split( ' ', QString::SkipEmptyParts );
655 if ( aValues.length() < 3 )
658 HYDROData_Bathymetry::AltitudePoint aPoint;
660 QString anX = aValues.value( 0 );
661 QString anY = aValues.value( 1 );
662 QString aZ = aValues.value( 2 );
664 bool isXOk = false, isYOk = false, isZOk = false;
666 aPoint.X = anX.toDouble( &isXOk );
667 aPoint.Y = anY.toDouble( &isYOk );
668 aPoint.Z = aZ.toDouble( &isZOk );
670 if ( !isXOk || !isYOk || !isZOk )
673 if ( HYDROData_Tool::IsNan( aPoint.X ) || HYDROData_Tool::IsInf( aPoint.X ) ||
674 HYDROData_Tool::IsNan( aPoint.Y ) || HYDROData_Tool::IsInf( aPoint.Y ) ||
675 HYDROData_Tool::IsNan( aPoint.Z ) || HYDROData_Tool::IsInf( aPoint.Z ) )
678 // Invert the z value if requested
679 if ( anIsAltitudesInverted )
680 aPoint.Z = -aPoint.Z;
682 if( thePoints.size()>=thePoints.capacity() )
683 thePoints.reserve( thePoints.size()+BLOCK_SIZE );
685 thePoints.push_back( aPoint );
690 std::ofstream stream( "W:/HYDRO/WORK/log.txt", std::ofstream::out );
691 aTimer.Show( stream );
697 bool HYDROData_Bathymetry::importFromASCFile( QFile& theFile,
698 HYDROData_Bathymetry::AltitudePoints& thePoints ) const
700 if ( !theFile.isOpen() )
704 QStringList aStrList;
713 aLine = theFile.readLine().simplified();
714 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
715 if ( aStrList.length() != 2 && aStrList[0].toLower() != "ncols" )
717 aNCols = aStrList[1].toInt();
719 aLine = theFile.readLine().simplified();
720 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
721 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nrows" )
723 aNRows = aStrList[1].toInt();
725 aLine = theFile.readLine().simplified();
726 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
727 if ( aStrList.length() != 2 && aStrList[0].toLower() != "xllcorner" )
729 anXllCorner = aStrList[1].toDouble();
731 aLine = theFile.readLine().simplified();
732 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
733 if ( aStrList.length() != 2 && aStrList[0].toLower() != "yllcorner" )
735 anYllCorner = aStrList[1].toDouble();
737 aLine = theFile.readLine().simplified();
738 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
739 if ( aStrList.length() != 2 && aStrList[0].toLower() != "cellsize" )
741 aCellSize = aStrList[1].toDouble();
743 aLine = theFile.readLine().simplified();
744 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
745 if ( aStrList.length() != 2 && aStrList[0].toLower() != "nodata_value" )
747 aNoDataValue = aStrList[1].toDouble();
749 bool anIsAltitudesInverted = IsAltitudesInverted();
753 while ( !theFile.atEnd() )
755 aLine = theFile.readLine().simplified();
756 aStrList = aLine.split( ' ', QString::SkipEmptyParts );
758 aStrLength = aStrList.length();
759 if ( aStrLength == 0 )
762 if ( aStrLength != aNRows )
765 for (int j = 0; j < aNCols; j++)
767 if (aStrList[j].toDouble() != aNoDataValue)
769 HYDROData_Bathymetry::AltitudePoint aPoint;
770 aPoint.X = anXllCorner + aCellSize*(j + 0.5);
771 aPoint.Y = anYllCorner + aCellSize*(aNRows - i + 0.5);
772 aPoint.Z = aStrList[j].toDouble();
774 if ( anIsAltitudesInverted )
775 aPoint.Z = -aPoint.Z;
777 if( thePoints.size()>=thePoints.capacity() )
778 thePoints.reserve( thePoints.size()+BLOCK_SIZE );
779 thePoints.push_back(aPoint);
789 Handle_HYDROData_PolylineXY HYDROData_Bathymetry::CreateBoundaryPolyline() const
791 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
792 Handle_HYDROData_PolylineXY aResult =
793 Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
795 if( aResult.IsNull() )
799 QString aPolylinePref = GetName() + "_Boundary";
800 QString aPolylineName = HYDROData_Tool::GenerateObjectName( aDocument, aPolylinePref );
801 aResult->SetName( aPolylineName );
803 double Xmin = 0.0, Xmax = 0.0, Ymin = 0.0, Ymax = 0.0;
805 HYDROData_Bathymetry::AltitudePoints aPoints = GetAltitudePoints();
807 HYDROData_Bathymetry::AltitudePoints::const_iterator anIter = aPoints.begin(), aLast = aPoints.end();
808 for ( ; anIter!=aLast; ++anIter )
810 const HYDROData_Bathymetry::AltitudePoint& aPoint = *anIter;
812 double x = aPoint.X, y = aPoint.Y;
813 if( isFirst || x<Xmin )
815 if( isFirst || x>Xmax )
817 if( isFirst || y<Ymin )
819 if( isFirst || y>Ymax )
824 aResult->AddSection( "bound", HYDROData_IPolyline::SECTION_POLYLINE, true );
825 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymin ) );
826 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymax ) );
827 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymax ) );
828 aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymin ) );
830 aResult->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
837 void HYDROData_Bathymetry::UpdateLocalCS( double theDx, double theDy )
839 gp_XYZ aDelta( theDx, theDy, 0 );
840 HYDROData_Bathymetry::AltitudePoints aPoints = GetAltitudePoints();
841 HYDROData_Bathymetry::AltitudePoints::iterator anIter = aPoints.begin(), aLast = aPoints.end();
842 for ( int i = 0; anIter!=aLast; ++i, ++anIter )
844 HYDROData_Bathymetry::AltitudePoint& aPoint = *anIter;
845 aPoint.X += aDelta.X();
846 aPoint.Y += aDelta.Y();
847 aPoint.Z += aDelta.Z();
849 SetAltitudePoints( aPoints );