diff --git a/Modules/CommandLine/src/mitkCommandLineParser.cpp b/Modules/CommandLine/src/mitkCommandLineParser.cpp index 3d7ebad13f..d6b1ea79b6 100644 --- a/Modules/CommandLine/src/mitkCommandLineParser.cpp +++ b/Modules/CommandLine/src/mitkCommandLineParser.cpp @@ -1,996 +1,1050 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ /*========================================================================= Library: CTK Copyright (c) Kitware Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.txt Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =========================================================================*/ // STL includes #include #include // MITK includes #include "mitkCommandLineParser.h" using namespace std; namespace { // -------------------------------------------------------------------------- class CommandLineParserArgumentDescription { public: CommandLineParserArgumentDescription(const string &longArg, const string &longArgPrefix, const string &shortArg, const string &shortArgPrefix, mitkCommandLineParser::Type type, const string &argHelp, const string &argLabel, const us::Any &defaultValue, bool ignoreRest, bool deprecated, bool optional, string &argGroup, string &groupDescription) : LongArg(longArg), LongArgPrefix(longArgPrefix), ShortArg(shortArg), ShortArgPrefix(shortArgPrefix), ArgHelp(argHelp), ArgLabel(argLabel), ArgGroup(argGroup), ArgGroupDescription(groupDescription), IgnoreRest(ignoreRest), NumberOfParametersToProcess(0), Deprecated(deprecated), Optional(optional), DefaultValue(defaultValue), Value(type), ValueType(type) { Value = defaultValue; switch (type) { case mitkCommandLineParser::String: { NumberOfParametersToProcess = 1; } break; case mitkCommandLineParser::Bool: { NumberOfParametersToProcess = 0; } break; case mitkCommandLineParser::StringList: { NumberOfParametersToProcess = -1; } break; case mitkCommandLineParser::Int: { NumberOfParametersToProcess = 1; } break; case mitkCommandLineParser::Float: { NumberOfParametersToProcess = 1; } break; case mitkCommandLineParser::OutputDirectory: case mitkCommandLineParser::InputDirectory: { NumberOfParametersToProcess = 1; } break; case mitkCommandLineParser::OutputFile: case mitkCommandLineParser::InputFile: { NumberOfParametersToProcess = 1; } break; case mitkCommandLineParser::InputImage: { NumberOfParametersToProcess = 1; } break; default: std::cout << "Type not supported: " << static_cast(type); } } ~CommandLineParserArgumentDescription() {} bool addParameter(const string &value); string helpText(); string LongArg; string LongArgPrefix; string ShortArg; string ShortArgPrefix; string ArgHelp; string ArgLabel; string ArgGroup; string ArgGroupDescription; bool IgnoreRest; int NumberOfParametersToProcess; bool Deprecated; bool Optional; us::Any DefaultValue; us::Any Value; mitkCommandLineParser::Type ValueType; }; // -------------------------------------------------------------------------- bool CommandLineParserArgumentDescription::addParameter(const string &value) { switch (ValueType) { case mitkCommandLineParser::String: { Value = value; } break; case mitkCommandLineParser::Bool: { if (value.compare("true") == 0) Value = true; else Value = false; } break; case mitkCommandLineParser::StringList: { try { mitkCommandLineParser::StringContainerType list = us::any_cast(Value); list.push_back(value); Value = list; } catch (...) { mitkCommandLineParser::StringContainerType list; list.push_back(value); Value = list; } } break; case mitkCommandLineParser::Int: { stringstream ss(value); int i; ss >> i; Value = i; } break; case mitkCommandLineParser::Float: { stringstream ss(value); float f; ss >> f; Value = f; } break; case mitkCommandLineParser::InputDirectory: case mitkCommandLineParser::OutputDirectory: { Value = value; } break; case mitkCommandLineParser::InputFile: case mitkCommandLineParser::InputImage: case mitkCommandLineParser::OutputFile: { Value = value; } break; default: return false; } return true; } // -------------------------------------------------------------------------- string CommandLineParserArgumentDescription::helpText() { string text; string shortAndLongArg; if (!this->ShortArg.empty()) { shortAndLongArg = " "; shortAndLongArg += this->ShortArgPrefix; shortAndLongArg += this->ShortArg; } if (!this->LongArg.empty()) { if (this->ShortArg.empty()) shortAndLongArg.append(" "); else shortAndLongArg.append(", "); shortAndLongArg += this->LongArgPrefix; shortAndLongArg += this->LongArg; } text = text + shortAndLongArg + ", " + this->ArgHelp; if (this->Optional) text += " (optional)"; if (!this->DefaultValue.Empty()) { text = text + ", (default: " + this->DefaultValue.ToString() + ")"; } + string value_type = "Unknown"; + switch (this->ValueType) + { + case 0: + { + value_type = "String"; + break; + } + case 1: + { + value_type = "Bool"; + break; + } + case 2: + { + value_type = "StringList"; + break; + } + case 3: + { + value_type = "Int"; + break; + } + case 4: + { + value_type = "Float"; + break; + } + case 5: + { + value_type = "InputDirectory"; + break; + } + case 6: + { + value_type = "InputFile"; + break; + } + case 7: + { + value_type = "OutputDirectory"; + break; + } + case 8: + { + value_type = "OutputFile"; + break; + } + case 9: + { + value_type = "InputImage"; + } + } + text = text + ", Type: " + value_type; text += "\n"; return text; } } // -------------------------------------------------------------------------- // ctkCommandLineParser::ctkInternal class // -------------------------------------------------------------------------- class mitkCommandLineParser::ctkInternal { public: ctkInternal() : Debug(false), FieldWidth(0), StrictMode(false) {} ~ctkInternal() {} CommandLineParserArgumentDescription *argumentDescription(const string &argument); vector ArgumentDescriptionList; map ArgNameToArgumentDescriptionMap; map> GroupToArgumentDescriptionListMap; StringContainerType UnparsedArguments; StringContainerType ProcessedArguments; string ErrorString; bool Debug; string::size_type FieldWidth; string LongPrefix; string ShortPrefix; string CurrentGroup; string DisableQSettingsLongArg; string DisableQSettingsShortArg; bool StrictMode; }; // -------------------------------------------------------------------------- // ctkCommandLineParser::ctkInternal methods // -------------------------------------------------------------------------- CommandLineParserArgumentDescription *mitkCommandLineParser::ctkInternal::argumentDescription(const string &argument) { string unprefixedArg = argument; if (!LongPrefix.empty() && argument.compare(0, LongPrefix.size(), LongPrefix) == 0) { // Case when (ShortPrefix + UnPrefixedArgument) matches LongPrefix if (argument == LongPrefix && !ShortPrefix.empty() && argument.compare(0, ShortPrefix.size(), ShortPrefix) == 0) { unprefixedArg = argument.substr(ShortPrefix.size(), argument.size()); } else { unprefixedArg = argument.substr(LongPrefix.size(), argument.size()); } } else if (!ShortPrefix.empty() && argument.compare(0, ShortPrefix.size(), ShortPrefix) == 0) { unprefixedArg = argument.substr(ShortPrefix.size(), argument.size()); } else if (!LongPrefix.empty() && !ShortPrefix.empty()) { return nullptr; } if (ArgNameToArgumentDescriptionMap.count(unprefixedArg)) { return this->ArgNameToArgumentDescriptionMap[unprefixedArg]; } return nullptr; } // -------------------------------------------------------------------------- // ctkCommandLineParser methods // -------------------------------------------------------------------------- mitkCommandLineParser::mitkCommandLineParser() { this->Internal = new ctkInternal(); this->Category = string(); this->Title = string(); this->Contributor = string(); this->Description = string(); this->ParameterGroupName = "Parameters"; this->ParameterGroupDescription = "Parameters"; } // -------------------------------------------------------------------------- mitkCommandLineParser::~mitkCommandLineParser() { delete this->Internal; } // -------------------------------------------------------------------------- map mitkCommandLineParser::parseArguments(const StringContainerType &arguments, bool *ok) { // Reset this->Internal->UnparsedArguments.clear(); this->Internal->ProcessedArguments.clear(); this->Internal->ErrorString.clear(); // foreach (CommandLineParserArgumentDescription* desc, this->Internal->ArgumentDescriptionList) for (unsigned int i = 0; i < Internal->ArgumentDescriptionList.size(); i++) { CommandLineParserArgumentDescription *desc = Internal->ArgumentDescriptionList.at(i); desc->Value = us::Any(desc->ValueType); if (!desc->DefaultValue.Empty()) { desc->Value = desc->DefaultValue; } } bool error = false; bool ignoreRest = false; CommandLineParserArgumentDescription *currentArgDesc = nullptr; vector parsedArgDescriptions; for (unsigned int i = 1; i < arguments.size(); ++i) { string argument = arguments.at(i); if (this->Internal->Debug) { std::cout << "Processing" << argument; } if (!argument.compare("--version")) { std::cout << "Git commit hash: " << MITK_REVISION << std::endl; std::cout << "Git branch name: " << MITK_REVISION_NAME << std::endl; } if (!argument.compare("--xml") || !argument.compare("-xml") || !argument.compare("--XML") || !argument.compare("-XML")) { this->generateXmlOutput(); return map(); } // should argument be ignored ? if (ignoreRest) { if (this->Internal->Debug) { std::cout << " Skipping: IgnoreRest flag was been set"; } this->Internal->UnparsedArguments.push_back(argument); continue; } // Skip if the argument does not start with the defined prefix if (!(argument.compare(0, Internal->LongPrefix.size(), Internal->LongPrefix) == 0 || argument.compare(0, Internal->ShortPrefix.size(), Internal->ShortPrefix) == 0)) { if (this->Internal->StrictMode) { this->Internal->ErrorString = "Unknown argument "; this->Internal->ErrorString += argument; error = true; break; } if (this->Internal->Debug) { std::cout << " Skipping: It does not start with the defined prefix"; } this->Internal->UnparsedArguments.push_back(argument); continue; } // Skip if argument has already been parsed ... bool alreadyProcessed = false; for (auto alreadyHandledArgument : Internal->ProcessedArguments) if (argument.compare(alreadyHandledArgument) == 0) { alreadyProcessed = true; break; } if (alreadyProcessed) { if (this->Internal->StrictMode) { this->Internal->ErrorString = "Argument "; this->Internal->ErrorString += argument; this->Internal->ErrorString += " already processed !"; error = true; break; } if (this->Internal->Debug) { std::cout << " Skipping: Already processed !"; } continue; } // Retrieve corresponding argument description currentArgDesc = this->Internal->argumentDescription(argument); // Is there a corresponding argument description ? if (currentArgDesc) { // If the argument is deprecated, print the help text but continue processing if (currentArgDesc->Deprecated) { std::cout << "Deprecated argument " << argument << ": " << currentArgDesc->ArgHelp; } else { parsedArgDescriptions.push_back(currentArgDesc); } this->Internal->ProcessedArguments.push_back(currentArgDesc->ShortArg); this->Internal->ProcessedArguments.push_back(currentArgDesc->LongArg); int numberOfParametersToProcess = currentArgDesc->NumberOfParametersToProcess; ignoreRest = currentArgDesc->IgnoreRest; if (this->Internal->Debug && ignoreRest) { std::cout << " IgnoreRest flag is True"; } // Is the number of parameters associated with the argument being processed known ? if (numberOfParametersToProcess == 0) { currentArgDesc->addParameter("true"); } else if (numberOfParametersToProcess > 0) { string missingParameterError = "Argument %1 has %2 value(s) associated whereas exacly %3 are expected."; for (int j = 1; j <= numberOfParametersToProcess; ++j) { if (i + j >= arguments.size()) { // this->Internal->ErrorString = // missingParameterError.arg(argument).arg(j-1).arg(numberOfParametersToProcess); // if (this->Internal->Debug) { std::cout << this->Internal->ErrorString; } if (ok) { *ok = false; } return map(); } string parameter = arguments.at(i + j); if (this->Internal->Debug) { std::cout << " Processing parameter" << j << ", value:" << parameter; } if (this->argumentAdded(parameter)) { // this->Internal->ErrorString = // missingParameterError.arg(argument).arg(j-1).arg(numberOfParametersToProcess); // if (this->Internal->Debug) { std::cout << this->Internal->ErrorString; } if (ok) { *ok = false; } return map(); } if (!currentArgDesc->addParameter(parameter)) { // this->Internal->ErrorString = string( // "Value(s) associated with argument %1 are incorrect. %2"). // arg(argument).arg(currentArgDesc->ExactMatchFailedMessage); // if (this->Internal->Debug) { std::cout << this->Internal->ErrorString; } if (ok) { *ok = false; } return map(); } } // Update main loop increment i = i + numberOfParametersToProcess; } else if (numberOfParametersToProcess == -1) { if (this->Internal->Debug) { std::cout << " Proccessing StringList ..."; } int j = 1; while (j + i < arguments.size()) { if (this->argumentAdded(arguments.at(j + i))) { if (this->Internal->Debug) { std::cout << " No more parameter for" << argument; } break; } string parameter = arguments.at(j + i); if (parameter.compare(0, Internal->LongPrefix.size(), Internal->LongPrefix) == 0 || parameter.compare(0, Internal->ShortPrefix.size(), Internal->ShortPrefix) == 0) { j--; break; } if (this->Internal->Debug) { std::cout << " Processing parameter" << j << ", value:" << parameter; } if (!currentArgDesc->addParameter(parameter)) { // this->Internal->ErrorString = string( // "Value(s) associated with argument %1 are incorrect. %2"). // arg(argument).arg(currentArgDesc->ExactMatchFailedMessage); // if (this->Internal->Debug) { std::cout << this->Internal->ErrorString; } if (ok) { *ok = false; } return map(); } j++; } // Update main loop increment i = i + j; } } else { if (this->Internal->StrictMode) { this->Internal->ErrorString = "Unknown argument "; this->Internal->ErrorString += argument; error = true; break; } if (this->Internal->Debug) { std::cout << " Skipping: Unknown argument"; } this->Internal->UnparsedArguments.push_back(argument); } } if (ok) { *ok = !error; } map parsedArguments; int obligatoryArgs = 0; vector::iterator it; for (it = Internal->ArgumentDescriptionList.begin(); it != Internal->ArgumentDescriptionList.end(); ++it) { CommandLineParserArgumentDescription *desc = *it; if (!desc->Optional) obligatoryArgs++; } int parsedObligatoryArgs = 0; for (it = parsedArgDescriptions.begin(); it != parsedArgDescriptions.end(); ++it) { CommandLineParserArgumentDescription *desc = *it; string key; if (!desc->LongArg.empty()) { key = desc->LongArg; } else { key = desc->ShortArg; } if (!desc->Optional) parsedObligatoryArgs++; std::pair elem; elem.first = key; elem.second = desc->Value; parsedArguments.insert(elem); } if (obligatoryArgs > parsedObligatoryArgs) { parsedArguments.clear(); cout << helpText(); } return parsedArguments; } // ------------------------------------------------------------------------- map mitkCommandLineParser::parseArguments(int argc, char **argv, bool *ok) { std::cout << "Running Command Line Utility *" << Title << "*" << std::endl; StringContainerType arguments; // Create a StringContainerType of arguments for (int i = 0; i < argc; ++i) arguments.push_back(argv[i]); return this->parseArguments(arguments, ok); } // ------------------------------------------------------------------------- string mitkCommandLineParser::errorString() const { return this->Internal->ErrorString; } // ------------------------------------------------------------------------- const mitkCommandLineParser::StringContainerType &mitkCommandLineParser::unparsedArguments() const { return this->Internal->UnparsedArguments; } // -------------------------------------------------------------------------- void mitkCommandLineParser::addArgument(const string &longarg, const string &shortarg, Type type, const string &argLabel, const string &argHelp, const us::Any &defaultValue, bool optional, bool ignoreRest, bool deprecated) { if (longarg.empty() && shortarg.empty()) { return; } /* Make sure it's not already added */ bool added = (this->Internal->ArgNameToArgumentDescriptionMap.count(longarg) != 0); if (added) { return; } added = (this->Internal->ArgNameToArgumentDescriptionMap.count(shortarg) != 0); if (added) { return; } auto argDesc = new CommandLineParserArgumentDescription(longarg, this->Internal->LongPrefix, shortarg, this->Internal->ShortPrefix, type, argHelp, argLabel, defaultValue, ignoreRest, deprecated, optional, ParameterGroupName, ParameterGroupDescription); std::string::size_type argWidth = 0; if (!longarg.empty()) { this->Internal->ArgNameToArgumentDescriptionMap[longarg] = argDesc; argWidth += longarg.size() + this->Internal->LongPrefix.size(); } if (!shortarg.empty()) { this->Internal->ArgNameToArgumentDescriptionMap[shortarg] = argDesc; argWidth += shortarg.size() + this->Internal->ShortPrefix.size() + 2; } argWidth += 5; // Set the field width for the arguments if (argWidth > this->Internal->FieldWidth) { this->Internal->FieldWidth = argWidth; } this->Internal->ArgumentDescriptionList.push_back(argDesc); this->Internal->GroupToArgumentDescriptionListMap[this->Internal->CurrentGroup].push_back(argDesc); } // -------------------------------------------------------------------------- void mitkCommandLineParser::addDeprecatedArgument(const string &longarg, const string &shortarg, const string &argLabel, const string &argHelp) { addArgument(longarg, shortarg, StringList, argLabel, argHelp, us::Any(), false, true, false); } // -------------------------------------------------------------------------- std::vector < std::map > mitkCommandLineParser::getArgumentList() { std::vector < std::map > parameterList; //for (CommandLineParserArgumentDescription* argument : this->Internal->ArgumentDescriptionList) for (std::size_t i = 0; i< this->Internal->ArgumentDescriptionList.size(); ++i) { CommandLineParserArgumentDescription* argument = this->Internal->ArgumentDescriptionList[i]; std::map tmpMap; //tmpMap["helptext"] = us::Any(argument->helpText); tmpMap["longarg"] = us::Any(argument->LongArg); tmpMap["longargprefix"] = us::Any(argument->LongArgPrefix); tmpMap["shortarg"] = us::Any(argument->ShortArg); tmpMap["shortargprefix"] = us::Any(argument->ShortArgPrefix); tmpMap["arghelp"] = us::Any(argument->ArgHelp); tmpMap["arglabel"] = us::Any(argument->ArgLabel); tmpMap["arggroup"] = us::Any(argument->ArgGroup); tmpMap["arggroupdescription"] = us::Any(argument->ArgGroupDescription); tmpMap["ignorerest"] = us::Any(argument->IgnoreRest); tmpMap["numberofparameterstoprocess"] = us::Any(argument->NumberOfParametersToProcess); tmpMap["deprecated"] = us::Any(argument->Deprecated); tmpMap["optional"] = us::Any(argument->Optional); tmpMap["defaultvalue"] = argument->DefaultValue; tmpMap["value"] = argument->Value; tmpMap["valuetype"] = us::Any(argument->ValueType); parameterList.push_back(tmpMap); } return parameterList; } // -------------------------------------------------------------------------- std::string::size_type mitkCommandLineParser::fieldWidth() const { return this->Internal->FieldWidth; } // -------------------------------------------------------------------------- void mitkCommandLineParser::beginGroup(const string &description) { this->Internal->CurrentGroup = description; } // -------------------------------------------------------------------------- void mitkCommandLineParser::endGroup() { this->Internal->CurrentGroup.clear(); } // -------------------------------------------------------------------------- string mitkCommandLineParser::helpText() const { string text; vector deprecatedArgs; text = "Command Line Utility *" + Title + "* in Category *" + Category + "*\n"; text += Description + "\n"; text += Contributor + "\n\n"; text += "Use --xml to generate an XML description parsable as a CTK Command Line Module Plugin.\n"; text += "Use --version to print MITK revision information.\n"; // Loop over grouped argument descriptions map>::iterator it; for (it = Internal->GroupToArgumentDescriptionListMap.begin(); it != Internal->GroupToArgumentDescriptionListMap.end(); ++it) { if (!(*it).first.empty()) { text = text + "\n" + (*it).first + "\n"; } vector::iterator it2; for (it2 = (*it).second.begin(); it2 != (*it).second.end(); ++it2) { CommandLineParserArgumentDescription *argDesc = *it2; if (argDesc->Deprecated) { deprecatedArgs.push_back(argDesc); } else { text += argDesc->helpText(); } } } if (!deprecatedArgs.empty()) { text += "\nDeprecated arguments:\n"; vector::iterator it2; for (it2 = deprecatedArgs.begin(); it2 != deprecatedArgs.end(); ++it2) { CommandLineParserArgumentDescription *argDesc = *it2; text += argDesc->helpText(); } } return text; } // -------------------------------------------------------------------------- bool mitkCommandLineParser::argumentAdded(const string &argument) const { return (this->Internal->ArgNameToArgumentDescriptionMap.count(argument) != 0); } // -------------------------------------------------------------------------- bool mitkCommandLineParser::argumentParsed(const string &argument) const { for (unsigned int i = 0; i < Internal->ProcessedArguments.size(); i++) if (argument.compare(Internal->ProcessedArguments.at(i)) == 0) return true; return false; } // -------------------------------------------------------------------------- void mitkCommandLineParser::setArgumentPrefix(const string &longPrefix, const string &shortPrefix) { this->Internal->LongPrefix = longPrefix; this->Internal->ShortPrefix = shortPrefix; } // -------------------------------------------------------------------------- void mitkCommandLineParser::setStrictModeEnabled(bool strictMode) { this->Internal->StrictMode = strictMode; } void mitkCommandLineParser::generateXmlOutput() { std::stringstream xml; xml << "" << endl; xml << "" << Category << "" << endl; xml << "" << Title << "" << endl; xml << "" << Description << "" << endl; xml << "" << Contributor << "" << endl; xml << "" << endl; std::vector::iterator it; std::string lastParameterGroup = ""; for (it = this->Internal->ArgumentDescriptionList.begin(); it != this->Internal->ArgumentDescriptionList.end(); it++) { std::string type; switch ((*it)->ValueType) { case mitkCommandLineParser::String: type = "string"; break; case mitkCommandLineParser::Bool: type = "boolean"; break; case mitkCommandLineParser::StringList: type = "string-vector"; break; case mitkCommandLineParser::Int: type = "integer"; break; case mitkCommandLineParser::Float: type = "float"; break; case mitkCommandLineParser::OutputDirectory: case mitkCommandLineParser::InputDirectory: type = "directory"; break; case mitkCommandLineParser::InputImage: type = "image"; break; case mitkCommandLineParser::OutputFile: case mitkCommandLineParser::InputFile: type = "file"; break; } if (lastParameterGroup.compare((*it)->ArgGroup)) { if (it != this->Internal->ArgumentDescriptionList.begin()) { xml << "" << endl; xml << "" << endl; } xml << "" << endl; xml << "" << (*it)->ArgGroupDescription << "" << endl; lastParameterGroup = (*it)->ArgGroup; } // Skip help item, as it's no use in GUI if ((*it)->ShortArg == "h") continue; xml << "<" << type << ">" << endl; xml << "" << (*it)->LongArg << "" << endl; xml << "" << (*it)->ArgHelp << "" << endl; xml << "" << endl; if (!(*it)->DefaultValue.Empty()) xml << "" << (*it)->DefaultValue.ToString() << "" << endl; xml << "" << (*it)->LongArg << "" << endl; xml << "" << (*it)->ShortArg << "" << endl; if ((*it)->ValueType == mitkCommandLineParser::InputDirectory || (*it)->ValueType == mitkCommandLineParser::InputFile || (*it)->ValueType == mitkCommandLineParser::InputImage) { xml << "input" << endl; } else if ((*it)->ValueType == mitkCommandLineParser::OutputDirectory || (*it)->ValueType == mitkCommandLineParser::OutputFile) { xml << "output" << endl; } xml << "" << endl; } xml << "" << endl; xml << "" << endl; cout << xml.str(); } void mitkCommandLineParser::setTitle(string title) { Title = title; } void mitkCommandLineParser::setContributor(string contributor) { Contributor = contributor; } void mitkCommandLineParser::setCategory(string category) { Category = category; } void mitkCommandLineParser::setDescription(string description) { Description = description; } void mitkCommandLineParser::changeParameterGroup(string name, string tooltip) { ParameterGroupName = name; ParameterGroupDescription = tooltip; } diff --git a/Modules/DiffusionImaging/DiffusionCore/include/Algorithms/itkOdfMaximaExtractionFilter.cpp b/Modules/DiffusionImaging/DiffusionCore/include/Algorithms/itkOdfMaximaExtractionFilter.cpp index a3b3cea799..e53de6545c 100644 --- a/Modules/DiffusionImaging/DiffusionCore/include/Algorithms/itkOdfMaximaExtractionFilter.cpp +++ b/Modules/DiffusionImaging/DiffusionCore/include/Algorithms/itkOdfMaximaExtractionFilter.cpp @@ -1,358 +1,362 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __itkOdfMaximaExtractionFilter_cpp #define __itkOdfMaximaExtractionFilter_cpp #include "itkOdfMaximaExtractionFilter.h" #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace boost::math; namespace itk { static bool CompareVectors(const vnl_vector_fixed< double, 3 >& v1, const vnl_vector_fixed< double, 3 >& v2) { return (v1.magnitude()>v2.magnitude()); } template< class PixelType, int ShOrder, int NrOdfDirections > OdfMaximaExtractionFilter< PixelType, ShOrder, NrOdfDirections> ::OdfMaximaExtractionFilter() : m_NormalizationMethod(MAX_VEC_NORM) , m_MaxNumPeaks(2) , m_RelativePeakThreshold(0.4) , m_AbsolutePeakThreshold(0) , m_AngularThreshold(0.9) , m_NumCoeffs((ShOrder*ShOrder + ShOrder + 2)/2 + ShOrder) , m_Toolkit(MRTRIX) , m_FlipX(false) , m_FlipY(false) , m_FlipZ(false) , m_ApplyDirectionMatrix(false) , m_ScaleByGfa(false) , m_Iterations(10) { this->SetNumberOfRequiredInputs(1); } template< class PixelType, int ShOrder, int NrOdfDirections > double OdfMaximaExtractionFilter< PixelType, ShOrder, NrOdfDirections> ::FindCandidatePeaks(OdfType& odf, double thr, std::vector< DirectionType >& container) { double gfa = 1.0; if (m_ScaleByGfa) gfa = odf.GetGeneralizedFractionalAnisotropy(); //Find the peaks using a finite difference method bool flag = true; vnl_vector_fixed< bool, NrOdfDirections > used; used.fill(false); //Find the peaks for (int i=0; ithr*0.9 && gfa*val>m_AbsolutePeakThreshold*0.9) { flag = true; std::vector< int > neighbours = odf.GetNeighbors(i); for (unsigned int j=0; j void OdfMaximaExtractionFilter< PixelType, ShOrder, NrOdfDirections> ::BeforeThreadedGenerateData() { typename CoefficientImageType::Pointer ShCoeffImage = static_cast< CoefficientImageType* >( this->ProcessObject::GetInput(0) ); itk::Vector spacing = ShCoeffImage->GetSpacing(); double minSpacing = spacing[0]; if (spacing[1]GetOrigin(); itk::Matrix direction = ShCoeffImage->GetDirection(); ImageRegion<3> imageRegion = ShCoeffImage->GetLargestPossibleRegion(); if (m_MaskImage.IsNotNull()) { origin = m_MaskImage->GetOrigin(); direction = m_MaskImage->GetDirection(); imageRegion = m_MaskImage->GetLargestPossibleRegion(); } itk::Vector spacing3 = ShCoeffImage->GetSpacing(); itk::Point origin3 = ShCoeffImage->GetOrigin(); itk::Matrix direction3 = ShCoeffImage->GetDirection(); itk::ImageRegion<3> imageRegion3 = ShCoeffImage->GetLargestPossibleRegion(); itk::Vector spacing4; itk::Point origin4; itk::Matrix direction4; itk::ImageRegion<4> imageRegion4; spacing4[0] = spacing3[0]; spacing4[1] = spacing3[1]; spacing4[2] = spacing3[2]; spacing4[3] = 1; origin4[0] = origin3[0]; origin4[1] = origin3[1]; origin4[2] = origin3[2]; origin4[3] = 0; for (int r=0; r<3; r++) for (int c=0; c<3; c++) direction4[r][c] = direction3[r][c]; direction4[3][3] = 1; imageRegion4.SetSize(0, imageRegion3.GetSize()[0]); imageRegion4.SetSize(1, imageRegion3.GetSize()[1]); imageRegion4.SetSize(2, imageRegion3.GetSize()[2]); imageRegion4.SetSize(3, m_MaxNumPeaks*3); m_PeakImage = PeakImageType::New(); m_PeakImage->SetSpacing( spacing4 ); m_PeakImage->SetOrigin( origin4 ); m_PeakImage->SetDirection( direction4 ); m_PeakImage->SetRegions( imageRegion4 ); m_PeakImage->Allocate(); m_PeakImage->FillBuffer(0.0); if (m_MaskImage.IsNull()) { m_MaskImage = ItkUcharImgType::New(); m_MaskImage->SetSpacing( spacing ); m_MaskImage->SetOrigin( origin ); m_MaskImage->SetDirection( direction ); m_MaskImage->SetRegions( imageRegion ); m_MaskImage->Allocate(); m_MaskImage->FillBuffer(1); } m_NumDirectionsImage = ItkUcharImgType::New(); m_NumDirectionsImage->SetSpacing( spacing ); m_NumDirectionsImage->SetOrigin( origin ); m_NumDirectionsImage->SetDirection( direction ); m_NumDirectionsImage->SetRegions( imageRegion ); m_NumDirectionsImage->Allocate(); m_NumDirectionsImage->FillBuffer(0); // calculate SH basis OdfType odf; vnl_matrix< double > dir_matrix; dir_matrix.set_size(3, NrOdfDirections); for (int i=0; iSetNumberOfThreads(1); } template< class PixelType, int ShOrder, int NrOdfDirections > void OdfMaximaExtractionFilter< PixelType, ShOrder, NrOdfDirections> ::AfterThreadedGenerateData() { } template< class PixelType, int ShOrder, int NrOdfDirections > void OdfMaximaExtractionFilter< PixelType, ShOrder, NrOdfDirections> ::ThreadedGenerateData( const OutputImageRegionType& outputRegionForThread, ThreadIdType threadID ) { typename CoefficientImageType::Pointer ShCoeffImage = static_cast< CoefficientImageType* >( this->ProcessObject::GetInput(0) ); ImageRegionConstIterator< CoefficientImageType > cit(ShCoeffImage, outputRegionForThread ); + boost::progress_display disp(outputRegionForThread.GetSize()[0]*outputRegionForThread.GetSize()[1]*outputRegionForThread.GetSize()[2]); OdfType odf; while( !cit.IsAtEnd() ) { typename CoefficientImageType::IndexType idx3 = cit.GetIndex(); if (m_MaskImage->GetPixel(idx3)==0) { + ++disp; ++cit; continue; } CoefficientPixelType c = cit.Get(); vnl_vector coeffs; coeffs.set_size((ShOrder*ShOrder + ShOrder + 2)/2 + ShOrder); for (int j=0; jmax) max = odf[i]; } if (max<0.0001) { + ++disp; ++cit; continue; } std::vector< DirectionType > candidates, final_peaks; double scale = FindCandidatePeaks(odf, max*m_RelativePeakThreshold, candidates); // find all local maxima max = 0; for (unsigned int i=0; i x; x.set_size(2); x[0] = spherical[1]; // theta x[1] = spherical[0]; // phi VnlCostFunction cost; if (m_Toolkit==Toolkit::MRTRIX) cost.SetProblem(coeffs, ShOrder, true, max); else cost.SetProblem(coeffs, ShOrder, false, max); vnl_lbfgsb minimizer(cost); minimizer.set_f_tolerance(1e-6); // minimizer.set_trace(true); vnl_vector l; l.set_size(2); l[0] = 0; l[1] = -itk::Math::pi; vnl_vector u; u.set_size(2); u[0] = itk::Math::pi; u[1] = itk::Math::pi; vnl_vector bound_selection; bound_selection.set_size(2); bound_selection.fill(2); minimizer.set_bound_selection(bound_selection); minimizer.set_lower_bound(l); minimizer.set_upper_bound(u); if (m_Iterations>0) minimizer.set_max_function_evals(m_Iterations); minimizer.minimize(x); float v = -minimizer.get_end_error()*scale; candidates[i] = mitk::sh::Sph2Cart(x[0], x[1], v); if (v>max) max = v; } std::sort( candidates.begin(), candidates.end(), CompareVectors ); // sort peaks // kick out directions to close to a larger direction for (unsigned int i=0; im_AngularThreshold && val idx4; idx4[0] = idx3[0]; idx4[1] = idx3[1]; idx4[2] = idx3[2]; // fill output image unsigned int num = final_peaks.size(); if ( num>m_MaxNumPeaks ) num = m_MaxNumPeaks; for (unsigned int i=0; iGetDirection()*dir; if (m_FlipX) dir[0] = -dir[0]; if (m_FlipY) dir[1] = -dir[1]; if (m_FlipZ) dir[2] = -dir[2]; for (unsigned int j = 0; j<3; j++) { idx4[3] = i*3 + j; m_PeakImage->SetPixel(idx4, dir[j]); } } m_NumDirectionsImage->SetPixel(idx3, num); + ++disp; ++cit; } MITK_INFO << "Thread " << threadID << " finished extraction"; } } #endif // __itkOdfMaximaExtractionFilter_cpp diff --git a/Modules/ImageStatistics/Testing/mitkImageStatisticsCalculatorTest.cpp b/Modules/ImageStatistics/Testing/mitkImageStatisticsCalculatorTest.cpp index 2d208aac38..35a7cda970 100644 --- a/Modules/ImageStatistics/Testing/mitkImageStatisticsCalculatorTest.cpp +++ b/Modules/ImageStatistics/Testing/mitkImageStatisticsCalculatorTest.cpp @@ -1,1972 +1,1137 @@ + /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ - #include "mitkImageStatisticsCalculator.h" #include #include #include #include #include #include #include #include #include #include #include #include /** * \brief Test class for mitkImageStatisticsCalculator * * This test covers: * - instantiation of an ImageStatisticsCalculator class * - correctness of statistics when using PlanarFigures for masking */ class mitkImageStatisticsCalculatorTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkImageStatisticsCalculatorTestSuite); MITK_TEST(TestUninitializedImage); MITK_TEST(TestCase1); MITK_TEST(TestCase2); MITK_TEST(TestCase3); MITK_TEST(TestCase4); MITK_TEST(TestCase5); MITK_TEST(TestCase6); MITK_TEST(TestCase7); MITK_TEST(TestCase8); MITK_TEST(TestCase9); MITK_TEST(TestCase10); MITK_TEST(TestCase11); MITK_TEST(TestCase12); - MITK_TEST(TestImageMaskingEmpty); - MITK_TEST(TestImageMaskingNonEmpty); - MITK_TEST(TestRecomputeOnModifiedMask); - MITK_TEST(TestPic3DStatistics); - MITK_TEST(TestPic3DAxialPlanarFigureMaskStatistics); - MITK_TEST(TestPic3DSagittalPlanarFigureMaskStatistics); - MITK_TEST(TestPic3DCoronalPlanarFigureMaskStatistics); - MITK_TEST(TestPic3DImageMaskStatistics_label1); - MITK_TEST(TestPic3DImageMaskStatistics_label2); - MITK_TEST(TestPic3DIgnorePixelValueMaskStatistics); - MITK_TEST(TestPic3DSecondaryMaskStatistics); - MITK_TEST(TestUS4DCylStatistics_time1); - MITK_TEST(TestUS4DCylAxialPlanarFigureMaskStatistics_time1); - MITK_TEST(TestUS4DCylSagittalPlanarFigureMaskStatistics_time1); - MITK_TEST(TestUS4DCylCoronalPlanarFigureMaskStatistics_time1); - MITK_TEST(TestUS4DCylImageMaskStatistics_time1_label_1); - MITK_TEST(TestUS4DCylImageMaskStatistics_time2_label_1); - MITK_TEST(TestUS4DCylImageMaskStatistics_time1_label_2); - MITK_TEST(TestUS4DCylIgnorePixelValueMaskStatistics_time1); - MITK_TEST(TestUS4DCylSecondaryMaskStatistics_time1); + MITK_TEST(TestPic3DCroppedNoMask); + MITK_TEST(TestPic3DCroppedBinMask); + MITK_TEST(TestPic3DCroppedMultilabelMask); + MITK_TEST(TestPic3DCroppedPlanarFigure); + MITK_TEST(TestUS4DCroppedNoMaskTimeStep1); + MITK_TEST(TestUS4DCroppedBinMaskTimeStep1); + MITK_TEST(TestUS4DCroppedMultilabelMaskTimeStep1); + MITK_TEST(TestUS4DCroppedPlanarFigureTimeStep1); CPPUNIT_TEST_SUITE_END(); public: void TestUninitializedImage(); void TestCase1(); void TestCase2(); void TestCase3(); void TestCase4(); void TestCase5(); void TestCase6(); void TestCase7(); void TestCase8(); void TestCase9(); void TestCase10(); void TestCase11(); void TestCase12(); - void TestImageMaskingEmpty(); - void TestImageMaskingNonEmpty(); - void TestRecomputeOnModifiedMask(); - - void TestPic3DStatistics(); - void TestPic3DAxialPlanarFigureMaskStatistics(); - void TestPic3DSagittalPlanarFigureMaskStatistics(); - void TestPic3DCoronalPlanarFigureMaskStatistics(); - void TestPic3DImageMaskStatistics_label1(); - void TestPic3DImageMaskStatistics_label2(); - void TestPic3DIgnorePixelValueMaskStatistics(); - void TestPic3DSecondaryMaskStatistics(); - - void TestUS4DCylStatistics_time1(); - void TestUS4DCylAxialPlanarFigureMaskStatistics_time1(); - void TestUS4DCylSagittalPlanarFigureMaskStatistics_time1(); - void TestUS4DCylCoronalPlanarFigureMaskStatistics_time1(); - void TestUS4DCylImageMaskStatistics_time1_label_1(); - void TestUS4DCylImageMaskStatistics_time2_label_1(); - void TestUS4DCylImageMaskStatistics_time1_label_2(); - void TestUS4DCylIgnorePixelValueMaskStatistics_time1(); - void TestUS4DCylSecondaryMaskStatistics_time1(); - - void TestDifferentNBinsForHistogramStatistics(); - void TestDifferentBinSizeForHistogramStatistic(); - - void TestSwitchFromBinSizeToNBins(); - void TestSwitchFromNBinsToBinSize(); + + void TestPic3DCroppedNoMask(); + void TestPic3DCroppedBinMask(); + void TestPic3DCroppedMultilabelMask(); + void TestPic3DCroppedPlanarFigure(); + + void TestUS4DCroppedNoMaskTimeStep1(); + void TestUS4DCroppedBinMaskTimeStep1(); + void TestUS4DCroppedMultilabelMaskTimeStep1(); + void TestUS4DCroppedPlanarFigureTimeStep1(); private: - mitk::Image::ConstPointer m_TestImage; - - mitk::Image::ConstPointer m_Pic3DImage; - mitk::Image::Pointer m_Pic3DImageMask; - mitk::Image::Pointer m_Pic3DImageMask2; - mitk::PlanarFigure::Pointer m_Pic3DPlanarFigureAxial; - mitk::PlanarFigure::Pointer m_Pic3DPlanarFigureSagittal; - mitk::PlanarFigure::Pointer m_Pic3DPlanarFigureCoronal; - - mitk::Image::ConstPointer m_US4DImage; - mitk::Image::Pointer m_US4DImageMask; - mitk::Image::Pointer m_US4DImageMask2; - mitk::PlanarFigure::Pointer m_US4DPlanarFigureAxial; - mitk::PlanarFigure::Pointer m_US4DPlanarFigureSagittal; - mitk::PlanarFigure::Pointer m_US4DPlanarFigureCoronal; - - mitk::PlaneGeometry::Pointer m_Geometry; - - // calculate statistics for the given image and planarpolygon - const mitk::ImageStatisticsContainer::Pointer ComputeStatistics( mitk::Image::ConstPointer image, - mitk::PlanarFigure::Pointer polygon ); - - // calculate statistics for the given image and mask - const mitk::ImageStatisticsContainer::Pointer ComputeStatistics(mitk::Image::ConstPointer image, - mitk::Image::Pointer image_mask ); - - // universal function to calculate statistics - const mitk::ImageStatisticsContainer::Pointer ComputeStatisticsNew(mitk::Image::ConstPointer image, - mitk::MaskGenerator::Pointer maskGen=nullptr, - mitk::MaskGenerator::Pointer secondardMaskGen=nullptr, - unsigned short label=1); - - void VerifyStatistics(mitk::ImageStatisticsContainer::StatisticsObject stats, - double testMean, double testSD, double testMedian=0); - - void VerifyStatistics(mitk::ImageStatisticsContainer::StatisticsObject stats, - unsigned long N, - double mean, - double MPP, - double median, - double skewness, - double kurtosis, - double uniformity, - double UPP, - double variance, - double stdev, - double min, - double max, - double RMS, - double entropy, - vnl_vector minIndex, - vnl_vector maxIndex); + mitk::Image::ConstPointer m_TestImage; + + mitk::Image::ConstPointer m_Pic3DCroppedImage; + mitk::Image::Pointer m_Pic3DCroppedBinMask; + mitk::Image::Pointer m_Pic3DCroppedMultilabelMask; + mitk::PlanarFigure::Pointer m_Pic3DCroppedPlanarFigure; + + mitk::Image::ConstPointer m_US4DCroppedImage; + mitk::Image::Pointer m_US4DCroppedBinMask; + mitk::Image::Pointer m_US4DCroppedMultilabelMask; + mitk::PlanarFigure::Pointer m_US4DCroppedPlanarFigure; + + mitk::PlaneGeometry::Pointer m_Geometry; + // calculate statistics for the given image and planarpolygon + const mitk::ImageStatisticsContainer::Pointer ComputeStatistics(mitk::Image::ConstPointer image, + mitk::PlanarFigure::Pointer polygon); + + // calculate statistics for the given image and mask + const mitk::ImageStatisticsContainer::Pointer ComputeStatistics(mitk::Image::ConstPointer image, + mitk::Image::Pointer image_mask); + + // universal function to calculate statistics + const mitk::ImageStatisticsContainer::Pointer ComputeStatisticsNew(mitk::Image::ConstPointer image, + mitk::MaskGenerator::Pointer maskGen = nullptr, + mitk::MaskGenerator::Pointer secondardMaskGen = nullptr, + unsigned short label = 1); + + void VerifyStatistics(mitk::ImageStatisticsContainer::StatisticsObject stats, + double testMean, double testSD, double testMedian = 0); + + // T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) + void VerifyStatistics(mitk::ImageStatisticsContainer::StatisticsObject stats, + unsigned long N, + double mean, + double MPP, + double skewness, + double kurtosis, + double variance, + double stdev, + double min, + double max, + double RMS, + vnl_vector minIndex, + vnl_vector maxIndex); }; +void mitkImageStatisticsCalculatorTestSuite::TestUninitializedImage() +{ + /***************************** + * loading uninitialized image to datastorage + ******************************/ + MITK_INFO << std::endl << "Test uninitialized image: -----------------------------------------------------------------------------------"; + CPPUNIT_ASSERT_THROW( + mitk::Image::Pointer image = mitk::Image::New(); + mitk::DataNode::Pointer node = mitk::DataNode::New(); + node->SetData(image); + + mitk::ImageStatisticsCalculator::Pointer is = mitk::ImageStatisticsCalculator::New(); + is->GetStatistics(), mitk::Exception); +} + void mitkImageStatisticsCalculatorTestSuite::TestCase1() { - /***************************** - * one whole white pixel - * -> mean of 255 expected - ******************************/ - MITK_INFO << std::endl << "Test case 1:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); - figure1->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 10.5 ; pnt1[1] = 3.5; - figure1->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 3.5; - figure1->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 9.5; pnt3[1] = 4.5; - figure1->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 10.5; pnt4[1] = 4.5; - figure1->SetControlPoint( 3, pnt4, true ); - figure1->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 255.0, 0.0, 255.0); + /***************************** + * one whole white pixel + * -> mean of 255 expected + ******************************/ + MITK_INFO << std::endl << "Test case 1:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); + figure1->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 10.5; pnt1[1] = 3.5; + figure1->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 3.5; + figure1->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 9.5; pnt3[1] = 4.5; + figure1->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 10.5; pnt4[1] = 4.5; + figure1->SetControlPoint(3, pnt4, true); + figure1->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 255.0, 0.0, 255.0); } void mitkImageStatisticsCalculatorTestSuite::TestCase2() { - /***************************** - * half pixel in x-direction (white) - * -> mean of 255 expected - ******************************/ - MITK_INFO << std::endl << "Test case 2:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); - figure1->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 10.0 ; pnt1[1] = 3.5; - figure1->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 3.5; - figure1->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 9.5; pnt3[1] = 4.5; - figure1->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 10.0; pnt4[1] = 4.5; - figure1->SetControlPoint( 3, pnt4, true ); - figure1->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 255.0, 0.0, 255.0); + /***************************** + * half pixel in x-direction (white) + * -> mean of 255 expected + ******************************/ + MITK_INFO << std::endl << "Test case 2:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); + figure1->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 10.0; pnt1[1] = 3.5; + figure1->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 3.5; + figure1->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 9.5; pnt3[1] = 4.5; + figure1->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 10.0; pnt4[1] = 4.5; + figure1->SetControlPoint(3, pnt4, true); + figure1->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 255.0, 0.0, 255.0); } void mitkImageStatisticsCalculatorTestSuite::TestCase3() { - /***************************** - * half pixel in diagonal-direction (white) - * -> mean of 255 expected - ******************************/ - MITK_INFO << std::endl << "Test case 3:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); - figure1->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 10.5 ; pnt1[1] = 3.5; - figure1->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 3.5; - figure1->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 9.5; pnt3[1] = 4.5; - figure1->SetControlPoint( 2, pnt3, true ); - figure1->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 255.0, 0.0, 255.0); + /***************************** + * half pixel in diagonal-direction (white) + * -> mean of 255 expected + ******************************/ + MITK_INFO << std::endl << "Test case 3:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); + figure1->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 10.5; pnt1[1] = 3.5; + figure1->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 3.5; + figure1->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 9.5; pnt3[1] = 4.5; + figure1->SetControlPoint(2, pnt3, true); + figure1->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 255.0, 0.0, 255.0); } void mitkImageStatisticsCalculatorTestSuite::TestCase4() { - /***************************** - * one pixel (white) + 2 half pixels (white) + 1 half pixel (black) - * -> mean of 191.25 expected - ******************************/ - MITK_INFO << std::endl << "Test case 4:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); - figure1->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 1.1; pnt1[1] = 1.1; - figure1->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 2.0; pnt2[1] = 2.0; - figure1->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 3.0; pnt3[1] = 1.0; - figure1->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 2.0; pnt4[1] = 0.0; - figure1->SetControlPoint( 3, pnt4, true ); - figure1->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 191.25, 110.41, 242.250); + /***************************** + * one pixel (white) + 2 half pixels (white) + 1 half pixel (black) + * -> mean of 191.25 expected + ******************************/ + MITK_INFO << std::endl << "Test case 4:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); + figure1->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 1.1; pnt1[1] = 1.1; + figure1->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 2.0; pnt2[1] = 2.0; + figure1->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 3.0; pnt3[1] = 1.0; + figure1->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 2.0; pnt4[1] = 0.0; + figure1->SetControlPoint(3, pnt4, true); + figure1->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 191.25, 110.41, 242.250); } void mitkImageStatisticsCalculatorTestSuite::TestCase5() { - /***************************** - * whole pixel (white) + half pixel (gray) in x-direction - * -> mean of 191.5 expected - ******************************/ - MITK_INFO << std::endl << "Test case 5:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); - figure1->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 11.0; pnt1[1] = 3.5; - figure1->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 3.5; - figure1->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 9.5; pnt3[1] = 4.5; - figure1->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 11.0; pnt4[1] = 4.5; - figure1->SetControlPoint( 3, pnt4, true ); - figure1->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 191.50, 63.50, 134.340); + /***************************** + * whole pixel (white) + half pixel (gray) in x-direction + * -> mean of 191.5 expected + ******************************/ + MITK_INFO << std::endl << "Test case 5:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); + figure1->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 11.0; pnt1[1] = 3.5; + figure1->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 3.5; + figure1->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 9.5; pnt3[1] = 4.5; + figure1->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 11.0; pnt4[1] = 4.5; + figure1->SetControlPoint(3, pnt4, true); + figure1->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 191.50, 63.50, 134.340); } void mitkImageStatisticsCalculatorTestSuite::TestCase6() { - /***************************** - * quarter pixel (black) + whole pixel (white) + half pixel (gray) in x-direction - * -> mean of 191.5 expected - ******************************/ - MITK_INFO << std::endl << "Test case 6:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); - figure1->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 11.0; pnt1[1] = 3.5; - figure1->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 9.25; pnt2[1] = 3.5; - figure1->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 9.25; pnt3[1] = 4.5; - figure1->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 11.0; pnt4[1] = 4.5; - figure1->SetControlPoint( 3, pnt4, true ); - figure1->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 191.5, 63.50, 134.340); + /***************************** + * quarter pixel (black) + whole pixel (white) + half pixel (gray) in x-direction + * -> mean of 191.5 expected + ******************************/ + MITK_INFO << std::endl << "Test case 6:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); + figure1->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 11.0; pnt1[1] = 3.5; + figure1->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 9.25; pnt2[1] = 3.5; + figure1->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 9.25; pnt3[1] = 4.5; + figure1->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 11.0; pnt4[1] = 4.5; + figure1->SetControlPoint(3, pnt4, true); + figure1->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 191.5, 63.50, 134.340); } void mitkImageStatisticsCalculatorTestSuite::TestCase7() { - /***************************** - * half pixel (black) + whole pixel (white) + half pixel (gray) in x-direction - * -> mean of 127.66 expected - ******************************/ - MITK_INFO << std::endl << "Test case 7:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); - figure1->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 11.0; pnt1[1] = 3.5; - figure1->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 9.0; pnt2[1] = 3.5; - figure1->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 9.0; pnt3[1] = 4.0; - figure1->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 11.0; pnt4[1] = 4.0; - figure1->SetControlPoint( 3, pnt4, true ); - figure1->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 127.66, 104.1, 140.250); + /***************************** + * half pixel (black) + whole pixel (white) + half pixel (gray) in x-direction + * -> mean of 127.66 expected + ******************************/ + MITK_INFO << std::endl << "Test case 7:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure1 = mitk::PlanarPolygon::New(); + figure1->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 11.0; pnt1[1] = 3.5; + figure1->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 9.0; pnt2[1] = 3.5; + figure1->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 9.0; pnt3[1] = 4.0; + figure1->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 11.0; pnt4[1] = 4.0; + figure1->SetControlPoint(3, pnt4, true); + figure1->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure1.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 127.66, 104.1, 140.250); } void mitkImageStatisticsCalculatorTestSuite::TestCase8() { - /***************************** - * whole pixel (gray) - * -> mean of 128 expected - ******************************/ - MITK_INFO << std::endl << "Test case 8:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); - figure2->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 11.5; pnt1[1] = 10.5; - figure2->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 11.5; pnt2[1] = 11.5; - figure2->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 12.5; pnt3[1] = 11.5; - figure2->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 12.5; pnt4[1] = 10.5; - figure2->SetControlPoint( 3, pnt4, true ); - figure2->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 128.0, 0.0, 128.0); + /***************************** + * whole pixel (gray) + * -> mean of 128 expected + ******************************/ + MITK_INFO << std::endl << "Test case 8:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); + figure2->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 11.5; pnt1[1] = 10.5; + figure2->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 11.5; pnt2[1] = 11.5; + figure2->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 12.5; pnt3[1] = 11.5; + figure2->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 12.5; pnt4[1] = 10.5; + figure2->SetControlPoint(3, pnt4, true); + figure2->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 128.0, 0.0, 128.0); } void mitkImageStatisticsCalculatorTestSuite::TestCase9() { - /***************************** - * whole pixel (gray) + half pixel (white) in y-direction - * -> mean of 191.5 expected - ******************************/ - MITK_INFO << std::endl << "Test case 9:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); - figure2->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 11.5; pnt1[1] = 10.5; - figure2->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 11.5; pnt2[1] = 12.0; - figure2->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 12.5; pnt3[1] = 12.0; - figure2->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 12.5; pnt4[1] = 10.5; - figure2->SetControlPoint( 3, pnt4, true ); - figure2->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 191.5, 63.50, 134.340); + /***************************** + * whole pixel (gray) + half pixel (white) in y-direction + * -> mean of 191.5 expected + ******************************/ + MITK_INFO << std::endl << "Test case 9:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); + figure2->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 11.5; pnt1[1] = 10.5; + figure2->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 11.5; pnt2[1] = 12.0; + figure2->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 12.5; pnt3[1] = 12.0; + figure2->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 12.5; pnt4[1] = 10.5; + figure2->SetControlPoint(3, pnt4, true); + figure2->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 191.5, 63.50, 134.340); } void mitkImageStatisticsCalculatorTestSuite::TestCase10() { - /***************************** - * 2 whole pixel (white) + 2 whole pixel (black) in y-direction - * -> mean of 127.66 expected - ******************************/ - MITK_INFO << std::endl << "Test case 10:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); - figure2->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 11.5; pnt1[1] = 10.5; - figure2->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 11.5; pnt2[1] = 13.5; - figure2->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 12.5; pnt3[1] = 13.5; - figure2->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 12.5; pnt4[1] = 10.5; - figure2->SetControlPoint( 3, pnt4, true ); - figure2->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 127.66, 104.1, 140.250); + /***************************** + * 2 whole pixel (white) + 2 whole pixel (black) in y-direction + * -> mean of 127.66 expected + ******************************/ + MITK_INFO << std::endl << "Test case 10:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); + figure2->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 11.5; pnt1[1] = 10.5; + figure2->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 11.5; pnt2[1] = 13.5; + figure2->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 12.5; pnt3[1] = 13.5; + figure2->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 12.5; pnt4[1] = 10.5; + figure2->SetControlPoint(3, pnt4, true); + figure2->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 127.66, 104.1, 140.250); } void mitkImageStatisticsCalculatorTestSuite::TestCase11() { - /***************************** - * 9 whole pixels (white) + 3 half pixels (white) - * + 3 whole pixel (black) [ + 3 slightly less than half pixels (black)] - * -> mean of 204.0 expected - ******************************/ - MITK_INFO << std::endl << "Test case 11:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); - figure2->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 0.5; pnt1[1] = 0.5; - figure2->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 3.5; pnt2[1] = 3.5; - figure2->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 8.4999; pnt3[1] = 3.5; - figure2->SetControlPoint( 2, pnt3, true ); - mitk::Point2D pnt4; pnt4[0] = 5.4999; pnt4[1] = 0.5; - figure2->SetControlPoint( 3, pnt4, true ); - figure2->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 204.0, 102.00, 242.250); + /***************************** + * 9 whole pixels (white) + 3 half pixels (white) + * + 3 whole pixel (black) [ + 3 slightly less than half pixels (black)] + * -> mean of 204.0 expected + ******************************/ + MITK_INFO << std::endl << "Test case 11:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); + figure2->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 0.5; pnt1[1] = 0.5; + figure2->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 3.5; pnt2[1] = 3.5; + figure2->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 8.4999; pnt3[1] = 3.5; + figure2->SetControlPoint(2, pnt3, true); + mitk::Point2D pnt4; pnt4[0] = 5.4999; pnt4[1] = 0.5; + figure2->SetControlPoint(3, pnt4, true); + figure2->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 204.0, 102.00, 242.250); } void mitkImageStatisticsCalculatorTestSuite::TestCase12() { - /***************************** - * half pixel (white) + whole pixel (white) + half pixel (black) - * -> mean of 212.66 expected - ******************************/ - MITK_INFO << std::endl << "Test case 12:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); - MITK_TEST_CONDITION_REQUIRED(m_Geometry.IsNotNull(), "Getting image geometry"); - - mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); - figure2->SetPlaneGeometry( m_Geometry ); - mitk::Point2D pnt1; pnt1[0] = 9.5; pnt1[1] = 0.5; - figure2->PlaceFigure( pnt1 ); - - mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 2.5; - figure2->SetControlPoint( 1, pnt2, true ); - mitk::Point2D pnt3; pnt3[0] = 11.5; pnt3[1] = 2.5; - figure2->SetControlPoint( 2, pnt3, true ); - figure2->GetPolyLine(0); - - auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 212.66, 59.860, 248.640); -} - -void mitkImageStatisticsCalculatorTestSuite::TestImageMaskingEmpty() -{ - MITK_INFO << std::endl << "TestImageMaskingEmpty:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - mitk::Image::Pointer mask_image = mitk::ImageGenerator::GenerateImageFromReference( m_TestImage->Clone(), 0 ); - - auto statisticsContainer = ComputeStatistics( m_TestImage, mask_image ); - // test if no statisticsContainer for timestep 0 exists - MITK_TEST_CONDITION(!statisticsContainer->TimeStepExists(0), "No statistics for TimeStep 0 does exist."); - MITK_TEST_FOR_EXCEPTION(mitk::Exception, statisticsContainer->GetStatisticsForTimeStep(0)); -} - -void mitkImageStatisticsCalculatorTestSuite::TestImageMaskingNonEmpty() -{ - MITK_INFO << std::endl << "TestImageMaskingNonEmpty:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - mitk::Image::Pointer mask_image = mitk::ImageGenerator::GenerateImageFromReference( m_TestImage->Clone(), 0 ); - - // activate voxel in the mask image - if (mask_image->GetDimension() == 3) - { - std::vector< itk::Index<3U> > activated_indices; - itk::Index<3U> index = { { 10, 8, 0 } }; - activated_indices.push_back(index); - - index[0] = 9; index[1] = 8; index[2] = 0; - activated_indices.push_back(index); - - index[0] = 9; index[1] = 7; index[2] = 0; - activated_indices.push_back(index); - - index[0] = 10; index[1] = 7; index[2] = 0; - activated_indices.push_back(index); - - std::vector< itk::Index<3U> >::const_iterator indexIter = activated_indices.begin(); - - mitk::ImagePixelWriteAccessor< unsigned char, 3> writeAccess(mask_image); - while (indexIter != activated_indices.end()) - { - writeAccess.SetPixelByIndex((*indexIter++), 1); - } - } - if (mask_image->GetDimension() == 4) - { - std::vector< itk::Index<4U> > activated_indices; - itk::Index<4U> index = { { 10, 8, 0, 0 } }; - activated_indices.push_back(index); - - index[0] = 9; index[1] = 8; index[2] = 0; index[3] = 0; - activated_indices.push_back(index); - - index[0] = 9; index[1] = 7; index[2] = 0; index[3] = 0; - activated_indices.push_back(index); - - index[0] = 10; index[1] = 7; index[2] = 0; index[3] = 0; - activated_indices.push_back(index); - - std::vector< itk::Index<4U> >::const_iterator indexIter = activated_indices.begin(); - - mitk::ImagePixelWriteAccessor< unsigned char, 4> writeAccess(mask_image); - while (indexIter != activated_indices.end()) - { - writeAccess.SetPixelByIndex((*indexIter++), 1); - } - } - - auto statisticsContainer = ComputeStatistics(m_TestImage, mask_image); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 127.5, 127.5, 12.750); -} - -void mitkImageStatisticsCalculatorTestSuite::TestRecomputeOnModifiedMask() -{ - MITK_INFO << std::endl << "TestRecomputeOnModifiedMask:-----------------------------------------------------------------------------------"; - - std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.dcm"); - m_TestImage = mitk::IOUtil::Load(filename); - MITK_TEST_CONDITION_REQUIRED(m_TestImage.IsNotNull(), "Loaded an mitk::Image"); - - mitk::Image::Pointer mask_image = mitk::ImageGenerator::GenerateImageFromReference( m_TestImage->Clone(), 0 ); - - mitk::ImageStatisticsCalculator::Pointer statisticsCalculator = mitk::ImageStatisticsCalculator::New(); - statisticsCalculator->SetInputImage( m_TestImage ); - - mitk::ImageMaskGenerator::Pointer imgMaskGen = mitk::ImageMaskGenerator::New(); - imgMaskGen->SetImageMask(mask_image); - - statisticsCalculator->SetMask(imgMaskGen.GetPointer()); - - auto statisticsContainer = statisticsCalculator->GetStatistics(); - - // test if no statisticsContainer for timestep 0 exists - MITK_TEST_CONDITION(!statisticsContainer->TimeStepExists(0), "No statistics for TimeStep 0 does exist."); - MITK_TEST_FOR_EXCEPTION(mitk::Exception, statisticsContainer->GetStatisticsForTimeStep(0)); - - // activate voxel in the mask image - if (mask_image->GetDimension() == 3) - { - itk::Index<3U> test_index = { { 11, 8, 0 } }; - mitk::ImagePixelWriteAccessor< unsigned char, 3> writeAccess(mask_image); - writeAccess.SetPixelByIndex(test_index, 1); - } - if (mask_image->GetDimension() == 4) - { - itk::Index<4U> test_index = { { 11, 8, 0, 0 } }; - mitk::ImagePixelWriteAccessor< unsigned char, 4> writeAccess(mask_image); - writeAccess.SetPixelByIndex(test_index, 1); - } - - //Delete if T25625 has been resolved - imgMaskGen->Modified(); - - statisticsContainer = statisticsCalculator->GetStatistics(); - - MITK_TEST_CONDITION(statisticsContainer->TimeStepExists(0), "Statistics for TimeStep 0 does exist."); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - this->VerifyStatistics(statisticsObjectTimestep0, 128.0, 0.0, 128.0); - auto numberOfVoxels = statisticsObjectTimestep0.GetValueConverted( - mitk::ImageStatisticsConstants::NUMBEROFVOXELS()); - MITK_TEST_CONDITION(numberOfVoxels == 1, "Calculated mask voxel count '" << numberOfVoxels << "' is equal to the desired value '" << 1 << "'" ); -} - -void mitkImageStatisticsCalculatorTestSuite::TestPic3DStatistics() -{ - MITK_INFO << std::endl << "Test plain Pic3D:-----------------------------------------------------------------------------------"; - - std::string Pic3DFile = this->GetTestDataFilePath("Pic3D.nrrd"); - m_Pic3DImage = mitk::IOUtil::Load(Pic3DFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImage.IsNotNull(), "Loaded Pic3D"); - - unsigned long expected_N = 3211264; - double expected_mean = -365.80015345982144; - double expected_MPP = 111.80226129535752; - double expected_median = -105.16000366210938; - double expected_skewness = -0.26976612134147004; - double expected_kurtosis = 1.4655017209571437; - double expected_uniformity = 0.06087994379480554; - double expected_UPP = 0.011227934437026977; - double expected_variance = 224036.80150510342; - double expected_standarddev = 473.32525973700518; - double expected_min = -1023; - double expected_max = 1361; - double expected_RMS = 598.20276978323352; - double expected_entropy = 4.6727423654570357; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 0; - expected_minIndex[1] = 0; - expected_minIndex[2] = 0; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 139; - expected_maxIndex[1] = 182; - expected_maxIndex[2] = 43; - - auto statisticsContainer = ComputeStatisticsNew(m_Pic3DImage); - auto statisticsObject = statisticsContainer->GetStatisticsForTimeStep(0); - - VerifyStatistics(statisticsObject, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); -} - -void mitkImageStatisticsCalculatorTestSuite::TestPic3DAxialPlanarFigureMaskStatistics() -{ - MITK_INFO << std::endl << "Test Pic3D axial pf:-----------------------------------------------------------------------------------"; - - std::string Pic3DFile = this->GetTestDataFilePath("Pic3D.nrrd"); - m_Pic3DImage = mitk::IOUtil::Load(Pic3DFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImage.IsNotNull(), "Loaded Pic3D"); - - std::string Pic3DAxialPlanarFigureFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3DAxialPlanarFigure.pf"); - m_Pic3DPlanarFigureAxial = mitk::IOUtil::Load(Pic3DAxialPlanarFigureFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DPlanarFigureAxial.IsNotNull(), "Loaded Pic3D axial planarFigure"); - - double expected_entropy = 5.6719817476387417; - double expected_kurtosis = 5.8846935191205221; - double expected_MPP = 230.43933685003768; - double expected_max = 1206; - double expected_mean = 182.30282131661443; - double expected_median = 95.970001220703125; - double expected_min = -156; - unsigned long expected_N = 3190; - double expected_RMS = 301.93844376702253; - double expected_skewness = 1.6400489794326298; - double expected_standarddev = 240.69172225993557; - double expected_UPP = 0.024889790784288681; - double expected_uniformity = 0.027579917650180332; - double expected_variance = 57932.505164453964; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 156; - expected_minIndex[1] = 133; - expected_minIndex[2] = 24; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 125; - expected_maxIndex[1] = 167; - expected_maxIndex[2] = 24; - - mitk::PlanarFigureMaskGenerator::Pointer pfMaskGen = mitk::PlanarFigureMaskGenerator::New(); - pfMaskGen->SetInputImage(m_Pic3DImage); - pfMaskGen->SetPlanarFigure(m_Pic3DPlanarFigureAxial); - - auto statisticsContainer = ComputeStatisticsNew(m_Pic3DImage, pfMaskGen.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - VerifyStatistics(statisticsObjectTimestep0, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); -} - -void mitkImageStatisticsCalculatorTestSuite::TestPic3DSagittalPlanarFigureMaskStatistics() -{ - MITK_INFO << std::endl << "Test Pic3D sagittal pf:-----------------------------------------------------------------------------------"; - - std::string Pic3DFile = this->GetTestDataFilePath("Pic3D.nrrd"); - m_Pic3DImage = mitk::IOUtil::Load(Pic3DFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImage.IsNotNull(), "Loaded Pic3D"); - - std::string Pic3DSagittalPlanarFigureFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3DSagittalPlanarFigure.pf"); - m_Pic3DPlanarFigureSagittal = mitk::IOUtil::Load(Pic3DSagittalPlanarFigureFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DPlanarFigureSagittal.IsNotNull(), "Loaded Pic3D sagittal planarFigure"); - - double expected_entropy = 5.6051911962074286; - double expected_kurtosis = 6.5814062739142338; - double expected_MPP = 249.03202846975088; - double expected_max = 1240; - double expected_mean = 233.93602693602693; - double expected_median = 174.9849853515625; - double expected_min = -83; - unsigned long expected_N = 1188; - double expected_RMS = 332.03230188484594; - double expected_skewness = 1.7489809015501814; - double expected_standarddev = 235.62551813489128; - double expected_UPP = 0.026837539253364174; - double expected_uniformity = 0.027346982734188126; - double expected_variance = 55519.384796335973; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 128; - expected_minIndex[1] = 119; - expected_minIndex[2] = 22; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 128; - expected_maxIndex[1] = 167; - expected_maxIndex[2] = 22; - - mitk::PlanarFigureMaskGenerator::Pointer pfMaskGen = mitk::PlanarFigureMaskGenerator::New(); - pfMaskGen->SetInputImage(m_Pic3DImage); - pfMaskGen->SetPlanarFigure(m_Pic3DPlanarFigureSagittal); - - auto statisticsContainer = ComputeStatisticsNew(m_Pic3DImage, pfMaskGen.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - VerifyStatistics(statisticsObjectTimestep0, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + /***************************** + * half pixel (white) + whole pixel (white) + half pixel (black) + * -> mean of 212.66 expected + ******************************/ + MITK_INFO << std::endl << "Test case 12:-----------------------------------------------------------------------------------"; + + std::string filename = this->GetTestDataFilePath("ImageStatisticsTestData/testimage.nrrd"); + m_TestImage = mitk::IOUtil::Load(filename); + CPPUNIT_ASSERT_MESSAGE("Failed loading an mitk::Image", m_TestImage.IsNotNull()); + + m_Geometry = m_TestImage->GetSlicedGeometry()->GetPlaneGeometry(0); + CPPUNIT_ASSERT_MESSAGE("Failed getting image geometry", m_Geometry.IsNotNull()); + + mitk::PlanarPolygon::Pointer figure2 = mitk::PlanarPolygon::New(); + figure2->SetPlaneGeometry(m_Geometry); + mitk::Point2D pnt1; pnt1[0] = 9.5; pnt1[1] = 0.5; + figure2->PlaceFigure(pnt1); + + mitk::Point2D pnt2; pnt2[0] = 9.5; pnt2[1] = 2.5; + figure2->SetControlPoint(1, pnt2, true); + mitk::Point2D pnt3; pnt3[0] = 11.5; pnt3[1] = 2.5; + figure2->SetControlPoint(2, pnt3, true); + figure2->GetPolyLine(0); + + auto statisticsContainer = ComputeStatistics(m_TestImage, figure2.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + this->VerifyStatistics(statisticsObjectTimestep0, 212.66, 59.860, 248.640); } -void mitkImageStatisticsCalculatorTestSuite::TestPic3DCoronalPlanarFigureMaskStatistics() +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) +void mitkImageStatisticsCalculatorTestSuite::TestPic3DCroppedNoMask() { - MITK_INFO << std::endl << "Test Pic3D coronal pf:-----------------------------------------------------------------------------------"; - - std::string Pic3DFile = this->GetTestDataFilePath("Pic3D.nrrd"); - m_Pic3DImage = mitk::IOUtil::Load(Pic3DFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImage.IsNotNull(), "Loaded Pic3D"); - - std::string Pic3DCoronalPlanarFigureFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3DCoronalPlanarFigure.pf"); - m_Pic3DPlanarFigureCoronal = mitk::IOUtil::Load(Pic3DCoronalPlanarFigureFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DPlanarFigureCoronal.IsNotNull(), "Loaded Pic3D coronal planarFigure"); - - double expected_entropy = 6.0677398647867449; - double expected_kurtosis = 1.6242929941303372; - double expected_MPP = 76.649350649350652; - double expected_max = 156; - double expected_mean = -482.14807692307693; - double expected_median = -660.07501220703125; - double expected_min = -897; - unsigned long expected_N = 520; - double expected_RMS = 595.09446729069839; - double expected_skewness = 0.51691492278851858; - double expected_standarddev = 348.81321207686312; - double expected_UPP = 0.0021560650887573964; - double expected_uniformity = 0.020295857988165685; - double expected_variance = 121670.6569193787; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 217; - expected_minIndex[1] = 127; - expected_minIndex[2] = 43; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 209; - expected_maxIndex[1] = 127; - expected_maxIndex[2] = 39; - - mitk::PlanarFigureMaskGenerator::Pointer pfMaskGen = mitk::PlanarFigureMaskGenerator::New(); - pfMaskGen->SetInputImage(m_Pic3DImage); - pfMaskGen->SetPlanarFigure(m_Pic3DPlanarFigureCoronal); - - auto statisticsContainer = ComputeStatisticsNew(m_Pic3DImage, pfMaskGen.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - VerifyStatistics(statisticsObjectTimestep0, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + MITK_INFO << std::endl << "Test Pic3D cropped without mask:-----------------------------------------------------------------------------------"; + + std::string Pic3DCroppedFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D_cropped.nrrd"); + m_Pic3DCroppedImage = mitk::IOUtil::Load(Pic3DCroppedFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading Pic3D_cropped", m_Pic3DCroppedImage.IsNotNull()); + + unsigned long expected_N = 27; + double expected_mean = -564.1481481481481481; + double expected_MPP = 113.66666666666667; + double expected_median = -825; + double expected_skewness = 0.7120461106763573; + double expected_kurtosis = 1.8794464383714844; + double expected_variance = 140541.38545953357; + double expected_standarddev = 374.88849736892911; + double expected_min = -927; + double expected_max = 147; + double expected_RMS = 677.35110431630551; + vnl_vector expected_minIndex; + expected_minIndex.set_size(3); + expected_minIndex[0] = 2; + expected_minIndex[1] = 1; + expected_minIndex[2] = 1; + + vnl_vector expected_maxIndex; + expected_maxIndex.set_size(3); + expected_maxIndex[0] = 0; + expected_maxIndex[1] = 1; + expected_maxIndex[2] = 2; + + auto statisticsContainer = ComputeStatisticsNew(m_Pic3DCroppedImage); + auto statisticsObject = statisticsContainer->GetStatisticsForTimeStep(0); + + VerifyStatistics(statisticsObject, + expected_N, + expected_mean, + expected_MPP, + expected_skewness, + expected_kurtosis, + expected_variance, + expected_standarddev, + expected_min, + expected_max, + expected_RMS, + expected_minIndex, + expected_maxIndex); } -void mitkImageStatisticsCalculatorTestSuite::TestPic3DImageMaskStatistics_label1() +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) +void mitkImageStatisticsCalculatorTestSuite::TestPic3DCroppedBinMask() { - MITK_INFO << std::endl << "Test Pic3D image mask label 1 pf:-----------------------------------------------------------------------------------"; - - std::string Pic3DFile = this->GetTestDataFilePath("Pic3D.nrrd"); - m_Pic3DImage = mitk::IOUtil::Load(Pic3DFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImage.IsNotNull(), "Loaded Pic3D"); - - std::string Pic3DImageMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D-labels.nrrd"); - m_Pic3DImageMask = mitk::IOUtil::Load(Pic3DImageMaskFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImageMask.IsNotNull(), "Loaded Pic3D image mask"); - - double expected_entropy = 5.695858251095868; - double expected_kurtosis = 4.2728827997815717; - double expected_MPP = 413.52408256880733; - double expected_max = 1206; - double expected_mean = 413.52408256880733; - double expected_median = 324; - double expected_min = 6; - unsigned long expected_N = 872; - double expected_RMS = 472.02024695145235; - double expected_skewness = 1.3396074364415382; - double expected_standarddev = 227.59821323493802; - double expected_UPP = 0.029758648261930806; - double expected_uniformity = 0.029758648261930806; - double expected_variance = 51800.946667736309; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 135; - expected_minIndex[1] = 158; - expected_minIndex[2] = 24; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 125; - expected_maxIndex[1] = 167; - expected_maxIndex[2] = 24; - - mitk::ImageMaskGenerator::Pointer imgMaskGen = mitk::ImageMaskGenerator::New(); - imgMaskGen->SetImageMask(m_Pic3DImageMask); - imgMaskGen->SetInputImage(m_Pic3DImage); - imgMaskGen->SetTimeStep(0); - - auto statisticsContainer = ComputeStatisticsNew(m_Pic3DImage, imgMaskGen.GetPointer(), nullptr, 1); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - VerifyStatistics(statisticsObjectTimestep0, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + MITK_INFO << std::endl << "Test Pic3D cropped binary mask:-----------------------------------------------------------------------------------"; + + std::string Pic3DCroppedFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D_cropped.nrrd"); + m_Pic3DCroppedImage = mitk::IOUtil::Load(Pic3DCroppedFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading Pic3D_cropped", m_Pic3DCroppedImage.IsNotNull()); + + std::string Pic3DCroppedBinMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D_croppedBinMask.nrrd"); + m_Pic3DCroppedBinMask = mitk::IOUtil::Load(Pic3DCroppedBinMaskFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading Pic3D binary mask", m_Pic3DCroppedBinMask.IsNotNull()); + + double expected_kurtosis = 1.0765697398089618; + double expected_MPP = -nan(""); + double expected_max = -22; + double expected_mean = -464; + double expected_min = -846; + unsigned long expected_N = 4; + double expected_RMS = 595.42631785973322; + double expected_skewness = 0.0544059290851858; + double expected_standarddev = 373.14407405183323; + double expected_variance = 139236.50; + vnl_vector expected_minIndex; + expected_minIndex.set_size(3); + expected_minIndex[0] = 1; + expected_minIndex[1] = 0; + expected_minIndex[2] = 0; + + vnl_vector expected_maxIndex; + expected_maxIndex.set_size(3); + expected_maxIndex[0] = 0; + expected_maxIndex[1] = 0; + expected_maxIndex[2] = 1; + + mitk::ImageMaskGenerator::Pointer imgMaskGen = mitk::ImageMaskGenerator::New(); + imgMaskGen->SetImageMask(m_Pic3DCroppedBinMask); + imgMaskGen->SetInputImage(m_Pic3DCroppedImage); + imgMaskGen->SetTimeStep(0); + + auto statisticsContainer = ComputeStatisticsNew(m_Pic3DCroppedImage, imgMaskGen.GetPointer(), nullptr, 1); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + VerifyStatistics(statisticsObjectTimestep0, + expected_N, + expected_mean, + expected_MPP, + expected_skewness, + expected_kurtosis, + expected_variance, + expected_standarddev, + expected_min, + expected_max, + expected_RMS, + expected_minIndex, + expected_maxIndex); } - -void mitkImageStatisticsCalculatorTestSuite::TestPic3DImageMaskStatistics_label2() +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) +void mitkImageStatisticsCalculatorTestSuite::TestPic3DCroppedMultilabelMask() { - MITK_INFO << std::endl << "Test Pic3D image mask label 2 pf:-----------------------------------------------------------------------------------"; - - std::string Pic3DFile = this->GetTestDataFilePath("Pic3D.nrrd"); - m_Pic3DImage = mitk::IOUtil::Load(Pic3DFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImage.IsNotNull(), "Loaded Pic3D"); - - std::string Pic3DImageMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D-labels.nrrd"); - m_Pic3DImageMask = mitk::IOUtil::Load(Pic3DImageMaskFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImageMask.IsNotNull(), "Loaded Pic3D image mask"); - - double expected_entropy = 4.3685781901212764; - double expected_kurtosis = 9.7999112757587934; - double expected_MPP = -nan(""); - double expected_max = -145; - double expected_mean = -897.92833876221493; - double expected_median = -969.16499900817871; - double expected_min = -1008; - unsigned long expected_N = 307; - double expected_RMS = 913.01496468179471; - double expected_skewness = 2.6658524648889736; - double expected_standarddev = 165.29072623903585; - double expected_UPP = 0; - double expected_uniformity = 0.087544695434434425; - double expected_variance = 27321.024180627897; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 170; - expected_minIndex[1] = 60; - expected_minIndex[2] = 24; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 173; - expected_maxIndex[1] = 57; - expected_maxIndex[2] = 24; - - mitk::ImageMaskGenerator::Pointer imgMaskGen = mitk::ImageMaskGenerator::New(); - imgMaskGen->SetImageMask(m_Pic3DImageMask); - imgMaskGen->SetInputImage(m_Pic3DImage); - imgMaskGen->SetTimeStep(0); - - auto statisticsContainer = ComputeStatisticsNew(m_Pic3DImage, imgMaskGen.GetPointer(), nullptr, 2); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - VerifyStatistics(statisticsObjectTimestep0, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + MITK_INFO << std::endl << "Test Pic3D cropped multilabel mask:-----------------------------------------------------------------------------------"; + + std::string Pic3DCroppedFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D_cropped.nrrd"); + m_Pic3DCroppedImage = mitk::IOUtil::Load(Pic3DCroppedFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading Pic3D_cropped", m_Pic3DCroppedImage.IsNotNull()); + + std::string Pic3DCroppedMultilabelMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D_croppedMultilabelMask.nrrd"); + m_Pic3DCroppedMultilabelMask = mitk::IOUtil::Load(Pic3DCroppedMultilabelMaskFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading Pic3D multilabel mask", m_Pic3DCroppedMultilabelMask.IsNotNull()); + + double expected_kurtosis = 1.5; + double expected_MPP = -nan(""); + double expected_max = -22; + double expected_mean = -586.33333333333333; + double expected_min = -916; + unsigned long expected_N = 3; + double expected_RMS = 710.3006405741163; + double expected_skewness = 0.6774469597523700; + double expected_standarddev = 400.92421007245525; + double expected_variance = 160740.22222222222; + vnl_vector expected_minIndex; + expected_minIndex.set_size(3); + expected_minIndex[0] = 2; + expected_minIndex[1] = 0; + expected_minIndex[2] = 1; + + vnl_vector expected_maxIndex; + expected_maxIndex.set_size(3); + expected_maxIndex[0] = 0; + expected_maxIndex[1] = 0; + expected_maxIndex[2] = 1; + + mitk::ImageMaskGenerator::Pointer imgMaskGen = mitk::ImageMaskGenerator::New(); + imgMaskGen->SetImageMask(m_Pic3DCroppedMultilabelMask); + imgMaskGen->SetInputImage(m_Pic3DCroppedImage); + imgMaskGen->SetTimeStep(0); + + auto statisticsContainer = ComputeStatisticsNew(m_Pic3DCroppedImage, imgMaskGen.GetPointer(), nullptr, 2); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + VerifyStatistics(statisticsObjectTimestep0, + expected_N, + expected_mean, + expected_MPP, + expected_skewness, + expected_kurtosis, + expected_variance, + expected_standarddev, + expected_min, + expected_max, + expected_RMS, + expected_minIndex, + expected_maxIndex); } - -void mitkImageStatisticsCalculatorTestSuite::TestPic3DIgnorePixelValueMaskStatistics() +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) +void mitkImageStatisticsCalculatorTestSuite::TestPic3DCroppedPlanarFigure() { - MITK_INFO << std::endl << "Test Pic3D ignore zero pixels:-----------------------------------------------------------------------------------"; - - std::string Pic3DFile = this->GetTestDataFilePath("Pic3D.nrrd"); - m_Pic3DImage = mitk::IOUtil::Load(Pic3DFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImage.IsNotNull(), "Loaded Pic3D"); - - double expected_entropy = 4.671045011438645; - double expected_kurtosis = 1.4638176488404484; - double expected_MPP = 111.80226129535752; - double expected_max = 1361; - double expected_mean = -366.48547402877585; - double expected_median = -105.16000366210938; - double expected_min = -1023; - unsigned long expected_N = 3205259; - double expected_RMS = 598.76286909522139; - double expected_skewness = -0.26648854845130782; - double expected_standarddev = 473.50329537717545; - double expected_UPP = 0.011270044547276429; - double expected_uniformity = 0.061029773286547614; - double expected_variance = 224205.37073304466; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 0; - expected_minIndex[1] = 0; - expected_minIndex[2] = 0; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 139; - expected_maxIndex[1] = 182; - expected_maxIndex[2] = 43; - - mitk::IgnorePixelMaskGenerator::Pointer ignPixelValMask = mitk::IgnorePixelMaskGenerator::New(); - ignPixelValMask->SetInputImage(m_Pic3DImage); - ignPixelValMask->SetIgnoredPixelValue(0); - ignPixelValMask->SetTimeStep(0); - - auto statisticsContainer = ComputeStatisticsNew(m_Pic3DImage, ignPixelValMask.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - VerifyStatistics(statisticsObjectTimestep0, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + MITK_INFO << std::endl << "Test Pic3D cropped planar figure:-----------------------------------------------------------------------------------"; + + std::string Pic3DCroppedFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D_cropped.nrrd"); + m_Pic3DCroppedImage = mitk::IOUtil::Load(Pic3DCroppedFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading Pic3D_cropped", m_Pic3DCroppedImage.IsNotNull()); + + std::string Pic3DCroppedPlanarFigureFile = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D_croppedPF.pf"); + m_Pic3DCroppedPlanarFigure = mitk::IOUtil::Load(Pic3DCroppedPlanarFigureFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading Pic3D planar figure", m_Pic3DCroppedPlanarFigure.IsNotNull()); + + double expected_kurtosis = 1; + double expected_MPP = -nan(""); + double expected_max = -67; + double expected_mean = -446; + double expected_min = -825; + unsigned long expected_N = 2; + double expected_RMS = 585.28369189650243; + double expected_skewness = 0; + double expected_standarddev = 379; + double expected_variance = 143641; + vnl_vector expected_minIndex; + expected_minIndex.set_size(3); + expected_minIndex[0] = 1; + expected_minIndex[1] = 1; + expected_minIndex[2] = 1; + + vnl_vector expected_maxIndex; + expected_maxIndex.set_size(3); + expected_maxIndex[0] = 0; + expected_maxIndex[1] = 1; + expected_maxIndex[2] = 1; + + mitk::PlanarFigureMaskGenerator::Pointer pfMaskGen = mitk::PlanarFigureMaskGenerator::New(); + pfMaskGen->SetInputImage(m_Pic3DCroppedImage); + pfMaskGen->SetPlanarFigure(m_Pic3DCroppedPlanarFigure); + + auto statisticsContainer = ComputeStatisticsNew(m_Pic3DCroppedImage, pfMaskGen.GetPointer()); + auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); + + VerifyStatistics(statisticsObjectTimestep0, + expected_N, + expected_mean, + expected_MPP, + expected_skewness, + expected_kurtosis, + expected_variance, + expected_standarddev, + expected_min, + expected_max, + expected_RMS, + expected_minIndex, + expected_maxIndex); } - -void mitkImageStatisticsCalculatorTestSuite::TestPic3DSecondaryMaskStatistics() +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) +void mitkImageStatisticsCalculatorTestSuite::TestUS4DCroppedNoMaskTimeStep1() { - MITK_INFO << std::endl << "Test Pic3D ignore zero pixels AND Image mask 2:-----------------------------------------------------------------------------------"; - - std::string Pic3DFile = this->GetTestDataFilePath("Pic3D.nrrd"); - m_Pic3DImage = mitk::IOUtil::Load(Pic3DFile); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImage.IsNotNull(), "Loaded Pic3D"); - - std::string Pic3DImageMaskFile2 = this->GetTestDataFilePath("ImageStatisticsTestData/Pic3D-labels2.nrrd"); - m_Pic3DImageMask2 = mitk::IOUtil::Load(Pic3DImageMaskFile2); - MITK_TEST_CONDITION_REQUIRED(m_Pic3DImageMask2.IsNotNull(), "Loaded Pic3D image secondary mask"); - - double expected_entropy = 5.9741637167320176; - double expected_kurtosis = 3.490663358061596; - double expected_MPP = 332.43534482758622; - double expected_max = 1206; - double expected_mean = 320.63333333333333; - double expected_median = 265.06500244140625; - double expected_min = -57; - unsigned long expected_N = 720; - double expected_RMS = 433.57749531594055; - double expected_skewness = 1.1047775627624981; - double expected_standarddev = 291.86248474238687; - double expected_UPP = 0.020628858024691339; - double expected_uniformity = 0.021377314814814797; - double expected_variance = 85183.710000000006; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 116; - expected_minIndex[1] = 170; - expected_minIndex[2] = 24; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 125; - expected_maxIndex[1] = 167; - expected_maxIndex[2] = 24; - - mitk::IgnorePixelMaskGenerator::Pointer ignPixelValMask = mitk::IgnorePixelMaskGenerator::New(); - ignPixelValMask->SetInputImage(m_Pic3DImage); - ignPixelValMask->SetIgnoredPixelValue(0); - ignPixelValMask->SetTimeStep(0); - - mitk::ImageMaskGenerator::Pointer imgMaskGen2 = mitk::ImageMaskGenerator::New(); - imgMaskGen2->SetImageMask(m_Pic3DImageMask2); - imgMaskGen2->SetInputImage(m_Pic3DImage); - imgMaskGen2->SetTimeStep(0); - - auto statisticsContainer = - ComputeStatisticsNew(m_Pic3DImage, imgMaskGen2.GetPointer(), ignPixelValMask.GetPointer()); - auto statisticsObjectTimestep0 = statisticsContainer->GetStatisticsForTimeStep(0); - - VerifyStatistics(statisticsObjectTimestep0, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + MITK_INFO << std::endl << "Test US4D cropped without mask timestep 1:-----------------------------------------------------------------------------------"; + + std::string US4DCroppedFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D_Cropped.nrrd"); + m_US4DCroppedImage = mitk::IOUtil::Load(US4DCroppedFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading US4D_cropped", m_US4DCroppedImage.IsNotNull()); + + double expected_kurtosis = 1.5398359155908228; + double expected_MPP = 157.74074074074073; + double expected_max = 199; + double expected_mean = 157.74074074074073; + double expected_min = 101; + unsigned long expected_N = 27; + double expected_RMS = 160.991718213494823; + double expected_skewness = 0.0347280313508018; + double expected_standarddev = 32.189936997387058; + double expected_variance = 1036.19204389574722; + vnl_vector expected_minIndex; + expected_minIndex.set_size(3); + expected_minIndex[0] = 0; + expected_minIndex[1] = 2; + expected_minIndex[2] = 0; + + vnl_vector expected_maxIndex; + expected_maxIndex.set_size(3); + expected_maxIndex[0] = 0; + expected_maxIndex[1] = 0; + expected_maxIndex[2] = 1; + + auto statisticsContainer = ComputeStatisticsNew(m_US4DCroppedImage); + auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); + + VerifyStatistics(statisticsObjectTimestep1, + expected_N, + expected_mean, + expected_MPP, + expected_skewness, + expected_kurtosis, + expected_variance, + expected_standarddev, + expected_min, + expected_max, + expected_RMS, + expected_minIndex, + expected_maxIndex); } - -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylStatistics_time1() +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) +void mitkImageStatisticsCalculatorTestSuite::TestUS4DCroppedBinMaskTimeStep1() { - MITK_INFO << std::endl << "Test plain US4D timeStep1:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - double expected_entropy = 4.8272774900452502; - double expected_kurtosis = 6.1336513352934432; - double expected_MPP = 53.395358640738536; - double expected_max = 199; - double expected_mean = 35.771298153622375; - double expected_median = 20.894999504089355; - double expected_min = 0; - unsigned long expected_N = 3409920; - double expected_RMS = 59.244523377028408; - double expected_skewness = 1.8734292240015058; - double expected_standarddev = 47.226346233600559; - double expected_UPP = 0.12098731125004937; - double expected_uniformity = 0.12098731125004937; - double expected_variance = 2230.3277785759178; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 0; - expected_minIndex[1] = 0; - expected_minIndex[2] = 0; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 268; - expected_maxIndex[1] = 101; - expected_maxIndex[2] = 0; - - auto statisticsContainer = ComputeStatisticsNew(m_US4DImage); - auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); - - VerifyStatistics(statisticsObjectTimestep1, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + MITK_INFO << std::endl << "Test US4D cropped with binary mask timestep 1:-----------------------------------------------------------------------------------"; + + std::string US4DCroppedFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D_cropped.nrrd"); + m_US4DCroppedImage = mitk::IOUtil::Load(US4DCroppedFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading US4D_cropped", m_US4DCroppedImage.IsNotNull()); + + std::string US4DCroppedBinMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D_croppedBinMask.nrrd"); + m_US4DCroppedBinMask = mitk::IOUtil::Load(US4DCroppedBinMaskFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading US4D binary mask", m_US4DCroppedBinMask.IsNotNull()); + + double expected_kurtosis = 1.5863739712889191; + double expected_MPP = 166.75; + double expected_max = 199; + double expected_mean = 166.75; + double expected_min = 120; + unsigned long expected_N = 4; + double expected_RMS = 169.70636405273669; + double expected_skewness = -0.4285540263894276; + double expected_standarddev = 31.538666744172936; + double expected_variance = 994.6874999999999; + vnl_vector expected_minIndex; + expected_minIndex.set_size(3); + expected_minIndex[0] = 0; + expected_minIndex[1] = 0; + expected_minIndex[2] = 2; + + vnl_vector expected_maxIndex; + expected_maxIndex.set_size(3); + expected_maxIndex[0] = 1; + expected_maxIndex[1] = 1; + expected_maxIndex[2] = 1; + + mitk::ImageMaskGenerator::Pointer imgMask1 = mitk::ImageMaskGenerator::New(); + imgMask1->SetInputImage(m_US4DCroppedImage); + imgMask1->SetImageMask(m_US4DCroppedBinMask); + + auto statisticsContainer = ComputeStatisticsNew(m_US4DCroppedImage, imgMask1.GetPointer(), nullptr, 1); + auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); + + VerifyStatistics(statisticsObjectTimestep1, + expected_N, + expected_mean, + expected_MPP, + expected_skewness, + expected_kurtosis, + expected_variance, + expected_standarddev, + expected_min, + expected_max, + expected_RMS, + expected_minIndex, + expected_maxIndex); } - -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylAxialPlanarFigureMaskStatistics_time1() +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) +void mitkImageStatisticsCalculatorTestSuite::TestUS4DCroppedMultilabelMaskTimeStep1() { - MITK_INFO << std::endl << "Test US4D axial pf timeStep1:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - std::string US4DAxialPlanarFigureFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4DAxialPlanarFigure.pf"); - m_US4DPlanarFigureAxial = mitk::IOUtil::Load(US4DAxialPlanarFigureFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DPlanarFigureAxial.IsNotNull(), "Loaded US4D axial planarFigure"); - - double expected_entropy = 6.218151288002292; - double expected_kurtosis = 1.7322676370242023; - double expected_MPP = 121.11663807890223; - double expected_max = 199; - double expected_mean = 121.11663807890223; - double expected_median = 120.14999771118164; - double expected_min = 9; - unsigned long expected_N = 2332; - double expected_RMS = 134.41895158590751; - double expected_skewness = -0.1454808104597369; - double expected_standarddev = 58.30278317472294; - double expected_UPP = 0.021354765820606133; - double expected_uniformity = 0.021354765820606133; - double expected_variance = 3399.214525918756; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 129; - expected_minIndex[1] = 131; - expected_minIndex[2] = 19; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 126; - expected_maxIndex[1] = 137; - expected_maxIndex[2] = 19; - - mitk::PlanarFigureMaskGenerator::Pointer pfMaskGen = mitk::PlanarFigureMaskGenerator::New(); - pfMaskGen->SetInputImage(m_US4DImage); - pfMaskGen->SetPlanarFigure(m_US4DPlanarFigureAxial); - - auto statisticsContainer = ComputeStatisticsNew(m_US4DImage, pfMaskGen.GetPointer()); - auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); - - VerifyStatistics(statisticsObjectTimestep1, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + MITK_INFO << std::endl << "Test US4D cropped with mulitlabel mask timestep 1:-----------------------------------------------------------------------------------"; + + std::string US4DCroppedFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D_cropped.nrrd"); + m_US4DCroppedImage = mitk::IOUtil::Load(US4DCroppedFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading US4D_cropped", m_US4DCroppedImage.IsNotNull()); + + std::string US4DCroppedMultilabelMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D_croppedMultilabelMask.nrrd"); + m_US4DCroppedMultilabelMask = mitk::IOUtil::Load(US4DCroppedMultilabelMaskFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading US4D multilabel mask", m_US4DCroppedMultilabelMask.IsNotNull()); + + double expected_kurtosis = 1.0432484564918287; + double expected_MPP = 159.75; + double expected_max = 199; + double expected_mean = 159.75; + double expected_min = 120; + unsigned long expected_N = 4; + double expected_RMS = 163.74446555532802; + double expected_skewness = -0.004329226115093; + double expected_standarddev = 35.947009611371016; + double expected_variance = 1292.187500000000227; + vnl_vector expected_minIndex; + expected_minIndex.set_size(3); + expected_minIndex[0] = 0; + expected_minIndex[1] = 0; + expected_minIndex[2] = 2; + + vnl_vector expected_maxIndex; + expected_maxIndex.set_size(3); + expected_maxIndex[0] = 0; + expected_maxIndex[1] = 0; + expected_maxIndex[2] = 1; + + mitk::ImageMaskGenerator::Pointer imgMask1 = mitk::ImageMaskGenerator::New(); + imgMask1->SetInputImage(m_US4DCroppedImage); + imgMask1->SetImageMask(m_US4DCroppedMultilabelMask); + + auto statisticsContainer = ComputeStatisticsNew(m_US4DCroppedImage, imgMask1.GetPointer(), nullptr, 1); + auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); + + VerifyStatistics(statisticsObjectTimestep1, + expected_N, + expected_mean, + expected_MPP, + expected_skewness, + expected_kurtosis, + expected_variance, + expected_standarddev, + expected_min, + expected_max, + expected_RMS, + expected_minIndex, + expected_maxIndex); } - -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylSagittalPlanarFigureMaskStatistics_time1() +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) +void mitkImageStatisticsCalculatorTestSuite::TestUS4DCroppedPlanarFigureTimeStep1() { - MITK_INFO << std::endl << "Test US4D sagittal pf timeStep1:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - std::string US4DSagittalPlanarFigureFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4DSagittalPlanarFigure.pf"); - m_US4DPlanarFigureSagittal = mitk::IOUtil::Load(US4DSagittalPlanarFigureFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DPlanarFigureSagittal.IsNotNull(), "Loaded US4D sagittal planarFigure"); - - double expected_entropy = 5.2003987046387508; - double expected_kurtosis = 2.7574491062430142; - double expected_MPP = 26.212534059945504; - double expected_max = 59; - double expected_mean = 26.176870748299319; - double expected_median = 26.254999160766602; - double expected_min = 0; - unsigned long expected_N = 735; - double expected_RMS = 28.084905283121476; - double expected_skewness = 0.18245181360752327; - double expected_standarddev = 10.175133541567705; - double expected_UPP = 0.032921467906890628; - double expected_uniformity = 0.032921467906890628; - double expected_variance = 103.53334258873615; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 147; - expected_minIndex[1] = 94; - expected_minIndex[2] = 21; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 147; - expected_maxIndex[1] = 77; - expected_maxIndex[2] = 24; - - mitk::PlanarFigureMaskGenerator::Pointer pfMaskGen = mitk::PlanarFigureMaskGenerator::New(); - pfMaskGen->SetInputImage(m_US4DImage); - pfMaskGen->SetPlanarFigure(m_US4DPlanarFigureSagittal); - - auto statisticsContainer = ComputeStatisticsNew(m_US4DImage, pfMaskGen.GetPointer()); - auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); - - VerifyStatistics(statisticsObjectTimestep1, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); + MITK_INFO << std::endl << "Test US4D cropped planar figure timestep 1:-----------------------------------------------------------------------------------"; + + std::string US4DCroppedFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D_cropped.nrrd"); + m_US4DCroppedImage = mitk::IOUtil::Load(US4DCroppedFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading US4D_cropped", m_US4DCroppedImage.IsNotNull()); + + std::string US4DCroppedPlanarFigureFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D_croppedPF.pf"); + m_US4DCroppedPlanarFigure = mitk::IOUtil::Load(US4DCroppedPlanarFigureFile); + CPPUNIT_ASSERT_MESSAGE("Failed loading US4D planar figure", m_US4DCroppedPlanarFigure.IsNotNull()); + + double expected_kurtosis = 1; + double expected_MPP = 172.5; + double expected_max = 197; + double expected_mean = 172.5; + double expected_min = 148; + unsigned long expected_N = 2; + double expected_RMS = 174.23116827938679; + double expected_skewness = 0; + double expected_standarddev = 24.5; + double expected_variance = 600.25; + vnl_vector expected_minIndex; + expected_minIndex.set_size(3); + expected_minIndex[0] = 2; + expected_minIndex[1] = 2; + expected_minIndex[2] = 2; + + vnl_vector expected_maxIndex; + expected_maxIndex.set_size(3); + expected_maxIndex[0] = 2; + expected_maxIndex[1] = 2; + expected_maxIndex[2] = 1; + + mitk::PlanarFigureMaskGenerator::Pointer pfMaskGen = mitk::PlanarFigureMaskGenerator::New(); + pfMaskGen->SetInputImage(m_US4DCroppedImage); + pfMaskGen->SetPlanarFigure(m_US4DCroppedPlanarFigure); + + auto statisticsContainer = ComputeStatisticsNew(m_US4DCroppedImage, pfMaskGen.GetPointer()); + auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); + + VerifyStatistics(statisticsObjectTimestep1, + expected_N, + expected_mean, + expected_MPP, + expected_skewness, + expected_kurtosis, + expected_variance, + expected_standarddev, + expected_min, + expected_max, + expected_RMS, + expected_minIndex, + expected_maxIndex); } - -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylCoronalPlanarFigureMaskStatistics_time1() +const mitk::ImageStatisticsContainer::Pointer mitkImageStatisticsCalculatorTestSuite::ComputeStatistics(mitk::Image::ConstPointer image, mitk::PlanarFigure::Pointer polygon) { - MITK_INFO << std::endl << "Test US4D coronal pf timeStep1:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - std::string US4DCoronalPlanarFigureFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4DCoronalPlanarFigure.pf"); - m_US4DPlanarFigureCoronal = mitk::IOUtil::Load(US4DCoronalPlanarFigureFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DPlanarFigureCoronal.IsNotNull(), "Loaded US4D coronal planarFigure"); - - double expected_entropy = 5.8892941136639161; - double expected_kurtosis = 4.6434920707409564; - double expected_MPP = 55.486426346239433; - double expected_max = 199; - double expected_mean = 55.118479221927501; - double expected_median = 36.815000534057617; - double expected_min = 0; - unsigned long expected_N = 2262; - double expected_RMS = 71.98149752438627; - double expected_skewness = 1.4988288344523237; - double expected_standarddev = 46.29567187238105; - double expected_UPP = 0.023286748110675673; - double expected_uniformity = 0.023286748110675673; - double expected_variance = 2143.2892341151742; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 214; - expected_minIndex[1] = 169; - expected_minIndex[2] = 10; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 99; - expected_maxIndex[1] = 169; - expected_maxIndex[2] = 17; - - mitk::PlanarFigureMaskGenerator::Pointer pfMaskGen = mitk::PlanarFigureMaskGenerator::New(); - pfMaskGen->SetInputImage(m_US4DImage); - pfMaskGen->SetPlanarFigure(m_US4DPlanarFigureCoronal); - - auto statisticsContainer = ComputeStatisticsNew(m_US4DImage, pfMaskGen.GetPointer()); - auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); - - VerifyStatistics(statisticsObjectTimestep1, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); -} + mitk::ImageStatisticsCalculator::Pointer statisticsCalculator = mitk::ImageStatisticsCalculator::New(); + statisticsCalculator->SetInputImage(image); + statisticsCalculator->SetNBinsForHistogramStatistics(10); -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylImageMaskStatistics_time1_label_1() -{ - MITK_INFO << std::endl << "Test US4D image mask time 1 label 1:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - std::string US4DImageMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D-labels.nrrd"); - m_US4DImageMask = mitk::IOUtil::Load(US4DImageMaskFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImageMask.IsNotNull(), "Loaded US4D image mask"); - - double expected_entropy = 5.0082903903398677; - double expected_kurtosis = 3.6266994778237809; - double expected_MPP = 169.58938547486034; - double expected_max = 199; - double expected_mean = 169.58938547486034; - double expected_median = 187.44000244140625; - double expected_min = 63; - unsigned long expected_N = 716; - double expected_RMS = 173.09843164831432; - double expected_skewness = -1.2248969838579555; - double expected_standarddev = 34.677188083311712; - double expected_UPP = 0.076601073624418703; - double expected_uniformity = 0.076601073624418703; - double expected_variance = 1202.5073733653758; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 82; - expected_minIndex[1] = 158; - expected_minIndex[2] = 19; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 126; - expected_maxIndex[1] = 140; - expected_maxIndex[2] = 19; - - mitk::ImageMaskGenerator::Pointer imgMask1 = mitk::ImageMaskGenerator::New(); - imgMask1->SetInputImage(m_US4DImage); - imgMask1->SetImageMask(m_US4DImageMask); - - auto statisticsContainer = ComputeStatisticsNew(m_US4DImage, imgMask1.GetPointer(), nullptr, 1); - auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); - - VerifyStatistics(statisticsObjectTimestep1, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); -} + mitk::PlanarFigureMaskGenerator::Pointer planFigMaskGen = mitk::PlanarFigureMaskGenerator::New(); + planFigMaskGen->SetInputImage(image); + planFigMaskGen->SetPlanarFigure(polygon); + statisticsCalculator->SetMask(planFigMaskGen.GetPointer()); -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylImageMaskStatistics_time2_label_1() -{ - MITK_INFO << std::endl << "Test US4D image mask time 2 label 1:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - std::string US4DImageMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D-labels.nrrd"); - m_US4DImageMask = mitk::IOUtil::Load(US4DImageMaskFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImageMask.IsNotNull(), "Loaded US4D image mask"); - - double expected_entropy = 5.1857604214916506; - double expected_kurtosis = 3.0692303858330683; - double expected_MPP = 167.97194163860831; - double expected_max = 199; - double expected_mean = 167.97194163860831; - double expected_median = 184.39499664306641; - double expected_min = 72; - unsigned long expected_N = 891; - double expected_RMS = 171.67986611998634; - double expected_skewness = -1.1221651136259736; - double expected_standarddev = 35.488071983870803; - double expected_UPP = 0.063124070232188439; - double expected_uniformity = 0.063124070232188439; - double expected_variance = 1259.4032531323958; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 103; - expected_minIndex[1] = 212; - expected_minIndex[2] = 19; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 102; - expected_maxIndex[1] = 168; - expected_maxIndex[2] = 19; - - mitk::ImageMaskGenerator::Pointer imgMask1 = mitk::ImageMaskGenerator::New(); - imgMask1->SetInputImage(m_US4DImage); - imgMask1->SetImageMask(m_US4DImageMask); - - auto statisticsContainer = ComputeStatisticsNew(m_US4DImage, imgMask1.GetPointer(), nullptr, 1); - auto statisticsObjectTimestep2 = statisticsContainer->GetStatisticsForTimeStep(2); - - VerifyStatistics(statisticsObjectTimestep2, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); -} - - -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylImageMaskStatistics_time1_label_2() -{ - MITK_INFO << std::endl << "Test US4D image mask time 1 label 2:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - std::string US4DImageMaskFile = this->GetTestDataFilePath("ImageStatisticsTestData/US4D-labels.nrrd"); - m_US4DImageMask = mitk::IOUtil::Load(US4DImageMaskFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImageMask.IsNotNull(), "Loaded US4D image mask"); - - double expected_entropy = 5.0822234230119001; - double expected_kurtosis = 2.4346603343623747; - double expected_MPP = 20.733626373626375; - double expected_max = 46; - double expected_mean = 20.624836029733274; - double expected_median = 20.010000228881836; - double expected_min = 0; - unsigned long expected_N = 2287; - double expected_RMS = 22.508347574573804; - double expected_skewness = 0.13837218490626488; - double expected_standarddev = 9.0134260569684965; - double expected_UPP = 0.034783970308787; - double expected_uniformity = 0.034783970308787; - double expected_variance = 81.241849284438644; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 178; - expected_minIndex[1] = 76; - expected_minIndex[2] = 19; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 198; - expected_maxIndex[1] = 90; - expected_maxIndex[2] = 19; - - mitk::ImageMaskGenerator::Pointer imgMask1 = mitk::ImageMaskGenerator::New(); - imgMask1->SetInputImage(m_US4DImage); - imgMask1->SetImageMask(m_US4DImageMask); - - auto statisticsContainer = ComputeStatisticsNew(m_US4DImage, imgMask1.GetPointer(), nullptr, 2); - auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); - - VerifyStatistics(statisticsObjectTimestep1, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); -} - - -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylIgnorePixelValueMaskStatistics_time1() -{ - MITK_INFO << std::endl << "Test US4D ignore zero pixels:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - double expected_entropy = 5.8609813848087962; - double expected_kurtosis = 4.7556214582883651; - double expected_MPP = 53.395358640738536; - double expected_max = 199; - double expected_mean = 53.395358640738536; - double expected_median = 35.649999618530273; - double expected_min = 1; - unsigned long expected_N = 2284417; - double expected_RMS = 72.382339046507084; - double expected_skewness = 1.588289859859108; - double expected_standarddev = 48.868585834566694; - double expected_UPP = 0.023927063695115193; - double expected_uniformity = 0.023927063695115193; - double expected_variance = 2388.1386814704128; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 187; - expected_minIndex[1] = 19; - expected_minIndex[2] = 0; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 268; - expected_maxIndex[1] = 101; - expected_maxIndex[2] = 0; - - mitk::IgnorePixelMaskGenerator::Pointer ignPixelValMask = mitk::IgnorePixelMaskGenerator::New(); - ignPixelValMask->SetInputImage(m_US4DImage); - ignPixelValMask->SetIgnoredPixelValue(0); - ignPixelValMask->SetTimeStep(1); - - auto statisticsContainer = ComputeStatisticsNew(m_US4DImage, ignPixelValMask.GetPointer()); - auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); - - VerifyStatistics(statisticsObjectTimestep1, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); -} - - -void mitkImageStatisticsCalculatorTestSuite::TestUS4DCylSecondaryMaskStatistics_time1() -{ - MITK_INFO << std::endl << "Test US4d ignore zero pixels AND Image mask 2:-----------------------------------------------------------------------------------"; - - std::string US4DFile = this->GetTestDataFilePath("US4DCyl.nrrd"); - m_US4DImage = mitk::IOUtil::Load(US4DFile); - MITK_TEST_CONDITION_REQUIRED(m_US4DImage.IsNotNull(), "Loaded US4D"); - - std::string US4DImageMaskFile2 = this->GetTestDataFilePath("ImageStatisticsTestData/US4D-labels2.nrrd"); - m_US4DImageMask2 = mitk::IOUtil::Load(US4DImageMaskFile2); - MITK_TEST_CONDITION_REQUIRED(m_US4DImageMask2.IsNotNull(), "Loaded US4D image secondary mask"); - - double expected_entropy = 4.9955858614274558; - double expected_kurtosis = 17.471042803365179; - double expected_MPP = 32.791403286978507; - double expected_max = 199; - double expected_mean = 32.791403286978507; - double expected_median = 25.75; - double expected_min = 1; - unsigned long expected_N = 17402; - double expected_RMS = 42.776697859745241; - double expected_skewness = 3.3991813038552596; - double expected_standarddev = 27.469433016621732; - double expected_UPP = 0.043040554251756687; - double expected_uniformity = 0.043040554251756687; - double expected_variance = 754.56975025466807; - vnl_vector expected_minIndex; - expected_minIndex.set_size(3); - expected_minIndex[0] = 177; - expected_minIndex[1] = 27; - expected_minIndex[2] = 36; - - vnl_vector expected_maxIndex; - expected_maxIndex.set_size(3); - expected_maxIndex[0] = 109; - expected_maxIndex[1] = 116; - expected_maxIndex[2] = 36; - - mitk::IgnorePixelMaskGenerator::Pointer ignPixelValMask = mitk::IgnorePixelMaskGenerator::New(); - ignPixelValMask->SetInputImage(m_US4DImage); - ignPixelValMask->SetIgnoredPixelValue(0); - - mitk::ImageMaskGenerator::Pointer imgMaskGen2 = mitk::ImageMaskGenerator::New(); - imgMaskGen2->SetImageMask(m_US4DImageMask2); - imgMaskGen2->SetInputImage(m_US4DImage); - - auto statisticsContainer = - ComputeStatisticsNew(m_US4DImage, imgMaskGen2.GetPointer(), ignPixelValMask.GetPointer()); - auto statisticsObjectTimestep1 = statisticsContainer->GetStatisticsForTimeStep(1); - - VerifyStatistics(statisticsObjectTimestep1, - expected_N, - expected_mean, - expected_MPP, - expected_median, - expected_skewness, - expected_kurtosis, - expected_uniformity, - expected_UPP, - expected_variance, - expected_standarddev, - expected_min, - expected_max, - expected_RMS, - expected_entropy, - expected_minIndex, - expected_maxIndex); -} - - -const mitk::ImageStatisticsContainer::Pointer mitkImageStatisticsCalculatorTestSuite::ComputeStatistics( mitk::Image::ConstPointer image, mitk::PlanarFigure::Pointer polygon ) -{ - mitk::ImageStatisticsCalculator::Pointer statisticsCalculator = mitk::ImageStatisticsCalculator::New(); - statisticsCalculator->SetInputImage( image ); - - statisticsCalculator->SetNBinsForHistogramStatistics(10); - - mitk::PlanarFigureMaskGenerator::Pointer planFigMaskGen = mitk::PlanarFigureMaskGenerator::New(); - planFigMaskGen->SetInputImage(image); - planFigMaskGen->SetPlanarFigure(polygon); - - statisticsCalculator->SetMask(planFigMaskGen.GetPointer()); - - try - { - return statisticsCalculator->GetStatistics(); - } - catch( ... ) - { - return nullptr; - } + try + { + return statisticsCalculator->GetStatistics(); + } + catch (...) + { + return nullptr; + } } const mitk::ImageStatisticsContainer::Pointer -mitkImageStatisticsCalculatorTestSuite::ComputeStatistics(mitk::Image::ConstPointer image, mitk::Image::Pointer image_mask ) +mitkImageStatisticsCalculatorTestSuite::ComputeStatistics(mitk::Image::ConstPointer image, mitk::Image::Pointer image_mask) { - mitk::ImageStatisticsCalculator::Pointer statisticsCalculator = mitk::ImageStatisticsCalculator::New(); - statisticsCalculator->SetInputImage(image); + mitk::ImageStatisticsCalculator::Pointer statisticsCalculator = mitk::ImageStatisticsCalculator::New(); + statisticsCalculator->SetInputImage(image); - statisticsCalculator->SetNBinsForHistogramStatistics(10); + statisticsCalculator->SetNBinsForHistogramStatistics(10); - mitk::ImageMaskGenerator::Pointer imgMaskGen = mitk::ImageMaskGenerator::New(); - imgMaskGen->SetImageMask(image_mask); - statisticsCalculator->SetMask(imgMaskGen.GetPointer()); + mitk::ImageMaskGenerator::Pointer imgMaskGen = mitk::ImageMaskGenerator::New(); + imgMaskGen->SetImageMask(image_mask); + statisticsCalculator->SetMask(imgMaskGen.GetPointer()); - return statisticsCalculator->GetStatistics(); + return statisticsCalculator->GetStatistics(); } const mitk::ImageStatisticsContainer::Pointer mitkImageStatisticsCalculatorTestSuite::ComputeStatisticsNew(mitk::Image::ConstPointer image, - mitk::MaskGenerator::Pointer maskGen, - mitk::MaskGenerator::Pointer secondardMaskGen, - unsigned short label) + mitk::MaskGenerator::Pointer maskGen, + mitk::MaskGenerator::Pointer secondardMaskGen, + unsigned short label) { - mitk::ImageStatisticsCalculator::Pointer imgStatCalc = mitk::ImageStatisticsCalculator::New(); - imgStatCalc->SetInputImage(image); - - if (maskGen.IsNotNull()) - { - imgStatCalc->SetMask(maskGen.GetPointer()); - if (secondardMaskGen.IsNotNull()) - { - imgStatCalc->SetSecondaryMask(secondardMaskGen.GetPointer()); - } - } - - return imgStatCalc->GetStatistics(label); + mitk::ImageStatisticsCalculator::Pointer imgStatCalc = mitk::ImageStatisticsCalculator::New(); + imgStatCalc->SetInputImage(image); + + if (maskGen.IsNotNull()) + { + imgStatCalc->SetMask(maskGen.GetPointer()); + if (secondardMaskGen.IsNotNull()) + { + imgStatCalc->SetSecondaryMask(secondardMaskGen.GetPointer()); + } + } + + return imgStatCalc->GetStatistics(label); } void mitkImageStatisticsCalculatorTestSuite::VerifyStatistics(mitk::ImageStatisticsContainer::StatisticsObject stats, - double testMean, double testSD, double testMedian) + double testMean, double testSD, double testMedian) { - auto mean = stats.GetValueConverted(mitk::ImageStatisticsConstants::MEAN()); - int tmpMean = mean * 100; - double calculatedMean = tmpMean / 100.0; - MITK_TEST_CONDITION( calculatedMean == testMean, - "Calculated mean grayvalue '" << calculatedMean << - "' is equal to the desired value '" << testMean << "'" ); - - auto standardDeviation = stats.GetValueConverted(mitk::ImageStatisticsConstants::STANDARDDEVIATION()); - int tmpSD = standardDeviation * 100; - double calculatedSD = tmpSD / 100.0; - MITK_TEST_CONDITION( calculatedSD == testSD, - "Calculated grayvalue sd '" << calculatedSD << - "' is equal to the desired value '" << testSD <<"'" ); - - auto median = stats.GetValueConverted(mitk::ImageStatisticsConstants::MEDIAN()); - int tmpMedian = median * 100; - double calculatedMedian = tmpMedian / 100.0; - MITK_TEST_CONDITION( testMedian == calculatedMedian, - "Calculated median grayvalue '" << calculatedMedian << - "' is equal to the desired value '" << testMedian << "'"); + auto mean = stats.GetValueConverted(mitk::ImageStatisticsConstants::MEAN()); + int tmpMean = mean * 100; + double calculatedMean = tmpMean / 100.0; + CPPUNIT_ASSERT_MESSAGE("Calculated mean grayvalue is not equal to the desired value.", calculatedMean == testMean); + + auto standardDeviation = stats.GetValueConverted(mitk::ImageStatisticsConstants::STANDARDDEVIATION()); + int tmpSD = standardDeviation * 100; + double calculatedSD = tmpSD / 100.0; + CPPUNIT_ASSERT_MESSAGE("Calculated grayvalue sd is not equal to the desired value.", calculatedSD == testSD); + + auto median = stats.GetValueConverted(mitk::ImageStatisticsConstants::MEDIAN()); + int tmpMedian = median * 100; + double calculatedMedian = tmpMedian / 100.0; + CPPUNIT_ASSERT_MESSAGE("Calculated median grayvalue is not equal to the desired value.", testMedian == calculatedMedian); } +// T26098 histogram statistics need to be tested (median, uniformity, UPP, entropy) void mitkImageStatisticsCalculatorTestSuite::VerifyStatistics(mitk::ImageStatisticsContainer::StatisticsObject stats, - unsigned long N, - double mean, - double MPP, - double median, - double skewness, - double kurtosis, - double uniformity, - double UPP, - double variance, - double stdev, - double min, - double max, - double RMS, - double entropy, - vnl_vector minIndex, - vnl_vector maxIndex) -{ - auto numberOfVoxelsObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::NUMBEROFVOXELS()); - auto meanObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MEAN()); - auto mppObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MPP()); - auto medianObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MEDIAN()); - auto skewnessObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::SKEWNESS()); - auto kurtosisObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::KURTOSIS()); - auto uniformityObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::UNIFORMITY()); - auto uppObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::UPP()); - auto varianceObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::VARIANCE()); - auto standardDeviationObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::STANDARDDEVIATION()); - auto minObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MINIMUM()); - auto maxObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MAXIMUM()); - auto rmsObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::RMS()); - auto entropyObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::ENTROPY()); - auto minIndexObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MINIMUMPOSITION()); - auto maxIndexObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MAXIMUMPOSITION()); - - MITK_TEST_CONDITION(numberOfVoxelsObject - N == 0, "calculated N: " << numberOfVoxelsObject << " expected N: " << N); - MITK_TEST_CONDITION(std::abs(meanObject - mean) < mitk::eps, "calculated mean: " << meanObject << " expected mean: " << mean); - // in one test case MPP is None because the roi has no positive pixels - if (!std::isnan(mppObject)) - { - MITK_TEST_CONDITION(std::abs(mppObject - MPP) < mitk::eps, "calculated MPP: " << mppObject << " expected MPP: " << MPP); - } - MITK_TEST_CONDITION(std::abs(medianObject - median) < mitk::eps, "calculated median: " << medianObject << " expected median: " << median); - MITK_TEST_CONDITION(std::abs(skewnessObject - skewness) < mitk::eps, "calculated skewness: " << skewnessObject << " expected skewness: " << skewness); - MITK_TEST_CONDITION(std::abs(kurtosisObject - kurtosis) < mitk::eps, "calculated kurtosis: " << kurtosisObject << " expected kurtosis: " << kurtosis); - MITK_TEST_CONDITION(std::abs(uniformityObject - uniformity) < mitk::eps, "calculated uniformity: " << uniformityObject << " expected uniformity: " << uniformity); - MITK_TEST_CONDITION(std::abs(uppObject - UPP) < mitk::eps, "calculated UPP: " << uppObject << " expected UPP: " << UPP); - MITK_TEST_CONDITION(std::abs(varianceObject - variance) < mitk::eps, "calculated variance: " << varianceObject << " expected variance: " << variance); - MITK_TEST_CONDITION(std::abs(standardDeviationObject - stdev) < mitk::eps, "calculated stdev: " << standardDeviationObject << " expected stdev: " << stdev); - MITK_TEST_CONDITION(std::abs(minObject - min) < mitk::eps, "calculated min: " << minObject << " expected min: " << min); - MITK_TEST_CONDITION(std::abs(maxObject - max) < mitk::eps, "calculated max: " << maxObject << " expected max: " << max); - MITK_TEST_CONDITION(std::abs(rmsObject - RMS) < mitk::eps, "calculated RMS: " << rmsObject << " expected RMS: " << RMS); - MITK_TEST_CONDITION(std::abs(entropyObject - entropy) < mitk::eps, "calculated entropy: " << entropyObject << " expected entropy: " << entropy); - for (unsigned int i = 0; i < minIndex.size(); ++i) - { - MITK_TEST_CONDITION(std::abs(minIndexObject[i] - minIndex[i]) < mitk::eps, "minIndex [" << i << "] = " << minIndexObject[i] << " expected: " << minIndex[i]); - } - for (unsigned int i = 0; i < maxIndex.size(); ++i) - { - MITK_TEST_CONDITION(std::abs(maxIndexObject[i] - maxIndex[i]) < mitk::eps, "maxIndex [" << i << "] = " << maxIndexObject[i] << " expected: " << maxIndex[i]); - } -} - -void mitkImageStatisticsCalculatorTestSuite::TestUninitializedImage() + unsigned long N, + double mean, + double MPP, + double skewness, + double kurtosis, + double variance, + double stdev, + double min, + double max, + double RMS, + vnl_vector minIndex, + vnl_vector maxIndex) { - /***************************** - * loading uninitialized image to datastorage - ******************************/ - MITK_INFO << std::endl << "Test uninitialized image: -----------------------------------------------------------------------------------"; - MITK_TEST_FOR_EXCEPTION_BEGIN(mitk::Exception) - mitk::Image::Pointer image = mitk::Image::New(); - mitk::DataNode::Pointer node = mitk::DataNode::New(); - node->SetData(image); - - mitk::ImageStatisticsCalculator::Pointer is = mitk::ImageStatisticsCalculator::New(); - is->GetStatistics(); - MITK_TEST_FOR_EXCEPTION_END(mitk::Exception) + auto numberOfVoxelsObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::NUMBEROFVOXELS()); + auto meanObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MEAN()); + auto mppObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MPP()); + auto skewnessObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::SKEWNESS()); + auto kurtosisObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::KURTOSIS()); + auto varianceObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::VARIANCE()); + auto standardDeviationObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::STANDARDDEVIATION()); + auto minObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MINIMUM()); + auto maxObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MAXIMUM()); + auto rmsObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::RMS()); + auto minIndexObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MINIMUMPOSITION()); + auto maxIndexObject = stats.GetValueConverted(mitk::ImageStatisticsConstants::MAXIMUMPOSITION()); + + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", numberOfVoxelsObject - N == 0); + MITK_INFO << "Difference in mean value: " << std::abs(meanObject - mean); + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(meanObject - mean) < mitk::eps); + // in three test cases MPP is None because the roi has no positive pixels + if (!std::isnan(mppObject)) + { + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(mppObject - MPP) < mitk::eps); + } + MITK_INFO << "Difference in skewness value: " << std::abs(skewnessObject - skewness); + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(skewnessObject - skewness) < mitk::eps); + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(kurtosisObject - kurtosis) < mitk::eps); + MITK_INFO << "Difference in variance value: " << std::abs(varianceObject - variance); + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(varianceObject - variance) < mitk::eps); + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(standardDeviationObject - stdev) < mitk::eps); + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(minObject - min) < mitk::eps); + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(maxObject - max) < mitk::eps); + MITK_INFO << "Difference in RMS value: " << std::abs(rmsObject - RMS); + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(rmsObject - RMS) < mitk::eps); + for (unsigned int i = 0; i < minIndex.size(); ++i) + { + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(minIndexObject[i] - minIndex[i]) < mitk::eps); + } + for (unsigned int i = 0; i < maxIndex.size(); ++i) + { + CPPUNIT_ASSERT_MESSAGE("Calculated value does not fit expected value", std::abs(maxIndexObject[i] - maxIndex[i]) < mitk::eps); + } } - MITK_TEST_SUITE_REGISTRATION(mitkImageStatisticsCalculator) diff --git a/Modules/QtWidgetsExt/include/QmitkPlotWidget.h b/Modules/QtWidgetsExt/include/QmitkPlotWidget.h index 72efdc6ab0..4ed3cc5803 100644 --- a/Modules/QtWidgetsExt/include/QmitkPlotWidget.h +++ b/Modules/QtWidgetsExt/include/QmitkPlotWidget.h @@ -1,301 +1,302 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _QmitkPlotWidget_H_ #define _QmitkPlotWidget_H_ #include "MitkQtWidgetsExtExports.h" #include "mitkCommon.h" #include #include #include #include #include #include #include #include /** * Provides a convenient interface for plotting curves using qwt. * Designed for qwt version 5.2.1. * Can be used with a QmitkPlotDialog, which provides a "Close" button. * @see QmitkPlotDialog * * To plot data do the following: * 1. Create two QmitkPlotWidget::DataVector Objects and fill them * with corresponding x/y values. DataVectors are simple stl-vectors * of type std::vector. Please note that the xValues * vector and the yValues vector MUST have the same size. * 2. Instantiate the widget for example like that: * QmitkPlotWidget* widget = new QmitkPlotWidget( this, "widget" ); * widget->SetAxisTitle( QwtPlot::xBottom, "My x asis [mm]" ); * widget->SetAxisTitle( QwtPlot::yLeft, "My y axis [mm]" ); * int curveId = widget->InsertCurve( "My sophisticated data" ); * widget->SetCurveData( curveId, xValues, yValues ); * widget->SetCurvePen( curveId, QPen( red ) ); * widget->SetCurveTitle( curveId, "My curve description" ); * widget->Replot(); * 3. You can modify the behavior of the plot by directly referencing * the QwtPlot instance using the method GetPlot(). * @see QwtPlot +* @deprecatedSince{2018_04} See mitk::QmitkChartWidget */ -class MITKQTWIDGETSEXT_EXPORT QmitkPlotWidget : public QWidget +DEPRECATED(class MITKQTWIDGETSEXT_EXPORT QmitkPlotWidget : public QWidget { private: Q_OBJECT public: /** * represents the data type used for scalar values stored * in data arrays. This type is provided by qwt and may not * be changed. */ typedef double ScalarType; /** * This type may be used to store a set of scalar values * representing either x or y coordinates of the data * points that should be rendered. */ typedef std::vector DataVector; /** * convenience type used to store pairs representing x/y coordinates * that should be rendered as a curve by the plot widget */ typedef std::vector> XYDataVector; /** * Standard qt constructor */ QmitkPlotWidget(QWidget *parent = nullptr, const char *title = nullptr, const char *name = nullptr, Qt::WindowFlags f = nullptr); /** * Virtual destructor */ ~QmitkPlotWidget() override; /** * Returns the instance of the plot-widget. This may be used * to modify any detail of the appearance of the plot. */ QwtPlot *GetPlot(); /** * Set the title using (formatted) QwtText object */ void SetPlotTitle(const QwtText &qwt_title); /** * Set plain text title, using default formatting */ void SetPlotTitle(const char *title); /** * Inserts a new curve into the plot-window. * @param title the name of the curve * @returns the id of the curve. Use this id to * refer to the curve, if you want to modify or add data. */ unsigned int InsertCurve(const char *title, QColor color = QColor(Qt::black)); /** * Sets the title of the given axis. For the set of available axes * @see QwtPlot::Axis. * @param axis the axis for which the description should be set. * @param title the name of the axis. */ void SetAxisTitle(int axis, const char *title); /** * Sets the data for a previously added curve. Data is provided as two vectors of double. * The first vector represents the x coordinates, the second vector represents the y coordinates. * @param curveId the id of the curve for which data should be added. * @param xValues the x coordinates of the points that define the curve * @param yValues the y coordinates of the points that define the curve * @returns whether data was added successfully or not */ bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues); /** * @brief Sets the data with errors for a previously added curve. * * @param curveId the id of the curve for which data should be added. * @param xValues the x coordinates of the points that define the curve * @param yValues the y coordinates of the points that define the curve * @param yLowerError the magnitude (>0) of the error in the lesser direction of y * @param yUpperError the magnitude (>0) of the error in the larger direction of y * @returns whether data was added successfully or not */ bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues, const DataVector &yLowerError, const DataVector &yUpperError); /** * @brief Sets the data with errors for a previously added curve. * * @param curveId the id of the curve for which data should be added. * @param xValues the x coordinates of the points that define the curve * @param yValues the y coordinates of the points that define the curve * @param xLowerError the magnitude (>0) of the error in the lesser direction of x * @param xUpperError the magnitude (>0) of the error in the larger direction of x * @param yLowerError the magnitude (>0) of the error in the lesser direction of y * @param yUpperError the magnitude (>0) of the error in the larger direction of y * @returns whether data was added successfully or not */ bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues, const DataVector &xLowerError, const DataVector &xUpperError, const DataVector &yLowerError, const DataVector &yUpperError); /** * Sets the data for a previously added curve. Data is provided as a vectors of pairs. * The pairs represent x/y coordinates of the points that define the curve. * @param curveId the id of the curve for which data should be added. * @param data the coordinates of the points that define the curve * @returns whether data was added successfully or not */ bool SetCurveData(unsigned int curveId, const XYDataVector &data); /** * Defines how a curve should be drawn. For drawing a curve, a QPen is used. * @param curveId the id of the curve for which appearance should be changed * @param pen a QPen (@see QPen) defining the line style */ void SetCurvePen(unsigned int curveId, const QPen &pen); /** * Assign a brush, which defines the fill pattern of shapes drawn by a QPainter. * In case of brush.style() != QBrush::NoBrush and * style() != QwtPlotCurve::Sticks * the area between the curve and the baseline will be filled. * In case !brush.color().isValid() the area will be filled by pen.color(). * The fill algorithm simply connects the first and the last curve point to the * baseline. So the curve data has to be sorted (ascending or descending). * @param curveId the id of the curve for which appearance should be changed * @param brush a QBrush (@see QBrush) defining the line style */ void SetCurveBrush(unsigned int curveId, const QBrush &brush); /** * Sets the style how the line is drawn for the curve; like, plain line, * or with the data points marked with a symbol; * @param: style A QwtPlotCurve::CurveStyle */ void SetCurveStyle(unsigned int curveId, const QwtPlotCurve::CurveStyle style); /** * Sets the style data points are drawn for the curve; like, a line, * or dots; * @param: symbol A QwtSymbol */ void SetCurveSymbol(unsigned int curveId, QwtSymbol *symbol); void SetCurveAntialiasingOn(unsigned int curveId); void SetCurveAntialiasingOff(unsigned int curveId); /** * Sets the title of the given curve. The title will be shown in the legend of * the QwtPlot. * @param curveId the id of the curve for which the title should be set * @param title the description of the curve that will be shown in the legend. */ void SetCurveTitle(unsigned int curveId, const char *title); /** * Defines how a curves errors should be drawn. For drawing a QPen is used. * @param curveId the id of the curve for which error appearance should be changed * @param pen a QPen (@see QPen) defining the line style */ void SetErrorPen(unsigned int curveId, const QPen &pen); /** * Defines the style of errors, symbols or as a curve. * @param curveId the id of the curve for which error appearance should be changed * @param drawSmybols true - draw symbols, false - draw curve */ void SetErrorStyleSymbols(unsigned int curveId, bool drawSmybols); /** * Sets the legend of the plot * */ void SetLegend(QwtLegend *legend, QwtPlot::LegendPosition pos = QwtPlot::RightLegend, double ratio = -1); /** * Set a curve's legend attribute * @param curveId the id of the curve * @param attribute the legend attribute to be set */ void SetLegendAttribute(unsigned int curveId, const QwtPlotCurve::LegendAttribute &attribute); /** * Triggers a replot of the curve. Replot should be called once after * setting new data. */ void Replot(); /** * Resets the plot into an empty state */ void Clear(); protected: /** * Converts the given values into a raw double* array. * A new array is allocated via new and must be deleted[] by the caller. */ double *ConvertToRawArray(const DataVector &values); /** * Converts the given values into a raw double* array. * A new array is allocated via new and must be deleted[] by the caller. * @param values the x/y values to convert to an array * @param component defines if the x values (0) or the y values(1) should * be converted. Other values than 0 and 1 will not be accepted. */ double *ConvertToRawArray(const XYDataVector &values, unsigned int component); /** * Adds an error interval curve. * * All errors should be absolutes. The magnitude will be used. * * @param curveId Which curve should the error curve be added to * @param xValues Vector of x values an error bar belongs to * @param values The original data value * @param lessError Error in the negative direction (value - lessError) * @param moreError Error in the positive direction (value + lessError) * @param isXError Should the error bars be drawn horizontally */ bool AddErrorIntervalCurve(unsigned int curveId, const DataVector &lessError, const DataVector &moreError, bool isXError); QwtPlot *m_Plot; std::vector> m_PlotCurveVector; -}; +}); #endif diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkTractometryView.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkTractometryView.cpp index 79889ff504..b39ab96070 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkTractometryView.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkTractometryView.cpp @@ -1,351 +1,351 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include "QmitkTractometryView.h" #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include #include #include #include -#include + const std::string QmitkTractometryView::VIEW_ID = "org.mitk.views.tractometry"; using namespace mitk; QmitkTractometryView::QmitkTractometryView() : QmitkAbstractView() , m_Controls( nullptr ) , m_Visible(false) { } // Destructor QmitkTractometryView::~QmitkTractometryView() { } void QmitkTractometryView::CreateQtPartControl( QWidget *parent ) { // build up qt view, unless already done if ( !m_Controls ) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkTractometryViewControls; m_Controls->setupUi( parent ); connect( m_Controls->m_SamplingPointsBox, SIGNAL(valueChanged(int)), this, SLOT(UpdateGui()) ); connect( m_Controls->m_StDevBox, SIGNAL(stateChanged(int)), this, SLOT(UpdateGui()) ); mitk::TNodePredicateDataType::Pointer imageP = mitk::TNodePredicateDataType::New(); mitk::NodePredicateDimension::Pointer dimP = mitk::NodePredicateDimension::New(3); m_Controls->m_ImageBox->SetDataStorage(this->GetDataStorage()); m_Controls->m_ImageBox->SetPredicate(mitk::NodePredicateAnd::New(imageP, dimP)); + m_Controls->m_ChartWidget->SetTheme(GetColorTheme()); m_Controls->m_ChartWidget->SetXAxisLabel("Tract position"); m_Controls->m_ChartWidget->SetYAxisLabel("Image Value"); } } -void QmitkTractometryView::OnPageSuccessfullyLoaded() +::QmitkChartWidget::ColorTheme QmitkTractometryView::GetColorTheme() { berry::IPreferencesService* prefService = berry::WorkbenchPlugin::GetDefault()->GetPreferencesService(); berry::IPreferences::Pointer m_StylePref = prefService->GetSystemPreferences()->Node(berry::QtPreferences::QT_STYLES_NODE); QString styleName = m_StylePref->Get(berry::QtPreferences::QT_STYLE_NAME, ""); if (styleName == ":/org.blueberry.ui.qt/darkstyle.qss") { - this->m_Controls->m_ChartWidget->SetTheme(QmitkChartWidget::ChartStyle::darkstyle); + return mitk::QmitkChartWidget::ColorTheme::darkstyle; } else { - this->m_Controls->m_ChartWidget->SetTheme(QmitkChartWidget::ChartStyle::lightstyle); + return mitk::QmitkChartWidget::ColorTheme::lightstyle; } } void QmitkTractometryView::SetFocus() { } void QmitkTractometryView::UpdateGui() { berry::IWorkbenchPart::Pointer nullPart; OnSelectionChanged(nullPart, QList(m_CurrentSelection)); } bool QmitkTractometryView::Flip(vtkSmartPointer< vtkPolyData > polydata1, int i, vtkSmartPointer< vtkPolyData > ref_poly) { double d_direct = 0; double d_flipped = 0; vtkCell* cell1 = polydata1->GetCell(0); if (ref_poly!=nullptr) cell1 = ref_poly->GetCell(0); auto numPoints1 = cell1->GetNumberOfPoints(); vtkPoints* points1 = cell1->GetPoints(); std::vector> ref_points; for (int j=0; jGetPoint(j); itk::Point itk_p; itk_p[0] = p1[0]; itk_p[1] = p1[1]; itk_p[2] = p1[2]; ref_points.push_back(itk_p); } vtkCell* cell2 = polydata1->GetCell(i); vtkPoints* points2 = cell2->GetPoints(); for (int j=0; jGetPoint(j); d_direct = (p1[0]-p2[0])*(p1[0]-p2[0]) + (p1[1]-p2[1])*(p1[1]-p2[1]) + (p1[2]-p2[2])*(p1[2]-p2[2]); double* p3 = points2->GetPoint(numPoints1-j-1); d_flipped = (p1[0]-p3[0])*(p1[0]-p3[0]) + (p1[1]-p3[1])*(p1[1]-p3[1]) + (p1[2]-p3[2])*(p1[2]-p3[2]); } if (d_direct>d_flipped) return true; return false; } template void QmitkTractometryView::ImageValuesAlongTract(const mitk::PixelType, mitk::Image::Pointer image, mitk::FiberBundle::Pointer fib, std::vector > &data, std::string& clipboard_string) { unsigned int num_points = m_Controls->m_SamplingPointsBox->value(); mitk::ImagePixelReadAccessor readimage(image, image->GetVolumeData(0)); mitk::FiberBundle::Pointer working_fib = fib->GetDeepCopy(); working_fib->ResampleToNumPoints(num_points); vtkSmartPointer< vtkPolyData > polydata = working_fib->GetFiberPolyData(); std::vector > all_values; std::vector< double > mean_values; for (unsigned int i=0; iGetNumFibers(); ++i) { vtkCell* cell = polydata->GetCell(i); auto numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); std::vector< double > fib_vals; bool flip = false; if (i>0) flip = Flip(polydata, i); else if (m_ReferencePolyData!=nullptr) flip = Flip(polydata, 0, m_ReferencePolyData); for (int j=0; jGetPoint(numPoints - j - 1); else p = points->GetPoint(j); Point3D px; px[0] = p[0]; px[1] = p[1]; px[2] = p[2]; double pixelValue = static_cast(readimage.GetPixelByWorldCoordinates(px)); fib_vals.push_back(pixelValue); mean += pixelValue; if (pixelValuemax) max = pixelValue; mean_values.at(j) += pixelValue; } all_values.push_back(fib_vals); } if (m_ReferencePolyData==nullptr) m_ReferencePolyData = polydata; std::vector< double > std_values1; std::vector< double > std_values2; for (unsigned int i=0; iGetNumFibers(); double stdev = 0; for (unsigned int j=0; j(mean_values.at(i)); clipboard_string += " "; clipboard_string += boost::lexical_cast(stdev); clipboard_string += "\n"; } clipboard_string += "\n"; data.push_back(mean_values); data.push_back(std_values1); data.push_back(std_values2); MITK_INFO << "Min: " << min; MITK_INFO << "Max: " << max; MITK_INFO << "Mean: " << mean/working_fib->GetNumberOfPoints(); } void QmitkTractometryView::Activated() { } void QmitkTractometryView::Deactivated() { } void QmitkTractometryView::Visible() { m_Visible = true; QList selection = GetDataManagerSelection(); berry::IWorkbenchPart::Pointer nullPart; OnSelectionChanged(nullPart, selection); } void QmitkTractometryView::Hidden() { m_Visible = false; } std::string QmitkTractometryView::RGBToHexString(double *rgb) { std::ostringstream os; for (int i = 0; i < 3; ++i) { os << std::setw(2) << std::setfill('0') << std::hex << static_cast(rgb[i] * 255); } return os.str(); } void QmitkTractometryView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*part*/, const QList& nodes) { if (!m_Visible) return; m_CurrentSelection.clear(); if(m_Controls->m_ImageBox->GetSelectedNode().IsNull()) return; std::string clipboardString = ""; m_ReferencePolyData = nullptr; mitk::Image::Pointer image = dynamic_cast(m_Controls->m_ImageBox->GetSelectedNode()->GetData()); vtkSmartPointer lookupTable = vtkSmartPointer::New(); lookupTable->SetTableRange(0.0, 1.0); lookupTable->Build(); int num_tracts = 0; for (auto node: nodes) if ( dynamic_cast(node->GetData()) ) num_tracts++; int c = 1; this->m_Controls->m_ChartWidget->Clear(); for (auto node: nodes) { if ( dynamic_cast(node->GetData()) ) { clipboardString += node->GetName() + "\n"; clipboardString += "mean stdev\n"; mitk::FiberBundle::Pointer fib = dynamic_cast(node->GetData()); m_CurrentSelection.push_back(node); std::vector< std::vector< double > > data; mitkPixelTypeMultiplex4( ImageValuesAlongTract, image->GetPixelType(), image, fib, data, clipboardString ); m_Controls->m_ChartWidget->AddData1D(data.at(0), node->GetName() + " Mean", QmitkChartWidget::ChartType::line); if (m_Controls->m_StDevBox->isChecked()) { this->m_Controls->m_ChartWidget->AddData1D(data.at(1), node->GetName() + " +STDEV", QmitkChartWidget::ChartType::line); this->m_Controls->m_ChartWidget->AddData1D(data.at(2), node->GetName() + " -STDEV", QmitkChartWidget::ChartType::line); } double color[3]; if (num_tracts>1) { float scalar_color = ( (float)c/num_tracts - 1.0/num_tracts )/(1.0-1.0/num_tracts); lookupTable->GetColor(1.0 - scalar_color, color); } else lookupTable->GetColor(0, color); this->m_Controls->m_ChartWidget->SetColor(node->GetName() + " Mean", RGBToHexString(color)); if (m_Controls->m_StDevBox->isChecked()) { color[0] *= 0.5; color[1] *= 0.5; color[2] *= 0.5; this->m_Controls->m_ChartWidget->SetColor(node->GetName() + " +STDEV", RGBToHexString(color)); this->m_Controls->m_ChartWidget->SetColor(node->GetName() + " -STDEV", RGBToHexString(color)); } this->m_Controls->m_ChartWidget->Show(true); this->m_Controls->m_ChartWidget->SetShowDataPoints(false); ++c; } } QApplication::clipboard()->setText(clipboardString.c_str(), QClipboard::Clipboard); } diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkTractometryView.h b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkTractometryView.h index 47fc86c951..3176bddae5 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkTractometryView.h +++ b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkTractometryView.h @@ -1,81 +1,81 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QmitkTractometryView_h #define QmitkTractometryView_h #include #include "ui_QmitkTractometryViewControls.h" #include #include #include #include #include +#include /*! \brief Weight fibers by linearly fitting them to the image data. */ class QmitkTractometryView : public QmitkAbstractView, public mitk::ILifecycleAwarePart { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; QmitkTractometryView(); virtual ~QmitkTractometryView(); virtual void CreateQtPartControl(QWidget *parent) override; template void ImageValuesAlongTract(const mitk::PixelType, mitk::Image::Pointer image, mitk::FiberBundle::Pointer fib, std::vector< std::vector< double > >& data, std::string& clipboard_string); virtual void SetFocus() override; - void OnPageSuccessfullyLoaded(); - virtual void Activated() override; virtual void Deactivated() override; virtual void Visible() override; virtual void Hidden() override; protected slots: void UpdateGui(); protected: /// \brief called by QmitkAbstractView when DataManager's selection has changed virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer part, const QList& nodes) override; + QmitkChartWidget::ColorTheme GetColorTheme(); Ui::QmitkTractometryViewControls* m_Controls; bool Flip(vtkSmartPointer< vtkPolyData > polydata1, int i, vtkSmartPointer ref_poly=nullptr); std::string RGBToHexString(double *rgb); vtkSmartPointer< vtkPolyData > m_ReferencePolyData; QList m_CurrentSelection; bool m_Visible; }; #endif // _QMITKFIBERTRACKINGVIEW_H_INCLUDED