2014-10-31 285 views
1

我已经使用vtkDijkstraGraphGeodesicPath类(例如:http://www.cmake.org/Wiki/VTK/Examples/Cxx/PolyData/DijkstraGraphGeodesicPath)来查找网格上两点之间的最短路径,我的下一步是将路径(曲线)投影到平面。在vtk中是否有类或函数将曲线投影到平面? 另一种方法是采样路径(曲线),然后将采样点投影到平面,那么如何对曲线进行采样并获取采样点?提前谢谢!如何在vtk中投影曲线到平面

回答

1

我从来没有找到一种方法来进行3D网格投影,但我不得不使用它,并且我选择了纹理化方法,允许在平面/圆柱体/球体上投影网格(对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 

由于这种算法用于组织化,需要检索纹理COORDS和成平面坐标转换它们。 (文本COORDS在[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这里得到了在平面上的路径的投影的2维的所有坐标。 /!\这个坐标取决于你的平面坐标。