box.c File Reference

Detailed Description

Implementation of the functions operating on Tbox.

See Also
box.h, Tbox.

Definition in file box.c.

Functions

void InitBox (unsigned int dim, Tinterval *is, Tbox *b)
 Initializes a box. More...
 
void InitBoxFromPoint (unsigned int dim, double *p, Tbox *b)
 Initializes a box from a point. More...
 
void EnlargeBox (double lo, double uo, Tbox *b)
 Enlarges all the intervals of a box. More...
 
void ExpandBox (double *p, Tbox *b)
 Expands a box so that it includes a given point. More...
 
unsigned int GetBoxBufferSize (Tbox *b)
 Returns the size of a box when converted to an array of doubles. More...
 
void Box2Buffer (unsigned int c, unsigned int n, double *buffer, Tbox *b)
 Converts a box into an array of doubles. More...
 
void Buffer2Box (unsigned int *c, unsigned int *n, double *buffer, Tbox *b)
 Converts a buffer of doubles into a box. More...
 
void CopyBox (void *b_out, void *b_in)
 Box copy operator. More...
 
void MergeBoxes (Tbox *b1, Tbox *b2, Tbox *bout)
 Concats two boxes. More...
 
void CopyBoxSubset (boolean *used, void *b_out, void *b_in)
 Creates a box from a sub-set of a given box. More...
 
void SetBoxSubset (boolean *used, Tbox *bset, Tbox *b)
 Changes a sub-set of ranges in a given box. More...
 
void SetBoxIntervals (Tinterval *is, Tbox *b)
 Replaces the box intervals with a new set. More...
 
void SetBoxInterval (unsigned int n, Tinterval *is, Tbox *b)
 Replaces a particular interval in a box. More...
 
TintervalGetBoxInterval (unsigned int n, Tbox *b)
 Returns a pointer to one of the intervals defining the box. More...
 
TintervalGetBoxIntervals (Tbox *b)
 Returns a pointer to the array of intervals defining the box. More...
 
boolean BoxesIntersection (boolean *used, Tbox *b1, Tbox *b2, Tbox *bout)
 Computes the box intersection of two given boxes. More...
 
void BoxUnion (boolean *used, Tbox *b1, Tbox *b2, Tbox *b_out)
 Computes the box union of two given boxes. More...
 
boolean PointInBox (boolean *used, unsigned int n, double *v, double tol, Tbox *b)
 Checks if a point is included in a(sub-) box. More...
 
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. More...
 
unsigned int OutOfBoxTopology (boolean *used, unsigned int n, double *v, unsigned int *tp, signed int *s, Tbox *b)
 Determines the violated box limit. More...
 
boolean PointInSubBox (boolean *used, Tvector *v, double tol, Tbox *b)
 Checks if a point is included in a (sub-)box. More...
 
double DistanceToSubBoxCenter (boolean *used, Tvector *v, Tbox *b)
 Computes the distance from a point to the center of a (sub-)box. More...
 
boolean IsPunctualBox (boolean *used, double epsilon, Tbox *b)
 Checks if a (sub-)box is (almost) punctual. More...
 
boolean BoxInclusion (boolean *used, Tbox *b1, Tbox *b2)
 Checks if a (sub-)box is fully included in another box. More...
 
double GetBoxSize (boolean *used, Tbox *b)
 Computes the size of the box. More...
 
double GetBoxMaxSizeVarSet (Tvariable_set *vars, Tbox *b)
 Computes the size of the box. More...
 
double GetBoxMinSizeVarSet (Tvariable_set *vars, Tbox *b)
 Computes the minimum size of the box. More...
 
double GetBoxDiagonal (boolean *used, Tbox *b)
 Computes the diagonal of a (sub-)box. More...
 
unsigned int GetBoxLevel (Tbox *b)
 Returns the box level. More...
 
void RandomPointInBox (boolean *used, double *c, Tbox *b)
 Returns the a random point along the selected dimensions. More...
 
void GetBoxCenter (boolean *used, double *c, Tbox *b)
 Returns the box center along the selected dimensions. More...
 
double GetBoxCenterDistance (boolean *used, Tbox *b1, Tbox *b2)
 Computes distance between the center of two (sub-)boxes. More...
 
double SquaredDistancePointToBox (double t, double *p, Tbox *b)
 Distance from a point to a box. More...
 
double DistancePointToBox (double *p, Tbox *b)
 Distance from a point to a box. More...
 
double SquaredDistanceToBoxDimensionTopology (unsigned int dim, double p, unsigned int *tp, Tbox *b)
 Squared distance from a value to a given box dimension. More...
 
double SquaredDistancePointToBoxTopology (double t2, double *p, unsigned int *tp, Tbox *b)
 Squared distance from a point to a box. More...
 
double DistancePointToBoxTopology (double *p, unsigned int *tp, Tbox *b)
 Distance from a point to a box. More...
 
