/** * Load extra sources. Since we're on a single host, we might as * well load it directly from the working directory rather than by * uploading to the slaves cache. * */ virtual Bool_t LoadExtraSrcs() { TString tmp2 = fExtraSrcs.Strip(TString::kBoth, ':'); TObjArray* srcs = tmp2.Tokenize(":"); TIter next2(srcs); TObject* obj = 0; while ((obj = next2())) { TString full = gSystem->ConcatFileName(gSystem->WorkingDirectory(), obj->GetName()); Info("LoadExtraSrcs", "Will load %s", full.Data()); Int_t ret = gProof->Load(Form("%s+g", full.Data()), true,true); if (ret < 0) { Error("ProofRailway::PostSetup", "Failed to compile %s",obj->GetName()); return false; } } return true; }
static int tclvarNext(sqlite3_vtab_cursor *cur){ Tcl_Obj *pObj; int n = 0; int ok = 0; tclvar_cursor *pCur = (tclvar_cursor *)cur; Tcl_Interp *interp = ((tclvar_vtab *)(cur->pVtab))->interp; Tcl_ListObjLength(0, pCur->pList1, &n); while( !ok && pCur->i1<n ){ Tcl_ListObjIndex(0, pCur->pList1, pCur->i1, &pObj); ok = next2(interp, pCur, pObj); if( !ok ){ pCur->i1++; } } return 0; }
Path SplineGenerator::makeCatmul(int points, int nodes, int seed) { srand(seed); Path path; //test for catmull Vector2d p0(randf(),0); Vector2d p1(randf(),0); Vector2d p2(randf(),0); Vector2d p3(randf(),0); int pointsPerNode = points/nodes; for (int node=0; node<nodes; ++node) { Vector2d next(randf(),randf()); Vector2d next2(randf(),randf()); //works ok - quite roundy p0=p1; p1=p2; p2=p3; p3=next; //works ok - more roundy // p0=p1; // p1=p2; // p2=next; // p3=next2; for (int x=0;x<pointsPerNode;++x) { float t = x/float(pointsPerNode); Vector2d r = calculateCatmullPoint(t,p0,p1,p2,p3); path.push_back(r); std::cout << r.x << "\t" << r.y << "\t" << std::endl; } } return path; }
inline Color CurveGradient::color_func(const Point &point_, int quality, float supersample)const { Point origin=param_origin.get(Point()); Real width=param_width.get(Real()); std::vector<synfig::BLinePoint> bline(param_bline.get_list().begin(), param_bline.get_list().end()); Gradient gradient=param_gradient.get(Gradient()); bool loop=param_loop.get(bool()); bool zigzag=param_zigzag.get(bool()); bool perpendicular=param_perpendicular.get(bool()); bool fast=param_fast.get(bool()); Vector tangent; Vector diff; Point p1; Real thickness; Real dist; float perp_dist; bool edge_case = false; if(bline.size()==0) return Color::alpha(); else if(bline.size()==1) { tangent=bline.front().get_tangent1(); p1=bline.front().get_vertex(); thickness=bline.front().get_width(); } else { float t; Point point(point_-origin); std::vector<synfig::BLinePoint>::const_iterator iter,next; // Figure out the BLinePoints we will be using, // Taking into account looping. if(perpendicular) { next=find_closest(fast,bline,point,t,bline_loop,&perp_dist); perp_dist/=curve_length_; } else // not perpendicular { next=find_closest(fast,bline,point,t,bline_loop); } iter=next++; if(next==bline.end()) next=bline.begin(); // Setup the curve etl::hermite<Vector> curve( iter->get_vertex(), next->get_vertex(), iter->get_tangent2(), next->get_tangent1() ); // Setup the derivative function etl::derivative<etl::hermite<Vector> > deriv(curve); int search_iterations(7); /*if(quality==0)search_iterations=8; else if(quality<=2)search_iterations=10; else if(quality<=4)search_iterations=8; */ if(perpendicular) { if(quality>7) search_iterations=4; } else // not perpendicular { if(quality<=6)search_iterations=7; else if(quality<=7)search_iterations=6; else if(quality<=8)search_iterations=5; else search_iterations=4; } // Figure out the closest point on the curve if (fast) t = curve.find_closest(fast, point,search_iterations); // Calculate our values p1=curve(t); // the closest point on the curve tangent=deriv(t); // the tangent at that point // if the point we're nearest to is at either end of the // bline, our distance from the curve is the distance from the // point on the curve. we need to know which side of the // curve we're on, so find the average of the two tangents at // this point if (t<0.00001 || t>0.99999) { bool zero_tangent = (tangent[0] == 0 && tangent[1] == 0); if (t<0.5) { if (iter->get_split_tangent_angle() || iter->get_split_tangent_radius() || zero_tangent) { // fake the current tangent if we need to if (zero_tangent) tangent = curve(FAKE_TANGENT_STEP) - curve(0); // calculate the other tangent Vector other_tangent(iter->get_tangent1()); if (other_tangent[0] == 0 && other_tangent[1] == 0) { // find the previous blinepoint std::vector<synfig::BLinePoint>::const_iterator prev; if (iter != bline.begin()) (prev = iter)--; else if (loop) (prev = bline.end())--; else prev = iter; etl::hermite<Vector> other_curve(prev->get_vertex(), iter->get_vertex(), prev->get_tangent2(), iter->get_tangent1()); other_tangent = other_curve(1) - other_curve(1-FAKE_TANGENT_STEP); } // normalise and sum the two tangents tangent=(other_tangent.norm()+tangent.norm()); edge_case=true; } } else { if (next->get_split_tangent_angle() || next->get_split_tangent_radius() || zero_tangent) { // fake the current tangent if we need to if (zero_tangent) tangent = curve(1) - curve(1-FAKE_TANGENT_STEP); // calculate the other tangent Vector other_tangent(next->get_tangent2()); if (other_tangent[0] == 0 && other_tangent[1] == 0) { // find the next blinepoint std::vector<synfig::BLinePoint>::const_iterator next2(next); if (++next2 == bline.end()) { if (loop) next2 = bline.begin(); else next2 = next; } etl::hermite<Vector> other_curve(next->get_vertex(), next2->get_vertex(), next->get_tangent2(), next2->get_tangent1()); other_tangent = other_curve(FAKE_TANGENT_STEP) - other_curve(0); } // normalise and sum the two tangents tangent=(other_tangent.norm()+tangent.norm()); edge_case=true; } } } tangent = tangent.norm(); if(perpendicular) { tangent*=curve_length_; p1-=tangent*perp_dist; tangent=-tangent.perp(); } else // not perpendicular // the width of the bline at the closest point on the curve thickness=(next->get_width()-iter->get_width())*t+iter->get_width(); } if(perpendicular) { if(quality>7) { dist=perp_dist; /* diff=tangent.perp(); const Real mag(diff.inv_mag()); supersample=supersample*mag; */ supersample=0; } else { diff=tangent.perp(); //p1-=diff*0.5; const Real mag(diff.inv_mag()); supersample=supersample*mag; diff*=mag*mag; dist=(point_-origin - p1)*diff; } } else // not perpendicular { if (edge_case) { diff=(p1-(point_-origin)); if(diff*tangent.perp()<0) diff=-diff; diff=diff.norm()*thickness*width; } else diff=tangent.perp()*thickness*width; p1-=diff*0.5; const Real mag(diff.inv_mag()); supersample=supersample*mag; diff*=mag*mag; dist=(point_-origin - p1)*diff; } if(loop) dist-=floor(dist); if(zigzag) { dist*=2.0; supersample*=2.0; if(dist>1)dist=2.0-dist; } if(loop) { if(dist+supersample*0.5>1.0) { float left(supersample*0.5-(dist-1.0)); float right(supersample*0.5+(dist-1.0)); Color pool(gradient(1.0-(left*0.5),left).premult_alpha()*left/supersample); if (zigzag) pool+=gradient(1.0-right*0.5,right).premult_alpha()*right/supersample; else pool+=gradient(right*0.5,right).premult_alpha()*right/supersample; return pool.demult_alpha(); } if(dist-supersample*0.5<0.0) { float left(supersample*0.5-dist); float right(supersample*0.5+dist); Color pool(gradient(right*0.5,right).premult_alpha()*right/supersample); if (zigzag) pool+=gradient(left*0.5,left).premult_alpha()*left/supersample; else pool+=gradient(1.0-left*0.5,left).premult_alpha()*left/supersample; return pool.demult_alpha(); } } return gradient(dist,supersample); }
void RectMesh::populate() { vertices = new float[vertexCount * 3]; for (unsigned i = 0; i < vertexCount; i++) { vertices[i * 3 + 0] = points[i][0]; vertices[i * 3 + 1] = points[i][1]; vertices[i * 3 + 2] = points[i][2]; } indicies = new GLint[indicesCount]; unsigned vertexIndex = 0; unsigned index = 0; bool odd = true; bool up = true; while (index < indicesCount) { indicies[index] = vertexIndex; if ((index + 1) % (2 * length) == 0) { indicies[++index] = vertexIndex; odd = !odd; up = !up; } if (up) { vertexIndex += length; } else { if (odd) { vertexIndex -= (length - 1); } else { vertexIndex -= (length + 1); } } up = !up; index++; } normals = new float[vertexCount * 3]; unsigned int c, n1, n2; unsigned int prevC = 0; odd = true; for (unsigned i = 0; i < indicesCount; i++) { c = indicies[i]; if (i == indicesCount - 2) { n1 = indicies[i - 1]; n2 = indicies[i + 1]; } else if (i == indicesCount - 1) { n1 = indicies[i - 2]; n2 = indicies[i - 1]; } else if (i % length == length - 2) { n1 = indicies[i - 1]; n2 = indicies[i + 1]; } else { n1 = indicies[i + 1]; n2 = indicies[i + 2]; } vec3 currentPoint(vertices[c * 3 + 0], vertices[c * 3 + 1], vertices[c * 3 + 2]); vec3 next1(vertices[n1 * 3 + 0], vertices[n1 * 3 + 1], vertices[n1 * 3 + 2]); vec3 next2(vertices[n2 * 3 + 0], vertices[n2 * 3 + 1], vertices[n2 * 3 + 2]); vec3 v1 = next1 - currentPoint; vec3 v2 = next2 - currentPoint; vec3 crossV = normalize(cross(v1, v2)); if ((prevC == c) && (prevC != 0)) { odd = !odd; } if (!odd) { crossV = -crossV; } if (c > vertexCount - length - 1) { crossV = -crossV; } normals[c * 3 + 0] = crossV[0]; normals[c * 3 + 1] = crossV[1]; normals[c * 3 + 2] = crossV[2]; prevC = c; } for (unsigned i = 0; i < indicesCount; i++) { c = indicies[i]; if (i == indicesCount - 2) { n1 = indicies[i - 1]; n2 = indicies[i]; } else if (i == indicesCount - 1) { n1 = indicies[i - 2]; n2 = indicies[i - 1]; } else { n1 = indicies[i + 1]; n2 = indicies[i + 2]; } vec3 currentNormal(normals[c * 3 + 0], normals[c * 3 + 1], normals[c * 3 + 2]); vec3 nextNormal1(normals[n1 * 3 + 0], normals[n1 * 3 + 1], normals[n1 * 3 + 2]); vec3 nextNormal2(normals[n2 * 3 + 0], normals[n2 * 3 + 1], normals[n2 * 3 + 2]); vec3 totalNormal = normalize(currentNormal + nextNormal1 + nextNormal2); normals[c * 3 + 0] = totalNormal[0]; normals[c * 3 + 1] = totalNormal[1]; normals[c * 3 + 2] = totalNormal[2]; } }
void addcanvases(){ fSavePath = "data/perfLL"; const Int_t narr = 20; gStyle->SetOptStat(0); gStyle->SetOptTitle(0); TFile *f1 = TFile::Open("c_l3.root"); TIter next1(f1->GetListOfKeys()); TKey *key1; Int_t it1 = 0; TCanvas *carr1[narr]; while((key1 = (TKey*)next1())) { TClass *cl = gROOT->GetClass(key1->GetClassName()); if (!cl->InheritsFrom("TCanvas")) continue; carr1[it1] = (TCanvas*)key1->ReadObj(); it1++; } TFile *f2 = TFile::Open("c_l0.root"); TIter next2(f2->GetListOfKeys()); TKey *key2; Int_t it2 = 0; TCanvas *carr2[narr]; while ((key2 = (TKey*)next2())) { TClass *cl = gROOT->GetClass(key2->GetClassName()); if (!cl->InheritsFrom("TCanvas")) continue; carr2[it2] = (TCanvas*)key2->ReadObj(); it2++; } TLegend *leg = new TLegend(0.2,0.7,0.5,0.9); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); for(Int_t i=0; i<it2; i++){ carr1[i]->Draw(); //leg->AddEntry( carr1[i],"3x3 full coverage","l"); //leg->Draw(); canvasAdd(carr1[i]); TIter next(carr2[i]->GetListOfPrimitives()); TObject *obj; while((obj = next())){ // if(obj->InheritsFrom("TH1F")){ // TH1F *h = (TH1F*)obj; // std::cout<<"name "<< h->GetName() <<std::endl; // h->SetLineStyle(7); // h->SetLineWidth(2); // h->Draw("same"); // } if(obj->InheritsFrom("TGraph")){ TGraph *h = (TGraph*)obj; std::cout<<"name "<< h->GetName() <<std::endl; h->SetLineColor(32); h->SetMarkerColor(2); // h->SetLineWidth(2); h->Draw("same PL"); // leg->AddEntry(h,"6.5x6.5 MCP PMTs coverage","lp"); // leg->Draw(); } } } std::cout<<"save all " <<std::endl; canvasSave(0,1); }
inline Point CurveWarp::transform(const Point &point_, Real *dist, Real *along, int quality)const { std::vector<synfig::BLinePoint> bline(param_bline.get_list().begin(),param_bline.get_list().end()); Point start_point=param_start_point.get(Point()); Point end_point=param_end_point.get(Point()); Point origin=param_origin.get(Point()); bool fast=param_fast.get(bool()); Real perp_width=param_perp_width.get(Real()); Vector tangent; Vector diff; Point p1; Real thickness; bool edge_case = false; float len(0); bool extreme; float t; if(bline.size()==0) return Point(); else if(bline.size()==1) { tangent=bline.front().get_tangent1(); p1=bline.front().get_vertex(); thickness=bline.front().get_width(); t = 0.5; extreme = false; } else { Point point(point_-origin); std::vector<synfig::BLinePoint>::const_iterator iter,next; // Figure out the BLinePoint we will be using, next=find_closest_to_bline(fast,bline,point,t,len,extreme); iter=next++; if(next==bline.end()) next=bline.begin(); // Setup the curve etl::hermite<Vector> curve(iter->get_vertex(), next->get_vertex(), iter->get_tangent2(), next->get_tangent1()); // Setup the derivative function etl::derivative<etl::hermite<Vector> > deriv(curve); int search_iterations(7); if(quality<=6)search_iterations=7; else if(quality<=7)search_iterations=6; else if(quality<=8)search_iterations=5; else search_iterations=4; // Figure out the closest point on the curve if (fast) t = curve.find_closest(fast, point,search_iterations); // Calculate our values p1=curve(t); // the closest point on the curve tangent=deriv(t); // the tangent at that point // if the point we're nearest to is at either end of the // bline, our distance from the curve is the distance from the // point on the curve. we need to know which side of the // curve we're on, so find the average of the two tangents at // this point if (t<0.00001 || t>0.99999) { bool zero_tangent = (tangent[0] == 0 && tangent[1] == 0); if (t<0.5) { if (iter->get_split_tangent_angle() || iter->get_split_tangent_radius() || zero_tangent) { // fake the current tangent if we need to if (zero_tangent) tangent = curve(FAKE_TANGENT_STEP) - curve(0); // calculate the other tangent Vector other_tangent(iter->get_tangent1()); if (other_tangent[0] == 0 && other_tangent[1] == 0) { // find the previous blinepoint std::vector<synfig::BLinePoint>::const_iterator prev; if (iter != bline.begin()) (prev = iter)--; else prev = iter; etl::hermite<Vector> other_curve(prev->get_vertex(), iter->get_vertex(), prev->get_tangent2(), iter->get_tangent1()); other_tangent = other_curve(1) - other_curve(1-FAKE_TANGENT_STEP); } // normalise and sum the two tangents tangent=(other_tangent.norm()+tangent.norm()); edge_case=true; } } else { if (next->get_split_tangent_angle() || next->get_split_tangent_radius() || zero_tangent) { // fake the current tangent if we need to if (zero_tangent) tangent = curve(1) - curve(1-FAKE_TANGENT_STEP); // calculate the other tangent Vector other_tangent(next->get_tangent2()); if (other_tangent[0] == 0 && other_tangent[1] == 0) { // find the next blinepoint std::vector<synfig::BLinePoint>::const_iterator next2(next); if (++next2 == bline.end()) next2 = next; etl::hermite<Vector> other_curve(next->get_vertex(), next2->get_vertex(), next->get_tangent2(), next2->get_tangent1()); other_tangent = other_curve(FAKE_TANGENT_STEP) - other_curve(0); } // normalise and sum the two tangents tangent=(other_tangent.norm()+tangent.norm()); edge_case=true; } } } tangent = tangent.norm(); // the width of the bline at the closest point on the curve thickness=(next->get_width()-iter->get_width())*t+iter->get_width(); } if (thickness < TOO_THIN && thickness > -TOO_THIN) { if (thickness > 0) thickness = TOO_THIN; else thickness = -TOO_THIN; } if (extreme) { Vector tangent; if (t < 0.5) { std::vector<synfig::BLinePoint>::const_iterator iter(bline.begin()); tangent = iter->get_tangent1().norm(); len = 0; } else { std::vector<synfig::BLinePoint>::const_iterator iter(--bline.end()); tangent = iter->get_tangent2().norm(); len = curve_length_; } len += (point_-origin - p1)*tangent; diff = tangent.perp(); } else if (edge_case) { diff=(p1-(point_-origin)); if(diff*tangent.perp()<0) diff=-diff; diff=diff.norm(); } else diff=tangent.perp(); // diff is a unit vector perpendicular to the bline const Real unscaled_distance((point_-origin - p1)*diff); if (dist) *dist = unscaled_distance; if (along) *along = len; return ((start_point + (end_point - start_point) * len / curve_length_) + perp_ * unscaled_distance/(thickness*perp_width)); }