<commit_before>//----------------------------------------------------------------------------
//
// License:  See top level LICENSE.txt file.
//
// Author:  <NAME>
//
// Description: Automatic tie measurement extraction.
//
//----------------------------------------------------------------------------
// $Id$

#include "ossimTieMeasurementGenerator.h"
#include <ossim/base/ossimString.h>
#include <ossim/base/ossimNotify.h>
#include <ossim/base/ossimTrace.h>
#include <ossim/base/ossimIrect.h>
#include <ossim/base/ossimRefPtr.h>
#include <ossim/base/ossimConstants.h>
#include <ossim/elevation/ossimElevManager.h>
#include <ossim/imaging/ossimImageData.h>
#include <ossim/imaging/ossimImageSource.h>

#include "ossimIvtGeomXformVisitor.h"

#include <opencv/highgui.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/flann/flann.hpp>
// Note: These are purposely commented out to indicate non-use.
// #include <opencv2/nonfree/nonfree.hpp>
// #include <opencv2/nonfree/features2d.hpp>
// Note: These are purposely commented out to indicate non-use.

#include <vector>
#include <iostream>

static ossimTrace traceExec  ("ossimTieMeasurementGenerator:exec");
static ossimTrace traceDebug ("ossimTieMeasurementGenerator:debug");


//*****************************************************************************
//  METHOD: ossimTieMeasurementGenerator::ossimTieMeasurementGenerator()
//  
//  Constructor.
//*****************************************************************************
ossimTieMeasurementGenerator::ossimTieMeasurementGenerator()
   :
   m_initOK(false),
   m_src(0),
   m_igxA(0),
   m_igxB(0),
   m_imgA(),
   m_imgB(),
   m_numMeasurements(0),
   m_maxMatches(5),
   m_spIndexA(0),
   m_spIndexB(1),
   m_patchSizeA(),
   m_patchSizeB(),
   m_validBox(false),   
   m_useGrid(false),
   m_showCvWindow(false),
   m_patchRefA(),
   m_patchRefB(),
   m_measA(),
   m_measB(),
   m_distEditFactor(0),
   m_detectorName("ORB"),
   m_detector(),
   m_extractorName("FREAK"),
   m_extractor(),
   m_matcherName("BruteForce-Hamming"),
   m_matcher(),
   m_rep(0),
   m_maxCvWindowDim(500),
   m_cvWindowName("Correlation Patch")
{
   if (traceExec())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "\nDEBUG: ...ossimTieMeasurementGenerator::constructor" << std::endl;
   }
}


//*****************************************************************************
//  METHOD: ossimTieMeasurementGenerator::ossimTieMeasurementGenerator()
//  
//  Initializer.
//*****************************************************************************
bool ossimTieMeasurementGenerator::init(std::ostream& report)
{
   if (traceExec())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG: ...ossimTieMeasurementGenerator::init" << std::endl;
   }

   m_initOK = true;
   ossimString ts;
   ossim::getFormattedTime("%a %m.%d.%y %H:%M:%S", false, ts);

   m_rep = &report;


   // Initial report output
   *m_rep << "\nossimTieMeasurementGenerator Report     ";
   *m_rep << ts;
   *m_rep << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
   *m_rep << std::endl;
 
   // Set default grid size
   setGridSize(ossimIpt(1,1));

   try{
   // Set default detector, extractor, matcher
      setFeatureDetector(m_detectorName);
      setDescriptorExtractor(m_extractorName);
      setDescriptorMatcher(m_matcherName);

   }
   catch(...)
   {
      m_initOK = false;
   }

   return m_initOK;
}


//*****************************************************************************
//  DESTRUCTOR: ~ossimTieMeasurementGenerator()
//  
//*****************************************************************************
ossimTieMeasurementGenerator::~ossimTieMeasurementGenerator()
{
   if (traceExec())  ossimNotify(ossimNotifyLevel_DEBUG)
      << "DEBUG: ~ossimTieMeasurementGenerator(): returning..." << std::endl;
}


//*****************************************************************************
//  METHOD: ossimTieMeasurementGenerator::refreshCollectionTraits()
//  
//  Collection trait initializer.
//*****************************************************************************
bool ossimTieMeasurementGenerator::refreshCollectionTraits()
{
   bool initOK = true;

   if (m_useGrid)
   {
      int gridRows = m_gridSize.y;
      int gridCols = m_gridSize.x;
      cv::ORB::create("");
   }

   return initOK;
}


