box.h
Go to the documentation of this file.
1 #ifndef BOXH
2 #define BOXH
3 
4 #include "interval.h"
5 #include "boolean.h"
6 #include "variable_set.h"
7 #include "vector.h"
8 
9 #include <stdio.h>
10 
11 
20 /************************************************************************************/
25 #define EMPTY_BOX 0
26 
32 #define ERROR_IN_PROCESS 1
33 
38 #define REDUCED_BOX 2
39 
45 #define UNBOUNDED_BOX 3
46 
52 #define REDUCED_BOX_WITH_SOLUTION 4
53 
59 #define NOT_REDUCED_BOX 5
60 
65 #define BOX_OK 6
66 /************************************************************************************/
67 
83 typedef struct {
84  unsigned int level;
85  unsigned int n;
87 } Tbox;
88 
99 void InitBox(unsigned int dim,Tinterval *is,Tbox *b);
100 
110 void InitBoxFromPoint(unsigned int dim,double *p,Tbox *b);
111 
124 void EnlargeBox(double lo,double uo,Tbox *b);
125 
136 void ExpandBox(double *p,Tbox *b);
137 
152 unsigned int GetBoxBufferSize(Tbox *b);
153 
169 void Box2Buffer(unsigned int c,unsigned int n,double *buffer,Tbox *b);
170 
190 void Buffer2Box(unsigned int *c,unsigned int *n,double *buffer,Tbox *b);
191 
206 void CopyBox(void *b_out,void *b_in);
207 
217 void MergeBoxes(Tbox *b1,Tbox *b2,Tbox *bout);
218 
235 void CopyBoxSubset(boolean *used,void *b_out,void *b_in);
236 
253 void SetBoxSubset(boolean *used,Tbox *bset,Tbox *b);
254 
266 void SetBoxIntervals(Tinterval *is,Tbox *b);
267 
268 
279 void SetBoxInterval(unsigned int n,Tinterval *is,Tbox *b);
280 
281 
304 boolean BoxesIntersection(boolean *used,Tbox *b1,Tbox *b2,Tbox *bout);
305 
327 void BoxUnion(boolean *used,Tbox *b1,Tbox *b2,Tbox *b_out);
328 
329 
343 void Crop2Box(boolean *used,unsigned int n,double *p,Tbox *b);
344 
362 boolean PointInBox(boolean *used,unsigned int n,double *v,double tol,Tbox *b);
363 
388 boolean PointInBoxTopology(boolean *used,boolean update,
389  unsigned int n,double *v,double tol,unsigned int *tp,Tbox *b);
390 
413 unsigned int OutOfBoxTopology(boolean *used,unsigned int n,double *v,
414  unsigned int *tp,signed int *s,Tbox *b);
415 
439 boolean PointInSubBox(boolean *used,Tvector *v,double tol,Tbox *b);
440 
463 double DistanceToSubBoxCenter(boolean *used,Tvector *v,Tbox *b);
464 
482 boolean IsPunctualBox(boolean *used,double epsilon,Tbox *b);
483 
499 boolean BoxInclusion(boolean *used,Tbox *b1,Tbox *b2);
500 
515 Tinterval *GetBoxInterval(unsigned int n,Tbox *b);
516 
532 
547 double GetBoxSize(boolean *used,Tbox *b);
548 
563 double GetBoxMaxSizeVarSet(Tvariable_set *vars,Tbox *b);
564 
579 double GetBoxMinSizeVarSet(Tvariable_set *vars,Tbox *b);
580 
594 double GetBoxDiagonal(boolean *used,Tbox *b);
595 
606 unsigned int GetBoxLevel(Tbox *b);
607 
620 void RandomPointInBox(boolean *used,double *c,Tbox *b);
621 
634 void GetBoxCenter(boolean *used,double *c,Tbox *b);
635 
650 double GetBoxCenterDistance(boolean *used,Tbox *b1,Tbox *b2);
651 
667 double SquaredDistancePointToBox(double t2,double *p,Tbox *b);
668 
681 double DistancePointToBox(double *p,Tbox *b);
682 
696 double SquaredDistanceToBoxDimensionTopology(unsigned int dim,double p,unsigned int *tp,Tbox *b);
697 
714 double SquaredDistancePointToBoxTopology(double t,double *p,unsigned int *tp,Tbox *b);
715 
731 double DistancePointToBoxTopology(double *p,unsigned int *tp,Tbox *b);
732 
747 double GetBoxVolume(boolean *used,Tbox *b);
748 
768 double GetBoxSumSide(boolean *used,Tbox *b);
769 
779 unsigned int GetBoxNIntervals(Tbox *b);
780 
794 unsigned int GetBoxMaxDim(boolean *used,Tbox *b);
795 
811 unsigned int GetBoxSplitDim(boolean *used,Tbox *b);
812 
835 void SplitBox(unsigned int n,double r,Tbox *b1,Tbox *b2,Tbox *b);
836 
846 void ScaleBox(double max_upper,Tbox *b);
847 
856 void AddMargin2Box(double m,Tbox *b);
857 
858 
877 boolean CmpBoxDepthFirst(void *b1,void *b2,void *userData);
878 
897 boolean CmpBoxBreadthFirst(void *b1,void *b2,void *userData);
898 
914 void PrintBox(FILE *f,Tbox *b);
915 
937 void PrintBoxSubset(FILE *f,boolean *used,char **varNames,Tbox *b);
938 
953 int ReadBox(FILE *f,Tbox *b);
954 
955 
965 void SaveBox(FILE *f,Tbox *b);
966 
977 void LoadBox(FILE *f,Tbox *b);
978 
987 void DeleteBox(void *b);
988 
989 #endif
Definition of the boolean type.
double GetBoxDiagonal(boolean *used, Tbox *b)
Computes the diagonal of a (sub-)box.
Definition: box.c:678
Definition of the Tvariable_set type and the associated functions.
unsigned int GetBoxBufferSize(Tbox *b)
Returns the size of a box when converted to an array of doubles.
Definition: box.c:76
boolean IsPunctualBox(boolean *used, double epsilon, Tbox *b)
Checks if a (sub-)box is (almost) punctual.
Definition: box.c:590
void CopyBox(void *b_out, void *b_in)
Box copy operator.
Definition: box.c:160
unsigned int GetBoxLevel(Tbox *b)
Returns the box level.
Definition: box.c:700
boolean BoxInclusion(boolean *used, Tbox *b1, Tbox *b2)
Checks if a (sub-)box is fully included in another box.
Definition: box.c:610
void MergeBoxes(Tbox *b1, Tbox *b2, Tbox *bout)
Concats two boxes.
Definition: box.c:171
boolean CmpBoxDepthFirst(void *b1, void *b2, void *userData)
Determines which box to explore first in depth first mode.
Definition: box.c:1129
void LoadBox(FILE *f, Tbox *b)
Reads a box in binary format.
Definition: box.c:1266
Tinterval * GetBoxInterval(unsigned int n, Tbox *b)
Returns a pointer to one of the intervals defining the box.
Definition: box.c:270
void SplitBox(unsigned int n, double r, Tbox *b1, Tbox *b2, Tbox *b)
Splits a box.
Definition: box.c:1064
unsigned int n
Definition: box.h:85
double SquaredDistancePointToBoxTopology(double t, double *p, unsigned int *tp, Tbox *b)
Squared distance from a point to a box.
Definition: box.c:857
double DistancePointToBox(double *p, Tbox *b)
Distance from a point to a box.
Definition: box.c:777
double GetBoxMaxSizeVarSet(Tvariable_set *vars, Tbox *b)
Computes the size of the box.
Definition: box.c:639
double SquaredDistanceToBoxDimensionTopology(unsigned int dim, double p, unsigned int *tp, Tbox *b)
Squared distance from a value to a given box dimension.
Definition: box.c:782
void BoxUnion(boolean *used, Tbox *b1, Tbox *b2, Tbox *b_out)
Computes the box union of two given boxes.
Definition: box.c:314
void DeleteBox(void *b)
Destructor.
Definition: box.c:1283
double GetBoxSize(boolean *used, Tbox *b)
Computes the size of the box.
Definition: box.c:631
Tinterval * GetBoxIntervals(Tbox *b)
Returns a pointer to the array of intervals defining the box.
Definition: box.c:284
void SetBoxIntervals(Tinterval *is, Tbox *b)
Replaces the box intervals with a new set.
Definition: box.c:253
boolean BoxesIntersection(boolean *used, Tbox *b1, Tbox *b2, Tbox *bout)
Computes the box intersection of two given boxes.
Definition: box.c:293
double GetBoxCenterDistance(boolean *used, Tbox *b1, Tbox *b2)
Computes distance between the center of two (sub-)boxes.
Definition: box.c:739
boolean PointInBoxTopology(boolean *used, boolean update, unsigned int n, double *v, double tol, unsigned int *tp, Tbox *b)
Checks if a point is included in a(sub-) box.
Definition: box.c:374
void GetBoxCenter(boolean *used, double *c, Tbox *b)
Returns the box center along the selected dimensions.
Definition: box.c:721
void SaveBox(FILE *f, Tbox *b)
Saves a box in binary format.
Definition: box.c:1258
void PrintBox(FILE *f, Tbox *b)
Prints a box.
Definition: box.c:1142
void InitBoxFromPoint(unsigned int dim, double *p, Tbox *b)
Initializes a box from a point.
Definition: box.c:43
boolean CmpBoxBreadthFirst(void *b1, void *b2, void *userData)
Determines which box to explore first in breadth first mode.
Definition: box.c:1134
Tinterval * is
Definition: box.h:86
A set of variable indexes with powers.
Definition: variable_set.h:139
double GetBoxMinSizeVarSet(Tvariable_set *vars, Tbox *b)
Computes the minimum size of the box.
Definition: box.c:657
void ExpandBox(double *p, Tbox *b)
Expands a box so that it includes a given point.
Definition: box.c:67
unsigned int GetBoxNIntervals(Tbox *b)
Box dimensionality.
Definition: box.c:1016
A generic vector.
Definition: vector.h:227
void Box2Buffer(unsigned int c, unsigned int n, double *buffer, Tbox *b)
Converts a box into an array of doubles.
Definition: box.c:81
A box.
Definition: box.h:83
unsigned int GetBoxSplitDim(boolean *used, Tbox *b)
Computes the box dimension for which it is better to split the box.
Definition: box.c:1054
double GetBoxVolume(boolean *used, Tbox *b)
Computes the volume of the box.
Definition: box.c:980
Definition of the Tvector type and the associated functions.
unsigned int OutOfBoxTopology(boolean *used, unsigned int n, double *v, unsigned int *tp, signed int *s, Tbox *b)
Determines the violated box limit.
Definition: box.c:445
void Crop2Box(boolean *used, unsigned int n, double *p, Tbox *b)
Forces a point to be inside a box.
Definition: box.c:328
void AddMargin2Box(double m, Tbox *b)
Adds a margin to all dimensions of a box.
Definition: box.c:1117
void SetBoxInterval(unsigned int n, Tinterval *is, Tbox *b)
Replaces a particular interval in a box.
Definition: box.c:259
void ScaleBox(double max_upper, Tbox *b)
Scales a box.
Definition: box.c:1109
void RandomPointInBox(boolean *used, double *c, Tbox *b)
Returns the a random point along the selected dimensions.
Definition: box.c:706
boolean PointInBox(boolean *used, unsigned int n, double *v, double tol, Tbox *b)
Checks if a point is included in a(sub-) box.
Definition: box.c:356
unsigned int GetBoxMaxDim(boolean *used, Tbox *b)
The dimension of the (sub-)box along which the box has maximum size.
Definition: box.c:1024
int ReadBox(FILE *f, Tbox *b)
Reads a box from a file.
Definition: box.c:1196
double DistanceToSubBoxCenter(boolean *used, Tvector *v, Tbox *b)
Computes the distance from a point to the center of a (sub-)box.
Definition: box.c:566
void EnlargeBox(double lo, double uo, Tbox *b)
Enlarges all the intervals of a box.
Definition: box.c:59
boolean PointInSubBox(boolean *used, Tvector *v, double tol, Tbox *b)
Checks if a point is included in a (sub-)box.
Definition: box.c:545
void InitBox(unsigned int dim, Tinterval *is, Tbox *b)
Initializes a box.
Definition: box.c:23
void SetBoxSubset(boolean *used, Tbox *bset, Tbox *b)
Changes a sub-set of ranges in a given box.
Definition: box.c:238
Defines a interval.
Definition: interval.h:33
unsigned int level
Definition: box.h:84
void CopyBoxSubset(boolean *used, void *b_out, void *b_in)
Creates a box from a sub-set of a given box.
Definition: box.c:210
void PrintBoxSubset(FILE *f, boolean *used, char **varNames, Tbox *b)
Prints a (sub-)box.
Definition: box.c:1162
double GetBoxSumSide(boolean *used, Tbox *b)
Computes the sum of the sides of the box.
Definition: box.c:998
void Buffer2Box(unsigned int *c, unsigned int *n, double *buffer, Tbox *b)
Converts a buffer of doubles into a box.
Definition: box.c:122
double DistancePointToBoxTopology(double *p, unsigned int *tp, Tbox *b)
Distance from a point to a box.
Definition: box.c:971
double SquaredDistancePointToBox(double t2, double *p, Tbox *b)
Distance from a point to a box.
Definition: box.c:762
Definition of the Tinterval type and the associated functions.