# include <vtkSmartPointer.h>
# include <vtkActor.h>
# include <vtkPolyDataMapper.h>
# include <vtkRenderWindow.h>
# include <vtkRenderWindowInteractor.h>
# include <vtkSmartPointer.h>
# include <vtkActor.h>
# include <vtkPolyDataMapper.h>
# include <vtkRenderWindow.h>
# include <vtkRenderWindowInteractor.h>
# include <vtkRenderer.h>
# include <vtkPolyDataReader.h>
# include <vtkPLYReader.h>
# include <vtkAutoInit.h>
VTK_MODULE_INIT ( vtkRenderingOpenGL2) ;
VTK_MODULE_INIT ( vtkInteractionStyle) ;
int main ( int argc, char * argv[ ] )
{
vtkSmartPointer< vtkPLYReader> reader = vtkSmartPointer < vtkPLYReader> :: New ( ) ;
reader-> SetFileName ( "bunny.ply" ) ;
reader-> Update ( ) ;
vtkSmartPointer< vtkPolyDataMapper> originMapper = vtkSmartPointer < vtkPolyDataMapper> :: New ( ) ;
originMapper-> SetInputData ( reader-> GetOutput ( ) ) ;
vtkSmartPointer< vtkActor> originActor = vtkSmartPointer < vtkActor> :: New ( ) ;
originActor-> SetMapper ( originMapper) ;
vtkSmartPointer< vtkRenderer> originalRenderer = vtkSmartPointer < vtkRenderer> :: New ( ) ;
originalRenderer-> AddActor ( originActor) ;
originalRenderer-> ResetCamera ( ) ;
originalRenderer-> SetBackground ( 1 , 0 , 0 ) ;
vtkSmartPointer< vtkRenderWindow> renderWindow = vtkSmartPointer < vtkRenderWindow> :: New ( ) ;
renderWindow-> AddRenderer ( originalRenderer) ;
renderWindow-> SetSize ( 600 , 600 ) ;
vtkSmartPointer< vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer < vtkRenderWindowInteractor> :: New ( ) ;
renderWindowInteractor-> SetRenderWindow ( renderWindow) ;
renderWindowInteractor-> Initialize ( ) ;
renderWindowInteractor-> Start ( ) ;
return 0 ;
}
# include <vtkAutoInit.h>
VTK_MODULE_INIT ( vtkRenderingOpenGL2) ;
VTK_MODULE_INIT ( vtkInteractionStyle)
# include <vtkSmartPointer.h>
# include <vtkActor.h>
# include <vtkPolyData.h>
# include <vtkPointData.h>
# include <vtkPoints.h>
# include <vtkRenderer.h>
# include <vtkRenderWindow.h>
# include <vtkRenderWindowInteractor.h>
# include <vtkInteractorStyleTrackballCamera.h>
# include <vtkPolyDataMapper.h>
# include <vtkVertexGlyphFilter.h>
# include <vtkOutputWindow.h>
# include <vtkProperty.h>
# include <pcl/io/pcd_io.h>
# include <pcl/point_types.h>
int main ( )
{
vtkOutputWindow:: SetGlobalWarningDisplay ( 0 ) ;
pcl:: PointCloud< pcl:: PointXYZRGB> :: Ptr cloud ( new pcl:: PointCloud< pcl:: PointXYZRGB> ) ;
pcl:: io:: loadPCDFile ( "pig.pcd" , * cloud) ;
vtkSmartPointer< vtkPoints> points = vtkSmartPointer < vtkPoints> :: New ( ) ;
vtkSmartPointer< vtkUnsignedCharArray> color = vtkSmartPointer < vtkUnsignedCharArray> :: New ( ) ;
color-> SetNumberOfComponents ( 3 ) ;
for ( UINT32 i = 0 ; i < cloud-> size ( ) ; i++ )
{
points-> InsertNextPoint ( cloud-> points[ i] . x, cloud-> points[ i] . y, cloud-> points[ i] . z) ;
unsigned char rgb[ 3 ] = { cloud-> points[ i] . r, cloud-> points[ i] . g, cloud-> points[ i] . b } ;
color-> InsertNextTypedTuple ( rgb) ;
}
vtkSmartPointer< vtkPolyData> polyData = vtkSmartPointer < vtkPolyData> :: New ( ) ;
polyData-> SetPoints ( points) ;
polyData-> GetPointData ( ) -> SetScalars ( color) ;
vtkSmartPointer< vtkVertexGlyphFilter> glyphFilter = vtkSmartPointer < vtkVertexGlyphFilter> :: New ( ) ;
glyphFilter-> SetInputData ( polyData) ;
glyphFilter-> Update ( ) ;
vtkSmartPointer< vtkPolyDataMapper> mapper = vtkSmartPointer < vtkPolyDataMapper> :: New ( ) ;
mapper-> SetInputConnection ( glyphFilter-> GetOutputPort ( ) ) ;
vtkSmartPointer< vtkActor> actor = vtkSmartPointer < vtkActor> :: New ( ) ;
actor-> SetMapper ( mapper) ;
vtkSmartPointer< vtkRenderer> renderer = vtkSmartPointer < vtkRenderer> :: New ( ) ;
renderer-> AddActor ( actor) ;
renderer-> ResetCamera ( ) ;
renderer-> SetBackground ( 0.0 , 0.0 , 0.0 ) ;
vtkSmartPointer< vtkRenderWindow> renderwindow = vtkSmartPointer < vtkRenderWindow> :: New ( ) ;
renderwindow-> AddRenderer ( renderer) ;
renderwindow-> SetSize ( 512 , 512 ) ;
renderwindow-> SetBorders ( 1 ) ;
renderwindow-> SetFullScreen ( 0 ) ;
renderwindow-> SetLineSmoothing ( 0 ) ;
renderwindow-> Render ( ) ;
vtkSmartPointer< vtkRenderWindowInteractor> rwi = vtkSmartPointer < vtkRenderWindowInteractor> :: New ( ) ;
vtkSmartPointer< vtkInteractorStyleTrackballCamera> style = vtkSmartPointer < vtkInteractorStyleTrackballCamera> :: New ( ) ;
rwi-> SetInteractorStyle ( style) ;
rwi-> SetRenderWindow ( renderwindow) ;
rwi-> SetLightFollowCamera ( 1 ) ;
rwi-> Initialize ( ) ;
rwi-> Start ( ) ;
return 0 ;
}