//*****************************************************************************
//  METHOD: ossimTieMeasurementGenerator::run()
//  
//  
//*****************************************************************************
bool ossimTieMeasurementGenerator::run()
{
   bool runOK = true;

   // Refresh collection traits before run
   runOK = refreshCollectionTraits();

   if (runOK)
   {
      // ossimIrect constructor center-based constructor
      //    -> center view coordinates: m_patchRefA,m_patchRefB
      ossimIrect rectA(m_patchRefA, m_patchSizeA.x, m_patchSizeA.y);
      ossimIrect rectB(m_patchRefB, m_patchSizeB.x, m_patchSizeB.y);
      
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "DEBUG: ...ossimTieMeasurementGenerator::run" << std::endl;
         ossimNotify(ossimNotifyLevel_DEBUG)<<" m_patchRefA: "<<m_patchRefA<<" size: "<<m_patchSizeA<<std::endl; 
         ossimNotify(ossimNotifyLevel_DEBUG)<<" m_patchRefB: "<<m_patchRefB<<" size: "<<m_patchSizeB<<std::endl; 
         ossimNotify(ossimNotifyLevel_DEBUG)<<" rectA = "<<rectA<<endl;
         ossimNotify(ossimNotifyLevel_DEBUG)<<" rectB = "<<rectB<<endl;
         ossimNotify(ossimNotifyLevel_DEBUG)<<" m_src A ossimScalarType = "<<m_src[m_spIndexA]->getOutputScalarType()<<endl;
         ossimNotify(ossimNotifyLevel_DEBUG)<<" m_src B ossimScalarType = "<<m_src[m_spIndexB]->getOutputScalarType()<<endl;
      }
<commit_msg>Fixing core dumps<commit_after>//----------------------------------------------------------------------------
//
// License:  See top level LICENSE.txt file.
//
// Author:  <NAME>
//
// Description: Automatic tie measurement extraction.
//
//----------------------------------------------------------------------------
// $Id$

#include "ossimTieMeasurementGenerator.h"
#include <ossim/base/ossimString.h>
#include <ossim/base/ossimNotify.h>
#include <ossim/base/ossimTrace.h>
#include <ossim/base/ossimIrect.h>
#include <ossim/base/ossimRefPtr.h>
#include <ossim/base/ossimConstants.h>
#include <ossim/elevation/ossimElevManager.h>
#include <ossim/imaging/ossimImageData.h>
#include <ossim/imaging/ossimImageSource.h>

#include "ossimIvtGeomXformVisitor.h"

#include <opencv/highgui.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/flann/flann.hpp>
// Note: These are purposely commented out to indicate non-use.
// #include <opencv2/nonfree/nonfree.hpp>
// #include <opencv2/nonfree/features2d.hpp>
// Note: These are purposely commented out to indicate non-use.

#include <vector>
#include <iostream>

static ossimTrace traceExec  ("ossimTieMeasurementGenerator:exec");
static ossimTrace traceDebug ("ossimTieMeasurementGenerator:debug");


//*****************************************************************************
//  METHOD: ossimTieMeasurementGenerator::ossimTieMeasurementGenerator()
//  
//  Constructor.
//*****************************************************************************
ossimTieMeasurementGenerator::ossimTieMeasurementGenerator()
   :
   m_initOK(false),
   m_src(0),
   m_igxA(0),
   m_igxB(0),
   m_imgA(),
   m_imgB(),
   m_numMeasurements(0),
   m_maxMatches(5),
   m_spIndexA(0),
   m_spIndexB(1),
   m_patchSizeA(),
   m_patchSizeB(),
   m_validBox(false),   
   m_useGrid(false),
   m_showCvWindow(false),
   m_patchRefA(),
   m_patchRefB(),
   m_measA(),
   m_measB(),
   m_distEditFactor(0),
   m_detectorName("ORB"),
   m_detector(),
   m_extractorName("FREAK"),
   m_extractor(),
   m_matcherName("BruteForce-Hamming"),
   m_matcher(),
   m_rep(0),
   m_maxCvWindowDim(500),
   m_cvWindowName("Correlation Patch")
{
   if (traceExec())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "\nDEBUG: ...ossimTieMeasurementGenerator::constructor" << std::endl;
   }
}


