CCollisionResponseData::CCollisionResponseData(CInputStream& in, CSimplePool* resPool) : x30_RNGE(50.f), x34_FOFF(0.2f) { x0.resize(94); x10.resize(94); x20.resize(94); FourCC clsId = CPF::GetClassID(in); if (clsId == SBIG('CRSM')) { CRandom16 rand{99}; CGlobalRandom gr(rand); while (clsId != SBIG('_END')) { clsId = CPF::GetClassID(in); if (CheckAndAddResourceToResponse(clsId, in, resPool)) continue; if (clsId == SBIG('RNGE')) { CPF::GetClassID(in); x30_RNGE = CPF::GetReal(in); } else if (clsId == SBIG('FOFF')) { CPF::GetClassID(in); x34_FOFF = CPF::GetReal(in); } } } }
psiNtupler(const char * inFilename, const char * outFilename , float v1, float v2) { TCanvas c("IV","IV",800,600); TFile f(outFilename,"RECREATE"); TNtuple iv("IV","IV","time:V:I"); iv.ReadFile(inFilename); iv.Draw("-I:-V"); TGraph gr(iv.GetSelectedRows(),iv.GetV2(), iv.GetV1()); std::cout << "Results: " << gr.Eval(v1) << " " << gr.Eval(v2) << " " << (gr.Eval(v1)/gr.Eval(v2)) << " "; if(gr.Eval(v1)/gr.Eval(v2) > 2 || fabs(gr.Eval(v1)) > 0.000010) { std::cout << "C"; } else { if(fabs(gr.Eval(v1)) > 0.000002) std::cout << "B" ; else std::cout << "A"; } std::cout << " " << std::endl; //std::cout << "100: " << gr.Eval(100) << std::endl; //std::cout << "ratio150/100: " << gr.Eval(150)/gr.Eval(100) << std::endl; gr.Write(); c.SaveAs("debug.png"); iv.Write(); f.Write(); exit(0); }
wxNonOwnedWindowShapeImpl(wxNonOwnedWindow* win, const wxGraphicsPath& path) : m_win(win), m_path(path) { // Create the region corresponding to this path and set it as windows // shape. wxScopedPtr<wxGraphicsContext> context(wxGraphicsContext::Create(win)); Region gr(static_cast<GraphicsPath*>(m_path.GetNativePath())); win->SetShape( wxRegion( gr.GetHRGN(static_cast<Graphics*>(context->GetNativeContext())) ) ); // Connect to the paint event to draw the border. // // TODO: Do this only optionally? m_win->Connect ( wxEVT_PAINT, wxPaintEventHandler(wxNonOwnedWindowShapeImpl::OnPaint), NULL, this ); }
void DragonBustNode::genBezierSubdivide(Vec3Array g, uint depth, Vec3Array& points) { /* * Based on code from "Curved Surfaces Using Bézier Patches" * http://www.gamasutra.com/view/feature/131755/curved_surfaces_using_bzier_.php?page=6 * See: Bibliography. */ if (depth == 0) { points.push_back(g[0]); points.push_back(g[2]); return; } Vec3Array gl(3); Vec3Array gr(3); gl[0] = g[0]; gl[1] = (g[0] + g[1]) * 0.5f; gr[1] = (g[1] + g[2]) * 0.5f; gl[2] = gr[0] = (gl[1] + gr[1]) * 0.5f; gr[2] = g[2]; genBezierSubdivide(gl, --depth, points); genBezierSubdivide(gr, depth, points); }
int main(){ int round = 15; GeneralInteger gden(1); GeneralInteger gnum(0); for(int i= 0; i< round; ++i){ gden = gden.multiply(i+2); } gden.print(); printf("\n"); for(int i = (round/2)+1; i<=round; ++i){ vector<int> combi; vector<int> flag; combi.resize(i); for(unsigned int j = 0; j < combi.size(); ++j) combi[j]= j; do{ flag.clear(); flag.resize(round, 0); for(unsigned int j = 0; j < combi.size(); ++j) flag[combi[j]] = 1; GeneralInteger gtp(1); for(unsigned int j = 0; j < flag.size(); ++j){ if(flag[j] == 0) gtp = gtp.multiply(j+1); } gnum += gtp; }while(next_combination(combi, round, i)); } gnum.print(1); GeneralInteger gr(1); gden.print(); //gr= gden.divide(); printf("\n"); }
LRESULT ScrollForm::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { PAINTSTRUCT ps; HDC dc = BeginPaint(&ps); Graphics gr(dc); SolidBrush br(bgColor); if (formWnd) { RECT rcForm; formWnd->GetClientRect(&rcForm); formWnd->MapWindowPoints(m_hWnd, &rcForm); if (rcForm.right <= ps.rcPaint.right) { gr.FillRectangle(&br, rcForm.right, ps.rcPaint.top, (ps.rcPaint.right - rcForm.right)+1, (ps.rcPaint.bottom - ps.rcPaint.top)+1); } if (rcForm.bottom <= ps.rcPaint.bottom) { gr.FillRectangle(&br, ps.rcPaint.left, rcForm.bottom, (ps.rcPaint.right - ps.rcPaint.left)+1, (ps.rcPaint.bottom - rcForm.bottom)+1); } } else { gr.FillRectangle(&br, ps.rcPaint.left, ps.rcPaint.top, (ps.rcPaint.right - ps.rcPaint.left)+1, (ps.rcPaint.bottom - ps.rcPaint.top)+1); } EndPaint(&ps); return 0; }
void PathDeformRenderer::generateLensPixmap() { qreal rad = m_radius + LENS_EXTENT; QRect bounds = circle_bounds(QPointF(), rad, 0); QPainter painter; if (preferImage()) { m_lens_image = QImage(bounds.size(), QImage::Format_ARGB32_Premultiplied); m_lens_image.fill(0); painter.begin(&m_lens_image); } else { m_lens_pixmap = QPixmap(bounds.size()); m_lens_pixmap.fill(Qt::transparent); painter.begin(&m_lens_pixmap); } QRadialGradient gr(rad, rad, rad, 3 * rad / 5, 3 * rad / 5); gr.setColorAt(0.0, QColor(255, 255, 255, 191)); gr.setColorAt(0.2, QColor(255, 255, 127, 191)); gr.setColorAt(0.9, QColor(150, 150, 200, 63)); gr.setColorAt(0.95, QColor(0, 0, 0, 127)); gr.setColorAt(1, QColor(0, 0, 0, 0)); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(gr); painter.setPen(Qt::NoPen); painter.drawEllipse(0, 0, bounds.width(), bounds.height()); }
void DoPaint(winx::DCHandle dc) { if (m_image) { Gdiplus::Graphics gr(dc); Gdiplus::Rect rect(0, 0, m_image->GetWidth(), m_image->GetHeight()); gr.DrawImage(m_image, rect); } }
int main(int argc,char **argv) { mgl_textdomain(argv?argv[0]:NULL); Foo *foo = new Foo; mglQT gr(foo,"MathGL examples"); foo->Gr = &gr; foo->Run(); // <-- need MathGL version which use pthread return gr.Run(); }
// REF [file] >> ${MATHGL_HOME}/examples/glut_example.cpp. void glut_example() { mglGLUT gr(sample_1, "1D plots"); //mglGLUT gr(sample_2, "2D plots"); //mglGLUT gr(sample_3, "3D plots"); //mglGLUT gr(sample_d, "Dual plots"); //mglGLUT gr(test_wnd, "Testing"); //mglGLUT gr(sample, "Example of molecules"); }
double Utils::probToLogOdds(double prob) { if (gr(prob, 1) || (sm(prob, 0))) { throw std::invalid_argument(string("probToLogOdds: probability must ") + string("be in [0,1] ") + std::to_string(prob)); } double p = SMALL + (1.0 - 2 * SMALL) * prob; return log(p / (1 - p)); }
bool GraphsListN::addGraphsList( const GraphsListN& gln ) { if( iVerticesCount != gln.get_iVerticesCount( ) ) return false; vector< Graph > gr( gln.get_graphs( ) ); graphs.insert( graphs.end( ), gr.begin( ), gr.end( ) ); return true; }
bool GenomicRegionCollection<T>::ReadBED(const std::string & file, const BamHeader& hdr) { m_sorted = false; idx = 0; gzFile fp = NULL; fp = strcmp(file.c_str(), "-")? gzopen(file.c_str(), "r") : gzdopen(fileno(stdin), "r"); if (file.empty() || !fp) { std::cerr << "BED file not readable: " << file << std::endl; return false; } // http://www.lemoda.net/c/gzfile-read/ while (1) { int err; char buffer[GZBUFFER]; gzgets(fp, buffer, GZBUFFER); int bytes_read = strlen(buffer); // get one line if (bytes_read < GZBUFFER - 1) { if (gzeof (fp)) break; else { const char * error_string; error_string = gzerror (fp, &err); if (err) { fprintf (stderr, "Error: %s.\n", error_string); exit (EXIT_FAILURE); } } } // prepare to loop through each field of BED line //size_t counter = 0; std::string chr, pos1, pos2; std::string line(buffer); std::istringstream iss_line(line); std::string val; if (line.find("#") != std::string::npos) continue; // read first three BED columns iss_line >> chr >> pos1 >> pos2; // construct the GenomicRegion T gr(chr, pos1, pos2, hdr); if (gr.chr >= 0) m_grv->push_back(gr); } return true; }
// REF [file] >> ${MATHGL_HOME}/examples/glut_example.cpp. void qt_example() { // NOTICE [caution] >> Run-time error in DEBUG mode. mglQT gr(sample_1, "1D plots"); //mglQT gr(sample_2, "2D plots"); //mglQT gr(sample_3, "3D plots"); //mglQT gr(sample_d, "Dual plots"); //mglQT gr(test_wnd, "Testing"); //mglQT gr(sample, "Example of molecules"); }
KVGroupReconstructor* KVExpSetUp::GetReconstructorForGroup(const KVGroup* g) const { // Override KVMultiDetArray method // Call each array in turn to get reconstructor for group TIter next_array(&fMDAList); KVMultiDetArray* mda; KVGroupReconstructor* gr(nullptr); while ((mda = (KVMultiDetArray*)next_array())) { if ((gr = mda->GetReconstructorForGroup(g))) break; } return gr; }
int main(int argc, char **argv){ FILE *fin, *fout; // File streams char *fileIn, *fileOut; // File names char fileInName[] = "in.dat"; char fileOutName[] = "out.dat"; int numPart = 400; double radSep = 0.112725; double size = 1; int numBins = 150; fileIn = fileInName; fileOut = fileOutName; if(argc == 1){ // Use defualts fin = fopen(fileIn, "r"); fout = fopen(fileOut, "w"); } else{ if(argc >= 2){ // Use given input file fileIn = argv[1]; fin = fopen(fileIn, "r"); if(fin == NULL){ printf("!! Can't open %s\n", argv[1]); exit(0); } fout = fopen(fileOut, "w"); } if(argc >= 3){ // Use given output file fileOut = argv[2]; fout = fopen(fileOut, "w"); if(fout == NULL){ printf("C> Making file %s\n", fileOut); exit(0); } } if(argc >= 4){ // Use particle number sscanf(argv[3],"%d",&numPart); } if(argc >= 5){ // Use box size sscanf(argv[4],"%lf",&radSep); } if(argc >= 6){ // Use box size sscanf(argv[5],"%lf",&size); } if(argc >= 7){ // Use box size sscanf(argv[6],"%d",&numBins); } } //printf("Running with in=%s, out=%s, numPart=%d, radSep=%f size=%f, bins=%d\n", fileIn, fileOut, numPart, radSep, size, numBins); gr(fin, fout, numPart, radSep, size, numBins); fclose(fin); fclose(fout); return 0; }
int main(int argc, char* argv[]) { int percent = argc >= 2 && argv[1] ? strtol(argv[1], 0, 10) : 100; int start_x = argc >= 3 && argv[2] ? strtol(argv[2], 0, 10) : 0; int start_y = argc >= 4 && argv[3] ? strtol(argv[3], 0, 10) : 0; Grids gr(percent, true); //gr.draw(); //gr.print(); gr.draw(' ', ' ', ' '); gr.DFS(start_x, start_y); gr.print(); }
int main() { int first[] = {1, 1, 1, 5, 5, 4}; std::vector<int> firstVector(first, first + sizeof(first) / sizeof(int) ); int second[] = {2, 3, 4, 4, 2, 2}; std::vector<int> secondVector(second, second + sizeof(second) / sizeof(int) ); Graph gr(firstVector, secondVector); std::cout << gr.numOutgoing(1) << std::endl; try { std::cout << gr.numOutgoing(9); } catch(std::exception &error) { std::cerr << error.what(); } }
void plotVecField(const cv::Mat &gradientX, const cv::Mat &gradientY, const cv::Mat &img) { mglData *xData = matToData<double>(gradientX); mglData *yData = matToData<double>(gradientY); mglData *imgData = matToData<float>(img); mglGraph gr(0,gradientX.cols * 20, gradientY.rows * 20); gr.Vect(*xData, *yData); gr.Mesh(*imgData); gr.WriteFrame("vecField.png"); delete xData; delete yData; delete imgData; }
void test_smspec_wg() { std::string kw( "WWCT" ); std::string wg( "OP1" ); std::string gr( "WG1" ); ERT::smspec_node well( ECL_SMSPEC_WELL_VAR, wg, kw ); ERT::smspec_node group( ECL_SMSPEC_GROUP_VAR, gr, kw ); test_assert_true(well.wgname() == wg); test_assert_true(well.type() == ECL_SMSPEC_WELL_VAR ); test_assert_true(group.wgname() == gr); test_assert_true(group.type() == ECL_SMSPEC_GROUP_VAR ); }
void Draw1C::DrawImage(wchar_t *image_path, short x, short y, short w, short h, int angle, bool flip_x, bool flip_y) { if (!image_path) return; if (!wcslen(image_path)) return; Image image(image_path, false); if (flip_x || flip_y) { RotateFlipType rft; if (flip_x && !flip_y) rft = RotateFlipType::RotateNoneFlipX; else if (!flip_x && flip_y) rft = RotateFlipType::RotateNoneFlipY; else if (flip_x && flip_y) rft = RotateFlipType::RotateNoneFlipXY; image.RotateFlip(rft); } if (angle) { Image *image_copy = image.Clone(); Graphics gr(image_copy); int xc = image_copy->GetWidth() / 2; int yc = image_copy->GetHeight() / 2; gr.TranslateTransform((REAL)xc, (REAL)yc); gr.RotateTransform((REAL)angle); gr.TranslateTransform((REAL)-xc, (REAL)-yc); gr.Clear(Color(0, 0, 0, 0)); gr.DrawImage(&image, 0, 0, image.GetWidth(), image.GetHeight()); Graphics g(canvas); g.DrawImage(image_copy, x, y, w, h); delete image_copy; } else { Graphics g(canvas); g.DrawImage(&image, x, y, w, h); } }
void ClockWidget::drawClockWidget() { _clock_bg = QImage(prefix + "background.png"); /*gloss stuff*/ gloss = QImage(prefix + "gloss.png"); //gloss.convertDepth (32); // gloss.setAlphaBuffer (true); face = QPixmap(prefix + "face.png"); thedot = QPixmap(prefix + "thedot.png"); //date = QPixmap(prefix+"date_field.png"); /**seconds first **/ _secs_hand = QPixmap().fromImage(QImage(prefix + "second-hand-long.png")); sec_timer = new QTimer(this); connect(sec_timer, SIGNAL(timeout()), this, SLOT(drawSeconds())); sec_timer->start(1000); /** Mins after that **/ _mins_hand = QPixmap().fromImage(QImage(prefix + "second-hand.png")); _hour_hand = QPixmap().fromImage(QImage(prefix + "second-hand.png")); /**Createsa a nice Lense**/ /** Prerender into Qimage to save Processing in Painter event**/ double rad = ((face.width() / 2)) - 8.0; int offset = 28; QRect bounds(0, 0, face.width() - offset, face.height() - offset); QPainter p; lens = QImage(QSize(face.width() - offset, face.height() - offset), QImage::Format_ARGB32_Premultiplied); lens.fill(0); p.begin(&lens); QRadialGradient gr(rad, rad, rad, 3 * rad / 5, 3 * rad / 5); gr.setColorAt(0.0, QColor(255, 255, 255, 191)); gr.setColorAt(0.2, QColor(255, 255, 231, 191)); gr.setColorAt(0.9, QColor(150, 150, 200, 65)); gr.setColorAt(0.95, QColor(0, 0, 0, 0)); gr.setColorAt(1, QColor(0, 0, 0, 0)); p.setRenderHint(QPainter::Antialiasing); p.setBrush(gr); p.setPen(Qt::NoPen); p.drawEllipse(0, 0, bounds.width(), bounds.height()); p.end(); }
void ScatterScalarResponse<PHAL::AlbanyTraits::Residual, Traits>:: postEvaluate(typename Traits::PostEvalData workset) { // Here we scatter the *global* response //Teuchos::RCP<Epetra_Vector> g = workset.g; Teuchos::RCP<Tpetra_Vector> gT = workset.gT; //Tpetra version Teuchos::ArrayRCP<ST> gT_nonconstView; if (gT != Teuchos::null) { gT_nonconstView = gT->get1dViewNonConst(); } if (Teuchos::nonnull(gT)) for (PHAL::MDFieldIterator<ScalarT> gr(this->global_response); ! gr.done(); ++gr) gT_nonconstView[gr.idx()] = *gr; }
int main(int argc,char **argv) { mglFLTK gr("test"); gr.RunThr(); // <-- need MathGL version which use pthread for(int i=0;i<10;i++) // do calculation { long_calculations();// which can be very long pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1); gr.Clf(); // make new drawing gr.Line(mglPoint(),pnt,"Ar2"); char str[10] = "i=0"; str[3] = '0'+i; gr.Update(); // update window } return 0; // finish calculations and close the window }
void edit_graphics_rep::invalidate_graphical_object () { SI gx1, gy1, gx2, gy2; if (find_graphical_region (gx1, gy1, gx2, gy2) && !is_nil (go_box)) { int i; rectangles rs; rectangle gr (gx1, gy1, gx2, gy2); for (i=0; i<go_box->subnr(); i++) { box b= go_box->subbox (i); rs= rectangles (rectangle (b->x3, b->y3, b->x4, b->y4), rs); } rs= rs & rectangles (gr); invalidate (rs); } }
// generates a random graph using the benchmark approach Graph::Graph(int n1, int k1, int n2, int k2) { srand(getpid()); // srand(time(NULL)); nb_nodes = n1*n2; vector<vector<int> > gr(nb_nodes); for (int i=0 ; i<nb_nodes ; i++) gr[i].resize(nb_nodes,0); nb_links = 0; for (int i=0 ; i<nb_nodes ; i++) for (int j=i+1 ; j<nb_nodes ; j++) { double v = rand()*1./RAND_MAX; if (i/n1==j/n1) { // i and j in the same subgroup if (v<=(k1*1.)/(n1-1.)) { gr[i][j]=gr[j][i]=1; nb_links++; } } else { // i and j in different groups if (v<=(k2*1.)/(n1*(n2-1.))) { gr[i][j]=gr[j][i]=1; nb_links++; } } } total_weight = 2*nb_links; weights = NULL; degrees = (int *)malloc((long)nb_nodes*4); for (int i=0 ; i<nb_nodes ; i++) { int d = 0; for (int j=0 ; j<nb_nodes ; j++) d+=gr[i][j]; degrees[i]=d; } for (int i=1 ; i<nb_nodes ; i++) degrees[i]+=degrees[i-1]; links = (int *)malloc((long)nb_links*8); int pos=0; for (int i=0 ; i<nb_nodes ; i++) for (int j=0 ; j<nb_nodes ; j++) if (gr[i][j]==1) links[pos++]=j; }
void Histogram2D::Build(VData&data) { vec3 voxel_size = data.spacing; chunk_size.y = wxGetNumberFromUser( "Enter chunk size for the gradient", _T("Enter a number(>0):"), _T("Numeric input"), chunk_size.y, 1, 2024, 0 ); ivec3 data_size = data.GetSize(); hist_size = ivec2(1024,256); mag_scale = (float)(hist_size.y*chunk_size.y)/(float)(256*256); if(hist)delete[]hist; hist = new unsigned int[hist_size.x*hist_size.y]; memset(hist,0,hist_size.x*hist_size.y*sizeof(int)); int max_h = data_size.x*data_size.y*data_size.z/(hist_size.y*hist_size.x); if(!max_h)max_h=1; for(int i=0;i<data_size.x-1;i+=2) for(int j=0;j<data_size.y-1;j+=2) for(int k=0;k<data_size.z-1;k+=2) { unsigned int val = data.GetValue(i,j,k); ivec3 gr(-val); gr.x += data.GetValue(i+1,j,k); gr.y += data.GetValue(i,j+1,k); gr.z += data.GetValue(i,j,k+1); unsigned int tmpv = val/chunk_size.x; unsigned int grad_mag = sqrt(sqr(gr.x/voxel_size.x)+sqr(gr.y/voxel_size.y)+sqr(gr.z/voxel_size.z))/chunk_size.y; // tmpv=rand()%hist_size.x; // grad_mag=rand()%hist_size.y; if(tmpv>=0 && tmpv<hist_size.x && grad_mag<hist_size.y) { int id = tmpv+grad_mag*hist_size.x; if(rand()%max_h > hist[id]) hist[id]++; } } max_chunk = 0; unsigned int *hh = hist; for(int i=0;i<hist_size.x*hist_size.y;i++,hh++) { if(max_chunk<*hh)max_chunk=*hh; } //UpdateTexture(); need_reload_txt=1; }
int main() { int ct=1; while (1) { scanf("%d%d%d", &s, &t, &n); if (s == 0 && t == 0 && n == 0) break; printf("Case %d:\n", ct++); w = n*(t+s) + t; for (int i = 0; i < n; i++) { for (int j = 0; j < t; j++) hor(); for (int j = 0; j < s; j++) gr(); } for (int j = 0; j < t; j++) hor(); printf("\n"); } return 0; }
const array_matrix_type make_gm( const array_vector_type& gd ) const { auto const N = gd.size(); array_matrix_type gr( N, N ); array_matrix_type gc( N, N ); for ( size_type i = 0; i != N; ++i ) { std::fill( gr.row_begin( i ), gr.row_end( i ), gd[i] ); std::fill( gc.col_begin( i ), gc.col_end( i ), gd[i] ); } auto gm = gr - gc; //std::copy( gd.begin(), gd.end(), gm.diag_begin() ); std::fill( gm.diag_begin(), gm.diag_end(), gm[0][1] ); return gm; }
void test_smspec_wg() { std::string wkw( "WWCT" ); std::string gkw( "GWCT" ); std::string wg( "OP1" ); std::string gr( "WG1" ); ERT::smspec_node well( ECL_SMSPEC_WELL_VAR, wg, wkw ); ERT::smspec_node group( ECL_SMSPEC_GROUP_VAR, gr, gkw ); test_assert_string_equal(well.key1() , "WWCT:OP1"); test_assert_string_equal(well.keyword() , "WWCT"); test_assert_true(well.wgname() == wg); test_assert_true(well.type() == ECL_SMSPEC_WELL_VAR ); test_assert_string_equal(group.key1(), "GWCT:WG1"); test_assert_string_equal(group.keyword() , "GWCT"); test_assert_true(group.wgname() == gr); test_assert_true(group.type() == ECL_SMSPEC_GROUP_VAR ); }