🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Jeremy Fitzhardinge Sat, 10 Oct 1992 02:16
GCC 2.2.2 fails with fatal signal 6
#1178
Author: Jeremy Fitzhardinge
Date: Sat, 10 Oct 1992 02:16
2467 lines
43631 bytes
The following command causes gcc 2.2.2 to fail with a signal 6:

Script started on Fri Oct  9 21:05:28 1992
: chao:p8; gcc -v -O -g -target sun4 -c  ff.c
Reading specs from /usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/specs
gcc version 2.2.2
 /usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ -g ff.c /tmp/cca20219.i
GNU CPP version 2.2.2 (sparc)
 /usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/cc1 /tmp/cca20219.i -quiet -dumpbase ff.c -g -O -version -o /tmp/cca20219.s
GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
gcc: Internal compiler error: program cc1 got fatal signal 6
: chao:p8; 
script done on Fri Oct  9 21:06:00 1992

This file can be compiled with the Sun bundled 'cc'

-- 
jeremy@sw.oz.au ph:+61 2 698 2322-x122 fax:+61 2 699 9174
I have, however, taken liberties with the barber pole.

-- Source --
# 1 "ff.c"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
# 1 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/stdio.h" 1 3
 




extern	struct	_iobuf {
	int	_cnt;
	unsigned char *_ptr;
	unsigned char *_base;
	int	_bufsiz;
	short	_flag;
	char	_file;		 
} _iob[];








































extern struct _iobuf 	*fopen();
extern struct _iobuf 	*fdopen();
extern struct _iobuf 	*freopen();
extern struct _iobuf 	*popen();
extern struct _iobuf 	*tmpfile();
extern long	ftell();
extern char	*fgets();
extern char	*gets();
extern char	*sprintf();
extern char	*ctermid();
extern char	*cuserid();
extern char	*tempnam();
extern char	*tmpnam();






# 24 "ff.c" 2

# 1 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/stdlib.h" 1 3
 

 






# 1 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/sys/stdtypes.h" 1 3
 

 










typedef	int		sigset_t;	 

typedef	unsigned int	speed_t;	 
typedef	unsigned long	tcflag_t;	 
typedef	unsigned char	cc_t;		 
typedef	int		pid_t;		 

typedef	unsigned short	mode_t;		 
typedef	short		nlink_t;	 

typedef	long		clock_t;	 
typedef	long		time_t;		 



typedef	int		size_t;		 



typedef int		ptrdiff_t;	 



typedef	unsigned short	wchar_t;	 



# 10 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/stdlib.h" 2 3


extern unsigned int _mb_cur_max;




 
extern void	abort( );
extern int	abs( );
extern double	atof( );
extern int	atoi( );
extern long int	atol( );
extern char *	bsearch( 
);
extern void *	calloc( );
extern void	exit( );
extern void	free( );
extern char *	getenv( );
extern void *	malloc( );
extern int	qsort( 
);
extern int	rand( );
extern void *	realloc( );
extern int	srand( );

extern int    mbtowc( );
extern int    wctomb( );
extern size_t mbstowcs( );
extern size_t wcstombs( );


# 25 "ff.c" 2

# 1 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/math.h" 1 3
 

 



 






 





extern double	__infinity();
extern double	acos( );
extern double	asin( );
extern double	atan( );
extern double	atan2( );
extern double	ceil( );
extern double	cos( );
extern double	cosh( );
extern double	exp( );
extern double	fabs( );
extern double	floor( );
extern double	fmod( );
extern double	frexp( );
extern double	ldexp( );
extern double	log( );
extern double	log10( );
extern double	modf( );
extern double	pow( );
extern double	sin( );
extern double	sinh( );
extern double	sqrt( );
extern double	tan( );
extern double	tanh( );


# 1 "/usr/include/floatingpoint.h" 1 3
 

 



 










# 1 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/sys/ieeefp.h" 1 3
 

 



 







 


enum fp_direction_type 		 
	{
	fp_nearest	= 0,
	fp_tozero	= 1,
	fp_positive	= 2,
	fp_negative	= 3
	} ;

# 34 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/sys/ieeefp.h" 3

# 43 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/sys/ieeefp.h" 3


# 53 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/sys/ieeefp.h" 3

enum fp_precision_type		 
	{
	fp_extended	= 0,
	fp_single	= 1,
	fp_double	= 2,
	fp_precision_3	= 3
	} ;


# 73 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/sys/ieeefp.h" 3

enum fp_exception_type		 
	{
	fp_inexact	= 0,
	fp_division	= 1,
	fp_underflow	= 2,
	fp_overflow	= 3,
	fp_invalid	= 4
	} ;


enum fp_class_type		 
	{
	fp_zero		= 0,
	fp_subnormal	= 1,
	fp_normal	= 2,
	fp_infinity   	= 3,
	fp_quiet	= 4,
	fp_signaling	= 5
	} ;


# 18 "/usr/include/floatingpoint.h" 2 3


 

typedef float   single;
typedef unsigned long extended[3];	 

typedef long double quadruple;	 








typedef unsigned fp_exception_field_type;
 



typedef int     sigfpe_code_type;	 

typedef void    (*sigfpe_handler_type) ();
 





 

extern enum fp_direction_type fp_direction;
 



extern enum fp_precision_type fp_precision;
 



extern fp_exception_field_type fp_accrued_exceptions;
 





 


 

typedef char    decimal_string[512 ];
 

typedef struct {
	enum fp_class_type fpclass;
	int             sign;
	int             exponent;
	decimal_string  ds;	 


	int             more;	 


	int             ndigits; 


}
                decimal_record;

enum decimal_form {
	fixed_form,		 



	floating_form		 

};

typedef struct {
	enum fp_direction_type rd;
	 
	enum decimal_form df;	 
	int             ndigits; 
}
                decimal_mode;

