void FieldmapGeneratorFilter< OutputImageType >::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId)
{
    typename OutputImageType::Pointer outImage = static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
    ImageRegionIterator< OutputImageType > oit(outImage, outputRegionForThread);

    while( !oit.IsAtEnd() )
    {
        double value = 0;
        IndexType idx = oit.GetIndex();
        for (int i=0; i<3; i++)
            value += idx[i]*m_Gradient[i] + m_Offset[i];

        for (int i=0; i<m_WorldPositions.size(); i++)
        {
            mitk::Point3D c = m_WorldPositions.at(i);
            itk::Point<double, 3> vertex;
            outImage->TransformIndexToPhysicalPoint(idx, vertex);
            double dist = c.EuclideanDistanceTo(vertex);
            value += m_Heights.at(i)*exp(-dist*dist/(2*m_Variances.at(i)));
        }
        oit.Set(value);
        ++oit;
    }

    MITK_INFO << "Thread " << threadId << "finished processing";
}
  void QMCCostFunctionSingle::resetPsi()
  {

    OptimizableSetType::iterator oit(OptVariables.begin()), oit_end(OptVariables.end());
    while(oit != oit_end)
    {
      Return_t v=(*oit).second;
      OptVariablesForPsi[(*oit).first]=v;
      map<string,set<string>*>::iterator eit(equalConstraints.find((*oit).first));
      if(eit != equalConstraints.end())
      {
        set<string>::iterator f((*eit).second->begin()),l((*eit).second->end());
        while(f != l)
        {
          OptVariablesForPsi[(*f)]=v;
          ++f;
        }
      }
      ++oit;
    }

    //cout << "QMCCostFunctionSingle::resetPsi " <<endl;
    //oit=OptVariablesForPsi.begin();
    //oit_end=OptVariablesForPsi.end();
    //while(oit != oit_end)
    //{
    //  cout << (*oit).first << "=" << (*oit).second << " ";
    //  ++oit;
    //}
    //cout << endl;
    Psi.resetParameters(OptVariablesForPsi);
  }
