Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:19:46

0001 #ifndef CORNELIUS_H
0002 #define CORNELIUS_H
0003 
0004 #include <iostream>
0005 #include <fstream>
0006 #include <math.h>
0007 #include <stdlib.h>
0008 
0009 using namespace std;
0010 
0011 /**
0012  *
0013  * General class for elements. All other element classes are inherited
0014  * from this.
0015  *
0016  */
0017 class GeneralElement
0018 {
0019   protected:
0020     static const int DIM = 4;
0021     double *centroid;
0022     double *normal;
0023     int normal_calculated;
0024     int centroid_calculated;
0025     virtual void calculate_centroid() {};
0026     virtual void calculate_normal() {};
0027     void check_normal_direction(double *normal, double *out);
0028   public:
0029     GeneralElement();
0030     ~GeneralElement();
0031     double *get_centroid();
0032     double *get_normal();
0033 };
0034 
0035 /**
0036  *
0037  * This class is used for line elements gotten from the squares. Can
0038  * calculate the centroid and normal of the line.
0039  *
0040  */
0041 class Line : public GeneralElement
0042 {
0043   private:
0044     static const int LINE_CORNERS = 2;
0045     static const int LINE_DIM = 2;
0046     int x1,x2;
0047     int start_point;
0048     int end_point;
0049     double **corners;
0050     double *out;
0051     int *const_i;
0052     void calculate_centroid();
0053     void calculate_normal();
0054   public:
0055     Line();
0056     ~Line();
0057     void init(double**,double*,int*);
0058     void flip_start_end();
0059     double *get_start();
0060     double *get_end();
0061     double *get_out();
0062 };
0063 
0064 /**
0065  *
0066  * A class for storing polygons given by Cornelius. Can calculate
0067  * the centroid and normal of the polygon.
0068  *
0069  */
0070 class Polygon : public GeneralElement
0071 {
0072   private:
0073     static const int MAX_LINES = 24;
0074     static const int POLYGON_DIM = 3;
0075     Line **lines;
0076     int Nlines;
0077     int x1,x2,x3;
0078     int const_i;
0079     void calculate_centroid();
0080     void calculate_normal();
0081   public:
0082     Polygon();
0083     ~Polygon();
0084     void init(int);
0085     bool add_line(Line*,int);
0086     int get_Nlines();
0087     Line** get_lines();
0088     void print(ofstream &file,double*);
0089 };
0090 
0091 /**
0092  *
0093  * A class for storing polyhedrons given by Cornelius. Can calculate
0094  * the normal and centroid of the polyhedron.
0095  *
0096  */
0097 class Polyhedron : public GeneralElement
0098 {
0099   private:
0100     static const int MAX_POLYGONS = 24;
0101     Polygon **polygons;
0102     int Npolygons;
0103     int Ntetrahedra;
0104     int x1,x2,x3,x4;
0105     bool lines_equal(Line*,Line*);
0106     void tetravolume(double*,double*,double*,double*);
0107     void calculate_centroid();
0108     void calculate_normal();
0109   public:
0110     Polyhedron();
0111     ~Polyhedron();
0112     void init();
0113     bool add_polygon(Polygon*,int);
0114 };
0115 
0116 /**
0117  *
0118  * This class handles the squares which are splitted from the cube.
0119  * Finds the edges of the surface and also the poinst which point
0120  * the outward direction.
0121  *
0122  * 13.10.2011 Hannu Holopainen
0123  *
0124  */
0125 class Square
0126 {
0127   private:
0128     static const int DIM = 4;
0129     static const int SQUARE_DIM = 2;
0130     static const int MAX_POINTS = 4;
0131     static const int MAX_LINES = 2;
0132     double **points;
0133     double **cuts;
0134     double **out;
0135     double **points_temp;
0136     double *out_temp;
0137     int *const_i;
0138     double *const_value;
0139     int x1, x2;
0140     double *dx;
0141     int Ncuts;
0142     int Nlines;
0143     Line *lines;
0144     int ambiguous;
0145     void ends_of_edge(double);
0146     void find_outside(double);
0147   public:
0148     Square();
0149     ~Square();
0150     void init(double**,int*,double*,double*);
0151     void construct_lines(double);
0152     int is_ambiguous();
0153     int get_Nlines();
0154     Line* get_lines();
0155 };
0156 
0157 /**
0158  *
0159  * This class handles 3d-cubes. Splits them into squares and collects
0160  * polygons from the lines given from squares.
0161  *
0162  * 13.10.2011 Hannu Holopainen
0163  *
0164  */
0165 class Cube
0166 {
0167   private:
0168     static const int DIM = 4;
0169     static const int CUBE_DIM = 4;
0170     static const int MAX_POLY = 8;
0171     static const int NSQUARES = 6;
0172     static const int STEPS = 2;
0173     double ***cube;
0174     Line **lines;
0175     Polygon *polygons;
0176     Square *squares;
0177     int Nlines;
0178     int Npolygons;
0179     int ambiguous;
0180     int const_i;
0181     double const_value;
0182     int x1,x2,x3;
0183     double *dx;
0184     void split_to_squares();
0185     void check_ambiguous(int);
0186   public:
0187     Cube();
0188     ~Cube();
0189     void init(double***&,int,double,double*&);
0190     void construct_polygons(double);
0191     int get_Nlines();
0192     int get_Npolygons();
0193     int is_ambiguous();
0194     Polygon* get_polygons();
0195 };
0196 
0197 
0198 /**
0199  *
0200  * This class handles 4d-cubes. Splits them into squares and collects
0201  * polygons from the lines given from squares.
0202  *
0203  * 13.10.2011 Hannu Holopainen
0204  *
0205  */
0206 class Hypercube
0207 {
0208   private:
0209     static const int DIM = 4;
0210     static const int MAX_POLY = 10;
0211     static const int NCUBES = 8;
0212     static const int STEPS = 2;
0213     double ****hcube;
0214     Polyhedron *polyhedrons;
0215     Polygon **polygons;
0216     Cube *cubes;
0217     int Npolyhedrons;
0218     int ambiguous;
0219     int x1,x2,x3,x4;
0220     double *dx;
0221     void split_to_cubes();
0222     void check_ambiguous(double);
0223   public:
0224     Hypercube();
0225     ~Hypercube();
0226     void init(double****,double*);
0227     void construct_polyhedrons(double);
0228     int get_Npolyhedrons();
0229     Polyhedron* get_polyhedrons();
0230 };
0231 
0232 /**
0233  *
0234  * A class for finding a constant value surface from a 2-4 dimensional
0235  * cube. The values at corners and length of the side are needed as
0236  * an input.
0237  *
0238  * Algorithm by Pasi Huovinen. This code is based on the original FORTRAN
0239  * code by Pasi Huovinen.
0240  *
0241  * 23.04.2012 Hannu Holopainen
0242  *
0243  */
0244 class Cornelius
0245 {
0246   private:
0247     static const int STEPS = 2;
0248     static const int DIM = 4;
0249     static const int MAX_ELEMENTS = 10;
0250     int Nelements;
0251     double **normals;
0252     double **centroids;
0253     int cube_dim;
0254     int initialized;
0255     int print_initialized;
0256     double value0;
0257     double *dx;
0258     ofstream output_print;
0259     void surface_3d(double***,double*,int);
0260     Square cu2d;
0261     Cube cu3d;
0262     Hypercube cu4d;
0263   public:
0264     Cornelius();
0265     ~Cornelius();
0266     void init(int,double,double*);
0267     void init_print(string);
0268     void find_surface_2d(double**);
0269     void find_surface_3d(double***);
0270     void find_surface_3d_print(double***,double*);
0271     void find_surface_4d(double****);
0272     int get_Nelements();
0273     double **get_normals();
0274     double **get_centroids();
0275     double **get_normals_4d();
0276     double **get_centroids_4d();
0277     double get_centroid_elem(int,int);
0278     double get_normal_elem(int,int);
0279 };
0280 
0281 #endif /* CORNELIUS_H */