00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Paul S. Strauss (MMM yyyy) 00025 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifndef _SO_GET_BOUNDING_BOX_ACTION_ 00051 #define _SO_GET_BOUNDING_BOX_ACTION_ 00052 00053 #include <Inventor/SbBox.h> 00054 #include <Inventor/SbViewportRegion.h> 00055 #include <Inventor/actions/SoSubAction.h> 00056 00058 // 00059 // Class: SoGetBoundingBoxAction 00060 // 00061 // For computing a bounding box enclosing objects defined by a scene 00062 // graph. The box is a rectangular prism whose sides are aligned with 00063 // the coordinate axes, and is represented as an SbBox3f. It also 00064 // computes the center point, which is defined differently for 00065 // different objects. 00066 // 00068 00172 class SoGetBoundingBoxAction : public SoAction 00173 { 00174 SO_ACTION_HEADER(SoGetBoundingBoxAction); 00175 00176 public: 00188 SoGetBoundingBoxAction(const SbViewportRegion &viewportRegion); 00189 00190 // Destructor 00191 #ifndef HIDDEN_FROM_DOC 00192 virtual ~SoGetBoundingBoxAction(); 00193 #endif // HIDDEN_FROM_DOC 00194 00198 void setViewportRegion(const SbViewportRegion &newRegion); 00199 00203 const SbViewportRegion &getViewportRegion() const; 00204 00208 SbBox3f getBoundingBox() const; 00209 00213 SbXfBox3f &getXfBoundingBox(); 00214 00218 const SbVec3f &getCenter() const; 00219 00226 void setInCameraSpace(SbBool flag); 00227 00231 SbBool isInCameraSpace() const; 00232 00236 enum ResetType { // Which things get reset: 00240 TRANSFORM = 0x01, 00244 BBOX = 0x02, 00248 ALL = 0x03 00249 }; 00250 00257 void setResetPath(const SoPath *path, 00258 SbBool resetBefore = TRUE, 00259 ResetType what = ALL); 00263 const SoPath *getResetPath() const; 00267 SbBool isResetPath() const; 00271 SbBool isResetBefore() const; 00275 SoGetBoundingBoxAction::ResetType getWhatReset() const; 00276 00277 private: 00278 00279 // Call these methods at beginning and end (respectively) of 00280 // the getBoundingBox action for each node. (SoNode calls these in 00281 // its static method for this action.) 00282 void checkResetBefore(); 00283 void checkResetAfter(); 00284 00285 // Extends the current bounding box by the given bounding box, 00286 // after transforming it by the current value of the 00287 // SoLocalBBoxMatrixElement 00288 void extendBy(const SbBox3f &box); 00289 void extendBy(const SbXfBox3f &box); 00290 00291 void extendBy(const SbBox3d &box); 00292 void extendBy(const SbXfBox3d &box); 00293 00294 // Sets the center of the bounding box to the given point, which, 00295 // if transformCenter is TRUE, is first transformed by the current 00296 // value of the SoLocalBBoxMatrixElement. After this is called, 00297 // isCenterSet will return TRUE, unless resetCenter is called. 00298 // Shapes should setCenter() to whatever is appropriate (e.g. 00299 // left-justified text might set the center to be the start of the 00300 // string) with transformCenter set to TRUE. Groups are 00301 // responsible for averaging the centers if more than one shape 00302 // sets the center; when setting the center to the average of 00303 // transformed centers, pass FALSE for transformCenter. 00304 void setCenter(const SbVec3f ¢er, SbBool transformCenter); 00305 void setCenter(const SbVec3d ¢er, SbBool transformCenter); 00306 00307 SbBool isCenterSet() const; 00308 void resetCenter(); 00309 00310 private: 00311 static void initClass(); 00312 static void exitClass(); 00313 00322 void setIgnoreScreenSpaceBoundingBoxes(bool flag); 00323 00327 bool ignoreScreenSpaceBoundingBoxes() const; 00328 00329 private: 00330 // Initiates action on graph 00331 virtual void beginTraversal(SoNode *node); 00332 00333 private: 00334 SbXfBox3f box; // Bounding box 00335 SbVec3f center; // Center point 00336 SbBool cameraSpace; // Bounding box in camera space? 00337 const SoPath *resetPath; // path to reset transform 00338 SbBool resetBefore; // reset before or after? 00339 ResetType resetWhat; // which things get reset? 00340 SbViewportRegion vpRegion; // Current viewport region 00341 SbBool centerSet; // setCenter() called? 00342 00343 bool m_ignoreScreenSpaceBoundingBoxes; 00344 00345 // check to see if the reset parameters are met, if so, do the 00346 // reset transform and reset bbox 00347 void checkReset(SbBool resetBefore); 00348 00349 }; 00350 00351 #endif /* _SO_GET_BOUNDING_BOX_ACTION_ */ 00352 00353