Example #3
0
/*
In python:
>>> '海阔天空'.encode('utf-16')
b'\xff\xfewm\x14\x96)Yzz'
>>> '海阔天空'.encode('utf-16-le')
b'wm\x14\x96)Yzz'
>>> '海阔天空'.encode('utf-16-be')
b'mw\x96\x14Y)zz'
>>> chr(0x7a)
'z'
>>> chr(0x59)
'Y'

Output of this program: (Unicode mode)
GB2312: 海阔天空
77 6d 14 96 29 59 7a 7a
UTF-8 without BOM: 娴烽様澶╃┖
34 5a fd 70 d8 69 b6 6f 43 25 16 25
UTF-8 with BOM: 海阔天空
77 6d 14 96 29 59 7a 7a
UTF-16 BE: 海阔天空
77 6d 14 96 29 59 7a 7a
UTF-16 LE: 海阔天空
77 6d 14 96 29 59 7a 7a

So, windows uses UTF-16-LE to represent a string in UNICODE mode.
In non-unicode mode, cp936 is used.
*/
void dump(const _tstring &str)
{
    std::size_t wpos = str.rfind(_T(' '));
    if (_tstring::npos == wpos)
    {
        return;
    }

    const byte *beg = reinterpret_cast<const byte *>(str.c_str() + wpos + 1);
    const byte *end = reinterpret_cast<const byte *>(str.c_str() + str.size());

#if 0
    _tcout << std::hex;
    std::ostream_iterator<byte, _TCHAR> oit(_tcout, _T(" ")); // Caution
    std::copy(beg, end, oit);
    _tcout << std::dec << std::endl;
#else
    _tcout << std::setfill(_T('0')) << std::hex;
    for (const byte *p = beg; p != end; ++p)
    {
        if (*p <= 0x7f && std::isprint(static_cast<char>(*p)))
        {
            _tcout << static_cast<char>(*p);
        }
        else
        {
            // In non-unicode mode, if we want to print the value of '*p'
            // in hexadecimal format, we have to cast it into an integer.
            _tcout << _T("\\x") << std::setw(2) << static_cast<int>(*p);
        }
    }
    _tcout << std::setfill(_T(' ')) << std::dec << std::endl;
#endif
}
Example #4
0
void mitk::CLUtil::itkLogicalAndImages(const TImageType * image1, const mitk::Image::Pointer & image2, mitk::Image::Pointer & outimage)
{

  typename TImageType::Pointer itk_outimage = TImageType::New();
  itk_outimage->SetRegions(image1->GetLargestPossibleRegion());
  itk_outimage->SetDirection(image1->GetDirection());
  itk_outimage->SetOrigin(image1->GetOrigin());
  itk_outimage->SetSpacing(image1->GetSpacing());

  itk_outimage->Allocate();
  itk_outimage->FillBuffer(0);

  typename TImageType::Pointer itk_image2;
  mitk::CastToItkImage(image2,itk_image2);

  itk::ImageRegionConstIterator<TImageType> it1(image1, image1->GetLargestPossibleRegion());
  itk::ImageRegionConstIterator<TImageType> it2(itk_image2, itk_image2->GetLargestPossibleRegion());
  itk::ImageRegionIterator<TImageType> oit(itk_outimage,itk_outimage->GetLargestPossibleRegion());

  while(!it1.IsAtEnd())
  {
    if(it1.Value() == 0 || it2.Value() == 0)
    {
      oit.Set(0);
    }else
      oit.Set(it1.Value());
    ++it1;
    ++it2;
    ++oit;
  }

  mitk::CastToMitkImage(itk_outimage, outimage);
}
Example #5
0
bool ApsHandler::savePrinterDriver(KMPrinter *prt, PrintcapEntry *entry, DrMain *driver, bool*)
{
	if (driver->get("gsdriver").isEmpty())
	{
		manager()->setErrorMsg(i18n("The APS driver is not defined."));
		return false;
	}
	TQFile	f(sysconfDir() + "/" + prt->printerName() + "/apsfilterrc");
	if (f.open(IO_WriteOnly))
	{
		TQTextStream	t(&f);
		t << "# File generated by TDEPrint" << endl;
		t << "PRINTER='" << driver->get("gsdriver") << "'" << endl;
		TQValueStack<DrGroup*>	stack;
		stack.push(driver);
		while (stack.count() > 0)
		{
			DrGroup	*grp = stack.pop();
			TQPtrListIterator<DrGroup>	git(grp->groups());
			for (; git.current(); ++git)
				stack.push(git.current());
			TQPtrListIterator<DrBase>	oit(grp->options());
			TQString	value;
			for (; oit.current(); ++oit)
			{
				value = oit.current()->valueText();
				switch (oit.current()->type())
				{
					case DrBase::Boolean:
						if (value == "true")
							t << oit.current()->name() << "='" << value << "'" << endl;
						break;
					case DrBase::List:
						if (value != "(empty)")
							t << oit.current()->name() << "='" << value << "'" << endl;
						break;
					case DrBase::String:
						if (!value.isEmpty())
							t << oit.current()->name() << "='" << value << "'" << endl;
						break;
					default:
						break;
				}
			}
		}
		return true;
	}
	else
	{
		manager()->setErrorMsg(i18n("Unable to create the file %1.").arg(f.name()));
		return false;
	}
}
Example #6
0
DrBase *DrGroup::clone()
{
    DrGroup *grp = static_cast< DrGroup * >(DrBase::clone());

    QPtrListIterator< DrGroup > git(m_subgroups);
    for(; git.current(); ++git)
        grp->addGroup(static_cast< DrGroup * >(git.current()->clone()));

    QPtrListIterator< DrBase > oit(m_listoptions);
    for(; oit.current(); ++oit)
        grp->addOption(oit.current()->clone());

    return static_cast< DrBase * >(grp);
}
 virtual PyObject *populate(const Populator &populator) {
   npy_intp fdims[] = {(npy_intp)populator.size()};
   PyObject *array = NULL;
   array = (PyObject*)PyArray_SimpleNew(1, fdims, numpy_type<value_type>::id);
   try {
     string_array_output_iterator oit((PyArrayObject*)array);
     populator.insert_and_forget(oit);
   }
   catch (...) {
     Py_XDECREF(array);
     array = NULL;
     std::rethrow_exception(std::current_exception());
   }
   return array;
 }
