============
Highlighting
============

After a selection is performed, it is usually desirable to provide visual feedback to the user regarding what was selected. In HOOPS Visualize Desktop, this concept is called *highlighting*. The details of how to represent highlighting are up to the developer. You could choose to modify an object's color, line weight, vertex/edge/face visibility, material, shading mode, or any combination of these and other attributes. Selection and highlighting are two distinct operations. Thus, it isn't necessary to perform a selection before highlighting an object, nor must you highlight something that was selected.

Highlighting can be applied at several different levels:

.. csv-table::
	:header: "Selection level", "Description"
	
	"``HPS::SelectionResults``", "The complete contents of a ``HPS::SelectionResults`` object can be highlighted."
	"``HPS::SelectionItem``", "A single item within a ``HPS::SelectionResults`` object can be highlighted."
	"``HPS::SearchResults``", "The complete results of a search can be highlighted."
	"``HPS::KeyPath``", "A common selection case is to highlight a model sub-assembly. This is accomplished using a ``HPS::KeyPath``."
	"``HPS::Key``", "The contents of a segment can be highlighted."

Note that a single geometric entity cannot be highlighted by simply providing its key. HOOPS Visualize Desktop does not allow this because commonly, geometry is duplicated across the scene through the use of include segments. To avoid the ambiguous possibility of the same geometry being rendered multiple times, a ``HPS::KeyPath`` is required to provide resolution. The ``HPS::KeyPath`` object is discussed in :ref:`this section <prog_guide/0102_api_conventions:Using a KeyPath>`.

The ``HPS::HighlightControl`` is the object that controls this mechanic. It is only available from a ``HPS::WindowKey`` and uses the attributes of defined :doc:`styles <0403_styles>` to achieve the highlight effect. The code below defines a simple style and highlights an object based on its key path.

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_highlighting.cpp
		   :start-after: //! [highlighting]
		   :end-before: //! [highlighting]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_highlighting.cs
		   :start-after: //! [highlighting]
		   :end-before: //! [highlighting]

Why would you complicate matters by using the highlight control when you could just apply a style manually? You certainly *could* apply it manually, but the highlighting mechanic keeps track of what is highlighted so that it can easily be unhighlighted at a future time. It also enables you to easily select from highlight styles you've previously defined. For information on how to build a highlight style, see :doc:`this section <0403_styles>`.

The following screenshots show examples of highlight styles:

.. image:: images/bnc.png

*An unhighlighted model*

.. image:: images/bnc_opaque.png

*The model's bottom tube has been highlighted with an opaque red highlight style.*

.. image:: images/bnc_textured.png

*The model's bottom tube has been highlighted with a textured highlight style.*


Overlays
--------

All highlighting is performed using the concept of overlays. An overlay will allow an entity to be highlighted without redrawing the entire scene. When using overlays with a highlight style, you should set the overlay with the highlight options kit, not in the style itself. If both the highlight options kit and highlight style define different overlay settings, the result is undefined.

More information on overlays can be found :doc:`here <0605_overlays>`.


.. _highlight_operator:

Using a Highlight Operator
==========================

The ``HPS::HighlightOperator`` and ``HPS::HighlightAreaOperator`` provide visual feedback by applying a style to a selected object. The highlighting operators derive from the selection operators, and thus, can be used to perform selection as well. The style, or "highlight", is set by passing a ``HPS::HighlightOptionsKit`` to the operator before the selection occurs.

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_select_operator.cpp
		   :start-after: //! [highlight_operator]
		   :end-before: //! [highlight_operator]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_select_operator.cs
		   :start-after: //! [highlight_operator]
		   :end-before: //! [highlight_operator]
		   
For information on how to define the highlight style itself, see :doc:`this section <0403_styles>` of the Programming Guide. If you need more control over how highlights are applied, refer to the :doc:`custom operators section <0602_custom_operators>` for details on how to create your own custom operator.


.. _highlights_search:

Searching for Highlights
========================

There are two built-in methods for obtaining highlight information from the scene: 

* the ``HPS::WindowKey::FindHighlights()`` function
* the ``HPS::HighlightControl::ShowHighlightState`` function


FindHighlights()
----------------

To find highlighted elements in your scene, pass a ``HPS::HighlightSearchResults`` object to the ``HPS::WindowKey`` function. In the following example, we'll set an option in the ``HPS::HighlightSearchOptionsKit`` to limit our search to items that use the ``WithZValues`` overlay type:

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_highlighting.cpp
		   :start-after: //! [find_highlights]
		   :end-before: //! [find_highlights]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_highlighting.cs
		   :start-after: //! [find_highlights]
		   :end-before: //! [find_highlights]
		   
Using the ``HPS::HighlightSearchResultsIterator``, you can inspect each element in the ``HPS::HighlightSearchResults`` object. 


ShowHighlightState()
--------------------

The ``HPS::HighlightState`` object is populated with the ``HPS::HighlightControl::ShowHighlightState`` function. In this case, we're filtering our results 
with the ``HPS::HighlightSearchOptionsKit`` by searching only for highlighted items that use the built-in named style "highlight_style":

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_highlighting.cpp
		   :start-after: //! [highlight_state]
		   :end-before: //! [highlight_state]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_highlighting.cs
		   :start-after: //! [highlight_state]
		   :end-before: //! [highlight_state]
		   
After calling ``HPS::HighlightControl::ShowHighlightState``, you can call various functions on the ``HighlightState`` object to gather details about highlighting on the keypath:

* ``GetInheritsHighlight()`` indicates whether the keypath contains a highlight inherited from from a parent segment.
* ``GetSubentityHighlighted()`` indicates whether this segment contains a highlighted subentity (e.g., face or vertex). This function is only useful for shells and meshes.
* ``GetDirectlyHighlighted()`` indicates if any of the keys on the ``HPS::KeyPath`` are directly highlighted (i.e., the highlight is set on this segment and not just inherited from a parent segment). 
* ``GetOnHighlightPath()`` indicates whether there's a highlight in a child segment on this ``HPS::KeyPath``.
		

