Esempio n. 1
0
Jello::Jello(int& argc,char**& argv,char**& appDefaults)
	:Vrui::Application(argc,argv,appDefaults),
	 crystal(JelloCrystal::Index(4,4,8)),
	 renderer(crystal),
	 targetFrameRate(50.0),
	 numMiniSteps(1),
	 mainMenu(0),settingsDialog(0)
	{
	/* Target frame rate is only (optional) command line parameter: */
	if(argc>=2)
		targetFrameRate=atof(argv[1]);
	
	/* Determine a good color to draw the domain box: */
	GLColor<GLfloat,3> domainBoxColor;
	for(int i=0;i<3;++i)
		domainBoxColor[i]=1.0f-Vrui::getBackgroundColor()[i];
	renderer.setDomainBoxColor(domainBoxColor);
	
	/* Create the program's user interface: */
	mainMenu=createMainMenu();
	Vrui::setMainMenu(mainMenu);
	settingsDialog=createSettingsDialog();
	
	/* Initialize the navigation transformation: */
	centerDisplayCallback(0);
	
	/* Tell Vrui to run in a continuous frame sequence: */
	Vrui::updateContinuously();
	
	/* Initialize the frame time calculator: */
	lastFrameTime=Vrui::getApplicationTime();
	}
Esempio n. 2
0
HelloVrui::HelloVrui(int& argc,char**& argv)
	:Vrui::Application(argc,argv),
	 showSurface(true),surfaceTransparent(false),
	 surfaceMaterial(GLMaterial::Color(1.0f,1.0f,1.0f,0.333f),GLMaterial::Color(0.333f,0.333f,0.333f),10.0f),
	 showGrid(true),
	 mainMenu(0),
         drawGLCube(false)
	{
        if(argc > 1)
          {
          if(std::string(argv[1]) == "--gl")
            {
            this->drawGLCube = true;
            }
          }
	/* Create the user interface: */
	mainMenu=createMainMenu();
	Vrui::setMainMenu(mainMenu);

	/* Initialize Vrui navigation transformation: */
	centerDisplayCallback(0);

        this->renWin =
          vtkSmartPointer<vtkExternalOpenGLRenderWindow>::New();
        this->ren = vtkSmartPointer<vtkExternalOpenGLRenderer>::New();
//        this->cam = vtkSmartPointer<vtkExternalOpenGLCamera>::New();
//        this->ren->SetActiveCamera(this->cam);
	}
/*
 * initialize - Initialize the GUI portion of the application.
 *
 * parameter volumeFile - const char*& volumeFile
 */
void Domhan_Samhlaigh::initialize(void) {
	scene = new Scene(numberOfHorizontalPatches, numberOfVerticalPatches, minimumLevel, texturePrefix, heightMapPrefix);

	/* Create the user interface: */
	mainMenu=createMainMenu();
	Vrui::setMainMenu(mainMenu);

	/* Center display */
	centerDisplayCallback(0);
} // end initialize()
Esempio n. 4
0
GridEditor::GridEditor(int& argc,char**& argv)
	:Vrui::Application(argc,argv),
	 grid(0),
	 exportSurfaceHelper("ExportedSurface.ply",".ply",Vrui::openDirectory(".")),
	 mainMenu(0)
	{
	if(argc>=2)
		{
		/* Load the grid from a float-valued vol file: */
		Misc::File volFile(argv[1],"rb",Misc::File::BigEndian);
		
		/* Read the file header: */
		EditableGrid::Index numVertices;
		volFile.read<int>(numVertices.getComponents(),3);
		int borderSize=volFile.read<int>();
		for(int i=0;i<3;++i)
			numVertices[i]+=borderSize*2;
		float domainSize[3];
		volFile.read<float>(domainSize,3);
		EditableGrid::Size cellSize;
		for(int i=0;i<3;++i)
			cellSize[i]=domainSize[i]/float(numVertices[i]-borderSize*2-1);
		
		/* Create the grid: */
		grid=new EditableGrid(numVertices,cellSize);
		
		/* Read all grid values: */
		for(EditableGrid::Index i(0);i[0]<grid->getNumVertices(0);i.preInc(grid->getNumVertices()))
			grid->setValue(i,volFile.read<float>());
		grid->invalidateVertices(EditableGrid::Index(0,0,0),grid->getNumVertices());
		}
	else
		{
		/* Create a new grid: */
		grid=new EditableGrid(EditableGrid::Index(256,256,256),EditableGrid::Size(1.0f,1.0f,1.0f));
		}
	
	/* Create the program GUI: */
	mainMenu=createMainMenu();
	Vrui::setMainMenu(mainMenu);
	
	/* Initialize the navigation transformation: */
	centerDisplayCallback(0);
	
	/* Initialize the tool classes: */
	EditTool::initClass(*Vrui::getToolManager());
	}
