这篇教程C++ v1函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中v1函数的典型用法代码示例。如果您正苦于以下问题:C++ v1函数的具体用法?C++ v1怎么用?C++ v1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了v1函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: tst_isolate_rootsstatic void tst_isolate_roots() { enable_trace("isolate_roots"); unsynch_mpq_manager qm; polynomial::manager pm(qm); algebraic_numbers::manager am(qm); polynomial_ref x0(pm); polynomial_ref x1(pm); polynomial_ref x2(pm); polynomial_ref x3(pm); x0 = pm.mk_polynomial(pm.mk_var()); x1 = pm.mk_polynomial(pm.mk_var()); x2 = pm.mk_polynomial(pm.mk_var()); x3 = pm.mk_polynomial(pm.mk_var()); polynomial_ref p(pm); p = x3*x1 + 1; scoped_anum v0(am), v1(am), v2(am); tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); am.set(v1, 1); tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); am.set(v1, 2); am.root(v1, 2, v1); tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x1 + x2)*x3 + 1; am.set(v2, v1); tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x1 + x2)*x3 + x1*x2 + 2; tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x1 + x2)*(x3^3) + x1*x2 + 2; tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x1 + x2)*(x3^2) - x1*x2 - 2; tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = x0*(x1 + x2)*(x3^2) - x0*x1*x2 - 2; tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x1 - x2)*x3 + x1*x2 - 2; tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x1 - x2)*(x3^3) + x1*x2 - 2; tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x3 - x0)*(x3 - x0 - x1); am.set(v0, 2); am.root(v0, 2, v0); // x2 -> sqrt(2) am.set(v1, 3); am.root(v1, 2, v1); // x1 -> sqrt(3) am.reset(v2); tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x3 - x0)*((x3 - x0 - x1)^2); tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2); p = (x3 - x0)*(x3 - 2)*((x3 - 1)^2)*(x3 - x1); tst_isolate_roots(p, am, 0, v0, 1, v1, 2, v2);}
开发者ID:jackluo923,项目名称:juxta,代码行数:64,
示例2: streamTriMesh * Resource::loadMeshFromObj(std::string _objSrc){ std::istringstream stream(FileUtils::voxReadFile(_objSrc)); std::vector<glm::vec3> verts; std::vector<glm::vec3> normals; std::vector<glm::vec2> uvs; std::smatch match; std::regex faceRegex("(//d{1})[/]?(//d?)[/]?(//d?)[//s]{1}"); bool faceFormatChecked = false; bool hasUvs = false; bool hasNorms = false; ObjFaceFormat faceStructure = VERTS; TriMesh* mesh = new TriMesh(GL_TRIANGLES, GL_STATIC_DRAW); int maxchars = 8192; std::vector<char> buf(maxchars); while(stream.peek() != -1) { stream.getline(&buf[0], maxchars); std::string line(&buf[0]); if (line.size() > 0) { if (line[line.size()-1] == '/n') line.erase(line.size()-1); } if (line.size() > 0) { if (line[line.size()-1] == '/r') line.erase(line.size()-1); } char p1 = -1; char p2 = -1; if(line.size() >= 1){ p1 = line[0]; } if(line.size() >= 1){ p2 = line[1]; } if(p1 == -1 || p2 == -1){ continue; } if(p1 == '/0' || p1 == '#'){ continue; } if(p1 == 'v' && p2 == ' '){ glm::vec3 tempVert(1); sscanf(line.c_str(), "%*s %f %f %f", &tempVert.x, &tempVert.y, &tempVert.z); verts.push_back(tempVert); }else if(p1 == 'v' && p2 == 'n'){ glm::vec3 tempNorm(1); sscanf(line.c_str(), "%*s %f %f %f", &tempNorm.x, &tempNorm.y, &tempNorm.z); normals.push_back(tempNorm); }else if(p1 == 'v' && p2 == 't'){ glm::vec2 tempUv(1); sscanf(line.c_str(), "%*s %f %f", &tempUv.x, &tempUv.y); uvs.push_back(tempUv); }else if(p1 == 'f' && p2 == ' '){ if(!faceFormatChecked){ std::smatch matches; std::regex_search(line, matches, faceRegex); if(matches[2].str().size() > 0 && matches[3].str().size() > 0){ faceStructure = VERTS_UVS_NORMALS; hasUvs = true; hasNorms = true; }else if(matches[2].str().size() > 0 && matches[3].str().size() <= 0){ faceStructure = VERTS_UVS; hasUvs = true; }else if(matches[2].str().size() <= 0 && matches[3].str().size() > 0){ faceStructure = VERTS_NORMALS; hasNorms = true; } faceFormatChecked = true; } Face face; std::string faceVert; std::string faceVerts; switch(faceStructure){ case VERTS : faceVert = " %d"; faceVerts = "%*s" + faceVert + faceVert + faceVert; sscanf(line.c_str(), faceVerts.c_str(), &face.f1Vert, &face.f2Vert, &face.f3Vert); break; case VERTS_UVS : faceVert = " %d/%d"; faceVerts = "%*s" + faceVert + faceVert + faceVert; sscanf(line.c_str(), faceVerts.c_str(), &face.f1Vert, &face.f1Uv, &face.f2Vert, &face.f2Uv, &face.f3Vert, &face.f3Uv); break; case VERTS_NORMALS : faceVert = " %d//%d"; faceVerts = "%*s" + faceVert + faceVert + faceVert; sscanf(line.c_str(), faceVerts.c_str(), &face.f1Vert, &face.f1Norm, &face.f2Vert, &face.f2Norm, &face.f3Vert, &face.f3Norm); break; case VERTS_UVS_NORMALS : faceVert = " %d/%d/%d"; faceVerts = "%*s" + faceVert + faceVert + faceVert; sscanf(line.c_str(), faceVerts.c_str(), &face.f1Vert, &face.f1Uv, &face.f1Norm, &face.f2Vert, &face.f2Uv, &face.f2Norm, &face.f3Vert, &face.f3Uv, &face.f3Norm); break; } Vertex v1(verts.at(face.f1Vert - 1));//.........这里部分代码省略.........
开发者ID:seleb,项目名称:Ludum-Dare-32,代码行数:101,
示例3: TestSymBandDivvoid TestSymBandDiv(tmv::DivType dt, PosDefCode pdc){ const int N = 10; std::vector<tmv::SymBandMatrixView<T> > sb; std::vector<tmv::SymBandMatrixView<std::complex<T> > > csb; MakeSymBandList(sb,csb,pdc); tmv::Vector<T> v1(N); tmv::Vector<T> v2(N-1); for (int i=0; i<N; ++i) v1(i) = T(16-3*i); for (int i=0; i<N-1; ++i) v2(i) = T(-7+2*i); std::ostream* checkout = showdiv ? &std::cout : 0; for(size_t i=START;i<sb.size();i++) { if (i>START) break; tmv::SymBandMatrixView<T> si = sb[i]; tmv::SymBandMatrixView<std::complex<T> > csi = csb[i]; if (dt == tmv::CH && csi.issym()) continue; si.saveDiv(); csi.saveDiv(); if (showstartdone) std::cout<<"Start loop: i = "<<i<<", si = "<<tmv::TMV_Text(si)<< " "<<si<<std::endl; Assert(IsPosDef(si) == (pdc==PosDef),"IsPosDef"); if (csi.isherm()) { Assert(IsPosDef(csi) == (pdc==PosDef),"IsPosDef"); } tmv::Matrix<T> m(si); m.saveDiv(); if (dt == tmv::CH) m.divideUsing(tmv::LU); else m.divideUsing(dt); m.setDiv(); Assert(m.checkDecomp(checkout),"CheckDecomp m"); T eps = EPS; if (pdc == Sing) eps *= 1000; else eps *= Norm(m)*Norm(m.inverse()); si.divideUsing(dt); si.setDiv(); if (si.isherm()) { tmv::HermMatrix<T> six = si; six.divideUsing(dt); six.setDiv(); Assert(six.checkDecomp(checkout),"CheckDecomp six(herm)"); } else { tmv::SymBandMatrix<T> six = si; six.divideUsing(dt); six.setDiv(); Assert(six.checkDecomp(checkout),"CheckDecomp six(sym)"); } Assert(si.checkDecomp(checkout),"CheckDecomp si"); tmv::Vector<T> x1 = v1/si; tmv::Vector<T> x2 = v1/m; if (showacc) { std::cout<<"v1 = "<<v1<<std::endl; std::cout<<"v1/si = "<<x1<<std::endl; std::cout<<"v1/m = "<<x2<<std::endl; std::cout<<"si*x1 = "<<si*x1<<std::endl; std::cout<<"m*x2 = "<<m*x2<<std::endl; std::cout<<"v/b: Norm(x1-x2) = "<<Norm(x1-x2)<< " "<<eps*Norm(x1)<<std::endl; } Assert(Norm(x1-x2) < eps*Norm(x1),"SymBand v/b"); x1 = v1%si; x2 = v1%m; if (showacc) std::cout<<"v%b: Norm(x1-x2) = "<<Norm(x1-x2)<< " "<<eps*Norm(x1)<<std::endl; Assert(Norm(x1-x2) < eps*Norm(x1),"SymBand v%b"); tmv::Matrix<T,tmv::ColMajor> sinv = si.inverse(); tmv::Matrix<T,tmv::ColMajor> minv = m.inverse(); if (showacc) { std::cout<<"sinv = "<<sinv<<std::endl; std::cout<<"minv = "<<minv<<std::endl; std::cout<<"Norm(minv-sinv) = "<<Norm(minv-sinv)<< " "<<eps*Norm(sinv)<<std::endl; } Assert(Norm(sinv-minv) < eps*Norm(sinv),"SymBand Inverse"); if (showacc) { std::cout<<"Det(si) = "<<Det(si)<<", Det(m) = "<<Det(m)<<std::endl; std::cout<<"abs(sdet-mdet) = "<<std::abs(Det(si)-Det(m)); std::cout<<" EPS*abs(mdet) = "<<eps*std::abs(Det(m))<<std::endl; std::cout<<"abs(abs(sdet)-abs(mdet)) = "<< std::abs(std::abs(Det(si))-std::abs(Det(m))); std::cout<<" EPS*abs(mdet) = "<<eps*std::abs(Det(m))<<std::endl; } if (pdc != Sing) { Assert(std::abs(Det(m)-Det(si)) < eps*std::abs(Det(m)), "SymBand Det"); T msign,ssign; Assert(std::abs(m.logDet(&msign)-si.logDet(&ssign)) < 10*N*eps, "SymBand LogDet"); Assert(std::abs(msign-ssign) < 10*N*eps, "SymBand LogDet - sign");//.........这里部分代码省略.........
开发者ID:rmjarvis,项目名称:tmv,代码行数:101,
示例4: v1void World::transformPartB(){ for (int i = 0; i < objects.size(); i++) { (*objects[i]).transform(persp_trans); (*objects[i]).transform(ortho_proj); (*objects[i]).transform(viewport_trans); } for (int i = 0; i < objects.size(); i++) { Material obj_color = (*objects[i]).surface_mat; for (int j = 0; j < (*objects[i]).num_triangles; j++) { Triangle cur_tri = (*objects[i]).triangles[j]; Vector3 center = cur_tri.centroid; Vector3 tri_normal = (cur_tri.unit_normal[0] + cur_tri.unit_normal[1] + cur_tri.unit_normal[2]) / 3.0; //Back face culling if (tri_normal * (center) > 0.0) continue; Vector4 v1 = cur_tri.vertices[0]; Vector4 v2 = cur_tri.vertices[1]; Vector4 v3 = cur_tri.vertices[2]; float xa = v1(0); float xb = v2(0); float xc = v3(0); float ya = v1(1); float yb = v2(1); float yc = v3(1); float x_min = floor(getMin(xa, xb, xc)); float y_min = floor(getMin(ya, yb, yc)); float x_max = ceil(getMax(xa, xb, xc)); float y_max = ceil(getMax(ya, yb, yc)); float n = x_max - x_min; for (int y = y_min; y <= y_max; y++) { for (int x = x_min; x <= x_max; x++) { float beta = ( (ya - yc) * x + (xc - xa) * y + xa * yc - xc * ya) / ( (ya - yc) * xb + (xc - xa) * yb + xa * yc - xc * ya); float gamma = ( (ya - yb) * x + (xb - xa) * y + xa * yb - xb * ya) / ( (ya - yb) * xc + (xb - xa) * yc + xa * yb - xb * ya); if (beta > 0.0 && gamma > 0.0 && (beta + gamma) < 1.0) { //Attribute interpolation ==================================================== float d1 = cur_tri.world_vertices[0].getMagnitude(); float d2 = cur_tri.world_vertices[1].getMagnitude(); float d3 = cur_tri.world_vertices[2].getMagnitude(); Vector3 fragment_location = center; Vector3 fragment_normal = fragment_location - Vector3(0, 0, -7); fragment_location = fragment_location / fragment_location.getMagnitude(); fragment_normal = fragment_normal / fragment_normal.getMagnitude(); float distance = (d1 + beta * (d2 - d1) + gamma * (d3 - d1)) / 3.0; //End of attribute interpolation ============================================== Vector3 light_vec = (Vector3(-4.0, 4.0, -3.0) / Vector3(-4.0, 4.0, -3.0).getMagnitude()) - (fragment_location / fragment_location.getMagnitude()); light_vec = light_vec / light_vec.getMagnitude(); Vector3 h_spec = light_vec - (fragment_location / fragment_location.getMagnitude()); h_spec = h_spec / h_spec.getMagnitude(); RGBColor tri_color = getMax(0.0, 0.0, (fragment_normal * light_vec)) * obj_color.diffuse; tri_color = tri_color + (obj_color.ambient * 0.2); tri_color = tri_color + obj_color.specular * pow(getMax(0, 0, fragment_normal * h_spec), obj_color.phong_exponent); tri_color = tri_color.power(1.0 / 2.2); Pixel tri_pix = Pixel(tri_color, distance); if (tri_pix.depth < (im_plane.getPixel(x, y).depth - 0.001) || im_plane.getPixel(x, y).depth < 0.0) im_plane.setPixel(x, y, tri_pix); } } } } }}
开发者ID:J-norton,项目名称:Graphics-Rasterizer,代码行数:92,
示例5: mainintmain(int argc, char *argv[]){ struct db_i *dbip; struct directory *dp; struct rt_db_internal intern; struct rt_bot_internal *bot_ip = NULL; struct rt_wdb *wdbp; struct bu_vls name; struct bu_vls bname; struct Mesh_Info *prev_mesh = NULL; struct Mesh_Info *mesh = NULL; bu_vls_init(&name); if (argc != 3) { bu_exit(1, "Usage: %s file.g object", argv[0]); } dbip = db_open(argv[1], DB_OPEN_READWRITE); if (dbip == DBI_NULL) { bu_exit(1, "ERROR: Unable to read from geometry database file %s/n", argv[1]); } if (db_dirbuild(dbip) < 0) bu_exit(1, "ERROR: Unable to read from %s/n", argv[1]); dp = db_lookup(dbip, argv[2], LOOKUP_QUIET); if (dp == RT_DIR_NULL) { bu_exit(1, "ERROR: Unable to look up object %s/n", argv[2]); } RT_DB_INTERNAL_INIT(&intern) if (rt_db_get_internal(&intern, dp, dbip, NULL, &rt_uniresource) < 0) { bu_exit(1, "ERROR: Unable to get internal representation of %s/n", argv[2]); } if (intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_BOT) { bu_exit(1, "ERROR: object %s does not appear to be of type BoT/n", argv[2]); } else { bot_ip = (struct rt_bot_internal *)intern.idb_ptr; } RT_BOT_CK_MAGIC(bot_ip); for (size_t i_cnt = 1; i_cnt < 3; i_cnt++) { mesh = iterate(bot_ip, prev_mesh); prev_mesh = mesh; // Plot results struct bu_vls fname; bu_vls_init(&fname); bu_vls_printf(&fname, "root3_%d.pl", i_cnt); FILE* plot_file = fopen(bu_vls_addr(&fname), "w"); std::map<size_t, std::vector<size_t> >::iterator f_it; std::vector<size_t>::iterator l_it; int r = int(256*drand48() + 1.0); int g = int(256*drand48() + 1.0); int b = int(256*drand48() + 1.0); for (f_it = mesh->face_pts.begin(); f_it != mesh->face_pts.end(); f_it++) { l_it = (*f_it).second.begin(); plot_face(&mesh->points_p0[(int)(*l_it)], &mesh->points_p0[(int)(*(l_it+1))], &mesh->points_p0[(int)(*(l_it+2))], r, g , b, plot_file); } fclose(plot_file); } // When constructing the final BoT, use the limit points for all // vertices ON_3dPointArray points_inf; for (size_t v = 0; v < (size_t)mesh->points_p0.Count(); v++) { points_inf.Append(*mesh->points_p0.At((int)v)); //point_inf(v, mesh, &points_inf); } // The subdivision process shrinks the bot relative to its original // vertex positions - to better approximate the original surface, // average the change in position of the original vertices to get a // scaling factor and apply it to all points in the final mesh. fastf_t scale = 0.0; for (size_t pcnt = 0; pcnt < bot_ip->num_vertices; pcnt++) { ON_3dVector v1(ON_3dPoint(&bot_ip->vertices[pcnt*3])); ON_3dVector v2(*points_inf.At((int)pcnt)); scale += 1 + (v1.Length() - v2.Length())/v1.Length(); } scale = scale / bot_ip->num_vertices; for (size_t pcnt = 0; pcnt < (size_t)points_inf.Count(); pcnt++) { ON_3dPoint p0(*points_inf.At((int)pcnt)); ON_3dPoint p1 = p0 * scale; *points_inf.At((int)pcnt) = p1; } wdbp = wdb_dbopen(dbip, RT_WDB_TYPE_DB_DISK); fastf_t *vertices = (fastf_t *)bu_malloc(sizeof(fastf_t) * points_inf.Count() * 3, "new verts"); int *faces = (int *)bu_malloc(sizeof(int) * mesh->face_pts.size() * 3, "new faces"); for (size_t v = 0; v < (size_t)points_inf.Count(); v++) { vertices[v*3] = points_inf[(int)v].x; vertices[v*3+1] = points_inf[(int)v].y; vertices[v*3+2] = points_inf[(int)v].z; } std::map<size_t, std::vector<size_t> >::iterator f_it; std::vector<size_t>::iterator l_it;//.........这里部分代码省略.........
开发者ID:behollis,项目名称:brlcad-svn-rev65072-gsoc2015,代码行数:101,
示例6: basicStufftemplate<typename MatrixType> void basicStuff(const MatrixType& m){ typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; Index rows = m.rows(); Index cols = m.cols(); // this test relies a lot on Random.h, and there's not much more that we can do // to test it, hence I consider that we will have tested Random.h MatrixType m1 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols), m3(rows, cols), mzero = MatrixType::Zero(rows, cols), identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> ::Identity(rows, rows), square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>::Random(rows, rows); VectorType v1 = VectorType::Random(rows), v2 = VectorType::Random(rows), vzero = VectorType::Zero(rows); Scalar x = ei_random<Scalar>(); Index r = ei_random<Index>(0, rows-1), c = ei_random<Index>(0, cols-1); m1.coeffRef(r,c) = x; VERIFY_IS_APPROX(x, m1.coeff(r,c)); m1(r,c) = x; VERIFY_IS_APPROX(x, m1(r,c)); v1.coeffRef(r) = x; VERIFY_IS_APPROX(x, v1.coeff(r)); v1(r) = x; VERIFY_IS_APPROX(x, v1(r)); v1[r] = x; VERIFY_IS_APPROX(x, v1[r]); VERIFY_IS_APPROX( v1, v1); VERIFY_IS_NOT_APPROX( v1, 2*v1); VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1); if(!NumTraits<Scalar>::IsInteger) VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1.norm()); VERIFY_IS_NOT_MUCH_SMALLER_THAN(v1, v1); VERIFY_IS_APPROX( vzero, v1-v1); VERIFY_IS_APPROX( m1, m1); VERIFY_IS_NOT_APPROX( m1, 2*m1); VERIFY_IS_MUCH_SMALLER_THAN( mzero, m1); VERIFY_IS_NOT_MUCH_SMALLER_THAN(m1, m1); VERIFY_IS_APPROX( mzero, m1-m1); // always test operator() on each read-only expression class, // in order to check const-qualifiers. // indeed, if an expression class (here Zero) is meant to be read-only, // hence has no _write() method, the corresponding MatrixBase method (here zero()) // should return a const-qualified object so that it is the const-qualified // operator() that gets called, which in turn calls _read(). VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows,cols)(r,c), static_cast<Scalar>(1)); // now test copying a row-vector into a (column-)vector and conversely. square.col(r) = square.row(r).eval(); Matrix<Scalar, 1, MatrixType::RowsAtCompileTime> rv(rows); Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> cv(rows); rv = square.row(r); cv = square.col(r); VERIFY_IS_APPROX(rv, cv.transpose()); if(cols!=1 && rows!=1 && MatrixType::SizeAtCompileTime!=Dynamic) { VERIFY_RAISES_ASSERT(m1 = (m2.block(0,0, rows-1, cols-1))); } if(cols!=1 && rows!=1) { VERIFY_RAISES_ASSERT(m1[0]); VERIFY_RAISES_ASSERT((m1+m1)[0]); } VERIFY_IS_APPROX(m3 = m1,m1); MatrixType m4; VERIFY_IS_APPROX(m4 = m1,m1); m3.real() = m1.real(); VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), static_cast<const MatrixType&>(m1).real()); VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), m1.real()); // check == / != operators VERIFY(m1==m1); VERIFY(m1!=m2); VERIFY(!(m1==m2)); VERIFY(!(m1!=m1)); m1 = m2; VERIFY(m1==m2); VERIFY(!(m1!=m2));}
开发者ID:B-Rich,项目名称:sim3d,代码行数:96,
示例7: TESTTEST(TVector, can_create_copied_vector){ TVector<int> v(10); ASSERT_NO_THROW(TVector<int> v1(v));}
开发者ID:RomanGuskov,项目名称:mp2-lab2-matrix,代码行数:6,
示例8: TESTTEST(vector2, magnitude){ Vector2 v1(4, 5); float magnitude = 6.4031; EXPECT_NEAR(magnitude, v1.Magnitude(), .0001);}
开发者ID:TheCapleGuy,项目名称:MathLib,代码行数:6,
示例9: v0//.........这里部分代码省略......... double temp = std::sqrt(i*i+j*j); if ( temp < (Xdim/2)) A2D_ELEM(ROI,i,j)= 1; else A2D_ELEM(ROI,i,j)= 0; } Image<double> img; FourierTransformer transformer(FFTW_BACKWARD); FOR_ALL_OBJECTS_IN_METADATA(SF) { if (thereIsEnable) { int enabled; SF.getValue(MDL_ENABLED,enabled,__iter.objId); if ( (enabled==-1) ) { imgno++; continue; } } img.readApplyGeo(SF,__iter.objId); if (targetXdim!=-1 && targetXdim!=XSIZE(img())) selfScaleToSize(LINEAR,img(),targetXdim,targetXdim,1); MultidimArray<double> &mI=img(); mI.setXmippOrigin(); mI.statisticsAdjust(0,1); mask.setXmippOrigin(); //The size of v1 depends on the image size and must be declared here int numDescriptors1 = XSIZE(mI)/2; //=100; MultidimArray<float> v1(numDescriptors1); v1.initZeros(numDescriptors1); double var = 1; normalize(transformer,mI,tempI,modI,0,var,mask); modI.setXmippOrigin(); tempI.setXmippOrigin(); nI = sign*tempI*(modI*modI); tempM = (modI*modI); A1D_ELEM(v0,0) = (tempM*ROI).sum(); int index = 1; var+=2; while (index < numNorm) { normalize(transformer,mI,tempI,modI,0,var,mask); modI.setXmippOrigin(); tempI.setXmippOrigin(); nI += sign*tempI*(modI*modI); tempM += (modI*modI); A1D_ELEM(v0,index) = (tempM*ROI).sum(); index++; var+=2; } nI /= tempM; tempPcaAnalyzer0.addVector(v0); nI=(nI*ROI); auto_correlation_matrix(mI,autoCorr); if (first) { radialAveragePrecomputeDistance(autoCorr, center, distance, dim);
开发者ID:azazellochg,项目名称:scipion,代码行数:67,
示例10: mainint main (int, char**){ UnitTest t (76); Variant v0 (true); Variant v1 (42); Variant v2 (3.14); Variant v3 ("foo"); Variant v4 (1234567890, Variant::type_date); Variant v5 (1200, Variant::type_duration); // Truth table. Variant vFalse (false); Variant vTrue (true); t.is (vFalse && vFalse, false, "false && false --> false"); t.is (vFalse && vTrue, false, "false && true --> false"); t.is (vTrue && vFalse, false, "true && false --> false"); t.is (vTrue && vTrue, true, "true && true --> true"); Variant v00 = v0 && v0; t.is (v00.type (), Variant::type_boolean, "true && true --> boolean"); t.is (v00.get_bool (), true, "true && true --> true"); Variant v01 = v0 && v1; t.is (v01.type (), Variant::type_boolean, "true && 42 --> boolean"); t.is (v01.get_bool (), true, "true && 42 --> true"); Variant v02 = v0 && v2; t.is (v02.type (), Variant::type_boolean, "true && 3.14 --> boolean"); t.is (v02.get_bool (), true, "true && 3.14 --> true"); Variant v03 = v0 && v3; t.is (v03.type (), Variant::type_boolean, "true && 'foo' --> boolean"); t.is (v03.get_bool (), true, "true && 'foo' --> true"); Variant v04 = v0 && v4; t.is (v04.type (), Variant::type_boolean, "true && 1234567890 --> boolean"); t.is (v04.get_bool (), true, "true && 1234567890 --> true"); Variant v05 = v0 && v5; t.is (v05.type (), Variant::type_boolean, "true && 1200 --> boolean"); t.is (v05.get_bool (), true, "true && 1200 --> true"); Variant v10 = v1 && v0; t.is (v10.type (), Variant::type_boolean, "42 && true --> boolean"); t.is (v10.get_bool (), true, "42 && true --> true"); Variant v11 = v1 && v1; t.is (v11.type (), Variant::type_boolean, "42 && 42 --> boolean"); t.is (v11.get_bool (), true, "42 && 42 --> true"); Variant v12 = v1 && v2; t.is (v12.type (), Variant::type_boolean, "42 && 3.14 --> boolean"); t.is (v12.get_bool (), true, "42 && 3.14 --> true"); Variant v13 = v1 && v3; t.is (v13.type (), Variant::type_boolean, "42 && 'foo' --> boolean"); t.is (v13.get_bool (), true, "42 && 'foo' --> true"); Variant v14 = v1 && v4; t.is (v04.type (), Variant::type_boolean, "42 && 1234567890 --> boolean"); t.is (v04.get_bool (), true, "42 && 1234567890 --> true"); Variant v15 = v1 && v5; t.is (v15.type (), Variant::type_boolean, "42 && 1200 --> boolean"); t.is (v15.get_bool (), true, "42 && 1200 --> true"); Variant v20 = v2 && v0; t.is (v20.type (), Variant::type_boolean, "3.14 && true --> boolean"); t.is (v20.get_bool (), true, "3.14 && true --> true"); Variant v21 = v2 && v1; t.is (v21.type (), Variant::type_boolean, "3.14 && 42 --> boolean"); t.is (v21.get_bool (), true, "3.14 && 42 --> true"); Variant v22 = v2 && v2; t.is (v22.type (), Variant::type_boolean, "3.14 && 3.14 --> boolean"); t.is (v22.get_bool (), true, "3.14 && 3.14 --> true"); Variant v23 = v2 && v3; t.is (v23.type (), Variant::type_boolean, "3.14 && 'foo' --> boolean"); t.is (v23.get_bool (), true, "3.14 && 'foo' --> true"); Variant v24 = v2 && v4; t.is (v24.type (), Variant::type_boolean, "3.14 && 1234567890 --> boolean"); t.is (v24.get_bool (), true, "3.14 && 1234567890 --> true"); Variant v25 = v2 && v5; t.is (v25.type (), Variant::type_boolean, "3.14 && 1200 --> boolean"); t.is (v25.get_bool (), true, "3.14 && 1200 --> true"); Variant v30 = v3 && v0; t.is (v30.type (), Variant::type_boolean, "'foo' && true --> boolean"); t.is (v30.get_bool (), true, "'foo' && true --> true"); Variant v31 = v3 && v1; t.is (v31.type (), Variant::type_boolean, "'foo' && 42 --> boolean"); t.is (v31.get_bool (), true, "'foo' && 42 --> true"); Variant v32 = v3 && v2;//.........这里部分代码省略.........
开发者ID:austinwagner,项目名称:task,代码行数:101,
示例11: CGALPrimitivePrimitive* CGALImport::importSTL(QFileInfo fileinfo){ CGALPrimitive* p=new CGALPrimitive(); QFile f(fileinfo.absoluteFilePath()); if(!f.open(QIODevice::ReadOnly)) { output << "WARNING: Can't open import file '" << fileinfo.absoluteFilePath() << "'/n"; return p; } QByteArray header=f.read(5); if(header.size()==5 && QString(header)=="solid") { QTextStream data(&f); QRegExp re=QRegExp("//s*(vertex)?//s+"); while(!data.atEnd()) { QString line=data.readLine(); if(line.contains("solid") || line.contains("facet") || line.contains("endloop")) continue; if(line.contains("outer loop")) { p->createPolygon(); continue; } if(line.contains("vertex")) { QStringList tokens=line.split(re); bool ok=false; if(tokens.size()==4) { double x,y,z; bool ox,oy,oz; x=tokens[1].toDouble(&ox); y=tokens[2].toDouble(&oy); z=tokens[3].toDouble(&oz); if((ok=ox&&oy&&oz)) { CGAL::Point3 pt(x,y,z); p->appendVertex(pt); } } if(!ok) { output << "WARNING: Can't parse vertex line '" << line << "'/n"; } } } } else { f.read(80-5+4); while(1) { struct { float i, j, k; float x1, y1, z1; float x2, y2, z2; float x3, y3, z3; unsigned short acount; } __attribute__((packed)) data; if(f.read((char*)&data, sizeof(data)) != sizeof(data)) break; p->createPolygon(); CGAL::Point3 v1(data.x1,data.y1,data.z1); p->appendVertex(v1); CGAL::Point3 v2(data.x2,data.y2,data.z2); p->appendVertex(v2); CGAL::Point3 v3(data.x3,data.y3,data.z3); p->appendVertex(v3); } } return p->buildPrimitive();}
开发者ID:Klatticus,项目名称:RapCAD,代码行数:66,
示例12: main// Hotrod 2.8 with mediatype allows to store and retrieve entries in different data format// this can be done specifying the mediatype for the communicationint main(int argc, char** argv) { ConfigurationBuilder builder; builder.protocolVersion(Configuration::PROTOCOL_VERSION_28); builder.addServer().host("127.0.0.1").port(11222); builder.balancingStrategyProducer(nullptr); RemoteCacheManager cacheManager(builder.build(), false); cacheManager.start(); std::cout << "Tests for CacheManager" << std::endl; Marshaller<std::string> *km = new JBasicMarshaller<std::string>(); Marshaller<std::string> *vm = new JBasicMarshaller<std::string>(); RemoteCache<std::string, std::string> cache = cacheManager.getCache<std::string, std::string>(km, &Marshaller<std::string>::destroy, vm, &Marshaller<std::string>::destroy, std::string("transcodingCache")); // Define a data format for json DataFormat<std::string, std::string> df; df.keyMediaType = MediaType(APPLICATION_UNKNOWN_TYPE); df.valueMediaType = MediaType(APPLICATION_JSON_TYPE); df.valueMarshaller.reset(new BasicMarshaller<std::string>()); RemoteCache<std::string, std::string> cacheJson = cache.withDataFormat(&df); // Define a data forma for jboss marshaller DataFormat<std::string, std::string> df1; df1.keyMediaType = MediaType(APPLICATION_JBOSS_MARSHALLING_TYPE); df1.valueMediaType = MediaType(APPLICATION_JBOSS_MARSHALLING_TYPE); RemoteCache<std::string, std::string> cacheJBoss = cache.withDataFormat(&df1); std::string k1("key13"); std::string k2("key14"); std::string v1("boron"); std::string v2("chlorine"); cache.clear(); // put cache.put(k1, v1); std::unique_ptr<std::string> rv(cache.get(k1)); assert_not_null("get returned null!", __LINE__, rv); if (rv->compare(v1)) { std::cerr << "get/put fail for " << k1 << " got " << *rv << " expected " << v1 << std::endl; return 1; } cache.put(k2, v2); std::unique_ptr<std::string> rv2(cache.get(k2)); assert_not_null("get returned null!", __LINE__, rv2); if (rv2->compare(v2)) { std::cerr << "get/put fail for " << k2 << " got " << *rv2 << " expected " << v2 << std::endl; return 1; } std::unique_ptr<std::string> rv2Json(cacheJson.get(k2)); assert_not_null("get returned null!", __LINE__, rv2Json); if (rv2Json->compare("/"chlorine/"")) { std::cerr << "get/put fail for " << k2 << " got " << *rv2 << " expected /"boron/"" << std::endl; return 1; } std::unique_ptr<std::string> rv2JBoss(cacheJBoss.get(k2)); assert_not_null("get returned null!", __LINE__, rv2JBoss); if (rv2JBoss->compare(v2)) { std::cerr << "get/put fail for " << k2 << " got " << *rv2JBoss << " expected " << v2 << std::endl; return 1; } }
开发者ID:infinispan,项目名称:cpp-client,代码行数:64,
示例13: main//.........这里部分代码省略......... int StandardNumMyRows = StandardMatrix.NumMyRows(); int GatheredNumMyRows = GatheredMatrix.NumMyRows(); EPETRA_TEST_ERR(!(StandardNumMyRows==GatheredNumMyRows),ierr); forierr = 0; for (i=0; i< StandardNumMyRows; i++) { forierr += !(StandardMatrix.ExtractMyRowView(i, StandardNumEntries, StandardValues, StandardIndices)==0); forierr += !(GatheredMatrix.ExtractMyRowView(i, GatheredNumEntries, GatheredValues, GatheredIndices)==0); forierr += !(StandardNumEntries==GatheredNumEntries); for (j=0; j < StandardNumEntries; j++) { //if (StandardIndices[j]!=GatheredIndices[j]) // cout << "MyPID = " << MyPID << " i = " << i << " StandardIndices[" << j << "] = " << StandardIndices[j] // << " GatheredIndices[" << j << "] = " << GatheredIndices[j] << endl; //if (StandardValues[j]!=GatheredValues[j]) //cout << "MyPID = " << MyPID << " i = " << i << " StandardValues[" << j << "] = " << StandardValues[j] // << " GatheredValues[" << j << "] = " << GatheredValues[j] << endl; forierr += !(StandardIndices[j]==GatheredIndices[j]); forierr += !(StandardValues[j]==GatheredValues[j]); } } EPETRA_TEST_ERR(forierr,ierr); if (verbose) cout << "Matrix Export Check OK" << endl << endl; //Do Again with use of Epetra_OffsetIndex object for speed Epetra_OffsetIndex OffsetIndex( OverlapMatrix.Graph(), GatheredMatrix.Graph(), Exporter ); EPETRA_TEST_ERR(!(GatheredMatrix.Export(OverlapMatrix, Exporter, Add)==0),ierr); if (verbose) cout << "Optimized Matrix Export Check OK" << endl << endl; bool passed; Epetra_LongLongVector v1(StandardMap); v1.PutValue(2); Epetra_LongLongVector v2(StandardMap); v2.PutValue(3); Epetra_Export identExporter(StandardMap,StandardMap); // Identity exporter EPETRA_TEST_ERR(!(v2.Export(v1, identExporter, Insert)==0),ierr); passed = (v2.MinValue()==2); EPETRA_TEST_ERR(!passed,ierr); v1.PutValue(1); Epetra_Import identImporter(StandardMap,StandardMap); // Identity importer EPETRA_TEST_ERR(!(v2.Import(v1, identExporter, Insert)==0),ierr); passed = passed && (v2.MaxValue()==1); EPETRA_TEST_ERR(!passed,ierr); if (verbose) { if (passed) cout << "Identity Import/Export Check OK" << endl << endl; else cout << "Identity Import/Export Check Failed" << endl << endl; } int NumSubMapElements = StandardMap.NumMyElements()/2; int SubStart = Comm.MyPID(); NumSubMapElements = EPETRA_MIN(NumSubMapElements,StandardMap.NumMyElements()-SubStart); Epetra_Map SubMap((long long) -1, NumSubMapElements, StandardMyGlobalElements+SubStart, 0LL, Comm); Epetra_LongLongVector v3(View, SubMap, SubMap.MyGlobalElements64()); // Fill v3 with GID values for variety Epetra_Export subExporter(SubMap, StandardMap); // Export to a subset of indices of standard map EPETRA_TEST_ERR(!(v2.Export(v3,subExporter,Insert)==0),ierr); forierr = 0; for (i=0; i<SubMap.NumMyElements(); i++) { int i1 = StandardMap.LID(SubMap.GID64(i)); forierr += !(v3[i]==v2[i1]); }
开发者ID:00liujj,项目名称:trilinos,代码行数:67,
示例14: pEdgevoid ElPoly::DefineSkin(int NSample){ std::list<Weighted_point> l; FT shrinkfactor = 0.5; double *Plot = new double[pNType()*CUBE(NSample)]; double *Count = new double[CUBE(NSample)]; double Thre = 10.; double Radius = pEdge(0)/(double)NSample; for(int p=0;p<pNPart();p++){ int t = pType(p); int vx = (int)(pPos(p,0)/pEdge(0)*NSample); int vy = (int)(pPos(p,1)/pEdge(1)*NSample); int vz = (int)(pPos(p,2)/pEdge(2)*NSample); int vTot = (vz*NSample+vy)*NSample+vx; Plot[vTot*pNType()+t] += 1.; } double *Norm = (double *)calloc(pNType(),sizeof(double)); for(int t=0;t<pNType();t++){ for(int v=0;v<CUBE(NSample);v++){ if(Norm[t] < Plot[v*pNType()+t]) Norm[t] = Plot[v*pNType()+t]; } Norm[t] = Norm[t] <= 0. ? 1. : Norm[t]; } for(int vx=0;vx<NSample;vx++){ double x = vx*pEdge(0)/(double)NSample; for(int vy=0;vy<NSample;vy++){ double y = vy*pEdge(1)/(double)NSample; for(int vz=0;vz<NSample;vz++){ double z = vz*pEdge(2)/(double)NSample; int vTot = (vz*NSample+vy)*NSample+vx; if(Plot[vTot*pNType()] > Thre){ l.push_front(Weighted_point(Bare_point(x,y,z),Radius)); } } } } Polyhedron Polyhe; Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); CGAL::mesh_skin_surface_3(skin_surface, Polyhe); // CGAL::subdivide_skin_surface_mesh_3(skin_surface, Polyhe); // std::ofstream out("mesh.off"); // out << Polyhe; glDeleteLists(Dr->Particles,1); Dr->Particles = glGenLists(1); glNewList(Dr->Particles,GL_COMPILE); // Polyhedron::Facet_iterator fcUp = Polyhe.facets_begin(); // for(;fcUp != Polyhe.facets_end(); ++fcUp){ // Polyhedron::Supports_facet_halfedge = fcUp.halfedge(); // //Halfedge_around_facet_circulator heUp = fcUp.halfedge(); // } // for (Vertex_iterator vit = Polyhe.vertices_begin();vit != Polyhe.vertices_end(); vit++){ // // Vector n = policy.normal(vit); // // n = n/sqrt(n*n); // cout << vit->point() << std::endl; // Halfedge_iterator heUp = Polyhe.halfedges_begin(); // for(;heUp != Polyhe.halfedges_end(); ++heUp){ // //Polyhedron::Halfedge_handle Half = *heUp; // Vertex_handle veUp = heUp->vertex(); // K::Point_3 pf1 = vit->point(); // } // } CGAL::Inverse_index<Vertex_handle> index(Polyhe.vertices_begin(), Polyhe.vertices_end()); for(Facet_iterator fi = Polyhe.facets_begin();fi != Polyhe.facets_end(); ++fi) { HFC hc = fi->facet_begin(); HFC hc_end = hc; Polyhedron::Vertex_handle vf1 = (*hc).vertex(); hc++; Polyhedron::Vertex_handle vf2 = (*hc).vertex(); hc++; Polyhedron::Vertex_handle vf3 = (*hc).vertex(); hc++; K::Point_3 pf1 = vf1->point(); K::Point_3 pf2 = vf2->point(); K::Point_3 pf3 = vf3->point(); Vettore v1(pf1.x(),pf1.y(),pf1.z()); Vettore v2(pf2.x(),pf2.y(),pf2.z()); Vettore v3(pf3.x(),pf3.y(),pf3.z()); Vettore vN(3); v1.Mult(InvScaleUn); v2.Mult(InvScaleUn); v3.Mult(InvScaleUn); vN = (v1-v2) ^ (v3-v2); //if(vN.Norm() > 2.*AreaMean) continue; double Sfumatura = .3*Mat->Casuale(); glColor4f(0.1,.4+Sfumatura,0.2,1.); //glColor4f(HueUp[p].r,HueUp[p].g,HueUp[p].b,HueUp[p].a); DrTria(&v1,&v2,&v3,&vN); glColor4f(1.,.0,0.,1.); DrTriaContour(&v1,&v2,&v3);//.........这里部分代码省略.........
开发者ID:sabeiro,项目名称:Allink,代码行数:101,
示例15: mainint main(int argc, char** argv){ // ============================================= // vector init/add/sub/scale/normalize/dot/cross // ============================================= std::cout << "===========" << std::endl; std::cout << "vector init" << std::endl; std::cout << "===========" << std::endl << std::endl; { std::cout << "default c-tor:/t/t"; print_vec(glm::vec3()); std::cout << std::endl; std::cout << "arg c-tor (explicit):/t"; print_vec(glm::vec3(1, 2, 3)); std::cout << std::endl; std::cout << "arg c-tor (1 float):/t"; print_vec(glm::vec3(2)); std::cout << std::endl; std::cout << "arg c-tor (array):/t"; float arr[] = {1, 2, 3}; print_vec(glm::make_vec3(arr)); std::cout << std::endl; } std::cout << std::endl; std::cout << "==========" << std::endl; std::cout << "vector add" << std::endl; std::cout << "==========" << std::endl << std::endl; { glm::vec3 v1(1, 2, 3); glm::vec3 v2(4, 5, 6); std::cout << "v1:/t/t"; print_vec(v1); std::cout << std::endl; std::cout << "v2:/t/t"; print_vec(v2); std::cout << std::endl; std::cout << "v1+v2:/t/t"; print_vec(v1+v2); std::cout << std::endl; std::cout << "v1 += v2:/t"; v1 += v2; print_vec(v1); std::cout << std::endl; } std::cout << std::endl; std::cout << "==========" << std::endl; std::cout << "vector sub" << std::endl; std::cout << "==========" << std::endl << std::endl; { glm::vec3 v1(1, 2, 3); glm::vec3 v2(4, 5, 6); std::cout << "v1:/t/t"; print_vec(v1); std::cout << std::endl; std::cout << "v2:/t/t"; print_vec(v2); std::cout << std::endl; std::cout << "v1-v2:/t/t"; print_vec(v1-v2); std::cout << std::endl; std::cout << "v1 -= v2:/t"; v1 -= v2; print_vec(v1); std::cout << std::endl; } std::cout << std::endl; std::cout << "============" << std::endl; std::cout << "vector scale" << std::endl; std::cout << "============" << std::endl << std::endl; { glm::vec3 v(1, 2, 3); float k = 2; std::cout << "v:/t/t"; print_vec(v); std::cout << std::endl; std::cout << "k:/t/t" << k << std::endl; std::cout << "v*k:/t/tn/a"; //print_vec(v*k); std::cout << std::endl; std::cout << "v *= k:/t/t";//.........这里部分代码省略.........
开发者ID:onlyuser,项目名称:Sandbox,代码行数:101,
示例16: assertbool simplify_exprt::simplify_floatbv_op(exprt &expr){ const typet &type=ns.follow(expr.type()); if(type.id()!=ID_floatbv) return true; assert(expr.operands().size()==3); exprt op0=expr.op0(); exprt op1=expr.op1(); exprt op2=expr.op2(); // rounding mode assert(ns.follow(op0.type())==type); assert(ns.follow(op1.type())==type); // Remember that floating-point addition is _NOT_ associative. // Thus, we don't re-sort the operands. // We only merge constants! if(op0.is_constant() && op1.is_constant() && op2.is_constant()) { ieee_floatt v0(to_constant_expr(op0)); ieee_floatt v1(to_constant_expr(op1)); mp_integer rounding_mode; if(!to_integer(op2, rounding_mode)) { v0.rounding_mode=(ieee_floatt::rounding_modet)integer2long(rounding_mode); v1.rounding_mode=v0.rounding_mode; ieee_floatt result=v0; if(expr.id()==ID_floatbv_plus) result+=v1; else if(expr.id()==ID_floatbv_minus) result-=v1; else if(expr.id()==ID_floatbv_mult) result*=v1; else if(expr.id()==ID_floatbv_div) result/=v1; else assert(false); expr=result.to_expr(); return false; } } // division by one? Exact for all rounding modes. if (expr.id()==ID_floatbv_div && op1.is_constant() && op1.is_one()) { exprt tmp; tmp.swap(op0); expr.swap(tmp); return false; } return true;}
开发者ID:Dthird,项目名称:CBMC,代码行数:61,
示例17: test_basic_templatevoid test_basic_template( ForwardIterator first,ForwardIterator last BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Flyweight)){ typedef typename Flyweight::value_type value_type; ForwardIterator it; for(it=first;it!=last;++it){ /* construct/copy/destroy */ Flyweight f1(*it); Flyweight f2; Flyweight c1(f1); const Flyweight c2(static_cast<const Flyweight&>(f2)); value_type v1(*it); boost::value_initialized<value_type> v2; BOOST_TEST(f1.get_key()==*it); BOOST_TEST((f1==f2)==(f1.get()==v2.data())); BOOST_TEST(f1==c1); BOOST_TEST(f2==c2);#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) Flyweight cr1(std::move(c1)); Flyweight cr2(std::move(c2)); BOOST_TEST(f1==cr1); BOOST_TEST(f2==cr2);#endif#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) /* testcase for https://svn.boost.org/trac/boost/ticket/10439 */ Flyweight f3={}; BOOST_TEST(f3==f2);#endif f1=f1; BOOST_TEST(f1==f1); c1=f2; BOOST_TEST(c1==f2); c1=f1; BOOST_TEST(c1==f1); /* convertibility to underlying type */ BOOST_TEST(f1.get()==v1); /* identity of reference */ BOOST_TEST(&f1.get()==&c1.get()); /* modifiers */ f1.swap(f1); BOOST_TEST(f1==c1); f1.swap(f2); BOOST_TEST(f1==c2); BOOST_TEST(f2==c1); boost::flyweights::swap(f1,f2); BOOST_TEST(f1==c1); BOOST_TEST(f2==c2); /* specialized algorithms */ std::ostringstream oss1; oss1<<f1; std::ostringstream oss2; oss2<<f1.get(); BOOST_TEST(oss1.str()==oss2.str());#if !defined(BOOST_FLYWEIGHT_DISABLE_HASH_SUPPORT) /* hash support */ BOOST_TEST(boost::hash<Flyweight>()(f1)==boost::hash<Flyweight>()(c1)); BOOST_TEST(boost::hash<Flyweight>()(f1)== boost::hash<const value_type*>()(&f1.get()));#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) BOOST_TEST(std::hash<Flyweight>()(f1)==std::hash<Flyweight>()(c1)); BOOST_TEST(std::hash<Flyweight>()(f1)== std::hash<const value_type*>()(&f1.get()));#endif#endif }}
开发者ID:Ding8222,项目名称:abelkhan,代码行数:90,
示例18: B3_PROFILEvoid TinyRenderer::renderObject(TinyRenderObjectData& renderData){ B3_PROFILE("renderObject"); int width = renderData.m_rgbColorBuffer.get_width(); int height = renderData.m_rgbColorBuffer.get_height(); Vec3f light_dir_local = Vec3f(renderData.m_lightDirWorld[0], renderData.m_lightDirWorld[1], renderData.m_lightDirWorld[2]); Vec3f light_color = Vec3f(renderData.m_lightColor[0], renderData.m_lightColor[1], renderData.m_lightColor[2]); float light_distance = renderData.m_lightDistance; Model* model = renderData.m_model; if (0 == model) return; //discard invisible objects (zero alpha) if (model->getColorRGBA()[3] == 0) return; renderData.m_viewportMatrix = viewport(0, 0, width, height); b3AlignedObjectArray<float>& zbuffer = renderData.m_depthBuffer; b3AlignedObjectArray<float>* shadowBufferPtr = renderData.m_shadowBuffer; int* segmentationMaskBufferPtr = (renderData.m_segmentationMaskBufferPtr && renderData.m_segmentationMaskBufferPtr->size()) ? &renderData.m_segmentationMaskBufferPtr->at(0) : 0; TGAImage& frame = renderData.m_rgbColorBuffer; { // light target is set to be the origin, and the up direction is set to be vertical up. Matrix lightViewMatrix = lookat(light_dir_local * light_distance, Vec3f(0.0, 0.0, 0.0), Vec3f(0.0, 0.0, 1.0)); Matrix lightModelViewMatrix = lightViewMatrix * renderData.m_modelMatrix; Matrix modelViewMatrix = renderData.m_viewMatrix * renderData.m_modelMatrix; Vec3f localScaling(renderData.m_localScaling[0], renderData.m_localScaling[1], renderData.m_localScaling[2]); Matrix viewMatrixInv = renderData.m_viewMatrix.invert(); btVector3 P(viewMatrixInv[0][3], viewMatrixInv[1][3], viewMatrixInv[2][3]); Shader shader(model, light_dir_local, light_color, modelViewMatrix, lightModelViewMatrix, renderData.m_projectionMatrix, renderData.m_modelMatrix, renderData.m_viewportMatrix, localScaling, model->getColorRGBA(), width, height, shadowBufferPtr, renderData.m_lightAmbientCoeff, renderData.m_lightDiffuseCoeff, renderData.m_lightSpecularCoeff); { B3_PROFILE("face"); for (int i = 0; i < model->nfaces(); i++) { for (int j = 0; j < 3; j++) { shader.vertex(i, j); } // backface culling btVector3 v0(shader.world_tri.col(0)[0], shader.world_tri.col(0)[1], shader.world_tri.col(0)[2]); btVector3 v1(shader.world_tri.col(1)[0], shader.world_tri.col(1)[1], shader.world_tri.col(1)[2]); btVector3 v2(shader.world_tri.col(2)[0], shader.world_tri.col(2)[1], shader.world_tri.col(2)[2]); btVector3 N = (v1 - v0).cross(v2 - v0); if ((v0 - P).dot(N) >= 0) continue; mat<4, 3, float> stackTris[3]; b3AlignedObjectArray<mat<4, 3, float> > clippedTriangles; clippedTriangles.initializeFromBuffer(stackTris, 0, 3); bool hasClipped = clipTriangleAgainstNearplane(shader.varying_tri, clippedTriangles); if (hasClipped) { for (int t = 0; t < clippedTriangles.size(); t++) { triangleClipped(clippedTriangles[t], shader.varying_tri, shader, frame, &zbuffer[0], segmentationMaskBufferPtr, renderData.m_viewportMatrix, renderData.m_objectIndex + ((renderData.m_linkIndex + 1) << 24)); } } else { triangle(shader.varying_tri, shader, frame, &zbuffer[0], segmentationMaskBufferPtr, renderData.m_viewportMatrix, renderData.m_objectIndex + ((renderData.m_linkIndex + 1) << 24)); } } } }}
开发者ID:bulletphysics,项目名称:bullet3,代码行数:75,
示例19: mainint main (int, char**){ UnitTest t (72); Variant v0 (true); Variant v1 (42); Variant v2 (3.14); Variant v3 ("foo"); Variant v4 (1234567890, Variant::type_date); Variant v5 (1200, Variant::type_duration); Variant v00 = v0 != v0; t.is (v00.type (), Variant::type_boolean, "true != true --> boolean"); t.is (v00.get_bool (), false, "true != true --> false"); Variant v01 = v0 != v1; t.is (v01.type (), Variant::type_boolean, "true != 42 --> boolean"); t.is (v01.get_bool (), true, "true != 42 --> true"); Variant v02 = v0 != v2; t.is (v02.type (), Variant::type_boolean, "true != 3.14 --> boolean"); t.is (v02.get_bool (), true, "true != 3.14 --> true"); Variant v03 = v0 != v3; t.is (v03.type (), Variant::type_boolean, "true != 'foo' --> boolean"); t.is (v03.get_bool (), true, "true != 'foo' --> true"); Variant v04 = v0 != v4; t.is (v04.type (), Variant::type_boolean, "true != 1234567890 --> boolean"); t.is (v04.get_bool (), true, "true != 1234567890 --> true"); Variant v05 = v0 != v5; t.is (v05.type (), Variant::type_boolean, "true != 1200 --> boolean"); t.is (v05.get_bool (), true, "true != 1200 --> true"); Variant v10 = v1 != v0; t.is (v10.type (), Variant::type_boolean, "42 != true --> boolean"); t.is (v10.get_bool (), true, "42 != true --> true"); Variant v11 = v1 != v1; t.is (v11.type (), Variant::type_boolean, "42 != 42 --> boolean"); t.is (v11.get_bool (), false, "42 != 42 --> false"); Variant v12 = v1 != v2; t.is (v12.type (), Variant::type_boolean, "42 != 3.14 --> boolean"); t.is (v12.get_bool (), true, "42 != 3.14 --> true"); Variant v13 = v1 != v3; t.is (v13.type (), Variant::type_boolean, "42 != 'foo' --> boolean"); t.is (v13.get_bool (), true, "42 != 'foo' --> true"); Variant v14 = v1 != v4; t.is (v04.type (), Variant::type_boolean, "42 != 1234567890 --> boolean"); t.is (v04.get_bool (), true, "42 != 1234567890 --> true"); Variant v15 = v1 != v5; t.is (v15.type (), Variant::type_boolean, "42 != 1200 --> boolean"); t.is (v15.get_bool (), true, "42 != 1200 --> true"); Variant v20 = v2 != v0; t.is (v20.type (), Variant::type_boolean, "3.14 != true --> boolean"); t.is (v20.get_bool (), true, "3.14 != true --> true"); Variant v21 = v2 != v1; t.is (v21.type (), Variant::type_boolean, "3.14 != 42 --> boolean"); t.is (v21.get_bool (), true, "3.14 != 42 --> true"); Variant v22 = v2 != v2; t.is (v22.type (), Variant::type_boolean, "3.14 != 3.14 --> boolean"); t.is (v22.get_bool (), false, "3.14 != 3.14 --> false"); Variant v23 = v2 != v3; t.is (v23.type (), Variant::type_boolean, "3.14 != 'foo' --> boolean"); t.is (v23.get_bool (), true, "3.14 != 'foo' --> true"); Variant v24 = v2 != v4; t.is (v24.type (), Variant::type_boolean, "3.14 != 1234567890 --> boolean"); t.is (v24.get_bool (), true, "3.14 != 1234567890 --> true"); Variant v25 = v2 != v5; t.is (v25.type (), Variant::type_boolean, "3.14 != 1200 --> boolean"); t.is (v25.get_bool (), true, "3.14 != 1200 --> true"); Variant v30 = v3 != v0; t.is (v30.type (), Variant::type_boolean, "'foo' != true --> boolean"); t.is (v30.get_bool (), true, "'foo' != true --> true"); Variant v31 = v3 != v1; t.is (v31.type (), Variant::type_boolean, "'foo' != 42 --> boolean"); t.is (v31.get_bool (), true, "'foo' != 42 --> true"); Variant v32 = v3 != v2; t.is (v32.type (), Variant::type_boolean, "'foo' != 3.14 --> boolean"); t.is (v32.get_bool (), true, "'foo' != 3.14 --> true"); Variant v33 = v3 != v3; t.is (v33.type (), Variant::type_boolean, "'foo' != 'foo' --> boolean"); t.is (v33.get_bool (), false, "'foo' != 'foo' --> false"); Variant v34 = v3 != v4;//.........这里部分代码省略.........
开发者ID:austinwagner,项目名称:task,代码行数:101,
示例20: integer_type_teststemplate<typename MatrixType> void integer_type_tests(const MatrixType& m){ typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; VERIFY(NumTraits<Scalar>::IsInteger); enum { is_signed = (Scalar(-1) > Scalar(0)) ? 0 : 1 }; VERIFY(int(NumTraits<Scalar>::IsSigned) == is_signed); typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; Index rows = m.rows(); Index cols = m.cols(); // this test relies a lot on Random.h, and there's not much more that we can do // to test it, hence I consider that we will have tested Random.h MatrixType m1(rows, cols), m2 = MatrixType::Random(rows, cols), m3(rows, cols), mzero = MatrixType::Zero(rows, cols); typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType; SquareMatrixType identity = SquareMatrixType::Identity(rows, rows), square = SquareMatrixType::Random(rows, rows); VectorType v1(rows), v2 = VectorType::Random(rows), vzero = VectorType::Zero(rows); do { m1 = MatrixType::Random(rows, cols); } while(m1 == mzero || m1 == m2); do { v1 = VectorType::Random(rows); } while(v1 == vzero || v1 == v2); VERIFY_IS_APPROX( v1, v1); VERIFY_IS_NOT_APPROX( v1, 2*v1); VERIFY_IS_APPROX( vzero, v1-v1); VERIFY_IS_APPROX( m1, m1); VERIFY_IS_NOT_APPROX( m1, 2*m1); VERIFY_IS_APPROX( mzero, m1-m1); VERIFY_IS_APPROX(m3 = m1,m1); MatrixType m4; VERIFY_IS_APPROX(m4 = m1,m1); m3.real() = m1.real(); VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), static_cast<const MatrixType&>(m1).real()); VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), m1.real()); // check == / != operators VERIFY(m1==m1); VERIFY(m1!=m2); VERIFY(!(m1==m2)); VERIFY(!(m1!=m1)); m1 = m2; VERIFY(m1==m2); VERIFY(!(m1!=m2)); // check linear structure Scalar s1; do { s1 = internal::random<Scalar>(); } while(s1 == 0); VERIFY_IS_EQUAL(m1+m1, 2*m1); VERIFY_IS_EQUAL(m1+m2-m1, m2); VERIFY_IS_EQUAL(m1*s1, s1*m1); VERIFY_IS_EQUAL((m1+m2)*s1, s1*m1+s1*m2); m3 = m2; m3 += m1; VERIFY_IS_EQUAL(m3, m1+m2); m3 = m2; m3 -= m1; VERIFY_IS_EQUAL(m3, m2-m1); m3 = m2; m3 *= s1; VERIFY_IS_EQUAL(m3, s1*m2); // check matrix product. VERIFY_IS_APPROX(identity * m1, m1); VERIFY_IS_APPROX(square * (m1 + m2), square * m1 + square * m2); VERIFY_IS_APPROX((m1 + m2).transpose() * square, m1.transpose() * square + m2.transpose() * square); VERIFY_IS_APPROX((m1 * m2.transpose()) * m1, m1 * (m2.transpose() * m1));}
开发者ID:151706061,项目名称:ParaView,代码行数:85,
示例21: memcpy//! Creates a normal map from a height map texture.//! /param amplitude: Constant value by which the height information is multiplied.void CNullDriver::makeNormalMapTexture(ITexture* texture, f32 amplitude) const{ if (!texture) return; if (texture->getColorFormat() != ECF_A1R5G5B5 && texture->getColorFormat() != ECF_A8R8G8B8 ) { Printer::log("Error: Unsupported texture color format for making normal map.", ELL_ERROR); return; } dimension2d<u32> dim = texture->getSize(); amplitude = amplitude / 255.0f; f32 vh = dim.Height / (f32)dim.Width; f32 hh = dim.Width / (f32)dim.Height; if (texture->getColorFormat() == ECF_A8R8G8B8) { // ECF_A8R8G8B8 version s32 *p = (s32*)texture->lock(); if (!p) { Printer::log("Could not lock texture for making normal map.", ELL_ERROR); return; } // copy texture u32 pitch = texture->getPitch() / 4; s32* in = new s32[dim.Height * pitch]; memcpy(in, p, dim.Height * pitch * 4); for (s32 x=0; x < s32(pitch); ++x) for (s32 y=0; y < s32(dim.Height); ++y) { // TODO: this could be optimized really a lot vector3df h1((x-1)*hh, nml32(x-1, y, pitch, dim.Height, in)*amplitude, y*vh); vector3df h2((x+1)*hh, nml32(x+1, y, pitch, dim.Height, in)*amplitude, y*vh); //vector3df v1(x*hh, nml32(x, y-1, pitch, dim.Height, in)*amplitude, (y-1)*vh); //vector3df v2(x*hh, nml32(x, y+1, pitch, dim.Height, in)*amplitude, (y+1)*vh); vector3df v1(x*hh, nml32(x, y+1, pitch, dim.Height, in)*amplitude, (y-1)*vh); vector3df v2(x*hh, nml32(x, y-1, pitch, dim.Height, in)*amplitude, (y+1)*vh); vector3df v = v1-v2; vector3df h = h1-h2; vector3df n = v.crossProduct(h); n.normalize(); n *= 0.5f; n += vector3df(0.5f,0.5f,0.5f); // now between 0 and 1 n *= 255.0f; s32 height = (s32)nml32(x, y, pitch, dim.Height, in); p[y*pitch + x] = SColor( height, // store height in alpha (s32)n.X, (s32)n.Z, (s32)n.Y).color; } delete [] in; texture->unlock(); } else { // ECF_A1R5G5B5 version s16 *p = (s16*)texture->lock(); if (!p) { Printer::log("Could not lock texture for making normal map.", ELL_ERROR); return; } u32 pitch = texture->getPitch() / 2; // copy texture s16* in = new s16[dim.Height * pitch]; memcpy(in, p, dim.Height * pitch * 2); for (s32 x=0; x < s32(pitch); ++x) for (s32 y=0; y < s32(dim.Height); ++y) { // TODO: this could be optimized really a lot vector3df h1((x-1)*hh, nml16(x-1, y, pitch, dim.Height, in)*amplitude, y*vh); vector3df h2((x+1)*hh, nml16(x+1, y, pitch, dim.Height, in)*amplitude, y*vh); vector3df v1(x*hh, nml16(x, y-1, pitch, dim.Height, in)*amplitude, (y-1)*vh); vector3df v2(x*hh, nml16(x, y+1, pitch, dim.Height, in)*amplitude, (y+1)*vh); vector3df v = v1-v2; vector3df h = h1-h2;//.........这里部分代码省略.........
开发者ID:ChangerR,项目名称:dream,代码行数:101,
示例22: mainint main() { { miyabi::type_traits::dump< Foo >( std::cout ); std::cout << std::endl; miyabi::type_traits::dump< miyabi::ContainerFacade< Foo > >( std::cout ); std::cout << std::endl; miyabi::type_traits::dump< boost::array< float, 4 > >( std::cout ); } { miyabi::math::Vector< std::vector< float > > a( 3 ); a[ 0 ] = 3; a[ 1 ] = 4; a[ 2 ] = 5; miyabi::math::Vector< std::vector< float > > b( 4 ); b[ 0 ] = 0; b[ 1 ] = 3; b[ 2 ] = 6; b[ 3 ] = 9; miyabi::math::Vector< std::map< int, float > > c; c[ 0 ] = 1; c[ 3 ] = 2; c[ 7 ] = 3; c[ 9 ] = 4; miyabi::math::Vector< std::map< int, float > > d; d[ 0 ] = 1; d[ 2 ] = 4; d[ 3 ] = 8; d[ 5 ] = 12; miyabi::math::Vector< std::map< int, float > > result3 = c + d; std::cout << result3 << std::endl; c += d; std::cout << c[ 0 ] << " " << c[ 1 ] << " " << c[ 2 ] << " " << c[ 3 ] << " "; std::cout << c[ 4 ] << " " << c[ 5 ] << " " << c[ 6 ] << " " << c[ 7 ] << " "; std::cout << c[ 8 ] << " " << c[ 9 ] << " " << c[ 10 ] << " " << c[ 11 ] << std::endl; c += a; std::cout << c[ 0 ] << " " << c[ 1 ] << " " << c[ 2 ] << " " << c[ 3 ] << " "; std::cout << c[ 4 ] << " " << c[ 5 ] << " " << c[ 6 ] << " " << c[ 7 ] << " "; std::cout << c[ 8 ] << " " << c[ 9 ] << " " << c[ 10 ] << " " << c[ 11 ] << std::endl; miyabi::math::Vector< std::map< int, float > > da; da[ 0 ] = 1; miyabi::math::Vector< std::map< int, float > > db; db[ 2 ] = 1; std::cout << dot( da, da ) << std::endl; std::cout << dot( da, db ) << std::endl; miyabi::math::Vector< std::vector< float > > result = a + b; std::cout << &result.getBase() << std::endl; std::cout << result.size() << " " << result[ 1 ] << " " << result[ 2 ] << " " << result[ 3 ] << std::endl; miyabi::math::Vector< std::vector< float > > result2 = b - a; std::cout << result2[ 0 ] << " " << result2[ 1 ] << " " << result2[ 2 ] << " " << result2[ 3 ] << std::endl; miyabi::math::Vector< std::map< int, miyabi::math::Vector< std::map< int, float > > > > matrix; matrix[ 5 ][ 2 ] = 1; std::cout << matrix << std::endl; miyabi::math::outer_return_vector< miyabi::math::Vector< std::vector< float > >, miyabi::math::Vector< std::vector< float > > >::type ext_result = a * b; std::cout << ext_result << std::endl; miyabi::math::Vector< std::map< int, float > > foo; foo[ 90 ] = 1; foo[ 2048 ] = 1; std::cout << length( foo ) << std::endl; } { miyabi::math::Vector< std::map< int, float > > v1;v1[ 1 ]=1; miyabi::math::Vector< std::map< int, float > > v2;v2[ 0 ]=1; miyabi::math::Vector< std::map< int, float > > v3; std::cout << triangleArea( v1, v2, v3 ) << std::endl; miyabi::math::Vector< std::map< int, miyabi::math::Vector< std::map< int, float > > > > matrix2; for( int row = 0; row != 10; ++row ) for( int col = 0; col != 10; ++col ) matrix2.getValue( rand() % 16 ).getValue( rand() % 16 ) = rand() % 256; miyabi::math::Vector< std::vector< float > > log; for( int row = 0; row != 16; ++row ) log.getValue( row ) = row; std::cout << log << std::endl; std::cout << matrix2 << std::endl; lu( matrix2, log ); std::cout << matrix2 << std::endl; std::cout << log << std::endl; } { miyabi::math::Vector< std::map< int, miyabi::math::Vector< std::map< int, float > > > > mx; mx[0][0]=1;mx[0][1]=4;mx[0][2]=3;mx[0][3]=8; mx[1][1]=2;mx[1][2]=5;mx[1][3]=1; mx[2][0]=9;mx[2][1]=3; mx[3][0]=5; mx[3][2]=1;mx[3][3]=1; std::cout << inverse( mx ) << std::endl; std::cout << mx << std::endl; } { miyabi::math::Vector< std::vector< float > > v1( 3 ); v1[ 0 ] = 1.0f; v1[ 1 ] = 0.0f; v1[ 2 ] = 0.0f;//.........这里部分代码省略.........
开发者ID:Fadis,项目名称:miyabi,代码行数:101,
示例23: sqrtvoid CIcosahedron::init( float s ){ this->clearMesh(); float p = ((1.0 + sqrt(5.0))/2.0)*s; TVector3 v0(s,0.0,p); this->iVertices.push_back(v0); TVector3 v1(-s,0.0,p); this->iVertices.push_back(v1); TVector3 v2(s,0.0,-p); this->iVertices.push_back(v2); TVector3 v3(-s,0.0,-p); this->iVertices.push_back(v3); TVector3 v4(0.0,p,s); this->iVertices.push_back(v4); TVector3 v5(0,-p,s); this->iVertices.push_back(v5); TVector3 v6(0,p,-s); this->iVertices.push_back(v6); TVector3 v7(0.0,-p,-s); this->iVertices.push_back(v7); TVector3 v8(p,s,0.0); this->iVertices.push_back(v8); TVector3 v9(-p,s,0.0); this->iVertices.push_back(v9); TVector3 v10(p,-s,0.0); this->iVertices.push_back(v10); TVector3 v11(-p,-s,0.0); this->iVertices.push_back(v11); TTriangle t0(0,4,1); this->iTriangles.push_back(t0); TTriangle t1(0,1,5); this->iTriangles.push_back(t1); TTriangle t2(0,5,10); this->iTriangles.push_back(t2); TTriangle t3(0,10,8); this->iTriangles.push_back(t3); TTriangle t4(0,8,4); this->iTriangles.push_back(t4); TTriangle t5(4,8,6); this->iTriangles.push_back(t5); TTriangle t6(4,6,9); this->iTriangles.push_back(t6); TTriangle t7(4,9,1); this->iTriangles.push_back(t7); TTriangle t8(1,9,11); this->iTriangles.push_back(t8); TTriangle t9(1,11,5); this->iTriangles.push_back(t9); TTriangle t10(2,7,3); this->iTriangles.push_back(t10); TTriangle t11(2,3,6); this->iTriangles.push_back(t11); TTriangle t12(2,6,8); this->iTriangles.push_back(t12); TTriangle t13(2,8,10); this->iTriangles.push_back(t13); TTriangle t14(2,10,7); this->iTriangles.push_back(t14); TTriangle t15(7,10,5); this->iTriangles.push_back(t15); TTriangle t16(7,5,11); this->iTriangles.push_back(t16); TTriangle t17(7,11,3); this->iTriangles.push_back(t17); TTriangle t18(3,11,9); this->iTriangles.push_back(t18); TTriangle t19(3,9,6); this->iTriangles.push_back(t19); }
开发者ID:rroc,项目名称:rtdof,代码行数:91,
示例24: onEmitCode void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { const PLSAATriangleEffect& te = args.fGP.cast<PLSAATriangleEffect>(); GrGLSLVertexBuilder* vsBuilder = args.fVertBuilder; GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; varyingHandler->emitAttributes(te); this->setupPosition(vsBuilder, gpArgs, te.inPosition()->fName); GrGLSLVertToFrag v1(kVec2f_GrSLType); varyingHandler->addVarying("Vertex1", &v1, kHigh_GrSLPrecision); vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", v1.vsOut(), te.inVertex1()->fName, te.inVertex1()->fName); GrGLSLVertToFrag v2(kVec2f_GrSLType); varyingHandler->addVarying("Vertex2", &v2, kHigh_GrSLPrecision); vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", v2.vsOut(), te.inVertex2()->fName, te.inVertex2()->fName); GrGLSLVertToFrag v3(kVec2f_GrSLType); varyingHandler->addVarying("Vertex3", &v3, kHigh_GrSLPrecision); vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", v3.vsOut(), te.inVertex3()->fName, te.inVertex3()->fName); GrGLSLVertToFrag delta1(kVec2f_GrSLType); varyingHandler->addVarying("delta1", &delta1, kHigh_GrSLPrecision); vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;", delta1.vsOut(), v1.vsOut(), v2.vsOut(), v2.vsOut(), v1.vsOut()); GrGLSLVertToFrag delta2(kVec2f_GrSLType); varyingHandler->addVarying("delta2", &delta2, kHigh_GrSLPrecision); vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;", delta2.vsOut(), v2.vsOut(), v3.vsOut(), v3.vsOut(), v2.vsOut()); GrGLSLVertToFrag delta3(kVec2f_GrSLType); varyingHandler->addVarying("delta3", &delta3, kHigh_GrSLPrecision); vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;", delta3.vsOut(), v3.vsOut(), v1.vsOut(), v1.vsOut(), v3.vsOut()); GrGLSLVertToFrag windings(kInt_GrSLType); varyingHandler->addFlatVarying("windings", &windings, kLow_GrSLPrecision); vsBuilder->codeAppendf("%s = %s;", windings.vsOut(), te.inWindings()->fName); // emit transforms this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpArgs->fPositionVar, te.inPosition()->fName, te.localMatrix(), args.fTransformsIn, args.fTransformsOut); GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder; SkAssertResult(fsBuilder->enableFeature( GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLFeature)); SkAssertResult(fsBuilder->enableFeature( GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL); // Compute four subsamples, each shifted a quarter pixel along x and y from // gl_FragCoord. The oriented box positioning of the subsamples is of course not // optimal, but it greatly simplifies the math and this simplification is necessary for // performance reasons. fsBuilder->codeAppendf("highp vec2 firstSample = %s.xy - vec2(0.25);", fsBuilder->fragmentPosition()); fsBuilder->codeAppendf("highp vec2 delta1 = %s;", delta1.fsIn()); fsBuilder->codeAppendf("highp vec2 delta2 = %s;", delta2.fsIn()); fsBuilder->codeAppendf("highp vec2 delta3 = %s;", delta3.fsIn()); // Check whether first sample is inside the triangle by computing three dot products. If // all are < 0, we're inside. The first vector in each case is half of what it is // "supposed" to be, because we re-use them later as adjustment factors for which half // is the correct value, so we multiply the dots by two to compensate. fsBuilder->codeAppendf("highp float d1 = dot(delta1, (firstSample - %s).yx) * 2.0;", v1.fsIn()); fsBuilder->codeAppendf("highp float d2 = dot(delta2, (firstSample - %s).yx) * 2.0;", v2.fsIn()); fsBuilder->codeAppendf("highp float d3 = dot(delta3, (firstSample - %s).yx) * 2.0;", v3.fsIn()); fsBuilder->codeAppend("highp float dmax = max(d1, max(d2, d3));"); fsBuilder->codeAppendf("pls.windings[0] += (dmax <= 0.0) ? %s : 0;", windings.fsIn()); // for subsequent samples, we don't recalculate the entire dot product -- just adjust it // to the value it would have if we did recompute it. fsBuilder->codeAppend("d1 += delta1.x;"); fsBuilder->codeAppend("d2 += delta2.x;"); fsBuilder->codeAppend("d3 += delta3.x;"); fsBuilder->codeAppend("dmax = max(d1, max(d2, d3));"); fsBuilder->codeAppendf("pls.windings[1] += (dmax <= 0.0) ? %s : 0;", windings.fsIn()); fsBuilder->codeAppend("d1 += delta1.y;"); fsBuilder->codeAppend("d2 += delta2.y;"); fsBuilder->codeAppend("d3 += delta3.y;"); fsBuilder->codeAppend("dmax = max(d1, max(d2, d3));"); fsBuilder->codeAppendf("pls.windings[2] += (dmax <= 0.0) ? %s : 0;", windings.fsIn()); fsBuilder->codeAppend("d1 -= delta1.x;"); fsBuilder->codeAppend("d2 -= delta2.x;"); fsBuilder->codeAppend("d3 -= delta3.x;"); fsBuilder->codeAppend("dmax = max(d1, max(d2, d3));"); fsBuilder->codeAppendf("pls.windings[3] += (dmax <= 0.0) ? %s : 0;", windings.fsIn());//.........这里部分代码省略.........
开发者ID:C-Tillion,项目名称:skia,代码行数:101,
示例25: color_interpolationColor4 color_interpolation(Color4 const& color0, Color4 const& color1, float t) { Vector3 v0(color0[0]/255.0f, color0[1]/255.0f, color0[2]/255.0f); Vector3 v1(color1[0]/255.0f, color1[1]/255.0f, color1[2]/255.0f); Vector3 r = linear_interpolation(v0, v1, t); return Color4(r[0]*255.0f, r[1]*255.0f, r[2]*255.0f, 255);}
开发者ID:knied,项目名称:LD29,代码行数:6,
注:本文中的v1函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ v2f函数代码示例 C++ v函数代码示例 |