我正在处理眼睛图像,我想做的就是拍摄其中一张图像并将其作为球体的纹理应用。但是,我在缩放时遇到了一些麻烦,这是到目前为止的外观:
这是我正在使用的图像:
到目前为止,我已经尝试了各种方法,但是仍然没有得到想要的结果。
这是我一直在努力的代码:
#include <vtkSmartPointer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkTransformTextureCoords.h>
#include <vtkTexture.h>
#include <vtkTextureMapToSphere.h>
#include <vtkImageReader2Factory.h>
#include <vtkImageReader.h>
#include <vtkTexturedSphereSource.h>
#include <vtkSphereSource.h>
int main(int argc, char *argv[])
{
std::string fileName = "C:\\VTK\\eyeTextureNew2.jpg";
//Create sphere
vtkSmartPointer<vtkTexturedSphereSource> source =
vtkSmartPointer<vtkTexturedSphereSource>::New();
source->SetPhiResolution(100);
source->SetThetaResolution(100);
// Read texture file
vtkSmartPointer<vtkImageReader2Factory> readerFactory =
vtkSmartPointer<vtkImageReader2Factory>::New();
vtkImageReader2 *imageReader = readerFactory->CreateImageReader2(fileName.c_str());
imageReader->SetFileName(fileName.c_str());
// Create texture
vtkSmartPointer<vtkTexture> texture =
vtkSmartPointer<vtkTexture>::New();
texture->SetInputConnection(imageReader->GetOutputPort());
vtkSmartPointer<vtkTransformTextureCoords> transformTexture =
vtkSmartPointer<vtkTransformTextureCoords>::New();
transformTexture->SetInputConnection(source->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformTexture->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->SetTexture(texture);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(.1, .2, .3);
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renWinInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renWinInteractor->SetRenderWindow(renderWindow);
renderWindow->Render();
renWinInteractor->Start();
imageReader->Delete();
return EXIT_SUCCESS;
}
关于我可能做错/遗漏的任何想法?预先感谢!
答案 0 :(得分:0)
用vtkplotter我得到了(但背面对称):
4.1.*
4.1.0
函数实际上是这样做的:
from vtkplotter import Sphere
s = Sphere().texture('QeXKq.jpg')
s.show()