File indexing completed on 2025-08-03 08:19:42
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 #include <fstream>
0010
0011 using std::string;
0012 using std::vector;
0013 using std::ofstream;
0014 using std::ifstream;
0015 using std::abs;
0016
0017
0018
0019
0020
0021
0022
0023 class GeneralElement
0024 {
0025 protected:
0026 static const int DIM = 4;
0027 double *centroid;
0028 double *normal;
0029 int normal_calculated;
0030 int centroid_calculated;
0031 virtual void calculate_centroid() {};
0032 virtual void calculate_normal() {};
0033 void check_normal_direction(double *normal, double *out);
0034 public:
0035 GeneralElement();
0036 ~GeneralElement();
0037 double *get_centroid();
0038 double *get_normal();
0039 };
0040
0041
0042
0043
0044
0045
0046
0047 class Line : public GeneralElement
0048 {
0049 private:
0050 static const int LINE_CORNERS = 2;
0051 static const int LINE_DIM = 2;
0052 int x1,x2;
0053 int start_point;
0054 int end_point;
0055 double **corners;
0056 double *out;
0057 int *const_i;
0058 void calculate_centroid();
0059 void calculate_normal();
0060 public:
0061 Line();
0062 ~Line();
0063 void init(double**,double*,int*);
0064 void flip_start_end();
0065 double *get_start();
0066 double *get_end();
0067 double *get_out();
0068 };
0069
0070
0071
0072
0073
0074
0075
0076 class Polygon : public GeneralElement
0077 {
0078 private:
0079 static const int MAX_LINES = 24;
0080 static const int POLYGON_DIM = 3;
0081 Line **lines;
0082 int Nlines;
0083 int x1,x2,x3;
0084 int const_i;
0085 void calculate_centroid();
0086 void calculate_normal();
0087 public:
0088 Polygon();
0089 ~Polygon();
0090 void init(int);
0091 bool add_line(Line*,int);
0092 int get_Nlines();
0093 Line** get_lines();
0094 void print(ofstream &file,double*);
0095 };
0096
0097
0098
0099
0100
0101
0102
0103 class Polyhedron : public GeneralElement
0104 {
0105 private:
0106 static const int MAX_POLYGONS = 24;
0107 Polygon **polygons;
0108 int Npolygons;
0109 int Ntetrahedra;
0110 int x1,x2,x3,x4;
0111 bool lines_equal(Line*,Line*);
0112 void tetravolume(double*,double*,double*,double*);
0113 void calculate_centroid();
0114 void calculate_normal();
0115 public:
0116 Polyhedron();
0117 ~Polyhedron();
0118 void init();
0119 bool add_polygon(Polygon*,int);
0120 };
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 class Square
0132 {
0133 private:
0134 static const int DIM = 4;
0135 static const int SQUARE_DIM = 2;
0136 static const int MAX_POINTS = 4;
0137 static const int MAX_LINES = 2;
0138 double **points;
0139 double **cuts;
0140 double **out;
0141 double **points_temp;
0142 double *out_temp;
0143 int *const_i;
0144 double *const_value;
0145 int x1, x2;
0146 double *dx;
0147 int Ncuts;
0148 int Nlines;
0149 Line *lines;
0150 int ambiguous;
0151 void ends_of_edge(double);
0152 void find_outside(double);
0153 public:
0154 Square();
0155 ~Square();
0156 void init(double**,int*,double*,double*);
0157 void construct_lines(double);
0158 int is_ambiguous();
0159 int get_Nlines();
0160 Line* get_lines();
0161 };
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171 class Cube
0172 {
0173 private:
0174 static const int DIM = 4;
0175 static const int CUBE_DIM = 4;
0176 static const int MAX_POLY = 8;
0177 static const int NSQUARES = 6;
0178 static const int STEPS = 2;
0179 double ***cube;
0180 Line **lines;
0181 Polygon *polygons;
0182 Square *squares;
0183 int Nlines;
0184 int Npolygons;
0185 int ambiguous;
0186 int const_i;
0187 double const_value;
0188 int x1,x2,x3;
0189 double *dx;
0190 void split_to_squares();
0191 void check_ambiguous(int);
0192 public:
0193 Cube();
0194 ~Cube();
0195 void init(double***&,int,double,double*&);
0196 void construct_polygons(double);
0197 int get_Nlines();
0198 int get_Npolygons();
0199 int is_ambiguous();
0200 Polygon* get_polygons();
0201 };
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212 class Hypercube
0213 {
0214 private:
0215 static const int DIM = 4;
0216 static const int MAX_POLY = 10;
0217 static const int NCUBES = 8;
0218 static const int STEPS = 2;
0219 double ****hcube;
0220 Polyhedron *polyhedrons;
0221 Polygon **polygons;
0222 Cube *cubes;
0223 int Npolyhedrons;
0224 int ambiguous;
0225 int x1,x2,x3,x4;
0226 double *dx;
0227 void split_to_cubes();
0228 void check_ambiguous(double);
0229 public:
0230 Hypercube();
0231 ~Hypercube();
0232 void init(double****,double*);
0233 void construct_polyhedrons(double);
0234 int get_Npolyhedrons();
0235 Polyhedron* get_polyhedrons();
0236 };
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250 class Cornelius
0251 {
0252 private:
0253 static const int STEPS = 2;
0254 static const int DIM = 4;
0255 static const int MAX_ELEMENTS = 10;
0256 int Nelements;
0257 double **normals;
0258 double **centroids;
0259 int cube_dim;
0260 int initialized;
0261 int print_initialized;
0262 double value0;
0263 double *dx;
0264 ofstream output_print;
0265 void surface_3d(double***,double*,int);
0266 Square cu2d;
0267 Cube cu3d;
0268 Hypercube cu4d;
0269 public:
0270 Cornelius();
0271 ~Cornelius();
0272 void init(int,double,double*);
0273 void init_print(string);
0274 void find_surface_2d(double**);
0275 void find_surface_3d(double***);
0276 void find_surface_3d_print(double***,double*);
0277 void find_surface_4d(double****);
0278 int get_Nelements();
0279 double **get_normals();
0280 double **get_centroids();
0281 double **get_normals_4d();
0282 double **get_centroids_4d();
0283 double get_centroid_elem(int,int);
0284 double get_normal_elem(int,int);
0285 };
0286
0287 #endif