26 #include <vtkAppendPolyData.h> 27 #include <vtkCamera.h> 28 #include <vtkCellArray.h> 29 #include <vtkCharArray.h> 30 #include <vtkConeSource.h> 32 #include <vtkPointData.h> 33 #include <vtkSphereSource.h> 34 #include <vtkVectorOperators.h> 36 mitk::GizmoMapper2D::LocalStorage::LocalStorage()
38 m_VtkPolyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
39 m_Actor = vtkSmartPointer<vtkActor>::New();
40 m_Actor->SetMapper(m_VtkPolyDataMapper);
51 ls->m_Actor->VisibilityOff();
57 void AssignScalarValueTo(vtkPolyData *polydata,
char value)
59 vtkSmartPointer<vtkCharArray> pointData = vtkSmartPointer<vtkCharArray>::New();
61 int numberOfPoints = polydata->GetNumberOfPoints();
62 pointData->SetNumberOfComponents(1);
63 pointData->SetNumberOfTuples(numberOfPoints);
64 pointData->FillComponent(0, value);
65 polydata->GetPointData()->SetScalars(pointData);
71 vtkSmartPointer<vtkPolyData> Create2DDisk(
mitk::Vector3D viewRight,
78 vtkSmartPointer<vtkPolyData> disk = vtkSmartPointer<vtkPolyData>::New();
81 unsigned int numberOfRingPoints = 36;
82 vtkSmartPointer<vtkPoints> ringPoints = vtkSmartPointer<vtkPoints>::New();
83 vtkSmartPointer<vtkCellArray> ringPoly = vtkSmartPointer<vtkCellArray>::New();
84 ringPoly->InsertNextCell(numberOfRingPoints + 1);
85 for (
unsigned int segment = 0; segment < numberOfRingPoints; ++segment)
87 double x = std::cos((
double)(segment) / (
double)numberOfRingPoints * 2.0 * vtkMath::Pi());
88 double y = std::sin((
double)(segment) / (
double)numberOfRingPoints * 2.0 * vtkMath::Pi());
90 ringPointer = viewRight * x + viewUp * y;
92 ringPoints->InsertPoint(segment, (center + ringPointer * radius).GetDataPointer());
93 ringPoly->InsertCellPoint(segment);
95 ringPoly->InsertCellPoint(0);
97 disk->SetPoints(ringPoints);
98 disk->SetPolys(ringPoly);
108 vtkSmartPointer<vtkPolyData> Create2DArrow(
mitk::Vector3D cameraDirection,
112 int vertexValueScale)
115 mitk::Vector3D arrowOrthogonal = itk::CrossProduct(cameraDirection, arrowDirection);
116 arrowOrthogonal.Normalize();
118 double triangleFraction = 0.2;
120 vtkSmartPointer<vtkPolyData> arrow = vtkSmartPointer<vtkPolyData>::New();
121 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
123 points->InsertPoint(0, arrowStart.GetDataPointer());
124 points->InsertPoint(1, (arrowStart + arrowDirection * (1.0 - triangleFraction)).GetDataPointer());
127 points->InsertPoint(2, arrowTip.GetDataPointer());
128 points->InsertPoint(3,
129 (arrowStart + (1.0 - triangleFraction) * arrowDirection +
130 arrowOrthogonal * (0.5 * triangleFraction * arrowDirection.GetNorm()))
132 points->InsertPoint(4,
133 (arrowStart + (1.0 - triangleFraction) * arrowDirection -
134 arrowOrthogonal * (0.5 * triangleFraction * arrowDirection.GetNorm()))
136 arrow->SetPoints(points);
139 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
140 vtkIdType shaftLinePoints[] = {0, 1};
141 lines->InsertNextCell(2, shaftLinePoints);
142 arrow->SetLines(lines);
145 vtkSmartPointer<vtkCellArray> polys = vtkSmartPointer<vtkCellArray>::New();
146 vtkIdType tipLinePoints[] = {2, 3, 4};
147 polys->InsertNextCell(3, tipLinePoints);
148 arrow->SetPolys(polys);
151 vtkSmartPointer<vtkCharArray> pointData = vtkSmartPointer<vtkCharArray>::New();
152 pointData->SetNumberOfComponents(1);
153 pointData->SetNumberOfTuples(5);
154 pointData->FillComponent(0, vertexValueScale);
155 pointData->SetTuple1(0, vertexValueMove);
156 pointData->SetTuple1(1, vertexValueMove);
157 arrow->GetPointData()->SetScalars(pointData);
165 return m_LSH.
GetLocalStorage(renderer)->m_VtkPolyDataMapper->GetInput();
170 auto gizmo = GetInput();
176 if ((ls->m_LastUpdateTime >= node->GetMTime()) && (ls->m_LastUpdateTime >= gizmo->GetPipelineMTime()) &&
180 (ls->m_LastUpdateTime >= node->GetPropertyList()->GetMTime()) &&
181 (ls->m_LastUpdateTime >= node->GetPropertyList(renderer)->GetMTime()))
186 ls->m_LastUpdateTime.Modified();
190 bool visible2D =
true;
194 ls->m_Actor->VisibilityOff();
199 ls->m_Actor->VisibilityOn();
206 Point3D gizmoCenterView = plane->ProjectPointOntoPlane(gizmo->GetCenter());
209 camera->GetViewUp(viewUp.GetDataPointer());
211 camera->GetDirectionOfProjection(cameraDirection.GetDataPointer());
212 Vector3D viewRight = itk::CrossProduct(viewUp, cameraDirection);
214 auto appender = vtkSmartPointer<vtkAppendPolyData>::New();
217 double arrowLength = 0.3 * diagonal;
218 auto disk = Create2DDisk(viewRight, viewUp, gizmoCenterView - cameraDirection, 0.1 * arrowLength);
220 appender->AddInputData(disk);
223 for (
double direction = -1.0; direction < 2.0; direction += 2.0)
226 Create2DArrow(cameraDirection,
228 plane->ProjectPointOntoPlane(gizmo->GetCenter() + (gizmo->GetAxisX() * arrowLength) * direction),
231 appender->AddInputData(axisX);
234 Create2DArrow(cameraDirection,
236 plane->ProjectPointOntoPlane(gizmo->GetCenter() + (gizmo->GetAxisY() * arrowLength) * direction),
239 appender->AddInputData(axisY);
242 Create2DArrow(cameraDirection,
244 plane->ProjectPointOntoPlane(gizmo->GetCenter() + (gizmo->GetAxisZ() * arrowLength) * direction),
247 appender->AddInputData(axisZ);
250 ls->m_VtkPolyDataMapper->SetInputConnection(appender->GetOutputPort());
252 ApplyVisualProperties(renderer);
255 void mitk::GizmoMapper2D::ApplyVisualProperties(
BaseRenderer *renderer)
259 float lineWidth = 3.0f;
260 ls->m_Actor->GetProperty()->SetLineWidth(lineWidth);
264 if (lookupTableProp.IsNotNull())
266 ls->m_VtkPolyDataMapper->SetLookupTable(lookupTableProp->GetLookupTable()->GetVtkLookupTable());
269 bool scalarVisibility =
false;
271 ls->m_VtkPolyDataMapper->SetScalarVisibility((scalarVisibility ? 1 : 0));
273 if (scalarVisibility)
276 if (this->
GetDataNode()->GetProperty(scalarMode,
"scalar mode", renderer))
281 bool colorMode =
false;
283 ls->m_VtkPolyDataMapper->SetColorMode((colorMode ? 1 : 0));
285 double scalarsMin = 0;
288 double scalarsMax = 1.0;
291 ls->m_VtkPolyDataMapper->SetScalarRange(scalarsMin, scalarsMax);
306 double colorMoveFreely[] = {1, 0, 0, 1};
307 double colorAxisX[] = {0.753, 0, 0, 1};
308 double colorAxisY[] = {0, 0.69, 0, 1};
309 double colorAxisZ[] = {0, 0.502, 1, 1};
310 double colorInactive[] = {0.7, 0.7, 0.7, 1};
313 vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
314 lut->SetNumberOfTableValues((
int)Gizmo::NoHandle + 1);
315 lut->SetTableRange(0, (
int)Gizmo::NoHandle);
326 lut->SetTableValue(Gizmo::NoHandle, colorInactive);
329 mlut->SetVtkLookupTable(lut);
332 lutProp->SetLookupTable(mlut);
333 node->
SetProperty(
"LookupTable", lutProp, renderer);
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...
bool GetDoubleProperty(const char *propertyKey, double &doubleValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for double properties (instances of DoubleProperty)
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
vtkRenderer * GetVtkRenderer() const
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
Organizes the rendering process.
double GetScaleFactorMMPerDisplayUnit() const
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
virtual void SetScalarModeToDefault()
int GetSizeX() const
get the x_size of the RendererWindow
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual int GetVtkScalarMode()
virtual CameraController * GetCameraController()
virtual MapperSlotId GetMapperID()
Get the MapperSlotId to use.
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.
Class for nodes of the DataTree.
int GetSizeY() const
get the y_size of the RendererWindow