TreeNode* flat(TreeNode *node) { if (node == nullptr) { return node; } if (node->left == nullptr && node->right == nullptr) { return node; } TreeNode *left = flat(node->left); if (left == nullptr) { node -> right = flat(node->right); } else { TreeNode *temp = left; while (temp->right != nullptr) { temp = temp->right; } temp->right = flat(node->right); node->right = left; node->left = nullptr; } return node; }
int main() { WLLC lista1 = inicjuj(); WLLC lista2 = inicjuj(); lista1 = dopisz_liczbe(5,(dopisz_liczbe(3,NULL),dopisz_liste(dopisz_liczbe(5,dopisz_liczbe(8,NULL)),dopisz_liczbe(2,dopisz_liste(dopisz_liczbe(1,dopisz_liczbe(5,NULL)),dopisz_liste(NULL,NULL)))))); lista2 = dopisz_liczbe(3,dopisz_liczbe(2,dopisz_liczbe(1,NULL))); printf("Lista 1:\n"); wypisz(lista1); printf("\n\nLista 2:\n"); wypisz(lista2); WLLC lista3 = merge(lista1,lista2); printf("\n\nLista 3:\n"); wypisz(lista3); printf("\n\nLista 1 (po mergu):\n"); wypisz(lista1); WLLC lista4 = flat(lista3); printf("\n\nLista 4 (flat z listy 3):\n"); wypisz(lista4); WLLC lista5 = inicjuj(); lista5 = dopisz_liczbe(2,dopisz_liste(dopisz_liste(dopisz_liczbe(3,dopisz_liczbe(4,NULL)),NULL),NULL)); printf("\n\nLista 5 bez flat:\n"); wypisz(lista5); printf("\n\nLista 5 z flat:\n"); wypisz(flat(lista5)); putchar('\n'); return 0; }
//takes a non-atomic list and returns a list which is the original list with the parenthesis removed..except the outer parenthesis list flat(list p) { if(is_null(p)) return null(); if(atom(p)) return cons( p, null()); return append(flat(car(p)),flat(cdr(p))); }
FRAGMENT(JSString, subclasses) { js::Rooted<JSFlatString *> flat(cx, JS_FlattenString(cx, JS_NewStringCopyZ(cx, "Hi!"))); breakpoint(); (void) flat; }
void EvtPropSLPole::decay( EvtParticle *p ){ if(! _isProbMaxSet){ EvtId parnum,mesnum,lnum,nunum; parnum = getParentId(); mesnum = getDaug(0); lnum = getDaug(1); nunum = getDaug(2); double mymaxprob = calcMaxProb(parnum,mesnum, lnum,nunum,SLPoleffmodel); setProbMax(mymaxprob); _isProbMaxSet = true; } double minKstMass = EvtPDL::getMinMass(p->getDaug(0)->getId()); double maxKstMass = EvtPDL::getMaxMass(p->getDaug(0)->getId()); EvtIntervalFlatPdf flat(minKstMass, maxKstMass); EvtPdfGen<EvtPoint1D> gen(flat); EvtPoint1D point = gen(); double massKst = point.value(); p->getDaug(0)->setMass(massKst); p->initializePhaseSpace(getNDaug(),getDaugs()); // EvtVector4R p4meson = p->getDaug(0)->getP4(); calcamp->CalcAmp(p,_amp2,SLPoleffmodel); EvtParticle *mesonPart = p->getDaug(0); double meson_BWAmp = calBreitWigner(mesonPart, point); int list[2]; list[0]=0; list[1]=0; _amp2.vertex(0,0,_amp2.getAmp(list)*meson_BWAmp); list[0]=0; list[1]=1; _amp2.vertex(0,1,_amp2.getAmp(list)*meson_BWAmp); list[0]=1; list[1]=0; _amp2.vertex(1,0,_amp2.getAmp(list)*meson_BWAmp); list[0]=1; list[1]=1; _amp2.vertex(1,1,_amp2.getAmp(list)*meson_BWAmp); list[0]=2; list[1]=0; _amp2.vertex(2,0,_amp2.getAmp(list)*meson_BWAmp); list[0]=2; list[1]=1; _amp2.vertex(2,1,_amp2.getAmp(list)*meson_BWAmp); return; }
void main() { char special; special=choice_system(); if(special=='1') hostel(); else if(special=='2') flat(); else if(special=='3') { clrscr(); gotoxy(23,12); printf("Thank you for using this program"); gotoxy(23,13); printf("Coded by: Shivam"); gotoxy(33,14); printf("Akshay"); gotoxy(33,15); printf("Aayush"); getch(); } else main(); }
FRAGMENT(JSString, subclasses) { JS::Rooted<JSFlatString*> flat( cx, JS_FlattenString(cx, JS_NewStringCopyZ(cx, "Hi!"))); breakpoint(); use(flat); }
static void sample(Point* p, Point* q) { Point rr, *r=&rr; double t = 0.45 + 0.1 * (rand()/(double) RAND_MAX); T(r) = T(p) + t*(T(q)-T(p)); gamma(r); if (flat(p,q,r)) line(p,q); else { sample(p,r); sample(r,q); } }
void contractForm::fillFlats() { if(cmbFlat->count()>0) cmbFlat->clear(); QMapIterator<int,QString> flat(db->getFlatsName()); while(flat.hasNext()){ flat.next(); cmbFlat->addItem(flat.value(),flat.key()); } }
void DBlockHeader::load(std::istream &stream, size_t blockid) { mUnknown1 = VFS::read_le32(stream); mWidth = VFS::read_le32(stream); mHeight = VFS::read_le32(stream); mObjectRootOffset = VFS::read_le32(stream); mUnknown2 = VFS::read_le32(stream); stream.read(mModelData[0].data(), sizeof(mModelData)); for(uint32_t &val : mUnknown3) val = VFS::read_le32(stream); stream.seekg(mObjectRootOffset); std::vector<int32_t> rootoffsets(mWidth*mHeight); for(int32_t &val : rootoffsets) val = VFS::read_le32(stream); for(int32_t offset : rootoffsets) { while(offset > 0) { stream.seekg(offset); int32_t next = VFS::read_le32(stream); /*int32_t prev =*/ VFS::read_le32(stream); int32_t x = VFS::read_le32(stream); int32_t y = VFS::read_le32(stream); int32_t z = VFS::read_le32(stream); uint8_t type = stream.get(); uint32_t objoffset = VFS::read_le32(stream); if(type == ObjectType_Model) { stream.seekg(objoffset); ref_ptr<ModelObject> mdl(new ModelObject(blockid|offset, x, y, z)); mdl->load(stream, mModelData); mObjects.insert(blockid|offset, mdl); } else if(type == ObjectType_Flat) { stream.seekg(objoffset); ref_ptr<FlatObject> flat(new FlatObject(blockid|offset, x, y, z)); flat->load(stream); mObjects.insert(blockid|offset, flat); } offset = next; } } for(ref_ptr<ObjectBase> &obj : mObjects) obj->loadAction(stream, *this); }
ImagePtr FlatFrameFactory::operator()(const ImageSequence& images, const ImagePtr darkimage) const { Image<double> *doubledark = dynamic_cast<Image<double>*>(&*darkimage); Image<float> *floatdark = dynamic_cast<Image<float>*>(&*darkimage); if (doubledark) { debug(LOG_DEBUG, DEBUG_LOG, 0, "dark is Image<double>"); CountNaNs<double, double> countnans; debug(LOG_DEBUG, DEBUG_LOG, 0, "dark has %f nans", countnans(*doubledark)); return flat(images, *doubledark); } if (floatdark) { debug(LOG_DEBUG, DEBUG_LOG, 0, "dark is Image<float>"); CountNaNs<float, double> countnans; debug(LOG_DEBUG, DEBUG_LOG, 0, "dark has %f nans", countnans(*floatdark)); return flat(images, *floatdark); } throw std::runtime_error("unknown dark image type"); }
// flat predicate to determine when we subdivide bool AdaptiveWaterline::flat( Fiber& start, Fiber& mid, Fiber& stop ) const { if ( start.size() != stop.size() ) // start, mid, and stop need to have same size() return false; else if ( start.size() != mid.size() ) return false; else if ( mid.size() != stop.size() ) return false; else { if (!start.empty() ) { // all now have same size assert( start.size() == stop.size() && start.size() == mid.size() ); for (unsigned int n=0;n<start.size();++n) { // now check for angles between cl-points (NOTE: cl-points might not belong to same loop?) // however, errors here only lead to dense sampling which is harmless (but slow) if ( (!flat( start.upperCLPoint(n) , mid.upperCLPoint(n) , stop.upperCLPoint(n) )) ) return false; else if (!flat( start.lowerCLPoint(n) , mid.lowerCLPoint(n) , stop.lowerCLPoint(n) )) return false; } } return true; } }
//возвращает 0, если pt вне пирамиды с вершиной в начале координат и основанием tr, 1 - внутри bool InsidePiramide(Triangle& tr,vec3 pt) { vec3 cr; if(!flat_cross_line2(flat(tr.v[0],tr.norm), pt, &cr)) return 0; for(int i=0;i<3;i++) { vec3 tmpv = pt - tr.v[i], vv = tr.v[(i+1)%3] - tr.v[i]; vec3 nn1 = vec3::vect_mult(vv,tr.norm); if(vec3::dot(nn1,tmpv)<0) return 0; } return 1; }
Eigen::VectorXd flattenSymmetric(Eigen::MatrixXd symm) { //todo: other data types? //todo: safety/square matrix checking? int num_entries = symm.rows() * (symm.rows() + 1) / 2; Eigen::VectorXd flat(num_entries); int count = 0; for (int i = 0; i < symm.cols(); i++) { int ltcsz = symm.cols() - i; flat.block(count, 0, ltcsz, 1) = symm.block(i, i, ltcsz, 1); count += ltcsz; } return flat; }
TreeNode *flat(TreeNode *node) { if(node == NULL) return NULL; TreeNode *l = flat(node->left); TreeNode *r = flat(node->right); node->left = NULL; TreeNode *tmp = node; tmp->left = NULL; tmp->right = l; while (tmp->right) { tmp = tmp->right; } tmp->right = r; return node; }
void AdaptivePathDropCutter::adaptive_sample(const Span* span, double start_t, double stop_t, CLPoint start_cl, CLPoint stop_cl) { const double mid_t = start_t + (stop_t-start_t)/2.0; // mid point sample assert( mid_t > start_t ); assert( mid_t < stop_t ); CLPoint mid_cl = span->getPoint(mid_t); //std::cout << " apdc sampling at " << mid_t << "\n"; subOp[0]->run( mid_cl ); double fw_step = (stop_cl-start_cl).xyNorm(); if ( (fw_step > sampling) || // above minimum step-forward, need to sample more ( (!flat(start_cl,mid_cl,stop_cl)) && (fw_step > min_sampling) ) ) { // OR not flat, and not max sampling adaptive_sample( span, start_t, mid_t , start_cl, mid_cl ); adaptive_sample( span, mid_t , stop_t, mid_cl , stop_cl ); } else { clpoints.push_back(stop_cl); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- QVector<double> DynamicTableData::flattenData() const { int numRows = getNumRows(); int numCols = getNumCols(); QVector<double> flat(numRows * numCols); for (int row = 0; row < numRows; row++) { for (int col = 0; col < numCols; col++) { flat[row * numCols + col] = m_TableData[row][col]; } } return flat; }
/// Generate the winning lines from 4 prototypes. /// We only need the prototypes and the isomorphisms to generate all 76 /// of the winning lines. Note that iso::add() removes duplicates, /// so we can afford to be overzealous in generating them. void win::init() { win main(0,21,42,63); // a major diagonal win flat(0,1,2,3); // flat, but cuts 2 major diagonals win body(16,17,18,19); // flat without cutting a major diagonal win diag(0,5,10,15); // "minor" diagonal. All cut 2 majors. nextwin = 0; for (int i=0; i<iso::nextiso; i++) { win::add(iso::isos[i] * main); win::add(iso::isos[i] * flat); win::add(iso::isos[i] * diag); win::add(iso::isos[i] * body); } #ifndef NDEBUG cout << "There are " << nextwin << " winning lines" << endl; #endif }
int main(int argc, char * argv[]) { std::cout<<"Common LAAS Raster library"<<std::endl; if (argc < 3) { std::cerr<<"usage: "<<argv[0]<<" flat.tiff obstacle.tiff region_out.tif"<<std::endl; return EXIT_FAILURE; } gladys::gdal flat(argv[1]); gladys::gdal obstacle(argv[2]); gladys::gdal region; region.copy_meta(flat, clara::region::N_RASTER); region.bands_name = {"NO_3D_CLASS", "FLAT", "OBSTACLE", "ROUGH", "SLOPE"}; region.bands[clara::region::FLAT] = flat.bands[0]; region.bands[clara::region::OBSTACLE] = obstacle.bands[0]; region.save(argv[3]); return EXIT_SUCCESS; }
void AdaptiveWaterline::yfiber_adaptive_sample(const Span* span, double start_t, double stop_t, Fiber start_f, Fiber stop_f) { const double mid_t = start_t + (stop_t-start_t)/2.0; // mid point sample assert( mid_t > start_t ); assert( mid_t < stop_t ); //std::cout << "yfiber sample= ( " << start_t << " , " << stop_t << " ) \n"; Point mid_p1 = Point( span->getPoint( mid_t ).x, miny, zh ); Point mid_p2 = Point( span->getPoint( mid_t ).x, maxy, zh ); Fiber mid_f = Fiber( mid_p1, mid_p2 ); subOp[1]->run( mid_f ); double fw_step = fabs( start_f.p1.x - stop_f.p1.x ) ; if ( fw_step > sampling ) { // above minimum step-forward, need to sample more yfiber_adaptive_sample( span, start_t, mid_t , start_f, mid_f ); yfiber_adaptive_sample( span, mid_t , stop_t, mid_f , stop_f ); } else if ( !flat(start_f,mid_f,stop_f) ) { if (fw_step > min_sampling) { // not a flat segment, and we have not reached maximum sampling yfiber_adaptive_sample( span, start_t, mid_t , start_f, mid_f ); yfiber_adaptive_sample( span, mid_t , stop_t, mid_f , stop_f ); } } else { yfibers.push_back(stop_f); } }
void PointCloudModelGenerator::generate( const std::string& model_name, pcl::PointCloud<PointT>& output, double hole_rate) { output.points.clear(); if (model_name == "flat") { flat(output, hole_rate); } else if (model_name == "stairs") { stairs(output, hole_rate); } else if (model_name == "hills") { hills(output, hole_rate); } else if (model_name == "gaussian") { gaussian(output, hole_rate); } else if (model_name == "flat_pole") { flatPole(output, hole_rate); } }
/* * roomin: * Find what room some coordinates are in. NULL means they aren't * in any room. */ struct room * roomin(const coord *cp) { struct room *rp; int *fp; fp = &flat(cp->y, cp->x); if (*fp & F_PASS) return &passages[*fp & F_PNUM]; for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) if (cp->x <= rp->r_pos.x + rp->r_max.x && rp->r_pos.x <= cp->x && cp->y <= rp->r_pos.y + rp->r_max.y && rp->r_pos.y <= cp->y) return rp; msg("in some bizarre place (%d, %d)", unc(*cp)); #ifdef MASTER abort(); return NULL; #else return NULL; #endif }
void BezierCurveEvaluator::addBezier(std::vector<Point>& evaluatePoints, Point points[], float leftBorder, float rightBorder) const { //Ensure function rightBorder = MIN(rightBorder, points[3].x); leftBorder = MIN(leftBorder, points[0].x); if(flat(points)) { for(int i=0; i<4; i++) { if(points[0].x < leftBorder && points[i - 1].x < leftBorder && points[i].x >= leftBorder) { //Interpolate float dx = points[i].x - points[i - 1].x; float q = points[i].x - leftBorder; Point p; p.x = leftBorder; p.y = q / dx * points[i - 1].y - (1 - q / dx) * points[i].y; evaluatePoints.push_back(p); } if(points[3].x > rightBorder && points[i + 1].x > rightBorder && points[i].x <= rightBorder) { //Interpolate float dx = points[i + 1].x - points[i].x; float q = rightBorder - points[i].x; Point p; p.x = rightBorder; p.y = q / dx * points[i + 1].y + (1 - q / dx) * points[i].y; evaluatePoints.push_back(p); } if(points[i].x >= leftBorder && points[i].x <= rightBorder) { evaluatePoints.push_back(points[i]); } } } else { Point left[4], right[4]; divide(points, left, right); addBezier(evaluatePoints, left, leftBorder, rightBorder); addBezier(evaluatePoints, right, leftBorder, rightBorder); } }
/* * cansee: * Returns true if the hero can see a certain coordinate. */ int cansee(int y, int x) { struct room *rer; coord tp; if (on(player, ISBLIND)) return FALSE; if (dist(y, x, hero.y, hero.x) < LAMPDIST) { if (flat(y, x) & F_PASS) if (y != hero.y && x != hero.x && !step_ok(chat(y, hero.x)) && !step_ok(chat(hero.y, x))) return FALSE; return TRUE; } /* * We can only see if the hero in the same room as * the coordinate and the room is lit or if it is close. */ tp.y = y; tp.x = x; return ((rer = roomin(&tp)) == proom && !(rer->r_flags & ISDARK)); }
void test_forwardVelKin() { const int MAXNS = NUMSTATE(WmrModel::MAXNF); const int MAXNV = NUMQVEL(WmrModel::MAXNF); //make WmrModel object WmrModel mdl; Real state[MAXNS]; zoe(mdl,state,0); //rocky(mdl,state,0); //talon(mdl,state,0); //TODO //get from WmrModel const int nw = mdl.get_nw(); const int nt = mdl.get_nt(); const int na = mdl.get_na(); const int nv = NUMQVEL(mdl.get_nf()); //terrain SurfaceVector surfs; flat(surfs); //ramp(surfs); //grid(surfs, ResourceDir() + std::string("gridsurfdata.txt") ); //init contact geometry WheelContactGeom wcontacts[WmrModel::MAXNW]; TrackContactGeom tcontacts[WmrModel::MAXNW]; ContactGeom* contacts = 0; if (nw > 0) { contacts = static_cast<ContactGeom*>(wcontacts); } else if (nt > 0) { sub_initTrackContactGeom(mdl, tcontacts); contacts = static_cast<ContactGeom*>(tcontacts); } //convert state to homogeneous transforms HomogeneousTransform HT_parent[WmrModel::MAXNF]; HomogeneousTransform HT_world[WmrModel::MAXNF]; stateToHT(mdl,state,HT_parent,HT_world); //update contact geometry updateModelContactGeom(mdl, surfs, HT_world, mdl.min_npic, contacts); //controller inputs Real u[WmrModel::MAXNA]; Real qvel_cmd[MAXNV]; Real time = 0; mdl.controller(mdl, 0, state, u, qvel_cmd); //allocate outputs Real qvel[MAXNV]; Vec3 vc[WmrModel::MAXNW]; //compute joint space velocity forwardVelKin(mdl, state, u, HT_world, contacts, qvel, vc); //PRINT std::cout << "u =\n"; printMatReal(na,1,u,-1,-1); std::cout << std::endl; std::cout << "qvel_cmd =\n"; printMatReal(nv,1,qvel_cmd,-1,-1); std::cout << std::endl; std::cout << "qvel =\n"; printMatReal(nv,1,qvel,-1,-1); std::cout << std::endl; std::cout << "vc =\n"; printnVec3(nw,vc,-1,-1); std::cout << std::endl; if (1) { //time it int n= (int) 1e5; timeval t0, t1; gettimeofday(&t0, NULL); for (int i=0; i<n; i++) { forwardVelKin(mdl, state, u, HT_world, contacts, qvel, 0); } gettimeofday(&t1, NULL); std::cout << "wheelJacobians()\n"; std::cout << "iterations: " << (Real) n << std::endl; std::cout << "clock (sec): " << tosec(t1)-tosec(t0) << std::endl; } }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget container; container.resize(640, 680); container.setFocusPolicy ( Qt::NoFocus ); Engine engine(NULL); QMenuBar open_menu_bar(&container); QMenu open_menu("&File", &container); QAction open("&Open", &container); open.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); open_menu.addAction(&open); QAction reset("&Reset", &container); reset.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); open_menu.addAction(&reset); QAction save("&Save", &container); save.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); open_menu.addAction(&save); QAction close("&Close", &container); close.setShortcut(QKeySequence(Qt::ALT + Qt::Key_F4)); open_menu.addAction(&close); QMenu draw_menu("&Drawmodes", &container); QAction points("&Points", &container); points.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P)); draw_menu.addAction(&points); QAction wire("&Wireframe", &container); wire.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W)); draw_menu.addAction(&wire); QAction flat("&Flat shaded", &container); flat.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F)); draw_menu.addAction(&flat); QAction smooth("&Smooth shaded", &container); smooth.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); draw_menu.addAction(&smooth); /**** MENU CONVEX HULL ****/ QMenu convex_hull("Convex Hull", &container); QAction calc("&Calculate CH", &container); calc.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C)); convex_hull.addAction(&calc); /**** MENU HELP ****/ QMenu help_menu("&?", &container); QAction help("&Help", &container); help.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_H)); help_menu.addAction(&help); QAction about("&About", &container); about.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A)); help_menu.addAction(&about); open_menu_bar.addMenu(&open_menu); open_menu_bar.addMenu(&draw_menu); open_menu_bar.addMenu(&convex_hull); open_menu_bar.addMenu(&help_menu); Window_gl window(&container); window.setGeometry(0,22,640, 680); container.show(); QDialog instructions( NULL ); instructions.setFixedSize(300,180); instructions.setWindowTitle("Help"); QLabel instr_text("\nUp - Sposta l'osservatore verso l'alto\nDown - Sposta l'osservatore verso il basso\nLeft - Ruota verso sinistra\nRight - Ruota verso destra\nShift+Up - Zoom In\nShift+Down - Zoom out\n\nSi ricorda che il programma e' in grado di gestire\nsolo files di tipo .OFF.\nAltri formati non sono attualmente supportati.", &instructions); instr_text.setTextFormat(Qt::AutoText); instr_text.setWordWrap(true); instructions.hide(); QDialog credits( NULL ); credits.setFixedSize(300,100); credits.setWindowTitle("Credits"); QLabel cred_text("\tCGVew v.1.7\n\nA cura di Fabio Guggeri ([email protected])\ne Stefano Marras ([email protected]).\n", &credits); cred_text.setTextFormat(Qt::AutoText); cred_text.setWordWrap(true); credits.hide(); QObject::connect( &open, SIGNAL(triggered()), &engine, SLOT(open_file()) ); QObject::connect( &reset, SIGNAL(triggered()), &window, SLOT(reset()) ); QObject::connect( &reset, SIGNAL(triggered()), &engine, SLOT(reset()) ); QObject::connect( &save, SIGNAL(triggered()), &engine, SLOT(save_file()) ); QObject::connect( &points, SIGNAL(triggered()), &window, SLOT(set_p_drawmode()) ); QObject::connect( &wire, SIGNAL(triggered()), &window, SLOT(set_w_drawmode()) ); QObject::connect( &flat, SIGNAL(triggered()), &window, SLOT(set_f_drawmode()) ); QObject::connect( &smooth, SIGNAL(triggered()), &window, SLOT(set_s_drawmode()) ); QObject::connect( &help, SIGNAL(triggered()), &instructions, SLOT(show()) ); QObject::connect( &about, SIGNAL(triggered()), &credits, SLOT(show()) ); QObject::connect( &close, SIGNAL(triggered()), &app, SLOT(quit()) ); QObject::connect( &engine, SIGNAL(send_dcel(QVector<DCEL>&)), &window, SLOT(add_dcel(QVector<DCEL>&)) ); QObject::connect( &calc, SIGNAL(triggered()), &engine, SLOT(calculate_ch()) ); window.setFocus(); return app.exec(); }
/** * * @param parentId * @return */ virtual int writeH5Data(hid_t parentId) { int err = 0; // Generate the number of neighbors array and also compute the total number // of elements that would be needed to flatten the array std::vector<int32_t> numNeighbors(_data.size()); size_t total = 0; for(size_t dIdx = 0; dIdx < _data.size(); ++dIdx) { numNeighbors[dIdx] = static_cast<int32_t>(_data[dIdx]->size()); total += _data[dIdx]->size(); } // Check to see if the NumNeighbors is already written to the file bool rewrite = false; if (H5Lite::datasetExists(parentId, DREAM3D::FieldData::NumNeighbors) == false) { rewrite = true; } else { std::vector<int32_t> fileNumNeigh(_data.size()); err = H5Lite::readVectorDataset(parentId, DREAM3D::FieldData::NumNeighbors, fileNumNeigh); if (err < 0) { return -602; } // Compare the 2 vectors to make sure they are exactly the same; if (fileNumNeigh.size() != numNeighbors.size()) { rewrite = true; } // The sizes are the same, now compare each value; int32_t* numNeighPtr = &(numNeighbors.front()); int32_t* fileNumNeiPtr = &(fileNumNeigh.front()); size_t nBytes = numNeighbors.size() * sizeof(int32_t); if (::memcmp(numNeighPtr, fileNumNeiPtr, nBytes) != 0) { rewrite = true; } } // Write out the NumNeighbors Array if(rewrite == true) { std::vector<hsize_t> dims(1, numNeighbors.size()); err = H5Lite::writeVectorDataset(parentId, DREAM3D::FieldData::NumNeighbors, dims, numNeighbors); if(err < 0) { return -603; } err = H5Lite::writeScalarAttribute(parentId, DREAM3D::FieldData::NumNeighbors, std::string(H5_NUMCOMPONENTS), 1); if(err < 0) { return -605; } err = H5Lite::writeStringAttribute(parentId, DREAM3D::FieldData::NumNeighbors, DREAM3D::HDF5::ObjectType, "DataArray<T>"); if(err < 0) { return -604; } } // Allocate an array of the proper size to we can concatenate all the arrays together into a single array that // can be written to the HDF5 File. This operation can ballon the memory size temporarily until this operation // is complete. std::vector<T> flat (total); size_t currentStart = 0; for(size_t dIdx = 0; dIdx < _data.size(); ++dIdx) { size_t nEle = _data[dIdx]->size(); if (nEle == 0) { continue; } T* start = &(_data[dIdx]->front()); // Get the pointer to the front of the array // T* end = start + nEle; // Get the pointer to the end of the array T* dst = &(flat.front()) + currentStart; ::memcpy(dst, start, nEle*sizeof(T)); currentStart += _data[dIdx]->size(); } int32_t rank = 1; hsize_t dims[1] = { total }; if (total > 0) { err = H5Lite::writePointerDataset(parentId, GetName(), rank, dims, &(flat.front())); if(err < 0) { return -605; } err = H5Lite::writeScalarAttribute(parentId, GetName(), std::string(H5_NUMCOMPONENTS), 1); if(err < 0) { return -606; } err = H5Lite::writeStringAttribute(parentId, GetName(), DREAM3D::HDF5::ObjectType, getNameOfClass()); if(err < 0) { return -607; } err = H5Lite::writeStringAttribute(parentId, GetName(), "Linked NumNeighbors Dataset", DREAM3D::FieldData::NumNeighbors); if(err < 0) { return -608; } } return err; }
void test_forwardDyn() { const int MAXNS = NUMSTATE(WmrModel::MAXNF); const int MAXNV = NUMQVEL(WmrModel::MAXNF); //make WmrModel object WmrModel mdl; Real state[MAXNS]; Real qvel[MAXNV]; zoe(mdl,state,qvel); //rocky(mdl,state,qvel); //talon(mdl,state,qvel); //TODO //setVec(nv,0.0,qvel); //DEBUGGING mdl.actuatorModel=0; //ideal actuators //get from WmrModel const int nf = mdl.get_nf(); const int ns = NUMSTATE(nf); const int nv = NUMQVEL(nf); const int nw = mdl.get_nw(); const int nt = mdl.get_nt(); //terrain SurfaceVector surfs; flat(surfs); //ramp(surfs); //grid(surfs, ResourceDir() + std::string("gridsurfdata.txt") ); //init contact geometry WheelContactGeom wcontacts[WmrModel::MAXNW]; TrackContactGeom tcontacts[WmrModel::MAXNW]; ContactGeom* contacts = 0; if (nw > 0) { contacts = static_cast<ContactGeom*>(wcontacts); } else if (nt > 0) { sub_initTrackContactGeom(mdl, tcontacts); contacts = static_cast<ContactGeom*>(tcontacts); } //initTerrainContact(mdl, surfs, contacts, state); //DEBUGGING //convert state to Homogeneous Transforms HomogeneousTransform HT_parent[WmrModel::MAXNF + WmrModel::MAXNW]; HomogeneousTransform HT_world[WmrModel::MAXNF + WmrModel::MAXNW]; stateToHT(mdl,state,HT_parent,HT_world); //update contact geometry updateModelContactGeom(mdl, surfs, HT_world, 0, contacts); //controller inputs ControllerIO u; Real time = 0; mdl.controller(mdl, 0, state, u.cmd, 0); //additional inputs setVec(mdl.get_na(),0.0,u.interr); Real dt = .04; //time step //outputs Real qacc[MAXNV]; forwardDyn(mdl, state, qvel, u, HT_parent, HT_world, contacts, dt, qacc); //DEBUGGING, print std::cout << "state=\n"; printMatReal(ns,1,state,-1,-1); std::cout << std::endl; std::cout << "qvel=\n"; printMatReal(nv,1,qvel,-1,-1); std::cout << std::endl; std::cout << "qacc=\n"; printMatReal(nv,1,qacc,-1,-1); std::cout << std::endl; if (1) { //time it int n= (int) 1e4; timeval t0, t1; gettimeofday(&t0, NULL); for (int i=0; i<n; i++) { forwardDyn(mdl, state, qvel, u, HT_parent, HT_world, contacts, dt, qacc); } gettimeofday(&t1, NULL); std::cout << "forwardDyn()\n"; std::cout << "iterations: " << (Real) n << std::endl; std::cout << "clock (sec): " << tosec(t1)-tosec(t0) << std::endl; } }
/* * do_chase: * Make one thing chase another. */ int do_chase(THING *th) { coord *cp; struct room *rer, *ree; /* room of chaser, room of chasee */ int mindist = 32767, curdist; int stoprun = FALSE; /* TRUE means we are there */ int door; THING *obj; coord this; /* Temporary destination for chaser */ rer = th->t_room; /* Find room of chaser */ if (on(*th, ISGREED) && rer->r_goldval == 0) th->t_dest = &hero; /* If gold has been taken, run after hero */ if (th->t_dest == &hero) /* Find room of chasee */ ree = proom; else ree = roomin(th->t_dest); /* * We don't count doors as inside rooms for this routine */ door = (chat(th->t_pos.y, th->t_pos.x) == DOOR); /* * If the object of our desire is in a different room, * and we are not in a corridor, run to the door nearest to * our goal. */ over: if (rer != ree) { for (cp = rer->r_exit; cp < &rer->r_exit[rer->r_nexits]; cp++) { curdist = dist_cp(th->t_dest, cp); if (curdist < mindist) { this = *cp; mindist = curdist; } } if (door) { rer = &passages[flat(th->t_pos.y, th->t_pos.x) & F_PNUM]; door = FALSE; goto over; } } else { this = *th->t_dest; /* * For dragons check and see if (a) the hero is on a straight * line from it, and (b) that it is within shooting distance, * but outside of striking range. */ if (th->t_type == 'D' && (th->t_pos.y == hero.y || th->t_pos.x == hero.x || abs(th->t_pos.y - hero.y) == abs(th->t_pos.x - hero.x)) && dist_cp(&th->t_pos, &hero) <= BOLT_LENGTH * BOLT_LENGTH && !on(*th, ISCANC) && rnd(DRAGONSHOT) == 0) { delta.y = sign(hero.y - th->t_pos.y); delta.x = sign(hero.x - th->t_pos.x); if (has_hit) endmsg(); fire_bolt(&th->t_pos, &delta, "flame"); running = FALSE; count = 0; quiet = 0; if (to_death && !on(*th, ISTARGET)) { to_death = FALSE; kamikaze = FALSE; } return(0); } } /* * This now contains what we want to run to this time * so we run to it. If we hit it we either want to fight it * or stop running */ if (!chase(th, &this)) { if (ce(this, hero)) { return( attack(th) ); } else if (ce(this, *th->t_dest)) { for (obj = lvl_obj; obj != NULL; obj = next(obj)) if (th->t_dest == &obj->o_pos) { detach(lvl_obj, obj); attach(th->t_pack, obj); chat(obj->o_pos.y, obj->o_pos.x) = (th->t_room->r_flags & ISGONE) ? PASSAGE : FLOOR; th->t_dest = find_dest(th); break; } if (th->t_type != 'F') stoprun = TRUE; } } else { if (th->t_type == 'F') return(0); } relocate(th, &ch_ret); /* * And stop running if need be */ if (stoprun && ce(th->t_pos, *(th->t_dest))) th->t_flags &= ~ISRUN; return(0); }
void test_trackJacobians() { const int MAXNS = NUMSTATE(WmrModel::MAXNF); //make WmrModel object WmrModel mdl; Real state[MAXNS]; talon(mdl,state,0); //get from WmrModel const int nt = mdl.get_nt(); //terrain SurfaceVector surfs; flat(surfs); //ramp(surfs); //grid(surfs, ResourceDir() + std::string("gridsurfdata.txt") ); //convert state to homogeneous transforms HomogeneousTransform HT_parent[WmrModel::MAXNF + WmrModel::MAXNW]; HomogeneousTransform HT_world[WmrModel::MAXNF + WmrModel::MAXNW]; stateToHT(mdl,state,HT_parent,HT_world); //contact geometry TrackContactGeom tcontacts[WmrModel::MAXNW]; sub_initTrackContactGeom(mdl, tcontacts); ContactGeom* contacts = static_cast<ContactGeom*>(tcontacts); updateModelContactGeom(mdl, surfs, HT_world, mdl.min_npic, contacts); //number of points in contact int npic = 0; for (int tno = 0; tno < nt; tno++) { npic += logicalCount(tcontacts[tno].get_np(), tcontacts[tno].incontact); } //allocate matrix const int MAXNV = NUMQVEL(WmrModel::MAXNF); const int MAXNP = WmrModel::MAXNT * ContactGeom::MAXNP; //max number of contact points Real A[3*MAXNP * MAXNV]; trackJacobians(mdl, HT_world, tcontacts, A); //DEBUGGING, print int ncc = 3*npic; //number of contact constraints int nv = NUMQVEL(mdl.get_nf()); std::cout << "A=\n"; printMatReal(ncc,nv,A,-1,-1); std::cout << std::endl; if (1) { //time it int n= (int) 1e6; timeval t0, t1; gettimeofday(&t0, NULL); for (int i=0; i<n; i++) { trackJacobians(mdl, HT_world, tcontacts, A); } gettimeofday(&t1, NULL); std::cout << "trackJacobians()\n"; std::cout << "iterations: " << (Real) n << std::endl; std::cout << "clock (sec): " << tosec(t1)-tosec(t0) << std::endl; } }