enum decimal_string_form {	 
	invalid_form,		 
	whitespace_form,	 
	fixed_int_form,		 
	fixed_intdot_form,	 
	fixed_dotfrac_form,	 
	fixed_intdotfrac_form,	 
	floating_int_form,	 
	floating_intdot_form,	 
	floating_dotfrac_form,	 
	floating_intdotfrac_form,	 
	inf_form,		 
	infinity_form,		 
	nan_form,		 
	nanstring_form		 
};

 

extern void     double_to_decimal();
extern void     quadruple_to_decimal();
extern char    *econvert();
extern char    *fconvert();
extern char    *gconvert();
extern char    *qeconvert();
extern char    *qfconvert();
extern char    *qgconvert();

 



extern sigfpe_handler_type ieee_handlers[5	];
 






extern sigfpe_handler_type sigfpe();

extern void     single_to_decimal();
extern void     extended_to_decimal();

extern void     decimal_to_single();
extern void     decimal_to_double();
extern void     decimal_to_extended();
extern void     decimal_to_quadruple();

extern char    *seconvert();
extern char    *sfconvert();
extern char    *sgconvert();

extern void     string_to_decimal();
extern void     file_to_decimal();
extern void     func_to_decimal();

 

extern double   atof();

 

extern int      errno;

extern double   strtod();


# 47 "/usr/local/lib/gcc-lib/sparc-sunos4/2.2.2/include/math.h" 2 3

extern double	acosh();
extern double	asinh();
extern double	atanh();
extern double	cbrt();
extern double	copysign();
extern double	erf();
extern double	erfc();
extern double	expm1();
extern int	finite();
extern double	hypot();
extern double	j0();
extern double	j1();
extern double	jn();
extern double	lgamma();
extern double	log1p();
extern double	rint();
extern double	y0();
extern double	y1();
extern double	yn();

 



 


enum fp_pi_type {
	fp_pi_infinite	= 0,	 
	fp_pi_66	= 1,	 
	fp_pi_53	= 2	 
};

 


extern enum	fp_pi_type fp_pi;

 


extern enum	fp_class_type fp_class();
extern int	ieee_flags();
extern int	ieee_handler();
extern void	ieee_retrospective();
extern int	ilogb();
extern double	infinity();
extern int	irint();
extern int	isinf();
extern int	isnan();
extern int	isnormal();
extern int	issubnormal();
extern int	iszero();
extern double	logb();
extern double	max_normal();
extern double	max_subnormal();
extern double	min_normal();
extern double	min_subnormal();
extern double	nextafter();
extern void	nonstandard_arithmetic();
extern double	quiet_nan();
extern double	remainder();
extern double	scalb();
extern double	scalbn();
extern double	signaling_nan();
extern int	signbit();
extern double	significand();
extern void	standard_arithmetic();

 


extern double	acospi();
extern double	aint();
extern double	anint();
extern double	annuity();
extern double	asinpi();
extern double	atan2pi();
extern double	atanpi();
extern double	compound();
extern double	cospi();
extern double	exp10();
extern double	exp2();
extern double	log2();
extern int	nint();
extern void	sincos();
extern void	sincospi();
extern double	sinpi();
extern double	tanpi();
extern int	matherr();


 














 







 







 







 




extern int		 ir_finite_();
extern enum fp_class_type ir_fp_class_();
extern int		 ir_ilogb_();
extern int		 ir_irint_();
extern int		 ir_isinf_();
extern int		 ir_isnan_();
extern int		 ir_isnormal_();
extern int		 ir_issubnormal_();
extern int		 ir_iszero_();
extern int		 ir_nint_();
extern int		 ir_signbit_();
extern void		 r_sincos_();
extern void		 r_sincospi_();
extern double  r_acos_();
extern double  r_acosh_();
extern double  r_acospi_();
extern double  r_aint_();
extern double  r_anint_();
extern double  r_annuity_();
extern double  r_asin_();
extern double  r_asinh_();
extern double  r_asinpi_();
extern double  r_atan2_();
extern double  r_atan2pi_();
extern double  r_atan_();
extern double  r_atanh_();
extern double  r_atanpi_();
extern double  r_cbrt_();
extern double  r_ceil_();
extern double  r_compound_();
extern double  r_copysign_();
extern double  r_cos_();
extern double  r_cosh_();
extern double  r_cospi_();
extern double  r_erf_();
extern double  r_erfc_();
extern double  r_exp10_();
extern double  r_exp2_();
extern double  r_exp_();
extern double  r_expm1_();
extern double  r_fabs_();
extern double  r_floor_();
extern double  r_fmod_();
extern double  r_hypot_();
extern double  r_infinity_();
extern double  r_j0_();
extern double  r_j1_();
extern double  r_jn_();
extern double  r_lgamma_();
extern double  r_log10_();
extern double  r_log1p_();
extern double  r_log2_();
extern double  r_log_();
extern double  r_logb_();
extern double  r_max_normal_();
extern double  r_max_subnormal_();
extern double  r_min_normal_();
extern double  r_min_subnormal_();
extern double  r_nextafter_();
extern double  r_pow_();
extern double  r_quiet_nan_();
extern double  r_remainder_();
extern double  r_rint_();
extern double  r_scalb_();
extern double  r_scalbn_();
extern double  r_signaling_nan_();
extern double  r_significand_();
extern double  r_sin_();
extern double  r_sinh_();
extern double  r_sinpi_();
extern double  r_sqrt_();
extern double  r_tan_();
extern double  r_tanh_();
extern double  r_tanpi_();
extern double  r_y0_();
extern double  r_y1_();
extern double  r_yn_();

 












struct exception {
	int type;
	char *name;
	double arg1;
	double arg2;
	double retval;
};

 





























extern int	signgam;
 




extern double cabs();	 



extern double drem();	 


extern double gamma();	 






# 26 "ff.c" 2

# 1 "geo.h" 1
 
 
 
 
 
 
 
 




typedef double Matrix[4][4];               
static Matrix Identity = {
  1.0, 0.0, 0.0, 0.0,
  0.0, 1.0, 0.0, 0.0,
  0.0, 0.0, 1.0, 0.0,
  0.0, 0.0, 0.0, 1.
  };  





 



 
 
 
typedef struct { double x,y; } Vector2;    
typedef Vector2 point2;                   
typedef struct { int x,y;}  Intpoint2;  
typedef struct { double element[3][3]; } Matrix3; 
typedef struct Box2dStruct { point2 min, max; } Box2;  

typedef struct { int x,y,z; } Intpoint3;  
typedef struct { double element[4][4]; } Matrix4; 
typedef struct { double x,y,z; } point3;  
typedef struct { point3 min, max; } Box;

 
typedef struct { double x,y,z; } Vector;  
typedef struct {double x,y,z,h;} point4;  

typedef struct {  
  Vector n;                       
  Vector p;                       
  double d;                       
} Plane;                          

typedef struct {               
  point3 start;                   
  Vector dir;                     
} line;                           

typedef struct {
  Vector min, max;              
} BoundingBoxType;                

typedef struct {
  double r;                     
  Vector pos;                   
} BoundingSphereType;           

 
 
 
double vdot2(); 
double vlen2();
Vector2 *vnegate2();
Vector2 *vnorm2();
Vector2 *vscale2();
Vector2 *vadd2();
Vector2 *vsub2();
Vector2 *vinterp2();
Vector2 *vcomb2();
Vector2 *vmult2();
double vdist2();
Vector2 *vperp2();
Vector2 *vnew2();
Vector2 *vdup2();
point2 *vtransform2();
Matrix3 *multmatrix2();

 
 
 
double dot();                     
Vector cross();                   
double norm();                    
double geo_line();                
Vector *vadd();                   
Vector *vsub();                   
Vector *vnegate();
Vector *vmult();
Vector *vcomb();                  
Vector *vscalar();
double vdist();
double vlen();
Vector *vscale();
Vector *vmiddle();
Vector *vinterp();
Vector *vnew();
Vector *vdup();
Vector polynorm();                
double Power();                   

Vector *reflection();             
Vector *refraction();             
Vector *geo_h();                  
Vector *geo_ht();                 

 
 
 
void copymatrix();                
int same_matrix();                
void mult_matrix();                
void smult_matrix();
Vector vtransform();              
point3 *ptransform();
Vector vrotate();                 
void transpose_matrix();
int invert_matrix();              
void cr_rotatez();
void rotatex_matrix();
void rotatey_matrix();
void rotatez_matrix();
void scale_matrix();
void translate_matrix();
void subtract_matrix();
void ZPerspective_matrix();
void reorthogonalize_matrix();
void adjoint();
double det4x4();
double det3x3();
double det2x2();

void print_vector();              
void print_vector2();
void print_matrix();              



# 27 "ff.c" 2

# 1 "misc.h" 1
 
 
 
 
 
 
 
 



 






 
 
 


















 
 
 
 





















 

 


 





 
 

 






 
 
 
 

 


 
 
 
 













# 28 "ff.c" 2

# 1 "io.h" 1
 
 
 
 
 
 
 
 
 
 



 



 


















 
typedef struct {
  int debug;		 
  int statistics;	 
  int tablelog;          
  char *tablelogstr;     
  int show_pr_steps;     
  int print_scene;       
  int write_result;      

  int ff_raytrace;       
  int grid;		 

  int poly_grid;         

  int rayTransform;	 


  int visibility;	 
  int shadow;		 

  int rad_interp_type;    
  int ambient;           

  int device;		 
  char *meshfilename;     
  char *textfilename;     
  char *viewfilename;    
  char *DebugFilename;   
  char *InLogFilename;   
  char *OutLogFilename;  
  struct _iobuf  *StatFile;        
  char *StatFilename;   
  char *OutSceneFilename;  
  int VCRmode;           
  int UseVCR;            

  int alpha;		 
  int perspective;	 
} OptionType;


# 29 "ff.c" 2

# 1 "struct.h" 1
 
 
 
 
 
 
 
 
 
 



 
 
 
 

typedef struct { double samples[3 ]; } Spectra;
typedef struct { unsigned char r,g,b,a; } ColourChar;
typedef struct { double r, g, b, a; } Colour;

 
 
 
 
 




 




















 









 
typedef struct PolyListType {
  struct PolyType *patch;
  struct PolyListType *next;
} PolyList;

typedef struct PolyListHeadType {
  PolyList *front, *back;
  int num_polys;
} PolyListHead;

 
typedef struct VertexType {
  int id;
  char *name;
  Vector pos;             
  PolyList* polylist;     
  PolyListHead polyhead;  
} Vertex;

 
typedef struct PolyUVW {
  Vector Nu, Nv, Nw;     
  double Lu, Lv, Lw;     
  double du, dv, dw;
} polyUVW;

 
typedef struct PolyType {  

  int id;                
  char *name;
  int class;             
  Vertex *vert[4];       
  Vector normal[4];	 
  int changingNormal;	 
  double area;           
  polyUVW *uvw;          
  int numVert;           
  struct PolyType *child[4];  
  double d;		 

  int level;             
  struct MeshType *Mfather;  
  struct PolyType *next;  
  struct PolyType *Pfather;  

  PolyList* Links;       
  PolyListHead polyhead;  
  Spectra unshot_B;      
  Spectra B;             
  Spectra                
    vtx_B[  4          ];     
  Spectra                
    vtx_dB[  4          ];     
} Polygon;

 
typedef struct Vertex_listType {  
  Vertex *vtx;               
  struct Vertex_listType *next;
} Vertex_list;

 
typedef struct MeshType {
  int id;
  char *name;               
  Polygon *polys;           
  int num_polys;            
  struct ObjectType *Ofather; 
  BoundingBoxType *box;     
} Mesh;

 
 
 
 
