15 #include <vtkPolyLine.h> 16 #include <vtkIdList.h> 17 #include <vtkCellArray.h> 18 #include <vtkFloatArray.h> 19 #include <vtkPointData.h> 20 #include <vtkWarpVector.h> 21 #include <vtkCleanPolyData.h> 22 #include <vtkVectorNorm.h> 23 #include <vtkGlyph3D.h> 24 #include <vtkArrowSource.h> 36 #include "mapRegistration.h" 44 int internalFrequ = 1;
87 bounds[1] = size[0]/spacing[0];
89 bounds[3] = size[1]/spacing[1];
91 bounds[5] = size[2]/spacing[2];
92 gridDesc->SetBounds(bounds);
93 gridDesc->SetSpacing(spacing);
94 gridDesc->SetOrigin(origin);
96 gridFrequ = internalFrequ;
104 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
105 vtkSmartPointer<vtkFloatArray> vectors = vtkSmartPointer<vtkFloatArray>::New();
106 vectors->SetNumberOfComponents(3);
107 vectors->SetName(
"DeformationVectors");
109 long xExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(0));
110 long yExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(1));
111 long zExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(2));
117 for (pos[2] = bounds[4] ; pos[2]< bounds[4]+zExtend; ++(pos[2]))
119 for (pos[1] = bounds[2]; pos[1]< bounds[2]+yExtend; ++(pos[1]))
121 for (pos[0] = bounds[0]; pos[0]< bounds[0]+xExtend; ++(pos[0]))
125 points->InsertNextPoint(worldPos[0],worldPos[1],worldPos[2]);
129 map::core::RegistrationKernelBase<3,3>::InputPointType regInput(worldPos);
130 map::core::RegistrationKernelBase<3,3>::OutputPointType regOutput;
132 bool mapped = regKernel->mapPoint(regInput,regOutput);
139 vectors->InsertNextTuple(vector.GetDataPointer());
145 vtkSmartPointer<vtkPolyData> input = vtkSmartPointer<vtkPolyData>::New();
146 vtkSmartPointer<vtkFloatArray> vectorMagnitude;
148 input->SetPoints(points);
152 input->GetPointData()->SetVectors(vectors);
153 input->GetPointData()->SetActiveVectors(vectors->GetName());
155 vtkSmartPointer<vtkVectorNorm> norm = vtkSmartPointer<vtkVectorNorm>::New();
156 norm->SetInputData(input);
157 norm->SetAttributeModeToUsePointData();
160 vectorMagnitude = vtkFloatArray::SafeDownCast(norm->GetOutput()->GetPointData()->GetScalars());
161 vectorMagnitude->SetName(
"VectorMagnitude");
162 input->GetPointData()->SetScalars(vectorMagnitude);
163 input->GetPointData()->SetActiveScalars(vectorMagnitude->GetName());
166 vtkSmartPointer<vtkGlyph3D> glyphFilter = vtkSmartPointer<vtkGlyph3D>::New();
167 glyphFilter->ScalingOn();
168 glyphFilter->OrientOn();
169 glyphFilter->SetVectorModeToUseVector();
170 glyphFilter->SetScaleModeToScaleByVector();
171 glyphFilter->SetInputData(input);
173 vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New();
174 arrowSource->SetTipLength(0.2);
176 glyphFilter->SetSourceConnection(arrowSource->GetOutputPort());
178 glyphFilter->Update();
180 vtkSmartPointer<vtkPolyData> output = glyphFilter->GetOutput();
189 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
190 vtkSmartPointer<vtkFloatArray> vectors = vtkSmartPointer<vtkFloatArray>::New();
191 vectors->SetNumberOfComponents(3);
192 vectors->SetName(
"DeformationVectors");
194 long xExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(0))+1;
195 long yExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(1))+1;
196 long zExtend = itk::Math::Ceil<long,mitk::ScalarType>(gridDesc->
GetExtent(2))+1;
197 long zOffset = xExtend*yExtend;
203 for (pos[2] = bounds[4] ; pos[2]< bounds[4]+zExtend; ++(pos[2]))
205 for (pos[1] = bounds[2]; pos[1]< bounds[2]+yExtend; ++(pos[1]))
207 for (pos[0] = bounds[0]; pos[0]< bounds[0]+xExtend; ++(pos[0]))
211 points->InsertNextPoint(worldPos[0],worldPos[1],worldPos[2]);
215 map::core::RegistrationKernelBase<3,3>::InputPointType regInput(worldPos);
216 map::core::RegistrationKernelBase<3,3>::OutputPointType regOutput;
218 bool mapped = regKernel->mapPoint(regInput,regOutput);
225 vectors->InsertNextTuple(vector.GetDataPointer());
231 vtkSmartPointer<vtkCellArray> gridLinesCell = vtkSmartPointer<vtkCellArray>::New();
232 vtkSmartPointer<vtkPolyLine> gridLine = vtkSmartPointer<vtkPolyLine>::New();
233 gridLine->GetPointIds()->SetNumberOfIds(2);
236 for (
long zPos = 0; zPos< zExtend-1; ++zPos)
238 for (
long yPos = 0; yPos< yExtend-1; ++yPos)
240 for (
long xPos = 0; xPos< xExtend-1; ++xPos)
242 gridLine->GetPointIds()->SetId(0, xPos+yPos*xExtend+zPos*zOffset);
244 if ((yPos%gridFrequence == 0) && (zPos%gridFrequence == 0))
246 gridLine->GetPointIds()->SetId(1, (xPos+1)+yPos*xExtend+zPos*zOffset);
247 gridLinesCell->InsertNextCell(gridLine);
250 if ((xPos%gridFrequence == 0) && (zPos%gridFrequence == 0))
252 gridLine->GetPointIds()->SetId(1, xPos+(yPos+1)*xExtend+zPos*zOffset);
253 gridLinesCell->InsertNextCell(gridLine);
256 if ((xPos%gridFrequence == 0) && (yPos%gridFrequence == 0))
258 gridLine->GetPointIds()->SetId(1, xPos+yPos*xExtend+(zPos+1)*zOffset);
259 gridLinesCell->InsertNextCell(gridLine);
265 vtkSmartPointer<vtkPolyData> grid = vtkSmartPointer<vtkPolyData>::New();
266 vtkSmartPointer<vtkFloatArray> vectorMagnitude;
268 grid->SetPoints(points);
269 grid->SetLines(gridLinesCell);
273 grid->GetPointData()->SetVectors(vectors);
274 grid->GetPointData()->SetActiveVectors(vectors->GetName());
276 vtkSmartPointer<vtkVectorNorm> norm = vtkSmartPointer<vtkVectorNorm>::New();
277 norm->SetInputData(grid);
278 norm->SetAttributeModeToUsePointData();
281 vectorMagnitude = vtkFloatArray::SafeDownCast(norm->GetOutput()->GetPointData()->GetScalars());
282 vectorMagnitude->SetName(
"VectorMagnitude");
285 vtkSmartPointer<vtkPolyData> input = grid;
289 vtkSmartPointer<vtkWarpVector> warp = vtkSmartPointer<vtkWarpVector>::New();
291 warp->SetInputData(input);
292 warp->SetScaleFactor(1);
295 input = warp->GetPolyDataOutput();
297 input->GetPointData()->SetScalars(vectorMagnitude);
298 input->GetPointData()->SetActiveScalars(vectorMagnitude->GetName());
340 mitkThrow() <<
"Cannot check for outdated property. Passed regNode is null.";
348 result = reference < prop->GetMTime();
352 mitkThrow() <<
"Cannot check for outdated property. Property not defined in passed regNode. Property name: "<<propName;
360 const map::core::RegistrationKernelBase<3,3>* regKernel =
nullptr;
362 if (!regNode)
return regKernel;
366 if (!regWrapper)
return regKernel;
368 const map::core::Registration<3,3>* reg =
dynamic_cast<const map::core::Registration<3,3>*
>(regWrapper->
GetRegistration());
377 regKernel = &(reg->getDirectMapping());
381 regKernel = &(reg->getInverseMapping());
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...
virtual IdType GetValueAsId() const
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_RegVisFOVOrigin
void GetGridGeometryFromNode(const mitk::DataNode *regNode, mitk::Geometry3D::Pointer &gridDesc, unsigned int &gridFrequ)
BoundingBoxType::BoundsArrayType BoundsArrayType
const char *const nodeProp_RegVisDirection
ScalarType GetExtent(unsigned int direction) const
Set the time bounds (in ms)
DataCollection - Class to facilitate loading/accessing structured data.
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for int properties (instances of IntProperty)
virtual T GetValue() const
const char *const nodeProp_RegVisFOVSpacing
::map::core::RegistrationBase * GetRegistration()
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
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)
const char *const nodeProp_RegVisGridFrequence
const BoundsArrayType GetBounds() const
BaseGeometry Describes the geometry of a data object.
Class for nodes of the DataTree.
const map::core::RegistrationKernelBase< 3, 3 > * GetRelevantRegKernelOfNode(const mitk::DataNode *regNode)