📄 ibgdpixmap.c
字号:
/* last edit: Ilja Schmelzer -------------- 17-OCT-1994 19:59:24.66 */
/************************************************************************/
/* */
/* <<< I B G >>> - Intersection - Based Grid generation package */
/* */
/* Version 1.1 by Ilja Schmelzer schmelzer@iaas-berlin.d400.de */
/* */
/* to be distributed under IBG license conditions (see "readme.ibg") */
/* */
/************************************************************************/
/*
Using a pixmap for geometry description
This file can be used also as a pattern to define your own geometry
descriptions is you want to use an own RegionOfPoint function.
The implementation of a geometry is a C implementation of C++ schemes.
Your geometry can be considerd as a derived class of the basic class
ibGeometryRec. This class contains a pure virtual method RegionOfPoint and
other virtual methods. To create a geometry you have to define the derived
class, to implement the pure virtual method RegionOfPoint and at least one
constructor. You can also implement other versions of the other virtual
functions.
*/
#define const
#include "ibg.h"
#include "ibgi.h"
#include "ibglib.h"
#include "ibgg.h"
#include "ibgd.h"
#include "ibgd0.h"
#include "ibgdpixmap.h"
/* the definition of the derived class (the this-pointer for RegionOfPoint): */
typedef struct{
/* this first parameter is required for every geometry description: */
ibGeometryRec g; /* the basic class record in C++ */
/* the other parameter are application-dependend data: */
ibgPixmap p; /* will be defined in ibgdpixmap.h */
ibgFloat xm,dx;
ibgFloat ym,dy;
}ibgPixmap0;
/* RegionOfPoint can be considered as a pure virtual C++ method of the
data type ibGeometryRec. So it is necessary to implement this data type
in every derived class like ibgPixmap0 */
#define IBGPIXMAP_Cut_Pixel_Corner
static int RegionOfPoint(ibGeometry g, ibgPoint *nnew, ibgPoint *nold)
{
/* type conversion for the this-pointer: */
ibgPixmap0 *p = (ibgPixmap0*) g;
ibgFloat *x = ibgpX(*nnew); /* the coordinates of the point */
/* computation of the segment number for the point (x[0],x[1]): */
ibgFloat rx,ry;
int ix = (rx = (x[0] - p->xm) / (p->dx));
int iy = (ry = (x[1] - p->ym) / (p->dy));
int lx = ibgPixmapLx(p->p);
int ly = ibgPixmapLy(p->p);
int u00,u01,u10,jx,jy;
rx -= ix; ry -= iy;
if(ix<0) ix = rx = 0; else if(ix>=lx) {ix = lx - 1; rx=1;}
if(iy<0) iy = ry = 0; else if(iy>=ly) {iy = ly - 1; ry=1;}
u00 = ibgPixmapSegment(p->p,ix,iy);
#ifdef IBGPIXMAP_Cut_Pixel_Corner
if(rx > 0.5) {jx = ix+1; rx -= 0.5;} else {jx = ix-1; rx = 0.5-rx;}
if(ry > 0.5) {jy = iy+1; ry -= 0.5;} else {jy = iy-1; ry = 0.5-ry;}
if(jx<0) jx = 0; else if(jx>=lx) jx = lx - 1;
if(jy<0) jy = 0; else if(jy>=ly) jy = ly - 1;
u01 = ibgPixmapSegment(p->p,ix,jy);
u10 = ibgPixmapSegment(p->p,jx,iy);
if(u10 == u01) if(rx+ry > 0.5) u00 = u10;
#endif
/* standard end for successful computation: */
ibgpSegment(*nnew) = u00;
ibgpType(*nnew) = ibgSRegion;
return ibgRegionFound;
}
/* this is the destructor method for the ibgPixmap0 class: */
static int Free(ibGeometry g)
{
/* type conversion for the this-pointer: */
ibgPixmap0 *p = (ibgPixmap0*) g;
/* deallocation of the object record: */
ibgPixmapFree(p->p);
return ibgSuccess;
}
/* the class record: */
static ibGeometryClassRec ibgPixmapClass;
/* the constructor (combined with allocator) for the ibgPixmap0 class: */
ibGeometry ibgdPixmap(ibgPixmap *px,
ibgFloat xmin, ibgFloat xmax,
ibgFloat ymin, ibgFloat ymax)
{
/* allocation of the parameter for RegionOfPoint (like new in C++): */
ibgPixmap0 *px0 = (ibgPixmap0 *) malloc(sizeof(ibgPixmap0));
/* default initialization for object record and class record: */
ibgdInitialize((ibGeometry)px0,&ibgPixmapClass);
/* initialization of the class record for the pixmap class: */
/* RegionOfPoint and Free are like virtual functions in C++ */
ibgPixmapClass.RegionOfPoint = RegionOfPoint;
ibgPixmapClass.Free = Free; /* if you have defined Free */
/* initialization of the object record *px0: */
px0->p = *px;
px0->dx = (xmax - xmin) / (ibgPixmapLx(*px) - 1);
px0->dy = (ymax - ymin) / (ibgPixmapLy(*px) - 1);
px0->xm = xmin - 0.5*px0->dx;
px0->ym = ymin - 0.5*px0->dy;
/* The pointer to the basic class has to be returned. The inverse type
conversion has to be done for every call of the methods:
*/
return (ibGeometry) px0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -