6:点云处理—QT三维窗口显示

1.编写halcon显示程序

导出C++格式



*读取三维点云 
dev_get_window(WindowHandle)

dev_open_window(0, 0, 512, 512, 'black', WindowHandle1)

*512, 512
CamParam := [0.01,0,7e-6,7e-6,512/2, 512/2,512, 512]
DisPose:=[30.427, -1.05274, 97.8798, 8.29326, 356.416, 99.016, 0]

*彩色显示用的    0-----渐变色  ----伪彩图
GenParamNames := ['lut','intensity','light_position','disp_pose','alpha']
GenParamValues := ['color1','coord_z','0.0 0.0 -0.3 1.0','true',1]


read_object_model_3d('object55.om3', 'mm', [], [], ObjectModel3D, Status)
visualize_object_model_3d (WindowHandle1,ObjectModel3D, [],[],  \
                     GenParamNames,GenParamValues, [], [],\
                       [],  DispPose)

*单色显示

GenParNames := ['color_0','alpha']
GenParValues := ['cyan',0.7]
visualize_object_model_3d (WindowHandle1,ObjectModel3D, [],[],  \
                     GenParNames,GenParValues, [], [],\
                       [],  DispPose)

disp_object_model_3d(WindowHandle1, ObjectModel3D, [], [], GenParamNames,GenParamValues)


disp_object_model_3d(WindowHandle1, ObjectModel3D, [], [], GenParNames,GenParValues)

2.建立QT文件

3.添加公共显示的类

.h文件

#ifndef __KD_HALCON_ALG_H__
#define __KD_HALCON_ALG_H__


#include "HalconCpp.h"
#include "HDevThread.h"
#include <QDebug>
using namespace HalconCpp;
void action(long win,int  width,int height,HTuple ObjectModel3D);
void visualize_object_model_3d (HTuple WindowHandle, HTuple ObjectModel3D,
    HTuple CamParam, HTuple PoseIn, HTuple GenParamName, HTuple GenParamValue,
    HTuple Title, HTuple Label, HTuple Information, HTuple *PoseOut);
void dev_open_window_fit_image(HObject Image,HTuple width,HTuple height,HTuple Row, HTuple Column,
                               HTuple WidthLimit, HTuple HeightLimit, HTuple *WindowHandle, HTuple FatherWindow);
void disp_message (HTuple WindowHandle, HTuple String, HTuple CoordSystem,
    HTuple Row, HTuple Column, HTuple Color, HTuple Box);

#endif // ! __KD_HALCON_ALG_H__

.cpp文件




#include "HalconCpp.h"
#include "HDevThread.h"
#include <QDebug>
#include "halconAlg.h"
#include <QDir>



HTuple  gInfoDecor;
HTuple  gInfoPos;
HTuple  gTitlePos;
HTuple  gTitleDecor;
HTuple  gDispObjOffset;
HTuple  gLabelsDecor;
HTuple  gTerminationButtonLabel;
HTuple  gAlphaDeselected;
HTuple  gIsSinglePose;
HTuple  gUsesOpenGL;
HTuple ExpGetGlobalVar_gInfoDecor(void)
{
  return gInfoDecor;
}
void ExpSetGlobalVar_gInfoDecor(HTuple val)
{
  gInfoDecor = val;
}

HTuple ExpGetGlobalVar_gInfoPos(void)
{
  return gInfoPos;
}
void ExpSetGlobalVar_gInfoPos(HTuple val)
{
  gInfoPos = val;
}

HTuple ExpGetGlobalVar_gTitlePos(void)
{
  return gTitlePos;
}
void ExpSetGlobalVar_gTitlePos(HTuple val)
{
  gTitlePos = val;
}

HTuple ExpGetGlobalVar_gTitleDecor(void)
{
  return gTitleDecor;
}
void ExpSetGlobalVar_gTitleDecor(HTuple val)
{
  gTitleDecor = val;
}

HTuple ExpGetGlobalVar_gDispObjOffset(void)
{
  return gDispObjOffset;
}
void ExpSetGlobalVar_gDispObjOffset(HTuple val)
{
  gDispObjOffset = val;
}

HTuple ExpGetGlobalVar_gLabelsDecor(void)
{
  return gLabelsDecor;
}
void ExpSetGlobalVar_gLabelsDecor(HTuple val)
{
  gLabelsDecor = val;
}

HTuple ExpGetGlobalVar_gTerminationButtonLabel(void)
{
  return gTerminationButtonLabel;
}
void ExpSetGlobalVar_gTerminationButtonLabel(HTuple val)
{
  gTerminationButtonLabel = val;
}

HTuple ExpGetGlobalVar_gAlphaDeselected(void)
{
  return gAlphaDeselected;
}
void ExpSetGlobalVar_gAlphaDeselected(HTuple val)
{
  gAlphaDeselected = val;
}

HTuple ExpGetGlobalVar_gIsSinglePose(void)
{
  return gIsSinglePose;
}
void ExpSetGlobalVar_gIsSinglePose(HTuple val)
{
  gIsSinglePose = val;
}

HTuple ExpGetGlobalVar_gUsesOpenGL(void)
{
  return gUsesOpenGL;
}
void ExpSetGlobalVar_gUsesOpenGL(HTuple val)
{
  gUsesOpenGL = val;
}

// Procedure declarations
// External procedures
// Chapter: Develop
// Short Description: Open a new graphics window that preserves the aspect ratio of the given image.
//void dev_open_window_fit_image (HObject Image, HTuple Row, HTuple Column,
//    HTuple WidthLimit, HTuple HeightLimit, HTuple *WindowHandle);
// Chapter: Develop

// Short Description: Switch dev_update_pc, dev_update_var and dev_update_window to 'off'.
void dev_update_off ();
// Chapter: Graphics / Text
// Short Description: Set font independent of OS
void set_display_font (HTuple WindowHandle, HTuple Size, HTuple Font, HTuple Bold,
    HTuple Slant);
// Chapter: Graphics / Text
// Short Description: This procedure writes a text message.
// Chapter: Graphics / Output
void disp_title_and_information (HTuple WindowHandle, HTuple Title, HTuple Information);
// Chapter: Graphics / Output
// Short Description: Can replace disp_object_model_3d if there is no OpenGL available.
void disp_object_model_no_opengl (HObject *ModelContours, HTuple ObjectModel3DID,
    HTuple GenParamName, HTuple GenParamValue, HTuple WindowHandleBuffer,
    HTuple CamParam, HTuple PosesOut);
// Chapter: Graphics / Output
// Short Description: Interactively display 3D object models

// Chapter: Graphics / Output
// Short Description: Determine the optimum distance of the object to obtain a reasonable visualization
void determine_optimum_pose_distance (HTuple ObjectModel3DID, HTuple CamParam,
    HTuple ImageCoverage, HTuple PoseIn, HTuple *PoseOut);
// Chapter: Graphics / Output
// Short Description: Reflect the pose change that was introduced by the user by moving the mouse
void analyze_graph_event (HObject BackgroundImage, HTuple MouseMapping, HTuple Button,
    HTuple Row, HTuple Column, HTuple WindowHandle, HTuple WindowHandleBuffer,
    HTuple VirtualTrackball, HTuple TrackballSize, HTuple SelectedObjectIn,
    HTuple Scene3D, HTuple AlphaOrig, HTuple ObjectModel3DID, HTuple CamParam,
    HTuple Labels, HTuple Title, HTuple Information, HTuple GenParamName,
    HTuple GenParamValue, HTuple PosesIn, HTuple ButtonHoldIn, HTuple TBCenter,
    HTuple TBSize, HTuple WindowCenteredRotationlIn, HTuple MaxNumModels,
    HTuple *PosesOut, HTuple *SelectedObjectOut, HTuple *ButtonHoldOut,
    HTuple *WindowCenteredRotationOut);
// Chapter: Graphics / Output
// Short Description: Project an image point onto the trackball
void project_point_on_trackball (HTuple X, HTuple Y, HTuple VirtualTrackball,
    HTuple TrackballSize, HTuple *V);
// Chapter: Graphics / Text
// Short Description: This procedure writes a text message.
void disp_text_button (HTuple WindowHandle, HTuple String, HTuple CoordSystem,
    HTuple Row, HTuple Column, HTuple TextColor, HTuple ButtonColor);
// Chapter: Graphics / Output
// Short Description: Renders 3d object models in a buffer window.
void dump_image_output (HObject BackgroundImage, HTuple WindowHandleBuffer,
    HTuple Scene3D, HTuple AlphaOrig, HTuple ObjectModel3DID, HTuple GenParamName,
    HTuple GenParamValue, HTuple CamParam, HTuple Poses, HTuple ColorImage,
    HTuple Title, HTuple Information, HTuple Labels, HTuple VisualizeTrackball,
    HTuple DisplayContinueButton, HTuple TrackballCenterRow, HTuple TrackballCenterCol,
    HTuple TrackballRadiusPixel, HTuple SelectedObject, HTuple VisualizeRotationCenter,
    HTuple RotationCenter);
// Chapter: Graphics / Output
// Short Description: Get the center of the virtual trackback that is used to move the camera.
void get_trackball_center (HTuple SelectedObject, HTuple TrackballRadiusPixel,
    HTuple ObjectModel3D, HTuple Poses, HTuple *TBCenter, HTuple *TBSize);
// Chapter: Tuple / Arithmetic
// Short Description: Calculates the cross product of two vectors of length 3.
void tuple_vector_cross_product (HTuple V1, HTuple V2, HTuple *VC);
// Chapter: Graphics / Output
// Short Description: Compute the 3d rotation from the mose movement
void trackball (HTuple MX1, HTuple MY1, HTuple MX2, HTuple MY2, HTuple VirtualTrackball,
    HTuple TrackballSize, HTuple SensFactor, HTuple *QuatRotation);
// Chapter: Graphics / Output
// Short Description: Get string extends of several lines.
void max_line_width (HTuple WindowHandle, HTuple Lines, HTuple *MaxWidth);
// Chapter: Graphics / Output
// Short Description: Compute the center of all given 3D object models.
void get_object_models_center (HTuple ObjectModel3DID, HTuple *Center);
// Chapter: Graphics / Output
// Short Description: Displays a continue button.
void disp_continue_button (HTuple WindowHandle);
// Chapter: Graphics / Parameters
void color_string_to_rgb (HTuple Color, HTuple *RGB);
// Chapter: Graphics / Output
// Short Description: Get the center of the virtual trackback that is used to move the camera (version for inspection_mode = 'surface').
void get_trackball_center_fixed (HTuple SelectedObject, HTuple TrackballCenterRow,
    HTuple TrackballCenterCol, HTuple TrackballRadiusPixel, HTuple Scene3D,
    HTuple ObjectModel3DID, HTuple Poses, HTuple WindowHandleBuffer, HTuple CamParam,
    HTuple GenParamName, HTuple GenParamValue, HTuple *TBCenter, HTuple *TBSize);

// Procedures
// External procedures
// Chapter: Develop
// Short Description: Open a new graphics window that preserves the aspect ratio of the given image.

void dev_open_window_fit_image(HObject Image,HTuple width,HTuple height, HTuple Row, HTuple Column, HTuple WidthLimit, HTuple HeightLimit, HTuple *WindowHandle, HTuple FatherWindow)
{
    // Local iconic variables

    // Local control variables
    HTuple  MinWidth, MaxWidth, MinHeight;
    HTuple  MaxHeight, ResizeFactor, ImageWidth, ImageHeight;
    HTuple  TempWidth, TempHeight, WindowWidth, WindowHeight;

    if (0 != (HTuple((WidthLimit.TupleLength()) == 0).TupleOr(WidthLimit<0)))
    {
        MinWidth = 500;
        MaxWidth = 800;

    }
    else if (0 != ((WidthLimit.TupleLength()) == 1))
    {
        MinWidth = 0;
        MaxWidth = WidthLimit;
    }
    else
    {
        MinWidth = ((const HTuple&)WidthLimit)[0];
        MaxWidth = ((const HTuple&)WidthLimit)[1];
    }
    //Parse input tuple HeightLimit
    if (0 != (HTuple((HeightLimit.TupleLength()) == 0).TupleOr(HeightLimit<0)))
    {
        MinHeight = 400;
        MaxHeight = 600;
    }
    else if (0 != ((HeightLimit.TupleLength()) == 1))
    {
        MinHeight = 0;
        MaxHeight = HeightLimit;
    }
    else
    {
        MinHeight = ((const HTuple&)HeightLimit)[0];
        MaxHeight = ((const HTuple&)HeightLimit)[1];
    }
    //
    //Test, if window size has to be changed.
    ResizeFactor = 1;
    //GetImageSize(Image, &ImageWidth, &ImageHeight);
    ImageWidth=width;
    ImageHeight=height;
    //First, expand window to the minimum extents (if necessary).

    if (0 != (HTuple(MinWidth>ImageWidth).TupleOr(MinHeight>ImageHeight)))
    {
        ResizeFactor = (((MinWidth.TupleReal()) / ImageWidth).TupleConcat((MinHeight.TupleReal()) / ImageHeight)).TupleMax();
    }
    TempWidth = ImageWidth*ResizeFactor;
    TempHeight = ImageHeight*ResizeFactor;
    //Then, shrink window to maximum extents (if necessary).
    if (0 != (HTuple(MaxWidth<TempWidth).TupleOr(MaxHeight<TempHeight)))
    {
        ResizeFactor = ResizeFactor*((((MaxWidth.TupleReal()) / TempWidth).TupleConcat((MaxHeight.TupleReal()) / TempHeight)).TupleMin());
    }
    WindowWidth = ImageWidth*ResizeFactor;
    WindowHeight = ImageHeight*ResizeFactor;
    //Resize window
    SetWindowAttr("background_color", "black");
    OpenWindow(Row, Column, WindowWidth, WindowHeight, FatherWindow, "", "", &(*WindowHandle));
    HDevWindowStack::Push((*WindowHandle));
    if (HDevWindowStack::IsOpen())
        SetPart(HDevWindowStack::GetActive(), 0, 0, ImageHeight - 1, ImageWidth - 1);
    return;
}


void dev_update_off ()
{

  //This procedure sets different update settings to 'off'.
  //This is useful to get the best performance and reduce overhead.
  //
  // dev_update_pc(...); only in hdevelop
  // dev_update_var(...); only in hdevelop
  // dev_update_window(...); only in hdevelop
  return;
}

