// Create a volume rendering node with all desired attachments
NodePtr makeVolume( const char * datFile)
{  
    // Load the 3D-image and store it in the volume texture attachment
    ImagePtr datImage = Image::create();
    if (false == datImage->read(datFile)) {
        SLOG << "File: " << datFile << " not found" << std::endl;
	exit (-1);
    }
    
    return makeVolume(datImage);
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    // set log level to lowest unless specified otherwise by env variable
    osgLog().setLogLevel((LogLevel) 0);

    // create the scene or load it from a .osg-file
    if (argc == 1)
        scene = makeVolume("00_data64x64x64.dat");
    else
    {
        scene = SceneFileHandler::the().read(argv[1]);
        if (scene == NullFC)
        {
            SLOG << "Could not read file " << argv[1] << std::endl;
            exit(-1);
        }
    }

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow   (gwin );
    mgr->setRoot     (scene);
    mgr->setHighlight(scene);

    // show the whole scene
    mgr->showAll();
    Pnt3f from = mgr->getNavigator()->getFrom();
    from[2] = 3 * from[2];
    mgr->getNavigator()->setFrom(from);

    // GLUT main loop
    glutMainLoop();

    return 0;
}
示例#3
0
WCHAR* fileManage::getUsePath(const UINT num, WCHAR* dirPath, WCHAR* suffix) {
	if(useVolume!=NULL || realizePath!=NULL) {
		delete[] useVolume;
		delete[] realizePath;
	}
	int vlen = makeVolume(num);
	int plen = wcslen(dirPath);
	makeDir(dirPath, vlen, plen);
	if(dirPath[plen-1]!=L'\\') {
		plen++;
	}
	int flen = randomFileName();
	int slen = wcslen(suffix);
	int len = vlen+plen+flen+slen;
	realizePath = new WCHAR[len];
	makeFilePath(dirPath, suffix);

	return realizePath;
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    // create the scene or load it from a .osg-file
    if (argc == 1)
    {
        scene = makeVolume("00_data64x64x64.dat");
    }
    else if(!strcmp(argv[1], "RGBA"))
    {
        ImagePtr imageP = Image::create();
        const int res=64;
        Real32 rres = res;
        beginEditCP(imageP);
        imageP->set(Image::OSG_RGBA_PF,res,res,res);

        UInt8 *d = imageP->editData();
        for(Int16 z = 0; z < res; ++z)         
        for(Int16 y = 0; y < res; ++y)         
        for(Int16 x = 0; x < res; ++x)
        {
            Real32 dx = x/rres - .5f;
            Real32 dy = y/rres - .5f;
            Real32 dz = z/rres - .5f;

            Real32 dsq = (dx*dx + dy*dy + dz*dz);

            int  bx = (x<2 || x >=res-2),
                 by = (y<2 || y >=res-2),
                 bz = (z<2 || z >=res-2);
            if(bx + by + bz >=2)
            {
                *d++ = 0;
                *d++ = 255;
                *d++ = 0;
                *d++ = 64;
            } 
            else if (osgabs(dx) < .2 && osgabs(dy) < .2)
            {
                *d++ = 0;
                *d++ = 0;
                *d++ = 0;
                *d++ = 0;              
            }
            else if(dsq <= .25f)
            {
                *d++ = static_cast<UInt8>(x/rres * 255.f);
                *d++ = static_cast<UInt8>(y/rres * 255.f);
                *d++ = static_cast<UInt8>(z/rres * 255.f);
                *d++ = static_cast<UInt8>((.3f-dsq*dsq*dsq) * 255.f);
            }
            else
            {
                *d++ = 0;
                *d++ = 0;
                *d++ = 0;
                *d++ = 0;
            }
        }      

        endEditCP(imageP);  
        
        imageP->setAttachmentField( "SliceThickness", "1 1 1" );
        scene = makeVolume(imageP);        
    }
    else if(!strcmp(argv[1], "RGB"))
    {
        ImagePtr imageP = Image::create();
        const int res=64;
        Real32 rres = res;
        beginEditCP(imageP);
        imageP->set(Image::OSG_RGB_PF,res,res,res);

        UInt8 *d = imageP->editData();
        for(Int16 z = 0; z < res; ++z)         
        for(Int16 y = 0; y < res; ++y)         
        for(Int16 x = 0; x < res; ++x)
        {
            Real32 dx = x/rres - .5f;
            Real32 dy = y/rres - .5f;
            Real32 dz = z/rres - .5f;

            Real32 dsq = (dx*dx + dy*dy + dz*dz);

            int  bx = (x<2 || x >=res-2),
                 by = (y<2 || y >=res-2),
                 bz = (z<2 || z >=res-2);
            if(bx + by + bz >=2)
            {
                *d++ = 0;
                *d++ = 255;
                *d++ = 0;
            } 
            else if (osgabs(dx) < .2 && osgabs(dy) < .2)
            {
                *d++ = 0;
                *d++ = 0;
                *d++ = 0;
            }
            else if(dsq <= .25f)
            {
                *d++ = static_cast<UInt8>(x/rres * 255.f);
                *d++ = static_cast<UInt8>(y/rres * 255.f);
                *d++ = static_cast<UInt8>(z/rres * 255.f);
            }
            else
            {
                *d++ = 0;
                *d++ = 0;
                *d++ = 0;
            }
        }      

        endEditCP(imageP);  
        
        imageP->setAttachmentField( "SliceThickness", "1 1 1" );
        scene = makeVolume(imageP);        
    }
    else if(!strcmp(argv[1], "LA16"))
    {
        ImagePtr imageP = Image::create();
        const int res=64;
        Real32 rres = res;
        beginEditCP(imageP);
        imageP->set(Image::OSG_LA_PF,res,res,res,1,1,0,0,
                    Image::OSG_UINT16_IMAGEDATA);

        UInt16 *d = reinterpret_cast<UInt16 *>(imageP->editData());
        for(Int16 z = 0; z < res; ++z)         
        for(Int16 y = 0; y < res; ++y)         
        for(Int16 x = 0; x < res; ++x)
        {
            Real32 dx = x/rres - .5f;
            Real32 dy = y/rres - .5f;
            Real32 dz = z/rres - .5f;

            Real32 dsq = (dx*dx + dy*dy + dz*dz);

            int  bx = (x<2 || x >=res-2),
                 by = (y<2 || y >=res-2),
                 bz = (z<2 || z >=res-2);
            if(bx + by + bz >=2)
            {
                *d++ = 65535;
                *d++ = 16384;
            } 
            else if (osgabs(dx) < .2 && osgabs(dy) < .2)
            {
                *d++ = 0;
                *d++ = 0;              
            }
            else if(dsq <= .25f)
            {
                *d++ = static_cast<UInt16>(z/rres * 65535.f);
                *d++ = static_cast<UInt16>((.3f-dsq*dsq*dsq) * 65535.f);
            }
            else
            {
                *d++ = 0;
                *d++ = 0;
            }
        }      

        endEditCP(imageP);  
        
        imageP->setAttachmentField( "SliceThickness", "1 1 1" );
        scene = makeVolume(imageP);        
    }
    else if(!strcmp(argv[1], "LA"))
    {
        ImagePtr imageP = Image::create();
        const int res=64;
        Real32 rres = res;
        beginEditCP(imageP);
        imageP->set(Image::OSG_LA_PF,res,res,res);

        UInt8 *d = imageP->editData();
        for(Int16 z = 0; z < res; ++z)         
        for(Int16 y = 0; y < res; ++y)         
        for(Int16 x = 0; x < res; ++x)
        {
            Real32 dx = x/rres - .5f;
            Real32 dy = y/rres - .5f;
            Real32 dz = z/rres - .5f;

            Real32 dsq = (dx*dx + dy*dy + dz*dz);

            int  bx = (x<2 || x >=res-2),
                 by = (y<2 || y >=res-2),
                 bz = (z<2 || z >=res-2);
            if(bx + by + bz >=2)
            {
                *d++ = 32;
                *d++ = 64;
            } 
            else if (osgabs(dx) < .2 && osgabs(dy) < .2)
            {
                *d++ = 0;
                *d++ = 0;              
            }
            else if(dsq <= .25f)
            {
                *d++ = static_cast<UInt8>(z/rres * 255.f);
                *d++ = static_cast<UInt8>((.3f-dsq*dsq*dsq) * 255.f);
            }
            else
            {
                *d++ = 0;
                *d++ = 0;
            }
        }      

        endEditCP(imageP);  
        
        imageP->setAttachmentField( "SliceThickness", "1 1 1" );
        scene = makeVolume(imageP);        
    }
    else if(!strcmp(argv[1], "L"))
    {
        ImagePtr imageP = Image::create();
        const int res=64;
        Real32 rres = res;
        beginEditCP(imageP);
        imageP->set(Image::OSG_L_PF,res,res,res);

        UInt8 *d = imageP->editData();
        for(Int16 z = 0; z < res; ++z)         
        for(Int16 y = 0; y < res; ++y)         
        for(Int16 x = 0; x < res; ++x)
        {
            Real32 dx = x/rres - .5f;
            Real32 dy = y/rres - .5f;
            Real32 dz = z/rres - .5f;

            Real32 dsq = (dx*dx + dy*dy + dz*dz);

            int  bx = (x<2 || x >=res-2),
                 by = (y<2 || y >=res-2),
                 bz = (z<2 || z >=res-2);
            if(bx + by + bz >=2)
            {
                *d++ = 32;
            } 
            else if (osgabs(dx) < .2 && osgabs(dy) < .2)
            {
                *d++ = 0;
            }
            else if(dsq <= .25f)
            {
                *d++ = static_cast<UInt8>(z/rres * 255.f);
            }
            else
            {
                *d++ = 0;
            }
        }      

        endEditCP(imageP);  
        
        imageP->setAttachmentField( "SliceThickness", "1 1 1" );
        scene = makeVolume(imageP);        
    }
    else
    {
        scene = SceneFileHandler::the().read(argv[1]);
        if (scene == NullFC)
        {
	        SLOG << "Could not read file " << argv[1] << std::endl;
	        exit(-1);
        }
        traverse(scene, 
             osgTypedFunctionFunctor1CPtrRef<Action::ResultE,
                                             NodePtr        >(findVolume));

    }

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin );
    mgr->setRoot  (scene);

    // show the whole scene
    mgr->showAll();
    Pnt3f from = mgr->getNavigator()->getFrom();
    from[2] = 3 * from[2];
    mgr->getNavigator()->setFrom(from);
    
    // GLUT main loop
    glutMainLoop();

    return 0;
}
void initialize() {

    system("clear");


    String ip = "", netmask = "", command = "", alltargetsStr = "", currtarget = "", iqn = "", sendtargets = "", sql = "";
    String disklist = "", assocvol = "", mountpt = "", avspace = "", command1 = "", sql1 = "";


    int counter = 1;
    //sqlite3 information
    sqlite3 *db;
    int rc = 0;

    //open sqlite3 db
    rc = sqlite3_open(DBNAME,&db);
    if (rc){
       printf("\nCannot open database.\n");
       exit(0);
    }

    // get network information of initiator
    // what if interface is not eth0? what if eth1...?
    runCommand("ip addr show eth0 | grep \'inet \' | awk \'{print $2}\' | cut -f1 -d\'/\'", ip);
    runCommand("ip addr show eth0 | grep \'inet \' | awk \'{print $2}\' | cut -f2 -d\'/\'", netmask);
    // printf("*****  Network information  *****\n");
    ip[strlen(ip)] = '\0';
    netmask[strlen(netmask)] = '\0';
    syslog(LOG_INFO, "DiskPooling: Initiator IP address: %s/%s\n\n", ip, netmask);


    // do nmap for active hosts with port 3260 open
    // syslog(LOG_INFO, "DiskPooling: Scanning network...\n");
    sprintf(command, "nmap -v -n %s%s%s -p 3260 | grep open | awk '/Discovered/ {print $NF}'", ip, "/", netmask);
    runCommand(command, alltargetsStr);

    // discover iscsi targets on hosts scanned successfully
    char *ptr;
    ptr = strtok(alltargetsStr, "\n");

    while(ptr != NULL) {
    	printf("%s is a target.\n", ptr);
    	sprintf(sendtargets,"iscsiadm -m discovery -t sendtargets -p %s | awk '{print $2}'",ptr);
    	runCommand(sendtargets,iqn);
        printf("%s\n", iqn);
        sprintf(sql,"insert into Target(tid, ipadd,iqn) values (%d, '%s','%s');",counter, ptr,iqn);

        printf("** initconf, sql = %s\n", sql);

        rc = sqlite3_exec(db,sql,0,0,0);
        if (rc != SQLITE_OK){
            printf("\nDid not insert successfully!\n");
            exit(0);
        }
        strcpy(sendtargets,"");
        strcpy(sql,"");
        strcpy(iqn, "");
        ptr = strtok(NULL, "\n");
        counter++;
    }

    printf("\n\nLogging in to targets...");
    system("iscsiadm -m node --login");
    printf("\n\nAvailable partitions written to file \"%s\"\n", AV_DISKS);
    sleep(5);
    sprintf(command, "cat /proc/partitions > '%s'", AV_DISKS);
    system(command);
    system("cat /proc/partitions");

    makeVolume(0);

    runCommand("cat '../file_transaction/AvailableDisks.txt' | grep sd[b-z] | awk '{print $4}'",disklist);

    // syslog(LOG_INFO, "DiskPooling: DONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");

    // syslog(LOG_INFO, "DiskPooling: Disklist before: %s\n\n", disklist);
    //strcat(disklist, "\n");
    char *ptr1;
    //int counter = 1;    // to aidz: di ako sure dito ah.. pano kung nag delete then init_conf sure ba na 1 lagi tapos sunod sunod?
    ptr1 = strtok(disklist,"\n");
    // syslog(LOG_INFO, "DiskPooling: PTR Before: %s\n\n", ptr1);
    // syslog(LOG_INFO, "DiskPooling: DIskList after: %s\n\n", disklist);
    counter = 1;
    while(ptr1 != NULL){
    //    syslog(LOG_INFO, "DiskPooling: PTR: %s\n\n", ptr1);
    //    syslog(LOG_INFO, "DiskPooling: INSIDE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
       strcat(assocvol,"/dev/vg");
       strcat(assocvol,ptr1);
       strcat(assocvol,"/lv");
       strcat(assocvol,ptr1);


       strcat(mountpt,"/mnt/lv");
       strcat(mountpt,ptr1);

       sprintf(command1,"lvdisplay %s | grep 'LV Size' | awk '{print $3,$4}'",assocvol);

       runCommand(command1,avspace);

       // edit here not sure if working (assume: avspace = "12.3 GiB")
       double space_bytes = toBytes(avspace);

       sprintf(sql1,"update Target set assocvol = '%s', mountpt = '%s', avspace = %lf where tid = %d", assocvol, mountpt, space_bytes, counter);

    //    syslog(LOG_INFO, "DiskPooling: SQL1 = %s\n", sql1);
       rc = sqlite3_exec(db,sql1,0,0,0);

       if (rc != SQLITE_OK){
           syslog(LOG_INFO, "DiskPooling: Error: Target is not recorded");
           exit(0);
       }

       strcpy(assocvol,"");
       strcpy(mountpt,"");
       strcpy(avspace,"");
       counter++;
       ptr1 = strtok(NULL,"\n");
    //    printf("***************\n\n\n%s\n\n\n", ptr1);
    }

    printf("\n\nInitialization finished\n");
}