Exemple #1
0
ossimProjection*
ossimNitfProjectionFactory::createProjection(const ossimFilename& filename,
                                             ossim_uint32 entryIdx)const
{
   static const char MODULE[]="ossimNitfProjectionFactory::createProjection";
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " DEBUG:"
         << "\nfilename:  " << filename
         << "\nentryIdx:  " << entryIdx
         << std::endl;
   }

   // See if there is an external geomtry.
   ossimProjection* result = createProjectionFromGeometryFile(filename,
                                                              entryIdx);
   if (result)
   {
      return result;
   }

   if(!isNitf(filename))
   {
      return result; // result is NULL
   }

   ossimRefPtr<ossimNitfFile> nitf = new ossimNitfFile();
   if (!nitf->parseFile(filename))
   {
      return result; // result is NULL
   }

   long imageIndex = static_cast<long>(entryIdx);
   if ( imageIndex > (nitf->getHeader()->getNumberOfImages()-1) )
   {
      return result;
   }

   ossimRefPtr<ossimNitfImageHeader> imageHeader = nitf->getNewImageHeader(imageIndex);
   {
      if (!imageHeader)
      {
         return result;
      }
   }

   result = createProjectionFromHeaders(nitf->getHeader(),
                                        imageHeader.get());
   if (traceDebug())
   {
      ossimString coordinateSystem   = imageHeader->getCoordinateSystem();
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " DEBUG:"
         << "\ncoordinateSysetm:       " << coordinateSystem
         << std::endl;
   }

   return result;
}
rspfProjection*
rspfMapProjectionFactory::createProjection(const rspfFilename& filename,
                                            rspf_uint32 entryIdx)const
{
   if(!filename.exists())
   {
      return NULL;
   }
   rspfProjection* proj = createProjectionFromGeometryFile(filename,
                                                            entryIdx);
   if (proj)
   {
      return proj;
   }
   rspfFilename geomFile = filename;
   geomFile = geomFile.setExtension("geom");
   if(!geomFile.exists())
   {
      return NULL;
   }
   rspfKeywordlist kwl;
   if(kwl.addFile(geomFile))
   {
      return createProjection(kwl);
   }
   return NULL;
}
ossimProjection* ossimNgaProjectionFactory::createProjection(const ossimFilename& filename,
      ossim_uint32 entryIdx) const
      {
   // Check for external geometry file.
   return createProjectionFromGeometryFile(filename, entryIdx);
}
ossimProjection* ossimSensorModelFactory::createProjection(
   const ossimFilename& filename, ossim_uint32  entryIdx) const
{
   if(!filename.exists()) return 0;
   static const char MODULE[] = "ossimSensorModelFactory::createProjection";
   
   ossimKeywordlist kwl;
   ossimRefPtr<ossimProjection> model = 0;

   ossimFilename geomFile = filename;
   geomFile = geomFile.setExtension("geom");
   
   if(geomFile.exists()&&
      kwl.addFile(filename.c_str()))
   {
      ossimFilename coarseGrid;
      
      const char* type = kwl.find(ossimKeywordNames::TYPE_KW);
      if(type)
      {
         if(ossimString(type) ==
            ossimString(STATIC_TYPE_NAME(ossimCoarseGridModel)))
         {
            findCoarseGrid(coarseGrid, filename);
            
            if(coarseGrid.exists() &&(coarseGrid != ""))
            {
               kwl.add("grid_file_name",
                       coarseGrid.c_str(),
                       true);
               model = new ossimCoarseGridModel(kwl);
               if(!model->getErrorStatus())
               {
                  return model.release();
               }
               model = 0;
            }
         }
      }
      kwl.clear();
   }

   // See if there is an external geomtry.
   ossimRefPtr<ossimProjection> proj =
      createProjectionFromGeometryFile(filename, entryIdx);
   if (proj.valid())
   {
      return proj.release();
   }

   if(model.valid())
   {
      model = 0;
   }
   
   // first check for override
   //
   if(geomFile.exists()&&kwl.addFile(geomFile.c_str()))
   {
      model =  createProjection(kwl);
      if(model.valid())
      {
         return model.release();
      }
      model = 0;
   }

   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " DEBUG: Testing ossimCoarsGridModel" << std::endl;
   }
   
   ifstream input(geomFile.c_str());
   char ecgTest[4];
   input.read((char*)ecgTest, 3);
   ecgTest[3] = '\0';
   input.close();
   if(ossimString(ecgTest) == "eCG")
   {
      ossimKeywordlist kwlTemp;
      kwlTemp.add("type",
                  "ossimCoarseGridModel",
                  true);
      kwlTemp.add("geom_file",
                  geomFile.c_str(),
                  true);
      return createProjection(kwlTemp);
   }
   
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " DEBUG: testing ossimRpcModel" << std::endl;
   }

   //---
   // Test for quick bird rpc.  Could be either a tiff or nitf so not wrapped
   // around "isNitf()" anymore.
   //---
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " DEBUG: testing ossimQuickbirdRpcModel"
         << std::endl;
   }
   
   ossimRefPtr<ossimQuickbirdRpcModel> qbModel = new ossimQuickbirdRpcModel;
   if(qbModel->parseFile(filename))
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << MODULE << " DEBUG: returning ossimQuickbirdRpcModel"
            << std::endl;
      }
      model = qbModel.get();
      qbModel = 0;
      return model.release();
   }
   else
   {
      qbModel = 0;
   }
   
   //---
   // Test for ikonos rpc.  Could be tiff or nitf which is handled in
   // parseFile method.
   //---
   ossimRefPtr<ossimIkonosRpcModel> ikModel = new ossimIkonosRpcModel;
   if(ikModel->parseFile(filename))
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << MODULE << " DEBUG returning ossimQuickbirdRpcModel"
            << std::endl;
      }
      model = ikModel.get();
      ikModel = 0;
      return model.release();
   }
   else
   {
      ikModel = 0;
   }

   if(isNitf(filename))
   {
     if(traceDebug())
     {
        ossimNotify(ossimNotifyLevel_DEBUG)
           << MODULE << " DEBUG: testing ossimNitfRpcModel" << std::endl;
     }

     ossimRefPtr<ossimNitfRpcModel> rpcModel = new ossimNitfRpcModel();
     if ( rpcModel->parseFile(filename, entryIdx) ) // filename = NITF_file
     {
        model = rpcModel.get();
        rpcModel = 0;
        return model.release();
     }
     else
     {
        rpcModel = 0;
     }
     
     if(traceDebug())
     {
        ossimNotify(ossimNotifyLevel_DEBUG)
           << MODULE << " DEBUG: testing ossimIkinosRpcModel" << std::endl;
     }
     
     model = new ossimNitfMapModel(filename); // filename = NITF_file
     if(!model->getErrorStatus())
     {
        return model.release();
     }
     model = 0;
   }
   else if(isLandsat(filename))
   {
      model = new ossimLandSatModel(filename);
      if(!model->getErrorStatus())
      {
         return model.release();
      }
      model = 0;
   }
   
   model = new ossimRS1SarModel(filename);
   if(model->getErrorStatus()!= ossimErrorCodes::OSSIM_OK)
   {
      return model.release();
   }
   model = 0;

   // SPOT:
   ossimFilename spot5Test = geomFile;
   if(!spot5Test.exists())
   {
      spot5Test = geomFile.path();
      spot5Test = spot5Test.dirCat(ossimFilename("METADATA.DIM"));
      if (spot5Test.exists() == false)
      {
         spot5Test = geomFile.path();
         spot5Test = spot5Test.dirCat(ossimFilename("metadata.dim"));
      }
   }
   if(spot5Test.exists())
   {
      //---
      // Check the basename of the input file. So we don't create a projection
      // for ancillary files, icon.jpg amd preview.jpg.
      //---
      ossimFilename baseName = filename.file();
      baseName.downcase();

      if ( (baseName != "icon.jpg" ) && ( baseName != "preview.jpg" ) )
      {
         ossimRefPtr<ossimSpotDimapSupportData> meta =
            new ossimSpotDimapSupportData;
         if(meta->loadXmlFile(spot5Test))
         {
            model = new ossimSpot5Model(meta.get());
            if(!model->getErrorStatus())
            {
               return model.release();
            }
         }
      }
   }
   model = 0;
            
   ossimFilename ppjFilename = filename;
   ppjFilename = ppjFilename.setExtension("ppj");
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " DEBUG: testing ossimPpjFrameSensor" << std::endl;
   }
   if(ppjFilename.exists())
   {
      ossimRefPtr<ossimPpjFrameSensorFile> ppjFile = new ossimPpjFrameSensorFile();

      if(ppjFile->readFile(ppjFilename))
      {
         ossimRefPtr<ossimPpjFrameSensor> sensor = new ossimPpjFrameSensor();
         ossimDpt imageSize = ppjFile->getImageSize();
         sensor->setFocalLength(ppjFile->getIntrinsic()[0][0], ppjFile->getIntrinsic()[1][1]);
         sensor->setPrincipalPoint(ppjFile->getPrincipalPoint());
         sensor->setecef2CamMatrix(ppjFile->getExtrinsic().SymSubMatrix(1,3));
         sensor->setCameraPosition(ppjFile->getPlatformPosition());
         sensor->setImageSize(imageSize);
         sensor->setImageRect(ossimDrect(0,0,imageSize.x-1, imageSize.y-1));
         sensor->setRefImgPt(ossimDpt(imageSize.x*.5, imageSize.y*.5));
         sensor->setAveragePrjectedHeight(ppjFile->getAverageProjectedHeight());
         sensor->updateModel();
         return sensor.release();         
      }
      ppjFile = 0;
   }
   
   ossimFilename hdrFilename = filename;
   hdrFilename = hdrFilename.setExtension("hdr"); // image.hdr
   if ( !hdrFilename.exists() )   
   {     
      hdrFilename = filename;
      hdrFilename.string() += ".hdr"; // image.ras.hdr
   }
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " DEBUG: testing ossimAlphaSensor\nheader file: " << hdrFilename << std::endl;
   }
   if(hdrFilename.exists())
   {
      ossimRefPtr<ossimAlphaSensorSupportData> supData = new ossimAlphaSensorSupportData();
      if(supData->readSupportFiles(hdrFilename))
      {
         if (supData->isHSI())
         {
            if(traceDebug())
            {
               ossimNotify(ossimNotifyLevel_DEBUG)
                  << MODULE << " DEBUG: loading ossimAlphaSensorHSI" << std::endl;
            }
            ossimRefPtr<ossimAlphaSensorHSI> sensor = new ossimAlphaSensorHSI();
            if ( sensor->initialize( *(supData.get()) ) )
            {
               return (ossimProjection*)sensor.release();
            }
         }
         else
         {
            if(traceDebug())
            {
               ossimNotify(ossimNotifyLevel_DEBUG)
                  << MODULE << " DEBUG: loading ossimAlphaSensorHRI" << std::endl;
            }
            ossimRefPtr<ossimAlphaSensorHRI> sensor = new ossimAlphaSensorHRI();
            if ( sensor->initialize( *(supData.get()) ) )
            {
               return (ossimProjection*)sensor.release();
            }
         }
      }
      supData = 0;
   }

   model = new ossimCoarseGridModel(geomFile);
   if(model.valid())
   {
      if(!model->getErrorStatus())
      {
         return model.release();
      }
      model = 0;
   }

   return model.release();
}