diff --git a/Modules/FiberDissection/MachineLearning/mitkStreamlineFeatureExtractor.cpp b/Modules/FiberDissection/MachineLearning/mitkStreamlineFeatureExtractor.cpp index 43615ae..12b0f79 100644 --- a/Modules/FiberDissection/MachineLearning/mitkStreamlineFeatureExtractor.cpp +++ b/Modules/FiberDissection/MachineLearning/mitkStreamlineFeatureExtractor.cpp @@ -1,999 +1,1103 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center. 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 "mitkStreamlineFeatureExtractor.h" #define _USE_MATH_DEFINES #include #include #include #include namespace mitk{ StreamlineFeatureExtractor::StreamlineFeatureExtractor() : m_NumPoints(40) { } StreamlineFeatureExtractor::~StreamlineFeatureExtractor() { } void StreamlineFeatureExtractor::SetTractogramPrediction(const mitk::FiberBundle::Pointer &TractogramPrediction) { m_TractogramPrediction= TractogramPrediction; } void StreamlineFeatureExtractor::SetTractogramGroundtruth(const mitk::FiberBundle::Pointer &TractogramGroundtruth) { m_TractogramGroundtruth= TractogramGroundtruth; } void StreamlineFeatureExtractor::SetTractogramPlus(const mitk::FiberBundle::Pointer &TractogramPlus) { m_TractogramPlus = TractogramPlus; } void StreamlineFeatureExtractor::SetTractogramMinus(const mitk::FiberBundle::Pointer &TractogramMinus) { m_TractogramMinus = TractogramMinus; } void StreamlineFeatureExtractor::SetTractogramPrototypes(const mitk::FiberBundle::Pointer &TractogramPrototypes, bool standard) { if (standard) { MITK_INFO << "Use Standard Prototypes..."; m_inputPrototypes = mitk::IOUtil::Load("/home/r948e/E132-Projekte/Projects/2022_Peretzke_Interactive_Fiber_Dissection/mitk_diff/prototypes_599671_40.trk"); } else { MITK_INFO << "Use individual Prototypes..."; m_inputPrototypes = TractogramPrototypes; } } void StreamlineFeatureExtractor::SetActiveCycle(int &activeCycle) { m_activeCycle= activeCycle; } void StreamlineFeatureExtractor::SetInitRandom(int &initRandom) { m_initRandom= initRandom; } void StreamlineFeatureExtractor::SetTractogramTest(const mitk::FiberBundle::Pointer &TractogramTest, std::string TractogramTestName) { std::string path = "/home/r948e/E132-Projekte/Projects/2022_Peretzke_Interactive_Fiber_Dissection/mitk_diff/storage/"; path.append(TractogramTestName); m_TractogramTest= TractogramTest; auto s = std::to_string(m_NumPoints); m_DistancesTestName= path.append("_distances" + std::to_string(m_NumPoints) + "_" + std::to_string(m_activeCycle) + ".csv"); } std::vector > StreamlineFeatureExtractor::ResampleFibers(mitk::FiberBundle::Pointer tractogram) { MITK_INFO << "Infunction"; mitk::FiberBundle::Pointer temp_fib = tractogram->GetDeepCopy(); - temp_fib->ResampleToNumPoints(m_NumPoints); +// temp_fib->ResampleToNumPoints(m_NumPoints); MITK_INFO << "Resampling Done"; std::vector< vnl_matrix > out_fib(temp_fib->GetFiberPolyData()->GetNumberOfCells()); for (int i=0; iGetFiberPolyData()->GetNumberOfCells(); i++) { vtkCell* cell = temp_fib->GetFiberPolyData()->GetCell(i); int numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vnl_matrix streamline; streamline.set_size(3, m_NumPoints); streamline.fill(0.0); for (int j=0; jGetPoint(j, cand); vnl_vector_fixed< float, 3 > candV; candV[0]=cand[0]; candV[1]=cand[1]; candV[2]=cand[2]; streamline.set_column(j, candV); } // out_fib.push_back(streamline); out_fib.at(i)=streamline; } // }); return out_fib; } std::vector > StreamlineFeatureExtractor::CalculateDmdf(std::vector > tractogram, std::vector > prototypes) { std::vector< vnl_matrix > dist_vec(tractogram.size());// MITK_INFO << "Start Calculating Dmdf"; cv::parallel_for_(cv::Range(0, tractogram.size()), [&](const cv::Range &range) { for (int i = range.start; i < range.end; i++) // for (unsigned int i=0; i distances; distances.set_size(1, prototypes.size()); distances.fill(0.0); for (unsigned int j=0; j single_distances; single_distances.set_size(1, tractogram.at(0).cols()); single_distances.fill(0.0); vnl_matrix single_distances_flip; single_distances_flip.set_size(1, tractogram.at(0).cols()); single_distances_flip.fill(0.0); for (unsigned int ik=0; ik single_distances.mean()) { distances.put(0,j, single_distances.mean()); } else { distances.put(0,j, single_distances_flip.mean()); } } // dist_vec.push_back(distances); dist_vec.at(i) = distances; } }); MITK_INFO << "Done Calculation"; MITK_INFO << dist_vec.at(0).size(); return dist_vec; } std::vector > StreamlineFeatureExtractor::MergeTractogram(std::vector > prototypes, std::vector > positive_local_prototypes, std::vector > negative_local_prototypes) { unsigned int pos_locals; unsigned int neg_locals; - if (positive_local_prototypes.size() >= 50) - { - pos_locals= 50; - } - else { - pos_locals= positive_local_prototypes.size(); - } +// if (positive_local_prototypes.size() >= 50) +// { +// pos_locals= 50; +// } +// else { +// pos_locals= positive_local_prototypes.size(); +// } - if (pos_locals <= negative_local_prototypes.size()) - { - neg_locals = pos_locals; - } - else { - neg_locals= negative_local_prototypes.size(); - } +// if (pos_locals <= negative_local_prototypes.size()) +// { +// neg_locals = pos_locals; +// } +// else { +// neg_locals= negative_local_prototypes.size(); +// } std::vector< vnl_matrix > merged_prototypes; for (unsigned int k=0; k StreamlineFeatureExtractor::Sort(std::vector sortingVector, int lengths, int start) { std::vector index; std::priority_queue> q; for (unsigned int i = 0; i < sortingVector.size(); ++i) { q.push(std::pair(sortingVector[i], i)); } for (int i = 0; i < lengths; ++i) { int ki = q.top().second; if (i>=start) { index.push_back(ki); } q.pop(); } return index; } std::vector> StreamlineFeatureExtractor::GetData() { MITK_INFO << "Start Function Get Data"; /*Vector which saves Prediction and Fibers to label based on uncertainty*/ std::vector> index_vec; // int labels_arr [m_DistancesPlus.size()+m_DistancesMinus.size()]; cv::Mat data; cv::Mat labels_arr_vec; int size_plus = 0; /*Create Trainingdata: Go through positive and negative Bundle and save distances as cv::Mat and create vector with labels*/ for ( unsigned int i=0; i seeds; for (int cont = 0; cont < labels_arr_vec.rows; cont++) { seeds.push_back(cont); } cv::randShuffle(seeds); cv::Mat labels_shuffled; cv::Mat samples_shuffled; for (int cont = 0; cont < labels_arr_vec.rows; cont++) { labels_shuffled.push_back(labels_arr_vec.row(seeds[cont])); } for (int cont = 0; cont < labels_arr_vec.rows; cont++) { samples_shuffled.push_back(data.row(seeds[cont])); } std::ofstream labelsfile; labelsfile.open("/home/r948e/E132-Projekte/Projects/2022_Peretzke_Interactive_Fiber_Dissection/mitk_diff/storage/Labels_" + std::to_string(m_activeCycle) + ".csv"); labelsfile<< cv::format(labels_shuffled, cv::Formatter::FMT_CSV) << std::endl; labelsfile.close(); std::ofstream featuresfile; featuresfile.open("/home/r948e/E132-Projekte/Projects/2022_Peretzke_Interactive_Fiber_Dissection/mitk_diff/storage/Features_" + std::to_string(m_activeCycle) + ".csv"); featuresfile<< cv::format(samples_shuffled, cv::Formatter::FMT_CSV) << std::endl; featuresfile.close(); /*Create Dataset and initialize Classifier*/ cv::Ptr m_traindata = cv::ml::TrainData::create(samples_shuffled, cv::ml::ROW_SAMPLE, labels_shuffled); - auto statistic_model = cv::ml::RTrees::create(); + statistic_model= cv::ml::RTrees::create(); auto criteria = cv::TermCriteria(); criteria.type = cv::TermCriteria::MAX_ITER; // criteria.epsilon = 1e-8; criteria.maxCount = 400; statistic_model->setMaxDepth(10); //set to three // statistic_model->setMinSampleCount(m_traindata->getNTrainSamples()*0.01); statistic_model->setMinSampleCount(2); statistic_model->setTruncatePrunedTree(false); statistic_model->setUse1SERule(false); statistic_model->setUseSurrogates(false); statistic_model->setTermCriteria(criteria); statistic_model->setCVFolds(1); statistic_model->setPriors(newweight); /*Train Classifier*/ MITK_INFO << "Start Training"; statistic_model->train(m_traindata); - /*Predict on Test Data*/ MITK_INFO << "Predicting"; /*Create Dataset as cv::Mat*/ cv::Mat dataTest; for ( unsigned int i=0; i indexPrediction; std::vector e(m_DistancesTest.size()); std::vector pred(m_DistancesTest.size()); /*For every Sample/Streamline get Prediction and entropy (=based on counts of Random Forest)*/ MITK_INFO << "Predicting on all cores"; #pragma omp parallel for for (unsigned int i=0; ipredict(dataTest.row(i)); pred.at(i)=val; #pragma omp critical if (val==1) { indexPrediction.push_back(i); } cv::Mat vote; statistic_model->getVotes(dataTest.row(i), vote, 0); e.at(i) = ( -(vote.at(1,0)*1.0)/ (vote.at(1,0)+vote.at(1,1)) * log2((vote.at(1,0)*1.0)/ (vote.at(1,0)+vote.at(1,1))) - (vote.at(1,1)*1.0)/ (vote.at(1,0)+vote.at(1,1))* log2((vote.at(1,1)*1.0)/ (vote.at(1,0)+vote.at(1,1)))); if (isnan(e.at(i))) { e.at(i)=0; } } MITK_INFO << "Done"; /*Save entropy values for analysis*/ std::ofstream entropyfile; entropyfile.open("/home/r948e/mycsv/entropydata_" + std::to_string(m_activeCycle) + ".csv"); for (unsigned int i = 0; i < e.size(); i++) { entropyfile << e.at(i) << ' '; } entropyfile.close(); std::ofstream predictionfile; predictionfile.open("/home/r948e/mycsv/predictiondata_" + std::to_string(m_activeCycle) + ".csv"); for (unsigned int i = 0; i < pred.size(); i++) { predictionfile << pred.at(i) << ' '; } predictionfile.close(); MITK_INFO << "--------------"; MITK_INFO << "Prediction vector size:"; MITK_INFO << indexPrediction.size(); MITK_INFO << "Entropy vector size:"; + entropy_vector = e; MITK_INFO << e.size(); MITK_INFO << "--------------"; /*Get index of most unertain data (lengths defines how many data is saved)*/ // int lengths=500; int lengths = std::count_if(e.begin(), e.end(),[&](auto const& val){ return val >= 0.95; }); if (lengths>1500) { lengths=1500; } // else if (lengths>3000) // { // lengths=3000; // } int lengthsCertain = std::count_if(e.begin(), e.end(),[&](auto const& val){ return val < 0.05; }); std::vector indexUnc = Sort(e, lengths, 0); std::vector indexCertain = Sort(e, e.size() , e.size()-lengthsCertain ); - std::vector indexCertainBetween = Sort(e, e.size()-lengthsCertain , lengths); +// std::vector indexCertainBetween = Sort(e, e.size()-lengthsCertain , lengths); MITK_INFO << "Index Certainty Vector size"; MITK_INFO << indexCertain.size(); // for (unsigned int i=indexCertain.size(); i>=0; --i) std::vector indexCertainNeg; std::vector indexCertainPos; for (unsigned int i=0; i=0; --i) - std::vector indexCertainBetweenNeg; - std::vector indexCertainBetweenPos; +// std::vector indexCertainBetweenNeg; +// std::vector indexCertainBetweenPos; - for (unsigned int i=0; i distances_matrix; + +// distances_matrix.set_size(lengths, lengths); +// distances_matrix.fill(0.0); + +// std::vector distances_matrix_mean; +// for (int i=0; i diff = m_DistancesTest.at(indexUnc.at(i)) - m_DistancesTest.at(indexUnc.at(k)); + +// /*Into the eucledean difference matrix, put the distance in Feature Space between every sample pair*/ +// distances_matrix.put(i,k,diff.absolute_value_sum()/m_DistancesTest.at(0).size()); + +// } +// /*For every Sample/Streamline get the mean eucledean distance to all other Samples => one value for every Sample*/ +//// distances_matrix_mean.push_back(distances_matrix.get_row(i).mean()); +//// MITK_INFO << meanval.at(i); + +// } + + + +// /*Index to find values in distancematrix*/ +// std::vector myidx; +// /*Index to find actual streamlines using indexUnc*/ +// std::vector indexUncDist; +// /*Start with the Streamline of the highest entropy, which is in distance_matrix at idx 0*/ +// myidx.push_back(0); +// indexUncDist.push_back(indexUnc.at(myidx.at(0))); + +// /*Vecotr that stores minvalues of current iteration*/ +// vnl_matrix cur_vec; +// cur_vec.set_size(1,lengths); +// cur_vec.fill(0.0); +// for (int i=0; i sum_matrix; +// sum_matrix.set_size(myidx.size(), lengths); +// sum_matrix.fill(0); +// for (unsigned int ii=0; ii> StreamlineFeatureExtractor::GetDistanceData(float &value) +{ + /*Vector which saves Fibers to be labeled based on fft subset uncertainty*/ + std::vector> index_vec; + + /*Get index of most unertain data (lengths defines how many data is saved)*/ +// int lengths=500; + MITK_INFO << entropy_vector.size(); + int lengths = std::count_if(entropy_vector.begin(), entropy_vector.end(),[&](auto const& val){ return val >= value; }); + if (lengths>1500) + { + lengths=1500; + } + MITK_INFO << lengths; + /*Maybe shuffling of length so not the most uncertain values are chosen*/ + std::vector indexUnc = Sort(entropy_vector, lengths, 0); + vnl_matrix distances_matrix; distances_matrix.set_size(lengths, lengths); distances_matrix.fill(0.0); std::vector distances_matrix_mean; for (int i=0; i diff = m_DistancesTest.at(indexUnc.at(i)) - m_DistancesTest.at(indexUnc.at(k)); /*Into the eucledean difference matrix, put the distance in Feature Space between every sample pair*/ distances_matrix.put(i,k,diff.absolute_value_sum()/m_DistancesTest.at(0).size()); } /*For every Sample/Streamline get the mean eucledean distance to all other Samples => one value for every Sample*/ - distances_matrix_mean.push_back(distances_matrix.get_row(i).mean()); +// distances_matrix_mean.push_back(distances_matrix.get_row(i).mean()); // MITK_INFO << meanval.at(i); } - + MITK_INFO << "Distance Matrix Calculated"; /*Index to find values in distancematrix*/ std::vector myidx; /*Index to find actual streamlines using indexUnc*/ std::vector indexUncDist; /*Start with the Streamline of the highest entropy, which is in distance_matrix at idx 0*/ myidx.push_back(0); indexUncDist.push_back(indexUnc.at(myidx.at(0))); /*Vecotr that stores minvalues of current iteration*/ vnl_matrix cur_vec; cur_vec.set_size(1,lengths); cur_vec.fill(0.0); for (int i=0; i sum_matrix; sum_matrix.set_size(myidx.size(), lengths); sum_matrix.fill(0); for (unsigned int ii=0; ii &index) +mitk::FiberBundle::Pointer StreamlineFeatureExtractor::CreatePrediction(std::vector &index, bool removefrompool) { mitk::FiberBundle::Pointer Prediction; MITK_INFO << "Create Bundle"; vtkSmartPointer FibersData; FibersData = vtkSmartPointer::New(); FibersData->SetPoints(vtkSmartPointer::New()); FibersData->SetLines(vtkSmartPointer::New()); vtkSmartPointer vNewPolyData = vtkSmartPointer::New(); vtkSmartPointer vNewLines = vtkSmartPointer::New(); vtkSmartPointer vNewPoints = vtkSmartPointer::New(); // vtkSmartPointer weights = vtkSmartPointer::New(); // weights->SetNumberOfValues(this->GetNumFibers()+fib->GetNumFibers()); unsigned int indexSize = index.size(); unsigned int counter = 0; MITK_INFO << "Start Loop"; for (unsigned int i=0; iGetFiberPolyData()->GetCell(index[i]); auto numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vtkSmartPointer container = vtkSmartPointer::New(); for (unsigned int j=0; jGetPoint(j, p); vtkIdType id = vNewPoints->InsertNextPoint(p); container->GetPointIds()->InsertNextId(id); } // weights->InsertValue(counter, fib->GetFiberWeight(i)); vNewLines->InsertNextCell(container); counter++; } + if (removefrompool) + { + for (unsigned int i=0; iGetFiberPolyData()->DeleteCell(index[i]); + } + } + + + + MITK_INFO << "Counter"; MITK_INFO << counter; vNewPolyData->SetLines(vNewLines); vNewPolyData->SetPoints(vNewPoints); FibersData = vtkSmartPointer::New(); FibersData->SetPoints(vtkSmartPointer::New()); FibersData->SetLines(vtkSmartPointer::New()); FibersData->SetPoints(vNewPoints); FibersData->SetLines(vNewLines); Prediction = mitk::FiberBundle::New(vNewPolyData); // Bundle->SetFiberColors(255, 255, 255); MITK_INFO << "Cells Prediciton"; MITK_INFO << Prediction->GetFiberPolyData()->GetNumberOfCells(); MITK_INFO << "Cells Tractorgram"; MITK_INFO << m_TractogramTest->GetFiberPolyData()->GetNumberOfCells(); return Prediction; } std::vector StreamlineFeatureExtractor::CreateLabels(std::vector > Testdata, std::vector > Prediction) { // vnl_vector labels; // vnl_vector.set_size(Testdata.size()); // vnl_vector.fill(0); std::vector labels(Testdata.size(), 0); #pragma omp parallel for for (unsigned int i=0; i("/home/r948e/E132-Projekte/Projects/2022_Peretzke_Interactive_Fiber_Dissection/data/Synt_tract_40_prototypes.trk"); std::vector > T_Prototypes; std::vector > T_TractogramPlus; std::vector > T_TractogramMinus; std::vector > T_TractogramTest; std::vector > T_mergedPrototypes; MITK_INFO << "Resample Input Prototypes"; T_Prototypes = ResampleFibers(m_inputPrototypes); MITK_INFO << "Resample Input Tractogram Minus"; T_TractogramMinus= ResampleFibers(m_TractogramMinus); MITK_INFO << "Resample Input Tractogram Plus"; T_TractogramPlus= ResampleFibers(m_TractogramPlus); /* Merge T_Prototypes, T_TractogramMinus and T_TractogramPlus for extra Features*/ MITK_INFO << "Merging Prototypes"; T_mergedPrototypes = MergeTractogram(T_Prototypes, T_TractogramPlus, T_TractogramMinus); MITK_INFO << "Calculate Features"; MITK_INFO << "Calculate Minus Features"; m_DistancesMinus = CalculateDmdf(T_TractogramMinus, T_mergedPrototypes); // std::ofstream myFileminus("/home/r948e/E132-Projekte/Projects/2022_Peretzke_Interactive_Fiber_Dissection/mitk_diff/storage/dist_minus.csv"); // for(long unsigned int i = 0; i < m_DistancesMinus.size(); ++i) // { // myFileminus << m_DistancesMinus.at(i); // } // myFileminus.close(); MITK_INFO << "Calculate Plus Features"; m_DistancesPlus = CalculateDmdf(T_TractogramPlus, T_mergedPrototypes); // std::ofstream myFileplus("/home/r948e/E132-Projekte/Projects/2022_Peretzke_Interactive_Fiber_Dissection/mitk_diff/storage/dist_plus.csv"); // for(long unsigned int i = 0; i < m_DistancesPlus.size(); ++i) // { // myFileplus << m_DistancesPlus.at(i); // } // myFileplus.close(); MITK_INFO << m_DistancesTestName; MITK_INFO << "Resample Test Data"; T_TractogramTest= ResampleFibers(m_TractogramTest); // std::ofstream Prototypesfibers; // Prototypesfibers.open("/home/r948e/mycsv/Prototypefibers_" + std::to_string(m_activeCycle) + ".csv"); // for (unsigned int i = 0; i < T_mergedPrototypes.size(); i++) // { // Prototypesfibers<< T_mergedPrototypes.at(i) << ' '; // } // Prototypesfibers.close(); // std::ofstream TestfbiersFile; // TestfbiersFile.open("/home/r948e/mycsv/Testfibers_" + std::to_string(m_activeCycle) + ".csv"); // for (unsigned int i = 0; i < T_TractogramTest.size(); i++) // { // TestfbiersFile << T_TractogramTest.at(i) << ' '; // } // TestfbiersFile.close(); // MITK_INFO << "Calculate Features of Test Data"; m_DistancesTest= CalculateDmdf(T_TractogramTest, T_mergedPrototypes); // std::ofstream myFile(m_DistancesTestName); // for(long unsigned int i = 0; i < m_DistancesTest.size(); ++i) // { // myFile << m_DistancesTest.at(i); // } // myFile.close(); // std::ifstream f(m_DistancesTestName); // if (f.good() && m_activeCycle!=0) // { // MITK_INFO << "Loading Features of Tractogram"; // m_DistancesTest.clear(); // std::ifstream myFile(m_DistancesTestName); // if(!myFile.is_open()) throw std::runtime_error("Could not open file"); // std::string line; // vnl_matrix curline; // curline.set_size(1, m_DistancesPlus.at(0).cols()); // curline.fill(0.0); // float val; // while(std::getline(myFile, line)) // { // // Create a stringstream of the current line // std::stringstream ss(line); //// MITK_INFO << ss; // // Keep track of the current column index // int colIdx = 0; // // Extract each integer // while(ss >> val){ //// // Add the current integer to the 'colIdx' column's values vector // curline.put(0,colIdx, val); //// // If the next token is a comma, ignore it and move on //// if(ss.peek() == ',') ss.ignore(); //// // Increment the column index // colIdx++; // } // m_DistancesTest.push_back(curline); // } // // Close file // myFile.close(); // } // else // { // MITK_INFO << m_DistancesTestName; // MITK_INFO << "Resample Test Data"; // T_TractogramTest= ResampleFibers(m_TractogramTest); // MITK_INFO << "Calculate Features of Test Data"; // m_DistancesTest= CalculateDmdf(T_TractogramTest, T_mergedPrototypes); // std::ofstream myFile(m_DistancesTestName); // // myFile << colname << "\n"; // for(long unsigned int i = 0; i < m_DistancesTest.size(); ++i) // { // myFile << m_DistancesTest.at(i); // } // myFile.close(); // } // MITK_INFO << m_DistancesTest.size(); MITK_INFO << "Sizes of Plus and Minus"; MITK_INFO << m_DistancesPlus.size() + m_DistancesMinus.size(); MITK_INFO << "Sizes of Prototypes"; MITK_INFO << T_mergedPrototypes.size(); MITK_INFO << T_mergedPrototypes.at(0).rows(); MITK_INFO << "Size of Test Data"; MITK_INFO << m_DistancesTest.size(); MITK_INFO << "Done with Datacreation"; m_index =GetData(); } vnl_vector StreamlineFeatureExtractor::ValidationPipe() { std::vector > T_Prototypes; std::vector > T_TractogramPrediction; std::vector > T_TractogramGroundtruth; std::vector > T_TractogramTest; std::vector > DistancesPrediction; std::vector > DistancesGroundtruth; std::vector > DistancesTest; std::vector LabelsPrediction; std::vector LabelsGroundtruth; MITK_INFO << "Start Resampling"; T_Prototypes = ResampleFibers(m_inputPrototypes); T_TractogramPrediction= ResampleFibers(m_TractogramPrediction); T_TractogramGroundtruth= ResampleFibers(m_TractogramGroundtruth); T_TractogramTest= ResampleFibers(m_TractogramTest); MITK_INFO << "Calculate Features"; DistancesPrediction = CalculateDmdf(T_TractogramPrediction, T_Prototypes); DistancesGroundtruth = CalculateDmdf(T_TractogramGroundtruth, T_Prototypes); DistancesTest = CalculateDmdf(T_TractogramTest, T_Prototypes); LabelsGroundtruth = CreateLabels(DistancesTest, DistancesGroundtruth); LabelsPrediction = CreateLabels(DistancesTest, DistancesPrediction); std::ofstream LabelsPredictionFile; LabelsPredictionFile.open("/home/r948e/mycsv/predictionlabels_" + std::to_string(m_activeCycle) + ".csv"); for (unsigned int i = 0; i < LabelsPrediction.size(); i++) { LabelsPredictionFile << LabelsPrediction.at(i) << ' '; } LabelsPredictionFile.close(); std::ofstream LabelsGroundtruthFile; LabelsGroundtruthFile.open("/home/r948e/mycsv/groundtruthlabels_" + std::to_string(m_activeCycle) + ".csv"); for (unsigned int i = 0; i < LabelsGroundtruth.size(); i++) { LabelsGroundtruthFile << LabelsGroundtruth.at(i) << ' '; } LabelsGroundtruthFile.close(); float FP = 0.0; float FN = 0.0; float TP = 0.0; float TN = 0.0; + std::vector indexfp; //#pragma omp parallel for for (unsigned int i=0; i metrics(7); metrics.put(0, TP); metrics.put(1, FP); metrics.put(2, TN); metrics.put(3, FN); metrics.put(4, Precision); metrics.put(5, Recall); metrics.put(6, F1_score); return metrics; } } diff --git a/Modules/FiberDissection/MachineLearning/mitkStreamlineFeatureExtractor.h b/Modules/FiberDissection/MachineLearning/mitkStreamlineFeatureExtractor.h index 10829df..c39865e 100644 --- a/Modules/FiberDissection/MachineLearning/mitkStreamlineFeatureExtractor.h +++ b/Modules/FiberDissection/MachineLearning/mitkStreamlineFeatureExtractor.h @@ -1,126 +1,129 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center. 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 StreamlineFeatureExtractor_h #define StreamlineFeatureExtractor_h #include "MitkFiberDissectionExports.h" // MITK #include #include // ITK #include // VTK #include #include #include #include #include // OpenCV #include #include #include namespace mitk{ /** * \brief */ class MITKFIBERDISSECTION_EXPORT StreamlineFeatureExtractor { public: StreamlineFeatureExtractor(); ~StreamlineFeatureExtractor(); typedef itk::Image< float, 3 > FloatImageType; typedef itk::Image< unsigned char, 3 > UcharImageType; void Update(){ this->GenerateData(); } // void Validate(){ // this->ValidationPipe(); // } void SetTractogramGroundtruth(const mitk::FiberBundle::Pointer &Tractogram); void SetTractogramPrediction(const mitk::FiberBundle::Pointer &Tractogram); void SetTractogramPlus(const mitk::FiberBundle::Pointer &Tractogram); void SetTractogramMinus(const mitk::FiberBundle::Pointer &Tractogram); void SetTractogramTest(const mitk::FiberBundle::Pointer &Tractogram, std::string TractogramTestName); void SetTractogramPrototypes(const mitk::FiberBundle::Pointer &TractogramPrototypes, bool standard); void SetActiveCycle(int &activeCycle); void SetInitRandom(int &initRandom); // void SetRandomThreshold(int &threshold); vnl_vector ValidationPipe(); void CreateClassifier(); std::vector> GetData(); // void CreatePrediction(std::vector &index); - mitk::FiberBundle::Pointer CreatePrediction(std::vector &index); + mitk::FiberBundle::Pointer CreatePrediction(std::vector &index, bool removefrompool); + std::vector> GetDistanceData(float &value); mitk::FiberBundle::Pointer m_Prediction; mitk::FiberBundle::Pointer m_ToLabel; std::vector> m_index; + std::vector entropy_vector; + cv::Ptr statistic_model; protected: void GenerateData(); // void ValidationPipe(); std::vector CreateLabels(std::vector > Testdata, std::vector > Prediction); std::vector< vnl_matrix > ResampleFibers(FiberBundle::Pointer tractogram); std::vector > CalculateDmdf(std::vector > tractogram, std::vector > prototypes); std::vector< vnl_matrix > MergeTractogram(std::vector > prototypes, std::vector > positive_local_prototypes, std::vector > negative_local_prototypes); std::vector Sort(std::vector sortingVector, int lengths, int start); unsigned int m_NumPoints; int m_activeCycle; int m_initRandom; int m_thresh; mitk::FiberBundle::Pointer m_TractogramPrediction; mitk::FiberBundle::Pointer m_TractogramGroundtruth; mitk::FiberBundle::Pointer m_TractogramPlus; mitk::FiberBundle::Pointer m_TractogramMinus; mitk::FiberBundle::Pointer m_TractogramTest; mitk::FiberBundle::Pointer m_inputPrototypes; std::string m_DistancesTestName; std::vector > m_DistancesPlus; std::vector > m_DistancesMinus; std::vector > m_DistancesTest; cv::Ptr m_traindata; }; } #endif diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionView.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionView.cpp index b2b0d20..ff52252 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionView.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionView.cpp @@ -1,1533 +1,1729 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center. 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. ===================================================================*/ // Blueberry #include #include #include // Qmitk #include "QmitkInteractiveFiberDissectionView.h" #include //Pointset #include //Pointset #include #include #include #include #include #include #include #include "mitkNodePredicateDataType.h" #include #include #include #include //#include #include #include "usModuleRegistry.h" //#include #include #include #include #include #include #include #include #include #include #include #include #include #include const std::string QmitkInteractiveFiberDissectionView::VIEW_ID = "org.mitk.views.interactivefiberdissection"; const std::string id_DataManager = "org.mitk.views.datamanager"; using namespace mitk; QmitkInteractiveFiberDissectionView::QmitkInteractiveFiberDissectionView() : QmitkAbstractView() , m_Controls( 0 ) , m_IterationCounter(0) , m_RandomExtractionCounter(0) , m_activeCycleCounter(0) , m_createdStreamlineCounter(0) , m_StreamlineInteractor(nullptr) { } // Destructor QmitkInteractiveFiberDissectionView::~QmitkInteractiveFiberDissectionView() { //disable interactor if (m_StreamlineInteractor != nullptr) { // m_StreamlineInteractor->SetStreamlineNode(nullptr); m_StreamlineInteractor->EnableInteraction(false); } } void QmitkInteractiveFiberDissectionView::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::QmitkInteractiveFiberDissectionViewControls; m_Controls->setupUi( parent ); m_Controls->m_selectedPointSetWidget->SetDataStorage(GetDataStorage());//pointset m_Controls->m_selectedPointSetWidget->SetNodePredicate(mitk::NodePredicateAnd::New(//pointset mitk::TNodePredicateDataType::New(),//pointset mitk::NodePredicateNot::New(mitk::NodePredicateOr::New(//pointset mitk::NodePredicateProperty::New("helper object"),//pointset mitk::NodePredicateProperty::New("hidden object")))));//pointset m_Controls->m_selectedPointSetWidget->SetSelectionIsOptional(true);//pointset m_Controls->m_selectedPointSetWidget->SetAutoSelectNewNodes(true);//pointset m_Controls->m_selectedPointSetWidget->SetEmptyInfo(QString("Please select a point set"));//pointset m_Controls->m_selectedPointSetWidget->SetPopUpTitel(QString("Select point set"));//pointsett m_Controls->m_BundleBox->SetDataStorage(this->GetDataStorage()); mitk::TNodePredicateDataType::Pointer isBundle= mitk::TNodePredicateDataType::New(); m_Controls->m_BundleBox->SetPredicate( isBundle ); m_Controls->m_PrototypeBox->SetDataStorage(this->GetDataStorage()); mitk::TNodePredicateDataType::Pointer isPrototype = mitk::TNodePredicateDataType::New(); m_Controls->m_PrototypeBox->SetPredicate( isPrototype ); m_Controls->m_PredictionBox->SetDataStorage(this->GetDataStorage()); mitk::TNodePredicateDataType::Pointer isPrediction = mitk::TNodePredicateDataType::New(); m_Controls->m_PredictionBox->SetPredicate( isPrediction ); m_Controls->m_GroundtruthBox->SetDataStorage(this->GetDataStorage()); mitk::TNodePredicateDataType::Pointer isGroundtruth = mitk::TNodePredicateDataType::New(); m_Controls->m_GroundtruthBox->SetPredicate( isGroundtruth ); connect(m_Controls->m_ErazorButton, SIGNAL(toggled(bool)), this, SLOT( RemovefromBundle(bool) ) ); //need connect(m_Controls->m_StreamlineCreation, SIGNAL( clicked() ), this, SLOT( CreateStreamline())); connect(m_Controls->m_AddRandomFibers, SIGNAL( clicked() ), this, SLOT( ExtractRandomFibersFromTractogram() ) ); //need connect(m_Controls->m_TrainClassifier, SIGNAL( clicked() ), this, SLOT( StartAlgorithm( ))); connect(m_Controls->m_CreatePrediction, SIGNAL( clicked() ), this, SLOT( CreatePredictionNode( ))); connect(m_Controls->m_certainData, SIGNAL( clicked() ), this, SLOT( CreateCertainNode( ))); connect(m_Controls->m_AddUncertainFibers, SIGNAL( clicked() ), this, SLOT( CreateUncertaintySampleNode( ))); connect(m_Controls->m_AddDistanceFibers, SIGNAL( clicked() ), this, SLOT( CreateDistanceSampleNode( ))); connect(m_Controls->m_unclabeling, SIGNAL(toggled(bool)), this, SLOT( RemovefromUncertainty(bool) ) ); //need connect(m_Controls->m_distlabeling, SIGNAL(toggled(bool)), this, SLOT( RemovefromDistance(bool) ) ); //need connect(m_Controls->m_predlabeling, SIGNAL(toggled(bool)), this, SLOT( RemovefromPrediction(bool) ) ); //need connect(m_Controls->m_sellabeling, SIGNAL(toggled(bool)), this, SLOT( RemovefromSelection(bool) ) ); //need connect(m_Controls->m_ResampleButton, SIGNAL( clicked() ), this, SLOT( ResampleTractogram( ) ) ); connect(m_Controls->m_RandomPrototypesButton, SIGNAL( clicked() ), this, SLOT( RandomPrototypes( ) ) ); connect(m_Controls->m_SFFPrototypesButton, SIGNAL( clicked() ), this, SLOT( SFFPrototypes( ) ) ); connect(m_Controls->m_validate, SIGNAL( clicked() ), this, SLOT( StartValidation( ) ) ); connect(m_Controls->m_automaticLabelling, SIGNAL( clicked() ), this, SLOT( AutomaticLabelling( ) ) ); + connect(m_Controls->m_RemoveCertainData, SIGNAL( clicked() ), this, SLOT( RemoveCertainData( ) ) ); + connect(m_Controls->m_addPointSetPushButton, &QPushButton::clicked,//pointset this, &QmitkInteractiveFiberDissectionView::OnAddPointSetClicked);//pointset connect(m_Controls->m_selectedPointSetWidget, &QmitkSingleNodeSelectionWidget::CurrentSelectionChanged,//pointset this, &QmitkInteractiveFiberDissectionView::OnCurrentSelectionChanged);//pointset auto renderWindowPart = this->GetRenderWindowPart();//pointset if (nullptr != renderWindowPart)//pointset this->RenderWindowPartActivated(renderWindowPart);//pointset this->OnCurrentSelectionChanged(m_Controls->m_selectedPointSetWidget->GetSelectedNodes());//pointset } UpdateGui(); } void QmitkInteractiveFiberDissectionView::SetFocus() { m_Controls->toolBoxx->setFocus(); //m_Controls->m_addPointSetPushButton->setFocus();//pointset } void QmitkInteractiveFiberDissectionView::UpdateGui() { m_Controls->m_FibLabel->setText("mandatory"); m_Controls->m_InputData->setTitle("Please Select Input Data"); // disable alle frames m_Controls->m_ErazorButton->setCheckable(true); m_Controls->m_ErazorButton->setEnabled(false); m_Controls->m_unclabeling->setCheckable(true); m_Controls->m_unclabeling->setEnabled(false); m_Controls->m_predlabeling->setCheckable(true); m_Controls->m_predlabeling->setEnabled(false); m_Controls->m_distlabeling->setCheckable(true); m_Controls->m_distlabeling->setEnabled(false); m_Controls->m_sellabeling->setCheckable(true); m_Controls->m_sellabeling->setEnabled(false); m_Controls->m_addPointSetPushButton->setEnabled(false); m_Controls->m_StreamlineCreation->setEnabled(false); m_Controls->m_TrainClassifier->setEnabled(false); m_Controls->m_CreatePrediction->setEnabled(false); m_Controls->m_CreateUncertantyMap->setEnabled(false); m_Controls->m_Numtolabel->setEnabled(false); m_Controls->m_Numtolabel2->setEnabled(false); m_Controls->m_addPointSetPushButton->setEnabled(false); m_Controls->m_AddRandomFibers->setEnabled(false); m_Controls->m_AddDistanceFibers->setEnabled(false); m_Controls->m_AddUncertainFibers->setEnabled(false); // m_Controls->m_PrototypeBox->setEditable(false); // m_Controls->m_useStandardP-> bool fibSelected = !m_SelectedFB.empty(); bool multipleFibsSelected = (m_SelectedFB.size()>1); bool sthSelected = m_SelectedImageNode.IsNotNull(); bool psSelected = m_SelectedPS.IsNotNull(); // bool nfibSelected = !m_newfibersBundleNode.empty(); -// bool posSelected = !m_positivBundlesNode.empty(); +// bool posSelected = !m_positiveBundleNode.empty(); bool nfibSelected = m_newfibersBundleNode.IsNotNull(); -// bool posSelected = !m_positivBundlesNode.IsNotNull(); +// bool posSelected = !m_positiveBundleNode.IsNotNull(); // bool negSelected = !m_negativeBundleNode.IsNotNull(); - bool posSelected = this->GetDataStorage()->Exists(m_positivBundlesNode); + bool posSelected = this->GetDataStorage()->Exists(m_positiveBundleNode); bool negSelected = this->GetDataStorage()->Exists(m_negativeBundleNode); bool indexSelected = !m_index.empty(); bool uncertaintySelected = this->GetDataStorage()->Exists(m_UncertaintyLabelNode); - bool distanceSelected = this->GetDataStorage()->Exists(m_DistanceLabelNode); +// bool distanceSelected = this->GetDataStorage()->Exists(m_DistanceLabelNode); bool predictionSelected = this->GetDataStorage()->Exists(m_PredictionNode); // toggle visibility of elements according to selected method // are fiber bundles selected? if ( fibSelected ) { m_Controls->m_FibLabel->setText(QString(m_SelectedFB.at(0)->GetName().c_str())); m_Controls->m_addPointSetPushButton->setEnabled(true); m_Controls->m_AddRandomFibers->setEnabled(true); m_Controls->m_sellabeling->setEnabled(true); // more than two bundles needed to join/subtract if (multipleFibsSelected) { m_Controls->m_FibLabel->setText("multiple bundles selected"); } } // is image selected if (sthSelected) { m_Controls->m_addPointSetPushButton->setEnabled(true); } if (psSelected) { m_Controls->m_StreamlineCreation->setEnabled(true); } if (nfibSelected && posSelected) { m_Controls->m_ErazorButton->setEnabled(true); } if (posSelected && negSelected) { m_Controls->m_TrainClassifier->setEnabled(true); } if (indexSelected) { m_Controls->m_CreatePrediction->setEnabled(true); m_Controls->m_AddUncertainFibers->setEnabled(true); m_Controls->m_Numtolabel->setEnabled(true); m_Controls->m_AddDistanceFibers->setEnabled(true); m_Controls->m_Numtolabel2->setEnabled(true); } if (uncertaintySelected) { m_Controls->m_unclabeling->setEnabled(true); } if (predictionSelected) { m_Controls->m_predlabeling->setEnabled(true); } - if (distanceSelected) - { +// if (distanceSelected) +// { m_Controls->m_distlabeling->setEnabled(true); - } +// } // if (m_Controls->m_useStandardP->isChecked()) // { // m_Controls->m_PrototypeBox->setEditable(true); // } } void QmitkInteractiveFiberDissectionView::OnEndInteraction() { } void QmitkInteractiveFiberDissectionView::ResampleTractogram() { mitk::DataNode::Pointer node = m_Controls->m_BundleBox->GetSelectedNode(); auto tractogram = dynamic_cast(node->GetData()); mitk::FiberBundle::Pointer tempfib = tractogram->GetDeepCopy(); std::vector myvec; for (unsigned int k=0; kGetNumFibers(); k++) { myvec.push_back(k); } // auto rng = std::default_random_engine {}; std::random_shuffle(std::begin(myvec), std::end(myvec)); vtkSmartPointer vNewPolyData = vtkSmartPointer::New(); vtkSmartPointer vNewLines = vtkSmartPointer::New(); vtkSmartPointer vNewPoints = vtkSmartPointer::New(); vtkSmartPointer weights = vtkSmartPointer::New(); /* Check wether all Streamlines of the bundles are labeled... If all are labeled Skip for Loop*/ unsigned int counter = 0; for (unsigned int i=0; iGetNumFibers(); i++) { vtkCell* cell = tempfib->GetFiberPolyData()->GetCell(myvec.at(i)); auto numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vtkSmartPointer container = vtkSmartPointer::New(); for (unsigned int j=0; jGetPoint(j, p); vtkIdType id = vNewPoints->InsertNextPoint(p); container->GetPointIds()->InsertNextId(id); } weights->InsertValue(counter, tempfib->GetFiberWeight(myvec.at(i))); vNewLines->InsertNextCell(container); counter++; } vNewPolyData->SetLines(vNewLines); vNewPolyData->SetPoints(vNewPoints); mitk::FiberBundle::Pointer ShuffledBundle = mitk::FiberBundle::New(vNewPolyData); ShuffledBundle->SetFiberWeights(weights); ShuffledBundle->ResampleToNumPoints(40); MITK_INFO << "Resampling Done"; mitk::DataNode::Pointer newnode = mitk::DataNode::New(); newnode->SetData( ShuffledBundle ); newnode->SetName( node->GetName() + "_" + std::to_string(40) ); this->GetDataStorage()->Add(newnode); UpdateGui(); } void QmitkInteractiveFiberDissectionView::RandomPrototypes() { MITK_INFO << "Number of Fibers to use as Prototypes: "; MITK_INFO << m_Controls->m_NumPrototypes->value(); mitk::FiberBundle::Pointer fib = dynamic_cast(m_Controls->m_BundleBox->GetSelectedNode()->GetData()); MITK_INFO << fib->GetNumFibers(); std::vector myvec; for (unsigned int k=0; kGetNumFibers(); k++) { myvec.push_back(k); } // auto rng = std::default_random_engine {}; std::random_shuffle(std::begin(myvec), std::end(myvec)); vtkSmartPointer vNewPolyData = vtkSmartPointer::New(); vtkSmartPointer vNewLines = vtkSmartPointer::New(); vtkSmartPointer vNewPoints = vtkSmartPointer::New(); vtkSmartPointer weights = vtkSmartPointer::New(); /* Check wether all Streamlines of the bundles are labeled... If all are labeled Skip for Loop*/ unsigned int counter = 0; for (int i=0; im_NumPrototypes->value(); i++) { vtkCell* cell = fib->GetFiberPolyData()->GetCell(myvec.at(i)); auto numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vtkSmartPointer container = vtkSmartPointer::New(); for (unsigned int j=0; jGetPoint(j, p); vtkIdType id = vNewPoints->InsertNextPoint(p); container->GetPointIds()->InsertNextId(id); } weights->InsertValue(counter, fib->GetFiberWeight(myvec.at(i))); vNewLines->InsertNextCell(container); counter++; } vNewPolyData->SetLines(vNewLines); vNewPolyData->SetPoints(vNewPoints); mitk::FiberBundle::Pointer PrototypesBundle = mitk::FiberBundle::New(vNewPolyData); PrototypesBundle->SetFiberWeights(weights); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(PrototypesBundle); node->SetName("Random_Prototypes"); // MITK_INFO << "Number of Streamlines in first function"; // MITK_INFO << m_newfibersBundleNode->GetData()->GetFiberPolyData()->GetNumberOfCells(); + m_Controls->m_PrototypeBox->SetAutoSelectNewItems (true); this->GetDataStorage()->Add(node); + m_Controls->m_PrototypeBox->SetAutoSelectNewItems (false); + m_Controls->m_useStandardP->setChecked(false); + node->SetVisibility(false); } void QmitkInteractiveFiberDissectionView::SFFPrototypes() { MITK_INFO << "Number of Fibers to use as Prototypes: "; MITK_INFO << m_Controls->m_NumPrototypes->value(); MITK_INFO << "Start Creating Prototypes based on SFF"; mitk::FiberBundle::Pointer fib = dynamic_cast(m_Controls->m_BundleBox->GetSelectedNode()->GetData()); /* Get Subset of Tractogram*/ int size_subset = std::max(1.0, ceil(3.0 * m_Controls->m_NumPrototypes->value() * std::log(m_Controls->m_NumPrototypes->value()))); MITK_INFO << fib->GetNumFibers(); std::vector myvec; for (unsigned int k=0; kGetNumFibers(); k++) { myvec.push_back(k); } // std::random_shuffle(std::begin(myvec), std::end(myvec)); vtkSmartPointer vNewPolyData = vtkSmartPointer::New(); vtkSmartPointer vNewLines = vtkSmartPointer::New(); vtkSmartPointer vNewPoints = vtkSmartPointer::New(); vtkSmartPointer weights = vtkSmartPointer::New(); unsigned int counter = 0; for (int i=0; iGetFiberPolyData()->GetCell(myvec.at(i)); auto numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vtkSmartPointer container = vtkSmartPointer::New(); for (unsigned int j=0; jGetPoint(j, p); vtkIdType id = vNewPoints->InsertNextPoint(p); container->GetPointIds()->InsertNextId(id); } weights->InsertValue(counter, fib->GetFiberWeight(myvec.at(i))); vNewLines->InsertNextCell(container); counter++; } vNewPolyData->SetLines(vNewLines); vNewPolyData->SetPoints(vNewPoints); mitk::FiberBundle::Pointer temp_fib = mitk::FiberBundle::New(vNewPolyData); temp_fib->SetFiberWeights(weights); MITK_INFO << temp_fib->GetFiberPolyData()->GetNumberOfCells(); /* Create std::vector of the SubsetBundle*/ std::vector< vnl_matrix > out_fib(temp_fib->GetFiberPolyData()->GetNumberOfCells()); for (int i=0; iGetFiberPolyData()->GetNumberOfCells(); i++) { vtkCell* cell = temp_fib->GetFiberPolyData()->GetCell(i); int numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vnl_matrix streamline; streamline.set_size(3, cell->GetNumberOfPoints()); streamline.fill(0.0); for (int j=0; jGetPoint(j, cand); vnl_vector_fixed< float, 3 > candV; candV[0]=cand[0]; candV[1]=cand[1]; candV[2]=cand[2]; streamline.set_column(j, candV); } // out_fib.push_back(streamline); out_fib.at(i)=streamline; } /* Calculate the distancematrix of Subset*/ std::vector< vnl_matrix > dist_vec(out_fib.size());// cv::parallel_for_(cv::Range(0, out_fib.size()), [&](const cv::Range &range) { for (int i = range.start; i < range.end; i++) // for (unsigned int i=0; i distances; distances.set_size(1, out_fib.size()); distances.fill(0.0); for (unsigned int j=0; j single_distances; single_distances.set_size(1, out_fib.at(0).cols()); single_distances.fill(0.0); vnl_matrix single_distances_flip; single_distances_flip.set_size(1, out_fib.at(0).cols()); single_distances_flip.fill(0.0); for (unsigned int ik=0; ik single_distances.mean()) { distances.put(0,j, single_distances.mean()); } else { distances.put(0,j, single_distances_flip.mean()); } } // dist_vec.push_back(distances); dist_vec.at(i) = distances; } }); /*Index to find values in distancematrix*/ std::vector myidx; /*Index to find actual streamlines using indexUnc*/ std::vector indexUncDist; /*Start with the Streamline of the highest entropy, which is in distance_matrix at idx 0*/ myidx.push_back(0); /*Vecotr that stores minvalues of current iteration*/ vnl_matrix cur_vec; cur_vec.set_size(1, size_subset); cur_vec.fill(0.0); for (int i=0; im_NumPrototypes->value(); i++) { // unsigned int cur_i = indexUnc.at(myidx.at(i)); /*Save mean distance of all used Samples*/ vnl_matrix sum_matrix; sum_matrix.set_size(myidx.size(), size_subset); sum_matrix.fill(0); for (unsigned int ii=0; ii vNewPolyData2 = vtkSmartPointer::New(); vtkSmartPointer vNewLines2 = vtkSmartPointer::New(); vtkSmartPointer vNewPoints2 = vtkSmartPointer::New(); vtkSmartPointer weights2 = vtkSmartPointer::New(); /* Check wether all Streamlines of the bundles are labeled... If all are labeled Skip for Loop*/ counter = 0; for (int i=0; im_NumPrototypes->value(); i++) { vtkCell* cell = fib->GetFiberPolyData()->GetCell(myidx.at(i)); auto numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vtkSmartPointer container = vtkSmartPointer::New(); for (unsigned int j=0; jGetPoint(j, p); vtkIdType id = vNewPoints2->InsertNextPoint(p); container->GetPointIds()->InsertNextId(id); } weights2->InsertValue(counter, fib->GetFiberWeight(myvec.at(i))); vNewLines2->InsertNextCell(container); counter++; } vNewPolyData2->SetLines(vNewLines2); vNewPolyData2->SetPoints(vNewPoints2); mitk::FiberBundle::Pointer PrototypesBundle = mitk::FiberBundle::New(vNewPolyData2); PrototypesBundle->SetFiberWeights(weights2); MITK_INFO << PrototypesBundle->GetFiberPolyData()->GetNumberOfCells(); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(PrototypesBundle); node->SetName("SFF_Prototypes"); //// MITK_INFO << "Number of Streamlines in first function"; //// MITK_INFO << m_newfibersBundleNode->GetData()->GetFiberPolyData()->GetNumberOfCells(); + m_Controls->m_PrototypeBox->SetAutoSelectNewItems (true); this->GetDataStorage()->Add(node); + m_Controls->m_PrototypeBox->SetAutoSelectNewItems (false); + m_Controls->m_useStandardP->setChecked(false); + node->SetVisibility(false); + } void QmitkInteractiveFiberDissectionView::OnAddPointSetClicked()//pointset { // ask for the name of the point set bool ok = false; QString name = QInputDialog::getText(QApplication::activeWindow(), tr("Add point set..."), tr("Enter name for the new point set"), QLineEdit::Normal, tr("PointSet").arg(++m_IterationCounter), &ok); // QString name = "PointSet"; if (!ok || name.isEmpty()) { return; } mitk::PointSet::Pointer pointSet = mitk::PointSet::New(); mitk::DataNode::Pointer pointSetNode = mitk::DataNode::New(); pointSetNode->SetData(pointSet); pointSetNode->SetProperty("name", mitk::StringProperty::New(name.toStdString())); pointSetNode->SetProperty("opacity", mitk::FloatProperty::New(1)); pointSetNode->SetColor(1.0, 1.0, 0.0); this->GetDataStorage()->Add(pointSetNode, m_SelectedImageNode); m_Controls->m_selectedPointSetWidget->SetCurrentSelectedNode(pointSetNode); } void QmitkInteractiveFiberDissectionView::OnCurrentSelectionChanged(QmitkSingleNodeSelectionWidget::NodeList /*nodes*/)//pointset { m_Controls->m_poinSetListWidget->SetPointSetNode(m_Controls->m_selectedPointSetWidget->GetSelectedNode()); m_SelectedPS = m_Controls->m_selectedPointSetWidget->GetSelectedNode(); // m_Controls->m_trainbundleWidget->SetPointSetNode(m_Controls->m_trainbundleWidget->GetSelectedNode()); // m_trainbundle = m_Controls->m_trainbundleWidget->GetSelectedNode(); UpdateGui(); } void QmitkInteractiveFiberDissectionView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*part*/, const QList& nodes) { m_SelectedFB.clear(); if (nodes.empty() || nodes.front().IsNull()) { m_SelectedImageNode = nullptr; } else { m_SelectedImageNode = nodes.front(); } for (auto node: nodes) { if (dynamic_cast(node->GetData())) m_SelectedImage = dynamic_cast(node->GetData()); else if ( dynamic_cast(node->GetData()) ) m_SelectedFB.push_back(node); } UpdateGui(); } void QmitkInteractiveFiberDissectionView::RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart)//pointset { if (nullptr != m_Controls) { m_Controls->m_poinSetListWidget->AddSliceNavigationController(renderWindowPart->GetQmitkRenderWindow("axial")->GetSliceNavigationController()); m_Controls->m_poinSetListWidget->AddSliceNavigationController(renderWindowPart->GetQmitkRenderWindow("sagittal")->GetSliceNavigationController()); m_Controls->m_poinSetListWidget->AddSliceNavigationController(renderWindowPart->GetQmitkRenderWindow("coronal")->GetSliceNavigationController()); } } void QmitkInteractiveFiberDissectionView::RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderWindowPart)//pointset { if (nullptr != m_Controls) { m_Controls->m_poinSetListWidget->RemoveSliceNavigationController(renderWindowPart->GetQmitkRenderWindow("axial")->GetSliceNavigationController()); m_Controls->m_poinSetListWidget->RemoveSliceNavigationController(renderWindowPart->GetQmitkRenderWindow("sagittal")->GetSliceNavigationController()); m_Controls->m_poinSetListWidget->RemoveSliceNavigationController(renderWindowPart->GetQmitkRenderWindow("coronal")->GetSliceNavigationController()); } } void QmitkInteractiveFiberDissectionView::CreateStreamline() { - if (m_positivBundlesNode.IsNull()) + if (m_positiveBundleNode.IsNull()) { mitk::DataNode::Pointer node = mitk::DataNode::New(); m_positiveFibersData = vtkSmartPointer::New(); m_positiveFibersData->SetPoints(vtkSmartPointer::New()); m_positiveFibersData->SetLines(vtkSmartPointer::New()); m_positiveBundle = mitk::FiberBundle:: New(m_positiveFibersData); node->SetData( m_positiveBundle ); - m_positivBundlesNode = node; - this->GetDataStorage()->Add(m_positivBundlesNode); + m_positiveBundleNode = node; + this->GetDataStorage()->Add(m_positiveBundleNode); MITK_INFO << "Create Bundle"; } - if (!m_positivBundlesNode.IsNull()) + if (!m_positiveBundleNode.IsNull()) { - this->GetDataStorage()->Remove(m_positivBundlesNode); + this->GetDataStorage()->Remove(m_positiveBundleNode); MITK_INFO << "Adding fibers"; MITK_INFO << m_positiveBundle->GetFiberPolyData()->GetNumberOfCells(); m_positiveFibersData = m_positiveBundle->GetFiberPolyData(); } vtkSmartPointer vNewPolyData = vtkSmartPointer::New(); vtkSmartPointer vNewLines = vtkSmartPointer::New(); vtkSmartPointer vNewPoints = vtkSmartPointer::New(); unsigned int counter = 0; for (unsigned int i=0; iGetNumberOfCells(); ++i) { MITK_INFO<< "New Line"; vtkCell* cell = m_positiveFibersData->GetCell(i); auto numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vtkSmartPointer container = vtkSmartPointer::New(); for (unsigned int j=0; jGetPoint(j, p); vtkIdType id = vNewPoints->InsertNextPoint(p); container->GetPointIds()->InsertNextId(id); } vNewLines->InsertNextCell(container); counter++; } mitk::PointSet::Pointer pointSet = dynamic_cast(m_SelectedPS->GetData()); vnl_matrix streamline; streamline.set_size(3, pointSet->GetSize()); streamline.fill(0.0); mitk::PointSet::PointsIterator begin = pointSet->Begin(); mitk::PointSet::PointsIterator end = pointSet->End(); unsigned int i; mitk::PointSet::PointsContainer::Iterator it; for (it = begin, i = 0; it != end; ++it, ++i) { PointSet::PointType pt = pointSet->GetPoint(it->Index()); vnl_vector_fixed< float, 3 > candV; candV[0]=pt[0]; candV[1]=pt[1]; candV[2]=pt[2]; streamline.set_column(i, candV); } // build Fiber vtkSmartPointer container = vtkSmartPointer::New(); for (unsigned int j=0; jInsertNextPoint(p); container->GetPointIds()->InsertNextId(id); } MITK_INFO<< "Last Line from current pointset"; vNewLines->InsertNextCell(container); vNewPolyData->SetPoints(vNewPoints); vNewPolyData->SetLines(vNewLines); m_positiveFibersData = vtkSmartPointer::New(); m_positiveFibersData->SetPoints(vtkSmartPointer::New()); m_positiveFibersData->SetLines(vtkSmartPointer::New()); m_positiveFibersData->SetPoints(vNewPoints); m_positiveFibersData->SetLines(vNewLines); m_positiveBundle = mitk::FiberBundle::New(vNewPolyData); -// m_positiveBundle->SetTrackVisHeader(dynamic_cast(m_SelectedImageNode->GetData())->GetGeometry()); - m_positiveBundle->SetFiberColors(0, 255, 0); + m_positiveBundle->ResampleToNumPoints(40); + MITK_INFO << "Resampling Done"; + + m_positiveBundle->SetFiberColors(0, 255, 0); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(m_positiveBundle); node->SetName("+Bundle"); - m_positivBundlesNode= node; - + m_positiveBundleNode= node; MITK_INFO << "The + Bundle has Streamlines:"; - auto m_PosStreamline= dynamic_cast(m_positivBundlesNode->GetData()); + auto m_PosStreamline= dynamic_cast(m_positiveBundleNode->GetData()); MITK_INFO << m_PosStreamline->GetFiberPolyData()->GetNumberOfCells(); - this->GetDataStorage()->Add(m_positivBundlesNode); + this->GetDataStorage()->Add(m_positiveBundleNode); // m_Controls->m_selectedPointSetWidget->m_ToggleAddPoint->setEnabled(false); UpdateGui(); m_createdStreamlineCounter +=1; } void QmitkInteractiveFiberDissectionView::ExtractRandomFibersFromTractogram() { m_SelectedFB.at(0)->SetVisibility(false); m_Controls->m_ErazorButton->setChecked(false); MITK_INFO << "Number of Fibers to extract from Tractogram: "; MITK_INFO << m_Controls->m_NumRandomFibers->value(); if (this->GetDataStorage()->Exists(m_newfibersBundleNode)) { MITK_INFO << "To Label Bundle Exists"; mitk::FiberBundle::Pointer Stack = dynamic_cast(m_newfibersBundleNode->GetData()); this->GetDataStorage()->Remove(m_newfibersBundleNode); mitk::DataNode::Pointer node = mitk::DataNode::New(); m_newfibersFibersData = vtkSmartPointer::New(); m_newfibersFibersData->SetPoints(vtkSmartPointer::New()); m_newfibersBundle = mitk::FiberBundle:: New(m_newfibersFibersData); m_newfibersFibersData->SetLines(vtkSmartPointer::New()); // node->SetData( m_newfibersBundle ); // m_newfibersBundleNode = node ; MITK_INFO << "Create Bundle"; } mitk::FiberBundle::Pointer fib = dynamic_cast(m_SelectedFB.at(0)->GetData()); // mitk::FiberBundle::Pointer fib = dynamic_cast(m_trainbundle->GetData()); vtkSmartPointer vNewPolyData = vtkSmartPointer::New(); vtkSmartPointer vNewLines = vtkSmartPointer::New(); vtkSmartPointer vNewPoints = vtkSmartPointer::New(); vtkSmartPointer weights = vtkSmartPointer::New(); // weights->SetNumberOfValues(this->GetNumFibers()+fib->GetNumFibers()); // MITK_INFO << fib->GetNumFibers(); // std::vector myvec; // for (unsigned int k=0; kGetNumFibers(); k++) // { // myvec.push_back(k); // } // std::random_shuffle(std::begin(myvec), std::end(myvec)); /* Check weather all Streamlines of the bundles are labeled... If all are labeled Skip for Loop*/ unsigned int counter = 0; - int thresh1; - int thresh2; - thresh2 = m_Controls->m_NumRandomFibers->value()*(m_RandomExtractionCounter+1); - thresh1 = m_Controls->m_NumRandomFibers->value()*(m_RandomExtractionCounter); - if (thresh1>fib->GetFiberPolyData()->GetNumberOfCells()) - { - thresh1=fib->GetFiberPolyData()->GetNumberOfCells(); - } - if (thresh2>fib->GetFiberPolyData()->GetNumberOfCells()) - { - thresh2=fib->GetFiberPolyData()->GetNumberOfCells(); - } +// int thresh1; +// int thresh2; +// thresh2 = m_Controls->m_NumRandomFibers->value()*(m_RandomExtractionCounter+1); +// thresh1 = m_Controls->m_NumRandomFibers->value()*(m_RandomExtractionCounter); +// if (thresh1>fib->GetFiberPolyData()->GetNumberOfCells()) +// { +// thresh1=fib->GetFiberPolyData()->GetNumberOfCells(); +// } +// if (thresh2>fib->GetFiberPolyData()->GetNumberOfCells()) +// { +// thresh2=fib->GetFiberPolyData()->GetNumberOfCells(); +// } - if (thresh1!=fib->GetFiberPolyData()->GetNumberOfCells()) +// if (thresh1!=fib->GetFiberPolyData()->GetNumberOfCells()) + if (m_Controls->m_NumRandomFibers->value()!=fib->GetFiberPolyData()->GetNumberOfCells()) { - for ( int i=thresh1; im_NumRandomFibers->value(); i++) { vtkCell* cell = fib->GetFiberPolyData()->GetCell(i); auto numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); vtkSmartPointer container = vtkSmartPointer::New(); for (unsigned int j=0; jGetPoint(j, p); vtkIdType id = vNewPoints->InsertNextPoint(p); container->GetPointIds()->InsertNextId(id); } weights->InsertValue(counter, fib->GetFiberWeight(i)); vNewLines->InsertNextCell(container); + counter++; } + for ( int i=0; im_NumRandomFibers->value(); i++) + { + fib->GetFiberPolyData()->DeleteCell(i); + } + fib->GetFiberPolyData()->RemoveDeletedCells(); + + MITK_INFO << fib->GetFiberPolyData()->GetNumberOfCells(); +// m_SelectedFB.at(0)->SetData(fib); vNewPolyData->SetLines(vNewLines); vNewPolyData->SetPoints(vNewPoints); m_newfibersFibersData = vtkSmartPointer::New(); m_newfibersFibersData->SetPoints(vtkSmartPointer::New()); m_newfibersFibersData->SetLines(vtkSmartPointer::New()); m_newfibersFibersData->SetPoints(vNewPoints); m_newfibersFibersData->SetLines(vNewLines); m_newfibersBundle = mitk::FiberBundle::New(vNewPolyData); m_newfibersBundle->SetFiberColors(255, 255, 255); m_newfibersBundle->SetFiberWeights(weights); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(m_newfibersBundle); node->SetName("ToLabel"); m_newfibersBundleNode = node; // MITK_INFO << "Number of Streamlines in first function"; // MITK_INFO << m_newfibersBundleNode->GetData()->GetFiberPolyData()->GetNumberOfCells(); this->GetDataStorage()->Add(m_newfibersBundleNode); m_RandomExtractionCounter++; } m_Controls->m_ErazorButton->setChecked(true); UpdateGui(); } //void QmitkInteractiveFiberDissectionView::ExtractClosestFibersFromTractogram() //{ // m_SelectedFB.at(0)->SetVisibility(false); // m_Controls->m_ErazorButton->setChecked(false); // MITK_INFO << "Number of Fibers to extract from Tractogram: "; // MITK_INFO << m_Controls->m_NumRandomFibers->value(); // if (this->GetDataStorage()->Exists(m_newfibersBundleNode)) // { // MITK_INFO << "To Label Bundle Exists"; // mitk::FiberBundle::Pointer Stack = dynamic_cast(m_newfibersBundleNode->GetData()); // this->GetDataStorage()->Remove(m_newfibersBundleNode); // mitk::DataNode::Pointer node = mitk::DataNode::New(); // m_newfibersFibersData = vtkSmartPointer::New(); // m_newfibersFibersData->SetPoints(vtkSmartPointer::New()); // m_newfibersBundle = mitk::FiberBundle:: New(m_newfibersFibersData); // m_newfibersFibersData->SetLines(vtkSmartPointer::New()); //// node->SetData( m_newfibersBundle ); //// m_newfibersBundleNode = node ; // MITK_INFO << "Create Bundle"; // } // mitk::FiberBundle::Pointer fib = dynamic_cast(m_SelectedFB.at(0)->GetData()); //// mitk::FiberBundle::Pointer fib = dynamic_cast(m_trainbundle->GetData()); // vtkSmartPointer vNewPolyData = vtkSmartPointer::New(); // vtkSmartPointer vNewLines = vtkSmartPointer::New(); // vtkSmartPointer vNewPoints = vtkSmartPointer::New(); // vtkSmartPointer weights = vtkSmartPointer::New(); //// weights->SetNumberOfValues(this->GetNumFibers()+fib->GetNumFibers()); //// MITK_INFO << fib->GetNumFibers(); //// std::vector myvec; //// for (unsigned int k=0; kGetNumFibers(); k++) //// { //// myvec.push_back(k); //// } //// std::random_shuffle(std::begin(myvec), std::end(myvec)); // /* Check weather all Streamlines of the bundles are labeled... If all are labeled Skip for Loop*/ // unsigned int counter = 0; // int thresh1; // int thresh2; // thresh2 = m_Controls->m_NumRandomFibers->value()*(m_RandomExtractionCounter+1); // thresh1 = m_Controls->m_NumRandomFibers->value()*(m_RandomExtractionCounter); // if (thresh1>fib->GetFiberPolyData()->GetNumberOfCells()) // { // thresh1=fib->GetFiberPolyData()->GetNumberOfCells(); // } // if (thresh2>fib->GetFiberPolyData()->GetNumberOfCells()) // { // thresh2=fib->GetFiberPolyData()->GetNumberOfCells(); // } // if (thresh1!=fib->GetFiberPolyData()->GetNumberOfCells()) // { // for ( int i=thresh1; iGetFiberPolyData()->GetCell(i); // auto numPoints = cell->GetNumberOfPoints(); // vtkPoints* points = cell->GetPoints(); // vtkSmartPointer container = vtkSmartPointer::New(); // for (unsigned int j=0; jGetPoint(j, p); // vtkIdType id = vNewPoints->InsertNextPoint(p); // container->GetPointIds()->InsertNextId(id); // } // weights->InsertValue(counter, fib->GetFiberWeight(i)); // vNewLines->InsertNextCell(container); // counter++; // } // vNewPolyData->SetLines(vNewLines); // vNewPolyData->SetPoints(vNewPoints); // m_newfibersFibersData = vtkSmartPointer::New(); // m_newfibersFibersData->SetPoints(vtkSmartPointer::New()); // m_newfibersFibersData->SetLines(vtkSmartPointer::New()); // m_newfibersFibersData->SetPoints(vNewPoints); // m_newfibersFibersData->SetLines(vNewLines); // m_newfibersBundle = mitk::FiberBundle::New(vNewPolyData); // m_newfibersBundle->SetFiberColors(255, 255, 255); // m_newfibersBundle->SetFiberWeights(weights); // mitk::DataNode::Pointer node = mitk::DataNode::New(); // node->SetData(m_newfibersBundle); // node->SetName("ToLabel"); // m_newfibersBundleNode = node; //// MITK_INFO << "Number of Streamlines in first function"; //// MITK_INFO << m_newfibersBundleNode->GetData()->GetFiberPolyData()->GetNumberOfCells(); // this->GetDataStorage()->Add(m_newfibersBundleNode); // m_RandomExtractionCounter++; // } // m_Controls->m_ErazorButton->setChecked(true); // UpdateGui(); //} void QmitkInteractiveFiberDissectionView::RemovefromBundle( bool checked ) { if (checked) { if (m_StreamlineInteractor.IsNull()) { this->CreateStreamlineInteractor(); mitk::FiberBundle::Pointer m_negativeBundle = mitk::FiberBundle::New(); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetName("-Bundle"); node->SetData(m_negativeBundle); m_negativeBundleNode = node; this->GetDataStorage()->Add(m_negativeBundleNode); m_StreamlineInteractor->EnableInteraction(true); m_StreamlineInteractor->LabelfromPrediction(false); m_StreamlineInteractor->SetNegativeNode(m_negativeBundleNode); - m_StreamlineInteractor->SetPositiveNode(m_positivBundlesNode); + m_StreamlineInteractor->SetPositiveNode(m_positiveBundleNode); m_StreamlineInteractor->SetToLabelNode(m_newfibersBundleNode); } else { m_StreamlineInteractor->EnableInteraction(true); m_StreamlineInteractor->LabelfromPrediction(false); - m_StreamlineInteractor->SetPositiveNode(m_positivBundlesNode); + m_StreamlineInteractor->SetPositiveNode(m_positiveBundleNode); m_StreamlineInteractor->SetToLabelNode(m_newfibersBundleNode); } } else { m_StreamlineInteractor->EnableInteraction(false); // m_StreamlineInteractor = nullptr; } - - - - - - UpdateGui(); } void QmitkInteractiveFiberDissectionView::CreateStreamlineInteractor() { m_StreamlineInteractor = mitk::StreamlineInteractor::New(); m_StreamlineInteractor->LoadStateMachine("Streamline3DStates.xml", us::ModuleRegistry::GetModule("MitkFiberDissection")); m_StreamlineInteractor->SetEventConfig("Streamline3DConfig.xml", us::ModuleRegistry::GetModule("MitkFiberDissection")); // m_StreamlineInteractor->SetRotationEnabled(rotationEnabled); } void QmitkInteractiveFiberDissectionView::StartAlgorithm() { m_negativeBundle = dynamic_cast(m_negativeBundleNode->GetData()); if (m_activeCycleCounter==0) { int neg_cells; int pos_cells; neg_cells = m_negativeBundle->GetFiberPolyData()->GetNumberOfCells(); pos_cells = m_positiveBundle->GetFiberPolyData()->GetNumberOfCells(); m_initRandom = neg_cells - pos_cells; MITK_INFO << m_initRandom; } this->GetDataStorage()->Remove(m_UncertaintyLabelNode); this->GetDataStorage()->Remove(m_DistanceLabelNode); // vtkSmartPointer< vtkFloatArray > weights = m_positiveBundle->GetFiberWeights(); // MITK_INFO << weights->GetNumberOfValues(); // MITK_INFO << m_positiveBundle->GetNumFibers(); // for (unsigned int k=0; kGetNumFibers(); k++) // { // m_positiveBundle->SetFiberWeight(k, 1.0); // } // vtkSmartPointer< vtkFloatArray > newweights = m_positiveBundle->GetFiberWeights(); // MITK_INFO << newweights->GetNumberOfValues(); + MITK_INFO << "Clean Test Data"; + +// this->CleanTestArray(); + + mitk::FiberBundle::Pointer fib = dynamic_cast(m_SelectedFB.at(0)->GetData()); + MITK_INFO << fib->GetFiberPolyData()->GetNumberOfCells(); + fib->GetFiberPolyData()->RemoveDeletedCells(); + MITK_INFO << fib->GetFiberPolyData()->GetNumberOfCells(); + m_Controls->m_unclabeling->setChecked(false); m_Controls->m_distlabeling->setChecked(false); m_Controls->m_predlabeling->setChecked(false); classifier.reset(); MITK_INFO << "Extract Features"; classifier = std::make_shared(); classifier->SetInitRandom(m_initRandom); classifier->SetActiveCycle(m_activeCycleCounter); classifier->SetTractogramPlus(m_positiveBundle); classifier->SetTractogramMinus(m_negativeBundle); classifier->SetTractogramPrototypes(dynamic_cast(m_Controls->m_PrototypeBox->GetSelectedNode()->GetData()), m_Controls->m_useStandardP->isChecked()); classifier->SetTractogramTest(dynamic_cast(m_SelectedFB.at(0)->GetData()), m_SelectedFB.at(0)->GetName()); // classifier->SetTractogramTest(dynamic_cast(m_trainbundle->GetData()), m_trainbundle->GetName()); classifier->Update(); m_index = classifier->m_index; MITK_INFO << "Number of Cycles"; MITK_INFO << m_activeCycleCounter; m_activeCycleCounter += 1; // m_Prediction = classifier->CreatePrediction(m_index.at(0)); // mitk::DataNode::Pointer node = mitk::DataNode::New(); // node->SetData(m_Prediction); // node->SetName("Prediction"); // m_PredictionNode = node; // this->GetDataStorage()->Add(m_PredictionNode); // m_UncertaintyLabel = classifier->m_UncertaintyLabel; // mitk::DataNode::Pointer node2 = mitk::DataNode::New(); // node2->SetData(m_UncertaintyLabel); // node2->SetName("UncertaintyLabels"); // m_UncertaintyLabelNode = node2; // MITK_INFO << "Number of Streamlines in first function"; // MITK_INFO << m_newfibersBundleNode->GetData()->GetFiberPolyData()->GetNumberOfCells(); // this->GetDataStorage()->Add(m_UncertaintyLabelNode); // this->GetDataStorage()->Add(m_PredictionNode); // classifier->GetData(); // MITK_INFO << data.at(0); // MITK_INFO << data.at(1); // cv::Ptr m_traindata = classifier->GetData(); // MITK_INFO << classifier->m_labels; // MITK_INFO << data.at(1); // MITK_INFO << "Start Classification"; // classifier->CreateClassifier(); // cv::Mat curdata = classifier->StartAlgorithm(); // MITK_INFO << curdata; MITK_INFO << "Algorithm run succesfully"; - + mitk::DataNode::Pointer node = mitk::DataNode::New(); +// cv::Ptr statistic_model = classifier->statistic_model; +// node->SetData(statistic_model); + this->GetDataStorage()->Add(node); m_Controls->m_CreatePrediction->setEnabled(true); UpdateGui(); } void QmitkInteractiveFiberDissectionView::CreatePredictionNode() { MITK_INFO << "Create Prediction"; - m_Prediction = classifier->CreatePrediction(m_index.at(0)); + m_Prediction = classifier->CreatePrediction(m_index.at(0), false); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(m_Prediction); auto s = std::to_string(m_activeCycleCounter); node->SetName("Prediction"+s); m_PredictionNode = node; this->GetDataStorage()->Add(m_PredictionNode); UpdateGui(); } void QmitkInteractiveFiberDissectionView::CreateCertainNode() { MITK_INFO << "Create Certain Data"; - m_CertainMinus = classifier->CreatePrediction(m_index.at(3)); + m_CertainMinus = classifier->CreatePrediction(m_index.at(2), false); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(m_CertainMinus); auto s = std::to_string(m_activeCycleCounter); node->SetName("m_CertainMinus"+s); m_CertainMinusNode = node; this->GetDataStorage()->Add(m_CertainMinusNode); // m_CertainPlus = classifier->CreatePrediction(m_index.at(4)); // mitk::DataNode::Pointer node2= mitk::DataNode::New(); // node2->SetData(m_CertainPlus); // node2->SetName("m_CertainPlus"+s); // m_CertainPlusNode = node2; // this->GetDataStorage()->Add(m_CertainPlusNode); // m_CertainBetweenMinus = classifier->CreatePrediction(m_index.at(4)); // mitk::DataNode::Pointer node3 = mitk::DataNode::New(); // node3->SetData(m_CertainBetweenMinus); // node3->SetName("m_CertainBetweenMinus"+s); // m_CertainBetweenMinusNode = node3; // this->GetDataStorage()->Add(m_CertainBetweenMinusNode); // m_CertainBetweenPlus = classifier->CreatePrediction(m_index.at(6)); // mitk::DataNode::Pointer node4= mitk::DataNode::New(); // node4->SetData(m_CertainBetweenPlus); // node4->SetName("m_CertainBetweenPlus"+s); // m_CertainBetweenPlusNode = node4; // this->GetDataStorage()->Add(m_CertainBetweenPlusNode); } +void QmitkInteractiveFiberDissectionView::RemoveCertainData() +{ + mitk::FiberBundle::Pointer fib = dynamic_cast(m_SelectedFB.at(0)->GetData()); + MITK_INFO << "Length of certain negativ data:"; + MITK_INFO << m_index.at(2).size(); + MITK_INFO << "Length of Testdata"; + MITK_INFO << fib->GetFiberPolyData()->GetNumberOfCells(); + for (unsigned int i=0; i< m_index.at(2).size(); i++) + { + fib->GetFiberPolyData()->DeleteCell(m_index.at(2).at(i)); + } +// fib->GetFiberPolyData()->RemoveDeletedCells(); + + MITK_INFO << "Length of Testdata"; + MITK_INFO << fib->GetFiberPolyData()->GetNumberOfCells(); +} + void QmitkInteractiveFiberDissectionView::CreateUncertaintySampleNode() { MITK_INFO << "Create Fibers to label based on Uncertainty"; std::vector myvec = m_index.at(1); myvec.resize(m_Controls->m_Numtolabel->value()); MITK_INFO << m_index.at(1).size(); MITK_INFO << myvec.size(); - m_UncertaintyLabel = classifier->CreatePrediction(myvec); + m_UncertaintyLabel = classifier->CreatePrediction(myvec, true); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(m_UncertaintyLabel); auto s = std::to_string(m_activeCycleCounter); node->SetName("UncertaintyLabel"+s); m_UncertaintyLabelNode = node; this->GetDataStorage()->Add(m_UncertaintyLabelNode); UpdateGui(); } void QmitkInteractiveFiberDissectionView::CreateDistanceSampleNode() { - MITK_INFO << "Create Fibers to label based on Distance in Features-Space"; - std::vector myvec = m_index.at(2); - myvec.resize(m_Controls->m_Numtolabel2->value()); - MITK_INFO << m_index.at(2).size(); - MITK_INFO << myvec.size(); - - - m_DistanceLabel = classifier->CreatePrediction(myvec); +// MITK_INFO << "Create Fibers to label based on Distance in Features-Space"; +// std::vector myvec = m_index.at(2); +// myvec.resize(m_Controls->m_Numtolabel2->value()); +// MITK_INFO << m_index.at(2).size(); +// MITK_INFO << myvec.size(); + + float myval = m_Controls->m_subsetfft->value() * 0.01; + MITK_INFO << myval; + std::vector> curidx; + curidx = classifier->GetDistanceData(myval); + std::vector myvec = curidx.at(0); + myvec.resize(m_Controls->m_Numtolabel2->value()); + MITK_INFO << m_index.at(2).size(); + MITK_INFO << myvec.size(); + m_DistanceLabel = classifier->CreatePrediction(myvec, true); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(m_DistanceLabel); auto s = std::to_string(m_activeCycleCounter); node->SetName("DistanceLabel"+s); m_DistanceLabelNode = node; this->GetDataStorage()->Add(m_DistanceLabelNode); UpdateGui(); } void QmitkInteractiveFiberDissectionView::RemovefromUncertainty( bool checked ) { if (checked) { m_UncertaintyLabel->SetFiberColors(255, 255, 255); m_StreamlineInteractor->EnableInteraction(true); m_StreamlineInteractor->LabelfromPrediction(false); m_StreamlineInteractor->SetToLabelNode(m_UncertaintyLabelNode); } else { m_StreamlineInteractor->EnableInteraction(false); // m_StreamlineInteractor = nullptr; } RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkInteractiveFiberDissectionView::RemovefromDistance( bool checked ) { if (checked) { m_DistanceLabel->SetFiberColors(255, 255, 255); m_StreamlineInteractor->EnableInteraction(true); m_StreamlineInteractor->LabelfromPrediction(false); m_StreamlineInteractor->SetToLabelNode(m_DistanceLabelNode); } else { m_StreamlineInteractor->EnableInteraction(false); // m_StreamlineInteractor = nullptr; } RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkInteractiveFiberDissectionView::RemovefromPrediction( bool checked ) { if (checked) { // m_Prediction->SetFiberColors(255, 255, 255); m_StreamlineInteractor->EnableInteraction(true); m_StreamlineInteractor->LabelfromPrediction(true); m_StreamlineInteractor->SetToLabelNode(m_PredictionNode); } else { m_StreamlineInteractor->EnableInteraction(false); // m_StreamlineInteractor = nullptr; } } void QmitkInteractiveFiberDissectionView::RemovefromSelection( bool checked ) { if (checked) { // m_Prediction->SetFiberColors(255, 255, 255); m_StreamlineInteractor->EnableInteraction(true); m_StreamlineInteractor->LabelfromPrediction(true); m_StreamlineInteractor->SetToLabelNode(m_SelectedFB.at(0)); } else { m_StreamlineInteractor->EnableInteraction(false); // m_StreamlineInteractor = nullptr; } } void QmitkInteractiveFiberDissectionView::StartValidation() { validater.reset(); mitk::DataNode::Pointer prednode = m_Controls->m_BundleBox->GetSelectedNode(); mitk::FiberBundle::Pointer pred = dynamic_cast(prednode->GetData()); mitk::DataNode::Pointer gtnode = m_Controls->m_BundleBox->GetSelectedNode(); mitk::FiberBundle::Pointer gt = dynamic_cast(gtnode->GetData()); // mitk::FiberBundle::Pointer pred = dynamic_cast(m_Controls->m_PredictionBox->GetSelectedNode()->GetData()); // mitk::FiberBundle::Pointer gt = dynamic_cast(m_Controls->m_GroundtruthBox->GetSelectedNode()->GetData()); validater= std::make_shared(); validater->SetTractogramPrototypes(dynamic_cast(m_Controls->m_PrototypeBox->GetSelectedNode()->GetData()), m_Controls->m_useStandardP->isChecked()); MITK_INFO << "Prototypes loaded"; validater->SetTractogramPrediction(dynamic_cast(m_Controls->m_PredictionBox->GetSelectedNode()->GetData())); MITK_INFO << "Prediction loaded"; validater->SetTractogramGroundtruth(dynamic_cast(m_Controls->m_GroundtruthBox->GetSelectedNode()->GetData())); MITK_INFO << "Groundtruth loaded"; validater->SetActiveCycle(m_activeCycleCounter); validater->SetTractogramTest(dynamic_cast(m_SelectedFB.at(0)->GetData()), m_SelectedFB.at(0)->GetName()); // classifier->SetTractogramTest(dynamic_cast(m_trainbundle->GetData()), m_trainbundle->GetName()); MITK_INFO << "Testdata loaded"; vnl_vector metrics; metrics = validater->ValidationPipe(); m_metrics.push_back(metrics); std::ofstream metricsfile; metricsfile.open("/home/r948e/mycsv/metrics_" + std::to_string(m_activeCycleCounter) + ".csv"); for (unsigned int i = 0; i < m_metrics.size(); i++) { metricsfile << m_metrics.at(i) << std::endl; } metricsfile.close(); MITK_INFO << "Validation run succesfully"; UpdateGui(); } void QmitkInteractiveFiberDissectionView::AutomaticLabelling() { - mitk::FiberBundle::Pointer fib = dynamic_cast(m_SelectedFB.at(0)->GetData()); - mitk::FiberBundle::Pointer fib_true = dynamic_cast(m_Controls->m_GroundtruthBox->GetSelectedNode()->GetData()); - vtkCell* cell; - vtkCell* cell2; +// mitk::FiberBundle::Pointer fib = dynamic_cast(m_SelectedFB.at(0)->GetData()); +// mitk::FiberBundle::Pointer fib_true = dynamic_cast(m_Controls->m_GroundtruthBox->GetSelectedNode()->GetData()); +// vtkCell* cell; +// vtkCell* cell2; +// for (int i=0; iGetFiberPolyData()->GetNumberOfCells(); i++) +// { +// cell = fib->GetFiberPolyData()->GetCell(i); +// for (int k=0; kGetFiberPolyData()->GetNumberOfCells(); k++ ) +// { +// cell2 = fib_true->GetFiberPolyData()->GetCell(i); +// if (cell==cell2) +// MITK_INFO << "Same"; +// } +// } + + mitk::FiberBundle::Pointer fib = dynamic_cast(m_PredictionNode->GetData()); + mitk::FiberBundle::Pointer fib_true = dynamic_cast(m_positiveBundleNode->GetData()); + + vtkSmartPointer vNewPolyData = vtkSmartPointer::New(); + vtkSmartPointer vNewLines = vtkSmartPointer::New(); + vtkSmartPointer vNewPoints = vtkSmartPointer::New(); + + vtkSmartPointer weights = vtkSmartPointer::New(); + + /* Check wether all Streamlines of the bundles are labeled... If all are labeled Skip for Loop*/ + unsigned int counter = 0; + for (int i=0; iGetFiberPolyData()->GetNumberOfCells(); i++) { - cell = fib->GetFiberPolyData()->GetCell(i); - for (int k=0; kGetFiberPolyData()->GetNumberOfCells(); k++ ) - { - cell2 = fib_true->GetFiberPolyData()->GetCell(i); - if (cell==cell2) - MITK_INFO << "Same"; - } + vtkCell* cell = fib->GetFiberPolyData()->GetCell(i); + auto numPoints = cell->GetNumberOfPoints(); + vtkPoints* points = cell->GetPoints(); + + vtkSmartPointer container = vtkSmartPointer::New(); + for (unsigned int j=0; jGetPoint(j, p); + + vtkIdType id = vNewPoints->InsertNextPoint(p); + container->GetPointIds()->InsertNextId(id); + } + weights->InsertValue(counter, fib->GetFiberWeight(i)); + vNewLines->InsertNextCell(container); + counter++; + } + for (int i=0; iGetFiberPolyData()->GetNumberOfCells(); i++) + { + vtkCell* cell = fib_true->GetFiberPolyData()->GetCell(i); + auto numPoints = cell->GetNumberOfPoints(); + vtkPoints* points = cell->GetPoints(); + vtkSmartPointer container = vtkSmartPointer::New(); + for (unsigned int j=0; jGetPoint(j, p); + + vtkIdType id = vNewPoints->InsertNextPoint(p); + container->GetPointIds()->InsertNextId(id); + } + weights->InsertValue(counter, fib_true->GetFiberWeight(i)); + vNewLines->InsertNextCell(container); + counter++; + } + vNewPolyData->SetLines(vNewLines); + vNewPolyData->SetPoints(vNewPoints); + + mitk::FiberBundle::Pointer MergedPrediction = mitk::FiberBundle::New(vNewPolyData); + MergedPrediction->SetFiberWeights(weights); + + mitk::DataNode::Pointer node = mitk::DataNode::New(); + node->SetData(MergedPrediction); + node->SetName("MergedPrediction"); + this->GetDataStorage()->Add(node); + + } +void QmitkInteractiveFiberDissectionView::CleanTestArray() +{ + + mitk::FiberBundle::Pointer fib_pos = dynamic_cast(m_positiveBundleNode->GetData()); + mitk::FiberBundle::Pointer fib_neg = dynamic_cast(m_negativeBundleNode->GetData()); + mitk::FiberBundle::Pointer fib = dynamic_cast(m_SelectedFB.at(0)->GetData()); + vtkCell* cur_cell; + vtkCell* cur_cell2; + MITK_INFO << fib_neg->GetFiberPolyData()->GetNumberOfCells(); + MITK_INFO << fib_pos->GetFiberPolyData()->GetNumberOfCells(); + MITK_INFO << fib->GetFiberPolyData()->GetNumberOfCells(); + + + std::vector array; + std::vector array2; + + + // cv::parallel_for_(cv::Range(0, fib->GetFiberPolyData()->GetNumberOfCells()), [&](const cv::Range &range) + // { + // for (int i = range.start; i < range.end; i++) + for (int i=0; iGetFiberPolyData()->GetNumberOfCells(); i++) + { + cur_cell = fib->GetFiberPolyData()->GetCell(i); + auto numPoints = cur_cell->GetNumberOfPoints(); + vtkPoints* points = cur_cell->GetPoints(); + for (unsigned int j=0; jGetPoint(j, p); + array.push_back(*p); + } + for (int ik=0; ikGetFiberPolyData()->GetNumberOfCells(); ik++) + { + cur_cell2 = fib_neg->GetFiberPolyData()->GetCell(ik); + auto numPoints2 = cur_cell2->GetNumberOfPoints(); + vtkPoints* points2 = cur_cell2->GetPoints(); + for (unsigned int j2=0; j2GetPoint(j2, p2); + array2.push_back(*p2); + + } + if (array==array2) + { + fib->GetFiberPolyData()->DeleteCell(i); + MITK_INFO << "Delete Cell"; + } + array2.clear(); + } + for (int ik=0; ikGetFiberPolyData()->GetNumberOfCells(); ik++) + { + + cur_cell2 = fib_pos->GetFiberPolyData()->GetCell(ik); + auto numPoints2 = cur_cell2->GetNumberOfPoints(); + vtkPoints* points2 = cur_cell2->GetPoints(); + for (unsigned int j2=0; j2GetPoint(j2, p2); + array2.push_back(*p2); + } + if (array==array2) + { + fib->GetFiberPolyData()->DeleteCell(i); + MITK_INFO << "Delete Cell"; + } + array2.clear(); + } + array.clear(); + } + // }); + + fib->GetFiberPolyData()->RemoveDeletedCells(); + + MITK_INFO << fib->GetFiberPolyData()->GetNumberOfCells(); + + + +} diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionView.h b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionView.h index 8cce888..01a0f68 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionView.h +++ b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionView.h @@ -1,179 +1,181 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center. 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 QmitkInteractiveFiberDissectionView_h #define QmitkInteractiveFiberDissectionView_h #include "ui_QmitkInteractiveFiberDissectionViewControls.h" #include //Pointset #include //Pointset #include //Pointset #include //Pointset #include #include #include //Pointset #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*! \brief View to process fiber bundles. Supplies methods to extract fibers from the bundle, fiber resampling, mirroring, join and subtract bundles and much more. */ class QmitkInteractiveFiberDissectionView : public QmitkAbstractView, public mitk::IRenderWindowPartListener { // 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: typedef itk::Image< unsigned char, 3 > ItkUCharImageType; typedef itk::Image< float, 3 > ItkFloatImageType; static const std::string VIEW_ID; QmitkInteractiveFiberDissectionView(); virtual ~QmitkInteractiveFiberDissectionView(); virtual void CreateQtPartControl(QWidget *parent) override; /// /// Sets the focus to an internal widget. /// virtual void SetFocus() override; protected slots: void RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) override; //Pointset void RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderWindowPart) override; //Pointset void OnAddPointSetClicked();//Pointset void CreateStreamline(); void RemovefromBundle( bool checked ); void ExtractRandomFibersFromTractogram(); void StartAlgorithm(); void CreatePredictionNode(); void CreateCertainNode(); void CreateUncertaintySampleNode(); void CreateDistanceSampleNode(); void RemovefromUncertainty( bool checked ); void RemovefromDistance( bool checked ); void RemovefromPrediction( bool checked ); void RemovefromSelection( bool checked ); void ResampleTractogram(); void RandomPrototypes(); void SFFPrototypes(); void StartValidation(); void AutomaticLabelling(); + void RemoveCertainData(); void UpdateGui(); ///< update button activity etc. dpending on current datamanager selection protected: void OnCurrentSelectionChanged(QmitkSingleNodeSelectionWidget::NodeList nodes);//Pointset virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer part, const QList& nodes) override; void OnEndInteraction(); void CreateStreamlineInteractor(); + void CleanTestArray(); Ui::QmitkInteractiveFiberDissectionViewControls* m_Controls; int m_IterationCounter; ///< used for data node naming int m_RandomExtractionCounter; ///< used for random extracton of different Streamlines int m_activeCycleCounter; int m_initRandom; int m_createdStreamlineCounter; // int m_thresh2; std::vector m_SelectedFB; ///< selected fiber bundle nodes // mitk::DataNode::Pointer m_trainbundle; mitk::Image::Pointer m_SelectedImage; mitk::DataNode::Pointer m_SelectedPS; mitk::DataNode::Pointer m_SelectedImageNode; mitk::FiberBundle::Pointer m_positiveBundle; mitk::FiberBundle::Pointer m_newfibersBundle; mitk::FiberBundle::Pointer m_negativeBundle; mitk::FiberBundle::Pointer m_Prediction; mitk::FiberBundle::Pointer m_CertainPlus; mitk::FiberBundle::Pointer m_CertainMinus; mitk::FiberBundle::Pointer m_CertainBetweenPlus; mitk::FiberBundle::Pointer m_CertainBetweenMinus; mitk::FiberBundle::Pointer m_UncertaintyLabel; mitk::FiberBundle::Pointer m_DistanceLabel; - mitk::DataNode::Pointer m_positivBundlesNode; + mitk::DataNode::Pointer m_positiveBundleNode; mitk::DataNode::Pointer m_newfibersBundleNode; mitk::DataNode::Pointer m_negativeBundleNode; mitk::DataNode::Pointer m_PredictionNode; mitk::DataNode::Pointer m_CertainPlusNode; mitk::DataNode::Pointer m_CertainMinusNode; mitk::DataNode::Pointer m_CertainBetweenPlusNode; mitk::DataNode::Pointer m_CertainBetweenMinusNode; mitk::DataNode::Pointer m_UncertaintyLabelNode; mitk::DataNode::Pointer m_DistanceLabelNode; vtkSmartPointer m_positiveFibersData; vtkSmartPointer m_newfibersFibersData; vtkSmartPointer m_picker1; mitk::StreamlineInteractor::Pointer m_StreamlineInteractor; std::shared_ptr< mitk::StreamlineFeatureExtractor > classifier; std::shared_ptr< mitk::StreamlineFeatureExtractor > validater; std::vector> m_metrics; std::vector> m_index; }; #endif // _QMITKFIBERTRACKINGVIEW_H_INCLUDED diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionViewControls.ui b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionViewControls.ui index 1c6a75d..67ff520 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionViewControls.ui +++ b/Plugins/org.mitk.gui.qt.diffusionimaging.fiberprocessing/src/internal/QmitkInteractiveFiberDissectionViewControls.ui @@ -1,887 +1,1012 @@ QmitkInteractiveFiberDissectionViewControls 0 0 417 711 Form QCommandLinkButton:disabled { border: none; } QGroupBox { background-color: transparent; } 9 9 9 9 - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 40 - - - - Please Select Input Data Input DTI Fiber Bundle: <html><head/><body><p><span style=" color:#ff0000;">mandatory</span></p></body></html> true + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 40 + + + + true true Label Fibers QFrame::NoFrame 3 6 0 0 399 424 Generate Prototypes - - - - - - - Use Standard Prototypes - - - - - - - 10 - - - 200 - - - 100 - - - - - - - Choose own Prototypes - - - - - - - Random Extraction - - - - - - - Number of Prototypes - - - - - - - - - - true - - - Use Standard Prototypes - - - true - - - - - - - SFF Extraction - - - - - - - Extract from + + + + 0 - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Resample Bundle + + 0 + + + + 0 + 0 + 381 + 344 + + + + Defaults + + + + + + Extract from + + + + + + + + + + SFF Extraction + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 0 + 0 + 273 + 171 + + + + Advanced Settings + + + + + + Number of Prototypes + + + + + + + 10 + + + 200 + + + 100 + + + + + + + Random Extraction + + + + + + + Resample Bundle + + + + + + + true + + + Use Standard Prototypes + + + true + + + + + + + Choose own Prototypes + + + + + + + + + + Qt::Vertical + + + + 20 + 170 + + + + + + 0 0 399 424 Fiber Creation QFrame::StyledPanel QFrame::Raised Selected Streamline Pointset Qt::Horizontal 40 20 Streamline Points Qt::Vertical 20 40 Qt::Horizontal 40 20 Qt::Horizontal 40 20 Add new Streamline Pointset 0 0 0 40 Qt::Vertical 20 40 Create Streamline true 0 0 - 426 - 410 + 399 + 424 Fiber Labelling Dissect/Eraze Fibers by Erasion and Highlighting true ArrowCursor QFrame::NoFrame QFrame::Raised Label individual Streamlines Qt::Vertical 20 40 Streamlines to be labeled QFrame::StyledPanel QFrame::Raised - - - - Random Streamlines - - - - + Qt::Vertical 20 40 - - - - - - - Accept: Rightclick + alt - - - - - - - Add - - - - + 30 30 :/org.mitk.gui.qt.diffusionimaging.fiberprocessing/resources/eraze.png:/org.mitk.gui.qt.diffusionimaging.fiberprocessing/resources/eraze.png 32 32 true - + + + + Unlabel: Leftclick + shift/alt + + + + + + + Reject: Rightclick + shift + + + + + + + Label Streamlines + + + + + + + Accept: Rightclick + alt + + + + 1 2000 - 10 + 20 - - - - Unlabel: Leftclick + shift/alt - - - - - + + - Label Streamlines + Add - - + + - Reject: Rightclick + shift + Random Streamlines - + Qt::Horizontal 40 20 - - - - Closest Streamlines - - - - - - - Add - - - 0 0 399 424 Active Learning - 9 - 9 - 341 + 0 + 0 + 381 391 QFrame::StyledPanel QFrame::Raised - - - - Create Uncertanty Map - - - - - - - Add - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Train Classifier - - - - - - - Create Prediction - - - - - - - Dist: to label - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - + + + 1 - - 500 - - - 10 - - - - - - - Unc_dis_Label - - - - - - - Qt::Horizontal - - - - 84 - 22 - - - - - - - - Selection_Label - - - - - - - Unc: to label - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Add - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - 1 - - - 500 - - - 0 - - - 10 - - - - - - - Pred_Label - - - - - - - Uncertainty_Label - - - - .. - - - - - - - Certain Data - + + + + 0 + 0 + 361 + 309 + + + + Default + + + + + + Label + + + + .. + + + + + + + Qt::Horizontal + + + + 57 + 20 + + + + + + + + Qt::Horizontal + + + + 57 + 20 + + + + + + + + 1 + + + 2000 + + + 0 + + + 20 + + + + + + + Qt::Horizontal + + + + 57 + 20 + + + + + + + + Label + + + + + + + Create Prediction + + + + + + + Qt::Horizontal + + + + 57 + 20 + + + + + + + + Train Classifier + + + + + + + Unc: to label + + + + + + + Label from Uncertainy Node + + + + + + + Add + + + + + + + Label from Prediction Node + + + + + + + Qt::Horizontal + + + + 57 + 20 + + + + + + + + + + 0 + 0 + 361 + 309 + + + + Advanced + + + + + + Label from Current Selection + + + + + + + Create Uncertanty Map + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Unc_dis_Label + + + + + + + Add + + + + + + + 100 + + + 95 + + + + + + + Certain Data + + + + + + + 100 + + + + + + + 1 + + + 500 + + + 20 + + + + + + + Dist: to label + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Label + + + + + + + Remove + + + + + 0 0 399 424 Validation 10 20 351 371 QFrame::StyledPanel QFrame::Raised Qt::Vertical 20 40 - - - - Validate - - - Prediction - - - - Qt::Horizontal - - - - 40 - 20 - - - - Groundtrouth - + + + + Validate + + + + - Automatic Labelling + Merge Prediction with Labled Data QmitkDataStorageComboBox QComboBox
QmitkDataStorageComboBox.h
QmitkSingleNodeSelectionWidget QWidget
QmitkSingleNodeSelectionWidget.h
+ 1
QmitkPointListWidget QWidget
QmitkPointListWidget.h