typedef struct {
  Spectra Ka;               
  Spectra Kd;               
  Spectra Ks;               
  Spectra p;                
  Spectra t;                
  Spectra n;                
} ShadeType;

 
typedef struct {
  Spectra E;                 
  Spectra B;                 
} Radiance;

 
typedef struct {
  Spectra trans;            
  Spectra Ktrans;           
  Spectra blendCol;       
} Transmit;

 
typedef struct {
  Spectra n;                
  Spectra metal;           
} Specularity;

 
typedef struct {
  int id;
  char *name;
  ShadeType shade;         
  Radiance rad;            
  Specularity spec;        
  Transmit *trans;         
} SurfaceProp;

 
typedef struct {
  int id;
  char *name;
  int lightType;           
  double standardDistance; 
  Vector shineFrom;	   
  double dropoff;	   
  double cutoff;	   
  double cosCutoff;	   
  Vector shineAt;	   
  Vector shineDir;	   
  int maxSamples;
  int usedSamples;
} LightProp;

 
typedef struct {
  int id;
  char *name;
  int class;               
  int resolution;          
  ColourChar *map;         
} TextureProp;

 
 
 
typedef struct SphereInfo {           
  Vector orig;
  double r;
} SphereInfo;

typedef struct CylInfo {              
  double h;
  double r1, r2;
} CylInfo;

typedef struct CubeInfo {             
  double length;
} CubeInfo;

typedef struct ConeInfo {             
  double h;
  double r1, r2;
} ConeInfo;

typedef struct ObjectType {
  int id;
  char *name;
  long rayID;	           
  Matrix WToM;	           
  Matrix MToW;	           
  char *primtype;          
  int primid;              
  SurfaceProp *surface;    
  TextureProp *texture;    
  LightProp *light;        
  Mesh *meshes;            
  int num_meshes;          
  char *info;              
  int (*intersect) ();     
  BoundingBoxType *box;    
  int in_facingprim;       
} Objectt;                 

 
typedef struct SceneType {
  Objectt *objects;
  TextureProp *textures;
  int num_objects;
  int num_textures;
} Scene;

 






 
 
 
extern void print_PolyList();
extern void print_Polygon();
extern void print_Vertex();
extern void print_VertexList();
extern void print_Colour();
extern void print_Spectra();
extern void print_ShadeType();
extern void print_Radiance();
extern void print_LightProp();
extern void print_TextureMap();
extern void print_Object();
extern void print_Scene();
extern char *ProgName;


# 30 "ff.c" 2

# 1 "rad.h" 1
 
 
 
 
 
 
 
 
 
 









 






typedef struct {               
  Vector lookfrom;             
  Vector lookat;               
  Vector lookup;               
  int fovx, fovy;              
  double near, far;            
  short xRes, yRes;            
  unsigned long *buffer;       
  double bank;                 
} Camera;

typedef struct Elist {         
  Polygon *element;            
  struct Elist *next;          
  double ff;                   
  double vtx_ff[  4          ];  
  int is_receiver;             
  int is_subdivided;           
} Elist;

typedef struct {               
  int log;                     
  int objcount;                
  int meshcount;               
  int polycount;               
  int totpoly;                 
  int totmesh;                 
  int num_objects;             
  int num_textures;            

  int num_elements;            
  int num_receivers;           
  Elist *elements;             
  Elist *eltail;

  double threshold;            

  int max_iterations;          
  int forming_links;           
  double intensityScale;       
  short hemicubeRes;           
  int writerad;                
  double worldSize;            
  BoundingBoxType worldbox;    

  Camera displayView;          
  double totalEnergy;          

  double totalEnergyLeft;      
  double totalArea;            
  Spectra ptotalArea;          
  Spectra ambient_term;        
} RadParams;

typedef struct {               
  Camera view;                 
  double *topFactors;          
  double *sideFactors;         
  int buffersize;              
} Hemicube;




# 31 "ff.c" 2

# 1 "ray.h" 1
 
 
 
 
 
 
 
 
 
 
 
 














 



typedef struct {         
  long	rayID;		 
  Vector origin;	 
  Vector dir;		 
  double visible;	 
  int generation;	 
  int shadow;		 
  Transmit *transmissivity; 
} Ray;

typedef struct {         
  Objectt *obj;		 
  Polygon *poly;         
  Mesh *mesh;            
  double distance;	 
  Vector intersect;	 
  Vector texture;	 
  Vector normal;	 
} HitData;

typedef struct {      
  long currentRayID;  
  long numRays;       
  long intRay;        
  long intRayID;      
  long rayCone;       
  long intCone;       
  long rayCube;       
  long intCube;       
  long raySphere;     
  long intSphere;     
  long rayCylinder;   
  long intCylinder;   
  long rayMesh;       
  long rayPoly;       
  long intPoly;       
  long rayBox;        
  long intBox;        
} RayStats_Type;

 
 
 
extern int RayBox();                 
extern int BoxEnter();
extern int BoxNormal();
extern void RayCube();               
extern RaySphere();                  
extern void RayCylinder();           
extern void RayCone();               
extern void get_uv();               
extern int Inside_Polygon();
extern BoundingBoxType BoxPoly();
extern int RayPoly_Edge();
extern int RayPlane();               
extern int RayPolygon();             

extern void Store_HitInter();        
extern void Reset_Hit();
extern Store_HitNorm();



# 32 "ff.c" 2

# 1 "ff.h" 1
 
 
 
 
 
 
 
 
 
 
 






























typedef struct {              
  Polygon *p;                 
  Vector pos;                 
  Vector norm;                
  double area;                
  Vector corners[  4          ];  
} Sampletype;

typedef struct {
  double B_min, B_max;        
  double F_min, F_max;        
  int sampling_type;          
  int num_samples;            
  int fftype;                 
  double F_diff_poly;         
  double F_diff_edge;         

  int max_levels;             
  int sample_shape;           
  int varying_numsamps;       
  int use_analytic;           

  int src_rec_cull;           

  int quadtri_ray;            


  int shaft_cull;             
  double min_element_area;    

} FF_OptionType;

