| 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 | #include <Inventor/SbDict.h>cxx . . $ `<file>/lib/database/include/Inventor/SbDict.h`/ |
| 38 | #include <Inventor/SbPList.h>cxx . . $ `<file>/lib/database/include/Inventor/SbPList.h`/ |
| 39 | #include <Inventor/fields/SoMFVec2f.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoMFVec2f.h`/ |
| 40 | #include <Inventor/fields/SoMFVec3f.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoMFVec3f.h`/ |
| 41 | |
| 42 | #include "IfAssert.h"cxx . . $ `<file>/apps/tools/ivfix/IfAssert.h`/ |
| 43 | #include "IfHasher.h"cxx . . $ `<file>/apps/tools/ivfix/IfHasher.h`/ |
| 44 | |
| 45 | ///////////////////////////////////////////////////////////////////////////// |
| 46 | // |
| 47 | // Constructors for 2- or 3-dimensional vectors. |
| 48 | // |
| 49 | ///////////////////////////////////////////////////////////////////////////// |
| 50 | |
| 51 | IfHashercxx . . $ IfHasher#::IfHashercxx . . $ IfHasher#IfHasher(a117f951706c2a58).(SoMFVec2fcxx . . $ SoMFVec2f# *field, int maxNumVectors, |
| 52 | const SbVec2fcxx . . $ SbVec2f# &min, const SbVec2fcxx . . $ SbVec2f# &scale) |
| 53 | { |
| 54 | dimensioncxx . . $ IfHasher#dimension. = 2; |
| 55 | |
| 56 | field2cxx . . $ IfHasher#field2. = field; |
| 57 | field3cxx . . $ IfHasher#field3. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 58 | |
| 59 | hashMincxx . . $ IfHasher#hashMin.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] = min[cxx . . $ SbVec2f#`operator[]`(c60a38c584b9a5cc).0]; |
| 60 | hashMincxx . . $ IfHasher#hashMin.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).1] = min[cxx . . $ SbVec2f#`operator[]`(c60a38c584b9a5cc).1]; |
| 61 | hashMincxx . . $ IfHasher#hashMin.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] = 0.0; |
| 62 | |
| 63 | hashScalecxx . . $ IfHasher#hashScale.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] = scale[cxx . . $ SbVec2f#`operator[]`(c60a38c584b9a5cc).0]; |
| 64 | hashScalecxx . . $ IfHasher#hashScale.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).1] = scale[cxx . . $ SbVec2f#`operator[]`(c60a38c584b9a5cc).1]; |
| 65 | hashScalecxx . . $ IfHasher#hashScale.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] = 1.0; |
| 66 | |
| 67 | maxNumcxx . . $ IfHasher#maxNum. = maxNumVectors; |
| 68 | |
| 69 | commonConstructorcxx . . $ IfHasher#commonConstructor(49f6e7a06ebc5aa8).(); |
| 70 | } |
| 71 | |
| 72 | IfHashercxx . . $ IfHasher#::IfHashercxx . . $ IfHasher#IfHasher(34480c6fbf58449e).(SoMFVec3fcxx . . $ SoMFVec3f# *field, int maxNumVectors, |
| 73 | const SbVec3fcxx . . $ SbVec3f# &min, const SbVec3fcxx . . $ SbVec3f# &scale) |
| 74 | { |
| 75 | dimensioncxx . . $ IfHasher#dimension. = 3; |
| 76 | |
| 77 | field2cxx . . $ IfHasher#field2. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 78 | field3cxx . . $ IfHasher#field3. = field; |
| 79 | |
| 80 | hashMincxx . . $ IfHasher#hashMin. =cxx . . $ SbVec3f#`operator=`(c7808628d070cfbe). min; |
| 81 | hashScalecxx . . $ IfHasher#hashScale. =cxx . . $ SbVec3f#`operator=`(c7808628d070cfbe). scale; |
| 82 | |
| 83 | maxNumcxx . . $ IfHasher#maxNum. = maxNumVectors; |
| 84 | |
| 85 | commonConstructorcxx . . $ IfHasher#commonConstructor(49f6e7a06ebc5aa8).(); |
| 86 | } |
| 87 | |
| 88 | ///////////////////////////////////////////////////////////////////////////// |
| 89 | // |
| 90 | // Stuff common to both constructors. |
| 91 | // |
| 92 | ///////////////////////////////////////////////////////////////////////////// |
| 93 | |
| 94 | void |
| 95 | IfHashercxx . . $ IfHasher#::commonConstructorcxx . . $ IfHasher#commonConstructor(49f6e7a06ebc5aa8).() |
| 96 | { |
| 97 | // Create an array of HashEntry instances |
| 98 | entriescxx . . $ IfHasher#entries. = new HashEntrycxx . . $ IfHasher#HashEntry#[maxNumcxx . . $ IfHasher#maxNum.]; |
| 99 | curEntrycxx . . $ IfHasher#curEntry. = 0; |
| 100 | |
| 101 | // Make room in the field and begin editing |
| 102 | if (dimensioncxx . . $ IfHasher#dimension. == 2) { |
| 103 | field2cxx . . $ IfHasher#field2.->setNumcxx . . $ SoMField#setNum(d4f767463ce0a6b3).(maxNumcxx . . $ IfHasher#maxNum.); |
| 104 | vectors2cxx . . $ IfHasher#vectors2. = field2cxx . . $ IfHasher#field2.->startEditingcxx . . $ SoMFVec2f#startEditing(8881486cd4924579).(); |
| 105 | vectors3cxx . . $ IfHasher#vectors3. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 106 | } |
| 107 | else { |
| 108 | field3cxx . . $ IfHasher#field3.->setNumcxx . . $ SoMField#setNum(d4f767463ce0a6b3).(maxNumcxx . . $ IfHasher#maxNum.); |
| 109 | vectors3cxx . . $ IfHasher#vectors3. = field3cxx . . $ IfHasher#field3.->startEditingcxx . . $ SoMFVec3f#startEditing(d7218d170b8c46e1).(); |
| 110 | vectors2cxx . . $ IfHasher#vectors2. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 111 | } |
| 112 | |
| 113 | // Set up the dictionary |
| 114 | vectorDictcxx . . $ IfHasher#vectorDict. = new SbDictcxx . . $ SbDict#SbDict(d4f767463ce0a6b3).(1235); |
| 115 | |
| 116 | // Multiply the scale values by some arbitrary numbers to make |
| 117 | // the hash function more random |
| 118 | hashScalecxx . . $ IfHasher#hashScale.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] *= 233; |
| 119 | hashScalecxx . . $ IfHasher#hashScale.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).1] *= 72091; |
| 120 | hashScalecxx . . $ IfHasher#hashScale.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] *= 453451; |
| 121 | } |
| 122 | |
| 123 | ///////////////////////////////////////////////////////////////////////////// |
| 124 | // |
| 125 | // Destructor. |
| 126 | // |
| 127 | ///////////////////////////////////////////////////////////////////////////// |
| 128 | |
| 129 | IfHashercxx . . $ IfHasher#::~cxx . . $ IfHasher#`~IfHasher`(49f6e7a06ebc5aa8).IfHashercxx . . $ IfHasher#() |
| 130 | { |
| 131 | } |
| 132 | |
| 133 | ///////////////////////////////////////////////////////////////////////////// |
| 134 | // |
| 135 | // These add a vector to the list, returning its index. Room is |
| 136 | // made in the field, if necessary. |
| 137 | // |
| 138 | ///////////////////////////////////////////////////////////////////////////// |
| 139 | |
| 140 | int |
| 141 | IfHashercxx . . $ IfHasher#::addVectorcxx . . $ IfHasher#addVector(99c9770a51b3f843).(const SbVec2fcxx . . $ SbVec2f# &newVector) |
| 142 | { |
| 143 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(vectorDict != NULL); |
| 144 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(dimension == 2); |
| 145 | |
| 146 | // See if we need to add this one, or is it already there |
| 147 | int index; |
| 148 | SbBoolcxx . . $ SbBool# notThere = addIfNotTherecxx . . $ IfHasher#addIfNotThere(514777f33b1340d6).(newVector.getValuecxx . . $ SbVec2f#getValue(d64004c6a662f6a6).(), index); |
| 149 | |
| 150 | // If it's not there, we need to add it to the field |
| 151 | if (notThere) |
| 152 | vectors2cxx . . $ IfHasher#vectors2.[index] =cxx . . $ SbVec2f#`operator=`(55af37c201462dc0). newVector; |
| 153 | |
| 154 | return index; |
| 155 | } |
| 156 | |
| 157 | int |
| 158 | IfHashercxx . . $ IfHasher#::addVectorcxx . . $ IfHasher#addVector(19324dd683622d1f).(const SbVec3fcxx . . $ SbVec3f# &newVector) |
| 159 | { |
| 160 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(vectorDict != NULL); |
| 161 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(dimension == 3); |
| 162 | |
| 163 | // See if we need to add this one, or is it already there |
| 164 | int index; |
| 165 | SbBoolcxx . . $ SbBool# notThere = addIfNotTherecxx . . $ IfHasher#addIfNotThere(514777f33b1340d6).(newVector.getValuecxx . . $ SbVec3f#getValue(d64004c6a662f6a6).(), index); |
| 166 | |
| 167 | // If it's not there, we need to add it to the field |
| 168 | if (notThere) |
| 169 | vectors3cxx . . $ IfHasher#vectors3.[index] =cxx . . $ SbVec3f#`operator=`(c7808628d070cfbe). newVector; |
| 170 | |
| 171 | return index; |
| 172 | } |
| 173 | |
| 174 | ///////////////////////////////////////////////////////////////////////////// |
| 175 | // |
| 176 | // Adds the given vector to the hash table, if it is not already |
| 177 | // there. Returns TRUE if the vector was added. |
| 178 | // |
| 179 | ///////////////////////////////////////////////////////////////////////////// |
| 180 | |
| 181 | SbBoolcxx . . $ SbBool# |
| 182 | IfHashercxx . . $ IfHasher#::addIfNotTherecxx . . $ IfHasher#addIfNotThere(514777f33b1340d6).(const float *newVector, int &index) |
| 183 | { |
| 184 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(curEntry < maxNum - 1); |
| 185 | |
| 186 | // Find the hash key |
| 187 | uint32_tcxx . . $ uint32_t# key = hashVectorcxx . . $ IfHasher#hashVector(15bc1c131e1ff402).(newVector); |
| 188 | |
| 189 | // See if there already is a list of vectors with the same key |
| 190 | void *list; |
| 191 | if (vectorDictcxx . . $ IfHasher#vectorDict.->findcxx . . $ SbDict#find(a750591cf51bff5e).(key, list)) { |
| 192 | |
| 193 | // If so, look through the list for an exact match |
| 194 | HashEntrycxx . . $ IfHasher#HashEntry# *entry, *prevEntry = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 195 | for (entry = (HashEntrycxx . . $ IfHasher#HashEntry# *) list; entry != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; entry = entry->nextcxx . . $ IfHasher#HashEntry#next.) { |
| 196 | |
| 197 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(entry->index < curEntry); |
| 198 | |
| 199 | // If the vectors are the same, re-use the old one and stop |
| 200 | if (sameVectorcxx . . $ IfHasher#sameVector(58d4fdd276b11965).(newVector, entry->indexcxx . . $ IfHasher#HashEntry#index.)) { |
| 201 | index = entry->indexcxx . . $ IfHasher#HashEntry#index.; |
| 202 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 203 | } |
| 204 | |
| 205 | prevEntry = entry; |
| 206 | } |
| 207 | |
| 208 | // If there were no matches, add the new vector to the end of |
| 209 | // the list |
| 210 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(prevEntry != NULL); |
| 211 | entry = &entriescxx . . $ IfHasher#entries.[curEntrycxx . . $ IfHasher#curEntry.]; |
| 212 | entry->indexcxx . . $ IfHasher#HashEntry#index. = curEntrycxx . . $ IfHasher#curEntry.; |
| 213 | entry->nextcxx . . $ IfHasher#HashEntry#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 214 | prevEntry->nextcxx . . $ IfHasher#HashEntry#next. = entry; |
| 215 | } |
| 216 | |
| 217 | // If there were no entries in the dictionary, start one |
| 218 | else { |
| 219 | HashEntrycxx . . $ IfHasher#HashEntry# *entry = &entriescxx . . $ IfHasher#entries.[curEntrycxx . . $ IfHasher#curEntry.]; |
| 220 | entry->indexcxx . . $ IfHasher#HashEntry#index. = curEntrycxx . . $ IfHasher#curEntry.; |
| 221 | entry->nextcxx . . $ IfHasher#HashEntry#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 222 | vectorDictcxx . . $ IfHasher#vectorDict.->entercxx . . $ SbDict#enter(9b3d2d56e494888).(key, entry); |
| 223 | } |
| 224 | |
| 225 | index = curEntrycxx . . $ IfHasher#curEntry.++; |
| 226 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 227 | } |
| 228 | |
| 229 | ///////////////////////////////////////////////////////////////////////////// |
| 230 | // |
| 231 | // Hash function for finding duplicate vectors. |
| 232 | // |
| 233 | ///////////////////////////////////////////////////////////////////////////// |
| 234 | |
| 235 | uint32_tcxx . . $ uint32_t# |
| 236 | IfHashercxx . . $ IfHasher#::hashVectorcxx . . $ IfHasher#hashVector(15bc1c131e1ff402).(const float *v) |
| 237 | { |
| 238 | float sum = 0.0; |
| 239 | for (int i = 0; i < dimensioncxx . . $ IfHasher#dimension.; i++) |
| 240 | sum += (v[i] - hashMincxx . . $ IfHasher#hashMin.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).i]) * hashScalecxx . . $ IfHasher#hashScale.[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).i]; |
| 241 | return (int32_tcxx . . $ int32_t#) sum; |
| 242 | } |
| 243 | |
| 244 | ///////////////////////////////////////////////////////////////////////////// |
| 245 | // |
| 246 | // Returns TRUE if the given vector matches the given existing vector. |
| 247 | // |
| 248 | ///////////////////////////////////////////////////////////////////////////// |
| 249 | |
| 250 | SbBoolcxx . . $ SbBool# |
| 251 | IfHashercxx . . $ IfHasher#::sameVectorcxx . . $ IfHasher#sameVector(58d4fdd276b11965).(const float *vector, int index) |
| 252 | { |
| 253 | if (dimensioncxx . . $ IfHasher#dimension. == 2) |
| 254 | return (vector[0] == vectors2cxx . . $ IfHasher#vectors2.[index][cxx . . $ SbVec2f#`operator[]`(5dbdaf238659ae67).0] && |
| 255 | vector[1] == vectors2cxx . . $ IfHasher#vectors2.[index][cxx . . $ SbVec2f#`operator[]`(5dbdaf238659ae67).1]); |
| 256 | else |
| 257 | return (vector[0] == vectors3cxx . . $ IfHasher#vectors3.[index][cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] && |
| 258 | vector[1] == vectors3cxx . . $ IfHasher#vectors3.[index][cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).1] && |
| 259 | vector[2] == vectors3cxx . . $ IfHasher#vectors3.[index][cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2]); |
| 260 | } |
| 261 | |
| 262 | ///////////////////////////////////////////////////////////////////////////// |
| 263 | // |
| 264 | // Finishes up. |
| 265 | // |
| 266 | ///////////////////////////////////////////////////////////////////////////// |
| 267 | |
| 268 | void |
| 269 | IfHashercxx . . $ IfHasher#::finishcxx . . $ IfHasher#finish(49f6e7a06ebc5aa8).() |
| 270 | { |
| 271 | // Stop editing and set the field to contain the correct number of |
| 272 | // values |
| 273 | if (dimensioncxx . . $ IfHasher#dimension. == 2) { |
| 274 | field2cxx . . $ IfHasher#field2.->finishEditingcxx . . $ SoMFVec2f#finishEditing(49f6e7a06ebc5aa8).(); |
| 275 | field2cxx . . $ IfHasher#field2.->setNumcxx . . $ SoMField#setNum(d4f767463ce0a6b3).(curEntrycxx . . $ IfHasher#curEntry.); |
| 276 | } |
| 277 | else { |
| 278 | field3cxx . . $ IfHasher#field3.->finishEditingcxx . . $ SoMFVec3f#finishEditing(49f6e7a06ebc5aa8).(); |
| 279 | field3cxx . . $ IfHasher#field3.->setNumcxx . . $ SoMField#setNum(d4f767463ce0a6b3).(curEntrycxx . . $ IfHasher#curEntry.); |
| 280 | } |
| 281 | |
| 282 | // Get rid of the dictionary and the HashEntry instances |
| 283 | delete vectorDictcxx . . $ IfHasher#vectorDict.; |
| 284 | delete [] entriescxx . . $ IfHasher#entries.; |
| 285 | |
| 286 | // Make sure nobody uses this again |
| 287 | vectorDictcxx . . $ IfHasher#vectorDict. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 288 | } |