Esempio n. 5
0
vruivnc::vruivnc(int& argc, char**& argv, char**& appDefaults) :
    Vrui::Application(argc, argv, appDefaults),
    rfbProtocolStartupData(),
    vncManager(new VncManager(*this, *this, !Vrui::isMaster(), Vrui::openPipe())),
    scaleToEnvironment(true),
    surfaceMaterial(GLMaterial::Color(1.0f, 1.0f, 1.0f, 0.333f), GLMaterial::Color(0.333f, 0.333f, 0.333f), 10.0f)
{
    // Parse the command line:
    for (int i = 1; i < argc; ++i)
    {
        if (argv[i][0] == '-')
        {
            if (strcasecmp(argv[i]+1, "host") == 0)
            {
                i++;
                rfbProtocolStartupData.desktopHost    = argv[i++];
                rfbProtocolStartupData.initViaConnect = true;
            }
            else if (strcasecmp(argv[i]+1, "port") == 0)
            {
                i++;
                rfbProtocolStartupData.rfbPort = atoi(argv[i++]);
            }
            else if (strcasecmp(argv[i]+1, "encodings") == 0)
            {
                i++;
                rfbProtocolStartupData.requestedEncodings = argv[i++];
            }
            else if (strcasecmp(argv[i]+1, "shared") == 0)
            {
                i++;
                rfbProtocolStartupData.sharedDesktopFlag = true;
            }
            else
            {
                std::cout << "Unrecognized switch " << argv[i] << std::endl;
            }
        }
    }

    // Initialize Vrui navigation transformation:
    centerDisplayCallback(0);
}
SharedJello::SharedJello(int& argc,char**& argv,char**& appDefaults)
	:Vrui::Application(argc,argv,appDefaults),
	 pipe(0),
	 newParameterVersion(1),parameterVersion(1),
	 lockedIndex(0),mostRecentIndex(1),
	 nextDraggerID(0),
	 mainMenu(0),settingsDialog(0)
	{
	/* Parse the command line: */
	const char* serverHostName=0;
	int serverPortID=-1;
	bool renderDomainBox=true;
	for(int i=0;i<argc;++i)
		{
		if(argv[i][0]=='-')
			{
			if(strcasecmp(argv[i]+1,"host")==0)
				{
				++i;
				if(i<argc)
					serverHostName=argv[i];
				else
					std::cerr<<"SharedJello::SharedJello: Ignored dangling -host option"<<std::endl;
				}
			else if(strcasecmp(argv[i]+1,"port")==0)
				{
				++i;
				if(i<argc)
					serverPortID=atoi(argv[i]);
				else
					std::cerr<<"SharedJello::SharedJello: Ignored dangling -port option"<<std::endl;
				}
			else if(strcasecmp(argv[i]+1,"nobox")==0)
				renderDomainBox=false;
			}
		}
	if(serverHostName==0||serverPortID<0)
		Misc::throwStdErr("SharedJello::SharedJello: No server host name or port ID provided");
	
	/* Connect to the shared Jell-O server: */
	pipe=Cluster::openTCPPipe(Vrui::getClusterMultiplexer(),serverHostName,serverPortID);
	pipe->negotiateEndianness();
	
	/* Initiate the connection: */
	if(readMessage(*pipe)!=CONNECT_REPLY)
		{
		/* Bail out: */
		pipe=0;
		Misc::throwStdErr("SharedJello::SharedJello: Connection refused by shared Jell-O server");
		}
	
	/* Read the Jell-O crystal's domain box: */
	read(domain,*pipe);
	
	/* Read the number of atoms in the Jell-O crystal: */
	Card na[3];
	pipe->read(na,3);
	JelloCrystal::Index numAtoms(na[0],na[1],na[2]);
	
	/* Wait for the first parameter update message to get the initial simulation parameters: */
	if(readMessage(*pipe)!=SERVER_PARAMUPDATE)
		{
		/* Bail out: */
		pipe=0;
		Misc::throwStdErr("SharedJello::SharedJello: Connection refused by shared Jell-O server");
		}
	atomMass=pipe->read<Scalar>();
	attenuation=pipe->read<Scalar>();
	gravity=pipe->read<Scalar>();
	
	/* Wait for the first server update message to get initial atom positions: */
	if(readMessage(*pipe)!=SERVER_UPDATE)
		{
		/* Bail out: */
		pipe=0;
		Misc::throwStdErr("SharedJello::SharedJello: Connection refused by shared Jell-O server");
		}
	
	/* Create triple buffer of Jell-O crystals: */
	for(int i=0;i<3;++i)
		crystals[i]=new JelloCrystal(numAtoms);
	
	/* Read the first crystal state: */
	crystals[mostRecentIndex]->readAtomStates(*pipe);
	
	/* Calculate the domain box color: */
	GLColor<GLfloat,3> domainBoxColor;
	for(int i=0;i<3;++i)
		domainBoxColor[i]=1.0f-Vrui::getBackgroundColor()[i];
	
	/* Create the triple buffer of Jell-O renderers: */
	for(int i=0;i<3;++i)
		{
		renderers[i]=new JelloRenderer(*crystals[i]);
		renderers[i]->setRenderDomainBox(renderDomainBox);
		renderers[i]->setDomainBoxColor(domainBoxColor);
		}
	renderers[mostRecentIndex]->update();
	
	/* Start the server communication thread: */
	communicationThread.start(this,&SharedJello::communicationThreadMethod);
	
	/* Create the program's user interface: */
	mainMenu=createMainMenu();
	Vrui::setMainMenu(mainMenu);
	settingsDialog=createSettingsDialog();
	
	/* Initialize the navigation transformation: */
	centerDisplayCallback(0);
	}