typedef struct {              
  double val;                 
  Polygon *patch_i,*patch_j;  
} FF_type;

 
extern void UVToXYZ();
extern int Init_Samples();
extern int ff_Generate_Patch_Samples();
extern double ff_da_analytic();
extern double ff_da_disc();
extern double ff_patches();
extern int shoot_ray();
extern void ff_print_samples();
void ff_print_FF_Options();


# 33 "ff.c" 2

# 1 "rtime.h" 1
 
 
 
 
 
 
 
 



typedef struct {
  float avg_ray;           
  float avg_shaft;         
  float avg_ff;            
  float avg_iter;          
  float tot_time;          
  float cur_time;          
  float last_time;    
  float prep_pHBV;         
  float prep_oHBV;         
  float prep_Model;        
  float utime, stime;      
} Time_Stats;  

extern float Cpu_Time();
extern float Elapsed_Time();
extern void Init_Time();
extern void Print_Times();


# 34 "ff.c" 2


 
extern OptionType Option;
extern char *ProgName;
extern int HitObject();
extern Time_Stats tstats;

 
 
 
double MAX_F_DIFF_EDGE = 0.016;        



double MIN_ELEMENT_PERC = 0.1;         


FF_OptionType FF_Options = {           
  0.001  , 0.01   ,        
  0.005  , 0.05   ,        
  0            , 16   ,            
  0       ,  
  0.02 ,   0.016,
  0    , 3            
  };

 
 
 
void ff_print_FF_Options(ffopt)
     FF_OptionType ffopt;
{
  struct _iobuf  *fp;
  if (Option.device == 	1 )
    fp = (&_iob[1]) ;
  else
    fp = Option.StatFile;

  fprintf(fp,"\n\t*** Form-factor options *** \n");
  fprintf(fp,"\tB {max %g} {min %g}\n", ffopt.B_max, ffopt.B_min);
  fprintf(fp,"\tF {max %g} {min %g}\n", ffopt.F_max, ffopt.F_min);
  fprintf(fp,"\t%s %s form factors", 
	 (ffopt.fftype == 1         ? "Analytic" : "Numerical"),
	 (ffopt.sample_shape == 2          ? "elliptical" : "circular"));
  if (ffopt.use_analytic) fprintf(fp,", WITH Analytic for special cases.\n");
  else fprintf(fp,".\n");
  fprintf(fp,"\tMinimum subdivision area %g\n", ffopt.min_element_area);
  fprintf(fp,"\tMaximum poly form factor difference %g\n", ffopt.F_diff_poly);
  fprintf(fp,"\tMaximum edge form factor difference %g\n", ffopt.F_diff_edge);
  fprintf(fp,"\tMaximum patch subdivision levels %d\n", ffopt.max_levels);

  if (Option.ff_raytrace) {
    fprintf(fp,"\tUsing ray cast visibility testing, with\n");
    fprintf(fp,"\t%s sampling with %d %s samples per polygon.\n", 
	   (ffopt.sampling_type == 0             ? "uniform" : "jittered"),
	   ffopt.num_samples,
	   (ffopt.varying_numsamps == 1 ? "adjusted" : "unadjusted"));
  }
}
  
 
 
 
 