// Chapter: Graphics / Text
// Short Description: Set font independent of OS
void set_display_font (HTuple WindowHandle, HTuple Size, HTuple Font, HTuple Bold,
    HTuple Slant)
{

  // Local iconic variables

  // Local control variables
  HTuple  OS, BufferWindowHandle, Ascent;
  HTuple  Descent, Width, Height, Scale, Exception;
  HTuple  SubFamily, Fonts, SystemFonts, Guess;
  HTuple  I, Index, AllowedFontSizes, Distances;
  HTuple  Indices, FontSelRegexp, FontsCourier;

  //This procedure sets the text font of the current window with
  //the specified attributes.
  //It is assumed that following fonts are installed on the system:
  //Windows: Courier New, Arial Times New Roman
  //Mac OS X: CourierNewPS, Arial, TimesNewRomanPS
  //Linux: courier, helvetica, times
  //Because fonts are displayed smaller on Linux than on Windows,
  //a scaling factor of 1.25 is used the get comparable results.
  //For Linux, only a limited number of font sizes is supported,
  //to get comparable results, it is recommended to use one of the
  //following sizes: 9, 11, 14, 16, 20, 27
  //(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34)
  //
  //Input parameters:
  //WindowHandle: The graphics window for which the font will be set
  //Size: The font size. If Size=-1, the default of 16 is used.
  //Bold: If set to 'true', a bold font is used
  //Slant: If set to 'true', a slanted font is used
  //
  GetSystem("operating_system", &OS);
  // dev_get_preferences(...); only in hdevelop
  // dev_set_preferences(...); only in hdevelop
  if (0 != (HTuple(Size==HTuple()).TupleOr(Size==-1)))
  {
    Size = 16;
  }
  if (0 != ((OS.TupleSubstr(0,2))==HTuple("Win")))
  {
    //Set font on Windows systems
    try
    {
      //Check, if font scaling is switched on
      OpenWindow(0, 0, 256, 256, 0, "buffer", "", &BufferWindowHandle);
      SetFont(BufferWindowHandle, "-Consolas-16-*-0-*-*-1-");
      GetStringExtents(BufferWindowHandle, "test_string", &Ascent, &Descent,
          &Width, &Height);
      //Expected width is 110
      Scale = 110.0/Width;
      Size = (Size*Scale).TupleInt();
      CloseWindow(BufferWindowHandle);
    }
    // catch (Exception)
    catch (HalconCpp::HException &HDevExpDefaultException)
    {
      HDevExpDefaultException.ToHTuple(&Exception);
      //throw (Exception)
    }
    if (0 != (HTuple(Font==HTuple("Courier")).TupleOr(Font==HTuple("courier"))))
    {
      Font = "Courier New";
    }
    else if (0 != (Font==HTuple("mono")))
    {
      Font = "Consolas";
    }
    else if (0 != (Font==HTuple("sans")))
    {
      Font = "Arial";
    }
    else if (0 != (Font==HTuple("serif")))
    {
      Font = "Times New Roman";
    }
    if (0 != (Bold==HTuple("true")))
    {
      Bold = 1;
    }
    else if (0 != (Bold==HTuple("false")))
    {
      Bold = 0;
    }
    else
    {
      Exception = "Wrong value of control parameter Bold";
      throw HalconCpp::HException(Exception);
    }
    if (0 != (Slant==HTuple("true")))
    {
      Slant = 1;
    }
    else if (0 != (Slant==HTuple("false")))
    {
      Slant = 0;
    }
    else
    {
      Exception = "Wrong value of control parameter Slant";
      throw HalconCpp::HException(Exception);
    }
    try
    {
      SetFont(WindowHandle, ((((((("-"+Font)+"-")+Size)+"-*-")+Slant)+"-*-*-")+Bold)+"-");
    }
    // catch (Exception)
    catch (HalconCpp::HException &HDevExpDefaultException)
    {
      HDevExpDefaultException.ToHTuple(&Exception);
      //throw (Exception)
    }
  }
  else if (0 != ((OS.TupleSubstr(0,2))==HTuple("Dar")))
  {
    //Set font on Mac OS X systems. Since OS X does not have a strict naming
    //scheme for font attributes, we use tables to determine the correct font
    //name.
    SubFamily = 0;
    if (0 != (Slant==HTuple("true")))
    {
      SubFamily = SubFamily|1;
    }
    else if (0 != (Slant!=HTuple("false")))
    {
      Exception = "Wrong value of control parameter Slant";
      throw HalconCpp::HException(Exception);
    }
    if (0 != (Bold==HTuple("true")))
    {
      SubFamily = SubFamily|2;
    }
    else if (0 != (Bold!=HTuple("false")))
    {
      Exception = "Wrong value of control parameter Bold";
      throw HalconCpp::HException(Exception);
    }
    if (0 != (Font==HTuple("mono")))
    {
      Fonts.Clear();
      Fonts[0] = "Menlo-Regular";
      Fonts[1] = "Menlo-Italic";
      Fonts[2] = "Menlo-Bold";
      Fonts[3] = "Menlo-BoldItalic";
    }
    else if (0 != (HTuple(Font==HTuple("Courier")).TupleOr(Font==HTuple("courier"))))
    {
      Fonts.Clear();
      Fonts[0] = "CourierNewPSMT";
      Fonts[1] = "CourierNewPS-ItalicMT";
      Fonts[2] = "CourierNewPS-BoldMT";
      Fonts[3] = "CourierNewPS-BoldItalicMT";
    }
    else if (0 != (Font==HTuple("sans")))
    {
      Fonts.Clear();
      Fonts[0] = "ArialMT";
      Fonts[1] = "Arial-ItalicMT";
      Fonts[2] = "Arial-BoldMT";
      Fonts[3] = "Arial-BoldItalicMT";
    }
    else if (0 != (Font==HTuple("serif")))
    {
      Fonts.Clear();
      Fonts[0] = "TimesNewRomanPSMT";
      Fonts[1] = "TimesNewRomanPS-ItalicMT";
      Fonts[2] = "TimesNewRomanPS-BoldMT";
      Fonts[3] = "TimesNewRomanPS-BoldItalicMT";
    }
    else
    {
      //Attempt to figure out which of the fonts installed on the system
      //the user could have meant.
      QueryFont(WindowHandle, &SystemFonts);
      Fonts.Clear();
      Fonts.Append(Font);
      Fonts.Append(Font);
      Fonts.Append(Font);
      Fonts.Append(Font);
      Guess.Clear();
      Guess.Append(Font);
      Guess.Append(Font+"-Regular");
      Guess.Append(Font+"MT");
      {
      HTuple end_val100 = (Guess.TupleLength())-1;
      HTuple step_val100 = 1;
      for (I=0; I.Continue(end_val100, step_val100); I += step_val100)
      {
        TupleFind(SystemFonts, HTuple(Guess[I]), &Index);
        if (0 != (Index!=-1))
        {
          Fonts[0] = HTuple(Guess[I]);
          break;
        }
      }
      }
      //Guess name of slanted font
      Guess.Clear();
      Guess.Append(Font+"-Italic");
      Guess.Append(Font+"-ItalicMT");
      Guess.Append(Font+"-Oblique");
      {
      HTuple end_val109 = (Guess.TupleLength())-1;
      HTuple step_val109 = 1;
      for (I=0; I.Continue(end_val109, step_val109); I += step_val109)
      {
        TupleFind(SystemFonts, HTuple(Guess[I]), &Index);
        if (0 != (Index!=-1))
        {
          Fonts[1] = HTuple(Guess[I]);
          break;
        }
      }
      }
      //Guess name of bold font
      Guess.Clear();
      Guess.Append(Font+"-Bold");
      Guess.Append(Font+"-BoldMT");
      {
      HTuple end_val118 = (Guess.TupleLength())-1;
      HTuple step_val118 = 1;
      for (I=0; I.Continue(end_val118, step_val118); I += step_val118)
      {
        TupleFind(SystemFonts, HTuple(Guess[I]), &Index);
        if (0 != (Index!=-1))
        {
          Fonts[2] = HTuple(Guess[I]);
          break;
        }
      }
      }
      //Guess name of bold slanted font
      Guess.Clear();
      Guess.Append(Font+"-BoldItalic");
      Guess.Append(Font+"-BoldItalicMT");
      Guess.Append(Font+"-BoldOblique");
      {
      HTuple end_val127 = (Guess.TupleLength())-1;
      HTuple step_val127 = 1;
      for (I=0; I.Continue(end_val127, step_val127); I += step_val127)
      {
        TupleFind(SystemFonts, HTuple(Guess[I]), &Index);
        if (0 != (Index!=-1))
        {
          Fonts[3] = HTuple(Guess[I]);
          break;
        }
      }
      }
    }
    Font = ((const HTuple&)Fonts)[SubFamily];
    try
    {
      SetFont(WindowHandle, (Font+"-")+Size);
    }
    // catch (Exception)
    catch (HalconCpp::HException &HDevExpDefaultException)
    {
      HDevExpDefaultException.ToHTuple(&Exception);
      //throw (Exception)
    }
  }
  else
  {
    //Set font for UNIX systems
    Size = Size*1.25;
    AllowedFontSizes.Clear();
    AllowedFontSizes[0] = 11;
    AllowedFontSizes[1] = 14;
    AllowedFontSizes[2] = 17;
    AllowedFontSizes[3] = 20;
    AllowedFontSizes[4] = 25;
    AllowedFontSizes[5] = 34;
    if (0 != ((AllowedFontSizes.TupleFind(Size))==-1))
    {
      Distances = (AllowedFontSizes-Size).TupleAbs();
      TupleSortIndex(Distances, &Indices);
      Size = ((const HTuple&)AllowedFontSizes)[HTuple(Indices[0])];
    }
    if (0 != (HTuple(Font==HTuple("mono")).TupleOr(Font==HTuple("Courier"))))
    {
      Font = "courier";
    }
    else if (0 != (Font==HTuple("sans")))
    {
      Font = "helvetica";
    }
    else if (0 != (Font==HTuple("serif")))
    {
      Font = "times";
    }
    if (0 != (Bold==HTuple("true")))
    {
      Bold = "bold";
    }
    else if (0 != (Bold==HTuple("false")))
    {
      Bold = "medium";
    }
    else
    {
      Exception = "Wrong value of control parameter Bold";
      throw HalconCpp::HException(Exception);
    }
    if (0 != (Slant==HTuple("true")))
    {
      if (0 != (Font==HTuple("times")))
      {
        Slant = "i";
      }
      else
      {
        Slant = "o";
      }
    }
    else if (0 != (Slant==HTuple("false")))
    {
      Slant = "r";
    }
    else
    {
      Exception = "Wrong value of control parameter Slant";
      throw HalconCpp::HException(Exception);
    }
    try
    {
      SetFont(WindowHandle, ((((((("-adobe-"+Font)+"-")+Bold)+"-")+Slant)+"-normal-*-")+Size)+"-*-*-*-*-*-*-*");
    }
    // catch (Exception)
    catch (HalconCpp::HException &HDevExpDefaultException)
    {
      HDevExpDefaultException.ToHTuple(&Exception);
      if (0 != (HTuple((OS.TupleSubstr(0,4))==HTuple("Linux")).TupleAnd(Font==HTuple("courier"))))
      {
        QueryFont(WindowHandle, &Fonts);
        FontSelRegexp = (("^-[^-]*-[^-]*[Cc]ourier[^-]*-"+Bold)+"-")+Slant;
        FontsCourier = (Fonts.TupleRegexpSelect(FontSelRegexp)).TupleRegexpMatch(FontSelRegexp);
        if (0 != ((FontsCourier.TupleLength())==0))
        {
          Exception = "Wrong font name";
          //throw (Exception)
        }
        else
        {
          try
          {
            SetFont(WindowHandle, ((HTuple(FontsCourier[0])+"-normal-*-")+Size)+"-*-*-*-*-*-*-*");
          }
          // catch (Exception)
          catch (HalconCpp::HException &HDevExpDefaultException)
          {
            HDevExpDefaultException.ToHTuple(&Exception);
            //throw (Exception)
          }
        }
      }
      //throw (Exception)
    }
  }
  // dev_set_preferences(...); only in hdevelop
  return;
}

// Chapter: Graphics / Output
void disp_title_and_information (HTuple WindowHandle, HTuple Title, HTuple Information)
{

  // Local iconic variables

  // Local control variables
  HTuple  WinRow, WinColumn, WinWidth;
  HTuple  WinHeight, NumTitleLines, Row, Column;
  HTuple  TextWidth, NumInfoLines, Ascent, Descent;
  HTuple  Width, Height;

  //global tuple gInfoDecor
  //global tuple gInfoPos
  //global tuple gTitlePos
  //global tuple gTitleDecor
  //
  GetWindowExtents(WindowHandle, &WinRow, &WinColumn, &WinWidth, &WinHeight);
  Title = ((""+Title)+"").TupleSplit("\n");
  NumTitleLines = Title.TupleLength();
  if (0 != (NumTitleLines>0))
  {
    Row = 12;
    if (0 != (ExpGetGlobalVar_gTitlePos()==HTuple("UpperLeft")))
    {
      Column = 12;
    }
    else if (0 != (ExpGetGlobalVar_gTitlePos()==HTuple("UpperCenter")))
    {
      max_line_width(WindowHandle, Title, &TextWidth);
      Column = (WinWidth/2)-(TextWidth/2);
    }
    else if (0 != (ExpGetGlobalVar_gTitlePos()==HTuple("UpperRight")))
    {
      if (0 != (HTuple(ExpGetGlobalVar_gTitleDecor()[1])==HTuple("true")))
      {
        max_line_width(WindowHandle, Title+"  ", &TextWidth);
      }
      else
      {
        max_line_width(WindowHandle, Title, &TextWidth);
      }
      Column = (WinWidth-TextWidth)-10;
    }
    else
    {
      //Unknown position!
      // stop(); only in hdevelop
    }
    disp_message(WindowHandle, Title, "window", Row, Column, HTuple(ExpGetGlobalVar_gTitleDecor()[0]),
        HTuple(ExpGetGlobalVar_gTitleDecor()[1]));
  }
  Information = ((""+Information)+"").TupleSplit("\n");
  NumInfoLines = Information.TupleLength();
  if (0 != (NumInfoLines>0))
  {
    if (0 != (ExpGetGlobalVar_gInfoPos()==HTuple("UpperLeft")))
    {
      Row = 12;
      Column = 12;
    }
    else if (0 != (ExpGetGlobalVar_gInfoPos()==HTuple("UpperRight")))
    {
      if (0 != (HTuple(ExpGetGlobalVar_gInfoDecor()[1])==HTuple("true")))
      {
        max_line_width(WindowHandle, Information+"  ", &TextWidth);
      }
      else
      {
        max_line_width(WindowHandle, Information, &TextWidth);
      }
      Row = 12;
      Column = (WinWidth-TextWidth)-12;
    }
    else if (0 != (ExpGetGlobalVar_gInfoPos()==HTuple("LowerLeft")))
    {
      GetStringExtents(WindowHandle, Information, &Ascent, &Descent,
          &Width, &Height);
      Row = (WinHeight-(NumInfoLines*Height))-12;
      Column = 12;
    }
    else
    {
      //Unknown position!
      // stop(); only in hdevelop
    }
    disp_message(WindowHandle, Information, "window", Row, Column, HTuple(ExpGetGlobalVar_gInfoDecor()[0]),
        HTuple(ExpGetGlobalVar_gInfoDecor()[1]));
  }
  //
  return;
}

// Chapter: Graphics / Output
// Short Description: Can replace disp_object_model_3d if there is no OpenGL available.
void disp_object_model_no_opengl (HObject *ModelContours, HTuple ObjectModel3DID,
    HTuple GenParamName, HTuple GenParamValue, HTuple WindowHandleBuffer,
    HTuple CamParam, HTuple PosesOut)
{

  // Local iconic variables

  // Local control variables
  HTuple  Idx, CustomParamName, CustomParamValue;
  HTuple  Font, IndicesDispBackGround, Indices, HasPolygons;
  HTuple  HasTri, HasPoints, HasLines, NumPoints;
  HTuple  IsPrimitive, Center, Diameter, OpenGlHiddenSurface;
  HTuple  CenterX, CenterY, CenterZ, PosObjectsZ;
  HTuple  I, Pose, HomMat3DObj, PosObjCenterX;
  HTuple  PosObjCenterY, PosObjCenterZ, PosObjectsX;
  HTuple  PosObjectsY, Color, Indices1, IndicesIntensities;
  HTuple  Indices2, J, Indices3, HomMat3D, SampledObjectModel3D;
  HTuple  X, Y, Z, HomMat3D1, Qx, Qy, Qz;
  HTuple  Row, Column, ObjectModel3DConvexHull, Exception;

  //This procedure allows to use project_object_model_3d to simulate a disp_object_model_3d
  //call for small objects. Large objects are sampled down to display.
  Idx = GenParamName.TupleFind("point_size");
  if (0 != (HTuple(Idx.TupleLength()).TupleAnd(Idx!=-1)))
  {
    CustomParamName = "point_size";
    CustomParamValue = ((const HTuple&)GenParamValue)[Idx];
    if (0 != (CustomParamValue==1))
    {
      CustomParamValue = 0;
    }
  }
  else
  {
    CustomParamName = HTuple();
    CustomParamValue = HTuple();
  }
  GetFont(WindowHandleBuffer, &Font);
  TupleFind(GenParamName, "disp_background", &IndicesDispBackGround);
  if (0 != (IndicesDispBackGround!=-1))
  {
    TupleFind(HTuple(GenParamName[IndicesDispBackGround]), "false", &Indices);
    if (0 != (Indices!=-1))
    {
      ClearWindow(WindowHandleBuffer);
    }
  }
  set_display_font(WindowHandleBuffer, 11, "mono", "false", "false");
  disp_message(WindowHandleBuffer, "OpenGL missing!", "image", 5, HTuple(CamParam[6])-130,
      "red", "false");
  SetFont(WindowHandleBuffer, Font);
  GetObjectModel3dParams(ObjectModel3DID, "has_polygons", &HasPolygons);
  GetObjectModel3dParams(ObjectModel3DID, "has_triangles", &HasTri);
  GetObjectModel3dParams(ObjectModel3DID, "has_points", &HasPoints);
  GetObjectModel3dParams(ObjectModel3DID, "has_lines", &HasLines);
  GetObjectModel3dParams(ObjectModel3DID, "num_points", &NumPoints);
  GetObjectModel3dParams(ObjectModel3DID, "has_primitive_data", &IsPrimitive);
  GetObjectModel3dParams(ObjectModel3DID, "center", &Center);
  GetObjectModel3dParams(ObjectModel3DID, "diameter", &Diameter);
  GetSystem("opengl_hidden_surface_removal_enable", &OpenGlHiddenSurface);
  SetSystem("opengl_hidden_surface_removal_enable", "false");
  //Sort the objects by inverse z
  CenterX = ((const HTuple&)Center)[HTuple::TupleGenSequence(0,(Center.TupleLength())-1,3)];
  CenterY = ((const HTuple&)Center)[HTuple::TupleGenSequence(0,(Center.TupleLength())-1,3)+1];
  CenterZ = ((const HTuple&)Center)[HTuple::TupleGenSequence(0,(Center.TupleLength())-1,3)+2];
  PosObjectsZ = HTuple();
  if (0 != ((PosesOut.TupleLength())>7))
  {
    {
    HTuple end_val40 = (ObjectModel3DID.TupleLength())-1;
    HTuple step_val40 = 1;
    for (I=0; I.Continue(end_val40, step_val40); I += step_val40)
    {
      Pose = PosesOut.TupleSelectRange(I*7,(I*7)+6);
      PoseToHomMat3d(Pose, &HomMat3DObj);
      AffineTransPoint3d(HomMat3DObj, HTuple(CenterX[I]), HTuple(CenterY[I]),
          HTuple(CenterZ[I]), &PosObjCenterX, &PosObjCenterY, &PosObjCenterZ);
      PosObjectsZ = PosObjectsZ.TupleConcat(PosObjCenterZ);
    }
    }
  }
  else
  {
    Pose = PosesOut.TupleSelectRange(0,6);
    PoseToHomMat3d(Pose, &HomMat3DObj);
    AffineTransPoint3d(HomMat3DObj, CenterX, CenterY, CenterZ, &PosObjectsX,
        &PosObjectsY, &PosObjectsZ);
  }
  Idx = (PosObjectsZ.TupleSortIndex()).TupleInverse();
  Color = "white";
  SetColor(WindowHandleBuffer, Color);
  if (0 != ((GenParamName.TupleLength())>0))
  {
    TupleFind(GenParamName, "colored", &Indices1);
    TupleFind(GenParamName, "intensity", &IndicesIntensities);
    TupleFind(GenParamName, "color", &Indices2);
    if (0 != (HTuple(Indices1[0])!=-1))
    {
      if (0 != (HTuple(GenParamValue[HTuple(Indices1[0])])==3))
      {
        Color.Clear();
        Color[0] = "red";
        Color[1] = "green";
        Color[2] = "blue";
      }
      else if (0 != (HTuple(GenParamValue[HTuple(Indices1[0])])==6))
      {
        Color.Clear();
        Color[0] = "red";
        Color[1] = "green";
        Color[2] = "blue";
        Color[3] = "cyan";
        Color[4] = "magenta";
        Color[5] = "yellow";
      }
      else if (0 != (HTuple(GenParamValue[HTuple(Indices1[0])])==12))
      {
        Color.Clear();
        Color[0] = "red";
        Color[1] = "green";
        Color[2] = "blue";
        Color[3] = "cyan";
        Color[4] = "magenta";
        Color[5] = "yellow";
        Color[6] = "coral";
        Color[7] = "slate blue";
        Color[8] = "spring green";
        Color[9] = "orange red";
        Color[10] = "pink";
        Color[11] = "gold";
      }
    }
    else if (0 != (HTuple(Indices2[0])!=-1))
    {
      Color = ((const HTuple&)GenParamValue)[HTuple(Indices2[0])];
    }
    else if (0 != (HTuple(IndicesIntensities[0])!=-1))
    {
    }
  }
  {
  HTuple end_val71 = (ObjectModel3DID.TupleLength())-1;
  HTuple step_val71 = 1;
  for (J=0; J.Continue(end_val71, step_val71); J += step_val71)
  {
    I = ((const HTuple&)Idx)[J];
    if (0 != (HTuple(HTuple(HTuple(HTuple(HasPolygons[I])==HTuple("true")).TupleOr(HTuple(HasTri[I])==HTuple("true"))).TupleOr(HTuple(HasPoints[I])==HTuple("true"))).TupleOr(HTuple(HasLines[I])==HTuple("true"))))
    {
      if (0 != ((GenParamName.TupleLength())>0))
      {
        TupleFind(GenParamName, "color_"+I, &Indices3);
        if (0 != (HTuple(Indices3[0])!=-1))
        {
          SetColor(WindowHandleBuffer, HTuple(GenParamValue[HTuple(Indices3[0])]));
        }
        else
        {
          SetColor(WindowHandleBuffer, HTuple(Color[I%(Color.TupleLength())]));
        }
      }
      if (0 != ((PosesOut.TupleLength())>=((I*7)+6)))
      {
        Pose = PosesOut.TupleSelectRange(I*7,(I*7)+6);
      }
      else
      {
        Pose = PosesOut.TupleSelectRange(0,6);
      }
      if (0 != (HTuple(NumPoints[I])<10000))
      {
        ProjectObjectModel3d(&(*ModelContours), HTuple(ObjectModel3DID[I]),
            CamParam, Pose, CustomParamName, CustomParamValue);
        DispObj((*ModelContours), WindowHandleBuffer);
      }
      else
      {
        PoseToHomMat3d(Pose, &HomMat3D);
        SampleObjectModel3d(HTuple(ObjectModel3DID[I]), "fast", 0.01*HTuple(Diameter[I]),
            HTuple(), HTuple(), &SampledObjectModel3D);
        ProjectObjectModel3d(&(*ModelContours), SampledObjectModel3D, CamParam,
            Pose, "point_size", 1);
        GetObjectModel3dParams(SampledObjectModel3D, "point_coord_x", &X);
        GetObjectModel3dParams(SampledObjectModel3D, "point_coord_y", &Y);
        GetObjectModel3dParams(SampledObjectModel3D, "point_coord_z", &Z);
        PoseToHomMat3d(Pose, &HomMat3D1);
        AffineTransPoint3d(HomMat3D1, X, Y, Z, &Qx, &Qy, &Qz);
        Project3dPoint(Qx, Qy, Qz, CamParam, &Row, &Column);
        DispObj((*ModelContours), WindowHandleBuffer);
        ClearObjectModel3d(SampledObjectModel3D);
      }
    }
    else
    {
      if (0 != ((GenParamName.TupleLength())>0))
      {
        TupleFind(GenParamName, "color_"+I, &Indices3);
        if (0 != (HTuple(Indices3[0])!=-1))
        {
          SetColor(WindowHandleBuffer, HTuple(GenParamValue[HTuple(Indices3[0])]));
        }
        else
        {
          SetColor(WindowHandleBuffer, HTuple(Color[I%(Color.TupleLength())]));
        }
      }
      if (0 != ((PosesOut.TupleLength())>=((I*7)+6)))
      {
        Pose = PosesOut.TupleSelectRange(I*7,(I*7)+6);
      }
      else
      {
        Pose = PosesOut.TupleSelectRange(0,6);
      }
      if (0 != (HTuple(IsPrimitive[I])==HTuple("true")))
      {
        try
        {
          ConvexHullObjectModel3d(HTuple(ObjectModel3DID[I]), &ObjectModel3DConvexHull);
          if (0 != (HTuple(NumPoints[I])<10000))
          {
            ProjectObjectModel3d(&(*ModelContours), ObjectModel3DConvexHull,
                CamParam, Pose, CustomParamName, CustomParamValue);
            DispObj((*ModelContours), WindowHandleBuffer);
          }
          else
          {
            PoseToHomMat3d(Pose, &HomMat3D);
            SampleObjectModel3d(ObjectModel3DConvexHull, "fast", 0.01*HTuple(Diameter[I]),
                HTuple(), HTuple(), &SampledObjectModel3D);
            ProjectObjectModel3d(&(*ModelContours), SampledObjectModel3D, CamParam,
                Pose, "point_size", 1);
            DispObj((*ModelContours), WindowHandleBuffer);
            ClearObjectModel3d(SampledObjectModel3D);
          }
          ClearObjectModel3d(ObjectModel3DConvexHull);
        }
        // catch (Exception)
        catch (HalconCpp::HException &HDevExpDefaultException)
        {
          HDevExpDefaultException.ToHTuple(&Exception);
        }
      }
    }
  }
  }
  SetSystem("opengl_hidden_surface_removal_enable", OpenGlHiddenSurface);
  return;
}

