diff --git a/Modules/Annotation/src/mitkColorBarAnnotation.cpp b/Modules/Annotation/src/mitkColorBarAnnotation.cpp index 9798634a5e..6d854a7e34 100644 --- a/Modules/Annotation/src/mitkColorBarAnnotation.cpp +++ b/Modules/Annotation/src/mitkColorBarAnnotation.cpp @@ -1,183 +1,190 @@ /*=================================================================== 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 "mitkColorBarAnnotation.h" #include "mitkLookupTable.h" #include "mitkLookupTableProperty.h" #include mitk::ColorBarAnnotation::ColorBarAnnotation() { SetDrawAnnotations(true); SetDrawTickLabels(true); SetOrientationToVertical(); SetMaxNumberOfColors(100); SetNumberOfLabels(4); SetAnnotationTextScaling(false); SetLookupTable(NULL); } mitk::ColorBarAnnotation::~ColorBarAnnotation() { + for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer()) + { + if (renderer) + { + this->RemoveFromBaseRenderer(renderer); + } + } } mitk::ColorBarAnnotation::LocalStorage::~LocalStorage() { } mitk::ColorBarAnnotation::LocalStorage::LocalStorage() { m_ScalarBarActor = vtkSmartPointer::New(); } void mitk::ColorBarAnnotation::UpdateVtkAnnotation(mitk::BaseRenderer *renderer) { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); if (ls->IsGenerateDataRequired(renderer, this)) { ls->m_ScalarBarActor->SetDrawAnnotations(this->GetDrawAnnotations()); ls->m_ScalarBarActor->SetLookupTable(this->GetLookupTable()); ls->m_ScalarBarActor->SetOrientation(this->GetOrientation()); ls->m_ScalarBarActor->SetDrawTickLabels(this->GetDrawTickLabels()); ls->m_ScalarBarActor->SetMaximumNumberOfColors(this->GetMaxNumberOfColors()); ls->m_ScalarBarActor->SetNumberOfLabels(this->GetNumberOfLabels()); ls->m_ScalarBarActor->SetAnnotationTextScaling(this->GetAnnotationTextScaling()); // manually set position so there is no overlap with mitk logo in 3d renderwindow if (this->GetOrientation() == 1) { ls->m_ScalarBarActor->SetPosition(0.80, 0.15); ls->m_ScalarBarActor->SetWidth(0.15); ls->m_ScalarBarActor->SetHeight(0.85); } else { ls->m_ScalarBarActor->SetPosition(0.03, 0.03); ls->m_ScalarBarActor->SetWidth(0.8); ls->m_ScalarBarActor->SetHeight(0.15); } } } vtkProp *mitk::ColorBarAnnotation::GetVtkProp(BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_ScalarBarActor; } void mitk::ColorBarAnnotation::SetDrawAnnotations(bool annotations) { SetBoolProperty("ColorBarAnnotation.DrawAnnotations", annotations); } bool mitk::ColorBarAnnotation::GetDrawAnnotations() const { bool annotations; GetPropertyList()->GetBoolProperty("ColorBarAnnotation.DrawAnnotations", annotations); return annotations; } void mitk::ColorBarAnnotation::SetLookupTable(vtkSmartPointer table) { mitk::LookupTable::Pointer lut = mitk::LookupTable::New(); mitk::LookupTableProperty::Pointer prop = mitk::LookupTableProperty::New(lut); lut->SetVtkLookupTable(table); prop->SetLookupTable(lut); SetProperty("ColorBarAnnotation.LookupTable", prop.GetPointer()); } vtkSmartPointer mitk::ColorBarAnnotation::GetLookupTable() const { mitk::LookupTable::Pointer lut = mitk::LookupTable::New(); lut = dynamic_cast(GetPropertyList()->GetProperty("ColorBarAnnotation.LookupTable")) ->GetLookupTable(); return lut->GetVtkLookupTable(); } void mitk::ColorBarAnnotation::SetOrientation(int orientation) { SetIntProperty("ColorBarAnnotation.Orientation", orientation); } int mitk::ColorBarAnnotation::GetOrientation() const { int orientation; GetPropertyList()->GetIntProperty("ColorBarAnnotation.Orientation", orientation); return orientation; } void mitk::ColorBarAnnotation::SetDrawTickLabels(bool ticks) { SetBoolProperty("ColorBarAnnotation.DrawTicks", ticks); } bool mitk::ColorBarAnnotation::GetDrawTickLabels() const { bool ticks; GetPropertyList()->GetBoolProperty("ColorBarAnnotation.DrawTicks", ticks); return ticks; } void mitk::ColorBarAnnotation::SetOrientationToHorizontal() { SetOrientation(0); } void mitk::ColorBarAnnotation::SetOrientationToVertical() { SetOrientation(1); } void mitk::ColorBarAnnotation::SetMaxNumberOfColors(int numberOfColors) { SetIntProperty("ColorBarAnnotation.MaximumNumberOfColors", numberOfColors); } int mitk::ColorBarAnnotation::GetMaxNumberOfColors() const { int numberOfColors; GetPropertyList()->GetIntProperty("ColorBarAnnotation.MaximumNumberOfColors", numberOfColors); return numberOfColors; } void mitk::ColorBarAnnotation::SetNumberOfLabels(int numberOfLabels) { SetIntProperty("ColorBarAnnotation.NumberOfLabels", numberOfLabels); } int mitk::ColorBarAnnotation::GetNumberOfLabels() const { int numberOfLabels; GetPropertyList()->GetIntProperty("ColorBarAnnotation.NumberOfLabels", numberOfLabels); return numberOfLabels; } void mitk::ColorBarAnnotation::SetAnnotationTextScaling(bool scale) { SetBoolProperty("ColorBarAnnotation.ScaleAnnotationText", scale); } bool mitk::ColorBarAnnotation::GetAnnotationTextScaling() const { bool scale; GetPropertyList()->GetBoolProperty("ColorBarAnnotation.ScaleAnnotationText", scale); return scale; } diff --git a/Modules/Annotation/src/mitkLabelAnnotation3D.cpp b/Modules/Annotation/src/mitkLabelAnnotation3D.cpp index f4c9f78392..f3c0bb0ff7 100644 --- a/Modules/Annotation/src/mitkLabelAnnotation3D.cpp +++ b/Modules/Annotation/src/mitkLabelAnnotation3D.cpp @@ -1,163 +1,170 @@ /*=================================================================== 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 "mitkLabelAnnotation3D.h" #include #include #include #include #include #include #include #include #include #include #include mitk::LabelAnnotation3D::LabelAnnotation3D() : m_PointSetModifiedObserverTag(0) { } mitk::LabelAnnotation3D::~LabelAnnotation3D() { if (m_LabelCoordinates.IsNotNull()) m_LabelCoordinates->RemoveObserver(m_PointSetModifiedObserverTag); + for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer()) + { + if (renderer) + { + this->RemoveFromBaseRenderer(renderer); + } + } } mitk::LabelAnnotation3D::LocalStorage::~LocalStorage() { } mitk::LabelAnnotation3D::LocalStorage::LocalStorage() { m_Points = vtkSmartPointer::New(); // Add label array. m_Labels = vtkSmartPointer::New(); m_Labels->SetNumberOfValues(0); m_Labels->SetName("labels"); // Add priority array. m_Sizes = vtkSmartPointer::New(); m_Sizes->SetNumberOfValues(0); m_Sizes->SetName("sizes"); m_Points->GetPointData()->AddArray(m_Sizes); m_Points->GetPointData()->AddArray(m_Labels); m_PointSetToLabelHierarchyFilter = vtkSmartPointer::New(); m_PointSetToLabelHierarchyFilter->SetInputData(m_Points); m_PointSetToLabelHierarchyFilter->SetLabelArrayName("labels"); m_PointSetToLabelHierarchyFilter->SetPriorityArrayName("sizes"); m_PointSetToLabelHierarchyFilter->Update(); m_LabelMapper = vtkSmartPointer::New(); m_LabelMapper->SetInputConnection(m_PointSetToLabelHierarchyFilter->GetOutputPort()); m_LabelsActor = vtkSmartPointer::New(); m_LabelsActor->SetMapper(m_LabelMapper); } void mitk::LabelAnnotation3D::UpdateVtkAnnotation(mitk::BaseRenderer *renderer) { if (m_LabelCoordinates.IsNull()) { MITK_WARN << "No pointset defined to print labels!"; return; } LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); if (ls->IsGenerateDataRequired(renderer, this)) { vtkSmartPointer points = vtkSmartPointer::New(); size_t pointsetsize = (size_t)m_LabelCoordinates->GetSize(); ls->m_Labels->SetNumberOfValues(pointsetsize); ls->m_Sizes->SetNumberOfValues(pointsetsize); for (size_t i = 0; i < pointsetsize; i++) { mitk::Point3D coordinate = m_LabelCoordinates->GetPoint(i); points->InsertNextPoint(coordinate[0] + GetOffsetVector()[0], coordinate[1] + GetOffsetVector()[1], coordinate[2] + GetOffsetVector()[2]); if (m_LabelVector.size() > i) ls->m_Labels->SetValue(i, m_LabelVector[i]); else ls->m_Labels->SetValue(i, ""); if (m_PriorityVector.size() > i) ls->m_Sizes->SetValue(i, m_PriorityVector[i]); else ls->m_Sizes->SetValue(i, 1); } ls->m_Points->SetPoints(points); ls->m_PointSetToLabelHierarchyFilter->Update(); ls->m_LabelMapper->Update(); float color[3] = {1, 1, 1}; float opacity = 1.0; GetColor(color); GetOpacity(opacity); ls->m_LabelsActor->GetProperty()->SetColor(color[0], color[1], color[2]); ls->m_LabelsActor->GetProperty()->SetOpacity(opacity); ls->UpdateGenerateDataTime(); } } vtkProp *mitk::LabelAnnotation3D::GetVtkProp(BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_LabelsActor; } void mitk::LabelAnnotation3D::SetLabelVector(const std::vector &LabelVector) { m_LabelVector = LabelVector; this->Modified(); } void mitk::LabelAnnotation3D::SetPriorityVector(const std::vector &PriorityVector) { m_PriorityVector = PriorityVector; this->Modified(); } void mitk::LabelAnnotation3D::SetLabelCoordinates(mitk::PointSet::Pointer LabelCoordinates) { if (m_LabelCoordinates.IsNotNull()) { m_LabelCoordinates->RemoveObserver(m_PointSetModifiedObserverTag); m_PointSetModifiedObserverTag = 0; m_LabelCoordinates = NULL; } if (LabelCoordinates.IsNull()) { return; } m_LabelCoordinates = LabelCoordinates; itk::MemberCommand::Pointer _PropertyListModifiedCommand = itk::MemberCommand::New(); _PropertyListModifiedCommand->SetCallbackFunction(this, &mitk::LabelAnnotation3D::PointSetModified); m_PointSetModifiedObserverTag = m_LabelCoordinates->AddObserver(itk::ModifiedEvent(), _PropertyListModifiedCommand); this->Modified(); } void mitk::LabelAnnotation3D::PointSetModified(const itk::Object * /*caller*/, const itk::EventObject &) { this->Modified(); } diff --git a/Modules/Annotation/src/mitkLogoAnnotation.cpp b/Modules/Annotation/src/mitkLogoAnnotation.cpp index 9e77623b62..d27d5b96ba 100644 --- a/Modules/Annotation/src/mitkLogoAnnotation.cpp +++ b/Modules/Annotation/src/mitkLogoAnnotation.cpp @@ -1,197 +1,204 @@ /*=================================================================== 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 "mitkLogoAnnotation.h" #include "vtkUnicodeString.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include mitk::LogoAnnotation::LogoAnnotation() { m_readerFactory = vtkSmartPointer::New(); mitk::Point2D offset; offset.Fill(0.03); SetOffsetVector(offset); SetRelativeSize(0.2); SetLogoImagePath("mbiLogo"); SetCornerPosition(3); m_VtkImageImport = vtkSmartPointer::New(); } mitk::LogoAnnotation::~LogoAnnotation() { + for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer()) + { + if (renderer) + { + this->RemoveFromBaseRenderer(renderer); + } + } } mitk::LogoAnnotation::LocalStorage::~LocalStorage() { } mitk::LogoAnnotation::LocalStorage::LocalStorage() { m_LogoRep = vtkSmartPointer::New(); } void mitk::LogoAnnotation::UpdateVtkAnnotation(mitk::BaseRenderer *renderer) { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); if (ls->IsGenerateDataRequired(renderer, this)) { if (GetLogoImagePath().empty()) { ls->m_LogoRep->SetVisibility(0); return; } vtkImageReader2 *imageReader = m_readerFactory->CreateImageReader2(GetLogoImagePath().c_str()); if (imageReader) { imageReader->SetFileName(GetLogoImagePath().c_str()); imageReader->Update(); ls->m_LogoImage = imageReader->GetOutput(); imageReader->Delete(); } else { ls->m_LogoImage = CreateMbiLogo(); } ls->m_LogoRep->SetImage(ls->m_LogoImage); ls->m_LogoRep->SetDragable(false); ls->m_LogoRep->SetMoving(false); ls->m_LogoRep->SetPickable(false); ls->m_LogoRep->SetShowBorder(true); ls->m_LogoRep->SetRenderer(renderer->GetVtkRenderer()); float size = GetRelativeSize(); ls->m_LogoRep->SetPosition2(size, size); int corner = GetCornerPosition(); ls->m_LogoRep->SetCornerPosition(corner); mitk::Point2D offset = GetOffsetVector(); ls->m_LogoRep->SetPosition(offset[0], offset[1]); float opacity = 1.0; GetOpacity(opacity); ls->m_LogoRep->GetImageProperty()->SetOpacity(opacity); ls->m_LogoRep->BuildRepresentation(); ls->UpdateGenerateDataTime(); } } vtkImageData *mitk::LogoAnnotation::CreateMbiLogo() { m_VtkImageImport->SetDataScalarTypeToUnsignedChar(); m_VtkImageImport->SetNumberOfScalarComponents(mbiLogo_NumberOfScalars); m_VtkImageImport->SetWholeExtent(0, mbiLogo_Width - 1, 0, mbiLogo_Height - 1, 0, 1 - 1); m_VtkImageImport->SetDataExtentToWholeExtent(); char *ImageData; // flip mbi logo around y axis and change color order ImageData = new char[mbiLogo_Height * mbiLogo_Width * mbiLogo_NumberOfScalars]; unsigned int column, row; char *dest = ImageData; char *source = (char *)&mbiLogo_Data[0]; ; char r, g, b, a; for (column = 0; column < mbiLogo_Height; column++) for (row = 0; row < mbiLogo_Width; row++) { // change r with b b = *source++; g = *source++; r = *source++; a = *source++; *dest++ = r; *dest++ = g; *dest++ = b; *dest++ = a; } m_VtkImageImport->SetImportVoidPointer(ImageData); m_VtkImageImport->Modified(); m_VtkImageImport->Update(); return m_VtkImageImport->GetOutput(); } void mitk::LogoAnnotation::SetLogoImagePath(std::string path) { SetStringProperty("Annotation.LogoImagePath", path.c_str()); Modified(); } std::string mitk::LogoAnnotation::GetLogoImagePath() const { std::string path; GetPropertyList()->GetStringProperty("Annotation.LogoImagePath", path); return path; } void mitk::LogoAnnotation::SetOffsetVector(const Point2D &OffsetVector) { mitk::Point2dProperty::Pointer OffsetVectorProperty = mitk::Point2dProperty::New(OffsetVector); SetProperty("Annotation.OffsetVector", OffsetVectorProperty.GetPointer()); Modified(); } mitk::Point2D mitk::LogoAnnotation::GetOffsetVector() const { mitk::Point2D OffsetVector; OffsetVector.Fill(0); GetPropertyValue("Annotation.OffsetVector", OffsetVector); return OffsetVector; } void mitk::LogoAnnotation::SetCornerPosition(const int &corner) { SetIntProperty("Annotation.CornerPosition", corner); Modified(); } int mitk::LogoAnnotation::GetCornerPosition() const { int corner = 0; GetIntProperty("Annotation.CornerPosition", corner); return corner; } void mitk::LogoAnnotation::SetRelativeSize(const float &size) { SetFloatProperty("Annotation.RelativeSize", size); Modified(); } float mitk::LogoAnnotation::GetRelativeSize() const { float size = 0; GetFloatProperty("Annotation.RelativeSize", size); return size; } vtkProp *mitk::LogoAnnotation::GetVtkProp(BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_LogoRep; } diff --git a/Modules/Annotation/src/mitkScaleLegendAnnotation.cpp b/Modules/Annotation/src/mitkScaleLegendAnnotation.cpp index 57e9358cb8..9e4926da1d 100644 --- a/Modules/Annotation/src/mitkScaleLegendAnnotation.cpp +++ b/Modules/Annotation/src/mitkScaleLegendAnnotation.cpp @@ -1,209 +1,216 @@ /*=================================================================== 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 "mitkScaleLegendAnnotation.h" #include #include #include mitk::ScaleLegendAnnotation::ScaleLegendAnnotation() { SetRightAxisVisibility(true); SetLeftAxisVisibility(true); SetTopAxisVisibility(true); SetBottomAxisVisibility(true); SetLegendVisibility(true); SetRightBorderOffset(50); SetLeftBorderOffset(50); SetTopBorderOffset(30); SetBottomBorderOffset(30); SetCornerOffsetFactor(2.0); SetFontFactor(1.0); } mitk::ScaleLegendAnnotation::~ScaleLegendAnnotation() { + for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer()) + { + if (renderer) + { + this->RemoveFromBaseRenderer(renderer); + } + } } mitk::ScaleLegendAnnotation::LocalStorage::~LocalStorage() { } mitk::ScaleLegendAnnotation::LocalStorage::LocalStorage() { m_legendScaleActor = vtkSmartPointer::New(); } void mitk::ScaleLegendAnnotation::UpdateVtkAnnotation(mitk::BaseRenderer *renderer) { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); if (ls->IsGenerateDataRequired(renderer, this)) { ls->m_legendScaleActor->SetRightAxisVisibility(this->GetRightAxisVisibility()); ls->m_legendScaleActor->SetTopAxisVisibility(this->GetTopAxisVisibility()); ls->m_legendScaleActor->SetLeftAxisVisibility(this->GetLeftAxisVisibility()); ls->m_legendScaleActor->SetBottomAxisVisibility(this->GetBottomAxisVisibility()); ls->m_legendScaleActor->SetLegendVisibility(this->GetLegendVisibility()); ls->m_legendScaleActor->SetRightBorderOffset(this->GetRightBorderOffset()); ls->m_legendScaleActor->SetLeftBorderOffset(this->GetLeftBorderOffset()); ls->m_legendScaleActor->SetTopBorderOffset(this->GetTopBorderOffset()); ls->m_legendScaleActor->SetBottomBorderOffset(this->GetBottomBorderOffset()); ls->m_legendScaleActor->SetCornerOffsetFactor(this->GetCornerOffsetFactor()); ls->m_legendScaleActor->GetLeftAxis()->SetFontFactor(this->GetFontFactor()); ls->m_legendScaleActor->GetRightAxis()->SetFontFactor(this->GetFontFactor()); ls->m_legendScaleActor->GetTopAxis()->SetFontFactor(this->GetFontFactor()); ls->m_legendScaleActor->GetBottomAxis()->SetFontFactor(this->GetFontFactor()); } } vtkProp *mitk::ScaleLegendAnnotation::GetVtkProp(BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_legendScaleActor; } void mitk::ScaleLegendAnnotation::SetRightAxisVisibility(bool visibility) { SetBoolProperty("ScaleLegendAnnotation.RightAxisVisibility", visibility); } bool mitk::ScaleLegendAnnotation::GetRightAxisVisibility() const { bool visibility; GetPropertyList()->GetBoolProperty("ScaleLegendAnnotation.RightAxisVisibility", visibility); return visibility; } void mitk::ScaleLegendAnnotation::SetLeftAxisVisibility(bool visibility) { SetBoolProperty("ScaleLegendAnnotation.LeftAxisVisibility", visibility); } bool mitk::ScaleLegendAnnotation::GetLeftAxisVisibility() const { bool visibility; GetPropertyList()->GetBoolProperty("ScaleLegendAnnotation.LeftAxisVisibility", visibility); return visibility; } void mitk::ScaleLegendAnnotation::SetTopAxisVisibility(bool visibility) { SetBoolProperty("ScaleLegendAnnotation.TopAxisVisibility", visibility); } bool mitk::ScaleLegendAnnotation::GetTopAxisVisibility() const { bool visibility; GetPropertyList()->GetBoolProperty("ScaleLegendAnnotation.TopAxisVisibility", visibility); return visibility; } void mitk::ScaleLegendAnnotation::SetBottomAxisVisibility(bool visibility) { SetBoolProperty("ScaleLegendAnnotation.BottomAxisVisibility", visibility); } bool mitk::ScaleLegendAnnotation::GetBottomAxisVisibility() const { bool visibility; GetPropertyList()->GetBoolProperty("ScaleLegendAnnotation.BottomAxisVisibility", visibility); return visibility; } void mitk::ScaleLegendAnnotation::SetLegendVisibility(bool visibility) { SetBoolProperty("ScaleLegendAnnotation.SetLegendVisibility", visibility); } bool mitk::ScaleLegendAnnotation::GetLegendVisibility() const { bool visibility; GetPropertyList()->GetBoolProperty("ScaleLegendAnnotation.SetLegendVisibility", visibility); return visibility; } void mitk::ScaleLegendAnnotation::SetRightBorderOffset(int offset) { SetIntProperty("ScaleLegendAnnotation.RightBorderOffset", offset); } int mitk::ScaleLegendAnnotation::GetRightBorderOffset() const { int offset; GetPropertyList()->GetIntProperty("ScaleLegendAnnotation.RightBorderOffset", offset); return offset; } void mitk::ScaleLegendAnnotation::SetLeftBorderOffset(int offset) { SetIntProperty("ScaleLegendAnnotation.LeftBorderOffset", offset); } int mitk::ScaleLegendAnnotation::GetLeftBorderOffset() const { int offset; GetPropertyList()->GetIntProperty("ScaleLegendAnnotation.LeftBorderOffset", offset); return offset; } void mitk::ScaleLegendAnnotation::SetTopBorderOffset(int offset) { SetIntProperty("ScaleLegendAnnotation.TopBorderOffset", offset); } int mitk::ScaleLegendAnnotation::GetTopBorderOffset() const { int offset; GetPropertyList()->GetIntProperty("ScaleLegendAnnotation.TopBorderOffset", offset); return offset; } void mitk::ScaleLegendAnnotation::SetBottomBorderOffset(int offset) { SetIntProperty("ScaleLegendAnnotation.BottomBorderOffset", offset); } int mitk::ScaleLegendAnnotation::GetBottomBorderOffset() const { int offset; GetPropertyList()->GetIntProperty("ScaleLegendAnnotation.BottomBorderOffset", offset); return offset; } void mitk::ScaleLegendAnnotation::SetCornerOffsetFactor(double offsetFactor) { SetDoubleProperty("ScaleLegendAnnotation.CornerOffsetFactor", offsetFactor); } double mitk::ScaleLegendAnnotation::GetCornerOffsetFactor() const { double offsetFactor; GetPropertyList()->GetDoubleProperty("ScaleLegendAnnotation.CornerOffsetFactor", offsetFactor); return offsetFactor; } void mitk::ScaleLegendAnnotation::SetFontFactor(double fontFactor) { SetDoubleProperty("ScaleLegendAnnotation.FontFactor", fontFactor); } double mitk::ScaleLegendAnnotation::GetFontFactor() const { double offsetFactor; GetPropertyList()->GetDoubleProperty("ScaleLegendAnnotation.FontFactor", offsetFactor); return offsetFactor; } diff --git a/Modules/Annotation/src/mitkTextAnnotation2D.cpp b/Modules/Annotation/src/mitkTextAnnotation2D.cpp index ed7c547aa9..c7d9107b58 100644 --- a/Modules/Annotation/src/mitkTextAnnotation2D.cpp +++ b/Modules/Annotation/src/mitkTextAnnotation2D.cpp @@ -1,152 +1,159 @@ /*=================================================================== 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 "mitkTextAnnotation2D.h" #include "vtkUnicodeString.h" #include #include #include mitk::TextAnnotation2D::TextAnnotation2D() { mitk::Point2D position; position[0] = position[1] = 0; this->SetPosition2D(position); this->SetOffsetVector(position); this->SetText(""); this->SetFontSize(20); this->SetColor(1.0, 1.0, 1.0); this->SetStringProperty("font.family", "Arial"); this->SetBoolProperty("font.bold", false); this->SetBoolProperty("font.italic", false); this->SetBoolProperty("drawShadow", false); } mitk::TextAnnotation2D::~TextAnnotation2D() { + for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer()) + { + if (renderer) + { + this->RemoveFromBaseRenderer(renderer); + } + } } mitk::Annotation::Bounds mitk::TextAnnotation2D::GetBoundsOnDisplay(mitk::BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); mitk::Annotation::Bounds bounds; bounds.Position = ls->m_TextActor->GetPosition(); double size[2]; ls->m_TextActor->GetSize(renderer->GetVtkRenderer(), size); bounds.Size[0] = size[0]; bounds.Size[1] = size[1]; return bounds; } void mitk::TextAnnotation2D::SetBoundsOnDisplay(mitk::BaseRenderer *renderer, const mitk::Annotation::Bounds &bounds) { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); mitk::Point2D posT, posS; posT[0] = bounds.Position[0]; posT[1] = bounds.Position[1]; posS[0] = posT[0] + 1; posS[1] = posT[1] - 1; ls->m_TextActor->SetDisplayPosition(posT[0], posT[1]); ls->m_STextActor->SetDisplayPosition(posS[0], posS[1]); } mitk::TextAnnotation2D::LocalStorage::~LocalStorage() { } mitk::TextAnnotation2D::LocalStorage::LocalStorage() { m_TextActor = vtkSmartPointer::New(); m_TextProp = vtkSmartPointer::New(); m_STextActor = vtkSmartPointer::New(); m_STextProp = vtkSmartPointer::New(); m_TextActor->SetTextProperty(m_TextProp); m_STextActor->SetTextProperty(m_STextProp); m_Assembly = vtkSmartPointer::New(); m_Assembly->AddPart(m_STextActor); m_Assembly->AddPart(m_TextActor); } void mitk::TextAnnotation2D::UpdateVtkAnnotation2D(mitk::BaseRenderer *renderer) { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); if (ls->IsGenerateDataRequired(renderer, this)) { float color[3] = {0.0, 1.0, 0.0}; float opacity = 1.0; GetColor(color); GetOpacity(opacity); ls->m_TextProp->SetColor(color[0], color[1], color[2]); ls->m_STextProp->SetColor(0, 0, 0); ls->m_TextProp->SetFontSize(GetFontSize()); ls->m_TextProp->SetOpacity(opacity); ls->m_STextProp->SetFontSize(GetFontSize()); ls->m_STextProp->SetOpacity(opacity); std::string fontFamilyAsString; if (GetStringProperty("font.family", fontFamilyAsString) == false) { fontFamilyAsString = "Arial"; } ls->m_TextProp->SetFontFamilyAsString(fontFamilyAsString.c_str()); ls->m_STextProp->SetFontFamilyAsString(fontFamilyAsString.c_str()); bool boldFont(false); GetBoolProperty("font.bold", boldFont); ls->m_TextProp->SetBold(boldFont); ls->m_STextProp->SetBold(boldFont); bool italicFont(false); GetBoolProperty("font.italic", italicFont); ls->m_TextProp->SetBold(italicFont); ls->m_STextProp->SetBold(italicFont); bool drawShadow; GetBoolProperty("drawShadow", drawShadow); ls->m_TextProp->SetShadow(false); ls->m_STextProp->SetShadow(false); ls->m_STextActor->SetVisibility(drawShadow); ls->m_TextActor->SetInput(GetText().c_str()); ls->m_STextActor->SetInput(GetText().c_str()); mitk::Point2D posT, posS; posT[0] = GetPosition2D()[0] + GetOffsetVector()[0]; posT[1] = GetPosition2D()[1] + GetOffsetVector()[1]; posS[0] = posT[0] + 1; posS[1] = posT[1] - 1; ls->m_TextActor->SetDisplayPosition(posT[0], posT[1]); ls->m_STextActor->SetDisplayPosition(posS[0], posS[1]); ls->UpdateGenerateDataTime(); } } vtkProp *mitk::TextAnnotation2D::GetVtkProp(mitk::BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_Assembly; } vtkActor2D *mitk::TextAnnotation2D::GetVtkActor2D(BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_TextActor; } diff --git a/Modules/Annotation/src/mitkTextAnnotation3D.cpp b/Modules/Annotation/src/mitkTextAnnotation3D.cpp index 3847141c02..1f4e571766 100644 --- a/Modules/Annotation/src/mitkTextAnnotation3D.cpp +++ b/Modules/Annotation/src/mitkTextAnnotation3D.cpp @@ -1,105 +1,112 @@ /*=================================================================== 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 "mitkTextAnnotation3D.h" #include #include #include #include #include #include #include #include mitk::TextAnnotation3D::TextAnnotation3D() { mitk::Point3D position; position.Fill(0); this->SetPosition3D(position); this->SetOffsetVector(position); this->SetText(""); this->SetFontSize(20); this->SetColor(1.0, 1.0, 1.0); } mitk::TextAnnotation3D::~TextAnnotation3D() { + for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer()) + { + if (renderer) + { + this->RemoveFromBaseRenderer(renderer); + } + } } mitk::TextAnnotation3D::LocalStorage::~LocalStorage() { } mitk::TextAnnotation3D::LocalStorage::LocalStorage() { // Create some text m_textSource = vtkSmartPointer::New(); // Create a mapper vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetInputConnection(m_textSource->GetOutputPort()); // Create a subclass of vtkActor: a vtkFollower that remains facing the camera m_follower = vtkSmartPointer::New(); m_follower->SetMapper(mapper); m_follower->GetProperty()->SetColor(1, 0, 0); // red m_follower->SetScale(1); } void mitk::TextAnnotation3D::UpdateVtkAnnotation(mitk::BaseRenderer *renderer) { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); if (ls->IsGenerateDataRequired(renderer, this)) { Point3D pos3d = GetPosition3D(); vtkRenderer *vtkRender = renderer->GetVtkRenderer(); if (vtkRender) { vtkCamera *camera = vtkRender->GetActiveCamera(); ls->m_follower->SetCamera(camera); if (camera != nullptr) { // calculate the offset relative to the camera's view direction Point3D offset = GetOffsetVector(); Vector3D viewUp; camera->GetViewUp(viewUp.GetDataPointer()); Vector3D cameraDirection; camera->GetDirectionOfProjection(cameraDirection.GetDataPointer()); Vector3D viewRight; vtkMath::Cross(cameraDirection.GetDataPointer(), viewUp.GetDataPointer(), viewRight.GetDataPointer()); pos3d = pos3d + viewRight * offset[0] + viewUp * offset[1] + cameraDirection * offset[2]; } } ls->m_follower->SetPosition(pos3d.GetDataPointer()); ls->m_textSource->SetText(GetText().c_str()); float color[3] = {1, 1, 1}; float opacity = 1.0; GetColor(color); GetOpacity(opacity); ls->m_follower->GetProperty()->SetColor(color[0], color[1], color[2]); ls->m_follower->GetProperty()->SetOpacity(opacity); ls->m_follower->SetScale(this->GetFontSize()); ls->UpdateGenerateDataTime(); } } vtkProp *mitk::TextAnnotation3D::GetVtkProp(BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_follower; } diff --git a/Modules/Core/include/mitkLocalStorageHandler.h b/Modules/Core/include/mitkLocalStorageHandler.h index bb8d900477..a47e30d2e8 100644 --- a/Modules/Core/include/mitkLocalStorageHandler.h +++ b/Modules/Core/include/mitkLocalStorageHandler.h @@ -1,108 +1,119 @@ /*=================================================================== 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 LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08 #define LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08 #include "mitkBaseRenderer.h" #include "mitkCommon.h" #include "mitkLevelWindow.h" #include "mitkVtkPropRenderer.h" #include #include #include // Just included to get VTK version #include class vtkWindow; class vtkProp; namespace mitk { /** \brief Interface for accessing (templated) LocalStorageHandler instances. */ class BaseLocalStorageHandler { public: virtual ~BaseLocalStorageHandler() {} virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer = true) = 0; }; /** \brief Templated class for management of LocalStorage implementations in Mappers. * * The LocalStorageHandler is responsible for providing a LocalStorage to a * concrete mitk::Mapper subclass. Each RenderWindow / mitk::BaseRenderer is * assigned its own LocalStorage instance so that all contained ressources * (actors, shaders, textures, ...) are provided individually per window. * */ template class LocalStorageHandler : public mitk::BaseLocalStorageHandler { protected: std::map m_BaseRenderer2LS; public: /** \brief deallocates a local storage for a specifc BaseRenderer (if the * BaseRenderer is itself deallocating it in its destructor, it has to set * unregisterFromBaseRenderer=false) */ virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer = true) override { // MITK_INFO << "deleting a localstorage on a mapper request"; if (unregisterFromBaseRenderer) renderer->UnregisterLocalStorageHandler(this); L *l = m_BaseRenderer2LS[renderer]; m_BaseRenderer2LS.erase(renderer); delete l; } + std::vector GetRegisteredBaseRenderer() + { + std::vector baserenderers; + typename std::map::iterator it; + for (it = m_BaseRenderer2LS.begin(); it != m_BaseRenderer2LS.end(); ++it) + { + baserenderers.push_back(it->first); + } + return baserenderers; + } + /** \brief Retrieves a LocalStorage for a specific BaseRenderer. * * Should be used by mappers in GenerateDataForRenderer() */ L *GetLocalStorage(mitk::BaseRenderer *forRenderer) { L *l = m_BaseRenderer2LS[forRenderer]; if (!l) { // MITK_INFO << "creating new localstorage"; l = new L; m_BaseRenderer2LS[forRenderer] = l; forRenderer->RegisterLocalStorageHandler(this); } return l; } ~LocalStorageHandler() { typename std::map::iterator it; for (it = m_BaseRenderer2LS.begin(); it != m_BaseRenderer2LS.end(); it++) { (*it).first->UnregisterLocalStorageHandler(this); delete (*it).second; } m_BaseRenderer2LS.clear(); } }; } // namespace mitk #endif /* LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08 */