Debian Codegraph @

lib/database/src/so/nodes/SoNonIndexedShape.c++

raw symbols SCIP
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 | SoNonIndexedShape
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/elements/SoCoordinateElement.h>
56 #include <Inventor/nodes/SoNonIndexedShape.h>
57
58 SO_NODE_ABSTRACT_SOURCE(SoNonIndexedShape);
59
60 ////////////////////////////////////////////////////////////////////////
61 //
62 // Description:
63 // Constructor
64 //
65 // Use: protected
66
67 SoNonIndexedShape::SoNonIndexedShape()
68 //
69 ////////////////////////////////////////////////////////////////////////
70 {
71 SO_NODE_CONSTRUCTOR(SoNonIndexedShape);
72
73 SO_NODE_ADD_FIELD(startIndex, (0));
74 }
75
76 ////////////////////////////////////////////////////////////////////////
77 //
78 // Description:
79 // Destructor
80 //
81 // Use: private
82
83 SoNonIndexedShape::~SoNonIndexedShape()
84 //
85 ////////////////////////////////////////////////////////////////////////
86 {
87 }
88
89 ////////////////////////////////////////////////////////////////////////
90 //
91 // Description:
92 // This is a convenience method to simplify the job of computing
93 // bounding boxes for subclasses; it can be called from a
94 // subclass's computeBBox() method. It sets the given bounding box
95 // to contain all vertices of the shape, assuming that the shape
96 // uses the numVertices coordinates beginning at the value in
97 // startIndex. (If numVertices is negative, it uses all coordinates
98 // from startIndex on.) It also sets the center to the average of
99 // the vertices' coordinates.
100 //
101 // Use: protected
102
103 void
104 SoNonIndexedShape::computeCoordBBox(SoAction *action, int numVertices,
105 SbBox3f &box, SbVec3f &center)
106 //
107 ////////////////////////////////////////////////////////////////////////
108 {
109 int32_t i, lastIndex;
110 const SoCoordinateElement *ce = NULL;
111 const SbVec3f *vpCoords = NULL;
112
113 SoVertexProperty *vp = (SoVertexProperty *)vertexProperty.getValue();
114 if (vp && vp->vertex.getNum() > 0) {
115 vpCoords = vp->vertex.getValues(0);
116 } else {
117 ce = SoCoordinateElement::getInstance(action->getState());
118 }
119
120 // Start with an empty box and zero sum
121 center.setValue(0.0, 0.0, 0.0);
122 box.makeEmpty();
123
124 // Loop through coordinates, keeping max bounding box and sum of coords
125 i = startIndex.getValue();
126 if (numVertices < 0) {
127 lastIndex = (ce ? ce->getNum() - 1 : vp->vertex.getNum() - 1);
128 numVertices = (int) (lastIndex - i + 1);
129 }
130 else
131 lastIndex = i + numVertices - 1;
132
133 while (i <= lastIndex) {
134
135 const SbVec3f &v = (ce ? ce->get3((int) i) : vpCoords[i]);
136
137 box.extendBy(v);
138 center += v;
139
140 i++;
141 }
142
143 // The center point is the average of the vertices
144 center /= (float) numVertices;
145 }
146