Esempio n. 7
0
VRMeshEditor::VRMeshEditor(int& argc,char**& argv,char**& appDefaults)
    :Vrui::Application(argc,argv,appDefaults),
     mesh(0),
     morphBox(0),
     defaultDraggerType(MESHDRAGGER),
     defaultActionType(Influence::DRAG),
     overrideTools(true),
     renderMode(SHADED),
     meshMaterial(GLMaterial::Color(0.7f,0.7f,0.7f),GLMaterial::Color(1.0f,1.0f,1.0f),50.0f),
     mainMenu(0)
{
    /* Parse the command line: */
    int meshFileType=1;
    const char* meshFileName=0;
    int subdivisionDepth=2;
    for(int i=1; i<argc; ++i)
    {
        if(argv[i][0]=='-')
        {
            if(strcasecmp(argv[i]+1,"GTS")==0)
                meshFileType=2;
            else if(strcasecmp(argv[i]+1,"PLY")==0)
                meshFileType=3;
            else if(strcasecmp(argv[i]+1,"DEPTH")==0)
            {
                subdivisionDepth=atoi(argv[i+1]);
                ++i;
            }
        }
        else
            meshFileName=argv[i];
    }
    if(meshFileName==0)
    {
        meshFileType=4;
        // throw std::runtime_error("VRMeshEditor: No mesh file name supplied");
    }

    /* Load the base mesh: */
    MyMesh::BaseMesh* baseMesh=0;
    switch(meshFileType)
    {
    case 1:
        baseMesh=loadMeshfile<MyMesh::Point>(meshFileName);
        break;

    case 2:
        baseMesh=loadGtsMeshfile<MyMesh::Point>(meshFileName);
        break;

    case 3:
        baseMesh=loadPlyMeshfile<MyMesh::Point>(meshFileName);
        break;

    case 4:
        baseMesh=createTetrahedron<MyMesh::Point>();
        break;
    }

    /* Subdivide the base mesh: */
    for(int i=0; i<subdivisionDepth; ++i)
        subdivideCatmullClark(*baseMesh);
    mesh=new MyMesh(*baseMesh);
    delete baseMesh;

    /* Create the main menu: */
    mainMenu=createMainMenu();
    Vrui::setMainMenu(mainMenu);

    /* Set additional physical-space light sources: */
    Vrui::Point l1=Vrui::getDisplayCenter()+Vrui::Vector(-1.0,-0.1,0.5)*Vrui::getDisplaySize();
    Vrui::Point l2=Vrui::getDisplayCenter()+Vrui::Vector(1.0,-0.1,0.5)*Vrui::getDisplaySize();
    Vrui::getLightsourceManager()->createLightsource(true,GLLight(GLLight::Color(0.5f,0.25f,0.25f),GLLight::Position(l1[0],l1[1],l1[2],1.0f)));
    Vrui::getLightsourceManager()->createLightsource(true,GLLight(GLLight::Color(0.25f,0.25f,0.5f),GLLight::Position(l2[0],l2[1],l2[2],1.0f)));

    /* Initialize navigation transformation: */
    centerDisplayCallback(0);
}
NanotechConstructionKit::NanotechConstructionKit(int& argc,char**& argv,char**& appDefaults)
	:Vrui::Application(argc,argv,appDefaults),
	 grid(0),
	 createType(UnitDragger::NONE),draggingMode(UnitDragger::SINGLE_UNIT),
	 overrideTools(true),
	 influenceSphereRadius(10.0*Vrui::getUiSize()),
	 currentVoid(0),
	 mainMenu(0),statisticsDialog(0)
	{
	/* Parse the command line: */
	int loadFileMode=0;
	const char* loadFileName=0;
	const char* configFileName=NANOTECHCONSTRUCTIONKIT_CFGFILENAME;
	NCK::Scalar domainSize(24);
	for(int i=1;i<argc;++i)
		{
		if(argv[i][0]=='-')
			{
			if(strcasecmp(argv[i]+1,"CAR")==0)
				loadFileMode=1;
			else if(strcasecmp(argv[i]+1,"UNITS")==0)
				loadFileMode=0;
			else if(strcasecmp(argv[i]+1,"CONFIGFILE")==0)
				{
				++i;
				configFileName=argv[i];
				}
			else if(strcasecmp(argv[i]+1,"DOMAINSIZE")==0)
				{
				++i;
				domainSize=NCK::Scalar(atof(argv[i]));
				}
			}
		else
			loadFileName=argv[i];
		}
	
	/* Initialize structural unit classes: */
	Misc::ConfigurationFile nckConfigFile(configFileName);
	nckConfigFile.setCurrentSection("/NanotechConstructionKit");
	NCK::Scalar maxUnitRadius=NCK::UnitManager::initializeUnitTypes(nckConfigFile.getCurrentSection());
	
	/* Load the input file: */
	if(loadFileName!=0)
		{
		if(loadFileMode==0)
			{
			/* Read a unit file: */
			grid=NCK::readUnitFile(maxUnitRadius,loadFileName);
			}
		else
			{
			/* Read a CAR file: */
			grid=NCK::readCarFile(loadFileName);
			}
		}
	else
		{
		/* Create empty space grid: */
		NCK::Box gridBox(NCK::Point(-domainSize,-domainSize,-domainSize),NCK::Point(domainSize,domainSize,domainSize));
		grid=new NCK::SpaceGrid(gridBox,maxUnitRadius,0x7);
		}
	
	/* Set space grid parameters: */
	grid->setAttenuation(Math::pow(nckConfigFile.retrieveValue<double>("./attenuation",0.95),20.0));
	
	/* Set space grid rendering flags: */
	grid->readRenderingFlags(nckConfigFile.getSection("./RenderingFlags"));
	
	/* Calculate grid boundary color based on background color: */
	Vrui::Color gridColor;
	for(int i=0;i<3;++i)
		gridColor[i]=1.0f-Vrui::getBackgroundColor()[i];
	gridColor[3]=1.0f;
	grid->setGridBoundaryColor(gridColor);
	
	/* Create the UI widgets: */
	mainMenu=createMainMenu();
	Vrui::setMainMenu(mainMenu);
	statisticsDialog=createStatisticsDialog();
	
	/* Initialize navigation transformation: */
	centerDisplayCallback(0);
	
	/* Enable continuous update: */
	Vrui::updateContinuously();
	}
