| 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * Further, this software is distributed without any warranty that it is |
| 16 | * free of the rightful claim of any third person regarding infringement |
| 17 | * or the like. Any license provided herein, whether implied or |
| 18 | * otherwise, applies only to this software file. Patent licenses, if |
| 19 | * any, provided herein do not apply to combinations of this program with |
| 20 | * other software, or any other product whatsoever. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 | * Mountain View, CA 94043, or: |
| 28 | * |
| 29 | * http://www.sgi.com |
| 30 | * |
| 31 | * For further information regarding this notice, see: |
| 32 | * |
| 33 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * Copyright (C) 1990,91 Silicon Graphics, Inc. |
| 39 | * |
| 40 | _______________________________________________________________________ |
| 41 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 | | |
| 43 | | $Revision $ |
| 44 | | |
| 45 | | Classes: |
| 46 | | SoClipPlaneElement |
| 47 | | |
| 48 | | Author(s) : Paul S. Strauss |
| 49 | | |
| 50 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 | _______________________________________________________________________ |
| 52 | */ |
| 53 | |
| 54 | #include <Inventor/elements/SoClipPlaneElement.h>cxx . . $ `<file>/lib/database/include/Inventor/elements/SoClipPlaneElement.h`/ |
| 55 | #include <Inventor/elements/SoModelMatrixElement.h>cxx . . $ `<file>/lib/database/include/Inventor/elements/SoModelMatrixElement.h`/ |
| 56 | #include <Inventor/errors/SoDebugError.h>cxx . . $ `<file>/lib/database/include/Inventor/errors/SoDebugError.h`/ |
| 57 | |
| 58 | SO_ELEMENT_SOURCEcxx . . $ `lib/database/include/Inventor/elements/SoSubElement.h:173:9`!(SoClipPlaneElement); |
| 59 | |
| 60 | // |
| 61 | // This structure contains all information needed for a clipping |
| 62 | // plane. Pointers to instances of this structure are stored in the |
| 63 | // "planes" SbPList. |
| 64 | // |
| 65 | |
| 66 | struct So_ClipPlanecxx . . $ So_ClipPlane# { |
| 67 | SbPlanecxx . . $ SbPlane# objPlanecxx . . $ So_ClipPlane#objPlane.; // World-space clipping plane |
| 68 | SbPlanecxx . . $ SbPlane# worldPlanecxx . . $ So_ClipPlane#worldPlane.; // World-space clipping plane |
| 69 | SbMatrixcxx . . $ SbMatrix# objToWorldcxx . . $ So_ClipPlane#objToWorld.; // Converts object space to world space |
| 70 | SbBoolcxx . . $ SbBool# worldPlaneValidcxx . . $ So_ClipPlane#worldPlaneValid.;// TRUE if worldPlane was computed |
| 71 | }; |
| 72 | |
| 73 | //////////////////////////////////////////////////////////////////////// |
| 74 | // |
| 75 | // Description: |
| 76 | // Destructor. |
| 77 | // |
| 78 | // Use: private |
| 79 | |
| 80 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::~cxx . . $ SoClipPlaneElement#`~SoClipPlaneElement`(49f6e7a06ebc5aa8).SoClipPlaneElementcxx . . $ SoClipPlaneElement#() |
| 81 | // |
| 82 | //////////////////////////////////////////////////////////////////////// |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | //////////////////////////////////////////////////////////////////////// |
| 87 | // |
| 88 | // Description: |
| 89 | // Initializes element. |
| 90 | // |
| 91 | // Use: public |
| 92 | |
| 93 | void |
| 94 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::initcxx . . $ SoClipPlaneElement#init(10e5c4d2a7f63e3e).(SoStatecxx . . $ SoState# *) |
| 95 | // |
| 96 | //////////////////////////////////////////////////////////////////////// |
| 97 | { |
| 98 | planescxx . . $ SoClipPlaneElement#planes..truncatecxx . . $ SbPList#truncate(d4f767463ce0a6b3).(0); |
| 99 | startIndexcxx . . $ SoClipPlaneElement#startIndex. = 0; |
| 100 | } |
| 101 | |
| 102 | //////////////////////////////////////////////////////////////////////// |
| 103 | // |
| 104 | // Description: |
| 105 | // Adds a clip plane to the current set in the state. |
| 106 | // |
| 107 | // Use: public, static |
| 108 | |
| 109 | void |
| 110 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::addcxx . . $ SoClipPlaneElement#add(9c980c658a5394e7).(SoStatecxx . . $ SoState# *state, SoNodecxx . . $ SoNode# *node, const SbPlanecxx . . $ SbPlane# &plane) |
| 111 | // |
| 112 | //////////////////////////////////////////////////////////////////////// |
| 113 | { |
| 114 | SoClipPlaneElementcxx . . $ SoClipPlaneElement# *elt; |
| 115 | |
| 116 | // Get an instance we can change (pushing if necessary) |
| 117 | elt = (SoClipPlaneElementcxx . . $ SoClipPlaneElement# *) getElementcxx . . $ SoElement#getElement(a44dab01fbe42818).(state, classStackIndexcxx . . $ SoClipPlaneElement#classStackIndex.); |
| 118 | |
| 119 | if (elt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 120 | elt->addToEltcxx . . $ SoClipPlaneElement#addToElt(b43e0644e367a739).(plane, SoModelMatrixElementcxx . . $ SoModelMatrixElement#::getcxx . . $ SoModelMatrixElement#get(361591dce4cd33b0).(state)); |
| 121 | |
| 122 | // Update node id list in element |
| 123 | elt->addNodeIdcxx . . $ SoAccumulatedElement#addNodeId(1421811f981777c4).(node); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | //////////////////////////////////////////////////////////////////////// |
| 128 | // |
| 129 | // Description: |
| 130 | // Override push to copy the existing planes from the previous |
| 131 | // element. |
| 132 | // |
| 133 | // Use: public |
| 134 | |
| 135 | void |
| 136 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::pushcxx . . $ SoClipPlaneElement#push(10e5c4d2a7f63e3e).(SoStatecxx . . $ SoState# *) |
| 137 | // |
| 138 | //////////////////////////////////////////////////////////////////////// |
| 139 | { |
| 140 | const SoClipPlaneElementcxx . . $ SoClipPlaneElement# *elt = |
| 141 | (const SoClipPlaneElementcxx . . $ SoClipPlaneElement# *) getNextInStackcxx . . $ SoElement#getNextInStack(b4facc7fcf5bd448).(); |
| 142 | |
| 143 | // Use SbPList::operator = to copy the pointers to the existing |
| 144 | // planes. Since the previous element can't be destroyed before |
| 145 | // this one is, there is no problem with using pointers to |
| 146 | // existing plane structures. However, any new ones we add have to |
| 147 | // be freed up when this instance goes away, so we save the |
| 148 | // starting index to allow us to fix this in pop(). |
| 149 | planescxx . . $ SoClipPlaneElement#planes. =cxx . . $ SbPList#`operator=`(5a1053fd52a8627). elt->planescxx . . $ SoClipPlaneElement#planes.; |
| 150 | startIndexcxx . . $ SoClipPlaneElement#startIndex. = planescxx . . $ SoClipPlaneElement#planes..getLengthcxx . . $ SbPList#getLength(455f465bc33b4cdf).(); |
| 151 | nodeIdscxx . . $ SoAccumulatedElement#nodeIds. =cxx . . $ SbPList#`operator=`(5a1053fd52a8627). elt->nodeIdscxx . . $ SoAccumulatedElement#nodeIds.; |
| 152 | } |
| 153 | |
| 154 | //////////////////////////////////////////////////////////////////////// |
| 155 | // |
| 156 | // Description: |
| 157 | // Override pop to free up plane structures that were created in |
| 158 | // the instance that was removed from the state. |
| 159 | // |
| 160 | // Use: public |
| 161 | |
| 162 | void |
| 163 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::popcxx . . $ SoClipPlaneElement#pop(90c797341866ebf4).(SoStatecxx . . $ SoState# *, const SoElementcxx . . $ SoElement# *prevTopElement) |
| 164 | // |
| 165 | //////////////////////////////////////////////////////////////////////// |
| 166 | { |
| 167 | const SoClipPlaneElementcxx . . $ SoClipPlaneElement# *prevElt = |
| 168 | (const SoClipPlaneElementcxx . . $ SoClipPlaneElement# *) prevTopElement; |
| 169 | |
| 170 | // Free up any plane structures that were created by prevElt |
| 171 | for (int i = prevElt->startIndexcxx . . $ SoClipPlaneElement#startIndex.; i < prevElt->planescxx . . $ SoClipPlaneElement#planes..getLengthcxx . . $ SbPList#getLength(455f465bc33b4cdf).(); i++) |
| 172 | delete (So_ClipPlanecxx . . $ So_ClipPlane# *) prevElt->planescxx . . $ SoClipPlaneElement#planes.[cxx . . $ SbPList#`operator[]`(5f9a4f363ac2f591).i]; |
| 173 | } |
| 174 | |
| 175 | //////////////////////////////////////////////////////////////////////// |
| 176 | // |
| 177 | // Description: |
| 178 | // Returns the first (top) instance of the element in the state. |
| 179 | // |
| 180 | // Use: public, static |
| 181 | |
| 182 | const SoClipPlaneElementcxx . . $ SoClipPlaneElement# * |
| 183 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::getInstancecxx . . $ SoClipPlaneElement#getInstance(6de2e9004b1abde).(SoStatecxx . . $ SoState# *state) |
| 184 | // |
| 185 | //////////////////////////////////////////////////////////////////////// |
| 186 | { |
| 187 | return (const SoClipPlaneElementcxx . . $ SoClipPlaneElement# *) |
| 188 | getConstElementcxx . . $ SoElement#getConstElement(b376fdfac8d61874).(state, classStackIndexcxx . . $ SoClipPlaneElement#classStackIndex.); |
| 189 | } |
| 190 | |
| 191 | //////////////////////////////////////////////////////////////////////// |
| 192 | // |
| 193 | // Description: |
| 194 | // Returns the number of planes in the element |
| 195 | // |
| 196 | // Use: public |
| 197 | |
| 198 | int |
| 199 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::getNumcxx . . $ SoClipPlaneElement#getNum(455f465bc33b4cdf).() const |
| 200 | // |
| 201 | //////////////////////////////////////////////////////////////////////// |
| 202 | { |
| 203 | return planescxx . . $ SoClipPlaneElement#planes..getLengthcxx . . $ SbPList#getLength(455f465bc33b4cdf).(); |
| 204 | } |
| 205 | |
| 206 | //////////////////////////////////////////////////////////////////////// |
| 207 | // |
| 208 | // Description: |
| 209 | // Returns the nth plane stored in an instance in object or world |
| 210 | // space. |
| 211 | // |
| 212 | // Use: public |
| 213 | |
| 214 | const SbPlanecxx . . $ SbPlane# & |
| 215 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::getcxx . . $ SoClipPlaneElement#get(3fa63512a8f66182).(int index, SbBoolcxx . . $ SbBool# inWorldSpace) const |
| 216 | // |
| 217 | //////////////////////////////////////////////////////////////////////// |
| 218 | { |
| 219 | #ifdef DEBUG |
| 220 | if (index < 0 || index >= planes.getLength()) |
| 221 | SoDebugError::post("SoClipPlaneElement::get", |
| 222 | "Index (%d) is out of range 0 - %d", |
| 223 | index, planes.getLength() - 1); |
| 224 | #endif /* DEBUG */ |
| 225 | |
| 226 | So_ClipPlanecxx . . $ So_ClipPlane# *plane = (So_ClipPlanecxx . . $ So_ClipPlane# *) planescxx . . $ SoClipPlaneElement#planes.[cxx . . $ SbPList#`operator[]`(5f9a4f363ac2f591).index]; |
| 227 | |
| 228 | if (! inWorldSpace) |
| 229 | return plane->objPlanecxx . . $ So_ClipPlane#objPlane.; |
| 230 | |
| 231 | // Transform plane into world space if necessary |
| 232 | if (! plane->worldPlaneValidcxx . . $ So_ClipPlane#worldPlaneValid.) { |
| 233 | plane->worldPlanecxx . . $ So_ClipPlane#worldPlane. =cxx . . $ SbPlane#`operator=`(3252c25eedbd9e66). plane->objPlanecxx . . $ So_ClipPlane#objPlane.; |
| 234 | plane->worldPlanecxx . . $ So_ClipPlane#worldPlane..transformcxx . . $ SbPlane#transform(37d2f951b3ffd7a6).(plane->objToWorldcxx . . $ So_ClipPlane#objToWorld.); |
| 235 | } |
| 236 | return plane->worldPlanecxx . . $ So_ClipPlane#worldPlane.; |
| 237 | } |
| 238 | |
| 239 | //////////////////////////////////////////////////////////////////////// |
| 240 | // |
| 241 | // Description: |
| 242 | // Prints element for debugging. |
| 243 | // |
| 244 | // Use: public |
| 245 | // |
| 246 | //////////////////////////////////////////////////////////////////////// |
| 247 | |
| 248 | #ifdef DEBUG |
| 249 | void |
| 250 | SoClipPlaneElement::print(FILE *fp) const |
| 251 | { |
| 252 | SoAccumulatedElement::print(fp); |
| 253 | } |
| 254 | #else /* DEBUG */ |
| 255 | void |
| 256 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::printcxx . . $ SoClipPlaneElement#print(e682089247c2ee8c).(FILE *) const |
| 257 | { |
| 258 | } |
| 259 | #endif /* DEBUG */ |
| 260 | |
| 261 | //////////////////////////////////////////////////////////////////////// |
| 262 | // |
| 263 | // Description: |
| 264 | // Adds clipping plane to element. |
| 265 | // |
| 266 | // Use: protected, virtual |
| 267 | |
| 268 | void |
| 269 | SoClipPlaneElementcxx . . $ SoClipPlaneElement#::addToEltcxx . . $ SoClipPlaneElement#addToElt(b43e0644e367a739).(const SbPlanecxx . . $ SbPlane# &plane, |
| 270 | const SbMatrixcxx . . $ SbMatrix# &modelMatrix) |
| 271 | // |
| 272 | //////////////////////////////////////////////////////////////////////// |
| 273 | { |
| 274 | So_ClipPlanecxx . . $ So_ClipPlane# *newPlane = new So_ClipPlanecxx . . $ So_ClipPlane#; |
| 275 | |
| 276 | newPlane->objPlanecxx . . $ So_ClipPlane#objPlane. =cxx . . $ SbPlane#`operator=`(3252c25eedbd9e66). plane; |
| 277 | newPlane->objToWorldcxx . . $ So_ClipPlane#objToWorld. =cxx . . $ SbMatrix#`operator=`(5bda0b2cfca989a9). modelMatrix; |
| 278 | newPlane->worldPlaneValidcxx . . $ So_ClipPlane#worldPlaneValid. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 279 | |
| 280 | planescxx . . $ SoClipPlaneElement#planes..appendcxx . . $ SbPList#append(5d22bdacc48458e8).(newPlane); |
| 281 | } |