double GetBoxVolume (boolean *used, Tbox *b)
 Computes the volume of the box. More...
 
double GetBoxSumSide (boolean *used, Tbox *b)
 Computes the sum of the sides of the box. More...
 
unsigned int GetBoxNIntervals (Tbox *b)
 Box dimensionality. More...
 
unsigned int GetBoxMaxDim (boolean *used, Tbox *b)
 The dimension of the (sub-)box along which the box has maximum size. More...
 
unsigned int GetBoxSplitDim (boolean *used, Tbox *b)
 Computes the box dimension for which it is better to split the box. More...
 
void SplitBox (unsigned int n, double r, Tbox *b1, Tbox *b2, Tbox *b)
 Splits a box. More...
 
void ScaleBox (double max_upper, Tbox *b)
 Scales a box. More...
 
void AddMargin2Box (double m, Tbox *b)
 Adds a margin to all dimensions of a box. More...
 
boolean CmpBoxDepthFirst (void *b1, void *b2, void *userData)
 Determines which box to explore first in depth first mode. More...
 
boolean CmpBoxBreadthFirst (void *b1, void *b2, void *userData)
 Determines which box to explore first in breadth first mode. More...
 
void PrintBox (FILE *f, Tbox *b)
 Prints a box. More...
 
void PrintBoxSubset (FILE *f, boolean *used, char **varNames, Tbox *b)
 Prints a (sub-)box. More...
 
int ReadBox (FILE *f, Tbox *b)
 Reads a box from a file. More...
 
void SaveBox (FILE *f, Tbox *b)
 Saves a box in binary format. More...
 
void LoadBox (FILE *f, Tbox *b)
 Reads a box in binary format. More...
 
void DeleteBox (void *b)
 Destructor. More...
 

Function Documentation

void InitBox ( unsigned int  dim,
Tinterval is,
Tbox b 
)

Creates a new box with the given parameters.

Parameters
dimDimension of the new box (i.e., number of intervals).
isVector of intervals used to initilize the new box. If the pointer is NULL the box intervals are set to [0,0].
bThe box to initialize.

Definition at line 23 of file box.c.

References Tbox::is, Tbox::level, Tbox::n, NEW, and NewInterval().

Referenced by BoxFromVariables(), CSRemoveLCVars(), DefinePolytope(), ListOfBoxesBB(), main(), MPI_SolveCuikSystem(), MPI_TreatBox(), NewtonInWorld(), ReadBox(), RegenerateSolution(), and SolveCuikSystem().

void InitBoxFromPoint ( unsigned int  dim,
double *  p,
Tbox b 
)

Creates a new box with punctual intervals from a given vector.

Parameters
dimDimension of the new box (i.e., number of intervals).
pThe point to use to initialize the box.
bThe box to initialize.

Definition at line 43 of file box.c.

References Tbox::is, Tbox::level, Tbox::n, NEW, and NewInterval().

Referenced by AdjustBioWorldGeometry(), CuikNewtonInBox(), CutPolytopeWithFace(), DetectLinksAndJointsFromResidues(), RegenerateSolutionPoint(), SaveSamplesInt(), and WorldDOF2Sol().

void EnlargeBox ( double  lo,
double  uo,
Tbox b 
)

Enlarges all the intervals of the box by substracting/adding a given value to their lower/upper limits.

Parameters
loThe offset to add to all interval lower limits.
uoThe offset to add to all interval upper limits.
bThe box to modify.
See Also
EnlargeInterval.

Definition at line 59 of file box.c.

References EnlargeInterval(), Tbox::is, and Tbox::n.

void ExpandBox ( double *  p,
Tbox b 
)

Expands a box so that it includes a given point.

Parameters
pThe point.
bThe box to modify.
See Also
ExpandInterval.

Definition at line 67 of file box.c.

References ExpandInterval(), Tbox::is, and Tbox::n.

Referenced by CutPolytopeWithFace(), and DetectLinksAndJointsFromResidues().

unsigned int GetBoxBufferSize ( Tbox b)

In a multiprocessors system, the master and the slave processors exchange boxes and they do so by converting boxes into arrays of doubles. This function returns the number of doubles that takes a box when converted to into doubles. Typically, in the array of doubles we store some heading information plus the lower and upper limits for each one of the intervals in the box.

Parameters
bThe box to convert to an array of doubles.
Returns
The number of doubles that the box conversion will use.
See Also
Box2Buffer, Buffer2Box

Definition at line 76 of file box.c.

References Tbox::n.

Referenced by MPI_SolveCuikSystem(), and MPI_TreatBox().

void Box2Buffer ( unsigned int  c,
unsigned int  n,
double *  buffer,
Tbox b 
)

Packs a box into an array of doubles and adds some heading information to the array.

