Editing
Software Plugins and Codes
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Writing Plugins for Paraview== Have a look at the paraview_plugins project in the Numerics88 source code. The plugins there are working examples. ===Links=== Here are some useful links. http://paraview.org/Wiki/Plugin_HowTo http://paraview.org/Wiki/ParaView:FAQ#How_do_I_add_my_own_vtk_filter.2Freader_to_ParaView.3F http://public.kitware.com/pipermail/paraview/2003-September/000290.html http://paraview.org/Wiki/ExtendingParaView ===Tips=== ====Link to Paraview's internal VTK==== Your plugins, and any libraries that they use, must link to Paraview's internal version of VTK, and not some other VTK libraries. This is true even if both the internal and external versions of VTK were built from the same VTK sources! As a concrete example, paraview_plugins links to vtkski. The plugins will die with mysterious segmentation faults unless you build vtkski to link against the Paraview internal version of VTK. So for example, on my Linux system, cmake will automatically find vtk at <tt>/usr/lib/vtk-5.2</tt> . However, I have to change the cmake variable <tt>VTK_DIR</tt> manually to <tt>/home/eric/source/ParaView3/build/VTK</tt> . ====Implement RequestInformation for vtkImageData data types==== This seems to be necessary for vtkImageData, although strangely not for vtkUnstructuredData. Here is an example, where the extent, spacing, origin and data type are set in RequestInformation. This seems to be sufficient. <source lang=c> int vtkAIMReaderPlugin::RequestInformation ( vtkInformation * vtkNotUsed( request ), vtkInformationVector** vtkNotUsed( inputVector ), vtkInformationVector * outputVector) { // Make sure FileName is set if (!this->FileName) { vtkErrorMacro("A Filename must be specified"); return 0; } vtkSmartPointer<vtkAIMReader> reader = vtkSmartPointer<vtkAIMReader>::New(); reader->SetFileName (FileName); reader->UpdateInformation(); vtkImageData* data = reader->GetOutput(); vtkInformation* outInfo = outputVector->GetInformationObject(0); outInfo->Set (vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), data->GetWholeExtent(), 6); outInfo->Set (vtkDataObject::SPACING(), data->GetSpacing(), 3); outInfo->Set (vtkDataObject::ORIGIN(), data->GetOrigin(), 3); vtkDataObject::SetPointDataActiveScalarInfo(outInfo, VTK_FLOAT, 1); return 1; } </source> ====You may need to convert to VTK_FLOAT==== Paraview does not seem to handle byte (char) data well. In particular, there is sign/unsigned ambiguity with char types in paraview. If your source produces byte data, I recommend converting it in your plugin to float. ====Scalar values must be named==== If you don't assign a name to scalar values, paraview can't do anything with them. Here is an example. <source lang=c> int vtkAIMReaderPlugin::RequestData (vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) { vtkSmartPointer<vtkImageData> temp = vtkSmartPointer<vtkImageData>::New(); // ACTUAL WORKING CODE TO FILL temp REMOVED FOR CLARITY // see vtkAIMReaderPlugin.cxx for details. // . // . // . vtkImageData* out = vtkImageData::GetData (outputVector); out->ShallowCopy(temp); // Must have a name for the scalar data otherwise paraview can do nothing // with it. out->GetPointData()->GetScalars()->SetName("AIMData"); return 1; } </source> ====Copy your data to the output, instead of connecting the output to a VTK filter==== I don't understand why this is sometimes required, but using ShallowCopy seems be necessary in certain cases. Note there should in theory be no performance impact to using ShallowCopy (no new copy of the data will be made in memory). Here is an example. <source lang="c"> int vtkAIMReaderPlugin::RequestData (vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) { // Make sure FileName is set if (!this->FileName) { vtkErrorMacro("A Filename must be specified"); return 0; } vtkSmartPointer<vtkAIMReader> reader = vtkSmartPointer<vtkAIMReader>::New(); reader->SetFileName (FileName); reader->UpdateInformation(); // Not sure if this is redundant reader->Update(); vtkImageData* data = reader->GetOutput(); vtkImageData* out = vtkImageData::GetData (outputVector); if (!out) { return 0; } // Not sure why we need a temporary object for the caster, but without it, // an error occurs in paraview. vtkSmartPointer<vtkImageData> temp = vtkSmartPointer<vtkImageData>::New(); // Convert to float, regardless of original type vtkSmartPointer<vtkImageCast> caster = vtkSmartPointer<vtkImageCast>::New(); caster->SetInput (data); caster->SetOutput (temp); caster->SetOutputScalarType (VTK_FLOAT); caster->Update(); out->ShallowCopy(temp); // Must have a name for the scalar data otherwise paraview can do nothing // with it. out->GetPointData()->GetScalars()->SetName("AIMData"); return 1; } </source> This is the error that you will get if you fail to use ShallowCopy and just set the output of caster in the above example to 'out': ERROR: In /home/eric/source/paraview-3.6.1/Servers/Common/vtkPVDataInformation.cxx, line 586 vtkPVDataInformation (0x2c391a0): Could not cast object to a known data set: vtkAlgorithmOutput [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']]
Summary:
Please note that all contributions to bone.wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BoneWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
associated-pages
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Documents
Recent changes
Help
Tools
What links here
Related changes
Page information