void UVToXYZ(quad, u, v, xyz)
     Vector quad[  4          ];
     double u,v;
     Vector *xyz;
{
  xyz->x = quad[0].x * (1.-u)*(1.-v) + quad[1].x * (1.-u)*v + 
    quad[2].x *u*v + quad[3].x * u*(1.-v);
  xyz->y = quad[0].y * (1.-u)*(1.-v) + quad[1].y * (1.-u)*v + 
    quad[2].y *u*v + quad[3].y * u*(1.-v);
  xyz->z = quad[0].z * (1.-u)*(1.-v) + quad[1].z * (1.-u)*v + 
    quad[2].z *u*v + quad[3].z * u*(1.-v);
}

 
 
 
int Init_Samples(s)
     Sampletype s[64       ];
{
  int i;
  for(i=0;i<64       ;i++) { s[i].p = 0; }
}

 
 
 
void ff_print_samples(s,num_samples,label)
     Sampletype s[64       ];
     int num_samples;
     char *label;
{
  int i,j;

  printf("\n\tSamples %s (%d) {\n", label, num_samples);
  for(i=0;i<num_samples;i++) {
    printf("\tPoly[%d] %s%d {", i, s[i].p->name, s[i].p->id);
    printf(" Pos %g %g %g;", s[i].pos.x, s[i].pos.y, s[i].pos.z);
    printf(" Norm %g %g %g;", s[i].norm.x, s[i].norm.y, s[i].norm.z);
    printf(" A %g\n", s[i].area);

    printf("\tCorners: ");
    for(j=0;j<s[i].p->numVert;j++)
      printf("(%g %g %g) ", s[i].corners[j].x, s[i].corners[j].y, 
	     s[i].corners[j].z);
    printf("\n");  
  }
  printf("\t}\n");  
}

 
 
 
void Sample_Triangle_Center(tri,s,iter,sample_num)
     Vector tri[4];
     Sampletype s[64       ];
     int iter;
     int *sample_num;
{
  int i;
  Vector mid[3];
  Vector corners[3];
  Vector tri_sample;
  
  if (iter >= 0) 
    iter--;
  else
    return;

   
  if (iter == -1) {
    tri_sample.x = (tri[0].x + tri[1].x + tri[2].x) / 3.0;
    tri_sample.y = (tri[0].y + tri[1].y + tri[2].y) / 3.0;
    tri_sample.z = (tri[0].z + tri[1].z + tri[2].z) / 3.0;
    s[*sample_num].pos = tri_sample;
    for(i=0;i<3;i++) 
      s[*sample_num].corners[i] = tri[i];
    (*sample_num)++;
  }

   
  mid[0] = *vmiddle(&tri[0],&tri[1]);
  mid[1] = *vmiddle(&tri[1],&tri[2]);
  mid[2] = *vmiddle(&tri[2],&tri[0]);

   
  corners[0] = tri[0];  corners[1] = mid[0];  corners[2] = mid[2];
  Sample_Triangle_Center(corners,s,iter,sample_num);  

  corners[0] = mid[0];  corners[1] = tri[1];  corners[2] = mid[1];
  Sample_Triangle_Center(corners,s,iter,sample_num);

  corners[0] = mid[2];  corners[1] = mid[0];  corners[2] = mid[1];
  Sample_Triangle_Center(corners,s,iter,sample_num);  

  corners[0] = mid[2];  corners[1] = mid[1];  corners[2] = tri[2];
  Sample_Triangle_Center(corners,s,iter,sample_num);  

}

 
 
 
void Sample_Triangle(tri,s,num_samples,sample_type, corners, area, normal)
     Polygon *tri;
     Sampletype s[64       ];
     int num_samples;
     int sample_type;
     Vector corners[  4          ];
     double area;
     Vector normal;
{
  int i;
  int sample_num = 0;
  int iter;
  double result;

   
  for(i=0;i<num_samples;i++) {
    s[sample_num].p = tri;
    s[sample_num].norm = normal;
    s[sample_num++].area = area / num_samples;
  }

   

  iter = 0; result = num_samples / 4.0;
  while (result >= 1.0) {
    iter++;
    result /= 4.0;
  }
  sample_num = 0;
  Sample_Triangle_Center(corners,s,iter,&sample_num);
}
  
 
 
 
void Sample_Quad(quad,s,num_samples,sample_type, corners, area, normal)
     Polygon *quad;
     Sampletype s[64       ];
     int num_samples;
     int sample_type;
     Vector corners[  4          ];
     double area;
     Vector normal;
{
  int i,j;
  double u,v, du, dv;
  double jitter_u, jitter_v;
  Vector tmp;
  int nu, nv;
  int sample_num = 0;

  for(i=0;i<  4          ;i++) 
    corners[i] = quad->vert[i]->pos;
  
   
  nv = nu =  ((sqrt((double)num_samples))==(int)(sqrt((double)num_samples)) ? (sqrt((double)num_samples)) : (sqrt((double)num_samples))>0 ? 1+(int)(sqrt((double)num_samples)) : -(1+(int)(-sqrt((double)num_samples)))) ;
  dv = du = 1.0 / (double) nu;
  
  for(i=0,u=du/2.0; i<nu; i++, u+=du) {
    for(j=0,v=dv/2.0; j<nv; j++, v+=dv, sample_num++) {
      UVToXYZ(corners, u, v, &tmp);
      s[sample_num].pos = tmp;
      UVToXYZ(corners, u-du/2.0, v-dv/2.0, &tmp);
      s[sample_num].corners[0] = tmp;
      UVToXYZ(corners, u+du/2.0, v-dv/2.0, &tmp);
      s[sample_num].corners[1] = tmp;
      UVToXYZ(corners, u+du/2.0, v+dv/2.0, &tmp);
      s[sample_num].corners[2] = tmp;
      UVToXYZ(corners, u-du/2.0, v+dv/2.0, &tmp);
      s[sample_num].corners[3] = tmp;
      s[sample_num].p = quad;
      s[sample_num].norm = normal;
      s[sample_num].area = area / num_samples;
    }
  }
}




 
 
 
 
 
 
 
 
int Adjusted_NumSamples(p)
     Polygon *p;
{   
  int i;
  int num_samps, scale;
  int sample_weight;  


  if (FF_Options.num_samples == 16)
    sample_weight = 2;
  else if (FF_Options.num_samples == 4)
    sample_weight = 1;
  else 
    sample_weight = 0;

   
  for (i=0;i<3 ;i++)
    if (p->unshot_B.samples[i] < 0.1 ) 
      sample_weight--;

   
   

   
  if (p->level > 0) {
    scale = (int) Power(4.0,(double)p->level);
    if (scale >= FF_Options.num_samples)
      sample_weight = 0;
    else
      sample_weight -= p->level;
  }

  num_samps = 1;
  if (sample_weight < 0)      sample_weight = 0;
  else if (sample_weight > 2) sample_weight = 2;
  for (i=1;i<sample_weight;i++)
    num_samps = num_samps * 4;

  if (Option.statistics) {
    if (Option.device == 	1 )
      printf("\tAdjusted number samples = %d\n", num_samps);
    else
      fprintf(Option.StatFile,"\tAdjusted number samples = %d\n", num_samps);
  }

# 345 "ff.c"


  return num_samps;
}

 
 
 
int ff_Generate_Patch_Samples(p,s,corners,area,normal)
     Polygon *p;
     Sampletype s[64       ];
     Vector corners[  4          ];
     double area;
     Vector normal;
{
  int num_samples;
  int i;

  if (FF_Options.fftype == 1        )
    num_samples = 4   ;
  else {
    if (FF_Options.varying_numsamps)
      num_samples = Adjusted_NumSamples(p);
    else
      num_samples = FF_Options.num_samples;
  }

  switch (FF_Options.sampling_type) {

  case -1           :                

    for (i=0;i<num_samples;i++) {
      s[i].p = p;
      s[i].pos = corners[i];
      s[i].norm = normal;
      s[i].area = area / num_samples;
    }
    break;
    
  case 0            :                

    if (p->class == 	7          ) 
      Sample_Quad(p,s,num_samples,0            ,corners,area,normal);
    else if (p->class == 8          )
      Sample_Triangle(p,s,num_samples,0            ,corners,area,normal);
    break;
    
  case 1           :                 

    if (p->class == 	7          ) 
      Sample_Quad(p,s,num_samples,1           ,corners,area,normal);
    else if (p->class == 8          )
      Sample_Triangle(p,s,num_samples,1           ,corners,area,normal);
    break;
    
  default:
    fprintf((&_iob[2]) ,"%s: Unknown sampling type %d\n", ProgName,
	    FF_Options.sampling_type);
    exit(1);
  }
  return (num_samples);
}


 
 
 
int Patches_Abut(src,rec)
     Polygon *src, *rec;
{
  int i;
  Vector rv, sv, sn, ray_dir;
  double cos_angle_p;
  int is_perp = 0 ;
  int is_touching = 0 ;

   
  sn = src->normal[0];
  i = 0;
  while (i<rec->numVert && is_perp == 0 ) {
    sv = src->vert[0]->pos;
    rv = rec->vert[i]->pos;
    ray_dir = *vsub(&sv,&rv);
    norm(&ray_dir);
    cos_angle_p = dot(&sn, vnegate(&ray_dir));
    if (cos_angle_p == 0.0) 
      is_perp = 1 ;
    i++;
  }

  if (is_perp) {
    i = 0;
    while (i<src->numVert && is_touching == 0 ) {
      sv = src->vert[i]->pos;
      if (vsame(&rv, &sv,       (1e-10) )) is_touching = 1 ;
      i++;
    }
  }
  return is_touching;
}  

