VTK渲染 灰度图的像素值曲面点图
作者:互联网
效果如下:
代码如下:
double leftview[4] = {0,0, 0.5,1}; // double midview[4] = {0.33,0, 0.66,1}; double rightview[4] = {0.5,0, 1.0,1}; vtkSmartPointer<vtkJPEGReader> reader = vtkSmartPointer<vtkJPEGReader>::New(); reader->SetFileName("d:/lena.jpg"); reader->Update(); vtkSmartPointer<vtkImageLuminance> lum = vtkSmartPointer<vtkImageLuminance>::New(); lum->SetInputConnection(reader->GetOutputPort()); lum->Update(); vtkImageData* idata = lum->GetOutput(); int ndims[3] = {0}; idata->GetDimensions(ndims); vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); vtkIdType idtype; qDebug() <<ndims[0] <<ndims[1] <<ndims[2]; for(int x = 0; x < ndims[0]; x++){ for(int y = 0; y < ndims[1]; y++){ uchar* pixel = (uchar*)idata->GetScalarPointer(x,y,0); idtype = points->InsertNextPoint(x, y, *pixel); cells->InsertNextCell(1, &idtype); } } vtkSmartPointer<vtkPolyData> poly = vtkSmartPointer<vtkPolyData>::New(); poly->SetPoints(points); poly->SetVerts(cells); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputData(poly); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); vtkSmartPointer<vtkImageActor> actor1 = vtkSmartPointer<vtkImageActor>::New(); actor1->SetInputData(lum->GetOutput()); vtkSmartPointer<vtkRenderer> render = vtkSmartPointer<vtkRenderer>::New(); render->AddActor(actor1); render->SetViewport(leftview); vtkSmartPointer<vtkRenderer> render2 = vtkSmartPointer<vtkRenderer>::New(); render2->AddActor(actor); render2->SetViewport(rightview); pRenderWindow->AddRenderer(render); pRenderWindow->AddRenderer(render2); pRenderer = render;
标签:render,VTK,poly,vtkSmartPointer,灰度,render2,点图,New,lum 来源: https://www.cnblogs.com/larkin-cn/p/16457652.html