29 #include <vtkAppendPolyData.h>
30 #include <vtkCamera.h>
31 #include <vtkCellArray.h>
32 #include <vtkCharArray.h>
33 #include <vtkConeSource.h>
35 #include <vtkPointData.h>
36 #include <vtkSphereSource.h>
37 #include <vtkVectorOperators.h>
39 mitk::GizmoMapper2D::LocalStorage::LocalStorage()
43 m_Actor->SetMapper(m_VtkPolyDataMapper);
53 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
54 ls->m_Actor->VisibilityOff();
60 void AssignScalarValueTo(vtkPolyData *polydata,
char value)
64 int numberOfPoints = polydata->GetNumberOfPoints();
65 pointData->SetNumberOfComponents(1);
66 pointData->SetNumberOfTuples(numberOfPoints);
67 pointData->FillComponent(0, value);
68 polydata->GetPointData()->SetScalars(pointData);
74 vtkSmartPointer<vtkPolyData> Create2DDisk(
mitk::Vector3D viewRight,
84 unsigned int numberOfRingPoints = 36;
87 ringPoly->InsertNextCell(numberOfRingPoints + 1);
88 for (
unsigned int segment = 0; segment < numberOfRingPoints; ++segment)
90 double x = std::cos((
double)(segment) / (
double)numberOfRingPoints * 2.0 * vtkMath::Pi());
91 double y = std::sin((
double)(segment) / (
double)numberOfRingPoints * 2.0 * vtkMath::Pi());
93 ringPointer = viewRight * x + viewUp * y;
95 ringPoints->InsertPoint(segment, (center + ringPointer * radius).GetDataPointer());
96 ringPoly->InsertCellPoint(segment);
98 ringPoly->InsertCellPoint(0);
100 disk->SetPoints(ringPoints);
101 disk->SetPolys(ringPoly);
111 vtkSmartPointer<vtkPolyData> Create2DArrow(
mitk::Vector3D cameraDirection,
115 int vertexValueScale)
118 mitk::Vector3D arrowOrthogonal = itk::CrossProduct(cameraDirection, arrowDirection);
119 arrowOrthogonal.Normalize();
121 double triangleFraction = 0.2;
126 points->InsertPoint(0, arrowStart.GetDataPointer());
127 points->InsertPoint(1, (arrowStart + arrowDirection * (1.0 - triangleFraction)).GetDataPointer());
130 points->InsertPoint(2, arrowTip.GetDataPointer());
131 points->InsertPoint(3,
132 (arrowStart + (1.0 - triangleFraction) * arrowDirection +
133 arrowOrthogonal * (0.5 * triangleFraction * arrowDirection.GetNorm()))
135 points->InsertPoint(4,
136 (arrowStart + (1.0 - triangleFraction) * arrowDirection -
137 arrowOrthogonal * (0.5 * triangleFraction * arrowDirection.GetNorm()))
139 arrow->SetPoints(points);
143 vtkIdType shaftLinePoints[] = {0, 1};
144 lines->InsertNextCell(2, shaftLinePoints);
145 arrow->SetLines(lines);
149 vtkIdType tipLinePoints[] = {2, 3, 4};
150 polys->InsertNextCell(3, tipLinePoints);
151 arrow->SetPolys(polys);
155 pointData->SetNumberOfComponents(1);
156 pointData->SetNumberOfTuples(5);
157 pointData->FillComponent(0, vertexValueScale);
158 pointData->SetTuple1(0, vertexValueMove);
159 pointData->SetTuple1(1, vertexValueMove);
160 arrow->GetPointData()->SetScalars(pointData);
168 return m_LSH.GetLocalStorage(renderer)->m_VtkPolyDataMapper->GetInput();
173 auto gizmo = GetInput();
174 auto node = GetDataNode();
176 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
179 if ((ls->m_LastUpdateTime >= node->GetMTime()) && (ls->m_LastUpdateTime >= gizmo->GetPipelineMTime()) &&
182 (ls->m_LastUpdateTime >= node->GetPropertyList()->GetMTime()) &&
183 (ls->m_LastUpdateTime >= node->GetPropertyList(renderer)->GetMTime()))
188 ls->m_LastUpdateTime.Modified();
192 bool visible2D =
true;
193 this->GetDataNode()->GetBoolProperty(
"show in 2D", visible2D);
196 ls->m_Actor->VisibilityOff();
201 ls->m_Actor->VisibilityOn();
208 Point3D gizmoCenterView = plane->ProjectPointOntoPlane(gizmo->GetCenter());
211 camera->GetViewUp(viewUp.GetDataPointer());
213 camera->GetDirectionOfProjection(cameraDirection.GetDataPointer());
214 Vector3D viewRight = itk::CrossProduct(viewUp, cameraDirection);
219 double arrowLength = 0.1 * diagonal;
220 auto disk = Create2DDisk(viewRight, viewUp, gizmoCenterView - cameraDirection, 0.1 * arrowLength);
222 appender->AddInputData(disk);
225 for (
double direction = -1.0; direction < 2.0; direction += 2.0)
228 Create2DArrow(cameraDirection,
230 plane->ProjectPointOntoPlane(gizmo->GetCenter() + (gizmo->GetAxisX() * arrowLength) * direction),
233 appender->AddInputData(axisX);
236 Create2DArrow(cameraDirection,
238 plane->ProjectPointOntoPlane(gizmo->GetCenter() + (gizmo->GetAxisY() * arrowLength) * direction),
241 appender->AddInputData(axisY);
244 Create2DArrow(cameraDirection,
246 plane->ProjectPointOntoPlane(gizmo->GetCenter() + (gizmo->GetAxisZ() * arrowLength) * direction),
249 appender->AddInputData(axisZ);
252 ls->m_VtkPolyDataMapper->SetInputConnection(appender->GetOutputPort());
254 ApplyVisualProperties(renderer);
257 void mitk::GizmoMapper2D::ApplyVisualProperties(BaseRenderer *renderer)
259 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
261 float lineWidth = 3.0f;
262 ls->m_Actor->GetProperty()->SetLineWidth(lineWidth);
265 this->GetDataNode()->GetProperty(lookupTableProp,
"LookupTable", renderer);
266 if (lookupTableProp.IsNotNull())
268 ls->m_VtkPolyDataMapper->SetLookupTable(lookupTableProp->GetLookupTable()->GetVtkLookupTable());
271 bool scalarVisibility =
false;
272 this->GetDataNode()->GetBoolProperty(
"scalar visibility", scalarVisibility);
273 ls->m_VtkPolyDataMapper->SetScalarVisibility((scalarVisibility ? 1 : 0));
275 if (scalarVisibility)
278 if (this->GetDataNode()->GetProperty(scalarMode,
"scalar mode", renderer))
283 bool colorMode =
false;
284 this->GetDataNode()->GetBoolProperty(
"color mode", colorMode);
285 ls->m_VtkPolyDataMapper->SetColorMode((colorMode ? 1 : 0));
287 double scalarsMin = 0;
288 this->GetDataNode()->GetDoubleProperty(
"ScalarsRangeMinimum", scalarsMin, renderer);
290 double scalarsMax = 1.0;
291 this->GetDataNode()->GetDoubleProperty(
"ScalarsRangeMaximum", scalarsMax, renderer);
293 ls->m_VtkPolyDataMapper->SetScalarRange(scalarsMin, scalarsMax);
308 double colorMoveFreely[] = {1, 0, 0, 1};
309 double colorAxisX[] = {0.753, 0, 0, 1};
310 double colorAxisY[] = {0, 0.69, 0, 1};
311 double colorAxisZ[] = {0, 0.502, 1, 1};
312 double colorInactive[] = {0.7, 0.7, 0.7, 1};
316 lut->SetNumberOfTableValues((
int)Gizmo::NoHandle + 1);
317 lut->SetTableRange(0, (
int)Gizmo::NoHandle);
328 lut->SetTableValue(Gizmo::NoHandle, colorInactive);
331 mlut->SetVtkLookupTable(lut);
334 lutProp->SetLookupTable(mlut);
335 node->
SetProperty(
"LookupTable", lutProp, renderer);
int GetSizeX() const
get the x_size of the RendererWindow
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Organizes the rendering process.
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual void SetScalarModeToDefault()
Vector< ScalarType, 3 > Vector3D
virtual int GetVtkScalarMode()
int GetSizeY() const
get the y_size of the RendererWindow
virtual MapperSlotId GetMapperID()
Get the MapperSlotId to use.
Point< ScalarType, 3 > Point3D
void ResetMapper(mitk::BaseRenderer *renderer) override
"Resets" the mapper, setting its result to invisible.
vtkPolyData * GetVtkPolyData(mitk::BaseRenderer *renderer)
unsigned long GetCurrentWorldPlaneGeometryUpdateTime()
Get timestamp of last call of SetCurrentWorldPlaneGeometry.
void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
vtkRenderer * GetVtkRenderer() const
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.