Try setting the number of bins to 4 and here is what you should see.ĭo not hesitate to download the archive to get the full code explained here. You can now change the value in your filter and the change should appear in your Python View when you apply it. bins = dataObject.GetPointData().GetArray(BINS_ARRAY_NAME)Ĭongratulations! You just customized your Python View with a simple Python Plugin =) view.SetAttributeArrayStatus(i,, BINS_ARRAY_NAME, 1)Īnd then, you can retrieve your information in the variable storing the number of bins. ![]() First, setup your array in the setup_data method in the loop. Lastly, we will make use of this variable and allows passing our data array to the Python View. BINS_ARRAY_NAME = "bins"Īt this point, you should be able to make match names easily. Here I declare the name of the array right after the imports to be able to see it easily in the script text area. This will avoid repeating your array’s name in the script. Vtk_image = python_view.figure_to_image(figure)Īt this point, your Python View should look like this.Īn optional thing you can do for quick modifications and a better legibility is to declare at the top of your script a variable that will keep the name of your array. If not isinstance(dataObject, vtkDataSet):ĭisp = dataObject.GetPointData().GetArray("displacement6") View.SetAttributeArrayStatus(i,, "displacement6", 1)įigure = python_view.matplotlib_figure(width, height)ĭataObject = view.GetVisibleDataObjectForRendering(i) Import _support as nsįrom vtkmodules.vtkCommonDataModel import vtkDataSetįor i in range(view.GetNumberOfVisibleDataObjects()): Here is an example of a simple Python View displaying an histogram of the displacement6 data array available on the given dataset. Then, you can add your own script to the view. After applying your custom filter on your data, you may split the render screen and create a new Python View. The next step is to create our Python View. Go in the Information panel and see your new Data Array being displayed. After applying the filter, you should still see your dataset unchanged. Here, I will apply it on the blow.vtk dataset that you can find in ParaView Examples, or in the archive available at the top of the topic. For this, open ParaView and click on Tools / Manage Plugins. To use our freshly created plugin in ParaView, we have to import it. Simply add the following before the return. Using numpy interface, it’s easy to add tables to the output. The last thing needed to make it work is adding the logic in the RequestData method. The second parameter is the actual value we want to pass to the Python View, in this case the number of bins of an histogram. It can be useful to expose it though in order to allow quick modification in the Python View script. The first one is optional, it’s the name of the array we will create to pass our parameters to the Python View. Now, we have two parameters we can modify inside ParaView. Let’s add the necessary to make them editable from ParaView before to explain their use. But for now, they don’t appear in ParaView. You can see that I added two parameters that we will want to manipulate when applying this filter. Here we are declaring a simple filter that takes a vtkDataSet and returns the exact same input. Output = dsa.WrapDataObject(self.GetOutputData(outInfo, 0)) Input = dsa.WrapDataObject(vtkDataSet.GetData(inInfo)) Return super().RequestDataObject(request, inInfo, outInfo)ĭef RequestData(self, request, inInfo, outInfo): OutInfo.GetInformationObject(0).Set(outData.DATA_OBJECT(), outData) If outData is None or (not outData.IsA(inData.GetClassName())): Super()._init_(nInputPorts=1, nOutputPorts=1, inputType="vtkDataSet", outputType="vtkDataSet")ĭef RequestDataObject(self, request, inInfo, outInfo): from import *įrom vtkmodules.numpy_interface import dataset_adapter as dsaįrom vtkmodules.vtkCommonDataModel import composite_data_supported=False)Ĭlass PythonViewHelperFilter(VTKPythonAlgorithmBase): For this, go ahead and create a new Python file declaring a new filter Python Filter with its base structure. What you will want to do to add parameters to your Python View is to first create a Python Plugin that you will load in ParaView to get your custom Python Filter. Python_view_scripting.zip (72.8 KB) Python Plugin Creating the Python Filter You may find the full example with the data below. In this example, we will manipulate the number of bins of an histogram from our Python View. ![]() This is an example of how to customize dynamically your Python View by adding parameters in ParaView linked to your Python View through the use of a custom Python Plugin (adding a Python Filter).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |