void ossimKakaduJ2kReader::getDecimationFactors(
   vector<ossimDpt>& decimations) const
{
   const ossim_uint32 LEVELS = getNumberOfDecimationLevels();
   decimations.resize(LEVELS);
   for (ossim_uint32 level = 0; level < LEVELS; ++level)
   {
      getDecimationFactor(level, decimations[level]);
   }
}
ossim_uint32 ossimKakaduJ2kReader::getNumberOfSamples(
   ossim_uint32 resLevel) const
{
   ossim_uint32 result = 0;
   if (resLevel < getNumberOfDecimationLevels())
   {
      result = theSizRecord.theXsiz;
      if ( resLevel > 0 )
      {
         ossimDpt dpt;
         getDecimationFactor(resLevel, dpt);
         result = static_cast<ossim_uint32>(result * dpt.x);
      }
   }
   return result;
}
rspfIrect rspfPolyCutter::getBoundingRect(rspf_uint32 resLevel)const
{
   rspfIrect result;

   result.makeNan();
   if(!theInputConnection)
   {
      return result;
   }
   if(!isSourceEnabled())
   {
      return rspfImageSourceFilter::getBoundingRect(resLevel);
   }
   
   result = theInputConnection->getBoundingRect(resLevel);

   if(isSourceEnabled()&&(!theBoundingRect.hasNans()))
   {
      if(theCutType == RSPF_POLY_NULL_OUTSIDE)
      {
         rspfDpt decimation;
         getDecimationFactor(resLevel, decimation);
         if(decimation.hasNans())
         {
            result =  theBoundingRect;
         }
         else
         {
            result = theBoundingRect*decimation;
         }
      }
   }
   else if(isSourceEnabled())
   {
      return theBoundingRect;
   }
   
   return result;
}
rspfRefPtr<rspfImageData> rspfPolyCutter::getTile(const rspfIrect& tileRect,
                                                     rspf_uint32 resLevel)
{
   if(!theInputConnection)
   {
      return theTile;
   }
   rspfRefPtr<rspfImageData> input = theInputConnection->getTile(tileRect,
                                                                   resLevel);
   
   if(!isSourceEnabled() || theBoundingRect.hasNans() || !input.valid())
   {
      return input;
   }
   
   if((input->getDataObjectStatus() == RSPF_EMPTY) ||
      (input->getDataObjectStatus() == RSPF_NULL))
   {
      return input;
   }

   if(!theTile.valid())
   {
      allocate(); // First time through...
   }

   if(!theTile.valid())
   {
      return input;
   }
   
   theTile->setImageRectangle(tileRect);
   
   theTile->loadTile(input.get());
   theTile->setDataObjectStatus(input->getDataObjectStatus());
   vector<rspfPolygon>* polyList = &thePolygonList;
   vector<rspfPolygon>  scaledPoly;
   
   rspfIrect boundingRect = getBoundingRect(resLevel);
   if(resLevel)
   {
      rspfDpt decimation;
      getDecimationFactor(resLevel, decimation);

      if(!decimation.hasNans())
      {
         for(int polyIndex = 0;
             polyIndex < (int)thePolygonList.size();
             ++polyIndex)
         {
            scaledPoly.push_back(thePolygonList[polyIndex]*decimation);
         }
         polyList = &scaledPoly;
      }
   }
   
   if(polyList->size()&&
      theTile->getDataObjectStatus()!=RSPF_NULL)
   {
//       rspfActiveEdgeTable aet;
      
      
      if(theCutType == RSPF_POLY_NULL_OUTSIDE)
      {
         if(boundingRect.intersects(tileRect))
         {
            theTile->makeBlank();
            theHelper.setImageData(theTile.get());
            for(int polyIndex = 0; polyIndex < (int)polyList->size(); ++polyIndex)
            {
               theHelper.copyInputToThis(input->getBuf(),
                                      (*polyList)[polyIndex]);
            }
            theTile->validate();
         }
         else
         {
            theTile->makeBlank();
         }
      }
      else if(theCutType == RSPF_POLY_NULL_INSIDE)
      {
         if(boundingRect.intersects(tileRect))
         {
            theHelper.setImageData(theTile.get());
            for(int polyIndex = 0;
                polyIndex < (int)polyList->size();
                ++polyIndex)
            {
               theHelper.fill(theTile->getNullPix(),
                           (*polyList)[polyIndex]);
            }
         }
         theTile->validate();
      }
      
   }
   return theTile;
}