The article describe a simple way to display point id list on the original model. We use VTK to draw and show all scenes.
vtkSmartPointer<vtkPolyData> UShowData::ShowListByPoints(vtkSmartPointer<vtkPolyData> polyData, vtkSmartPointer<vtkIdList> list)
{
vSPNew( result, vtkPolyData );
vSPNew( resultPts, vtkPoints );
vSPNew( resultVerts, vtkCellArray );
for( int i = 0; i < list->GetNumberOfIds(); ++i )
{
auto ptId = list->GetId( i );
if( ptId >= polyData->GetNumberOfPoints() || ptId < 0) continue;
PointStruct pt( polyData->GetPoint( ptId ) );
resultPts->InsertNextPoint( pt.GetPoint() );
vtkIdType pts[1] = { i };
resultVerts->InsertNextCell( 1, pts );
}
result->SetPoints( resultPts );
result->SetVerts( resultVerts );
result->Modified();
return result;
}
vtkSmartPointer<vtkPolyData> UShowData::ShowListByLine(vtkSmartPointer<vtkPolyData> polyData, vtkSmartPointer<vtkIdList> list)
{
vSPNew( result, vtkPolyData );
vSPNew( resultPts, vtkPoints );
vSPNew( resultLines, vtkCellArray );
for( int i = 0; i < list->GetNumberOfIds(); ++i )
{
auto ptId = list->GetId( i );
if( ptId >= polyData->GetNumberOfPoints() || ptId < 0) continue;
PointStruct pt( polyData->GetPoint( ptId ) );
resultPts->InsertNextPoint( pt.GetPoint() );
}
for( int i = 0; i < resultPts->GetNumberOfPoints()-1; ++i )
{
vtkIdType pts[2] = { i, i + 1 };
resultLines->InsertNextCell( 2, pts );
}
result->SetPoints( resultPts );
result->SetLines( resultLines );
result->Modified();
return result;
}
#include <iostream>
#include "UShowData.h"
#include <vtkSphereSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
int main()
{
vSPNew( source, vtkSphereSource );
source->SetPhiResolution( 40 );
source->SetThetaResolution( 40 );
source->Update();
vSPNew( list, vtkIdList );
for( int i = 0; i < 20; i++ )
{
list->InsertNextId( i );
}
auto originData = source->GetOutput();
UShowData showData;
auto tmp = showData.ShowListByPoints( originData, list );
vSPNew( dataMapper, vtkPolyDataMapper );
dataMapper->SetInputData( tmp );
vSPNew( dataActor, vtkActor );
dataActor->SetMapper( dataMapper );
dataActor->GetProperty()->SetLineWidth( 3 );
dataActor->GetProperty()->SetPointSize( 3 );
dataActor->GetProperty()->SetColor( 1, 0, 0 );
vSPNew( mapper, vtkPolyDataMapper );
mapper->SetInputData( originData );
vSPNew( actor, vtkActor );
actor->SetMapper( mapper );
vSPNew( renderer, vtkRenderer );
renderer->AddActor( dataActor );
renderer->AddActor( actor );
renderer->SetBackground( 0, 0, 0 );
vSPNew( renderWindow, vtkRenderWindow );
renderWindow->AddRenderer( renderer );
vSPNew( renderWindowInteractor, vtkRenderWindowInteractor );
renderWindowInteractor->SetRenderWindow( renderWindow );
renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}