Parameters
cStatus information related to the box (EMPTY_BOX, REDUCED_BOX, etc.).
nProcess information related to the box. Right now this is used to store the number of time a box is reduced in a slave processors before it is returned to the master processors. The master collects this informations into a global statistics.
bufferThe buffer of doubles where the box is to be stored. The size of this buffer should be, at least, the number returned by GetBoxBufferSize.
bThe box to convert to an array of doubles.
See Also
GetBoxBufferSize

Definition at line 81 of file box.c.

References EMPTY_BOX, Error(), ERROR_IN_PROCESS, Tbox::is, Tbox::level, LowerLimit(), Tbox::n, REDUCED_BOX, REDUCED_BOX_WITH_SOLUTION, and UpperLimit().

Referenced by MPI_SolveCuikSystem(), and MPI_TreatBox().

void Buffer2Box ( unsigned int *  c,
unsigned int *  n,
double *  buffer,
Tbox b 
)

Converts an array of doubles into a box.

This is not a box constructor. The box is to be initialized before calling this function and if the box size and the buffer size do not match this function will trigger an error. The idea is to convert a box into a buffer, send it to slave processor, and then update the box with the information sent by the slave.

Parameters
cRecovers the box status (EMPTY_BOX, REDUCED_BOX, etc.) from the buffer.
nRecovers process information related to the box. Right now it returns the number box reductions applied in the slave processors in order to crop the box.
bufferThe buffer from which the box is to be defined.
bThe output box.
See Also
GetBoxBufferSize

Definition at line 122 of file box.c.

References EMPTY_BOX, Error(), ERROR_IN_PROCESS, Tbox::is, Tbox::level, Tbox::n, NewInterval(), REDUCED_BOX, and REDUCED_BOX_WITH_SOLUTION.

Referenced by MPI_SolveCuikSystem(), and MPI_TreatBox().

void CopyBox ( void *  b_out,
void *  b_in 
)

Copies one box into another. This is a copy constructor and, therefore, the output box is initialized inside the CopyBox (i.e., there is no need to init the box beforehand).
The parameters are given as a void pointers to define a generic copy function that is used in box list or box vectors.

Parameters
b_outOutput box. Box constructed by the copy.
b_inInput box. Box used to create b_out.

Definition at line 160 of file box.c.

References NEW.

Referenced by ConcatListOfBoxes(), CopyListOfBoxes(), CopyPolytope(), CropEquation(), CuikNewtonInBox(), Heap2List(), IncrementalSampleCuikSystemInBox(), InitHeapOfBoxes(), ListOfBoxesBB(), ListOfBoxesCluster(), main(), MergeBoxes(), NewCP(), PostProcessBox(), ReduceBox(), ReduceBoxEquationWise(), ReverseListOfBoxes(), SampleCuikSystemInBox(), and SetPolytopeBB().

void MergeBoxes ( Tbox b1,
Tbox b2,
Tbox bout 
)

Defines a box as a concatenation of two boxes.

Parameters
b1The first box to concat.
b2The second box to concat.
boutThe box to be created.

Definition at line 171 of file box.c.

References CopyBox(), DeleteBox(), Tbox::is, Tbox::level, MEM_EXPAND, Tbox::n, and NEW.

Referenced by main().

void CopyBoxSubset ( boolean used,
void *  b_out,
void *  b_in 
)

This is a constructor that builds a box form a subset of intervals of a given box.
The parameters are given as a void pointers to define a generic copy function that is used in box list or box vectors.

Parameters
usedArray of booleans, one for each interval of the input box (b_in). If the boolean is TRUE, the corresponding interval is used in the selective copy. If the given pointer is NULL, all intervals are used (i.e., in this case CopyBoxSubset is the same as CopyBox).
b_outOutput box. Box constructed by the copy.
b_inInput box. Box used to create b_out.

Definition at line 210 of file box.c.

References CopyInterval(), and NEW.

void SetBoxSubset ( boolean used,
Tbox bset,
Tbox b 
)

Replaces the ranges selected by the flags used of box by the ranges in box bset. Box bset only need to have as many ranges as flags to TRUE in used but the array of flags need as many entries as elements in b.

Parameters
usedArray of booleans, one for each interval of the input box (b_in). If the boolean is TRUE, the corresponding interval is used in the selective copy. If the given pointer is NULL, all intervals are used (i.e., in this case CopyBoxSubset is the same as CopyBox).
bsetThe box with the new sub-set of ranges.
bThe box to modify.

Definition at line 238 of file box.c.

References CopyInterval(), Tbox::is, and Tbox::n.

Referenced by CuikNewtonInBox().

void SetBoxIntervals ( Tinterval is,
Tbox b 
)

Replaces the box intervals with a new set of intervals.

Parameters
isArray with the new set of intervals. The array must have as many elements as those in the box, otherwise the effect of SetBoxIntervals is undefined.
bThe box to be modified.

Definition at line 253 of file box.c.

References Tbox::is, and Tbox::n.

