51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
#include "actors/MapLineActor.hpp"
|
||
|
||
#include <cstddef>
|
||
|
||
#include <vtkCellArray.h>
|
||
#include <vtkNew.h>
|
||
#include <vtkPoints.h>
|
||
#include <vtkPolyData.h>
|
||
#include <vtkPolyDataMapper.h>
|
||
#include <vtkPolyLine.h>
|
||
#include <vtkProperty.h>
|
||
|
||
namespace geopro::render {
|
||
|
||
vtkSmartPointer<vtkActor> buildSurveyLine(const geopro::core::Grid& g,
|
||
const geopro::core::GeoLocalFrame& frame)
|
||
{
|
||
const int nx = g.nx();
|
||
const bool hasLatLon =
|
||
g.lat.size() >= static_cast<size_t>(nx) && g.lon.size() >= static_cast<size_t>(nx);
|
||
if (nx < 2 || !hasLatLon) return vtkSmartPointer<vtkActor>::New();
|
||
|
||
vtkNew<vtkPoints> points;
|
||
for (int i = 0; i < nx; ++i) {
|
||
auto p = frame.toLocal(g.lat[i], g.lon[i]);
|
||
points->InsertNextPoint(p.x, p.y, 0.0); // 平铺在 z=0,供俯视
|
||
}
|
||
|
||
vtkNew<vtkPolyLine> line;
|
||
line->GetPointIds()->SetNumberOfIds(nx);
|
||
for (int i = 0; i < nx; ++i) line->GetPointIds()->SetId(i, i);
|
||
|
||
vtkNew<vtkCellArray> cells;
|
||
cells->InsertNextCell(line);
|
||
|
||
vtkNew<vtkPolyData> poly;
|
||
poly->SetPoints(points);
|
||
poly->SetLines(cells);
|
||
|
||
vtkNew<vtkPolyDataMapper> mapper;
|
||
mapper->SetInputData(poly);
|
||
|
||
auto actor = vtkSmartPointer<vtkActor>::New();
|
||
actor->SetMapper(mapper);
|
||
actor->GetProperty()->SetColor(0.85, 0.15, 0.15); // 测线:红
|
||
actor->GetProperty()->SetLineWidth(3.0);
|
||
return actor;
|
||
}
|
||
|
||
} // namespace geopro::render
|