#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>
#include <OSD_Timer.hxx>
#endif
-#define _DEVDEBUG_
+//#define _DEVDEBUG_
#include "HYDRO_trace.hxx"
const int BLOCK_SIZE = 1000;
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
-//HYDROData_QuadtreeNode* HYDROData_Bathymetry::myQuadtree = 0;
-
+//int HYDROData_Bathymetry::myQuadTreeNumber = 0;
std::map<int, HYDROData_QuadtreeNode*> HYDROData_Bathymetry::myQuadtrees;
#ifndef LIGHT_MODE
+//int HYDROData_Bathymetry::myDelaunayNumber = 0;
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()
HYDROData_QuadtreeNode* HYDROData_Bathymetry::GetQuadtreeNodes() const
{
- TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
- if (aLabel.IsNull())
- return 0;
- int labkey = myLab.Tag();
- //int altkey = aLabel.Tag();
- //DEBTRACE("GetQuadtreeNodes this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
- // if (myQuadtree->isEmpty() )
- if (myQuadtrees.find(labkey) == myQuadtrees.end())
+ TDF_Label aLabel2 = myLab.FindChild(DataTag_Quadtree, false);
+ if (aLabel2.IsNull())
{
- 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);
if (aLabel.IsNull())
return 0;
- Handle(TDataStd_RealArray) aCoordsArray;
- if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
- return 0;
-
- Nodes_3D* aListOfNodes = new Nodes_3D();
-
- int index =0;
- for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
+ int aQuadTreeNumber = 0;
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+ if ( ! aDocument.IsNull() )
{
- if (i + 3 > n + 1)
- break;
-
- double x = aCoordsArray->Value(i++);
- double y = aCoordsArray->Value(i++);
- double z = aCoordsArray->Value(i++);
- gpi_XYZ* aPoint = new gpi_XYZ(x, y, z, index);
- index++;
- aListOfNodes->push_back(aPoint);
+ aQuadTreeNumber = aDocument->GetCountQuadtree();
+ DEBTRACE("aQuadTreeNumber " << aQuadTreeNumber);
+ aQuadTreeNumber++;
+ aDocument->SetCountQuadtree(aQuadTreeNumber);
}
- DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
- aQuadtree->setNodesAndCompute(aListOfNodes);
+ else
+ DEBTRACE("document.IsNull()");
+ DEBTRACE("compute Quadtree "<< aQuadTreeNumber);
+ HYDROData_QuadtreeNode* aQuadtree = ComputeQuadtreeNodes(aQuadTreeNumber);
return aQuadtree;
}
else
- return myQuadtrees[labkey];
+ {
+ Handle(TDataStd_Integer) aQuadtreeNum;
+ if ( aLabel2.FindAttribute( TDataStd_Integer::GetID(), aQuadtreeNum ) )
+ {
+ if (myQuadtrees.find(aQuadtreeNum->Get()) != myQuadtrees.end())
+ return myQuadtrees[aQuadtreeNum->Get()];
+ else
+ {
+ DEBTRACE("recompute Quadtree "<< aQuadtreeNum->Get());
+ HYDROData_QuadtreeNode* aQuadtree = ComputeQuadtreeNodes(aQuadtreeNum->Get());
+ return aQuadtree;
+ }
+ }
+ else DEBTRACE("no attribute TDataStd_Integer");
+ }
+ return 0;
}
-#ifndef LIGHT_MODE
-vtkPolyData* HYDROData_Bathymetry::GetVtkDelaunay2D() const
+HYDROData_QuadtreeNode* HYDROData_Bathymetry::ComputeQuadtreeNodes( int key) const
{
TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
if (aLabel.IsNull())
return 0;
- int labkey = myLab.Tag();
- //int altkey = aLabel.Tag();
- //DEBTRACE("GetVtkDelaunay2D this labkey altkey "<<this<<" "<<labkey<<" "<<altkey);
- if (myDelaunay2D.find(labkey) == myDelaunay2D.end())
+
+ Handle(TDataStd_RealArray) aCoordsArray;
+ if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
+ return 0;
+
+ TDataStd_Integer::Set( myLab.FindChild( DataTag_Quadtree ), key );
+ DEBTRACE("GetQuadtreeNodes init " << this << " " << key);
+ HYDROData_QuadtreeNode* aQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
+ myQuadtrees[key] = aQuadtree;
+
+ Nodes_3D* aListOfNodes = new Nodes_3D();
+
+ int index =0;
+ for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
{
- DEBTRACE("GetVtkDelaunay2D init " << this << " " << labkey);
+ if (i + 3 > n + 1)
+ break;
+
+ double x = aCoordsArray->Value(i++);
+ double y = aCoordsArray->Value(i++);
+ double z = aCoordsArray->Value(i++);
+ gpi_XYZ* aPoint = new gpi_XYZ(x, y, z, index);
+ index++;
+ aListOfNodes->push_back(aPoint);
+ }
+ DEBTRACE(" GetQuadtreeNodes call setNodesAndCompute");
+ aQuadtree->setNodesAndCompute(aListOfNodes);
+ return aQuadtree;
+}
+#ifndef LIGHT_MODE
+vtkPolyData* HYDROData_Bathymetry::GetVtkDelaunay2D() const
+{
+ TDF_Label aLabel2 = myLab.FindChild(DataTag_Delaunay, false);
+ if (aLabel2.IsNull())
+ {
TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
if (aLabel.IsNull())
return 0;
- Handle(TDataStd_RealArray) aCoordsArray;
- if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
- return 0;
- vtkPoints *points = vtkPoints::New();
- points->Allocate(aCoordsArray->Upper() +1);
- for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
+ int aDelaunayNumber = 0;
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+ if ( ! aDocument.IsNull() )
{
- if (i + 3 > n + 1)
- break;
- double x = aCoordsArray->Value(i++);
- double y = aCoordsArray->Value(i++);
- double z = aCoordsArray->Value(i++);
- vtkIdType index = points->InsertNextPoint(x, y, z); // same index than in GetQuadtreeNodes
- //DEBTRACE(" " << index);
+ aDelaunayNumber = aDocument->GetCountDelaunay();
+ DEBTRACE("aDelaunayNumber " << aDelaunayNumber);
+ aDelaunayNumber++;
+ aDocument->SetCountDelaunay(aDelaunayNumber);
}
- vtkPolyData* profile = vtkPolyData::New();
- profile->SetPoints(points);
- DEBTRACE("Number of Points: "<< points->GetNumberOfPoints());
-
- vtkDelaunay2D* delaunay2D = vtkDelaunay2D::New();
- delaunay2D->SetInputData(profile);
- delaunay2D->Update();
- vtkPolyData* data = delaunay2D->GetOutput();
- data->BuildLinks();
- myDelaunay2D[labkey] = data;
+ else
+ DEBTRACE("document.IsNull()");
+ DEBTRACE("compute Delaunay "<< aDelaunayNumber);
+ vtkPolyData* data = ComputeVtkDelaunay2D(aDelaunayNumber);
return data;
}
else
- return myDelaunay2D[labkey];
+ {
+ Handle(TDataStd_Integer) aDelaunayNum;
+ if ( aLabel2.FindAttribute( TDataStd_Integer::GetID(), aDelaunayNum ) )
+ {
+ if (myDelaunay2D.find(aDelaunayNum->Get()) != myDelaunay2D.end())
+ return myDelaunay2D[aDelaunayNum->Get()];
+ else
+ {
+ DEBTRACE("recompute Delaunay "<< aDelaunayNum->Get());
+ vtkPolyData* data = ComputeVtkDelaunay2D(aDelaunayNum->Get());
+ return data;
+ }
+ }
+ else DEBTRACE("no attribute TDataStd_Integer");
+ }
+ return 0;
+}
+
+vtkPolyData* HYDROData_Bathymetry::ComputeVtkDelaunay2D(int key) const
+{
+ TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
+ if (aLabel.IsNull())
+ return 0;
+ Handle(TDataStd_RealArray) aCoordsArray;
+ if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
+ return 0;
+
+ TDataStd_Integer::Set( myLab.FindChild( DataTag_Delaunay ), key );
+ DEBTRACE("GetVtkDelaunay2D init " << this << " " << key);
+ vtkPoints *points = vtkPoints::New();
+ points->Allocate(aCoordsArray->Upper() +1);
+ for (int i = aCoordsArray->Lower(), n = aCoordsArray->Upper(); i <= n;)
+ {
+ if (i + 3 > n + 1)
+ break;
+ double x = aCoordsArray->Value(i++);
+ double y = aCoordsArray->Value(i++);
+ double z = aCoordsArray->Value(i++);
+ vtkIdType index = points->InsertNextPoint(x, y, z); // same index than in GetQuadtreeNodes
+ //DEBTRACE(" " << index);
+ }
+ vtkPolyData* profile = vtkPolyData::New();
+ profile->SetPoints(points);
+ DEBTRACE("Number of Points: "<< points->GetNumberOfPoints());
+
+ vtkDelaunay2D* delaunay2D = vtkDelaunay2D::New();
+ delaunay2D->SetInputData(profile);
+ delaunay2D->Update();
+ vtkPolyData* data = delaunay2D->GetOutput();
+ data->BuildLinks();
+ myDelaunay2D[key] = data;
+ return data;
}
+
#endif
+
+
void HYDROData_Bathymetry::RemoveAltitudePoints()
{
TDF_Label aLabel = myLab.FindChild( DataTag_AltitudePoints, false );
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;
}
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();
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
+ 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,
}
-Handle_HYDROData_PolylineXY HYDROData_Bathymetry::CreateBoundaryPolyline() const
+Handle(HYDROData_PolylineXY) HYDROData_Bathymetry::CreateBoundaryPolyline() const
{
Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
- Handle_HYDROData_PolylineXY aResult =
- Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
+ Handle(HYDROData_PolylineXY) aResult =
+ Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
if( aResult.IsNull() )
return aResult;