void SetBoxInterval ( unsigned int  n,
Tinterval is,
Tbox b 
)

Replaces a particular interval in a box by the given one.

Parameters
nThe index of the interval to replace.
isThe new interval.
bThe box to be modified.

Definition at line 259 of file box.c.

References CopyInterval(), Error(), and Tbox::is.

Referenced by BoxFromVariables(), CSRemoveLCVars(), CuikNewtonInBox(), DefinePolytope(), IncrementalSampleCuikSystemInBox(), main(), NewtonInWorld(), RegenerateJointBox(), RegenerateLinkBoxLinks(), RegenerateLinkBoxQLinks(), RegenerateSolution(), and UpdateOriginalFromSimple().

Tinterval* GetBoxInterval ( unsigned int  n,
Tbox b 
)

Returns a pointer to the n interval of the box.

Parameters
nThe interval to retrive.
bThe box.
Returns
A pointer to the required interval or NULL if n is larger than the box dimensionality.
Note that we give access directly to the box internal structures. This allow to directly modify the interval. If you free the pointer, the behavior will be undefined.

Definition at line 270 of file box.c.

References Error(), and Tbox::is.

Referenced by CSRemoveVarsWithCtRange(), CuikNewtonInBox(), ErrorInInequalities(), ErrorInSolution(), EvaluateEqMin(), GetSCpSystem(), IncrementalSampleCuikSystemInBox(), InitBTree(), InitRRT(), InitSampleFromBox(), IsSimplificable(), LoadRRT(), main(), MoveWorld(), NewCP(), NewtonInWorld(), PointInSystemBox(), PrintWorldAxes(), ReduceBox(), ReduceBoxEquationWise(), ReduceRange(), RegenerateJointBox(), RegenerateLinkBoxQLinks(), RegenerateSolutionPoint(), SampleCuikSystemInBox(), SimpleFromOriginal(), SimplexGetOptimalValue(), SimplifyCuikSystem(), UpdateOriginalFromSimple(), and VariablesFromBox().

Tinterval* GetBoxIntervals ( Tbox b)

Returns a pointer to the intervals defining the box. This allows fast access to the whole set of intervals of the box, i.e., we do not have to access them one at a time.

Parameters
bThe box.
Returns
A pointer to the array of intervals.
Note that we give access directly to the box internal structures. This allow to directly modify the interval. If you free the pointer, the behavior will be undefined.

Definition at line 284 of file box.c.

References Tbox::is.

Referenced by AddEquation2Simplex(), ComputeSplitDimInt(), CropEquation(), CropLinearConstraint(), EvaluateEqMin(), GetFirstOrderApproximationToEquation(), LinearizeBilinealMonomialEquation(), LinearizeCircleEquation(), LinearizeGeneralEquation(), LinearizeGeneralEquationInt(), LinearizeParabolaEquation(), LinearizeSaddleEquation(), LinearizeSphereEquation(), RegenerateLinkBoxLinks(), SetSimplexBounds(), UpdateOriginalFromSimple(), and UpdateSplitWeight().

boolean BoxesIntersection ( boolean used,
Tbox b1,
Tbox b2,
Tbox bout 
)

The intersection of two boxes is a box (possibly empty). This function computes the intersection of two given boxes, along a sub-set of its intervals.
The two input boxes must have the same dimensionality.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the intersection. The non-used intervals are undefined in the output. If the given pointer is NULL, all intervals are used.
b1The first box to be intersected.
b2The second box to be intersected.
boutThe box resulting from the intersection.
Returns
Returns TRUE if the boxes actually intersect (i.e., if the output box is not empty).
See Also
Intersection

Definition at line 293 of file box.c.

References Error(), Intersection(), Tbox::is, Tbox::n, and TRUE.

Referenced by ListOfBoxesCluster().

void BoxUnion ( boolean used,
Tbox b1,
Tbox b2,
Tbox b_out 
)

The union of two boxes is a box. This function computes the union of two given boxes, along a sub-set of its intervals.
The two input boxes must have the same dimensionality.
Note that the union of two boxes is never empty (if the input boxes are not empty).

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the intersection. The non-used intervals are undefined in the output. If the given pointer is NULL, all intervals are used.
b1The first box to be intersected.
b2The second box to be intersected.
b_outThe box resulting from the intersection.
See Also
Union

Definition at line 314 of file box.c.

References Error(), Tbox::is, Tbox::n, and Union().

Referenced by ListOfBoxesBB(), and ListOfBoxesCluster().

boolean PointInBox ( boolean used,
unsigned int  n,
double *  v,
double  tol,
Tbox b 
)

Checks if a point (defined by an array of n doubles) is included in a box.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the check. If the given pointer is NULL, all intervals are used.
nLength of the array of doubles. It must be the same as the box dimensionality.
vThe array of doubles defining the point.
tolTolerance in the comparison.
bThe box.
Returns
TRUE if the point is inside the(sub-)box.

