diff --git a/Modules/Core/include/vtkMitkRectangleProp.h b/Modules/Core/include/vtkMitkRectangleProp.h index c73221d42b..707ad3677d 100644 --- a/Modules/Core/include/vtkMitkRectangleProp.h +++ b/Modules/Core/include/vtkMitkRectangleProp.h @@ -1,75 +1,68 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. 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 vtkMitkRectangleProp_h #define vtkMitkRectangleProp_h #include #include -#include #include class vtkPolyData; +class vtkViewport; /** - * @brief The vtkMitkRectangleProp2 class Renders a rectangle into a renderwindow as a frame. - * - * This class is a replacement for the deprecated vtkMitkRectangleProp, which - * used to render the same effect with pure OpenGL. + * @brief The vtkMitkRectangleProp class renders a rectangle into a renderwindow as a frame. */ class MITKCORE_EXPORT vtkMitkRectangleProp : public vtkActor2D { public: static vtkMitkRectangleProp *New(); vtkTypeMacro(vtkMitkRectangleProp, vtkProp); - /** - * @brief SetColor Set the color of the rectangle. - * @param col1 red - * @param col2 green - * @param col3 blue - */ - void SetColor(float col1, float col2, float col3); - + void SetColor(float red, float green, float blue); void SetLineWidth(unsigned int lineWidth); - int RenderOverlay(vtkViewport *viewport) override; protected: vtkMitkRectangleProp(); ~vtkMitkRectangleProp() override; +private: + /** + * @brief Internal helper to fill a vtkPolydata with a rectangle. + */ + void CreateRectangle(); + void UpdateRectangle(); + int m_Height; int m_Width; int m_OriginX; int m_OriginY; - vtkIdType m_BottomLeftR, m_BottomRightL, m_BottomLeftU, m_TopLeftD, m_TopLeftR, m_TopRightL, m_TopRightD, - m_BottomRightU; - - /** - * @brief CreateRectangle internal helper to fill a vtkPolydata with a rectangle. - */ - void CreateRectangle(); - void UpdateRectangle(); + vtkIdType m_BottomLeft; + vtkIdType m_BottomRight; + vtkIdType m_TopRight; + vtkIdType m_TopLeft; /** - * @brief m_PolyData holds the rectangle. - */ + * @brief Holds the rectangle. + */ vtkSmartPointer m_PolyData; }; -#endif /* vtkMitkRectangleProp_h */ + +#endif diff --git a/Modules/Core/src/Rendering/vtkMitkRectangleProp.cpp b/Modules/Core/src/Rendering/vtkMitkRectangleProp.cpp index e43fc553ff..2661c1dc8e 100644 --- a/Modules/Core/src/Rendering/vtkMitkRectangleProp.cpp +++ b/Modules/Core/src/Rendering/vtkMitkRectangleProp.cpp @@ -1,152 +1,132 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. 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 "vtkMitkRectangleProp.h" -#include -#include #include -#include -#include #include #include #include -#include #include vtkStandardNewMacro(vtkMitkRectangleProp); -vtkMitkRectangleProp::vtkMitkRectangleProp() : m_Height(0), m_Width(0), m_OriginX(0), m_OriginY(0) +vtkMitkRectangleProp::vtkMitkRectangleProp() + : m_Height(0), + m_Width(0), + m_OriginX(0), + m_OriginY(0), + m_PolyData(vtkSmartPointer::New()) { - vtkSmartPointer mapper = vtkSmartPointer::New(); - m_PolyData = vtkSmartPointer::New(); - - vtkSmartPointer lines = vtkSmartPointer::New(); - vtkSmartPointer points = vtkSmartPointer::New(); - + auto points = vtkSmartPointer::New(); m_PolyData->SetPoints(points); + + auto lines = vtkSmartPointer::New(); m_PolyData->SetLines(lines); - vtkCoordinate *tcoord = vtkCoordinate::New(); - tcoord->SetCoordinateSystemToDisplay(); - mapper->SetTransformCoordinate(tcoord); - tcoord->Delete(); + auto mapper = vtkSmartPointer::New(); - CreateRectangle(); + auto transformCoordinate = vtkSmartPointer::New(); + transformCoordinate->SetCoordinateSystemToDisplay(); + mapper->SetTransformCoordinate(transformCoordinate); + + this->CreateRectangle(); mapper->SetInputData(m_PolyData); - SetMapper(mapper); - GetProperty()->SetLineWidth(2); + this->SetMapper(mapper); + + this->GetProperty()->SetLineWidth(2); } vtkMitkRectangleProp::~vtkMitkRectangleProp() { } int vtkMitkRectangleProp::RenderOverlay(vtkViewport *viewport) { - if (!this->Mapper) + if (nullptr == this->Mapper) { vtkErrorMacro(<< "vtkActor2D::Render - No mapper set"); return 0; } if (!GetVisibility()) return 0; + if (viewport->GetSize()[0] != m_Width || viewport->GetSize()[1] != m_Height) { m_Width = viewport->GetSize()[0]; m_Height = viewport->GetSize()[1]; m_OriginX = viewport->GetOrigin()[0]; m_OriginY = viewport->GetOrigin()[1]; - UpdateRectangle(); + this->UpdateRectangle(); } - this->Mapper->RenderOverlay(viewport, this); + this->Mapper->RenderOverlay(viewport, this); return 1; } void vtkMitkRectangleProp::UpdateRectangle() { - vtkSmartPointer points = m_PolyData->GetPoints(); - float offset = (GetProperty()->GetLineWidth() - 0.5); - float wLine = m_OriginX + m_Width - 1; - float hLine = m_OriginY + m_Height - 1; - float offX = m_OriginX + offset; - float offY = m_OriginY + offset; - - points->SetPoint(m_BottomLeftR, m_OriginX, offY, 0.0); - points->SetPoint(m_BottomRightL, m_Width + m_OriginX, offY, 0.0); - - points->SetPoint(m_BottomLeftU, offX, m_OriginY, 0.0); - points->SetPoint(m_TopLeftD, offX, m_OriginY + m_Height, 0.0); - - points->SetPoint(m_TopLeftR, m_OriginX, hLine, 0.0); - points->SetPoint(m_TopRightL, m_Width + m_OriginX, hLine, 0.0); + float offset = this->GetProperty()->GetLineWidth() * 0.5f; - points->SetPoint(m_TopRightD, wLine, m_OriginY + m_Height, 0.0); - points->SetPoint(m_BottomRightU, wLine, m_OriginY, 0.0); + auto points = m_PolyData->GetPoints(); + points->SetPoint(m_BottomLeft, m_OriginX + offset, m_OriginY + offset, 0.0f); + points->SetPoint(m_BottomRight, m_OriginX + m_Width - offset, m_OriginY + offset, 0.0f); + points->SetPoint(m_TopRight, m_OriginX + m_Width - offset, m_OriginY + m_Height - offset, 0.0f); + points->SetPoint(m_TopLeft, m_OriginX + offset, m_OriginY + m_Height - offset, 0.0f); } void vtkMitkRectangleProp::CreateRectangle() { - vtkSmartPointer points = m_PolyData->GetPoints(); - vtkSmartPointer lines = m_PolyData->GetLines(); - - // 4 corner points - m_BottomLeftR = points->InsertNextPoint(0.0, 0.0, 0.0); - m_BottomRightL = points->InsertNextPoint(1.0, 0.0, 0.0); - - m_BottomLeftU = points->InsertNextPoint(0.0, 0.0, 0.0); - m_TopLeftD = points->InsertNextPoint(0.0, 1.0, 0.0); - - m_TopLeftR = points->InsertNextPoint(0.0, 1.0, 0.0); - m_TopRightL = points->InsertNextPoint(1.0, 1.0, 0.0); - - m_TopRightD = points->InsertNextPoint(1.0, 1.0, 0.0); - m_BottomRightU = points->InsertNextPoint(1.0, 0.0, 0.0); - - vtkSmartPointer lineVtk; - lineVtk = vtkSmartPointer::New(); - lineVtk->GetPointIds()->SetId(0, m_BottomLeftR); - lineVtk->GetPointIds()->SetId(1, m_BottomRightL); - lines->InsertNextCell(lineVtk); - - lineVtk = vtkSmartPointer::New(); - lineVtk->GetPointIds()->SetId(0, m_BottomLeftU); - lineVtk->GetPointIds()->SetId(1, m_TopLeftD); - lines->InsertNextCell(lineVtk); - - lineVtk = vtkSmartPointer::New(); - lineVtk->GetPointIds()->SetId(0, m_TopLeftR); - lineVtk->GetPointIds()->SetId(1, m_TopRightL); - lines->InsertNextCell(lineVtk); - - lineVtk = vtkSmartPointer::New(); - lineVtk->GetPointIds()->SetId(0, m_TopRightD); - lineVtk->GetPointIds()->SetId(1, m_BottomRightU); - lines->InsertNextCell(lineVtk); + auto points = m_PolyData->GetPoints(); + auto lines = m_PolyData->GetLines(); + + m_BottomLeft = points->InsertNextPoint(0.0f, 0.0f, 0.0f); + m_BottomRight = points->InsertNextPoint(1.0f, 0.0f, 0.0f); + m_TopRight = points->InsertNextPoint(1.0f, 1.0f, 0.0f); + m_TopLeft = points->InsertNextPoint(0.0f, 1.0f, 0.0f); + + auto line = vtkSmartPointer::New(); + line->GetPointIds()->SetId(0, m_BottomLeft); + line->GetPointIds()->SetId(1, m_BottomRight); + lines->InsertNextCell(line); + + line = vtkSmartPointer::New(); + line->GetPointIds()->SetId(0, m_BottomRight); + line->GetPointIds()->SetId(1, m_TopRight); + lines->InsertNextCell(line); + + line = vtkSmartPointer::New(); + line->GetPointIds()->SetId(0, m_TopRight); + line->GetPointIds()->SetId(1, m_TopLeft); + lines->InsertNextCell(line); + + line = vtkSmartPointer::New(); + line->GetPointIds()->SetId(0, m_TopLeft); + line->GetPointIds()->SetId(1, m_BottomLeft); + lines->InsertNextCell(line); } -void vtkMitkRectangleProp::SetColor(float col1, float col2, float col3) +void vtkMitkRectangleProp::SetColor(float red, float green, float blue) { - GetProperty()->SetColor(col1, col2, col3); + this->GetProperty()->SetColor(red, green, blue); } void vtkMitkRectangleProp::SetLineWidth(unsigned int lineWidth) { - GetProperty()->SetLineWidth(lineWidth); + this->GetProperty()->SetLineWidth(lineWidth); }