vr全景软件app

# 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<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
	reader->SetFileName("fran_cut.vtk");
	reader->Update();*/
	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);

	//double originalViewport[4] = { 0.0, 0.0, 0.5, 1.0 };
	vtkSmartPointer<vtkRenderer> originalRenderer = vtkSmartPointer<vtkRenderer>::New();
	//originalRenderer->SetViewport(originalViewport);
	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);
	//vtkSmartPointer<vtkPolygon>polygon = vtkSmartPointer<vtkPolygon>::New();
	//vtkSmartPointer<vtkCellArray>cells= vtkSmartPointer<vtkCellArray>::New();
	//polygon->GetPointIds()->SetNumberOfIds(cloud->size());
	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);
		//polygon->GetPointIds()->SetId(i,i);
	}
	//cells->InsertNextCell(polygon);
	vtkSmartPointer<vtkPolyData>polyData = vtkSmartPointer<vtkPolyData>::New();
	polyData->SetPoints(points);
	polyData->GetPointData()->SetScalars(color);
	//polyData->SetPolys(cells);
	vtkSmartPointer<vtkVertexGlyphFilter>glyphFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
	glyphFilter->SetInputData(polyData);
	glyphFilter->Update();

	//可视化
	vtkSmartPointer<vtkPolyDataMapper>mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputConnection(glyphFilter->GetOutputPort());
	//mapper->SetInputData(polyData);
	vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);
	//actor->GetProperty()->SetColor(1, 0, 0);
	//定义视窗
	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;
}

知秋君
上一篇 2024-09-04 07:02
下一篇 2024-09-03 22:36

相关推荐