Definition at line 332 of file box.c.

References Error(), Tbox::is, IsInside(), Tbox::n, and TRUE.

Referenced by CuikNewtonInBox(), and InitWorldFromMolecule().

boolean PointInBoxTopology ( boolean used,
boolean  update,
unsigned int  n,
double *  v,
double  tol,
unsigned int *  tp,
Tbox b 
)

Checks if a point (defined by an array of n doubles) is included in a box taking into accont the topology of each variable.

If the point can be made to enter the box by adjusting the angular variables (adding/substracting 2*pi), the given point (v) is modified and at the end of the function it contains the values tha make the point to be inside the box.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the check. If the given pointer is NULL, all intervals are used.
updateTRUE if the input point has to be updated using the topology.
nLength of the array of doubles. It must be the same as the box dimensionality.
vThe array of doubles defining the point.
tolTolerance in the comparison.
tpThe topology for each variable.
bThe box.
Returns
TRUE if the point is inside the (sub-)box.

Definition at line 350 of file box.c.

References ANGLE_ACCURACY, Error(), FALSE, Tbox::is, IsInside(), LowerLimit(), M_2PI, M_PI, Tbox::n, NEW, PI2PI, TOPOLOGY_R, TRUE, and UpperLimit().

Referenced by AddBranchToRRT(), AtlasRRT(), AtlasRRTstar(), AtlasTRRT(), cBiRRT(), ccRRT(), ccTRRT(), ConnectSamples(), ConnectSamplesChart(), ExtendAtlasFromPoint(), GradientSmooth(), InitChartInt(), InitRRT(), main(), NewChartFromPoint(), NewTemptativeSample(), and RRTstar().

unsigned int OutOfBoxTopology ( boolean used,
unsigned int  n,
double *  v,
unsigned int *  tp,
signed int *  s,
Tbox b 
)

For a point aut of the box, we determine the dimension for which the point is out of the box.

We assume that the point is out of the box only in one of the dimensions. This is typically the case when tracing rays from inside the box to out of the box, where the point out of the box is acurately located via dichotomics search.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the check. If the given pointer is NULL, all intervals are used.
nLength of the array of doubles. It must be the same as the box dimensionality.
vThe array of doubles defining the point.
tpThe topology for each variable.
s[Output] -1 if the lower limit of the interval is violated and +1 if the upper limit is violated.
bThe box.
Returns
The dimension along which the point is out of the box.

Definition at line 421 of file box.c.

References ANGLE_ACCURACY, Tbox::is, LowerLimit(), M_2PI, M_PI, NO_UINT, PI2PI, TOPOLOGY_R, and UpperLimit().

boolean PointInSubBox ( boolean used,
Tvector v,
double  tol,
Tbox b 
)

Checks if a point (defined by an array of doubles) is included in a (sub-)box. The (sub-)box is selected using an array of flags.
The difference with PointInBox is that v only need to include as many elements as TRUE elements in the used array. Moreover, here the point is defined as a Tvector and not as an array of doubles. The Tvector is used to facilitate the queries from the sample structures that store the configurations in the form of vectors.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the check. If the given pointer is NULL, all intervals are used.
vThe vector defining the point.
tolTolerance in the comparisons.
bThe box.
Returns
TRUE if the point is inside the (sub-)box.
See Also
PointInBox, Tvector, Tsample

Definition at line 521 of file box.c.

References GetVectorElement(), Tbox::is, IsInside(), and TRUE.

double DistanceToSubBoxCenter ( boolean used,
Tvector v,
Tbox b 
)

Computes the distance from a point to the center of a (sub-)box. The (sub-)box is selected using an array of flags.
The point is described using an vector of doubles with one entry for each one of the dimensions to be checked. The Tvector is used to facilitate the queries from the sample structures that store the configurations in the form of vectors.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the check. If the given pointer is NULL, all intervals are used.
vThe vector defining the point.
bThe box.
Returns
The distance of the point to the center of the (sub-)box.
See Also
Tvector

Definition at line 542 of file box.c.

References GetVectorElement(), IntervalCenter(), Tbox::is, and Tbox::n.

boolean IsPunctualBox ( boolean used,
double  epsilon,
Tbox b 
)

Returns TRUE if the input box is (amost) punctual along the selected dimensions. A punctual interval is an interval whose size is below epsilon.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the check. If the given pointer is NULL, all intervals are used.
epsilonThe threshold to decide when an interval is punctual.
bThe box.
Returns
TRUE if the all selected ranges in the (sub-)box have size below epsilon.

Definition at line 566 of file box.c.

References IntervalSize(), Tbox::is, and TRUE.

boolean BoxInclusion ( boolean used,
Tbox b1,
Tbox b2 
)

Returns TRUE if the the first box is fully included in the second box.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the check. If the given pointer is NULL, all intervals are used.
b1The small box, the one to be fully sourrounded by b2.
b2The box that is to include b1.
Returns
TRUE b1 is fully included in b2.