int FF_Testing = 0;                                
 
 
 
 
int shoot_ray(ray_orig, ray_dir, s, t)
     Vector ray_orig, ray_dir;
     Sampletype s;
     double *t;
{
  double tmp;
  Vector normray_dir;

  tmp = vlen(&ray_dir);       
  *t = tmp;
  if (FF_Testing) {
    printf("\tShooting from %g,%g,%g to %g,%g,%g ", 
	   ray_orig.x, ray_orig.y, ray_orig.z,
	   ray_dir.x, ray_dir.y, ray_dir.z);
    printf("at pos %g %g %g. t = %g\n", s.pos.x, s.pos.y, s.pos.z, *t);
  }

   

  if (Option.visibility == 11 ) {
    normray_dir = ray_dir;
    norm(&normray_dir);
    if (HitObject(ray_orig, normray_dir, *t))
      return 0;
    else
      return 1;
  } else
    return 1;
}

 
 
 
 
double ff_da_analytic(pptr, from, corners, pnorm)
     Polygon *pptr;                     
     Vector *from;                      
     Vector *pnorm;                     
     Vector corners[  4          ];     
{
  int i, ii;
  double dff;
  Vector R[  4          ];
  Vector Tau[  4          ];
  Vector direction;
  double corner_angle;
  double cos_corner_angle;

   

  for(i=0;i<(pptr->numVert);i++) {
    R[i] = *vsub(&corners[i], from);
    norm(&R[i]);
  }
  
   
  dff = 0.0;
  for(i=0;i<pptr->numVert;i++) {
    ii = (i + 1) % pptr->numVert;
    cos_corner_angle = dot(&R[i], &R[ii]);
    corner_angle = acos(cos_corner_angle);
    direction = cross(&R[i], &R[ii]);
    norm(&direction);
    Tau[i] = *vscalar(corner_angle, &direction);
    dff += fabs(dot(pnorm, &Tau[i]));
  }

  dff = dff / (2.0 *               (3.14159265358979323846) );
  return(dff);
}


 
 
 
 
 
double ff_da_disc(v,n,p,samples,num_samples)
     Vector v, n;                 
     Polygon *p;                        
     Sampletype samples[64       ];   
     int num_samples;                   
{
  int i;
  double ff, cos_angle_v, cos_angle_p, t, dff, w;  
  Vector ray_dir;                     
  Vector norm_ray_dir;                
					
   
  ff = 0.0;
  for (i=0;i<num_samples;i++) {
    ray_dir = *vsub(&(samples[i].pos), &v);
    norm_ray_dir = ray_dir;
    norm(&norm_ray_dir);
    w = samples[i].area;
    if (shoot_ray(v, ray_dir, samples[i], &t)) {
      cos_angle_v = dot(&n, &norm_ray_dir);
      cos_angle_p = dot(&(samples[i].norm), vnegate(&norm_ray_dir));
      if (cos_angle_p == 0.0) cos_angle_p = cos(	 0.017453	 * 90.0);      
      dff = (cos_angle_v * cos_angle_p) / ((3.14159265358979323846  * t*t) + samples[i].area);
      
       
      dff = dff * w;
      ff += dff;
    }
  }
  return(ff);
}

 
 
 
double ff_da_ellipse(v,n,p,samples,num_samples)
     Vector v, n;                 
     Polygon *p;                        
     Sampletype samples[64       ];   
     int num_samples;                   
{
  int i;
  double ff, cos_angle_v, cos_angle_p, t, dff, w;  
  Vector ray_dir;                     
  Vector norm_ray_dir;                
  double a,b;
					
   
  ff = 0.0;
  for (i=0;i<num_samples;i++) {
    ray_dir = *vsub(&(samples[i].pos), &v);
    a = vlen(vsub(&samples[i].pos, 
		  vmiddle(&samples[i].corners[2], &samples[i].corners[1])));
    if (p->class == 8          )
      b = vlen(vsub(&samples[i].pos, &samples[i].corners[2]));
    else
      b = vlen(vsub(&samples[i].pos, 
		    vmiddle(&samples[i].corners[3], &samples[i].corners[2])));

    norm_ray_dir = ray_dir;
    norm(&norm_ray_dir);
    w = samples[i].area;
    if (shoot_ray(v, ray_dir, samples[i], &t)) {
      cos_angle_v = dot(&n, &norm_ray_dir);
      cos_angle_p = dot(&(samples[i].norm), vnegate(&norm_ray_dir));
      if (cos_angle_p == 0.0) cos_angle_p = cos(	 0.017453	 * 90.0);

      if (a == b)  
	dff = (cos_angle_v * cos_angle_p) / ((3.14159265358979323846  * t*t) + samples[i].area);
      else        
	dff = (cos_angle_v * cos_angle_p) / 
	  (3.14159265358979323846  * sqrt( (t*t+a*a) * (t*t+b*b) ) );
      dff = dff * w;

       
      ff += dff;
    }
  }
  return(ff);
}
	
 
 
 
 
