std::basic_string<TCHAR> CStringBuilderEx::ToString() const { std::vector<TCHAR> vCopy(m_vBuf); vCopy.push_back(0); return std::basic_string<TCHAR>(&vCopy[0]); }
/* * Duplicate <v_in> and return the result. */ Vector *vDup(Vector *v_in) { Vector *v_out = vNew(v_in->n_rows); vCopy(v_out, v_in); return v_out; }
void text_t::MakeMap(void) { #define vCopy(d,x,y) {d[0] = x; d[1] = y;} GLint i = 0; GLfloat x, y; tIncX = (GLfloat)pow (blockCol, -1); tIncY = (GLfloat)pow (blockRow, -1); for (y = 1 - tIncY; y >= 0; y -= tIncY) for (x = 0; x <= 1 - tIncX; x += tIncX, i ++) vCopy(tPoints[i], x, y); #undef vCopy }
/* * Calculate the cross-product of vectors <v1> and <v2> and put the result into * <v_out>. All three vectors must have 3 rows. */ void vCrossP(Vector *v_out, Vector *v1, Vector *v2) { Vector *v_tmp; assert(v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows && v2->n_rows == 3); v_tmp = vNew(v_out->n_rows); v_tmp->row[0] = v1->row[1] * v2->row[2] + v1->row[2] * v2->row[1]; v_tmp->row[1] = v1->row[2] * v2->row[0] + v1->row[0] * v2->row[2]; v_tmp->row[2] = v1->row[0] * v2->row[1] + v1->row[1] * v2->row[0]; vCopy(v_out, v_tmp); vDel(v_tmp); }
void VisionSet8(image_t *pSrc, image_t *pDst) { benchmark_t bench; // 1. Start a benchmark, execute vision operation and send info to PC benchmark_start(&bench, "Copy"); vCopy(pSrc, pDst); benchmark_stop(&bench); pc_send_benchmark(&bench); pDst->lut = LUT_STRETCH; pc_send_image(pDst); pc_send_string("1. Copy"); // 2. Start a benchmark, execute vision operation and send info to PC benchmark_start(&bench, "Erase"); vErase(pDst); benchmark_stop(&bench); pc_send_benchmark(&bench); pDst->lut = LUT_BINARY; pc_send_image(pDst); pc_send_string("2. Erase"); }
void loadOBJFile(char* path, int four_d_verts, OBJContents* contents) { char* f, *raw; int line = 0; int cur_pos = 0; int cur_norm = 0; int cur_tex = 0; int cur_param = 0; int current_vertex_index = 0; raw = readFile(path, NULL); if(!raw) return; memset(contents, 0, sizeof(OBJContents)); int numVertices = 0; int numNormals = 0; int numTexCoords = 0; int numFaces = 0; f = raw; while(*f) { char c; c = *f; f++; if(c == 'f') { // faces numFaces++; } else if(c == 'v') { c = *f; if(c == ' ') numVertices++; else if(c == 'n') numNormals++; else if(c == 't') numTexCoords++; } while(*f++ != '\n'); } printf("Vertices: %d\n", numVertices); printf("Normals: %d\n", numNormals); printf("TexCoords: %d\n", numTexCoords); printf("Faces: %d\n", numFaces); Vector* vertices; Vector* normals; Vector2* texCoords; OBJVertex* faces; int vc = 0; int nc = 0; int tc = 0; int fc = 0; vertices = malloc(numVertices * sizeof(Vector)); normals = malloc(numNormals * sizeof(Vector)); texCoords = malloc(numTexCoords * sizeof(Vector2)); // only triangles are supported atm faces = malloc(numFaces * 3 * sizeof(OBJVertex)); f = raw; while(*f) { char c; int chars_read, n, j; int fd[3][3]; //printf("looping \n"); c = *f; f++; if(c == 'f') { // faces. currently only triangles and quite hacky // f v[/t[/n]] v[/t[/n]] v[/t[/n]] [v[/t[/n]]] n = sscanf(f, " %d/%d/%d %d/%d/%d %d/%d/%d%n", &fd[0][0], &fd[0][1], &fd[0][2], &fd[1][0], &fd[1][1], &fd[1][2], &fd[2][0], &fd[2][1], &fd[2][2], &chars_read); vCopy( &vertices[fd[0][0]-1], &faces[fc].v); vCopy2(&texCoords[fd[0][1]-1], &faces[fc].t); vCopy( &normals[fd[0][2]-1], &faces[fc].n); fc++; vCopy( &vertices[fd[1][0]-1], &faces[fc].v); vCopy2(&texCoords[fd[1][1]-1], &faces[fc].t); vCopy( &normals[fd[1][2]-1], &faces[fc].n); fc++; vCopy( &vertices[fd[2][0]-1], &faces[fc].v); vCopy2(&texCoords[fd[2][1]-1], &faces[fc].t); vCopy( &normals[fd[2][2]-1], &faces[fc].n); fc++; f += chars_read; } else if(c == 'v') { c = *f; f++; if(c == ' ') { chars_read = 0; n = sscanf(f, " %f %f %f%n", &vertices[vc].x, &vertices[vc].y, &vertices[vc].z, &chars_read); if(n < 3) { fprintf(stderr, "error reading vertex\n"); } //printf("got vertex: %f %f %f\n",vertices[vc].x,vertices[vc].y,vertices[vc].z); f += chars_read; vc++; } else if(c == 'n') { chars_read = 0; n = sscanf(f, " %f %f %f%n", &normals[nc].x, &normals[nc].y, &normals[nc].z, &chars_read); if(n < 3) { fprintf(stderr, "error reading normal\n"); } f += chars_read; nc++; } else if(c == 't') { chars_read = 0; n = sscanf(f, " %f %f%n", &texCoords[tc].x, &texCoords[tc].y, &chars_read); if(n < 2) { fprintf(stderr, "error reading tex coord\n"); } //printf("got tex coords: %f %f\n", texCoords[tc].x, texCoords[tc].y); f += chars_read; tc++; } } while(*f++ != '\n'); } contents->faces = faces; contents->faceCnt = numFaces; }
void InitBeam(void) // initialize beam; produce description string { double w0; // beam width /* TO ADD NEW BEAM * Add here all intermediate variables, which are used only inside this function. */ // initialization of global option index for error messages opt=opt_beam; // beam initialization switch (beamtype) { case B_PLANE: if (IFROOT) strcpy(beam_descr,"plane wave"); beam_asym=false; if (surface) { if (prop_0[2]==0) PrintError("Ambiguous setting of beam propagating along the surface. Please specify " "the incident direction to have (arbitrary) small positive or negative z-component"); if (msubInf && prop_0[2]>0) PrintError("Perfectly reflecting surface ('-surf ... inf') is incompatible " "with incident direction from below (including the default one)"); // Here we set ki,kt,ktVec and propagation directions prIncRefl,prIncTran if (prop_0[2]>0) { // beam comes from the substrate (below) // here msub should always be defined inc_scale=1/creal(msub); ki=msub*prop_0[2]; /* Special case for msub near 1 to remove discontinuities for near-grazing incidence. The details * are discussed in CalcFieldSurf() in crosssec.c. */ if (cabs(msub-1)<ROUND_ERR && fabs(ki)<SQRT_RND_ERR) kt=ki; else kt=cSqrtCut(1 - msub*msub*(prop_0[0]*prop_0[0]+prop_0[1]*prop_0[1])); // determine propagation direction and full wavevector of wave transmitted into substrate ktVec[0]=msub*prop_0[0]; ktVec[1]=msub*prop_0[1]; ktVec[2]=kt; } else if (prop_0[2]<0) { // beam comes from above the substrate inc_scale=1; vRefl(prop_0,prIncRefl); ki=-prop_0[2]; if (!msubInf) { // same special case as above if (cabs(msub-1)<ROUND_ERR && fabs(ki)<SQRT_RND_ERR) kt=ki; else kt=cSqrtCut(msub*msub - (prop_0[0]*prop_0[0]+prop_0[1]*prop_0[1])); // determine propagation direction of wave transmitted into substrate ktVec[0]=prop_0[0]; ktVec[1]=prop_0[1]; ktVec[2]=-kt; } } else LogError(ONE_POS,"Ambiguous setting of beam propagating along the surface. Please specify the" "incident direction to have (arbitrary) small positive or negative z-component"); vRefl(prop_0,prIncRefl); if (!msubInf) { vReal(ktVec,prIncTran); vNormalize(prIncTran); } } return; case B_DIPOLE: vCopy(beam_pars,beam_center_0); if (surface) { if (beam_center_0[2]<=-hsub) PrintErrorHelp("External dipole should be placed strictly above the surface"); inc_scale=1; // but scaling of Mueller matrix is weird anyway } // in weird scenarios the dipole can be positioned exactly at the origin; reused code from Gaussian beams beam_asym=(beam_center_0[0]!=0 || beam_center_0[1]!=0 || beam_center_0[2]!=0); if (!beam_asym) vInit(beam_center); /* definition of p0 is important for scaling of many scattering quantities (that are normalized to incident * irradiance). Alternative definition is p0=1, but then the results will scale with unit of length * (breaking scale invariance) */ p0=1/(WaveNum*WaveNum*WaveNum); if (IFROOT) sprintf(beam_descr,"point dipole at "GFORMDEF3V,COMP3V(beam_center_0)); return; case B_LMINUS: case B_DAVIS3: case B_BARTON5: if (surface) PrintError("Currently, Gaussian incident beam is not supported for '-surf'"); // initialize parameters w0=beam_pars[0]; TestPositive(w0,"beam width"); vCopy(beam_pars+1,beam_center_0); beam_asym=(beam_Npars==4 && (beam_center_0[0]!=0 || beam_center_0[1]!=0 || beam_center_0[2]!=0)); if (!beam_asym) vInit(beam_center); s=1/(WaveNum*w0); s2=s*s; scale_x=1/w0; scale_z=s*scale_x; // 1/(k*w0^2) // beam info if (IFROOT) { strcpy(beam_descr,"Gaussian beam ("); switch (beamtype) { case B_LMINUS: strcat(beam_descr,"L- approximation)\n"); break; case B_DAVIS3: strcat(beam_descr,"3rd order approximation, by Davis)\n"); break; case B_BARTON5: strcat(beam_descr,"5th order approximation, by Barton)\n"); break; default: break; } sprintf(beam_descr+strlen(beam_descr),"\tWidth="GFORMDEF" (confinement factor s="GFORMDEF")\n" "\tCenter position: "GFORMDEF3V,w0,s,COMP3V(beam_center_0)); } return; case B_READ: // the safest is to assume cancellation of all symmetries symX=symY=symZ=symR=false; if (surface) inc_scale=1; // since we can't know it, we assume the default case if (IFROOT) { if (beam_Npars==1) sprintf(beam_descr,"specified by file '%s'",beam_fnameY); else sprintf(beam_descr,"specified by files '%s' and '%s'",beam_fnameY,beam_fnameX); } // we do not define beam_asym here, because beam_center is not defined anyway return; } LogError(ONE_POS,"Unknown type of incident beam (%d)",(int)beamtype); /* TO ADD NEW BEAM * add a case above. Identifier ('B_...') should be defined inside 'enum beam' in const.h. The case should * 1) save all the input parameters from array 'beam_pars' to local variables (defined in the beginning of this * source files) * 2) test all input parameters (for that you're encouraged to use functions from param.h since they would * automatically produce informative output in case of error). * 3) the symmetry breaking due to prop or beam_center is taken care of in VariablesInterconnect() in param.c. * But if there are other reasons why beam would break any symmetry, corresponding variable should be set to * false here. Do not set any of them to true, as they can be set to false by other factors. * symX, symY, symZ - symmetries of reflection over planes YZ, XZ, XY respectively. * symR - symmetry of rotation for 90 degrees over the Z axis * 4) initialize the following: * beam_descr - descriptive string, which will appear in log file. * beam_asym - whether beam center does not coincide with the reference frame origin. If it is set to true, then * set also beam_center_0 - 3D radius-vector of beam center in the laboratory reference frame (it * will be then automatically transformed to particle reference frame, if required). * 5) Consider the case of surface (substrate near the particle). If the new beam type is incompatible with it, add * an explicit exception, like "if (surface) PrintErrorHelp(...);". Otherwise, you also need to define inc_scale. * All other auxiliary variables, which are used in beam generation (GenerateB(), see below), should be defined in * the beginning of this file. If you need temporary local variables (which are used only in this part of the code), * define them in the beginning of this function. */ }