// Chapter: Graphics / Output
// Short Description: Interactively display 3D object models
void visualize_object_model_3d (HTuple WindowHandle, HTuple ObjectModel3D,
    HTuple CamParam, HTuple PoseIn, HTuple GenParamName, HTuple GenParamValue,
    HTuple Title, HTuple Label, HTuple Information, HTuple *PoseOut)
{

  // Local iconic variables
  HObject  Image, ImageDump;

  // Local control variables
  HTuple  ExpTmpLocalVar_gDispObjOffset, ExpTmpLocalVar_gLabelsDecor;
  HTuple  ExpTmpLocalVar_gInfoDecor, ExpTmpLocalVar_gInfoPos;
  HTuple  ExpTmpLocalVar_gTitlePos, ExpTmpLocalVar_gTitleDecor;
  HTuple  ExpTmpLocalVar_gTerminationButtonLabel, ExpTmpLocalVar_gAlphaDeselected;
  HTuple  ExpTmpLocalVar_gIsSinglePose, ExpTmpLocalVar_gUsesOpenGL;
  HTuple  TrackballSize, VirtualTrackball, MouseMapping;
  HTuple  WaitForButtonRelease, MaxNumModels, WindowCenteredRotation;
  HTuple  NumModels, SelectedObject, ClipRegion;
  HTuple  CPLength, RowNotUsed, ColumnNotUsed, Width;
  HTuple  Height, WPRow1, WPColumn1, WPRow2, WPColumn2;
  HTuple  CamWidth, CamHeight, Scale, Indices;
  HTuple  DispBackground, Mask, Center, PoseEstimated;
  HTuple  Poses, HomMat3Ds, Sequence, WindowHandleBuffer;
  HTuple  Font, Exception, OpenGLInfo, DummyObjectModel3D;
  HTuple  Scene3DTest, CameraIndexTest, PoseTest;
  HTuple  InstanceIndexTest, MinImageSize, TrackballRadiusPixel;
  HTuple  Ascent, Descent, TextWidth, TextHeight;
  HTuple  NumChannels, ColorImage, Scene3D, CameraIndex;
  HTuple  AllInstances, SetLight, LightParam, LightPosition;
  HTuple  LightKind, LightIndex, PersistenceParamName;
  HTuple  PersistenceParamValue, ValueListSS3P, ValueListSS3IP;
  HTuple  AlphaOrig, UsedParamMask, I, ParamName;
  HTuple  ParamValue, UseParam, ParamNameTrunk, Instance;
  HTuple  GenParamNameRemaining, GenParamValueRemaining;
  HTuple  HomMat3D, Qx, Qy, Qz, TBCenter, TBSize;
  HTuple  ButtonHold, VisualizeTB, MaxIndex, TrackballCenterRow;
  HTuple  TrackballCenterCol, GraphEvent, Exit, GraphButtonRow;
  HTuple  GraphButtonColumn, GraphButton, ButtonReleased;

  //The procedure visualize_object_model_3d can be used to display
  //one or more 3d object models and to interactively modify
  //the object poses by using the mouse.
  //
  //The pose can be modified by moving the mouse while
  //pressing a mouse button. The default settings are:
  //
  // Left mouse button:   Modify the object orientation
  // Shift+ left mouse button  or
  // center mouse button: Modify the object distance
  // Right mouse button:  Modify the object position
  // Ctrl + Left mouse button: (De-)select object(s)
  // Alt + Mouse button: Low mouse sensitiviy
  // (Default may be changed with the variable MouseMapping below)
  //
  //In GenParamName and GenParamValue all generic Paramters
  //of disp_object_model_3d are supported.
  //
  //**********************************************************
  //Define global variables
  //**********************************************************
  //
  //global def tuple gDispObjOffset
  //global def tuple gLabelsDecor
  //global def tuple gInfoDecor
  //global def tuple gInfoPos
  //global def tuple gTitlePos
  //global def tuple gTitleDecor
  //global def tuple gTerminationButtonLabel
  //global def tuple gAlphaDeselected
  //global def tuple gIsSinglePose
  //global def tuple gUsesOpenGL
  //
  //**********************************************************
  //First some user defines that may be adapted if desired
  //**********************************************************
  //
  //TrackballSize defines the diameter of the trackball in
  //the image with respect to the smaller image dimension.
  TrackballSize = 0.8;
  //
  //VirtualTrackball defines the type of virtual trackball that
  //shall be used ('shoemake' or 'bell').
  VirtualTrackball = "shoemake";
  //VirtualTrackball := 'bell'
  //
  //Functionality of mouse buttons
  //    1: Left Button
  //    2: Middle Button
  //    4: Right Button
  //    5: Left+Right Mousebutton
  //  8+x: Shift + Mousebutton
  // 16+x: Ctrl + Mousebutton
  // 48+x: Ctrl + Alt + Mousebutton
  //in the order [Translate, Rotate, Scale, ScaleAlternative1, ScaleAlternative2, SelectObjects, ToggleSelectionMode]
  MouseMapping.Clear();
  MouseMapping[0] = 17;
  MouseMapping[1] = 1;
  MouseMapping[2] = 2;
  MouseMapping[3] = 5;
  MouseMapping[4] = 9;
  MouseMapping[5] = 4;
  MouseMapping[6] = 49;
  //
  //The labels of the objects appear next to their projected
  //center. With gDispObjOffset a fixed offset is added
  //                  R,  C
  ExpTmpLocalVar_gDispObjOffset.Clear();
  ExpTmpLocalVar_gDispObjOffset[0] = -30;
  ExpTmpLocalVar_gDispObjOffset[1] = 0;
  ExpSetGlobalVar_gDispObjOffset(ExpTmpLocalVar_gDispObjOffset);
  //
  //Customize the decoration of the different text elements
  //              Color,   Box
  ExpTmpLocalVar_gInfoDecor.Clear();
  ExpTmpLocalVar_gInfoDecor[0] = "white";
  ExpTmpLocalVar_gInfoDecor[1] = "false";
  ExpSetGlobalVar_gInfoDecor(ExpTmpLocalVar_gInfoDecor);
  ExpTmpLocalVar_gLabelsDecor.Clear();
  ExpTmpLocalVar_gLabelsDecor[0] = "white";
  ExpTmpLocalVar_gLabelsDecor[1] = "false";
  ExpSetGlobalVar_gLabelsDecor(ExpTmpLocalVar_gLabelsDecor);
  ExpTmpLocalVar_gTitleDecor.Clear();
  ExpTmpLocalVar_gTitleDecor[0] = "black";
  ExpTmpLocalVar_gTitleDecor[1] = "true";
  ExpSetGlobalVar_gTitleDecor(ExpTmpLocalVar_gTitleDecor);
  //
  //Customize the position of some text elements
  //  gInfoPos has one of the values
  //  {'UpperLeft', 'LowerLeft', 'UpperRight'}
  ExpTmpLocalVar_gInfoPos = "LowerLeft";
  ExpSetGlobalVar_gInfoPos(ExpTmpLocalVar_gInfoPos);
  //  gTitlePos has one of the values
  //  {'UpperLeft', 'UpperCenter', 'UpperRight'}
  ExpTmpLocalVar_gTitlePos = "UpperLeft";
  ExpSetGlobalVar_gTitlePos(ExpTmpLocalVar_gTitlePos);
  //Alpha value (=1-transparency) that is used for visualizing
  //the objects that are not selected
  ExpTmpLocalVar_gAlphaDeselected = 0.3;
  ExpSetGlobalVar_gAlphaDeselected(ExpTmpLocalVar_gAlphaDeselected);
  //Customize the label of the continue button
  ExpTmpLocalVar_gTerminationButtonLabel = " Continue ";
  ExpSetGlobalVar_gTerminationButtonLabel(ExpTmpLocalVar_gTerminationButtonLabel);
  //Define if the continue button responds to a single click event or
  //if it responds only if the mouse button is released while being placed
  //over the continue button.
  //'true':  Wait until the continue button has been released.
  //         This should be used to avoid unwanted continuations of
  //         subsequent calls of visualize_object_model_3d, which can
  //         otherwise occur if the mouse button remains pressed while the
  //         next visualization is active.
  //'false': Continue the execution already if the continue button is
  //         pressed. This option allows a fast forwarding through
  //         subsequent calls of visualize_object_model_3d.
  WaitForButtonRelease = "true";
  //Number of 3D Object models that can be handled individually
  //if there are more models passed then this number, some calculations
  //are performed differently. And the individual handling of models is not
  //supported anymore
  MaxNumModels = 5;
  //Defines the default for the initial state of the rotation center:
  //(1) The rotation center is fixed in the center of the image and lies
  //    on the surface of the object.
  //(2) The rotation center lies in the center of the object.
  WindowCenteredRotation = 2;
  //
  //**********************************************************
  //
  //Initialize some values
  NumModels = ObjectModel3D.TupleLength();
  SelectedObject = HTuple(NumModels,1);
  //
  //Apply some system settings
  // dev_set_preferences(...); only in hdevelop
  // dev_get_preferences(...); only in hdevelop
  // dev_set_preferences(...); only in hdevelop
  // dev_get_preferences(...); only in hdevelop
  // dev_set_preferences(...); only in hdevelop
  GetSystem("clip_region", &ClipRegion);
  SetSystem("clip_region", "false");
  dev_update_off();
  //
  //Refactor camera parameters to fit to window size
  //
  CPLength = CamParam.TupleLength();
  GetWindowExtents(WindowHandle, &RowNotUsed, &ColumnNotUsed, &Width,
      &Height);
  GetPart(WindowHandle, &WPRow1, &WPColumn1, &WPRow2, &WPColumn2);
  SetPart(WindowHandle, 0, 0, Height-1, Width-1);
  if (0 != (CPLength==0))
  {
    CamParam.Clear();
    CamParam[0] = 0.06;
    CamParam[1] = 0;
    CamParam[2] = 8.5e-6;
    CamParam[3] = 8.5e-6;
    CamParam.Append(Width/2);
    CamParam.Append(Height/2);
    CamParam.Append(Width);
    CamParam.Append(Height);
    CPLength = CamParam.TupleLength();
  }
  else
  {
    CamWidth = HTuple(CamParam[CPLength-2]).TupleReal();
    CamHeight = HTuple(CamParam[CPLength-1]).TupleReal();
    Scale = ((Width/CamWidth).TupleConcat(Height/CamHeight)).TupleMin();
    CamParam[CPLength-6] = HTuple(CamParam[CPLength-6])/Scale;
    CamParam[CPLength-5] = HTuple(CamParam[CPLength-5])/Scale;
    CamParam[CPLength-4] = HTuple(CamParam[CPLength-4])*Scale;
    CamParam[CPLength-3] = HTuple(CamParam[CPLength-3])*Scale;
    CamParam[CPLength-2] = (HTuple(CamParam[CPLength-2])*Scale).TupleInt();
    CamParam[CPLength-1] = (HTuple(CamParam[CPLength-1])*Scale).TupleInt();
  }
  //
  //Check the generic parameters for window_centered_rotation
  //(Note that the default is set above to WindowCenteredRotation := 2)
  Indices = GenParamName.TupleFind("inspection_mode");
  if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple())))
  {
    if (0 != (HTuple(GenParamValue[HTuple(Indices[0])])==HTuple("surface")))
    {
      WindowCenteredRotation = 1;
    }
    else if (0 != (HTuple(GenParamValue[HTuple(Indices[0])])==HTuple("standard")))
    {
      WindowCenteredRotation = 2;
    }
    else
    {
      //Wrong parameter value, use default value
    }
    GenParamName = GenParamName.TupleRemove(Indices);
    GenParamValue = GenParamValue.TupleRemove(Indices);
  }
  //
  //Check the generic parameters for disp_background
  //(The former parameter name 'use_background' is still supported
  // for compatibility reasons)
  DispBackground = "false";
  if (0 != ((GenParamName.TupleLength())>0))
  {
    Mask = (GenParamName.TupleEqualElem("disp_background")).TupleOr(GenParamName.TupleEqualElem("use_background"));
    Indices = Mask.TupleFind(1);
  }
  else
  {
    Indices = -1;
  }
  if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple())))
  {
    DispBackground = ((const HTuple&)GenParamValue)[HTuple(Indices[0])];
    if (0 != (HTuple(DispBackground!=HTuple("true")).TupleAnd(DispBackground!=HTuple("false"))))
    {
      //Wrong parameter value: Only 'true' and 'false' are allowed
      throw HalconCpp::HException("Wrong value for parameter 'disp_background' (must be either 'true' or 'false')");
    }
    //Note the the background is handled explicitely in this procedure
    //and therefore, the parameter is removed from the list of
    //parameters and disp_background is always set to true (see below)
    GenParamName = GenParamName.TupleRemove(Indices);
    GenParamValue = GenParamValue.TupleRemove(Indices);
  }
  //
  //Read and check the parameter Label for each object
  if (0 != ((Label.TupleLength())==0))
  {
    Label = 0;
  }
  else if (0 != ((Label.TupleLength())==1))
  {
    Label = HTuple(NumModels,Label);
  }
  else
  {
    if (0 != ((Label.TupleLength())!=NumModels))
    {
      //Error: Number of elements in Label does not match the
      //number of object models
      // stop(); only in hdevelop
    }
  }
  //
  //Read and check the parameter PoseIn for each object
  get_object_models_center(ObjectModel3D, &Center);
  if (0 != ((PoseIn.TupleLength())==0))
  {
    //If no pose was specified by the caller, automatically calculate
    //a pose that is appropriate for the visualization.
    //Set the initial model reference pose. The orientation is parallel
    //to the object coordinate system, the position is at the center
    //of gravity of all models.
    CreatePose(-HTuple(Center[0]), -HTuple(Center[1]), -HTuple(Center[2]),
        0, 0, 0, "Rp+T", "gba", "point", &PoseIn);
    determine_optimum_pose_distance(ObjectModel3D, CamParam, 0.9, PoseIn,
        &PoseEstimated);
    Poses = HTuple();
    HomMat3Ds = HTuple();
    Sequence = HTuple::TupleGenSequence(0,(NumModels*7)-1,1);
    Poses = ((const HTuple&)PoseEstimated)[Sequence%7];
    ExpTmpLocalVar_gIsSinglePose = 1;
    ExpSetGlobalVar_gIsSinglePose(ExpTmpLocalVar_gIsSinglePose);
  }
  else if (0 != ((PoseIn.TupleLength())==7))
  {
    Poses = HTuple();
    HomMat3Ds = HTuple();
    Sequence = HTuple::TupleGenSequence(0,(NumModels*7)-1,1);
    Poses = ((const HTuple&)PoseIn)[Sequence%7];
    ExpTmpLocalVar_gIsSinglePose = 1;
    ExpSetGlobalVar_gIsSinglePose(ExpTmpLocalVar_gIsSinglePose);
  }
  else
  {
    if (0 != ((PoseIn.TupleLength())!=((ObjectModel3D.TupleLength())*7)))
    {
      //Error: Wrong number of values of input control parameter 'PoseIn'
      // stop(); only in hdevelop
    }
    else
    {
      Poses = PoseIn;
    }
    ExpTmpLocalVar_gIsSinglePose = 0;
    ExpSetGlobalVar_gIsSinglePose(ExpTmpLocalVar_gIsSinglePose);
  }
  //
  //Open (invisible) buffer window to avoid flickering
  OpenWindow(0, 0, Width, Height, 0, "buffer", "", &WindowHandleBuffer);
  SetPart(WindowHandleBuffer, 0, 0, Height-1, Width-1);
  GetFont(WindowHandle, &Font);
  try
  {
    SetFont(WindowHandleBuffer, Font);
  }
  // catch (Exception)
  catch (HalconCpp::HException &HDevExpDefaultException)
  {
    HDevExpDefaultException.ToHTuple(&Exception);
  }
  //
  // Is OpenGL available and should it be used?
  ExpTmpLocalVar_gUsesOpenGL = "true";
  ExpSetGlobalVar_gUsesOpenGL(ExpTmpLocalVar_gUsesOpenGL);
  Indices = GenParamName.TupleFind("opengl");
  if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple())))
  {
    ExpTmpLocalVar_gUsesOpenGL = ((const HTuple&)GenParamValue)[HTuple(Indices[0])];
    ExpSetGlobalVar_gUsesOpenGL(ExpTmpLocalVar_gUsesOpenGL);
    GenParamName = GenParamName.TupleRemove(Indices);
    GenParamValue = GenParamValue.TupleRemove(Indices);
    if (0 != (HTuple(ExpGetGlobalVar_gUsesOpenGL()!=HTuple("true")).TupleAnd(ExpGetGlobalVar_gUsesOpenGL()!=HTuple("false"))))
    {
      //Wrong parameter value: Only 'true' and 'false' are allowed
      throw HalconCpp::HException("Wrong value for parameter 'opengl' (must be either 'true' or 'false')");
    }
  }
  if (0 != (ExpGetGlobalVar_gUsesOpenGL()==HTuple("true")))
  {
    GetSystem("opengl_info", &OpenGLInfo);
    if (0 != (OpenGLInfo==HTuple("No OpenGL support included.")))
    {
      ExpTmpLocalVar_gUsesOpenGL = "false";
      ExpSetGlobalVar_gUsesOpenGL(ExpTmpLocalVar_gUsesOpenGL);
    }
    else
    {
      GenObjectModel3dFromPoints(0, 0, 0, &DummyObjectModel3D);
      CreateScene3d(&Scene3DTest);
      AddScene3dCamera(Scene3DTest, CamParam, &CameraIndexTest);
      determine_optimum_pose_distance(DummyObjectModel3D, CamParam, 0.9, ((((((HTuple(0).Append(0)).Append(0)).Append(0)).Append(0)).Append(0)).Append(0)),
          &PoseTest);
      AddScene3dInstance(Scene3DTest, DummyObjectModel3D, PoseTest, &InstanceIndexTest);
      try
      {
        DisplayScene3d(WindowHandleBuffer, Scene3DTest, InstanceIndexTest);
      }
      // catch (Exception)
      catch (HalconCpp::HException &HDevExpDefaultException)
      {
        HDevExpDefaultException.ToHTuple(&Exception);
        ExpTmpLocalVar_gUsesOpenGL = "false";
        ExpSetGlobalVar_gUsesOpenGL(ExpTmpLocalVar_gUsesOpenGL);
      }
      ClearScene3d(Scene3DTest);
      ClearObjectModel3d(DummyObjectModel3D);
    }
  }
  //
  //Compute the trackball
  MinImageSize = (Width.TupleConcat(Height)).TupleMin();
  TrackballRadiusPixel = (TrackballSize*MinImageSize)/2.0;
  //
  //Measure the text extents for the continue button in the
  //graphics window
  GetStringExtents(WindowHandleBuffer, ExpGetGlobalVar_gTerminationButtonLabel()+"  ",
      &Ascent, &Descent, &TextWidth, &TextHeight);
  //
  //Store background image
  if (0 != (DispBackground==HTuple("false")))
  {
    ClearWindow(WindowHandle);
  }
  DumpWindowImage(&Image, WindowHandle);
  //Special treatment for color background images necessary
  CountChannels(Image, &NumChannels);
  ColorImage = NumChannels==3;
  //
  CreateScene3d(&Scene3D);
  AddScene3dCamera(Scene3D, CamParam, &CameraIndex);
  AddScene3dInstance(Scene3D, ObjectModel3D, Poses, &AllInstances);
  //Always set 'disp_background' to true,  because it is handled explicitely
  //in this procedure (see above)
  SetScene3dParam(Scene3D, "disp_background", "true");
  //Check if we have to set light specific parameters
  SetLight = GenParamName.TupleRegexpTest("light_");
  if (0 != SetLight)
  {
    //set position of light source
    Indices = GenParamName.TupleFind("light_position");
    if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple())))
    {
      //If multiple light positions are given, use the last one
      LightParam = (HTuple(GenParamValue[HTuple(Indices[(Indices.TupleLength())-1])]).TupleSplit(", ")).TupleNumber();
      if (0 != ((LightParam.TupleLength())!=4))
      {
        throw HalconCpp::HException("light_position must be given as a string that contains four space separated floating point numbers");
      }
      LightPosition = LightParam.TupleSelectRange(0,2);
      LightKind = "point_light";
      if (0 != (HTuple(LightParam[3])==0))
      {
        LightKind = "directional_light";
      }
      //Currently, only one light source is supported
      RemoveScene3dLight(Scene3D, 0);
      AddScene3dLight(Scene3D, LightPosition, LightKind, &LightIndex);
      TupleRemove(GenParamName, Indices, &GenParamName);
      TupleRemove(GenParamValue, Indices, &GenParamValue);
    }
    //set ambient part of light source
    Indices = GenParamName.TupleFind("light_ambient");
    if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple())))
    {
      //If the ambient part is set multiple times, use the last setting
      LightParam = (HTuple(GenParamValue[HTuple(Indices[(Indices.TupleLength())-1])]).TupleSplit(", ")).TupleNumber();
      if (0 != ((LightParam.TupleLength())<3))
      {
        throw HalconCpp::HException("light_ambient must be given as a string that contains three space separated floating point numbers");
      }
      SetScene3dLightParam(Scene3D, 0, "ambient", LightParam.TupleSelectRange(0,2));
      TupleRemove(GenParamName, Indices, &GenParamName);
      TupleRemove(GenParamValue, Indices, &GenParamValue);
    }
    //set diffuse part of light source
    Indices = GenParamName.TupleFind("light_diffuse");
    if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple())))
    {
      //If the diffuse part is set multiple times, use the last setting
      LightParam = (HTuple(GenParamValue[HTuple(Indices[(Indices.TupleLength())-1])]).TupleSplit(", ")).TupleNumber();
      if (0 != ((LightParam.TupleLength())<3))
      {
        throw HalconCpp::HException("light_diffuse must be given as a string that contains three space separated floating point numbers");
      }
      SetScene3dLightParam(Scene3D, 0, "diffuse", LightParam.TupleSelectRange(0,2));
      TupleRemove(GenParamName, Indices, &GenParamName);
      TupleRemove(GenParamValue, Indices, &GenParamValue);
    }
  }
  //
  //Handle persistence parameters separately because persistence will
  //only be activated immediately before leaving the visualization
  //procedure
  PersistenceParamName = HTuple();
  PersistenceParamValue = HTuple();
  //set position of light source
  Indices = GenParamName.TupleFind("object_index_persistence");
  if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple())))
  {
    if (0 != (HTuple(GenParamValue[HTuple(Indices[(Indices.TupleLength())-1])])==HTuple("true")))
    {
      PersistenceParamName = PersistenceParamName.TupleConcat("object_index_persistence");
      PersistenceParamValue = PersistenceParamValue.TupleConcat("true");
    }
    else if (0 != (HTuple(GenParamValue[HTuple(Indices[(Indices.TupleLength())-1])])==HTuple("false")))
    {
    }
    else
    {
      throw HalconCpp::HException("Wrong value for parameter 'object_index_persistence' (must be either 'true' or 'false')");
    }
    TupleRemove(GenParamName, Indices, &GenParamName);
    TupleRemove(GenParamValue, Indices, &GenParamValue);
  }
  Indices = GenParamName.TupleFind("depth_persistence");
  if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple())))
  {
    if (0 != (HTuple(GenParamValue[HTuple(Indices[(Indices.TupleLength())-1])])==HTuple("true")))
    {
      PersistenceParamName = PersistenceParamName.TupleConcat("depth_persistence");
      PersistenceParamValue = PersistenceParamValue.TupleConcat("true");
    }
    else if (0 != (HTuple(GenParamValue[HTuple(Indices[(Indices.TupleLength())-1])])==HTuple("false")))
    {
    }
    else
    {
      throw HalconCpp::HException("Wrong value for parameter 'depth_persistence' (must be either 'true' or 'false')");
    }
    TupleRemove(GenParamName, Indices, &GenParamName);
    TupleRemove(GenParamValue, Indices, &GenParamValue);
  }
  //
  //Parse the generic parameters
  //- First, all parameters that are understood by set_scene_3d_instance_param
  GetParamInfo("set_scene_3d_param", "GenParamName", "value_list", &ValueListSS3P);
  GetParamInfo("set_scene_3d_instance_param", "GenParamName", "value_list", &ValueListSS3IP);
  AlphaOrig = HTuple(NumModels,1);
  UsedParamMask = HTuple(GenParamName.TupleLength(),0);
  {
  HTuple end_val371 = (GenParamName.TupleLength())-1;
  HTuple step_val371 = 1;
  for (I=0; I.Continue(end_val371, step_val371); I += step_val371)
  {
    ParamName = ((const HTuple&)GenParamName)[I];
    ParamValue = ((const HTuple&)GenParamValue)[I];
    //Check if this parameter is understood by set_scene_3d_param
    UseParam = ValueListSS3P.TupleRegexpTest(("^"+ParamName)+"$");
    if (0 != UseParam)
    {
      try
      {
        SetScene3dParam(Scene3D, ParamName, ParamValue);
      }
      // catch (Exception)
      catch (HalconCpp::HException &HDevExpDefaultException)
      {
        HDevExpDefaultException.ToHTuple(&Exception);
        if (0 != (HTuple(HTuple(Exception[0])==1204).TupleOr(HTuple(Exception[0])==1304)))
        {
          throw HalconCpp::HException((("Wrong type or value for parameter "+ParamName)+": ")+ParamValue);
        }
        else
        {
          throw HalconCpp::HException(Exception);
        }
      }
      UsedParamMask[I] = 1;
      if (0 != (ParamName==HTuple("alpha")))
      {
        AlphaOrig = HTuple(NumModels,ParamValue);
      }
      continue;
    }
    //Check if it is a parameter that is valid for only one instance
    //and therefore can be set only with set_scene_3d_instance_param
    ParamNameTrunk = ParamName.TupleRegexpReplace("_\\d+$","");
    UseParam = ValueListSS3IP.TupleRegexpTest(("^"+ParamNameTrunk)+"$");
    if (0 != UseParam)
    {
      Instance = (ParamName.TupleRegexpReplace(("^"+ParamNameTrunk)+"_(\\d+)$","$1")).TupleNumber();
      if (0 != (HTuple(Instance<0).TupleOr(Instance>(NumModels-1))))
      {
        throw HalconCpp::HException(("Parameter "+ParamName)+" refers to a non existing 3D object model");
      }
      try
      {
        SetScene3dInstanceParam(Scene3D, Instance, ParamNameTrunk, ParamValue);
      }
      // catch (Exception)
      catch (HalconCpp::HException &HDevExpDefaultException)
      {
        HDevExpDefaultException.ToHTuple(&Exception);
        if (0 != (HTuple(HTuple(Exception[0])==1204).TupleOr(HTuple(Exception[0])==1304)))
        {
          throw HalconCpp::HException((("Wrong type or value for parameter "+ParamName)+": ")+ParamValue);
        }
        else
        {
          throw HalconCpp::HException(Exception);
        }
      }
      UsedParamMask[I] = 1;
      if (0 != (ParamNameTrunk==HTuple("alpha")))
      {
        AlphaOrig[Instance] = ParamValue;
      }
      continue;
    }
  }
  }
  //
  //Check if there are remaining parameters
  if (0 != ((GenParamName.TupleLength())>0))
  {
    GenParamNameRemaining = GenParamName.TupleSelectMask(UsedParamMask.TupleNot());
    GenParamValueRemaining = GenParamValue.TupleSelectMask(UsedParamMask.TupleNot());
    if (0 != (GenParamNameRemaining!=HTuple()))
    {
      throw HalconCpp::HException("Parameters that cannot be handled: "+((((GenParamNameRemaining+" := ")+GenParamValueRemaining)+", ").TupleSum()));
    }
  }
  //
  //Start the visualization loop
  PoseToHomMat3d(Poses.TupleSelectRange(0,6), &HomMat3D);
  AffineTransPoint3d(HomMat3D, HTuple(Center[0]), HTuple(Center[1]), HTuple(Center[2]),
      &Qx, &Qy, &Qz);
  TBCenter.Clear();
  TBCenter.Append(Qx);
  TBCenter.Append(Qy);
  TBCenter.Append(Qz);
  TBSize = (0.5+((0.5*(SelectedObject.TupleSum()))/NumModels))*TrackballRadiusPixel;
  ButtonHold = 0;
  while (0 != 1)
  {
    VisualizeTB = (SelectedObject.TupleMax())!=0;
    MaxIndex = ((HTuple(ObjectModel3D.TupleLength()).TupleConcat(MaxNumModels)).TupleMin())-1;
    //Set trackball fixed in the center of the window
    TrackballCenterRow = Height/2;
    TrackballCenterCol = Width/2;
    if (0 != (WindowCenteredRotation==1))
    {
      try
      {
        get_trackball_center_fixed(SelectedObject.TupleSelectRange(0,MaxIndex),
            TrackballCenterRow, TrackballCenterCol, TrackballRadiusPixel,
            Scene3D, ObjectModel3D.TupleSelectRange(0,MaxIndex), Poses.TupleSelectRange(0,((MaxIndex+1)*7)-1),
            WindowHandleBuffer, CamParam, GenParamName, GenParamValue,
            &TBCenter, &TBSize);
      }
      // catch (Exception)
      catch (HalconCpp::HException &HDevExpDefaultException)
      {
        HDevExpDefaultException.ToHTuple(&Exception);
        disp_message(WindowHandle, "Surface inspection mode is not available.",
            "image", 5, 20, "red", "true");
        WindowCenteredRotation = 2;
        get_trackball_center(SelectedObject.TupleSelectRange(0,MaxIndex), TrackballRadiusPixel,
            ObjectModel3D.TupleSelectRange(0,MaxIndex), Poses.TupleSelectRange(0,((MaxIndex+1)*7)-1),
            &TBCenter, &TBSize);
        WaitSeconds(1);
      }
    }
    else
    {
      get_trackball_center(SelectedObject.TupleSelectRange(0,MaxIndex), TrackballRadiusPixel,
          ObjectModel3D.TupleSelectRange(0,MaxIndex), Poses.TupleSelectRange(0,((MaxIndex+1)*7)-1),
          &TBCenter, &TBSize);
    }
    dump_image_output(Image, WindowHandleBuffer, Scene3D, AlphaOrig,
        ObjectModel3D, GenParamName, GenParamValue, CamParam, Poses,
        ColorImage, Title, Information, Label, VisualizeTB, "true",
        TrackballCenterRow, TrackballCenterCol, TBSize, SelectedObject,
        WindowCenteredRotation, TBCenter);
    DumpWindowImage(&ImageDump, WindowHandleBuffer);
    HDevWindowStack::SetActive(WindowHandle);
    if (HDevWindowStack::IsOpen())
      DispObj(ImageDump, HDevWindowStack::GetActive());
    //
    //Check for mouse events
    GraphEvent = 0;
    Exit = 0;
    while (0 != 1)
    {
      //
      //Check graphic event
      try
      {
        GetMpositionSubPix(WindowHandle, &GraphButtonRow, &GraphButtonColumn,
            &GraphButton);
        if (0 != (GraphButton!=0))
        {
          if (0 != (HTuple(HTuple(HTuple(GraphButtonRow>((Height-TextHeight)-13)).TupleAnd(GraphButtonRow<Height)).TupleAnd(GraphButtonColumn>((Width-TextWidth)-13))).TupleAnd(GraphButtonColumn<Width)))
          {
            //Wait until the continue button has been released
            if (0 != (WaitForButtonRelease==HTuple("true")))
            {
              while (0 != 1)
              {
                GetMpositionSubPix(WindowHandle, &GraphButtonRow, &GraphButtonColumn,
                    &GraphButton);
                if (0 != (HTuple(GraphButton==0).TupleOr(GraphButton==HTuple())))
                {
                  if (0 != (HTuple(HTuple(HTuple(GraphButtonRow>((Height-TextHeight)-13)).TupleAnd(GraphButtonRow<Height)).TupleAnd(GraphButtonColumn>((Width-TextWidth)-13))).TupleAnd(GraphButtonColumn<Width)))
                  {
                    ButtonReleased = 1;
                  }
                  else
                  {
                    ButtonReleased = 0;
                  }
                  //
                  break;
                }
                //Keep waiting until mouse button is released or moved out of the window
              }
            }
            else
            {
              ButtonReleased = 1;
            }
            //Exit the visualization loop
            if (0 != ButtonReleased)
            {
              Exit = 1;
              break;
            }
          }
          GraphEvent = 1;
          break;
        }
        else
        {
          ButtonHold = 0;
        }
      }
      // catch (Exception)
      catch (HalconCpp::HException &HDevExpDefaultException)
      {
        HDevExpDefaultException.ToHTuple(&Exception);
        //Keep waiting
      }
    }
    if (0 != GraphEvent)
    {
      analyze_graph_event(Image, MouseMapping, GraphButton, GraphButtonRow,
          GraphButtonColumn, WindowHandle, WindowHandleBuffer, VirtualTrackball,
          TrackballSize, SelectedObject, Scene3D, AlphaOrig, ObjectModel3D,
          CamParam, Label, Title, Information, GenParamName, GenParamValue,
          Poses, ButtonHold, TBCenter, TBSize, WindowCenteredRotation,
          MaxNumModels, &Poses, &SelectedObject, &ButtonHold, &WindowCenteredRotation);
    }
    if (0 != Exit)
    {
      break;
    }
  }
  //
  //Display final state with persistence, if requested
  //Note that disp_object_model_3d must be used instead of the 3D scene
  if (0 != ((PersistenceParamName.TupleLength())>0))
  {
    try
    {
      DispObjectModel3d(WindowHandle, ObjectModel3D, CamParam, Poses,
          (HTuple("disp_background").Append("alpha")).TupleConcat(PersistenceParamName),
          (HTuple("true").Append(0.0)).TupleConcat(PersistenceParamValue));
    }
    // catch (Exception)
    catch (HalconCpp::HException &HDevExpDefaultException)
    {
      HDevExpDefaultException.ToHTuple(&Exception);
      // stop(); only in hdevelop
    }
  }
  //
  //Compute the output pose
  if (0 != ExpGetGlobalVar_gIsSinglePose())
  {
    (*PoseOut) = Poses.TupleSelectRange(0,6);
  }
  else
  {
    (*PoseOut) = Poses;
  }
  //
  //Clean up
  SetSystem("clip_region", ClipRegion);
  // dev_set_preferences(...); only in hdevelop
  // dev_set_preferences(...); only in hdevelop
  // dev_set_preferences(...); only in hdevelop
  dump_image_output(Image, WindowHandleBuffer, Scene3D, AlphaOrig, ObjectModel3D,
      GenParamName, GenParamValue, CamParam, Poses, ColorImage, Title,
      HTuple(), Label, 0, "false", TrackballCenterRow, TrackballCenterCol,
      TBSize, SelectedObject, WindowCenteredRotation, TBCenter);
  DumpWindowImage(&ImageDump, WindowHandleBuffer);
  HDevWindowStack::SetActive(WindowHandle);
  if (HDevWindowStack::IsOpen())
    DispObj(ImageDump, HDevWindowStack::GetActive());
  CloseWindow(WindowHandleBuffer);
  SetPart(WindowHandle, WPRow1, WPColumn1, WPRow2, WPColumn2);
  ClearScene3d(Scene3D);
  return;
}

