예제 #1
0
int main(int argc,char** args) {

    srand(time(NULL));

    try {

        if (SDL_Init(SDL_INIT_VIDEO)) {
            fprintf(stderr,"Unable to initialize SDL: %s\n",SDL_GetError());
            return EXIT_FAILURE;
        }
        atexit(SDL_Quit);

        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
#if 0
        screen = SDL_SetVideoMode(1440,900,32,SDL_OPENGL|SDL_FULLSCREEN);
#else
        screen = SDL_SetVideoMode(1024,768,32,SDL_OPENGL/*|SDL_FULLSCREEN*/);
#endif
        if(!screen) {
            fprintf(stderr,"Unable to create SDL screen: %s\n",SDL_GetError());
            return EXIT_FAILURE;
        }
        SDL_WM_SetCaption("GlestNG","GlestNG");

        GLenum err = glewInit();
        if(GLEW_OK != err) {
            fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
            return EXIT_FAILURE;
        }
        fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));

        // we have a GL context so we can go ahead and init all the singletons
        std::auto_ptr<fs_t> fs_settings(fs_t::create("data/"));
        fs_t::settings = fs_settings.get(); // set it globally
        std::auto_ptr<xml_parser_t> xml_settings(new xml_parser_t("UI Settings",fs_settings->get_body("ui_settings.xml")));
        xml_settings->set_as_settings();
        std::auto_ptr<graphics_t::mgr_t> graphics_mgr(graphics_t::create());
        std::auto_ptr<fonts_t> fonts(fonts_t::create());
        std::auto_ptr<fs_t> fs;
        try {
            fs.reset(fs_t::create("data/Glest"));
            if(false) {
                fs_file_t::ptr_t logo_file(fs_settings->get("logo.g3d"));
                istream_t::ptr_t logostream(logo_file->reader());
                logo = std::auto_ptr<model_g3d_t>(new model_g3d_t(*logostream));
            }
            load(*fs);
        } catch(glest_exception_t* e) {
            std::cerr << "cannot load glest data: " << e << std::endl;
            delete e;
        }
        std::auto_ptr<ui_mgr_t> ui_(ui_mgr());
        std::auto_ptr<mod_ui_t> mod_ui(mod_ui_t::create());

        std::auto_ptr<terrain_t> terrain(terrain_t::gen_planet(5,500,3));
        //world()->dump(std::cout);

        v4_t light_amb(0,0,0,1), light_dif(1.,1.,1.,1.), light_spec(1.,1.,1.,1.), light_pos(1.,1.,-1.,0.),
             mat_amb(.7,.7,.7,1.), mat_dif(.8,.8,.8,1.), mat_spec(1.,1.,1.,1.);
        glLightfv(GL_LIGHT0,GL_AMBIENT,light_amb.v);
        glLightfv(GL_LIGHT0,GL_DIFFUSE,light_dif.v);
        glLightfv(GL_LIGHT0,GL_SPECULAR,light_spec.v);
        glLightfv(GL_LIGHT0,GL_POSITION,light_pos.v);
        glLightfv(GL_LIGHT1,GL_AMBIENT,light_amb.v);
        glLightfv(GL_LIGHT1,GL_DIFFUSE,light_dif.v);
        glLightfv(GL_LIGHT1,GL_SPECULAR,light_spec.v);
        glMaterialfv(GL_FRONT,GL_AMBIENT,mat_amb.v);
        glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_dif.v);
        glMaterialfv(GL_FRONT,GL_SPECULAR,mat_spec.v);
        glMaterialf(GL_FRONT,GL_SHININESS,100.0);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHT1);
        glDepthFunc(GL_LEQUAL);
        glEnable(GL_DEPTH_TEST);
        glAlphaFunc(GL_GREATER,0.4);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_RESCALE_NORMAL);
        glEnable(GL_BLEND);
        glEnable(GL_TEXTURE_2D);
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_NORMALIZE);
        glFrontFace(GL_CW);
        camera();
        bool quit = false;
        SDL_Event event;
        SDL_EnableKeyRepeat(200,20);
        SDL_EnableUNICODE(true);
        const unsigned start = SDL_GetTicks();
        framerate.reset();
        while(!quit) {
            set_now(SDL_GetTicks()-start);
            while(!quit && SDL_PollEvent(&event)) {
                if(ui_mgr()->offer(event))
                    continue;
                switch (event.type) {
                case SDL_MOUSEMOTION:
                    if(selection)
                        std::cout << "drag" << std::endl;
                    /*printf("Mouse moved by %d,%d to (%d,%d)\n",
                    event.motion.xrel, event.motion.yrel,
                    event.motion.x, event.motion.y);*/
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    click(event.button.x,event.button.y);
                    if(selection)
                        std::cout << "selection: "<<selected_point<<std::endl;
                    break;
                case SDL_MOUSEBUTTONUP:
                    if(selection)
                        std::cout << "selection stopped" << std::endl;
                    selection = false;
                    break;
                case SDL_KEYDOWN:
                    switch(event.key.keysym.sym) {
                    case SDLK_PLUS:
                        zoom += 1;
                        camera();
                        break;
                    case SDLK_MINUS:
                        zoom -= 1;
                        camera();
                        break;
                    case SDLK_ESCAPE:
                        quit = true;
                        break;
                    case SDLK_m: // MODDING MODE
                        if(!fs.get()) {
                            std::cerr << "(modding menu triggered but mod not loaded)" << std::endl;
                            break;
                        }
                        if(mod_ui->is_shown())
                            mod_ui->hide();
                        else
                            mod_ui->show(ref_t(*techtree,TECHTREE,techtree->name));
                        break;
                    default:
                        std::cout << "Ignoring key " <<
                                  (int)event.key.keysym.scancode << "," <<
                                  event.key.keysym.sym << "," <<
                                  event.key.keysym.mod << "," <<
                                  event.key.keysym.unicode << std::endl;
                    }
                    break;
                case SDL_QUIT:
                    quit = true;
                    break;
                }
            }
            framerate.tick(now());
            tick();
        }
        for(tests_t::iterator i=objs.begin(); i!=objs.end(); i++)
            delete *i;
        return EXIT_SUCCESS;
    } catch(data_error_t* de) {
        std::cerr << "Oh! " << de << std::endl;
    } catch(graphics_error_t* ge) {
        std::cerr << "Oh! " << ge << std::endl;
    } catch(panic_t* panic) {
        std::cerr << "Oh! " << panic << std::endl;
    }
    return EXIT_FAILURE;
}
예제 #2
0
void CameraEngine::saveSettings() {

    if (strcmp( config_file, "none" ) == 0) {
#ifdef __APPLE__
        char path[1024];
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef mainBundleURL = CFBundleCopyBundleURL( mainBundle);
        CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
        CFStringGetCString( cfStringRef, path, 1024, kCFStringEncodingASCII);
        CFRelease( mainBundleURL);
        CFRelease( cfStringRef);
        sprintf(full_path,"%s/Contents/Resources/camera.xml",path);
        config_file = full_path;
#else
        config_file = "./camera.xml";
#endif
    }

    TiXml::TiXmlDocument xml_settings( config_file );
    xml_settings.LoadFile();
    if( xml_settings.Error() )
    {
        std::cout << "Error loading camera configuration file: " << config_file << std::endl;
        return;
    }

    TiXml::TiXmlHandle docHandle( &xml_settings );
    TiXml::TiXmlHandle camera = docHandle.FirstChild("portvideo").FirstChild("camera");
    TiXml::TiXmlElement* settings_element = camera.FirstChild("settings").Element();

    char config_value[64];

    if (settings_element!=NULL) {
        if(settings_element->Attribute("brightness")!=NULL) {

            if (config.brightness==SETTING_MAX) settings_element->SetAttribute("brightness","max");
            else if (config.brightness==SETTING_MIN) settings_element->SetAttribute("brightness","min");
            else if (config.brightness==SETTING_AUTO) settings_element->SetAttribute("brightness","auto");
            else if (config.brightness==SETTING_DEFAULT) settings_element->SetAttribute("brightness","default");
            else {
                sprintf(config_value,"%d",config.brightness);
                settings_element->SetAttribute("brightness",config_value);
            }
        }
        if(settings_element->Attribute("gain")!=NULL) {
            if (config.gain==SETTING_MAX) settings_element->SetAttribute("gain","max");
            else if (config.gain==SETTING_MIN) settings_element->SetAttribute("gain","min");
            else if (config.gain==SETTING_AUTO) settings_element->SetAttribute("gain","auto");
            else if (config.gain==SETTING_DEFAULT) settings_element->SetAttribute("gain","default");
            else {
                sprintf(config_value,"%d",config.gain);
                settings_element->SetAttribute("gain",config_value);
            }
        }
        if(settings_element->Attribute("gamma")!=NULL) {
            if (config.gamma==SETTING_MAX) settings_element->SetAttribute("gamma","max");
            else if (config.gamma==SETTING_MIN) settings_element->SetAttribute("gamma","min");
            else if (config.gamma==SETTING_AUTO) settings_element->SetAttribute("gamma","auto");
            else if (config.gamma==SETTING_DEFAULT) settings_element->SetAttribute("gamma","default");
            else {
                sprintf(config_value,"%d",config.gamma);
                settings_element->SetAttribute("gamma",config_value);
            }
        }
        if(settings_element->Attribute("shutter")!=NULL) {
            if (config.shutter==SETTING_MAX) settings_element->SetAttribute("shutter","max");
            else if (config.shutter==SETTING_MIN) settings_element->SetAttribute("shutter","min");
            else if (config.shutter==SETTING_AUTO) settings_element->SetAttribute("shutter","auto");
            else if (config.shutter==SETTING_DEFAULT) settings_element->SetAttribute("shutter","default");
            else {
                sprintf(config_value,"%d",config.shutter);
                settings_element->SetAttribute("shutter",config_value);
            }
        }
        if(settings_element->Attribute("exposure")!=NULL) {
            if (config.exposure==SETTING_MAX) settings_element->SetAttribute("exposure","max");
            else if (config.exposure==SETTING_MIN) settings_element->SetAttribute("exposure","min");
            else if (config.exposure==SETTING_AUTO) settings_element->SetAttribute("exposure","auto");
            else if (config.exposure==SETTING_DEFAULT) settings_element->SetAttribute("exposure","default");
            else {
                sprintf(config_value,"%d",config.exposure);
                settings_element->SetAttribute("exposure",config_value);
            }
        }
        if(settings_element->Attribute("sharpness")!=NULL) {
            if (config.sharpness==SETTING_MAX) settings_element->SetAttribute("sharpness","max");
            else if (config.sharpness==SETTING_MIN) settings_element->SetAttribute("sharpness","min");
            else if (config.sharpness==SETTING_AUTO) settings_element->SetAttribute("sharpness","auto");
            else if (config.sharpness==SETTING_DEFAULT) settings_element->SetAttribute("sharpness","default");
            else {
                sprintf(config_value,"%d",config.sharpness);
                settings_element->SetAttribute("sharpness",config_value);
            }
        }
        if(settings_element->Attribute("focus")!=NULL) {
            if (config.focus==SETTING_MAX) settings_element->SetAttribute("focus","max");
            else if (config.focus==SETTING_MIN) settings_element->SetAttribute("focus","min");
            else if (config.focus==SETTING_AUTO) settings_element->SetAttribute("focus","auto");
            else if (config.focus==SETTING_DEFAULT) settings_element->SetAttribute("focus","default");
            else {
                sprintf(config_value,"%d",config.focus);
                settings_element->SetAttribute("focus",config_value);
            }
        }
    }

    xml_settings.SaveFile();
    if( xml_settings.Error() ) std::cout << "Error saving camera configuration file: "  << config_file << std::endl;

}
예제 #3
0
void readSettings(reactivision_settings *config) {

	config->port = 3333;
	sprintf(config->host,"localhost");
	sprintf(config->tree_config,"none");
	sprintf(config->grid_config,"none");
	sprintf(config->midi_config,"none");
	sprintf(config->camera_config,"none");
	config->invert_x = false;
	config->invert_y = false;
	config->invert_a = false;
	config->midi = false;
	config->amoeba = true;
	config->classic = false;
	config->background = false;
	config->fullscreen = false;
	config->headless = false;
	config->finger_size = 0;
	config->finger_sensitivity = 100;
	config->gradient_gate = 32;
	config->tile_size = 10;
	config->thread_count = 1;
	config->display_mode = 2;

	if (strcmp( config->file, "none" ) == 0) {
#ifdef __APPLE__
	char app_path[1024];
	CFBundleRef mainBundle = CFBundleGetMainBundle();
	CFURLRef mainBundleURL = CFBundleCopyBundleURL( mainBundle);
	CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
	CFStringGetCString( cfStringRef, app_path, 1024, kCFStringEncodingASCII);	
	CFRelease( mainBundleURL);
	CFRelease( cfStringRef);
	sprintf(config->file,"%s/Contents/Resources/reacTIVision.xml",app_path);
#elif !defined WIN32
        if (access ("./reacTIVision.xml", F_OK )==0) sprintf(config->file,"./reacTIVision.xml");
        else if (access ("/usr/share/reacTIVision/reacTIVision.xml", F_OK )==0) sprintf(config->file,"/usr/share/reacTIVision/reacTIVision.xml");
        else if (access ("/usr/local/share/reacTIVision/reacTIVision.xml", F_OK )==0) sprintf(config->file,"/usr/local/share/reacTIVision/reacTIVision.xml");
        else if (access ("/opt/share/reacTIVision/reacTIVision.xml", F_OK )==0) sprintf(config->file,"/opt/share/reacTIVision/reacTIVision.xml");
#else
        sprintf(config->file,"./reacTIVision.xml");
#endif
	}

	TiXmlDocument xml_settings( config->file );
	xml_settings.LoadFile();
	if( xml_settings.Error() )
	{
		std::cout << "Error loading configuration file: " << config->file << std::endl;
		return;
	}

	TiXmlHandle docHandle( &xml_settings );
	TiXmlHandle config_root = docHandle.FirstChild("reactivision");

	TiXmlElement* tuio_element = config_root.FirstChild("tuio").Element();
	if( tuio_element!=NULL )
	{
		if(tuio_element->Attribute("host")!=NULL) sprintf(config->host,"%s",tuio_element->Attribute("host"));
		if(tuio_element->Attribute("port")!=NULL) config->port = atoi(tuio_element->Attribute("port"));
	}

	TiXmlElement* camera_element = config_root.FirstChild("camera").Element();
	if( camera_element!=NULL )
	{
		if(camera_element->Attribute("config")!=NULL) sprintf(config->camera_config,"%s",camera_element->Attribute("config"));
	}

	TiXmlElement* midi_element = config_root.FirstChild("midi").Element();
	if( midi_element!=NULL )
	{
		if(midi_element->Attribute("config")!=NULL) {
			sprintf(config->midi_config,"%s",midi_element->Attribute("config"));
			config->midi=true;
		}
	}

	TiXmlElement* finger_element = config_root.FirstChild("finger").Element();
	if( finger_element!=NULL )
	{
		if(finger_element->Attribute("size")!=NULL) config->finger_size = atoi(finger_element->Attribute("size"));
		if(finger_element->Attribute("sensitivity")!=NULL) config->finger_sensitivity = atoi(finger_element->Attribute("sensitivity"));
	}

	TiXmlElement* image_element = config_root.FirstChild("image").Element();
	if( image_element!=NULL )
	{
		if(image_element->Attribute("display")!=NULL)  {
			if ( strcmp( image_element->Attribute("display"), "none" ) == 0 ) config->display_mode = 0;
			else if ( strcmp( image_element->Attribute("display"), "src" ) == 0 )  config->display_mode = 1;
			else if ( strcmp( image_element->Attribute("display"), "dest" ) == 0 )  config->display_mode = 2;
		}
        
		if(image_element->Attribute("equalize")!=NULL) {
			if ((strcmp( image_element->Attribute("equalize"), "true" ) == 0) ||  atoi(image_element->Attribute("equalize"))==1) config->background = true;
		}

        if(image_element->Attribute("fullscreen")!=NULL) {
            if ((strcmp( image_element->Attribute("fullscreen"), "true" ) == 0) ||  atoi(image_element->Attribute("fullscreen"))==1) config->fullscreen = true;
        }

	}

    TiXmlElement* threshold_element = config_root.FirstChild("threshold").Element();
    if( threshold_element!=NULL )
    {
        if(threshold_element->Attribute("gradient")!=NULL) {
            if (strcmp(threshold_element->Attribute("gradient"), "max" ) == 0) config->gradient_gate=64;
            else if (strcmp(threshold_element->Attribute("gradient"), "min" ) == 0) config->gradient_gate=0;
            else config->gradient_gate = atoi(threshold_element->Attribute("gradient"));
        }

        if(threshold_element->Attribute("tile")!=NULL) {
            if (strcmp(threshold_element->Attribute("tile"), "max" ) == 0) config->tile_size=INT_MAX;
            else if (strcmp(threshold_element->Attribute("tile"), "min" ) == 0) config->tile_size=2;
            else  config->tile_size = atoi(threshold_element->Attribute("tile"));
        }

        if(threshold_element->Attribute("threads")!=NULL) {
            if (strcmp(threshold_element->Attribute("threads"), "max" ) == 0) config->thread_count=SDL_GetCPUCount();
            else if (strcmp(threshold_element->Attribute("threads"), "min" ) == 0) config->thread_count=1;
            else {
                config->thread_count = atoi(threshold_element->Attribute("threads"));
                if(config->thread_count<1) config->thread_count = 1;
                if(config->thread_count>SDL_GetCPUCount()) config->thread_count =  SDL_GetCPUCount();                
            }
        }
        
        
 
    }

	TiXmlElement* fiducial_element = config_root.FirstChild("fiducial").Element();
	if( fiducial_element!=NULL )
	{
		if(fiducial_element->Attribute("engine")!=NULL)  {
			if ( strcmp( fiducial_element->Attribute("engine"), "amoeba" ) == 0 ) config->amoeba = true;
			else if ( strcmp( fiducial_element->Attribute("engine"), "classic" ) == 0 ) { config->classic = true; config->amoeba = false; }
		}
		if(fiducial_element->Attribute("tree")!=NULL) sprintf(config->tree_config,"%s",fiducial_element->Attribute("tree"));
	}

	TiXmlElement* calibration_element = config_root.FirstChild("calibration").Element();
	if( calibration_element!=NULL )
	{
		if(calibration_element->Attribute("invert")!=NULL)  {
			if (strstr(calibration_element->Attribute("invert"),"x")>0) config->invert_x = true;
			if (strstr(calibration_element->Attribute("invert"),"y")>0) config->invert_y = true; 
			if (strstr(calibration_element->Attribute("invert"),"a")>0) config->invert_a = true; 			
		}
		if(calibration_element->Attribute("grid")!=NULL) sprintf(config->grid_config,"%s",calibration_element->Attribute("grid"));
	}

}
예제 #4
0
void CameraEngine::readSettings() {

    config.device = 0;
    config.color = false;
    config.width = SETTING_MAX;
    config.height = SETTING_MAX;
    config.fps = SETTING_MAX;
    config.format7 = false;
    config.xoff = 0;
    config.yoff = 0;
    sprintf(config.file,"none");
    sprintf(config.folder,"none");
    config.brightness = SETTING_DEFAULT;
    config.gain = SETTING_DEFAULT;
    config.gamma = SETTING_DEFAULT;
    config.exposure = SETTING_DEFAULT;
    config.sharpness = SETTING_DEFAULT;
    config.shutter = SETTING_DEFAULT;

#ifdef __APPLE__
    char path[1024];
#endif

    if (strcmp( config_file, "none" ) == 0) {
#ifdef __APPLE__
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef mainBundleURL = CFBundleCopyBundleURL( mainBundle);
        CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
        CFStringGetCString( cfStringRef, path, 1024, kCFStringEncodingASCII);
        CFRelease( mainBundleURL);
        CFRelease( cfStringRef);

#ifndef IOS
        sprintf(full_path,"%s/Contents/Resources/camera.xml",path);
#else
        sprintf(full_path,"%s/camera.xml",path);
#endif

        config_file = full_path;
#elif !defined WIN32
        if (access ("./camera.xml", F_OK )==0) config_file = "./camera.xml";
        else if (access ("/usr/share/reacTIVision/camera.xml", F_OK )==0) config_file = "/usr/share/reacTIVision/camera.xml";
        else if (access ("/usr/local/share/reacTIVision/camera.xml", F_OK )==0) config_file = "/usr/local/share/camera.xml";
        else if (access ("/opt/share/reacTIVision/camera.xml", F_OK )==0) config_file = "/opt/share/reacTIVision/camera.xml";
#else
        config_file = "./camera.xml";
#endif
    }

    TiXml::TiXmlDocument xml_settings( config_file );
    xml_settings.LoadFile();
    if( xml_settings.Error() )
    {
        std::cout << "Error loading camera configuration file: " << config_file << std::endl;
        return;
    }

    TiXml::TiXmlHandle docHandle( &xml_settings );
    TiXml::TiXmlHandle camera = docHandle.FirstChild("portvideo").FirstChild("camera");
    TiXml::TiXmlElement* camera_element = camera.Element();


    if( camera_element==NULL )
    {
        std::cout << "Error loading camera configuration file: " << config_file << std::endl;
        return;
    }

    if(camera_element->Attribute("id")!=NULL) {
        if (strcmp(camera_element->Attribute("id"), "auto" ) == 0) config.device=SETTING_AUTO;
        else config.device = atoi(camera_element->Attribute("id"));
    }

    if(camera_element->Attribute("file")!=NULL) {
#ifdef __APPLE__
        sprintf(config.file,"%s/../%s",path,camera_element->Attribute("file"));
#else
        sprintf(config.file,"%s",camera_element->Attribute("file"));
#endif
    }
    if(camera_element->Attribute("folder")!=NULL) {
#ifdef __APPLE__
        sprintf(config.folder,"%s/../%s",path,camera_element->Attribute("folder"));
#else
        sprintf(config.folder,"%s",camera_element->Attribute("folder"));
#endif
    }


    TiXml::TiXmlElement* image_element = camera.FirstChild("image").Element();

    if (image_element!=NULL) {
        if ((image_element->Attribute("color")!=NULL) && ( strcmp( image_element->Attribute("color"), "true" ) == 0 )) config.color = true;

        if(image_element->Attribute("width")!=NULL) {
            if (strcmp( image_element->Attribute("width"), "max" ) == 0) config.width = SETTING_MAX;
            else config.width = atoi(image_element->Attribute("width"));
        }

        if(image_element->Attribute("height")!=NULL) {
            if (strcmp( image_element->Attribute("height"), "max" ) == 0) config.height = SETTING_MAX;
            else config.height = atoi(image_element->Attribute("height"));
        }
        if(image_element->Attribute("fps")!=NULL) {
            if (strcmp( image_element->Attribute("fps"), "max" ) == 0) config.fps = SETTING_MAX;
            else config.fps = atof(image_element->Attribute("fps"));
        }
    }

    TiXml::TiXmlElement* format7_element = camera.FirstChild("format7").Element();
    if (format7_element!=NULL) {
        config.format7 = true;

        if(format7_element->Attribute("xoff")!=NULL) {
            if (strcmp( format7_element->Attribute("xoff"), "max" ) == 0) config.xoff = SETTING_MAX;
            else if (strcmp( format7_element->Attribute("xoff"), "min" ) == 0) config.xoff = 0;
            else config.xoff = atoi(format7_element->Attribute("xoff"));
        }

        if(format7_element->Attribute("yoff")!=NULL) {
            if (strcmp( format7_element->Attribute("yoff"), "max" ) == 0) config.yoff = SETTING_MAX;
            else if (strcmp( format7_element->Attribute("yoff"), "min" ) == 0) config.yoff = 0;
            else config.yoff = atoi(format7_element->Attribute("yoff"));
        }
    }

    TiXml::TiXmlElement* settings_element = camera.FirstChild("settings").Element();
    if (settings_element!=NULL) {
        if(settings_element->Attribute("brightness")!=NULL) {
            if (strcmp(settings_element->Attribute("brightness"), "max" ) == 0) config.brightness=SETTING_MAX;
            else if (strcmp(settings_element->Attribute("brightness"), "min" ) == 0) config.brightness=SETTING_MIN;
            else if (strcmp(settings_element->Attribute("brightness"), "auto" ) == 0) config.brightness=SETTING_AUTO;
            else if (strcmp(settings_element->Attribute("brightness"), "default" ) == 0) config.brightness=SETTING_DEFAULT;
            else config.brightness = atoi(settings_element->Attribute("brightness"));
        }
        if(settings_element->Attribute("gain")!=NULL) {
            if (strcmp(settings_element->Attribute("gain"), "max" ) == 0) config.gain=SETTING_MAX;
            else if (strcmp(settings_element->Attribute("gain"), "min" ) == 0) config.gain=SETTING_MIN;
            else if (strcmp(settings_element->Attribute("gain"), "auto" ) == 0) config.gain=SETTING_AUTO;
            else if (strcmp(settings_element->Attribute("gain"), "default" ) == 0) config.gain=SETTING_DEFAULT;
            else config.gain = atoi(settings_element->Attribute("gain"));
        }
        if(settings_element->Attribute("gamma")!=NULL) {
            if (strcmp(settings_element->Attribute("gamma"), "max" ) == 0) config.gamma=SETTING_MAX;
            else if (strcmp(settings_element->Attribute("gamma"), "min" ) == 0) config.gamma=SETTING_MIN;
            else if (strcmp(settings_element->Attribute("gamma"), "auto" ) == 0) config.gamma=SETTING_AUTO;
            else if (strcmp(settings_element->Attribute("gamma"), "default" ) == 0) config.gamma=SETTING_DEFAULT;
            else config.gamma = atoi(settings_element->Attribute("gamma"));
        }
        if(settings_element->Attribute("shutter")!=NULL) {
            if (strcmp(settings_element->Attribute("shutter"), "max" ) == 0) config.shutter=SETTING_MAX;
            else if (strcmp(settings_element->Attribute("shutter"), "min" ) == 0) config.shutter=SETTING_MIN;
            else if (strcmp(settings_element->Attribute("shutter"), "auto" ) == 0) config.shutter=SETTING_AUTO;
            else if (strcmp(settings_element->Attribute("shutter"), "default" ) == 0) config.shutter=SETTING_DEFAULT;
            else config.shutter = atoi(settings_element->Attribute("shutter"));
        }
        if(settings_element->Attribute("exposure")!=NULL) {
            if (strcmp(settings_element->Attribute("exposure"), "max" ) == 0) config.exposure=SETTING_MAX;
            else if (strcmp(settings_element->Attribute("exposure"), "min" ) == 0) config.exposure=SETTING_MIN;
            else if (strcmp(settings_element->Attribute("exposure"), "auto" ) == 0) config.exposure=SETTING_AUTO;
            else if (strcmp(settings_element->Attribute("exposure"), "default" ) == 0) config.exposure=SETTING_DEFAULT;
            else config.exposure = atoi(settings_element->Attribute("exposure"));
        }
        if(settings_element->Attribute("sharpness")!=NULL) {
            if (strcmp(settings_element->Attribute("sharpness"), "max" ) == 0) config.sharpness=SETTING_MAX;
            else if (strcmp(settings_element->Attribute("sharpness"), "min" ) == 0) config.sharpness=SETTING_MIN;
            else if (strcmp(settings_element->Attribute("sharpness"), "auto" ) == 0) config.sharpness=SETTING_AUTO;
            else if (strcmp(settings_element->Attribute("sharpness"), "default" ) == 0) config.sharpness=SETTING_DEFAULT;
            else config.sharpness = atoi(settings_element->Attribute("sharpness"));
        }
        if(settings_element->Attribute("focus")!=NULL) {
            if (strcmp(settings_element->Attribute("focus"), "max" ) == 0) config.focus=SETTING_MAX;
            else if (strcmp(settings_element->Attribute("focus"), "min" ) == 0) config.focus=SETTING_MIN;
            else if (strcmp(settings_element->Attribute("focus"), "auto" ) == 0) config.focus=SETTING_AUTO;
            else if (strcmp(settings_element->Attribute("focus"), "default" ) == 0) config.focus=SETTING_DEFAULT;
            else config.focus = atoi(settings_element->Attribute("focus"));
        }
    }

    width = config.width;
    height = config.height;
    colour = config.color;
    bytes = (colour?3:1);

}
예제 #5
0
void writeSettings(reactivision_settings *config) {

	TiXmlDocument xml_settings( config->file );
	xml_settings.LoadFile();
	if( xml_settings.Error() )
	{
		std::cout << "Error loading configuration file: " << config->file << std::endl;
		return;
	}

	char config_value[64];

	TiXmlHandle docHandle( &xml_settings );
	TiXmlHandle config_root = docHandle.FirstChild("reactivision");

	TiXmlElement* tuio_element = config_root.FirstChild("tuio").Element();
	if( tuio_element!=NULL )
	{
		if(tuio_element->Attribute("host")!=NULL) tuio_element->SetAttribute("host",config->host);
		if(tuio_element->Attribute("port")!=NULL) {
			sprintf(config_value,"%d",config->port);
			tuio_element->SetAttribute("port",config_value);
		}
	}

	TiXmlElement* camera_element = config_root.FirstChild("camera").Element();
	if( camera_element!=NULL )
	{
		if(camera_element->Attribute("config")!=NULL) camera_element->SetAttribute("config",config->camera_config);
	}

	TiXmlElement* midi_element = config_root.FirstChild("midi").Element();
	if( midi_element!=NULL )
	{
		if(midi_element->Attribute("config")!=NULL) midi_element->SetAttribute("config",config->midi_config);
	}

	TiXmlElement* finger_element = config_root.FirstChild("finger").Element();
	if( finger_element!=NULL )
	{
		if(finger_element->Attribute("size")!=NULL) {
			sprintf(config_value,"%d",config->finger_size);
			finger_element->SetAttribute("size",config_value);
		}
		if(finger_element->Attribute("sensitivity")!=NULL) {
			sprintf(config_value,"%d",config->finger_sensitivity);
			finger_element->SetAttribute("sensitivity",config_value);
		}
	}

	TiXmlElement* image_element = config_root.FirstChild("image").Element();
	if( image_element!=NULL )
	{
		if(image_element->Attribute("display")!=NULL)  {
			if (config->display_mode == 0) image_element->SetAttribute("display","none");
			else if (config->display_mode == 1) image_element->SetAttribute("display","src");
			else if (config->display_mode == 2) image_element->SetAttribute("display","dest");  
		}
		if(image_element->Attribute("equalize")!=NULL) {
			if (config->background) image_element->SetAttribute("equalize","true");
			else image_element->SetAttribute("equalize","false");
		}
        if(image_element->Attribute("fullscreen")!=NULL) {
            if (config->fullscreen) image_element->SetAttribute("fullscreen","true");
            else image_element->SetAttribute("fullscreen","false");
        }

	}

    TiXmlElement* threshold_element = config_root.FirstChild("threshold").Element();
    if( threshold_element!=NULL )
    {
        if(threshold_element->Attribute("gradient")!=NULL) {
            sprintf(config_value,"%d",config->gradient_gate);
            threshold_element->SetAttribute("gradient",config_value);
        }
        if(threshold_element->Attribute("tile")!=NULL) {
            sprintf(config_value,"%d",config->tile_size);
            threshold_element->SetAttribute("tile",config_value);
        }
    }


	TiXmlElement* fiducial_element = config_root.FirstChild("fiducial").Element();
	if( fiducial_element!=NULL )
	{
		if(fiducial_element->Attribute("engine")!=NULL)  {
			if (config->amoeba) fiducial_element->SetAttribute("engine", "amoeba"); 
			else if (config->classic) fiducial_element->SetAttribute("engine","classic"); 
		}
		if(fiducial_element->Attribute("tree")!=NULL) fiducial_element->SetAttribute("tree",config->tree_config);
	}

	TiXmlElement* calibration_element = config_root.FirstChild("calibration").Element();
	if( calibration_element!=NULL )
	{
		sprintf(config_value," ");
		if(calibration_element->Attribute("invert")!=NULL)  {
			if (config->invert_x) strcat(config_value,"x");
			if (config->invert_y) strcat(config_value,"y");
			if (config->invert_a) strcat(config_value,"a");
			calibration_element->SetAttribute("invert",config_value);
		}
		if(calibration_element->Attribute("grid")!=NULL) calibration_element->SetAttribute("grid",config->grid_config);
	}

	xml_settings.SaveFile();
	if( xml_settings.Error() ) std::cout << "Error saving configuration file: "  << config->file << std::endl;

}