Definition at line 586 of file box.c.

References IntervalInclusion(), Tbox::is, and Tbox::n.

Referenced by ReduceBox().

double GetBoxSize ( boolean used,
Tbox b 
)

Determines the largest box side, among the sub-set of intervals selected via the array of booleans used.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
bThe box.
Returns
The box size.

Definition at line 607 of file box.c.

References GetBoxMaxDim(), IntervalSize(), Tbox::is, and Tbox::n.

Referenced by HeapOfBoxesMaxSize(), ListOfBoxesMaxSize(), MaxReduction(), MaxWorldReduction(), MPI_SolveCuikSystem(), PostProcessBox(), ReduceBox(), ReduceBoxEquationWise(), and SolveCuikSystem().

double GetBoxMaxSizeVarSet ( Tvariable_set vars,
Tbox b 
)

Determines the largest box side, among the sub-set of variables included in the variable set vars.

Parameters
varsSet of variables (i.e., box dimensions) to be taken into account in the computation.
bThe box.
Returns
The box size.
See Also
Tvariable_set

Definition at line 615 of file box.c.

References GetVariableN(), IntervalSize(), Tbox::is, and VariableSetSize().

Referenced by GetFirstOrderApproximationToEquation(), and LinearizeGeneralEquationInt().

double GetBoxMinSizeVarSet ( Tvariable_set vars,
Tbox b 
)

Determines the smallest box side, among the sub-set of variables included in the variable set vars.

Parameters
varsSet of variables (i.e., box dimensions) to be taken into account in the computation.
bThe box.
Returns
The box size.
See Also
Tvariable_set

Definition at line 633 of file box.c.

References GetVariableN(), IntervalSize(), Tbox::is, and VariableSetSize().

Referenced by AddEquation2Simplex().

double GetBoxDiagonal ( boolean used,
Tbox b 
)

Determines the diagonal of a sub-box of b determined using the array used.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
bThe box.
Returns
The (sub-)box diagonal.

Definition at line 654 of file box.c.

References IntervalSize(), Tbox::is, and Tbox::n.

Referenced by HeapOfBoxesMaxDiagonal(), InitWorldFromMolecule(), ListOfBoxesMaxDiagonal(), and PostProcessBox().

unsigned int GetBoxLevel ( Tbox b)

Returns the box level, i.e., the number of bisections form the first box used to cretate this box.

Parameters
bThe box.
Returns
The box level.

Definition at line 676 of file box.c.

References Tbox::level.

Referenced by MaxWorldReduction(), MPI_SolveCuikSystem(), PostProcessBox(), and SolveCuikSystem().

void RandomPointInBox ( boolean used,
double *  c,
Tbox b 
)

Computes a random point along the selected dimensions.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
cSpace where to store the random point (should be allocated by the caller with, at least, space for the point along the selected dimensions).
bThe box.

Definition at line 682 of file box.c.

References Tbox::is, Tbox::n, and randomInInterval().

Referenced by RandomPointInPolytope(), and RRTSample().

void GetBoxCenter ( boolean used,
double *  c,
Tbox b 
)

Computes the box center along the selected dimensions.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
cSpace where to store the center (should be allocated by the caller with, at least, space for the center along the selected dimensions).
bThe box.

Definition at line 697 of file box.c.

References IntervalCenter(), Tbox::is, and Tbox::n.

Referenced by LoadSamples(), main(), and MoveWorld().

double GetBoxCenterDistance ( boolean used,
Tbox b1,
Tbox b2 
)

Determines the distance between the cener of two (sub-)boxes determined using the array used.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
b1One of the boxes.
b2The other box.
Returns
The (sub-)box center distance.

Definition at line 715 of file box.c.

References Error(), IntervalCenter(), Tbox::is, and Tbox::n.

double SquaredDistancePointToBox ( double  t2,
double *  p,
Tbox b 
)

Computes the square of the minimum distance from a point to a box.

Parameters
t2Threshold. Only poits closer than 't' to the box are relevant. Use INF if all points must be considered. Using a threshold accelerates the computation. This value is a squared distance!.
pThe point.
bThe box.
Returns
The minimum distance between the input parameters.
See Also
DistancePointToBox

Definition at line 738 of file box.c.

References DistanceToInterval(), Tbox::is, and Tbox::n.

Referenced by DistancePointToBox().

double DistancePointToBox ( double *  p,
Tbox b 
)

Computes the minimum distance from a point to a box.

Parameters
pThe point.
bThe box.
Returns
The minimum distance between the input parameters.
See Also
SquqredDistancePointToBox, DistanceToInterval

Definition at line 753 of file box.c.

References INF, and SquaredDistancePointToBox().

double SquaredDistanceToBoxDimensionTopology ( unsigned int  dim,
double  p,
unsigned int *  tp,
Tbox b 
)

