Debian Codegraph @

apps/tools/ivnorm/FindNormals.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 // Takes a scene graph and generates normals for it
39 //
40
41 #include <assert.h>
42 #include <cmath>
43
44 #include <Inventor/SoDB.h>cxx . . $ `<file>/lib/database/include/Inventor/SoDB.h`/
45 #include <Inventor/nodes/SoGroup.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoGroup.h`/
46 #include <Inventor/nodes/SoIndexedFaceSet.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoIndexedFaceSet.h`/
47 #include <Inventor/nodes/SoNormal.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoNormal.h`/
48 #include <Inventor/nodes/SoNormalBinding.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoNormalBinding.h`/
49 #include <Inventor/nodes/SoCoordinate3.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoCoordinate3.h`/
50 #include <Inventor/nodes/SoShapeHints.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoShapeHints.h`/
51 #include <Inventor/actions/SoSearchAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoSearchAction.h`/
52
53 #include "FindNormals.h"cxx . . $ `<file>/apps/tools/ivnorm/FindNormals.h`/
54 #include "Edges.h"cxx . . $ `<file>/apps/tools/ivnorm/Edges.h`/
55
56 FindNormalscxx . . $ FindNormals#::FindNormalscxx . . $ FindNormals#FindNormals(49f6e7a06ebc5aa8).()
57 {
58 defaultOrientationcxx . . $ FindNormals#defaultOrientation. = Facecxx . . $ Face#::UNKNOWNcxx . . $ Face#UNKNOWN.;
59 creaseAnglecxx . . $ FindNormals#creaseAngle. = M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`!/6;
60 verbosecxx . . $ FindNormals#verbose. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
61 }
62
63 FindNormalscxx . . $ FindNormals#::~cxx . . $ FindNormals#`~FindNormals`(49f6e7a06ebc5aa8).FindNormalscxx . . $ FindNormals#()
64 {
65 }
66
67 void
68 FindNormalscxx . . $ FindNormals#::AssumeOrientationcxx . . $ FindNormals#AssumeOrientation(5d3e26acd51309dc).(FaceOrientationcxx . . $ FaceOrientation# o)
69 {
70 defaultOrientationcxx . . $ FindNormals#defaultOrientation. = o;
71 }
72
73 void
74 FindNormalscxx . . $ FindNormals#::applycxx . . $ FindNormals#apply(de18c6a3dadfdca6).(SoNodecxx . . $ SoNode# *root, int doVertexNormals)
75 {
76 //
77 // IndexedFaceSets:
78 // First, search for them:
79 //
80 if (verbosecxx . . $ FindNormals#verbose.)
81 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "FindNormals: searching for IndexedFaceSets.\n");
82 SoSearchActioncxx . . $ SoSearchAction# sacxx . . $ SoSearchAction#SoSearchAction(49f6e7a06ebc5aa8).;
83 sa.setTypecxx . . $ SoSearchAction#setType(a368ce5ca5a50910).(SoIndexedFaceSetcxx . . $ SoIndexedFaceSet#::getClassTypeIdcxx . . $ SoIndexedFaceSet#getClassTypeId(c00c150378d2b968).());
84 sa.setInterestcxx . . $ SoSearchAction#setInterest(b27440939ca13a5b).(SoSearchActioncxx . . $ SoSearchAction#::ALLcxx . . $ SoSearchAction#ALL.);
85 sa.applycxx . . $ SoAction#apply(da6c7544ccee32bd).(root);
86 SoPathListcxx . . $ SoPathList# &paths = sa.getPathscxx . . $ SoSearchAction#getPaths(e5198181f61c9f38).();
87 if (verbosecxx . . $ FindNormals#verbose.) fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "FindNormals: searching finished.\n");
88 for (int i=0; i < paths.getLengthcxx . . $ SbPList#getLength(455f465bc33b4cdf).(); i++) {
89 if (verbosecxx . . $ FindNormals#verbose. && !(i%50))
90 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "FindNormals: faceSet %d of %d\n",
91 i+1, paths.getLengthcxx . . $ SbPList#getLength(455f465bc33b4cdf).());
92
93 SoGroupcxx . . $ SoGroup# *parent = (SoGroupcxx . . $ SoGroup#*)paths[cxx . . $ SoPathList#`operator[]`(81b2b9099fcfac9c).i]->getNodeFromTailcxx . . $ SoPath#getNodeFromTail(fd675789997d09c2).(1);
94
95 // disable notification, or we'll have n^2 time spent notifying
96 // the entire path list for every change.
97 #ifndef INVENTOR1
98 SbBoolcxx . . $ SbBool# pNot = parent->enableNotifycxx . . $ SoFieldContainer#enableNotify(7864480464b09eea).(FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!);
99 #else
100 parent->setNotification(FALSE);
101 #endif
102
103 doIndexedFaceSetcxx . . $ FindNormals#doIndexedFaceSet(5ced60b0973735da).(paths[cxx . . $ SoPathList#`operator[]`(81b2b9099fcfac9c).i], doVertexNormals);
104
105 // restore notification
106 #ifndef INVENTOR1
107 parent->enableNotifycxx . . $ SoFieldContainer#enableNotify(7864480464b09eea).(pNot);
108 #else
109 parent->setNotification(TRUE);
110 #endif
111 }
112 }
113
114 SoNodecxx . . $ SoNode# *
115 FindNormalscxx . . $ FindNormals#::searchLastTypecxx . . $ FindNormals#searchLastType(2b54b4d2bafc6aa5).(SoPathcxx . . $ SoPath# *p, SoTypecxx . . $ SoType# t)
116 {
117 SoSearchActioncxx . . $ SoSearchAction# sacxx . . $ SoSearchAction#SoSearchAction(49f6e7a06ebc5aa8).;
118 sa.setTypecxx . . $ SoSearchAction#setType(a368ce5ca5a50910).(t);
119 sa.setInterestcxx . . $ SoSearchAction#setInterest(b27440939ca13a5b).(SoSearchActioncxx . . $ SoSearchAction#::LASTcxx . . $ SoSearchAction#LAST.);
120 sa.applycxx . . $ SoAction#apply(eed4dbbaf0eca0f1).(p);
121 SoPathcxx . . $ SoPath# *foundPath = sa.getPathcxx . . $ SoSearchAction#getPath(58db5280b30558ed).();
122
123 if (foundPath != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
124 return foundPath->getTailcxx . . $ SoPath#getTail(b794963b450d51b3).();
125
126 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
127 }
128
129 void
130 FindNormalscxx . . $ FindNormals#::doIndexedFaceSetcxx . . $ FindNormals#doIndexedFaceSet(5ced60b0973735da).(SoPathcxx . . $ SoPath# *p, int doVertexNormals)
131 {
132 // If there is already a normal node, bail
133
134 if (searchLastTypecxx . . $ FindNormals#searchLastType(2b54b4d2bafc6aa5).(p, SoNormalcxx . . $ SoNormal#::getClassTypeIdcxx . . $ SoNormal#getClassTypeId(c00c150378d2b968).()) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
135 return;
136
137 //
138 // First, find Coordinates in path:
139 //
140 SoCoordinate3cxx . . $ SoCoordinate3# *coords = (SoCoordinate3cxx . . $ SoCoordinate3# *)
141 searchLastTypecxx . . $ FindNormals#searchLastType(2b54b4d2bafc6aa5).(p, SoCoordinate3cxx . . $ SoCoordinate3#::getClassTypeIdcxx . . $ SoCoordinate3#getClassTypeId(c00c150378d2b968).());
142
143 SoIndexedFaceSetcxx . . $ SoIndexedFaceSet# *ifs = (SoIndexedFaceSetcxx . . $ SoIndexedFaceSet# *)p->getTailcxx . . $ SoPath#getTail(b794963b450d51b3).();
144
145 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(coords != NULL);
146
147 FaceListcxx . . $ FaceList# facescxx . . $ FaceList#FaceList(dd88af99dd740d16).(coords->pointcxx . . $ SoCoordinate3#point..getValuescxx . . $ SoMFVec3f#getValues(aa6f7bb3bba6ed95).(0), ifs);
148
149 if (defaultOrientationcxx . . $ FindNormals#defaultOrientation. == Facecxx . . $ Face#::UNKNOWNcxx . . $ Face#UNKNOWN.)
150 {
151 faces.findOrientationcxx . . $ FaceList#findOrientation(49f6e7a06ebc5aa8).();
152 }
153 else
154 {
155 for (int i = 0; i < faces.getLengthcxx . . $ SbPList#getLength(455f465bc33b4cdf).(); i++)
156 {
157 faces[cxx . . $ FaceList#`operator[]`(45a0b426fc8d6873).i]->orientationcxx . . $ Face#orientation. = defaultOrientationcxx . . $ FindNormals#defaultOrientation.;
158 }
159 faces.correctOrientationcxx . . $ FaceList#correctOrientation(49f6e7a06ebc5aa8).();
160 }
161
162 SoNormalcxx . . $ SoNormal# *n = new SoNormalcxx . . $ SoNormal#;
163 SoNormalBindingcxx . . $ SoNormalBinding# *normb = new SoNormalBindingcxx . . $ SoNormalBinding#;
164
165 SoNodecxx . . $ SoNode# *tn = p->getNodecxx . . $ SoPath#getNode(fd675789997d09c2).(p->getLengthcxx . . $ SoPath#getLength(455f465bc33b4cdf).()-2);
166 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(tn->isOfType(SoGroup::getClassTypeId()));
167
168 SoGroupcxx . . $ SoGroup# *g = (SoGroupcxx . . $ SoGroup# *)tn;
169
170 int index = g->findChildcxx . . $ SoGroup#findChild(25d228eba4c5059a).(ifs);
171
172 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(index != -1);
173
174 g->insertChildcxx . . $ SoGroup#insertChild(de18c6a3dadfdca6).(normb, index);
175 g->insertChildcxx . . $ SoGroup#insertChild(de18c6a3dadfdca6).(n, index);
176
177 faces.findShapeInfocxx . . $ FaceList#findShapeInfo(49f6e7a06ebc5aa8).();
178 if (faces.isSolidcxx . . $ FaceList#isSolid(b126dc7c1de90089).()) {
179 SoShapeHintscxx . . $ SoShapeHints# *hints = new SoShapeHintscxx . . $ SoShapeHints#;
180 hints->vertexOrderingcxx . . $ SoShapeHints#vertexOrdering. =cxx . . $ SoSFEnum#`operator=`(7864480464b09eea). SoShapeHintscxx . . $ SoShapeHints#::COUNTERCLOCKWISEcxx . . $ SoShapeHints#COUNTERCLOCKWISE.;
181 hints->shapeTypecxx . . $ SoShapeHints#shapeType. =cxx . . $ SoSFEnum#`operator=`(7864480464b09eea). SoShapeHintscxx . . $ SoShapeHints#::SOLIDcxx . . $ SoShapeHints#SOLID.;
182 g->insertChildcxx . . $ SoGroup#insertChild(de18c6a3dadfdca6).(hints, index);
183 }
184
185 if (doVertexNormals)
186 {
187 faces.findVertexNormalscxx . . $ FaceList#findVertexNormals(9910a12f5746ab52).(n, ifs, creaseAnglecxx . . $ FindNormals#creaseAngle.);
188 normb->valuecxx . . $ SoNormalBinding#value..setValuecxx . . $ SoSFEnum#setValue(d4f767463ce0a6b3).(SoNormalBindingcxx . . $ SoNormalBinding#::PER_VERTEX_INDEXEDcxx . . $ SoNormalBinding#PER_VERTEX_INDEXED.);
189 }
190 else
191 {
192 faces.findFacetNormalscxx . . $ FaceList#findFacetNormals(c3eb233a7f77e81d).(n);
193 normb->valuecxx . . $ SoNormalBinding#value..setValuecxx . . $ SoSFEnum#setValue(d4f767463ce0a6b3).(SoNormalBindingcxx . . $ SoNormalBinding#::PER_FACEcxx . . $ SoNormalBinding#PER_FACE.);
194 }
195 }