Esempio n. 9
0
ClusterJello::ClusterJello(int& argc,char**& argv,char**& appDefaults)
	:Vrui::Application(argc,argv,appDefaults),
	 clusterPipe(Vrui::openPipe()),
	 crystal(0),
	 atomLocks(17),
	 updateTime(0.02),
	 renderer(0),
	 mainMenu(0),settingsDialog(0),
	 nextDraggerID(0)
	{
	/* Target frame rate is only (optional) command line parameter: */
	if(argc>=2)
		updateTime=1.0/atof(argv[1]);
	
	/* Initialize the proxy crystal states: */
	for(int i=0;i<3;++i)
		proxyCrystal.accessSlot(i).setNumAtoms(JelloCrystal::Index(4,4,8));
	
	/* Initialize the crystal renderer: */
	renderer=new JelloRenderer(proxyCrystal.getLockedValue());
	
	/* Determine a good color to draw the domain box: */
	GLColor<GLfloat,3> domainBoxColor;
	for(int i=0;i<3;++i)
		domainBoxColor[i]=1.0f-Vrui::getBackgroundColor()[i];
	renderer->setDomainBoxColor(domainBoxColor);
	
	if(Vrui::isMaster())
		{
		/* Initialize the simulated Jell-O crystal: */
		crystal=new JelloCrystal(JelloCrystal::Index(4,4,8));
		currentSimulationParameters.atomMass=crystal->getAtomMass();
		currentSimulationParameters.attenuation=crystal->getAttenuation();
		currentSimulationParameters.gravity=crystal->getGravity();
		Vrui::write(clusterPipe,currentSimulationParameters.atomMass);
		Vrui::write(clusterPipe,currentSimulationParameters.attenuation);
		Vrui::write(clusterPipe,currentSimulationParameters.gravity);
		Vrui::finishMessage(clusterPipe);
		
		/* Start the simulation thread: */
		simulationThread.start(this,&ClusterJello::simulationThreadMethodMaster);
		}
	else
		{
		/* Receive the initial simulation parameters: */
		currentSimulationParameters.atomMass=clusterPipe->read<Scalar>();
		currentSimulationParameters.attenuation=clusterPipe->read<Scalar>();
		currentSimulationParameters.gravity=clusterPipe->read<Scalar>();
		
		/* Start the simulation thread: */
		simulationThread.start(this,&ClusterJello::simulationThreadMethodSlave);
		}
	
	/* Create the program's user interface: */
	mainMenu=createMainMenu();
	Vrui::setMainMenu(mainMenu);
	settingsDialog=createSettingsDialog();
	
	/* Initialize the navigation transformation: */
	centerDisplayCallback(0);
	}
