Пример #1
0
void SvmTrain::train() {
    svm_ = cv::ml::SVM::create();
    svm_->setType(cv::ml::SVM::C_SVC);
    svm_->setKernel(cv::ml::SVM::RBF);
    svm_->setDegree(0.1);
    // 1.4 bug fix: old 1.4 ver gamma is 1
    svm_->setGamma(0.1);
    svm_->setCoef0(0.1);
    svm_->setC(1);
    svm_->setNu(0.1);
    svm_->setP(0.1);
    svm_->setTermCriteria(cvTermCriteria(CV_TERMCRIT_ITER, 100000, 0.00001));

    auto train_data = tdata();

    fprintf(stdout, ">> Training SVM model, please wait...\n");
    long start = utils::getTimestamp();
    //svm_->trainAuto(train_data, 10, SVM::getDefaultGrid(SVM::C),
    //                SVM::getDefaultGrid(SVM::GAMMA), SVM::getDefaultGrid(SVM::P),
    //                SVM::getDefaultGrid(SVM::NU), SVM::getDefaultGrid(SVM::COEF),
    //                SVM::getDefaultGrid(SVM::DEGREE), true);
    svm_->train(train_data);

    long end = utils::getTimestamp();
    fprintf(stdout, ">> Training done. Time elapse: %ldms\n", end - start);
    fprintf(stdout, ">> Saving model file...\n");
    svm_->save(svm_xml_);
    fprintf(stdout, ">> Your SVM Model was saved to %s\n", svm_xml_);
    fprintf(stdout, ">> Testing...\n");
    this->test();

}
Пример #2
0
void* write_func(void *data) {
    std::unique_ptr<TaskData> tdata((TaskData*)data);
    int epollfd = tdata->epollfd;
    epoll_event event = (tdata->event);
    CEpollSocketWatcher &socket_handler = *(tdata->watcher);

    CEpollContext *epoll_context = (CEpollContext *) event.data.ptr;
    int fd = epoll_context->fd;
    LOG_DEBUG("start write data");

    int ret = socket_handler.on_writeable(*epoll_context);
    if (ret == WRITE_CONN_CLOSE) {
        close_and_release(epollfd, event, socket_handler);
        return NULL;
    }

    if (ret == WRITE_CONN_CONTINUE) {
        event.events = EPOLLOUT;
    } else {
        event.events = EPOLLIN;
    }
    epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event);

    return NULL;
}
Пример #3
0
void* read_func(void *data) {
    std::unique_ptr<TaskData> tdata((TaskData*)data);
    int epollfd = tdata->epollfd;
    epoll_event event = (tdata->event);
    CEpollSocketWatcher &socket_handler = *(tdata->watcher);

    CEpollContext *epoll_context = (CEpollContext *) event.data.ptr;
    int fd = epoll_context->fd;

    int ret = socket_handler.on_readable(epollfd, event);
    if (ret == READ_CLOSE) {
        close_and_release(epollfd, event, socket_handler);
        return NULL;
    }
    if (ret == READ_CONTINUE) {
        event.events = EPOLLIN;
        epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event);
    } else if (ret == READ_OVER) { // READ_OVER
        event.events = EPOLLOUT;
        epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event);
    } else {
        LOG_ERROR("unkonw ret!");
    }

    return NULL;
}
Пример #4
0
static const char *hexcmp(const char *fn, const void *buf, unsigned int len)
{
	char hexbuf[256];
	size_t flen;
	char *fdata = load_file(tdata(fn), &flen);
	int cmp;

	if (!fdata)
		return strerror(errno);
	while (flen && isspace(fdata[flen-1]))
		flen--;
	fdata[flen] = 0;

	mkhex(buf, len, hexbuf);

	cmp = strcmp(hexbuf, fdata);
	free(fdata);
	return cmp ? "Fingerprint does not match" : NULL;
}
Пример #5
0
void AnnTrain::train() {
  cv::Mat layers(1, 3, CV_32SC1);
  layers.at<int>(0) = 120;                // the input layer
  layers.at<int>(1) = kNeurons;           // the neurons
  layers.at<int>(2) = kCharsTotalNumber;  // the output layer

  ann_->setLayerSizes(layers);
  ann_->setActivationFunction(cv::ml::ANN_MLP::SIGMOID_SYM, 1, 1);
  ann_->setTrainMethod(cv::ml::ANN_MLP::TrainingMethods::BACKPROP);
  ann_->setBackpropWeightScale(0.1);
  ann_->setBackpropMomentumScale(0.1);

  auto traindata = tdata();
  std::cout << "Training ANN model, please wait..." << std::endl;
  long start = utils::getTimestamp();
  ann_->train(traindata);
  long end = utils::getTimestamp();
  std::cout << "Training done. Time elapse: " << (end - start) << "ms"
            << std::endl;

  ann_->save(ann_xml_);
  std::cout << "Your ANN Model was saved to " << ann_xml_ << std::endl;
}
Пример #6
0
int main()
{
  AFile_AString tdata("Hello <aos:session>some/path</aos:session>");

  AAutoPtr<ATemplate> pTemplate(new ATemplate(), true);
  
  pTemplate->addHandler(new ATemplateNodeHandler_LUA());
  pTemplate->addHandler(new ATemplateNodeHandler_SESSION());

  pTemplate->fromAFile(tdata);
  
  AXmlDocument model("root");
  ABasePtrContainer objects;
  AEventVisitor visitor;
  ATemplateContext ctx(objects, model, visitor);

  pTemplate->debugDump();
  
  AString str;
  pTemplate->process(ctx, str);

  return 0;
}
Пример #7
0
RcppExport SEXP sumExpected(SEXP Rtdata, SEXP Rtabdata, SEXP Rrwmeans, SEXP Rnitems, SEXP Rncores)
{
    BEGIN_RCPP

    const IntegerMatrix tdata(Rtdata);
    const IntegerMatrix tabdata(Rtabdata);
    const NumericVector rwmeans(Rrwmeans);
    const int ncores = as<int>(Rncores);
    const int nitems = as<int>(Rnitems);
    const int N = tdata.ncol();
    const int n = tabdata.nrow();
    const int J = tdata.nrow();
    vector<double> expected(n);
    #ifdef SUPPORT_OPENMP
    omp_set_num_threads(ncores);
    #endif

#pragma omp parallel for
    for(int i = 0; i < n; ++i){
        int count = 0;
        double tempexp = 0.0;
        for(int NN = 0; NN < N; ++NN){
            int tmp = 0;
            for(int j = 0; j < J; ++j)
                tmp += tabdata(i, j) == tdata(j, NN);
            if(tmp == nitems){
                count += 1;
                tempexp = tempexp + rwmeans(NN);
            }
        }
        if(count) expected[i] = tempexp / count;
    }

    return(wrap(expected));

    END_RCPP
}
Пример #8
0
QByteArray TagReader::LoadEmbeddedArt(const QString& filename) const {
  if (filename.isEmpty()) return QByteArray();

  qLog(Debug) << "Loading art from" << filename;

#ifdef Q_OS_WIN32
  TagLib::FileRef ref(filename.toStdWString().c_str());
#else
  TagLib::FileRef ref(QFile::encodeName(filename).constData());
#endif

  if (ref.isNull() || !ref.file()) return QByteArray();

  // MP3
  TagLib::MPEG::File* file = dynamic_cast<TagLib::MPEG::File*>(ref.file());
  if (file && file->ID3v2Tag()) {
    TagLib::ID3v2::FrameList apic_frames =
        file->ID3v2Tag()->frameListMap()["APIC"];
    if (apic_frames.isEmpty()) return QByteArray();

    TagLib::ID3v2::AttachedPictureFrame* pic =
        static_cast<TagLib::ID3v2::AttachedPictureFrame*>(apic_frames.front());

    return QByteArray((const char*)pic->picture().data(),
                      pic->picture().size());
  }

  // Ogg vorbis/speex
  TagLib::Ogg::XiphComment* xiph_comment =
      dynamic_cast<TagLib::Ogg::XiphComment*>(ref.file()->tag());

  if (xiph_comment) {
    TagLib::Ogg::FieldListMap map = xiph_comment->fieldListMap();

    // Other than the below mentioned non-standard COVERART,
    // METADATA_BLOCK_PICTURE
    // is the proposed tag for cover pictures.
    // (see http://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE)
    if (map.contains("METADATA_BLOCK_PICTURE")) {
      TagLib::StringList pict_list = map["METADATA_BLOCK_PICTURE"];
      for (std::list<TagLib::String>::iterator it = pict_list.begin();
           it != pict_list.end(); ++it) {
        QByteArray data(QByteArray::fromBase64(it->toCString()));
        TagLib::ByteVector tdata(data.data(), data.size());
        TagLib::FLAC::Picture p(tdata);
        if (p.type() == TagLib::FLAC::Picture::FrontCover)
          return QByteArray(p.data().data(), p.data().size());
      }
      // If there was no specific front cover, just take the first picture
      QByteArray data(QByteArray::fromBase64(
          map["METADATA_BLOCK_PICTURE"].front().toCString()));
      TagLib::ByteVector tdata(data.data(), data.size());
      TagLib::FLAC::Picture p(tdata);
      return QByteArray(p.data().data(), p.data().size());
    }

    // Ogg lacks a definitive standard for embedding cover art, but it seems
    // b64 encoding a field called COVERART is the general convention
    if (!map.contains("COVERART")) return QByteArray();

    return QByteArray::fromBase64(map["COVERART"].toString().toCString());
  }

#ifdef TAGLIB_HAS_FLAC_PICTURELIST
  // Flac
  TagLib::FLAC::File* flac_file = dynamic_cast<TagLib::FLAC::File*>(ref.file());
  if (flac_file && flac_file->xiphComment()) {
    TagLib::List<TagLib::FLAC::Picture*> pics = flac_file->pictureList();
    if (!pics.isEmpty()) {
      // Use the first picture in the file - this could be made cleverer and
      // pick the front cover if it's present.

      std::list<TagLib::FLAC::Picture*>::iterator it = pics.begin();
      TagLib::FLAC::Picture* picture = *it;

      return QByteArray(picture->data().data(), picture->data().size());
    }
  }
#endif

  // MP4/AAC
  TagLib::MP4::File* aac_file = dynamic_cast<TagLib::MP4::File*>(ref.file());
  if (aac_file) {
    TagLib::MP4::Tag* tag = aac_file->tag();
    const TagLib::MP4::ItemListMap& items = tag->itemListMap();
    TagLib::MP4::ItemListMap::ConstIterator it = items.find("covr");
    if (it != items.end()) {
      const TagLib::MP4::CoverArtList& art_list = it->second.toCoverArtList();

      if (!art_list.isEmpty()) {
        // Just take the first one for now
        const TagLib::MP4::CoverArt& art = art_list.front();
        return QByteArray(art.data().data(), art.data().size());
      }
    }
  }

  return QByteArray();
}
Пример #9
0
void TTFont::make_subset(ISeqStreamOutput& subset_font,
                         UsedGlyphs const& used_glyphs,
                         bool include_cmap)
{
    TTFontMaker font_maker;
    font_maker.set_codepoint_to_glyph(used_glyphs.codepoint_to_glyph());


    // Iterate over the used glyphs and insert them to fontmaker. Construct
    // additonal_glyphs for those referenced from composite glyphs.
    typedef std::set<UInt16> Glyphs;
    Glyphs additional_glyphs;
    typedef UsedGlyphs::Glyphs::const_iterator GlyphIterator;
    GlyphIterator end = used_glyphs.glyphs_end();
    for(GlyphIterator it = used_glyphs.glyphs_begin(); it!=end; ++it)
    {
        // load the glyph and add it to font maker
        m_ttparser.load_glyph(*it);
        font_maker.add_glyph(m_ttparser.current_glyph_data(),
                             m_ttparser.current_glyph_size(),
                             *it);

        // inspect the glyph
        if (m_ttparser.current_glyph_size())
        {
            tt_glyph_data const* glyph_data =
                static_cast<tt_glyph_data const*>(m_ttparser.current_glyph_data());

            // is it a composite glyph?
            if (static_cast<short>(glyph_data->m_number_of_contours) < 0)
            {
                Byte const* curr =
                    static_cast<Byte const*>(m_ttparser.current_glyph_data()) + sizeof(tt_glyph_data);
                
                unsigned short flags;
                do {
                    flags = static_cast<unsigned short>(*reinterpret_cast<ubig16_t const*>(curr));
                    ubig16_t const* c_glyph_index = reinterpret_cast<ubig16_t const*>(curr+2);
                    curr += 4;
                    
                    // verify that the glyph is not already in the passed set,
                    if (!used_glyphs.glyphs().count(*c_glyph_index))
                        additional_glyphs.insert(*c_glyph_index);
                    
                    curr += flags & ARG_1_AND_2_ARE_WORDS ? 4 : 2;
                    if (flags & WE_HAVE_A_SCALE)
                        curr += 2;
                    
                    if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
                        curr += 4;
                    
                    if (flags & WE_HAVE_A_TWO_BY_TWO)
                        curr += 8;
                }
                while(flags & MORE_COMPONENTS);
            }
        }
    }
    
    if (!additional_glyphs.empty())
    {
        // upload the additional glyphs to fontmaker
        Glyphs::iterator endg = additional_glyphs.end();
        for(Glyphs::iterator it = additional_glyphs.begin(); it!=endg; ++it)
        {
            m_ttparser.load_glyph(*it);
            font_maker.add_glyph(m_ttparser.current_glyph_data(),
                                 m_ttparser.current_glyph_size(),
                                 *it);
        }
    }

    // The subset can contain no outlines, i.e it for instance could have only
    // spaces with varying widths. In such case the .notdef glyph (index 0) is
    // added to the subset. Otherwise, a missing glyf table causes problems for
    // e.g. Reader or certain FreeType versions.
    if (!font_maker.has_outlines())
    {
        // search through the first 255 glyph slots for one with glyph outlines
        UInt16 i = 0;
        const UInt16 NGLYPHS = 255;
        for(; i < NGLYPHS; ++i)
        {
            m_ttparser.load_glyph(i);
            if (m_ttparser.current_glyph_size())
            {
                font_maker.add_glyph(m_ttparser.current_glyph_data(),
                                     m_ttparser.current_glyph_size(),
                                     i);
                break;
            }
        }

        if (i >= NGLYPHS) {
            TRACE_WRN << "font subset has an empty glyph table";
        }
    }
    

    TTFontParser::TableData table_data(m_ttparser.load_table(TT_MAXP));
    font_maker.add_table(TT_MAXP, table_data.first, table_data.second);

    table_data = m_ttparser.load_table(TT_HEAD);
    font_maker.add_table(TT_HEAD, table_data.first, table_data.second);


    // spec (5.8) says that name, os2 and post should not be needed
    // but when really removed Acrobat does not behave well
    const int num_const_tables = 8;
    const TTTableType const_tables[num_const_tables] = {
        TT_NAME, TT_OS2, TT_CVT, TT_FPGM, TT_PREP, TT_HHEA, TT_HMTX, TT_POST
    };

    for (int i=0; i<num_const_tables; ++i)
    {
        TTFontParser::TableData tdata(m_ttparser.load_table(const_tables[i]));
        if (tdata.first)
            font_maker.add_table(const_tables[i], tdata.first, tdata.second);
    }

    // to FontMaker::add_glyph() signature
    font_maker.output(subset_font, include_cmap);
}
// ============================================================================
// pxpByteCode
// ============================================================================
pxpByteCode::pxpByteCode( pkgDecompiler* decompiler )
:   Decompiler(decompiler)
,   CToken(NULL)
,   CTokenTree(NULL)
,   CTokenGroup(NULL)
,   CTokenGroupTree(NULL)
,   CTokenItem(NULL)
,   CTokenItemTree(NULL)
,   CTokenGroupCnd(NULL)
,   CTokenGroupCndTree(NULL)
,   unXmlParser()
{
    // temp tree nodes
    unXmlParseTree bytecode   ( wxT("bytecode") );
    unXmlParseTree bgroup     ( wxT("group") );
    unXmlParseTree gname      ( wxT("name") );
    unXmlParseTree gmemo      ( wxT("memo") );

    unXmlParseTree gtoken     ( wxT("token") );
    unXmlParseTree tcode      ( wxT("code") );
    unXmlParseTree tname      ( wxT("name") );
    unXmlParseTree tdesc      ( wxT("desc") );
    unXmlParseTree tdata      ( wxT("data") );

    unXmlParseTree titem      ( wxT("item") );
    unXmlParseTree itype      ( wxT("type") );
    unXmlParseTree iname      ( wxT("name") );

    unXmlParseTree ttext      ( wxT("text") );

    unXmlParseTree gcond      ( wxT("gcond") );
    unXmlParseTree cif        ( wxT("if") );
    unXmlParseTree ceq        ( wxT("eq") );
    unXmlParseTree cthen      ( wxT("then") );
    unXmlParseTree cleft      ( wxT("left") );
    unXmlParseTree cright     ( wxT("right") );

    unXmlParseTree ctstream   ( wxT("tstream") );
    unXmlParseTree cnum       ( wxT("num") );

    unXmlParseTree nfunc      ( wxT("nativefunctions") );
    unXmlParseTree ffirst     ( wxT("first") );
    unXmlParseTree fextended  ( wxT("extended") );

    // token group - pre
    bgroup.AddCommand( new_xpObjCreate<pkgTokenGroup>(txpParseTree) );
    bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroup, txpTokenGroupObject ) );
    bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupTree, txpParseTree ) );
        gname.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::SetName, txpNodeName(txpParseTree) ) );
        gname.AddPostCommand( new_xpFunc1( Decompiler, &pkgDecompiler::AddTokenGroup, txpTokenGroup ) );

    // token group - post
    bgroup.AddPostCommand( new_xpObjClear(txpParseTree) );
    bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroup ) );
    bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupTree ) );

    // gcond = pre
    gcond.AddCommand( new_xpObjCreate<pkgTokenCondition>(txpParseTree) );
    gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCnd, txpTokenGroupCndObject ) );
    gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCndTree, txpParseTree ) );

    // gcond = post
    gcond.AddPostCommand( new_xpObjClear(txpParseTree) );
    gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCnd ) );
    gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCndTree ) );

    // token - pre
    gtoken.AddCommand( new_xpObjCreate<dtToken>(txpParseTree) );
    gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetToken, txpTokenObject ) );
    gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenTree, txpParseTree ) );
        tcode.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenData, txpNodeData(txpParseTree) ) );
        tname.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenName, txpNodeName(txpParseTree) ) );
        tdesc.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetDesc, txpNodeName(txpParseTree) ) );
        tdesc.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::AddToken, txpToken ) );
        tdesc.AddCommand( new_xpFunc2( Decompiler, &pkgDecompiler::AddToken, txpToken, txpTokenGroupCnd ) );

    // token - post
    gtoken.AddPostCommand( new_xpFunc0( txpToken, &dtToken::DumpInfo ) );
    gtoken.AddPostCommand( new_xpObjClear(txpParseTree) );
    gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearToken ) );
    gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenTree ) );

    // titem - pre
    titem.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItemTree, txpParseTree ) );
        itype.AddCommand( new_xpObjFactory( txpTokenItemTree, &GDataTypeFactory, &pkgDataTypeFactory::Create, txpNodeName(txpParseTree) ) );
        itype.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItem, txpTokenItemTreeObject ) );
        iname.AddCommand( new_xpFunc1( txpTokenItem, &pkgDataType::SetDesc, txpNodeName(txpParseTree) ) );

    // titem - post
    titem.AddPostCommand( new_xpFunc1( txpToken, &dtToken::AddItem, txpTokenItem ) );
    titem.AddPostCommand( new_xpObjClear(txpParseTree) );
    titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItem ) );
    titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItemTree ) );
    
    ffirst.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdFirst, txpNodeData(txpParseTree) ) );
    fextended.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdExtended, txpNodeData(txpParseTree) ) );


    // construct tree starting from leaves
    // ie: node on right side *cannot* appear anywhere below on left side

    // token
    gtoken.AddChild( tcode, pl::one );
    gtoken.AddChild( tname, pl::one );
    gtoken.AddChild( tdesc, pl::one );
            titem.AddChild( itype, pl::one );
            titem.AddChild( iname, pl::one );
        tdata.AddChild( titem, pl::minone );
        tdata.AddChild( ttext, pl::maxone );
    gtoken.AddChild( tdata, pl::maxone );

    // if
            cleft.AddChild( ctstream, pl::maxone );
            cleft.AddChild( cnum, pl::maxone );
            cright.AddChild( ctstream, pl::maxone );
            cright.AddChild( cnum, pl::maxone );
        ceq.AddChild( cleft, pl::one );
        ceq.AddChild( cright, pl::one );
    cif.AddChild( ceq, pl::one );

    // then
    cthen.AddChild( gtoken, pl::any );

    // group
    bgroup.AddChild( gname, pl::one );
    bgroup.AddChild( gmemo, pl::any );
        gcond.AddChild( cif, pl::one );
        gcond.AddChild( cthen, pl::one );
    bgroup.AddChild( gcond, pl::maxone );
    bgroup.AddChild( gtoken, pl::any );

    // native functions
    nfunc.AddChild( fextended, pl::one );
    nfunc.AddChild( ffirst, pl::one );

    // bytecode
    bytecode.AddChild( bgroup, pl::minone );
    bytecode.AddChild( nfunc, pl::maxone );

    ParseTree = new unXmlParseTree( bytecode );
}
Пример #11
0
Exec_stat MCF_parsetextatts(Properties which, const MCString &data,
                            uint4 &flags, char *&fname, uint2 &height,
                            uint2 &size, uint2 &style)
{
	int2 i1;
	switch (which)
	{
	case P_TEXT_ALIGN:
		flags &= ~F_ALIGNMENT;
		if (data == MCleftstring || data.getlength() == 0)
			flags |= F_ALIGN_LEFT;
		else
			if (data == MCcenterstring)
				flags |= F_ALIGN_CENTER;
			else
				if (data == MCrightstring)
					flags |= F_ALIGN_RIGHT;
				else
					if (data == MCjustifystring)
						flags |= F_ALIGN_JUSTIFY;
					else
					{
						MCeerror->add(EE_OBJECT_BADALIGN, 0, 0, data);
						return ES_ERROR;
					}
		break;
	case P_TEXT_FONT:
		{
			fname = data.clone();
			
			// MW-2012-02-17: [[ IntrinsicUnicode ]] Strip any lang tag from the
			//   fontname.
			char *t_tag;
			t_tag = strchr(fname, ',');
			if (t_tag != nil)
				t_tag[0] = '\0';
		}
		break;
	case P_TEXT_HEIGHT:
		if (!MCU_stoi2(data, i1))
		{
			MCeerror->add
			(EE_OBJECT_TEXTHEIGHTNAN, 0, 0, data);
			return ES_ERROR;
		}
		height = i1;
		break;
	case P_TEXT_SIZE:
		if (data.getlength() == 0)
			i1 = 0;
		else
			if (!MCU_stoi2(data, i1))
			{
				MCeerror->add
				(EE_OBJECT_TEXTSIZENAN, 0, 0, data);
				return ES_ERROR;
			}
		size = i1;
		break;
	case P_TEXT_STYLE:
		{
			// MW-2012-02-17: [[ SplitTextAttrs ]] If the string is empty, then
			//   return 0 for the style - indicating to unset the property.
			uint4 l = data.getlength();
			const char *sptr = data.getstring();
			if (l == 0)
				style = 0;
			else
			{
				style = FA_DEFAULT_STYLE;
				while (l)
				{
					const char *startptr = sptr;
					if (!MCU_strchr(sptr, l, ','))
					{
						sptr += l;
						l = 0;
					}
					MCString tdata(startptr, sptr - startptr);
					MCU_skip_char(sptr, l);
					MCU_skip_spaces(sptr, l);
					if (MCF_setweightstring(style, tdata))
						continue;
					if (MCF_setexpandstring(style, tdata))
						continue;
					if (MCF_setslantlongstring(style, tdata))
						continue;
					if (tdata == MCplainstring)
					{
						style = FA_DEFAULT_STYLE;
						continue;
					}
					if (tdata == MCmixedstring)
					{
						style = FA_DEFAULT_STYLE;
						continue;
					}
					if (tdata == MCboxstring)
					{
						style &= ~FA_3D_BOX;
						style |= FA_BOX;
						continue;
					}
					if (tdata == MCthreedboxstring)
					{
						style &= ~FA_BOX;
						style |= FA_3D_BOX;
						continue;
					}
					if (tdata == MCunderlinestring)
					{
						style |= FA_UNDERLINE;
						continue;
					}
					if (tdata == MCstrikeoutstring)
					{
						style |= FA_STRIKEOUT;
						continue;
					}
					if (tdata == MCgroupstring || tdata == MClinkstring)
					{
						style |= FA_LINK;
						continue;
					}
					MCeerror->add(EE_OBJECT_BADSTYLE, 0, 0, data);
					return ES_ERROR;
				}
			}
		}
		break;
	default:
		break;
	}
	return ES_NORMAL;
}
Пример #12
0
bool loadObj( std::vector<Geometry> &geomList, const std::string &filename, float scale, int flags)
{
    std::ifstream file;
    file.open(filename.c_str(), std::ios::in);

    std::cout<<"loading "<<filename<<std::endl;

    if(file.fail())
    {
        std::cout<<"loadObj failed, could not read "<<std::endl;
        return 1;
    }

    VertexBank vb;

    Geometry g;
    std::string line,param;

    std::vector<vec3> tempVertex;
    std::vector<vec3> tempNormal;
    std::vector<vec2> tempTexCoord;

    tempVertex.reserve(10000);
    tempNormal.reserve(10000);
    tempTexCoord.reserve(10000);
    
    std::vector<std::vector<int> > vertexUsed;
    std::vector<int> texCoordUsed;
    int tempSG = 0;

    std::vector<size_t> vertexRemap;
    std::vector<size_t> normalRemap;
    std::vector<size_t> texCoordRemap;

    std::vector<int> resetVector;
    resetVector.resize(1,-1);

    std::string tempName;

    while( !file.eof() && file.good() )
    {
        std::getline(file,line);

        #ifdef DEBUG
        std::cout<<line<<"\n";
        #endif
        Tokenizer token(line);

        param = token.getToken();
        if(param == "v")
        {
            vec3 vertex;

            vertex.x = scale*toFloat(token.getToken());
            vertex.y = scale*toFloat(token.getToken());
            vertex.z = scale*toFloat(token.getToken());

            //tempVertex.push_back(vertex);
            //vertexUsed.push_back(resetVector);
            vertexRemap.push_back( insertUnique(tempVertex, vertex) );
        }
        else if(param == "f")
        {
            ivec4 vdata(-1), tdata(-1), ndata(-1), fdata(-1);

            for(int i=0; i<(int)token.size()-1; ++i)
            {
                param = token.getToken();
                getIndices(param, vdata[i], tdata[i], ndata[i],
                    hasVertex,
                    hasTexCoord && !(flags & LOADOBJ_IGNORE_TEXCOORDS),
                    hasNormal && !(flags & LOADOBJ_IGNORE_NORMALS) );

                int remappedV = (vdata[i] > -1) ? vdata[i] : -1;
                int remappedN = (ndata[i] > -1) ? ndata[i] : -1;
                int remappedT = (tdata[i] > -1) ? tdata[i] : -1;

                int index;
                //printf("Checking vertex uniqueness \n");
                if(vb.isUnique(remappedV, remappedN, remappedT, index))
                {
                    index = g.getVertexSize();

                    Geometry::sVertex tv;

                    assert( remappedV < (int)tempVertex.size() );
                    tv.position = tempVertex[ remappedV ];

                    if(remappedT > -1)
                    {
                        assert( remappedT < (int)tempTexCoord.size() );
                        tv.texCoord = tempTexCoord[ remappedT ];
                    }
                    if(remappedN > -1)
                    {
                        assert( remappedN < (int)tempNormal.size() );
                        tv.normal = tempNormal[ remappedN ];
                    }

                    g.addVertex(tv);
                }

                assert(index < (int)g.getVertexSize());
                fdata[i] = index;

                // if(tempSG > (int)vertexUsed[vdata[i]].size()-1)
                //     vertexUsed[vdata[i]].resize(tempSG+1,-1);

                // if(vertexUsed[vdata[i]][tempSG] > -1)
                //     fdata[i] = vertexUsed[vdata[i]][tempSG];
                // else
                // {
                //     vertexUsed[vdata[i]][tempSG] = (int)g.vertices.size();

                //     fdata[i] = g.getVertexSize();

                //     Geometry::sVertex tv;
                //     tv.position = tempVertex[vdata[i]];
                //     //tv.nx = tv.ny = tv.nz = tv.s = tv.t = 0.0f;

                //     if(vtdata[i]>-1 && !(flags & LOADOBJ_IGNORE_TEXCOORDS))
                //     {
                //         assert( vtdata[i] < tempTexCoord.size() );
                //         tv.texCoord = tempTexCoord[vtdata[i]];
                //     }
                //     if(ndata[i]>-1 && !(flags & LOADOBJ_IGNORE_NORMALS))
                //     {
                //         assert( ndata[i] < tempNormal.size() );
                //         tv.normal = tempNormal[ndata[i]];
                //     }

                //     g.addVertex(tv);
                // }
            }
            // if its a triangle, just insert.
            // However if its a quad, then insert the two triangles forming the quad.
            uvec3 t;
            t[0] = fdata[0];
            t[1] = fdata[1];
            t[2] = fdata[2];

            g.addTriangle(t);

            if(fdata[3] != -1)
            {
                t[0] = fdata[3];
                t[1] = fdata[0];
                t[2] = fdata[2];

                g.addTriangle(t);
            }
        }
        else if(param == "vt")
        {
            vec2 tc;

            tc.x = toFloat(token.getToken());
            tc.y = toFloat(token.getToken());

            //tempTexCoord.push_back(tc);
            texCoordRemap.push_back( insertUnique(tempTexCoord, tc) );
        }
        else if(param == "vn")
        {
            vec3 normal;

            normal.x = toFloat(token.getToken());
            normal.y = toFloat(token.getToken());
            normal.z = toFloat(token.getToken());

            //tempNormal.push_back(normal);
            normalRemap.push_back( insertUnique(tempNormal, normal) );
        }
        else if(param == "s")
            tempSG = toInt(token.getToken());
        else if(param == "g")
        {
            /*if(first)
                first=false;
            else
            {
                g.process();
                geomList.push_back(g);
            }

            for(unsigned int i=0; i<vertexUsed.size(); ++i)
                vertexUsed[i].clear();
            
            g.clear();
            */
        }

        if(file.eof())
            break;
    }
    file.close();
    printf("tempVertex.size() = %i \n", (int)tempVertex.size());
    printf("tempNormal.size() = %i \n", (int)tempNormal.size());
    printf("tempTexCoord.size() = %i \n", (int)tempTexCoord.size());
    printf("Reading is done, gonna process \n");
    g.process();
    geomList.push_back(g);

    std::cout<<"done reading "<<filename<<std::endl;

    return 0;
}
Пример #13
0
void * Bf2h5Calculator::doDownSampleSingleSubband (void *threaddata)
{
  thread_data *tdata(0);
  
  while(!itsStopProcessing) {
    
    pthread_mutex_lock(&calculationMapMutex);
    while ((level < 1) && (!itsStopProcessing))
      pthread_cond_wait(&condition, &calculationMapMutex);
    
    if ((level > 0) && (!itsStopProcessing)) {
      // grab one subband of the data
      tdata = reinterpret_cast<thread_data *>(threaddata);
      calculationMap::iterator firstBlock = itsData.find(currentBlockNr);
      if (firstBlock != itsData.end()) {
	std::deque<std::pair<uint8_t, BFRawFormat::Sample *> > &blockDeque = firstBlock->second;
	tdata->busy = true;
	tdata->blockNr = firstBlock->first;
	tdata->subbandNr = blockDeque.front().first;
	tdata->input_data = blockDeque.front().second;
	tdata->subband_output_data = dataBlockOutput[tdata->subbandNr];
	blockDeque.pop_front();
	if (blockDeque.empty()) {
	  itsData.erase(itsData.begin());
	}
	--level;
	pthread_mutex_unlock(&calculationMapMutex);
	
	// do the actual processing of the data (mutex is unlocked)
	uint32_t xx_intensity(0), yy_intensity(0);
	uint64_t start(0);
	
	for ( uint32_t count = 0; count < itsSingleSubbandNrOutputSamples; ++count ) // count loops over all output samples
	  {
	    tdata->subband_output_data[count] = 0;
	    for ( uint64_t idx = start; idx < (start + itsDownSampleFactor); ++idx ) // loop over nr of samples defined by downsampling factor
	      {
		xx_intensity = (uint32_t)(real(tdata->input_data[ idx ].xx) * real(tdata->input_data[ idx ].xx) +
					  imag(tdata->input_data[ idx ].xx) * imag(tdata->input_data[ idx ].xx) ); // this will be max 33 bits integer
		yy_intensity = (uint32_t)(real(tdata->input_data[ idx ].yy) * real(tdata->input_data[ idx ].yy) +
					  imag(tdata->input_data[ idx ].yy) * imag(tdata->input_data[ idx ].yy) );
		tdata->subband_output_data[count] += (float)xx_intensity + (float)yy_intensity;
		//TODO: check if this intensity data needs to be divided by itsDownSampleFactor to get averaged value
	      }
	    start += itsDownSampleFactor;
	  }
	
	//  keep track of finished subbands
	itsParent->calculatorDataReady(tdata->blockNr, tdata->subbandNr, tdata->subband_output_data); // signal itsParent app to write the data
	subbandReady[tdata->subbandNr] = true;
	checkIfBlockComplete(); // TODO: do this somewhere else?
	tdata->busy = false;
      }
      else { // didn't find data for current block
        pthread_mutex_unlock(&calculationMapMutex);
        return 0;
      }
    }
    else {
      pthread_mutex_unlock(&calculationMapMutex);
      return 0;
    }
  }
  return 0;
}
Пример #14
0
static const char *create_worker(struct Worker **w_p, bool is_server, ...)
{
	va_list ap;
	const char *k, *v;
	int klen;
	struct Worker *w;
	int err;
	const char *mem = NULL;
	void *fdata;
	size_t flen;
	const char *errmsg = NULL;

	*w_p = NULL;

	w = calloc(1, sizeof *w);
	if (!w)
		return "calloc";

	w->wstate = HANDSHAKE;
	w->is_server = is_server;
	w->config = tls_config_new();
	if (!w->config)
		return "tls_config_new failed";

	if (is_server) {
		w->base = tls_server();
		if (!w->base)
			return "tls_server failed";
	} else {
		w->ctx = tls_client();
		if (!w->ctx)
			return "tls_client failed";
	}

	va_start(ap, is_server);
	while (1) {
		k = va_arg(ap, char *);
		if (!k)
			break;
		v = strchr(k, '=');
		if (!v) {
			errmsg = k;
			break;
		}
		v++;
		klen = v - k;
		err = 0;
		if (!strncmp(k, "mem=", klen)) {
			mem = v;
		} else if (!strncmp(k, "ca=", klen)) {
			if (mem) {
				fdata = load_file(tdata(v), &flen);
				if (!fdata) {
					errmsg = strerror(errno);
					break;
				}
				err = tls_config_set_ca_mem(w->config, fdata, flen);
				free(fdata);
			} else {
				err = tls_config_set_ca_file(w->config, tdata(v));
			}
		} else if (!strncmp(k, "cert=", klen)) {
			if (mem) {
				fdata = load_file(tdata(v), &flen);
				if (!fdata) {
					errmsg = strerror(errno);
					break;
				}
				err = tls_config_set_cert_mem(w->config, fdata, flen);
				free(fdata);
			} else {
				err = tls_config_set_cert_file(w->config, tdata(v));
			}
		} else if (!strncmp(k, "key=", klen)) {
			if (mem) {
				fdata = load_file(tdata(v), &flen);
				if (!fdata) {
					errmsg = strerror(errno);
					break;
				}
				err = tls_config_set_key_mem(w->config, fdata, flen);
				free(fdata);
			} else {
				err = tls_config_set_key_file(w->config, tdata(v));
			}
		} else if (!strncmp(k, "show=", klen)) {
			w->show = v;
		} else if (!strncmp(k, "ciphers=", klen)) {
			err = tls_config_set_ciphers(w->config, v);
		} else if (!strncmp(k, "host=", klen)) {
			w->hostname = v;
		} else if (!strncmp(k, "noverifycert=", klen)) {
			tls_config_insecure_noverifycert(w->config);
		} else if (!strncmp(k, "noverifyname=", klen)) {
			tls_config_insecure_noverifyname(w->config);
		} else if (!strncmp(k, "verify=", klen)) {
			tls_config_verify(w->config);
		} else if (!strncmp(k, "dheparams=", klen)) {
			err = tls_config_set_dheparams(w->config, v);
		} else if (!strncmp(k, "ecdhecurve=", klen)) {
			err = tls_config_set_ecdhecurve(w->config, v);
		} else if (!strncmp(k, "protocols=", klen)) {
			uint32_t protos;
			err = tls_config_parse_protocols(&protos, v);
			tls_config_set_protocols(w->config, protos);
		} else if (!strncmp(k, "peer-sha1=", klen)) {
			w->peer_fingerprint_sha1 = v;
		} else if (!strncmp(k, "peer-sha256=", klen)) {
			w->peer_fingerprint_sha256 = v;
		} else if (!strncmp(k, "verify-client=", klen)) {
			tls_config_verify_client(w->config);
		} else if (!strncmp(k, "verify-client-optional=", klen)) {
			tls_config_verify_client_optional(w->config);
		} else if (!strncmp(k, "aggressive-close=", klen)) {
			w->aggressive_close = 1;
		} else {
			errmsg = k;
			break;
		}
		if (err < 0) {
			errmsg = k;
			break;
		}
	}
	va_end(ap);

	if (errmsg)
		return errmsg;
	if (is_server) {
		if (tls_configure(w->base, w->config) < 0)
			return tls_error(w->base);
	} else {
		if (tls_configure(w->ctx, w->config) < 0)
			return tls_error(w->ctx);
	}

	*w_p = w;
	return "OK";
}