我使用了vtkDijkstraGraphGeodesicPath
类(例如:http://www.cmake.org/Wiki/VTK/Examples/Cxx/PolyData/DijkstraGraphGeodesicPath)来找到网格上两点之间的最短路径,我的下一步是将路径(曲线)投影到平面。在vtk中是否有类或函数将曲线投影到平面?
另一种方法是对路径(曲线)进行采样,然后将采样点投影到平面,那么如何对曲线进行采样并获取采样点?提前谢谢!
答案 0 :(得分:1)
我从未找到过投影3D网格的方法,但我必须使用它,并且我选择了纹理化方法,允许在Plane / Cylinder / Sphere上投影网格(到texzturize)。
本案例中使用的主要方法是vtkTextureMapToPlane。
// your mesh
vtkSmartPointer<vtkPolyData> mainMesh = myFilter->GetOutput ();
// extract your path from the poly data
// retrieve selected ids from dijkstra algo
vtkSmartPointer<vtkIdList> idList = dijkstra->GetIdList ();
vtkSmartPointer<vtkIdTypeArray> ids = convertToIdTypeArr (idList); // custom method to convert id array
// Once the ID selections is done, the extraction is invoked
vtkSmartPointer<vtkSelectionNode> selectionNode = vtkSelectionNode::New ();
selectionNode->SetFieldType (vtkSelectionNode::POINT);
selectionNode->SetContentType (vtkSelectionNode::INDICES);
selectionNode->SetSelectionList (ids);
vtkSmartPointer<vtkSelection> selection = vtkSelection::New ();
selection->AddNode (selectionNode);
vtkSmartPointer<vtkExtractSelection> extract = vtkExtractSelection::New ();
extract->SetInputData (0, pl);
extract->SetInputData (1, selection);
// convert result to polydata
vtkSmartPointer<vtkGeometryFilter> geoFilter = vtkGeometryFilter::New ();
geoFilter->SetInputConnection (extract->GetOutputPort());
geoFilter->Update();
vtkSmartPointer<vtkPolyData> selected = geoFilter->GetOutput();
您有一个vtkpolyData
来自路径的顶点。您需要创建平面和项目
// plane is sized with 800x600, on y-z directions
double orig[3] = {0, 0, 0};
double pt1[3] = {0, 600, 0};
double pt2[3] = {0, 0, 800};
// create TextureMapToPlan instance
vtkSmartPointer<vtkTextureMapToPlane> planeMapper = vtkTextureMapToPlane::New ();
planeMapper->SetOrigin(orig);
planeMapper->SetPoint1(pt1);
planeMapper->SetPoint2(pt2);
planeMapper->SetInputData (selected);
planeMapper->Update (); // project
vtkSmartPointer<vtkPolyData> d = planeMapper->GetPolyDataOutput(); // retrieve result
由于此算法用于纹理化,您需要检索纹理坐标,并将它们转换为平面坐标。 (文本坐标以[0,1]的高度和宽度比定义)
vtkSmartPointer<vtkDataArray> textCoord = d->GetPointData()->GetTCoords ();
vtkSmartPointer <vtkPoints> textPoints = vtkPoints::New ();
for (int i = 0; i < textCoord->GetNumberOfTuples (); ++i)
{
textPoints->InsertNextPoint (textCoord->GetTuple2(i)[0] * 800,
textCoord->GetTuple2(i)[1] * 600, 0);
}
textPoints
在这里得到了你在飞机上的路径投影的二维中的所有坐标。 /!\这个坐标取决于您的平面坐标。