19 #include <vtkLinearTransform.h> 21 #include "vtkContext2D.h" 22 #include "vtkContextDevice2D.h" 23 #include "vtkOpenGLContextDevice2D.h" 42 vtkOpenGLContextDevice2D *device =
nullptr;
43 device = vtkOpenGLContextDevice2D::New();
57 float rgba[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
67 this->
m_Context->GetPen()->SetColorF((
double)rgba[0], (
double)rgba[1], (
double)rgba[2], (
double)rgba[3]);
89 if (!renderingContour)
95 vtkOpenGLContextDevice2D::SafeDownCast(
112 dataNode->GetFloatProperty(
"opacity", opacity, renderer);
117 double red = colorprop->GetColor().GetRed();
118 double green = colorprop->GetColor().GetGreen();
119 double blue = colorprop->GetColor().GetBlue();
120 this->
m_Context->GetPen()->SetColorF(red, green, blue, opacity);
124 dynamic_cast<mitk::ColorProperty *
>(dataNode->GetProperty(
"contour.points.color", renderer));
130 vtkLinearTransform *transform = dataNode->GetVtkTransform();
137 float lineWidth = 3.0;
141 bool isHovering =
false;
142 dataNode->GetBoolProperty(
"contour.hovering", isHovering);
145 dataNode->GetFloatProperty(
"contour.hovering.width", lineWidth);
147 dataNode->GetFloatProperty(
"contour.width", lineWidth);
149 bool showSegments =
false;
150 dataNode->GetBoolProperty(
"contour.segments.show", showSegments);
152 bool showControlPoints =
false;
153 dataNode->GetBoolProperty(
"contour.controlpoints.show", showControlPoints);
155 bool showPoints =
false;
156 dataNode->GetBoolProperty(
"contour.points.show", showPoints);
158 bool showPointsNumbers =
false;
159 dataNode->GetBoolProperty(
"contour.points.text", showPointsNumbers);
161 bool showControlPointsNumbers =
false;
162 dataNode->GetBoolProperty(
"contour.controlpoints.text", showControlPointsNumbers);
164 bool projectmode =
false;
165 dataNode->GetVisibility(projectmode, renderer,
"contour.project-onto-plane");
176 while (pointsIt != renderingContour->
IteratorEnd(timestep))
180 point = (*pointsIt)->Coordinates;
183 transform->TransformPoint(vtkp, vtkp);
195 else if (scalardiff < maxDiff)
210 if (!(pointsIt == renderingContour->
IteratorBegin(timestep)))
212 this->
m_Context->GetPen()->SetWidth(lineWidth);
213 this->
m_Context->DrawLine(pt2d[0], pt2d[1], lastPt2d[0], lastPt2d[1]);
218 if (showControlPoints)
221 if ((*pointsIt)->IsControlPoint)
231 this->
m_Context->GetPen()->SetColorF(selectedcolor->GetColor().GetRed(),
232 selectedcolor->GetColor().GetBlue(),
233 selectedcolor->GetColor().GetGreen());
236 auto* rectPts =
new float[8];
252 colorprop->GetColor().GetRed(), colorprop->GetColor().GetGreen(), colorprop->GetColor().GetBlue());
253 this->
m_Context->DrawPoint(pt2d[0], pt2d[1]);
267 this->
m_Context->GetPen()->SetColorF(0.0, 0.0, 0.0);
270 auto* rectPts =
new float[8];
283 this->
m_Context->DrawPolygon(rectPts, 4);
286 colorprop->GetColor().GetRed(), colorprop->GetColor().GetGreen(), colorprop->GetColor().GetBlue());
287 this->
m_Context->DrawPoint(pt2d[0], pt2d[1]);
290 if (showPointsNumbers)
293 std::stringstream ss;
305 if (showControlPointsNumbers && (*pointsIt)->IsControlPoint)
308 std::stringstream ss;
327 if (renderingContour->
IsClosed(timestep) && drawit && showSegments)
332 transform->TransformPoint(vtkp, vtkp);
336 this->
m_Context->GetPen()->SetWidth(lineWidth);
337 this->
m_Context->DrawLine(lastPt2d[0], lastPt2d[1], pt2d[0], pt2d[1]);
348 transform->TransformPoint(vtkp, vtkp);
357 if (scalardiff < maxDiff)
362 this->
m_Context->GetPen()->SetColorF(0.0, 1.0, 0.0);
365 auto* rectPts =
new float[8];
368 rectPts[0] = pt2d[0] - pointsize;
369 rectPts[1] = pt2d[1] + pointsize;
370 rectPts[2] = pt2d[0] + pointsize;
371 rectPts[3] = pt2d[1] + pointsize;
372 rectPts[4] = pt2d[0] + pointsize;
373 rectPts[5] = pt2d[1] - pointsize;
374 rectPts[6] = pt2d[0] - pointsize;
375 rectPts[7] = pt2d[1] - pointsize;
376 this->
m_Context->DrawPolygon(rectPts, 4);
390 textAnnotation->SetText(text);
391 textAnnotation->SetColor(rgb);
392 textAnnotation->SetOpacity(1);
393 textAnnotation->SetFontSize(16);
394 textAnnotation->SetBoolProperty(
"drawShadow",
false);
395 textAnnotation->SetVisibility(
true);
virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const
TextAnnotationPointerType m_PointNumbersAnnotation
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
void UpdateOutputInformation() override
Update the OutputInformation of a ContourModel object.
virtual const VertexType * GetVertexAt(int index, int timestep=0) const
Returns the vertex at the index position within the container.
mitk::Point3D Coordinates
Coordinates in 3D space.
vtkRenderer * GetVtkRenderer() const
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
virtual void InternalDrawContour(mitk::ContourModel *renderingContour, mitk::BaseRenderer *renderer)
Organizes the rendering process.
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
void ApplyColorAndOpacityProperties(mitk::BaseRenderer *renderer, vtkActor *actor=nullptr) override
Apply specific color and opacity properties read from the PropertyList. Reimplemented in GLmapper (do...
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
void WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const
This method converts a 3D world index to the display point using the geometry of the renderWindow...
void Initialize(mitk::BaseRenderer *renderer)
The ColorProperty class RGB color property.
VertexType * GetSelectedVertex()
Get the current selected vertex.
ContourModelGLMapper2DBase()
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
bool IsEmptyTimeStep(unsigned int t) const override
Check if there isn't something at this timestep.
void WriteTextWithAnnotation(TextAnnotationPointerType textAnnotation, const char *text, float rgb[3], Point2D pt2d, mitk::BaseRenderer *)
void DrawContour(mitk::ContourModel *contour, mitk::BaseRenderer *renderer)
virtual unsigned int GetTimeStep() const
RendererListType m_RendererList
void vtk2itk(const Tin &in, Tout &out)
VertexIterator IteratorEnd(int timestep=0) const
Returns a const VertexIterator at the end element of the contour.
~ContourModelGLMapper2DBase() override
bool IsClosed(int timestep=0) const
Return if the contour is closed or not.
static void AddAnnotation(Annotation *Annotation, const std::string &rendererID)
void itk2vtk(const Tin &in, Tout &out)
VertexIterator IteratorBegin(int timestep=0) const
Returns a const VertexIterator at the start element of the contour.
TextAnnotationPointerType m_ControlPointNumbersAnnotation
vtkNew< vtkContext2D > m_Context
void WorldToView(const Point3D &worldIndex, Point2D &viewPoint) const
This method converts a 3D world index to the point on the viewport using the geometry of the renderWi...
Class for nodes of the DataTree.