C++ SDK Reference  12.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diguySensorRegion.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 1992-2013 Boston Dynamics
4  * ALL RIGHTS RESERVED.
5  *
6  * These coded instructions, statements, and computer programs
7  * contain unpublished proprietary information of Boston Dynamics
8  * and are protected by Copyright Laws of the United States.
9  * They may not be used, duplicated, or disclosed in any form, in
10  * whole or in part, without the prior written consent from Boston
11  * Dynamics.
12  *
13  * RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the government is subject
15  * to restrictions as set forth in FAR 52.227.19(c)(2) or
16  * subparagraph (c)(1)(ii) of the Rights in Technical Data and
17  * Computer Software clause at DFARS 252.227-7013 and/or in
18  * similar or successor clauses in the FAR, or the DOD or NASA
19  * FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the
20  * Commercial Computer Software--Restricted Rights at 48 CFR
21  * 52.227-19, as applicable. Unpublished-rights reserved under
22  * the Copyright Laws of the United States.
23  * Contractor/Manufacturer is:
24  * Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.
25  */
26 
27 /*********************************************************************
28  **
29  *t diguySensorRegion
30  **
31  *b Link against: libdiguy
32  */
33 
34 #ifndef __diguySensorRegion_H
35 #define __diguySensorRegion_H
36 
37 #ifdef SWIG
38 %module diguySensorRegion
39 #else
40 #define CPLUSPLUS_ONLY
41 #endif
42 
43 #ifdef CPLUSPLUS_ONLY
44 
45 #include <stdio.h> // for NULL definition
46 #include <diguy_constants.h>
47 #include <diguy_typedefs.h>
48 
49 class bdiScenarioSensorRegion;
50 class diguySensorRegion;
51 class diguyCharacter;
53 
54 #endif
55 
56 
57 #include <declspec_diguy.h>
58 
59 /****************************************************************************/
60 class BDI_DECLSPEC_diguy diguySensorRegion
61 {
62 
63 public:
64 
65  /*l
66  *b Description:
67  **
68  ** Returns the name of the object. This pointer will
69  ** never be NULL.
70  **
71  *b Returns:
72  **
73  ** name of the object
74  **
75  *b Callable From:
76  **
77  *- - C++
78  *- - Script
79  */
80  const char* get_name();
81 
82  /*l
83  *b Description:
84  **
85  ** This function sets the name of this object.
86  **
87  *b Returns:
88  **
89  ** 0 on success, -1 on failure
90  **
91  *b Callable From:
92  **
93  *- - C++
94  *- - Script
95  */
96  int set_name(const char* name);
97 
98  /*l
99  *b Description:
100  **
101  ** Returns the type name of the object. This pointer will
102  ** never be NULL.
103  **
104  *b Returns:
105  **
106  ** type name of the object
107  **
108  *b Callable From:
109  **
110  *- - C++
111  *- - Script
112  */
113  const char* get_type_name();
114 
115  /*l
116  *b Description:
117  **
118  ** This function is checks whether the passed x, y, z position
119  ** is in the sensor region.
120  **
121  *b Arguments:
122  **
123  *a tx, ty, tz - point to check
124  **
125  *b Returns:
126  **
127  ** 1 if the passed point is in the sensor region;
128  ** 0 otherwise.
129  */
130  int contains_point(float tx, float ty, float tz);
131 
132  /*l
133  *b Description:
134  **
135  ** This function checks to see whether the passed character is
136  ** within this sensor region. The actual point that is checked
137  ** is the point returned by diguyCharacter::get_position().
138  **
139  ** Note that this point is typically by the character's feet, so
140  ** it is possible for the upper half of a character to pass
141  ** through a sensor region without this function detecting this.
142  **
143  ** To check the upper portion of a character, use
144  ** contains_character_link() instead, and specify "cervical"
145  ** or "back" as the link.
146  **
147  *b Arguments:
148  **
149  *a character - character to check
150  **
151  *b Returns:
152  **
153  ** 1 if the passed character is in the sensor region;
154  ** 0 otherwise.
155  **
156  *b Callable From:
157  **
158  *- - C++
159  *- - Script
160  *- - Decision Bead
161  */
162  int contains_character(const char* character_name);
163 
164  /*l
165  *b Description:
166  **
167  ** This function checks to see whether a character with the specified
168  ** type is within this sensor region. The actual point that is
169  ** checked is the point returned by diguyCharacter::get_position().
170  **
171  ** Note that this point is typically by the character's feet, so it
172  ** is possible for the upper half of a character to pass through a
173  ** sensor region without this function detecting this.
174  **
175  *b Arguments:
176  **
177  *a character_type - character type to check
178  **
179  *b Returns:
180  **
181  ** 1 if a character with the passed type is in the sensor region;
182  ** 0 otherwise.
183  **
184  *b Callable From:
185  **
186  *- - C++
187  *- - Script
188  *- - Decision Bead
189  */
190  int contains_character_by_type(const char* character_type);
191 
192  /*l
193  *b Description:
194  **
195  ** This function checks to see whether a character with the specified
196  ** type and appearance is within this sensor region. The actual point
197  ** that is checked is the point returned by
198  ** diguyCharacter::get_position().
199  **
200  ** Note that this point is typically by the character's feet, so
201  ** it is possible for the upper half of a character to pass
202  ** through a sensor region without this function detecting this.
203  **
204  *b Arguments:
205  **
206  *a character_type - character type to check
207  *a appearance - appearance to check
208  **
209  *b Returns:
210  **
211  ** 1 if a character with the passed type is in the sensor region;
212  ** 0 otherwise.
213  **
214  *b Callable From:
215  **
216  *- - C++
217  *- - Script
218  *- - Decision Bead
219  */
220  int contains_character_by_type_and_appearance(const char* character_type,
221  const char* appearance);
222 
223  /*l
224  *b Description:
225  **
226  ** This function checks to see whether a character from the specified
227  ** group is within this sensor region. The actual point that is
228  ** checked is the point returned by diguyCharacter::get_position().
229  **
230  ** Note that this point is typically by the character's feet, so it
231  ** is possible for the upper half of a character to pass through a
232  ** sensor region without this function detecting this.
233  **
234  *b Arguments:
235  **
236  *a group_name - group of characters to check
237  **
238  *b Returns:
239  **
240  ** 1 if a character from the group is in the sensor region;
241  ** 0 otherwise.
242  **
243  *b Callable From:
244  **
245  *- - C++
246  *- - Script
247  *- - Decision Bead
248  */
249  int contains_character_from_group(const char* group_name);
250 
251  /*l
252  *b Description:
253  **
254  ** This function is similar to contains_character(), but
255  ** rather than checking whether the character's ideal position
256  ** is in the sensor region, this function checks whether the
257  ** specified link is in the sensor region.
258  **
259  *b Arguments:
260  **
261  *a character_name - name of the character
262  *a link_name - name of the link
263  *a offset_tx, offset_ty, offset_tz - offset in link
264  **
265  *b Returns:
266  **
267  ** 1 if the passed character link is in the sensor region;
268  ** 0 otherwise.
269  */
270  int contains_character_link(const char* character_name,
271  const char* link_name,
272  float offset_tx, float offset_ty, float offset_tz);
273 
274  /*l
275  *b Description:
276  **
277  ** This function checks all characters in the scenario for whether
278  ** they are in this sensor region. Each character that is in the
279  ** sensor region is put into the passed character group. Note that
280  ** the group is first cleared of all members.
281  **
282  ** A subset of characters can be checked by calling
283  ** add_candidate_characters_in_region_to_group().
284  **
285  *b Arguments:
286  **
287  *a group - group to which characters in sensor region should
288  *a be added
289  **
290  *b Returns:
291  **
292  ** 0 on success, -1 on failure
293  **
294  *b Callable From:
295  **
296  *- - C++
297  *- - Script
298  */
299  int add_characters_in_region_to_group(diguyCharacterGroup* group);
300 
301  /*l
302  *b Description:
303  **
304  ** This function checks all characters in the candidates_group
305  ** for whether they are in this sensor region. Each character that
306  ** is in the sensor region is put into the passed character group.
307  ** Note that the group is first cleared of all members.
308  **
309  *b Arguments:
310  **
311  *a candidates_group - group whose members should be checked
312  *a group - group to which characters in sensor region
313  *a should be added
314  **
315  *b Returns:
316  **
317  ** 0 on success, -1 on failure
318  **
319  *b Callable From:
320  **
321  *- - C++
322  *- - Script
323  */
324  int add_candidate_characters_in_region_to_group(diguyCharacterGroup* candidates_group,
325  diguyCharacterGroup* group);
326 
327 
328 /*****************************************************************************/
356  /*l
357  *b Description:
358  **
359  ** This function sets the group that will be used as
360  ** autosense candidates.
361  **
362  ** The passed group must be created by the DI-Guy Scenario UI
363  ** or via a call to diguyScenario::create_group().
364  **
365  ** The members of the candidates group should be set using
366  ** the DI-Guy Scenario UI or via calls to
367  ** diguyCharacterGroup::add_member().
368  **
369  *b Arguments:
370  **
371  *a autosense_candidates_group - group of characters to
372  *a use as candidates
373  **
374  *b Returns:
375  **
376  ** 0 on success, -1 on failure
377  **
378  *b Callable From:
379  **
380  *- - C++
381  *- - Script
382  */
383  int set_autosense_candidates_group(diguyCharacterGroup* autosense_candidates_group);
384 
385  /*l
386  *b Returns:
387  **
388  ** the most recent setting of set_autosense_candidates_group()
389  **
390  *b Callable From:
391  **
392  *- - C++
393  *- - Script
394  */
395  diguyCharacterGroup* get_autosense_candidates_group();
396 
397  /*l
398  *b Description:
399  **
400  ** This function sets the group that will be used to hold
401  ** autosense candidate characters that are in this sensor
402  ** region.
403  **
404  ** The passed group must be created by the DI-Guy Scenario UI
405  ** or via a call to diguyScenario::create_group().
406  **
407  ** The members group is always a subset of the candidates group.
408  ** Characters should not be manually added or removed from the
409  ** members group.
410  **
411  *b Arguments:
412  **
413  *a autosense_members_group - group that holds which candidate
414  *a characters are in this sensor region
415  **
416  *b Returns:
417  **
418  ** 0 on success, -1 on failure
419  **
420  *b Callable From:
421  **
422  *- - C++
423  *- - Script
424  */
425  int set_autosense_members_group(diguyCharacterGroup* autosense_members_group);
426 
427  /*l
428  *b Returns:
429  **
430  ** the most recent setting of set_autosense_members_group()
431  **
432  *b Callable From:
433  **
434  *- - C++
435  *- - Script
436  */
437  diguyCharacterGroup* get_autosense_members_group();
438 
439  /*l
440  *b Description:
441  **
442  ** This function returns the character of the autosense
443  ** candidates group that has entered the sensor
444  ** region, triggering a CALLBACK_ID_AUTOSENSE_CHARACTER_ENTERED
445  ** callback. This function will return NULL when not in the
446  ** above callback.
447  **
448  *b Returns:
449  **
450  ** autosense candidate that has entered this region; NULL if
451  ** not in a CALLBACK_ID_AUTOSENSE_CHARACTER_ENTERED callback
452  **
453  *b Callable From:
454  **
455  *- - C++
456  *- - Script
457  */
458  diguyCharacter* get_autosense_callback_candidate_entered();
459 
460  /*l
461  *b Description:
462  **
463  ** This function returns the character of the autosense
464  ** candidates group that has left the sensor
465  ** region, triggering a CALLBACK_ID_AUTOSENSE_CHARACTER_LEFT
466  ** callback. This function will return NULL when not in the
467  ** above callback.
468  **
469  *b Returns:
470  **
471  ** autosense candidate that has left this region; NULL if
472  ** not in a CALLBACK_ID_AUTOSENSE_CHARACTER_LEFT callback
473  **
474  *b Callable From:
475  **
476  *- - C++
477  *- - Script
478  */
479  diguyCharacter* get_autosense_callback_candidate_left();
480 
481 
482 /*****************************************************************************/
487  /*l
488  *b Description:
489  **
490  ** This is an enumeration of the different callbacks
491  ** that can be registered with add_callback() and
492  ** add_callback_script().
493  **
494  *b Usable From:
495  **
496  *- - C++
497  *- - Script
498  */
499  enum {
500  CALLBACK_ID_CREATE = 1,
501  CALLBACK_ID_DESTROY,
502  CALLBACK_ID_DETONATION,
503  CALLBACK_ID_AUTOSENSE_CHARACTER_ENTERED,
504  CALLBACK_ID_AUTOSENSE_CHARACTER_LEFT
505  };
506 
507 
508 #ifdef CPLUSPLUS_ONLY
509 
510  /*l
511  *b Description:
512  **
513  ** This function adds a user callback. Callbacks can be removed
514  ** with remove_callback() or remove_callback_with_user_data().
515  **
516  *b Arguments:
517  **
518  *a callback - pointer to function with prototype
519  *a diguySensorRegionCallback (typedefed above)
520  *a callback_id - integer id of when this callback is to be called
521  *a callback_params - not currently used; pass NULL
522  *a callback_user_data - pointer for user's own use; DI-Guy will
523  *a do nothing to the contents of this pointer
524  *a beyond passing it back when the callback is
525  *a invoked
526  **
527  ** callback_id should be one of the following values:
528  **
529  *i CALLBACK_ID_CREATE
530  **
531  ** This callback will be called when a new sensor region is created.
532  **
533  ** Note that this callback can only be added by calling
534  ** diguyScenario::add_default_sensor_region_callback(); adding it
535  ** with diguySensorRegion::add_callback() will have no effect, as
536  ** by that time the sensor region has already been created.
537  **
538  *i CALLBACK_ID_DESTROY
539  **
540  ** This callback will be called when a sensor region is
541  ** destroyed.
542  **
543  *i CALLBACK_ID_DETONATION
544  **
545  ** This callback will be called when a detonation occurs within
546  ** the sensor region.
547  **
548  *i CALLBACK_ID_AUTOSENSE_CHARACTER_ENTERED
549  **
550  ** This callback will be called when an autosense candidate
551  ** character first enters the sensor region.
552  **
553  *i CALLBACK_ID_AUTOSENSE_CHARACTER_LEFT
554  **
555  ** This callback will be called when an autosense candidate
556  ** character first leaves the sensor region.
557  **
558  ** Callbacks return a value of type diguyCallbackReturn,
559  ** which will be DIGUY_CALLBACK_STOP or DIGUY_CALLBACK_CONTINUE.
560  ** If the callback returns DIGUY_CALLBACK_STOP, the default handler
561  ** of the function will not be called; the callback is asserting
562  ** that it has done everything necessary for the function call.
563  ** If the callback returns DIGUY_CALLBACK_CONTINUE, the default
564  ** handler for the function will be called after the callback.
565  **
566  *b Returns:
567  **
568  ** 0 on success, -1 on failure
569  **
570  *b Callable From:
571  **
572  *- - C++
573  */
574  int add_callback(int callback_id,
575  diguySensorRegionCallback* callback,
576  void* callback_params = 0,
577  void* callback_user_data = 0);
578 
579  /*l
580  *b Description:
581  **
582  ** This function removes a user callback. All callbacks matching
583  ** the specified callback_id and callback function will be removed.
584  **
585  *b Arguments:
586  **
587  *a callback_id - integer id of when this callback is to be called
588  *a callback - pointer to function with prototype
589  *a diguySensorRegionCallback (typedefed above)
590  **
591  *b Returns:
592  **
593  ** 0 on success, -1 on failure
594  */
595  int remove_callback(int callback_id,
596  diguySensorRegionCallback* callback);
597 
598  /*l
599  *b Description:
600  **
601  ** This function removes a user callback. All callbacks matching
602  ** the specified callback_id and callback_user_data pointer will
603  ** be removed.
604  **
605  *b Arguments:
606  **
607  *a callback_id - integer id of when this callback is to be called
608  *a callback_user_data - pointer for user's own use
609  **
610  *b Returns:
611  **
612  ** 0 on success, -1 on failure
613  */
614  int remove_callback_with_user_data(int callback_id,
615  void* callback_user_data);
616 
617 #endif
618 
619  /*l
620  *b Description:
621  **
622  ** This function adds a user callback script. Callback scripts can
623  ** be removed with remove_callback_script().
624  **
625  ** See diguyCharacter::add_callback_script() for an example
626  ** of use.
627  **
628  *b Arguments:
629  **
630  *a callback_id - integer id of the callback
631  *a callback_script - script text of callback to be added
632  *a callback_script_type - the type of script contained in
633  *a callback_script
634  **
635  ** If NULL is passed for callback_script_type, a default script type
636  ** will be derived based on the default script interpreter of the
637  ** scenario.
638  **
639  *i lua specific:
640  **
641  ** When the script is called, the object for which it is being called
642  ** will be in the callback_object global.
643  **
644  ** To pass NULL when calling from a lua script, use nil.
645  **
646  *b Returns:
647  **
648  ** 0 on success, -1 on failure
649  **
650  *b Callable From:
651  **
652  *- - C++
653  *- - Script
654  */
655  int add_callback_script(int callback_id,
656  const char* callback_script,
657  const char* callback_script_type = NULL);
658 
659  /*l
660  *b Description:
661  **
662  ** This function removes a user callback script previously added with
663  ** add_callback_script().
664  **
665  ** See diguyCharacter::remove_callback_script() for an example
666  ** of use.
667  **
668  *b Arguments:
669  **
670  *a callback_id - integer id of the callback
671  *a callback_script - script text of callback previously added
672  *a callback_script_type - the type of script contained in
673  *a callback_script
674  **
675  ** If NULL is passed for callback_script, all callback
676  ** scripts whose ids match callback_id and whose types match
677  ** callback_script_type will be removed.
678  **
679  ** If NULL is passed for callback_script_type, a default script type
680  ** will be derived based on the default script interpreter of the
681  ** scenario.
682  **
683  *i Lua specific:
684  **
685  ** To pass NULL when calling from a lua script, use nil.
686  **
687  *b Returns:
688  **
689  ** 0 on success, -1 on failure
690  **
691  *b Callable From:
692  **
693  *- - C++
694  *- - Script
695  */
696  int remove_callback_script(int callback_id,
697  const char* callback_script,
698  const char* callback_script_type = NULL);
699 
700 
701 /*****************************************************************************/
707  /*l
708  *b Description:
709  **
710  ** This function maps the event handler with the given name
711  ** to a callback id. This mapping will be saved in the .dss
712  ** file and restored when the .dss file is loaded.
713  **
714  ** Mappings can also be made via the DI-Guy Scenario UI.
715  **
716  ** The event handler is one of the following:
717  **
718  *- - a scene object callback function registered by
719  *- diguyScenario::register_sensor_region_event_handler() or
720  *- diguyScenario::register_sensor_region_event_handler_from_library()
721  *- - a script registered by
722  *- diguyScenario::register_sensor_region_event_handler_script()
723  *- - a Script, Decision, or Library Function in the scenario
724  *- whose "Event Type" is "Sensor Region"
725  **
726  *b Arguments:
727  **
728  *a callback_id - integer id of callback
729  *a handler_name - name of the event handler to map
730  **
731  *b Returns:
732  **
733  ** 0 on success, -1 on failure
734  **
735  *b Callable From:
736  **
737  *- - C++
738  *- - Script
739  */
740  int map_event_handler_to_callback_id(int callback_id,
741  const char* handler_name);
742 
743  /*l
744  *b Description:
745  **
746  ** This function unmaps the event handler with the given name
747  ** from a callback id.
748  **
749  *b Arguments:
750  **
751  *a callback_id - integer id of callback
752  *a handler_name - name of the event handler to map
753  *a unmap_all_matches - pass 0 to unmap only the first match,
754  *a pass 1 to unmap all matches
755  **
756  *b Returns:
757  **
758  ** 0 on success, -1 on failure
759  **
760  *b Callable From:
761  **
762  *- - C++
763  *- - Script
764  */
765  int unmap_event_handler_from_callback_id(int callback_id,
766  const char* handler_name,
767  int unmap_all_matches = 0);
768 
769 
774 #ifdef CPLUSPLUS_ONLY
775 
776 private:
777 
778  /*l
779  ** A private constructor.
780  */
781  diguySensorRegion(bdiScenarioSensorRegion* sensor_region);
782 
783  /*l
784  ** A pointer to internal data.
785  */
786  bdiScenarioSensorRegion* m_sensor_region;
787 
788  friend class bdiScenarioSensorRegion;
789 
790 #endif
791 
792 };
793 
794 #endif /* __diguySensorRegion_H */