Esempio n. 10
0
GridEditor::GridEditor(int& argc,char**& argv)
	:Vrui::Application(argc,argv),
	 grid(0),
	 saveGridHelper("SavedGrid.fvol",".fvol",Vrui::openDirectory(".")),
	 exportSurfaceHelper("ExportedSurface.ply",".ply",Vrui::openDirectory(".")),
	 mainMenu(0)
	{
	/* Parse the command line: */
	EditableGrid::Index newGridSize(256,256,256);
	EditableGrid::Size newCellSize(1.0f,1.0f,1.0f);
	const char* gridFileName=0;
	for(int i=1;i<argc;++i)
		{
		if(argv[i][0]=='-')
			{
			if(strcasecmp(argv[i]+1,"h")==0)
				{
				std::cout<<"Usage:"<<std::endl;
				std::cout<<"  "<<argv[0]<<" [-gridSize <sx> <sy> <sz>] [-cellSize <cx> <cy> <cz>] [<grid file name>]"<<std::endl;
				std::cout<<"Options:"<<std::endl;
				std::cout<<"  -gridSize <sx> <sy> <sz>"<<std::endl;
				std::cout<<"    Number of vertices for newly-created grids in x, y, and z. Defaults to 256 256 256."<<std::endl;
				std::cout<<"  -cellSize <cx> <cy> <cz>"<<std::endl;
				std::cout<<"    Grid cell dimensions for newly-created grids in x, y, and z in some arbitrary unit of measurement. Defaults to 1.0 1.0 1.0."<<std::endl;
				std::cout<<"  <grid file name>"<<std::endl;
				std::cout<<"    Name of a grid file (extension .fvol) to load upon start-up. If not provided, a new grid will be created."<<std::endl;
				}
			else if(strcasecmp(argv[i]+1,"gridSize")==0)
				{
				if(i+3<argc)
					{
					/* Read the requested size for new grids: */
					for(int j=0;j<3;++j)
						{
						++i;
						newGridSize[j]=atoi(argv[i]);
						}
					}
				else
					{
					std::cerr<<"Ignoring dangling -gridSize option"<<std::endl;
					i=argc;
					}
				}
			else if(strcasecmp(argv[i]+1,"cellSize")==0)
				{
				if(i+3<argc)
					{
					/* Read the requested cell size for new grids: */
					for(int j=0;j<3;++j)
						{
						++i;
						newCellSize[j]=EditableGrid::Size::Scalar(atof(argv[i]));
						}
					}
				else
					{
					std::cerr<<"Ignoring dangling -gridSize option"<<std::endl;
					i=argc;
					}
				}
			}
		else if(gridFileName==0)
			gridFileName=argv[i];
		}
	
	if(gridFileName!=0)
		{
		try
			{
			/* Load the grid from a float-valued vol file: */
			IO::FilePtr volFile=Vrui::openFile(gridFileName);
			volFile->setEndianness(Misc::BigEndian);
			
			/* Read the file header: */
			EditableGrid::Index numVertices;
			volFile->read<int>(numVertices.getComponents(),3);
			int borderSize=volFile->read<int>();
			for(int i=0;i<3;++i)
				numVertices[i]+=borderSize*2;
			float domainSize[3];
			volFile->read<float>(domainSize,3);
			EditableGrid::Size cellSize;
			for(int i=0;i<3;++i)
				cellSize[i]=domainSize[i]/float(numVertices[i]-borderSize*2-1);
			
			/* Create the grid: */
			grid=new EditableGrid(numVertices,cellSize);
			
			/* Read all grid values: */
			for(EditableGrid::Index i(0);i[0]<grid->getNumVertices(0);i.preInc(grid->getNumVertices()))
				grid->setValue(i,volFile->read<float>());
			grid->invalidateVertices(EditableGrid::Index(0,0,0),grid->getNumVertices());
			}
		catch(std::runtime_error err)
			{
			std::cerr<<"Unable to load grid file "<<gridFileName<<" due to exception "<<err.what()<<std::endl;
			
			/* Create a new grid: */
			grid=new EditableGrid(newGridSize,newCellSize);
			}
		}
	else
		{
		/* Create a new grid: */
		grid=new EditableGrid(newGridSize,newCellSize);
		}
	
	/* Create the program GUI: */
	mainMenu=createMainMenu();
	Vrui::setMainMenu(mainMenu);
	
	/* Initialize the navigation transformation: */
	centerDisplayCallback(0);
	
	/* Initialize the tool classes: */
	EditTool::initClass(*Vrui::getToolManager());
	}