Esempio n. 1
0
bool
QA::entry(void)
{
   if(!isCheckData)
     pIn->dataVarIndex.clear();

   // no data section provided in the NetCDF file; enable
   // a single loop
   if( pIn->currRec == pIn->ncRecEnd )
      ++pIn->ncRecEnd;

   // records could have been reset by TC,
   for( ; pIn->currRec < pIn->ncRecEnd ; pIn->currRec += pIn->recStride )
   {
     // read next field
     pIn->entry() ;

     for( size_t i=0 ; i < pIn->dataVarIndex.size() ; ++i)
     {
       Variable &var = pIn->variable[pIn->dataVarIndex[i]];

       if( var.isNoData() )
          continue;

       if( pIn->currRec && var.isFixed )
         continue;

       var.pDS->clear();

       if( var.isArithmeticMean )
         // use the entire record
         var.pDS->add( (void*) var.pMA );
       else
       {
         // loop over the layers and there should be at least one.
         var.pGM->resetLayer();
         do
         {
           // due to area weighted statistics, we have to cycle
           // through the layers one by one.
//         if( var.pGM->isLayerMutable() )
//           ;

           var.pDS->add( var.pGM->getCellValue(),
                       *var.pGM->getCellWeight() );
           // break the while loop, if the last layer was processed.
         } while ( var.pGM->cycleLayers() ) ; //cycle through levels
       }
     }

     // the final for this record
     closeEntry();

     isNotFirstRecord = true;
   }

   return true;
}
Esempio n. 2
0
ossimMrSidReader::~ossimMrSidReader()
{
   closeEntry();
   theReader->release();
   theReader = 0;
   if (theImageNavigator != 0)
   {
      delete theImageNavigator;
      theImageNavigator = 0;
   }
}
Esempio n. 3
0
void MlCache::setCachedSlices(const std::string & name)
{
	openEntry(name);
	HBase * p = getNamedEntry(name);
	int nf = p->numChildren();
	unsigned csize = entrySize(name);
	for(int i = 0; i < nf; i++) {
		if(p->isChildData(i))
			setCached(name, p->getChildName(i), csize);
	}
	
	closeEntry(name);
}
Esempio n. 4
0
bool MlCache::doRead(const std::string & name)
{
	if(!HFile::doRead(name)) return false;
	
	openEntry("/info");
	HBase *info = getNamedEntry("/info");
	if(info->hasNamedAttr(".scene"))
	    info->readStringAttr(".scene", m_sceneName);
	if(info->hasNamedAttr(".range"))
	    info->readIntAttr(".range", m_bakeRange);
	closeEntry("/info");
	
	setCachedSlices("/p");
	setCachedSlices("/tang");
	setCachedSlices("/ang");
	return true;
}
ossimKakaduJ2kReader::~ossimKakaduJ2kReader()
{
   closeEntry();
}
bool ossimKakaduJ2kReader::open()
{
   static const char MODULE[] = "ossimKakaduJ2kReader::open";

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " entered...\n";
   }
   
   bool result = false;
   
   if(isOpen())
   {
      closeEntry();
   }

   // Open up a stream to the file.
   theFileStr.open(theImageFile.c_str(), ios::in | ios::binary);
   if ( theFileStr.good() )
   {
      //---
      // Check for the Start Of Codestream (SOC) and Size (SIZ) markers which
      // are required as first and second fields in the main header.
      //---
      ossim_uint16 soc;
      ossim_uint16 siz;
      theFileStr.read((char*)&soc,  2);
      theFileStr.read((char*)&siz,  2);
      
      if (ossim::byteOrder() == OSSIM_LITTLE_ENDIAN) // Alway big endian.
      {
         ossimEndian().swap(soc);
         ossimEndian().swap(siz);
      }

      if ( (soc == SOC_MARKER) && (siz == SIZ_MARKER) )
      {
         // Read in and store the size record.
         theSizRecord.parseStream(theFileStr);

         // Position to start of code stream prior to create call.
         theFileStr.seekg(0);
 
         //---
         // Initialize the codestream.  The class ossimKakaduNitfReader is a
         // kdu_compressed source so we feed ourself to the codestream.
         //
         // TODO:  Currently no kdu_thread_env.  This should be implemented for
         // speed...
         //---
         
         //---
         // Construct multi-threaded processing environment if required.
         // Temp hard coded to a single thread.
         //---
         
         if (theThreadEnv)
         {
            theThreadEnv->terminate(NULL, true);
            theThreadEnv->destroy();
         }
         else
         {
            theThreadEnv = new kdu_thread_env();
         }
         
         theThreadEnv->create(); // Creates the single "owner" thread

         // Check for threads in prefs file.
         ossim_uint32 threads = 1;
         const char* lookup = ossimPreferences::instance()->findPreference("kakadu_threads");
         if ( lookup )
         {
            threads = ossimString::toUInt32(lookup);
            if ( threads > 1 )
            {
               for (ossim_uint32 nt=1; nt < threads; ++nt)
               {
                  if ( !theThreadEnv->add_thread() )
                  {
                     if (traceDebug())
                     {
                        ossimNotify(ossimNotifyLevel_WARN)
                           << "Unable to create thread!\n";
                     }
                  }
               }
            }
         }
         
         theOpenTileThreadQueue = theThreadEnv->add_queue(NULL,NULL,"open_tile_q");
         
         theCodestream.create(this, theThreadEnv);
         
         if ( theCodestream.exists() )
         {
            //---
            // We have to store things here in this non-const method because
            // NONE of the kakadu methods are const.
            //---
            theMinDwtLevels = theCodestream.get_min_dwt_levels();
            
            theCodestream.set_persistent(); // ????
            theCodestream.enable_restart(); // ????
            
            kdu_dims region_of_interest;
            region_of_interest.pos.x = 0;
            region_of_interest.pos.y = 0;
            region_of_interest.size.x = getNumberOfSamples(0);
            region_of_interest.size.y = getNumberOfLines(0);

            theCodestream.apply_input_restrictions(
               0, // first_component
               0, // max_components (0 = all remaining will appear)
               0, // highest resolution level
               0, // max_layers (0 = all layers retained)
               &region_of_interest, // expanded out to block boundary.
               //KDU_WANT_CODESTREAM_COMPONENTS);
               KDU_WANT_OUTPUT_COMPONENTS);
            
            // Set the scalar:
            theScalarType = theSizRecord.getScalarType();
            if (theScalarType != OSSIM_SCALAR_UNKNOWN)
            {
               //---
               // NOTE: Please leave commented out code for now.
               //---
               // Capture the sub image offset.
               // theSubImageOffset.x = theSizRecord.theXOsiz;
               // theSubImageOffset.y = theSizRecord.theYOsiz;
               
               // Initialize the image rect.
               theImageRect = ossimIrect(0,
                                         0,
                                         theSizRecord.theXsiz-1,
                                         theSizRecord.theYsiz-1);

               // Initialize the cache.
               if (theCacheId != -1)
               {
                  ossimAppFixedTileCache::instance()->deleteCache(theCacheId);
                  theCacheId = -1;
               }
               ossimIpt tileSize(theSizRecord.theXTsiz, theSizRecord.theYTsiz);

               // Stretch to tile boundary for the cache.
               ossimIrect fullImgRect = theImageRect;
               fullImgRect.stretchToTileBoundary(tileSize);
               
               // Set up the tile cache.
               theCacheId = ossimAppFixedTileCache::instance()->
                  newTileCache(fullImgRect, tileSize);

               // Add the sub image rect after the 
               
               // Initialize the tile we will return.
               initializeTile();

               // Call the base complete open to pick up overviews.
               completeOpen();
               
               // We should be good now so set the return result to true.
               result = true;

               if (traceDebug())
               {
                  ossimNotify(ossimNotifyLevel_DEBUG)
                     << "\nSIZ marker segment"
                     << theSizRecord
                     << "theCodestream.get_num_components(false): "
                     << theCodestream.get_num_components(false)
                     << "\ntheCodestream.get_num_components(true): "
                     << theCodestream.get_num_components(true)
                     << "\ntheCodestream.get_bit_depth(0, true): "
                     << theCodestream.get_bit_depth(0, true)
                     << "\ntheCodestream.get_signed(0, true): "
                     << theCodestream.get_signed(0, true)
                     << "\ntheCodestream.get_min_dwt_levels(): "
                     << theCodestream.get_min_dwt_levels()
                     << "\ntheImageRect: " << theImageRect
                     << "\nFull image rect: " << fullImgRect
                     << "\nthreads: " << threads
                     << "\n";
                  
                  vector<ossimDpt> decimations;
                  getDecimationFactors(decimations);
                  for (ossim_uint32 i = 0; i < decimations.size(); ++i)
                  {
                     ossimNotify(ossimNotifyLevel_DEBUG)
                        << theCodestream.get_min_dwt_levels()
                        << "Decimation factor[" << i << "]: "
                        << decimations[i]
                        << "\nsamples[" << i << "]: "
                        << getNumberOfSamples(i)
                        << "\nlines[" << i << "]: "
                        << getNumberOfLines(i)
                        << std::endl;
                     
                  }
               }
            }
               
         } // matches: if ( theCodestream.exists() )
         
      } //  matches: if ( (soc == SOC_MARKER) && (siz == SIZ_MARKER) )
      
   } // matches: if ( theFileStr.good() )
   else
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << MODULE << " ERROR:"
            << "\nCannot open:  " << theImageFile.c_str() << endl;
      }
   }

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " exit status = " << (result?"true":"false\n")
         << std::endl;
   }

   return result;
}
Esempio n. 7
0
bool MlCache::doCopy(const std::string & name)
{
	std::cout<<"copy cache to "<<name;

	useDocument();
	openEntry("/ang");
	int nang = entrySize("/ang");

	if(nang < 1) return false;
	
	std::vector<std::string> sliceNames;
	unsigned numSlices = cacheSliceNames("/ang", sliceNames);
	std::cout<<" n slice "<<numSlices<<"in /ang\n";
	if(numSlices < 2) return false;
	
	openEntry("/tang");
	int tsize = entrySize("/tang");
	openEntry("/p");
	int ptsize = entrySize("/p");
	
	MlCache tgt;
	if(!tgt.create(name)) return false;
	
	tgt.useDocument();
	tgt.openEntry("/info");
	HBase *info = tgt.getNamedEntry("/info");
	info->addStringAttr(".scene", m_sceneName.size());
	info->writeStringAttr(".scene", m_sceneName);
	info->addIntAttr(".range", 2);
	info->writeIntAttr(".range", m_bakeRange);
	tgt.closeEntry("/info");
	
	tgt.openEntry("/ang");
	tgt.saveEntrySize("/ang", nang);
	
	tgt.openEntry("/tang");
	tgt.saveEntrySize("/tang", tsize);
	
	tgt.openEntry("/p");
	tgt.saveEntrySize("/p", ptsize);
	
	const unsigned blockL = 4096;
	float * b = new float[blockL];
	Vector3F * bp = new Vector3F[blockL];
	Matrix33F * bm = new Matrix33F[blockL];
	
	BoundingBox box;
	Vector3F center;
	unsigned i, j, start, count;
	for(i = 0; i < sliceNames.size(); i++) {
		std::string aslice = HObject::PartialPath("/ang", sliceNames[i]);
		if(aslice == "-9999") continue;
		
		useDocument();
		openSliceFloat("/ang", aslice);
		openSliceVector3("/p", aslice);
		openSliceMatrix33("/tang", aslice);
		
		tgt.useDocument();
		tgt.openSliceFloat("/ang", aslice);
		tgt.openSliceVector3("/p", aslice);
		tgt.openSliceMatrix33("/tang", aslice);
		
		start = 0;
		count = blockL;
		for(j = 0; j <= nang/blockL; j++) {
			if(j== nang/blockL)
				count = nang%blockL;
				
			start = j * blockL;

			useDocument();
			readSliceFloat("/ang", aslice, start, count, b);
		
			tgt.useDocument();
			tgt.writeSliceFloat("/ang", aslice, start, count, b);
		}
		
		start = 0;
		count = blockL;
		for(j = 0; j <= tsize/blockL; j++) {
			if(j== tsize/blockL)
				count = tsize%blockL;
				
			start = j * blockL;	
			useDocument();
			readSliceVector3("/p", aslice, start, count, bp);
			readSliceMatrix33("/tang", aslice, start, count, bm);
			
			tgt.useDocument();
			tgt.writeSliceVector3("/p", aslice, start, count, bp);
			tgt.writeSliceMatrix33("/tang", aslice, start, count, bm);

		}
		
		useDocument();
		closeSlice("/ang", aslice);
		closeSlice("/tang", aslice);
		closeSlice("/p", aslice);
		tgt.useDocument();
		tgt.closeSlice("/ang", aslice);
		tgt.closeSlice("/tang", aslice);
		tgt.closeSlice("/p", aslice);
		
		getBounding(aslice, box);
		getTranslation(aslice, center);
		
		tgt.setBounding(aslice, box);
		tgt.setTranslation(aslice, center);
		tgt.flush();
	}
	delete[] b;
	delete[] bp;
	delete[] bm;
	
	useDocument();
	closeEntry("/ang");
	closeEntry("/tang");
	closeEntry("/p");
	
	tgt.useDocument();
	tgt.closeEntry("/ang");
	tgt.closeEntry("/tang");
	tgt.closeEntry("/p");
	
	tgt.close();
	return true;
}
Esempio n. 8
0
bool ossimMrSidReader::open()
{
   static const char MODULE[] = "ossimMrSidReader::open";

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " entered...\n"
         << "image: " << theImageFile << "\n";
   }
   
   bool result = false;

   if(isOpen())
   {
      closeEntry();
   }

   LT_STATUS sts = LT_STS_Uninit;

   const LTFileSpec fileSpec(theImageFile.c_str());
 
   theReader = MrSIDImageReader::create();
   sts = theReader->initialize(fileSpec, true);
   if (LT_SUCCESS(sts) == false)
   {
      return false;
   }

   theImageNavigator = new LTINavigator(*theReader);

   theImageRect = ossimIrect(0, 0, theReader->getWidth()-1, theReader->getHeight()-1);
   theNumberOfBands = theReader->getNumBands();
   theMinDwtLevels = theReader->getNumLevels();

   getDataType();

   if (getImageDimensions(theMrSidDims))
   {
      if (theScalarType != OSSIM_SCALAR_UNKNOWN)
      {
         ossim_uint32 width  = theReader->getWidth();
         ossim_uint32 height = theReader->getHeight();

         // Check for zero width, height.
         if ( !width || !height )
         {
            ossimIpt tileSize;
            ossim::defaultTileSize(tileSize);

            width  = tileSize.x;
            height = tileSize.y;
         }

         theTile = ossimImageDataFactory::instance()->create(this, this);

         theTile->initialize();

         // Call the base complete open to pick up overviews.
         computeMinMax();
         completeOpen();

         result = true;
      }
   }

   if (result == false)
   {
      closeEntry();
   }

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " exit status = " << (result?"true":"false\n")
         << std::endl;
   }

   return result;
}