Example #8
0
/**
 * @brief Writes to file associated with the calling object. If a valid key
 *        is available, data is encrypted (AES-GCM) prior to writing.
 *
 * @param ss const reference to a string stream with data.
 * @param key const reference to a byte vector with the encryption key.
 *
 * @return true, if data was sucessfully written to file.
 */
bool FileCryptopp::writeFile(
    const std::stringstream& ss,
    const std::vector<uint8_t>& key
) {

    // Start a file stream.
    std::ofstream fileStream(_filename, std::ios::binary);

    // Check if file stream is open.
    if (!fileStream.is_open()) {
        return false;
    }

    // Initialize an ostream_iterator to write to the file stream.
    std::ostream_iterator<uint8_t> oit(fileStream);

    // Check if encyption key is provided.
    if (!key.empty()) {
        // Check if encryption key has length equal to default AES key length.
        if (key.size() != FileCryptopp::AESNODE_DEFAULT_KEY_LENGTH_BYTES) {
            // Invalid key.
            std::cout << "Invalid key length";
            return false;
        }

        // Vector to store encrypted bytes of data.
        std::vector<uint8_t> cipherData;

        // Attempt to encrypt input stream ss and load bytes into cipherData.
        if (!encrypt(ss, cipherData, key)) {
            // Failed encryption.
            return false;
        }
        // Write encrypted bytes from cipherData to file as chars.
        std::copy(cipherData.begin(), cipherData.end(), oit);
    } else {
        // Write to file without encryption.
        fileStream << ss.str();
    }

    fileStream.close();
	return true;
}
Example #9
0
int main()
{
  Site_vector input, output;
  Site site;

  std::back_insert_iterator<Site_vector> oit(output);

  while (std::cin >> site) { input.push_back(site); }

  oit = CGAL::make_degenerate(input.begin(), input.end(), oit, Traits());

  std::cout << std::setprecision(17);
  for (std::vector<Site>::iterator it = output.begin();
       it != output.end(); ++it)
    {
      std::cout << (*it) << std::endl;
    }

  return 0;
}
void
ImageProcessing::convertBuffer( FrameBuffer const * frame, 
				FrameBuffer * outFrame, 
				unsigned int subSample )
{
  FrameBufferIterator it( frame );
  FrameBufferIterator oit( outFrame );
  RawPixel pPixel;

  for( unsigned int row = 0; row < frame->height; row = row + subSample )
    {
      it.goPosition( row, 0 );
      oit.goPosition(row, 0 );

      for( unsigned int col = subSample; col < frame->width; col = col + subSample, it.goRight( subSample ), oit.goRight( subSample ) )
	{
	  it.getPixel( & pPixel );
	  oit.setPixel( pPixel );
	}
    }
}
Example #11
0
/**
 * Resolve the types referenced by our UMLEntityAttributes.
 * Reimplements the method from UMLClassifier.
 */
