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 variablesHTuple 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 HeightLimitif (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 windowSetWindowAttr("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 hdevelopreturn;
}// 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 variablesHTuple 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 hdevelopif (0 != (HTuple(Size==HTuple()).TupleOr(Size==-1))){Size = 16;}if (0 != ((OS.TupleSubstr(0,2))==HTuple("Win"))){//Set font on Windows systemstry{//Check, if font scaling is switched onOpenWindow(0, 0, 256, 256, 0, "buffer", "", &BufferWindowHandle);SetFont(BufferWindowHandle, "-Consolas-16-*-0-*-*-1-");GetStringExtents(BufferWindowHandle, "test_string", &Ascent, &Descent,&Width, &Height);//Expected width is 110Scale = 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 fontGuess.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 fontGuess.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 fontGuess.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 systemsSize = 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 hdevelopreturn;
}// Chapter: Graphics / Output
void disp_title_and_information (HTuple WindowHandle, HTuple Title, HTuple Information)
{// Local iconic variables// Local control variablesHTuple 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 variablesHTuple 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 zCenterX = ((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 variablesHObject Image, ImageDump;// Local control variablesHTuple 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, CExpTmpLocalVar_gDispObjOffset.Clear();ExpTmpLocalVar_gDispObjOffset[0] = -30;ExpTmpLocalVar_gDispObjOffset[1] = 0;ExpSetGlobalVar_gDispObjOffset(ExpTmpLocalVar_gDispObjOffset);////Customize the decoration of the different text elements// Color, BoxExpTmpLocalVar_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 selectedExpTmpLocalVar_gAlphaDeselected = 0.3;ExpSetGlobalVar_gAlphaDeselected(ExpTmpLocalVar_gAlphaDeselected);//Customize the label of the continue buttonExpTmpLocalVar_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 anymoreMaxNumModels = 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 valuesNumModels = 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 hdevelopGetSystem("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 allowedthrow 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 objectif (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 objectget_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 flickeringOpenWindow(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 allowedthrow 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 trackballMinImageSize = (Width.TupleConcat(Height)).TupleMin();TrackballRadiusPixel = (TrackballSize*MinImageSize)/2.0;////Measure the text extents for the continue button in the//graphics windowGetStringExtents(WindowHandleBuffer, ExpGetGlobalVar_gTerminationButtonLabel()+" ",&Ascent, &Descent, &TextWidth, &TextHeight);////Store background imageif (0 != (DispBackground==HTuple("false"))){ClearWindow(WindowHandle);}DumpWindowImage(&Image, WindowHandle);//Special treatment for color background images necessaryCountChannels(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 parametersSetLight = GenParamName.TupleRegexpTest("light_");if (0 != SetLight){//set position of light sourceIndices = GenParamName.TupleFind("light_position");if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple()))){//If multiple light positions are given, use the last oneLightParam = (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 supportedRemoveScene3dLight(Scene3D, 0);AddScene3dLight(Scene3D, LightPosition, LightKind, &LightIndex);TupleRemove(GenParamName, Indices, &GenParamName);TupleRemove(GenParamValue, Indices, &GenParamValue);}//set ambient part of light sourceIndices = GenParamName.TupleFind("light_ambient");if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple()))){//If the ambient part is set multiple times, use the last settingLightParam = (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 sourceIndices = GenParamName.TupleFind("light_diffuse");if (0 != (HTuple(Indices!=-1).TupleAnd(Indices!=HTuple()))){//If the diffuse part is set multiple times, use the last settingLightParam = (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//procedurePersistenceParamName = HTuple();PersistenceParamValue = HTuple();//set position of light sourceIndices = 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_paramGetParamInfo("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_paramUseParam = 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_paramParamNameTrunk = 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 parametersif (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 loopPoseToHomMat3d(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 windowTrackballCenterRow = 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 eventsGraphEvent = 0;Exit = 0;while (0 != 1){////Check graphic eventtry{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 releasedif (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 loopif (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 sceneif (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 poseif (0 != ExpGetGlobalVar_gIsSinglePose()){(*PoseOut) = Poses.TupleSelectRange(0,6);}else{(*PoseOut) = Poses;}////Clean upSetSystem("clip_region", ClipRegion);// dev_set_preferences(...); only in hdevelop// dev_set_preferences(...); only in hdevelop// dev_set_preferences(...); only in hdevelopdump_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 variablesHTuple 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 visualizedSeq = 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 objectsZAdd = 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 errorsif (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 projectionAffineTransPoint3d(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 viewHomMat3dRotateLocal(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 variablesHObject ImageDump;// Local control variablesHTuple 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 2CountSeconds(&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 objecttry{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 possiblereturn;}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 poseHomMat3dIdentity(&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 windowTrackballCenterRow = 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_3dExpTmpLocalVar_gIsSinglePose = 0;ExpSetGlobalVar_gIsSinglePose(ExpTmpLocalVar_gIsSinglePose);}CountChannels(BackgroundImage, &NumChannels);ColorImage = NumChannels==3;//Alt (32) => lower sensitivityTupleRsh(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-directionMRow1 = 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 distanceMRow1 = 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 onlyPoseToHomMat3d(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 objectMRow1 = 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 coordinatesMX1 = (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//movementtrackball(MX1, MY1, MX2, MY2, VirtualTrackball, TrackballSize,SensFactor, &RelQuaternion);//Transform the quaternion to a rotation matrixQuatToHomMat3d(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 onlyPoseToHomMat3d(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 variablesHTuple R, XP, YP, ZP;if (0 != (VirtualTrackball==HTuple("shoemake"))){//Virtual Trackball according to ShoemakeR = ((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 BellR = ((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 variablesHObject UpperLeft, LowerRight, Rectangle;// Local control variablesHTuple 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 windowGetRgb(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 settingsif (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 coordinatesFactorRow = (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 extentsString = (" "+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 rectanglesGetSystem("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 settingsSetRgb(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 variablesHObject ModelContours, Image, TrackballContour;HObject CrossRotCenter;// Local control variablesHTuple 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 imageClearWindow(WindowHandleBuffer);if (0 != ColorImage){DispColor(BackgroundImage, WindowHandleBuffer);}else{DispImage(BackgroundImage, WindowHandleBuffer);}////Display objectsif (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 fallbackdisp_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 fallbackDeselectedIdx = 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 labelsif (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 modelPose = 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 desiredif (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 desiredif (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 titledisp_title_and_information(WindowHandleBuffer, Title, Information);////Display the 'Exit' buttonif (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 variablesHTuple 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 centersMD = 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 variablesHTuple 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 trackballproject_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 axistuple_vector_cross_product(P1, P2, &RotAxis);//Compute the rotation angleD = 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 variablesHTuple 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 variablesHTuple 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 centersMD = 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 variablesHTuple 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 gTerminationButtonLabeltry{ContinueMessage = ExpGetGlobalVar_gTerminationButtonLabel();}// catch (Exception)catch (HalconCpp::HException &HDevExpDefaultException){HDevExpDefaultException.ToHTuple(&Exception);ContinueMessage = "Continue";}//Display the continue buttonGetWindowExtents(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 variablesHObject Rectangle, Image;// Local control variablesHTuple 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 variablesHObject RegionCenter, DistanceImage, Domain;// Local control variablesHTuple NumModels, Width, Height, SelectPose;HTuple Index1, Rows, Columns, Grayval, IndicesG;HTuple Value, Pos;//Determine the trackball center for the fixed trackballNumModels = ObjectModel3DID.TupleLength();Width = ((const HTuple&)CamParam)[(CamParam.TupleLength())-2];Height = ((const HTuple&)CamParam)[(CamParam.TupleLength())-1];////Project the selected objectsSelectPose = 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//centerGenRegionPoints(&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 TBCenterif (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 variablesHTuple 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 windowGetRgb(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 settingsif (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 coordinatesFactorRow = (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 sizeUseShadow = 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 extentsString = (" "+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 rectanglesGetDraw(WindowHandle, &DrawMode);SetDraw(WindowHandle, "fill");//Set shadow colorSetColor(WindowHandle, ShadowColor);if (0 != UseShadow){DispRectangle1(WindowHandle, R1+1, C1+1, R2+1, C2+1);}//Set box colorSetColor(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 settingsSetRgb(WindowHandle, Red, Green, Blue);SetPart(WindowHandle, Row1Part, Column1Part, Row2Part, Column2Part);return;
}
4.添加显示按钮
void MainWindow::on_pushButton_clicked()
{//QString FileName= QFileDialog::getOpenFileName()// Local control variablesHTuple 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, 761hv_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);}
相关文章:
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]*彩…...
css3伸缩盒模型第三章(伸缩相关)
伸缩盒模型第三章(伸缩) 介绍了伸缩性的伸缩提现到哪些方面,以及flex 居中的小技巧,视觉差异等 flex 水平垂直居中伸缩性flex 复合式属性项目排序侧轴单独对齐 flex 水平居中 我们可以使用flex 使元素居中对齐,当然也可以用 margin 等进行…...
【Ubuntu】安裝向日葵远程控制
前言 在Ubuntu 24.04.2下安装向日葵远程控制出错,少了一些依赖,需要安装一些依赖。 1.安装gconf2-common wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gconf/gconf2-common_3.2.6-6ubuntu1_all.deb sudo dpkg -i gconf2-common_3.2.6-6ub…...
Screeps Arena基础入门
本文主要内容 JavaSsript语法使用VScode编译环境Screeps Arena游戏规则 JavaSsript语法使用 基本数据类型 // String, Numker,Boolean,null, undefined const username "John"; const age 30; const rate 4.5; const iscool true; const x null; #表示值为…...
docker 安装 sqlserver2022 和注意点
一、前言 1、可以直接参考微软官方文档 快速入门:使用 Docker 运行 SQL Server Linux 容器映像,这里主要是说一些注意点和坑 二、安装 1、拉取镜像 docker pull mcr.microsoft.com/mssql/server:2022-latest2、创建挂载目录,这里只是比官方…...
Centos系统详解架构详解
CentOS 全面详解 一、CentOS 概述 CentOS(Community Enterprise Operating System) 是基于 Red Hat Enterprise Linux(RHEL) 源代码构建的免费开源操作系统,专注于稳定性、安全性和长期支持,广泛应用于服…...
Git实战经验分享:深入掌握git commit --amend的进阶技巧
一、工具简介 git commit --amend是Git版本控制系统的核心补救命令,主要用于修正最近一次提交的元数据。该命令不会产生新的提交记录,而是通过覆盖原提交实现版本历史的整洁性,特别适合在本地仓库进行提交优化。 二、核心应用场景 提交信息…...
基于LSTM与SHAP可解释性分析的神经网络回归预测模型【MATLAB】
基于LSTM与SHAP可解释性分析的神经网络回归预测模型【MATLAB】 一、引言 在数据驱动的智能时代,时间序列预测已成为许多领域(如金融、气象、工业监测等)中的关键任务。长短期记忆网络(LSTM)因其在捕捉时间序列长期依…...
C++卡特兰数讲解
前情提要,参考资料:卡特兰数 - OI Wiki 一、定义 卡特兰数(Catalan number)是一个在组合数学中经常出现的数列,应用范围很广,例如括号匹配问题、出栈顺序问题、多边形三角剖分问题等。在 C 中,可以使用多种…...
【数据融合实战手册·应用篇】“数字孪生+视频融合”让智慧城市拥有空间感知
一、视频融合技术如何破局城市治理? #从"碎片监控"到"上帝视角" 传统视频监控系统画面分散,监管人员需要观看多个分镜头画面,难以将零散的分镜头视频与其实际地理位置对应,容易产生信息孤岛,同时…...
[数据库之十一] 数据库索引之联合索引
执行数据库查询时,通常查询条件是多对个属性进行判断和约束,对于这种类型的查询,如果存在多个索引则使用多个索引,或者使用建立在多属性搜索码上的索引,这样能提高查询效率。 一、使用多个单码索引 假设数据表 instruc…...
【Linux】Linux工具(1)
3.Linux工具(1) 文章目录 3.Linux工具(1)Linux 软件包管理器 yum什么是软件包关于 rzsz查看软件包——yum list命令如何安装软件如何卸载软件补充——yum如何找到要安装软件的下载地址 Linux开发工具Linux编辑器-vim使用1.vim的基…...
微信小程序使用腾讯云COS SDK实现用户头像上传
引入与初始化COS SDK (从官网下载cos-wx-sdk-v5.js文件,本地上传) const COS require(../../../static/utils/cos-wx-sdk-v5.js) as any;//实例化一个cos对象 const cos new COS({SecretId: AK***********************VedSJ, //idSecretK…...
什么是HTML、CSS 和 JavaScript?
HTML、CSS 和 JavaScript 是构建网页的三大核心技术,它们分工明确又紧密协作。接下来我将分别介绍三者的定义、功能,并阐述它们如何共同构成网页,最后推荐学习资源。 一、HTML:网页的骨架与内容基础 HTML(HyperText …...
兼具直连存储与分布式存储优势的混合存储方案
兼具直连存储与分布式存储优势的混合存储方案 一、分层存储架构 热数据本地直存 将高频访问的热数据(如数据库事务日志、实时计算中间结果)存储在DAS本地SSD中利用DAS的低延迟特性提升实时性要求高的业务性能 温冷数据分布式存储 低频访问的温…...
App Store支付新政重构跨境电商生态:eBay卖家的突围之道
2024年4月,美国联邦法院对苹果应用商店支付体系的裁决掀起全球电商海啸。这场源自Epic Games诉讼案的制度变革,正在跨境电商领域掀起超预期的蝴蝶效应。本文将深入剖析政策变革对eBay生态的冲击路径,揭示跨境卖家转型升级的核心策略。 一、支…...
Rust 开发环境搭建与插件
生成完整文章 用户请求写一篇完整的CSDN文章,要求根据之前的建议生成。文章要包含结构清晰、标题、代码示例、常见提示、跨平台Rust工具链安装差异等内容。文章需准确,包括插件和使用提示,CLI程序示例等。主要内容包括:介绍、Rus…...
Axios替代品Alova
介绍alova | Alova.JS Multipart 实体请求 | Axios中文文档 | Axios中文网 1. 极致的轻量与性能 Tree-shaking优化:仅打包使用到的功能模块 零依赖:基础包仅 4KB(Axios 12KB) 2. 智能请求管理(开箱即用࿰…...
【C语言】文件操作(续)
目录 复习: 一⽂件的顺序读写 例子: 前言: 在上篇文章中介绍了文件的类型,文件指针,流,操作的函数。 在本篇文章继续为大家带来文件细节分享,如 顺序读写等等。 复习: fopen是…...
Angular 面试常见问题
1. 请阐述 Angular 的工作原理 Angular 的工作流程涉及多个关键环节,从组件交互到浏览器渲染,以下是其核心流程: 组件交互:当用户触发特定事件(如点击按钮)时,组件会响应这些交互,…...
数据库(MySQL)基础
一、登录数据库 在linux系统中登录数据库的指令 mysql -h 127.48.0.236 -P 3306 -u root -p -h:填写IP地址,指明要连接的主机。如果不加该字段表示本地主机-P:填写端口号,指明进程。 如果不加该字段会使用默认的端口号。-u&…...
【Java ee 初阶】文件操作和IO(上)
一、文件 文件在计算机中,是保存到“硬盘”上的。操作系统,把硬盘操作进行了抽象封装,使得编程的时候,是不会直接操作硬盘的,而是通过“文件”的概念来进行间接操作。 文件有哪些操作?——>打开文件&a…...
微信小程序备案的一些记录
小程序如果没有备案是搜索不到小程序的。 小程序备案需要填写主体负责人的信息,需要主体负责人的手机号验证码, 需要填写管理员的信息,同样也需要验证手机号码, 填写完毕之后,提交进行初审,初审之后会打…...
leetcode0279. 完全平方数-medium
1 题目:完全平方数 官方标定难度:中 给你一个整数 n ,返回 和为 n 的完全平方数的最少数量 。 完全平方数 是一个整数,其值等于另一个整数的平方;换句话说,其值等于一个整数自乘的积。例如,1…...
2018机械行业ERP软件发展趋势
随着互联网经济的发展,实体的经济将来很有发展的优势,管理的信息化工具,也要随着市场需求的改变而改变。 以前的ERP管理系统,管理管控的方向。 1、以物料管理为核心,通过ERP管理系统,将企业的物料管理清楚&…...
限制布局大小,实现文本自适应
实现数字部分自适应 适配后 使用页需绑定ref <div class"setting-bind-text" ref"element" :style"{ transform: scale(${scale}) }">{{ coin }}</div> script部分引入使用 import { useTextScale } from /hooks/useTextScale; c…...
涨薪技术|0到1学会性能测试第52课-Tomcat调优技术
前面的推文我们掌握了Tomcat服务器的3种监控技术知识。今天给大家分享Tomcat调优技术。后续文章都会系统分享干货,带大家从0到1学会性能测试。 在对Tomcat进行调优之前,需要对Tomcat的结构体系有一个清楚的了解,这对调优起到至交重要的作用,Tomcat结构体系图,如图10-20所示…...
Arm核的Ubuntu系统上安装Wireshark
Arm核的Ubuntu系统上安装Wireshark 一、安装wireshark 安装命令: sudo apt-get install wireshark-qt 如下图所示: 安装过程弹出如下界面: 鼠标选择Yes,点回车键确认 安装完成。 二、打开wireshark 输入命令行打开wireshark …...
C++模板【上篇】 —详解模板基础语法
文章目录 前言1. 泛型编程2. 模板的类别2.1 函数模板2.2 类模板 3. 模板的实例化3.1 函数模板的实例化3.1.1 隐式实例化* 编译器实例化原理3.1.2 显示实例化 3.2 类模板的实例化 前言 在这篇文章中,主要介绍一些模板的基础的语法和一些细节,同时了解泛型…...
谈谈Redis缓存和数据库一致性
目录 1、缓存问题 2、更新缓存 3、删除缓存 4、最终方案 5、缓存分类 5.1、缓存穿透 5.2、缓存击穿 5.2、缓存雪崩 6、示例 前言 Redis 作为缓存与数据库之间的通信模式能够显著提升系统性能,减少数据库的压力。 通过合理使用 Redis 进行数据存取ÿ…...
JWT深度解析:现代Web身份验证的通行证-优雅草卓伊凡
# JWT深度解析:现代Web身份验证的通行证 ## 一、JWT的本质与构成 ### 1.1 JWT的定义解析 JWT(JSON Web Token)是一种**开放标准(RFC 7519)**,用于在各方之间安全地传输信息作为JSON对象。这种信息可以被…...
VTK|.obj文件数据处理+Jet/Viridis/CoolToWarm/Grayscale/Rainbow/风格颜色渲染
文章目录 处理OBJ文件Jet渲染风格Viridis渲染风格CoolToWarm渲染风格Grayscale渲染风格Rainbow渲染风格切换风格按钮槽函数(可优化)相关代码github链接 将 .obj 数据进行 Elevation 着色并可视化渲染的完整流程 和.ply文件处理方式一样 处理OBJ文件 vo…...
如何通过服务主体获取 Azure 凭据
本文详细讲解如何通过 Azure 服务主体生成凭据,使应用程序能够安全访问 Azure 资源(如部署 Container Apps)。以下步骤基于 Azure Portal 操作,适用于自动化部署、CI/CD 等场景。 步骤 1:登录 Azure Portal 访问 Azure 门户。使用 Azure 账户(需具备订阅管理员权限)登录…...
Kubernetes探针生产环境实战指南
一、探针的本质:应用健康的智能体检系统 想象你的应用是一个高空走钢丝的演员,Kubernetes探针就像三位安全员: 启动探针:检查演员是否站稳(应用是否完成初始化)就绪探针:确认演员准备好表演&a…...
node.js 实战——express图片保存到本地或服务器(七牛云、腾讯云、阿里云)
本地 ✅ 使用formidable 读取表单内容 npm i formidable ✅ 使用mime-types 获取图片后缀 npm install mime-types✅ js 中提交form表单 document.getElementById(uploadForm).addEventListener(submit, function(e){e.preventDefault();const blob preview._blob;if(!blob)…...
线代第二章矩阵第五、六、七节矩阵的转置、方阵的行列式、方阵的伴随矩阵
文章目录 矩阵的转置转置性质对称矩阵与反对称矩阵 方阵的行列式方阵的伴随矩阵(重要) 矩阵的转置 转置性质 (1) (2) (3) (4)注意这个: 扩展&a…...
经验:从CAN到以太网为主的车载网络架构升级
引言 新能源汽车智能化与网联化的进程中,传统CAN总线已难以满足高带宽、低延迟的通信需求,车载以太网逐步成为新一代电子架构的核心骨干。本文基于工程实践,系统性解析车载以太网的核心技术、协议栈、拓扑设计及工具链升级策略,助…...
基于FPGA婴儿安全监护系统(蓝牙小程序监测)
基于FPGA婴儿安全监护系统 前言一、芯片手册阅读二、代码分析1.温湿度驱动2.转速等级设置模块3.电机转速控制模块 总结视频演示 前言 实时监测车内温湿度数据(DTH11温湿度模块)----实时控制风扇驱动速度(结合温湿度进行控制)----…...
嵌入式 C 语言控制语句
目录 1. 控制语句 2. 分支语句 2.1 if else 2.2 switch 3. 循环语句 3.1 goto 3.2 while 循环 3.3 do while 循环 3.4 for 循环 3.5 例题 3.6 循环控制语句 3.6.1 break 3.6.2 continue 1. 控制语句 控制语句分为:顺序语句,分支语句࿰…...
leaflet-velocity风场粒子效果及数据处理
一,后台给到的数据 {"msg": "success","code": 200,"data": {"startLat": 39.3,"endlat": 41.2,"latdel": 0.099999994,"startLon": 115.3,"endLon": 117.50001,"…...
React 实现 JWT 登录验证的最小可运行示例
下面是一个用 React 实现 JWT 登录验证的最小可运行示例,包含: React 前端:登录、保存 Token、获取用户数据。模拟后端:用 mock API(你也可以接真后端)。 🧱 技术栈 React(使用 Vi…...
MySQL报错解决过程
我在调试datagrip的时候,显示拒绝连接,开始的时候,我以为只是服务没有开启,结果到后来在网上搜索各种解决办法无果后,就选择卸载,卸载之后安装新的MySQL 以下就是我的解决过程。 如果只是在使用外置软件&…...
更多 QVariant 使用案例
以下是 QVariant 的其他典型应用场景及代码示例,涵盖更多实际开发需求: 6. 数据库查询结果处理 处理数据库字段的异构数据类型(如整数、字符串、日期等): QSqlQuery query; query.exec("SELECT name, age, crea…...
WPF中解决数据绑定不匹配的问题
在 WPF 开发中,IValueConverter 和 IMultiValueConverter 接口是非常实用的工具,它们允许你在数据绑定过程中对数据进行转换。 IValueConverter 接口示例 IValueConverter 接口用于单值转换,它包含 Convert 和 ConvertBack 两个方法。Conve…...
学习Cesium Entities
🌐 Cesium中的Entities系统趣味学习 📊 Entities系统架构流程图 #mermaid-svg-Lkue5O3gYOkEVSbD {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-Lkue5O3gYOkEVSbD .error-icon{fill:#552222;}#mermaid-svg-Lku…...
Spark处理过程-案例数据清洗
(一)需求说明 准备十条符合包含用户信息的文本文件,每行格式为 姓名,年龄,性别,需要清洗掉年龄为空或者非数字的行。 例如: 张三,25,男 李四,,女 王五,30,男 赵六,a,女 孙七,35,男 周八,40,女 吴九,abc,男 郑十,45,女…...
【AI提示词】马斯洛需求分析专家
提示说明 专业的心理学需求分析专家,熟悉马斯洛需求层次理论及其在不同文化背景下的适用性。 提示词 # Role: 马斯洛需求分析专家## Profile - language: 中文 - description: 专业的心理学需求分析专家,熟悉马斯洛需求层次理论及其在不同文化背景下的…...
【WebRTC-13】是在哪,什么时候,创建编解码器?
Android-RTC系列软重启,改变以往细读源代码的方式 改为 带上实际问题分析代码。增加实用性,方便形成肌肉记忆。同时不分种类、不分难易程度,在线征集问题切入点。 问题:编解码器的关键实体类是什么?在哪里&什么时候…...
Kuikly 安装环境篇
1、安装版本号为2024.1.1 的Android studio(如使用高版本的Android studio需要更改JDK版本号为17) 2、JDK版本使用17(如需要修改JDK:Android Studio -> Settings -> Build,Execution,Deployment -> Build Tools -> Gr…...
npm create vite@latest my-vue-app 解读
背景发荧光的样式。 filter属性的学习:filter - CSS:层叠样式表 | MDN 复习一下em 组件的调用: 是msg让“ViteVue”显示出来的!! a标签的targte属性: 组件之间怎么传值的: ,没看懂code标签怎么…...