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()); }
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()); }