예제 #1
0
void Valgrind::OnMemCheck(wxCommandEvent& )
{
	wxString ExeTarget;
	wxString CommandLineArguments;
	if(!CheckRequirements(ExeTarget, CommandLineArguments))
	{
		return;
	}
	long Version = DoValgrindVersion();
	const wxString XmlOutputFile = _T("ValgrindOut.xml");
	wxString XmlOutputCommand;
	if(Version >= 350)
	{
		XmlOutputCommand = _T(" --xml-file=") + XmlOutputFile;
	}
	const bool UseXml = true;
	wxString CommandLine = _T("valgrind --leak-check=yes --xml=yes") + XmlOutputCommand + _T(" \"")
		+ ExeTarget + _T("\" ") + CommandLineArguments;
//	CommandLine = _("valgrind --leak-check=yes \"") + ExeTarget + _("\" ") + CommandLineArguments;
	AppendToLog(CommandLine);
	wxArrayString Output, Errors;
	wxExecute(CommandLine, Output, Errors);
	size_t Count = Output.GetCount();
	for(size_t idxCount = 0; idxCount < Count; ++idxCount)
	{
		// EXTRA NOTE : it seems the output from valgrind comes on the error channel, not here !!!
		// it seems that all valgrind stuff starts with == (in case of not xml)
		// filter on that, so we can remove regular output from the tested exe
//		if(Output[idxCount].StartsWith(_("==")))
		{
			AppendToLog(Output[idxCount]);
		}
	} // end for : idx: idxCount
	wxString Xml;
	Count = Errors.GetCount();
	for(size_t idxCount = 0; idxCount < Count; ++idxCount)
	{
		Xml += Errors[idxCount];
		AppendToLog(Errors[idxCount]);
	} // end for : idx: idxCount
	if(UseXml)
	{
		TiXmlDocument Doc;
		if(Version >= 350)
		{
			Doc.LoadFile(XmlOutputFile.ToAscii());
		}
		else
		{
			Doc.Parse(Xml.ToAscii());
		}
		if(!Doc.Error())
		{
			bool ErrorsPresent = false;
			TiXmlHandle Handle(&Doc);
			Handle = Handle.FirstChildElement("valgrindoutput");
			for(const TiXmlElement* Error = Handle.FirstChildElement("error").ToElement(); Error;
					Error = Error->NextSiblingElement("error"))
			{
				ErrorsPresent = true;
				wxString WhatValue;
				if(const TiXmlElement* What = Error->FirstChildElement("xwhat"))
				{	// style use since Valgrind 3.5.0
					if(const TiXmlElement* Text = What->FirstChildElement("text"))
					{
						WhatValue = wxString::FromAscii(Text->GetText());
					}
				}
				else if(const TiXmlElement* What = Error->FirstChildElement("what"))
				{
					WhatValue = wxString::FromAscii(What->GetText());
				}
				// process the first stack
				if(const TiXmlElement* Stack = Error->FirstChildElement("stack"))
				{
					ProcessStack(*Stack, WhatValue);
				}
			} // end for
			if(ErrorsPresent)
			{
				if(Manager::Get()->GetLogManager())
				{
					CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_ListLog);
					Manager::Get()->ProcessEvent(evtSwitch);
				}
			}
		}
		// loop over the errors
	}
} // end of OnMemCheck
예제 #2
0
파일: mser.cpp 프로젝트: autosquid/openMVG
      /**
      * @brief Extract MSER regions
      * @param img Input image
      * @param[out] regions Output regions
      */
      void MSERExtractor::Extract( const image::Image<unsigned char> & img , std::vector<MSERRegion> & regions ) const
      {
        // Compute minimum and maximum region area relative to this image
        const int minRegArea = img.Width() * img.Height() * m_minimum_area;
        const int maxRegArea = img.Width() * img.Height() * m_maximum_area;

        // List of processed pixels (maybe we can use a more efficient structure)
        std::vector<std::vector<bool >> processed;
        processed.resize( img.Width() );
        for (int i = 0; i < img.Width(); ++i )
        {
          processed[ i ].resize( img.Height() );
          std::fill( processed[ i ].begin() , processed[ i ].end() , false );
        }

        // Holds the boundary of given grayscale value (boundary[0] -> pixels in the boundary with 0 grayscale value)
        std::vector<PixelStackElt> boundary[ 256 ];

        // List of regions computed so far (not only valid MSER regions)
        std::vector<MSERRegion *> regionStack;

        // Push en empty region
        regionStack.push_back( new MSERRegion );

        // Start processing from top left pixel
        PixelStackElt cur_pix;
        cur_pix.pix_x = 0;
        cur_pix.pix_y = 0;
        cur_pix.pix_level = img( 0 , 0 );
        cur_pix.edge_index = PIXEL_RIGHT;

        processed[ cur_pix.pix_x ][ cur_pix.pix_y ] = true;

        regionStack.push_back( new MSERRegion( cur_pix.pix_level , cur_pix.pix_x , cur_pix.pix_y ) );

        int priority = 256;

        // Start process
        while (1)
        {
          bool restart = false;

          // Process neighboring to see if there's something to search with lower grayscale level
          for ( PixelNeighborsDirection curDir = cur_pix.edge_index;
                curDir <= PIXEL_BOTTOM_RIGHT;
                curDir = NextDirection( curDir , m_connectivity ) )
          {
            int nx , ny;
            GetNeighbor( cur_pix.pix_x , cur_pix.pix_y , curDir , img.Width() , img.Height() , nx , ny );

            // Pixel was not processed before
            if (ValidPixel( nx , ny , img.Width() , img.Height() ) && ! processed[ nx ][ ny ] )
            {
              const int nLevel = img( ny , nx );
              processed[ nx ][ ny ] = true;

              // Info of the neighboring pixel
              PixelStackElt n_elt;
              n_elt.pix_x = nx;
              n_elt.pix_y = ny;
              n_elt.pix_level = nLevel;
              n_elt.edge_index = PIXEL_RIGHT;

              // Now look from which pixel do we have to continue
              if (nLevel >= cur_pix.pix_level )
              {
                // Continue from the same pixel
                boundary[ nLevel ].push_back( n_elt );

                // Store the lowest value so far
                priority = std::min( nLevel , priority );
              }
              else
              {
                // Go on with the neighboring pixel (go down)
                cur_pix.edge_index = NextDirection( curDir , m_connectivity ); // Next time we have to process the next boundary pixel
                boundary[ cur_pix.pix_level ].push_back( cur_pix );

                // Store the lowest value so far
                priority = std::min( cur_pix.pix_level , priority );

                // Push the next pixel to process
                cur_pix = n_elt;
                restart = true;
                break;
              }
            }
          }
          // Do we have to restart from a new pixel ?
          if (restart )
          {
            // If so it's that because we found a lower grayscale value so let's start a new region
            regionStack.push_back( new MSERRegion( cur_pix.pix_level , cur_pix.pix_x , cur_pix.pix_y ) );
            continue;
          }

          // We have process all the neighboring pixels, current pixel is the lowest we have found so far
          // now process the current pixel
          regionStack.back()->AppendPixel( cur_pix.pix_x , cur_pix.pix_y );

          // End of the process : we have no boundary region, compute MSER from graph
          if (priority == 256 )
          {
            regionStack.back()->ComputeMSER( m_delta , minRegArea , maxRegArea , m_max_variation , m_min_diversity , regions );
            break;
          }

          PixelStackElt next_pix = boundary[ priority ].back();
          boundary[ priority ].pop_back();

          // Get the next pixel level
          while (boundary[ priority ].empty() && ( priority < 256 ))
          {
            ++priority;
          }

          // Clear the stack
          const int newLevel = next_pix.pix_level;

          // Process the current stack of pixels if the next processing pixel is not at the same curent level
          if (newLevel != cur_pix.pix_level )
          {
            // Try to merge the regions to fomr a tree
            ProcessStack( newLevel , next_pix.pix_x , next_pix.pix_y , regionStack );
          }

          // Update next pixel for processing
          cur_pix = next_pix;
        }

        // Clear region stack created so far
        for (size_t i = 0; i < regionStack.size(); ++i )
        {
          delete regionStack[ i ];
        }
      }
