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 
347 boolean PointInBox(boolean *used,unsigned int n,double *v,double tol,Tbox *b);
348 
373 boolean PointInBoxTopology(boolean *used,boolean update,
374  unsigned int n,double *v,double tol,unsigned int *tp,Tbox *b);
375 
398 unsigned int OutOfBoxTopology(boolean *used,unsigned int n,double *v,
399  unsigned int *tp,signed int *s,Tbox *b);
400 
424 boolean PointInSubBox(boolean *used,Tvector *v,double tol,Tbox *b);
425 
448 double DistanceToSubBoxCenter(boolean *used,Tvector *v,Tbox *b);
449 
467 boolean IsPunctualBox(boolean *used,double epsilon,Tbox *b);
468 
484 boolean BoxInclusion(boolean *used,Tbox *b1,Tbox *b2);
485 
500 Tinterval *GetBoxInterval(unsigned int n,Tbox *b);
501 
517 
532 double GetBoxSize(boolean *used,Tbox *b);
533 
548 double GetBoxMaxSizeVarSet(Tvariable_set *vars,Tbox *b);
549 
564 double GetBoxMinSizeVarSet(Tvariable_set *vars,Tbox *b);
565 
579 double GetBoxDiagonal(boolean *used,Tbox *b);
580 
591 unsigned int GetBoxLevel(Tbox *b);
592 
605 void RandomPointInBox(boolean *used,double *c,Tbox *b);
606 
619 void GetBoxCenter(boolean *used,double *c,Tbox *b);
620 
635 double GetBoxCenterDistance(boolean *used,Tbox *b1,Tbox *b2);
636 
652 double SquaredDistancePointToBox(double t2,double *p,Tbox *b);
653 
666 double DistancePointToBox(double *p,Tbox *b);
667 
681 double SquaredDistanceToBoxDimensionTopology(unsigned int dim,double p,unsigned int *tp,Tbox *b);
682 
699 double SquaredDistancePointToBoxTopology(double t,double *p,unsigned int *tp,Tbox *b);
700 
716 double DistancePointToBoxTopology(double *p,unsigned int *tp,Tbox *b);
717 
732 double GetBoxVolume(boolean *used,Tbox *b);
733 
753 double GetBoxSumSide(boolean *used,Tbox *b);
754 
764 unsigned int GetBoxNIntervals(Tbox *b);
765 
779 unsigned int GetBoxMaxDim(boolean *used,Tbox *b);
780 
796 unsigned int GetBoxSplitDim(boolean *used,Tbox *b);
797 
820 void SplitBox(unsigned int n,double r,Tbox *b1,Tbox *b2,Tbox *b);
821 
831 void ScaleBox(double max_upper,Tbox *b);
832 
841 void AddMargin2Box(double m,Tbox *b);
842 
843 
862 boolean CmpBoxDepthFirst(void *b1,void *b2,void *userData);
863 
882 boolean CmpBoxBreadthFirst(void *b1,void *b2,void *userData);
883 
899 void PrintBox(FILE *f,Tbox *b);
900 
922 void PrintBoxSubset(FILE *f,boolean *used,char **varNames,Tbox *b);
923 
938 int ReadBox(FILE *f,Tbox *b);
939 
940 
950 void SaveBox(FILE *f,Tbox *b);
951 
962 void LoadBox(FILE *f,Tbox *b);
963 
972 void DeleteBox(void *b);
973 
974 #endif
Definition of the boolean type.
double GetBoxDiagonal(boolean *used, Tbox *b)
Computes the diagonal of a (sub-)box.
Definition: box.c:654
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:566
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:676
boolean BoxInclusion(boolean *used, Tbox *b1, Tbox *b2)
Checks if a (sub-)box is fully included in another box.
Definition: box.c:586
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:1105
void LoadBox(FILE *f, Tbox *b)
Reads a box in binary format.
Definition: box.c:1242
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:1040
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:833
double DistancePointToBox(double *p, Tbox *b)
Distance from a point to a box.
Definition: box.c:753
double GetBoxMaxSizeVarSet(Tvariable_set *vars, Tbox *b)
Computes the size of the box.
Definition: box.c:615
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:758
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:1259
double GetBoxSize(boolean *used, Tbox *b)
Computes the size of the box.
Definition: box.c:607
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:715
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:350
void GetBoxCenter(boolean *used, double *c, Tbox *b)
Returns the box center along the selected dimensions.
Definition: box.c:697
void SaveBox(FILE *f, Tbox *b)
Saves a box in binary format.
Definition: box.c:1234
void PrintBox(FILE *f, Tbox *b)
Prints a box.
Definition: box.c:1118
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:1110
Tinterval * is
Definition: box.h:86
A set of variable indexes with powers.
Definition: variable_set.h:131
double GetBoxMinSizeVarSet(Tvariable_set *vars, Tbox *b)
Computes the minimum size of the box.
Definition: box.c:633
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:992
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:1030
double GetBoxVolume(boolean *used, Tbox *b)
Computes the volume of the box.
Definition: box.c:956
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:421
void AddMargin2Box(double m, Tbox *b)
Adds a margin to all dimensions of a box.
Definition: box.c:1093
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:1085
void RandomPointInBox(boolean *used, double *c, Tbox *b)
Returns the a random point along the selected dimensions.
Definition: box.c:682
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:332
unsigned int GetBoxMaxDim(boolean *used, Tbox *b)
The dimension of the (sub-)box along which the box has maximum size.
Definition: box.c:1000
int ReadBox(FILE *f, Tbox *b)
Reads a box from a file.
Definition: box.c:1172
double DistanceToSubBoxCenter(boolean *used, Tvector *v, Tbox *b)
Computes the distance from a point to the center of a (sub-)box.
Definition: box.c:542
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:521
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:1138
double GetBoxSumSide(boolean *used, Tbox *b)
Computes the sum of the sides of the box.
Definition: box.c:974
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:947
double SquaredDistancePointToBox(double t2, double *p, Tbox *b)
Distance from a point to a box.
Definition: box.c:738
Definition of the Tinterval type and the associated functions.