std::vector<tripoint> map::route( const tripoint &f, const tripoint &t, const pathfinding_settings &settings, const std::set<tripoint> &pre_closed ) const { /* TODO: If the origin or destination is out of bound, figure out the closest * in-bounds point and go to that, then to the real origin/destination. */ std::vector<tripoint> ret; if( f == t || !inbounds( f ) ) { return ret; } if( !inbounds( t ) ) { tripoint clipped = t; clip_to_bounds( clipped ); return route( f, clipped, settings, pre_closed ); } // First, check for a simple straight line on flat ground // Except when the line contains a pre-closed tile - we need to do regular pathing then static const auto non_normal = PF_SLOW | PF_WALL | PF_VEHICLE | PF_TRAP; if( f.z == t.z ) { const auto line_path = line_to( f, t ); const auto &pf_cache = get_pathfinding_cache_ref( f.z ); // Check all points for any special case (including just hard terrain) if( std::all_of( line_path.begin(), line_path.end(), [&pf_cache]( const tripoint & p ) { return !( pf_cache.special[p.x][p.y] & non_normal ); } ) ) { const std::set<tripoint> sorted_line( line_path.begin(), line_path.end() ); if( is_disjoint( sorted_line, pre_closed ) ) { return line_path; } } } // If expected path length is greater than max distance, allow only line path, like above if( rl_dist( f, t ) > settings.max_dist ) { return ret; } int max_length = settings.max_length; int bash = settings.bash_strength; bool doors = settings.allow_open_doors; bool trapavoid = settings.avoid_traps; const int pad = 16; // Should be much bigger - low value makes pathfinders dumb! int minx = std::min( f.x, t.x ) - pad; int miny = std::min( f.y, t.y ) - pad; int minz = std::min( f.z, t.z ); // TODO: Make this way bigger int maxx = std::max( f.x, t.x ) + pad; int maxy = std::max( f.y, t.y ) + pad; int maxz = std::max( f.z, t.z ); // Same TODO as above clip_to_bounds( minx, miny, minz ); clip_to_bounds( maxx, maxy, maxz ); pathfinder pf( minx, miny, maxx, maxy ); // Make NPCs not want to path through player // But don't make player pathing stop working for( const auto &p : pre_closed ) { if( p.x >= minx && p.x < maxx && p.y >= miny && p.y < maxy ) { pf.close_point( p ); } } // Start and end must not be closed pf.unclose_point( f ); pf.unclose_point( t ); pf.add_point( 0, 0, f, f ); bool done = false; do { auto cur = pf.get_next(); const int parent_index = flat_index( cur.x, cur.y ); auto &layer = pf.get_layer( cur.z ); auto &cur_state = layer.state[parent_index]; if( cur_state == ASL_CLOSED ) { continue; } if( layer.gscore[parent_index] > max_length ) { // Shortest path would be too long, return empty vector return std::vector<tripoint>(); } if( cur == t ) { done = true; break; } cur_state = ASL_CLOSED; const auto &pf_cache = get_pathfinding_cache_ref( cur.z ); const auto cur_special = pf_cache.special[cur.x][cur.y]; // 7 3 5 // 1 . 2 // 6 4 8 constexpr std::array<int, 8> x_offset{{ -1, 1, 0, 0, 1, -1, -1, 1 }}; constexpr std::array<int, 8> y_offset{{ 0, 0, -1, 1, -1, 1, -1, 1 }}; for( size_t i = 0; i < 8; i++ ) { const tripoint p( cur.x + x_offset[i], cur.y + y_offset[i], cur.z ); const int index = flat_index( p.x, p.y ); // @todo Remove this and instead have sentinels at the edges if( p.x < minx || p.x >= maxx || p.y < miny || p.y >= maxy ) { continue; } if( layer.state[index] == ASL_CLOSED ) { continue; } // Penalize for diagonals or the path will look "unnatural" int newg = layer.gscore[parent_index] + ( ( cur.x != p.x && cur.y != p.y ) ? 1 : 0 ); const auto p_special = pf_cache.special[p.x][p.y]; // @todo De-uglify, de-huge-n if( !( p_special & non_normal ) ) { // Boring flat dirt - the most common case above the ground newg += 2; } else { int part = -1; const maptile &tile = maptile_at_internal( p ); const auto &terrain = tile.get_ter_t(); const auto &furniture = tile.get_furn_t(); const vehicle *veh = veh_at_internal( p, part ); const int cost = move_cost_internal( furniture, terrain, veh, part ); // Don't calculate bash rating unless we intend to actually use it const int rating = ( bash == 0 || cost != 0 ) ? -1 : bash_rating_internal( bash, furniture, terrain, false, veh, part ); if( cost == 0 && rating <= 0 && ( !doors || !terrain.open ) && veh == nullptr ) { layer.state[index] = ASL_CLOSED; // Close it so that next time we won't try to calc costs continue; } newg += cost; if( cost == 0 ) { // Handle all kinds of doors // Only try to open INSIDE doors from the inside if( doors && terrain.open && ( !terrain.has_flag( "OPENCLOSE_INSIDE" ) || !is_outside( cur ) ) ) { // To open and then move onto the tile newg += 4; } else if( veh != nullptr ) { part = veh->obstacle_at_part( part ); int dummy = -1; if( doors && veh->part_flag( part, VPFLAG_OPENABLE ) && ( !veh->part_flag( part, "OPENCLOSE_INSIDE" ) || veh_at_internal( cur, dummy ) == veh ) ) { // Handle car doors, but don't try to path through curtains newg += 10; // One turn to open, 4 to move there } else if( part >= 0 && bash > 0 ) { // Car obstacle that isn't a door // @todo Account for armor int hp = veh->parts[part].hp(); if( hp / 20 > bash ) { // Threshold damage thing means we just can't bash this down layer.state[index] = ASL_CLOSED; continue; } else if( hp / 10 > bash ) { // Threshold damage thing means we will fail to deal damage pretty often hp *= 2; } newg += 2 * hp / bash + 8 + 4; } else if( part >= 0 ) { if( !doors || !veh->part_flag( part, VPFLAG_OPENABLE ) ) { // Won't be openable, don't try from other sides layer.state[index] = ASL_CLOSED; } continue; } } else if( rating > 1 ) { // Expected number of turns to bash it down, 1 turn to move there // and 5 turns of penalty not to trash everything just because we can newg += ( 20 / rating ) + 2 + 10; } else if( rating == 1 ) { // Desperate measures, avoid whenever possible newg += 500; } else { // Unbashable and unopenable from here if( !doors || !terrain.open ) { // Or anywhere else for that matter layer.state[index] = ASL_CLOSED; } continue; } } if( trapavoid && p_special & PF_TRAP ) { const auto &ter_trp = terrain.trap.obj(); const auto &trp = ter_trp.is_benign() ? tile.get_trap_t() : ter_trp; if( !trp.is_benign() ) { // For now make them detect all traps if( has_zlevels() && terrain.has_flag( TFLAG_NO_FLOOR ) ) { // Special case - ledge in z-levels // Warning: really expensive, needs a cache if( valid_move( p, tripoint( p.x, p.y, p.z - 1 ), false, true ) ) { tripoint below( p.x, p.y, p.z - 1 ); if( !has_flag( TFLAG_NO_FLOOR, below ) ) { // Otherwise this would have been a huge fall auto &layer = pf.get_layer( p.z - 1 ); // From cur, not p, because we won't be walking on air pf.add_point( layer.gscore[parent_index] + 10, layer.score[parent_index] + 10 + 2 * rl_dist( below, t ), cur, below ); } // Close p, because we won't be walking on it layer.state[index] = ASL_CLOSED; continue; } } else if( trapavoid ) { // Otherwise it's walkable newg += 500; } } } } // If not visited, add as open // If visited, add it only if we can do so with better score if( layer.state[index] == ASL_NONE || newg < layer.gscore[index] ) { pf.add_point( newg, newg + 2 * rl_dist( p, t ), cur, p ); } } if( !has_zlevels() || !( cur_special & PF_UPDOWN ) || !settings.allow_climb_stairs ) { // The part below is only for z-level pathing continue; } const maptile &parent_tile = maptile_at_internal( cur ); const auto &parent_terrain = parent_tile.get_ter_t(); if( settings.allow_climb_stairs && cur.z > minz && parent_terrain.has_flag( TFLAG_GOES_DOWN ) ) { tripoint dest( cur.x, cur.y, cur.z - 1 ); dest = vertical_move_destination<TFLAG_GOES_UP>( *this, dest ); if( inbounds( dest ) ) { auto &layer = pf.get_layer( dest.z ); pf.add_point( layer.gscore[parent_index] + 2, layer.score[parent_index] + 2 * rl_dist( dest, t ), cur, dest ); } } if( settings.allow_climb_stairs && cur.z < maxz && parent_terrain.has_flag( TFLAG_GOES_UP ) ) { tripoint dest( cur.x, cur.y, cur.z + 1 ); dest = vertical_move_destination<TFLAG_GOES_DOWN>( *this, dest ); if( inbounds( dest ) ) { auto &layer = pf.get_layer( dest.z ); pf.add_point( layer.gscore[parent_index] + 2, layer.score[parent_index] + 2 * rl_dist( dest, t ), cur, dest ); } } if( cur.z < maxz && parent_terrain.has_flag( TFLAG_RAMP ) && valid_move( cur, tripoint( cur.x, cur.y, cur.z + 1 ), false, true ) ) { auto &layer = pf.get_layer( cur.z + 1 ); for( size_t it = 0; it < 8; it++ ) { const tripoint above( cur.x + x_offset[it], cur.y + y_offset[it], cur.z + 1 ); pf.add_point( layer.gscore[parent_index] + 4, layer.score[parent_index] + 4 + 2 * rl_dist( above, t ), cur, above ); } } } while( !done && !pf.empty() ); if( done ) { ret.reserve( rl_dist( f, t ) * 2 ); tripoint cur = t; // Just to limit max distance, in case something weird happens for( int fdist = max_length; fdist != 0; fdist-- ) { const int cur_index = flat_index( cur.x, cur.y ); const auto &layer = pf.get_layer( cur.z ); const tripoint &par = layer.parent[cur_index]; if( cur == f ) { break; } ret.push_back( cur ); // Jumps are acceptable on 1 z-level changes // This is because stairs teleport the player too if( rl_dist( cur, par ) > 1 && abs( cur.z - par.z ) != 1 ) { debugmsg( "Jump in our route! %d:%d:%d->%d:%d:%d", cur.x, cur.y, cur.z, par.x, par.y, par.z ); return ret; } cur = par; } std::reverse( ret.begin(), ret.end() ); } return ret; }
std::vector<tripoint> map::route( const tripoint &f, const tripoint &t, const int bash, const int maxdist ) const { /* TODO: If the origin or destination is out of bound, figure out the closest * in-bounds point and go to that, then to the real origin/destination. */ if( !inbounds( f ) || !inbounds( t ) ) { // Note: The creature needs to understand not-moving upwards // or else the plans can cause it to do so. if( sees( f, t, -1 ) ) { return find_clear_path( f, t ); } else { return {}; } } // First, check for a simple straight line on flat ground // Except when the player is on the line - we need to do regular pathing then const tripoint &pl_pos = g->u.pos(); if( f.z == t.z && clear_path( f, t, -1, 2, 2 ) ) { const auto line_path = line_to( f, t ); if( pl_pos.z != f.z ) { // Player on different z-level, certainly not on the line return line_path; } if( std::find( line_path.begin(), line_path.end(), pl_pos ) == line_path.end() ) { return line_path; } } const int pad = 8; // Should be much bigger - low value makes pathfinders dumb! int minx = std::min( f.x, t.x ) - pad; int miny = std::min( f.y, t.y ) - pad; int minz = std::min( f.z, t.z ); // TODO: Make this way bigger int maxx = std::max( f.x, t.x ) + pad; int maxy = std::max( f.y, t.y ) + pad; int maxz = std::max( f.z, t.z ); // Same TODO as above clip_to_bounds( minx, miny, minz ); clip_to_bounds( maxx, maxy, maxz ); pathfinder pf( minx, miny, maxx, maxy ); pf.add_point( 0, 0, f, f ); // Make NPCs not want to path through player // But don't make player pathing stop working if( f != pl_pos && t != pl_pos ) { pf.close_point( pl_pos ); } bool done = false; do { auto cur = pf.get_next(); const int parent_index = flat_index( cur.x, cur.y ); auto &layer = pf.get_layer( cur.z ); auto &cur_state = layer.state[parent_index]; if( cur_state == ASL_CLOSED ) { continue; } if( layer.gscore[parent_index] > maxdist ) { // Shortest path would be too long, return empty vector return std::vector<tripoint>(); } if( cur == t ) { done = true; break; } cur_state = ASL_CLOSED; std::vector<tripoint> neighbors = closest_tripoints_first( 1, cur ); for( const auto &p : neighbors ) { const int index = flat_index( p.x, p.y ); // TODO: Remove this and instead have sentinels at the edges if( p.x < minx || p.x >= maxx || p.y < miny || p.y >= maxy ) { continue; } if( layer.state[index] == ASL_CLOSED ) { continue; } int part = -1; const maptile &tile = maptile_at_internal( p ); const auto &terrain = tile.get_ter_t(); const auto &furniture = tile.get_furn_t(); const vehicle *veh = veh_at_internal( p, part ); const int cost = move_cost_internal( furniture, terrain, veh, part ); // Don't calculate bash rating unless we intend to actually use it const int rating = ( bash == 0 || cost != 0 ) ? -1 : bash_rating_internal( bash, furniture, terrain, false, veh, part ); if( cost == 0 && rating <= 0 && terrain.open.empty() ) { layer.state[index] = ASL_CLOSED; // Close it so that next time we won't try to calc costs continue; } int newg = layer.gscore[parent_index] + cost + ( (cur.x != p.x && cur.y != p.y ) ? 1 : 0); if( cost == 0 ) { // Handle all kinds of doors // Only try to open INSIDE doors from the inside if( !terrain.open.empty() && ( !terrain.has_flag( "OPENCLOSE_INSIDE" ) || !is_outside( cur ) ) ) { newg += 4; // To open and then move onto the tile } else if( veh != nullptr ) { part = veh->obstacle_at_part( part ); int dummy = -1; if( !veh->part_flag( part, "OPENCLOSE_INSIDE" ) || veh_at_internal( cur, dummy ) == veh ) { // Handle car doors, but don't try to path through curtains newg += 10; // One turn to open, 4 to move there } else { // Car obstacle that isn't a door newg += veh->parts[part].hp / bash + 8 + 4; } } else if( rating > 1 ) { // Expected number of turns to bash it down, 1 turn to move there // and 2 turns of penalty not to trash everything just because we can newg += ( 20 / rating ) + 2 + 4; } else if( rating == 1 ) { // Desperate measures, avoid whenever possible newg += 500; } else { continue; // Unbashable and unopenable from here } } // If not visited, add as open // If visited, add it only if we can do so with better score if( layer.state[index] == ASL_NONE || newg < layer.gscore[index] ) { pf.add_point( newg, newg + 2 * rl_dist( p, t ), cur, p ); } } if( !has_zlevels() ) { // The part below is only for z-level pathing continue; } const maptile &parent_tile = maptile_at_internal( cur ); const auto &parent_terrain = parent_tile.get_ter_t(); if( cur.z > minz && parent_terrain.has_flag( TFLAG_GOES_DOWN ) ) { tripoint dest( cur.x, cur.y, cur.z - 1 ); dest = vertical_move_destination<TFLAG_GOES_UP>( *this, dest ); if( inbounds( dest ) ) { auto &layer = pf.get_layer( dest.z ); pf.add_point( layer.gscore[parent_index] + 2, layer.score[parent_index] + 2 * rl_dist( dest, t ), cur, dest ); } } if( cur.z < maxz && parent_terrain.has_flag( TFLAG_GOES_UP ) ) { tripoint dest( cur.x, cur.y, cur.z + 1 ); dest = vertical_move_destination<TFLAG_GOES_DOWN>( *this, dest ); if( inbounds( dest ) ) { auto &layer = pf.get_layer( dest.z ); pf.add_point( layer.gscore[parent_index] + 2, layer.score[parent_index] + 2 * rl_dist( dest, t ), cur, dest ); } } } while( !done && !pf.empty() ); std::vector<tripoint> ret; ret.reserve( rl_dist( f, t ) * 2 ); if( done ) { tripoint cur = t; // Just to limit max distance, in case something weird happens for( int fdist = maxdist; fdist != 0; fdist-- ) { const int cur_index = flat_index( cur.x, cur.y ); const auto &layer = pf.get_layer( cur.z ); const tripoint &par = layer.parent[cur_index]; if( cur == f ) { break; } ret.push_back( cur ); // Jumps are acceptable on 1 z-level changes // This is because stairs teleport the player too if( rl_dist( cur, par ) > 1 && abs( cur.z - par.z ) != 1 ) { debugmsg( "Jump in our route! %d:%d:%d->%d:%d:%d", cur.x, cur.y, cur.z, par.x, par.y, par.z ); return ret; } cur = par; } std::reverse( ret.begin(), ret.end() ); } return ret; }
int main( int argc, char *argv[] ) { QApplication::setColorSpec( QApplication::ManyColor ); DesignerApplication a( argc, argv ); DesignerApplication::setOverrideCursor( Qt::WaitCursor ); bool creatPid = FALSE; if ( a.argc() > 1 ) { QString arg1 = a.argv()[ 1 ]; if ( arg1 == "-client" ) { QFile pf( QDir::homeDirPath() + "/.designerpid" ); if ( pf.exists() && pf.open( IO_ReadOnly ) ) { QString pidStr; pf.readLine( pidStr, pf.size() ); QFile f( QDir::homeDirPath() + "/.designerargs" ); f.open( IO_WriteOnly ); QTextStream ts( &f ); for ( int i = 1; i < a.argc(); ++i ) ts << a.argv()[ i ] << " "; ts << endl; f.close(); #if defined(Q_OS_UNIX) if ( kill( pidStr.toInt(), SIGUSR1 ) == -1 ) creatPid = TRUE; else return 0; #elif defined(Q_OS_WIN32) if ( !GetProcessVersion( pidStr.toUInt() ) ) { creatPid = TRUE; } else { if ( a.winVersion() & Qt::WV_NT_based ) SendMessage( HWND_BROADCAST, RegisterWindowMessage((TCHAR*)"QT_DESIGNER_OPEN_FILE"), 0, 0 ); else SendMessage( HWND_BROADCAST, RegisterWindowMessageA("QT_DESIGNER_OPEN_FILE"), 0, 0 ); return 0; } #endif } else { creatPid = TRUE; } } else if(arg1 == "-debug_stderr") { extern bool debugToStderr; //outputwindow.cpp debugToStderr = TRUE; } } if ( creatPid ) { QFile pf( QDir::homeDirPath() + "/.designerpid" ); pf.open( IO_WriteOnly ); QTextStream ts( &pf ); #if defined(Q_OS_UNIX) signal( SIGUSR1, signalHandler ); #endif ts << getpid() << endl; pf.close(); signal( SIGABRT, exitHandler ); signal( SIGFPE, exitHandler ); signal( SIGILL, exitHandler ); signal( SIGINT, exitHandler ); signal( SIGSEGV, exitHandler ); signal( SIGTERM, exitHandler ); } extern void qInitImages_designercore(); qInitImages_designercore(); QSettings config; QString keybase = DesignerApplication::settingsKey(); config.insertSearchPath( QSettings::Windows, "/Trolltech" ); QStringList pluginPaths = config.readListEntry( keybase + "PluginPaths" ); if (pluginPaths.count()) QApplication::setLibraryPaths(pluginPaths); QSplashScreen *splash = a.showSplash(); MainWindow *mw = new MainWindow( creatPid ); a.setMainWidget( mw ); #if defined(QT_NON_COMMERCIAL) mw->setCaption( "Qt Designer by Trolltech for non-commercial use" ); #else mw->setCaption( "Qt Designer by Trolltech" ); #endif if ( config.readBoolEntry( keybase + "Geometries/MainwindowMaximized", FALSE ) ) { int x = config.readNumEntry( keybase + "Geometries/MainwindowX", 0 ); int y = config.readNumEntry( keybase + "Geometries/MainwindowY", 0 ); mw->move( x, y ); mw->showMaximized(); } else { mw->show(); } if ( splash ) splash->finish( mw ); delete splash; QApplication::restoreOverrideCursor(); for ( int i = 1; i < a.argc(); ++i ) { QString arg = a.argv()[ i ]; if ( arg[0] != '-' ) mw->fileOpen( "", "", arg ); } return a.exec(); }
void macro_test(void) { printf("macro:\n"); pf("N=%d\n", N); printf("aaa=%d\n", AAA); printf("min=%d\n", min(1, min(2, -1))); printf("s1=%s\n", glue(HIGH, LOW)); printf("s2=%s\n", xglue(HIGH, LOW)); printf("s3=%s\n", str("c")); printf("s4=%s\n", str(a1)); printf("B3=%d\n", B3); #ifdef A printf("A defined\n"); #endif #ifdef B printf("B defined\n"); #endif #ifdef A printf("A defined\n"); #else printf("A not defined\n"); #endif #ifdef B printf("B defined\n"); #else printf("B not defined\n"); #endif #ifdef A printf("A defined\n"); #ifdef B printf("B1 defined\n"); #else printf("B1 not defined\n"); #endif #else printf("A not defined\n"); #ifdef B printf("B2 defined\n"); #else printf("B2 not defined\n"); #endif #endif #if 1+1 printf("test true1\n"); #endif #if 0 printf("test true2\n"); #endif #if 1-1 printf("test true3\n"); #endif #if defined(A) printf("test trueA\n"); #endif #if defined(B) printf("test trueB\n"); #endif #if 0 printf("test 0\n"); #elif 0 printf("test 1\n"); #elif 2 printf("test 2\n"); #else printf("test 3\n"); #endif MACRO_NOARGS(); #ifdef __LINE__ printf("__LINE__ defined\n"); #endif printf("__LINE__=%d __FILE__=%s\n", __LINE__, __FILE__); #line 200 printf("__LINE__=%d __FILE__=%s\n", __LINE__, __FILE__); #line 203 "test" printf("__LINE__=%d __FILE__=%s\n", __LINE__, __FILE__); #line 227 "tcctest.c" /* not strictly preprocessor, but we test it there */ #ifdef C99_MACROS printf("__func__ = %s\n", __func__); dprintf(1, "vaarg=%d\n", 1); #endif dprintf1(1, "vaarg1\n"); dprintf1(1, "vaarg1=%d\n", 2); dprintf1(1, "vaarg1=%d %d\n", 1, 2); /* gcc extension */ printf("func='%s'\n", __FUNCTION__); /* complicated macros in glibc */ printf("INT64_MIN=%Ld\n", INT64_MIN); { int a; a = 1; glue(a+, +); printf("a=%d\n", a); glue(a <, <= 2); printf("a=%d\n", a); } /* macro function with argument outside the macro string */ #define MF_s MF_hello #define MF_hello(msg) printf("%s\n",msg) #define MF_t printf("tralala\n"); MF_hello MF_s("hi"); MF_t("hi"); /* test macro substituion inside args (should not eat stream) */ printf("qq=%d\n", qq(qq)(2)); /* test zero argument case. NOTE: gcc 2.95.x does not accept a null argument without a space. gcc 3.2 fixes that. */ #define qq1(x) 1 printf("qq1=%d\n", qq1( )); /* comment with stray handling *\ / /* this is a valid *\/ comment */ /* this is a valid comment *\*/ // this is a valid\ comment /* test function macro substitution when the function name is substituted */ TEST2(); }
void testConvolutionAndPool() { if (true) { const int filterDim = 8; const int imageDim = 28; const int poolDim = 3; const int numFilters = 100; const int outputDim = (imageDim - filterDim + 1) / poolDim; RandomFilterFunction rff(filterDim, numFilters); rff.configure(); SigmoidFunction sf; ConvolutionFunction cf(&rff, &sf); MeanPoolFunction pf(numFilters, outputDim); //MeanPoolFunction mpf; Eigen::Vector2i configImageDim; configImageDim << imageDim, imageDim; MNISTDataFunction mnistdf; Config config; updateMNISTConfig(config); config.setValue("addBiasTerm", false); config.setValue("meanStddNormalize", false); mnistdf.configure(&config); Convolutions* convolvedFeatures = nullptr; for (int i = 0; i < 13; ++i) convolvedFeatures = cf.conv(mnistdf.getTrainingX().topRows<199>(), configImageDim); assert(convolvedFeatures->unordered_map.size() == 199); for (auto i = convolvedFeatures->unordered_map.begin(); i != convolvedFeatures->unordered_map.end(); ++i) assert((int )i->second.size() == rff.getWeights().cols()); // Validate convoluations Matrix_t ConvImages = mnistdf.getTrainingX().topRows<8>(); for (int i = 0; i < 1000; ++i) { const int filterNum = rand() % rff.getWeights().cols(); const int imageNum = rand() % 8; const int imageRow = rand() % (configImageDim(0) - rff.getConfig()(0) + 1); const int imageCol = rand() % (configImageDim(1) - rff.getConfig()(1) + 1); Vector_t im = ConvImages.row(imageNum); Eigen::Map<Matrix_t> Image(im.data(), configImageDim(0), configImageDim(1)); Matrix_t Patch = Image.block(imageRow, imageCol, rff.getConfig()(0), rff.getConfig()(1)); // Filter Eigen::Map<Matrix_t> W(rff.getWeights().col(filterNum).data(), rff.getConfig()(0), rff.getConfig()(1)); const double b = rff.getBiases()(filterNum); double feature = Patch.cwiseProduct(W).sum() + b; feature = 1.0f / (1.0f + exp(-feature)); if (fabs( feature - convolvedFeatures->unordered_map[imageNum][filterNum]->X(imageRow, imageCol)) > 1e-9) { std::cout << "Convolved feature does not match test feature: " << i << std::endl; std::cout << "Filter Number: " << filterNum << std::endl; std::cout << "Image Number: " << imageNum << std::endl; std::cout << "Image Row: " << imageRow << std::endl; std::cout << "Image Col: " << imageCol << std::endl; std::cout << "Convolved feature: " << convolvedFeatures->unordered_map[imageNum][filterNum]->X(imageRow, imageCol) << std::endl; std::cout << "Test feature: " << feature << std::endl; std::cout << "Convolved feature does not match test feature" << std::endl; exit(EXIT_FAILURE); } } // Pool Poolings* pooling = nullptr; for (int i = 0; i < 13; ++i) pooling = pf.pool(convolvedFeatures, poolDim); assert((int )pooling->unordered_map.size() == 199); for (auto iter = pooling->unordered_map.begin(); iter != pooling->unordered_map.end(); ++iter) { assert(iter->second.size() == (size_t )rff.getWeights().cols()); for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) { assert(iter2->second->X.rows() == (configImageDim(0) - rff.getConfig()(0) + 1) / 3); assert(iter2->second->X.rows() == 7); assert(iter2->second->X.cols() == (configImageDim(0) - rff.getConfig()(0) + 1) / 3); assert(iter2->second->X.cols() == 7); } } } if (true) { // test pool function Vector_t testVec(64); for (int i = 0; i < testVec.size(); ++i) testVec(i) = i + 1; Eigen::Map<Matrix_t> TestMatrix(testVec.data(), 8, 8); std::cout << "TestMatrix: " << std::endl; std::cout << TestMatrix << std::endl; Matrix_t ExpectedMatrix(2, 2); ExpectedMatrix(0, 0) = TestMatrix.block(0, 0, 4, 4).array().mean(); ExpectedMatrix(0, 1) = TestMatrix.block(0, 4, 4, 4).array().mean(); ExpectedMatrix(1, 0) = TestMatrix.block(4, 0, 4, 4).array().mean(); ExpectedMatrix(1, 1) = TestMatrix.block(4, 4, 4, 4).array().mean(); std::cout << "Expected: " << std::endl; std::cout << ExpectedMatrix << std::endl; Convolutions cfs; Convolution xcf; xcf.X = TestMatrix; cfs.unordered_map[0].insert(std::make_pair(0, (&xcf))); MeanPoolFunction testMpf(1, 2); Poolings* pfs = testMpf.pool(&cfs, 4); assert(pfs->unordered_map.size() == 1); assert(pfs->unordered_map[0].size() == 1); Matrix_t PX = pfs->unordered_map[0][0]->X; std::cout << "Obtain: " << std::endl; std::cout << PX << std::endl; } }
static void BLOrace(raceC* r) { if(race) delete race; race = r; if(race) pf("race: %s\n", race->Name); }
/* startpos: translate_dir: unit vector with only one of x, y or z face_dir: unit vector with only one of x, y or z */ static void updateFastFaceRow( MeshMakeData *data, v3s16 startpos, v3s16 translate_dir, v3f translate_dir_f, v3s16 face_dir, v3f face_dir_f, core::array<FastFace> &dest) { v3s16 p = startpos; u16 continuous_tiles_count = 0; bool makes_face = false; v3s16 p_corrected; v3s16 face_dir_corrected; u16 lights[4] = {0,0,0,0}; TileSpec tile; getTileInfo(data, p, face_dir, makes_face, p_corrected, face_dir_corrected, lights, tile); for(u16 j=0; j<MAP_BLOCKSIZE; j++) { // If tiling can be done, this is set to false in the next step bool next_is_different = true; v3s16 p_next; bool next_makes_face = false; v3s16 next_p_corrected; v3s16 next_face_dir_corrected; u16 next_lights[4] = {0,0,0,0}; TileSpec next_tile; // If at last position, there is nothing to compare to and // the face must be drawn anyway if(j != MAP_BLOCKSIZE - 1) { p_next = p + translate_dir; getTileInfo(data, p_next, face_dir, next_makes_face, next_p_corrected, next_face_dir_corrected, next_lights, next_tile); if(next_makes_face == makes_face && next_p_corrected == p_corrected + translate_dir && next_face_dir_corrected == face_dir_corrected && next_lights[0] == lights[0] && next_lights[1] == lights[1] && next_lights[2] == lights[2] && next_lights[3] == lights[3] && next_tile == tile) { next_is_different = false; } else{ /*if(makes_face){ g_profiler->add("Meshgen: diff: next_makes_face != makes_face", next_makes_face != makes_face ? 1 : 0); g_profiler->add("Meshgen: diff: n_p_corr != p_corr + t_dir", (next_p_corrected != p_corrected + translate_dir) ? 1 : 0); g_profiler->add("Meshgen: diff: next_f_dir_corr != f_dir_corr", next_face_dir_corrected != face_dir_corrected ? 1 : 0); g_profiler->add("Meshgen: diff: next_lights[] != lights[]", (next_lights[0] != lights[0] || next_lights[0] != lights[0] || next_lights[0] != lights[0] || next_lights[0] != lights[0]) ? 1 : 0); g_profiler->add("Meshgen: diff: !(next_tile == tile)", !(next_tile == tile) ? 1 : 0); }*/ } /*g_profiler->add("Meshgen: Total faces checked", 1); if(makes_face) g_profiler->add("Meshgen: Total makes_face checked", 1);*/ } else { /*if(makes_face) g_profiler->add("Meshgen: diff: last position", 1);*/ } continuous_tiles_count++; // This is set to true if the texture doesn't allow more tiling bool end_of_texture = false; /* If there is no texture, it can be tiled infinitely. If tiled==0, it means the texture can be tiled infinitely. Otherwise check tiled agains continuous_tiles_count. */ if(tile.texture.atlas != NULL && tile.texture.tiled != 0) { if(tile.texture.tiled <= continuous_tiles_count) end_of_texture = true; } // Do this to disable tiling textures //end_of_texture = true; //DEBUG if(next_is_different || end_of_texture) { /* Create a face if there should be one */ if(makes_face) { // Floating point conversion of the position vector v3f pf(p_corrected.X, p_corrected.Y, p_corrected.Z); // Center point of face (kind of) v3f sp = pf - ((f32)continuous_tiles_count / 2. - 0.5) * translate_dir_f; if(continuous_tiles_count != 1) sp += translate_dir_f; v3f scale(1,1,1); if(translate_dir.X != 0) { scale.X = continuous_tiles_count; } if(translate_dir.Y != 0) { scale.Y = continuous_tiles_count; } if(translate_dir.Z != 0) { scale.Z = continuous_tiles_count; } makeFastFace(tile, lights[0], lights[1], lights[2], lights[3], sp, face_dir_corrected, scale, dest); g_profiler->avg("Meshgen: faces drawn by tiling", 0); for(int i=1; i<continuous_tiles_count; i++){ g_profiler->avg("Meshgen: faces drawn by tiling", 1); } } continuous_tiles_count = 0; makes_face = next_makes_face; p_corrected = next_p_corrected; face_dir_corrected = next_face_dir_corrected; lights[0] = next_lights[0]; lights[1] = next_lights[1]; lights[2] = next_lights[2]; lights[3] = next_lights[3]; tile = next_tile; } p = p_next; } }
virtual void on_draw() { pixfmt pf(rbuf_window()); renderer_base ren_base(pf); ren_base.clear(agg::rgba(0.5, 0.75, 0.85)); renderer_scanline ren(ren_base); rasterizer_scanline ras; scanline sl; ras.clip_box(0, 0, width(), height()); // Pattern source. Must have an interface: // width() const // height() const // pixel(int x, int y) const // Any agg::renderer_base<> or derived // is good for the use as a source. //----------------------------------- pattern_src_brightness_to_alpha_rgba8 p1(rbuf_img(0)); agg::pattern_filter_bilinear_rgba8 fltr; // Filtering functor // agg::line_image_pattern is the main container for the patterns. It creates // a copy of the patterns extended according to the needs of the filter. // agg::line_image_pattern can operate with arbitrary image width, but if the // width of the pattern is power of 2, it's better to use the modified // version agg::line_image_pattern_pow2 because it works about 15-25 percent // faster than agg::line_image_pattern (because of using simple masking instead // of expensive '%' operation). typedef agg::line_image_pattern<agg::pattern_filter_bilinear_rgba8> pattern_type; typedef agg::renderer_base<pixfmt> base_ren_type; typedef agg::renderer_outline_image<base_ren_type, pattern_type> renderer_img_type; typedef agg::rasterizer_outline_aa<renderer_img_type, agg::line_coord_sat> rasterizer_img_type; typedef agg::renderer_outline_aa<base_ren_type> renderer_line_type; typedef agg::rasterizer_outline_aa<renderer_line_type, agg::line_coord_sat> rasterizer_line_type; //-- Create with specifying the source //pattern_type patt(fltr, src); //-- Create uninitialized and set the source pattern_type patt(fltr); patt.create(p1); renderer_img_type ren_img(ren_base, patt); rasterizer_img_type ras_img(ren_img); //-- create uninitialized and set parameters agg::line_profile_aa profile; profile.smoother_width(10.0); //optional profile.width(8.0); //mandatory! renderer_line_type ren_line(ren_base, profile); ren_line.color(agg::rgba8(0,0,127)); //mandatory! rasterizer_line_type ras_line(ren_line); ras_line.round_cap(true); //optional //ras_line.line_join(agg::outline_no_join); //optional // Calculate the dilation value so that, the line caps were // drawn correctly. //--------------- double w2 = 9.0;//p1.height() / 2 + 2; // Set the clip box a bit bigger than you expect. You need it // to draw the clipped line caps correctly. The correct result // is achieved with raster clipping. //------------------------ ren_img.scale_x(m_scale_x.value()); ren_img.start_x(m_start_x.value()); ren_img.clip_box (50-w2, 50-w2, width()-50+w2, height()-50+w2); ren_line.clip_box(50-w2, 50-w2, width()-50+w2, height()-50+w2); // First, draw polyline without raster clipping just to show the idea //------------------------ draw_polyline(ras_line, ren_line, m_line1.polygon(), m_line1.num_points()); draw_polyline(ras_img, ren_img, m_line1.polygon(), m_line1.num_points()); // Clear the area, almost opaque, but not completely //------------------------ ren_base.blend_bar(0, 0, (int)width(), (int)height(), agg::rgba(1,1,1), 200); // Set the raster clip box and then, draw again. // In reality there shouldn't be two calls above. // It's done only for demonstration //------------------------ ren_base.clip_box((int)50, (int)50, (int)width()-50, (int)height()-50); // This "copy_bar" is also for demonstration only //------------------------ ren_base.copy_bar(0, 0, (int)width(), (int)height(), agg::rgba(1,1,1)); // Finally draw polyline correctly clipped: We use double clipping, // first is vector clipping, with extended clip box, second is raster // clipping with normal clip box. //------------------------ ren_img.scale_x(m_scale_x.value()); ren_img.start_x(m_start_x.value()); draw_polyline(ras_line, ren_line, m_line1.polygon(), m_line1.num_points()); draw_polyline(ras_img, ren_img, m_line1.polygon(), m_line1.num_points()); // Reset clipping and draw the controls and stuff ren_base.reset_clipping(true); m_line1.line_width(1/m_scale.scale()); m_line1.point_radius(5/m_scale.scale()); agg::render_ctrl(ras, sl, ren_base, m_line1); agg::render_ctrl(ras, sl, ren_base, m_scale_x); agg::render_ctrl(ras, sl, ren_base, m_start_x); char buf[256]; agg::gsv_text t; t.size(10.0); agg::conv_stroke<agg::gsv_text> pt(t); pt.width(1.5); pt.line_cap(agg::round_cap); const double* p = m_line1.polygon(); sprintf(buf, "Len=%.2f", agg::calc_distance(p[0], p[1], p[2], p[3]) * m_scale.scale()); t.start_point(10.0, 30.0); t.text(buf); ras.add_path(pt); ren.color(agg::rgba(0,0,0)); agg::render_scanlines(ras, sl, ren); }
void Bras::in_state_func() { switch (state) { case RANGE_DEPART : scr(); a0(); spb(); pf(); break; case INT_RANGE : //va bumper scn(); a0(); spb(); pf(); break; case INT2_RANGE : set_time_out(400, trigger_to_be); scn(); a0(); spb(); pf(); break; case GO_ATTENTE : scn(); a1(); spb(); pf(); break; case ATTENTE_ACTIF : scn(); a1(); spb(); pf(); break; case DESCENTE_LAT : scn(); a4(); spb(); pf(); break; case DESCENTE_POMPE_LAT : scn(); a4(); spb(); po(); break; case PRISE_LAT : scn(); a4(); spb(); po(); break; case MONTE_VERT : set_time_out(500, TIME_OUT); scn(); a0(); spv(); po(); break; case MONTE : scn(); a0(); spb(); po(); break; case RANGE_PRISE : set_time_out(2000, TIME_OUT); scl(); a0(); spb(); po(); break; case LACHE : set_time_out(300, TIME_OUT); scl(); a0(); spb(); pf(); break; case MONTE_ECH : scn(); a3(); spb(); po(); break; case MONTE_ECH_VERT : sce(); a3(); spr(); po(); break; case RETOURNE_ECH : call_for_help(); sce(); a3(); spr(); po(); break; case REPLACE_APRES_ECH : set_time_out(300, TIME_OUT); scn(); a3(); spb(); pf(); break; case SEND_MINE : scv(); a4(); spv(); pf(); break; case SENDMASTER_PRET : scv(); a4(); spv(); po(); break; case PRISE_VERT : scv(); a4(); spv(); po(); break; case PRISE_COPAIN : a2(); sce(); spb(); po(); break; } }
void TPZNonDarcyFlow::Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix<STATE> &ek, TPZFMatrix<STATE> &ef) { TPZFMatrix<STATE> &phi = data.phi; TPZFMatrix<STATE> &dphia = data.dphix; TPZManVector<REAL,3> &x = data.x; const int nphi = phi.Rows(); const REAL r = x[0]; const REAL pir2 = 2.*M_PI*r; TPZFMatrix<STATE> &axes = data.axes; TPZFMatrix<STATE> dphi; TPZAxesTools<STATE>::Axes2XYZ(dphia,dphi,axes); if (globData.fState == ELastState){ REAL dpdr = data.dsol[0](0,0); REAL rho, por; REAL p = data.sol[0][0]; this->ReturnPor(p,por); this->ReturnRho(p,rho); REAL dt = globData.fDeltaT; for (int i = 0 ; i < nphi ; i++){ REAL res = - rho / dt * phi(i,0) * por * pir2; ef(i,0) += - 1. * res * weight; } } else if (globData.fState == ECurrentState){ VarFad pf(data.sol[0][0],0); VarFad dpdrf(data.dsol[0](0,0),1); VarFad dpdzf(data.dsol[0](1,0),2); VarFad rhof, porf, muf; REAL kh,kv; this->ReturnPor(pf,porf); this->ReturnRho(pf,rhof); this->ReturnVisc(pf,muf); kh = globData.fKh; kv = globData.fKv; REAL dt = globData.fDeltaT; //REAL g = globData.Gravity(); for (int i = 0 ; i < nphi ; i++){ VarFad resfad = (kh/muf * rhof * dpdrf * dphi(0,i) * pir2) + (kv/muf * rhof * (dpdzf /*+ rhof*g*/) * dphi(1,i) * pir2); resfad += rhof / dt * phi(i,0) * porf * pir2; REAL res = -1.*weight*resfad.val(); ef(i,0) += res; const REAL dRdp = resfad.dx(0); const REAL dRdpdr = resfad.dx(1); const REAL dRdpdz = resfad.dx(2); for (int j = 0 ; j < nphi ; j++){ REAL fadStiff = dRdp * phi(j,0) + dRdpdr * dphi(0,j)+ dRdpdz * dphi(1,j); ek(i,j) += fadStiff * weight; } } } else { DebugStop(); // why no state????? } }
void f() { pointmemfun pmf(0); // { dg-warning "zero as null pointer" } pointdmem pdm(0); // { dg-warning "zero as null pointer" } pointfun pf(0); // { dg-warning "zero as null pointer" } int* p(0); // { dg-warning "zero as null pointer" } pointmemfun pmfn(nullptr); pointdmem pdmn(nullptr); pointfun pfn(nullptr); int* pn(nullptr); pmf = 0; // { dg-warning "zero as null pointer" } pdm = 0; // { dg-warning "zero as null pointer" } pf = 0; // { dg-warning "zero as null pointer" } p = 0; // { dg-warning "zero as null pointer" } pmf = nullptr; pdm = nullptr; pf = nullptr; p = nullptr; if (pmf) ; if (pdm) ; if (pf) ; if (p) ; if (!pmf) ; if (!pdm) ; if (!pf) ; if (!p) ; if (pmf == 0) // { dg-warning "zero as null pointer" } ; if (pdm == 0) // { dg-warning "zero as null pointer" } ; if (pf == 0) // { dg-warning "zero as null pointer" } ; if (p == 0) // { dg-warning "zero as null pointer" } ; if (0 == pmf) // { dg-warning "zero as null pointer" } ; if (0 == pdm) // { dg-warning "zero as null pointer" } ; if (0 == pf) // { dg-warning "zero as null pointer" } ; if (0 == p) // { dg-warning "zero as null pointer" } ; if (pmf != 0) // { dg-warning "zero as null pointer" } ; if (pdm != 0) // { dg-warning "zero as null pointer" } ; if (pf != 0) // { dg-warning "zero as null pointer" } ; if (p != 0) // { dg-warning "zero as null pointer" } ; if (0 != pmf) // { dg-warning "zero as null pointer" } ; if (0 != pdm) // { dg-warning "zero as null pointer" } ; if (0 != pf) // { dg-warning "zero as null pointer" } ; if (0 != p) // { dg-warning "zero as null pointer" } ; if (pmf == nullptr) ; if (pdm == nullptr) ; if (pf == nullptr) ; if (p == nullptr) ; if (nullptr == pmf) ; if (nullptr == pdm) ; if (nullptr == pf) ; if (nullptr == p) ; if (pmf != nullptr) ; if (pdm != nullptr) ; if (pf != nullptr) ; if (p != nullptr) ; if (nullptr != pmf) ; if (nullptr != pdm) ; if (nullptr != pf) ; if (nullptr != p) ; }
int main (int argc, char *argv[]) { pf ("/* This file is automatically generated --" " see configure.in for details */\n" "\n" "#ifndef SCM_SCMCONFIG_H\n" "#define SCM_SCMCONFIG_H\n"); /*** various important headers ***/ pf ("\n"); pf ("/* Important headers */\n"); if (SCM_I_GSC_NEEDS_STDINT_H) pf ("#include <stdint.h>\n"); if (SCM_I_GSC_NEEDS_INTTYPES_H) pf ("#include <inttypes.h>\n"); #ifdef HAVE_LIMITS_H pf ("#include <limits.h>\n"); #else pf ("/* limits.h not available */\n"); #endif # ifdef TIME_WITH_SYS_TIME pf ("#include <sys/time.h>\n"); pf ("#include <time.h>\n"); # else # ifdef HAVE_SYS_TIME_H pf ("#include <sys/time.h>\n"); # else # ifdef HAVE_TIME_H pf ("#include <time.h>\n"); # endif # endif # endif pf("\n"); #ifdef STDC_HEADERS pf ("#define SCM_HAVE_STDC_HEADERS 1 /* 0 or 1 */\n"); pf ("#include <stdlib.h>\n"); # ifdef HAVE_SYS_TYPES_H pf ("#include <sys/types.h>\n"); # endif # ifdef HAVE_SYS_STDTYPES_H pf ("#include <sys/stdtypes.h>\n"); # endif pf ("#include <stddef.h>\n"); #else /* STDC_HEADERS */ pf ("#define SCM_HAVE_STDC_HEADERS 0 /* 0 or 1 */"); #endif /* def STDC_HEADERS */ pf("\n"); #ifdef HAVE_SYS_SELECT_H pf ("#define SCM_HAVE_SYS_SELECT_H 1 /* 0 or 1 */\n"); #else pf ("#define SCM_HAVE_SYS_SELECT_H 0 /* 0 or 1 */\n"); #endif #ifdef HAVE_WINSOCK2_H pf ("#define SCM_HAVE_WINSOCK2_H 1 /* 0 or 1 */\n"); #else pf ("#define SCM_HAVE_WINSOCK2_H 0 /* 0 or 1 */\n"); #endif /*** GUILE_DEBUG (defined or undefined) ***/ pf ("\n"); pf ("/* Define to include various undocumented debugging functions. */\n"); if (SCM_I_GSC_GUILE_DEBUG) pf ("#define GUILE_DEBUG 1 /* defined or undefined */\n"); else pf ("/* #undef GUILE_DEBUG */\n"); /*** SCM_ENABLE_DEPRECATED (0 or 1) ***/ pf ("\n"); pf ("/* Set to 1 if you want to enable deprecated features. */\n"); pf ("/* (value will be 0 or 1). */\n"); pf ("#define SCM_ENABLE_DEPRECATED %d\n", SCM_I_GSC_ENABLE_DEPRECATED); /*** SCM_STACK_GROWS_UP (0 or 1) ***/ pf ("\n"); pf ("/* Set to 1 if the stack grows up, 0 otherwise. */\n"); pf ("#define SCM_STACK_GROWS_UP %d /* 0 or 1 */\n", SCM_I_GSC_STACK_GROWS_UP); /*** SCM_C_INLINE (defined to appropriate string or undefined) ***/ pf ("\n"); pf ("/* C compiler's syntax for inline functions if any,\n" " otherwise undefined. */\n"); if (SCM_I_GSC_C_INLINE) pf ("#define SCM_C_INLINE %s\n", SCM_I_GSC_C_INLINE); else pf ("/* #undef SCM_C_INLINE */\n"); pf ("\n"); pf ("/* Standard types. */\n"); pf ("/* These are always defined */\n"); pf ("#define SCM_SIZEOF_CHAR %d\n", SIZEOF_CHAR); pf ("#define SCM_SIZEOF_UNSIGNED_CHAR %d\n", SIZEOF_UNSIGNED_CHAR); pf ("#define SCM_SIZEOF_SHORT %d\n", SIZEOF_SHORT); pf ("#define SCM_SIZEOF_UNSIGNED_SHORT %d\n", SIZEOF_UNSIGNED_SHORT); pf ("#define SCM_SIZEOF_LONG %d\n", SIZEOF_LONG); pf ("#define SCM_SIZEOF_UNSIGNED_LONG %d\n", SIZEOF_UNSIGNED_LONG); pf ("#define SCM_SIZEOF_INT %d\n", SIZEOF_INT); pf ("#define SCM_SIZEOF_UNSIGNED_INT %d\n", SIZEOF_UNSIGNED_INT); pf ("#define SCM_SIZEOF_SIZE_T %d\n", SIZEOF_SIZE_T); pf ("\n"); pf ("/* Size of (unsigned) long long or 0 if not available (scm_t_*64 may\n" " be more likely to be what you want */\n"); pf ("#define SCM_SIZEOF_LONG_LONG %d\n", SIZEOF_LONG_LONG); pf ("#define SCM_SIZEOF_UNSIGNED_LONG_LONG %d\n", SIZEOF_UNSIGNED_LONG_LONG); pf ("\n"); pf ("/* These are always defined. */\n"); pf ("typedef %s scm_t_int8;\n", SCM_I_GSC_T_INT8); pf ("typedef %s scm_t_uint8;\n", SCM_I_GSC_T_UINT8); pf ("typedef %s scm_t_int16;\n", SCM_I_GSC_T_INT16); pf ("typedef %s scm_t_uint16;\n", SCM_I_GSC_T_UINT16); pf ("typedef %s scm_t_int32;\n", SCM_I_GSC_T_INT32); pf ("typedef %s scm_t_uint32;\n", SCM_I_GSC_T_UINT32); pf ("typedef %s scm_t_intmax;\n", SCM_I_GSC_T_INTMAX); pf ("typedef %s scm_t_uintmax;\n", SCM_I_GSC_T_UINTMAX); pf ("typedef %s scm_t_intptr;\n", SCM_I_GSC_T_INTPTR); pf ("typedef %s scm_t_uintptr;\n", SCM_I_GSC_T_UINTPTR); if (0 == strcmp ("intmax_t", SCM_I_GSC_T_INTMAX)) pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_INTMAX_T); else if (0 == strcmp ("long long", SCM_I_GSC_T_INTMAX)) pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_LONG_LONG); else if (0 == strcmp ("__int64", SCM_I_GSC_T_INTMAX)) pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF___INT64); else return 1; pf ("\n"); pf ("#define SCM_HAVE_T_INT64 1 /* 0 or 1 */\n"); pf ("typedef %s scm_t_int64;\n", SCM_I_GSC_T_INT64); pf ("#define SCM_HAVE_T_UINT64 1 /* 0 or 1 */\n"); pf ("typedef %s scm_t_uint64;\n", SCM_I_GSC_T_UINT64); pf ("\n"); pf ("/* scm_t_ptrdiff_t and size, always defined -- defined to long if\n" " platform doesn't have ptrdiff_t. */\n"); pf ("typedef %s scm_t_ptrdiff;\n", SCM_I_GSC_T_PTRDIFF); if (0 == strcmp ("long", SCM_I_GSC_T_PTRDIFF)) pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_LONG); else pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_PTRDIFF_T); pf ("\n"); pf ("/* Size of intptr_t or 0 if not available */\n"); pf ("#define SCM_SIZEOF_INTPTR_T %d\n", SIZEOF_INTPTR_T); pf ("/* Size of uintptr_t or 0 if not available */\n"); pf ("#define SCM_SIZEOF_UINTPTR_T %d\n", SIZEOF_UINTPTR_T); pf ("\n"); pf ("/* same as POSIX \"struct timespec\" -- always defined */\n"); #ifdef HAVE_STRUCT_TIMESPEC pf ("typedef struct timespec scm_t_timespec;\n"); #else pf ("/* POSIX.4 structure for a time value. This is like a `struct timeval'" " but has nanoseconds instead of microseconds. */\n"); pf ("typedef struct\n" "{\n" " long int tv_sec; /* Seconds. */\n" " long int tv_nsec; /* Nanoseconds. */\n" "} scm_t_timespec;\n"); #endif pf ("\n"); pf ("/*** Threading model (scmconfig.h support not finished) ***/\n"); pf ("/* Define to 1 if using pthread multithreading. */\n"); pf ("#define SCM_USE_PTHREAD_THREADS %d /* 0 or 1 */\n", SCM_I_GSC_USE_PTHREAD_THREADS); pf ("/* Define to 1 if using one-thread 'multi'threading. */\n"); pf ("#define SCM_USE_NULL_THREADS %d /* 0 or 1 */\n", SCM_I_GSC_USE_NULL_THREADS); pf ("/* Define to 1 if need braces around PTHREAD_ONCE_INIT (for Solaris). */\n"); pf ("#define SCM_NEED_BRACES_ON_PTHREAD_ONCE_INIT %d /* 0 or 1 */\n", SCM_I_GSC_NEED_BRACES_ON_PTHREAD_ONCE_INIT); pf ("/* Define to 1 if need braces around PTHREAD_MUTEX_INITIALIZER\n" " (for IRIX with GCC) */\n"); pf ("#define SCM_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER %d /* 0 or 1 */\n", SCM_I_GSC_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER); #ifdef HAVE_GC_PTHREAD_CANCEL pf ("#define SCM_HAVE_GC_PTHREAD_CANCEL 1 /* 0 or 1 */\n"); #else pf ("#define SCM_HAVE_GC_PTHREAD_CANCEL 0 /* 0 or 1 */\n"); #endif #ifdef HAVE_GC_PTHREAD_EXIT pf ("#define SCM_HAVE_GC_PTHREAD_EXIT 1 /* 0 or 1 */\n"); #else pf ("#define SCM_HAVE_GC_PTHREAD_EXIT 0 /* 0 or 1 */\n"); #endif #ifdef HAVE_GC_PTHREAD_SIGMASK pf ("#define SCM_HAVE_GC_PTHREAD_SIGMASK 1 /* 0 or 1 */\n"); #else pf ("#define SCM_HAVE_GC_PTHREAD_SIGMASK 0 /* 0 or 1 */\n"); #endif pf ("\n\n/*** File system access ***/\n"); pf ("/* Define to 1 if `struct dirent64' is available. */\n"); pf ("#define SCM_HAVE_STRUCT_DIRENT64 %d /* 0 or 1 */\n", SCM_I_GSC_HAVE_STRUCT_DIRENT64); pf ("/* Define to 1 if `readdir64_r ()' is available. */\n"); #ifdef HAVE_READDIR64_R pf ("#define SCM_HAVE_READDIR64_R 1 /* 0 or 1 */\n"); #else pf ("#define SCM_HAVE_READDIR64_R 0 /* 0 or 1 */\n"); #endif /* Arrange so that we have a file offset type that reflects the one used when compiling Guile, regardless of what the application's `_FILE_OFFSET_BITS' says. See http://lists.gnu.org/archive/html/bug-guile/2009-06/msg00018.html for the original bug report. Note that we can't define `scm_t_off' in terms of `off_t' or `off64_t' because they may or may not be available depending on how the application that uses Guile is compiled. */ #if defined GUILE_USE_64_CALLS && defined HAVE_STAT64 pf ("typedef scm_t_int64 scm_t_off;\n"); #elif SIZEOF_OFF_T == SIZEOF_INT pf ("typedef int scm_t_off;\n"); #else pf ("typedef long int scm_t_off;\n"); #endif pf ("/* Define to 1 if the compiler supports the " "`__thread' storage class. */\n"); if (SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS) pf ("#define SCM_HAVE_THREAD_STORAGE_CLASS\n"); else pf ("/* #undef SCM_HAVE_THREAD_STORAGE_CLASS */\n"); #ifdef USE_DLL_IMPORT pf ("\n"); pf ("/* Define some additional CPP macros on Win32 platforms. */\n"); pf ("# define __REGEX_IMPORT__ 1\n"); pf ("# define __CRYPT_IMPORT__ 1\n"); pf ("# define __READLINE_IMPORT__ 1\n"); pf ("# define QT_IMPORT 1\n"); #endif pf ("\n"); pf ("#define SCM_HAVE_ARRAYS 1 /* always true now */\n"); pf ("\n"); pf ("/* Constants from uniconv.h. */\n"); pf ("#define SCM_ICONVEH_ERROR %d\n", SCM_I_GSC_ICONVEH_ERROR); pf ("#define SCM_ICONVEH_QUESTION_MARK %d\n", SCM_I_GSC_ICONVEH_QUESTION_MARK); pf ("#define SCM_ICONVEH_ESCAPE_SEQUENCE %d\n", SCM_I_GSC_ICONVEH_ESCAPE_SEQUENCE); printf ("#endif\n"); return 0; }
void ConsoleTools::genOutput(bool useTokens){ try{ // Source file text lines store. TextLinesStore textLinesStore; textLinesStore.loadFile(inputFileName, inputEncoding, true); // parsers factory ParserFactory pf(catalogPath); // HRC loading HRCParser *hrcParser = pf.getHRCParser(); // HRD RegionMapper creation bool useMarkup = false; RegionMapper *mapper = null; if (!useTokens){ try{ mapper = pf.createStyledMapper(&DString("rgb"), hrdName); }catch(ParserFactoryException &){ useMarkup = true; mapper = pf.createTextMapper(hrdName); } } // Base editor to make primary parse BaseEditor baseEditor(&pf, &textLinesStore); // Using compact regions baseEditor.setRegionCompact(true); baseEditor.setRegionMapper(mapper); baseEditor.lineCountEvent(textLinesStore.getLineCount()); // Choosing file type FileType *type = selectType(hrcParser, &textLinesStore); baseEditor.setFileType(type); // writing result into HTML colored stream... const RegionDefine *rd = null; if (mapper != null) rd = baseEditor.rd_def_Text; Writer *escapedWriter = null; Writer *commonWriter = null; try{ if (outputFileName != null) commonWriter = new FileWriter(outputFileName, outputEncodingIndex, bomOutput); else commonWriter = new StreamWriter(stdout, outputEncodingIndex, bomOutput); if (htmlEscaping) escapedWriter = new HtmlEscapesWriter(commonWriter); else escapedWriter = commonWriter; }catch(Exception &e){ fprintf(stderr, "can't open file '%s' for writing:\n", outputFileName->getChars()); fprintf(stderr, e.getMessage()->getChars()); return; } if (htmlWrapping && useTokens){ commonWriter->write(DString("<html>\n<head>\n<style></style>\n</head>\n<body><pre>\n")); }else if (htmlWrapping && rd != null){ if (useMarkup){ commonWriter->write(TextRegion::cast(rd)->stext); }else{ commonWriter->write(DString("<html><body style='")); ParsedLineWriter::writeStyle(commonWriter, StyledRegion::cast(rd)); commonWriter->write(DString("'><pre>\n")); } } if (copyrightHeader){ commonWriter->write(DString("Created with colorer-take5 library. Type '")); commonWriter->write(type->getName()); commonWriter->write(DString("'\n\n")); } int lni = 0; int lwidth = 1; int lncount = textLinesStore.getLineCount(); for(lni = lncount/10; lni > 0; lni = lni/10, lwidth++); for(int i = 0; i < lncount; i++){ if (lineNumbers){ int iwidth = 1; for(lni = i/10; lni > 0; lni = lni/10, iwidth++); for(lni = iwidth; lni < lwidth; lni++) commonWriter->write(0x0020); commonWriter->write(SString(i)); commonWriter->write(DString(": ")); } if (useTokens){ ParsedLineWriter::tokenWrite(commonWriter, escapedWriter, docLinkHash, textLinesStore.getLine(i), baseEditor.getLineRegions(i)); }else if (useMarkup){ ParsedLineWriter::markupWrite(commonWriter, escapedWriter, docLinkHash, textLinesStore.getLine(i), baseEditor.getLineRegions(i)); }else{ ParsedLineWriter::htmlRGBWrite(commonWriter, escapedWriter, docLinkHash, textLinesStore.getLine(i), baseEditor.getLineRegions(i)); } commonWriter->write(DString("\n")); } if (htmlWrapping && useTokens){ commonWriter->write(DString("</pre></body></html>\n")); }else if (htmlWrapping && rd != null){ if (useMarkup){ commonWriter->write(TextRegion::cast(rd)->etext); }else{ commonWriter->write(DString("</pre></body></html>\n")); } } if (htmlEscaping) delete commonWriter; delete escapedWriter; delete mapper; }catch(Exception &e){ fprintf(stderr, "%s\n", e.getMessage()->getChars()); }catch(...){ fprintf(stderr, "unknown exception ...\n"); } }
int main(int argc, char** argv) { pid_t child1, child2; int do_vfork = 1; //argc == 1; int n, sum = 0; int result; char *arg[5]; char **env = NULL; char carg[10], csum[10]; if (find_dynamo_library()) printf("rio\n"); else printf("native\n"); //printf("%d %s %s %s\n", argc, argv[0], argv[1], argv[2]); if (argc < 3) { // start calculation if (2 == argc) // vfork-fib 10 n = atoi(argv[1]); else n = N; printf("parent fib(%d)=%d\n", n, fib(n)); sum = 0; } else { assert(argc == 3); // vfork-fib fib 10 n = atoi(argv[2]); sum = 0; } pf("\tfib %d\n", n); if (n <= 1) { // base case pf("base case\n"); _exit(1); } // now spawn two children arg[0] = argv[0]; arg[1] = "fib"; arg[3] = NULL; if (do_vfork) { /* default */ pf("using vfork()\n"); child1 = vfork(); } else { pf("using fork()\n"); child1 = fork(); } if (child1 < 0) { perror("ERROR on fork"); } else if (child1 == 0) { snprintf(carg, 10, "%d", n-2); arg[2] = carg; #if 0 pf("execing %d %s %s=%s %s\n", 3, arg[0], carg, arg[1], arg[2]); #endif result = execve(arg[0], arg, env); if (result < 0) perror("ERROR in execve"); } else { pid_t result; int status; int children = 2; if (do_vfork) { /* default */ pf("second child using vfork()\n"); child2 = vfork(); } else { pf("second child using fork()\n"); child2 = fork(); } if (child2 < 0) { perror("ERROR on fork"); } else if (child2 == 0) { snprintf(carg, 10, "%d", n-1); arg[2] = carg; result = execve(arg[0], arg, env); if (result < 0) perror("ERROR in execve"); } while(children > 0) { pf("parent waiting for %d children\n", children); result = wait(&status); assert(result == child2 || result == child1); assert(WIFEXITED(status)); //printf("child %d has exited with status=%d %d\n", result, status, WEXITSTATUS(status)); sum+=WEXITSTATUS(status); if (children == 2 && result == child1) pf("first child before second\n"); else pf("second child before first\n"); children--; } #if 0 result = waitpid(child2, &status, 0); assert(result == child2); assert(WIFEXITED(status)); pf("child2 has exited with status=%d %d\n", status, WEXITSTATUS(status)); sum+=WEXITSTATUS(status); pf("parent waiting for child1 %d\n", child1); result = waitpid(child1, &status, 0); assert(result == child1); assert(WIFEXITED(status)); pf("child1 has exited with status=%d %d\n", status, WEXITSTATUS(status)); sum+=WEXITSTATUS(status); #endif } #ifdef DEBUG printf("\tfib(%d)=%d [%d] %s\n", n, sum, fib(n), sum == fib(n) ? "OK" : "BAD"); #else if (argc == 1) printf("\tfib(%d)=%d [%d] %s\n", n, sum, fib(n), sum == fib(n) ? "OK" : "BAD"); #endif _exit(sum); }
/** * @function main */ int main( int argc, char* argv[] ) { double sx; double sy; double sz; double ox; double oy; double oz; double resolution; sx = 1.0; sy = 1.0; sz = 1.0; ox = 0.0; oy = 0.0; oz = 0.0; resolution = 0.0125; // Distance Field printf("Create PF Distance Field \n"); PFDistanceField pf( sx, sy, sz, resolution, ox, oy, oz ); pf.reset(); // Geometry pf.addBox( 0.2, 0.2, 0.3, 0.24, 0.24, 0.3 ); pf.addBox( 0.1, 0.1, 0.2, 0.4, 0.5, 0.4 ); // Settings parameters int cost = 10; int radius = 2; int numPaths = 3; DiversePaths dp( &pf, radius, cost ); // Set goal and start std::vector<double> goal(3); goal[0] = 0.65; goal[1] = 0.4; goal[2] = 0.6; std::vector<double> start(3); start[0] = 0.16; start[1] = 0.1; start[2] = 0.1; // Paths std::vector<std::vector<double> > midPoints; std::vector<std::vector<std::vector<double> > > paths; // Get paths float boundFactor = 2.0; int numCheckPoints = 10; time_t ts = clock(); paths = dp.getDiversePaths2( start, goal, numPaths, midPoints, boundFactor, numCheckPoints ); time_t tf = clock(); double dt = (double) ( tf - ts ) / CLOCKS_PER_SEC; printf( "** getDiversePaths2 time: %f \n", dt ); printf( "Num points: %d \n", midPoints.size() ); // Create viewer boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = createViewer(); // View the path reset_PCL_Tools_counters(); // MidPoints: View pointcloud (NOT BOTH Balls and pointcloud) // viewPoints( midPoints, viewer, 255,0,255 ); // Get checkPoint Lines int ind = 2; std::vector<std::vector<std::vector<double> > > checkLines; if( paths.size() > 1 ) { checkLines = dp.getCheckPointLines( paths[0], paths[ind], numCheckPoints ); } else { printf( " !! Only one path, no drawing checkPoint lines! \n" ); } /* for( int i = 0; i < checkLines.size(); ++i ) { viewPath( checkLines[i], viewer, 0, 0, 255 ); } */ dp.visualizePath( viewer, paths[0], true, 0, 100, 0 ); dp.visualizePath( viewer, paths[ind], true, 255, 69, 0 ); // Loop while( !viewer->wasStopped() ) { viewer->spinOnce(100); boost::this_thread::sleep( boost::posix_time::microseconds(100000)); } printf("End of program \n"); return(0); }
void Bras::stop() { pf(); asc.stop(); }
TEST(ParticleFilterTest, GeneralTest) { unsigned rank = MPI::COMM_WORLD.Get_rank(); unsigned size = MPI::COMM_WORLD.Get_size(); RWObservation* observations = new RWObservation[2]; unsigned num_of_particles = 32768; unsigned array_size = num_of_particles/size; Resampling_Method type = FullRadix; bool debug = false; ParticleFilter<RWParticle,RWState,RWObservation> pf(rank,size,num_of_particles,1,observations,type,debug); EXPECT_EQ(rank,pf.rank); EXPECT_EQ(size,pf.num_of_procs); EXPECT_EQ(num_of_particles,pf.num_of_particles); EXPECT_EQ(num_of_particles/size,pf.array_size); EXPECT_EQ(1,pf.num_of_steps); EXPECT_NEAR(-log(size),pf.ln_total_weight,1.0e-10); EXPECT_EQ(debug,pf.debug); observations[1].position = 3; EXPECT_FLOAT_EQ(3,pf.observations[1].position); EXPECT_FLOAT_EQ(-log(num_of_particles),pf.particles[5].ln_weight); double mean_x = 0; double mean_v = 0; double stdev_x = 0; double stdev_v = 0; for(int i=0; i<array_size; i++) { mean_x += pf.particles[i].state.position; mean_v += pf.particles[i].state.velocity; } mean_x /= array_size; mean_v /= array_size; for(int i=0; i<array_size; i++) { stdev_x += (pf.particles[i].state.position-mean_x)*(pf.particles[i].state.position-mean_x); stdev_v += (pf.particles[i].state.velocity-mean_v)*(pf.particles[i].state.velocity-mean_v); } stdev_x /= (array_size-1); stdev_v /= (array_size-1); stdev_x = sqrt(stdev_x); stdev_v = sqrt(stdev_v); EXPECT_NEAR(0,mean_x,0.05); EXPECT_NEAR(0,mean_v,0.05); EXPECT_NEAR(1,stdev_x,0.05); EXPECT_NEAR(1,stdev_v,0.05); pf.particles[5].state.position = -500; pf.particles[7].state.velocity = -700; RWState min_state = pf.get_min_state(); EXPECT_FLOAT_EQ(501,min_state.position); EXPECT_FLOAT_EQ(701,min_state.velocity); pf.particles[11].state.position = 1100; pf.particles[13].state.velocity = 1300; RWState max_ln_state = pf.get_max_ln_weighted_state(min_state); EXPECT_FLOAT_EQ(-3.0188239954,max_ln_state.position); EXPECT_FLOAT_EQ(-2.79580537382,max_ln_state.velocity); for(int i=0; i<array_size; i++) { pf.particles[i].state.position = 17; pf.particles[i].state.velocity = 19; pf.particles[i].ln_weight = log(((double)i+1)/(size*array_size*(array_size+1)/2));//gsl_ran_gaussian(rng, 10); } pf.ln_total_weight = -log(size); RWState state = pf.calculate_expected(); EXPECT_FLOAT_EQ(17,state.position); EXPECT_FLOAT_EQ(19,state.velocity); }
/*! Given the \a progId return a list of the profile names which that program is authorised to access. The information is read from the Qt Extended SXE policy file [qt_prefix]/etc/sxe.policy. A caching algorithm is used to lessen the number of file accesses required for recurring lookups. The cache is checked for freshness against this files last modify time, as the Qt Extended installer may have changed it since it was last accessed. */ QStringList SXEPolicyManager::findPolicy( unsigned char progId ) { static QString policyFileName; if ( policyFileName.isNull() ) policyFileName = QPackageRegistry::getInstance()->sxeConfPath() + "/" + QPackageRegistry::policyFileName; QMutexLocker lock( &policyMutex ); // XXX Use notifcation from package installer rather than stat file. static time_t freshness = 0; time_t lastModified = fileModified( policyFileName ); if ( lastModified != freshness ) { policyCache.clear(); freshness = lastModified; } else { QStringList *cachedPolicy = policyCache.object(progId); if (cachedPolicy) return *cachedPolicy; } bool cacheNeedsPriming = policyCache.isEmpty(); QFile pf( policyFileName ); if ( ! pf.open( QFile::ReadOnly )) { qWarning( "Could not open policy file %s!", qPrintable(policyFileName) ); return QStringList(); } #ifndef SXE_INSTALLER Qtopia::lockFile( pf ); #endif QTextStream ts( &pf ); unsigned int line = 1; QStringList list; QStringList theFoundList; QString buf; unsigned char progbuf = 255; int num; while( !ts.atEnd() ) { buf = ts.readLine(); if ( buf[0] == QLatin1Char('[') ) { if (( num = parseNumberInSquareBrackets( buf )) == -1 ) { qWarning( "%s: bad number in square brackets at line %d", qPrintable( policyFileName ), line ); return QStringList(); } // if the cache needs priming and not the first time thru the loop // cache the one we just finished with before we clear it; but make // sure we dont keep "new"'ing if the cache is nearly full if ( cacheNeedsPriming && ( list.count() > 0 ) && ( policyCache.totalCost() < ( policyCache.maxCost() - 10 ))) policyCache.insert( progbuf, new QStringList( list ), list.count() ); if ( progbuf == progId ) { // always cache the hits policyCache.insert( progbuf, new QStringList( list ), list.count() ); theFoundList = list; } progbuf = (unsigned char)num; list.clear(); } else { #ifndef SXE_INSTALLER // ##### TODO - handle filtering policy int idx = buf.indexOf(QLatin1Char('{')); if (idx >= 0) list << buf.left(idx); else #endif list << buf; } line++; } if ( progbuf == progId ) { // always cache the hits policyCache.insert( progbuf, new QStringList( list ), list.count() ); theFoundList = list; } return theFoundList; // QFile pf destructs off the stack and closes file, releasing lock }
static void BLOunit(int u) { if(!race) return; if(race->GetUtype(unitID + u)) unitID += u; pf("%s\n", race->GetUtype(unitID)->Name); }
Final Fantasy VII Launcher is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Final Fantasy VII Launcher. If not, see <http://www.gnu.org/licenses/>. */ #include "flags.h" //------------- //Windows //------------- PAIR_FLAG FLAGS_WS[] = { pf(WS_BORDER), pf(WS_CAPTION), pf(WS_CHILD), pf(WS_CHILDWINDOW), pf(WS_CLIPCHILDREN), pf(WS_CLIPSIBLINGS), pf(WS_DISABLED), pf(WS_DLGFRAME), pf(WS_GROUP), pf(WS_HSCROLL), pf(WS_ICONIC), pf(WS_MAXIMIZE), pf(WS_MAXIMIZEBOX), pf(WS_MINIMIZE), pf(WS_MINIMIZEBOX), pf(WS_OVERLAPPED), pf(WS_OVERLAPPEDWINDOW), pf(WS_POPUP), pf(WS_POPUPWINDOW), pf(WS_SIZEBOX), pf(WS_SYSMENU), pf(WS_TABSTOP), pf(WS_THICKFRAME), pf(WS_TILED), pf(WS_TILEDWINDOW), pf(WS_VISIBLE), pf(WS_VSCROLL) }; UINT CFLAGS_WS = sizeof(FLAGS_WS)/sizeof(FLAGS_WS[0]); PAIR_FLAG FLAGS_WS_EX[] = { pf(WS_EX_ACCEPTFILES), pf(WS_EX_APPWINDOW), pf(WS_EX_CLIENTEDGE),/* pf(WS_EX_COMPOSITED),*/ pf(WS_EX_CONTEXTHELP), pf(WS_EX_CONTROLPARENT), pf(WS_EX_DLGMODALFRAME),/* pf(WS_EX_LAYERED),*/ pf(WS_EX_LAYOUTRTL), pf(WS_EX_LEFT), pf(WS_EX_LEFTSCROLLBAR), pf(WS_EX_LTRREADING), pf(WS_EX_MDICHILD),/* pf(WS_EX_NOACTIVATE),*/ pf(WS_EX_NOINHERITLAYOUT), pf(WS_EX_NOPARENTNOTIFY), pf(WS_EX_OVERLAPPEDWINDOW), pf(WS_EX_PALETTEWINDOW), pf(WS_EX_RIGHT), pf(WS_EX_RIGHTSCROLLBAR), pf(WS_EX_RTLREADING), pf(WS_EX_STATICEDGE), pf(WS_EX_TOOLWINDOW), pf(WS_EX_TOPMOST), pf(WS_EX_TRANSPARENT), pf(WS_EX_WINDOWEDGE)
int load_module_dynamic(struct mod **modp, const struct pl *modpath, const struct pl *name) { char file[256]; struct mod *m = NULL; int err = 0; if (!name) return EINVAL; if (re_snprintf(file, sizeof(file), "%r\\%r", modpath, name) < 0) { err = ENOMEM; goto out; } err = mod_load(&m, file); if (err) goto out; // set function pointers { pf_set_mem_alloc_cb pf = (pf_set_mem_alloc_cb)mod_sym(m, "set_mem_alloc_cb"); if (pf) pf(mem_alloc); } { pf_set_mem_deref_cb pf = (pf_set_mem_deref_cb)mod_sym(m, "set_mem_deref_cb"); if (pf) pf(mem_deref); } { pf_set_aucodec_register_cb pf = (pf_set_aucodec_register_cb)mod_sym(m, "set_aucodec_register_cb"); if (pf) pf(aucodec_register); } { pf_set_aucodec_unregister_cb pf = (pf_set_aucodec_unregister_cb)mod_sym(m, "set_aucodec_unregister_cb"); if (pf) pf(aucodec_unregister); } { pf_validate_dll pf = (pf_validate_dll)mod_sym(m, "validate_dll"); if (pf) { int rc = pf(); if (rc) { DEBUG_INFO("Failed to validate dll, rc = %d\n", rc); err = ELIBBAD; goto out; } } else { DEBUG_INFO("No validate_dll() symbol\n"); err = ELIBBAD; goto out; } } err = mod_call_init(m); if (err) { goto out; } if (modp) *modp = m; out: if (err) { DEBUG_WARNING("module %r: %m\n", name, err); } return err; }
/** *@brief サインスマート製4自由度ロボットアーム制御クラスのコンストラクタ */ RobotArm::RobotArm() { jl = new Vector3d[4]; pl = new Vector3d[4]; l[0] = ArmLength0; l[1] = ArmLength1; l[2] = ArmLength2; l[3] = ArmLength3; lh = HandLength; lf = FingerLength; m[0] = ArmMath0; m[1] = ArmMath1; m[2] = ArmMath2; m[3] = ArmMath3; mh = HandMath; mf = FingerMath; wi = ArmWidth; wf = FingerWidth; hi = ArmHeight; hf = FingerHeight; rh = HandRadius; jl[0](0) = 0; jl[0](1) = 0; jl[0](2) = 0; pl[0](0) = jl[0](0); pl[0](1) = jl[0](1); pl[0](2) = jl[0](2)+l[0]/2; jl[1](0) = pl[0](0); jl[1](1) = pl[0](1); jl[1](2) = pl[0](2)+l[0]/2; pl[1](0) = jl[1](0); pl[1](1) = jl[1](1); pl[1](2) = jl[1](2)+l[1]/2; jl[2](0) = pl[1](0); jl[2](1) = pl[1](1); jl[2](2) = pl[1](2)+l[1]/2; pl[2](0) = jl[2](0); pl[2](1) = jl[2](1); pl[2](2) = jl[2](2)+l[2]/2; jl[3](0) = pl[2](0); jl[3](1) = pl[2](1); jl[3](2) = pl[2](2)+l[2]/2; pl[3](0) = jl[3](0); pl[3](1) = jl[3](1)+l[3]/2; pl[3](2) = jl[3](2); jh(0) = pl[3](0); jh(1) = pl[3](1)+l[3]/2; jh(2) = pl[3](2); ph(0) = jh(0); //pyh = jyh+lh/2; ph(1) = jh(1); ph(2) = jh(2); jf(0) = ph(0); //jyf = pyh+lh/2; jf(1) = ph(1); jf(2) = ph(2); pf(0) = jf(0); pf(1) = jf(1); pf(2) = jf(2)-lf/2; hw = 0.02; setAngle(0, 0, 0, 0); dt = 0.01; //endTime = -1; //time = 0; /*targetPoint(0) = 0; targetPoint(1) = 0; targetPoint(2) = 0; startPoint(0) = 0; startPoint(1) = 0; startPoint(2) = 0;*/ setOffset(0,0,0,0); Kp = 10; Kjp = 10; openGripper(); maxSpeedCartesian = Vector3d(1000, 1000, 1000); maxSpeedJoint[0] = 1000; maxSpeedJoint[1] = 1000; maxSpeedJoint[2] = 1000; maxSpeedJoint[3] = 1000; softUpperLimitCartesian = Vector3d(1000, 1000, 1000); softLowerLimitCartesian = Vector3d(-1000, -1000, -1000); pauseFalg = false; stopFalg = false; //homePosition = Vector3d(0, 0, 0); softUpperLimitJoint[0] = MOTOR_UPPER__LIMIT_0; softUpperLimitJoint[1] = MOTOR_UPPER__LIMIT_1; softUpperLimitJoint[2] = MOTOR_UPPER__LIMIT_2; softUpperLimitJoint[3] = MOTOR_UPPER__LIMIT_3; softLowerLimitJoint[0] = MOTOR_LOWER__LIMIT_0; softLowerLimitJoint[1] = MOTOR_LOWER__LIMIT_1; softLowerLimitJoint[2] = MOTOR_LOWER__LIMIT_2; softLowerLimitJoint[3] = MOTOR_LOWER__LIMIT_3; serbo = true; manifactur = "SainSmart"; type = "DIY 4-Axis Servos Control Palletizing Robot Arm"; axisNum = 4; cmdCycle = 50; isGripper = false; //speedPoint = 10; //speedJointPos = 1; MaxSpeedJoint[0] = 2; MaxSpeedJoint[1] = 2; MaxSpeedJoint[2] = 2; MaxSpeedJoint[3] = 2; MaxSpeedCartesianTrans = 0.5; MaxSpeedCartesianRot = 2; MinTime = dt; jointOffset[0] = MOTOR_OFFSET_0; jointOffset[1] = MOTOR_OFFSET_1; jointOffset[2] = MOTOR_OFFSET_2; jointOffset[3] = MOTOR_OFFSET_3; }