21 #include <vtkCellArray.h>
22 #include <vtkClipPolyData.h>
23 #include <vtkContourFilter.h>
24 #include <vtkCylinder.h>
25 #include <vtkFloatArray.h>
26 #include <vtkGeneralTransform.h>
27 #include <vtkImplicitBoolean.h>
28 #include <vtkImplicitModeller.h>
30 #include <vtkPointData.h>
31 #include <vtkPoints.h>
32 #include <vtkPolyDataMapper.h>
33 #include <vtkProperty.h>
34 #include <vtkRenderer.h>
35 #include <vtkSampleFunction.h>
36 #include <vtkSphereSource.h>
37 #include <vtkTubeFilter.h>
38 #include <vtkUnsignedIntArray.h>
55 return m_LSH.GetLocalStorage(renderer)->m_vtkTubeGraphAssembly;
60 bool renderTubeGraph(
false);
61 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
65 dynamic_cast<TubeGraphProperty *
>(tubeGraph->GetProperty(
"Tube Graph.Visualization Information").GetPointer());
67 if (tubeGraph.IsNull() || tubeGraphProperty.IsNull())
69 itkWarningMacro(<<
"Input of tube graph mapper is NULL!");
73 if (tubeGraph->GetMTime() > ls->m_lastGenerateDataTime)
75 this->GenerateTubeGraphData(renderer);
76 renderTubeGraph =
true;
82 if (tubeGraphProperty->GetMTime() > ls->m_lastRenderDataTime)
84 this->RenderTubeGraphPropertyInformation(renderer);
85 renderTubeGraph =
true;
91 std::vector<TubeGraph::VertexDescriptorType> alreadyRenderedVertexList;
95 alreadyRenderedVertexList.push_back(root);
98 ls->m_vtkTubesActorMap.begin();
99 itTubes != ls->m_vtkTubesActorMap.end();
102 if (tubeGraphProperty->IsTubeVisible(itTubes->first))
105 ls->m_vtkTubeGraphAssembly->AddPart(itTubes->second);
108 if (std::find(alreadyRenderedVertexList.begin(), alreadyRenderedVertexList.end(), itTubes->first.first) ==
109 alreadyRenderedVertexList.end())
111 std::map<TubeGraph::VertexDescriptorType, vtkSmartPointer<vtkActor>>::iterator itSourceSphere =
112 ls->m_vtkSpheresActorMap.find(itTubes->first.first);
113 if (itSourceSphere != ls->m_vtkSpheresActorMap.end())
114 ls->m_vtkTubeGraphAssembly->AddPart(itSourceSphere->second);
115 alreadyRenderedVertexList.push_back(itSourceSphere->first);
117 if (std::find(alreadyRenderedVertexList.begin(), alreadyRenderedVertexList.end(), itTubes->first.second) ==
118 alreadyRenderedVertexList.end())
120 std::map<TubeGraph::VertexDescriptorType, vtkSmartPointer<vtkActor>>::iterator itTargetSphere =
121 ls->m_vtkSpheresActorMap.find(itTubes->first.second);
122 if (itTargetSphere != ls->m_vtkSpheresActorMap.end())
123 ls->m_vtkTubeGraphAssembly->AddPart(itTargetSphere->second);
124 alreadyRenderedVertexList.push_back(itTargetSphere->first);
140 MITK_INFO <<
"Render tube graph property information!";
141 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
144 dynamic_cast<TubeGraphProperty *
>(tubeGraph->GetProperty(
"Tube Graph.Visualization Information").GetPointer());
146 if (tubeGraphProperty.IsNull())
148 MITK_INFO <<
"No tube graph property!! So no special render information...";
152 std::vector<TubeGraphVertex> allVertices = tubeGraph->GetVectorOfAllVertices();
153 for (std::vector<TubeGraphVertex>::iterator vertex = allVertices.begin(); vertex != allVertices.end(); ++vertex)
157 double sphereColorR = 0;
158 double sphereColorG = 0;
159 double sphereColorB = 0;
161 int numberOfVisibleEdges = 0;
162 std::vector<TubeGraphEdge> allEdgesOfVertex = tubeGraph->GetAllEdgesOfAVertex(vertexDesc);
163 for (std::vector<TubeGraphEdge>::iterator edge = allEdgesOfVertex.begin(); edge != allEdgesOfVertex.end(); ++edge)
169 std::pair<TubeGraphVertex, TubeGraphVertex> soureTargetPair = tubeGraph->GetVerticesOfAnEdge(edgeDesc);
175 tube.first = tubeGraph->GetVertexDescriptor(source);
176 tube.second = tubeGraph->GetVertexDescriptor(target);
178 if (tubeGraphProperty->IsTubeVisible(tube))
180 mitk::Color tubeColor = tubeGraphProperty->GetColorOfTube(tube);
182 vtkSmartPointer<vtkDataArray> scalars =
183 ls->m_vtkTubesActorMap[tube]->GetMapper()->GetInput()->GetPointData()->GetScalars();
185 scalars->GetTuple(0, color);
187 if (color[0] != tubeColor[0] || color[1] != tubeColor[1] || color[2] != tubeColor[2])
189 int numberOfPoints = scalars->GetSize();
192 colorScalars->SetName(
"colorScalars");
193 colorScalars->SetNumberOfComponents(3);
194 colorScalars->SetNumberOfTuples(numberOfPoints);
195 for (
int i = 0; i < numberOfPoints; i++)
197 scalars->InsertTuple3(i, tubeColor[0], tubeColor[1], tubeColor[2]);
199 ls->m_vtkTubesActorMap[tube]->GetMapper()->GetInput()->GetPointData()->SetActiveScalars(
"colorScalars");
202 sphereColorR += tubeColor[0];
203 sphereColorG += tubeColor[1];
204 sphereColorB += tubeColor[2];
205 numberOfVisibleEdges++;
208 if (numberOfVisibleEdges > 0)
210 sphereColorR /= 255 * numberOfVisibleEdges;
211 sphereColorG /= 255 * numberOfVisibleEdges;
212 sphereColorB /= 255 * numberOfVisibleEdges;
215 ls->m_vtkSpheresActorMap[vertexDesc]->GetProperty()->SetColor(sphereColorR, sphereColorG, sphereColorB);
217 ls->m_lastRenderDataTime.Modified();
223 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
225 ls->m_vtkTubesActorMap.clear();
226 ls->m_vtkSpheresActorMap.clear();
230 dynamic_cast<TubeGraphProperty *
>(tubeGraph->GetProperty(
"Tube Graph.Visualization Information").GetPointer());
231 if (tubeGraphProperty.IsNull())
232 MITK_INFO <<
"No tube graph property!! So no special render information...";
235 std::vector<TubeGraphEdge> allEdges = tubeGraph->GetVectorOfAllEdges();
236 for (std::vector<TubeGraphEdge>::iterator edge = allEdges.begin(); edge != allEdges.end(); ++edge)
238 this->GeneratePolyDataForTube(*edge, tubeGraph, tubeGraphProperty, renderer);
242 std::vector<TubeGraphVertex> allVertices = tubeGraph->GetVectorOfAllVertices();
243 for (std::vector<TubeGraphVertex>::iterator vertex = allVertices.begin(); vertex != allVertices.end(); ++vertex)
245 this->GeneratePolyDataForFurcation(*vertex, tubeGraph, renderer);
246 if (this->ClipStructures())
248 this->ClipPolyData(*vertex, tubeGraph, tubeGraphProperty, renderer);
251 ls->m_lastGenerateDataTime.Modified();
259 LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
265 if (dynamic_cast<const mitk::CircularProfileTubeElement *>(vertex.
GetTubeElement()))
270 sphereSource->SetCenter(coordinates[0], coordinates[1], coordinates[2]);
271 sphereSource->SetRadius(diameter / 2.0f);
272 sphereSource->SetThetaResolution(12);
273 sphereSource->SetPhiResolution(12);
274 sphereSource->Update();
280 sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
281 sphereActor->SetMapper(sphereMapper);
283 ls->m_vtkSpheresActorMap.insert(std::make_pair(graph->GetVertexDescriptor(vertex), sphereActor));
291 LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
297 std::pair<TubeGraphVertex, TubeGraphVertex> soureTargetPair = graph->GetVerticesOfAnEdge(edgeDesc);
303 tube.first = graph->GetVertexDescriptor(source);
304 tube.second = graph->GetVertexDescriptor(target);
307 if (graphProperty.IsNotNull())
309 color = graphProperty->GetColorOfTube(tube);
324 points->SetNumberOfPoints(numberOfPoints);
327 radii->SetName(
"radii");
328 radii->SetNumberOfComponents(1);
333 colorScalars->SetName(
"colorScalars");
334 colorScalars->SetNumberOfComponents(3);
337 radii->SetNumberOfTuples(numberOfPoints);
338 colorScalars->SetNumberOfTuples(numberOfPoints);
339 lines->InsertNextCell(numberOfPoints);
350 if (dynamic_cast<const mitk::CircularProfileTubeElement *>(source.
GetTubeElement()))
354 points->InsertPoint(
id, coordinates[0], coordinates[1], coordinates[2]);
355 radii->InsertTuple1(
id, diameter / 2.0f);
357 colorScalars->InsertTuple3(
id, color[0], color[1], color[2]);
358 lines->InsertCellPoint(
id);
365 coordinates = allElements[index]->GetCoordinates();
366 if (dynamic_cast<mitk::CircularProfileTubeElement *>(allElements[index]))
370 points->InsertPoint(
id, coordinates[0], coordinates[1], coordinates[2]);
371 radii->InsertTuple1(
id, diameter / 2.0f);
372 colorScalars->InsertTuple3(
id, color[0], color[1], color[2]);
373 lines->InsertCellPoint(
id);
379 if (dynamic_cast<const mitk::CircularProfileTubeElement *>(target.
GetTubeElement()))
383 points->InsertPoint(
id, coordinates[0], coordinates[1], coordinates[2]);
384 radii->InsertTuple1(
id, diameter / 2.0f);
385 colorScalars->InsertTuple3(
id, color[0], color[1], color[2]);
386 lines->InsertCellPoint(
id);
392 polyData->SetPoints(points);
393 polyData->SetLines(lines);
394 polyData->GetPointData()->AddArray(radii);
395 polyData->GetPointData()->AddArray(colorScalars);
396 polyData->GetPointData()->SetActiveScalars(radii->GetName());
399 double *range = radii->GetRange();
401 assert(range[0] != 0.0f && range[1] != 0.0f);
404 tubeFilter->SetInputData(polyData);
405 tubeFilter->SetRadius(range[0]);
406 tubeFilter->SetRadiusFactor(range[1] / range[0]);
408 if (range[0] != range[1])
409 tubeFilter->SetVaryRadiusToVaryRadiusByScalar();
411 tubeFilter->SetNumberOfSides(9);
412 tubeFilter->SidesShareVerticesOn();
413 tubeFilter->CappingOff();
414 tubeFilter->Update();
416 tubeFilter->GetOutput()->GetPointData()->SetActiveScalars(
"colorScalars");
422 tubeMapper->SetInputConnection(tubeFilter->GetOutputPort());
423 tubeActor->SetMapper(tubeMapper);
424 tubeActor->GetProperty()->SetColor(color[0], color[1], color[2]);
434 LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
438 if (dynamic_cast<const mitk::CircularProfileTubeElement *>(vertex.
GetTubeElement()))
445 std::map<TubeGraph::TubeDescriptorType, vtkSmartPointer<vtkImplicitBoolean>> cylinderForClipping;
449 std::vector<TubeGraphEdge> allEdgesOfVertex = graph->GetAllEdgesOfAVertex(vertexDesc);
450 for (std::vector<TubeGraphEdge>::iterator edge = allEdgesOfVertex.begin(); edge != allEdgesOfVertex.end(); ++edge)
456 std::pair<TubeGraphVertex, TubeGraphVertex> soureTargetPair = graph->GetVerticesOfAnEdge(edgeDesc);
462 tube.first = graph->GetVertexDescriptor(source);
463 tube.second = graph->GetVertexDescriptor(target);
468 double cylinderDiameter = diameter;
469 float radius = diameter / 2;
472 if (source == vertex)
475 if ((*edge).GetNumberOfElements() != 0)
477 double lastDistance = 0, distance = 0;
479 unsigned int index = 0;
481 for (; index < (*edge).GetNumberOfElements(); index++)
483 mitk::Vector3D diffVec = (*edge).GetTubeElement(index)->GetCoordinates() - centerVertex;
484 distance = std::sqrt(pow(diffVec[0], 2) + pow(diffVec[1], 2) + pow(diffVec[2], 2));
485 if (distance > radius)
487 lastDistance = distance;
490 if (index < (*edge).GetNumberOfElements())
492 double withinSphereDiameter = diameter, outsideSphereDiameter = diameter, interpolationValue = 0.5;
494 interpolationValue = (radius - lastDistance) / (distance - lastDistance);
498 if (dynamic_cast<mitk::CircularProfileTubeElement *>((*edge).GetTubeElement(0)))
499 outsideSphereDiameter =
504 if (dynamic_cast<mitk::CircularProfileTubeElement *>((*edge).GetTubeElement(index - 1)))
505 withinSphereDiameter =
508 if (dynamic_cast<mitk::CircularProfileTubeElement *>((*edge).GetTubeElement(index)))
509 outsideSphereDiameter =
514 (1 - interpolationValue) * withinSphereDiameter + interpolationValue * outsideSphereDiameter;
517 edgeDirectionPoint = (*edge).GetTubeElement(0)->GetCoordinates();
530 if ((*edge).GetNumberOfElements() != 0)
532 double lastDistance = 0, distance = 0;
534 unsigned int index = (*edge).GetNumberOfElements() - 1;
535 for (; index >= 0; index--)
537 mitk::Vector3D diffVec = (*edge).GetTubeElement(index)->GetCoordinates() - centerVertex;
538 distance = std::sqrt(pow(diffVec[0], 2) + pow(diffVec[1], 2) + pow(diffVec[2], 2));
539 if (distance > radius)
541 lastDistance = distance;
546 double withinSphereDiameter = diameter, outsideSphereDiameter = diameter, interpolationValue = 0.5;
548 interpolationValue = (radius - lastDistance) / (distance - lastDistance);
550 if (index == (*edge).GetNumberOfElements() - 1)
552 if (dynamic_cast<mitk::CircularProfileTubeElement *>(
553 (*edge).GetTubeElement((*edge).GetNumberOfElements() - 1)))
554 outsideSphereDiameter = (dynamic_cast<mitk::CircularProfileTubeElement *>(
555 (*edge).GetTubeElement((*edge).GetNumberOfElements() - 1)))
560 if (dynamic_cast<mitk::CircularProfileTubeElement *>((*edge).GetTubeElement(index + 1)))
561 withinSphereDiameter =
564 if (dynamic_cast<mitk::CircularProfileTubeElement *>((*edge).GetTubeElement(index)))
565 outsideSphereDiameter =
570 (1 - interpolationValue) * withinSphereDiameter + interpolationValue * outsideSphereDiameter;
574 edgeDirectionPoint = (*edge).GetTubeElement((*edge).GetNumberOfElements() - 1)->GetCoordinates();
587 (edgeDirectionPoint[0] - centerVertex[0]),
588 (edgeDirectionPoint[1] - centerVertex[1]),
589 (edgeDirectionPoint[2] - centerVertex[2]));
590 vecOrientation.Normalize();
594 mitk::FillVector3D(vecRandom, (rand() % 100 - 50), (rand() % 100 - 50), (rand() % 100 - 50));
597 vecOrthoToOrientation = vecRandom - (vecRandom * vecOrientation) * vecOrientation;
598 vecOrthoToOrientation.Normalize();
602 vecCrossProduct = itk::CrossProduct(vecOrientation, vecOrthoToOrientation);
603 vecCrossProduct.Normalize();
607 vtkTransformMatrix->Identity();
609 vtkTransformMatrix->SetElement(0, 0, vecOrthoToOrientation[0]);
610 vtkTransformMatrix->SetElement(1, 0, vecOrthoToOrientation[1]);
611 vtkTransformMatrix->SetElement(2, 0, vecOrthoToOrientation[2]);
613 vtkTransformMatrix->SetElement(0, 1, vecOrientation[0]);
614 vtkTransformMatrix->SetElement(1, 1, vecOrientation[1]);
615 vtkTransformMatrix->SetElement(2, 1, vecOrientation[2]);
617 vtkTransformMatrix->SetElement(0, 2, vecCrossProduct[0]);
618 vtkTransformMatrix->SetElement(1, 2, vecCrossProduct[1]);
619 vtkTransformMatrix->SetElement(2, 2, vecCrossProduct[2]);
621 vtkTransformMatrix->SetElement(0, 3, centerVertex[0]);
622 vtkTransformMatrix->SetElement(1, 3, centerVertex[1]);
623 vtkTransformMatrix->SetElement(2, 3, centerVertex[2]);
626 transform->Concatenate(vtkTransformMatrix);
629 transform->Inverse();
634 plane->SetOrigin(0, 0, 0);
635 plane->SetNormal(0, 1, 0);
639 cylinder->SetCenter(0, 0, 0);
640 cylinder->SetRadius(cylinderDiameter / 2);
645 cutCylinder->SetOperationTypeToDifference();
646 cutCylinder->SetTransform(transform);
647 cutCylinder->AddFunction(cylinder);
648 cutCylinder->AddFunction(plane);
650 cylinderForClipping.insert(
676 double sphereColorR = 0;
677 double sphereColorG = 0;
678 double sphereColorB = 0;
681 cylinderForClipping.begin();
682 itClipStructure != cylinderForClipping.end();
685 vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
686 dynamic_cast<vtkPolyDataMapper *
>(ls->m_vtkSpheresActorMap[vertexDesc]->GetMapper());
688 if (sphereMapper != NULL)
692 clipperSphere->SetInputData(sphereMapper->GetInput());
693 clipperSphere->SetClipFunction(itClipStructure->second);
694 clipperSphere->GenerateClippedOutputOn();
695 clipperSphere->Update();
697 sphereMapper->SetInputConnection(clipperSphere->GetOutputPort());
698 sphereMapper->Update();
701 mitk::Color tubeColor = graphProperty->GetColorOfTube(itClipStructure->first);
702 sphereColorR += tubeColor[0];
703 sphereColorG += tubeColor[1];
704 sphereColorB += tubeColor[2];
708 cylinderForClipping.begin();
709 itTobBeClipped != cylinderForClipping.end();
714 if (itClipStructure->first != toBeClippedTube)
716 vtkSmartPointer<vtkPolyDataMapper> tubeMapper =
717 dynamic_cast<vtkPolyDataMapper *
>(ls->m_vtkTubesActorMap[toBeClippedTube]->GetMapper());
719 if (tubeMapper != NULL)
723 tubeMapper->Update();
724 clipperTube->SetInputData(tubeMapper->GetInput());
725 clipperTube->SetClipFunction(itClipStructure->second);
726 clipperTube->GenerateClippedOutputOn();
727 clipperTube->Update();
729 tubeMapper->SetInputConnection(clipperTube->GetOutputPort());
730 tubeMapper->Update();
735 if (cylinderForClipping.size() != 0)
737 sphereColorR /= 255 * cylinderForClipping.size();
738 sphereColorG /= 255 * cylinderForClipping.size();
739 sphereColorB /= 255 * cylinderForClipping.size();
742 ls->m_vtkSpheresActorMap[vertexDesc]->GetProperty()->SetColor(sphereColorR, sphereColorG, sphereColorB);
745 bool mitk::TubeGraphVtkMapper3D::ClipStructures()
750 itkWarningMacro(<<
"associated node is NULL!");
754 bool clipStructures =
false;
755 node->GetBoolProperty(
"Tube Graph.Clip Structures", clipStructures);
757 return clipStructures;
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
unsigned int GetNumberOfElements() const
void GeneratePolyDataForTube(TubeGraphEdge &edge, const TubeGraph::Pointer &graph, const TubeGraphProperty::Pointer &graphProperty, mitk::BaseRenderer *renderer)
void ClipPolyData(TubeGraphVertex &vertex, const TubeGraph::Pointer &graph, const TubeGraphProperty::Pointer &graphProperty, mitk::BaseRenderer *renderer)
Base Class for Tube Graphs.
virtual void GenerateTubeGraphData(mitk::BaseRenderer *renderer)
Base Class for Tube Graph Vertices.
Organizes the rendering process.
void GeneratePolyDataForFurcation(TubeGraphVertex &vertex, const TubeGraph::Pointer &graph, mitk::BaseRenderer *renderer)
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
T::Pointer GetData(const std::string &name)
virtual void RenderTubeGraphPropertyInformation(mitk::BaseRenderer *renderer)
TubeGraph::EdgeDescriptorType EdgeDescriptorType
std::pair< VertexDescriptorType, VertexDescriptorType > TubeDescriptorType
Property for tube graphs.
virtual ~TubeGraphVtkMapper3D()
Class for elements which describes tubular structur with a circular cross section.
Base Class for Tube Graph Edges.
virtual const TubeGraph * GetInput()
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
const TubeElement * GetTubeElement() const
boost::graph_traits< GraphType >::vertex_descriptor VertexDescriptorType
virtual const Point3D & GetCoordinates() const =0
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
std::vector< TubeElement * > GetElementVector()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.