/** * Description not yet available. * \param */ dmatrix laplace_approximation_calculator::get_gradient_for_hessian_calcs (const dmatrix& local_Hess,double & f) { int us=local_Hess.indexmax(); int nvar=us*us; independent_variables cy(1,nvar); cy.initialize(); int ii=1; int i,j; for (i=1;i<=us;i++) for (j=1;j<=us;j++) cy(ii++)=local_Hess(i,j); dvar_vector vy=dvar_vector(cy); dvar_matrix vHess(1,us,1,us); ii=1; for (i=1;i<=us;i++) for (j=1;j<=us;j++) vHess(i,j)=vy(ii++); dvariable vf=0.0; int sgn=0; vf+=0.5*ln_det(vHess,sgn); f=value(vf); dvector g(1,nvar); gradcalc(nvar,g); dmatrix hessadjoint(1,us,1,us); ii=1; for (i=1;i<=us;i++) for (j=1;j<=us;j++) hessadjoint(i,j)=g(ii++); return hessadjoint; }
KCanvasPath* SVGEllipseElement::toPathData() const { float _cx = cx()->baseVal()->value(), _cy = cy()->baseVal()->value(); float _rx = rx()->baseVal()->value(), _ry = ry()->baseVal()->value(); return KCanvasCreator::self()->createEllipse(_cx, _cy, _rx, _ry); }
//----------------------------------------------------------------------------- int sample_d(mglGraph *gr) { mglData a(50,50),b(50,50); mglData cx(50,50,50),cy(50,50,50),cz(50,50,50); a.Modify("0.6*sin(2*pi*x)*sin(3*pi*y) + 0.4*cos(3*pi*(x*y))"); b.Modify("0.6*cos(2*pi*x)*cos(3*pi*y) + 0.4*cos(3*pi*(x*y))"); cx.Modify("0.01*(x-0.3)/pow((x-0.3)^2+(y-0.5)^2+(z-0.5)^2,1.5) - 0.01*(x-0.7)/pow((x-0.7)^2+(y-0.5)^2+(z-0.5)^2,1.5)"); cy.Modify("0.01*(y-0.5)/pow((x-0.3)^2+(y-0.5)^2+(z-0.5)^2,1.5) - 0.01*(y-0.5)/pow((x-0.7)^2+(y-0.5)^2+(z-0.5)^2,1.5)"); cz.Modify("0.01*(z-0.5)/pow((x-0.3)^2+(y-0.5)^2+(z-0.5)^2,1.5) - 0.01*(z-0.5)/pow((x-0.7)^2+(y-0.5)^2+(z-0.5)^2,1.5)"); gr->NewFrame(); gr->Box(); gr->Axis("xy"); gr->Puts(mglPoint(0,1.2,1),"Vector field (color ~ \\sqrt{a^2})","rC",8); gr->Vect(a,b,"","value 50"); gr->EndFrame(); gr->NewFrame(); gr->Box(); gr->Axis("xy"); gr->Puts(mglPoint(0,1.2,1),"Vector field (length ~ \\sqrt{a^2})","rC",8); gr->Vect(a,b); gr->EndFrame(); gr->NewFrame(); gr->Box(); gr->Axis("xy"); gr->Puts(mglPoint(0,1.2,1),"Flow chart (blue - source)","rC",8); gr->Flow(a,b); gr->EndFrame(); return gr->GetNumFrame(); }
void CameraCalibration::set4Params(float _fx, float _fy, float _cx, float _cy){ m_intrinsic = cv::Matx33f::zeros(); fx() = _fx; fy() = _fy; cx() = _cx; cy() = _cy; }
string MQ_2::report_value() { std::stringstream ss; for (int i = 0; i < _data.size() / 4; i++) { // ss << "+(" << w(i) << ")*sqrt(" << a(i) << "**2 + (" << cx(i) << "-x)**2 + (" << cy(i) << "-y)**2) "; ss << w(i) << " " << a(i) << " " << cx(i) << " " << cy(i) << std::endl; } ss << std::endl; return ss.str(); }
void sim::image::image_data(const sim::image_data & target) { release(); pImageData = ⌖ magni(1.0f); radian(0.0f); cx(width() / 2.0f); cy(height() / 2.0f); }
cv::Point3d PinholeCameraModel::projectPixelTo3dRay(const cv::Point2d& uv_rect) const { assert( initialized() ); cv::Point3d ray; ray.x = (uv_rect.x - cx() - Tx()) / fx(); ray.y = (uv_rect.y - cy() - Ty()) / fy(); ray.z = 1.0; return ray; }
int main(int argc, char **argv){ /* h é uma referencia para os dados de altura dos pontos no lago */ float **h, t, dt, P, ***amostra_h, *x, *y; /* i, j índice das matrizes */ int i, j, k, Niter, T; unsigned int s; /* Pegando os dados do arquivo */ if (argc != 2){ printf ("USO: ondas <nome do arquivo>\n"); exit(EXIT_FAILURE); } leia_entrada(argv[1], &larg, &alt, &L, &H, &T, &v, &Niter, &s, &eps, &P); /* Configurando a semente */ /* srand(s); */ /* Montando matriz de alturas inicialmente com tudo 0 */ h = calloc_matriz_float(H, L); /* Calculando coordenadas */ x = malloc(L * sizeof *x); for(i = 0; i < L; i++) x[i] = cx(i); y = malloc(H * sizeof *y); for(i = 0; i < H; i++) y[i] = cy(i); /* Variação do tempo por iteração */ dt = (float)T / Niter; /* Inicializando o vetor de amostras */ amostra_h = malloc(Niter * sizeof *amostra_h); for(i = 0; i < Niter; i++) amostra_h[i] = calloc_matriz_float(H, L); /* Faz as Niter iterações */ /* Atualizando tempo para cada iteração */ for(k = 0, t = 0; k < Niter; k++, t += dt){ #pragma omp parallel for private(j, i) schedule(auto) /* Para cada ponto no lago calcula a altura da água */ for(i = 0; i < H; i++) for(j = 0; j < L; j++) amostra_h[k][i][j] = h[i][j] = calcula_altura(x[j], y[i], t); /* Verificando se nessa iteração será gerada uma nova gota */ if((float)rand_r(&s) / RAND_MAX < P / 100) nova_gota((float)(rand() % larg), (float)(rand() % alt), t); } gera_imagem(h, H, L); gera_segundo_arquivo(Niter, H, L, amostra_h); return 0; }
int main(int argc, char *argv[]) { BigNumber::begin(128); BigNumber two(2.0), radius(16.0); BigNumber bbx1(-2.0), bbx2(2.0); BigNumber bby1(-2.0), bby2(2.0); BigNumber NXBN(NX); BigNumber NYBN(NY); BigNumber dx((bbx2 - bbx1) / NXBN); BigNumber dy((bby2 - bby1) / NYBN); printf("P6 %d %d %d\n", NX, NY, MAX_IT - 1); BigNumber cy(bby1); for(int y=0; y<NY; y++) { fprintf(stderr, "%d\n", NY - y); BigNumber cx(bbx1); for(int x=0; x<NX; x++) { int it = MAX_IT; BigNumber wx, wy, xsq, ysq; do { BigNumber z = xsq - ysq + cx; wy = wx * wy * two + cy; wx = z; xsq = wx * wx; ysq = wy * wy; it--; } while(it > 0 && xsq + ysq <= radius); char *wx_str = wx.toString(); char *wy_str = wy.toString(); printf("%c%c%c", it - atoi(wx_str), it, it - atoi(wy_str)); free(wy_str); free(wx_str); cx += dx; } cy += dy; } return 0; }
cameracalibration::cameracalibration(float _fx, float _fy, float _cx, float _cy) { m_intrinsic = cv::Matx33f::zeros(); fx() = _fx; fy() = _fy; cx() = _cx; cy() = _cy; m_distortion.create(5,1); for (int i=0; i<5; i++) m_distortion(i) = 0; }
const SVGStyledElement *SVGEllipseElement::pushAttributeContext(const SVGStyledElement *context) { // All attribute's contexts are equal (so just take the one from 'cx'). const SVGStyledElement *restore = cx()->baseVal()->context(); cx()->baseVal()->setContext(context); cy()->baseVal()->setContext(context); rx()->baseVal()->setContext(context); ry()->baseVal()->setContext(context); SVGStyledElement::pushAttributeContext(context); return restore; }
cv::Point2d PinholeCameraModel::project3dToPixel(const cv::Point3d& xyz) const { assert( initialized() ); assert(P_(2, 3) == 0.0); // Calibrated stereo cameras should be in the same plane // [U V W]^T = P * [X Y Z 1]^T // u = U/W // v = V/W cv::Point2d uv_rect; uv_rect.x = (fx()*xyz.x + Tx()) / xyz.z + cx(); uv_rect.y = (fy()*xyz.y + Ty()) / xyz.z + cy(); return uv_rect; }
static JSObjectRef Cache(JSContextRef context, Arg_ *arg) { JSObjectRef global(CYGetGlobalObject(context)); JSObjectRef cy(CYCastJSObject(context, CYGetProperty(context, global, cy_s))); char label[32]; sprintf(label, "%s%p", Internal_::Cache_, arg); CYJSString name(label); JSValueRef value(CYGetProperty(context, cy, name)); if (!JSValueIsUndefined(context, value)) return CYCastJSObject(context, value); JSObjectRef object(Make(context, arg)); CYSetProperty(context, cy, name, object); return object; }
cv::Point2d PinholeCameraModel::unrectifyPoint(const cv::Point2d& uv_rect) const { assert( initialized() ); if (cache_->distortion_state == NONE) return uv_rect; if (cache_->distortion_state == UNKNOWN) throw Exception("Cannot call unrectifyPoint when distortion is unknown."); assert(cache_->distortion_state == CALIBRATED); /// @todo Make this just call projectPixelTo3dRay followed by cv::projectPoints. But /// cv::projectPoints requires 32-bit float, which is annoying. // Formulae from docs for cv::initUndistortRectifyMap, // http://opencv.willowgarage.com/documentation/cpp/camera_calibration_and_3d_reconstruction.html // x <- (u - c'x) / f'x // y <- (v - c'y) / f'y // c'x, f'x, etc. (primed) come from "new camera matrix" P[0:3, 0:3]. double x = (uv_rect.x - cx() - Tx()) / fx(); double y = (uv_rect.y - cy() - Ty()) / fy(); // [X Y W]^T <- R^-1 * [x y 1]^T double X = R_(0,0)*x + R_(1,0)*y + R_(2,0); double Y = R_(0,1)*x + R_(1,1)*y + R_(2,1); double W = R_(0,2)*x + R_(1,2)*y + R_(2,2); // x' <- X/W, y' <- Y/W double xp = X / W; double yp = Y / W; // x'' <- x'(1+k1*r^2+k2*r^4+k3*r^6) + 2p1*x'*y' + p2(r^2+2x'^2) // y'' <- y'(1+k1*r^2+k2*r^4+k3*r^6) + p1(r^2+2y'^2) + 2p2*x'*y' // where r^2 = x'^2 + y'^2 double r2 = xp*xp + yp*yp; double r4 = r2*r2; double r6 = r4*r2; double a1 = 2*xp*yp; double k1 = D_(0,0), k2 = D_(0,1), p1 = D_(0,2), p2 = D_(0,3), k3 = D_(0,4); double barrel_correction = 1 + k1*r2 + k2*r4 + k3*r6; if (D_.cols == 8) barrel_correction /= (1.0 + D_(0,5)*r2 + D_(0,6)*r4 + D_(0,7)*r6); double xpp = xp*barrel_correction + p1*a1 + p2*(r2+2*(xp*xp)); double ypp = yp*barrel_correction + p1*(r2+2*(yp*yp)) + p2*a1; // map_x(u,v) <- x''fx + cx // map_y(u,v) <- y''fy + cy // cx, fx, etc. come from original camera matrix K. return cv::Point2d(xpp*K_(0,0) + K_(0,2), ypp*K_(1,1) + K_(1,2)); }
std::vector<ChebSegment> CFunctionToBspline::CFunctionToBsplineImpl::approxSegment(double umin, double umax, int depth) { // to estimate the error, we do a chebycheff approximation at higher // degree and evaluate the coefficients int K = _degree + 4; double alpha = 0.5; math_Vector cx = cheb_approx(_xfunc, K+1, umin, umax); math_Vector cy = cheb_approx(_yfunc, K+1, umin, umax); math_Vector cz = cheb_approx(_zfunc, K+1, umin, umax); // estimate error double errx=0., erry = 0., errz = 0.; for (int i = _degree+1; i < K+1; ++i) { errx += fabs(cx(i)); erry += fabs(cy(i)); errz += fabs(cz(i)); } double error = sqrt(errx*errx + erry*erry + errz*errz); if (error < _tol || depth >= _maxDepth) { // we can use this approximation, store to structure ChebSegment seg(_degree); seg.cx = subVec(cx, 0, _degree); seg.cy = subVec(cy, 0, _degree); seg.cz = subVec(cz, 0, _degree); seg.error = error; seg.umin = umin; seg.umax = umax; std::vector<ChebSegment> list; list.push_back(seg); return list; } else { // we have to split the range in two parts and do the approximation for each of them std::vector<ChebSegment> list1 = approxSegment(umin, umin + (umax-umin)*alpha, depth + 1); std::vector<ChebSegment> list2 = approxSegment(umin + (umax-umin)*alpha, umax, depth + 1); // combine lists list1.insert(list1.end(), list2.begin(), list2.end()); return list1; } }
virtual Real funcRHS_2D(const Real &x1, const Real &x2, const int k) { Real val(0), eps(std::sqrt(ROL::ROL_EPSILON<Real>())); //Real cx(2*cx_+eps), cy(2*cy_+eps), half(0.5); Real cx(0.1), cy(0.05), half(0.5); switch(loadCase_) { case 0: { // Force applied to center of top boundary if ( x1 > half*(xmax_-cx) && x1 < half*(xmax_+cx) && x2 > ymax_-cy ) { val = loadMag_*((k==0) ? std::sin(loadAngle1_) : std::cos(loadAngle1_)); } break; } case 1: { // Force applied to top right corner if ( (x1 > xmax_-cx) && (x2 > ymax_-cy) ) { val = loadMag_*((k==0) ? std::sin(loadAngle1_) : std::cos(loadAngle1_)); } break; } case 2: { // Force applied to center of right boundary if ( (x1 > xmax_-cx) && (x2 > half*(ymax_-cy) && x2 < half*(ymax_+cy)) ) { val = loadMag_*((k==0) ? std::sin(loadAngle1_) : std::cos(loadAngle1_)); } break; } case 3: { // Force applied to lower right corner if ( (x1 > xmax_-cx) && (x2 < cy) ) { val = loadMag_*((k==0) ? std::sin(loadAngle1_) : std::cos(loadAngle1_)); } break; } case 4: { // Force applied to center of bottom boundary if ( (x1 > half*(xmax_-cx) && x1 < half*(xmax_+cx)) && (x2 < cy) ) { val = loadMag_*((k==0) ? std::sin(loadAngle1_) : std::cos(loadAngle1_)); } break; } } return val; }
void SVGEllipseElement::parseMappedAttribute(MappedAttribute *attr) { const AtomicString& value = attr->value(); if (attr->name() == SVGNames::cxAttr) cx()->baseVal()->setValueAsString(value.impl()); if (attr->name() == SVGNames::cyAttr) cy()->baseVal()->setValueAsString(value.impl()); if (attr->name() == SVGNames::rxAttr) rx()->baseVal()->setValueAsString(value.impl()); if (attr->name() == SVGNames::ryAttr) ry()->baseVal()->setValueAsString(value.impl()); else { if(SVGTests::parseMappedAttribute(attr)) return; if(SVGLangSpace::parseMappedAttribute(attr)) return; if(SVGExternalResourcesRequired::parseMappedAttribute(attr)) return; SVGStyledTransformableElement::parseMappedAttribute(attr); } }
int main(int argc, char** argv) { help(); box = cv::Rect(-1, -1, 0, 0); cv::Mat image(200, 200, CV_8UC3), temp; image.copyTo(temp); box = cv::Rect(-1, -1, 0, 0); image = cv::Scalar::all(0); cv::namedWindow("Box Example"); // Check Point cv::Point3i p0(1, 2, 3); cv::Point3i p1(4, 5, 6); float x = p0.dot(p1); cv::Point3i cy(p0.cross(p1)); // Here is the crucial moment where we actually install // the callback. Note that we set the value of ‘params’ to // be the image we are working with so that the callback // will have the image to edit. // cv::setMouseCallback( "Box Example", my_mouse_callback, (void*)&image ); // The main program loop. Here we copy the working image // to the temp image, and if the user is drawing, then // put the currently contemplated box onto that temp image. // Display the temp image, and wait 15ms for a keystroke, // then repeat. // for (;;) { image.copyTo(temp); if (drawing_box) draw_box(temp, box); cv::imshow("Box Example", temp); if (cv::waitKey(15) == 27) break; } return 0; }
void MainWindow::newPoints(int n) { scene.periodic_triangulation.clear(); scene.points.clear(); CGAL::Random rnd(std::time(NULL)); CGAL::Random_points_in_cube_3<Point_3, Creator> in_cube(1,rnd); for (int i=0 ; i<n ; i++) if (scene.two_dimensional) { Point_3 rdpt = *in_cube++; scene.points.push_back(Point_3(rdpt.x(),rdpt.y(),0.)); } else scene.points.push_back(*in_cube++); Iso_cuboid_3 dom(-1,-1,-1,1,1,1); scene.periodic_triangulation.set_domain(dom); scene.periodic_triangulation.insert(scene.points.begin(), scene.points.end()); FT cx(0),cy(0),cz(0); for (int i=0 ; i<8 ; i++) { cx += dom[i].x(); cy += dom[i].y(); cy += dom[i].y(); } qglviewer::Vec center(cx/8.,cy/8.,cz/8.); viewer->setSceneCenter(center); viewer->setSceneRadius(std::sqrt( ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())) + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())) + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())))); speedSlider->setRange(0,100); speedSlider->setSliderPosition(100); emit (sceneChanged()); }
void MainWindow::loadPoints() { QString fileName = QFileDialog ::getOpenFileName(this, tr("Open point set"), ".", tr("All files (*)")); if(fileName.isEmpty()) return; std::ifstream ifs(fileName.toLatin1().data() ); scene.points.clear(); Iso_cuboid_3 dom; ifs >> dom; std::copy(std::istream_iterator<Point_3>(ifs), std::istream_iterator<Point_3>(), std::back_inserter(scene.points)); scene.periodic_triangulation.set_domain(dom); scene.periodic_triangulation.insert(scene.points.begin(), scene.points.end()); FT cx(0),cy(0),cz(0); for (int i=0 ; i<8 ; i++) { cx += dom[i].x(); cy += dom[i].y(); cy += dom[i].y(); } qglviewer::Vec center(cx/8.,cy/8.,cz/8.); viewer->setSceneCenter(center); viewer->setSceneRadius(std::sqrt( ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())) + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())) + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())))); speedSlider->setRange(0,100); speedSlider->setSliderPosition(100); emit (sceneChanged()); }
void draw_tile(vec2 c, float s, float rot, colour col, int tile_num, int flags) { vec2 cx(cosf(rot) * s * 0.5f, sinf(rot) * s * 0.5f); vec2 cy(perp(cx)); draw_tile(c - cx - cy, c + cx - cy, c - cx + cy, c + cx + cy, col, col, col, col, tile_num, flags); }
//--------------------------------------------------------- void NDG2D::OutputNodes_cub() //--------------------------------------------------------- { static int count = 0; string output_dir = "."; string buf = umOFORM("%s/cub_N%02d_%04d.vtk", output_dir.c_str(), m_cub.Ncub, ++count); FILE *fp = fopen(buf.c_str(), "w"); if (!fp) { umLOG(1, "Could no open %s for output!\n", buf.c_str()); return; } // Set flags and totals int Npoints = m_cub.Ncub; // cubature nodes per element // set totals for Vtk output #if (1) // FIXME: no connectivity int vtkTotalPoints = this->K * Npoints; int vtkTotalCells = vtkTotalPoints; int vtkTotalConns = vtkTotalPoints; int Ncells = Npoints; #else int vtkTotalPoints = this->K * Npoints; int vtkTotalCells = this->K * Ncells; int vtkTotalConns = (this->EToV.num_cols()+1) * this->K * Ncells; int Ncells = this->N * this->N; #endif //------------------------------------- // 1. Write the VTK header details //------------------------------------- fprintf(fp, "# vtk DataFile Version 2"); fprintf(fp, "\nNDGFem simulation nodes (high-order cubature)"); fprintf(fp, "\nASCII"); fprintf(fp, "\nDATASET UNSTRUCTURED_GRID\n"); fprintf(fp, "\nPOINTS %d double", vtkTotalPoints); int newNpts=0; //------------------------------------- // 2. Write the vertex data //------------------------------------- const DMat& cx=m_cub.x; const DMat& cy=m_cub.y; for (int k=1; k<=this->K; ++k) { for (int n=1; n<=Npoints; ++n) { fprintf(fp, "\n%20.12e %20.12e %6.1lf", cx(n,k), cy(n,k), 0.0); } } //------------------------------------- // 3. Write the element connectivity //------------------------------------- // Number of indices required to define connectivity fprintf(fp, "\n\nCELLS %d %d", vtkTotalCells, 2*vtkTotalConns); // TODO: write element connectivity to file // FIXME: out-putting as VTK_VERTEX int nodesk=0; for (int k=0; k<this->K; ++k) { // for each element for (int n=1; n<=Npoints; ++n) { fprintf(fp, "\n%d", 1); // for each triangle for (int i=1; i<=1; ++i) { // FIXME: no connectivity fprintf(fp, " %5d", nodesk); // nodes in nth triangle nodesk++; // indexed from 0 } } } //------------------------------------- // 4. Write the cell types //------------------------------------- // For each element (cell) write a single integer // identifying the cell type. The integer should // correspond to the enumeration in the vtk file: // /VTK/Filtering/vtkCellType.h fprintf(fp, "\n\nCELL_TYPES %d", vtkTotalCells); for (int k=0; k<this->K; ++k) { fprintf(fp, "\n"); for (int i=1; i<=Ncells; ++i) { //fprintf(fp, "5 "); // 5:VTK_TRIANGLE fprintf(fp, "1 "); // 1:VTK_VERTEX if (! (i%10)) fprintf(fp, "\n"); } } // add final newline to output fprintf(fp, "\n"); fclose(fp); }
bool SVGCircleElement::selfHasRelativeLengths() const { return cx().isRelative() || cy().isRelative() || r().isRelative(); }
Path SVGEllipseElement::toPathData() const { return Path::createEllipse(FloatPoint(cx().value(), cy().value()), rx().value(), ry().value()); }
bool SVGEllipseElement::hasRelativeValues() const { return (cx().isRelative() || cy().isRelative() || rx().isRelative() || ry().isRelative()); }
Path SVGCircleElement::toPathData() const { return Path::createCircle(FloatPoint(cx().value(this), cy().value(this)), r().value(this)); }
bool SVGCircleElement::hasRelativeValues() const { return (cx().isRelative() || cy().isRelative() || r().isRelative()); }
void draw_tile(vec2 c, float s, colour col, int tile_num, int flags) { vec2 cx(s, 0.0f); vec2 cy(0.0f, s); draw_tile(c - cx - cy, c + cx - cy, c - cx + cy, c + cx + cy, col, col, col, col, tile_num, flags); }
int main(){ std::vector <int> mat(0); std::vector <int> cat(0); std::vector <double> cx(0); std::vector <double> cy(0); std::vector <double> cz(0); std::vector <std::string> type(0); std::vector <std::string> filenames(0); // open coordinate file std::ifstream coord_file; coord_file.open("atoms-coords.cfg"); // read in file header std::string dummy; getline(coord_file,dummy); //std::cout << dummy << std::endl; getline(coord_file,dummy); //std::cout << dummy << std::endl; getline(coord_file,dummy); //std::cout << dummy << std::endl; getline(coord_file,dummy); //std::cout << dummy << std::endl; getline(coord_file,dummy); //std::cout << dummy << std::endl; // get number of atoms unsigned int n_atoms; getline(coord_file,dummy); //std::cout << dummy << std::endl; dummy.erase (dummy.begin(), dummy.begin()+17); n_atoms=atoi(dummy.c_str()); getline(coord_file,dummy); //std::cout << dummy << std::endl; // get number of subsidiary files unsigned int n_files; getline(coord_file,dummy); //std::cout << dummy << std::endl; dummy.erase (dummy.begin(), dummy.begin()+22); n_files=atoi(dummy.c_str()); for(int file=0; file<n_files; file++){ getline(coord_file,dummy); filenames.push_back(dummy); //std::cout << filenames[file] << std::endl; } getline(coord_file,dummy); //std::cout << dummy << std::endl; unsigned int n_local_atoms; getline(coord_file,dummy); //std::cout << dummy << std::endl; n_local_atoms=atoi(dummy.c_str()); // resize arrays mat.resize(n_atoms); cat.resize(n_atoms); cx.resize(n_atoms); cy.resize(n_atoms); cz.resize(n_atoms); type.resize(n_atoms); unsigned int counter=0; // finish reading master file coordinates for(int i=0;i<n_local_atoms;i++){ coord_file >> mat[counter] >> cat[counter] >> cx[counter] >> cy[counter] >> cz[counter] >> type[counter]; counter++; } // close master file coord_file.close(); // now read subsidiary files for(int file=0; file<n_files; file++){ std::ifstream infile; infile.open(filenames[file].c_str()); // read number of atoms in this file getline(infile,dummy); n_local_atoms=atoi(dummy.c_str()); for(int i=0;i<n_local_atoms;i++){ infile >> mat[counter] >> cat[counter] >> cx[counter] >> cy[counter] >> cz[counter] >> type[counter]; counter++; } // close subsidiary file infile.close(); } // check for correct read in of coordinates if(counter!=n_atoms) std::cerr << "Error in reading in coordinates" << std::endl; // Loop over all possible spin config files int ios = 0; int spinfile_counter=0; while(ios==0){ std::stringstream file_sstr; file_sstr << "atoms-"; file_sstr << std::setfill('0') << std::setw(8) << spinfile_counter; file_sstr << ".cfg"; std::string cfg_file = file_sstr.str(); //const char* cfg_filec = cfg_file.c_str(); std::ifstream spinfile; spinfile.open(cfg_file.c_str()); if(spinfile.is_open()){ std::cout << "Processing file: " << cfg_file << std::endl; // Read in file header getline(spinfile,dummy); //std::cout << dummy << std::endl; getline(spinfile,dummy); //std::cout << dummy << std::endl; getline(spinfile,dummy); //std::cout << dummy << std::endl; getline(spinfile,dummy); //std::cout << dummy << std::endl; getline(spinfile,dummy); //std::cout << dummy << std::endl; // get number of atoms unsigned int n_spins; getline(spinfile,dummy); //std::cout << dummy << std::endl; dummy.erase (dummy.begin(), dummy.begin()+17); n_spins=atoi(dummy.c_str()); if(n_spins!=n_atoms) std::cerr << "Error! - mismatch between number of atoms in coordinate and spin files" << std::endl; getline(spinfile,dummy); // sys dimensions //std::cout << dummy << std::endl; char const field_delim = '\t'; dummy.erase (dummy.begin(), dummy.begin()+18); std::istringstream ss(dummy); std::vector<double> val(0); for (std::string num; getline(ss, num, field_delim); ) { val.push_back(atof(num.c_str())); //std::cout << num << "\t" << val << std::endl; } double dim[3] = {val[0],val[1],val[2]}; //std::cout << dim[0] << "\t" << dim[1] << "\t" << dim[2] << std::endl; getline(spinfile,dummy); // coord file getline(spinfile,dummy); // time //std::cout << dummy << std::endl; dummy.erase (dummy.begin(), dummy.begin()+5); double time = atof(dummy.c_str()); getline(spinfile,dummy); // field //std::cout << dummy << std::endl; dummy.erase (dummy.begin(), dummy.begin()+6); double field = atof(dummy.c_str()); getline(spinfile,dummy); // temp //std::cout << dummy << std::endl; dummy.erase (dummy.begin(), dummy.begin()+12); double temperature = atof(dummy.c_str()); // magnetisation getline(spinfile,dummy); dummy.erase (dummy.begin(), dummy.begin()+14); std::istringstream ss2(dummy); val.resize(0); for (std::string num; getline(ss2, num, field_delim); ) { val.push_back(atof(num.c_str())); //std::cout << num << "\t" << val << std::endl; } double mx = val[0]; double my = val[1]; double mz = val[2]; // get number of materials unsigned int n_mat; getline(spinfile,dummy); //std::cout << dummy << std::endl; dummy.erase (dummy.begin(), dummy.begin()+20); n_mat=atoi(dummy.c_str()); std::vector <material_t> material(n_mat); for(int imat=0;imat<n_mat;imat++){ getline(spinfile,dummy); //dummy.erase (dummy.begin(), dummy.begin()+22); std::istringstream ss(dummy); std::vector<double> val(0); for (std::string num; getline(ss, num, field_delim); ) { val.push_back(atof(num.c_str())); } material[imat].mu_s = val[0]; material[imat].mx = val[1]; material[imat].my = val[2]; material[imat].mz = val[3]; material[imat].magm = val[4]; //std::cout << material[imat].mu_s << "\t" << material[imat].mx << "\t" << material[imat].my << "\t" << material[imat].mz << "\t" << material[imat].magm << std::endl; } // line getline(spinfile,dummy); //std::cout << dummy << std::endl; // get number of subsidiary files unsigned int n_files; getline(spinfile,dummy); //std::cout << dummy << std::endl; dummy.erase (dummy.begin(), dummy.begin()+22); n_files=atoi(dummy.c_str()); filenames.resize(0); for(int file=0; file<n_files; file++){ getline(spinfile,dummy); filenames.push_back(dummy); //std::cout << filenames[file] << std::endl; } getline(spinfile,dummy); //std::cout << dummy << std::endl; unsigned int n_local_atoms; getline(spinfile,dummy); //std::cout << dummy << std::endl; n_local_atoms=atoi(dummy.c_str()); // Open Povray Include File std::stringstream incpov_file_sstr; incpov_file_sstr << "atoms-"; incpov_file_sstr << std::setfill('0') << std::setw(8) << spinfile_counter; incpov_file_sstr << ".inc"; std::string incpov_file = incpov_file_sstr.str(); // Open Povray Output file std::stringstream pov_file_sstr; pov_file_sstr << "atoms-"; pov_file_sstr << std::setfill('0') << std::setw(8) << spinfile_counter; pov_file_sstr << ".pov"; std::string pov_file = pov_file_sstr.str(); std::ofstream pfile; pfile.open(pov_file.c_str()); // Ouput povray file header double size, mag_vec; double vec[3]; size = sqrt(dim[0]*dim[0] + dim[1]*dim[1] + dim[2]*dim[2]); vec[0] = (1.0/dim[0]); vec[1] = (1.0/dim[1]); vec[2] = (1.0/dim[2]); mag_vec = sqrt(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]); vec[0]/=mag_vec; vec[1]/=mag_vec; vec[2]/=mag_vec; pfile << "#include \"colors.inc\"" << std::endl; pfile << "#include \"metals.inc\"" << std::endl; pfile << "#include \"screen.inc\"" << std::endl; pfile << "#declare LX=" << dim[0]*0.5 << ";" << std::endl; pfile << "#declare LY=" << dim[1]*0.5 << ";" << std::endl; pfile << "#declare LZ=" << dim[2]*0.5 << ";" << std::endl; pfile << "#declare CX=" << size*vec[0]*6.0 << ";" << std::endl; pfile << "#declare CY=" << size*vec[1]*6.0 << ";" << std::endl; pfile << "#declare CZ=" << size*vec[2]*6.0 << ";" << std::endl; pfile << "#declare ref=0.4;" << std::endl; pfile << "global_settings { assumed_gamma 2.0 }" << std::endl; pfile << "background { color Gray30 }" << std::endl; pfile << "Set_Camera(<CX,CY,CZ>, <LX,LY,LZ>, 15)" << std::endl; pfile << "Set_Camera_Aspect(4,3)" << std::endl; pfile << "Set_Camera_Sky(<0,0,1>)" << std::endl; pfile << "light_source { <2*CX, 2*CY, 2*CZ> color White}" << std::endl; for(int imat=0;imat<n_mat;imat++){ pfile << "#declare sscale"<< imat << "=2.0;" << std::endl; pfile << "#declare rscale"<< imat << "=1.2;" << std::endl; pfile << "#declare cscale"<< imat << "=3.54;" << std::endl; pfile << "#declare cones"<< imat << "=0;" << std::endl; pfile << "#declare arrows"<< imat << "=1;" << std::endl; pfile << "#declare spheres"<< imat << "=1;" << std::endl; pfile << "#declare cubes" << imat << "=0;" << std::endl; pfile << "#declare spincolors"<< imat << "=1;" << std::endl; pfile << "#declare spincolor"<< imat << "=pigment {color rgb < 0.1 0.1 0.1 >};" << std::endl; pfile << "#macro spinm"<< imat << "(cx,cy,cz,sx,sy,sz, cr,cg,cb)" << std::endl; pfile << "union{" << std::endl; pfile << "#if(spheres" << imat << ") sphere {<cx,cy,cz>,0.5*rscale"<< imat << "} #end" << std::endl; pfile << "#if(cubes" << imat << ") box {<cx-cscale"<< imat << "*0.5,cy-cscale" << imat << "*0.5,cz-cscale"<< imat << "*0.5>,<cx+cscale"<< imat << "*0.5,cy+cscale" << imat << "*0.5,cz+cscale"<< imat << "*0.5>} #end" << std::endl; pfile << "#if(cones"<< imat << ") cone {<cx+0.5*sx*sscale0,cy+0.5*sy*sscale"<< imat << ",cz+0.5*sz*sscale"<< imat << ">,0.0 <cx-0.5*sx*sscale"<< imat << ",cy-0.5*sy*sscale"<< imat << ",cz-0.5*sz*sscale"<< imat << ">,sscale0*0.5} #end" << std::endl; pfile << "#if(arrows" << imat << ") cylinder {<cx+sx*0.5*sscale"<< imat <<",cy+sy*0.5*sscale"<< imat <<",cz+sz*0.5*sscale"<< imat << ">,<cx-sx*0.5*sscale"<< imat <<",cy-sy*0.5*sscale"<< imat <<",cz-sz*0.5*sscale"<< imat <<">,sscale"<< imat <<"*0.12}"; pfile << "cone {<cx+sx*0.5*1.6*sscale"<< imat <<",cy+sy*0.5*1.6*sscale"<< imat <<",cz+sz*0.5*1.6*sscale"<< imat <<">,sscale"<< imat <<"*0.0 <cx+sx*0.5*sscale"<< imat << ",cy+sy*0.5*sscale"<< imat <<",cz+sz*0.5*sscale"<< imat <<">,sscale"<< imat <<"*0.2} #end" << std::endl; pfile << "#if(spincolors"<< imat << ") texture { pigment {color rgb <cr cg cb>}finish {reflection {ref} diffuse 1 ambient 0}}" << std::endl; pfile << "#else texture { spincolor"<< imat << " finish {reflection {ref} diffuse 1 ambient 0}} #end" << std::endl; pfile << "}" << std::endl; pfile << "#end" << std::endl; } pfile << "#include \"" << incpov_file_sstr.str() << "\"" << std::endl; pfile.close(); std::ofstream incpfile; incpfile.open(incpov_file.c_str()); double sx,sy,sz,red,green,blue,ireal; unsigned int si=0; // Read in spin coordinates and output to povray file for(int i=0; i<n_local_atoms;i++){ spinfile >> sx >> sy >> sz; rgb(sz,red,green,blue); incpfile << "spinm"<< mat[si] << "(" << cx[si] << "," << cy[si] << "," << cz[si] << "," << sx << "," << sy << "," << sz << "," << red << "," << green << "," << blue << ")" << std::endl; si++; } // close master file spinfile.close(); // now read subsidiary files for(int file=0; file<n_files; file++){ std::ifstream infile; infile.open(filenames[file].c_str()); // read number of atoms in this file getline(infile,dummy); n_local_atoms=atoi(dummy.c_str()); for(int i=0;i<n_local_atoms;i++){ infile >> sx >> sy >> sz; rgb(sz,red,green,blue); incpfile << "spinm"<< mat[si] << "(" << cx[si] << "," << cy[si] << "," << cz[si] << "," << sx << "," << sy << "," << sz << "," << red << "," << green << "," << blue << ")" << std::endl; si++; } // close subsidiary file infile.close(); } // close povray inc file incpfile.close(); spinfile_counter++; } else ios=1;
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(r*cos(c*du), h, r*sin(c*du), 0, 0, 0, 0, 3, 0); //head position;eye direction(0.0,0.0,0.0),original point;(0.0,1.0,0.0),head above direction¡£ //cylinder a(1, 15, 0, 90, 0, 0, 5, 0); //r,h,xangle yangle zangle, module position(xx yy zz) //sphere b(3, 100, 100, 0, 0, 0, 0, 2.5, 0); //r,xangle yangle zangle, module position(xx yy zz) //cube c(5, 10, 0, 0, 1, 1, 1); //length xangle yangle zangle, module position(xx yy zz) //rectangularpyramid d(4, 0, 0, 0, 0, 2, 0); //length xangle yangle zangle, module position(xx yy zz) //triangularpyramid f(2, 0, 0, 0, 8, 8, 8);//length xangle yangle zangle, module position(xx yy zz) //f.draw(); sphere sp(3, 100, 100, 0, 0, -2, 0, 8, 0); cylinder cy(3, 5, 0, 90, 0, -3, 9, -10); cube cu(3, 0, 0, 0, 0, 8, 10); triangularpyramid tr(2, 0, 0, 0, 0, -6, 8); rectangularpyramid rec(2, 0, 0, 0, 0, -6, -8); cylinder k1(0.3, 2, 90, 0, 0, 0, 0, 0); cylinder k2(0.3, 2, -90, 0, 0, 0, 0, 0); cylinder k3(0.3, 2, -45, 0, 0, 0, 0, 0); cylinder k4(0.3, 2.5, 45, 0, 0, 0, 0, 0); cylinder u1(0.3, 2, 90, 0, 0, 0, 0, 3); cylinder u2(0.3, 1.5, -90, 0, 0, 0, 0, 3); cylinder u3(0.3, 2, 0, 0, 0, 0, -1.8, 3); cylinder u4(0.3, 2, 90, 0, 0, 0, 0, 5); cylinder u5(0.3, 1.5, -90, 0, 0, 0, 0, 5); cylinder g1(0.3, 2, -90, 0, 0, 0, -0.5, 6.4); cylinder g2(0.3, 1.5, -90, 0, 0, 0, -0.5, 6.4); cylinder g3(0.3, 2, 0, 0, 0, 0, -0.3, 6.4); cylinder g4(0.3, 2, 0, 0, 0, 0, 1.3, 6.4); cylinder g5(0.3, 2, 90, 0, 0, 0, 0, 8.4); cylinder g6(0.3, 1.5, -90, 0, 0, 0, 0, 8.4); cylinder g7(0.3, 2, 0, 0, 0, 0, -1.8, 6.4); cylinder e1(0.3, 1.8, -90, 0, 0, 0, -0.2, 10); cylinder e2(0.3, 1.8, 90, 0, 0, 0, -0.2, 10); cylinder e3(0.3, 2, 0, 0, 0, 0, -0.3, 10); cylinder e4(0.3, 2, 0, 0, 0, 0, 1.3, 10); cylinder e5(0.3, 2, 0, 0, 0, 0, -1.8, 10); cylinder r1(0.3, 1.8, -90, 0, 0, 0, -0.2, 13.5); cylinder r2(0.3, 1.8, 90, 0, 0, 0, -0.2, 13.5); cylinder r3(0.3, 2, 0, 0, 0, 0, -0.3, 13.5); cylinder r4(0.3, 1.2, 0, 0, 0, 0, 1.3, 13.5); cylinder r5(0.3, 1.7, 60, 0, 0, 0, 1.3, 14.5); cylinder r6(0.3, 2.5, 45, 0, 0, 0, 0, 13.5); cylinder c1(0.3, 2, 90, 0, 0, 0, 0, -15); cylinder c2(0.3, 2, -90, 0, 0, 0, 0, -15); cylinder c3(0.3, 3, 0, 0, 0, 0, -1.8, -15); cylinder c4(0.3, 3, 0, 0, 0, 0, 1.8, -15); cylinder plus1(0.3,3.5, 0, 0, 0, 0, 0, -11); cylinder plus2(0.3, 4, 90, 0, 0, 0, 2, -9.2); cylinder plus3(0.3, 3.5, 0, 0, 0, 0, 0, -6); cylinder plus4(0.3, 4, 90, 0, 0, 0, 2, -4.2); cy.draw(); sp.draw(); cu.draw(); tr.draw(); rec.draw(); k1.draw(); k2.draw(); k3.draw(); k4.draw(); u1.draw(); u2.draw(); u3.draw(); u4.draw(); u5.draw(); g1.draw(); g2.draw(); g3.draw(); g4.draw(); g5.draw(); g6.draw(); g7.draw(); e1.draw(); e2.draw(); e3.draw(); e4.draw(); e5.draw(); r1.draw(); r2.draw(); r3.draw(); r4.draw(); r5.draw(); r6.draw(); c1.draw(); c2.draw(); c3.draw(); c4.draw(); plus1.draw(); plus2.draw(); plus3.draw(); plus4.draw(); glFlush(); }