bool UMLEntity::resolveRef()
{
    bool success = UMLClassifier::resolveRef();
    for (UMLObjectListIt oit(m_List); oit.hasNext(); ) {
        UMLObject* obj = oit.next();
        if (obj->resolveRef()) {
            UMLClassifierListItem *cli = static_cast<UMLClassifierListItem*>(obj);
            switch (cli->baseType() ) {
                case UMLObject::ot_EntityAttribute:
                    emit entityAttributeAdded(cli);
                    break;
                case UMLObject::ot_UniqueConstraint:
                case UMLObject::ot_ForeignKeyConstraint:
                    emit entityConstraintAdded(cli);
                    break;
                default:
                    break;
            }
        }
    }
    return success;
}
Example #12
0
void DrGroup::flattenGroup(QMap< QString, DrBase * > &optmap, int &index)
{
    QPtrListIterator< DrGroup > git(m_subgroups);
    for(; git.current(); ++git)
        git.current()->flattenGroup(optmap, index);

    QDictIterator< DrBase > oit(m_options);
    for(; oit.current(); ++oit)
        optmap[oit.current()->name()] = oit.current();

    if(name().isEmpty())
        optmap[QString::fromLatin1("group%1").arg(index++)] = this;
    else
        optmap[name()] = this;

    m_subgroups.setAutoDelete(false);
    m_options.setAutoDelete(false);
    m_subgroups.clear();
    m_options.clear();
    m_listoptions.clear();
    m_subgroups.setAutoDelete(true);
    m_options.setAutoDelete(true);
}
Example #13
0
void KXmlCommandAdvancedDlg::parseGroupItem(DrGroup *grp, TQListViewItem *parent)
{
	TQListViewItem	*item(0);

	TQPtrListIterator<DrGroup>	git(grp->groups());
	for (; git.current(); ++git)
	{
		TQString	namestr = git.current()->name();
		if (namestr.isEmpty())
		{
			namestr = "group_"+kapp->randomString(4);
		}
		git.current()->setName(namestr);
		item = new TQListViewItem(parent, item, git.current()->get("text"), git.current()->name());
		item->setPixmap(0, SmallIcon("folder"));
		item->setOpen(true);
		item->setRenameEnabled(0, true);
		parseGroupItem(git.current(), item);
		m_opts[namestr] = git.current();
	}

	TQPtrListIterator<DrBase>	oit(grp->options());
	for (; oit.current(); ++oit)
	{
		TQString	namestr = oit.current()->name().mid(m_xmlcmd->name().length()+6);
		if (namestr.isEmpty())
		{
			namestr = "option_"+kapp->randomString(4);
		}
		oit.current()->setName(namestr);
		item = new TQListViewItem(parent, item, oit.current()->get("text"), namestr);
		item->setPixmap(0, SmallIcon("document"));
		item->setRenameEnabled(0, true);
		m_opts[namestr] = oit.current();
	}
}
Example #14
0
void mitk::CLUtil::itkInterpolateCheckerboardPrediction(TImageType * checkerboard_prediction, Image::Pointer &checkerboard_mask, mitk::Image::Pointer & outimage)
{
  typename TImageType::Pointer itk_checkerboard_mask;
  mitk::CastToItkImage(checkerboard_mask,itk_checkerboard_mask);

  typename TImageType::Pointer itk_outimage = TImageType::New();
  itk_outimage->SetRegions(checkerboard_prediction->GetLargestPossibleRegion());
  itk_outimage->SetDirection(checkerboard_prediction->GetDirection());
  itk_outimage->SetOrigin(checkerboard_prediction->GetOrigin());
  itk_outimage->SetSpacing(checkerboard_prediction->GetSpacing());
  itk_outimage->Allocate();
  itk_outimage->FillBuffer(0);

  //typedef typename itk::ShapedNeighborhoodIterator<TImageType>::SizeType SizeType;
  typedef itk::Size<3> SizeType;
  SizeType size;
  size.Fill(1);
  itk::ShapedNeighborhoodIterator<TImageType> iit(size,checkerboard_prediction,checkerboard_prediction->GetLargestPossibleRegion());
  itk::ShapedNeighborhoodIterator<TImageType> mit(size,itk_checkerboard_mask,itk_checkerboard_mask->GetLargestPossibleRegion());
  itk::ImageRegionIterator<TImageType> oit(itk_outimage,itk_outimage->GetLargestPossibleRegion());

  typedef typename itk::ShapedNeighborhoodIterator<TImageType>::OffsetType OffsetType;
  OffsetType offset;
  offset.Fill(0);
  offset[0] = 1;       // {1,0,0}
  iit.ActivateOffset(offset);
  mit.ActivateOffset(offset);
  offset[0] = -1;      // {-1,0,0}
  iit.ActivateOffset(offset);
  mit.ActivateOffset(offset);
  offset[0] = 0; offset[1] = 1; //{0,1,0}
  iit.ActivateOffset(offset);
  mit.ActivateOffset(offset);
  offset[1] = -1;      //{0,-1,0}
  iit.ActivateOffset(offset);
  mit.ActivateOffset(offset);

  //    iit.ActivateOffset({{0,0,1}});
  //    iit.ActivateOffset({{0,0,-1}});
  //    mit.ActivateOffset({{0,0,1}});
  //    mit.ActivateOffset({{0,0,-1}});

  while(!iit.IsAtEnd())
  {
    if(mit.GetCenterPixel() == 0)
    {
      typename TImageType::PixelType mean = 0;
      for (auto i = iit.Begin(); ! i.IsAtEnd(); i++)
      { mean += i.Get(); }


      //std::sort(list.begin(),list.end(),[](const typename TImageType::PixelType x,const typename TImageType::PixelType y){return x<=y;});

      oit.Set((mean+0.5)/6.0);
    }
    else
    {
      oit.Set(iit.GetCenterPixel());
    }
    ++iit;
    ++mit;
    ++oit;
  }

  mitk::CastToMitkImage(itk_outimage,outimage);
}
Example #15
0
/* generic algorithms
 * algorithm never execute container operations
 */
