Debian Codegraph @

lib/database/src/so/engines/SoComputeBoundingBox.c++

raw
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: 1.1.1.1 $
44 |
45 | Classes:
46 | SoComputeBoundingBox
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/actions/SoGetBoundingBoxAction.h>
55 #include <Inventor/engines/SoComputeBoundingBox.h>
56
57 SO_ENGINE_SOURCE(SoComputeBoundingBox);
58
59 ////////////////////////////////////////////////////////////////////////
60 //
61 // Description:
62 // Constructor
63 //
64 // Use: public
65
66 SoComputeBoundingBox::SoComputeBoundingBox()
67 //
68 ////////////////////////////////////////////////////////////////////////
69 {
70 SO_ENGINE_CONSTRUCTOR(SoComputeBoundingBox);
71
72 SO_ENGINE_ADD_INPUT(node, (NULL));
73 SO_ENGINE_ADD_INPUT(path, (NULL));
74
75 SO_ENGINE_ADD_OUTPUT(min, SoSFVec3f);
76 SO_ENGINE_ADD_OUTPUT(max, SoSFVec3f);
77 SO_ENGINE_ADD_OUTPUT(boxCenter, SoSFVec3f);
78 SO_ENGINE_ADD_OUTPUT(objectCenter, SoSFVec3f);
79
80 isBuiltIn = TRUE;
81
82 // Create the action only when necessary
83 bba = NULL;
84
85 // Assume default NULL values
86 gotNode = gotPath = FALSE;
87
88 // Disable all of our outputs
89 min.enable(FALSE);
90 max.enable(FALSE);
91 boxCenter.enable(FALSE);
92 objectCenter.enable(FALSE);
93 }
94
95 ////////////////////////////////////////////////////////////////////////
96 //
97 // Description:
98 // Destructor
99 //
100 // Use: private
101
102 SoComputeBoundingBox::~SoComputeBoundingBox()
103 //
104 ////////////////////////////////////////////////////////////////////////
105 {
106 if (bba != NULL)
107 delete bba;
108 }
109
110 ////////////////////////////////////////////////////////////////////////
111 //
112 // Description:
113 // Sets viewport region to use for bounding box computation.
114 //
115 // Use: public
116
117 void
118 SoComputeBoundingBox::setViewportRegion(const SbViewportRegion &vpReg)
119 //
120 ////////////////////////////////////////////////////////////////////////
121 {
122 // Set the viewport region in the SoGetBoundingBoxAction. If we
123 // don't have an action instance yet, create one.
124 if (bba == NULL)
125 bba = new SoGetBoundingBoxAction(vpReg);
126 else
127 bba->setViewportRegion(vpReg);
128 }
129
130 ////////////////////////////////////////////////////////////////////////
131 //
132 // Description:
133 // Returns viewport region used for bounding box computation.
134 //
135 // Use: public
136
137 const SbViewportRegion &
138 SoComputeBoundingBox::getViewportRegion() const
139 //
140 ////////////////////////////////////////////////////////////////////////
141 {
142 // Get the viewport region from the SoGetBoundingBoxAction. If we
143 // don't have an action instance yet, create one. Cast away const
144 // to do this.
145 if (bba == NULL) {
146 SoComputeBoundingBox *cbb = (SoComputeBoundingBox *) this;
147 cbb->bba = new SoGetBoundingBoxAction(SbViewportRegion());
148 }
149
150 return bba->getViewportRegion();
151 }
152
153 ////////////////////////////////////////////////////////////////////////
154 //
155 // Description:
156 // Detects when the inputs changed. Outputs are enabled if either
157 // of the inputs is non-NULL.
158 //
159 // Use: protected
160
161 void
162 SoComputeBoundingBox::inputChanged(SoField *whichInput)
163 //
164 ////////////////////////////////////////////////////////////////////////
165 {
166 // See if the changed pointer is NULL
167 if (whichInput == &node)
168 gotNode = (node.getValue() != NULL);
169 else
170 gotPath = (path.getValue() != NULL);
171
172 // If either input is now non-NULL, enable the outputs
173 SbBool enable = (gotNode || gotPath);
174 min.enable(enable);
175 max.enable(enable);
176 boxCenter.enable(enable);
177 objectCenter.enable(enable);
178 }
179
180 ////////////////////////////////////////////////////////////////////////
181 //
182 // Description:
183 // Evaluation routine
184 //
185 // Use: private
186
187 void
188 SoComputeBoundingBox::evaluate()
189 //
190 ////////////////////////////////////////////////////////////////////////
191 {
192 // Create an action instance if necessary
193 if (bba == NULL)
194 bba = new SoGetBoundingBoxAction(SbViewportRegion());
195
196 // This should be called only when the outputs are enabled, so we
197 // know that we have a non-NULL node or path
198 if (gotPath)
199 bba->apply(path.getValue());
200 else
201 bba->apply(node.getValue());
202
203 SbBox3f box = bba->getBoundingBox();
204 SbVec3f boxCent = box.getCenter();
205 SbVec3f objCent = bba->getCenter();
206
207 SO_ENGINE_OUTPUT(min, SoSFVec3f, setValue(box.getMin()));
208 SO_ENGINE_OUTPUT(max, SoSFVec3f, setValue(box.getMax()));
209 SO_ENGINE_OUTPUT(boxCenter, SoSFVec3f, setValue(boxCent));
210 SO_ENGINE_OUTPUT(objectCenter, SoSFVec3f, setValue(objCent));
211 }