20 #include <vtkCellArray.h>
21 #include <vtkCellData.h>
22 #include <vtkCutter.h>
23 #include <vtkDataArray.h>
24 #include <vtkDataObject.h>
25 #include <vtkDataSetWriter.h>
26 #include <vtkFloatArray.h>
27 #include <vtkGlyph2D.h>
28 #include <vtkGlyphSource2D.h>
29 #include <vtkImageData.h>
30 #include <vtkImageReslice.h>
31 #include <vtkIndent.h>
32 #include <vtkLinearTransform.h>
33 #include <vtkLookupTable.h>
34 #include <vtkLookupTable.h>
38 #include <vtkMatrix4x4.h>
39 #include <vtkMatrixToLinearTransform.h>
42 #include <vtkPointData.h>
43 #include <vtkPoints.h>
44 #include <vtkPolyData.h>
45 #include <vtkPolyData.h>
46 #include <vtkPolyDataMapper.h>
47 #include <vtkScalarsToColors.h>
48 #include <vtkScalarsToColors.h>
49 #include <vtkTransform.h>
74 GetDataNode()->GetVisibility(visible, renderer,
"visible");
84 vtkImageData *vtkImage = input->GetVtkImageData(this->GetCurrentTimeStep(input, renderer));
94 if (worldPlaneGeometry.IsNotNull())
97 point = worldPlaneGeometry->GetOrigin();
98 normal = worldPlaneGeometry->GetNormal();
100 m_Plane->SetTransform((vtkAbstractTransform *)NULL);
104 itkWarningMacro(<<
"worldPlaneGeometry is NULL!");
108 double vp[3], vp_slice[3], vnormal[3];
109 vnl2vtk(point.GetVnlVector(), vp);
110 vnl2vtk(normal.GetVnlVector(), vnormal);
118 vtkLinearTransform *vtktransform = GetDataNode()->GetVtkTransform();
121 world2vtk->Identity();
122 world2vtk->Concatenate(vtktransform->GetLinearInverse());
124 world2vtk->GetScale(myscale);
125 world2vtk->PostMultiply();
126 world2vtk->Scale(1 / myscale[0], 1 / myscale[1], 1 / myscale[2]);
127 world2vtk->TransformPoint(vp, vp);
128 world2vtk->TransformNormalAtPoint(vp, vnormal, vnormal);
139 vtkImage->GetDimensions(dims);
141 vtkImage->GetSpacing(spac);
145 if (fabs(vnormal[0]) > fabs(vnormal[1]) && fabs(vnormal[0]) > fabs(vnormal[2]))
147 if (fabs(vp_slice[0] / spac[0]) < 0.4)
148 vp_slice[0] = 0.4 * spac[0];
149 if (fabs(vp_slice[0] / spac[0]) > (dims[0] - 1) - 0.4)
150 vp_slice[0] = ((dims[0] - 1) - 0.4) * spac[0];
155 if (fabs(vnormal[1]) > fabs(vnormal[0]) && fabs(vnormal[1]) > fabs(vnormal[2]))
157 if (fabs(vp_slice[1] / spac[1]) < 0.4)
158 vp_slice[1] = 0.4 * spac[1];
159 if (fabs(vp_slice[1] / spac[1]) > (dims[1] - 1) - 0.4)
160 vp_slice[1] = ((dims[1] - 1) - 0.4) * spac[1];
165 if (fabs(vnormal[2]) > fabs(vnormal[1]) && fabs(vnormal[2]) > fabs(vnormal[0]))
167 if (fabs(vp_slice[2] / spac[2]) < 0.4)
168 vp_slice[2] = 0.4 * spac[2];
169 if (fabs(vp_slice[2] / spac[2]) > (dims[2] - 1) - 0.4)
170 vp_slice[2] = ((dims[2] - 1) - 0.4) * spac[2];
175 m_Plane->SetOrigin(vp_slice);
176 m_Plane->SetNormal(vnormal);
178 vtkPolyData *cuttedPlane;
179 if (!((dims[0] == 1 && vnormal[0] != 0) || (dims[1] == 1 && vnormal[1] != 0) || (dims[2] == 1 && vnormal[2] != 0)))
181 m_Cutter->SetCutFunction(m_Plane);
182 m_Cutter->SetInputData(vtkImage);
183 m_Cutter->GenerateCutScalarsOff();
185 cuttedPlane = m_Cutter->GetOutput();
193 points->SetNumberOfPoints(vtkImage->GetNumberOfPoints());
194 for (
int i = 0; i < vtkImage->GetNumberOfPoints(); i++)
195 points->SetPoint(i, vtkImage->GetPoint(i));
196 cuttedPlane->SetPoints(points);
198 int comps = vtkImage->GetPointData()->GetScalars()->GetNumberOfComponents();
199 pointdata->SetNumberOfComponents(comps);
200 int tuples = vtkImage->GetPointData()->GetScalars()->GetNumberOfTuples();
201 pointdata->SetNumberOfTuples(tuples);
202 for (
int i = 0; i < tuples; i++)
203 pointdata->SetTuple(i, vtkImage->GetPointData()->GetScalars()->GetTuple(i));
204 pointdata->SetName(
"vector");
205 cuttedPlane->GetPointData()->AddArray(pointdata);
208 if (cuttedPlane->GetNumberOfPoints() != 0)
213 vtkPointData *pointData = cuttedPlane->GetPointData();
214 if (pointData == NULL)
216 itkWarningMacro(<<
"no point data associated with cutters result!");
219 if (pointData->GetNumberOfArrays() == 0)
221 itkWarningMacro(<<
"point data returned by cutter doesn't have any arrays associated!");
224 else if (pointData->GetArray(0)->GetNumberOfComponents() <= 1)
226 itkWarningMacro(<<
"number of components <= 1!");
229 else if (pointData->GetArrayName(0) == NULL)
231 pointData->GetArray(0)->SetName(
"vector");
240 vtkIdType numPoints, pointId;
241 numPoints = cuttedPlane->GetNumberOfPoints();
242 vtkDataArray *inVectors = cuttedPlane->GetPointData()->GetVectors(
"vector");
243 assert(inVectors != NULL);
245 vectorMagnitudes->SetName(
"vectorMagnitudes");
246 vectorMagnitudes->SetNumberOfComponents(1);
247 vectorMagnitudes->SetNumberOfValues(numPoints);
248 vectorMagnitudes->SetNumberOfTuples(numPoints);
249 double inVector[3], outVector[3], wnormal[3];
251 vnl2vtk(normal.GetVnlVector(), wnormal);
254 m_DataNode->GetBoolProperty(
"NormalizeVecs", normalizeVecs);
255 for (pointId = 0; pointId < numPoints; ++pointId)
257 inVectors->GetTuple(pointId, inVector);
260 vnl_vector<double> tmp(3);
265 k = vtkMath::Dot(wnormal, inVector);
267 outVector[0] = inVector[0] - (wnormal[0] * k);
268 outVector[1] = inVector[1] - (wnormal[1] * k);
269 outVector[2] = inVector[2] - (wnormal[2] * k);
270 inVectors->SetTuple(pointId, outVector);
273 vectorMagnitudes->SetValue(pointId, vtkMath::Norm(outVector));
278 pointData->AddArray(vectorMagnitudes);
279 pointData->CopyAllOn();
289 glyphSource->DashOn();
293 glyphSource->CrossOff();
298 vtkImage->GetSpacing(spacing);
299 double min = spacing[0];
300 min = min > spacing[1] ? spacing[1] :
min;
301 min = min > spacing[2] ? spacing[2] :
min;
306 if (mitkScaleProp.IsNotNull())
308 scale = mitkScaleProp->GetValue();
312 glyphGenerator->SetSourceData(glyphSource->GetOutput());
313 glyphGenerator->
SetInput(cuttedPlane);
314 glyphGenerator->SetInputArrayToProcess(1, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS,
"vector");
315 glyphGenerator->SetVectorModeToUseVector();
316 glyphGenerator->OrientOn();
317 glyphGenerator->SetScaleFactor(min * scale);
318 glyphGenerator->SetUseMaskPoints(
true);
320 glyphGenerator->SetMaximumNumberOfPoints(128 * 128);
322 glyphGenerator->Update();
337 if (mitkColorProp.IsNotNull())
339 color = mitkColorProp->GetColor();
351 if (mitkLWidthProp.IsNotNull())
353 lwidth = mitkLWidthProp->GetValue();
358 trafo->Concatenate(vtktransform);
359 trafo->PreMultiply();
361 trafo->GetScale(myscale);
362 trafo->Scale(1 / myscale[0], 1 / myscale[1], 1 / myscale[2]);
364 this->PaintCells(glyphGenerator->GetOutput(),
373 vectorMagnitudes->Delete();
374 glyphSource->Delete();
375 glyphGenerator->Delete();
380 std::cout <<
" no points cutted!" << std::endl;
387 vtkLinearTransform *vtktransform,
389 vtkScalarsToColors *lut,
394 vtkPoints *points = glyphs->GetPoints();
395 vtkPointData *vpointdata = glyphs->GetPointData();
396 vtkDataArray *vpointscalars = vpointdata->GetArray(
"vectorMagnitudes");
398 assert(vpointscalars != NULL);
408 for (
auto &elem : offset)
413 vtkIdType numCells = glyphs->GetNumberOfCells();
414 for (vtkIdType cellId = 0; cellId < numCells; ++cellId)
418 cell = glyphs->GetCell(cellId);
419 idList = cell->GetPointIds();
421 int numPoints = idList->GetNumberOfIds();
426 double pos[3], vp_raster[3];
427 points->GetPoint(idList->GetId(0), vp);
428 vp_raster[0] = vtkMath::Round(vp[0] / spacing[0]) * spacing[0];
429 vp_raster[1] = vtkMath::Round(vp[1] / spacing[1]) * spacing[1];
430 vp_raster[2] = vtkMath::Round(vp[2] / spacing[2]) * spacing[2];
431 vtktransform->TransformPoint(vp_raster, pos);
432 offset[0] = pos[0] - vp[0];
433 offset[1] = pos[1] - vp[1];
434 offset[2] = pos[2] - vp[2];
439 glBegin(GL_LINE_LOOP);
441 for (
int pointNr = 0; pointNr < numPoints; ++pointNr)
443 points->GetPoint(idList->GetId(pointNr), vp);
445 vp[0] = vp[0] + offset[0];
446 vp[1] = vp[1] + offset[1];
447 vp[2] = vp[2] + offset[2];
450 vtktransform->TransformPoint(vp, tmp);
462 if (vpointscalars != NULL)
464 vpointscalars->GetComponent(pointNr, 0);
465 color = lut->GetColor(vpointscalars->GetComponent(idList->GetId(pointNr), 0));
466 glColor3f(color[0], color[1], color[2]);
471 glColor3f(color.GetRed(), color.GetGreen(), color.GetBlue());
476 glVertex2f(p2d[0], p2d[1]);
489 m_Cutter->SetCutFunction(m_Plane);
490 m_Cutter->GenerateValues(1, 0, 1);
499 if (m_Cutter != NULL)
509 if ((dataTimeGeometry == NULL) || (dataTimeGeometry->CountTimeSteps() == 0))
511 itkWarningMacro(<<
"The given object is missing a mitk::TimeGeometry, or the number of time steps is 0!");
523 if (time > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin())
527 itkWarningMacro(<< timestep <<
" is not a valid time of the given data object!");
Base of all data objects.
mitk::Image::ConstPointer m_Image
Organizes the rendering process.
void vtk2vnl(const Tin *in, vnl_vector< Tout > &out)
static vtkMaskedGlyph3D * New()
ScalarType GetTime() const
Get the time in ms of the currently displayed content.
virtual void PaintCells(vtkPolyData *contour, const PlaneGeometry *, vtkLinearTransform *vtktransform, BaseRenderer *renderer, vtkScalarsToColors *lut, mitk::Color color, float lwidth, double *spacing)
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 Paint(mitk::BaseRenderer *renderer) override
Do the painting into the renderer.
The ColorProperty class RGB color property.
virtual ~VectorImageMapper2D()
void SetRandomMode(int mode)
virtual void SetInput(vtkDataSet *input)
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 vnl2vtk(const vnl_vector< Tin > &in, Tout *out)
const mitk::Image * GetInput(void)
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
Image class for storing images.
void vtk2itk(const Tin &in, Tout &out)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
void Normalize(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer im2, mitk::Image::Pointer mask1, std::string output)
const mitk::TimeGeometry * GetUpdatedTimeGeometry()
Return the TimeGeometry of the data.
int GetCurrentTimeStep(mitk::BaseData *data, mitk::BaseRenderer *renderer)
Describes a two-dimensional, rectangular plane.
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
virtual bool IsValidTimeStep(TimeStepType timeStep) const =0
Test for the given time step if a geometry is availible.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.