static int test_generic_algorithm()
{
    std::string s("hello world");

    //find
    auto ret = std::find(s.cbegin(), s.cend(), 'k');
    if (ret != s.cend())
        cout << *ret << endl;

    int a[] = { 13, 2, 72, 13, 38};
    auto ret2 = std::find(std::begin(a), std::end(a), 72);
#if _cplusplus > 201103L
    if (ret2 != std::cend(a))
        cout << *ret2 << endl;
#endif
    //accumulate
    auto sum = std::accumulate(std::begin(a), std::end(a), 0);
    cout << sum << endl;

    //equal
    std::array<int, sizeof(a) / sizeof(*a)> a2{13, 2};
    auto ret4 = std::equal(std::begin(a), std::end(a), a2.begin());
    cout << ret4 << endl;

    //fill
    std::fill(a2.begin(), a2.end(), 8);

    //fill_n
    vector<int> vec;
    auto it = std::back_inserter(vec);
    *it = 32;

    std::fill_n(std::back_inserter(vec), 10, 0);
    cout << "vec size is " << vec.size() << endl;

    //copy
    vec.resize(0);
    std::copy(std::begin(a), std::end(a), back_inserter(vec));

    //replace
    std::replace(vec.begin(), vec.end(), 13, 28);

    //replace_copy
    vec.resize(0);
    std::replace_copy(std::begin(a), std::end(a), back_inserter(vec), 13, 28);

    string input_text{"the quick red fox jumps over the slow red turtle"};
    vector<string> story_text;
    std::stringstream input_st(input_text);
    string si;
    while (input_st >> si) {
        story_text.push_back(si);
    }

    //sort
    std::sort(story_text.begin(), story_text.end());

    //unique
    auto ret5 = std::unique(story_text.begin(), story_text.end());
    story_text.erase(ret5, story_text.end());

    print(story_text);

    vector<string> story_text_2;
    std::copy(story_text.begin(), story_text.end(), std::back_inserter(story_text_2));
    std::stable_sort(story_text.begin(), story_text.end(), isShorter);
    std::sort(story_text_2.begin(), story_text_2.end(), isShorter);
    print(story_text);
    print(story_text_2);

    auto ret6 = biggies(story_text_2, 4);
    std::for_each(ret6, story_text_2.cend(), [](const string &s)->void {cout << s << " "; });
    cout << endl;

    //lambda
    {
        int i1 = 1;
        int ii = 10;
        {
            /*const*/ int i2 = 2;
            int ii = 20;
            auto f = [=, &i2] ()  mutable {cout << ++ii <<  " " << ++i2 << endl; };
            f();
        }
    }

    //bind
    test_bind();

    //insert iterator
    {
        std::list<int> lst = { 1, 2, 3, 4 };
        std::deque<int> lst2, lst3;
        std::copy(lst.begin(), lst.end(), std::front_inserter(lst2));

        *std::front_inserter(lst2) = 5;
        *std::back_inserter(lst2) = 0;
        *std::inserter(lst2, lst2.begin()+ (lst2.end()-lst2.begin())/2) = 10;

        for_each(lst2.begin(), lst2.end(), [](int v) {cout << v << " "; });
        cout << endl;
    }

    //istream/ostream iterator
    {
        std::ostream_iterator<int> oit(cout, " ");
        oit = 1;
        *oit = 2;
        cout << endl;
        std::vector<int> vec= { 1, 2, 3, 4, 5 };
        std::copy(vec.begin(), vec.end(), oit);
        cout << endl;

        //	std::istream_iterator<int> iit(cin);
        //	std::istream_iterator<int> eof;

//		iit++;	//在这里要输入两次, 因为++ --是读取下一个值,在读取下一个值之前,先要读取得到当前值
//      int n = -1;
//      n = *iit++;
//      cout << n << endl;
//
//      assert(++iit == eof);

//      cout << "begin loop" << endl;
//      vec.clear();
//      int vec_size;
//      while (iit != eof) {
//          vec.push_back(*iit++);
//          vec_size = vec.size();
//      }
//      std::copy(vec.begin(), vec.end(), oit);
//      cout << endl;
    }

    //reverse iterator
    {
        string line{"first, middle, last"};
        auto it = std::find(line.cbegin(), line.cend(), ',');
        cout << string(line.cbegin(), it) << endl;

        auto rit = std::find(line.crbegin(), line.crend(), ',');
        cout << string(rit.base(), line.cend()) << endl;	//base成员函数得到正向的迭代器
    }

    return 0;
}
    void DiffusionOdfPrepareVisualizationImageFilter< TOdfPixelType,
    NrOdfDirections>
    ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
    ThreadIdType )
  {
    typename OutputImageType::Pointer outputImage =
      static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
    ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
    oit.GoToBegin();

    typedef itk::OrientationDistributionFunction<TOdfPixelType,NrOdfDirections> OdfType;
    typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
    typedef typename InputImageType::PixelType         OdfVectorType;
    typename InputImageType::Pointer inputImagePointer = nullptr;
    inputImagePointer = static_cast< InputImageType * >(
      this->ProcessObject::GetInput(0) );
    InputIteratorType git(inputImagePointer, outputRegionForThread );
    git.GoToBegin();

    typedef ImageRegionConstIterator< GfaImageType > GfaIteratorType;
    GfaIteratorType gfaIt(m_GfaImage, outputRegionForThread);

    while( !git.IsAtEnd() )
    {
      OdfVectorType b = git.Get();
      OdfType odf = b.GetDataPointer();

      switch( m_NormalizationMethod )
      {
      case PV_NONE:
        {
          break;
        }
      case PV_MAX:
        {
          odf = odf.MaxNormalize();
          break;
        }
      case PV_MIN_MAX:
        {
          odf = odf.MinMaxNormalize();
          break;
        }
      case PV_GLOBAL_MAX:
        {
          odf *= 1.0/m_GlobalInputMaximum;
          break;
        }
      case PV_MIN_MAX_INVERT:
        {
          odf = odf.MinMaxNormalize();
          for(int i=0; i<NrOdfDirections; i++)
          {
            odf[i] = 1.0 - odf[i];
          }
          break;
        }
      }

      if(m_DoScaleGfa)
      {
        odf *= gfaIt.Get();
        ++gfaIt;
      }

      odf *= 0.5;
      oit.Set( odf.GetDataPointer() );
      ++oit;
      ++git; // Gradient  image iterator
    }

    std::cout << "One Thread finished extraction" << std::endl;
  }
