Import Geant4 11.4.0 source tree
This commit is contained in:
+3
-16
@@ -74,13 +74,11 @@ public:
|
||||
:m_depth_test(true)
|
||||
,m_blend(false)
|
||||
,m_zbuffer(0)
|
||||
//,m_zmin(0),m_zmax(0)
|
||||
,m_zimage(0)
|
||||
,m_zbw(0),m_zbh(0)
|
||||
,m_begX(0),m_begY(0),m_endX(0),m_endY(0)
|
||||
,m_scan_pixel(0L)
|
||||
,m_planeAC(0),m_planeBC(0),m_planeDC(0)
|
||||
//,m_zboundPrec(10)
|
||||
{}
|
||||
virtual ~buffer(){
|
||||
cmem_free(m_zbuffer);
|
||||
@@ -101,7 +99,6 @@ protected:
|
||||
}
|
||||
public:
|
||||
void set_depth_test(bool a_on) {m_depth_test = a_on;}
|
||||
//bool depth_test() const {return m_depth_test;}
|
||||
|
||||
void set_blend(bool a_value) {m_blend = a_value;}
|
||||
|
||||
@@ -115,7 +112,6 @@ public:
|
||||
cmem_free(m_zimage);
|
||||
}
|
||||
|
||||
//printf ("debug:ZBufferChangeSize:%d %d\n",a_width,a_height);
|
||||
m_zbw = a_width;
|
||||
m_zbh = a_height;
|
||||
m_zbuffer = cmem_alloc<ZReal>(m_zbw*m_zbh);
|
||||
@@ -156,7 +152,6 @@ public:
|
||||
void clear_depth_buffer() {
|
||||
// Erase acoording clip region.
|
||||
ZPos row,col;
|
||||
//printf("debug:ZBufferClearDepthBuffer: %g.\n",a_depth);
|
||||
|
||||
for(row=m_begY;row<=m_endY;row++) {
|
||||
ZReal* zbuff = m_zbuffer + row * m_zbw + m_begX;
|
||||
@@ -224,7 +219,6 @@ public:
|
||||
// Assume a_list is closed.
|
||||
if(a_number<3) return;
|
||||
if(a_C==0) return; //polygone seen from edge
|
||||
//if(m_zboundPrec<0) m_zboundPrec = 0;
|
||||
|
||||
m_scan_pixel = a_pixel;
|
||||
m_planeAC = a_A/a_C;
|
||||
@@ -235,11 +229,8 @@ public:
|
||||
//to an other B than |dz| then some pixel of A could overwrite
|
||||
//pixel of B. Your have then to give a lower m_zboundPrec
|
||||
|
||||
//ZZ dz = m_zboundPrec * (a_zmax - a_zmin)/100.;
|
||||
//m_zmin = (ZReal)(a_zmin - dz);
|
||||
//m_zmax = (ZReal)(a_zmax + dz);
|
||||
m_polygon.scan(a_number,a_list,0,WriteScanLine,this,m_zbw,m_zbh);
|
||||
|
||||
m_polygon.scan(a_number,a_list,0,WriteScanLine,this);
|
||||
|
||||
}
|
||||
|
||||
@@ -304,8 +295,8 @@ protected:
|
||||
if(a_end<a_buffer.m_begX) return;
|
||||
|
||||
// border clip :
|
||||
int beg = mx(a_beg,(int)a_buffer.m_begX);
|
||||
int end = mn(a_end,(int)a_buffer.m_endX);
|
||||
int beg = max_of(a_beg,(int)a_buffer.m_begX);
|
||||
int end = min_of(a_end,(int)a_buffer.m_endX);
|
||||
|
||||
unsigned long offset = a_y * a_buffer.m_zbw + beg;
|
||||
ZReal* zbuff = a_buffer.m_zbuffer + offset;
|
||||
@@ -319,8 +310,6 @@ protected:
|
||||
- a_buffer.m_planeBC * a_y);
|
||||
if(a_buffer.m_depth_test) {
|
||||
if((zpoint>=(*zbuff))
|
||||
// &&(zpoint>=a_buffer.m_zmin) //for plane quite perpandicular to screen.
|
||||
// &&(zpoint<=a_buffer.m_zmax)
|
||||
){
|
||||
*zbuff = zpoint;
|
||||
a_buffer.blend(*zimage,a_buffer.m_scan_pixel);
|
||||
@@ -430,7 +419,6 @@ protected:
|
||||
bool m_depth_test;
|
||||
bool m_blend;
|
||||
ZReal* m_zbuffer;
|
||||
//ZReal m_zmin,m_zmax;
|
||||
|
||||
ZPixel* m_zimage;
|
||||
|
||||
@@ -442,7 +430,6 @@ protected:
|
||||
ZZ m_planeAC;
|
||||
ZZ m_planeBC;
|
||||
ZZ m_planeDC;
|
||||
//int m_zboundPrec;
|
||||
polygon m_polygon;
|
||||
};
|
||||
|
||||
|
||||
+4
-3
@@ -96,6 +96,7 @@ inline void CreateETandAET (
|
||||
,EdgeTableEntry* AET
|
||||
,EdgeTableEntry* pETEs
|
||||
,ScanLineListBlock* pSLLBlock
|
||||
,int a_pts_xmin,int a_pts_ymin,int a_pts_ymax
|
||||
)
|
||||
/***************************************************************************/
|
||||
/*
|
||||
@@ -138,14 +139,14 @@ inline void CreateETandAET (
|
||||
AET->next = (EdgeTableEntry *)NULL;
|
||||
AET->back = (EdgeTableEntry *)NULL;
|
||||
AET->nextWETE = (EdgeTableEntry *)NULL;
|
||||
AET->bres.minor_axis = SMALL_COORDINATE;
|
||||
AET->bres.minor_axis = a_pts_xmin;
|
||||
|
||||
/*
|
||||
* initialize the Edge Table.
|
||||
*/
|
||||
ET->scanlines.next = (ScanLineList *)NULL;
|
||||
ET->ymax = SMALL_COORDINATE;
|
||||
ET->ymin = LARGE_COORDINATE;
|
||||
ET->ymax = a_pts_ymin;
|
||||
ET->ymin = a_pts_ymax;
|
||||
pSLLBlock->next = (ScanLineListBlock *)NULL;
|
||||
|
||||
PrevPt = &pts[count-1];
|
||||
|
||||
@@ -41,8 +41,6 @@
|
||||
* If it is moving to the left, then we don't want it to flip until
|
||||
* we traverse an entire pixel.
|
||||
*/
|
||||
#define LARGE_COORDINATE 1000000
|
||||
#define SMALL_COORDINATE -LARGE_COORDINATE
|
||||
|
||||
#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
|
||||
int dx; /* local storage */ \
|
||||
|
||||
@@ -13,6 +13,7 @@ typedef double ZZ;
|
||||
class point {
|
||||
public:
|
||||
point():x(0),y(0),z(0){}
|
||||
point(const ZPos& a_x,const ZPos& a_y,const ZZ& a_z):x(a_x),y(a_y),z(a_z){}
|
||||
public:
|
||||
point(const point& a_from):x(a_from.x),y(a_from.y),z(a_from.z){}
|
||||
point& operator=(const point& a_from){
|
||||
|
||||
+86
-11
@@ -48,7 +48,8 @@ public:
|
||||
void scan(int Count, /* number of pts */
|
||||
const point* Pts, /* the pts */
|
||||
int rule, /* winding rule */
|
||||
scan_func a_proc,void* a_tag){
|
||||
scan_func a_proc,void* a_tag,
|
||||
unsigned int a_width,unsigned int a_height){
|
||||
// polytoregion
|
||||
// Scan converts a polygon by returning a run-length
|
||||
// encoding of the resultant bitmap -- the run-length
|
||||
@@ -71,6 +72,37 @@ public:
|
||||
if(a_proc==NULL) return;
|
||||
if(Count==0) return;
|
||||
|
||||
if(Count==3) {
|
||||
point pts[3];
|
||||
pts[0] = Pts[0];
|
||||
pts[1] = Pts[1];
|
||||
pts[2] = Pts[2];
|
||||
|
||||
point vp_down[3];
|
||||
vp_down[0] = point(0,0,0);
|
||||
vp_down[1] = point(a_width,0,0);
|
||||
vp_down[2] = point(a_width,a_height,0);
|
||||
if(triangles_overlap(pts,vp_down)) {
|
||||
} else {
|
||||
point vp_up[3];
|
||||
vp_up[0] = point(0,0,0);
|
||||
vp_up[1] = point(a_width,a_height,0);
|
||||
vp_up[2] = point(0,a_height,0);
|
||||
if(!triangles_overlap(pts,vp_up)) return;
|
||||
}
|
||||
}
|
||||
|
||||
int pts_xmin = Pts[0].x;
|
||||
int pts_xmax = pts_xmin;
|
||||
int pts_ymin = Pts[0].y;
|
||||
int pts_ymax = pts_ymin;
|
||||
{for(int count=1;count<Count;count++) {
|
||||
if(Pts[count].x<pts_xmin) pts_xmin = Pts[count].x;
|
||||
if(Pts[count].x>pts_xmax) pts_xmax = Pts[count].x;
|
||||
if(Pts[count].y<pts_ymin) pts_ymin = Pts[count].y;
|
||||
if(Pts[count].y>pts_ymax) pts_ymax = Pts[count].y;
|
||||
}}
|
||||
|
||||
/* special case a rectangle */
|
||||
point* pts = (point*)Pts;
|
||||
if (((Count == 4) ||
|
||||
@@ -85,10 +117,10 @@ public:
|
||||
(pts[3].y == pts[0].y))))
|
||||
{
|
||||
int xmin,xmax,ymin,ymax;
|
||||
xmin = (int)mn(pts[0].x, pts[2].x);
|
||||
ymin = (int)mn(pts[0].y, pts[2].y);
|
||||
xmax = (int)mx(pts[0].x, pts[2].x);
|
||||
ymax = (int)mx(pts[0].y, pts[2].y);
|
||||
xmin = (int)min_of(pts[0].x, pts[2].x);
|
||||
ymin = (int)min_of(pts[0].y, pts[2].y);
|
||||
xmax = (int)max_of(pts[0].x, pts[2].x);
|
||||
ymax = (int)max_of(pts[0].y, pts[2].y);
|
||||
if ((xmin != xmax) && (ymin != ymax))
|
||||
{
|
||||
for(y=ymin;y<=ymax;y++) a_proc(a_tag,xmin ,xmax ,y);
|
||||
@@ -108,20 +140,18 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/*G.Barrand : quiet g++-11 warnings : begin :*/
|
||||
ET.scanlines.next = (ScanLineList*)NULL;
|
||||
ET.ymax = SMALL_COORDINATE;
|
||||
ET.ymin = LARGE_COORDINATE;
|
||||
ET.ymax = pts_ymin;
|
||||
ET.ymin = pts_ymax;
|
||||
|
||||
AET.next = (EdgeTableEntry*)NULL;
|
||||
AET.back = (EdgeTableEntry*)NULL;
|
||||
AET.nextWETE = (EdgeTableEntry*)NULL;
|
||||
AET.bres.minor_axis = SMALL_COORDINATE;
|
||||
AET.bres.minor_axis = pts_xmin;
|
||||
|
||||
SLLBlock.next = (ScanLineListBlock*)NULL;
|
||||
/*G.Barrand : end.*/
|
||||
|
||||
CreateETandAET (Count,(point*)Pts, &ET, &AET, m_pETEs, &SLLBlock);
|
||||
CreateETandAET (Count,(point*)Pts, &ET, &AET, m_pETEs, &SLLBlock,pts_xmin,pts_ymin,pts_ymax);
|
||||
|
||||
pSLL = ET.scanlines.next;
|
||||
|
||||
@@ -290,6 +320,51 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// from: https://rosettacode.org/wiki/Determine_if_two_triangles_overlap#C++
|
||||
static double det_2D(const point& a_p1,const point& a_p2,const point& a_p3) {
|
||||
return a_p1.x*(a_p2.y-a_p3.y)+a_p2.x*(a_p3.y-a_p1.y)+a_p3.x*(a_p1.y-a_p2.y);
|
||||
}
|
||||
|
||||
static void check_winding(point& a_p1,point& a_p2,point& a_p3) {
|
||||
double detTri = det_2D(a_p1, a_p2, a_p3);
|
||||
if(detTri < 0.0) { //swap p2 and p3:
|
||||
point a = a_p3;
|
||||
a_p3 = a_p2;
|
||||
a_p2 = a;
|
||||
}
|
||||
}
|
||||
|
||||
static bool check_boundary_overlap(point& a_p1,point& a_p2,point& a_p3) {return det_2D(a_p1, a_p2, a_p3) < 0.0;}
|
||||
|
||||
static bool triangles_overlap(point* a_t1,point* a_t2) {
|
||||
//Trangles must be expressed anti-clockwise
|
||||
check_winding(a_t1[0], a_t1[1], a_t1[2]);
|
||||
check_winding(a_t2[0], a_t2[1], a_t2[2]);
|
||||
|
||||
//For edge E of trangle 1,
|
||||
for(int i=0; i<3; i++) {
|
||||
int j=(i+1)%3;
|
||||
|
||||
//Check all points of trangle 2 lay on the external side of the edge E. If
|
||||
//they do, the triangles do not overlap.
|
||||
if (check_boundary_overlap(a_t1[i], a_t1[j], a_t2[0]) &&
|
||||
check_boundary_overlap(a_t1[i], a_t1[j], a_t2[1]) &&
|
||||
check_boundary_overlap(a_t1[i], a_t1[j], a_t2[2])) return false;
|
||||
}
|
||||
|
||||
//For edge E of trangle 2,
|
||||
for(int i=0; i<3; i++) {
|
||||
int j=(i+1)%3;
|
||||
|
||||
//Check all points of trangle 1 lay on the external side of the edge E. If
|
||||
//they do, the triangles do not overlap.
|
||||
if (check_boundary_overlap(a_t2[i], a_t2[j], a_t1[0]) &&
|
||||
check_boundary_overlap(a_t2[i], a_t2[j], a_t1[1]) &&
|
||||
check_boundary_overlap(a_t2[i], a_t2[j], a_t1[2])) return false;
|
||||
}
|
||||
|
||||
return true; //the triangles overlap.
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user