This tutorial shows how to get your own analysis results into the UnstructGridModel by creating a DataReader.
It is a very simple reader that returns one hexahedron element with one scalar, one vector, one displacement and one transformation result, but it will work as a starting point for building your own file reader.
To create a custom data reader, you have to sub-class the DataReader class.
First you need to implement a method to detect if the file is supported or not as well as open and close methods. We also need to specify how many geometries there are in our file. Usually this is 1.
In this case this is really simple as we are doing a sample in-memory "reader"
The next step is to provide information (meta-data) regarding the file that was just opened. To specify the contents of the file (number of states, name and id of all the results, etc) you have to implement the initializeDirectory() method. This method will be called by the system after the file is successfully opened.
Next, we need to provide the geometry. This is done by overriding the readGeometry() method. In this method, you will have to provide the DataGeometry for the given state and geometry id. Please note that if you have a new geometry for each state (adaptive/remeshing model) you have to override the hasNewGeometryForEachState() method and return true for the geometry/geometries that are remeshed.
Next, we provide the scalar result. This method is called whenever the UnstructGridModel (during updateVisualization()) needs a scalar result and it is not present in the data source. This could be because the result is specified as fringes result in the ModelSpec, specified to be mapped on a cutting plane or isosurface or specified to be mapped on a particle trace. Only the results added to the directory in the initializeDirectory() will be queried by this method.
Next, we provide the vector result. This works in the same way as for scalar results.
Next, we provide a displacement result. Please note that the displacement results needs to contain new absolute node coordinates, not just the displaced value.
Finally, we provide a transformation result. This is a rigid body transformation per part.
This concludes the custom DataReader and demonstrates how to use all the virtual methods in the interface.
Please not that the following methods must be overridden (pure virtual methods):
The rest of the methods are optional, but you need to implement read* methods for all the result you provide directory information about in the initializeDirectory() method.
Please note that the rest of this example would work with any reader and actually any data source, as it used the content from the data source directory to setup the model. The UnstructGridModel will use the reader when necessary to load the DataSource with the required results.
Create a model and the DataSourceReader data source with our newly created DataReader.Then open the "file" so it is ready to use.
Use the DataSourceDirectory to get information about states and result provided by our reader.
Here we setup the model spec with the results found in the data source directory.
Then we can add the model to the view and call updateVisualization(). This call will trigger loading of the results and states specified in the ModelSpec and our reader will get calls to readGeometry, readScalar() etc. depending on what is specified in the ModelSpec.
Finally, as in all other examples, we need to set a default camera position and update the viewer.
UnstructGrid: Create a custom DataReader to add support for your file format