Squared distance of a value to the interval defining a box along a given dimension.

Parameters
dimThe dimension.
pThe point.
tpThe topology of the space where the box and the point are defined.
bThe box.
Returns
The squared distance from the value to the interval.

Definition at line 758 of file box.c.

References ANGLE_ACCURACY, Tbox::is, LowerLimit(), M_2PI, M_PI, PI2PI, TOPOLOGY_R, and UpperLimit().

double SquaredDistancePointToBoxTopology ( double  t,
double *  p,
unsigned int *  tp,
Tbox b 
)

Computes the minimum squared distance from a point to a box but considering a possible special topology for the input box and the input point.

Parameters
tThreshold. Only poits closer than 't' to the box are relevant. Use INF if all points must be considered. Using a threshold accelerates the computation.
pThe point.
tpThe topology of the space where the box and the point are defined.
bThe box.
Returns
The minimum distance between the input parameters.

Definition at line 833 of file box.c.

References ANGLE_ACCURACY, Tbox::is, LowerLimit(), M_2PI, M_PI, Tbox::n, PI2PI, TOPOLOGY_R, and UpperLimit().

Referenced by DistancePointToBoxTopology().

double DistancePointToBoxTopology ( double *  p,
unsigned int *  tp,
Tbox b 
)

Computes the minimum distance from a point to a box but considering a possible special topology for the input box and the input point.

Parameters
pThe point.
tpThe topology of the space where the box and the point are defined.
bThe box.
Returns
The minimum distance between the input parameters.
See Also
SquaredDistancePointToBoxTopology

Definition at line 947 of file box.c.

References INF, and SquaredDistancePointToBoxTopology().

Referenced by CutPolytopeWithFace().

double GetBoxVolume ( boolean used,
Tbox b 
)

Determines the volume of a box (i.e., the product of the box sides), for a sub-set of intervals selected via the array of booleans used.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
bThe box.
Returns
The box volume.

Definition at line 956 of file box.c.

References IntervalSize(), Tbox::is, and Tbox::n.

Referenced by HeapOfBoxesVolume(), ListOfBoxesVolume(), MPI_SolveCuikSystem(), PolytopeMaxVolume(), PostProcessBox(), ReduceBox(), ReduceBoxEquationWise(), and SolveCuikSystem().

double GetBoxSumSide ( boolean used,
Tbox b 
)

Determines the sum of the sides of the box, for a sub-set of intervals selected via the array of booleans used.

This function is used to determine if a box shrinks in any of its sides and it provides information even if the box is 0-size along any of its dimensions, while GetBoxVolume does not. Intuitively, GetBoxVolume corresponds to the determinant and GetBoxSumSide to the trace of a matrix. They provide different norms useful for different purposes.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
bThe box.
Returns
The sum of the sides.

Definition at line 974 of file box.c.

References IntervalSize(), Tbox::is, and Tbox::n.

Referenced by IncrementalSampleCuikSystemInBox().

unsigned int GetBoxMaxDim ( boolean used,
Tbox b 
)

Returns dimension of the (sub-)box along which the box has maximum size.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
bThe box.
Returns
The dimension of the box with maximal size. If the box is dimension-less this function returns NO_UINT.

Definition at line 1000 of file box.c.

References IntervalSize(), Tbox::is, Tbox::n, and NO_UINT.

Referenced by GetBoxSize(), and GetBoxSplitDim().

unsigned int GetBoxSplitDim ( boolean used,
Tbox b 
)

Computes the box dimension for which it is better to split the box. Right now this function is an alias to GetBoxMaxDim.

Parameters
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the computations. If the given pointer is NULL, all intervals are used.
bThe box.
Returns
The best split dimension for the given box.
See Also
GetBoxMaxDim

Definition at line 1030 of file box.c.

References GetBoxMaxDim().

void SplitBox ( unsigned int  n,
double  r,
Tbox b1,
Tbox b2,
Tbox b 
)

Splits a given box in two sub-boxes. This can be seen as a constructor method, that is, the two sub-boxes are created (or initilized) inside this function.
If the dimension for which we want to split the box is larger than the box dimensionality this functions generates an error.
If the cut point is outside th box (i.e., r is below 0 or larger than 1) this functions generates an error.

Parameters
nThe dimension
rA double in (0,1) defining the cut point along dimension n given in relative to the box size along this dimension.
b1The first resulting box. This is a copy of b but for dimension n where this box only includes the lower part of the original interval.
b2The second resulting box.This is a copy of b but for dimension n where this box only includes the upper part of the original interval.
bThe original box to split.

Definition at line 1040 of file box.c.

References Error(), Tbox::is, Tbox::level, LowerLimit(), Tbox::n, NEW, NewInterval(), PointInInterval(), and UpperLimit().

Referenced by PostProcessBox().

void ScaleBox ( double  max_upper,
Tbox b 
)

Scales a box for all its dimensions with the given scale factor.

