void PaintCharacter(Painter& sw, const Pointf& p, int chr, Font font) { GlyphInfo gi = GetGlyphInfo(font, chr); PaintCharPath pw; pw.sw = &sw; if(gi.IsNormal()) font.Render(pw, p.x, p.y, chr); else if(gi.IsReplaced()) { Font fnt = font; fnt.Face(gi.lspc); fnt.Height(gi.rspc); fnt.Render(pw, p.x, p.y + font.GetAscent() - fnt.GetAscent(), chr); } else if(gi.IsComposed()) { ComposedGlyph cg; Compose(font, chr, cg); font.Render(pw, p.x, p.y, cg.basic_char); sw.Div(); cg.mark_font.Render(pw, p.x + cg.mark_pos.x, p.y + cg.mark_pos.y, cg.mark_char); } sw.EvenOdd(true); }
void mitk::BaseGeometry::Compose(const vtkMatrix4x4 *vtkmatrix, bool pre) { mitk::BaseGeometry::TransformType::Pointer itkTransform = mitk::BaseGeometry::TransformType::New(); TransferVtkMatrixToItkTransform(vtkmatrix, itkTransform.GetPointer()); Compose(itkTransform, pre); }
void M2MFstAligner::_conditional_max( bool y_given_x ){ /* Compute the conditional distribution, P(Y|X) using the WFST paradigm. This is bassed on the approach from Shu and Hetherington 2002. It is assumed that all WFSTs and operations use the Log semiring. Given: FST1 = P(X,Y) Compute: FST2 = P(X) := Map_inv(Det(RmEps(Proj_i(FST1)))) FST3 = P(Y|X) := Compose(FST2,FST1) Proj_i: project on input labels RmEps: epsilon removal Det: determinize Map_inv: invert weights Notes: An analogous process may be used to compute P(X|Y). In this case one would project on OUTPUT labels - Proj_o, and reverse the composition order to Compose(FST1,FST2). Future work: What we are doing here in terms of *generating* the JOINT fst each time is really just a dumb hack. We *should* encode the model in an FST and encode the individual lattices, rather than doing the hacky manual label encoding that we currently rely on. */ //Joint distribution that we start with VectorFst<LogArc>* joint = new VectorFst<LogArc>(); SymbolTable* misyms = new SymbolTable("misyms"); SymbolTable* mosyms = new SymbolTable("mosyms"); joint->AddState(); joint->AddState(); joint->SetStart(0); joint->SetFinal(1,LogArc::Weight::One()); map<LogArc::Label,LogWeight>::iterator it; for( it=prev_alignment_model.begin(); it != prev_alignment_model.end(); it++ ){ string isym = isyms->Find((*it).first); vector<string> io = tokenize_utf8_string( &isym, &s1s2_sep ); LogArc arc( misyms->AddSymbol(io[0]), mosyms->AddSymbol(io[1]), (*it).second, 1 ); joint->AddArc( 0, arc ); } //VectorFst<LogArc>* joint = new VectorFst<LogArc>(); //Push<LogArc,REWEIGHT_TO_FINAL>(*_joint, joint, kPushWeights); //joint->SetFinal(1,LogWeight::One()); joint->Write("m2mjoint.fst"); //BEGIN COMPUTE MARGINAL P(X) VectorFst<LogArc>* dmarg; if( y_given_x ) dmarg = new VectorFst<LogArc>(ProjectFst<LogArc>(*joint, PROJECT_INPUT)); else dmarg = new VectorFst<LogArc>(ProjectFst<LogArc>(*joint, PROJECT_OUTPUT)); RmEpsilon(dmarg); VectorFst<LogArc>* marg = new VectorFst<LogArc>(); Determinize(*dmarg, marg); ArcMap(marg, InvertWeightMapper<LogArc>()); if( y_given_x ) ArcSort(marg, OLabelCompare<LogArc>()); else ArcSort(marg, ILabelCompare<LogArc>()); //END COMPUTE MARGINAL P(X) marg->Write("marg.fst"); //CONDITIONAL P(Y|X) VectorFst<LogArc>* cond = new VectorFst<LogArc>(); if( y_given_x ) Compose(*marg, *joint, cond); else Compose(*joint, *marg, cond); //cond now contains the conditional distribution P(Y|X) cond->Write("cond.fst"); //Now update the model with the new values for( MutableArcIterator<VectorFst<LogArc> > aiter(cond, 0); !aiter.Done(); aiter.Next() ){ LogArc arc = aiter.Value(); string lab = misyms->Find(arc.ilabel)+"}"+mosyms->Find(arc.olabel); int labi = isyms->Find(lab); alignment_model[labi] = arc.weight; prev_alignment_model[labi] = LogWeight::Zero(); } delete joint, marg, cond, dmarg; delete misyms, mosyms; return; }
/** * Compose a SerialNumber from a file. * * @param filename a filename to open */ QString ObservationNumber::Compose(const QString &filename, bool def2filename) { Pvl p(filename); return Compose(p, def2filename); }
/** * Compose a SerialNumber fPvlGroup snGrouprom a Cube. * * @param cube An opened Isis cube */ QString ObservationNumber::Compose(Cube &cube, bool def2filename) { return Compose(*cube.label(), def2filename); }
void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) { #if defined(flagWINGL) || defined(flagLINUXGL) if(IsNull(ink)) return; DrawTextOp(x, y, angle, text, font, ink, n, dx); #else if(IsNull(ink)) return; if(n < 0) n = wstrlen(text); Std(font); double sina = 0; double cosa = 1; int posx = 0; if(angle) Draw::SinCos(angle, sina, cosa); Font font0 = font; if(GetInfo() & DRAWTEXTLINES) font.Underline(false).Strikeout(false); for(int i = 0; i < n; i++) { wchar chr = text[i]; GlyphInfo gi = GetGlyphInfo(font, chr); if(gi.IsNormal()) if(angle) DrawTextOp(int(x + cosa * posx), int(y - sina * posx), angle, &chr, font, ink, 1, NULL); else { int c = 1; int dd = 0; while(i + c < n && c < 1000) { GlyphInfo gi2 = GetGlyphInfo(font, text[i + c]); if(!gi2.IsNormal()) break; dd += dx ? dx[c - 1] : gi.width; c++; gi = gi2; } DrawTextOp(x + posx, y, 0, text + i, font, ink, c, dx); posx += dd; i += c - 1; if(dx) dx += c - 1; } else if(gi.IsReplaced()) { Font fnt = font; fnt.Face(gi.lspc); fnt.Height(gi.rspc); if(angle) DrawTextOp(int(x + cosa * posx), int(y - sina * (font.GetAscent() - fnt.GetAscent() + posx)), angle, &chr, fnt, ink, 1, NULL); else DrawTextOp(x + posx, y + font.GetAscent() - fnt.GetAscent(), 0, &chr, fnt, ink, 1, NULL); GlyphMetrics(gi, font, chr); } else if(gi.IsComposed()) { ComposedGlyph cg; Compose(font, chr, cg); if(angle) { DrawTextOp(int(x + cosa * posx), int(y - sina * posx), angle, &cg.basic_char, font, ink, 1, NULL); DrawTextOp(int(x + cosa * (posx + cg.mark_pos.x)), int(y - sina * (cg.mark_pos.y + posx)), angle, &cg.mark_char, cg.mark_font, ink, 1, NULL); } else { DrawTextOp(x + posx, y, 0, &cg.basic_char, font, ink, 1, NULL); DrawTextOp(x + cg.mark_pos.x + posx, y + cg.mark_pos.y, 0, &cg.mark_char, cg.mark_font, ink, 1, NULL); } GlyphMetrics(gi, font, chr); } else { Font fnt = Arial(font.GetHeight()); wchar chr = 0x25a1; gi = GetGlyphInfo(fnt, chr); if(!gi.IsNormal()) { chr = ' '; gi = GetGlyphInfo(fnt, chr); } if(angle) DrawTextOp(int(x + cosa * posx), int(y - sina * posx), angle, &chr, fnt, ink, 1, NULL); else DrawTextOp(x + posx, y, 0, &chr, fnt, ink, 1, NULL); } posx += dx ? *dx++ : gi.width; } if((GetInfo() & DRAWTEXTLINES) && (font0.IsUnderline() || font0.IsStrikeout())) { int hg = abs(font0.GetCy()); if(hg == 0) hg = 10; int thickness = max(hg / 20, 1); int ascent = font0.GetAscent(); Size offset = Point(0, ascent); if(angle) { offset.cx = fround(ascent * sina); offset.cy = fround(ascent * cosa); } x += offset.cx; y += offset.cy; if(font0.IsUnderline()) { int p = max(hg / 15, int(font0.Info().GetDescent() > 0)); DrawLine( int(x + p * sina), int(y + p * cosa), int(x + posx * cosa + p * sina), int(y - posx * sina + p * cosa), thickness, ink ); } if(font0.IsStrikeout()) { int p = -ascent / 3; DrawLine( int(x + p * sina), int(y + p * cosa), int(x + posx * cosa + p * sina), int(y - posx * sina + p * cosa), thickness, ink ); } } #endif }
void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) { #ifdef flagWINGL if(IsNull(ink)) return; DrawTextOp(x, y, angle, text, font, ink, n, dx); #else if(IsNull(ink)) return; if(n < 0) n = wstrlen(text); Std(font); double sina; double cosa; int d = 0; if(angle) Draw::SinCos(angle, sina, cosa); for(int i = 0; i < n; i++) { wchar chr = text[i]; GlyphInfo gi = GetGlyphInfo(font, chr); if(gi.IsNormal()) if(angle) DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &chr, font, ink, 1, NULL); else { int c = 1; int dd = 0; while(i + c < n) { GlyphInfo gi2 = GetGlyphInfo(font, text[i + c]); if(!gi2.IsNormal()) break; dd += dx ? dx[c] : gi.width; c++; gi = gi2; } DrawTextOp(x + d, y, 0, text + i, font, ink, c, dx); d += dd; i += c - 1; if(dx) dx += c - 1; } else if(gi.IsReplaced()) { Font fnt = font; fnt.Face(gi.lspc); fnt.Height(gi.rspc); if(angle) DrawTextOp(int(x + cosa * d), int(y - sina * (font.GetAscent() - fnt.GetAscent() + d)), angle, &chr, fnt, ink, 1, NULL); else DrawTextOp(x + d, y + font.GetAscent() - fnt.GetAscent(), 0, &chr, fnt, ink, 1, NULL); GlyphMetrics(gi, font, chr); } else if(gi.IsComposed()) { ComposedGlyph cg; Compose(font, chr, cg); if(angle) { DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &cg.basic_char, font, ink, 1, NULL); DrawTextOp(int(x + cosa * (d + cg.mark_pos.x)), int(y - sina * (cg.mark_pos.y + d)), angle, &cg.mark_char, cg.mark_font, ink, 1, NULL); } else { DrawTextOp(x + d, y, 0, &cg.basic_char, font, ink, 1, NULL); DrawTextOp(x + cg.mark_pos.x + d, y + cg.mark_pos.y, 0, &cg.mark_char, cg.mark_font, ink, 1, NULL); } GlyphMetrics(gi, font, chr); } else { Font fnt = Arial(font.GetHeight()); wchar chr = 0x25a1; gi = GetGlyphInfo(fnt, chr); if(!gi.IsNormal()) { chr = ' '; gi = GetGlyphInfo(fnt, chr); } if(angle) DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &chr, fnt, ink, 1, NULL); else DrawTextOp(x + d, y, 0, &chr, fnt, ink, 1, NULL); } d += dx ? *dx++ : gi.width; } #endif }
//------------------------------------------------------------------------------ void TileRenderer::RenderTile(std::string tile_uri, mapnik::Map m, int x, int y, int zoom, GoogleProjection tileproj, mapnik::projection prj, bool verbose, bool overrideTile, bool lockEnabled, std::string compositionLayerPath, std::string compositionMode, double compositionAlpha) { if(!overrideTile && FileSystem::FileExists(tile_uri)) { return; } else { // Calculate pixel positions of bottom-left & top-right ituple p0(x * 256, (y + 1) * 256); ituple p1((x + 1) * 256, y * 256); // Convert to LatLong (EPSG:4326) dtuple l0 = tileproj.pixel2GeoCoord(p0, zoom); dtuple l1 = tileproj.pixel2GeoCoord(p1, zoom); // Convert to map projection (e.g. mercator co-ords EPSG:900913) dtuple c0(l0.a,l0.b); dtuple c1(l1.a,l1.b); prj.forward(c0.a, c0.b); prj.forward(c1.a, c1.b); // Bounding box for the tile #ifndef MAPNIK_2 mapnik::Envelope<double> bbox = mapnik::Envelope<double>(c0.a,c0.b,c1.a,c1.b); m.resize(256,256); m.zoomToBox(bbox); #else mapnik::box2d<double> bbox(c0.a,c0.b,c1.a,c1.b); m.resize(256,256); m.zoom_to_box(bbox); #endif m.set_buffer_size(128); // Render image with default Agg renderer #ifndef MAPNIK_2 mapnik::Image32 buf(m.getWidth(),m.getHeight()); mapnik::agg_renderer<mapnik::Image32> ren(m,buf); #else mapnik::image_32 buf(m.width(), m.height()); mapnik::agg_renderer<mapnik::image_32> ren(m,buf); #endif ren.apply(); if(lockEnabled) { int lockhandle = FileSystem::Lock(tile_uri); #ifndef MAPNIK_2 Compose(compositionLayerPath, compositionMode, compositionAlpha, m.getWidth(),m.getHeight(),&buf, zoom, x,y); mapnik::save_to_file<mapnik::ImageData32>(buf.data(),tile_uri,"png"); #else Compose(compositionLayerPath, compositionMode, compositionAlpha, m.width(),m.height(),&buf, zoom, x,y); mapnik::save_to_file<mapnik::image_data_32>(buf.data(),tile_uri,"png"); #endif FileSystem::Unlock(tile_uri, lockhandle); } else { #ifndef MAPNIK_2 Compose(compositionLayerPath, compositionMode, compositionAlpha, m.getWidth(),m.getHeight(),&buf, zoom, x,y); mapnik::save_to_file<mapnik::ImageData32>(buf.data(),tile_uri,"png"); #else Compose(compositionLayerPath, compositionMode, compositionAlpha, m.width(),m.height(),&buf, zoom, x,y); mapnik::save_to_file<mapnik::image_data_32>(buf.data(),tile_uri,"png"); #endif } } }
QList<QStandardItem *> BookMarkModelRead::Compose( const QDomElement e , const int leveldeep ) { Q_ASSERT ( e.tagName() == "fo:bookmark" ); const int SessionID = qrand () % 1200; treeLoop++; QList<QStandardItem *> diritto; QIcon icob = createBookColorIcon( Qt::darkRed ); QString txt = e.firstChildElement("fo:bookmark-title").text(); if (txt.size() < 2) { txt = tr("No Title found!"); icob = createBookColorIcon( Qt::red ); } const QString link = e.attribute("internal-destination","null"); internalLinkFound.append(link); //////////////qDebug() << "### read -> " << txt << "-" << treeLoop; QStandardItem *item0 = new QStandardItem(txt); item0->setData(leveldeep + treeLoop + SessionID ,Qt::UserRole); item0->setData(bold_base_font,Qt::FontRole); item0->setIcon ( icob ); item0->setFlags( flags ); diritto.append(item0); QStandardItem *item1 = new QStandardItem(link); item1->setFlags( flags ); item1->setData(leveldeep + treeLoop + SessionID ,Qt::UserRole); diritto.append(item1); QStandardItem *item2 = new QStandardItem(QString("%1").arg(leveldeep)); item2->setFlags( Qt::ItemIsEnabled ); item2->setData(leveldeep + treeLoop + SessionID ,Qt::UserRole); diritto.append(item2); if (!e.firstChildElement("fo:bookmark").isNull() && leveldeep == 0 ) { /* one level deep down child */ QDomElement child = e.firstChildElement("fo:bookmark"); while (!child.isNull()) { if ( child.tagName() == "fo:bookmark") { const QString nextlink = child.attribute("internal-destination","null"); if (!internalLinkFound.contains(nextlink)) { diritto.first()->appendRow(Compose(child,leveldeep + 1)); } } child = child.nextSiblingElement(); } } else if (!e.firstChildElement("fo:bookmark").isNull() && leveldeep > 0 ) { /* same level is only next on deep */ QDomElement child = e.firstChildElement("fo:bookmark"); while (!child.isNull()) { if ( child.tagName() == "fo:bookmark") { const QString nextlink = child.attribute("internal-destination","null"); if (!internalLinkFound.contains(nextlink)) { diritto.first()->appendRow(Compose(child,leveldeep + 1)); } } child = child.nextSiblingElement("fo:bookmark"); } } return diritto; }
int main( int argc, char **argv ) { //printf("%d", LevenshteinDistance("*****@*****.**", "xiaoxia yquoxitsoftwareLom")); //return 1; ParseParam ArgvParser = ParseParam(argc, argv); if (argc == 1) { ArgvParser.HelpInfo(); return 1; } ArgvParser.SetGetOptStr("r::g::c::f::w:n:m:p:e:i:t:o:a:sh"); int arg_index = 0; while(1) { int c = ArgvParser.CallGetOpt(); ArgvParser.ParseVal(c, arg_index); arg_index++; if(c == -1) break; } //TextProcess tt; //tt.Test1(); ArgValues InVal = ArgvParser.GetResult(); vector<string> VPValW; vector<int> VPValN; IplImage* pImgGet0 = NULL; IplImage* pImgGet1 = NULL; for (int i = 0; i < InVal.ActionFlag.size(); i++) { switch (InVal.ActionFlag[i]) { case FXQA_FUNC_COMPAREIMG: _DEBUG_INFO("COMPAREIMG run.\n"); if (strcmp(InVal.ImgName0, "-c") == 0) { // compare images. _DEBUG_INFO("-c runned.\n"); if (strcmp(InVal.ImgName1, "-w") == 0) { _DEBUG_INFO("-w runned.\n"); Compare(pImgGet0, pImgGet1, InVal); break; // Compare images. all from srceen shot. } else { Compare(pImgGet0, InVal); break; // Compare images. one from srceen shot,other is local file. } } Compare(InVal); break; // Compare images, or file. case FXQA_FUNC_GETDESKTOPIMG: _DEBUG_INFO("GETDESKTOPIMG run.\n"); VPValW = ArgvParser.ParseInputWValue(InVal.ProgramVal); VPValN = ArgvParser.ParseInputNValue(InVal.ScreenShotSize); if (VPValW.size() == 0) { pImgGet0 = GetScreenImg(argc, argv, NULL, InVal); } else if (VPValW.size() == 1) { pImgGet0 = GetScreenImg(argc, argv, VPValW[0].c_str(), InVal); } else { pImgGet0 = GetScreenImg(argc, argv, VPValW[0].c_str(), InVal); pImgGet1 = GetScreenImg(argc, argv, VPValW[1].c_str(), InVal); } break; case FXQA_FUNC_COMPOSE: Compose(InVal); break; case FXQA_FUNC_FINDIMG: FXQAFunc_Find(argc, argv, InVal); break; case FXQA_FUNC_OCR: FXQAFunc_OCR(argc, argv, InVal); break; default: _DEBUG_INFO("DEFAULT run.\n"); break; } } return 0; }