00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <OSGVerifyGeoGraphOp.h>
00045
00046 OSG_USING_NAMESPACE
00047
00048
00049
00050
00051
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 VerifyGeoGraphOp::VerifyGeoGraphOp(const char* name, bool repair):
00071 SingleTypeGraphOpGeo(name), _repair(repair)
00072 {
00073 }
00074
00075 VerifyGeoGraphOp::~VerifyGeoGraphOp(void)
00076 {
00077 }
00078
00079 GraphOp *VerifyGeoGraphOp::create()
00080 {
00081 VerifyGeoGraphOp *inst = new VerifyGeoGraphOp();
00082 return inst;
00083 }
00084
00085 void VerifyGeoGraphOp::setParams(const std::string params)
00086 {
00087 ParamSet ps(params);
00088
00089 ps("repair", _repair);
00090
00091 std::string out = ps.getUnusedParams();
00092 if(out.length())
00093 {
00094 FWARNING(("VerifyGeoGraphOp doesn't have parameters '%s'.\n",
00095 out.c_str()));
00096 }
00097 }
00098
00099 std::string VerifyGeoGraphOp::usage(void)
00100 {
00101 return
00102 "Verify: Test validity of Geometries\n"
00103 " Run some validity tests on Geometries, makes sure indices are\n"
00104 " in the valid range etc.\n"
00105 "Params: name (type, default)\n"
00106 " repair (bool, true): try to repair consistency errors\n";
00107 }
00108
00109 void VerifyGeoGraphOp::setRepair(bool repair)
00110 {
00111 _repair = repair;
00112 }
00113
00114 bool VerifyGeoGraphOp::travNodeEnter(NodePtr node)
00115 {
00116 if (!node->getCore()->getType().isDerivedFrom(Geometry::getClassType()))
00117 {
00118 FWARNING(("VerifyGeoOp: travNodeEnter got a non-Geometry Node\n"));
00119 return false;
00120 }
00121
00122 bool _verified = true;
00123
00124 GeometryPtr geo=GeometryPtr::dcast(node->getCore());
00125
00126 if(geo->getTypes() != NullFC && geo->getTypes()->size() == 0)
00127 {
00128 if (_repair)
00129 {
00130
00131 }
00132 else
00133 {
00134
00135 }
00136 }
00137
00138 if(geo->getLengths() != NullFC && geo->getLengths()->size() == 0)
00139 {
00140 if (_repair)
00141 {
00142
00143 }
00144 else
00145 {
00146
00147 }
00148 }
00149
00150 if(geo->getPositions() != NullFC && geo->getPositions()->size() == 0)
00151 {
00152 if (_repair)
00153 geo->setPositions(NullFC);
00154 else
00155 {
00156 _verified = false;
00157 }
00158 }
00159
00160 if(geo->getNormals() != NullFC && geo->getNormals()->size() == 0)
00161 {
00162 if (_repair)
00163 geo->setNormals(NullFC);
00164 else
00165 {
00166 _verified = false;
00167 }
00168 }
00169
00170 if(geo->getColors() != NullFC && geo->getColors()->size() == 0)
00171 {
00172 if (_repair)
00173 geo->setColors(NullFC);
00174 else
00175 {
00176 _verified = false;
00177 }
00178 }
00179
00180 if(geo->getSecondaryColors() != NullFC && geo->getSecondaryColors()->size() == 0)
00181 {
00182 if (_repair)
00183 geo->setSecondaryColors(NullFC);
00184 else
00185 {
00186 _verified = false;
00187 }
00188 }
00189
00190 if(geo->getTexCoords() != NullFC && geo->getTexCoords()->size() == 0)
00191 {
00192 if (_repair)
00193 geo->setTexCoords(NullFC);
00194 else
00195 {
00196 _verified = false;
00197 }
00198 }
00199
00200 if(geo->getTexCoords1() != NullFC && geo->getTexCoords1()->size() == 0)
00201 {
00202 if (_repair)
00203 geo->setTexCoords1(NullFC);
00204 else
00205 {
00206 _verified = false;
00207 }
00208 }
00209
00210 if(geo->getTexCoords2() != NullFC && geo->getTexCoords2()->size() == 0)
00211 {
00212 if (_repair)
00213 geo->setTexCoords2(NullFC);
00214 else
00215 {
00216 _verified = false;
00217 }
00218 }
00219
00220 if(geo->getTexCoords3() != NullFC && geo->getTexCoords3()->size() == 0)
00221 {
00222 if (_repair)
00223 geo->setTexCoords3(NullFC);
00224 else
00225 {
00226 _verified = false;
00227 }
00228 }
00229
00230 bool consistent=true;
00231 int i, mind;
00232
00233 GeoIndicesPtr ind = geo->getIndices();
00234 UInt16 nmap = geo->getIndexMapping().size();
00235
00236 if (nmap==0) return Action::Continue;
00237
00238 UInt32* sizes = new UInt32[nmap];
00239 for (i=0; i<nmap; i++) sizes[i]=UInt32(-1);
00240
00241 if ( ( mind = geo->calcMappingIndex( Geometry::MapPosition ) ) >= 0 )
00242 {
00243 if (geo->getPositions()!=NullFC)
00244 sizes[ mind ] = osgMin ( sizes[ mind ], geo->getPositions()->size() );
00245 else
00246 {
00247 if (_repair)
00248 {
00249 UInt16 &im = geo->getIndexMapping(mind);
00250 im &=~( Geometry::MapPosition );
00251 }
00252 else
00253 {
00254 _verified = false;
00255 FDEBUG(("calcMappingIndex>=0, getPositions = NullFC\n"));
00256 }
00257 }
00258 }
00259
00260 if ( ( mind = geo->calcMappingIndex( Geometry::MapNormal ) ) >= 0 )
00261 {
00262 if (geo->getNormals()!=NullFC)
00263 sizes[ mind ] = osgMin ( sizes[ mind ], geo->getNormals()->size() );
00264 else
00265 {
00266 if (_repair)
00267 {
00268 UInt16 &im = geo->getIndexMapping(mind);
00269 im &=~( Geometry::MapNormal );
00270 }
00271 else
00272 {
00273 _verified = false;
00274 FDEBUG(("calcMappingIndex>=0, getNormals = NullFC\n"));
00275 }
00276 }
00277 }
00278
00279 if ( ( mind = geo->calcMappingIndex( Geometry::MapColor ) ) >= 0 )
00280 {
00281 if (geo->getColors()!=NullFC)
00282 sizes[ mind ] = osgMin ( sizes[ mind ], geo->getColors()->size() );
00283 else
00284 {
00285 if (_repair)
00286 {
00287 UInt16 &im = geo->getIndexMapping(mind);
00288 im &=~( Geometry::MapColor );
00289 }
00290 else
00291 {
00292 _verified = false;
00293 FDEBUG(("calcMappingIndex>=0, getColors = NullFC\n"));
00294 }
00295 }
00296 }
00297
00298 if ( ( mind = geo->calcMappingIndex( Geometry::MapSecondaryColor ) ) >= 0 )
00299 {
00300 if (geo->getSecondaryColors()!=NullFC)
00301 sizes[ mind ] = osgMin ( sizes[ mind ], geo->getSecondaryColors()->size() );
00302 else
00303 {
00304 if (_repair)
00305 {
00306 UInt16 &im = geo->getIndexMapping(mind);
00307 im &=~( Geometry::MapSecondaryColor );
00308 }
00309 else
00310 {
00311 _verified = false;
00312 FDEBUG(("calcMappingIndex>=0, getSecondaryColors = NullFC\n"));
00313 }
00314 }
00315 }
00316
00317 if ( ( mind = geo->calcMappingIndex( Geometry::MapTexCoords ) ) >= 0 )
00318 {
00319 if (geo->getTexCoords()!=NullFC)
00320 sizes[ mind ] = osgMin ( sizes[ mind ], geo->getTexCoords()->size() );
00321 else
00322 {
00323 if (_repair)
00324 {
00325 UInt16 &im = geo->getIndexMapping(mind);
00326 im &=~( Geometry::MapTexCoords );
00327 }
00328 else
00329 {
00330 _verified = false;
00331 FDEBUG(("calcMappingIndex>=0, getTexCoords = NullFC\n"));
00332 }
00333 }
00334 }
00335
00336 if ( ( mind = geo->calcMappingIndex( Geometry::MapTexCoords1 ) ) >= 0 )
00337 {
00338 if (geo->getTexCoords1()!=NullFC)
00339 sizes[ mind ] = osgMin ( sizes[ mind ], geo->getTexCoords1()->size() );
00340 else
00341 {
00342 if (_repair)
00343 {
00344 UInt16 &im = geo->getIndexMapping(mind);
00345 im &=~( Geometry::MapTexCoords1 );
00346 }
00347 else
00348 {
00349 _verified = false;
00350 FDEBUG(("calcMappingIndex>=0, getTexCoords1 = NullFC\n"));
00351 }
00352 }
00353
00354 }
00355
00356 if ( ( mind = geo->calcMappingIndex( Geometry::MapTexCoords2 ) ) >= 0 )
00357 {
00358 if (geo->getTexCoords2()!=NullFC)
00359 sizes[ mind ] = osgMin ( sizes[ mind ], geo->getTexCoords2()->size() );
00360 else
00361 {
00362 if (_repair)
00363 {
00364 UInt16 &im = geo->getIndexMapping(mind);
00365 im &=~( Geometry::MapTexCoords2 );
00366 }
00367 else
00368 {
00369 _verified = false;
00370 FDEBUG(("calcMappingIndex>=0, getTexCoords2 = NullFC\n"));
00371 }
00372 }
00373
00374 }
00375
00376 if ( ( mind = geo->calcMappingIndex( Geometry::MapTexCoords3 ) ) >= 0 )
00377 {
00378 if (geo->getTexCoords3()!=NullFC)
00379 sizes[ mind ] = osgMin ( sizes[ mind ], geo->getTexCoords3()->size() );
00380 else
00381 {
00382 if (_repair)
00383 {
00384 UInt16 &im = geo->getIndexMapping(mind);
00385 im &=~( Geometry::MapTexCoords3 );
00386 }
00387 else
00388 {
00389 _verified = false;
00390 FDEBUG(("calcMappingIndex>=0, getTexCoords3 = NullFC\n"));
00391 }
00392 }
00393 }
00394
00395 for (UInt32 j=0; j<ind->size(); j++)
00396 if (ind->getValue(j)>=sizes[j % nmap])
00397 {
00398 if (_repair)
00399 {
00400 ind->setValue(0,j);
00401 }
00402 else
00403 {
00404 consistent = false; break;
00405 }
00406 }
00407
00408 _verified = (_verified && (_repair | consistent) );
00409
00410 if (_verified)
00411 return Action::Continue;
00412 else
00413 return Action::Quit;
00414 }
00415
00416 bool VerifyGeoGraphOp::travNodeLeave(NodePtr)
00417 {
00418 return true;
00419 }
00420
00421
00422
00423