template<int i> struct UpwardsB { template<class TV> static PredicateType<3,TV> eval(const TV S0, const TV S1, const TV S2) { static_assert(i==1 || i==2,""); const auto c01 = S1.xy()-S0.xy(), c02 = S2.xy()-S0.xy(); return i==1 ? c01.x*esqr_magnitude(c02) // Negated below : c02.x*esqr_magnitude(c01); }};
// determine if the ray intersects with the sphere // if there is an intersection, set t_max, current_object, and semi_infinite as appropriate and return true bool Plane:: Intersection(Ray& ray) const { typedef Vector_3D<double> TV; TV d = ray.direction; TV P0 = ray.endpoint; TV q = x1; TV n = normal; d.Normalize(); n.Normalize(); double denom = TV::Dot_Product(n, d); if (denom != 0) { TV qP0 = q - P0; double t = TV::Dot_Product(qP0, n) / denom; if (t < 0) // t is behind the camera return false; if (t < ray.t_max) { ray.t_max = t; ray.current_object = this; } ray.semi_infinite = false; return true; } return false; }
int main() { TV* tv = new ConcreteTV(); tv->add("Channel 1"); tv->add("Channel 2"); ChannelIterator* it = tv->getIterator(); cout << it->hasNext() << endl; cout << it->currentItem() << endl; return 0; }
static void Reserve(CStrTokenizeBase& tokenizer, TV& target, TP& token_pos) { // Reserve vector size only for empty vectors. For vectors which // already have items this has been known to work more slowly. if ( target.empty() ) { size_t tokens = TCount::Count(tokenizer); if (tokens) { token_pos.reserve(tokens); target.reserve(tokens); } } }
int main(int ac, char **av) { #if 1 TV tv; RemoteController control; control.setState(tv); control.setProgramIndex(tv, 12); cout << "电视机状态:" << (tv.getState() ? "开机" : "关机")<<endl; cout << "频道:" << tv.getProgramIndex() << endl; #endif return 0; }
bool test_cube() { LEVELSET<GRID<TV> >* implicit_object = createTriMeshAndLevelSet("/Users/jingweihuang/Desktop/projects/levelset/Resources/models/cube.obj"); for (int i = 1; i <= implicit_object->phi.dim(1); ++i) { for (int j = 1; j <= implicit_object->phi.dim(2); ++j) { for (int k = 1; k <= implicit_object->phi.dim(3); ++k) { double min_dis = 2; TV x = implicit_object->grid.X(TV_INT(i,j,k)); if (x(1) < -0.95 || x(1) > 0.95 || x(2) < -0.95 || x(2) > 0.95 || x(3) < -0.95 || x(3) > 0.95) continue; TV normal = TV(0,0,0); if (min_dis > x(1) + 1) { min_dis = x(1) + 1; normal = TV(-1,0,0); } if (min_dis > 1 - x(1)) { min_dis = 1 - x(1); normal = TV(1, 0, 0); } if (min_dis > x(2) + 1) { min_dis = x(2) + 1; normal = TV(0, -1, 0); } if (min_dis > 1 - x(2)) { min_dis = 1 - x(2); normal = TV(0, 1, 0); } if (min_dis > x(3) + 1) { min_dis = x(3) + 1; normal = TV(0, 0, -1); } if (min_dis > 1 - x(3)) { min_dis = 1 - x(3); normal = TV(0, 0, 1); } pair<float, TV> intersection = implicit_object->Intersect(x); double angle = acos(normal.Dot_Product(intersection.second)) / 3.141502654 * 180.0; if (angle > 5 && fabs(fabs(x(1)) - fabs(x(2))) > 1e-4 && fabs(fabs(x(1)) - fabs(x(3))) > 1e-4 && fabs(fabs(x(2)) - fabs(x(3))) > 1e-4) { return false; } } } } return true; }
static inline bool apply(TV const& vs, TX const& rx, TV& vd) { typename TX::size_type const rsz = rx.size(); if (vd.size() != rsz) { return false; } typename TX::size_type const vsz = vs.size(); for (typename TX::size_type i = 0; i < rsz; ++i) { typename TX::value_type const rxv = rx[i]; if (rxv >= vsz) { return false; } vd[i] = vs[rxv]; } return true; }
bool test_sphere() { LEVELSET<GRID<TV> >* implicit_object = createTriMeshAndLevelSet("/Users/jingweihuang/Desktop/projects/levelset/Resources/models/unit.obj"); TV_INT indd; TV xx; for (int i = 1; i <= implicit_object->phi.dim(1); ++i) { for (int j = 1; j <= implicit_object->phi.dim(2); ++j) { for (int k = 1; k <= implicit_object->phi.dim(3); ++k) { TV x = implicit_object->grid.X(TV_INT(i,j,k)); TV normal = x.Normal(); pair<float, TV> intersection = implicit_object->Intersect(x); if (intersection.first > 0) continue; double angle = acos(intersection.second.Dot_Product(normal)) / 3.141592654 * 180; if (angle > 15 && x.Magnitude() > 0.2 && x.Magnitude() < 0.8) { return false; } } } } return true; }
void plugins_reorder(TV &oPlugins, const std::list<std::string>& order_list) { TV prev(oPlugins); oPlugins.clear(); for (std::list<std::string>::const_iterator i = order_list.begin(); i != order_list.end(); ++i) { for (TI j = prev.begin(); j != prev.end(); ++j) { if (*i == (*j)->get_filename()) { oPlugins.push_back(*j); } } } for (TI i=prev.begin(); i!=prev.end(); ++i) { TI j; for (j=oPlugins.begin(); j!=oPlugins.end(); ++j) { if (*j == *i) break; } if (j == oPlugins.end()) delete *i; } }
static inline bool equalApply(TV const& vs, TX const& rx, TV const& vn) { typename TX::size_type const rsz = rx.size(); if (vn.size() != rsz) { return false; } typename TX::size_type const vsz = vs.size(); for (typename TX::size_type i = 0; i < rsz; ++i) { typename TX::value_type const rxv = rx[i]; if (rxv >= vsz) { return false; } if (vn[i] != vs[rxv]) { return false; } } return true; }
int main(int argc, char *argv[]) { MythAVTestCommandLineParser cmdline; if (!cmdline.Parse(argc, argv)) { cmdline.PrintHelp(); return GENERIC_EXIT_INVALID_CMDLINE; } if (cmdline.toBool("showhelp")) { cmdline.PrintHelp(); return GENERIC_EXIT_OK; } if (cmdline.toBool("showversion")) { cmdline.PrintVersion(); return GENERIC_EXIT_OK; } QApplication a(argc, argv); QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHAVTEST); int retval; if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK) return retval; if (!cmdline.toString("display").isEmpty()) { MythUIHelper::SetX11Display(cmdline.toString("display")); } if (!cmdline.toString("geometry").isEmpty()) { MythUIHelper::ParseGeometryOverride(cmdline.toString("geometry")); } QString filename = ""; if (cmdline.GetArgs().size() >= 1) filename = cmdline.GetArgs()[0]; gContext = new MythContext(MYTH_BINARY_VERSION); if (!gContext->Init()) { LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting."); return GENERIC_EXIT_NO_MYTHCONTEXT; } cmdline.ApplySettingsOverride(); setuid(getuid()); QString themename = gCoreContext->GetSetting("Theme"); QString themedir = GetMythUI()->FindThemeDir(themename); if (themedir.isEmpty()) { QString msg = QString("Fatal Error: Couldn't find theme '%1'.") .arg(themename); LOG(VB_GENERAL, LOG_ERR, msg); return GENERIC_EXIT_NO_THEME; } GetMythUI()->LoadQtConfig(); #if defined(Q_OS_MACX) // Mac OS X doesn't define the AudioOutputDevice setting #else QString auddevice = gCoreContext->GetSetting("AudioOutputDevice"); if (auddevice.isEmpty()) { LOG(VB_GENERAL, LOG_ERR, "Fatal Error: Audio not configured, you need " "to run 'mythfrontend', not 'mythtv'."); return GENERIC_EXIT_SETUP_ERROR; } #endif MythMainWindow *mainWindow = GetMythMainWindow(); mainWindow->Init(); TV::InitKeys(); if (!UpgradeTVDatabaseSchema(false)) { LOG(VB_GENERAL, LOG_ERR, "Fatal Error: Incorrect database schema."); delete gContext; return GENERIC_EXIT_DB_OUTOFDATE; } TV *tv = new TV(); if (!tv->Init()) { LOG(VB_GENERAL, LOG_ERR, "Fatal Error: Could not initialize TV class."); return GENERIC_EXIT_NOT_OK; } if (filename.isEmpty()) { TV::StartTV(NULL, kStartTVNoFlags); } else { ProgramInfo pginfo(filename); TV::StartTV(&pginfo, kStartTVNoFlags); } delete gContext; return GENERIC_EXIT_OK; }
int main(int argc, char *argv[]) { bool cmdline_err; MythCommandLineParser cmdline( kCLPOverrideSettings | kCLPWindowed | kCLPNoWindowed | #ifdef USING_X11 kCLPDisplay | #endif // USING_X11 kCLPGeometry | kCLPVerbose | kCLPExtra | kCLPHelp); print_verbose_messages |= VB_PLAYBACK | VB_LIBAV; for (int argpos = 1; argpos < argc; ++argpos) { if (cmdline.PreParse(argc, argv, argpos, cmdline_err)) { if (cmdline_err) return GENERIC_EXIT_INVALID_CMDLINE; if (cmdline.WantsToExit()) return GENERIC_EXIT_OK; } } QApplication a(argc, argv); QFileInfo finfo(a.argv()[0]); QString binname = finfo.baseName(); int argpos = 1; QString filename = ""; while (argpos < a.argc()) { if (cmdline.Parse(a.argc(), a.argv(), argpos, cmdline_err)) { if (cmdline_err) return GENERIC_EXIT_INVALID_CMDLINE; if (cmdline.WantsToExit()) return GENERIC_EXIT_OK; } else if (a.argv()[argpos][0] != '-') { filename = a.argv()[argpos]; } else { return GENERIC_EXIT_INVALID_CMDLINE; } ++argpos; } if (!cmdline.GetDisplay().isEmpty()) { MythUIHelper::SetX11Display(cmdline.GetDisplay()); } if (!cmdline.GetGeometry().isEmpty()) { MythUIHelper::ParseGeometryOverride(cmdline.GetGeometry()); } gContext = new MythContext(MYTH_BINARY_VERSION); if (!gContext->Init()) { VERBOSE(VB_IMPORTANT, "Failed to init MythContext, exiting."); return GENERIC_EXIT_NO_MYTHCONTEXT; } gCoreContext->SetAppName(binname); QMap<QString, QString> settingsOverride = cmdline.GetSettingsOverride(); if (settingsOverride.size()) { QMap<QString, QString>::iterator it; for (it = settingsOverride.begin(); it != settingsOverride.end(); ++it) { VERBOSE(VB_IMPORTANT, QString("Setting '%1' being forced to '%2'") .arg(it.key()).arg(*it)); gCoreContext->OverrideSettingForSession(it.key(), *it); } } // Create priveledged thread, then drop privs pthread_t priv_thread; bool priv_thread_created = true; int status = pthread_create(&priv_thread, NULL, run_priv_thread, NULL); if (status) { VERBOSE(VB_IMPORTANT, QString("Warning: ") + "Failed to create priveledged thread." + ENO); priv_thread_created = false; } setuid(getuid()); QString themename = gCoreContext->GetSetting("Theme"); QString themedir = GetMythUI()->FindThemeDir(themename); if (themedir.isEmpty()) { QString msg = QString("Fatal Error: Couldn't find theme '%1'.") .arg(themename); VERBOSE(VB_IMPORTANT, msg); return GENERIC_EXIT_NO_THEME; } GetMythUI()->LoadQtConfig(); #if defined(Q_OS_MACX) // Mac OS X doesn't define the AudioOutputDevice setting #else QString auddevice = gCoreContext->GetSetting("AudioOutputDevice"); if (auddevice.isEmpty()) { VERBOSE(VB_IMPORTANT, "Fatal Error: Audio not configured, you need " "to run 'mythfrontend', not 'mythtv'."); return GENERIC_EXIT_SETUP_ERROR; } #endif MythMainWindow *mainWindow = GetMythMainWindow(); mainWindow->Init(); TV::InitKeys(); if (!UpgradeTVDatabaseSchema(false)) { VERBOSE(VB_IMPORTANT, "Fatal Error: Incorrect database schema."); delete gContext; return GENERIC_EXIT_DB_OUTOFDATE; } TV *tv = new TV(); if (!tv->Init()) { VERBOSE(VB_IMPORTANT, "Fatal Error: Could not initialize TV class."); return GENERIC_EXIT_NOT_OK; } if (filename.isEmpty()) { TV::StartTV(NULL, kStartTVNoFlags); } else { ProgramInfo pginfo(filename); TV::StartTV(&pginfo, kStartTVNoFlags); } if (priv_thread_created) { gCoreContext->addPrivRequest(MythPrivRequest::MythExit, NULL); pthread_join(priv_thread, NULL); } delete gContext; return GENERIC_EXIT_OK; }