From 300d6090d42b44a57dcb557beff90c51169eeeba Mon Sep 17 00:00:00 2001 From: Anna Ilina Date: Mon, 23 Oct 2017 12:47:23 -0400 Subject: [PATCH] ENH: 3ddosefilereader recognizes and loads 3ddose file https://github.com/SlicerRt/SlicerRT/issues/73 --- ...tkSlicerDosxyzNrc3dDoseFileReaderLogic.cxx | 617 +----------------- .../vtkSlicerDosxyzNrc3dDoseFileReaderLogic.h | 21 +- ...qSlicerDosxyzNrc3dDoseFileReaderModule.cxx | 4 +- ...qSlicerDosxyzNrc3dDoseFileReaderPlugin.cxx | 2 +- 4 files changed, 28 insertions(+), 616 deletions(-) diff --git a/DosxyzNrc3dDoseFileReader/Logic/vtkSlicerDosxyzNrc3dDoseFileReaderLogic.cxx b/DosxyzNrc3dDoseFileReader/Logic/vtkSlicerDosxyzNrc3dDoseFileReaderLogic.cxx index 346e1157d..5f8b0237f 100644 --- a/DosxyzNrc3dDoseFileReader/Logic/vtkSlicerDosxyzNrc3dDoseFileReaderLogic.cxx +++ b/DosxyzNrc3dDoseFileReader/Logic/vtkSlicerDosxyzNrc3dDoseFileReaderLogic.cxx @@ -45,8 +45,6 @@ #include #include -//todo: include error check for making sure that .3ddose file is proper format - //---------------------------------------------------------------------------- vtkStandardNewMacro(vtkSlicerDosxyzNrc3dDoseFileReaderLogic); @@ -60,141 +58,14 @@ vtkSlicerDosxyzNrc3dDoseFileReaderLogic::~vtkSlicerDosxyzNrc3dDoseFileReaderLogi { } -// //---------------------------------------------------------------------------- -// std::string vtkSlicerDosxyzNrc3dDoseFileReaderLogic::TrimSpacesFromEndsOfString(std::string &stringToTrim) -// { -// // Trim spaces from the beginning of the string -// stringToTrim.erase(stringToTrim.begin(), std::find_if(stringToTrim.begin(), stringToTrim.end(), std::not1(std::ptr_fun(std::isspace)))); -// // Trim spaces from the end of the string -// stringToTrim.erase(std::find_if(stringToTrim.rbegin(), stringToTrim.rend(), std::not1(std::ptr_fun(std::isspace))).base(), stringToTrim.end()); - -// return stringToTrim; -// } bool vtkSlicerDosxyzNrc3dDoseFileReaderLogic::AreEqualWithTolerance(double a, double b) { return fabs(a - b) < MAX_TOLERANCE_SPACING; } -// //---------------------------------------------------------------------------- -// bool vtkSlicerDosxyzNrc3dDoseFileReaderLogic::ReadDosxyzNrc3dDoseFileHeader(ifstream &readFileStream, std::map ¶meterList) -// { -// std::string currentStringFromFile = ""; -// while(readFileStream.good()) -// { -// char nextCharacter; -// nextCharacter = readFileStream.get(); - -// // The form feed character and the following line feed indicate the beginning of the image data -// if (nextCharacter == '\f') -// { -// break; -// } - -// // Parameters are separated from each other using semicolons and line feeds -// else if (nextCharacter == ';') -// { -// if (currentStringFromFile.compare("ncaa") != 0) -// { -// std::string parameterType; -// std::string parameterValue; -// size_t locationToSplitString = currentStringFromFile.find("=", 0); -// if (locationToSplitString != std::string::npos) -// { -// parameterType = currentStringFromFile.substr(0, locationToSplitString); -// parameterType = this->TrimSpacesFromEndsOfString(parameterType); -// parameterValue = currentStringFromFile.substr(locationToSplitString+1); -// parameterValue = this->TrimSpacesFromEndsOfString(parameterValue); -// if (parameterValue.size() <= 0) -// { -// vtkWarningMacro("ReadDosxyzNrc3dDoseFileHeader: Nothing follows the equal sign in header item: '" << parameterType << "'"); -// } -// else -// { -// parameterList[parameterType] = parameterValue; -// } -// } -// else -// { -// vtkWarningMacro("ReadDosxyzNrc3dDoseFileHeader: No equal sign in header item '" << parameterType << "'"); -// } -// } -// currentStringFromFile = ""; -// } -// else if (nextCharacter != '\n') -// { -// nextCharacter = ::tolower(nextCharacter); -// currentStringFromFile += nextCharacter; -// } -// } - -// return true; -// } - -// //---------------------------------------------------------------------------- -// template -// std::vector vtkSlicerDosxyzNrc3dDoseFileReaderLogic::ParseNumberOfNumbersFromString(std::string stringToParse, unsigned int numberOfNumbers) -// { -// std::vector vectorOfNumberOfNumbers (numberOfNumbers, 0); -// if (numberOfNumbers == 0) -// { -// return vectorOfNumberOfNumbers; -// } - -// stringToParse = this->TrimSpacesFromEndsOfString(stringToParse); -// unsigned int currentNumber = 0; -// // Parses out the specified number of numbers from the string, -// // assuming that numbers are separated by commas, spaces, or both -// while (currentNumber < numberOfNumbers) -// { -// size_t locationToSplitString = stringToParse.find_first_of(",", 0); -// std::string stringContainingNumber; -// if (locationToSplitString != std::string::npos) -// { -// stringContainingNumber = stringToParse.substr(0,locationToSplitString); -// stringToParse = stringToParse.substr(locationToSplitString+1); -// } -// else -// { -// size_t locationToSplitString = stringToParse.find_first_of(" ", 0); -// if (locationToSplitString != std::string::npos) -// { -// stringContainingNumber = stringToParse.substr(0,locationToSplitString); -// stringToParse = stringToParse.substr(locationToSplitString+1); -// } -// else -// { -// stringContainingNumber = stringToParse; -// } -// } -// stringContainingNumber = this->TrimSpacesFromEndsOfString(stringContainingNumber); -// if (stringContainingNumber.empty()) -// { -// return vectorOfNumberOfNumbers; -// } -// std::stringstream convertStringToNumber(stringContainingNumber); -// Num parsedNumber; -// // Converts the parsed string into the number -// convertStringToNumber >> parsedNumber; -// std::string checkForConversionSuccess; - -// // Checks that the string was correctly converted into the number, -// // which would result in nothing left in the stream -// if (convertStringToNumber >> checkForConversionSuccess) -// { -// return vectorOfNumberOfNumbers; -// } -// else -// { -// vectorOfNumberOfNumbers[currentNumber] = parsedNumber; -// } -// currentNumber++; -// stringToParse = this->TrimSpacesFromEndsOfString(stringToParse); -// } -// return vectorOfNumberOfNumbers; - -// } + //---------------------------------------------------------------------------- void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::PrintSelf(ostream& os, vtkIndent indent) @@ -202,477 +73,43 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::PrintSelf(ostream& os, vtkIndent i this->Superclass::PrintSelf(os, indent); } // -////---------------------------------------------------------------------------- -//void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char *filename, bool useImageIntensityScaleAndOffsetFromFile) // this is Jen's version (for reference). Delete once done. Mine is called "Read.." instead of "Load.." -//{ -// ifstream readFileStream; -// readFileStream.open(filename, std::ios::binary); -// if (!(readFileStream.fail())) -// { -// int size[3] = {0, 0, 0}; -// bool parameterMissing = false; -// bool parameterInvalidValue = false; -// -// bool headerParseSuccess = this->ReadDosxyzNrc3dDoseFileHeader(readFileStream, parameterList); -// if (headerParseSuccess == false) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The header did not parse correctly."); -// } -// -// // For each of the known parameters, interprets the string associated with the parameter into the correct format and sets the corresponding variable, as well as checking the correctness of the value -// std::vector numberFromParsedStringRank = this->ParseNumberOfNumbersFromString(parameterList["rank"], 1); -// if (numberFromParsedStringRank.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: An integer was not entered for the rank. The value entered for the rank must be 3."); -// parameterMissing = true; -// } -// else -// { -// rank = numberFromParsedStringRank[0]; -// if (rank != 3) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The value entered for the rank must be 3."); -// parameterInvalidValue = true; -// } -// } -// -// if (parameterList["type"].empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A string was not entered for the type. The value must be separated from the parameter with an '='. The value entered for the type must be raster."); -// parameterMissing = true; -// } -// else -// { -// type = parameterList["type"]; -// if (type.compare("raster") != 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The value entered for the type must be raster."); -// parameterInvalidValue = true; -// } -// } -// -// if (parameterList["format"].empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A string was not entered for the format. The value must be separated from the parameter with an '='. The value entered for the format must be slice."); -// parameterMissing = true; -// } -// else -// { -// format = parameterList["format"]; -// if (format.compare("slice") != 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The value entered for the format must be slice."); -// parameterInvalidValue = true; -// } -// } -// -// std::vector numberFromParsedStringBits = this->ParseNumberOfNumbersFromString(parameterList["bits"], 1); -// if (numberFromParsedStringBits.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: An integer was not entered for the bits. The value must be divisible by 8."); -// parameterMissing = true; -// } -// else -// { -// bits = numberFromParsedStringBits[0]; -// if (bits % 8 != 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The value entered for the bits must be divisible by 8."); -// parameterInvalidValue = true; -// } -// } -// -// std::vector numberFromParsedStringBands = this->ParseNumberOfNumbersFromString(parameterList["bands"], 1); -// if (numberFromParsedStringBands.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: An integer was not entered for the bands. The value entered for the bands must be 1."); -// parameterMissing = true; -// } -// else -// { -// bands = numberFromParsedStringBands[0]; -// if (bands != 1) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The value entered for the bands must be 1."); -// parameterInvalidValue = true; -// } -// } -// -// std::vector numbersFromParsedStringSize = this->ParseNumberOfNumbersFromString(parameterList["size"], 3); -// if (numbersFromParsedStringSize.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: 3 integers were not entered for the size."); -// parameterMissing = true; -// } -// else -// { -// size[0] = numbersFromParsedStringSize[0]; -// size[1] = numbersFromParsedStringSize[1]; -// size[2] = numbersFromParsedStringSize[2]; -// if (size[0] <= 0 || size[1] <=0 || size[2] <= 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The values for the size must each be greater than 0."); -// parameterInvalidValue = true; -// } -// } -// -// std::vector numbersFromParsedStringSpacing = this->ParseNumberOfNumbersFromString(parameterList["spacing"], 3); -// if (numbersFromParsedStringSpacing.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: 3 doubles were not entered for the spacing."); -// parameterMissing = true; -// } -// else -// { -// spacing[0] = numbersFromParsedStringSpacing[0]; -// spacing[1] = numbersFromParsedStringSpacing[1]; -// spacing[2] = numbersFromParsedStringSpacing[2]; -// if (spacing[0] < 0 || spacing[1] <0 || spacing[2] < 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The values for the spacing must each be greater than or equal to 0."); -// parameterInvalidValue = true; -// } -// } -// -// std::vector numbersFromParsedStringOrigin = this->ParseNumberOfNumbersFromString(parameterList["origin"], 3); -// if (numbersFromParsedStringOrigin.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: 3 doubles were not entered for the origin."); -// parameterMissing = true; -// } -// else -// { -// origin[0] = numbersFromParsedStringOrigin[0]; -// origin[1] = numbersFromParsedStringOrigin[1]; -// origin[2] = numbersFromParsedStringOrigin[2]; -// if (origin[0] < 0 || origin[1] <0 || origin[2] < 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The values for the origin must each be greater than or equal to 0."); -// parameterInvalidValue = true; -// } -// } -// -// std::vector numberFromParsedStringRawsize = this->ParseNumberOfNumbersFromString(parameterList["rawsize"], 1); -// if (numberFromParsedStringRawsize.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: An integer was not entered for the rawsize."); -// parameterMissing = true; -// } -// else -// { -// rawsize = numberFromParsedStringRawsize[0]; -// if (rawsize <= 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The value entered for the rawsize must be greater than or equal to 0."); -// parameterInvalidValue = true; -// } -// } -// -// std::vector numberFromParsedStringDataScale = this->ParseNumberOfNumbersFromString(parameterList["data_scale"], 1); -// if (numberFromParsedStringDataScale.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A double was not entered for the data_scale."); -// parameterMissing = true; -// } -// else -// { -// data_scale = numberFromParsedStringDataScale[0]; -// } -// -// std::vector numberFromParsedStringDataOffset = this->ParseNumberOfNumbersFromString(parameterList["data_offset"], 1); -// if (numberFromParsedStringDataOffset.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A double was not entered for the data_offset. The value entered must be 0."); -// parameterMissing = true; -// } -// else -// { -// data_offset = numberFromParsedStringDataOffset[0]; -// } -// -// if (parameterList["handlescatter"].empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A string was not entered for Handle Scatter. The value must be separated from the parameter with an '='. The value entered for Handle Scatter must be factor."); -// parameterMissing = true; -// } -// else -// { -// handleScatter = parameterList["handlescatter"]; -// if (handleScatter.compare("factor") != 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The value entered for Handle Scatter must be factor."); -// parameterInvalidValue = true; -// } -// } -// -// std::vector numberFromParsedStringReferenceScatterFactor = this->ParseNumberOfNumbersFromString(parameterList["referencescatterfactor"], 1); -// if (numberFromParsedStringReferenceScatterFactor.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A double was not entered for the Reference Scatter Factor. The value entered must be 1."); -// parameterMissing = true; -// } -// else -// { -// referenceScatterFactor = numberFromParsedStringReferenceScatterFactor[0]; -// } -// -// std::vector numberFromParsedStringDataScatterFactor = this->ParseNumberOfNumbersFromString(parameterList["datascatterfactor"], 1); -// if (numberFromParsedStringDataScatterFactor.empty()) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A double was not entered for the Data Scatter Factor. The value entered must be 1."); -// parameterMissing = true; -// } -// else -// { -// dataScatterFactor = numberFromParsedStringDataScatterFactor[0]; -// } -// -// if (parameterList["filter"].empty()) -// { -// vtkWarningMacro("LoadDosxyzNrc3dDoseFile: Empty filter value! The value must be separated from the parameter with an '='"); -// //parameterMissing = true; -// } -// else -// { -// filter = parameterList["filter"]; -// vtkDebugMacro("LoadDosxyzNrc3dDoseFile: Used filter for optical CT file is:\n" << filter); -// } -// -// if (parameterList["title"].empty() == false) -// { -// title = parameterList["title"]; -// -// // Parse out the name of the file from the file path given as the parameter title -// std::string fileNameFromTitle = title; -// int lastSlashPos = fileNameFromTitle.find_last_of("/\\"); -// if (lastSlashPos != std::string::npos) -// { -// fileNameFromTitle = fileNameFromTitle.substr(lastSlashPos+1); -// fileNameFromTitle = this->TrimSpacesFromEndsOfString(fileNameFromTitle); -// } -// // Strip the extension from the end of the string -// int lastPeriodPos = fileNameFromTitle.find_last_of("."); -// if (lastPeriodPos != std::string::npos && fileNameFromTitle.substr(lastPeriodPos) == ".DosxyzNrc3dDose") -// { -// fileNameFromTitle = fileNameFromTitle.substr(0, lastPeriodPos); -// } -// -// // Do the same to the input file name -// std::string fileNameStr = filename; -// lastSlashPos = fileNameStr.find_last_of("/\\"); -// if (lastSlashPos != std::string::npos) -// { -// fileNameStr = fileNameStr.substr(lastSlashPos+1); -// } -// lastPeriodPos = fileNameStr.find_last_of("."); -// if (lastPeriodPos != std::string::npos && fileNameStr.substr(lastPeriodPos) == ".DosxyzNrc3dDose") -// { -// fileNameStr = fileNameStr.substr(0, lastPeriodPos); -// } -// -// // Volume node name will be original file name and the title in parenthesis if different from file name -// name = fileNameStr; -// if (fileNameFromTitle != fileNameStr) -// { -// name += " (" + fileNameFromTitle + ")"; -// } -// } -// else -// { -// parameterMissing = true; -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A string was not entered for the title."); -// } -// -// if (parameterList["date"].size() <= 0) -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: A string was not entered for the date. The value must be separated from the parameter with an '='."); -// } -// else -// { -// date = parameterList["date"]; -// isDateCurrentlySet = true; -// } -// -// // Checks that the end of the header has been reached and that all of the required parameters have been set -// if (parameterMissing == false && parameterInvalidValue == false) -// { -// // Calculates the number of bytes to read based on some of the specified parameters -// long bytesToRead = 1; -// bytesToRead = bands*bits/8; -// int sizeOfImageData = (int)size[0]*size[1]*size[2]*(bits/8); -// -// if (rawsize != sizeOfImageData) -// { -// vtkWarningMacro("LoadDosxyzNrc3dDoseFile: The specified size from the parameters does not match the specified raw size."); -// } -// -// vtkSmartPointer dosxyzNrc3dDoseVolumeNode = vtkSmartPointer::New(); -// dosxyzNrc3dDoseVolumeNode->SetScene(this->GetMRMLScene()); -// dosxyzNrc3dDoseVolumeNode->SetName(name.c_str()); -// dosxyzNrc3dDoseVolumeNode->SetSpacing(spacing[0], spacing[1], spacing[2]); -// dosxyzNrc3dDoseVolumeNode->SetOrigin(origin[0], origin[1], origin[2]); -// vtkSmartPointer lpsToRasMatrix = vtkSmartPointer::New(); -// lpsToRasMatrix->SetElement(0,0,-1); -// lpsToRasMatrix->SetElement(1,1,-1); -// vtkSmartPointer dosxyzNrc3dDoseIjkToLpsMatrix = vtkSmartPointer::New(); -// dosxyzNrc3dDoseVolumeNode->GetIJKToRASMatrix(dosxyzNrc3dDoseIjkToLpsMatrix); -// vtkSmartPointer DosxyzNrc3dDoseIjkToRasMatrix = vtkSmartPointer::New(); -// vtkMatrix4x4::Multiply4x4(dosxyzNrc3dDoseIjkToLpsMatrix, lpsToRasMatrix, DosxyzNrc3dDoseIjkToRasMatrix); -// dosxyzNrc3dDoseVolumeNode->SetIJKToRASMatrix(DosxyzNrc3dDoseIjkToRasMatrix); -// dosxyzNrc3dDoseVolumeNode->SetSlicerDataType(type.c_str()); -// this->GetMRMLScene()->AddNode(dosxyzNrc3dDoseVolumeNode); -// -// // Checks if the date parameter (not required) was set -// if (isDateCurrentlySet == true) -// { -// dosxyzNrc3dDoseVolumeNode->SetAttribute("Date", date.c_str()); -// } -// -// vtkSmartPointer floatDosxyzNrc3dDoseVolumeData = vtkSmartPointer::New(); -// floatDosxyzNrc3dDoseVolumeData->SetExtent(0, size[0]-1, 0, size[1]-1, 0, size[2]-1); -// floatDosxyzNrc3dDoseVolumeData->SetSpacing(1, 1, 1); -// floatDosxyzNrc3dDoseVolumeData->SetOrigin(0, 0, 0); -// floatDosxyzNrc3dDoseVolumeData->AllocateScalars(VTK_FLOAT, bands); -// -// // Reads the line feed that comes directly before the image data from the file -// readFileStream.get(); -// -// float* floatPtr = (float*)floatDosxyzNrc3dDoseVolumeData->GetScalarPointer(); -// std::stringstream ss; -// -// // The size of the image data read is specified in the header by the parameter size -// for (long x = 0; x < size[0]; x++) -// { -// for (long y = 0; y < size[1]; y++) -// { -// for (long z = 0; z < size[2]; z++) -// { -// if (!readFileStream.eof()) -// { -// // Reads in the specified number of bytes at a time from the file -// char *buffer = new char[bytesToRead]; -// char *newBuffer = new char[bytesToRead]; -// readFileStream.read(buffer, bytesToRead); -// -// // Checks that the correct number of bytes were read from the file -// if (readFileStream.gcount() == bytesToRead) -// { -// float *valueFromFile = (float *) newBuffer; -// -// // Reverses the byte order -// for (int byte=0; byte imageIntensityShiftScale = vtkSmartPointer::New(); -// imageIntensityShiftScale->SetScale(data_scale); -// imageIntensityShiftScale->SetShift(data_offset); -// imageIntensityShiftScale->SetInputData(floatDosxyzNrc3dDoseVolumeData); -// imageIntensityShiftScale->Update(); -// floatDosxyzNrc3dDoseVolumeData = imageIntensityShiftScale->GetOutput(); -// } -// -// dosxyzNrc3dDoseVolumeNode->SetAndObserveImageData(floatDosxyzNrc3dDoseVolumeData); -// -// vtkSmartPointer dosxyzNrc3dDoseVolumeDisplayNode = vtkSmartPointer::New(); -// this->GetMRMLScene()->AddNode(dosxyzNrc3dDoseVolumeDisplayNode); -// dosxyzNrc3dDoseVolumeNode->SetAndObserveDisplayNodeID(dosxyzNrc3dDoseVolumeDisplayNode->GetID()); -// -// if (this->GetApplicationLogic()!=NULL) -// { -// if (this->GetApplicationLogic()->GetSelectionNode()!=NULL) -// { -// this->GetApplicationLogic()->GetSelectionNode()->SetReferenceActiveVolumeID(dosxyzNrc3dDoseVolumeNode->GetID()); -// this->GetApplicationLogic()->PropagateVolumeSelection(); -// this->GetApplicationLogic()->FitSliceToAll(); -// } -// } -// -// if (bands == 1) -// { -// DosxyzNrc3dDoseVolumeDisplayNode->SetAndObserveColorNodeID("vtkMRMLColorTableNodeGrey"); -// } -// DosxyzNrc3dDoseVolumeNode->SetAndObserveDisplayNodeID(DosxyzNrc3dDoseVolumeDisplayNode->GetID()); -// } -// else -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: Incorrect parameters or required parameters that were not set, DosxyzNrc3dDose file failed to load. The required parameters are: rank, type, format, bits, bands, size, spacing, origin, rawsize, data scale, data offset, and title."); -// } -// } -// else -// { -// vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The specified file could not be opened."); -// } -// -// readFileStream.close(); -//} + //---------------------------------------------------------------------------- void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* filename) { - //const char* fileName = "C:\\d\\Segment01.3ddose"; + ifstream readFileStream(filename); //todo test that this doesn't crash when filename is null - if (!(readFileStream.fail())) - { - vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The specified file could not be opened."); - readFileStream.close(); - return; + if (!readFileStream){ + vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The specified file could not be opened."); + return; } int size[3] = { 0, 0, 0 }; double spacing[3] = { 0, 0, 0 }; double origin[3] = { 0, 0, 0 }; std::string title = ""; - //bool parameterInvalidValue = false; //todo do I need this variable? // read in block 1 (number of voxels in x, y, z directions) readFileStream >> size[0] >> size[1] >> size[2]; int numTotalVoxels = size[0] * size[1] * size[2]; - if (size[0] <= 0 || size[0] <= 0 || size[2] <= 0) + if (size[0] <= 0 || size[1] <= 0 || size[2] <= 0) { - vtkErrorMacro("LoadDosxyzNrc3dDoseFile: Number of voxels in X, Y, or Z direction must be greater than zero."); - //parameterInvalidValue = true; + vtkErrorMacro("LoadDosxyzNrc3dDoseFile: Number of voxels in X, Y, or Z direction must be greater than zero." << "numVoxelsX " << size[0] << ", numVoxelsY " << size[1] << ", numVoxelsZ " << size[2]); return; } - std::vector voxelBoundariesX(size[0] + 1); //todo: make sure that double is large enough for .3ddose data + std::vector voxelBoundariesX(size[0] + 1); std::vector voxelBoundariesY(size[1] + 1); std::vector voxelBoundariesZ(size[2] + 1); double spacingX = 0; double spacingY = 0; double spacingZ = 0; - //std::vector doseValues(numTotalVoxels); - //std::vector errorValues(numTotalVoxels); - int counter = 0; double initialVoxelSpacing = 0; double currentVoxelSpacing = 0; @@ -682,6 +119,7 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file while (!readFileStream.eof() && counter < size[0] + 1) { readFileStream >> voxelBoundariesX[counter]; + voxelBoundariesX[counter] = voxelBoundariesX[counter] * 10.0; // convert from cm to mm if (counter == 1) { initialVoxelSpacing = fabs(voxelBoundariesX[counter] - voxelBoundariesX[counter - 1]); @@ -691,16 +129,19 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file { currentVoxelSpacing = abs(voxelBoundariesX[counter] - voxelBoundariesX[counter - 1]); if (AreEqualWithTolerance(initialVoxelSpacing, currentVoxelSpacing) == false){ - vtkErrorMacro("LoadDosxyzNrc3dDoseFile: Voxels have uneven spacing in X direction.") + vtkWarningMacro("LoadDosxyzNrc3dDoseFile: Voxels have uneven spacing in X direction.") } } counter += 1; } + // read in block 3 (voxel boundaries, cm, in y direction) + counter = 0; while (!readFileStream.eof() && counter < size[1] + 1) { readFileStream >> voxelBoundariesY[counter]; + voxelBoundariesY[counter] = voxelBoundariesY[counter] * 10.0; // convert from cm to mm if (counter == 1) { initialVoxelSpacing = fabs(voxelBoundariesY[counter] - voxelBoundariesY[counter - 1]); @@ -710,16 +151,18 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file { currentVoxelSpacing = abs(voxelBoundariesY[counter] - voxelBoundariesY[counter - 1]); if (AreEqualWithTolerance(initialVoxelSpacing, currentVoxelSpacing) == false){ - vtkErrorMacro("LoadDosxyzNrc3dDoseFile: Voxels have uneven spacing in Y direction.") + vtkWarningMacro("LoadDosxyzNrc3dDoseFile: Voxels have uneven spacing in Y direction.") } } counter += 1; } // read in block 4 (voxel boundaries, cm, in z direction) + counter = 0; while (!readFileStream.eof() && counter < size[2] + 1) { readFileStream >> voxelBoundariesZ[counter]; + voxelBoundariesZ[counter] = voxelBoundariesZ[counter] * 10.0; // convert from cm to mm if (counter == 1) { initialVoxelSpacing = fabs(voxelBoundariesZ[counter] - voxelBoundariesZ[counter - 1]); @@ -729,27 +172,18 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file { currentVoxelSpacing = abs(voxelBoundariesZ[counter] - voxelBoundariesZ[counter - 1]); if (AreEqualWithTolerance(initialVoxelSpacing, currentVoxelSpacing) == false){ - vtkErrorMacro("LoadDosxyzNrc3dDoseFile: Voxels have uneven spacing in Z direction.") + vtkWarningMacro("LoadDosxyzNrc3dDoseFile: Voxels have uneven spacing in Z direction.") } } counter += 1; } - - //// read in block 5 (dose array values) - //vtkSmartPointer dosxyzNrc3dDoseVolumeNode = vtkSmartPointer::New(); - //dosxyzNrc3dDoseVolumeNode->SetScene(this->GetMRMLScene()); - //dosxyzNrc3dDoseVolumeNode->SetName(name.c_str()); //todo: Use vtksys::GetFilenameWithoutExtension - //dosxyzNrc3dDoseVolumeNode->SetSpacing(1.0, 1.0, 1.0); - //dosxyzNrc3dDoseVolumeNode->SetOrigin(0.0, 0.0, 0.0); - //this->GetMRMLScene()->AddNode(dosxyzNrc3dDoseVolumeNode); - // read in block 5 (dose array values) vtkSmartPointer floatDosxyzNrc3dDoseVolumeData = vtkSmartPointer::New(); floatDosxyzNrc3dDoseVolumeData->SetExtent(0, size[0] - 1, 0, size[1] - 1, 0, size[2] - 1); - floatDosxyzNrc3dDoseVolumeData->SetSpacing(spacingX, spacingZ, spacingY); //todo .3ddose gives spacing in cm. Does slicer take cm or mm? + floatDosxyzNrc3dDoseVolumeData->SetSpacing(spacingX, spacingZ, spacingY); floatDosxyzNrc3dDoseVolumeData->SetOrigin(voxelBoundariesX[0], voxelBoundariesY[0], voxelBoundariesZ[0]); - floatDosxyzNrc3dDoseVolumeData->AllocateScalars(VTK_FLOAT, 1); //todo what does this do? + floatDosxyzNrc3dDoseVolumeData->AllocateScalars(VTK_FLOAT, 1); float* floatPtr = (float*)floatDosxyzNrc3dDoseVolumeData->GetScalarPointer(); float currentValue = 0.0; @@ -770,20 +204,13 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file } } - if (readFileStream.get() && !readFileStream.eof()) - { - vtkWarningMacro("LoadDosxyzNrc3dDoseFile: The end of the file was not reached."); //todo: check that this warning is not thrown when only whitespace remaining - } - // create volume node for dose values vtkSmartPointer dosxyzNrc3dDoseVolumeNode = vtkSmartPointer::New(); dosxyzNrc3dDoseVolumeNode->SetScene(this->GetMRMLScene()); - dosxyzNrc3dDoseVolumeNode->SetName(vtksys::SystemTools::GetFilenameWithoutExtension(filename).c_str()); //todo + dosxyzNrc3dDoseVolumeNode->SetName(vtksys::SystemTools::GetFilenameWithoutExtension(filename).c_str()); dosxyzNrc3dDoseVolumeNode->SetSpacing(spacingX, spacingY, spacingZ); - dosxyzNrc3dDoseVolumeNode->SetOrigin(voxelBoundariesX[0], voxelBoundariesY[0], voxelBoundariesZ[0]); //todo - //dosxyzNrc3dDoseVolumeNode->SetSlicerDataType();//todo do I need this? - //dosxyzNrc3dDoseVolumeNode->SetAttribute("Date", date.c_str()); //could set other attributes I want this way + dosxyzNrc3dDoseVolumeNode->SetOrigin(voxelBoundariesX[0], voxelBoundariesY[0], voxelBoundariesZ[0]); this->GetMRMLScene()->AddNode(dosxyzNrc3dDoseVolumeNode); dosxyzNrc3dDoseVolumeNode->SetAndObserveImageData(floatDosxyzNrc3dDoseVolumeData); diff --git a/DosxyzNrc3dDoseFileReader/Logic/vtkSlicerDosxyzNrc3dDoseFileReaderLogic.h b/DosxyzNrc3dDoseFileReader/Logic/vtkSlicerDosxyzNrc3dDoseFileReaderLogic.h index 9b249a166..729f1f67c 100644 --- a/DosxyzNrc3dDoseFileReader/Logic/vtkSlicerDosxyzNrc3dDoseFileReaderLogic.h +++ b/DosxyzNrc3dDoseFileReader/Logic/vtkSlicerDosxyzNrc3dDoseFileReaderLogic.h @@ -21,7 +21,7 @@ #ifndef __vtkSlicerDosxyzNrc3dDoseFileReaderLogic_h #define __vtkSlicerDosxyzNrc3dDoseFileReaderLogic_h -#define MAX_TOLERANCE_SPACING 0.001 +#define MAX_TOLERANCE_SPACING 0.01 // Slicer includes #include "vtkSlicerModuleLogic.h" @@ -48,33 +48,18 @@ class VTK_SLICER_DOSXYZNRC3DDOSEFILEREADER_LOGIC_EXPORT vtkSlicerDosxyzNrc3dDose /// Load DosxyzNrc3dDose volume from file /// \param filename Path and filename of the DosxyzNrc3dDose file - /// \param useImageIntensityScaleAndOffsetFromFile Boolean flag which is set to false by default, but is set to true to use the intensity scale and offset provided in the file to load the image void LoadDosxyzNrc3dDoseFile(char* filename); /// Determine if two numbers are equal within a small tolerance (0.001) static bool AreEqualWithTolerance(double a, double b); -protected: - /// A helper function which removes all spaces from the beginning and end of a string, and returns the modified string. - /// \param stringToTrim String which is to be modified - /// \return String that has had leading and trailing spaces removed - // std::string TrimSpacesFromEndsOfString(std::string &stringToTrim); - - /// A helper function which extracts a user-specified number of numbers from a string, which can be of any numerical type, and returns them as a vector. - /// \param stringToParse String from which the numbers are to be extracted - /// \param numberOfNumbers Integer specifying the number of numbers to be extracted from the string and returned in the vector - /// \return Vector containing the extracted numbers - // template std::vector ParseNumberOfNumbersFromString(std::string stringToParse, unsigned int numberOfNumbers); - - // bool ReadDosxyzNrc3dDoseFileHeader(ifstream &readFileStream, std::map ¶meterList); - protected: vtkSlicerDosxyzNrc3dDoseFileReaderLogic(); virtual ~vtkSlicerDosxyzNrc3dDoseFileReaderLogic(); private: - vtkSlicerDosxyzNrc3dDoseFileReaderLogic(const vtkSlicerDosxyzNrc3dDoseFileReaderLogic&); // Not implemented - void operator=(const vtkSlicerDosxyzNrc3dDoseFileReaderLogic&); // Not implemented + vtkSlicerDosxyzNrc3dDoseFileReaderLogic(const vtkSlicerDosxyzNrc3dDoseFileReaderLogic&); // Not implemented + void operator=(const vtkSlicerDosxyzNrc3dDoseFileReaderLogic&); // Not implemented }; #endif \ No newline at end of file diff --git a/DosxyzNrc3dDoseFileReader/qSlicerDosxyzNrc3dDoseFileReaderModule.cxx b/DosxyzNrc3dDoseFileReader/qSlicerDosxyzNrc3dDoseFileReaderModule.cxx index 7b5d5b247..631bf6363 100644 --- a/DosxyzNrc3dDoseFileReader/qSlicerDosxyzNrc3dDoseFileReaderModule.cxx +++ b/DosxyzNrc3dDoseFileReader/qSlicerDosxyzNrc3dDoseFileReaderModule.cxx @@ -68,7 +68,7 @@ qSlicerDosxyzNrc3dDoseFileReaderModule::~qSlicerDosxyzNrc3dDoseFileReaderModule( QString qSlicerDosxyzNrc3dDoseFileReaderModule::helpText()const { QString help = QString( - "The DosxyzNrc3dDoseFileReader module enables importing and loading DosxyzNrc3dDose files into Slicer.
" + "The DosxyzNrc3dDoseFileReader module enables importing and loading .3ddose files into Slicer.
" "The DosxyzNrc3dDoseFileReader module is hidden and therefore does not require an application.
"); return help.arg(this->slicerWikiUrl()).arg(Slicer_VERSION_MAJOR).arg(Slicer_VERSION_MINOR); } @@ -85,7 +85,7 @@ QString qSlicerDosxyzNrc3dDoseFileReaderModule::acknowledgementText()const QStringList qSlicerDosxyzNrc3dDoseFileReaderModule::contributors()const { QStringList moduleContributors; - moduleContributors << QString("Jennifer Andrea (Queen's)") << QString("Csaba Pinter (Queen's)"); + moduleContributors << QString("Anna Ilina (Queen's)") << QString("Csaba Pinter (Queen's)"); return moduleContributors; } diff --git a/DosxyzNrc3dDoseFileReader/qSlicerDosxyzNrc3dDoseFileReaderPlugin.cxx b/DosxyzNrc3dDoseFileReader/qSlicerDosxyzNrc3dDoseFileReaderPlugin.cxx index 344ebcfd0..ae886d441 100644 --- a/DosxyzNrc3dDoseFileReader/qSlicerDosxyzNrc3dDoseFileReaderPlugin.cxx +++ b/DosxyzNrc3dDoseFileReader/qSlicerDosxyzNrc3dDoseFileReaderPlugin.cxx @@ -85,7 +85,7 @@ qSlicerIO::IOFileType qSlicerDosxyzNrc3dDoseFileReaderPlugin::fileType()const //----------------------------------------------------------------------------- QStringList qSlicerDosxyzNrc3dDoseFileReaderPlugin::extensions()const { - return QStringList() << "DosxyzNrc3dDose (*.DosxyzNrc3dDose)"; + return QStringList() << "DosxyzNrc3dDose (*.3ddose)"; } //-----------------------------------------------------------------------------