//*****************************************************************************
//  METHOD: ossimTieMeasurementGenerator::ossimTieMeasurementGenerator()
//  
//  Initializer.
//*****************************************************************************
bool ossimTieMeasurementGenerator::init(std::ostream& report)
{
   if (traceExec())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG: ...ossimTieMeasurementGenerator::init" << std::endl;
   }

   m_initOK = true;
   ossimString ts;
   ossim::getFormattedTime("%a %m.%d.%y %H:%M:%S", false, ts);

   m_rep = &report;


   // Initial report output
   *m_rep << "\nossimTieMeasurementGenerator Report     ";
   *m_rep << ts;
   *m_rep << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
   *m_rep << std::endl;
 
   // Set default grid size
   setGridSize(ossimIpt(1,1));

   try{
   // Set default detector, extractor, matcher
      setFeatureDetector(m_detectorName);
      setDescriptorExtractor(m_extractorName);
      setDescriptorMatcher(m_matcherName);

   }
   catch(...)
   {
      m_initOK = false;
   }

   return m_initOK;
}


//*****************************************************************************
//  DESTRUCTOR: ~ossimTieMeasurementGenerator()
//  
//*****************************************************************************
ossimTieMeasurementGenerator::~ossimTieMeasurementGenerator()
{
   if (traceExec())  ossimNotify(ossimNotifyLevel_DEBUG)
      << "DEBUG: ~ossimTieMeasurementGenerator(): returning..." << std::endl;
}


//*****************************************************************************
//  METHOD: ossimTieMeasurementGenerator::refreshCollectionTraits()
//  
//  Collection trait initializer.
//*****************************************************************************
bool ossimTieMeasurementGenerator::refreshCollectionTraits()
{
   bool initOK = true;

   if (m_useGrid)
   {
      int gridRows = m_gridSize.y;
      int gridCols = m_gridSize.x;
      cv::ORB::create("");
   }

   return initOK;
}


//*****************************************************************************
//  METHOD: ossimTieMeasurementGenerator::run()
//  
//  
//*****************************************************************************
bool ossimTieMeasurementGenerator::run()
{
   bool runOK = true;

   // Refresh collection traits before run
   runOK = refreshCollectionTraits();
   if(!m_detector) runOK = false;
   if(!m_extractor) runOK = false;
   if (runOK)
   {
      // ossimIrect constructor center-based constructor
      //    -> center view coordinates: m_patchRefA,m_patchRefB
      ossimIrect rectA(m_patchRefA, m_patchSizeA.x, m_patchSizeA.y);
      ossimIrect rectB(m_patchRefB, m_patchSizeB.x, m_patchSizeB.y);
      
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "DEBUG: ...ossimTieMeasurementGenerator::run" << std::endl;
         ossimNotify(ossimNotifyLevel_DEBUG)<<" m_patchRefA: "<<m_patchRefA<<" size: "<<m_patchSizeA<<std::endl; 
         ossimNotify(ossimNotifyLevel_DEBUG)<<" m_patchRefB: "<<m_patchRefB<<" size: "<<m_patchSizeB<<std::endl; 
         ossimNotify(ossimNotifyLevel_DEBUG)<<" rectA = "<<rectA<<endl;
         ossimNotify(ossimNotifyLevel_DEBUG)<<" rectB = "<<rectB<<endl;
         ossimNotify(ossimNotifyLevel_DEBUG)<<" m_src A ossimScalarType = "<<m_src[m_spIndexA]->getOutputScalarType()<<endl;
         ossimNotify(ossimNotifyLevel_DEBUG)<<" m_src B ossimScalarType = "<<m_src[m_spIndexB]->getOutputScalarType()<<endl;
      }

{'fraction_non_alphanumeric': 0.2880027266530334, 'fraction_numerical': 0.0034083162917518746, 'mean_word_length': 4.080952380952381, 'pattern_counts': {'":': 0, '<': 175, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3509781', 'n_tokens_mistral': 3828, 'n_tokens_neox': 3606, 'n_words': 544}