.. role:: ts-api-decorator

#################
UnstructGridModel
#################

.. js:module:: cee.usg
   :noindex:

.. container:: ts-api-section

   .. js:class:: UnstructGridModel

      The UnstructGridModel implements a client side model for handling surface CAE models. 

      It handles surface elements with any number of nodes. A model has one or more ``State``s, which links a ``Geometry`` to 
      scalar, displacement and transformation results for that geometry in that state.

      Here is a simple example of how to create an usg model containing a single quad element 
      with a per node scalar result in one state:


      .. code-block:: javascript

         let model = new cee.usg.UnstructGridModel();
         this.m_view.addModel(model);

         let geometry = new cee.usg.Geometry();
         let part = geometry.addPart();

         // Create a single quad mesh
         const nodeArr = [0,0,0, 1,0,0, 1,1,0, 0,1,0];
         const elConnArr = [0,1,2,3];
         part.mesh = new cee.usg.Mesh(nodeArr, 4, elConnArr);

         // Configure the visual appearance of the part
         part.settings.color = new cee.Color3(1,0,0);
         part.settings.drawStyle = cee.usg.DrawStyle.SURFACE_MESH

         // Create a state, set the geometry and add the scalar result
         let state = model.addState();
         state.geometry = geometry;

         let scalarArr = [1,2,3,4];
         state.setPartFringesAt(0, new cee.usg.PartScalars(cee.usg.ResultMapping.PER_NODE, scalarArr));

         // Configure the mapper to use, and 
         const mapper = new cee.ScalarMapperFilledContoursUniform();
         mapper.colorArray = cee.ColorTableFactory.color4TableArray(cee.ColorTable.RAINBOW, 15);
         mapper.setRange(1,4);
         model.fringesSettings.scalarMapper = mapper;

         // Add a color legend based on the mapper
         this.m_view.overlay.addCustomColorLegendForScalarMapper(mapper, "Demo result", 1);


      This code sample produces the following image in the 3D Viewer:

      .. image:: ../../images/UsgModel.png





.. container:: api-index-section

   .. rubric:: Constructors

   .. rst-class:: api-index-list-item api-kind-constructor api-parent-kind-class

   * :js:meth:`~cee.usg.UnstructGridModel.constructor`



.. container:: api-index-section

   .. rubric:: Accessors

   .. rst-class:: api-index-list-item api-kind-accessor api-parent-kind-class

   * :js:attr:`~cee.usg.UnstructGridModel.currentState`
   * :js:attr:`~cee.usg.UnstructGridModel.currentStateIndex`
   * :js:attr:`~cee.usg.UnstructGridModel.displacementSettings`
   * :js:attr:`~cee.usg.UnstructGridModel.fringesSettings`
   * :js:attr:`~cee.usg.UnstructGridModel.name`
   * :js:attr:`~cee.usg.UnstructGridModel.stateCount`
   * :js:attr:`~cee.usg.UnstructGridModel.vectorSettings`



.. container:: api-index-section

   .. rubric:: Methods

   .. rst-class:: api-index-list-item api-kind-method api-parent-kind-class

   * :js:meth:`~cee.usg.UnstructGridModel.addState`
   * :js:meth:`~cee.usg.UnstructGridModel.deleteAllStates`
   * :js:meth:`~cee.usg.UnstructGridModel.deleteStateAt`
   * :js:meth:`~cee.usg.UnstructGridModel.deleteStateRange`
   * :js:meth:`~cee.usg.UnstructGridModel.getBoundingBox`
   * :js:meth:`~cee.usg.UnstructGridModel.getDefaultCameraConfig`
   * :js:meth:`~cee.usg.UnstructGridModel.getFringesResultRange`
   * :js:meth:`~cee.usg.UnstructGridModel.getStateArray`
   * :js:meth:`~cee.usg.UnstructGridModel.getStateAt`
   * :js:meth:`~cee.usg.UnstructGridModel.rayIntersect`





------------

Constructors
============

.. container:: ts-api-section

   .. js:function:: UnstructGridModel.constructor([ options])

      :param options: :ts-api-decorator:`optional` None
      :type options: UnstructGridModelOptions


      Create the UnstructGridModel

      Use the options to set the resource usage strategy for the model in a multi-state scenario. See
      ``UnstructGridModelOptions`` for more info.


      :rtype: UnstructGridModel



Accessors
=========

