Show
Ignore:
Timestamp:
04/24/14 12:49:57 (less than one hour ago)
Author:
robert
Message:

From Mattias Helsing, "Seems I was only half right given what you asked for. CMP0017 only
says that modules that are found and ran from cmake modules dir should
prefer cmake-provided modules. find_package() and include() still look
in CMAKE_MODULE_PATH first.

After some investigating I've come up with a proposal examplified in
the attached FindGDAL.cmake script. It simply calls the cmake provided
FindGDAL.cmake if it exists and returns if it succeeds in finding GDAL
using that, otherwise continue with our local cmake code.
Pro: Wont clutter our root CMakeLists.txt
Con: If we begin to write more advanced Findxxx modules (using
COMPONENTS, REQUIRED etc.) we may have to revise this scheme.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/Inventor/ConvertToInventor.cpp

    r13497 r13557  
    2525//  but you are not forced to do so. 
    2626// 
    27  
    28 #include <osg/Config> 
    29 #ifndef OSG_USE_DEPRECATED_GEOMETRY_METHODS  
    30 #define OSG_USE_DEPRECATED_GEOMETRY_METHODS 1 
    31 #endif 
    3227 
    3328#include <osg/BlendFunc> 
     
    471466 
    472467template<typename variableType, typename fieldType> 
    473 bool ivProcessArray(const osg::Array *indices, const osg::Array *drawElemIndices, 
     468bool ivProcessArray(const osg::Array *drawElemIndices, 
    474469                         fieldType *destField, const fieldType *srcField, 
    475470                         int startIndex, int numToProcess) 
     
    477472  bool ok = true; 
    478473 
    479   if (indices || drawElemIndices) { 
     474  if (drawElemIndices) { 
    480475 
    481476    // "deindex" original data 
    482     if (indices && !drawElemIndices) 
    483       ok = ivDeindex<variableType>(destField->startEditing(), 
    484                                  srcField->getValues(startIndex), 
    485                                  srcField->getNum(), indices, numToProcess); else 
    486     if (!indices && drawElemIndices) 
    487       ok = ivDeindex<variableType>(destField->startEditing(), 
    488                                  srcField->getValues(startIndex), 
    489                                  srcField->getNum(), drawElemIndices, numToProcess); 
    490     else { 
    491       OSG_WARN << "IvWriter: NOT IMPLEMENTED" << std::endl; 
    492       assert(0); // FIXME: 
    493     } 
     477    ok = ivDeindex<variableType>(destField->startEditing(), 
     478                                srcField->getValues(startIndex), 
     479                                srcField->getNum(), drawElemIndices, numToProcess); 
    494480 
    495481    destField->finishEditing(); 
     
    512498 
    513499 
    514 static void processIndices(const osg::Array *indices, const osg::Array *drawElemIndices, 
     500static void processIndices(const osg::Array *drawElemIndices, 
    515501                           SoMFInt32 &ivIndices, 
    516502                           int startIndex, int stopIndex, int numItemsUntilMinusOne) 
    517503{ 
    518   if (indices || drawElemIndices) { 
    519     if (indices && !drawElemIndices) 
    520       osgArray2ivMField(indices, ivIndices, startIndex, stopIndex, numItemsUntilMinusOne); else 
    521     if (!indices && drawElemIndices) 
     504  if (drawElemIndices) { 
     505 
    522506      osgArray2ivMField(drawElemIndices, ivIndices, startIndex, stopIndex, numItemsUntilMinusOne); 
    523     else { 
    524       OSG_WARN << "IvWriter: NOT IMPLEMENTED" << std::endl; 
    525       assert(0); // FIXME: 
    526     } 
    527507 
    528508  } else { 
     509 
    529510    int num = stopIndex-startIndex; 
    530511    if (numItemsUntilMinusOne != 0 && num >= 1) 
     
    573554 
    574555static void postProcessField(const SbIntList &runLengths, osg::PrimitiveSet::Mode primType, 
    575                              SoMFInt32 *field, osg::Geometry::AttributeBinding binding) 
    576 { 
    577   if (binding==osg::Geometry::BIND_OFF || binding==osg::Geometry::BIND_OVERALL || 
    578       binding==osg::Geometry::BIND_PER_PRIMITIVE_SET) 
     556                             SoMFInt32 *field, deprecated_osg::Geometry::AttributeBinding binding) 
     557{ 
     558  if (binding==deprecated_osg::Geometry::BIND_OFF || binding==deprecated_osg::Geometry::BIND_OVERALL || 
     559      binding==deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET) 
    579560    return; 
    580561 
     
    589570  const int l = runLengths.getLength(); 
    590571  switch (binding) { 
    591     case osg::Geometry::BIND_PER_VERTEX: 
     572    case deprecated_osg::Geometry::BIND_PER_VERTEX: 
    592573      for (int i=0; i<l; i++) 
    593574        newNum += (runLengths[i]-3)*3; 
    594575      break; 
    595     case osg::Geometry::BIND_PER_PRIMITIVE: 
     576    case deprecated_osg::Geometry::BIND_PER_PRIMITIVE: 
    596577      for (int i=0; i<l; i++) 
    597578        newNum += runLengths[i]-3; 
     
    607588  // int32_t *dst2 = dst; 
    608589  switch (binding) { 
    609     case osg::Geometry::BIND_PER_VERTEX: 
     590    case deprecated_osg::Geometry::BIND_PER_VERTEX: 
    610591      for (int i=0; i<l; i++) { 
    611592        int c = runLengths[i]; 
     
    643624      break; 
    644625 
    645     case osg::Geometry::BIND_PER_PRIMITIVE: 
     626    case deprecated_osg::Geometry::BIND_PER_PRIMITIVE: 
    646627      for (int i=0; i<l; i++,src++) { 
    647628        int c = runLengths[i]; 
     
    663644 
    664645static void postProcessTriangleSeparation(SoIndexedShape *shape, osg::PrimitiveSet::Mode primType, 
    665                                           osg::Geometry::AttributeBinding normalBinding, 
    666                                           osg::Geometry::AttributeBinding colorBinding) 
     646                                          deprecated_osg::Geometry::AttributeBinding normalBinding, 
     647                                          deprecated_osg::Geometry::AttributeBinding colorBinding) 
    667648{ 
    668649  // compute runLengths 
     
    681662    runLengths.append(l); 
    682663 
    683   postProcessField(runLengths, primType, &shape->coordIndex,        osg::Geometry::BIND_PER_VERTEX); 
     664  postProcessField(runLengths, primType, &shape->coordIndex,        deprecated_osg::Geometry::BIND_PER_VERTEX); 
    684665  postProcessField(runLengths, primType, &shape->normalIndex,       normalBinding); 
    685666  postProcessField(runLengths, primType, &shape->materialIndex,     colorBinding); 
     
    687668                         (shape->textureCoordIndex.getNum()==1 && shape->textureCoordIndex[0] == -1); 
    688669  if (!notUseTexCoords) 
    689     postProcessField(runLengths, primType, &shape->textureCoordIndex, osg::Geometry::BIND_PER_VERTEX); 
    690  
    691 } 
    692  
    693  
    694 static SoMaterialBinding* createMaterialBinding(const osg::Geometry *g, bool isMaterialIndexed) 
     670    postProcessField(runLengths, primType, &shape->textureCoordIndex, deprecated_osg::Geometry::BIND_PER_VERTEX); 
     671 
     672} 
     673 
     674 
     675static SoMaterialBinding* createMaterialBinding(const deprecated_osg::Geometry *g, bool isMaterialIndexed) 
    695676{ 
    696677  SoMaterialBinding *materialBinding = new SoMaterialBinding; 
    697678  switch (g->getColorBinding()) { 
    698   case osg::Geometry::BIND_OFF: // OFF means use material from state set (if any) for whole geometry 
    699   case osg::Geometry::BIND_OVERALL: 
    700   case osg::Geometry::BIND_PER_PRIMITIVE_SET: materialBinding->value = SoMaterialBinding::OVERALL; break; 
    701   case osg::Geometry::BIND_PER_PRIMITIVE:     materialBinding->value = (isMaterialIndexed) ? SoMaterialBinding::PER_PART_INDEXED   : SoMaterialBinding::PER_PART; break; 
    702   case osg::Geometry::BIND_PER_VERTEX:        materialBinding->value = (isMaterialIndexed) ? SoMaterialBinding::PER_VERTEX_INDEXED : SoMaterialBinding::PER_VERTEX; break; 
     679  case deprecated_osg::Geometry::BIND_OFF: // OFF means use material from state set (if any) for whole geometry 
     680  case deprecated_osg::Geometry::BIND_OVERALL: 
     681  case deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET: materialBinding->value = SoMaterialBinding::OVERALL; break; 
     682  case deprecated_osg::Geometry::BIND_PER_PRIMITIVE:     materialBinding->value = (isMaterialIndexed) ? SoMaterialBinding::PER_PART_INDEXED   : SoMaterialBinding::PER_PART; break; 
     683  case deprecated_osg::Geometry::BIND_PER_VERTEX:        materialBinding->value = (isMaterialIndexed) ? SoMaterialBinding::PER_VERTEX_INDEXED : SoMaterialBinding::PER_VERTEX; break; 
    703684  default: assert(0); 
    704685  } 
     
    707688 
    708689 
    709 static SoNormalBinding* createNormalBinding(const osg::Geometry *g, bool areNormalsIndexed) 
     690static SoNormalBinding* createNormalBinding(const deprecated_osg::Geometry *g, bool areNormalsIndexed) 
    710691{ 
    711692  // Convert normal binding 
    712693  SoNormalBinding *normalBinding = new SoNormalBinding; 
    713694  switch (g->getNormalBinding()) { 
    714   case osg::Geometry::BIND_OFF: // FIXME: what to do with BIND_OFF value? 
    715   case osg::Geometry::BIND_OVERALL: 
    716   case osg::Geometry::BIND_PER_PRIMITIVE_SET: normalBinding->value = SoNormalBinding::OVERALL; break; 
    717   case osg::Geometry::BIND_PER_PRIMITIVE:     normalBinding->value = (areNormalsIndexed) ? SoNormalBinding::PER_PART_INDEXED   : SoNormalBinding::PER_PART; break; 
    718   case osg::Geometry::BIND_PER_VERTEX:        normalBinding->value = (areNormalsIndexed) ? SoNormalBinding::PER_VERTEX_INDEXED : SoNormalBinding::PER_VERTEX; break; 
     695  case deprecated_osg::Geometry::BIND_OFF: // FIXME: what to do with BIND_OFF value? 
     696  case deprecated_osg::Geometry::BIND_OVERALL: 
     697  case deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET: normalBinding->value = SoNormalBinding::OVERALL; break; 
     698  case deprecated_osg::Geometry::BIND_PER_PRIMITIVE:     normalBinding->value = (areNormalsIndexed) ? SoNormalBinding::PER_PART_INDEXED   : SoNormalBinding::PER_PART; break; 
     699  case deprecated_osg::Geometry::BIND_PER_VERTEX:        normalBinding->value = (areNormalsIndexed) ? SoNormalBinding::PER_VERTEX_INDEXED : SoNormalBinding::PER_VERTEX; break; 
    719700  default: assert(0); 
    720701  } 
     
    11021083 
    11031084 
    1104 static bool processPrimitiveSet(const osg::Geometry *g, const osg::PrimitiveSet *pset, 
     1085static bool processPrimitiveSet(const deprecated_osg::Geometry *g, const osg::PrimitiveSet *pset, 
    11051086                                osg::UIntArray *drawElemIndices, bool needSeparateTriangles, 
    11061087                                int elementsCount, int primSize, const int startIndex, int stopIndex, 
     
    11371118 
    11381119  // Normal indexing 
    1139   int normalStart = g->getNormalBinding() == osg::Geometry::BIND_PER_VERTEX ? startIndex : normalIndex; 
     1120  int normalStart = (g->getNormalBinding() == deprecated_osg::Geometry::BIND_PER_VERTEX) ? startIndex : normalIndex; 
    11401121  int numNormalsUsed = 0; 
    11411122  switch (g->getNormalBinding()) { 
    1142   case osg::Geometry::BIND_OFF: // FIXME: what is meaning of OFF value? 
    1143   case osg::Geometry::BIND_OVERALL:           numNormalsUsed = 0; break; 
    1144   case osg::Geometry::BIND_PER_PRIMITIVE_SET: numNormalsUsed = 1; break; 
    1145   case osg::Geometry::BIND_PER_PRIMITIVE:     numNormalsUsed = primSize!=0 ? (stopIndex-startIndex)/primSize : 
     1123  case deprecated_osg::Geometry::BIND_OFF: // FIXME: what is meaning of OFF value? 
     1124  case deprecated_osg::Geometry::BIND_OVERALL:           numNormalsUsed = 0; break; 
     1125  case deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET: numNormalsUsed = 1; break; 
     1126  case deprecated_osg::Geometry::BIND_PER_PRIMITIVE:     numNormalsUsed = primSize!=0 ? (stopIndex-startIndex)/primSize : 
    11461127                                                (drawArrayLengths ? drawArrayLengths->size() : 1); break; 
    1147   case osg::Geometry::BIND_PER_VERTEX:        numNormalsUsed = stopIndex-startIndex; break; 
     1128  case deprecated_osg::Geometry::BIND_PER_VERTEX:        numNormalsUsed = stopIndex-startIndex; break; 
    11481129  } 
    11491130  normalIndex += numNormalsUsed; 
    11501131 
    11511132  // Color indexing 
    1152   int colorStart = g->getColorBinding() == osg::Geometry::BIND_PER_VERTEX ? startIndex : colorIndex; 
     1133  int colorStart = g->getColorBinding() == deprecated_osg::Geometry::BIND_PER_VERTEX ? startIndex : colorIndex; 
    11531134  int numColorsUsed = 0; 
    11541135  switch (g->getColorBinding()) { 
    1155   case osg::Geometry::BIND_OFF: 
    1156   case osg::Geometry::BIND_OVERALL:           numColorsUsed = 0; break; 
    1157   case osg::Geometry::BIND_PER_PRIMITIVE_SET: numColorsUsed = 1; break; 
    1158   case osg::Geometry::BIND_PER_PRIMITIVE:     numColorsUsed = primSize!=0 ? (stopIndex-startIndex)/primSize : 
     1136  case deprecated_osg::Geometry::BIND_OFF: 
     1137  case deprecated_osg::Geometry::BIND_OVERALL:           numColorsUsed = 0; break; 
     1138  case deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET: numColorsUsed = 1; break; 
     1139  case deprecated_osg::Geometry::BIND_PER_PRIMITIVE:     numColorsUsed = primSize!=0 ? (stopIndex-startIndex)/primSize : 
    11591140                                                (drawArrayLengths ? drawArrayLengths->size() : 1); break; 
    1160   case osg::Geometry::BIND_PER_VERTEX:        numColorsUsed = stopIndex-startIndex; break; 
     1141  case deprecated_osg::Geometry::BIND_PER_VERTEX:        numColorsUsed = stopIndex-startIndex; break; 
    11611142  } 
    11621143  colorIndex += numColorsUsed; 
     
    11651146 
    11661147    // Convert to SoIndexedShape 
    1167     processIndices(g->getVertexIndices(), drawElemIndices, ((SoIndexedShape*)shape)->coordIndex, 
     1148    processIndices(drawElemIndices, ((SoIndexedShape*)shape)->coordIndex, 
    11681149                   startIndex, stopIndex, primSize); 
    11691150 
    11701151    if (ivNormals) 
    1171       processIndices(g->getNormalIndices(), drawElemIndices, ((SoIndexedShape*)shape)->normalIndex, 
     1152      processIndices(drawElemIndices, ((SoIndexedShape*)shape)->normalIndex, 
    11721153                     normalStart, normalStart+(numNormalsUsed==0 ? 1 : numNormalsUsed), 
    1173                      g->getNormalBinding()==osg::Geometry::BIND_PER_VERTEX ? primSize : 0); 
     1154                     g->getNormalBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX ? primSize : 0); 
    11741155 
    11751156    if (ivMaterial) 
    1176       processIndices(g->getColorIndices(), drawElemIndices, ((SoIndexedShape*)shape)->materialIndex, 
     1157      processIndices(drawElemIndices, ((SoIndexedShape*)shape)->materialIndex, 
    11771158                     colorStart, colorStart+(numColorsUsed==0 ? 1 : numColorsUsed), 
    1178                      g->getColorBinding()==osg::Geometry::BIND_PER_VERTEX ? primSize : 0); 
     1159                     g->getColorBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX ? primSize : 0); 
    11791160 
    11801161    if (ivTexCoords && !ivTexCoords->isOfType(SoTextureCoordinateFunction::getClassTypeId())) 
    1181       processIndices(g->getTexCoordIndices(0), drawElemIndices, ((SoIndexedShape*)shape)->textureCoordIndex, 
     1162      processIndices(drawElemIndices, ((SoIndexedShape*)shape)->textureCoordIndex, 
    11821163                     startIndex, stopIndex, primSize); 
    11831164 
     
    11871168      postProcessDrawArrayLengths(drawArrayLengths, &((SoIndexedShape*)shape)->coordIndex); 
    11881169 
    1189       if (ivNormals && g->getNormalBinding()==osg::Geometry::BIND_PER_VERTEX) 
     1170      if (ivNormals && g->getNormalBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX) 
    11901171        postProcessDrawArrayLengths(drawArrayLengths, &((SoIndexedShape*)shape)->normalIndex); 
    11911172 
    1192       if (ivMaterial && g->getColorBinding()==osg::Geometry::BIND_PER_VERTEX) 
     1173      if (ivMaterial && g->getColorBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX) 
    11931174        postProcessDrawArrayLengths(drawArrayLengths, &((SoIndexedShape*)shape)->materialIndex); 
    11941175 
     
    12151196      if (ok) { 
    12161197        ((SoCoordinate4*)nonIndexedCoords)->point.setNum(n); 
    1217         ok = ivProcessArray<SbVec4f,SoMFVec4f>(g->getVertexIndices(), 
    1218                                              drawElemIndices, 
     1198        ok = ivProcessArray<SbVec4f,SoMFVec4f>(drawElemIndices, 
    12191199                                             &((SoCoordinate4*)nonIndexedCoords)->point, 
    12201200                                             &((SoCoordinate4*)ivCoords)->point, 
     
    12251205      if (ok) { 
    12261206        ((SoCoordinate3*)nonIndexedCoords)->point.setNum(n); 
    1227         ok = ivProcessArray<SbVec3f,SoMFVec3f>(g->getVertexIndices(), 
    1228                                              drawElemIndices, 
     1207        ok = ivProcessArray<SbVec3f,SoMFVec3f>(drawElemIndices, 
    12291208                                             &((SoCoordinate3*)nonIndexedCoords)->point, 
    12301209                                             &((SoCoordinate3*)ivCoords)->point, 
     
    12421221        { 
    12431222          ((SoTextureCoordinate2*)nonIndexedTexCoords)->point.setNum(n); 
    1244           ok = ivProcessArray<SbVec2f,SoMFVec2f>(g->getTexCoordIndices(0), 
    1245                                                drawElemIndices, 
     1223          ok = ivProcessArray<SbVec2f,SoMFVec2f>(drawElemIndices, 
    12461224                                               &((SoTextureCoordinate2*)nonIndexedTexCoords)->point, 
    12471225                                               &((SoTextureCoordinate2*)ivTexCoords)->point, 
     
    12561234        { 
    12571235          ((SoTextureCoordinate3*)nonIndexedTexCoords)->point.setNum(n); 
    1258           ok = ivProcessArray<SbVec3f,SoMFVec3f>(g->getTexCoordIndices(0), 
    1259                                                drawElemIndices, 
     1236          ok = ivProcessArray<SbVec3f,SoMFVec3f>(drawElemIndices, 
    12601237                                               &((SoTextureCoordinate3*)nonIndexedTexCoords)->point, 
    12611238                                               &((SoTextureCoordinate3*)ivCoords)->point, 
     
    12731250      if (ok) { 
    12741251        nonIndexedNormals->vector.setNum(numNormalsUsed==0 ? 1 : numNormalsUsed); 
    1275         ok = ivProcessArray<SbVec3f,SoMFVec3f>(g->getNormalIndices(), 
    1276                                              g->getNormalBinding()==osg::Geometry::BIND_PER_VERTEX ? drawElemIndices : NULL, 
     1252        ok = ivProcessArray<SbVec3f,SoMFVec3f>(g->getNormalBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX ? drawElemIndices : NULL, 
    12771253                                             &nonIndexedNormals->vector, &ivNormals->vector, 
    12781254                                             normalStart, numNormalsUsed==0 ? 1 : numNormalsUsed); 
     
    12961272                                   &((SoBaseColor*)ivMaterial)->rgb; 
    12971273        dstColorField->setNum(numColorsUsed==0 ? 1 : numColorsUsed); 
    1298         ok = ivProcessArray<SbColor,SoMFColor>(g->getColorIndices(), 
    1299                                             g->getColorBinding()==osg::Geometry::BIND_PER_VERTEX ? drawElemIndices : NULL, 
     1274        ok = ivProcessArray<SbColor,SoMFColor>(g->getColorBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX ? drawElemIndices : NULL, 
    13001275                                            dstColorField, srcColorField, 
    13011276                                            colorStart, numColorsUsed==0 ? 1 : numColorsUsed); 
     
    14721447 
    14731448 
    1474 void ConvertToInventor::processGeometry(const osg::Geometry *g, InventorState *ivState) 
     1449void ConvertToInventor::processGeometry(const deprecated_osg::Geometry *g, InventorState *ivState) 
    14751450{ 
    14761451  int normalIndex = 0; 
     
    15991574 
    16001575    // Create appropriate SoShape 
    1601     bool useIndices = g->getVertexIndices() != NULL || vrml1Conversion; 
     1576    bool useIndices = vrml1Conversion; 
    16021577    bool needSeparateTriangles = false; 
    16031578    SoVertexShape *shape = NULL; 
     
    18351810void ConvertToInventor::processDrawable(osg::Drawable *d) 
    18361811{ 
    1837   osg::Geometry *g = d->asGeometry(); // FIXME: other drawables have to be handled also 
    1838   osg::ShapeDrawable *sd; 
     1812  deprecated_osg::Geometry *g = dynamic_cast<deprecated_osg::Geometry*>(d); // FIXME: other drawables have to be handled also 
     1813  osg::ShapeDrawable *sd = 0; 
    18391814 
    18401815  // Create SoSeparator and convert StateSet for Drawable