29 #include <vtkActor2D.h> 30 #include <vtkCellArray.h> 31 #include <vtkCellData.h> 33 #include <vtkPoints.h> 34 #include <vtkPolyData.h> 35 #include <vtkPolyDataMapper2D.h> 36 #include <vtkProperty2D.h> 37 #include <vtkTriangle.h> 52 SimpleInterval(T start = T(), T end = T())
53 : m_LowerBoundary(
std::
min(start, end)), m_UpperBoundary(
std::
max(start, end))
57 T GetLowerBoundary()
const {
return m_LowerBoundary; }
58 T GetUpperBoundary()
const {
return m_UpperBoundary; }
59 bool empty()
const {
return m_LowerBoundary == m_UpperBoundary; }
60 bool operator<(
const SimpleInterval &otherInterval)
const 62 return this->m_UpperBoundary < otherInterval.GetLowerBoundary();
74 typedef SimpleInterval<T> IntervalType;
76 IntervalSet(IntervalType startingInterval) { m_IntervalsContainer.insert(std::move(startingInterval)); }
77 void operator-=(
const IntervalType &interval)
81 auto range = m_IntervalsContainer.equal_range(interval);
83 for (
auto iter = range.first; iter != range.second;)
85 auto subtractionResult = SubtractIntervals(*iter, interval);
88 iter = m_IntervalsContainer.erase(iter);
89 for (
auto &&interval : subtractionResult)
91 if (!interval.empty())
96 iter = m_IntervalsContainer.insert(iter, std::move(interval));
103 IntervalSet operator-(
const IntervalType &interval)
105 IntervalSet result = *
this;
110 typedef std::set<IntervalType> IntervalsContainer;
112 const IntervalsContainer &getIntervals()
const {
return m_IntervalsContainer; }
114 IntervalsContainer m_IntervalsContainer;
116 std::array<IntervalType, 2> SubtractIntervals(
const IntervalType &firstInterval,
const IntervalType &secondInterval)
118 assert(secondInterval.GetUpperBoundary() >= firstInterval.GetLowerBoundary() &&
119 firstInterval.GetUpperBoundary() >=
120 secondInterval.GetLowerBoundary());
122 if (secondInterval.GetLowerBoundary() < firstInterval.GetLowerBoundary())
124 if (firstInterval.GetUpperBoundary() < secondInterval.GetUpperBoundary())
126 std::array<IntervalType, 2> result = {{IntervalType(), IntervalType()}};
129 std::array<IntervalType, 2> result = {
130 {IntervalType(firstInterval.GetUpperBoundary(), secondInterval.GetUpperBoundary()), IntervalType()}};
134 if (firstInterval.GetUpperBoundary() < secondInterval.GetUpperBoundary())
136 std::array<IntervalType, 2> result = {
137 {IntervalType(firstInterval.GetLowerBoundary(), secondInterval.GetLowerBoundary()), IntervalType()}};
140 std::array<IntervalType, 2> result = {
141 {IntervalType(firstInterval.GetLowerBoundary(), secondInterval.GetLowerBoundary()),
142 IntervalType(secondInterval.GetUpperBoundary(), firstInterval.GetUpperBoundary())}};
157 : m_RenderOrientationArrows(false), m_ArrowOrientationPositive(true), m_DepthValue(1.0f)
185 if (generateDataRequired)
196 Self *otherInstance = *it;
199 if (otherInstance ==
this)
214 auto *otherGeometry =
dynamic_cast<PlaneGeometry *
>(otherData->GetPlaneGeometry());
215 if (otherGeometry && !dynamic_cast<AbstractTransformGeometry *>(otherData->GetPlaneGeometry()))
247 if (input.IsNull() || input.GetPointer() == rendererWorldPlaneGeometryData)
252 const auto *inputPlaneGeometry =
dynamic_cast<const PlaneGeometry *
>(input->GetPlaneGeometry());
254 const auto *worldPlaneGeometry =
257 if (worldPlaneGeometry && dynamic_cast<const AbstractTransformGeometry *>(worldPlaneGeometry) ==
nullptr &&
260 const BaseGeometry *referenceGeometry = inputPlaneGeometry->GetReferenceGeometry();
269 if (worldPlaneGeometry->IntersectionLine(inputPlaneGeometry, crossLine))
274 if (!hasIntersection)
282 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
283 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
284 vtkSmartPointer<vtkPolyData> linesPolyData = vtkSmartPointer<vtkPolyData>::New();
296 auto intervals = IntervalSet<double>(SimpleInterval<double>(0, 1));
298 ScalarType lineLength = point1.EuclideanDistanceTo(point2);
300 float gapSizeParam = gapInMM / lineLength;
304 while (otherPlanesIt != otherPlanesEnd)
306 bool ignorePlane =
false;
307 (*otherPlanesIt)->GetPropertyValue(
"Crosshair.Ignore", ignorePlane);
315 static_cast<PlaneGeometryData *
>((*otherPlanesIt)->GetData())->GetPlaneGeometry());
317 if (otherPlaneGeometry != inputPlaneGeometry && otherPlaneGeometry != worldPlaneGeometry)
319 double intersectionParam;
320 if (otherPlaneGeometry->IntersectionPointParam(crossLine, intersectionParam) && intersectionParam > 0 &&
321 intersectionParam < 1)
325 bool intersectionPointInsideOtherPlane =
326 otherPlaneGeometry->HasReferenceGeometry() ?
330 if (intersectionPointInsideOtherPlane)
332 intervals -= SimpleInterval<double>(intersectionParam - gapSizeParam, intersectionParam + gapSizeParam);
340 for (
const auto &interval : intervals.getIntervals())
343 crossLine.
GetPoint(interval.GetUpperBoundary()),
349 linesPolyData->SetPoints(points);
351 linesPolyData->SetLines(lines);
354 orthogonalVector = inputPlaneGeometry->GetNormal();
355 worldPlaneGeometry->Project(orthogonalVector, orthogonalVector);
356 orthogonalVector.Normalize();
359 ls->
m_Mapper->SetInputData(linesPolyData);
364 bool showAreaOfThickSlicing =
false;
369 referenceGeometry ? referenceGeometry->
GetSpacing() : inputPlaneGeometry->GetSpacing(), orthogonalVector);
373 thickSliceDistance *= intProperty->
GetValue() + 0.5;
375 showAreaOfThickSlicing =
false;
383 vtkSmartPointer<vtkPolyData> arrowPolyData = vtkSmartPointer<vtkPolyData>::New();
389 vtkSmartPointer<vtkCellArray> triangles = vtkSmartPointer<vtkCellArray>::New();
390 vtkSmartPointer<vtkPoints> triPoints = vtkSmartPointer<vtkPoints>::New();
394 arrowPolyData->SetPoints(triPoints);
395 arrowPolyData->SetPolys(triangles);
400 vtkSmartPointer<vtkPolyData> helperlinesPolyData = vtkSmartPointer<vtkPolyData>::New();
402 if (showAreaOfThickSlicing)
404 vtkSmartPointer<vtkCellArray> helperlines = vtkSmartPointer<vtkCellArray>::New();
407 Vector3D vecToHelperLine = orthogonalVector * thickSliceDistance;
409 this->
DrawLine(point1 - vecToHelperLine, point2 - vecToHelperLine, helperlines, points);
410 this->
DrawLine(point1 + vecToHelperLine, point2 + vecToHelperLine, helperlines, points);
413 helperlinesPolyData->SetPoints(points);
416 helperlinesPolyData->SetLines(helperlines);
429 planeGeometry->
Map(point, mappedPoint);
432 return (planeGeometry->
GetBounds()[0] < mappedPoint[0] && mappedPoint[0] < planeGeometry->
GetBounds()[1] &&
433 planeGeometry->
GetBounds()[2] < mappedPoint[1] && mappedPoint[1] < planeGeometry->
GetBounds()[3]);
439 return referenceGeometry->
IsInside(point);
448 planeGeometry->
Map(crossLine.
GetPoint(), indexLinePoint);
451 planeGeometry->
WorldToIndex(indexLinePoint, indexLinePoint);
452 planeGeometry->
WorldToIndex(indexLineDirection, indexLineDirection);
464 intersectionPoints[0],
465 intersectionPoints[1]);
467 if (nIntersections < 2)
472 planeGeometry->
IndexToWorld(intersectionPoints[0], intersectionPoints[0]);
473 planeGeometry->
IndexToWorld(intersectionPoints[1], intersectionPoints[1]);
477 planeGeometry->
Map(intersectionPoints[0], point1);
478 planeGeometry->
Map(intersectionPoints[1], point2);
487 Point3D boundingBoxMin, boundingBoxMax;
497 referenceGeometry->
WorldToIndex(boundingBoxMin, boundingBoxMin);
498 referenceGeometry->
WorldToIndex(boundingBoxMax, boundingBoxMax);
515 if (nIntersections < 2)
532 vtkIdType pidStart = points->InsertNextPoint(p0[0], p0[1], p0[2]);
533 vtkIdType pidEnd = points->InsertNextPoint(p1[0], p1[1], p1[2]);
535 vtkSmartPointer<vtkLine> lineVtk = vtkSmartPointer<vtkLine>::New();
536 lineVtk->GetPointIds()->SetId(0, pidStart);
537 lineVtk->GetPointIds()->SetId(1, pidEnd);
539 lines->InsertNextCell(lineVtk);
543 vtkSmartPointer<vtkPoints> triPoints,
544 double triangleSizeMM,
553 v1 *= triangleSizeMM;
557 v2 *= triangleSizeMM;
562 Point3D p1 = point1 + v1 * 2.0;
565 vtkIdType t0 = triPoints->InsertNextPoint(point1[0], point1[1], point1[2]);
566 vtkIdType t1 = triPoints->InsertNextPoint(p1[0], p1[1], p1[2]);
567 vtkIdType
t2 = triPoints->InsertNextPoint(p2[0], p2[1], p2[2]);
569 vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
570 triangle->GetPointIds()->SetId(0, t0);
571 triangle->GetPointIds()->SetId(1, t1);
572 triangle->GetPointIds()->SetId(2, t2);
574 triangles->InsertNextCell(triangle);
579 int thickSlicesMode = 0;
582 if (dn->
GetProperty(resliceMethodEnumProperty,
"reslice.thickslices") && resliceMethodEnumProperty)
583 thickSlicesMode = resliceMethodEnumProperty->
GetValueAsId();
586 if (dn->
GetProperty(intProperty,
"reslice.thickslices.num") && intProperty)
588 thickSlicesNum = intProperty->
GetValue();
589 if (thickSlicesNum < 1)
591 if (thickSlicesNum > 10)
595 if (thickSlicesMode == 0)
598 return thickSlicesMode;
615 if (decorationProperty !=
nullptr)
637 float rgba[4] = {1.0f, 1.0f, 1.0f, 1.0f};
641 node->
GetColor(rgba, renderer,
"color");
643 node->
GetOpacity(rgba[3], renderer,
"opacity");
645 double drgba[4] = {rgba[0], rgba[1], rgba[2], rgba[3]};
646 actor->GetProperty()->SetColor(drgba);
647 actor->GetProperty()->SetOpacity(drgba[3]);
656 aliases->
AddAlias(
"line width",
"Crosshair.Line Width",
"");
662 aliases->
AddAlias(
"decoration",
"Crosshair.Orientation Decoration",
"");
673 m_CrosshairAssembly = vtkSmartPointer<vtkPropAssembly>::New();
675 m_CrosshairActor = vtkSmartPointer<vtkActor2D>::New();
676 m_ArrowActor = vtkSmartPointer<vtkActor2D>::New();
677 m_CrosshairHelperLineActor = vtkSmartPointer<vtkActor2D>::New();
679 m_HelperLinesmapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
680 m_Mapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
681 m_Arrowmapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
683 m_CrosshairActor->SetMapper(m_Mapper);
684 m_ArrowActor->SetMapper(m_Arrowmapper);
685 m_CrosshairHelperLineActor->SetMapper(m_HelperLinesmapper);
687 m_CrosshairActor->SetVisibility(0);
688 m_ArrowActor->SetVisibility(0);
689 m_CrosshairHelperLineActor->SetVisibility(0);
691 m_CrosshairAssembly->AddPart(m_CrosshairActor);
692 m_CrosshairAssembly->AddPart(m_ArrowActor);
693 m_CrosshairAssembly->AddPart(m_CrosshairHelperLineActor);
695 vtkCoordinate *tcoord = vtkCoordinate::New();
696 tcoord->SetCoordinateSystemToWorld();
697 m_HelperLinesmapper->SetTransformCoordinate(tcoord);
698 m_Mapper->SetTransformCoordinate(tcoord);
700 m_Arrowmapper->SetTransformCoordinate(tcoord);
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr, bool fallBackOnDataProperties=true) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
virtual IdType GetValueAsId() const
vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
returns the a prop assembly
virtual int GetPlaneDecoration()
Interface of property aliases service.
vtkSmartPointer< vtkActor2D > m_ArrowActor
virtual DataNode * GetCurrentWorldPlaneGeometryNode()
Get a DataNode pointing to a data object containing the current 2D-worldgeometry. ...
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
bool m_ArrowOrientationPositive
void IndexToWorld(const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const
Convert (continuous or discrete) index coordinates of a vector vec_units to world coordinates (in mm)...
Base class for mapper specific rendering ressources.
PlaneGeometryDataMapper2D()
vtkSmartPointer< vtkPolyDataMapper2D > m_Arrowmapper
vtkSmartPointer< vtkActor2D > m_CrosshairHelperLineActor
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Mapper *mapper, mitk::DataNode *dataNode) const
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
void DrawOrientationArrow(vtkSmartPointer< vtkCellArray > triangles, vtkSmartPointer< vtkPoints > triPoints, double triangleSizeMM, Vector3D &orthogonalVector, Point3D &point1, Point3D &point2)
bool IsInside(const mitk::Point3D &p) const
Test whether the point p (world coordinates in mm) is inside the bounding box.
Internal class holding the mapper, actor, etc. for each of the 3 2D render windows.
bool GetFloatProperty(const char *propertyKey, float &floatValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for float properties (instances of FloatProperty)
bool operator<(const StaticParameterMap::ValueType &a, const StaticParameterMap::ValueType &b)
Compares two var lists and returns true if the first list's first item is lower than the second one's...
Organizes the rendering process.
double GetScaleFactorMMPerDisplayUnit() const
NodesVectorType m_OtherPlaneGeometries
Point3D GetCornerPoint(int id) const
Get the position of the corner number id (in world coordinates)
virtual bool AddAlias(const std::string &propertyName, const std::string &alias, const std::string &className="")=0
Add an alias for a specific property.
bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for GenericProperty<T> properties (T being the type of the second parameter...
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
set the default properties for this mapper
static int BoxLineIntersection(TCoordRep x1, TCoordRep y1, TCoordRep z1, TCoordRep x2, TCoordRep y2, TCoordRep z2, itk::Point< TCoordRep, 3 > p, itk::Vector< TCoordRep, 3 > d, itk::Point< TCoordRep, 3 > &s1, itk::Point< TCoordRep, 3 > &s2)
Calculates the intersection points of a straight line in 3D with a box.
virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const
Project a 3D point given in mm (pt3d_mm) onto the 2D geometry. The result is a 2D point in mm (pt2d_m...
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
Base class of all mappers, Vtk as well as OpenGL mappers.
vtkSmartPointer< vtkPropAssembly > m_CrosshairAssembly
mitk::LocalStorageHandler< LocalStorage > m_LSH
The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows.
virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const
int DetermineThickSliceMode(DataNode *dn, int &thickSlicesNum)
Returns the thick slice mode for the given datanode.
const itk::Point< TCoordRep, NPointDimension > & GetPoint() const
Get start point of the line.
bool m_RenderOrientationArrows
virtual T GetValue() const
const itk::Point< TCoordRep, NPointDimension > & GetPoint1() const
Get start point of the line.
const itk::Vector< TCoordRep, NPointDimension > & GetDirection() const
Get the direction vector of the line.
void ApplyColorAndOpacityProperties2D(BaseRenderer *renderer, vtkActor2D *actor)
void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting float properties (instances of FloatProperty)
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
static bool CutCrossLineWithReferenceGeometry(const BaseGeometry *referenceGeometry, Line3D &crossLine)
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
bool IsVisible(const mitk::BaseRenderer *renderer, const char *propertyKey="visible", bool defaultIsOn=true) const
Convenience access method for visibility properties (instances of BoolProperty). Return value is the ...
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const
static bool TestPointInPlaneGeometry(const PlaneGeometry *planeGeometry, const Point3D &point)
void UpdateVtkTransform(mitk::BaseRenderer *renderer) override
Set the vtkTransform of the m_Prop3D for the current time step of renderer.
void SetPoints(const itk::Point< TCoordRep, NPointDimension > &point1, const itk::Point< TCoordRep, NPointDimension > &point2)
Define line by two points.
bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey="visible") const
Convenience access method for visibility properties (instances of BoolProperty with property-key "vis...
vtkSmartPointer< vtkPolyDataMapper2D > m_Mapper
~PlaneGeometryDataMapper2D() override
Data class containing PlaneGeometry objects.
static bool CutCrossLineWithPlaneGeometry(const PlaneGeometry *planeGeometry, Line3D &crossLine)
static AllInstancesContainer s_AllInstances
void CreateVtkCrosshair(BaseRenderer *renderer)
void WorldToIndex(const mitk::Point3D &pt_mm, mitk::Point3D &pt_units) const
Convert world coordinates (in mm) of a point to (continuous!) index coordinates.
vtkSmartPointer< vtkActor2D > m_CrosshairActor
vtkSmartPointer< vtkPolyDataMapper2D > m_HelperLinesmapper
static bool TestPointInReferenceGeometry(const BaseGeometry *referenceGeometry, const Point3D &point)
virtual const mitk::PlaneGeometryData * GetInput() const
virtual void ApplyAllProperties(BaseRenderer *renderer)
itk::Point< TCoordRep, NPointDimension > GetPoint2() const
Get end point of the line.
void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
std::set< Self * > AllInstancesContainer
void UpdateGenerateDataTime()
static double CalculateSpacing(const mitk::Vector3D &spacing, const mitk::Vector3D &d)
static int RectangleLineIntersection(TCoordRep x1, TCoordRep y1, TCoordRep x2, TCoordRep y2, itk::Point< TCoordRep, 2 > p, itk::Vector< TCoordRep, 2 > d, itk::Point< TCoordRep, 2 > &s1, itk::Point< TCoordRep, 2 > &s2)
Calculates the intersection points of a straight line in 2D with a rectangle.
Describes a two-dimensional, rectangular plane.
virtual mitk::PlaneGeometry * GetPlaneGeometry() const
Get the reference to the PlaneGeometry that is stored by the object.
static IPropertyAliases * GetPropertyAliases(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyAliases instance.
const BoundsArrayType GetBounds() const
BaseGeometry Describes the geometry of a data object.
Class for nodes of the DataTree.
void DrawLine(Point3D p0, Point3D p1, vtkCellArray *lines, vtkPoints *points)
static void SetDefaultProperties(DataNode *node, BaseRenderer *renderer=nullptr, bool overwrite=false)
Set default values of properties used by this mapper to node.