.. container:: ts-api-section

   .. js:function:: UnstructGridModel.currentState()



      The zero based index of the state currently shown in the view. Returns null for an invalid ``currentStateIndex``.


      :rtype: State



.. container:: ts-api-section

   .. js:function:: UnstructGridModel.currentStateIndex()



      The state to show in the view.

      The given zero-based index must be between 0 and ``stateCount`` - 1.


      :rtype: number

   .. js:function:: UnstructGridModel.currentStateIndex( stateIndex)

      :param stateIndex: None
      :type stateIndex: number


      :rtype: void



.. container:: ts-api-section

   .. js:function:: UnstructGridModel.displacementSettings()



      Settings for the displacement results


      :rtype: DisplacementSettings



.. container:: ts-api-section

   .. js:function:: UnstructGridModel.fringesSettings()



      Settings for the scalars shown as fringes on the model


      :rtype: ScalarSettings



.. container:: ts-api-section

   .. js:function:: UnstructGridModel.name()



      The name of the geometry model. Mainly used for debugging.


      :rtype: string

   .. js:function:: UnstructGridModel.name( name)

      :param name: None
      :type name: string


      Name of the model. 

      Mainly used for debugging.


      :rtype: void



.. container:: ts-api-section

   .. js:function:: UnstructGridModel.stateCount()



      Returns the number of states in this model


      :rtype: number



.. container:: ts-api-section

   .. js:function:: UnstructGridModel.vectorSettings()



      Settings for the scalars shown as fringes on the model


      :rtype: VectorSettings



Methods
=======

.. rst-class:: ts-api-section

addState
--------

.. js:method:: UnstructGridModel.addState()



   Add a state to the model.

   The added state is returned.


   :rtype: State

.. rst-class:: ts-api-section

deleteAllStates
---------------

.. js:method:: UnstructGridModel.deleteAllStates()



   Delete all states in the model.


   :rtype: void

.. rst-class:: ts-api-section

deleteStateAt
-------------

.. js:method:: UnstructGridModel.deleteStateAt( stateIndex)

   :param stateIndex: None
   :type stateIndex: number


   Delete a state at the given zero based index.


   :rtype: void

.. rst-class:: ts-api-section

deleteStateRange
----------------

.. js:method:: UnstructGridModel.deleteStateRange( startIndex[, deleteCount])

   :param startIndex: None
   :type startIndex: number
   :param deleteCount: :ts-api-decorator:`optional` None
   :type deleteCount: number


   Delete a range of states. First state that will be deleted is the state with the given index
   If deleteCount is omitted, all states starting with the given index will be deleted.

   Works similar to the splice method on Javascript arrays


   :rtype: void

.. rst-class:: ts-api-section

getBoundingBox
--------------

.. js:method:: UnstructGridModel.getBoundingBox([ _options])

   :param _options: :ts-api-decorator:`optional` None
   :type _options: ModelBoundingBoxOptions


   Returns the ``BoundingBox`` (in world coordinates) of the current state within the model.

   The returned bounding box will reflect the currently visible objects in the model.

   Note that this method does not support any ``ModelBoundingBoxOptions``


   :rtype: BoundingBox

.. rst-class:: ts-api-section

getDefaultCameraConfig
----------------------

.. js:method:: UnstructGridModel.getDefaultCameraConfig()



   Returns default camera configuration, which is always null for this model.


   :rtype: unknown

.. rst-class:: ts-api-section

getFringesResultRange
---------------------

.. js:method:: UnstructGridModel.getFringesResultRange()



   Get the range of the scalar result in this model


   :rtype: Range

.. rst-class:: ts-api-section

getStateArray
-------------

.. js:method:: UnstructGridModel.getStateArray()



   Returns a readonly array of all the states in the model


   :rtype: unknown

.. rst-class:: ts-api-section

getStateAt
----------

.. js:method:: UnstructGridModel.getStateAt( stateIndex)

   :param stateIndex: None
   :type stateIndex: number


   Returns a reference to the state at the given index


   :rtype: State

.. rst-class:: ts-api-section

rayIntersect
------------

.. js:method:: UnstructGridModel.rayIntersect( ray)

   :param ray: None
   :type ray: Ray


   Performs picking on the model in the current state.

   If something was hit, returns a HitItem containing information about the part and primitive that was hit.

   If nothing was hit, returns null.


   :rtype: HitItem