// Chapter: Graphics / Output
// Short Description: Determine the optimum distance of the object to obtain a reasonable visualization
void determine_optimum_pose_distance (HTuple ObjectModel3DID, HTuple CamParam,
    HTuple ImageCoverage, HTuple PoseIn, HTuple *PoseOut)
{

  // Local iconic variables

  // Local control variables
  HTuple  NumModels, Rows, Cols, MinMinZ;
  HTuple  BB, Seq, DXMax, DYMax, DZMax, Diameter;
  HTuple  ZAdd, IBB, BB0, BB1, BB2, BB3;
  HTuple  BB4, BB5, X, Y, Z, PoseInter;
  HTuple  HomMat3D, CX, CY, CZ, DR, DC;
  HTuple  MaxDist, HomMat3DRotate, MinImageSize;
  HTuple  Zs, ZDiff, ScaleZ, ZNew;

  //Determine the optimum distance of the object to obtain
  //a reasonable visualization
  //
  NumModels = ObjectModel3DID.TupleLength();
  Rows = HTuple();
  Cols = HTuple();
  MinMinZ = 1e30;
  GetObjectModel3dParams(ObjectModel3DID, "bounding_box1", &BB);
  //Calculate diameter over all objects to be visualized
  Seq = HTuple::TupleGenSequence(0,(BB.TupleLength())-1,6);
  DXMax = (HTuple(BB[Seq+3]).TupleMax())-(HTuple(BB[Seq]).TupleMin());
  DYMax = (HTuple(BB[Seq+4]).TupleMax())-(HTuple(BB[Seq+1]).TupleMin());
  DZMax = (HTuple(BB[Seq+5]).TupleMax())-(HTuple(BB[Seq+2]).TupleMin());
  Diameter = (((DXMax*DXMax)+(DYMax*DYMax))+(DZMax*DZMax)).TupleSqrt();
  if (0 != (((BB.TupleAbs()).TupleSum())==0.0))
  {
    BB.Clear();
    BB.Append(-(HTuple(HTuple::TupleRand(3)*1e-20).TupleAbs()));
    BB.Append(HTuple(HTuple::TupleRand(3)*1e-20).TupleAbs());
  }
  //Allow the visualization of single points or extremely small objects
  ZAdd = 0.0;
  if (0 != ((Diameter.TupleMax())<1e-10))
  {
    ZAdd = 0.01;
  }
  //Set extremely small diameters to 1e-10 to avoid CZ == 0.0, which would lead
  //to projection errors
  if (0 != ((Diameter.TupleMin())<1e-10))
  {
    Diameter = Diameter-(((((Diameter-1e-10).TupleSgn())-1).TupleSgn())*1e-10);
  }
  IBB = HTuple::TupleGenSequence(0,(BB.TupleLength())-1,6);
  BB0 = ((const HTuple&)BB)[IBB];
  BB1 = ((const HTuple&)BB)[IBB+1];
  BB2 = ((const HTuple&)BB)[IBB+2];
  BB3 = ((const HTuple&)BB)[IBB+3];
  BB4 = ((const HTuple&)BB)[IBB+4];
  BB5 = ((const HTuple&)BB)[IBB+5];
  X.Clear();
  X.Append(BB0);
  X.Append(BB3);
  X.Append(BB0);
  X.Append(BB0);
  X.Append(BB3);
  X.Append(BB3);
  X.Append(BB0);
  X.Append(BB3);
  Y.Clear();
  Y.Append(BB1);
  Y.Append(BB1);
  Y.Append(BB4);
  Y.Append(BB1);
  Y.Append(BB4);
  Y.Append(BB1);
  Y.Append(BB4);
  Y.Append(BB4);
  Z.Clear();
  Z.Append(BB2);
  Z.Append(BB2);
  Z.Append(BB2);
  Z.Append(BB5);
  Z.Append(BB2);
  Z.Append(BB5);
  Z.Append(BB5);
  Z.Append(BB5);
  PoseInter = PoseIn.TupleReplace(2,(-(Z.TupleMin()))+(2*(Diameter.TupleMax())));
  PoseToHomMat3d(PoseInter, &HomMat3D);
  //Determine the maximum extention of the projection
  AffineTransPoint3d(HomMat3D, X, Y, Z, &CX, &CY, &CZ);
  Project3dPoint(CX, CY, CZ, CamParam, &Rows, &Cols);
  MinMinZ = CZ.TupleMin();
  DR = Rows-HTuple(CamParam[(CamParam.TupleLength())-3]);
  DC = Cols-HTuple(CamParam[(CamParam.TupleLength())-4]);
  DR = (DR.TupleMax())-(DR.TupleMin());
  DC = (DC.TupleMax())-(DC.TupleMin());
  MaxDist = ((DR*DR)+(DC*DC)).TupleSqrt();
  //
  if (0 != (MaxDist<1e-10))
  {
    //If the object has no extension in the above projection (looking along
    //a line), we determine the extension of the object in a rotated view
    HomMat3dRotateLocal(HomMat3D, HTuple(90).TupleRad(), "x", &HomMat3DRotate);
    AffineTransPoint3d(HomMat3DRotate, X, Y, Z, &CX, &CY, &CZ);
    Project3dPoint(CX, CY, CZ, CamParam, &Rows, &Cols);
    DR = Rows-HTuple(CamParam[(CamParam.TupleLength())-3]);
    DC = Cols-HTuple(CamParam[(CamParam.TupleLength())-4]);
    DR = (DR.TupleMax())-(DR.TupleMin());
    DC = (DC.TupleMax())-(DC.TupleMin());
    MaxDist = (MaxDist.TupleConcat(((DR*DR)+(DC*DC)).TupleSqrt())).TupleMax();
  }
  //
  MinImageSize = (HTuple(CamParam[(CamParam.TupleLength())-2]).TupleConcat(HTuple(CamParam[(CamParam.TupleLength())-1]))).TupleMin();
  //
  Z = ((const HTuple&)PoseInter)[2];
  Zs = MinMinZ;
  ZDiff = Z-Zs;
  ScaleZ = MaxDist/(((0.5*MinImageSize)*ImageCoverage)*2.0);
  ZNew = ((ScaleZ*Zs)+ZDiff)+ZAdd;
  (*PoseOut) = PoseInter.TupleReplace(2,ZNew);
  //
  return;
}