double ff_patches(src,rec,ff_rs_vtx,
		  num_src_samples, src_samples,
		  corners)
     Polygon *src;                          
     Polygon *rec;                          
     double ff_rs_vtx[  4          ];       
     int num_src_samples;                   
     Sampletype src_samples[64       ];   
     Vector corners[  4          ];         
{
  int i;
  double ff_rs;                        
  double element_ff;
  Vector element_pos, element_norm;
  Vector rec_corners[  4          ];     
  Sampletype rec_samples[64       ];
  int num_rec_samples;  

  float ff_start, ff_end;
  
  ff_rs = 0.0;
  ff_start = Cpu_Time(&tstats.utime, &tstats.stime);  
  
  if (FF_Options.fftype == 0       ) {
    
     
    for(i=0;i<rec->numVert;i++) { 
      ff_rs_vtx[i] = 0.0;
      element_pos = rec->vert[i]->pos;
      element_norm = rec->normal[0];
      
       

       

      if (FF_Options.sample_shape == 3            )
	element_ff = ff_da_disc(element_pos, element_norm,
				src, src_samples, num_src_samples);
      else
	element_ff = ff_da_ellipse(element_pos, element_norm,
				src, src_samples, num_src_samples);	
      if (element_ff > 0.0) {
	ff_rs += element_ff;                 
	ff_rs_vtx[i] = element_ff;           
      }
    } 
  } 

  else if (FF_Options.fftype == 1        ) {

     
    for(i=0;i<rec->numVert;i++) 
      rec_corners[i] = rec->vert[i]->pos;
    num_rec_samples = ff_Generate_Patch_Samples(rec,rec_samples, rec_corners, 
						rec->area, rec->normal[0]);
    for (i=0;i<num_rec_samples;i++) { 
      ff_rs_vtx[i] = ff_da_analytic(src, &rec_samples[i].pos, corners,
				    &rec->normal[0]);
      ff_rs_vtx[i] /= (double)num_rec_samples;
      ff_rs += ff_rs_vtx[i];
    }
  }

  ff_end = Cpu_Time(&tstats.utime, &tstats.stime);  
  tstats.avg_ff += (ff_end - ff_start);

  if (Option.debug) {
    printf("\t+ Receiver %s%d to source %s%d ff: %g\n\t  with vertex ff: ", 
	   rec->name, rec->id, src->name, src->id,ff_rs);
    for(i=0;i<rec->numVert;i++) printf("%g ",ff_rs_vtx[i]);
    printf("\n");
  }
  return (ff_rs);
}

 
 
 
 
 
 
void LinkPoly_ToPoly(to_poly, link_poly, ff_to_link)
     Polygon *to_poly, *link_poly;
     double ff_to_link;
{
  PolyList *pl;

  pl = (PolyList *) malloc(sizeof(PolyList));
  pl->patch = link_poly;
  pl->next = (PolyList *)0;

  if (to_poly->polyhead.num_polys == 0) {  
    to_poly->Links = pl;
    to_poly->polyhead.front = to_poly->polyhead.back = to_poly->Links;
  } else {           
    to_poly->polyhead.back->next = pl;
    to_poly->polyhead.back = pl;
  }
  to_poly->polyhead.num_polys++;
}

 
 
 
void ff_Link_Patches(p,q, ff_pq, ff_qp)
     Polygon *p, *q;
     double ff_pq, ff_qp;
{
  if (Option.debug)
    printf("\tLinking polygon %s%d and poly %s%d.\n",
	   p->name, p->id, q->name, q->id);
  LinkPoly_ToPoly(p,q, ff_pq);
  LinkPoly_ToPoly(q,p, ff_qp);
}

 
 
 
void ff_BF_Refine(src,rec)
     Polygon *src, *rec;
{
  int i;
  double ff_rs, ff_sr;
  double ff_difference;
  double subdiv_src_area, subdiv_rec_area;
  double ff_rs_vtx[  4          ];
  double ff_sr_vtx[  4          ];

  int num_src_samples;          
  int num_rec_samples;          
  Sampletype src_samples[64       ];
  Sampletype rec_samples[64       ];
  Vector src_corners[  4          ];
  Vector rec_corners[  4          ];
  
   

  for(i=0;i<src->numVert;i++) src_corners[i] = src->vert[i]->pos;
  num_src_samples = ff_Generate_Patch_Samples(src,src_samples, 
					      src_corners, src->area, 
					      src->normal[0]);
  for(i=0;i<rec->numVert;i++) rec_corners[i] = rec->vert[i]->pos;
  num_rec_samples = ff_Generate_Patch_Samples(rec,rec_samples, 
					      rec_corners, rec->area, 
					      rec->normal[0]);

   
  ff_sr = ff_patches(src,rec,ff_sr_vtx, num_src_samples,
		     src_samples, src_corners);
  ff_rs = ff_patches(rec,src,ff_rs_vtx, num_rec_samples,
		     rec_samples, rec_corners);
  ff_difference = fabs(ff_sr - ff_rs);
  subdiv_src_area = src->area / 4.0;
  subdiv_rec_area = rec->area / 4.0;

  if ((ff_rs < FF_Options.F_min) && (ff_sr < FF_Options.F_min))
    ff_Link_Patches(src,rec, ff_sr, ff_rs);
  else if (ff_difference > FF_Options.F_diff_poly) {

    if (ff_sr > ff_rs) {
      if (subdiv_rec_area > FF_Options.min_element_area) {
	 
	Subdivide_Polygon(rec);
	for (i=0;i<4       ;i++) 
	  ff_BF_Refine(src,rec->child[i]);
      } else 
	ff_Link_Patches(src,rec, ff_sr, ff_rs);
    } else {
      if (subdiv_src_area > FF_Options.min_element_area) {
	 
	Subdivide_Polygon(src);
	for (i=0;i<4       ;i++) 
	  ff_BF_Refine(rec,src->child[i]);
      } else 
	ff_Link_Patches(src,rec, ff_sr, ff_rs);
    }
  }
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads