void VolumeURLListProperty::loadVolumes(bool selectedOnly /*= false*/, bool removeOnFailure /*= false*/) {

    std::vector<std::string> failedURLs;

    for (size_t i=0; i<value_.size(); i++) {
        std::string url = value_[i];
        if (selectedOnly && !isSelected(url))
            continue;
        if (getVolume(url))
            continue;

        try {
            loadVolume(url, false);
        }
        catch (tgt::FileException& e) {
            LERROR(e.what());
            failedURLs.push_back(url);
        }
        catch (std::bad_alloc&) {
            LERROR("bad allocation while loading volume: " << url);
            failedURLs.push_back(url);
        }
        catch (tgt::Exception& e) {
            LERROR("unknown exception while loading volume '" << url << "':" << e.what());
            failedURLs.push_back(url);
        }
    }

    if (removeOnFailure) {
        for (size_t i=0; i<failedURLs.size(); i++)
            removeURL(failedURLs.at(i), false);
    }

    invalidate();
}
示例#2
0
Volume::Volume(char* filePath, int* vSize, Eigen::Vector3f dimension){
    cout << "Start" << endl;
    int voxelArraySize = vSize[0]*vSize[1]*vSize[2];
    volSize = vSize;
    voxelArray = new GLubyte[voxelArraySize];

    ///Reading the texture file and sorting it in voxelArray
    ifstream file (filePath, ios::in|ios::binary);

    char buff[128];
    int i =0;

    if(file.is_open())
    {
        cout << "3D texture file opened:"<<endl;
        while (!file.eof())
        {
            file.read(buff, 1);
            voxelArray[i] = (unsigned char)buff[0];
            i+=1;
        }
        file.close();
    }
    else cout << "Unable to open file!" << endl;

    ///Initializing the mesh
    mesh = new Mesh();
    cout << "Mesh created." << endl;

    realDimension = dimension;

    ///Loading the Volume
    cout << "Entering loadVolume()" << endl;
    loadVolume();
}
示例#3
0
scene::scene(string filename){
	cout << "Reading scene from " << filename << " ..." << endl;
	cout << " " << endl;
	char* fname = (char*)filename.c_str();
	fp_in.open(fname);
	if(fp_in.is_open()){
		while(fp_in.good()){
			string line;
            utilityCore::safeGetline(fp_in,line);
			if(!line.empty()){
				vector<string> tokens = utilityCore::tokenizeString(line);
				if(strcmp(tokens[0].c_str(), "MATERIAL")==0){
				    loadMaterial(tokens[1]);
				    cout << " " << endl;
				}else if(strcmp(tokens[0].c_str(), "OBJECT")==0){
				    loadObject(tokens[1]);
				    cout << " " << endl;
				}else if(strcmp(tokens[0].c_str(), "LIGHT")==0){
				    loadLight(tokens[1]);
				    cout << " " << endl;
				}else if(strcmp(tokens[0].c_str(), "VOLUME")==0){
				    loadVolume(tokens[1]);
				    cout << " " << endl;
				}else if(strcmp(tokens[0].c_str(), "CAMERA")==0){
				    loadCamera();
				    cout << " " << endl;
				}
			}
		}
	}
}
void ACubiquityVolume::PostEditChangeProperty(FPropertyChangedEvent & PropertyChangedEvent)
{
	Super::PostEditChangeProperty(PropertyChangedEvent);

	const FName PropertyName = PropertyChangedEvent.Property ? PropertyChangedEvent.Property->GetFName() : NAME_None;

	if (PropertyName == FName(TEXT("volumeFileName")))
	{
		//Should we save the old volume? Probably not without asking.
		//Unload old volume
		//Load new one

		TArray<AActor*> children = Children; //Make a copy to avoid overruns
		for (AActor* childActor : children) //Should only be 1 child of this Actor
		{
			if (childActor && !childActor->IsPendingKillPending())
			{
				GetWorld()->DestroyActor(childActor);
			}

		}

		loadVolume();

		createOctree();

		updateMaterial(); //TODO needed?
	}
	else if (PropertyName == FName(TEXT("Material")))
	{
		updateMaterial();
	}
}
示例#5
0
//--------------------------------------------------------------
//  class WarpVolume member functions
//--------------------------------------------------------------
WarpVolume::WarpVolume(char* fVF, int xx, int yy, 
	float rx,float ry, float rz )
  :dimX(xx),dimY(yy),fdMap(NULL),
   voxSize(sizeof(struct Pt3d)), xres(rx), yres(ry), zres(rz)
{
   strcpy(fWarp, fVF);
   planSize = dimX*dimY;
   loadVolume(fVF, fdMap, dimZ);
   reorganize(fdMap,dimZ);
}
示例#6
0
WITMainWindowController::WITMainWindowController(WITMainWindow *window)
{
	this->window = window;
	this->app = &WITApplication::getInstance();
	this->connect(this->window, SIGNAL(loadPDB(std::string)), this->app->getPathwayController(), SLOT(loadPDB(std::string)));
	this->connect(this->window, SIGNAL(loadVolume(std::string)), this->app->getSubjectDataController(), SLOT(loadVolume(std::string)));
	this->connect(this->window, SIGNAL(undo()), this->app->getUndoSystem(), SLOT(undo()));
	this->connect(this->window, SIGNAL(redo()), this->app->getUndoSystem(), SLOT(redo()));

	// Add the controller for the view widget
	new WITViewController(this->window->getViewWidget());
}
void ACubiquityVolume::PostActorCreated()
{
	loadVolume();

	const auto eyePosition = eyePositionInVolumeSpace();
	//while (!volume()->update({ eyePosition.X, eyePosition.Y, eyePosition.Z }, 0.0)) { /*Keep calling update until it returns true*/ }
	volume()->update({ eyePosition.X, eyePosition.Y, eyePosition.Z }, lodThreshold);

	createOctree();

	Super::PostActorCreated();
}
示例#8
0
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent)
    {
        loadVolAction = new QAction("Load Volume Data", this);
        connect(loadVolAction, SIGNAL(triggered()), this, SLOT(loadVolume()));

        loadTFAction = new QAction("Load Transfer Function", this);
        connect(loadTFAction, SIGNAL(triggered()), this, SLOT(loadTransferFunction()));

        quitAction = new QAction("Quit", this);
        connect(quitAction, SIGNAL(triggered()), this, SLOT(quit()));

        mipAction = new QAction("Maximum Intensity Projection", this);
        connect(mipAction, SIGNAL(triggered()), this, SLOT(modeMIP()));

        avgAction = new QAction("Average Intensity Projection", this);
        connect(avgAction, SIGNAL(triggered()), this, SLOT(modeAVG()));

        comAction = new QAction("Composition Projection", this);
        connect(comAction, SIGNAL(triggered()), this, SLOT(modeCOM()));

        contourTreeAction = new QAction("Build Contour Tree", this);
        connect(contourTreeAction, SIGNAL(triggered()), this, SLOT(buildContourTree()));

        fileMenu = new QMenu("File", this);
        fileMenu->addAction(loadVolAction);
        fileMenu->addAction(loadTFAction);
        fileMenu->addSeparator();
        fileMenu->addAction(quitAction);

        viewMenu = new QMenu("View", this);
        viewMenu->addAction(mipAction);
        viewMenu->addAction(avgAction);
        viewMenu->addAction(comAction);

        toolMenu = new QMenu("Tools", this);
        toolMenu->addAction(contourTreeAction);

        menuBar()->addMenu(fileMenu);
        menuBar()->addMenu(viewMenu);
        menuBar()->addMenu(toolMenu);

        resize(600, 600);

        QGLFormat f;
        f.setVersion(4, 2);
        f.setProfile(QGLFormat::CoreProfile);

        view = new Ui::Viewport(f, this);
        setCentralWidget(view);
    }
void ACubiquityVolume::PostLoad()
{
	//In here, we are loading an existing volume. We should initialise all the Cubiquity stuff by loading the filename from the UProperty
	//It seems too early to spawn actors as the World doesn't exist yet.
	//Actors in the tree will have been serialised anyway so should be loaded.

	loadVolume();

	const auto eyePosition = eyePositionInVolumeSpace();
	//while (!volume()->update({ eyePosition.X, eyePosition.Y, eyePosition.Z }, 0.0)) { /*Keep calling update until it returns true*/ }
	volume()->update({ eyePosition.X, eyePosition.Y, eyePosition.Z }, lodThreshold);

	Super::PostLoad();
}
示例#10
0
void init()
{
	sx = sy = sz = 1;
	coloredVolume.resize(4);
	curDataIdx = 0;
	curResLevel = 0;

	colorMap = loadColorMap(0);
	coloredVolume = loadVolume(curDataIdx, curResLevel);

	printHelp();

	initDisp();
}
示例#11
0
Volume::Volume(){
            volSize = new int[3];
            volSize[0] = XSIZE; volSize[1] = YSIZE; volSize[2] = ZSIZE;

            ///Setting up the
            int voxelArraySize = XSIZE*YSIZE*ZSIZE;
            voxelArray = new GLubyte[voxelArraySize];

            ///Reading the texture file and sorting it in voxelArray
            ifstream file (FILENAME, ios::in|ios::binary);

            char buff[128];
            int i =0;

            if(file.is_open())
            {
                cout << "3D texture file opened:"<<endl;
                while (!file.eof()) //hardcoded number of bytes to read
                {
                    file.read(buff, 1);
                    voxelArray[i] = (unsigned char)buff[0];
                    i+=1;
                }
                file.close();
                cout<<"Closed file"<<endl; // << iterations << " voxels read." << endl;
            }
            else cout << "Unable to open file!" << endl;

            ///Initializing the mesh
            mesh = new Mesh();
            cout << "Mesh created." << endl;

            realDimension << 1.0, 1.0, 1.0;

            ///Loading the Volume
            cout << "Entering loadVolume()" << endl;
            loadVolume();
}
// function that creates a roi map from glm and a previously defined roi in mni
void emotionRoiProcessing::createROIVolume(studyParams &vdb)
{
	// Bring MNI Mask to Subject Space
	char compositeFile[500], outputFile[500], name[500], regionExtractMapFile[500], roiVolumeFile[500], meanFile[500];
	char pngFile[500];
	double correlationExtractPercent;
	stringstream CmdLn;
	char prefix[30] = "_RFI2";
	vector<vector<double>> timeseries;

	// generating the means file
	volume<float> v;

	// preparing timeseries variable
	timeseries.resize(meanCalculation.roiCount());
	for (int i = 0; i < timeseries.size(); i++)
		timeseries[i].resize(vdb.interval.maxIndex());

	// calculating the means
	for (int i = 0; i < vdb.interval.maxIndex(); i++)
	{
		loadVolume(vdb, v, i+1);
		meanCalculation.calculateMeans(v);

		for (int j = 0; j < meanCalculation.roiCount(); j++)
			timeseries[j][i] = meanCalculation.roiMean(j);
	}

	// z normalized
	for (int j = 0; j < timeseries.size(); j++)	znormalise(timeseries[j]);

	// saving the result to file
	sprintf(meanFile, "%s%s_%s%s.txt", vdb.outputDir, vdb.subject, "means", vdb.trainFeatureSuffix);
	fstream Output(meanFile, fstream::in | fstream::out | fstream::trunc);
	for (int i = 0; i < vdb.interval.maxIndex(); i++)
	{
		for (int j = 0; j < timeseries.size(); j++)
			Output << timeseries[j][i] << '\t';
		Output << '\n';
	}
	Output.close();

	// generating the roi means graph png
	fprintf(stderr, "Generating roi means graphic\n");
	changeFileExt(meanFile, ".png", pngFile);
	CmdLn << "fsl_tsplot -i " << meanFile << " -t \"z-normalised roi means plot\" -u 1 --start=1 --finish=" << meanCalculation.roiCount() << " -a ";

	vector<int> roiValues;
	meanCalculation.getRoiValues(roiValues);
	// Building the labels with the intensities of the roi volume file
	int counter=0;
	CmdLn << '\"';
	for (int t = 0; t < roiValues.size(); t++)
	{
		CmdLn << "Intensity " << roiValues[t];
		counter++;
		if (counter < meanCalculation.roiCount())
			CmdLn << ',';
	}
	// completing the command
	CmdLn << '\"';
	CmdLn << " -w 640 -h 144 -o " << pngFile;
	fsl_tsplot((char *)CmdLn.str().c_str());


	extractFileName(vdb.mniMask, name);
	for (int t = 0; t<strlen(name); t++)
	if (name[t] == '.') name[t] = '_';

	sprintf(outputFile, "%s%s%s.nii", vdb.inputDir, name, vdb.trainFeatureSuffix);

	MniToSubject(vdb.maskFile, vdb.mniMask, vdb.mniTemplate, outputFile, prefix);

	// saving a composite file just to assure the side of the roi volume
	sprintf(compositeFile, "%s%s%s.nii", vdb.inputDir, "compositeFile", vdb.trainFeatureSuffix);
	uniteVolumes(vdb.rfiFile, outputFile, compositeFile);

	// read Region extract map file and percentage
	correlationExtractPercent = vdb.readedIni.GetDoubleValue("FRIEND", "PercentageOfBestVoxelsPerROI") / 100.0;
	strcpy(regionExtractMapFile, vdb.readedIni.GetValue("FRIEND", "ROIExtractionMapFile"));


	RegionExtraction extractor;


	// reading the mappings
	std::map<int, int> mappings;
	extractor.readMappings(regionExtractMapFile, mappings);

	sprintf(roiVolumeFile, "%s%s%s%s", vdb.outputDir, "ROIsMap", vdb.trainFeatureSuffix, ".nii");

	// Execute segmentation
	extractor.regionsExtraction(outputFile, vdb.glmTOutput, vdb.featuresAllTrainSuffix, roiVolumeFile, mappings, correlationExtractPercent);

	// calculate initial target values for positive and negative conditions
	if (fileExists(roiVolumeFile))
	{
		meanCalculation.loadReference(roiVolumeFile);
		positiveIndex = meanCalculation.roiIndex(3); // 3 in the intensity value of positive emotion ROI
		negativeIndex = meanCalculation.roiIndex(1); // 1 in the intensity value of negative emotion ROI

		for (int i=1; i <= vdb.interval.maxIndex(); i++)
		{
			float classnum, projection;
			processVolume(vdb, i, classnum, projection);
		}

		char negativeCurveFile[BUFF_SIZE], positiveCurveFile[BUFF_SIZE];
		sprintf(negativeCurveFile, "%s%c%s%s.txt", vdb.outputDir, PATHSEPCHAR, "negative_curve", vdb.trainFeatureSuffix);
		sprintf(positiveCurveFile, "%s%c%s%s.txt", vdb.outputDir, PATHSEPCHAR, "positive_curve", vdb.trainFeatureSuffix);

		positiveActivationLevel.saveCurves(positiveCurveFile);
		negativeActivationLevel.saveCurves(negativeCurveFile);

		vdb.readedIni.SetDoubleValue("FRIEND", "NegativeActivationLevel", negativeActivationLevel.mean);
		vdb.readedIni.SetDoubleValue("FRIEND", "PositiveActivationLevel", positiveActivationLevel.mean);
		vdb.readedIni.SaveFile(vdb.configFileNameRead);
	}
}
// calculates the feedback value
int emotionRoiProcessing::processVolume(studyParams &vdb, int index, float &classnum, float &feedbackValue)
{
   int idxInterval = vdb.interval.returnInterval(index);
   double positivePSC, negativePSC;

   volume<float> v;


   loadVolume(vdb, v, index);
   // if in baseline condition, calculates the mean volume, one by one
   classnum = vdb.getClass(index);
   feedbackValue = 0;

   double intervalSize = (double)(vdb.interval.intervals[idxInterval].end - vdb.interval.intervals[idxInterval].start + 1);

   if (vdb.interval.isBaselineCondition(index))
   {
      if (vdb.interval.intervals[idxInterval].start == index) meanbaseline = v;
      else meanbaseline += v;
      // in the end of condition, divides the sum by the size of the current block
      if (vdb.interval.intervals[idxInterval].end == index) 
      {
         meanbaseline /= intervalSize;
         meanCalculation.calculateMeans(meanbaseline);
         
         // calculates the mean roi value of the mean volume. We just need this value
         positiveBaseline = meanCalculation.roiMean(positiveIndex);
		 negativeBaseline = meanCalculation.roiMean(negativeIndex);
	  }
   }
   else // task condition. Taking the mean of the volume and calculating the PSC
   {
      meanCalculation.calculateMeans(v);
	  positivePSC = PSC(meanCalculation.roiMean(positiveIndex), positiveBaseline);
	  negativePSC = PSC(meanCalculation.roiMean(negativeIndex), negativeBaseline);

	  // negative emotion Feedback
	  if (classnum == 1)
	  {
		  feedbackValue = negativePSC / negativeTargetValue;
		  if (vdb.interval.intervals[idxInterval].start == index) negativePSCMean = negativePSC / intervalSize;
		  else  negativePSCMean += negativePSC / intervalSize;

		  if (vdb.interval.intervals[idxInterval].end == index)
		  {
			  if (negativePSCMean >= negativeTargetValue)
				  negativeBlocksAboveTarget++;
		  }

		  if (negativePSC > 0)
			  negativeActivationLevel.addValue(negativePSC, 1);

		  double valueLevel = negativeActivationLevel.mean * (1 + levelMultiplyer);
		  if (valueLevel > 0) negativeTargetValue = valueLevel;
	  }
	  else if (classnum == 3)
	  {
		  feedbackValue = positivePSC / positiveTargetValue;
		  if (vdb.interval.intervals[idxInterval].start == index) positivePSCMean = positivePSC / intervalSize;
		  else  positivePSCMean += positivePSC / intervalSize;

		  if (vdb.interval.intervals[idxInterval].end == index)
		  {
			  if (positivePSCMean >= positiveTargetValue)
				  positiveBlocksAboveTarget++;
		  }

		  if (positivePSC > 0)
			  positiveActivationLevel.addValue(positivePSC, 1);

		  double valueLevel = positiveActivationLevel.mean * (1 + levelMultiplyer);
		  if (valueLevel > 0) positiveTargetValue = valueLevel;
	  }
      fprintf(stderr, "Feedback value = %f\n", feedbackValue);
   }
   return 0;
}