// Chapter: Graphics / Output
// Short Description: Reflect the pose change that was introduced by the user by moving the mouse
void analyze_graph_event (HObject BackgroundImage, HTuple MouseMapping, HTuple Button,
    HTuple Row, HTuple Column, HTuple WindowHandle, HTuple WindowHandleBuffer,
    HTuple VirtualTrackball, HTuple TrackballSize, HTuple SelectedObjectIn,
    HTuple Scene3D, HTuple AlphaOrig, HTuple ObjectModel3DID, HTuple CamParam,
    HTuple Labels, HTuple Title, HTuple Information, HTuple GenParamName,
    HTuple GenParamValue, HTuple PosesIn, HTuple ButtonHoldIn, HTuple TBCenter,
    HTuple TBSize, HTuple WindowCenteredRotationlIn, HTuple MaxNumModels,
    HTuple *PosesOut, HTuple *SelectedObjectOut, HTuple *ButtonHoldOut,
    HTuple *WindowCenteredRotationOut)
{

  // Local iconic variables
  HObject  ImageDump;

  // Local control variables
  HTuple  ExpTmpLocalVar_gIsSinglePose, VisualizeTB;
  HTuple  InvLog2, Seconds, ModelIndex, Exception1;
  HTuple  HomMat3DIdentity, NumModels, Width, Height;
  HTuple  MinImageSize, TrackballRadiusPixel, TrackballCenterRow;
  HTuple  TrackballCenterCol, NumChannels, ColorImage;
  HTuple  BAnd, SensFactor, IsButtonTrans, IsButtonRot;
  HTuple  IsButtonDist, MRow1, MCol1, ButtonLoop;
  HTuple  MRow2, MCol2, PX, PY, PZ, QX1;
  HTuple  QY1, QZ1, QX2, QY2, QZ2, Len;
  HTuple  Dist, Translate, Index, PoseIn, HomMat3DIn;
  HTuple  HomMat3DOut, PoseOut, Indices, Sequence;
  HTuple  Mod, SequenceReal, Sequence2Int, Selected;
  HTuple  InvSelected, Exception, DRow, TranslateZ;
  HTuple  MX1, MY1, MX2, MY2, RelQuaternion;
  HTuple  HomMat3DRotRel, HomMat3DInTmp1, HomMat3DInTmp;
  HTuple  PosesOut2;

  //This procedure reflects
  //- the pose change that was introduced by the user by
  //  moving the mouse
  //- the selection of a single object
  //
  //global tuple gIsSinglePose
  //
  (*ButtonHoldOut) = ButtonHoldIn;
  (*PosesOut) = PosesIn;
  (*SelectedObjectOut) = SelectedObjectIn;
  (*WindowCenteredRotationOut) = WindowCenteredRotationlIn;
  VisualizeTB = ((*SelectedObjectOut).TupleMax())!=0;
  InvLog2 = 1.0/(HTuple(2).TupleLog());
  //
  if (0 != (Button==HTuple(MouseMapping[6])))
  {
    if (0 != (*ButtonHoldOut))
    {
      return;
    }
    //Ctrl (16) + Alt (32) + left mouse button (1) => Toggle rotation center position
    //If WindowCenteredRotation is not 1, set it to 1, otherwise, set it to 2
    CountSeconds(&Seconds);
    if (0 != ((*WindowCenteredRotationOut)==1))
    {
      (*WindowCenteredRotationOut) = 2;
    }
    else
    {
      (*WindowCenteredRotationOut) = 1;
    }
    (*ButtonHoldOut) = 1;
    return;
  }
  if (0 != (HTuple(Button==HTuple(MouseMapping[5])).TupleAnd((ObjectModel3DID.TupleLength())<=MaxNumModels)))
  {
    if (0 != (*ButtonHoldOut))
    {
      return;
    }
    //Ctrl (16) + left mouse button (1) => Select an object
    try
    {
      SetScene3dParam(Scene3D, "object_index_persistence", "true");
      DisplayScene3d(WindowHandleBuffer, Scene3D, 0);
      GetDisplayScene3dInfo(WindowHandleBuffer, Scene3D, Row, Column,
          "object_index", &ModelIndex);
      SetScene3dParam(Scene3D, "object_index_persistence", "false");
    }
    // catch (Exception1)
    catch (HalconCpp::HException &HDevExpDefaultException)
    {
      HDevExpDefaultException.ToHTuple(&Exception1);
      //* NO OpenGL, no selection possible
      return;
    }
    if (0 != (ModelIndex==-1))
    {
      //Background click:
      if (0 != (((*SelectedObjectOut).TupleSum())==((*SelectedObjectOut).TupleLength())))
      {
        //If all objects are already selected, deselect all
        (*SelectedObjectOut) = HTuple(ObjectModel3DID.TupleLength(),0);
      }
      else
      {
        //Otherwise select all
        (*SelectedObjectOut) = HTuple(ObjectModel3DID.TupleLength(),1);
      }
    }
    else
    {
      //Object click:
      (*SelectedObjectOut)[ModelIndex] = HTuple((*SelectedObjectOut)[ModelIndex]).TupleNot();
    }
    (*ButtonHoldOut) = 1;
  }
  else
  {
    //Change the pose
    HomMat3dIdentity(&HomMat3DIdentity);
    NumModels = ObjectModel3DID.TupleLength();
    Width = ((const HTuple&)CamParam)[(CamParam.TupleLength())-2];
    Height = ((const HTuple&)CamParam)[(CamParam.TupleLength())-1];
    MinImageSize = (Width.TupleConcat(Height)).TupleMin();
    TrackballRadiusPixel = (TrackballSize*MinImageSize)/2.0;
    //Set trackball fixed in the center of the window
    TrackballCenterRow = Height/2;
    TrackballCenterCol = Width/2;
    if (0 != ((ObjectModel3DID.TupleLength())<MaxNumModels))
    {
      if (0 != ((*WindowCenteredRotationOut)==1))
      {
        get_trackball_center_fixed(SelectedObjectIn, TrackballCenterRow, TrackballCenterCol,
            TrackballRadiusPixel, Scene3D, ObjectModel3DID, PosesIn,
            WindowHandleBuffer, CamParam, GenParamName, GenParamValue,
            &TBCenter, &TBSize);
      }
      else
      {
        get_trackball_center(SelectedObjectIn, TrackballRadiusPixel, ObjectModel3DID,
            PosesIn, &TBCenter, &TBSize);
      }
    }
    if (0 != (HTuple(((*SelectedObjectOut).TupleMin())==0).TupleAnd(((*SelectedObjectOut).TupleMax())==1)))
    {
      //At this point, multiple objects do not necessary have the same
      //pose any more. Consequently, we have to return a tuple of poses
      //as output of visualize_object_model_3d
      ExpTmpLocalVar_gIsSinglePose = 0;
      ExpSetGlobalVar_gIsSinglePose(ExpTmpLocalVar_gIsSinglePose);
    }
    CountChannels(BackgroundImage, &NumChannels);
    ColorImage = NumChannels==3;
    //Alt (32) => lower sensitivity
    TupleRsh(Button, 5, &BAnd);
    if (0 != (BAnd%2))
    {
      SensFactor = 0.1;
    }
    else
    {
      SensFactor = 1.0;
    }
    IsButtonTrans = HTuple(HTuple(MouseMapping[0])==Button).TupleOr((32+HTuple(MouseMapping[0]))==Button);
    IsButtonRot = HTuple(HTuple(MouseMapping[1])==Button).TupleOr((32+HTuple(MouseMapping[1]))==Button);
    IsButtonDist = HTuple(HTuple(HTuple(HTuple(HTuple(HTuple(MouseMapping[2])==Button).TupleOr((32+HTuple(MouseMapping[2]))==Button)).TupleOr(HTuple(MouseMapping[3])==Button)).TupleOr((32+HTuple(MouseMapping[3]))==Button)).TupleOr(HTuple(MouseMapping[4])==Button)).TupleOr((32+HTuple(MouseMapping[4]))==Button);
    if (0 != IsButtonTrans)
    {
      //Translate in XY-direction
      MRow1 = Row;
      MCol1 = Column;
      while (0 != IsButtonTrans)
      {
        try
        {
          GetMpositionSubPix(WindowHandle, &Row, &Column, &ButtonLoop);
          IsButtonTrans = ButtonLoop==Button;
          MRow2 = MRow1+((Row-MRow1)*SensFactor);
          MCol2 = MCol1+((Column-MCol1)*SensFactor);
          GetLineOfSight(MRow1, MCol1, CamParam, &PX, &PY, &PZ,
              &QX1, &QY1, &QZ1);
          GetLineOfSight(MRow2, MCol2, CamParam, &PX, &PY, &PZ,
              &QX2, &QY2, &QZ2);
          Len = (((QX1*QX1)+(QY1*QY1))+(QZ1*QZ1)).TupleSqrt();
          Dist = (((HTuple(TBCenter[0])*HTuple(TBCenter[0]))+(HTuple(TBCenter[1])*HTuple(TBCenter[1])))+(HTuple(TBCenter[2])*HTuple(TBCenter[2]))).TupleSqrt();
          Translate = ((((QX2-QX1).TupleConcat(QY2-QY1)).TupleConcat(QZ2-QZ1))*Dist)/Len;
          (*PosesOut) = HTuple();
          if (0 != (NumModels<=MaxNumModels))
          {
            {
            HTuple end_val110 = NumModels-1;
            HTuple step_val110 = 1;
            for (Index=0; Index.Continue(end_val110, step_val110); Index += step_val110)
            {
              PoseIn = PosesIn.TupleSelectRange(Index*7,(Index*7)+6);
              if (0 != (HTuple((*SelectedObjectOut)[Index])))
              {
                PoseToHomMat3d(PoseIn, &HomMat3DIn);
                HomMat3dTranslate(HomMat3DIn, HTuple(Translate[0]), HTuple(Translate[1]),
                    HTuple(Translate[2]), &HomMat3DOut);
                HomMat3dToPose(HomMat3DOut, &PoseOut);
                SetScene3dInstancePose(Scene3D, Index, PoseOut);
              }
              else
              {
                PoseOut = PoseIn;
              }
              (*PosesOut) = (*PosesOut).TupleConcat(PoseOut);
            }
            }
          }
          else
          {
            TupleFind((*SelectedObjectOut), 1, &Indices);
            PoseIn = PosesIn.TupleSelectRange(HTuple(Indices[0])*7,(HTuple(Indices[0])*7)+6);
            PoseToHomMat3d(PoseIn, &HomMat3DIn);
            HomMat3dTranslate(HomMat3DIn, HTuple(Translate[0]), HTuple(Translate[1]),
                HTuple(Translate[2]), &HomMat3DOut);
            HomMat3dToPose(HomMat3DOut, &PoseOut);
            Sequence = HTuple::TupleGenSequence(0,(NumModels*7)-1,1);
            TupleMod(Sequence, 7, &Mod);
            SequenceReal = HTuple::TupleGenSequence(0,NumModels-(1.0/7.0),1.0/7.0);
            Sequence2Int = SequenceReal.TupleInt();
            TupleSelect((*SelectedObjectOut), Sequence2Int, &Selected);
            InvSelected = 1-Selected;
            TupleSelect(PoseOut, Mod, &(*PosesOut));
            (*PosesOut) = ((*PosesOut)*Selected)+(PosesIn*InvSelected);
            SetScene3dInstancePose(Scene3D, HTuple::TupleGenSequence(0,NumModels-1,1),
                (*PosesOut));
          }
          dump_image_output(BackgroundImage, WindowHandleBuffer, Scene3D,
              AlphaOrig, ObjectModel3DID, GenParamName, GenParamValue,
              CamParam, (*PosesOut), ColorImage, Title, Information,
              Labels, VisualizeTB, "true", TrackballCenterRow, TrackballCenterCol,
              TBSize, (*SelectedObjectOut), (*WindowCenteredRotationOut)==1,
              TBCenter);
          DumpWindowImage(&ImageDump, WindowHandleBuffer);
          HDevWindowStack::SetActive(WindowHandle);
          if (HDevWindowStack::IsOpen())
            DispObj(ImageDump, HDevWindowStack::GetActive());
          //
          MRow1 = Row;
          MCol1 = Column;
          PosesIn = (*PosesOut);
        }
        // catch (Exception)
        catch (HalconCpp::HException &HDevExpDefaultException)
        {
          HDevExpDefaultException.ToHTuple(&Exception);
          //Keep waiting
        }
      }
    }
    else if (0 != IsButtonDist)
    {
      //Change the Z distance
      MRow1 = Row;
      while (0 != IsButtonDist)
      {
        try
        {
          GetMpositionSubPix(WindowHandle, &Row, &Column, &ButtonLoop);
          IsButtonDist = ButtonLoop==Button;
          MRow2 = Row;
          DRow = MRow2-MRow1;
          Dist = (((HTuple(TBCenter[0])*HTuple(TBCenter[0]))+(HTuple(TBCenter[1])*HTuple(TBCenter[1])))+(HTuple(TBCenter[2])*HTuple(TBCenter[2]))).TupleSqrt();
          TranslateZ = (((-Dist)*DRow)*0.003)*SensFactor;
          TBCenter[2] = HTuple(TBCenter[2])+TranslateZ;
          (*PosesOut) = HTuple();
          if (0 != (NumModels<=MaxNumModels))
          {
            {
            HTuple end_val164 = NumModels-1;
            HTuple step_val164 = 1;
            for (Index=0; Index.Continue(end_val164, step_val164); Index += step_val164)
            {
              PoseIn = PosesIn.TupleSelectRange(Index*7,(Index*7)+6);
              if (0 != (HTuple((*SelectedObjectOut)[Index])))
              {
                //Transform the whole scene or selected object only
                PoseToHomMat3d(PoseIn, &HomMat3DIn);
                HomMat3dTranslate(HomMat3DIn, 0, 0, TranslateZ, &HomMat3DOut);
                HomMat3dToPose(HomMat3DOut, &PoseOut);
                SetScene3dInstancePose(Scene3D, Index, PoseOut);
              }
              else
              {
                PoseOut = PoseIn;
              }
              (*PosesOut) = (*PosesOut).TupleConcat(PoseOut);
            }
            }
          }
          else
          {
            TupleFind((*SelectedObjectOut), 1, &Indices);
            PoseIn = PosesIn.TupleSelectRange(HTuple(Indices[0])*7,(HTuple(Indices[0])*7)+6);
            PoseToHomMat3d(PoseIn, &HomMat3DIn);
            HomMat3dTranslate(HomMat3DIn, 0, 0, TranslateZ, &HomMat3DOut);
            HomMat3dToPose(HomMat3DOut, &PoseOut);
            Sequence = HTuple::TupleGenSequence(0,(NumModels*7)-1,1);
            TupleMod(Sequence, 7, &Mod);
            SequenceReal = HTuple::TupleGenSequence(0,NumModels-(1.0/7.0),1.0/7.0);
            Sequence2Int = SequenceReal.TupleInt();
            TupleSelect((*SelectedObjectOut), Sequence2Int, &Selected);
            InvSelected = 1-Selected;
            TupleSelect(PoseOut, Mod, &(*PosesOut));
            (*PosesOut) = ((*PosesOut)*Selected)+(PosesIn*InvSelected);
            SetScene3dInstancePose(Scene3D, HTuple::TupleGenSequence(0,NumModels-1,1),
                (*PosesOut));
          }
          dump_image_output(BackgroundImage, WindowHandleBuffer, Scene3D,
              AlphaOrig, ObjectModel3DID, GenParamName, GenParamValue,
              CamParam, (*PosesOut), ColorImage, Title, Information,
              Labels, VisualizeTB, "true", TrackballCenterRow, TrackballCenterCol,
              TBSize, (*SelectedObjectOut), (*WindowCenteredRotationOut),
              TBCenter);
          DumpWindowImage(&ImageDump, WindowHandleBuffer);
          HDevWindowStack::SetActive(WindowHandle);
          if (HDevWindowStack::IsOpen())
            DispObj(ImageDump, HDevWindowStack::GetActive());
          //
          MRow1 = Row;
          PosesIn = (*PosesOut);
        }
        // catch (Exception)
        catch (HalconCpp::HException &HDevExpDefaultException)
        {
          HDevExpDefaultException.ToHTuple(&Exception);
          //Keep waiting
        }
      }
    }
    else if (0 != IsButtonRot)
    {
      //Rotate the object
      MRow1 = Row;
      MCol1 = Column;
      while (0 != IsButtonRot)
      {
        try
        {
          GetMpositionSubPix(WindowHandle, &Row, &Column, &ButtonLoop);
          IsButtonRot = ButtonLoop==Button;
          MRow2 = Row;
          MCol2 = Column;
          //Transform the pixel coordinates to relative image coordinates
          MX1 = (TrackballCenterCol-MCol1)/(0.5*MinImageSize);
          MY1 = (TrackballCenterRow-MRow1)/(0.5*MinImageSize);
          MX2 = (TrackballCenterCol-MCol2)/(0.5*MinImageSize);
          MY2 = (TrackballCenterRow-MRow2)/(0.5*MinImageSize);
          //Compute the quaternion rotation that corresponds to the mouse
          //movement
          trackball(MX1, MY1, MX2, MY2, VirtualTrackball, TrackballSize,
              SensFactor, &RelQuaternion);
          //Transform the quaternion to a rotation matrix
          QuatToHomMat3d(RelQuaternion, &HomMat3DRotRel);
          (*PosesOut) = HTuple();
          if (0 != (NumModels<=MaxNumModels))
          {
            {
            HTuple end_val226 = NumModels-1;
            HTuple step_val226 = 1;
            for (Index=0; Index.Continue(end_val226, step_val226); Index += step_val226)
            {
              PoseIn = PosesIn.TupleSelectRange(Index*7,(Index*7)+6);
              if (0 != (HTuple((*SelectedObjectOut)[Index])))
              {
                //Transform the whole scene or selected object only
                PoseToHomMat3d(PoseIn, &HomMat3DIn);
                HomMat3dTranslate(HomMat3DIn, -HTuple(TBCenter[0]), -HTuple(TBCenter[1]),
                    -HTuple(TBCenter[2]), &HomMat3DIn);
                HomMat3dCompose(HomMat3DRotRel, HomMat3DIn, &HomMat3DIn);
                HomMat3dTranslate(HomMat3DIn, HTuple(TBCenter[0]), HTuple(TBCenter[1]),
                    HTuple(TBCenter[2]), &HomMat3DOut);
                HomMat3dToPose(HomMat3DOut, &PoseOut);
                SetScene3dInstancePose(Scene3D, Index, PoseOut);
              }
              else
              {
                PoseOut = PoseIn;
              }
              (*PosesOut) = (*PosesOut).TupleConcat(PoseOut);
            }
            }
          }
          else
          {
            TupleFind((*SelectedObjectOut), 1, &Indices);
            PoseIn = PosesIn.TupleSelectRange(HTuple(Indices[0])*7,(HTuple(Indices[0])*7)+6);
            PoseToHomMat3d(PoseIn, &HomMat3DIn);
            HomMat3dTranslate(HomMat3DIn, -HTuple(TBCenter[0]), -HTuple(TBCenter[1]),
                -HTuple(TBCenter[2]), &HomMat3DInTmp1);
            HomMat3dCompose(HomMat3DRotRel, HomMat3DInTmp1, &HomMat3DInTmp);
            HomMat3dTranslate(HomMat3DInTmp, HTuple(TBCenter[0]), HTuple(TBCenter[1]),
                HTuple(TBCenter[2]), &HomMat3DOut);
            HomMat3dToPose(HomMat3DOut, &PoseOut);
            Sequence = HTuple::TupleGenSequence(0,(NumModels*7)-1,1);
            TupleMod(Sequence, 7, &Mod);
            SequenceReal = HTuple::TupleGenSequence(0,NumModels-(1.0/7.0),1.0/7.0);
            Sequence2Int = SequenceReal.TupleInt();
            TupleSelect((*SelectedObjectOut), Sequence2Int, &Selected);
            InvSelected = 1-Selected;
            TupleSelect(PoseOut, Mod, &(*PosesOut));
            PosesOut2 = ((*PosesOut)*Selected)+(PosesIn*InvSelected);
            (*PosesOut) = PosesOut2;
            SetScene3dInstancePose(Scene3D, HTuple::TupleGenSequence(0,NumModels-1,1),
                (*PosesOut));
          }
          dump_image_output(BackgroundImage, WindowHandleBuffer, Scene3D,
              AlphaOrig, ObjectModel3DID, GenParamName, GenParamValue,
              CamParam, (*PosesOut), ColorImage, Title, Information,
              Labels, VisualizeTB, "true", TrackballCenterRow, TrackballCenterCol,
              TBSize, (*SelectedObjectOut), (*WindowCenteredRotationOut),
              TBCenter);
          DumpWindowImage(&ImageDump, WindowHandleBuffer);
          HDevWindowStack::SetActive(WindowHandle);
          if (HDevWindowStack::IsOpen())
            DispObj(ImageDump, HDevWindowStack::GetActive());
          //
          MRow1 = Row;
          MCol1 = Column;
          PosesIn = (*PosesOut);
        }
        // catch (Exception)
        catch (HalconCpp::HException &HDevExpDefaultException)
        {
          HDevExpDefaultException.ToHTuple(&Exception);
          //Keep waiting
        }
      }
    }
    (*PosesOut) = PosesIn;
  }
  return;
}