void Valgrind::ParseMemCheckXML(TiXmlDocument &Doc)
{
    if (Doc.Error())
        return;
    m_ListLog->Clear();

    wxArrayString Arr;
    int Errors = 0;
    TiXmlHandle Handle(&Doc);
    Handle = Handle.FirstChildElement("valgrindoutput");
    for (const TiXmlElement* Error = Handle.FirstChildElement("error").ToElement(); Error;
            Error = Error->NextSiblingElement("error"), Errors++)
    {
        wxString WhatValue, KindValue;
        if (const TiXmlElement* XWhat = Error->FirstChildElement("xwhat"))
        {	// style use since Valgrind 3.5.0
            if (const TiXmlElement* Text = XWhat->FirstChildElement("text"))
            {
                WhatValue = wxString::FromAscii(Text->GetText());
            }
        }
        else if (const TiXmlElement* What = Error->FirstChildElement("what"))
        {
            WhatValue = wxString::FromAscii(What->GetText());
        }
        if (const TiXmlElement *Kind = Error->FirstChildElement("kind"))
            KindValue = wxString::FromAscii(Kind->GetText());

        Arr.Clear();
        Arr.Add(KindValue);
        Arr.Add(wxT("===="));
        Arr.Add(WhatValue);
        m_ListLog->Append(Arr, Logger::error);

        // process the first stack
        const TiXmlElement* Stack = Error->FirstChildElement("stack");
        if (Stack)
        {
            ProcessStack(*Stack, true);
            if (const TiXmlElement *AuxWhat = Error->FirstChildElement("auxwhat"))
            {
                Arr.Clear();
                Arr.Add(wxEmptyString);
                Arr.Add(wxEmptyString);
                Arr.Add(wxString::FromAscii(AuxWhat->GetText()));
                m_ListLog->Append(Arr, Logger::warning);
            }
            Stack = Stack->NextSiblingElement("stack");
            if (Stack)
                ProcessStack(*Stack, false);
        }

    } // end for
    if (Errors > 0)
    {
        Arr.Clear();
        Arr.Add(wxEmptyString);
        Arr.Add(wxEmptyString);
        Arr.Add(wxString::Format(_("Valgrind found %d errors!"), Errors));
        m_ListLog->Append(Arr, Logger::error);

        if (Manager::Get()->GetLogManager())
        {
            CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_ListLog);
            Manager::Get()->ProcessEvent(evtSwitch);
        }
        m_ListLog->Fit();
    }
}