#include <TDataStd_RealArray.hxx>
#include <TDataStd_AsciiString.hxx>
#include <TDataStd_Integer.hxx>
+#include <TDataStd_ExtStringArray.hxx>
#include <QColor>
#include <QFile>
#include <QPointF>
#include <QPolygonF>
#include <QStringList>
+#include <QString>
#ifndef LIGHT_MODE
#include <vtkPoints.h>
std::map<int, vtkPolyData*> HYDROData_Bathymetry::myDelaunay2D;
#endif
+inline double sqr( double x )
+{
+ return x*x;
+}
+
+HYDROData_Bathymetry::AltitudePoint::AltitudePoint( double x, double y, double z )
+{
+ X=x; Y=y; Z=z;
+}
+
+double HYDROData_Bathymetry::AltitudePoint::SquareDistance( const HYDROData_Bathymetry::AltitudePoint& p ) const
+{
+ double d = 0;
+ d += sqr( X - p.X );
+ d += sqr( Y - p.Y );
+ d += sqr( Z - p.Z );
+ return d;
+}
HYDROData_Bathymetry::HYDROData_Bathymetry()
: HYDROData_IAltitudeObject()
// if (myQuadtree->isEmpty() )
if (myQuadtrees.find(labkey) == myQuadtrees.end())
{
- DEBTRACE("GetQuadtreeNodes init " << this << " " << labkey);
+ //DEBTRACE("GetQuadtreeNodes init " << this << " " << labkey);
HYDROData_QuadtreeNode* aQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
myQuadtrees[labkey] = aQuadtree;
TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
index++;
aListOfNodes->push_back(aPoint);
}
- DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
+ //DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
aQuadtree->setNodesAndCompute(aListOfNodes);
return aQuadtree;
}
//DEBTRACE("GetVtkDelaunay2D this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
if (myDelaunay2D.find(labkey) == myDelaunay2D.end())
{
- DEBTRACE("GetVtkDelaunay2D init " << this << " " << labkey);
+ //DEBTRACE("GetVtkDelaunay2D init " << this << " " << labkey);
TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
if (aLabel.IsNull())
}
vtkPolyData* profile = vtkPolyData::New();
profile->SetPoints(points);
- DEBTRACE("Number of Points: "<< points->GetNumberOfPoints());
+ //DEBTRACE("Number of Points: "<< points->GetNumberOfPoints());
vtkDelaunay2D* delaunay2D = vtkDelaunay2D::New();
delaunay2D->SetInputData(profile);
int nbPts = triangle->GetNumberOfIds();
if (nbPts != 3)
{
- DEBTRACE("not a triangle ?");
+ //DEBTRACE("not a triangle ?");
return false;
}
vtkIdType s[3];
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]);
if (det == 0)
{
- DEBTRACE("flat triangle ?");
+ //DEBTRACE("flat triangle ?");
return false;
}
double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint, int theMethod) const
{
- DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << "), interpolation method: " << theMethod);
+ //DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << "), interpolation method: " << theMethod);
double anInvalidAltitude = GetInvalidAltitude();
double aResAltitude = anInvalidAltitude;
HYDROData_QuadtreeNode* aQuadtree = GetQuadtreeNodes();
if (!aQuadtree)
{
- DEBTRACE(" no Quadtree");
+ //DEBTRACE(" no Quadtree");
return aResAltitude;
}
while (dist2nodes.size() == 0)
{
aQuadtree->setPrecision(aQuadtree->getPrecision() *2);
- DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
+ //DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
}
std::map<double, const gpi_XYZ*>::const_iterator it = dist2nodes.begin();
aResAltitude = it->second->Z();
int nodeIndex = it->second->getIndex();
- DEBTRACE(" number of points found: " << dist2nodes.size() << " nearest z: " << aResAltitude << " point index: " << nodeIndex);
+ //DEBTRACE(" number of points found: " << dist2nodes.size() << " nearest z: " << aResAltitude << " point index: " << nodeIndex);
// --- for coarse bathymetry clouds (when the TELEMAC mesh is more refined than the bathymetry cloud)
// interpolation is required.
points->Allocate(64);
aDelaunay2D->GetPointCells(nodeIndex, cells);
vtkIdType nbCells = cells->GetNumberOfIds();
- DEBTRACE(" triangles on nearest point: " << nbCells);
+ //DEBTRACE(" triangles on nearest point: " << nbCells);
bool isInside = false;
for (int i=0; i<nbCells; i++)
{
if (isInside)
{
aResAltitude = z;
- DEBTRACE(" interpolated z: " << z);
+ //DEBTRACE(" interpolated z: " << z);
break;
}
}
- if (!isInside) DEBTRACE(" point outside triangles, nearest z kept");
+ if (!isInside)
+ {
+ // DEBTRACE(" point outside triangles, nearest z kept");
+ }
}
#endif
return aResAltitude;
TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
}
+void HYDROData_Bathymetry::SetFilePaths( const QStringList& theFilePaths )
+{
+ int i = 1;
+ Handle_TDataStd_ExtStringArray TExtStrArr = TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_FilePaths ), 1, theFilePaths.size() );
+ foreach (QString filepath, theFilePaths)
+ {
+ std::string sstr = filepath.toStdString();
+ const char* Val = sstr.c_str();
+ TExtStrArr->SetValue(i, TCollection_ExtendedString(Val));
+ i++;
+ }
+}
+
TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const
{
TCollection_AsciiString aRes;
if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
aRes = anAsciiStr->Get();
}
+ else
+ {
+ aLabel = myLab.FindChild( DataTag_FilePaths, false );
+ if ( !aLabel.IsNull() )
+ {
+ Handle(TDataStd_ExtStringArray) anExtStrArr;
+ if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) )
+ aRes = anExtStrArr->Value(1); //try take the first; convert extstring to asciistring
+ }
+ }
return aRes;
}
+QStringList HYDROData_Bathymetry::GetFilePaths() const
+{
+ QStringList aResL;
+
+ TDF_Label aLabel = myLab.FindChild( DataTag_FilePaths, false );
+ if ( !aLabel.IsNull() )
+ {
+ Handle(TDataStd_ExtStringArray) anExtStrArr;
+ if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) )
+ {
+ for (int i = anExtStrArr->Lower(); i <= anExtStrArr->Upper(); i++ )
+ {
+ Standard_ExtString str = anExtStrArr->Value(i).ToExtString();
+ TCollection_AsciiString aText (str);
+ aResL << QString(aText.ToCString());
+ }
+ }
+ }
+ else //backward compatibility
+ {
+ TDF_Label anOldLabel = myLab.FindChild( DataTag_FilePath, false );
+ if ( !anOldLabel.IsNull() )
+ {
+ Handle(TDataStd_AsciiString) anAsciiStr;
+ if ( anOldLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
+ aResL << QString(anAsciiStr->Get().ToCString());
+ }
+ }
+
+ return aResL;
+}
+
void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted,
const bool theIsUpdate )
{
return aRes;
}
-bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName )
+bool HYDROData_Bathymetry::ImportFromFile( const QString& theFileName )
{
- // Try to open the file
- QFile aFile( theFileName.ToCString() );
- if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
- return false;
+ return ImportFromFiles(QStringList(theFileName));
+}
- bool aRes = false;
+bool HYDROData_Bathymetry::ImportFromFiles( const QStringList& theFileNames )
+{
+ AltitudePoints AllPoints;
+ bool Stat = false;
- QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
+ foreach (QString theFileName, theFileNames)
+ {
+ // Try to open the file
+ QFile aFile( theFileName );
+ if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
+ continue;
- HYDROData_Bathymetry::AltitudePoints aPoints;
+ QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
- // Try to import the file
- if ( aFileSuf == "xyz" )
- aRes = importFromXYZFile( aFile, aPoints );
- else if ( aFileSuf == "asc" )
- aRes = importFromASCFile( aFile, aPoints );
+ HYDROData_Bathymetry::AltitudePoints aPoints;
- // Close the file
- aFile.close();
-
+ // Try to import the file
+ if ( aFileSuf == "xyz" )
+ Stat = importFromXYZFile( aFile, aPoints );
+ else if ( aFileSuf == "asc" )
+ Stat = importFromASCFile( aFile, aPoints );
+
+ if (!Stat)
+ continue; //ignore this points
+
+ // Close the file
+ aFile.close();
+
+ AllPoints.insert(AllPoints.end(), aPoints.begin(), aPoints.end());
+ }
// Convert from global to local CS
Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
- HYDROData_Bathymetry::AltitudePoints::iterator anIter = aPoints.begin(), aLast = aPoints.end();
+ HYDROData_Bathymetry::AltitudePoints::iterator anIter = AllPoints.begin(), aLast = AllPoints.end();
for ( ; anIter!=aLast; ++anIter )
{
HYDROData_Bathymetry::AltitudePoint& aPoint = *anIter;
aDoc->Transform( aPoint.X, aPoint.Y, aPoint.Z, true );
}
- if ( aRes )
+ if ( Stat )
{
// Update file path and altitude points of this Bathymetry
- SetFilePath( theFileName );
- SetAltitudePoints( aPoints );
+ SetFilePaths (theFileNames );
+ SetAltitudePoints( AllPoints );
}
- return aRes && !aPoints.empty();
+ return Stat && !AllPoints.empty();
}
bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,