// Chapter: Graphics / Output
// Short Description: Project an image point onto the trackball
void project_point_on_trackball (HTuple X, HTuple Y, HTuple VirtualTrackball,
    HTuple TrackballSize, HTuple *V)
{

  // Local iconic variables

  // Local control variables
  HTuple  R, XP, YP, ZP;

  if (0 != (VirtualTrackball==HTuple("shoemake")))
  {
    //Virtual Trackball according to Shoemake
    R = ((X*X)+(Y*Y)).TupleSqrt();
    if (0 != (R<=TrackballSize))
    {
      XP = X;
      YP = Y;
      ZP = ((TrackballSize*TrackballSize)-(R*R)).TupleSqrt();
    }
    else
    {
      XP = (X*TrackballSize)/R;
      YP = (Y*TrackballSize)/R;
      ZP = 0;
    }
  }
  else
  {
    //Virtual Trackball according to Bell
    R = ((X*X)+(Y*Y)).TupleSqrt();
    if (0 != (R<=(TrackballSize*0.70710678)))
    {
      XP = X;
      YP = Y;
      ZP = ((TrackballSize*TrackballSize)-(R*R)).TupleSqrt();
    }
    else
    {
      XP = X;
      YP = Y;
      ZP = ((0.6*TrackballSize)*TrackballSize)/R;
    }
  }
  (*V).Clear();
  (*V).Append(XP);
  (*V).Append(YP);
  (*V).Append(ZP);
  return;
}

// Chapter: Graphics / Text
// Short Description: This procedure writes a text message.
void disp_text_button (HTuple WindowHandle, HTuple String, HTuple CoordSystem,
    HTuple Row, HTuple Column, HTuple TextColor, HTuple ButtonColor)
{

  // Local iconic variables
  HObject  UpperLeft, LowerRight, Rectangle;

  // Local control variables
  HTuple  Red, Green, Blue, Row1Part;
  HTuple  Column1Part, Row2Part, Column2Part, RowWin;
  HTuple  ColumnWin, WidthWin, HeightWin, Exception;
  HTuple  Fac, RGBL, RGB, RGBD, ButtonColorBorderL;
  HTuple  ButtonColorBorderD, MaxAscent, MaxDescent;
  HTuple  MaxWidth, MaxHeight, R1, C1, FactorRow;
  HTuple  FactorColumn, Width, Index, Ascent;
  HTuple  Descent, W, H, FrameHeight, FrameWidth;
  HTuple  R2, C2, ClipRegion, DrawMode, BorderWidth;
  HTuple  CurrentColor;

  //This procedure displays text in a graphics window.
  //
  //Input parameters:
  //WindowHandle: The WindowHandle of the graphics window, where
  //   the message should be displayed
  //String: A tuple of strings containing the text message to be displayed
  //CoordSystem: If set to 'window', the text position is given
  //   with respect to the window coordinate system.
  //   If set to 'image', image coordinates are used.
  //   (This may be useful in zoomed images.)
  //Row: The row coordinate of the desired text position
  //   If set to -1, a default value of 12 is used.
  //Column: The column coordinate of the desired text position
  //   If set to -1, a default value of 12 is used.
  //Color: defines the color of the text as string.
  //   If set to [], '' or 'auto' the currently set color is used.
  //   If a tuple of strings is passed, the colors are used cyclically
  //   for each new textline.
  //ButtonColor: Must be set to a color string (e.g. 'white', '#FF00CC', etc.).
  //             The text is written in a box of that color.
  //
  //prepare window
  GetRgb(WindowHandle, &Red, &Green, &Blue);
  GetPart(WindowHandle, &Row1Part, &Column1Part, &Row2Part, &Column2Part);
  GetWindowExtents(WindowHandle, &RowWin, &ColumnWin, &WidthWin, &HeightWin);
  SetPart(WindowHandle, 0, 0, HeightWin-1, WidthWin-1);
  //
  //default settings
  if (0 != (Row==-1))
  {
    Row = 12;
  }
  if (0 != (Column==-1))
  {
    Column = 12;
  }
  if (0 != (TextColor==HTuple()))
  {
    TextColor = "";
  }
  //
  try
  {
    color_string_to_rgb(ButtonColor, &RGB);
  }
  // catch (Exception)
  catch (HalconCpp::HException &HDevExpDefaultException)
  {
    HDevExpDefaultException.ToHTuple(&Exception);
    Exception = "Wrong value of control parameter ButtonColor (must be a valid color string)";
    throw HalconCpp::HException(Exception);
  }
  Fac = 0.4;
  RGBL = RGB+((((255.0-RGB)*Fac)+0.5).TupleInt());
  RGBD = RGB-(((RGB*Fac)+0.5).TupleInt());
  ButtonColorBorderL = "#"+((""+(RGBL.TupleString("02x"))).TupleSum());
  ButtonColorBorderD = "#"+((""+(RGBD.TupleString("02x"))).TupleSum());
  //
  String = ((""+String)+"").TupleSplit("\n");
  //
  //Estimate extentions of text depending on font size.
  GetFontExtents(WindowHandle, &MaxAscent, &MaxDescent, &MaxWidth, &MaxHeight);
  if (0 != (CoordSystem==HTuple("window")))
  {
    R1 = Row;
    C1 = Column;
  }
  else
  {
    //transform image to window coordinates
    FactorRow = (1.*HeightWin)/((Row2Part-Row1Part)+1);
    FactorColumn = (1.*WidthWin)/((Column2Part-Column1Part)+1);
    R1 = ((Row-Row1Part)+0.5)*FactorRow;
    C1 = ((Column-Column1Part)+0.5)*FactorColumn;
  }
  //
  //display text box depending on text size
  //
  //calculate box extents
  String = (" "+String)+" ";
  Width = HTuple();
  {
  HTuple end_val70 = (String.TupleLength())-1;
  HTuple step_val70 = 1;
  for (Index=0; Index.Continue(end_val70, step_val70); Index += step_val70)
  {
    GetStringExtents(WindowHandle, HTuple(String[Index]), &Ascent, &Descent,
        &W, &H);
    Width = Width.TupleConcat(W);
  }
  }
  FrameHeight = MaxHeight*(String.TupleLength());
  FrameWidth = (HTuple(0).TupleConcat(Width)).TupleMax();
  R2 = R1+FrameHeight;
  C2 = C1+FrameWidth;
  //display rectangles
  GetSystem("clip_region", &ClipRegion);
  SetSystem("clip_region", "false");
  GetDraw(WindowHandle, &DrawMode);
  SetDraw(WindowHandle, "fill");
  BorderWidth = 2;
  GenRegionPolygonFilled(&UpperLeft, ((((R1-BorderWidth).TupleConcat(R1-BorderWidth)).TupleConcat(R1)).TupleConcat(R2)).TupleConcat(R2+BorderWidth),
      ((((C1-BorderWidth).TupleConcat(C2+BorderWidth)).TupleConcat(C2)).TupleConcat(C1)).TupleConcat(C1-BorderWidth));
  GenRegionPolygonFilled(&LowerRight, ((((R2+BorderWidth).TupleConcat(R1-BorderWidth)).TupleConcat(R1)).TupleConcat(R2)).TupleConcat(R2+BorderWidth),
      ((((C2+BorderWidth).TupleConcat(C2+BorderWidth)).TupleConcat(C2)).TupleConcat(C1)).TupleConcat(C1-BorderWidth));
  GenRectangle1(&Rectangle, R1, C1, R2, C2);
  SetColor(WindowHandle, ButtonColorBorderL);
  DispObj(UpperLeft, WindowHandle);
  SetColor(WindowHandle, ButtonColorBorderD);
  DispObj(LowerRight, WindowHandle);
  SetColor(WindowHandle, ButtonColor);
  DispObj(Rectangle, WindowHandle);
  SetDraw(WindowHandle, DrawMode);
  SetSystem("clip_region", ClipRegion);
  //Write text.
  {
  HTuple end_val96 = (String.TupleLength())-1;
  HTuple step_val96 = 1;
  for (Index=0; Index.Continue(end_val96, step_val96); Index += step_val96)
  {
    CurrentColor = ((const HTuple&)TextColor)[Index%(TextColor.TupleLength())];
    if (0 != (HTuple(CurrentColor!=HTuple("")).TupleAnd(CurrentColor!=HTuple("auto"))))
    {
      SetColor(WindowHandle, CurrentColor);
    }
    else
    {
      SetRgb(WindowHandle, Red, Green, Blue);
    }
    Row = R1+(MaxHeight*Index);
    SetTposition(WindowHandle, Row, C1);
    WriteString(WindowHandle, HTuple(String[Index]));
  }
  }
  //reset changed window settings
  SetRgb(WindowHandle, Red, Green, Blue);
  SetPart(WindowHandle, Row1Part, Column1Part, Row2Part, Column2Part);
  return;
}

