.. _dataprovider-vtk-page:

##########
VTK Plugin 
##########

********
Overview
********

The VTK Data Provider Plugin has been developed using :ref:`data-provider-framework-page`.

The provider can be plugged into applications based on HOOPS Envision for Desktop. This includes 
HOOPS Envision Demo Analyzer and the RemoteModel server (UgServer) in |WebProductName|. 
The same plugin can be used both on web and desktop.

The cdp_Vtk plugin provides the following data based on a given ModelKey:

-   Meta data about the given model: Number of states (time increments), geometries (multiple domains + boundaries), results
-   CAE model with elements and nodes
-   Results: Scalar, Vector, Displacements and Tensors
-   Element sets

The VTK data provider plugin will then be used to open all your .vtu, .pvtu, .pvd and .vtm files.

If the built-in VTK reader should be used, just delete the cdp_VtkPlugin plugin from this path.


*****************
Available Options
*****************

The following options are supported by the VTK Data Provider:

================================  ======= =========  ==================================================================================
Name                              Type    Default    Description
================================  ======= =========  ==================================================================================
PVD_WELD_INTERFACE_NODES          bool    true       Weld interface nodes for pvd files.
PVTU_WELD_INTERFACE_NODES         bool    true       Weld interface nodes for parallel vtu files.
PVTU_PARTID_FIELD_NAME            string  PartID     Field name for Parts in PVTU files.
VTU_PARTID_FIELD_NAME             string  PartID     Field name for Parts in VTU files.
READ_VECTOR_AS_DISPLACEMENT       boolean false      Read Vector as Displacements.
USE_CEETRON_ACCESS_COMPATIBILITY  boolean true       HOOPS Access compatibility: i.e Use 6 components as SymTensor. Use 3 components as vector. Use Results Nature.
RESULTS_NAMES_MAPPING             string             U=VELOCITY;displacement=DISPLACEMENT;strain=STRAIN;strain_energy_density=STRAIN_ENERGY_DENSITY;stress=STRESS;pd=PRESSURE;T=TEMPERATURE;points=POSITION;origId=IDENTIFIER;rho=DENSITY;gamma=FLUID_PHASE;positions=POSITION;cellID=IDENTIFIER;scalars=SCALARS
================================  ======= =========  ==================================================================================
   
For Envision Web, use the :js:meth:`RemoteModel.setReaderOptions()` to specify these options before opening a file. 
For Envision Desktop, use the 
:func:`ReaderSettings::addDataProviderSettings() <cee::imp::cae::ReaderSettings::addDataProviderSettings()>` to specify 
these options before opening a file. 


********************
Use in |ProductName|
********************

Load the VTK data provider plugin using 
:func:`loadDataProviderPlugin() <cee::imp::cae::DataSourceCae::loadDataProviderPlugin()>` or load 
multiple plugins at once using 
:func:`loadDataProviderPluginsFromWildcard() <cee::imp::cae::DataSourceCae::loadDataProviderPluginsFromWildcard()>`.

Use the :func:`ReaderSettings::addDataProviderSettings() <cee::imp::cae::ReaderSettings::addDataProviderSettings()>` 
to specify these options before opening a file. 

See the list of available options for the VTK data provider in the list above.

Example:

.. code-block:: cpp

    for (size_t i = 0; i < cee::imp::cae::DataSourceCae::readerSettings().dataProviderSettingsCount(); ++i)
    {
        cee::imp::cae::ReaderSettingsDataProvider& settings = cee::imp::cae::DataSourceCae::readerSettings().dataProviderSettings(i);

        if (settings.providerIdString() == "VTKProvider")
        {
            settings.setBoolValue("PVTU_WELD_INTERFACE_NODES", true);
            settings.setBoolValue("PVTU_PARTID_FIELD_NAME", "MyPartID");
        }
    }

*************************************
Use in Envision Demo Analyzer Desktop
*************************************

You can use your data provider with Envision Demo Analyzer Desktop. When installed, the data provider plugins are in the 
**DataProviders** folder below the Analyzer executable. You can change this location by defining the environment 
variable **CEE_DATA_PROVIDERS_FOLDER** to point to the folder where your cdp_VtkPlugin is located.
Envision Demo Analyzer will load the data providers from the specified folder.  

In the **Settings** dialog under the **Data Provider** panel, all the reader options for the VTK data provider are 
shown and can be edited. See the list of available options for the VTK data provider in the list above.

Once any of this settings edited, please reopen your model to account for this modification.



***********************
Use in |WebProductName|
***********************

Data providers can be used with the RemoteModel server (UgServer). To load your data provider, set the 
**CEW_UG_DATA_PROVIDER_FOLDER** environment variable to point to the folder with your data provider. The UgServer will 
load all data providers in the specified folder. The data provider needs to comply to the following naming scheme:

    cdp_VtkPlugin.[dll|so|dylib]

Example:

    cdp_VtkPlugin.dll (Windows), cdp_VtkPlugin.so (Linux)

The server will list the registered VTK data provider plugin when a file is opened.

A data provider plugin can have a set of reader settings. For Envision Web, use the 
:js:meth:`RemoteModel.setReaderOptions()` to specify these options before opening a file.
See the list of available options for the VTK data provider in the list above.

Example:

.. code-block:: ts

    this.m_model.setReaderOptions("VTKProvider", { 
        "PVTU_WELD_INTERFACE_NODES": true, 
        "PVTU_PARTID_FIELD_NAME": "MyPartID"
    });


