#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkIdList.h>
-#include <vtkInformation.h>
-#include <vtkExecutive.h>
#include <iostream>
#define _DEVDEBUG_
#include "HYDRO_trace.hxx"
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
//HYDROData_QuadtreeNode* HYDROData_Bathymetry::myQuadtree = 0;
std::map<int, vtkPolyData*> HYDROData_Bathymetry::myDelaunay2D;
-hydroDelaunay2D* hydroDelaunay2D::New()
-{
- DEBTRACE("hydroDelaunay2D::New()");
- return new hydroDelaunay2D();
-}
-hydroDelaunay2D::hydroDelaunay2D() :
- vtkDelaunay2D()
-{
- DEBTRACE("hydroDelaunay2D");
-}
-
-hydroDelaunay2D::~hydroDelaunay2D()
-{
- DEBTRACE("~hydroDelaunay2D");
-}
-
-int hydroDelaunay2D::RequestData(vtkInformation *request , vtkInformationVector **inv, vtkInformationVector *outv)
-{
- DEBTRACE("hydroDelaunay2D::RequestData");
- vtkDelaunay2D::RequestData(request, inv, outv);
-}
-
-int hydroDelaunay2D::ProcessRequest(vtkInformation *request , vtkInformationVector **inv, vtkInformationVector *outv)
-{
- DEBTRACE("hydroDelaunay2D::ProcessRequest");
- vtkDelaunay2D::ProcessRequest(request, inv, outv);
-}
-
-
HYDROData_Bathymetry::HYDROData_Bathymetry()
: HYDROData_IAltitudeObject()
{
- //DEBTRACE("HYDROData_Bathymetry constructor start " << this);
-// if (! myQuadtree)
-// myQuadtree = new HYDROData_QuadtreeNode(0, 30, 5, 0.);
- //DEBTRACE("HYDROData_Bathymetry constructor end " << this);
}
HYDROData_Bathymetry::~HYDROData_Bathymetry()
{
- //DEBTRACE("HYDROData_Bathymetry destructor start " << this);
-// if (myQuadtree)
-// delete myQuadtree;
-// Nodes_3D::iterator it = myListOfNodes.begin();
-// for( ; it != myListOfNodes.end(); ++it)
-// delete *it;
-// myListOfNodes.clear();
}
QStringList HYDROData_Bathymetry::DumpToPython( const QString& thePyScriptPath,
TDF_Label aLabel = myLab.FindChild(DataTag_AltitudePoints, false);
if (aLabel.IsNull())
return 0;
- DEBTRACE("---");
Handle(TDataStd_RealArray) aCoordsArray;
if (!aLabel.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray))
return 0;
- DEBTRACE("---");
vtkPoints *points = vtkPoints::New();
points->Allocate(aCoordsArray->Upper() +1);
profile->SetPoints(points);
DEBTRACE("Number of Points: "<< points->GetNumberOfPoints());
- hydroDelaunay2D* delaunay2D = hydroDelaunay2D::New();
- delaunay2D->GetInputPortInformation(0)->Print(std::cerr);
- DEBTRACE("set the input data");
+ vtkDelaunay2D* delaunay2D = vtkDelaunay2D::New();
delaunay2D->SetInputData(profile);
- delaunay2D->GetInputPortInformation(0)->Print(std::cerr);
- delaunay2D->GetOutputPortInformation(0)->Print(std::cerr);
- DEBTRACE("---");
- delaunay2D->GetOutputInformation(0)->Print(std::cerr);
- delaunay2D->GetExecutive()->GetOutputInformation(0)->Print(std::cerr);
- DEBTRACE("---");
- vtkInformationVector** inv = delaunay2D->GetExecutive()->GetInputInformation();
- vtkInformationVector* outv = delaunay2D->GetExecutive()->GetOutputInformation();
- delaunay2D->GetExecutive()->GetInputInformation(0,0)->Print(std::cerr);
- delaunay2D->GetExecutive()->GetOutputInformation(0)->Print(std::cerr);
- vtkInformation* request = vtkInformation::New();
-
- //delaunay2D->ProcessRequest(request, inv,outv);
-
- delaunay2D->GetOutputPortInformation(0)->Print(std::cerr);
- delaunay2D->GetExecutive()->GetInputInformation(0,0)->Print(std::cerr);
- delaunay2D->GetExecutive()->GetOutputInformation(0)->Print(std::cerr);
-
- DEBTRACE("---");
delaunay2D->Update();
-
- DEBTRACE("---");
- delaunay2D->UpdateDataObject();
-
vtkPolyData* data = delaunay2D->GetOutput();
-
data->BuildLinks();
myDelaunay2D[labkey] = data;
- DEBTRACE("---");
return data;
}
else
//DEBTRACE("triangle node 0: " << v[0][0] << " " << v[0][1] << " " << v[0][2]);
//DEBTRACE("triangle node 1: " << v[1][0] << " " << v[1][1] << " " << v[1][2]);
//DEBTRACE("triangle node 2: " << v[2][0] << " " << v[2][1] << " " << v[2][2]);
+
// compute barycentric coordinates (https://en.wikipedia.org/wiki/Barycentric_coordinate_system)
// det = (y2-y3)(x1-x3)+(x3-x2)(y1-y3)
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]);
return false;
}
-double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint) const
+double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint, int theMethod) const
{
- DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")");
+ DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << "), interpolation method: " << theMethod);
double anInvalidAltitude = GetInvalidAltitude();
double aResAltitude = anInvalidAltitude;
DEBTRACE("adjust precision to: " << aQuadtree->getPrecision());
aQuadtree->NodesAround(thePoint, dist2nodes, aQuadtree->getPrecision());
}
- //aQuadtree->NodesAround(thePoint, dist2nodes, 5.0);
std::map<double, const gpi_XYZ*>::const_iterator it = dist2nodes.begin();
aResAltitude = it->second->Z();
int nodeIndex = it->second->getIndex();
// - get the triangle containing the point in the Delaunay2D mesh,
// - interpolate altitude
- bool isBathyInterpolRequired = true;
+ bool isBathyInterpolRequired = false;
+ if (theMethod)
+ isBathyInterpolRequired =true;
if (isBathyInterpolRequired)
{
vtkPolyData* aDelaunay2D = GetVtkDelaunay2D();
cells->Allocate(64);
vtkIdList* points= vtkIdList::New();
points->Allocate(64);
- DEBTRACE("---");
aDelaunay2D->GetPointCells(nodeIndex, cells);
vtkIdType nbCells = cells->GetNumberOfIds();
- DEBTRACE(nbCells);
+ DEBTRACE(" triangles on nearest point: " << nbCells);
+ bool isInside = false;
for (int i=0; i<nbCells; i++)
{
aDelaunay2D->GetCellPoints(cells->GetId(i), points);
double z = 0;
- if (interpolZtriangle(thePoint, aDelaunay2D, points, z))
+ isInside = interpolZtriangle(thePoint, aDelaunay2D, points, z);
+ if (isInside)
{
aResAltitude = z;
- DEBTRACE("interpolated z: " << z);
+ DEBTRACE(" interpolated z: " << z);
break;
}
- else
- {
- DEBTRACE("point outside triangles, nearest z kept");
- }
}
+ if (!isInside) DEBTRACE(" point outside triangles, nearest z kept");
}
return aResAltitude;
}
// Convert from global to local CS
- Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
AltitudePoints::Iterator anIter( aPoints );
for ( ; anIter.More(); anIter.Next() )
{
}
-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;