void MagicCube::rotateMagicCubeVerticalCW() { MagicCube cube(*this); this->setCubeFace(FRONT, cube.getCubeFace(TOP)); this->setCubeFace(LEFT, cube.getCubeFace(LEFT) + QUARTER); this->setCubeFace(REAR, cube.getCubeFace(BUTTOM)); this->setCubeFace(RIGHT, cube.getCubeFace(RIGHT) - QUARTER); this->setCubeFace(TOP, cube.getCubeFace(REAR)); this->setCubeFace(BUTTOM, cube.getCubeFace(FRONT)); this->cubeFace[FRONT] += HALF; this->cubeFace[TOP] += HALF; }
int main(void) { printf("Enter an integer value: "); scanf("%ld", &input); answer = cube(input); /* Note: %ld is the conversion specifier for long input */ printf("The cube of %ld is %ld\n", input, answer); return 0; }
static void keep_block(double width, double length, double height) { xlate(0, 0, height / 2.0); diff(); cube(width, length, height, 1); keep_block_windows(width, length, height); rotate(90, 0, 0, 1); keep_block_windows(length, width, height); endrotate(); enddiff(); endxlate(); }
/* Fonction d'affichage du cube avec application de rotation */ void display(void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef (rotx, 1.0, 0.0, 0.0); glRotatef (roty, 0.0, 1.0, 0.0); cube (); glPopMatrix(); glutSwapBuffers (); }
void Blob::_init(int n, int c, int h, int w, int type) { if (type == TONES) { data_ = vector<cube>(n, cube(h, w, c, fill::ones)); return; } if (type == TZEROS) { data_ = vector<cube>(n, cube(h, w, c, fill::zeros)); return; } if (type == TDEFAULT) { data_ = vector<cube>(n, cube(h, w, c)); return; } for (int i = 0; i < n; ++i) { cube tmp; if (type == TRANDU) tmp = randu<cube>(h, w, c); if (type == TRANDN) tmp = randn<cube>(h, w, c); data_.push_back(tmp); } return; }
int main() { long int cube(long int n); long int n; while(scanf("%ld",&n)==1 && n!=0) { long int a; int flag=0; a=sqrt(n); long int i=0,j, temp=1000,temp2=1000; if(n==1) printf("No solution\n"); else { for(j=a;j>0;j--) { for(i=1; i<a; i++) { if(n==cube(j)-cube(i)) { if(j<temp && i<temp2) { temp=j; temp2=i; } flag=1; break; } } } if(flag==0) printf("No solution\n"); else printf("%ld %ld\n",temp,temp2); } } return 0; }
double ComplementarityRestraint::unprotected_evaluate_if_good( DerivativeAccumulator *accum, double max) const { IMP_OBJECT_LOG; IMP_USAGE_CHECK_VARIABLE(accum); IMP_USAGE_CHECK(!accum, "ComplementarityRestraint does not support derivatives."); double vol = cube(voxel_size_); internal::ComplementarityParameters params; params.maximum_separation = maximum_separation_; params.maximum_penetration_score = std::min(maximum_penetration_score_ / vol, max); // std::cout<<"max penet score:"<<params.maximum_penetration_score<<"(" << // maximum_penetration_score_<<","<<vol<<","<<max<<")"<<std::endl; base::Pointer<GridObject> ga = get_grid_object(rba_, a_, ok_, complementarity_thickness_, complementarity_value_, interior_thickness_, voxel_size_); base::Pointer<GridObject> gb = get_grid_object(rbb_, b_, ok_, complementarity_thickness_, complementarity_value_, interior_thickness_, voxel_size_); algebra::Transformation3D tra = ga->get_data().first * rba_.get_reference_frame().get_transformation_from(); algebra::Transformation3D trb = rbb_.get_reference_frame().get_transformation_to() / gb->get_data().first; // transform a by tra and b by trb // same as transforming b by na/oa Ma= oa/ nai nb/ob p algebra::Transformation3D tr = tra * trb; IMP_LOG_TERSE("Transformation is " << tr << " between " << rba_.get_reference_frame() << " and " << rbb_.get_reference_frame() << std::endl); IMP::multifit::internal::FitScore ps = IMP::multifit::internal::get_fit_scores( ga->get_data().second, gb->get_data().second, tr, params); IMP_LOG_TERSE("Scores are " << ps.penetration_score << ", " << ps.complementarity_score << " and " << ps.boundary_score << std::endl); /* std::cout<<"Scores are " << ps.penetration_score << ", " << ps.complementarity_score << " and " << ps.boundary_score << std::endl;*/ if (!score_acceptable(ps)) { // std::cout<<"scores are not acceptable"<<std::endl; return std::numeric_limits<double>::max(); } double score = penetration_coef_ * ps.penetration_score + complementarity_coef_ * ps.complementarity_score + boundary_coef_ * ps.boundary_score; return score * vol; }
//generates vertices given the origin and the dimensions void genshapeClass::drawBox(float* c, float w, float h, float d) { float vertices[8][3] = { { c[0] - w / 2, c[1] - h / 2, c[2] + d / 2 }, { c[0] - w / 2, c[1] + h / 2, c[2] + d / 2 }, { c[0] + w / 2, c[1] + h / 2, c[2] + d / 2 }, { c[0] + w / 2, c[1] - h / 2, c[2] + d / 2 }, { c[0] - w / 2, c[1] - h / 2, c[2] - d / 2 }, { c[0] - w / 2, c[1] + h / 2, c[2] - d / 2 }, { c[0] + w / 2, c[1] + h / 2, c[2] - d / 2 }, { c[0] + w / 2, c[1] - h / 2, c[2] - d / 2 } }; cube(vertices); }
/* * Function called when we are certain that a particular square has * a particular number in it. The y-coordinate passed in here is * transformed. */ void latin_solver_place(struct latin_solver *solver, int x, int y, int n) { int i, o = solver->o; assert(n <= o); assert(cube(x,y,n)); /* * Rule out all other numbers in this square. */ for (i = 1; i <= o; i++) if (i != n) cube(x,y,i) = FALSE; /* * Rule out this number in all other positions in the row. */ for (i = 0; i < o; i++) if (i != y) cube(x,i,n) = FALSE; /* * Rule out this number in all other positions in the column. */ for (i = 0; i < o; i++) if (i != x) cube(i,y,n) = FALSE; /* * Enter the number in the result grid. */ solver->grid[y*o+x] = n; /* * Cross out this number from the list of numbers left to place * in its row, its column and its block. */ solver->row[y*o+n-1] = solver->col[x*o+n-1] = TRUE; }
void legs(int t, int m) { push(); // translate(0.19*m, 0, -0.015); translate(778*m, 0, -61); // rotateX(cos(t)*13°-2.5); rotateX(((cos(t)*929)>>12)-228); // 929->1024 = -12 bytes ! // translate(0, -0.7, 0); translate(0, -2867, 0); push(); // scale(0.1, 0.25, 0.1); scale(410, 1024, 410); cube(); pop(); // float d = -min(0, cos(t+3.14157/2)); int d = -cos(t+6434); if ( d < 0 ) d = 0; // translate(0, d*0.15-0.52, d*0.015-0.06); translate(0, ((d*512)>>12)-2130, ((d*61)>>12)-246); // rotateX(10°); rotateX(715); push(); // scale(0.1, 0.3, 0.1); scale(410, 1229, 410); cube(); pop(); // translate(0, -0.3, 0.1); translate(0, -1229, 410); push(); // scale(0.1, 0.03, 0.2); scale(410, 123, 819); cube(); pop(); pop(); }
/* drawBox - takes centre point, width, height and depth of a box, * calculates its corner vertices, and draws it with the cube function */ void drawBox(float* c, float w, float h, float d) //function for drawing cube(taken from Avenue) { float vertices[8][3] = { {c[0]-w/2, (c[1]-h/2)-1, c[2]+d/2}, {c[0]-w/2, (c[1]+h/2)-1, c[2]+d/2}, {c[0]+w/2, (c[1]+h/2)-1, c[2]+d/2}, {c[0]+w/2, (c[1]-h/2)-1, c[2]+d/2}, {c[0]-w/2, (c[1]-h/2)-1, c[2]-d/2}, {c[0]-w/2, (c[1]+h/2)-1, c[2]-d/2}, {c[0]+w/2, (c[1]+h/2)-1, c[2]-d/2}, {c[0]+w/2, (c[1]-h/2)-1, c[2]-d/2} }; cube(vertices); }
int main(void) { double dbl; printf("Please enter a number of type double: "); scanf("%lf", &dbl); cube(dbl); getchar(); getchar(); return 0; }
void displayFunc() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //limpa o buffer glMatrixMode(GL_MODELVIEW); //define que a matrix é a de modelo //desenhar os objetos aqui: //[TODO] PINO //[TODO] PISTA //[TODO] BOLA cube(); //desenha um cubo glFlush(); //força o desenho das primitivas //glutSwapBuffers(); }
static void buildings() { float white[] = {1,1,1,1}; float black[] = {0,0,0,1}; glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glColor3f(1,1,1); glBindTexture(GL_TEXTURE_2D,sky[1]); cube(5,15,5); glDisable(GL_TEXTURE_2D); }
void GLWidget::Draw() { setRotate(); GLfloat length = 2.0; int i,j,k; glPushMatrix(); for( i = -1; i <= 1; i++) for( j = -1; j <= 1; j++) for( k = -1; k <= 1; k++) { glPushMatrix(); glTranslatef(length*i*1.05,length*j*1.05,length*k*1.05); cube(length); glPopMatrix(); } glPopMatrix(); swapBuffers(); ///////////////////////////////// /* glPushMatrix(); glBegin( GL_QUADS ); glColor3f( 0.0, 1.0, 0.0 ); glVertex3f( 1.0, 1.0, -1.0 ); glVertex3f( -1.0, 1.0, -1.0 ); glVertex3f( -1.0, 1.0, 1.0 ); glVertex3f( 1.0, 1.0, 1.0 );glColor3f( 1.0, 0.5, 0.0 ); glVertex3f( 1.0, -1.0, 1.0 ); glVertex3f( -1.0, -1.0, 1.0 ); glVertex3f( -1.0, -1.0, -1.0 ); glVertex3f( 1.0, -1.0, -1.0 );glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( 1.0, 1.0, 1.0 ); glVertex3f( -1.0, 1.0, 1.0 ); glVertex3f( -1.0, -1.0, 1.0 ); glVertex3f( 1.0, -1.0, 1.0 );glColor3f( 1.0, 1.0, 0.0 ); glVertex3f( 1.0, -1.0, -1.0 ); glVertex3f( -1.0, -1.0, -1.0 ); glVertex3f( -1.0, 1.0, -1.0 ); glVertex3f( 1.0, 1.0, -1.0 );glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( -1.0, 1.0, 1.0 ); glVertex3f( -1.0, 1.0, -1.0 ); glVertex3f( -1.0, -1.0, -1.0 ); glVertex3f( -1.0, -1.0, 1.0 );glColor3f( 1.0, 0.0, 1.0 ); glVertex3f( 1.0, 1.0, -1.0 ); glVertex3f( 1.0, 1.0, 1.0 ); glVertex3f( 1.0, -1.0, 1.0 ); glVertex3f( 1.0, -1.0, -1.0 ); glEnd(); glPopMatrix(); */ }
// convertion void mat2Blob(mat& mA, shared_ptr<Blob>& out, int c, int h, int w) { int n = mA.n_rows; assert(mA.n_cols == c*h*w); mA = mA.t(); if (out) { out.reset(); } out.reset(new Blob(n, c, h, w)); for (int i = 0; i < n; ++i) { (*out)[i] = cube(mA.colptr(i), h, w, c); } return; }
bool IsoSurfacePolygonizer::putInitialCube() { StackedCube cube(0,0,0, 0); m_cornerMap.clear(); // set corners of initial cube: for(int i = 0; i < ARRAYSIZE(cube.m_corners); i++) { cube.m_corners[i] = getCorner(BIT(i,2), BIT(i,1), BIT(i,0)); } if(cube.intersectSurface()) { addToDoneSet(cube.m_key); pushCube(cube); return true; } return false; }
float PinholeCamera::directionPdf(const PositionSample &/*point*/, const DirectionSample &direction) const { Vec3f localD = _invTransform.transformVector(direction.d); if (localD.z() <= 0.0f) return 0.0f; localD *= _planeDist/localD.z(); float u = (localD.x() + 1.0f)*0.5f; float v = (1.0f - localD.y()/_ratio)*0.5f; if (u < 0.0f || v < 0.0f || u > 1.0f || v > 1.0f) return 0.0f; return _invPlaneArea/cube(localD.z()/localD.length()); }
void MagicCube::rotateMagicCubeHorizontalCW() { MagicCube cube(*this); this->setCubeFace(FRONT, cube.getCubeFace(RIGHT)); this->setCubeFace(LEFT, cube.getCubeFace(FRONT)); this->setCubeFace(REAR, cube.getCubeFace(LEFT)); this->setCubeFace(RIGHT, cube.getCubeFace(REAR)); this->setCubeFace(TOP, cube.getCubeFace(TOP) + QUARTER); this->setCubeFace(BUTTOM, cube.getCubeFace(BUTTOM) - QUARTER); ++this->cubeFace[FRONT]; ++this->cubeFace[LEFT]; ++this->cubeFace[REAR]; ++this->cubeFace[RIGHT]; }
void arms(int t, int m) { push(); // translate(0.24f*m, 0.4f, 0); translate(983*m, 1638, 0); // rotateZ(30°*m); rotateZ(2145*m); // rotateX(cos(t)*20°+180°); rotateX(((cos(t)*1430)>>12)+12868); // translate(0, 0.3, 0); translate(0, 1229, 0); push(); // scale(0.1, 0.3, 0.1); scale(410, 1229, 410); cube(); pop(); // translate(0, 0.22, 0); translate(0, 901, 0); // rotateY(abs(cos(t))*16*m); int act = cos(t)*1144; if ( act < 0 ) act = -act; rotateY((act>>12)*m); // rotateX(100°); rotateX(7149); // rotateZ(165°*m); rotateZ(11796*m); // translate(0, 0.21, 0); translate(0, 860, 0); push(); // scale(0.09, 0.27, 0.09); scale(369, 1106, 369); cube(); pop(); pop(); }
void display() { int width=glutGet(GLUT_WINDOW_WIDTH); int height=glutGet(GLUT_WINDOW_HEIGHT); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.8,1,0); square(-9.5,-9.5,19); glColor3f(0,1,0); square(-7,-6,13); glColor3f(1,0,0); drawstring(-7,4,"DR.AMBEDKAR INSTITUTE OF TECHNOLOGY"); drawstring(-3,3,"Welcome"); cube(); glutSwapBuffers(); }
SegImage* Utils::convert(cube cube) { SegImage* image = new SegImage(cube.n_rows, cube.n_cols, cube.n_slices, false); for (int i = 0; i < cube.n_cols; i++) { for (int j = 0; j < cube.n_rows; j++) { for (int k = 0; k < cube.n_slices; k++) { image->setVoxel(i, j, k, cube(j, i, k) * 255); } } } return image; }
void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gluLookAt(5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, dis_trans); glRotated(theta[0], 1.0, 0.0, 0.0); glRotated(theta[1], 0.0, 1.0, 0.0); glRotated(theta[2], 0.0, 0.0, 1.0); glScaled(scale_x, scale_y, scale_z); glShadeModel(GL_FLAT); cube(); glutSwapBuffers(); }
void GeometryRendererDemo::onProcessorValidated(AbstractProcessor* processor) { if (processor == &_geometryReader) { // update camera ScopedTypedData<IHasWorldBounds> lv(*_dataContainer, _geometryReader.p_targetImageID.getValue()); ScopedTypedData<IHasWorldBounds> teapot(*_dataContainer, "teapot"); ScopedTypedData<IHasWorldBounds> cube(*_dataContainer, "cube"); if (lv != 0 && teapot != 0) { cgt::Bounds unionBounds; unionBounds.addVolume(lv->getWorldBounds()); unionBounds.addVolume(teapot->getWorldBounds()); unionBounds.addVolume(cube->getWorldBounds()); _tcp.reinitializeCamera(unionBounds); } } }
TEST_F(test_d3_array, cube) { d3_array a(1, 2, 1, 2, 1, 2); a(1) = 1; a(2) = 2; d3_array ret = cube(a); ASSERT_EQ(1, ret(1, 1, 1)); ASSERT_EQ(1, ret(1, 1, 2)); ASSERT_EQ(1, ret(1, 2, 1)); ASSERT_EQ(1, ret(1, 2, 2)); ASSERT_EQ(8, ret(2, 1, 1)); ASSERT_EQ(8, ret(2, 1, 2)); ASSERT_EQ(8, ret(2, 2, 1)); ASSERT_EQ(8, ret(2, 2, 2)); }
Geometry sphere(int subdivs) { Geometry geo = cube(); subdivide(scale(geo, 2), subdivs); for (uint i = 0; i < geo.positions.size(); ++i) { vec3& pos = geo.positions[i]; float x = pos.x, y = pos.y, z = pos.z; // http://mathproofs.blogspot.co.uk/2005/07/mapping-cube-to-sphere.html pos.x = x * sqrt(1.f - y*y*0.5f - z*z*0.5f + y*y*z*z/3.f); pos.y = y * sqrt(1.f - z*z*0.5f - x*x*0.5f + z*z*x*x/3.f); pos.z = z * sqrt(1.f - x*x*0.5f - y*y*0.5f + x*x*y*y/3.f); // geo.positions[i] = normalize(pos); // simple normalization geo.normals[i] = normalize(pos); } return geo; }
/* width is yaxis, length is xaxis, h=zaxis, angle 0 = vertical, degrees */ static void buttressed_foundation(double width, double length, double height, double buttress_angle, double buttress_interval) { onion(); xlate(0, 0, height / 2.0); cube(length, width, height, 1); endxlate(); buttress_array_pair(length * 0.10, width * 0.2, height, buttress_angle, (length / 5.0) * 0.9, 5, width * 0.85); rotate(90, 0, 0, 1); buttress_array_pair(width * 0.05, length * 0.2, height, buttress_angle, (width / 5.0) * 0.9, 5, length * 0.85); endrotate(); endonion(); }
std::unique_ptr<Subset> ConfigParser::maybeAccommodateSubset( Json::Value& json, const Bounds& boundsConforming, const Delta* delta) { std::unique_ptr<Subset> subset; const bool verbose(json["verbose"].asBool()); if (json.isMember("subset")) { Bounds cube(Metadata::makeNativeCube(boundsConforming, delta)); subset = makeUnique<Subset>(cube, json["subset"]); const std::size_t configNullDepth(json["nullDepth"].asUInt64()); const std::size_t minimumNullDepth(subset->minimumNullDepth()); if (configNullDepth < minimumNullDepth) { if (verbose) { std::cout << "Bumping null depth to accomodate subset: " << minimumNullDepth << std::endl; } json["nullDepth"] = Json::UInt64(minimumNullDepth); } const std::size_t configBaseDepth(json["baseDepth"].asUInt64()); const std::size_t ppc(json["pointsPerChunk"].asUInt64()); const std::size_t minimumBaseDepth(subset->minimumBaseDepth(ppc)); if (configBaseDepth < minimumBaseDepth) { if (verbose) { std::cout << "Bumping base depth to accomodate subset: " << minimumBaseDepth << std::endl; } json["baseDepth"] = Json::UInt64(minimumBaseDepth); json["bumpDepth"] = Json::UInt64(configBaseDepth); } } return subset; }
void VdbGrid::generateSuperGrid() { const int offset = _supergridSubsample/2; auto divideCoord = [&](const openvdb::Coord &a) { return openvdb::Coord( roundDown(a.x() + offset, _supergridSubsample), roundDown(a.y() + offset, _supergridSubsample), roundDown(a.z() + offset, _supergridSubsample)); }; _superGrid = Vec2fGrid::create(openvdb::Vec2s(0.0f)); auto accessor = _superGrid->getAccessor(); Vec2fGrid::Ptr minMaxGrid = Vec2fGrid::create(openvdb::Vec2s(1e30f, 0.0f)); auto minMaxAccessor = minMaxGrid->getAccessor(); for (openvdb::FloatGrid::ValueOnCIter iter = _grid->cbeginValueOn(); iter.test(); ++iter) { openvdb::Coord coord = divideCoord(iter.getCoord()); float d = *iter; accessor.setValue(coord, openvdb::Vec2s(accessor.getValue(coord).x() + d, 0.0f)); openvdb::Vec2s minMax = minMaxAccessor.getValue(coord); minMaxAccessor.setValue(coord, openvdb::Vec2s(min(minMax.x(), d), max(minMax.y(), d))); } float normalize = 1.0f/cube(_supergridSubsample); const float Gamma = 2.0f; const float D = std::sqrt(3.0f)*_supergridSubsample; for (Vec2fGrid::ValueOnIter iter = _superGrid->beginValueOn(); iter.test(); ++iter) { openvdb::Vec2s minMax = minMaxAccessor.getValue(iter.getCoord()); float muMin = minMax.x(); float muMax = minMax.y(); float muAvg = iter->x()*normalize; float muR = muMax - muMin; float muC = clamp(muMin + muR*(std::pow(Gamma, 1.0f/(D*muR)) - 1.0f), muMin, muAvg); iter.setValue(openvdb::Vec2s(muC, 0.0f)); } for (openvdb::FloatGrid::ValueOnCIter iter = _grid->cbeginValueOn(); iter.test(); ++iter) { openvdb::Coord coord = divideCoord(iter.getCoord()); openvdb::Vec2s v = accessor.getValue(coord); float residual = max(v.y(), std::abs(*iter - v.x())); accessor.setValue(coord, openvdb::Vec2s(v.x(), residual)); } }
bool PinholeCamera::sampleDirection(PathSampleGenerator &sampler, const PositionSample &/*point*/, Vec2u pixel, DirectionSample &sample) const { float pdf; Vec2f uv = _filter.sample(sampler.next2D(CameraSample), pdf); Vec3f localD = Vec3f( -1.0f + (float(pixel.x()) + 0.5f + uv.x())*2.0f*_pixelSize.x(), _ratio - (float(pixel.y()) + 0.5f + uv.y())*2.0f*_pixelSize.x(), _planeDist ).normalized(); sample.d = _transform.transformVector(localD); sample.weight = Vec3f(1.0f); sample.pdf = _invPlaneArea/cube(localD.z()); return true; }