.NET versus C++ API

The .NET framework implies differences between the C++ and the .NET API. This section may be skipped by .NET-only developers. However, it may be helpful if you are already familiar with the Open Inventor C++ API.

Classes and Extensions not Available in Open Inventor .NET

C++ Features Available in .NET But With a Different Interface

C++ Features That Are Not Necessary in .NET


Classes and Extensions not Available in Open Inventor .NET

  • The DialogViz classes provided with Open Inventor C++ are not available because you will use the standard Winforms package instead.
  • The GDI output available with HardCopy C++ is not currently available in the HardCopy package of Open Inventor .NET.
  • The TerrainViz extension of Open Inventor C++ is not currently available with Open Inventor .NET.
  • The MeshViz XLM extension is not currently available with Open Inventor .NET.

C++ Features Available in .NET But With a Different Interface

The following features cannot be implemented in the same way as they are implemented in C++.

Callback mechanism

The callback mechanism is used very often by Open inventor C++. Callback functions are defined as follows:

typedef <return_type> functionCB(void * userData, type1 arg1,..., typen argn);
static  <return_type> myFunctionCB(void * userData, type1 arg1,..., typen argn)
{
...
}

The callback is registered by calling an addCallback method:

 addCallback((functionCB*) myFunctionCB, this);

The .NET implementation is based on delegates and each type of callback is implemented by a specific delegate.
The following example shows how to set a callback on a selection point event.

bool SelectionPointCB(SoAction action, SoPrimitiveVertex v)
{
  SoDetail detail = v.GetDetail();
  int    coordIndex = ((SoPointDetail) detail).GetCoordinateIndex();
  ...
  return false; // con tinue examining next primitives
}

The delegate is registered as follows:

 SoExtSelection selection = new SoExtSelection();
selection.PointFilterCallback = new SoExtSelection.PointCB(SelectionPointCB);

Pointers, values

Most objects are handled through references -- not pointers or values, but only references. However, struct types (e.g. SbVec3f)are passed by value.

C++

SoCone *cone = new SoC one;
cone->height.setValue( 3 );

C#

SoCone cone = new SoCone();
 cone.height.SetValue( 3 ); // note also difference in capitalization of method name

Another minor difference between C++ and C# involves the new operator. The example below shows setting coordinate values into the vertex field of an SoVertexProperty node.

C++

Node->vertex.se t1Value (0, SbVec3f(x,y,z));

C#

Node.vertex.Set 1Value (0, new SbVec3f(x,y,z)); // "new" is required

C++ Features That Are Not Necessary in .NET

  • The C++ methods SoBase::ref(), SoBase::unref(), and SoBase::unrefNoDelete() are not needed because reference counting is a feature of the .NET language.
  • Class SoType is not needed because .NET Type is equivalent.
  • Class SbString is not needed because .NET String is equivalent.
  • Class SbBool is not needed because .NET bool is equivalent.
  • The C++ methods SoDB::init(), SoInteraction::init(), and SoNodeKit::init() are not needed because these classes are automatically initialized when loading the first Open Inventor.NET class. Likewise for SoHardCopy::init(), SoVolumeRendering::init(), and PoMeshviz::init().