void
ImageProcessing::SegmentColours( FrameBuffer * frame, 
				 FrameBuffer * outFrame, 
				 unsigned int threshold, 
				 unsigned int minLength,
				 unsigned int minSize,
				 unsigned int subSample,
				 ColourDefinition const & target,
				 RawPixel const & mark,
				 std::vector<VisionObject> & results
				 )
{
  FrameBufferIterator it( frame );
  FrameBufferIterator oit( outFrame );
  Pixel cPixel;
  RawPixel oPixel;
  //  unsigned int len;
  FloodFillState state;
  unsigned int count;
  
  for( unsigned int row = 0; row < frame->height; row = row + subSample )
    {
      it.goPosition(row, subSample);
      oit.goPosition(row, subSample);

      count = 0;
      for( unsigned int col = subSample; col < frame->width; col = col + subSample, it.goRight( subSample ),oit.goRight( subSample ) )
	{
	  oit.getPixel( & oPixel );
	  if ( oPixel == RawPixel( 0, 0, 0 ) )
	    {
	      it.getPixel( & cPixel );
	      
	      if ( target.isMatch( cPixel ) )
		{
		  count++;
		}
	      else
		{
		  count = 0;
		}
	      
	      if ( count >= minLength )
		{
		  state.initialize();
		  doFloodFill( frame, outFrame, Point( col, row), 
			       cPixel, threshold, & target, 
			       subSample, & state );
		  
#ifdef XX_DEBUG
		  if ( state.size() > minSize )
		    {
		      std::cout << "Flood fill returns size " << state.size() << std::endl;
		    }
#endif
		  if ( state.size() > minSize )
		    {
		      unsigned int tlx = state.bBox().topLeft().x();
		      unsigned int tly = state.bBox().topLeft().y();
		      unsigned int brx = state.bBox().bottomRight().x();
		      unsigned int bry = state.bBox().bottomRight().y();
		      
		      drawBresenhamLine( outFrame, tlx, tly, tlx, bry, mark );
		      drawBresenhamLine( outFrame, tlx, bry, brx, bry, mark );
		      drawBresenhamLine( outFrame, brx, bry, brx, tly, mark );
		      drawBresenhamLine( outFrame, brx, tly, tlx, tly, mark );

		      drawBresenhamLine( frame, tlx, tly, tlx, bry, mark );
		      drawBresenhamLine( frame, tlx, bry, brx, bry, mark );
		      drawBresenhamLine( frame, brx, bry, brx, tly, mark );
		      drawBresenhamLine( frame, brx, tly, tlx, tly, mark );
		      //		      swapColours( outFrame, 0, state.bBox(), 1, ColourDefinition( Pixel(colour), Pixel(colour) ), state.averageColour() );
		      VisionObject vo( target.name, state.size(), state.x(), state.y(), state.averageColour(), state.bBox() );

		      std::vector<VisionObject>::iterator i;

		      for( i = results.begin();
			   i != results.end();
			   ++i)
			{
			  if ( (*i).size < vo.size )
			    {
			      break;
			    }
			}
		      results.insert(i, vo );
		    }
		  count = 0;
		}
	    }
	  else
	    {
	      count = 0;
	    }
	}
    }
}
Example #18
0
QMimeSource* UMLClipboard::copy(bool fromView/*=false*/) {
    //Clear previous copied data
    m_AssociationList.clear();
    m_ItemList.clear();
    m_ObjectList.clear();
    m_ViewList.clear();

    UMLDrag *data = 0;
    QPixmap* png = 0;

    UMLListView * listView = UMLApp::app()->getListView();
    UMLListViewItemList selectedItems;
    selectedItems.setAutoDelete(false);

    if(fromView) {
        m_type = clip4;
        UMLView *view = UMLApp::app()->getCurrentView();
        view->checkSelections();
        if(!view->getSelectedWidgets(m_WidgetList)) {
            return 0;
        }
        //if there is no selected widget then there is no copy action
        if(!m_WidgetList.count()) {
            return 0;
        }
        m_AssociationList = view->getSelectedAssocs();
        view->copyAsImage(png);

    } else { //if the copy action is being performed from the ListView
        if(!listView->getSelectedItems(selectedItems)) {
            return 0;
        }
        //Set What type of copy operation are we performing and
        //also fill m_ViewList with all the selected Diagrams
        setCopyType(selectedItems);

        //if we are copying a diagram or part of a diagram, select the items
        //on the ListView that correspond to a UseCase, Actor or Concept
        //in the Diagram
        if(m_type == clip2) {
            //Fill the member lists with all the object and stuff to be copied
            //to the clipboard
            selectedItems.clear();
            //For each selected view select all the Actors, USe Cases and Concepts
            //widgets in the ListView
            for (UMLViewListIt vit(m_ViewList); vit.current(); ++vit) {
                UMLObjectList objects = vit.current()->getUMLObjects();
                for (UMLObjectListIt oit(objects); oit.current(); ++oit) {
                    UMLObject *o = oit.current();
                    UMLListViewItem *item = listView->findUMLObject(o);
                    if(item) {
                        listView->setSelected(item, true);
                    }
                }
            }
            if(!listView->getSelectedItems(selectedItems)) {
                return 0;
            }
        }
        if(!fillSelectionLists(selectedItems)) {
            return 0;
        }
    }
    int i =0;
    switch(m_type) {
    case clip1:
        data = new UMLDrag(m_ObjectList);
        break;
    case clip2:
        data = new UMLDrag(m_ObjectList, m_ItemList, m_ViewList);
        break;
    case clip3:
        data = new UMLDrag(m_ItemList);
        break;
    case clip4:
        if(png) {
            UMLView *view = UMLApp::app()->getCurrentView();
            data = new UMLDrag(m_ObjectList, m_WidgetList,
                               m_AssociationList, *png, view->getType());
        } else {
            return 0;
        }
        break;
    case clip5:
        data = new UMLDrag(m_ObjectList, i);
        // The int i is used to differentiate
        // which UMLDrag constructor gets called.
        break;
    }

    return (QMimeSource*)data;
}
                void append_encoded_string(const std::string& data) {
                    boost::u8_to_u32_iterator<std::string::const_iterator> it(data.cbegin(), data.cbegin(), data.cend());
                    boost::u8_to_u32_iterator<std::string::const_iterator> end(data.cend(), data.cend(), data.cend());
                    boost::utf8_output_iterator<std::back_insert_iterator<std::string>> oit(std::back_inserter(*m_out));

                    for (; it != end; ++it) {
                        uint32_t c = *it;

                        // This is a list of Unicode code points that we let
                        // through instead of escaping them. It is incomplete
                        // and can be extended later.
                        // Generally we don't want to let through any character
                        // that has special meaning in the OPL format such as
                        // space, comma, @, etc. and any non-printing characters.
                        if ((0x0021 <= c && c <= 0x0024) ||
                            (0x0026 <= c && c <= 0x002b) ||
                            (0x002d <= c && c <= 0x003c) ||
                            (0x003e <= c && c <= 0x003f) ||
                            (0x0041 <= c && c <= 0x007e) ||
                            (0x00a1 <= c && c <= 0x00ac) ||
                            (0x00ae <= c && c <= 0x05ff)) {
                            *oit = c;
                        } else {
                            *m_out += '%';
                            output_formatted("%04x", c);
                        }
                    }
                }