// Chapter: Graphics / Output
// Short Description: Renders 3d object models in a buffer window.
void dump_image_output (HObject BackgroundImage, HTuple WindowHandleBuffer,
    HTuple Scene3D, HTuple AlphaOrig, HTuple ObjectModel3DID, HTuple GenParamName,
    HTuple GenParamValue, HTuple CamParam, HTuple Poses, HTuple ColorImage,
    HTuple Title, HTuple Information, HTuple Labels, HTuple VisualizeTrackball,
    HTuple DisplayContinueButton, HTuple TrackballCenterRow, HTuple TrackballCenterCol,
    HTuple TrackballRadiusPixel, HTuple SelectedObject, HTuple VisualizeRotationCenter,
    HTuple RotationCenter)
{

  // Local iconic variables
  HObject  ModelContours, Image, TrackballContour;
  HObject  CrossRotCenter;

  // Local control variables
  HTuple  ExpTmpLocalVar_gUsesOpenGL, Exception;
  HTuple  Index, Position, PosIdx, Substrings;
  HTuple  I, HasExtended, ExtendedAttributeNames;
  HTuple  Matches, Exception1, DeselectedIdx, DeselectedName;
  HTuple  DeselectedValue, Pose, HomMat3D, Center;
  HTuple  CenterCamX, CenterCamY, CenterCamZ, CenterRow;
  HTuple  CenterCol, Label, Ascent, Descent, TextWidth;
  HTuple  TextHeight, RotCenterRow, RotCenterCol;
  HTuple  Orientation, Colors;

  //global tuple gAlphaDeselected
  //global tuple gTerminationButtonLabel
  //global tuple gDispObjOffset
  //global tuple gLabelsDecor
  //global tuple gUsesOpenGL
  //
  //Display background image
  ClearWindow(WindowHandleBuffer);
  if (0 != ColorImage)
  {
    DispColor(BackgroundImage, WindowHandleBuffer);
  }
  else
  {
    DispImage(BackgroundImage, WindowHandleBuffer);
  }
  //
  //Display objects
  if (0 != ((SelectedObject.TupleSum())==(SelectedObject.TupleLength())))
  {
    if (0 != (ExpGetGlobalVar_gUsesOpenGL()==HTuple("true")))
    {
      try
      {
        DisplayScene3d(WindowHandleBuffer, Scene3D, 0);
      }
      // catch (Exception)
      catch (HalconCpp::HException &HDevExpDefaultException)
      {
        HDevExpDefaultException.ToHTuple(&Exception);
        if (0 != (HTuple(HTuple(HTuple(HTuple(Exception[0])==1306).TupleOr(HTuple(Exception[0])==1305)).TupleOr(HTuple(Exception[0])==1406)).TupleOr(HTuple(Exception[0])==1405)))
        {
          if (0 != ((GenParamName.TupleLength())==(GenParamValue.TupleLength())))
          {
            //This case means we have a Parameter with structure parameter_x with x > |ObjectModel3DID|-1
            {
            HTuple end_val23 = (2*(ObjectModel3DID.TupleLength()))+1;
            HTuple step_val23 = 1;
            for (Index=ObjectModel3DID.TupleLength(); Index.Continue(end_val23, step_val23); Index += step_val23)
            {
              TupleStrstr(GenParamName, ""+Index, &Position);
              {
              HTuple end_val25 = (Position.TupleLength())-1;
              HTuple step_val25 = 1;
              for (PosIdx=0; PosIdx.Continue(end_val25, step_val25); PosIdx += step_val25)
              {
                if (0 != (HTuple(Position[PosIdx])!=-1))
                {
                  throw HalconCpp::HException((("One of the parameters is refferring to a non-existing object model 3D:\n"+HTuple(GenParamName[PosIdx]))+" -> ")+HTuple(GenParamValue[PosIdx]));
                }
              }
              }
            }
            }
            //Test for non-existing extended attributes:
            TupleStrstr(GenParamName, "intensity", &Position);
            {
            HTuple end_val33 = (Position.TupleLength())-1;
            HTuple step_val33 = 1;
            for (PosIdx=0; PosIdx.Continue(end_val33, step_val33); PosIdx += step_val33)
            {
              if (0 != (HTuple(Position[PosIdx])!=-1))
              {
                TupleSplit(HTuple(GenParamName[PosIdx]), "_", &Substrings);
                if (0 != (HTuple((Substrings.TupleLength())>1).TupleAnd(HTuple(Substrings[1]).TupleIsNumber())))
                {
                  I = HTuple(Substrings[1]).TupleNumber();
                  GetObjectModel3dParams(HTuple(ObjectModel3DID[I]), "has_extended_attribute",
                      &HasExtended);
                  if (0 != HasExtended)
                  {
                    GetObjectModel3dParams(HTuple(ObjectModel3DID[I]), "extended_attribute_names",
                        &ExtendedAttributeNames);
                    TupleFind(ExtendedAttributeNames, HTuple(GenParamValue[PosIdx]),
                        &Matches);
                  }
                  if (0 != (HTuple(HasExtended.TupleNot()).TupleOr(HTuple(Matches==-1).TupleOr((Matches.TupleLength())==0))))
                  {
                    throw HalconCpp::HException((((("One of the parameters is refferring to an extended attribute that is not contained in the object model 3d with the handle "+HTuple(ObjectModel3DID[I]))+":\n")+HTuple(GenParamName[PosIdx]))+" -> ")+HTuple(GenParamValue[PosIdx]));
                  }
                }
                else
                {
                  {
                  HTuple end_val47 = (ObjectModel3DID.TupleLength())-1;
                  HTuple step_val47 = 1;
                  for (I=0; I.Continue(end_val47, step_val47); I += step_val47)
                  {
                    GetObjectModel3dParams(HTuple(ObjectModel3DID[I]), "extended_attribute_names",
                        &ExtendedAttributeNames);
                    TupleFind(ExtendedAttributeNames, HTuple(GenParamValue[PosIdx]),
                        &Matches);
                    if (0 != (HTuple(Matches==-1).TupleOr((Matches.TupleLength())==0)))
                    {
                      throw HalconCpp::HException((("One of the parameters is refferring to an extended attribute that is not contained in all object models:\n"+HTuple(GenParamName[PosIdx]))+" -> ")+HTuple(GenParamValue[PosIdx]));
                    }
                  }
                  }
                }
              }
            }
            }
            //
            throw HalconCpp::HException((HTuple("Wrong generic parameters for display\n")+"Wrong Values are:\n")+((((("    "+((GenParamName+" -> ")+GenParamValue))+"\n").TupleSum())+"Exeption was:\n    ")+HTuple(Exception[2])));
          }
          else
          {
            throw HalconCpp::HException(Exception);
          }
        }
        else if (0 != (HTuple(HTuple(HTuple(Exception[0])==5185).TupleOr(HTuple(Exception[0])==5188)).TupleOr(HTuple(Exception[0])==5187)))
        {
          ExpTmpLocalVar_gUsesOpenGL = "false";
          ExpSetGlobalVar_gUsesOpenGL(ExpTmpLocalVar_gUsesOpenGL);
        }
        else
        {
          throw HalconCpp::HException(Exception);
        }
      }
    }
    if (0 != (ExpGetGlobalVar_gUsesOpenGL()==HTuple("false")))
    {
      //* NO OpenGL, use fallback
      disp_object_model_no_opengl(&ModelContours, ObjectModel3DID, GenParamName,
          GenParamValue, WindowHandleBuffer, CamParam, Poses);
    }
  }
  else
  {
    {
    HTuple end_val74 = (AlphaOrig.TupleLength())-1;
    HTuple step_val74 = 1;
    for (Index=0; Index.Continue(end_val74, step_val74); Index += step_val74)
    {
      if (0 != (HTuple(SelectedObject[Index])==1))
      {
        SetScene3dInstanceParam(Scene3D, Index, "alpha", HTuple(AlphaOrig[Index]));
      }
      else
      {
        SetScene3dInstanceParam(Scene3D, Index, "alpha", ExpGetGlobalVar_gAlphaDeselected());
      }
    }
    }
    try
    {
      if (0 != (ExpGetGlobalVar_gUsesOpenGL()==HTuple("false")))
      {
        throw HalconCpp::HException(HTuple());
      }
      DisplayScene3d(WindowHandleBuffer, Scene3D, 0);
    }
    // catch (Exception1)
    catch (HalconCpp::HException &HDevExpDefaultException)
    {
      HDevExpDefaultException.ToHTuple(&Exception1);
      //* NO OpenGL, use fallback
      DeselectedIdx = SelectedObject.TupleFind(0);
      if (0 != (DeselectedIdx!=-1))
      {
        DeselectedName = "color_"+DeselectedIdx;
        DeselectedValue = HTuple(DeselectedName.TupleLength(),"gray");
      }
      disp_object_model_no_opengl(&ModelContours, ObjectModel3DID, GenParamName.TupleConcat(DeselectedName),
          GenParamValue.TupleConcat(DeselectedValue), WindowHandleBuffer,
          CamParam, Poses);
    }
    {
    HTuple end_val95 = (AlphaOrig.TupleLength())-1;
    HTuple step_val95 = 1;
    for (Index=0; Index.Continue(end_val95, step_val95); Index += step_val95)
    {
      SetScene3dInstanceParam(Scene3D, Index, "alpha", HTuple(AlphaOrig[Index]));
    }
    }
  }
  DumpWindowImage(&Image, WindowHandleBuffer);
  //
  //Display labels
  if (0 != (Labels!=0))
  {
    SetColor(WindowHandleBuffer, HTuple(ExpGetGlobalVar_gLabelsDecor()[0]));
    {
    HTuple end_val104 = (ObjectModel3DID.TupleLength())-1;
    HTuple step_val104 = 1;
    for (Index=0; Index.Continue(end_val104, step_val104); Index += step_val104)
    {
      //Project the center point of the current model
      Pose = Poses.TupleSelectRange(Index*7,(Index*7)+6);
      PoseToHomMat3d(Pose, &HomMat3D);
      GetObjectModel3dParams(HTuple(ObjectModel3DID[Index]), "center", &Center);
      AffineTransPoint3d(HomMat3D, HTuple(Center[0]), HTuple(Center[1]),
          HTuple(Center[2]), &CenterCamX, &CenterCamY, &CenterCamZ);
      Project3dPoint(CenterCamX, CenterCamY, CenterCamZ, CamParam, &CenterRow,
          &CenterCol);
      Label = ((const HTuple&)Labels)[Index];
      if (0 != (Label!=HTuple("")))
      {
        GetStringExtents(WindowHandleBuffer, Label, &Ascent, &Descent,
            &TextWidth, &TextHeight);
        disp_message(WindowHandleBuffer, Label, "window", (CenterRow-(TextHeight/2))+HTuple(ExpGetGlobalVar_gDispObjOffset()[0]),
            (CenterCol-(TextWidth/2))+HTuple(ExpGetGlobalVar_gDispObjOffset()[1]),
            HTuple(), HTuple(ExpGetGlobalVar_gLabelsDecor()[1]));
      }
    }
    }
  }
  //
  //Visualize the trackball if desired
  if (0 != VisualizeTrackball)
  {
    SetLineWidth(WindowHandleBuffer, 1);
    GenEllipseContourXld(&TrackballContour, TrackballCenterRow, TrackballCenterCol,
        0, TrackballRadiusPixel, TrackballRadiusPixel, 0, 6.28318, "positive",
        1.5);
    SetColor(WindowHandleBuffer, "dim gray");
    DispXld(TrackballContour, WindowHandleBuffer);
  }
  //
  //Visualize the rotation center if desired
  if (0 != (HTuple(VisualizeRotationCenter!=0).TupleAnd((RotationCenter.TupleLength())==3)))
  {
    if (0 != (HTuple(RotationCenter[2])<1e-10))
    {
      RotationCenter[2] = 1e-10;
    }
    Project3dPoint(HTuple(RotationCenter[0]), HTuple(RotationCenter[1]), HTuple(RotationCenter[2]),
        CamParam, &RotCenterRow, &RotCenterCol);
    Orientation = HTuple(90).TupleRad();
    if (0 != (VisualizeRotationCenter==1))
    {
      Orientation = HTuple(45).TupleRad();
    }
    GenCrossContourXld(&CrossRotCenter, RotCenterRow, RotCenterCol, TrackballRadiusPixel/25.0,
        Orientation);
    SetLineWidth(WindowHandleBuffer, 3);
    QueryColor(WindowHandleBuffer, &Colors);
    SetColor(WindowHandleBuffer, "light gray");
    DispXld(CrossRotCenter, WindowHandleBuffer);
    SetLineWidth(WindowHandleBuffer, 1);
    SetColor(WindowHandleBuffer, "dim gray");
    DispXld(CrossRotCenter, WindowHandleBuffer);
  }
  //
  //Display title
  disp_title_and_information(WindowHandleBuffer, Title, Information);
  //
  //Display the 'Exit' button
  if (0 != (DisplayContinueButton==HTuple("true")))
  {
    disp_continue_button(WindowHandleBuffer);
  }
  //
  return;
}

// Chapter: Graphics / Output
// Short Description: Get the center of the virtual trackback that is used to move the camera.
void get_trackball_center (HTuple SelectedObject, HTuple TrackballRadiusPixel,
    HTuple ObjectModel3D, HTuple Poses, HTuple *TBCenter, HTuple *TBSize)
{

  // Local iconic variables

  // Local control variables
  HTuple  NumModels, Centers, Diameter;
  HTuple  MD, Weight, SumW, Index, ObjectModel3DIDSelected;
  HTuple  PoseSelected, HomMat3D, TBCenterCamX, TBCenterCamY;
  HTuple  TBCenterCamZ, InvSum;

  NumModels = ObjectModel3D.TupleLength();
  (*TBCenter)[0] = 0;
  (*TBCenter)[1] = 0;
  (*TBCenter)[2] = 0;
  GetObjectModel3dParams(ObjectModel3D, "center", &Centers);
  GetObjectModel3dParams(ObjectModel3D, "diameter_axis_aligned_bounding_box",
      &Diameter);
  //Normalize Diameter to use it as weights for a weighted mean of the individual centers
  MD = Diameter.TupleMean();
  if (0 != (MD>1e-10))
  {
    Weight = Diameter/MD;
  }
  else
  {
    Weight = Diameter;
  }
  SumW = (Weight.TupleSelectMask((SelectedObject.TupleSgn()).TupleAbs())).TupleSum();
  if (0 != (SumW<1e-10))
  {
    Weight = HTuple(Weight.TupleLength(),1.0);
    SumW = (Weight.TupleSelectMask((SelectedObject.TupleSgn()).TupleAbs())).TupleSum();
  }
  {
  HTuple end_val18 = NumModels-1;
  HTuple step_val18 = 1;
  for (Index=0; Index.Continue(end_val18, step_val18); Index += step_val18)
  {
    if (0 != (HTuple(SelectedObject[Index])))
    {
      ObjectModel3DIDSelected = ((const HTuple&)ObjectModel3D)[Index];
      PoseSelected = Poses.TupleSelectRange(Index*7,(Index*7)+6);
      PoseToHomMat3d(PoseSelected, &HomMat3D);
      AffineTransPoint3d(HomMat3D, HTuple(Centers[(Index*3)+0]), HTuple(Centers[(Index*3)+1]),
          HTuple(Centers[(Index*3)+2]), &TBCenterCamX, &TBCenterCamY,
          &TBCenterCamZ);
      (*TBCenter)[0] = HTuple((*TBCenter)[0])+(TBCenterCamX*HTuple(Weight[Index]));
      (*TBCenter)[1] = HTuple((*TBCenter)[1])+(TBCenterCamY*HTuple(Weight[Index]));
      (*TBCenter)[2] = HTuple((*TBCenter)[2])+(TBCenterCamZ*HTuple(Weight[Index]));
    }
  }
  }
  if (0 != ((SelectedObject.TupleMax())!=0))
  {
    InvSum = 1.0/SumW;
    (*TBCenter)[0] = HTuple((*TBCenter)[0])*InvSum;
    (*TBCenter)[1] = HTuple((*TBCenter)[1])*InvSum;
    (*TBCenter)[2] = HTuple((*TBCenter)[2])*InvSum;
    (*TBSize) = (0.5+((0.5*(SelectedObject.TupleSum()))/NumModels))*TrackballRadiusPixel;
  }
  else
  {
    (*TBCenter) = HTuple();
    (*TBSize) = 0;
  }
  return;
}

// Chapter: Tuple / Arithmetic
// Short Description: Calculates the cross product of two vectors of length 3.
void tuple_vector_cross_product (HTuple V1, HTuple V2, HTuple *VC)
{

  // Local iconic variables

  //The caller must ensure that the length of both input vectors is 3
  (*VC) = (HTuple(V1[1])*HTuple(V2[2]))-(HTuple(V1[2])*HTuple(V2[1]));
  (*VC) = (*VC).TupleConcat((HTuple(V1[2])*HTuple(V2[0]))-(HTuple(V1[0])*HTuple(V2[2])));
  (*VC) = (*VC).TupleConcat((HTuple(V1[0])*HTuple(V2[1]))-(HTuple(V1[1])*HTuple(V2[0])));
  return;
}

// Chapter: Graphics / Output
// Short Description: Compute the 3d rotation from the mose movement
void trackball (HTuple MX1, HTuple MY1, HTuple MX2, HTuple MY2, HTuple VirtualTrackball,
    HTuple TrackballSize, HTuple SensFactor, HTuple *QuatRotation)
{

  // Local iconic variables

  // Local control variables
  HTuple  D, P2, P1, T, RotAngle;
  HTuple  Len, RotAxis;

  //Compute the 3d rotation from the mouse movement
  //
  if (0 != (HTuple(MX1==MX2).TupleAnd(MY1==MY2)))
  {
    (*QuatRotation).Clear();
    (*QuatRotation)[0] = 1;
    (*QuatRotation)[1] = 0;
    (*QuatRotation)[2] = 0;
    (*QuatRotation)[3] = 0;
    return;
  }
  //Project the image point onto the trackball
  project_point_on_trackball(MX1, MY1, VirtualTrackball, TrackballSize,
      &P1);
  project_point_on_trackball(MX2, MY2, VirtualTrackball, TrackballSize,
      &P2);
  //The cross product of the projected points defines the rotation axis
  tuple_vector_cross_product(P1, P2, &RotAxis);
  //Compute the rotation angle
  D = P2-P1;
  T = (((D*D).TupleSum()).TupleSqrt())/(2.0*TrackballSize);
  if (0 != (T>1.0))
  {
    T = 1.0;
  }
  if (0 != (T<-1.0))
  {
    T = -1.0;
  }
  RotAngle = (2.0*(T.TupleAsin()))*SensFactor;
  Len = ((RotAxis*RotAxis).TupleSum()).TupleSqrt();
  if (0 != (Len>0.0))
  {
    RotAxis = RotAxis/Len;
  }
  AxisAngleToQuat(HTuple(RotAxis[0]), HTuple(RotAxis[1]), HTuple(RotAxis[2]),
      RotAngle, &(*QuatRotation));
  return;
}

