我在 Python 脚本中使用 Mayavi2 来计算 3d 等值面。结果我得到了一个 vtkPoints 对象。现在我想将此 vtkPoints 对象(下面的代码示例中的“vtkout”)转换为一个简单的 numpy 数组,其中 3 行包含所有 x、y 和 z 值。我使用如下代码得到 vtkout:
import numpy
from enthought.mayavi import mlab
import array
randVol = numpy.random.rand(50,50,50) # fill volume with some random potential
X, Y, Z = numpy.mgrid[0:50, 0:50, 0:50] # grid
surf = mlab.contour3d(X, Y, Z, randVol, contours=[0.5]) # calc contour
vtkout = surf.contour.contour_filter.output.points # get the vtkPoints object
Run Code Online (Sandbox Code Playgroud)
目前我使用以下代码将点提取到数组中:
pointsArray = numpy.zeros((3, vtkout.number_of_points))
for n in range(vtkout.number_of_points):
pointsArray[0,n] = vtkout[n][0]
pointsArray[1,n] = vtkout[n][1] …Run Code Online (Sandbox Code Playgroud) 我对编程和 Linux 真的很陌生,我想安装 PCL。现在我想安装 VTK 和 Qt 5.6。所以我按照这个网站上的步骤操作:http : //www.vtk.org/Wiki/VTK/Building/Linux
当我想配置 VTK 时,出现此错误:
/usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake 中的 CMake 错误:26 (find_package):找不到“Qt5UiPlugin”提供的具有以下任何名称的包配置文件:
Qt5UiPluginConfig.cmake
qt5uiplugin-config.cmake
Run Code Online (Sandbox Code Playgroud)
将“Qt5UiPlugin”的安装前缀添加到 CMAKE_PREFIX_PATH 或将“Qt5UiPlugin_DIR”设置为包含上述文件之一的目录。如果“Qt5UiPlugin”提供单独的开发包或SDK,请确保已安装。调用堆栈(最近调用优先):GUISupport/Qt/CMakeLists.txt:142 (find_package)
我在互联网上搜索并得到了这个:http : //www.qtcentre.org/threads/65284-vtk-integration-with-Qt-5-5
如何重新编译程序?有人可以帮忙吗?我真的很沮丧...谢谢!
我有一个读取图像并使用以下命令显示网格的管道VTK;在更改图像读取器的输入并更新管道后,网格不会更新,直到我与窗口交互。
我有一个目录,其中包含一系列分割文件(即,3D 图像体积,其中像素值对应于相应图像中的结构),这些文件显示结构如何随时间变化。我编写了一个实用程序VTK,允许我加载目录中的第一个图像,将标签可视化为网格,并通过更改输入图像的文件名和更新管道,使用箭头键向前或向后“步进” 。这几乎可以工作——唯一的问题是,更新管道后,网格体不会更新,直到我与窗口交互(例如,只需单击窗口中的任意位置即可更新网格体)。
呼吁Update()读者:
this->reader->Update();
Run Code Online (Sandbox Code Playgroud)呼吁Modified()演员们:
const auto actors = this->GetCurrentRenderer()->GetActors();
actors->InitTraversal();
for (vtkIdType i = 0; i < actors->GetNumberOfItems(); ++i)
{
actors->GetNextActor()->Modified();
}
Run Code Online (Sandbox Code Playgroud)调用Render()当前渲染窗口:
this->GetCurrentRenderer()->Render();
Run Code Online (Sandbox Code Playgroud)注意:阅读器在 中更新KeyPressInteractorStyle::UpdateReader()。
// VTK
#include <vtkSmartPointer.h>
#include <vtkNIFTIImageReader.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCamera.h>
#include <vtkDiscreteMarchingCubes.h>
#include <vtkProperty.h>
#include <vtkInteractorStyleTrackballCamera.h>
// Define interaction style
class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public: …Run Code Online (Sandbox Code Playgroud) 我有一个点云,对于每个点,我有 11 个数据数组,代表 11 个属性,包括 vx、vy、vz。我创建了一个新的数据数组,将 vx、vy、vz 作为每个点的元组存储,并将其命名为 v(即速度)。我想使用 vtkGlyph3D 将每个点的速度可视化为定向箭头,但它们都指向一个方向。我尝试了所有相关的例子,但它们仍然朝着相同的方向。我对 vtk 和 C++ 很陌生。如果有人能帮助我,我将不胜感激。
提前致谢!
这是我的代码:
//get vx, vy, vz
vtkDataArray* vx0 = polyData->GetPointData()->GetArray("vx");
vtkDataArray* vy0 = polyData->GetPointData()->GetArray("vy");
vtkDataArray* vz0 = polyData->GetPointData()->GetArray("vz");
//define and initialize v and magnitude
vtkDataArray* v = polyData->GetPointData()->GetArray("vz") ;
vtkDataArray* magnitude = polyData->GetPointData()->GetArray("vz");
v->SetName("v");
//insert v and magnitude to each point
int numPoints = polyData->GetNumberOfPoints();
for (vtkIdType i = 0; i < numPoints; i++) { //define i; set loop condition
double VX[3];
double VY[3];
double …Run Code Online (Sandbox Code Playgroud) 目前,我们使用Python的vtk包装器和Pyvista(一个更Pythonist的vtk包装器)。
在该过程的某些部分,我们有一些来自 .cxx 文件的日志行:
2022-03-17 17:21:56.031 ( 156.058s) [ 4CC78740] vtkDelaunay3D.cxx:518 WARN| vtkDelaunay3D (0x559d2b180400): 1 degenerate triangles encountered, mesh quality suspect
2022-03-17 17:21:58.045 ( 158.072s) [ 4CC78740] vtkMath.cxx:522 WARN| Unable to factor linear system
2022-03-17 17:21:58.288 ( 158.314s) [ 4CC78740] vtkDelaunay3D.cxx:518 WARN| vtkDelaunay3D (0x559d0877c080): 3 degenerate triangles encountered, mesh quality suspect
Run Code Online (Sandbox Code Playgroud)
是否可以从 python 日志记录模块抑制或管理这些日志?
我有这个TOF传感器,我想将传感器的数据可视化为Qt中的点云.我将数据转换为a pcl::PointCloud,现在我想要将其可视化.
无论何时创建一个传感器,API都会发出图片.我会把它发送给它QVTKWidget来形象化它.我尝试使用这段代码(我从这里获得):
pcl::visualization::PCLVisualizer pvis ("test_vis", false);
// 'false' prevents PCLVisualizer's own window to pop up
pvis.addPointCloud<pcl::PointXYZ>(pc); // pc is my point cloud
vtkSmartPointer<vtkRenderWindow> renderWindow = pvis.getRenderWindow();
widget.SetRenderWindow(renderWindow);
Run Code Online (Sandbox Code Playgroud)
但似乎这只是为了可视化一个稳定的点云而不是一个不断变化的点云序列.
问题:cloud_xyz当我的传感器发出新图片时,有没有办法更新?
我正在尝试使用Paraview 4.2从Python脚本中的切片中提取数据。我有这样的事情:
from paraview.numpy_support import vtk_to_numpy
from paraview.simple import *
import os
os.environ["DISPLAY"] = ":0"
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'XDMF Reader'
xDMFtemporalFieldsxmf = XDMFReader(FileNames=['<pathtodata>/XDMF.temporalFields.xmf'])
# Properties modified on xDMFtemporalFieldsxmf
xDMFtemporalFieldsxmf.PointArrayStatus = ['DensityProperty-mesh', 'VelocityField']
xDMFtemporalFieldsxmf.CellArrayStatus = []
# create a new 'Slice'
slice1 = Slice(Input=xDMFtemporalFieldsxmf)
# create a new 'Clip'
clip1 = Clip(Input=slice1)
clip1.ClipType = 'Scalar'
clip1.Value = 1200.0
Run Code Online (Sandbox Code Playgroud)
因此,我要做的就是从剪辑中提取VelocityField数据,最好是为每个数据点指定坐标位置。
这是我的一些探索:
>> print clip1
<paraview.servermanager.Clip object at 0x7f1a14e356d0>
>> print clip1.PointData.keys()
[]
>> print clip1.FieldData.keys()
[]
>> proxy = servermanager.Proxy(proxy=clip1.SMProxy) …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
#include <vtkInteractorStyleTrackballCamera.h>
class InteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static InteractorStyle* New() {};
vtkTypeMacro(InteractorStyle, vtkInteractorStyleTrackballCamera);
InteractorStyle() {
cout << "test";
}
virtual void OnLeftButtonDown();
virtual void OnKeyPress();
private:
};
vtkStandardNewMacro(InteractorStyle); //error here
void InteractorStyle::OnLeftButtonDown()
{
std::cout << "test";
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
};
void InteractorStyle::OnKeyPress()
{
// Get the keypress
vtkRenderWindowInteractor *rwi = this->Interactor;
std::string key = rwi->GetKeySym();
// Output the key that was pressed
std::cout << "Pressed " << key << std::endl;
// Forward events
vtkInteractorStyleTrackballCamera::OnKeyPress();
};
Run Code Online (Sandbox Code Playgroud)
即使我按照 …
我正在研究3D模型的生成设计项目.我需要创建一个简单的QT应用程序,允许用户使用VTK查看网格,并包含一些按钮,用于反馈生成算法.
图形用户界面对我来说是一个全新的东西,所以我很难理解如何将这里的代码集成到一个更广泛的程序中.现在我只想在观众中创建一个按钮和一个3D圆锥.
到目前为止,我的代码在运行时崩溃了.它使用来自给定链接的QVTKRenderWindowInteractor()对象,将对象直接粘贴到文件中.
try:
import sys
import vtk
from PyQt5.QtWidgets import QWidget, QSizePolicy, QApplication, QPushButton, QVBoxLayout
from PyQt5.QtCore import Qt, pyqtSignal, QTimer, QObject, QSize, QEvent
except ImportError:
raise ImportError("Cannot load either PyQt5")
import vtk
class neuralDesignerApp(QWidget):
def __init__(self):
super(QWidget,self).__init__()
self.initUI()
def initUI(self):
app = QApplication(['QVTKRenderWindowInteractor'])
vtkWindow = QVTKRenderWindowInteractor(self)
vtkWindow.Initialize()
vtkWindow.Start()
ren = vtk.vtkRenderer()
vtkWindow.GetRenderWindow().AddRenderer(ren)
cone = vtk.vtkConeSource()
cone.SetResolution(8)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
ren.AddActor(coneActor)
btn1 = QPushButton("Button 1", self)
vbox = QVBoxLayout()
vbox.addWidget(vtkWindow)
vbox.addWidget(btn1)
self.setLayout(vbox) …Run Code Online (Sandbox Code Playgroud)