Parameters
max_upperThe scale factor
bThe box to scale.

Definition at line 1085 of file box.c.

References IntervalScale(), Tbox::is, and Tbox::n.

void AddMargin2Box ( double  m,
Tbox b 
)

Adds a margin to all dimensions of a box.

Parameters
mThe margin to add.
bThe box to expand.

Definition at line 1093 of file box.c.

References Tbox::is, LowerLimit(), Tbox::n, NewInterval(), and UpperLimit().

boolean CmpBoxDepthFirst ( void *  b1,
void *  b2,
void *  userData 
)

Returns TRUE if box b1 is to be explored first in depth first.

This is to be used as a LessThan operator in a heap of boxes.

Parameters
b1The first box.
b2The second box.
userDataThe pointer to the data to pass to the LessThan operator as a third parameter. In this particular LessThan this parameter is not used.
Returns
TRUE if the first parameter is to be explored before than the second one when in depth first mode.
See Also
box_heap.h, Theap.

Definition at line 1105 of file box.c.

Referenced by MPI_SolveCuikSystem(), and SolveCuikSystem().

boolean CmpBoxBreadthFirst ( void *  b1,
void *  b2,
void *  userData 
)

Returns TRUE if box b1 is to be explored first in breadth first.

This is to be used as a LessThan operator in a heap of boxes.

Parameters
b1The first box.
b2The second box.
userDataThe pointer to the data to pass to the LessThan operator as a third parameter. In this particular LessThan this parameter is not used.
Returns
TRUE if the first parameter is to be explored before than the second one when in breadth first mode.
See Also
box_heap.h, Theap.

Definition at line 1110 of file box.c.

Referenced by MPI_SolveCuikSystem(), and SolveCuikSystem().

void PrintBox ( FILE *  f,
Tbox b 
)

Writes a box in file f, that can be stdout. The ouput is of the form {n [l1,u1]...[ln,un]} where n is the dimensionality of the box and [lx,ux] are the intervals defining the box.
All along CuikSuite print/read funtions are used to print/read in ASCII format and save/load are equivalen funcitions in binary format.

Parameters
fThe stream where to write.
bThe box to write.

Definition at line 1118 of file box.c.

References Tbox::is, Tbox::n, and PrintInterval().

Referenced by IncrementalSampleCuikSystemInBox(), main(), MPI_SolveCuikSystem(), MPI_TreatBox(), NewtonInWorld(), PostProcessBox(), ReduceBox(), ReduceBoxEquationWise(), SampleCuikSystemInBox(), SavePolytope(), SaveSamplesInt(), and SolveCuikSystem().

void PrintBoxSubset ( FILE *  f,
boolean used,
char **  varNames,
Tbox b 
)

Writes a box in file f, that can be stdout. The ouput is of the form {n v1:[l1,u1]...vn:[ln,un]} where n is the dimensionality of the box vx is the name of the variable for dimension x and [lx,ux] is the corresponding interval. The variable names are only printed if vars is not NULL.
All along CuikSuite print/read funtions are used to print/read in ASCII format and save/load are equivalen funcitions in binary format.

Parameters
fThe stream where to write.
usedArray of booleans, one for each interval of the input boxes. If the boolean is TRUE, the corresponding interval is used in the print. If the given pointer is NULL, all intervals are used.
varNamesThe name for variables.
bThe box to write.

Definition at line 1138 of file box.c.

References Tbox::is, Tbox::n, PRINT_VARIABLE_NAME, and PrintInterval().

Referenced by AdjustBioWorldGeometry(), IncrementalSampleCuikSystemInBox(), main(), on_cuikmove_save(), PostProcessBox(), PrintHeapOfBoxes(), and PrintListOfBoxes().

int ReadBox ( FILE *  f,
Tbox b 
)

Read a box from file f. The format of the boxes in the file is the same as that printed by PrintBox or PrintBoxSubset.
This function can be seen as a constructor, i.e., it generates a new box.

Parameters
fThe stream from which to read the box.
bThe box to read.
Returns
EOF if the file finishes before the box could be read.

Definition at line 1172 of file box.c.

References Error(), InitBox(), NEW, and NewInterval().

Referenced by LoadPolytope(), main(), and ReadListOfBoxes().

void SaveBox ( FILE *  f,
Tbox b 
)

Writes a box in file f in binary format.

Parameters
fThe stream where to write.
bThe box to write.

Definition at line 1234 of file box.c.

References Tbox::is, Tbox::level, and Tbox::n.

Referenced by SaveListOfBoxes().

void LoadBox ( FILE *  f,
Tbox b 
)

Reads a box from file f in binary format.
This function is a box constructor method.

Parameters
fThe stream from where to read.
bThe box to write.

Definition at line 1242 of file box.c.

References Tbox::is, Tbox::level, Tbox::n, and NEW.

Referenced by LoadListOfBoxes().