void HairpinSegment::updateGrips(Grip* defaultGrip, QVector<QRectF>& grip) const { *defaultGrip = Grip::END; QPointF pp(pagePos()); qreal _spatium = spatium(); qreal x = pos2().x(); if (x < _spatium) // minimum size of hairpin x = _spatium; qreal y = pos2().y(); QPointF p(x, y); // Calc QPointF for Grip Aperture QTransform doRotation; QPointF gripLineAperturePoint; qreal h1 = hairpin()->hairpinHeight().val() * spatium() * .5; qreal len = sqrt( x * x + y * y ); doRotation.rotateRadians( asin(y/len) ); qreal lineApertureX; qreal offsetX = 10; // Horizontal offset for x Grip if(len < offsetX * 3 ) // For small hairpin, offset = 30% of len offsetX = len/3; // else offset is fixed to 10 if( hairpin()->hairpinType() == Hairpin::Type::CRESCENDO ) lineApertureX = len - offsetX; // End of CRESCENDO - Offset else lineApertureX = offsetX; // Begin of DECRESCENDO + Offset qreal lineApertureH = ( len - offsetX ) * h1/len; // Vertical position for y grip gripLineAperturePoint.setX( lineApertureX ); gripLineAperturePoint.setY( lineApertureH ); gripLineAperturePoint = doRotation.map( gripLineAperturePoint ); // End calc position grip aperture grip[int(Grip::START)].translate( pp ); grip[int(Grip::END)].translate( p + pp ); grip[int(Grip::MIDDLE)].translate( p * .5 + pp ); grip[int(Grip::APERTURE)].translate( gripLineAperturePoint + pp ); }
double prob(Blob& Y, Blob& p) { assert(Y.get_N() == p.get_N()); assert(Y.get_C() == p.get_C()); assert(Y.get_H() == p.get_H()); assert(Y.get_W() == p.get_W()); double ret = 0; int N = Y.get_N(); int C = Y.get_C(); vector<int> pp(N, -1); vector<int> yy(N, -2); mat mpp = p.reshape(); mat myy = Y.reshape(); for (int i = 0; i < N; ++i) { int idx_p = 0, idx_y = 0; double max_p = mpp(i,0), max_y = myy(i,0); for (int j = 1; j < C; ++j) { if (mpp(i, j) > max_p) { max_p = mpp(i, j); idx_p = j; } if (myy(i, j) > max_y) { max_y = myy(i, j); idx_y = j; } } pp[i] = idx_p; yy[i] = idx_y; } int cnt = 0; for (int i = 0; i < N; ++i) { if (pp[i] == yy[i]) cnt++; } ret = (double)cnt / (double)N; return ret; }
void save(const ColorRanges *srcRanges, RacOut<IO> &rac) const { SimpleSymbolCoder<FLIFBitChanceMeta, RacOut<IO>, 24> coder(rac); SimpleSymbolCoder<FLIFBitChanceMeta, RacOut<IO>, 24> coderY(rac); SimpleSymbolCoder<FLIFBitChanceMeta, RacOut<IO>, 24> coderI(rac); SimpleSymbolCoder<FLIFBitChanceMeta, RacOut<IO>, 24> coderQ(rac); coder.write_int(1, MAX_PALETTE_SIZE, Palette_vector.size()); // printf("Saving %lu colors: ", Palette_vector.size()); prevPlanes pp(2); ColorVal min, max; for (Color c : Palette_vector) { ColorVal Y=std::get<0>(c); srcRanges->minmax(0,pp,min,max); coderY.write_int(min,max,Y); pp[0]=Y; srcRanges->minmax(1,pp,min,max); ColorVal I=std::get<1>(c); coderI.write_int(min, max, I); pp[1]=I; srcRanges->minmax(2,pp,min,max); coderQ.write_int(min, max, std::get<2>(c)); // printf("YIQ(%i,%i,%i)\t", std::get<0>(c), std::get<1>(c), std::get<2>(c)); } // printf("\nSaved palette of size: %lu\n",Palette_vector.size()); v_printf(5,"[%lu]",Palette_vector.size()); }
int main() { std::ios::sync_with_stdio(false); std::map<std::string::size_type, std::vector<std::string>> words; std::string line; while (std::getline(std::cin, line) && !line.empty()) { words[line.size()].push_back(line); } std::cout << "===" << std::endl << "index" << std::endl; for (auto& v : words) { std::cout << v.first << std::endl; } for (auto& v : words) { std::sort(std::begin(v.second), std::end(v.second)); Preprocessor pp(std::move(v.second)); pp.print_result(); } return 0; }
void context::display_lemma_as_smt_problem(std::ostream & out, unsigned num_antecedents, literal const * antecedents, unsigned num_eq_antecedents, enode_pair const * eq_antecedents, literal consequent, const char * logic) const { ast_smt_pp pp(m_manager); pp.set_benchmark_name("lemma"); pp.set_status("unsat"); pp.set_logic(logic); for (unsigned i = 0; i < num_antecedents; i++) { literal l = antecedents[i]; expr_ref n(m_manager); literal2expr(l, n); pp.add_assumption(n); } for (unsigned i = 0; i < num_eq_antecedents; i++) { enode_pair const & p = eq_antecedents[i]; expr_ref eq(m_manager); eq = m_manager.mk_eq(p.first->get_owner(), p.second->get_owner()); pp.add_assumption(eq); } expr_ref n(m_manager); literal2expr(~consequent, n); pp.display_smt2(out, n); }
void InsertProjectTester::testGroupRequest() { Part pp(0); MainDocument part( &pp ); pp.setDocument( &part ); addCalendar( part ); addResourceGroup( part ); addResource( part ); addTask( part ); addGroupRequest( part ); Project &p = part.getProject(); QVERIFY( p.numChildren() == 1 ); Part pp2(0); MainDocument part2( &pp2 ); pp2.setDocument( &part2 ); part2.insertProject( p, 0, 0 ); Project &p2 = part2.getProject(); QVERIFY( p2.childNode( 0 )->resourceGroupRequest( p2.resourceGroupAt( 0 ) ) != 0 ); }
void ReprojectionError3D::computeXc(const T * const _pp, const T * const _distortionParams, const T * const _focals, const T * const _xc, T *residuals) const { Eigen::Map<Eigen::Matrix<T, 3, 1>> xc((T*)_xc); Eigen::Map<Eigen::Matrix<T, 2, 1>> pp((T*)_pp); Eigen::Map<Eigen::Matrix<T, TDistortionParamVector::RowsAtCompileTime, 1>> distortionParams((T*)_distortionParams); Eigen::Map<Eigen::Matrix<T, 2, 1>> focals((T*)_focals); if (CeresUtils::ToDouble(xc[2]) <= 0) { //Negative point residuals[0] = T(1e3); residuals[1] = T(1e3); } else { //Point in front of camera, proceed Eigen::Matrix<T,2,1> p; CameraModel::ProjectFromWorld(pp, distortionParams, focals, xc, p); residuals[0] = (p[0] - T(mImgPoint[0])) / T(mScale); residuals[1] = (p[1] - T(mImgPoint[1])) / T(mScale); } }
bool Paragraph::Paint(int zoom, Draw& w, int x, int y, int cx, int ymax, PaintInfo& pi, Color paper) const { ParaPaint pp(w); int bi = style.bullet ? style.bulletindent : 0; pp.zoom = zoom; pp.posx = x; pp.liney = y; pp.ymax = ymax; pp.lm = DocZoom(zoom, style.lm + bi); pp.yl = pi.yl; pp.yp = 0; pp.paper = paper; cx -= DocZoom(zoom, style.lm + style.rm + bi); bool r = Format(pp, max(1, cx), zoom); if(pi.yl == 0 && pp.yp > 0 && style.bullet) style.bullet.Paint(w, x + DocZoom(zoom, style.lm), y, style.bulletsize.cx ? DocZoom(zoom, style.bulletsize.cx) : pp.bh, style.bulletsize.cy ? DocZoom(zoom, style.bulletsize.cy) : pp.bh, style.bulletcolor, paper, 0); pi.ypos = pp.liney; pi.yl = pp.yp; return r; }
void InsertProjectTester::testResourceAccount() { Part pp(0); MainDocument part( &pp ); pp.setDocument( &part ); addResourceGroup( part ); Resource *r = addResource( part ); Account *a = addAccount( part ); part.addCommand( new ResourceModifyAccountCmd( *r, r->account(), a ) ); Project &p = part.getProject(); QVERIFY( p.resourceGroupAt( 0 )->numResources() == 1 ); Part pp2(0); MainDocument part2( &pp2 ); pp2.setDocument( &part2 ); part2.insertProject( p, 0, 0 ); QVERIFY( part2.getProject().resourceGroupAt( 0 )->numResources() == 1 ); QVERIFY( part2.getProject().accounts().allAccounts().contains( a ) ); QCOMPARE( part2.getProject().resourceGroupAt( 0 )->resourceAt( 0 )->account(), a ); }
void TMesh::SetFromFB(FrameBuffer *fb, PPC *ppc) { vertsN = fb->w*fb->h; verts = new V3[vertsN]; cols = new V3[vertsN]; float z0 = ppc->GetF() / 100.0f; for (int v = 0; v < fb->h; v++) { for (int u = 0; u < fb->w; u++) { int uv = (fb->h-1-v)*fb->w+u; if (fb->zb[uv] == 0.0f) { verts[uv] = V3(FLT_MAX, FLT_MAX, FLT_MAX); cols[uv].setFromColor(fb->Get(u, v)); continue; } //V3 pp((float)u+0.5f, (float)v+0.5f, fb->zb[uv]); V3 pp((float)u+0.5f, (float)v+0.5f, z0); verts[uv] = ppc->UnProject(pp); cols[uv].setFromColor(fb->Get(u, v)); } } }
int main() { const int N = 1000; const unsigned int K = 10; Tree tree; Random_points_iterator rpit(4,1000.0); for(int i = 0; i < N; i++){ tree.insert(*rpit++); } Point_d pp(0.1,0.1,0.1,0.1); Point_d qq(0.2,0.2,0.2,0.2); Iso_box_d query(pp,qq); Distance tr_dist; Neighbor_search N1(tree, query, 5, 10.0, false); // eps=10.0, nearest=false std::cout << "For query rectangle = [0.1, 0.2]^4 " << std::endl << "the " << K << " approximate furthest neighbors are: " << std::endl; for (Neighbor_search::iterator it = N1.begin();it != N1.end();it++) { std::cout << " Point " << it->first << " at distance " << tr_dist.inverse_of_transformed_distance(it->second) << std::endl; } return 0; }
std::string mktmpdir(const char *prefix) { std::string sprefix; std::string tmpdir; std::string path; int i = 0; if (prefix) sprefix = prefix; do { tmpdir = sprefix; tmpdir += randomstr(7); boost::filesystem::path pp(qi::os::tmp(), qi::unicodeFacet()); pp.append(tmpdir, qi::unicodeFacet()); path = pp.make_preferred().string(qi::unicodeFacet()); ++i; } while (i < TMP_MAX && mkdir(path.c_str(), S_IRWXU) == -1); return path; }
void drawPolyLine( ipl_image_wrapper& ipl_image , const curve_vec_t& curves , bool is_closed , PIXEL color , std::size_t line_width ) { const std::size_t num_curves = curves.size(); boost::scoped_array<int> num_points_per_curve( new int[num_curves] ); std::size_t total_num_points = 0; for( std::size_t i = 0; i < num_curves; ++i ) { num_points_per_curve[i] = curves[i].size(); } // The curve array vector will deallocate all memory by itself. cvpoint_array_vec_t pp( num_curves ); CvPoint** curve_array = new CvPoint*[num_curves]; for( std::size_t i = 0; i < num_curves; ++i ) { pp[i] = make_cvPoint_array( curves[i] ); curve_array[i] = pp[i].get(); } cvPolyLine( ipl_image.get() , curve_array // needs to be pointer to C array of CvPoints. , num_points_per_curve.get()// int array that contains number of points of each curve. , curves.size() , is_closed , make_cvScalar( color ) , line_width ); }
void MessageFormatRegressionTest::Test4118592() { UErrorCode status = U_ZERO_ERROR; MessageFormat *mf = new MessageFormat("", status); failure(status, "new messageFormat"); UnicodeString pattern("{0,choice,1#YES|2#NO}"); UnicodeString prefix(""); Formattable *objs = 0; for (int i = 0; i < 5; i++) { UnicodeString formatted; formatted = prefix + "YES"; mf->applyPattern(prefix + pattern, status); failure(status, "mf->applyPattern"); prefix += "x"; //Object[] objs = mf.parse(formatted, new ParsePosition(0)); int32_t count = 0; ParsePosition pp(0); objs = mf->parse(formatted, pp, count); UnicodeString pat; logln(UnicodeString("") + i + ". pattern :\"" + mf->toPattern(pat) + "\""); log(" \"" + formatted + "\" parsed as "); if (objs == NULL) logln(" null"); else { UnicodeString temp; if(objs[0].getType() == Formattable::kString) logln((UnicodeString)" " + objs[0].getString(temp)); else logln((UnicodeString)" " + (objs[0].getType() == Formattable::kLong ? objs[0].getLong() : objs[0].getDouble())); delete[] objs; } } delete mf; }
bool json2xdropq (str t, str *out, ptr<const pub3::expr_t> cin) { xdr_procpair_t pp (NULL, NULL); bool found = json_fetch_constants_t::get_singleton_obj()->lookup_procpair (t, &pp); bool ret = false; if (found) { #define BUFSZ 4 char buf[BUFSZ]; xdrmem x (buf, BUFSZ, XDR_DECODE); #undef BUFSZ XDR *xd = &x; ptr<json_decoder_t> jd = json_XDR_dispatch_t::get_singleton_obj ()->alloc_decoder (xd); jd->init_decode (cin->cast_hack_copy ()); // run the standard str2xdr stuff void *obj = (*pp.alloc)(); ret = (*pp.proc) (xd, obj); if (ret) { xdrsuio xs (XDR_ENCODE, false); XDR *xe = &xs; ret = (*pp.proc) (xe, obj); if (ret) { mstr m (xs.uio ()->resid ()); xs.uio ()->copyout (m); *out = m; } } xdr_delete (pp.proc, obj); } return ret; }
bool load(const ColorRanges *srcRanges, RacIn<IO> &rac) { SimpleSymbolCoder<FLIFBitChanceMeta, RacIn<IO>, 24> coder(rac); SimpleSymbolCoder<FLIFBitChanceMeta, RacIn<IO>, 24> coderY(rac); SimpleSymbolCoder<FLIFBitChanceMeta, RacIn<IO>, 24> coderI(rac); SimpleSymbolCoder<FLIFBitChanceMeta, RacIn<IO>, 24> coderQ(rac); long unsigned size = coder.read_int(1, MAX_PALETTE_SIZE); // printf("Loading %lu colors: ", size); prevPlanes pp(2); ColorVal min, max; for (unsigned int p=0; p<size; p++) { srcRanges->minmax(0,pp,min,max); ColorVal Y=coderY.read_int(min,max); pp[0]=Y; srcRanges->minmax(1,pp,min,max); ColorVal I=coderI.read_int(min,max); pp[1]=I; srcRanges->minmax(2,pp,min,max); ColorVal Q=coderQ.read_int(min,max); Color c(Y,I,Q); Palette_vector.push_back(c); // printf("YIQ(%i,%i,%i)\t", std::get<0>(c), std::get<1>(c), std::get<2>(c)); } // printf("\nLoaded palette of size: %lu\n",Palette_vector.size()); v_printf(5,"[%lu]",Palette_vector.size()); return true; }
ptr<pub3::expr_t> xdropq2json (str typ, const str &xdr_opq) { ptr<pub3::expr_t> ret; xdr_procpair_t pp (NULL, NULL); bool found = json_fetch_constants_t::get_singleton_obj()->lookup_procpair (typ, &pp); if (found) { #define BUFSZ 4 // We need this dummy just as a result of the extensible_rpc v_XDR_t // base class. It really shouldn't need to do anything... xdrmem m (xdr_opq, xdr_opq.len ()); XDR *xm = &m; void *obj = (*pp.alloc)(); bool ok = (*pp.proc) (xm, obj); if (ok) { xdrsuio xs (XDR_ENCODE, false); XDR *xsp = &xs; ptr<json_encoder_t> e = json_XDR_dispatch_t::get_singleton_obj ()->alloc_encoder (xsp); ptr<v_XDR_t> vx = e; ok = (*pp.proc) (xsp, obj); if (ok) { ret = e->root_obj (); assert (ret); } } xdr_delete (pp.proc, obj); } return ret; }
status initialiseStringv(StringObj str, CharArray fmt, int argc, Any *argv) { if ( isDefault(fmt) ) { str_inithdr(&str->data, FALSE); str->data.s_size = 0; str_alloc(&str->data); } else if ( (Name) fmt == name_procent_s && argc == 1 && instanceOfObject(argv[0], ClassCharArray) ) { CharArray v = argv[0]; str_cphdr(&str->data, &v->data); if ( v->data.s_readonly ) { str->data.s_textA = v->data.s_textA; DEBUG(NAME_readOnly, Cprintf("Shared %s\n", pp(str))); } else { str_alloc(&str->data); memcpy(str->data.s_textA, v->data.s_textA, str_datasize(&v->data)); } } else TRY(str_writefv(&str->data, fmt, argc, argv)); succeed; }
int handle_user_login(msg_user_login* plogin) { msg_srv_progress msg; msg.pro_type_ = 0; msg.step_ = 1; send_msg(plogin->from_sock_, msg); player_ptr pp(new koko_player()); int ret = load_user_from_db(plogin, pp, true); if (ret != error_success){ return ret; } pp->from_socket_ = plogin->from_sock_; plogin->from_sock_->the_client_ = pp; msg.pro_type_ = 0; msg.step_ = 2; send_msg(plogin->from_sock_, msg); Database& db = *db_; Query q(db); msg.pro_type_ = 0; msg.step_ = 3; send_msg(plogin->from_sock_, msg); send_all_match_to_player(pp); msg.pro_type_ = 0; msg.step_ = 4; send_msg(plogin->from_sock_, msg); pending_login_users_.push_back(pp); return error_success; }
void UserView::paintEmptyArea(QPainter *p, const QRect &r) { if ((r.width() == 0) || (r.height() == 0)) return; QPixmap bg(r.width(), r.height()); QPainter pp(&bg); pp.fillRect(QRect(0, 0, r.width(), r.height()), colorGroup().base()); PaintView pv; pv.p = &pp; pv.pos = viewport()->mapToParent(r.topLeft()); pv.size = r.size(); pv.win = this; pv.isStatic = false; pv.height = r.height(); pv.margin = 0; QListViewItem *item = firstChild(); if (item) pv.height = item->height(); Event e(EventPaintView, &pv); e.process(); pp.end(); p->drawPixmap(r.topLeft(), bg); setStaticBackground(pv.isStatic); }
void InsertProjectTester::testExistingResourceAccount() { Part pp(0); MainDocument part( &pp ); pp.setDocument( &part ); addResourceGroup( part ); Resource *r = addResource( part ); Account *a = addAccount( part ); part.addCommand( new ResourceModifyAccountCmd( *r, r->account(), a ) ); Project &p = part.getProject(); QVERIFY( p.resourceGroupAt( 0 )->numResources() == 1 ); QDomDocument doc = part.saveXML(); Part pp2(0); MainDocument part2( &pp2 ); pp2.setDocument( &part2 ); part2.insertProject( p, 0, 0 ); QVERIFY( part2.getProject().resourceGroupAt( 0 )->numResources() == 1 ); QVERIFY( part2.getProject().accounts().allAccounts().contains( a ) ); QCOMPARE( part2.getProject().resourceGroupAt( 0 )->resourceAt( 0 )->account(), a ); part2.addCommand( new ResourceModifyAccountCmd( *(part2.getProject().resourceGroupAt( 0 )->resourceAt( 0 )), part2.getProject().resourceGroupAt( 0 )->resourceAt( 0 )->account(), 0 ) ); KoXmlDocument xdoc; xdoc.setContent( doc.toString() ); part.loadXML( xdoc, 0 ); part2.insertProject( part.getProject(), 0, 0 ); QVERIFY( part2.getProject().resourceGroupAt( 0 )->numResources() == 1 ); QVERIFY( part2.getProject().accounts().allAccounts().contains( a ) ); QVERIFY( part2.getProject().resourceGroupAt( 0 )->resourceAt( 0 )->account() == 0 ); }
void PaletteBox::paletteCmd(PaletteCommand cmd, int slot) { QLayoutItem* item = vbox->itemAt(slot); PaletteBoxButton* b = static_cast<PaletteBoxButton*>(item->widget()); Palette* palette = static_cast<Palette*>(vbox->itemAt(slot+1)->widget()); switch(cmd) { case PaletteCommand::PDELETE: { vbox->removeItem(item); b->deleteLater(); // this is the button widget delete item; item = vbox->itemAt(slot); vbox->removeItem(item); delete item->widget(); delete item; for (int i = 0; i < (vbox->count() - 1) / 2; ++i) static_cast<PaletteBoxButton*>(vbox->itemAt(i * 2)->widget())->setId(i*2); emit changed(); } break; case PaletteCommand::SAVE: { QString path = mscore->getPaletteFilename(false); if (!path.isEmpty()) palette->write(path); } break; case PaletteCommand::LOAD: { QString path = mscore->getPaletteFilename(true); if (!path.isEmpty()) { QFileInfo fi(path); Palette* palette = newPalette(fi.baseName(), slot); palette->read(path); } } emit changed(); break; case PaletteCommand::NEW: palette = newPalette(tr("new Palette"), slot); item = vbox->itemAt(slot); b = static_cast<PaletteBoxButton*>(item->widget()); // fall through case PaletteCommand::EDIT: { PaletteProperties pp(palette, 0); int rv = pp.exec(); if (rv == 1) { emit changed(); b->setText(palette->name()); palette->update(); } } emit changed(); break; case PaletteCommand::UP: if (slot) { QLayoutItem* i1 = vbox->itemAt(slot); QLayoutItem* i2 = vbox->itemAt(slot+1); vbox->removeItem(i1); vbox->removeItem(i2); vbox->insertWidget(slot-2, i2->widget()); vbox->insertWidget(slot-2, i1->widget()); delete i1; delete i2; for (int i = 0; i < (vbox->count() - 1) / 2; ++i) static_cast<PaletteBoxButton*>(vbox->itemAt(i * 2)->widget())->setId(i*2); emit changed(); } break; case PaletteCommand::DOWN: if (slot < (vbox->count() - 3)) { QLayoutItem* i1 = vbox->itemAt(slot); QLayoutItem* i2 = vbox->itemAt(slot+1); vbox->removeItem(i1); vbox->removeItem(i2); vbox->insertWidget(slot+2, i2->widget()); vbox->insertWidget(slot+2, i1->widget()); delete i1; delete i2; for (int i = 0; i < (vbox->count() - 1) / 2; ++i) static_cast<PaletteBoxButton*>(vbox->itemAt(i * 2)->widget())->setId(i*2); emit changed(); } break; } }
Spectrum SeparableBSSRDF::Sample_Sp(const Scene &scene, Float u1, const Point2f &u2, MemoryArena &arena, SurfaceInteraction *pi, Float *pdf) const { ProfilePhase pp(Prof::BSSRDFEvaluation); // Choose projection axis for BSSRDF sampling Vector3f vx, vy, vz; if (u1 < .5f) { vx = ss; vy = ts; vz = Vector3f(ns); u1 *= 2; } else if (u1 < .75f) { // Prepare for sampling rays with respect to _ss_ vx = ts; vy = Vector3f(ns); vz = ss; u1 = (u1 - .5f) * 4; } else { // Prepare for sampling rays with respect to _ts_ vx = Vector3f(ns); vy = ss; vz = ts; u1 = (u1 - .75f) * 4; } // Choose spectral channel for BSSRDF sampling int ch = Clamp((int)(u1 * Spectrum::nSamples), 0, Spectrum::nSamples - 1); u1 = u1 * Spectrum::nSamples - ch; // Sample BSSRDF profile in polar coordinates Float r = Sample_Sr(ch, u2[0]); if (r < 0) return Spectrum(0.f); Float phi = 2 * Pi * u2[1]; // Compute BSSRDF profile bounds and intersection height Float rMax = Sample_Sr(ch, 0.999f); if (r > rMax) return Spectrum(0.f); Float l = 2 * std::sqrt(rMax * rMax - r * r); // Compute BSSRDF sampling ray segment Interaction base; base.p = po.p + r * (vx * std::cos(phi) + vy * std::sin(phi)) - l * vz * 0.5f; base.time = po.time; Point3f pTarget = base.p + l * vz; // Intersect BSSRDF sampling ray against the scene geometry // Declare _IntersectionChain_ and linked list struct IntersectionChain { SurfaceInteraction si; IntersectionChain *next = nullptr; }; IntersectionChain *chain = ARENA_ALLOC(arena, IntersectionChain)(); // Accumulate chain of intersections along ray IntersectionChain *ptr = chain; int nFound = 0; while (scene.Intersect(base.SpawnRayTo(pTarget), &ptr->si)) { base = ptr->si; // Append admissible intersection to _IntersectionChain_ if (ptr->si.primitive->GetMaterial() == this->material) { IntersectionChain *next = ARENA_ALLOC(arena, IntersectionChain)(); ptr->next = next; ptr = next; nFound++; } } // Randomly choose one of several intersections during BSSRDF sampling if (nFound == 0) return Spectrum(0.0f); int selected = Clamp((int)(u1 * nFound), 0, nFound - 1); while (selected-- > 0) chain = chain->next; *pi = chain->si; // Compute sample PDF and return the spatial BSSRDF term $\Sp$ *pdf = this->Pdf_Sp(*pi) / nFound; return this->Sp(*pi); }
bool checkFile(std::string const & p) { namespace bfs = boost::filesystem; bfs::path pp(p); return bfs::exists(pp) && bfs::is_regular_file(pp); }
int main(int argc, char* argv[]) { printf("ELENA Assembler Compiler %d.%d.%d (C)2011-2019 by Alexei Rakov\n", ENGINE_MAJOR_VERSION, ENGINE_MINOR_VERSION, REVISION_NUMBER); if (argc<2) { printf("asm2binx [-amd64] <file.asm> <output path>"); return 0; } _ELENA_::Path target; bool esmMode = _ELENA_::Path::checkExtension(argv[1], "esm"); bool amd64Mode = false; if (argc == 4) { if (_ELENA_::ident_t(argv[1]).compare("-amd64")) { amd64Mode = true; _ELENA_::FileName name(argv[2]); target.copy(argv[3]); target.combine(name.str()); } else { printf("Invalid argument list"); return -1; } } else if (argc==3) { if (_ELENA_::ident_t(argv[1]).compare("-amd64")) { amd64Mode = true; target.copy(argv[2]); } else { _ELENA_::FileName name(argv[1]); target.copy(argv[2]); target.combine(name.str()); } } else target.copy(argv[1]); if (esmMode) { target.changeExtension("nl"); } else target.changeExtension("bin"); _ELENA_::PreProcessor pp(amd64Mode ? argv[2] : argv[1]); if (!pp.isOpened()) { printf("Cannot open the file %s", amd64Mode ? argv[2] : argv[1]); return -1; } try { pp.preProcess(); } catch (_ELENA_::PreProcessorException& e) { if (e.macroName == NULL) printf(e.message); else if (e.macroName == NULL && e.row >= 0) printf(e.message, e.row); else if (e.row == -1) printf(e.message, e.macroName); else printf(e.message, e.macroName, e.row); return -1; } _ELENA_::Path source(pp.getTempFileName()); _ELENA_::TextFileReader reader(source.c_str(), _ELENA_::feUTF8, true); if (!reader.isOpened()) { printf("Cannot open the temporal file %s", source.c_str()); return -1; } _ELENA_::Path::create(NULL, target.c_str()); try { if (esmMode) { _ELENA_::ECodesAssembler assembler; assembler.compile(&reader, target.c_str()); } else if (amd64Mode) { _ELENA_::AMD64Assembler assembler; assembler.compile(&reader, target.c_str()); } else { _ELENA_::x86Assembler assembler; assembler.compile(&reader, target.c_str()); } printf("Successfully compiled\n"); } catch(_ELENA_::InvalidChar& e) { printf("(%d): Invalid char %c\n", e.row, e.ch); return -1; } catch(_ELENA_::AssemblerException& e) { if (e.messageArguments == NULL) printf(e.message, e.row); else if (e.procedureName == NULL) printf(e.message, e.messageArguments.c_str(), e.procedureNumber); else printf(e.message, e.messageArguments.c_str(), e.procedureName.c_str()); return -1; } return 0; }
void TMesh::RenderFilled(PPC *ppc, FrameBuffer *fb, unsigned int color, V3 L, float ka, float se, int tm, int tl) { //Project all vertices V3 *pverts = new V3[vertsN]; for (int vi = 0; vi < vertsN; vi++) { ppc->Project(verts[vi], pverts[vi]); } for (int tri = 0; tri < trisN; tri++) { int vinds[3]; vinds[0] = tris[tri*3+0]; vinds[1] = tris[tri*3+1]; vinds[2] = tris[tri*3+2]; // Do not render triangle if any of its vertices had an invalid projection if (pverts[vinds[0]][0] == FLT_MAX || pverts[vinds[1]][0] == FLT_MAX || pverts[vinds[2]][0] == FLT_MAX) continue; // Compute bounding box aabb of projected vertices AABB aabb(pverts[vinds[0]]); aabb.AddPoint(pverts[vinds[1]]); aabb.AddPoint(pverts[vinds[2]]); // Clip aabb with frame if (!aabb.Clip(0.0f, (float) fb->w, 0.0f, (float) fb->h)) { continue; } // Setup edge equations ee0, ee1, ee2 V3 eeqs[3]; SetEEQS(pverts[vinds[0]], pverts[vinds[1]], pverts[vinds[2]], eeqs); //Setup coefficient matrix M33 ptm; ptm[0] = pverts[vinds[0]]; ptm[1] = pverts[vinds[1]]; ptm[2] = pverts[vinds[2]]; ptm.setColumn(2, V3(1.0f, 1.0f, 1.0f)); ptm = ptm.inverse(); //Get colors at verts V3 reds(cols[vinds[0]][0], cols[vinds[1]][0], cols[vinds[2]][0]); V3 greens(cols[vinds[0]][1], cols[vinds[1]][1], cols[vinds[2]][1]); V3 blues(cols[vinds[0]][2], cols[vinds[1]][2], cols[vinds[2]][2]); // Setup screen space interpolation of depth: zABC V3 zABC = ptm*V3(pverts[vinds[0]][2], pverts[vinds[1]][2], pverts[vinds[2]][2]); //Setup screen space interpolation of normals V3 nxABC = ptm*V3(normals[vinds[0]][0], normals[vinds[1]][0], normals[vinds[2]][0]); V3 nyABC = ptm*V3(normals[vinds[0]][1], normals[vinds[1]][1], normals[vinds[2]][1]); V3 nzABC = ptm*V3(normals[vinds[0]][2], normals[vinds[1]][2], normals[vinds[2]][2]); //Model space interpolation parameters M33 msiQ = GetMSIQ(verts[vinds[0]], verts[vinds[1]], verts[vinds[2]], ppc); V3 denABC = msiQ[0] + msiQ[1] + msiQ[2]; V3 redNABC(msiQ.getColumn(0) * reds, msiQ.getColumn(1) * reds, msiQ.getColumn(2) * reds); V3 greenNABC(msiQ.getColumn(0) * greens, msiQ.getColumn(1) * greens, msiQ.getColumn(2) * greens); V3 blueNABC(msiQ.getColumn(0) * blues, msiQ.getColumn(1) * blues, msiQ.getColumn(2) * blues); //Texture coordinates interpolation V3 sNumABC, tNumABC, sABC, tABC; if (tcs) { V3 ss(tcs[2*vinds[0]+0], tcs[2*vinds[1]+0], tcs[2*vinds[2]+0]); V3 ts(tcs[2*vinds[0]+1], tcs[2*vinds[1]+1], tcs[2*vinds[2]+1]); sNumABC = V3(msiQ.getColumn(0) * ss, msiQ.getColumn(1) * ss, msiQ.getColumn(2) * ss); tNumABC = V3(msiQ.getColumn(0) * ts, msiQ.getColumn(1) * ts, msiQ.getColumn(2) * ts); sABC = ptm * ss; tABC = ptm * ts; } // For every pixel in the bounding box int top = (int) (aabb.corners[0][1] + 0.5f); int bottom = (int) (aabb.corners[1][1] - 0.5f); int left = (int) (aabb.corners[0][0] + 0.5f); int right = (int) (aabb.corners[1][0] - 0.5f); for (int v = top; v <= bottom; v++) { for (int u = left; u <= right; u++) { V3 pixv(.5f + (float)u, .5f + (float)v, 1.0f); //Check edge equations if (eeqs[0]*pixv < 0.0f || eeqs[1]*pixv < 0.0f || eeqs[2]*pixv < 0.0f) continue; // Check z-buffer float currz = zABC * pixv; if (fb->IsFarther(u, v, currz)) continue; fb->SetZ(u, v, currz); V3 currColor; float msdn = denABC * pixv; V3 fullColor; if (tcs) { float currs = sABC * pixv; float currt = tABC * pixv; int ut, vt; ut=vt=0; if (tm == 0) { //nearest neighbor ut = (int) (currs * (float) texture->w); vt = (int) (currt * (float) texture->h); } else if(tm == 1) { //bilinear } fullColor.setFromColor(texture->Get(ut, vt)); } else { fullColor = V3(redNABC * pixv, greenNABC * pixv, blueNABC * pixv) / msdn; } V3 currNormal, lv; V3 pp(pixv); pp[2] = currz; lv = (L - ppc->UnProject(pp)).normalize(); currNormal = V3(nxABC*pixv, nyABC*pixv, nzABC*pixv).normalize(); float kd = lv * currNormal; kd = (kd < 0.0f) ? 0.0f : kd; float ks = 0; //pow(reflectedLightVector * eyeVector, se) currColor = fullColor * (ka + (1.0f-ka)*kd + ks); fb->Set(u, v, currColor.getColor()); } } } delete []pverts; }
void GraphEditor::mousePressEvent(QMouseEvent* e) {GeometricGraph & G = *(gwp->pGG); QPoint p((int)e->pos().x(),(int)e->pos().y()); setFocus(); // as we might loose the focus ColorItem *coloritem; if(FindItem(p,coloritem) != 0) {if(e->button() == Qt::LeftButton) {if(coloritem->node) {gwp->NodeColorItem[color_node]->SetPenColor(White); coloritem->SetPenColor(coloritem->brush_color); color_node = coloritem->brush_color; G.vcolor.definit(color_node); } else {gwp->EdgeColorItem[color_edge]->SetPenColor(White); coloritem->SetPenColor(coloritem->brush_color); color_edge = coloritem->brush_color; G.ecolor.definit(color_edge); } return; } else if(e->button() == Qt::RightButton) {QString t; if(coloritem->node) t.sprintf("Vertex color:%s",ColorName[coloritem->brush_color]); else t.sprintf("Edge color:%s",ColorName[coloritem->brush_color]); gwp->info_item = CreateInfoItem(gwp,t,p); setCursor(QCursor(Qt::WhatsThisCursor)); return; } } ThickItem *thickitem; if(FindItem(p,thickitem) != 0) {if(e->button() == Qt::LeftButton) {gwp->EdgeThickItem[width_edge]->SetBrushColor(White); thickitem->SetBrushColor(Yellow); width_edge = thickitem->width; G.ewidth.definit(width_edge); return; } else if(e->button() == Qt::RightButton) {QString t; t.sprintf("Edge width:%d",thickitem->width); gwp->info_item = CreateInfoItem(gwp,t,p); setCursor(QCursor(Qt::WhatsThisCursor)); return; } } if(e->button() == Qt::RightButton ) {NodeItem* node; EdgeItem *edge; QString t; int rtt = FindItem(p,node,edge); if(rtt == 0)rtt = FindItem(p,edge);//augment the collision zone if(rtt == node_rtti) if (G.Set().exist(PROP_VSLABEL) && G.Set(tvertex()).exist(PROP_SLABEL)) {QString tt; Prop1<svector<tstring *> >vslabel(G.Set(),PROP_VSLABEL); Prop<int> slabel(G.Set(tvertex()),PROP_SLABEL,0); if (vslabel()[slabel[node->v]]==(tstring *)0) tt="(null)"; else tt=~(*(vslabel()[slabel[node->v]])); t.sprintf("vertex:%d Label:%d (%s)",(node->v)(),G.vlabel[node->v],(const char *)tt.toLatin1()); } else t.sprintf("vertex:%d Label:%d",(node->v)(),G.vlabel[node->v]); else if(rtt == edge_rtti) {double d = Distance(G.vcoord[G.vin[edge->e]],G.vcoord[G.vin[-(edge->e)]])+.5; t.sprintf("edge:%d Label:%d len:%d",(edge->e)(),G.elabel[edge->e],(int)d); } else {t.sprintf("(%d,%d)",(int)e->pos().x(),(int)e->pos().y()); setCursor(QCursor(Qt::BlankCursor)); } gwp->info_item = CreateInfoItem(gwp,t,p); return; } //GetMouseAction_1 returns the active radio button (0,5) int MouseAction = GetMouseAction_1(); bool Shift = e->modifiers() == Qt::ShiftModifier; bool Control = e->modifiers() == Qt::ControlModifier; bool SControl = e->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier); if(e->button() == Qt::MidButton) //move MouseAction = (Shift) ? -3 : 3; else if(Shift && MouseAction == 1) //add MouseAction = -1; // delete vertex or edge else if(Control && MouseAction == 1) MouseAction = 10; //duplicate graph else if(SControl && MouseAction == 1) MouseAction = 11; //duplicate + else if(Shift && MouseAction == 2) //Orient or reorient if oriented MouseAction = -2; //disorient else if(Shift && MouseAction == 3) //move vertices MouseAction = -3; //move colored vertices else if(Shift && MouseAction == 4) //bissect MouseAction = -4; //contract else if(Shift && MouseAction == 5) //define exterior face MouseAction = -5; //define extbrin else if(Shift && MouseAction == 6) //define a label MouseAction = -6; //reset all labels to indices if(MouseAction == 0) // color {NodeItem* node; EdgeItem *edge; int rtt = FindItem(p,node,edge); if(rtt == 0) //augment the collision zone {rtt = FindItem(p,edge); if(rtt == 0)return; } if(rtt == node_rtti) {mywindow->UndoTouch(false); G.vcolor[node->v] = color_node; node->SetColor(color[color_node]); } else if(rtt == edge_rtti) {mywindow->UndoTouch(false); G.ecolor[edge->e] = color_edge; G.ewidth[edge->e] = width_edge; if(edge->lower) edge->SetColor(color[color_edge]); else edge->opp->SetColor(color[color_edge]); } return; } else if(MouseAction == 1) // Start create an edge {mywindow->UndoTouch(false); Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM); NodeItem* node; EdgeItem *edge; tvertex v; int h = (int)gwp->canvas->height(); int rtt = FindItem(p,node,edge); if(rtt != node_rtti)// add a vertex {Tpoint pp((double)p.x(),(double)(h - p.y())); v = G.NewVertex(pp); ToGrid(v); nodeitem[v] = node = CreateNodeItem(v,gwp); mywindow->mouse_actions->ButtonUndoGrid->setDisabled(true); } else v = node->v; start_position = QPoint((int)G.vcoord[v].x(),h-(int)G.vcoord[v].y()); node->SetColor(Qt::red); gwp->curs_item = new CursItem(v,start_position,gwp); } else if(MouseAction == -1) // Delete {NodeItem* node; EdgeItem *edge; int rtt = FindItem(p,node,edge); if(rtt == 0) //augment the collision zone {rtt = FindItem(p,edge); if(rtt == 0)return; } if(rtt == node_rtti) {mywindow->UndoTouch(true); G.DeleteVertex(node->v); mywindow->mouse_actions->ButtonUndoGrid->setDisabled(true); } else {mywindow->UndoTouch(true); G.DeleteEdge(edge->e); } load(false); mywindow->information();// Informations PrintSizeGrid(); return; } else if(MouseAction == 3) // Start moving a vertex {NodeItem* node; EdgeItem *edge; int rtt = FindItem(p,node,edge); if(rtt != node_rtti)return; mywindow->UndoTouch(false); gwp->moving_item = node; start_position = p; return; } else if(MouseAction == -3) // Start moving a subgraph {mywindow->UndoTouch(false); gwp->moving_subgraph = true; start_position = p; return; } else if(MouseAction == 4) // Bissect an edge {mywindow->UndoTouch(true); if(FitToGrid)//and we are sure that ButtonFitGrid exists mywindow->mouse_actions->ButtonFitGrid->setChecked(false); mywindow->mouse_actions->ButtonUndoGrid->setDisabled(true); EdgeItem *edge; int rtt = FindItem(p,edge); if(rtt != edge_rtti)return; G.BissectEdge(edge->e); DoNormalise = false; load(true); DoNormalise = true; mywindow->information();// Informations return; } else if(MouseAction == -4) // Contract an edge {EdgeItem *edge; int rtt = FindItem(p,edge); if(rtt != edge_rtti)return; mywindow->UndoTouch(true); // provisoire if(edge->lower)G.ReverseEdge(edge->e); // end provisoire G.ContractEdge(edge->e); load(false); mywindow->information();// Informations return; } else if(MouseAction == 5) // Color Exterior face {GeometricGraph & G = *(gwp->pGG); Prop<EdgeItem *> edgeitem(G.Set(tedge()),PROP_CANVAS_ITEM); Tpoint pp((double)p.x(),(double)(gwp->canvas->height()-p.y())); if(G.FindExteriorFace(pp) == 0)return; //ColorExteriorface tedge e; ForAllEdges(e,G)edgeitem[e]->SetColor(color[color_edge]); tbrin b0 = G.extbrin(); tbrin b = b0; do {e = b.GetEdge(); edgeitem[e]->SetColor(color[Red]); } while((b = G.cir[-b]) != b0); if(b0() > 0) edgeitem[b0.GetEdge()]->SetColor(color[Green],false); else edgeitem[b0.GetEdge()]->opp->SetColor(color[Green],false); return; } else if(MouseAction == -5) // Define Extbrin {EdgeItem *edge; int rtt = FindItem(p,edge); if(rtt != edge_rtti)return; Prop<EdgeItem *> edgeitem(G.Set(tedge()),PROP_CANVAS_ITEM); tedge je; ForAllEdges(je,G)edgeitem[je]->SetColor(color[color_edge]); GeometricGraph & G = *(gwp->pGG); je = edge->e; // Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM); // NodeItem *n1 = nodeitem[G.vin[je]]; Tpoint p1(n1->x(),n1->y()); // NodeItem *n2 = nodeitem[G.vin[-je]]; Tpoint p2(n2->x(),n2->y()); // Tpoint pp((double)p.x(),(double)p.y()); // G.extbrin() = (Distance2(pp,p1) < Distance2(pp,p2)) ? je.firsttbrin() : je.secondtbrin(); G.extbrin() = (edge->lower ) ? je.firsttbrin() : je.secondtbrin(); edge->SetColor(color[Green],false); return; } else if(MouseAction == 6) // Modify label {NodeItem* node; EdgeItem *edge; int rtt = FindItem(p,node,edge); if(rtt != node_rtti)return; tvertex v = node->v; bool ok; //int res = QInputDialog::getInteger(this,"Pigale","Enter a number:",(int)G.vlabel[node->v],0,2147483647,1,&ok); int res = QInputDialog::getInt(this,"Pigale","Enter a number:",(int)G.vlabel[node->v],0,2147483647,1,&ok); if(!ok)return; G.vlabel[node->v] = res; QString t = getVertexLabel(G.Container(),v); node->SetText(t); return; } else if(MouseAction == -6) // Reset all labels {Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM); for(tvertex v = 1; v <= G.nv();v++) {G.vlabel[v] = v(); nodeitem[v]->SetText(QString("%1").arg(v())); } for(tedge e = 1; e <= G.ne();e++) G.elabel[e] = e(); } else if(MouseAction == 2 || MouseAction == -2) // Orient/Reverse or deorient {Prop<bool> eoriented(G.Set(tedge()),PROP_ORIENTED,false); Prop<bool> reoriented(G.Set(tedge()),PROP_REORIENTED); Prop<EdgeItem *> edgeitem(G.Set(tedge()),PROP_CANVAS_ITEM); mywindow->setShowOrientation(true); EdgeItem *edge; int rtt = FindItem(p,edge); if(rtt != edge_rtti)return; mywindow->UndoTouch(true); if(MouseAction == 2) {if(eoriented[edge->e]) {G.ReverseEdge(edge->e); eoriented[edge->e] = true; reoriented[edge->e] = false; edgeitem[edge->e] = CreateEdgeItem(edge->e,gwp); if(edge->arrow) scene()->removeItem(edge->arrow); else scene()->removeItem(edge->opp->arrow); scene()->removeItem(edge->opp);scene()->removeItem(edge); mywindow->information();// Informations return; } else {eoriented[edge->e] = true; if(edge->lower) {G.ReverseEdge(edge->e);reoriented[edge->e] = false;} edgeitem[edge->e] = CreateEdgeItem(edge->e,gwp); if(edge->arrow) scene()->removeItem(edge->arrow); else scene()->removeItem(edge->opp->arrow); scene()->removeItem(edge->opp);scene()->removeItem(edge); mywindow->information();// Informations return; } } else {eoriented[edge->e] = false; edgeitem[edge->e] = CreateEdgeItem(edge->e,gwp); if(edge->arrow) scene()->removeItem(edge->arrow); else scene()->removeItem(edge->opp->arrow); scene()->removeItem(edge->opp);scene()->removeItem(edge); mywindow->information();// Informations return; } } else if(MouseAction == 10)// Duplicate the sugraph of the current color {mywindow->UndoTouch(true); if(FitToGrid)//and we are sure that ButtonFitGrid exists mywindow->mouse_actions->ButtonFitGrid->setChecked(false); mywindow->mouse_actions->ButtonUndoGrid->setDisabled(true); short vcol=0; G.vcolor.getinit(vcol); G.vcolor.definit((short)((vcol+1)%16)); GeometricGraph & G = *(gwp->pGG); Tpoint translate(this->width()/2.,0); int n = G.nv(); svector<tvertex> newvertex(1,n); tvertex v; for(v = 1; v <= n;v++)//translate all the graph G.vcoord[v] /= 2.; for(v = 1; v <= n;v++) {if(G.vcolor[v] != vcol)continue; newvertex[v] = G.NewVertex(G.vcoord[v] + translate); } int m = G.ne(); tvertex v1,v2; for(tedge e = 1; e <= m;e++) {v1 = G.vin[e];v2 = G.vin[-e]; if(G.vcolor[v1] == vcol && G.vcolor[v2] == vcol) G.NewEdge(newvertex[v1],newvertex[v2]); } load(true); mywindow->information();// Informations } else if(MouseAction == 11) //Duplicate the sugraph of the current color // and add edges between a new vertex and its father {mywindow->UndoTouch(true); if(FitToGrid)//and we are sure that ButtonFitGrid exists mywindow->mouse_actions->ButtonFitGrid->setChecked(false); mywindow->mouse_actions->ButtonUndoGrid->setDisabled(true); mywindow->mouse_actions->ButtonFitGrid->setChecked(false); short vcol=0; G.vcolor.getinit(vcol); G.vcolor.definit((short)((vcol+1)%16)); GeometricGraph & G = *(gwp->pGG); Tpoint translate(this->width()/2.,0); int n = G.nv(); svector<tvertex> newvertex(1,n); tvertex v; for(v = 1; v <= n;v++)//translate all the graph G.vcoord[v] /= 2.; for(v = 1; v <= n;v++) {if(G.vcolor[v] != vcol)continue; newvertex[v] = G.NewVertex(G.vcoord[v] + translate); } int m = G.ne(); tvertex v1,v2; for(tedge e = 1; e <= m;e++) {v1 = G.vin[e];v2 = G.vin[-e]; if(G.vcolor[v1] == vcol && G.vcolor[v2] == vcol) G.NewEdge(newvertex[v1],newvertex[v2]); } for(v = 1; v <= n;v++) {if(G.vcolor[v] != vcol)continue; G.NewEdge(v,newvertex[v]); } load(true); mywindow->information();// Informations } }
void GraphEditor::print(QPrinter *printer) {QPainter pp(printer); int nx = (int)gwp->canvas->width(); int ny = (int)gwp->canvas->height(); gwp->canvas->render(&pp,QRectF(0,0,printer->width(),printer->height()),QRect(0,0,nx,ny)); }
void GraphEditor::mouseReleaseEvent(QMouseEvent* event) {//setRenderHints(QPainter::Antialiasing); if(gwp->info_item) //end info {scene()->removeItem(gwp->info_item->rectitem); scene()->removeItem(gwp->info_item); gwp->info_item = 0; setCursor(QCursor(Qt::ArrowCursor)); return; } if(gwp->moving_item) //end moving a vertex {if(!FitToGrid) {gwp->moving_item = 0;return;} GeometricGraph & G = *(gwp->pGG); NodeItem *node = gwp->moving_item; tvertex v = node->v; double prev_x = G.vcoord[v].x(); double prev_y = G.vcoord[v].y(); ToGrid(v); double dx = G.vcoord[v].x() - prev_x; double dy = G.vcoord[v].y() - prev_y; G.vcoord[v].x() = prev_x; G.vcoord[v].y() = prev_y; node->moveBy(dx,-dy); gwp->moving_item = 0; UpdateSizeGrid(); PrintSizeGrid(); return; } if(gwp->moving_subgraph == true) {gwp->moving_subgraph = false; if(!FitToGrid)return; GeometricGraph & G = *(gwp->pGG); Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM); short vcol=0; G.vcolor.getinit(vcol); NodeItem * node; // Find a vertex of the subgraph tvertex mv = 0; tvertex v; for(v = 1; v <= G.nv();v++) {node =(NodeItem *)nodeitem[v]; if(G.vcolor[node->v] != vcol)continue; else {mv = v;break;} } if(!mv)return; double prev_x = G.vcoord[mv].x(); double prev_y = G.vcoord[mv].y(); ToGrid(mv); double dx = G.vcoord[mv].x() - prev_x; double dy = G.vcoord[mv].y() - prev_y; G.vcoord[mv].x() = prev_x; G.vcoord[mv].y() = prev_y; for(v = 1;v <= G.nv();v++) {node =(NodeItem *)nodeitem[v]; if(G.vcolor[node->v] != vcol)continue; node->moveBy(dx,-dy); } UpdateSizeGrid(); PrintSizeGrid(); return; } if(gwp->curs_item)// end creating an edge {GeometricGraph & G = *(gwp->pGG); Prop<EdgeItem *> edgeitem(G.Set(tedge()),PROP_CANVAS_ITEM); Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM); NodeItem* node; EdgeItem *edge; tvertex v1,v2; // Reset the color of starting vertex v1 = gwp->curs_item->v; node = (NodeItem *)(nodeitem[v1]); node->SetColor(color[G.vcolor[v1]]); QPoint p(event->pos()); ToGrid(p); int rtt = FindItem(p,node,edge); v2 = (rtt != node_rtti) ? 0 : node->v; if(rtt != node_rtti) //create a vertex {int h = (int)gwp->canvas->height(); Tpoint pp((double)p.x(),(double)(h - p.y())); v2 = G.NewVertex(pp);ToGrid(v2); nodeitem[v2] = CreateNodeItem(v2,gwp); mywindow->mouse_actions->ButtonUndoGrid->setDisabled(true); if(IsGrid)UpdateSizeGrid(); } else v2 = node->v; if(v1 != v2) // Create an edge {tedge e = G.NewEdge(v1,v2); edgeitem[e] = CreateEdgeItem(e,gwp); } delete gwp->curs_item; gwp->curs_item = 0; mywindow->information();// Informations if(v1 == v2) // We have created a vertex PrintSizeGrid(); return; } }
format value::pp(bool unicode) const { return unicode ? format(get_unicode_name()) : pp(); }