00001 /** 00002 * @file Pfield.h 00003 * 00004 * Definition of class Potentialfield 00005 * This file was originally named Potentialfield.h but had to be renamed 00006 * because of another Potentialfield.h in this project. 00007 * 00008 * @author <a href="mailto:timlaue@informatik.uni-bremen.de">Tim Laue</a> 00009 */ 00010 00011 #ifndef PFIELD_H_ 00012 #define PFIELD_H_ 00013 00014 00015 #include "PfieldConfig.h" 00016 #include <vector> 00017 #include <string> 00018 #include "PotentialfieldComposition.h" 00019 00020 class Object; 00021 class Parser; 00022 class PfPose; 00023 class PfVec; 00024 00025 00026 /** The criterions for computing the value of a field result*/ 00027 enum Criterion {CRITERION_GAIN, CRITERION_ABSOLUTE, CRITERION_GRADIENT, 00028 CRITERION_CONST}; 00029 00030 /** A datatype for different time constraints*/ 00031 enum ChangeType {MILLISECONDS, CALLS}; 00032 00033 /** A datatype describing to what to keep: a result or a field*/ 00034 enum KeepType {KEEP_RESULT, KEEP_FIELD}; 00035 00036 /** A type to distinguish between the two different field types*/ 00037 enum BehaviorFieldType {ACTION_FIELD, MOTION_FIELD}; 00038 00039 /** 00040 * @class Potentialfield 00041 * 00042 * An abstract base class for all fields 00043 */ 00044 class Potentialfield 00045 { 00046 public: 00047 /** Constructor */ 00048 Potentialfield(); 00049 00050 /** Destructor */ 00051 virtual ~Potentialfield(); 00052 00053 /** Initializes values and / or allocates additional memory for subsequent computations. 00054 This function should be called after all values are set and all objects have 00055 been assigned */ 00056 virtual void init() {} 00057 00058 /** Computes the result of a field 00059 * @param pose The pose on which the field affects 00060 * @param result The returned result 00061 */ 00062 void getResult(const PfPose& pose, PotentialfieldResult& result); 00063 00064 /** Computes an array of field values, used by visualization 00065 * @param x1 Minimum x-coordinate to compute 00066 * @param y1 Minimum y-coordinate to compute 00067 * @param x2 Maximum x-coordinate to compute 00068 * @param y2 Maximum y-coordinate to compute 00069 * @param xSteps The computation steps in x-direction 00070 * @param ySteps The computation steps in y-direction 00071 * @param value An array containing all computed values, memory has to be allocated BEFORE calling the function 00072 * @param max Returns the maximum value 00073 */ 00074 void getValueArray(double x1, double y1, double x2, double y2, 00075 int xSteps, int ySteps, double value[], double& max); 00076 00077 /** Computes an array of gradient directions, used by visualization 00078 * @param x1 Minimum x-coordinate to compute 00079 * @param y1 Minimum y-coordinate to compute 00080 * @param x2 Maximum x-coordinate to compute 00081 * @param y2 Maximum y-coordinate to compute 00082 * @param xSteps The computation steps in x-direction 00083 * @param ySteps The computation steps in y-direction 00084 * @param directions An array containing all computed gradients, memory has to be allocated BEFORE calling the function 00085 */ 00086 void getDirectionArray(double x1, double y1, double x2, double y2, 00087 int xSteps, int ySteps, PfVec directions[]); 00088 00089 /** Computes the gradient at a given position 00090 * @param pose The pose 00091 * @return The gradient 00092 */ 00093 PfVec getFieldVecAt(const PfPose& pose); 00094 00095 /** Computes the field value at a given position 00096 * @param pose The pose 00097 * @return The field value 00098 */ 00099 double getFieldValueAt(const PfPose& pose); 00100 00101 /** Adds an object to the field 00102 * @param object The object 00103 */ 00104 virtual void addObject(Object* object) 00105 { objects.push_back(object);} 00106 00107 /** Returns the name of the field 00108 * @return The name 00109 */ 00110 std::string getName() const 00111 { return name;} 00112 00113 /** Returns the type of the field 00114 * @return The type 00115 */ 00116 virtual BehaviorFieldType getBehaviorFieldType() const = 0; 00117 00118 /** Sets the time constraints 00119 * @param whatToKeep Describes what to keep: result or field 00120 * @param keepForN Keep for n CALLS or MILLISECONDS 00121 * @param n The value corresponding to keepForN 00122 * @param blockForM Block for m CALLS or MILLISECONDS 00123 * @param m The value corresponding to blockForM 00124 * @param keepMaxForO Keep this field at most o CALLS or MILLISECONDS 00125 * @param o The value corresponding to blockForO 00126 */ 00127 void setTimeConstraints(KeepType whatToKeep, ChangeType keepForN, int n, 00128 ChangeType blockForM, int m, ChangeType keepMaxForO, int o) 00129 { 00130 this->whatToKeep = whatToKeep; 00131 this->keepForN = keepForN; 00132 this->n = n; 00133 this->blockForM = blockForM; 00134 this->m = m; 00135 this->keepMaxForO = keepMaxForO; 00136 this->o = o; 00137 } 00138 00139 /** Sets the validity criterion 00140 * @param criterion The criterion 00141 * @param value An additional parameter (for criterion == CRITERION_CONST) 00142 */ 00143 void setCriterion(Criterion criterion, double value=0) 00144 { this->criterion = criterion; criterionParameter = value;} 00145 00146 /** Returns the names of the fields, this field is combined with 00147 * @return A list of field names 00148 */ 00149 std::vector<std::string> getCombinedFields() const 00150 { return combinedFields;} 00151 00152 /** Adds the name of a field, this field is combined with 00153 * @param fieldName The name of the field 00154 */ 00155 void addCombinedField(const std::string& fieldName) 00156 { combinedFields.push_back(fieldName);} 00157 00158 /** Returns whether the field is combined with other fields or not 00159 * @return true, if the field is combined with at least one other field 00160 */ 00161 bool isCombined() 00162 { return (combinedFields.size()>0);} 00163 00164 /** Gives the field information about being selected or not 00165 * @param selected True, if the field has been selected in the current run 00166 */ 00167 void setSelectionFeedback(bool selected); 00168 00169 /** Checks, if the field is still blocking other fields 00170 * @return true, if the field has to remain active 00171 */ 00172 bool hasToRemainActive(); 00173 00174 /** Activates and / or deactivates the field 00175 * @param isActive Deactivates the field, if false. 00176 */ 00177 void setActivation(bool isActive) 00178 {this->isActive = isActive;} 00179 00180 protected: 00181 /** The objects assigned to this field*/ 00182 std::vector<Object*> objects; 00183 /** The name of the field*/ 00184 std::string name; 00185 /** The criterion for result computation*/ 00186 Criterion criterion; 00187 /** An additional parameter for criterion*/ 00188 double criterionParameter; 00189 /** The names of the combined fields*/ 00190 std::vector<std::string> combinedFields; 00191 /** The last result computed by this field*/ 00192 PotentialfieldResult lastResult; 00193 /** Describes what to keep: result or field*/ 00194 KeepType whatToKeep; 00195 /** Keep for n CALLS or MILLISECONDS */ 00196 ChangeType keepForN; 00197 /** The value corresponding to keepForN */ 00198 unsigned int n; 00199 /** Block for m CALLS or MILLISECONDS */ 00200 ChangeType blockForM; 00201 /** The value corresponding to blockForM */ 00202 unsigned int m; 00203 /** Keep this field at most for o CALLS or MILLISECONDS*/ 00204 ChangeType keepMaxForO; 00205 /** The value corresponding to keepMaxForO */ 00206 int o; 00207 /** Describes, if the field has been selected last turn*/ 00208 bool currentlySelected; 00209 /** Describes how long this field has been selected*/ 00210 unsigned long selectedSince; 00211 /** Describes how often this field has been selected*/ 00212 unsigned long selectedCalls; 00213 /** Describes whether calls to be blocked or the point of time until the block is active*/ 00214 unsigned long block; 00215 /** Flag: True, if the field is active and executable*/ 00216 bool isActive; 00217 00218 /** Computes the result of a field 00219 * @param pose The pose on which the field affects 00220 * @param result The returned result 00221 */ 00222 virtual void execute(const PfPose& pose, PotentialfieldResult& result) = 0; 00223 00224 /** Checks if the field is blocked and cannot compute a result 00225 * @return true, if the field is blocked 00226 */ 00227 bool isBlocked(); 00228 00229 /** Checks if the field has to be blocked in future and sets 00230 * a block if necessary 00231 */ 00232 void checkForBlockAppliance(); 00233 }; 00234 00235 00236 #endif //PFIELD_H_ 00237 00238 00239 00240 /* 00241 * $Log: Pfield.h,v $ 00242 * Revision 1.2 2004/06/07 18:19:39 tim 00243 * removed dynamic_cast and RTTI 00244 * 00245 * Revision 1.1.1.1 2004/05/22 17:37:31 cvsadm 00246 * created new repository GT2004_WM 00247 * 00248 * Revision 1.1 2004/01/20 15:42:19 tim 00249 * Added potential fields implementation 00250 * 00251 * Revision 1.6 2003/06/09 20:00:04 tim 00252 * Changed potentialfield architecture 00253 * 00254 * Revision 1.5 2003/05/08 15:26:06 tim 00255 * no message 00256 * 00257 * Revision 1.4 2003/04/02 16:32:28 dueffert 00258 * warning removed 00259 * 00260 * Revision 1.3 2003/04/02 14:39:12 tim 00261 * Changed Bremen Byters Behavior 00262 * 00263 * Revision 1.2 2003/03/23 20:32:37 loetzsch 00264 * removed green compiler warning: no newline at end of file 00265 * 00266 * Revision 1.1 2003/03/23 17:51:27 tim 00267 * Added potentialfields 00268 * 00269 */