// Chapter: Graphics / Output
// Short Description: Get string extends of several lines.
void max_line_width (HTuple WindowHandle, HTuple Lines, HTuple *MaxWidth)
{

  // Local iconic variables

  // Local control variables
  HTuple  Index, Ascent, Descent, LineWidth;
  HTuple  LineHeight;

  (*MaxWidth) = 0;
  {
  HTuple end_val1 = (Lines.TupleLength())-1;
  HTuple step_val1 = 1;
  for (Index=0; Index.Continue(end_val1, step_val1); Index += step_val1)
  {
    GetStringExtents(WindowHandle, HTuple(Lines[Index]), &Ascent, &Descent,
        &LineWidth, &LineHeight);
    (*MaxWidth) = (LineWidth.TupleConcat((*MaxWidth))).TupleMax();
  }
  }
  return;
}

// Chapter: Graphics / Output
// Short Description: Compute the center of all given 3D object models.
void get_object_models_center (HTuple ObjectModel3DID, HTuple *Center)
{

  // Local iconic variables

  // Local control variables
  HTuple  Diameter, MD, Weight, SumW;
  HTuple  Index, ObjectModel3DIDSelected, C, InvSum;

  //Compute the mean of all model centers (weighted by the diameter of the object models)
  if (0 != ((ObjectModel3DID.TupleLength())>0))
  {
    GetObjectModel3dParams(ObjectModel3DID, "diameter_axis_aligned_bounding_box",
        &Diameter);
    //Normalize Diameter to use it as weights for a weighted mean of the individual centers
    MD = Diameter.TupleMean();
    if (0 != (MD>1e-10))
    {
      Weight = Diameter/MD;
    }
    else
    {
      Weight = Diameter;
    }
    SumW = Weight.TupleSum();
    if (0 != (SumW<1e-10))
    {
      Weight = HTuple(Weight.TupleLength(),1.0);
      SumW = Weight.TupleSum();
    }
    (*Center).Clear();
    (*Center)[0] = 0;
    (*Center)[1] = 0;
    (*Center)[2] = 0;
    {
    HTuple end_val16 = (ObjectModel3DID.TupleLength())-1;
    HTuple step_val16 = 1;
    for (Index=0; Index.Continue(end_val16, step_val16); Index += step_val16)
    {
      ObjectModel3DIDSelected = ((const HTuple&)ObjectModel3DID)[Index];
      GetObjectModel3dParams(ObjectModel3DIDSelected, "center", &C);
      (*Center)[0] = HTuple((*Center)[0])+(HTuple(C[0])*HTuple(Weight[Index]));
      (*Center)[1] = HTuple((*Center)[1])+(HTuple(C[1])*HTuple(Weight[Index]));
      (*Center)[2] = HTuple((*Center)[2])+(HTuple(C[2])*HTuple(Weight[Index]));
    }
    }
    InvSum = 1.0/SumW;
    (*Center)[0] = HTuple((*Center)[0])*InvSum;
    (*Center)[1] = HTuple((*Center)[1])*InvSum;
    (*Center)[2] = HTuple((*Center)[2])*InvSum;
  }
  else
  {
    (*Center) = HTuple();
  }
  return;
}

// Chapter: Graphics / Output
// Short Description: Displays a continue button.
void disp_continue_button (HTuple WindowHandle)
{

  // Local iconic variables

  // Local control variables
  HTuple  ContinueMessage, Exception, Row;
  HTuple  Column, Width, Height, Ascent, Descent;
  HTuple  TextWidth, TextHeight;

  //This procedure displays a 'Continue' text button
  //in the lower right corner of the screen.
  //It uses the procedure disp_message.
  //
  //Input parameters:
  //WindowHandle: The window, where the text shall be displayed
  //
  //Use the continue message set in the global variable gTerminationButtonLabel.
  //If this variable is not defined, set a standard text instead.
  //global tuple gTerminationButtonLabel
  try
  {
    ContinueMessage = ExpGetGlobalVar_gTerminationButtonLabel();
  }
  // catch (Exception)
  catch (HalconCpp::HException &HDevExpDefaultException)
  {
    HDevExpDefaultException.ToHTuple(&Exception);
    ContinueMessage = "Continue";
  }
  //Display the continue button
  GetWindowExtents(WindowHandle, &Row, &Column, &Width, &Height);
  GetStringExtents(WindowHandle, (" "+ContinueMessage)+" ", &Ascent, &Descent,
      &TextWidth, &TextHeight);
  disp_text_button(WindowHandle, ContinueMessage, "window", (Height-TextHeight)-12,
      (Width-TextWidth)-12, "black", "#f28f26");
  return;
}

// Chapter: Graphics / Parameters
void color_string_to_rgb (HTuple Color, HTuple *RGB)
{

  // Local iconic variables
  HObject  Rectangle, Image;

  // Local control variables
  HTuple  WindowHandleBuffer, Exception;

  OpenWindow(0, 0, 1, 1, 0, "buffer", "", &WindowHandleBuffer);
  SetPart(WindowHandleBuffer, 0, 0, -1, -1);
  GenRectangle1(&Rectangle, 0, 0, 0, 0);
  try
  {
    SetColor(WindowHandleBuffer, Color);
  }
  // catch (Exception)
  catch (HalconCpp::HException &HDevExpDefaultException)
  {
    HDevExpDefaultException.ToHTuple(&Exception);
    Exception = "Wrong value of control parameter Color (must be a valid color string)";
    throw HalconCpp::HException(Exception);
  }
  DispObj(Rectangle, WindowHandleBuffer);
  DumpWindowImage(&Image, WindowHandleBuffer);
  CloseWindow(WindowHandleBuffer);
  GetGrayval(Image, 0, 0, &(*RGB));
  (*RGB) += ((HTuple(0).Append(0)).Append(0));
  return;
}

// Chapter: Graphics / Output
// Short Description: Get the center of the virtual trackback that is used to move the camera (version for inspection_mode = 'surface').
void get_trackball_center_fixed (HTuple SelectedObject, HTuple TrackballCenterRow,
    HTuple TrackballCenterCol, HTuple TrackballRadiusPixel, HTuple Scene3D,
    HTuple ObjectModel3DID, HTuple Poses, HTuple WindowHandleBuffer, HTuple CamParam,
    HTuple GenParamName, HTuple GenParamValue, HTuple *TBCenter, HTuple *TBSize)
{

  // Local iconic variables
  HObject  RegionCenter, DistanceImage, Domain;

  // Local control variables
  HTuple  NumModels, Width, Height, SelectPose;
  HTuple  Index1, Rows, Columns, Grayval, IndicesG;
  HTuple  Value, Pos;

  //Determine the trackball center for the fixed trackball
  NumModels = ObjectModel3DID.TupleLength();
  Width = ((const HTuple&)CamParam)[(CamParam.TupleLength())-2];
  Height = ((const HTuple&)CamParam)[(CamParam.TupleLength())-1];
  //
  //Project the selected objects
  SelectPose = HTuple();
  {
  HTuple end_val7 = (SelectedObject.TupleLength())-1;
  HTuple step_val7 = 1;
  for (Index1=0; Index1.Continue(end_val7, step_val7); Index1 += step_val7)
  {
    SelectPose = SelectPose.TupleConcat(HTuple(7,HTuple(SelectedObject[Index1])));
    if (0 != (HTuple(SelectedObject[Index1])==0))
    {
      SetScene3dInstanceParam(Scene3D, Index1, "visible", "false");
    }
  }
  }
  SetScene3dParam(Scene3D, "depth_persistence", "true");
  DisplayScene3d(WindowHandleBuffer, Scene3D, 0);
  SetScene3dParam(Scene3D, "visible", "true");
  //
  //determine the depth of the object point that appears closest to the trackball
  //center
  GenRegionPoints(&RegionCenter, TrackballCenterRow, TrackballCenterCol);
  DistanceTransform(RegionCenter, &DistanceImage, "chamfer-3-4-unnormalized",
      "false", Width, Height);
  GetDomain(DistanceImage, &Domain);
  GetRegionPoints(Domain, &Rows, &Columns);
  GetGrayval(DistanceImage, Rows, Columns, &Grayval);
  TupleSortIndex(Grayval, &IndicesG);
  GetDisplayScene3dInfo(WindowHandleBuffer, Scene3D, Rows.TupleSelect(IndicesG),
      Columns.TupleSelect(IndicesG), "depth", &Value);
  TupleFind(Value.TupleSgn(), 1, &Pos);
  //
  SetScene3dParam(Scene3D, "depth_persistence", "false");
  //
  //
  //set TBCenter
  if (0 != (Pos!=-1))
  {
    //if the object is visible in the image
    (*TBCenter).Clear();
    (*TBCenter)[0] = 0;
    (*TBCenter)[1] = 0;
    (*TBCenter).Append(HTuple(Value[HTuple(Pos[0])]));
  }
  else
  {
    //if the object is not visible in the image, set the z coordinate to -1
    //to indicate, the the previous z value should be used instead
    (*TBCenter).Clear();
    (*TBCenter)[0] = 0;
    (*TBCenter)[1] = 0;
    (*TBCenter)[2] = -1;
  }
  //
  if (0 != ((SelectedObject.TupleMax())!=0))
  {
    (*TBSize) = (0.5+((0.5*(SelectedObject.TupleSum()))/NumModels))*TrackballRadiusPixel;
  }
  else
  {
    (*TBCenter) = HTuple();
    (*TBSize) = 0;
  }
  return;
}

void disp_message (HTuple WindowHandle, HTuple String, HTuple CoordSystem,
    HTuple Row, HTuple Column, HTuple Color, HTuple Box)
{

  // Local iconic variables

  // Local control variables
  HTuple  Red, Green, Blue, Row1Part;
  HTuple  Column1Part, Row2Part, Column2Part, RowWin;
  HTuple  ColumnWin, WidthWin, HeightWin, MaxAscent;
  HTuple  MaxDescent, MaxWidth, MaxHeight, R1;
  HTuple  C1, FactorRow, FactorColumn, UseShadow;
  HTuple  ShadowColor, Exception, Width, Index;
  HTuple  Ascent, Descent, W, H, FrameHeight;
  HTuple  FrameWidth, R2, C2, DrawMode, CurrentColor;

  //Prepare window
  GetRgb(WindowHandle, &Red, &Green, &Blue);
  GetPart(WindowHandle, &Row1Part, &Column1Part, &Row2Part, &Column2Part);
  GetWindowExtents(WindowHandle, &RowWin, &ColumnWin, &WidthWin, &HeightWin);
  SetPart(WindowHandle, 0, 0, HeightWin-1, WidthWin-1);
  //
  //default settings
  if (0 != (Row==-1))
  {
    Row = 12;
  }
  if (0 != (Column==-1))
  {
    Column = 12;
  }
  if (0 != (Color==HTuple()))
  {
    Color = "";
  }
  //
  String = ((""+String)+"").TupleSplit("\n");
  //
  //Estimate extentions of text depending on font size.
  GetFontExtents(WindowHandle, &MaxAscent, &MaxDescent, &MaxWidth, &MaxHeight);
  if (0 != (CoordSystem==HTuple("window")))
  {
    R1 = Row;
    C1 = Column;
  }
  else
  {
    //Transform image to window coordinates
    FactorRow = (1.*HeightWin)/((Row2Part-Row1Part)+1);
    FactorColumn = (1.*WidthWin)/((Column2Part-Column1Part)+1);
    R1 = ((Row-Row1Part)+0.5)*FactorRow;
    C1 = ((Column-Column1Part)+0.5)*FactorColumn;
  }
  //
  //Display text box depending on text size
  UseShadow = 1;
  ShadowColor = "gray";
  if (0 != (HTuple(Box[0])==HTuple("true")))
  {
    Box[0] = "#fce9d4";
    ShadowColor = "#f28d26";
  }
  if (0 != ((Box.TupleLength())>1))
  {
    if (0 != (HTuple(Box[1])==HTuple("true")))
    {
      //Use default ShadowColor set above
    }
    else if (0 != (HTuple(Box[1])==HTuple("false")))
    {
      UseShadow = 0;
    }
    else
    {
      ShadowColor = ((const HTuple&)Box)[1];
      //Valid color?
      try
      {
        SetColor(WindowHandle, HTuple(Box[1]));
      }
      // catch (Exception)
      catch (HalconCpp::HException &HDevExpDefaultException)
      {
        HDevExpDefaultException.ToHTuple(&Exception);
        Exception = "Wrong value of control parameter Box[1] (must be a 'true', 'false', or a valid color string)";
        throw HalconCpp::HException(Exception);
      }
    }
  }
  if (0 != (HTuple(Box[0])!=HTuple("false")))
  {
    //Valid color?
    try
    {
      SetColor(WindowHandle, HTuple(Box[0]));
    }
    // catch (Exception)
    catch (HalconCpp::HException &HDevExpDefaultException)
    {
      HDevExpDefaultException.ToHTuple(&Exception);
      Exception = "Wrong value of control parameter Box[0] (must be a 'true', 'false', or a valid color string)";
      throw HalconCpp::HException(Exception);
    }
    //Calculate box extents
    String = (" "+String)+" ";
    Width = HTuple();
    {
    HTuple end_val93 = (String.TupleLength())-1;
    HTuple step_val93 = 1;
    for (Index=0; Index.Continue(end_val93, step_val93); Index += step_val93)
    {
      GetStringExtents(WindowHandle, HTuple(String[Index]), &Ascent,
          &Descent, &W, &H);
      Width = Width.TupleConcat(W);
    }
    }
    FrameHeight = MaxHeight*(String.TupleLength());
    FrameWidth = (HTuple(0).TupleConcat(Width)).TupleMax();
    R2 = R1+FrameHeight;
    C2 = C1+FrameWidth;
    //Display rectangles
    GetDraw(WindowHandle, &DrawMode);
    SetDraw(WindowHandle, "fill");
    //Set shadow color
    SetColor(WindowHandle, ShadowColor);
    if (0 != UseShadow)
    {
      DispRectangle1(WindowHandle, R1+1, C1+1, R2+1, C2+1);
    }
    //Set box color
    SetColor(WindowHandle, HTuple(Box[0]));
    DispRectangle1(WindowHandle, R1, C1, R2, C2);
    SetDraw(WindowHandle, DrawMode);
  }
  //Write text.
  {
  HTuple end_val115 = (String.TupleLength())-1;
  HTuple step_val115 = 1;
  for (Index=0; Index.Continue(end_val115, step_val115); Index += step_val115)
  {
    CurrentColor = ((const HTuple&)Color)[Index%(Color.TupleLength())];
    if (0 != (HTuple(CurrentColor!=HTuple("")).TupleAnd(CurrentColor!=HTuple("auto"))))
    {
      SetColor(WindowHandle, CurrentColor);
    }
    else
    {
      SetRgb(WindowHandle, Red, Green, Blue);
    }
    Row = R1+(MaxHeight*Index);
    SetTposition(WindowHandle, Row, C1);
    WriteString(WindowHandle, HTuple(String[Index]));
  }
  }
  //Reset changed window settings
  SetRgb(WindowHandle, Red, Green, Blue);
  SetPart(WindowHandle, Row1Part, Column1Part, Row2Part, Column2Part);
  return;
}






4.添加显示按钮

void MainWindow::on_pushButton_clicked()
{
    //QString  FileName= QFileDialog::getOpenFileName()

    // Local control variables
    HTuple  hv_GenParamNames;
    HTuple  hv_GenParamValues, hv_ObjectModel3D, hv_Status;
    HTuple  hv_CamParam,hv_DisPose, hv_DispPose1,hv_GenParNames, hv_GenParValues;

    qDebug()<<"01";
    ReadObjectModel3d("object55.om3", "mm", HTuple(), HTuple(), &hv_ObjectModel3D,&hv_Status);
    qDebug()<<"02";
    GenNewWindowHandle(WindowHandle3D);

    hv_CamParam.Clear();
    hv_CamParam[0] = 0.01;
    hv_CamParam[1] = 0;
    hv_CamParam[2] = 7e-6;
    hv_CamParam[3] = 7e-6;
    hv_CamParam.Append(800/2);
    hv_CamParam.Append(500/2);
    hv_CamParam.Append(800);  //661, 761
    hv_CamParam.Append(500);
    hv_DisPose.Clear();
    hv_DisPose[0] = 30.427;
    hv_DisPose[1] = -1.05274;
    hv_DisPose[2] = 97.8798;
    hv_DisPose[3] = 8.29326;
    hv_DisPose[4] = 356.416;
    hv_DisPose[5] = 99.016;
    hv_DisPose[6] = 0;


    if(DisPlayMode==0) // 单色静态
    {
        //单色显示
        hv_GenParNames.Clear();
        hv_GenParNames[0] = "color_0";
        hv_GenParNames[1] = "alpha";
        hv_GenParValues.Clear();
        hv_GenParValues[0] = "cyan";
        hv_GenParValues[1] = 0.7;
        DispObjectModel3d(WindowHandle3D, hv_ObjectModel3D, hv_CamParam, hv_DisPose, hv_GenParamNames,
            hv_GenParamValues);
    }

    if(DisPlayMode==1)  //rgb
    {
        //单色显示
        hv_GenParamNames.Clear();
        hv_GenParamNames[0] = "lut";
        hv_GenParamNames[1] = "intensity";
        hv_GenParamNames[2] = "light_position";
        hv_GenParamNames[3] = "disp_pose";
        hv_GenParamNames[4] = "alpha";
        hv_GenParamValues.Clear();
        hv_GenParamValues[0] = "color1";
        hv_GenParamValues[1] = "coord_z";
        hv_GenParamValues[2] = "0.0 0.0 -0.3 1.0";
        hv_GenParamValues[3] = "true";
        hv_GenParamValues[4] = 1;
        DispObjectModel3d(WindowHandle3D, hv_ObjectModel3D, hv_CamParam, hv_DisPose, hv_GenParamNames,
            hv_GenParamValues);
    }

    if(DisPlayMode==2)
    {
        //单色显示
        hv_GenParNames.Clear();
        hv_GenParNames[0] = "color_0";
        hv_GenParNames[1] = "alpha";
        hv_GenParValues.Clear();
        hv_GenParValues[0] = "green";
        hv_GenParValues[1] = 0.7;
        visualize_object_model_3d(WindowHandle3D, hv_ObjectModel3D, hv_CamParam, hv_DisPose,
            hv_GenParNames, hv_GenParValues, HTuple(), HTuple(), HTuple(), &hv_DispPose1);

    }




    //hv_DispPose  保存 下来    与 后续剪切  的视角有关
     qDebug()<<"03";
}


5.显示更新窗口函数

在显示之前添加此函数,需要更新窗口,否则会卡死

//  函数2  输出窗口
void MainWindow::GenNewWindowHandle(HTuple &WindowHandle)
{
    HObject  Image; HTuple width,height;
    // 设计模板
    try  { ReadImage(&Image, "./data/model/background.png"); }
    catch(...)
    {
        // QMessageBox::warning(this,"提示","background.png not exist!");
    }
    WId winID = ui->graphicsView->winId();
    HTuple fartherWid = (Hlong)winID;
    width=ui->graphicsView->width();
    height=ui->graphicsView->height();
    CloseWindow(WindowHandle3D);
    dev_open_window_fit_image(Image, width,height,0, 0, -1, -1,&WindowHandle3D,fartherWid);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值