///////////////////////////////////////////////////////////////////////////////
// File generated by HDevelop for HALCON/C++ Version 10.0
///////////////////////////////////////////////////////////////////////////////
#include "HalconCpp.h"
using namespace Halcon;
// Default exception handler
void CPPExpDefaultExceptionHandler(const Halcon::HException& except)
{
throw except;
}
// 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 (Halcon::Hobject Image, Halcon::HTuple Row, Halcon::HTuple Column,
Halcon::HTuple WidthLimit, Halcon::HTuple HeightLimit, Halcon::HTuple *WindowHandle);
// Chapter: Graphics / Text
// Short Description: This procedure writes a text message.
void disp_message (Halcon::HTuple WindowHandle, Halcon::HTuple String, Halcon::HTuple CoordSystem,
Halcon::HTuple Row, Halcon::HTuple Column, Halcon::HTuple Color, Halcon::HTuple Box);
// 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 (Halcon::Hobject Image, Halcon::HTuple Row, Halcon::HTuple Column,
Halcon::HTuple WidthLimit, Halcon::HTuple HeightLimit, Halcon::HTuple *WindowHandle)
{
using namespace Halcon;
// Local control variables
HTuple MinWidth, MaxWidth, MinHeight, MaxHeight;
HTuple ResizeFactor, ImageWidth, ImageHeight, TempWidth;
HTuple TempHeight, WindowWidth, WindowHeight;
//This procedure opens a new graphics window and adjusts the size
//such that it fits into the limits specified by WidthLimit
//and HeightLimit, but also maintains the correct image aspect ratio.
//
//If it is impossible to match the minimum and maximum extent requirements
//at the same time (f.e. if the image is very long but narrow),
//the maximum value gets a higher priority,
//
//Parse input tuple WidthLimit
if (0 != (HTuple((WidthLimit.Num())==0).Or(WidthLimit<0)))
{
MinWidth = 500;
MaxWidth = 800;
}
else if (0 != ((WidthLimit.Num())==1))
{
MinWidth = 0;
MaxWidth = WidthLimit;
}
else
{
MinWidth = WidthLimit[0];
MaxWidth = WidthLimit[1];
}
//Parse input tuple HeightLimit
if (0 != (HTuple((HeightLimit.Num())==0).Or(HeightLimit<0)))
{
MinHeight = 400;
MaxHeight = 600;
}
else if (0 != ((HeightLimit.Num())==1))
{
MinHeight = 0;
MaxHeight = HeightLimit;
}
else
{
MinHeight = HeightLimit[0];
MaxHeight = HeightLimit[1];
}
//
//Test, if window size has to be changed.
ResizeFactor = 1;
get_image_size(Image, &ImageWidth, &ImageHeight);
//First, expand window to the minimum extents (if necessary).
if (0 != (HTuple(MinWidth>ImageWidth).Or(MinHeight>ImageHeight)))
{
ResizeFactor = (((MinWidth.Real())/ImageWidth).Concat((MinHeight.Real())/ImageHeight)).Max();
}
TempWidth = ImageWidth*ResizeFactor;
TempHeight = ImageHeight*ResizeFactor;
//Then, shrink window to maximum extents (if necessary).
if (0 != (HTuple(MaxWidth<TempWidth).Or(MaxHeight<TempHeight)))
{
ResizeFactor = ResizeFactor*((((MaxWidth.Real())/TempWidth).Concat((MaxHeight.Real())/TempHeight)).Min());
}
WindowWidth = ImageWidth*ResizeFactor;
WindowHeight = ImageHeight*ResizeFactor;
//Resize window
set_window_attr("background_color","black");
open_window(Row,Column,WindowWidth,WindowHeight,0,"","",&(*WindowHandle));
HDevWindowStack::Push((*WindowHandle));
if (HDevWindowStack::IsOpen())
set_part(HDevWindowStack::GetActive(),0, 0, ImageHeight-1, ImageWidth-1);
return;
}
// Chapter: Graphics / Text
// Short Description: This procedure writes a text message.
void disp_message (Halcon::HTuple WindowHandle, Halcon::HTuple String, Halcon::HTuple CoordSystem,
Halcon::HTuple Row, Halcon::HTuple Column, Halcon::HTuple Color, Halcon::HTuple Box)
{
using namespace Halcon;
// Local control variables
HTuple Red, Green, Blue, Row1Part, Column1Part;
HTuple Row2Part, Column2Part, RowWin, ColumnWin, WidthWin;
HTuple HeightWin, MaxAscent, MaxDescent, MaxWidth, MaxHeight;
HTuple R1, C1, FactorRow, FactorColumn, Width, Index, Ascent;
HTuple Descent, W, H, FrameHeight, FrameWidth, R2, C2;
HTuple DrawMode, Exception, CurrentColor;
// Install default exception handler
HException::InstallHHandler(&CPPExpDefaultExceptionHandler);
//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.
//Box: If set to 'true', the text is written within a white box.
//
//prepare window
get_rgb(WindowHandle, &Red, &Green, &Blue);
get_part(WindowHandle, &Row1Part, &Column1Part, &Row2Part, &Column2Part);
get_window_extents(WindowHandle, &RowWin, &ColumnWin, &WidthWin, &HeightWin);
set_part(WindowHandle, 0, 0, HeightWin-1, WidthWin-1);
//
//default settings
if (0 != (Row==-1))
{
Row = 12;
}
if (0 != (Column==-1))
{
Column = 12;
}
if (0 != (Color==HTuple()))
{
Color = "";
}
//
String = ((""+String)+"").Split("\n");
//
//Estimate extentions of text depending on font size.
get_font_extents(WindowHandle, &MaxAscent, &MaxDescent, &MaxWidth, &MaxHeight);
if (0 != (CoordSystem==HTuple("window")))
{
R1 = Row;
C1 = Column;
}
else
{
//transform image to window coordinates
FactorRow = (1.0*HeightWin)/((Row2Part-Row1Part)+1);
FactorColumn = (1.0*WidthWin)/((Column2Part-Column1Part)+1);
R1 = ((Row-Row1Part)+0.5)*FactorRow;
C1 = ((Column-Column1Part)+0.5)*FactorColumn;
}
//
//display text box depending on text size
if (0 != (Box==HTuple("true")))
{
//calculate box extents
String = (" "+String)+" ";
Width = HTuple();
for (Index=0; Index<=(String.Num())-1; Index+=1)
{
get_string_extents(WindowHandle, HTuple(String[Index]), &Ascent, &Descent,
&W, &H);
Width.Append(W);
}
FrameHeight = MaxHeight*(String.Num());
FrameWidth = (HTuple(0).Concat(Width)).Max();
R2 = R1+FrameHeight;
C2 = C1+FrameWidth;
//display rectangles
get_draw(WindowHandle, &DrawMode);
set_draw(WindowHandle, "fill");
set_color(WindowHandle, "light gray");
disp_rectangle1(WindowHandle, R1+3, C1+3, R2+3, C2+3);
set_color(WindowHandle, "white");
disp_rectangle1(WindowHandle, R1, C1, R2, C2);
set_draw(WindowHandle, DrawMode);
}
else if (0 != (Box!=HTuple("false")))
{
Exception = "Wrong value of control parameter Box";
throw HException(Exception);
}
//Write text.
for (Index=0; Index<=(String.Num())-1; Index+=1)
{
CurrentColor = Color[Index%(Color.Num())];
if (0 != (HTuple(CurrentColor!=HTuple("")).And(CurrentColor!=HTuple("auto"))))
{
set_color(WindowHandle, CurrentColor);
}
else
{
set_rgb(WindowHandle, Red, Green, Blue);
}
Row = R1+(MaxHeight*Index);
set_tposition(WindowHandle, Row, C1);
write_string(WindowHandle, HTuple(String[Index]));
}
//reset changed window settings
set_rgb(WindowHandle, Red, Green, Blue);
se
评论0