18 #define _USE_MATH_DEFINES
27 #include <vtkPointData.h>
28 #include <vtkDataArray.h>
29 #include <vtkUnsignedCharArray.h>
30 #include <vtkPolyLine.h>
31 #include <vtkCellArray.h>
32 #include <vtkCellData.h>
33 #include <vtkIdFilter.h>
34 #include <vtkClipPolyData.h>
36 #include <vtkDoubleArray.h>
37 #include <vtkKochanekSpline.h>
38 #include <vtkParametricFunctionSource.h>
39 #include <vtkParametricSpline.h>
40 #include <vtkPolygon.h>
41 #include <vtkCleanPolyData.h>
43 #include <boost/progress.hpp>
44 #include <vtkTransformPolyDataFilter.h>
46 #include <vtkLookupTable.h>
58 m_FiberWeights->SetName(
"FIBER_WEIGHTS");
61 if (fiberPolyData !=
nullptr)
63 m_FiberPolyData = fiberPolyData;
79 newFib->SetFiberColors(this->m_FiberColors);
80 newFib->SetFiberWeights(this->m_FiberWeights);
90 auto finIt = fiberIds.begin();
91 while ( finIt != fiberIds.end() )
93 if (*finIt < 0 || *finIt>GetNumFibers()){
94 MITK_INFO <<
"FiberID can not be negative or >NumFibers!!! check id Extraction!" << *finIt;
98 vtkSmartPointer<vtkCell> fiber = m_FiberIdDataSet->GetCell(*finIt);
99 vtkSmartPointer<vtkPoints> fibPoints = fiber->GetPoints();
101 newFiber->GetPointIds()->SetNumberOfIds( fibPoints->GetNumberOfPoints() );
103 for(
int i=0; i<fibPoints->GetNumberOfPoints(); i++)
105 newFiber->GetPointIds()->SetId(i, newPointSet->GetNumberOfPoints());
106 newPointSet->InsertNextPoint(fibPoints->GetPoint(i)[0], fibPoints->GetPoint(i)[1], fibPoints->GetPoint(i)[2]);
109 newLineSet->InsertNextCell(newFiber);
113 newFiberPolyData->SetPoints(newPointSet);
114 newFiberPolyData->SetLines(newLineSet);
115 return newFiberPolyData;
123 MITK_WARN <<
"trying to call AddBundle with NULL argument";
134 weights->SetNumberOfValues(this->GetNumFibers()+fib->
GetNumFibers());
136 unsigned int counter = 0;
137 for (
int i=0; i<m_FiberPolyData->GetNumberOfCells(); i++)
139 vtkCell* cell = m_FiberPolyData->GetCell(i);
140 int numPoints = cell->GetNumberOfPoints();
141 vtkPoints* points = cell->GetPoints();
144 for (
int j=0; j<numPoints; j++)
147 points->GetPoint(j, p);
149 vtkIdType
id = vNewPoints->InsertNextPoint(p);
150 container->GetPointIds()->InsertNextId(
id);
152 weights->InsertValue(counter, this->GetFiberWeight(i));
153 vNewLines->InsertNextCell(container);
161 int numPoints = cell->GetNumberOfPoints();
162 vtkPoints* points = cell->GetPoints();
165 for (
int j=0; j<numPoints; j++)
168 points->GetPoint(j, p);
170 vtkIdType
id = vNewPoints->InsertNextPoint(p);
171 container->GetPointIds()->InsertNextId(
id);
174 vNewLines->InsertNextCell(container);
179 vNewPolyData->SetPoints(vNewPoints);
180 vNewPolyData->SetLines(vNewLines);
184 newFib->SetFiberWeights(weights);
198 boost::progress_display disp(m_NumFibers);
199 for(
int i=0; i<m_NumFibers; i++ )
202 vtkCell* cell = m_FiberPolyData->GetCell(i);
203 int numPoints = cell->GetNumberOfPoints();
204 vtkPoints* points = cell->GetPoints();
206 if (points==
nullptr || numPoints<=0)
210 bool contained =
false;
211 for(
int i2=0; i2<numFibers2; i2++ )
214 int numPoints2 = cell2->GetNumberOfPoints();
215 vtkPoints* points2 = cell2->GetPoints();
217 if (points2==
nullptr)
221 if (numPoints2==numPoints)
223 itk::Point<float, 3> point_start = GetItkPoint(points->GetPoint(0));
224 itk::Point<float, 3> point_end = GetItkPoint(points->GetPoint(numPoints-1));
225 itk::Point<float, 3> point2_start = GetItkPoint(points2->GetPoint(0));
226 itk::Point<float, 3> point2_end = GetItkPoint(points2->GetPoint(numPoints2-1));
228 if ((point_start.SquaredEuclideanDistanceTo(point2_start)<=
mitk::eps && point_end.SquaredEuclideanDistanceTo(point2_end)<=
mitk::eps) ||
229 (point_start.SquaredEuclideanDistanceTo(point2_end)<=
mitk::eps && point_end.SquaredEuclideanDistanceTo(point2_start)<=
mitk::eps))
242 for(
int j=0; j<numPoints; j++)
244 vtkIdType
id = vNewPoints->InsertNextPoint(points->GetPoint(j));
245 container->GetPointIds()->InsertNextId(
id);
247 vNewLines->InsertNextCell(container);
250 if(vNewLines->GetNumberOfCells()==0)
253 vNewPolyData->SetPoints(vNewPoints);
254 vNewPolyData->SetLines(vNewLines);
262 itk::Point<float, 3> itkPoint;
263 itkPoint[0] = point[0];
264 itkPoint[1] = point[1];
265 itkPoint[2] = point[2];
274 if (fiberPD ==
nullptr)
278 m_FiberPolyData->DeepCopy(fiberPD);
279 ColorFibersByOrientation();
282 m_NumFibers = m_FiberPolyData->GetNumberOfLines();
285 UpdateFiberGeometry();
294 return m_FiberPolyData;
307 vtkPoints* extrPoints =
nullptr;
308 extrPoints = m_FiberPolyData->GetPoints();
310 if (extrPoints!=
nullptr)
311 numOfPoints = extrPoints->GetNumberOfPoints();
314 unsigned char rgba[4] = {0,0,0,0};
315 int componentSize = 4;
317 m_FiberColors->Allocate(numOfPoints * componentSize);
318 m_FiberColors->SetNumberOfComponents(componentSize);
319 m_FiberColors->SetName(
"FIBER_COLORS");
321 int numOfFibers = m_FiberPolyData->GetNumberOfLines();
326 vtkCellArray* fiberList = m_FiberPolyData->GetLines();
327 fiberList->InitTraversal();
328 for (
int fi=0; fi<numOfFibers; ++fi) {
331 vtkIdType pointsPerFiber;
332 fiberList->GetNextCell(pointsPerFiber, idList);
335 if (pointsPerFiber > 1)
338 for (
int i=0; i <pointsPerFiber; ++i)
341 if (i<pointsPerFiber-1 && i > 0)
344 vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(idList[i])[0], extrPoints->GetPoint(idList[i])[1],extrPoints->GetPoint(idList[i])[2]);
345 vnl_vector_fixed< double, 3 > nextPntvtk(extrPoints->GetPoint(idList[i+1])[0], extrPoints->GetPoint(idList[i+1])[1], extrPoints->GetPoint(idList[i+1])[2]);
346 vnl_vector_fixed< double, 3 > prevPntvtk(extrPoints->GetPoint(idList[i-1])[0], extrPoints->GetPoint(idList[i-1])[1], extrPoints->GetPoint(idList[i-1])[2]);
348 vnl_vector_fixed< double, 3 > diff1;
349 diff1 = currentPntvtk - nextPntvtk;
351 vnl_vector_fixed< double, 3 > diff2;
352 diff2 = currentPntvtk - prevPntvtk;
354 vnl_vector_fixed< double, 3 > diff;
355 diff = (diff1 - diff2) / 2.0;
358 rgba[0] = (
unsigned char) (255.0 * std::fabs(diff[0]));
359 rgba[1] = (
unsigned char) (255.0 * std::fabs(diff[1]));
360 rgba[2] = (
unsigned char) (255.0 * std::fabs(diff[2]));
361 rgba[3] = (
unsigned char) (255.0);
367 vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(idList[i])[0], extrPoints->GetPoint(idList[i])[1],extrPoints->GetPoint(idList[i])[2]);
368 vnl_vector_fixed< double, 3 > nextPntvtk(extrPoints->GetPoint(idList[i+1])[0], extrPoints->GetPoint(idList[i+1])[1], extrPoints->GetPoint(idList[i+1])[2]);
370 vnl_vector_fixed< double, 3 > diff1;
371 diff1 = currentPntvtk - nextPntvtk;
374 rgba[0] = (
unsigned char) (255.0 * std::fabs(diff1[0]));
375 rgba[1] = (
unsigned char) (255.0 * std::fabs(diff1[1]));
376 rgba[2] = (
unsigned char) (255.0 * std::fabs(diff1[2]));
377 rgba[3] = (
unsigned char) (255.0);
379 else if (i==pointsPerFiber-1)
382 vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(idList[i])[0], extrPoints->GetPoint(idList[i])[1],extrPoints->GetPoint(idList[i])[2]);
383 vnl_vector_fixed< double, 3 > prevPntvtk(extrPoints->GetPoint(idList[i-1])[0], extrPoints->GetPoint(idList[i-1])[1], extrPoints->GetPoint(idList[i-1])[2]);
385 vnl_vector_fixed< double, 3 > diff2;
386 diff2 = currentPntvtk - prevPntvtk;
389 rgba[0] = (
unsigned char) (255.0 * std::fabs(diff2[0]));
390 rgba[1] = (
unsigned char) (255.0 * std::fabs(diff2[1]));
391 rgba[2] = (
unsigned char) (255.0 * std::fabs(diff2[2]));
392 rgba[3] = (
unsigned char) (255.0);
394 m_FiberColors->InsertTupleValue(idList[i], rgba);
397 else if (pointsPerFiber == 1)
404 MITK_DEBUG <<
"Fiber with 0 points detected... please check your tractography algorithm!" ;
408 m_UpdateTime3D.Modified();
409 m_UpdateTime2D.Modified();
412 void mitk::FiberBundle::ColorFibersByCurvature(
bool minMaxNorm)
417 unsigned char rgba[4] = {0,0,0,0};
418 int componentSize = 4;
420 m_FiberColors->Allocate(m_FiberPolyData->GetNumberOfPoints() * componentSize);
421 m_FiberColors->SetNumberOfComponents(componentSize);
422 m_FiberColors->SetName(
"FIBER_COLORS");
426 lookupTable->SetTableRange(0.0, 0.8);
427 lookupTable->Build();
428 mitkLookup->SetVtkLookupTable(lookupTable);
431 vector< double > values;
434 MITK_INFO <<
"Coloring fibers by curvature";
435 boost::progress_display disp(m_FiberPolyData->GetNumberOfCells());
436 for (
int i=0; i<m_FiberPolyData->GetNumberOfCells(); i++)
439 vtkCell* cell = m_FiberPolyData->GetCell(i);
440 int numPoints = cell->GetNumberOfPoints();
441 vtkPoints* points = cell->GetPoints();
444 for (
int j=0; j<numPoints; j++)
448 std::vector< vnl_vector_fixed< float, 3 > > vectors;
449 vnl_vector_fixed< float, 3 > meanV; meanV.fill(0.0);
450 while(dist<window/2 && c>1)
453 points->GetPoint(c-1, p1);
455 points->GetPoint(c, p2);
457 vnl_vector_fixed< float, 3 > v;
461 dist += v.magnitude();
463 vectors.push_back(v);
470 while(dist<window/2 && c<numPoints-1)
473 points->GetPoint(c, p1);
475 points->GetPoint(c+1, p2);
477 vnl_vector_fixed< float, 3 > v;
481 dist += v.magnitude();
483 vectors.push_back(v);
491 for (
unsigned int c=0; c<vectors.size(); c++)
493 double angle = dot_product(meanV, vectors.at(c));
498 dev += acos(angle)*180/
M_PI;
500 if (vectors.size()>0)
501 dev /= vectors.size();
504 values.push_back(dev);
511 unsigned int count = 0;
512 for (
int i=0; i<m_FiberPolyData->GetNumberOfCells(); i++)
514 vtkCell* cell = m_FiberPolyData->GetCell(i);
515 int numPoints = cell->GetNumberOfPoints();
516 for (
int j=0; j<numPoints; j++)
519 double dev = values.at(count);
521 dev = (dev-
min)/(max-min);
523 lookupTable->GetColor(dev, color);
525 rgba[0] = (
unsigned char) (255.0 * color[0]);
526 rgba[1] = (
unsigned char) (255.0 * color[1]);
527 rgba[2] = (
unsigned char) (255.0 * color[2]);
528 rgba[3] = (
unsigned char) (255.0);
529 m_FiberColors->InsertTupleValue(cell->GetPointId(j), rgba);
533 m_UpdateTime3D.Modified();
534 m_UpdateTime2D.Modified();
539 for(
long i=0; i<m_FiberColors->GetNumberOfTuples(); i++)
541 double faValue = FAValArray->GetValue(i);
542 faValue = faValue * 255.0;
543 m_FiberColors->SetComponent(i,3, (
unsigned char) faValue );
545 m_UpdateTime3D.Modified();
546 m_UpdateTime2D.Modified();
551 for(
long i=0; i<m_FiberColors->GetNumberOfTuples(); i++)
552 m_FiberColors->SetComponent(i,3, 255.0 );
553 m_UpdateTime3D.Modified();
554 m_UpdateTime2D.Modified();
560 m_UpdateTime3D.Modified();
561 m_UpdateTime2D.Modified();
564 template <
typename TPixel>
568 m_FiberColors->Allocate(m_FiberPolyData->GetNumberOfPoints() * 4);
569 m_FiberColors->SetNumberOfComponents(4);
570 m_FiberColors->SetName(
"FIBER_COLORS");
574 unsigned char rgba[4] = {0,0,0,0};
575 vtkPoints* pointSet = m_FiberPolyData->GetPoints();
579 lookupTable->SetTableRange(0.0, 0.8);
580 lookupTable->Build();
581 mitkLookup->SetVtkLookupTable(lookupTable);
584 for(
long i=0; i<m_FiberPolyData->GetNumberOfPoints(); ++i)
587 px[0] = pointSet->GetPoint(i)[0];
588 px[1] = pointSet->GetPoint(i)[1];
589 px[2] = pointSet->GetPoint(i)[2];
590 double pixelValue = readimage.GetPixelByWorldCoordinates(px);
593 lookupTable->GetColor(1-pixelValue, color);
595 rgba[0] = (
unsigned char) (255.0 * color[0]);
596 rgba[1] = (
unsigned char) (255.0 * color[1]);
597 rgba[2] = (
unsigned char) (255.0 * color[2]);
599 rgba[3] = (
unsigned char) (255.0 * pixelValue);
601 rgba[3] = (
unsigned char) (255.0);
602 m_FiberColors->InsertTupleValue(i, rgba);
604 m_UpdateTime3D.Modified();
605 m_UpdateTime2D.Modified();
611 m_FiberColors->Allocate(m_FiberPolyData->GetNumberOfPoints() * 4);
612 m_FiberColors->SetNumberOfComponents(4);
613 m_FiberColors->SetName(
"FIBER_COLORS");
615 unsigned char rgba[4] = {0,0,0,0};
616 for(
long i=0; i<m_FiberPolyData->GetNumberOfPoints(); ++i)
618 rgba[0] = (
unsigned char) r;
619 rgba[1] = (
unsigned char) g;
620 rgba[2] = (
unsigned char) b;
621 rgba[3] = (
unsigned char) alpha;
622 m_FiberColors->InsertTupleValue(i, rgba);
624 m_UpdateTime3D.Modified();
625 m_UpdateTime2D.Modified();
630 if (m_FiberPolyData ==
nullptr)
634 idFiberFilter->SetInputData(m_FiberPolyData);
635 idFiberFilter->CellIdsOn();
637 idFiberFilter->SetIdsArrayName(FIBER_ID_ARRAY);
638 idFiberFilter->FieldDataOn();
639 idFiberFilter->Update();
641 m_FiberIdDataSet = idFiberFilter->GetOutput();
647 vtkSmartPointer<vtkPolyData> polyData = m_FiberPolyData;
650 float minSpacing = 1;
651 if(mask->GetSpacing()[0]<mask->GetSpacing()[1] && mask->GetSpacing()[0]<mask->GetSpacing()[2])
652 minSpacing = mask->GetSpacing()[0];
653 else if (mask->GetSpacing()[1] < mask->GetSpacing()[2])
654 minSpacing = mask->GetSpacing()[1];
656 minSpacing = mask->GetSpacing()[2];
659 fibCopy->ResampleSpline(minSpacing/5);
660 polyData = fibCopy->GetFiberPolyData();
666 boost::progress_display disp(m_NumFibers);
667 for (
int i=0; i<m_NumFibers; i++)
671 vtkCell* cell = polyData->GetCell(i);
672 int numPoints = cell->GetNumberOfPoints();
673 vtkPoints* points = cell->GetPoints();
675 vtkCell* cellOriginal = m_FiberPolyData->GetCell(i);
676 int numPointsOriginal = cellOriginal->GetNumberOfPoints();
677 vtkPoints* pointsOriginal = cellOriginal->GetPoints();
681 if (numPoints>1 && numPointsOriginal)
687 for (
int j=0; j<numPoints; j++)
689 double* p = points->GetPoint(j);
691 itk::Point<float, 3> itkP;
692 itkP[0] = p[0]; itkP[1] = p[1]; itkP[2] = p[2];
694 mask->TransformPhysicalPointToIndex(itkP, idx);
696 if ( mask->GetPixel(idx)>0 && mask->GetLargestPossibleRegion().IsInside(idx) )
698 for (
int k=0; k<numPointsOriginal; k++)
700 double* p = pointsOriginal->GetPoint(k);
701 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
702 container->GetPointIds()->InsertNextId(
id);
710 bool includeFiber =
true;
711 for (
int j=0; j<numPoints; j++)
713 double* p = points->GetPoint(j);
715 itk::Point<float, 3> itkP;
716 itkP[0] = p[0]; itkP[1] = p[1]; itkP[2] = p[2];
718 mask->TransformPhysicalPointToIndex(itkP, idx);
720 if ( mask->GetPixel(idx)>0 && mask->GetLargestPossibleRegion().IsInside(idx) )
722 includeFiber =
false;
729 for (
int k=0; k<numPointsOriginal; k++)
731 double* p = pointsOriginal->GetPoint(k);
732 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
733 container->GetPointIds()->InsertNextId(
id);
740 double* start = pointsOriginal->GetPoint(0);
741 itk::Point<float, 3> itkStart;
742 itkStart[0] = start[0]; itkStart[1] = start[1]; itkStart[2] = start[2];
744 mask->TransformPhysicalPointToIndex(itkStart, idxStart);
746 double* end = pointsOriginal->GetPoint(numPointsOriginal-1);
747 itk::Point<float, 3> itkEnd;
748 itkEnd[0] = end[0]; itkEnd[1] = end[1]; itkEnd[2] = end[2];
750 mask->TransformPhysicalPointToIndex(itkEnd, idxEnd);
756 if ( !mask->GetPixel(idxStart)>0 && !mask->GetPixel(idxEnd)>0 )
758 for (
int j=0; j<numPointsOriginal; j++)
760 double* p = pointsOriginal->GetPoint(j);
761 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
762 container->GetPointIds()->InsertNextId(
id);
766 else if ( !mask->GetPixel(idxStart)>0 || !mask->GetPixel(idxEnd)>0 )
768 for (
int j=0; j<numPointsOriginal; j++)
770 double* p = pointsOriginal->GetPoint(j);
771 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
772 container->GetPointIds()->InsertNextId(
id);
780 if ( mask->GetPixel(idxStart)>0 && mask->GetPixel(idxEnd)>0 && mask->GetLargestPossibleRegion().IsInside(idxStart) && mask->GetLargestPossibleRegion().IsInside(idxEnd) )
782 for (
int j=0; j<numPointsOriginal; j++)
784 double* p = pointsOriginal->GetPoint(j);
785 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
786 container->GetPointIds()->InsertNextId(
id);
790 else if ( (mask->GetPixel(idxStart)>0 && mask->GetLargestPossibleRegion().IsInside(idxStart)) || (mask->GetPixel(idxEnd)>0 && mask->GetLargestPossibleRegion().IsInside(idxEnd)) )
792 for (
int j=0; j<numPointsOriginal; j++)
794 double* p = pointsOriginal->GetPoint(j);
795 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
796 container->GetPointIds()->InsertNextId(
id);
803 vtkNewCells->InsertNextCell(container);
806 if (vtkNewCells->GetNumberOfCells()<=0)
810 newPolyData->SetPoints(vtkNewPoints);
811 newPolyData->SetLines(vtkNewCells);
817 float minSpacing = 1;
818 if(mask->GetSpacing()[0]<mask->GetSpacing()[1] && mask->GetSpacing()[0]<mask->GetSpacing()[2])
819 minSpacing = mask->GetSpacing()[0];
820 else if (mask->GetSpacing()[1] < mask->GetSpacing()[2])
821 minSpacing = mask->GetSpacing()[1];
823 minSpacing = mask->GetSpacing()[2];
826 fibCopy->ResampleSpline(minSpacing/10);
827 vtkSmartPointer<vtkPolyData> polyData =fibCopy->GetFiberPolyData();
833 boost::progress_display disp(m_NumFibers);
834 for (
int i=0; i<m_NumFibers; i++)
838 vtkCell* cell = polyData->GetCell(i);
839 int numPoints = cell->GetNumberOfPoints();
840 vtkPoints* points = cell->GetPoints();
845 int newNumPoints = 0;
846 for (
int j=0; j<numPoints; j++)
848 double* p = points->GetPoint(j);
850 itk::Point<float, 3> itkP;
851 itkP[0] = p[0]; itkP[1] = p[1]; itkP[2] = p[2];
853 mask->TransformPhysicalPointToIndex(itkP, idx);
855 if ( mask->GetPixel(idx)>0 && mask->GetLargestPossibleRegion().IsInside(idx) && !invert )
857 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
858 container->GetPointIds()->InsertNextId(
id);
861 else if ( (mask->GetPixel(idx)<=0 || !mask->GetLargestPossibleRegion().IsInside(idx)) && invert )
863 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
864 container->GetPointIds()->InsertNextId(
id);
867 else if (newNumPoints>0)
869 vtkNewCells->InsertNextCell(container);
877 vtkNewCells->InsertNextCell(container);
882 if (vtkNewCells->GetNumberOfCells()<=0)
886 newPolyData->SetPoints(vtkNewPoints);
887 newPolyData->SetLines(vtkNewCells);
889 newFib->Compress(0.1);
895 if (roi==
nullptr || !(dynamic_cast<PlanarFigure*>(roi->
GetData()) || dynamic_cast<PlanarFigureComposite*>(roi->
GetData())) )
898 std::vector<long> tmp = ExtractFiberIdSubset(roi, storage);
902 vtkSmartPointer<vtkPolyData> pTmp = GeneratePolyDataByIds(tmp);
908 std::vector<long> result;
909 if (roi==
nullptr || roi->
GetData()==
nullptr)
916 if (children->size()==0)
919 switch (pfc->getOperationType())
924 result = this->ExtractFiberIdSubset(children->ElementAt(0), storage);
925 std::vector<long>::iterator it;
926 for (
unsigned int i=1; i<children->Size(); ++i)
928 std::vector<long> inRoi = this->ExtractFiberIdSubset(children->ElementAt(i), storage);
930 std::vector<long> rest(
std::min(result.size(),inRoi.size()));
931 it = std::set_intersection(result.begin(), result.end(), inRoi.begin(), inRoi.end(), rest.begin() );
932 rest.resize( it - rest.begin() );
940 result = ExtractFiberIdSubset(children->ElementAt(0), storage);
941 std::vector<long>::iterator it;
942 for (
unsigned int i=1; i<children->Size(); ++i)
945 std::vector<long> inRoi = ExtractFiberIdSubset(children->ElementAt(i), storage);
946 result.insert(it, inRoi.begin(), inRoi.end());
950 sort(result.begin(), result.end());
951 it = unique(result.begin(), result.end());
952 result.resize( it - result.begin() );
958 for(
long i=0; i<this->GetNumFibers(); i++)
961 std::vector<long>::iterator it;
962 for (
long i=0; i<children->Size(); ++i)
964 std::vector<long> inRoi = ExtractFiberIdSubset(children->ElementAt(i), storage);
966 std::vector<long> rest(result.size()-inRoi.size());
967 it = std::set_difference(result.begin(), result.end(), inRoi.begin(), inRoi.end(), rest.begin() );
968 rest.resize( it - rest.begin() );
975 else if ( dynamic_cast<mitk::PlanarFigure*>(roi->
GetData()) )
977 if ( dynamic_cast<mitk::PlanarPolygon*>(roi->
GetData()) )
983 for (
unsigned int i=0; i<planarPoly->GetNumberOfControlPoints(); ++i)
985 itk::Point<double,3> p = planarPoly->GetWorldControlPoint(i);
986 vtkIdType
id = polygonVtk->GetPoints()->InsertNextPoint(p[0], p[1], p[2] );
987 polygonVtk->GetPointIds()->InsertNextId(
id);
991 boost::progress_display disp(m_NumFibers);
992 for (
int i=0; i<m_NumFibers; i++)
995 vtkCell* cell = m_FiberPolyData->GetCell(i);
996 int numPoints = cell->GetNumberOfPoints();
997 vtkPoints* points = cell->GetPoints();
999 for (
int j=0; j<numPoints-1; j++)
1002 double p1[3] = {0,0,0};
1003 points->GetPoint(j, p1);
1004 double p2[3] = {0,0,0};
1005 points->GetPoint(j+1, p2);
1006 double tolerance = 0.001;
1010 double x[3] = {0,0,0};
1011 double pcoords[3] = {0,0,0};
1014 int iD = polygonVtk->IntersectWithLine(p1, p2, tolerance, t, x, pcoords, subId);
1017 result.push_back(i);
1023 else if ( dynamic_cast<mitk::PlanarCircle*>(roi->
GetData()) )
1026 Vector3D planeNormal = planarFigure->GetPlaneGeometry()->GetNormal();
1027 planeNormal.Normalize();
1033 double radius = V1w.EuclideanDistanceTo(V2w);
1037 boost::progress_display disp(m_NumFibers);
1038 for (
int i=0; i<m_NumFibers; i++)
1041 vtkCell* cell = m_FiberPolyData->GetCell(i);
1042 int numPoints = cell->GetNumberOfPoints();
1043 vtkPoints* points = cell->GetPoints();
1045 for (
int j=0; j<numPoints-1; j++)
1048 double p1[3] = {0,0,0};
1049 points->GetPoint(j, p1);
1050 double p2[3] = {0,0,0};
1051 points->GetPoint(j+1, p2);
1055 double x[3] = {0,0,0};
1057 int iD = vtkPlane::IntersectWithLine(p1,p2,planeNormal.GetDataPointer(),V1w.GetDataPointer(),t,x);
1061 double dist = (x[0]-V1w[0])*(x[0]-V1w[0])+(x[1]-V1w[1])*(x[1]-V1w[1])+(x[2]-V1w[2])*(x[2]-V1w[2]);
1064 result.push_back(i);
1080 cleaner->SetInputData(m_FiberPolyData);
1081 cleaner->PointMergingOff();
1083 m_FiberPolyData = cleaner->GetOutput();
1085 m_FiberLengths.clear();
1086 m_MeanFiberLength = 0;
1087 m_MedianFiberLength = 0;
1089 m_NumFibers = m_FiberPolyData->GetNumberOfCells();
1091 if (m_FiberColors==
nullptr || m_FiberColors->GetNumberOfTuples()!=m_FiberPolyData->GetNumberOfPoints())
1092 this->ColorFibersByOrientation();
1094 if (m_FiberWeights->GetSize()!=m_NumFibers)
1097 m_FiberWeights->SetName(
"FIBER_WEIGHTS");
1098 m_FiberWeights->SetNumberOfValues(m_NumFibers);
1099 this->SetFiberWeights(1);
1104 m_MinFiberLength = 0;
1105 m_MaxFiberLength = 0;
1107 geometry->SetImageGeometry(
false);
1108 float b[] = {0, 1, 0, 1, 0, 1};
1109 geometry->SetFloatBounds(b);
1110 SetGeometry(geometry);
1114 m_FiberPolyData->GetBounds(b);
1117 for (
int i=0; i<m_FiberPolyData->GetNumberOfCells(); i++)
1119 vtkCell* cell = m_FiberPolyData->GetCell(i);
1120 int p = cell->GetNumberOfPoints();
1121 vtkPoints* points = cell->GetPoints();
1123 for (
int j=0; j<p-1; j++)
1126 points->GetPoint(j, p1);
1128 points->GetPoint(j+1, p2);
1130 float dist = std::sqrt((p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1])+(p1[2]-p2[2])*(p1[2]-p2[2]));
1133 m_FiberLengths.push_back(length);
1134 m_MeanFiberLength += length;
1137 m_MinFiberLength = length;
1138 m_MaxFiberLength = length;
1142 if (length<m_MinFiberLength)
1143 m_MinFiberLength = length;
1144 if (length>m_MaxFiberLength)
1145 m_MaxFiberLength = length;
1148 m_MeanFiberLength /= m_NumFibers;
1150 std::vector< float > sortedLengths = m_FiberLengths;
1151 std::sort(sortedLengths.begin(), sortedLengths.end());
1152 for (
int i=0; i<m_NumFibers; i++)
1153 m_LengthStDev += (m_MeanFiberLength-sortedLengths.at(i))*(m_MeanFiberLength-sortedLengths.at(i));
1155 m_LengthStDev /= (m_NumFibers-1);
1158 m_LengthStDev = std::sqrt(m_LengthStDev);
1159 m_MedianFiberLength = sortedLengths.at(m_NumFibers/2);
1162 geometry->SetFloatBounds(b);
1163 this->SetGeometry(geometry);
1165 m_UpdateTime3D.Modified();
1166 m_UpdateTime2D.Modified();
1171 return m_FiberWeights->GetValue(fiber);
1176 for (
int i=0; i<m_FiberWeights->GetSize(); i++)
1177 m_FiberWeights->SetValue(i, newWeight);
1182 if (m_NumFibers!=weights->GetSize())
1184 MITK_INFO <<
"Weights array not equal to number of fibers!";
1188 for (
int i=0; i<weights->GetSize(); i++)
1189 m_FiberWeights->SetValue(i, weights->GetValue(i));
1191 m_FiberWeights->SetName(
"FIBER_WEIGHTS");
1196 m_FiberWeights->SetValue(fiber, weight);
1201 for(
long i=0; i<m_FiberPolyData->GetNumberOfPoints(); ++i)
1203 unsigned char source[4] = {0,0,0,0};
1204 fiberColors->GetTupleValue(i, source);
1206 unsigned char target[4] = {0,0,0,0};
1207 target[0] = source[0];
1208 target[1] = source[1];
1209 target[2] = source[2];
1210 target[3] = source[3];
1211 m_FiberColors->InsertTupleValue(i, target);
1213 m_UpdateTime3D.Modified();
1214 m_UpdateTime2D.Modified();
1223 itk::Matrix< double, 3, 3 > rotX; rotX.SetIdentity();
1224 rotX[1][1] = cos(rx);
1225 rotX[2][2] = rotX[1][1];
1226 rotX[1][2] = -sin(rx);
1227 rotX[2][1] = -rotX[1][2];
1229 itk::Matrix< double, 3, 3 > rotY; rotY.SetIdentity();
1230 rotY[0][0] = cos(ry);
1231 rotY[2][2] = rotY[0][0];
1232 rotY[0][2] = sin(ry);
1233 rotY[2][0] = -rotY[0][2];
1235 itk::Matrix< double, 3, 3 > rotZ; rotZ.SetIdentity();
1236 rotZ[0][0] = cos(rz);
1237 rotZ[1][1] = rotZ[0][0];
1238 rotZ[0][1] = -sin(rz);
1239 rotZ[1][0] = -rotZ[0][1];
1241 itk::Matrix< double, 3, 3 > rot = rotZ*rotY*rotX;
1254 vnl_matrix_fixed< double, 3, 3 > rotX; rotX.set_identity();
1255 rotX[1][1] = cos(rx);
1256 rotX[2][2] = rotX[1][1];
1257 rotX[1][2] = -sin(rx);
1258 rotX[2][1] = -rotX[1][2];
1260 vnl_matrix_fixed< double, 3, 3 > rotY; rotY.set_identity();
1261 rotY[0][0] = cos(ry);
1262 rotY[2][2] = rotY[0][0];
1263 rotY[0][2] = sin(ry);
1264 rotY[2][0] = -rotY[0][2];
1266 vnl_matrix_fixed< double, 3, 3 > rotZ; rotZ.set_identity();
1267 rotZ[0][0] = cos(rz);
1268 rotZ[1][1] = rotZ[0][0];
1269 rotZ[0][1] = -sin(rz);
1270 rotZ[1][0] = -rotZ[0][1];
1272 vnl_matrix_fixed< double, 3, 3 > rot = rotZ*rotY*rotX;
1277 point[0] -= center[0];
1278 point[1] -= center[1];
1279 point[2] -= center[2];
1281 point[0] += center[0]+tx;
1282 point[1] += center[1]+ty;
1283 point[2] += center[2]+tz;
1284 itk::Point<float, 3> out; out[0] = point[0]; out[1] = point[1]; out[2] = point[2];
1294 vnl_matrix_fixed< double, 3, 3 > rotX; rotX.set_identity();
1295 rotX[1][1] = cos(rx);
1296 rotX[2][2] = rotX[1][1];
1297 rotX[1][2] = -sin(rx);
1298 rotX[2][1] = -rotX[1][2];
1300 vnl_matrix_fixed< double, 3, 3 > rotY; rotY.set_identity();
1301 rotY[0][0] = cos(ry);
1302 rotY[2][2] = rotY[0][0];
1303 rotY[0][2] = sin(ry);
1304 rotY[2][0] = -rotY[0][2];
1306 vnl_matrix_fixed< double, 3, 3 > rotZ; rotZ.set_identity();
1307 rotZ[0][0] = cos(rz);
1308 rotZ[1][1] = rotZ[0][0];
1309 rotZ[0][1] = -sin(rz);
1310 rotZ[1][0] = -rotZ[0][1];
1312 vnl_matrix_fixed< double, 3, 3 > rot = rotZ*rotY*rotX;
1320 for (
int i=0; i<m_NumFibers; i++)
1322 vtkCell* cell = m_FiberPolyData->GetCell(i);
1323 int numPoints = cell->GetNumberOfPoints();
1324 vtkPoints* points = cell->GetPoints();
1327 for (
int j=0; j<numPoints; j++)
1329 double* p = points->GetPoint(j);
1330 vnl_vector_fixed< double, 3 > dir;
1331 dir[0] = p[0]-center[0];
1332 dir[1] = p[1]-center[1];
1333 dir[2] = p[2]-center[2];
1335 dir[0] += center[0]+tx;
1336 dir[1] += center[1]+ty;
1337 dir[2] += center[2]+tz;
1338 vtkIdType
id = vtkNewPoints->InsertNextPoint(dir.data_block());
1339 container->GetPointIds()->InsertNextId(
id);
1341 vtkNewCells->InsertNextCell(container);
1345 m_FiberPolyData->SetPoints(vtkNewPoints);
1346 m_FiberPolyData->SetLines(vtkNewCells);
1347 this->SetFiberPolyData(m_FiberPolyData,
true);
1356 vnl_matrix_fixed< double, 3, 3 > rotX; rotX.set_identity();
1357 rotX[1][1] = cos(x);
1358 rotX[2][2] = rotX[1][1];
1359 rotX[1][2] = -sin(x);
1360 rotX[2][1] = -rotX[1][2];
1362 vnl_matrix_fixed< double, 3, 3 > rotY; rotY.set_identity();
1363 rotY[0][0] = cos(y);
1364 rotY[2][2] = rotY[0][0];
1365 rotY[0][2] = sin(y);
1366 rotY[2][0] = -rotY[0][2];
1368 vnl_matrix_fixed< double, 3, 3 > rotZ; rotZ.set_identity();
1369 rotZ[0][0] = cos(z);
1370 rotZ[1][1] = rotZ[0][0];
1371 rotZ[0][1] = -sin(z);
1372 rotZ[1][0] = -rotZ[0][1];
1380 for (
int i=0; i<m_NumFibers; i++)
1382 vtkCell* cell = m_FiberPolyData->GetCell(i);
1383 int numPoints = cell->GetNumberOfPoints();
1384 vtkPoints* points = cell->GetPoints();
1387 for (
int j=0; j<numPoints; j++)
1389 double* p = points->GetPoint(j);
1390 vnl_vector_fixed< double, 3 > dir;
1391 dir[0] = p[0]-center[0];
1392 dir[1] = p[1]-center[1];
1393 dir[2] = p[2]-center[2];
1394 dir = rotZ*rotY*rotX*dir;
1395 dir[0] += center[0];
1396 dir[1] += center[1];
1397 dir[2] += center[2];
1398 vtkIdType
id = vtkNewPoints->InsertNextPoint(dir.data_block());
1399 container->GetPointIds()->InsertNextId(
id);
1401 vtkNewCells->InsertNextCell(container);
1405 m_FiberPolyData->SetPoints(vtkNewPoints);
1406 m_FiberPolyData->SetLines(vtkNewCells);
1407 this->SetFiberPolyData(m_FiberPolyData,
true);
1413 boost::progress_display disp(m_NumFibers);
1421 for (
int i=0; i<m_NumFibers; i++)
1424 vtkCell* cell = m_FiberPolyData->GetCell(i);
1425 int numPoints = cell->GetNumberOfPoints();
1426 vtkPoints* points = cell->GetPoints();
1429 for (
int j=0; j<numPoints; j++)
1431 double* p = points->GetPoint(j);
1434 p[0] -= c[0]; p[1] -= c[1]; p[2] -= c[2];
1441 p[0] += c[0]; p[1] += c[1]; p[2] += c[2];
1443 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
1444 container->GetPointIds()->InsertNextId(
id);
1446 vtkNewCells->InsertNextCell(container);
1450 m_FiberPolyData->SetPoints(vtkNewPoints);
1451 m_FiberPolyData->SetLines(vtkNewCells);
1452 this->SetFiberPolyData(m_FiberPolyData,
true);
1460 for (
int i=0; i<m_NumFibers; i++)
1462 vtkCell* cell = m_FiberPolyData->GetCell(i);
1463 int numPoints = cell->GetNumberOfPoints();
1464 vtkPoints* points = cell->GetPoints();
1467 for (
int j=0; j<numPoints; j++)
1469 double* p = points->GetPoint(j);
1473 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
1474 container->GetPointIds()->InsertNextId(
id);
1476 vtkNewCells->InsertNextCell(container);
1480 m_FiberPolyData->SetPoints(vtkNewPoints);
1481 m_FiberPolyData->SetLines(vtkNewCells);
1482 this->SetFiberPolyData(m_FiberPolyData,
true);
1491 boost::progress_display disp(m_NumFibers);
1496 for (
int i=0; i<m_NumFibers; i++)
1499 vtkCell* cell = m_FiberPolyData->GetCell(i);
1500 int numPoints = cell->GetNumberOfPoints();
1501 vtkPoints* points = cell->GetPoints();
1504 for (
int j=0; j<numPoints; j++)
1506 double* p = points->GetPoint(j);
1508 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
1509 container->GetPointIds()->InsertNextId(
id);
1511 vtkNewCells->InsertNextCell(container);
1515 m_FiberPolyData->SetPoints(vtkNewPoints);
1516 m_FiberPolyData->SetLines(vtkNewCells);
1517 this->SetFiberPolyData(m_FiberPolyData,
true);
1526 boost::progress_display disp(m_FiberPolyData->GetNumberOfCells());
1527 for (
int i=0; i<m_FiberPolyData->GetNumberOfCells(); i++)
1530 vtkCell* cell = m_FiberPolyData->GetCell(i);
1531 int numPoints = cell->GetNumberOfPoints();
1532 vtkPoints* points = cell->GetPoints();
1536 bool discard =
false;
1537 for (
int j=0; j<numPoints-1; j++)
1540 points->GetPoint(j, p1);
1542 points->GetPoint(j+1, p2);
1544 vnl_vector_fixed< double, 3 > v1;
1545 v1[0] = p2[0]-p1[0];
1546 v1[1] = p2[1]-p1[1];
1547 v1[2] = p2[2]-p1[2];
1548 if (v1.magnitude()>0.001)
1552 if (fabs(dot_product(v1,dir))>threshold)
1561 for (
int j=0; j<numPoints; j++)
1564 points->GetPoint(j, p1);
1566 vtkIdType
id = vtkNewPoints->InsertNextPoint(p1);
1567 container->GetPointIds()->InsertNextId(
id);
1569 vtkNewCells->InsertNextCell(container);
1574 m_FiberPolyData->SetPoints(vtkNewPoints);
1575 m_FiberPolyData->SetLines(vtkNewCells);
1577 this->SetFiberPolyData(m_FiberPolyData,
true);
1591 MITK_INFO <<
"Applying curvature threshold";
1592 boost::progress_display disp(m_FiberPolyData->GetNumberOfCells());
1593 for (
int i=0; i<m_FiberPolyData->GetNumberOfCells(); i++)
1596 vtkCell* cell = m_FiberPolyData->GetCell(i);
1597 int numPoints = cell->GetNumberOfPoints();
1598 vtkPoints* points = cell->GetPoints();
1602 for (
int j=0; j<numPoints-2; j++)
1605 points->GetPoint(j, p1);
1607 points->GetPoint(j+1, p2);
1609 points->GetPoint(j+2, p3);
1611 vnl_vector_fixed< float, 3 > v1, v2, v3;
1613 v1[0] = p2[0]-p1[0];
1614 v1[1] = p2[1]-p1[1];
1615 v1[2] = p2[2]-p1[2];
1617 v2[0] = p3[0]-p2[0];
1618 v2[1] = p3[1]-p2[1];
1619 v2[2] = p3[2]-p2[2];
1621 v3[0] = p1[0]-p3[0];
1622 v3[1] = p1[1]-p3[1];
1623 v3[2] = p1[2]-p3[2];
1625 float a = v1.magnitude();
1626 float b = v2.magnitude();
1627 float c = v3.magnitude();
1628 float r = a*b*c/std::sqrt((a+b+c)*(a+b-c)*(b+c-a)*(a-b+c));
1630 vtkIdType
id = vtkNewPoints->InsertNextPoint(p1);
1631 container->GetPointIds()->InsertNextId(
id);
1633 if (deleteFibers && r<minRadius)
1639 vtkNewCells->InsertNextCell(container);
1642 else if (j==numPoints-3)
1644 id = vtkNewPoints->InsertNextPoint(p2);
1645 container->GetPointIds()->InsertNextId(
id);
1646 id = vtkNewPoints->InsertNextPoint(p3);
1647 container->GetPointIds()->InsertNextId(
id);
1648 vtkNewCells->InsertNextCell(container);
1653 if (vtkNewCells->GetNumberOfCells()<=0)
1657 m_FiberPolyData->SetPoints(vtkNewPoints);
1658 m_FiberPolyData->SetLines(vtkNewCells);
1659 this->SetFiberPolyData(m_FiberPolyData,
true);
1666 if (lengthInMM<=0 || lengthInMM<m_MinFiberLength)
1668 MITK_INFO <<
"No fibers shorter than " << lengthInMM <<
" mm found!";
1672 if (lengthInMM>m_MaxFiberLength)
1674 MITK_WARN <<
"Process aborted. No fibers would be left!";
1680 float min = m_MaxFiberLength;
1682 boost::progress_display disp(m_NumFibers);
1683 for (
int i=0; i<m_NumFibers; i++)
1686 vtkCell* cell = m_FiberPolyData->GetCell(i);
1687 int numPoints = cell->GetNumberOfPoints();
1688 vtkPoints* points = cell->GetPoints();
1690 if (m_FiberLengths.at(i)>=lengthInMM)
1693 for (
int j=0; j<numPoints; j++)
1695 double* p = points->GetPoint(j);
1696 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
1697 container->GetPointIds()->InsertNextId(
id);
1699 vtkNewCells->InsertNextCell(container);
1700 if (m_FiberLengths.at(i)<
min)
1701 min = m_FiberLengths.at(i);
1705 if (vtkNewCells->GetNumberOfCells()<=0)
1709 m_FiberPolyData->SetPoints(vtkNewPoints);
1710 m_FiberPolyData->SetLines(vtkNewCells);
1711 this->SetFiberPolyData(m_FiberPolyData,
true);
1717 if (lengthInMM<=0 || lengthInMM>m_MaxFiberLength)
1720 if (lengthInMM<m_MinFiberLength)
1727 boost::progress_display disp(m_NumFibers);
1728 for (
int i=0; i<m_NumFibers; i++)
1731 vtkCell* cell = m_FiberPolyData->GetCell(i);
1732 int numPoints = cell->GetNumberOfPoints();
1733 vtkPoints* points = cell->GetPoints();
1735 if (m_FiberLengths.at(i)<=lengthInMM)
1738 for (
int j=0; j<numPoints; j++)
1740 double* p = points->GetPoint(j);
1741 vtkIdType
id = vtkNewPoints->InsertNextPoint(p);
1742 container->GetPointIds()->InsertNextId(
id);
1744 vtkNewCells->InsertNextCell(container);
1748 if (vtkNewCells->GetNumberOfCells()<=0)
1752 m_FiberPolyData->SetPoints(vtkNewPoints);
1753 m_FiberPolyData->SetLines(vtkNewCells);
1754 this->SetFiberPolyData(m_FiberPolyData,
true);
1760 if (pointDistance<=0)
1767 vtkIdType pointHelperCnt = 0;
1770 boost::progress_display disp(m_NumFibers);
1771 for (
int i=0; i<m_NumFibers; i++)
1774 vtkCell* cell = m_FiberPolyData->GetCell(i);
1775 int numPoints = cell->GetNumberOfPoints();
1776 vtkPoints* points = cell->GetPoints();
1779 for (
int j=0; j<numPoints; j++)
1780 newPoints->InsertNextPoint(points->GetPoint(j));
1782 float length = m_FiberLengths.at(i);
1783 int sampling = std::ceil(length/pointDistance);
1788 xSpline->SetDefaultBias(bias); xSpline->SetDefaultTension(tension); xSpline->SetDefaultContinuity(continuity);
1789 ySpline->SetDefaultBias(bias); ySpline->SetDefaultTension(tension); ySpline->SetDefaultContinuity(continuity);
1790 zSpline->SetDefaultBias(bias); zSpline->SetDefaultTension(tension); zSpline->SetDefaultContinuity(continuity);
1793 spline->SetXSpline(xSpline);
1794 spline->SetYSpline(ySpline);
1795 spline->SetZSpline(zSpline);
1796 spline->SetPoints(newPoints);
1799 functionSource->SetParametricFunction(spline);
1800 functionSource->SetUResolution(sampling);
1801 functionSource->SetVResolution(sampling);
1802 functionSource->SetWResolution(sampling);
1803 functionSource->Update();
1805 vtkPolyData* outputFunction = functionSource->GetOutput();
1806 vtkPoints* tmpSmoothPnts = outputFunction->GetPoints();
1809 smoothLine->GetPointIds()->SetNumberOfIds(tmpSmoothPnts->GetNumberOfPoints());
1811 for (
int j=0; j<smoothLine->GetNumberOfPoints(); j++)
1813 smoothLine->GetPointIds()->SetId(j, j+pointHelperCnt);
1814 vtkSmoothPoints->InsertNextPoint(tmpSmoothPnts->GetPoint(j));
1816 vtkSmoothCells->InsertNextCell(smoothLine);
1817 pointHelperCnt += tmpSmoothPnts->GetNumberOfPoints();
1821 m_FiberPolyData->SetPoints(vtkSmoothPoints);
1822 m_FiberPolyData->SetLines(vtkSmoothCells);
1823 this->SetFiberPolyData(m_FiberPolyData,
true);
1824 m_FiberSampling = 10/pointDistance;
1829 ResampleSpline(pointDistance, 0, 0, 0 );
1834 unsigned long points = 0;
1835 for (
int i=0; i<m_FiberPolyData->GetNumberOfCells(); i++)
1837 vtkCell* cell = m_FiberPolyData->GetCell(i);
1838 points += cell->GetNumberOfPoints();
1849 unsigned long numRemovedPoints = 0;
1850 boost::progress_display disp(m_FiberPolyData->GetNumberOfCells());
1852 for (
int i=0; i<m_FiberPolyData->GetNumberOfCells(); i++)
1855 vtkCell* cell = m_FiberPolyData->GetCell(i);
1856 int numPoints = cell->GetNumberOfPoints();
1857 vtkPoints* points = cell->GetPoints();
1860 std::vector< int > removedPoints; removedPoints.resize(numPoints, 0);
1861 removedPoints[0]=-1; removedPoints[numPoints-1]=-1;
1865 bool pointFound =
true;
1869 double minError = error;
1870 int removeIndex = -1;
1872 for (
int j=0; j<numPoints; j++)
1874 if (removedPoints[j]==0)
1877 points->GetPoint(j, cand);
1878 vnl_vector_fixed< double, 3 > candV;
1879 candV[0]=cand[0]; candV[1]=cand[1]; candV[2]=cand[2];
1882 vnl_vector_fixed< double, 3 > pred;
1883 for (
int k=j-1; k>=0; k--)
1884 if (removedPoints[k]<=0)
1887 points->GetPoint(k, ref);
1888 pred[0]=ref[0]; pred[1]=ref[1]; pred[2]=ref[2];
1893 vnl_vector_fixed< double, 3 > succ;
1894 for (
int k=j+1; k<numPoints; k++)
1895 if (removedPoints[k]<=0)
1898 points->GetPoint(k, ref);
1899 succ[0]=ref[0]; succ[1]=ref[1]; succ[2]=ref[2];
1904 if (validP>=0 && validS>=0)
1906 double a = (candV-pred).magnitude();
1907 double b = (candV-succ).magnitude();
1908 double c = (pred-succ).magnitude();
1909 double s=0.5*(a+b+c);
1910 double hc=(2.0/c)*sqrt(fabs(s*(s-a)*(s-b)*(s-c)));
1924 removedPoints[removeIndex] = 1;
1929 for (
int j=0; j<numPoints; j++)
1931 if (removedPoints[j]<=0)
1934 points->GetPoint(j, cand);
1935 vtkIdType
id = vtkNewPoints->InsertNextPoint(cand);
1936 container->GetPointIds()->InsertNextId(
id);
1940 vtkNewCells->InsertNextCell(container);
1943 if (vtkNewCells->GetNumberOfCells()>0)
1945 MITK_INFO <<
"Removed points: " << numRemovedPoints;
1947 m_FiberPolyData->SetPoints(vtkNewPoints);
1948 m_FiberPolyData->SetLines(vtkNewCells);
1949 this->SetFiberPolyData(m_FiberPolyData,
true);
1958 MITK_INFO <<
"Reference bundle is NULL!";
1964 MITK_INFO <<
"Unequal number of fibers!";
1969 for (
int i=0; i<m_NumFibers; i++)
1971 vtkCell* cell = m_FiberPolyData->GetCell(i);
1972 int numPoints = cell->GetNumberOfPoints();
1973 vtkPoints* points = cell->GetPoints();
1976 int numPoints2 = cell2->GetNumberOfPoints();
1977 vtkPoints* points2 = cell2->GetPoints();
1979 if (numPoints2!=numPoints)
1981 MITK_INFO <<
"Unequal number of points in fiber " << i <<
"!";
1982 MITK_INFO << numPoints2 <<
" vs. " << numPoints;
1986 for (
int j=0; j<numPoints; j++)
1988 double* p1 = points->GetPoint(j);
1989 double* p2 = points2->GetPoint(j);
1990 if (fabs(p1[0]-p2[0])>eps || fabs(p1[1]-p2[1])>eps || fabs(p1[2]-p2[2])>eps)
1992 MITK_INFO <<
"Unequal points in fiber " << i <<
" at position " << j <<
"!";
1993 MITK_INFO <<
"p1: " << p1[0] <<
", " << p1[1] <<
", " << p1[2];
1994 MITK_INFO <<
"p2: " << p2[0] <<
", " << p2[1] <<
", " << p2[2];
FiberBundle::Pointer SubtractBundle(FiberBundle *fib)
bool RemoveLongFibers(float lengthInMM)
void ColorFibersByOrientation()
void ResampleSpline(float pointDistance=1)
Data management class that handles 'was created by' relations.
Gives locked and index-based read access for a particular image part. The class provides several set-...
static const char * FIBER_ID_ARRAY
void ScaleFibers(double x, double y, double z, bool subtractCenter=true)
void SetFiberOpacity(vtkDoubleArray *FAValArray)
virtual void SetRequestedRegion(const itk::DataObject *) override
Set the requested region from this data object to match the requested region of the data object passe...
virtual void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
itk::Matrix< double, 3, 3 > TransformMatrix(itk::Matrix< double, 3, 3 > m, double rx, double ry, double rz)
virtual void UpdateOutputInformation() override
virtual SetOfObjects::ConstPointer GetDerivations(const mitk::DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectDerivations=true) const =0
returns a set of derived objects for a given node.
void SetFiberWeights(float newWeight)
void RemoveDir(vnl_vector_fixed< double, 3 > dir, double threshold)
itk::Point< float, 3 > GetItkPoint(double point[3])
bool RemoveShortFibers(float lengthInMM)
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
#define mitkPixelTypeMultiplex2(function, ptype, param1, param2)
float GetFiberWeight(unsigned int fiber)
void SetFiberWeight(unsigned int fiber, float weight)
itk::Image< unsigned char, 3 > ItkUcharImgType
void TransformFibers(double rx, double ry, double rz, double tx, double ty, double tz)
void RotateAroundAxis(double x, double y, double z)
itk::SmartPointer< const Self > ConstPointer
FiberBundle::Pointer AddBundle(FiberBundle *fib)
FiberBundle(vtkPolyData *fiberPolyData=nullptr)
bool ApplyCurvatureThreshold(float minRadius, bool deleteFibers)
mitk::FiberBundle::Pointer GetDeepCopy()
itk::Point< float, 3 > TransformPoint(vnl_vector_fixed< double, 3 > point, double rx, double ry, double rz, double tx, double ty, double tz)
vtkSmartPointer< vtkPolyData > GetFiberPolyData() const
Base Class for Fiber Bundles;.
void UpdateFiberGeometry()
Point3D GetCenter() const
Get the center of the bounding-box in mm.
virtual bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
std::vector< long > ExtractFiberIdSubset(DataNode *roi, DataStorage *storage)
unsigned long GetNumberOfPoints()
void TranslateFibers(double x, double y, double z)
FiberBundle::Pointer ExtractFiberSubset(DataNode *roi, DataStorage *storage)
void ColorFibersByScalarMap(mitk::Image::Pointer, bool opacity)
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
void SetFiberColors(vtkSmartPointer< vtkUnsignedCharArray > fiberColors)
MITKCORE_EXPORT const ScalarType eps
void MirrorFibers(unsigned int axis)
FiberBundle::Pointer RemoveFibersOutside(ItkUcharImgType *mask, bool invert=false)
bool Equals(FiberBundle *fib, double eps=0.0001)
void Compress(float error=0.0)
virtual int GetNumFibers()
void SetFiberPolyData(vtkSmartPointer< vtkPolyData >, bool updateGeometry=true)
BaseGeometry Describes the geometry of a data object.
Class for nodes of the DataTree.
Class for defining the data type of pixels.
vtkSmartPointer< vtkPolyData > GeneratePolyDataByIds(std::vector< long >)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.