19 #include <vtkPolyLine.h>
20 #include <vtkIdList.h>
21 #include <vtkCellArray.h>
22 #include <vtkFloatArray.h>
23 #include <vtkPointData.h>
24 #include <vtkWarpVector.h>
25 #include <vtkCleanPolyData.h>
26 #include <vtkVectorNorm.h>
27 #include <vtkGlyph3D.h>
28 #include <vtkArrowSource.h>
40 #include "mapRegistration.h"
48 int internalFrequ = 1;
91 bounds[1] = size[0]/spacing[0];
93 bounds[3] = size[1]/spacing[1];
95 bounds[5] = size[2]/spacing[2];
96 gridDesc->SetBounds(bounds);
97 gridDesc->SetSpacing(spacing);
98 gridDesc->SetOrigin(origin);
100 gridFrequ = internalFrequ;
110 vectors->SetNumberOfComponents(3);
111 vectors->SetName(
"DeformationVectors");
113 long xExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(0));
114 long yExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(1));
115 long zExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(2));
116 long zOffset = xExtend*yExtend;
122 for (pos[2] = bounds[4] ; pos[2]< bounds[4]+zExtend; ++(pos[2]))
124 for (pos[1] = bounds[2]; pos[1]< bounds[2]+yExtend; ++(pos[1]))
126 for (pos[0] = bounds[0]; pos[0]< bounds[0]+xExtend; ++(pos[0]))
130 points->InsertNextPoint(worldPos[0],worldPos[1],worldPos[2]);
134 map::core::RegistrationKernelBase<3,3>::InputPointType regInput(worldPos);
135 map::core::RegistrationKernelBase<3,3>::OutputPointType regOutput;
137 bool mapped = regKernel->mapPoint(regInput,regOutput);
144 vectors->InsertNextTuple(vector.GetDataPointer());
151 vtkSmartPointer<vtkFloatArray> vectorMagnitude;
153 input->SetPoints(points);
157 input->GetPointData()->SetVectors(vectors);
158 input->GetPointData()->SetActiveVectors(vectors->GetName());
161 norm->SetInputData(input);
162 norm->SetAttributeModeToUsePointData();
165 vectorMagnitude = vtkFloatArray::SafeDownCast(norm->GetOutput()->GetPointData()->GetScalars());
166 vectorMagnitude->SetName(
"VectorMagnitude");
167 input->GetPointData()->SetScalars(vectorMagnitude);
168 input->GetPointData()->SetActiveScalars(vectorMagnitude->GetName());
172 glyphFilter->ScalingOn();
173 glyphFilter->OrientOn();
174 glyphFilter->SetVectorModeToUseVector();
175 glyphFilter->SetScaleModeToScaleByVector();
176 glyphFilter->SetInputData(input);
179 arrowSource->SetTipLength(0.2);
181 glyphFilter->SetSourceConnection(arrowSource->GetOutputPort());
183 glyphFilter->Update();
185 vtkSmartPointer<vtkPolyData> output = glyphFilter->GetOutput();
196 vectors->SetNumberOfComponents(3);
197 vectors->SetName(
"DeformationVectors");
199 long xExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(0))+1;
200 long yExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(1))+1;
201 long zExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(2))+1;
202 long zOffset = xExtend*yExtend;
208 for (pos[2] = bounds[4] ; pos[2]< bounds[4]+zExtend; ++(pos[2]))
210 for (pos[1] = bounds[2]; pos[1]< bounds[2]+yExtend; ++(pos[1]))
212 for (pos[0] = bounds[0]; pos[0]< bounds[0]+xExtend; ++(pos[0]))
216 points->InsertNextPoint(worldPos[0],worldPos[1],worldPos[2]);
220 map::core::RegistrationKernelBase<3,3>::InputPointType regInput(worldPos);
221 map::core::RegistrationKernelBase<3,3>::OutputPointType regOutput;
223 bool mapped = regKernel->mapPoint(regInput,regOutput);
230 vectors->InsertNextTuple(vector.GetDataPointer());
238 gridLine->GetPointIds()->SetNumberOfIds(2);
241 for (
long zPos = 0; zPos< zExtend-1; ++zPos)
243 for (
long yPos = 0; yPos< yExtend-1; ++yPos)
245 for (
long xPos = 0; xPos< xExtend-1; ++xPos)
247 gridLine->GetPointIds()->SetId(0, xPos+yPos*xExtend+zPos*zOffset);
249 if ((yPos%gridFrequence == 0) && (zPos%gridFrequence == 0))
251 gridLine->GetPointIds()->SetId(1, (xPos+1)+yPos*xExtend+zPos*zOffset);
252 gridLinesCell->InsertNextCell(gridLine);
255 if ((xPos%gridFrequence == 0) && (zPos%gridFrequence == 0))
257 gridLine->GetPointIds()->SetId(1, xPos+(yPos+1)*xExtend+zPos*zOffset);
258 gridLinesCell->InsertNextCell(gridLine);
261 if ((xPos%gridFrequence == 0) && (yPos%gridFrequence == 0))
263 gridLine->GetPointIds()->SetId(1, xPos+yPos*xExtend+(zPos+1)*zOffset);
264 gridLinesCell->InsertNextCell(gridLine);
271 vtkSmartPointer<vtkFloatArray> vectorMagnitude;
273 grid->SetPoints(points);
274 grid->SetLines(gridLinesCell);
278 grid->GetPointData()->SetVectors(vectors);
279 grid->GetPointData()->SetActiveVectors(vectors->GetName());
282 norm->SetInputData(grid);
283 norm->SetAttributeModeToUsePointData();
286 vectorMagnitude = vtkFloatArray::SafeDownCast(norm->GetOutput()->GetPointData()->GetScalars());
287 vectorMagnitude->SetName(
"VectorMagnitude");
290 vtkSmartPointer<vtkPolyData> input = grid;
296 warp->SetInputData(input);
297 warp->SetScaleFactor(1);
300 input = warp->GetPolyDataOutput();
302 input->GetPointData()->SetScalars(vectorMagnitude);
303 input->GetPointData()->SetActiveScalars(vectorMagnitude->GetName());
345 mitkThrow() <<
"Cannot check for outdated property. Passed regNode is null.";
353 result = reference < prop->GetMTime();
357 mitkThrow() <<
"Cannot check for outdated property. Property not defined in passed regNode. Property name: "<<propName;
365 const map::core::RegistrationKernelBase<3,3>* regKernel = NULL;
367 if (!regNode)
return regKernel;
371 if (!regWrapper)
return regKernel;
373 const map::core::Registration<3,3>* reg =
dynamic_cast<const map::core::Registration<3,3>*
>(regWrapper->
GetRegistration());
382 regKernel = &(reg->getDirectMapping());
386 regKernel = &(reg->getInverseMapping());
ScalarType GetExtent(unsigned int direction) const
Set the time bounds (in ms)
const char *const nodeProp_RegVisFOVOrigin
void GetGridGeometryFromNode(const mitk::DataNode *regNode, mitk::Geometry3D::Pointer &gridDesc, unsigned int &gridFrequ)
BoundingBoxType::BoundsArrayType BoundsArrayType
bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for int properties (instances of IntProperty)
const char *const nodeProp_RegVisDirection
DataCollection - Class to facilitate loading/accessing structured data.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
const BoundsArrayType GetBounds() const
const char *const nodeProp_RegVisFOVSpacing
map::core::RegistrationBase * GetRegistration()
Abstract base class for properties.
const char *const nodeProp_RegVisFOVSize
vtkSmartPointer< vtkPolyData > MITKMATCHPOINTREGISTRATION_EXPORT Generate3DDeformationGrid(const mitk::BaseGeometry *gridDesc, unsigned int gridFrequence, const map::core::RegistrationKernelBase< 3, 3 > *regKernel)
#define MITKMATCHPOINTREGISTRATION_EXPORT
bool PropertyIsOutdated(const mitk::DataNode *regNode, const std::string &propName, const itk::TimeStamp &reference)
bool GridIsOutdated(const mitk::DataNode *regNode, const itk::TimeStamp &reference)
vtkSmartPointer< vtkPolyData > Generate3DDeformationGlyph(const mitk::BaseGeometry *gridDesc, const map::core::RegistrationKernelBase< 3, 3 > *regKernel)
void IndexToWorld(const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const
Convert (continuous or discrete) index coordinates of a vector vec_units to world coordinates (in mm)...
const char *const nodeProp_RegVisGridFrequence
BaseGeometry Describes the geometry of a data object.
Class for nodes of the DataTree.
virtual IdType GetValueAsId() const
const map::core::RegistrationKernelBase< 3, 3 > * GetRelevantRegKernelOfNode(const mitk::DataNode *regNode)
virtual T GetValue() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.