VTK 定位相机以用对象填充视口
VTK Position Camera to Fill Viewport with Object
我有一个图像平面,可以从相机接收流视频。我试图将该图像放在相机前面,使其充满屏幕。但是,我无法计算相机与图像之间的距离。
auto camera = this->renderer()->camera();
double *origin = imageData->GetOrigin();
int *extent = imageData->GetExtent();
double *spacing = imageData->GetSpacing();
double viewportHeight = this->renderer()->camera()->viewport()->height();
this->Internal->cameraImagePlaneRepresentation()->setImageData(imageData);
double imageCenterX = origin[0] + 0.5f * (extent[0] + extent[1]) * spacing[0];
double imageCenterY = origin[1] + 0.5f * (extent[2] + extent[3]) * spacing[1];
double imageWidth = (extent[1] - extent[0] + 1.f) * spacing[0];
double imageHeight = (extent[3] - extent[2] + 1.f) * spacing[1];
double viewAngleRadians = degreesToRadians(camera->viewAngle());
double hypotenuse = imageHeight / viewAngleRadians;
double distance = tan(viewAngleRadians * 0.5f) * hypotenuse;
camera->setFocalPoint(vesVector3f(imageCenterX, imageCenterY, 0.f));
camera->setPosition(vesVector3f(imageCenterX, imageCenterY, distance));
我认为距离是正确的,但相差一个数量级。
如果您掌握了计算距离的正确公式,将大有帮助。
double viewAngleRadians = degreesToRadians(camera->viewAngle());
double distance = imageHeight / viewAngleRadians;
我有一个图像平面,可以从相机接收流视频。我试图将该图像放在相机前面,使其充满屏幕。但是,我无法计算相机与图像之间的距离。
auto camera = this->renderer()->camera();
double *origin = imageData->GetOrigin();
int *extent = imageData->GetExtent();
double *spacing = imageData->GetSpacing();
double viewportHeight = this->renderer()->camera()->viewport()->height();
this->Internal->cameraImagePlaneRepresentation()->setImageData(imageData);
double imageCenterX = origin[0] + 0.5f * (extent[0] + extent[1]) * spacing[0];
double imageCenterY = origin[1] + 0.5f * (extent[2] + extent[3]) * spacing[1];
double imageWidth = (extent[1] - extent[0] + 1.f) * spacing[0];
double imageHeight = (extent[3] - extent[2] + 1.f) * spacing[1];
double viewAngleRadians = degreesToRadians(camera->viewAngle());
double hypotenuse = imageHeight / viewAngleRadians;
double distance = tan(viewAngleRadians * 0.5f) * hypotenuse;
camera->setFocalPoint(vesVector3f(imageCenterX, imageCenterY, 0.f));
camera->setPosition(vesVector3f(imageCenterX, imageCenterY, distance));
我认为距离是正确的,但相差一个数量级。
如果您掌握了计算距离的正确公式,将大有帮助。
double viewAngleRadians = degreesToRadians(camera->viewAngle());
double distance = imageHeight / viewAngleRadians;