void DemoTin (HANDLE hLcWnd)
{
WCHAR* szPntsFName = L"c:/Data/TIN/TIN_points_2.txt";
WCHAR* szTinFName = L"c:/Data/TIN/TIN_demo2.tin";
WCHAR* szLcdFName = L"c:/Data/TIN/Demo_with_TIN.lcd";
HANDLE hBlock, hEntTIN, hPropWnd, hDrw;
double Lef, Bot, Rig, Top, d, dx, dy, PixSize;
bool bUseColorFill = false;
// get a block linked with the window
hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEWBLOCK );
// create TIN object from points file
hEntTIN = lcBlockAddTIN( hBlock, szPntsFName, 1 );
if (hEntTIN != 0){
// set TIN name
lcPropPutStr( hEntTIN, LC_PROP_TIN_NAME, L"Demo TIN" );
// get TIN extents
Lef = lcPropGetFloat( hEntTIN, LC_PROP_TIN_XMIN );
Bot = lcPropGetFloat( hEntTIN, LC_PROP_TIN_YMIN );
Rig = lcPropGetFloat( hEntTIN, LC_PROP_TIN_XMAX );
Top = lcPropGetFloat( hEntTIN, LC_PROP_TIN_YMAX );
// visibility of some elements
lcPropPutBool( hEntTIN, LC_PROP_TIN_VIEWPTZ, false );
lcPropPutBool( hEntTIN, LC_PROP_TIN_VIEWPTI, false );
lcPropPutBool( hEntTIN, LC_PROP_TIN_VIEWPTN, false );
lcPropPutBool( hEntTIN, LC_PROP_TIN_VIEWTRI, false );
// set active tin (select it)
lcBlockUnselect( hBlock );
lcBlockSelectEnt( hBlock, hEntTIN, true );
// define boundary
if (lcTIN_Bnd( hEntTIN, 20.0, hLcWnd) == LC_TRUE){
// hide visibility of the boundary
lcPropPutBool( hEntTIN, LC_PROP_TIN_VIEWBND, false );
// triangulate the boundary
if (lcTIN_Triangulate( hEntTIN, hLcWnd ) == LC_TRUE){
// generate Z-contours
lcTIN_Isolines( hEntTIN, 0.1, 5, hLcWnd );
if (bUseColorFill){
// generate color fill. Raster image will have 1000 pixels of bigger side
dx = Rig - Lef;
dy = Top - Bot;
if (dx > dy){
PixSize = dx / 1000.0;
}else{
PixSize = dy / 1000.0;
}
lcTIN_ColorFill( hEntTIN, 0.1, PixSize, hLcWnd );
}
}
}
lcBlockUnselect( hBlock );
// update Properties window
hPropWnd = lcPropGetHandle( hLcWnd, LC_PROP_WND_PROPWND );
lcPropsUpdate( hPropWnd, true );
// set view on the TIN extents
d = ((Rig-Lef) + (Top-Bot)) / 20.0; // add some gap around TIN extents
lcWndZoomRect( hLcWnd, Lef-d, Bot-d, Rig+d, Top+d );
// Save TIN data in a file. LCD file store only reference to this file
lcTIN_Save( hEntTIN, szTinFName, 0, false, hLcWnd );
// Save LCD file. This file has a reference to the TIN file
hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
lcDrwSave( hDrw, szLcdFName, false, hLcWnd );
}
}