7 #include "PlusConfigure.h" 10 #include "vtkIGSIOTransformRepository.h" 12 #include "vtkObjectFactory.h" 13 #include "vtkXMLUtilities.h" 14 #include "vtksys/SystemTools.hxx" 18 #include "itkLandmarkBasedTransformInitializer.h" 19 #include "itkSimilarity3DTransform.h" 40 vtkSmartPointer<vtkPoints> acquiredPoints = vtkSmartPointer<vtkPoints>::New();
43 vtkSmartPointer<vtkDoubleArray> markerToReferenceTransformMatrixArray = vtkSmartPointer<vtkDoubleArray>::New();
62 LOG_TRACE(
"vtkPlusPhantomLinearObjectRegistrationAlgo::Register");
88 LOG_DEBUG(
"Phantom plane " <<
i <<
": Defined: " << it->ToXMLString() <<
" Recorded: " << movingPlanes.
GetPlane(
i).
ToXMLString() );
93 auto transform = itk::VersorRigid3DTransform<double>::New();
94 transform->SetIdentity();
104 vtkSmartPointer<vtkMatrix4x4> phantomToReferenceTransformMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
105 phantomToReferenceTransformMatrix->Identity();
138 if (aTransformRepository)
142 aTransformRepository->SetTransformPersistent(phantomToReferenceTransformName,
true);
143 aTransformRepository->SetTransformDate(phantomToReferenceTransformName, vtkIGSIOAccurateTimer::GetInstance()->GetDateAndTimeString().c_str());
144 aTransformRepository->SetTransformError(phantomToReferenceTransformName, this->
RegistrationError);
148 LOG_INFO(
"Transform repository object is NULL, cannot save results into it");
158 LOG_TRACE(
"vtkPlusPhantomLinearObjectRegistrationAlgo::ReadConfiguration");
160 XML_FIND_NESTED_ELEMENT_REQUIRED(phantomDefinition, aConfig,
"PhantomDefinition");
167 XML_FIND_NESTED_ELEMENT_REQUIRED(geometry, phantomDefinition,
"Geometry");
170 vtkXMLDataElement* references = geometry->FindNestedElementWithName(
"References");
171 if (references == NULL)
173 if(geometry->FindNestedElementWithName(
"Landmarks") == NULL)
175 LOG_ERROR(
"No References or Landmarks found in configuration file found, registration is not possible!");
180 LOG_WARNING(
"No References found in configuration file found, perform Landmark Registration");
187 int numberOfReferences = references->GetNumberOfNestedElements();
191 for (
int i=0;
i<numberOfReferences; ++
i)
194 vtkXMLDataElement* reference = references->GetNestedElement(
i);
195 if ((reference == NULL) || (STRCASECMP(
"Reference", reference->GetName())))
197 LOG_WARNING(
"Invalid reference definition found");
202 const char* referenceName = reference->GetAttribute(
"Name");
203 if (referenceName==NULL)
205 LOG_WARNING(
"Invalid reference name (reference #"<<
i+1<<
")");
209 double referencePosition[3];
210 if (! reference->GetVectorAttribute(
"Position", 3, referencePosition))
212 LOG_WARNING(
"Invalid reference position (reference #"<<
i+1<<
")");
216 std::vector<double> referencePositionVector;
217 for(
int j=0; j<3;j++)
219 referencePositionVector.push_back(referencePosition[j]);
229 LOG_ERROR(
"No valid references were found!");
234 vtkXMLDataElement* planes = geometry->FindNestedElementWithName(
"Planes");
237 if(geometry->FindNestedElementWithName(
"Landmarks") == NULL)
239 LOG_ERROR(
"No Planes or Landmarks found in configuration file found, registration is not possible!");
244 LOG_WARNING(
"No Planes found in configuration file found, perform Landmark Registration");
251 int numberOfPlanes = planes->GetNumberOfNestedElements();
255 for (
int i=0;
i<numberOfPlanes; ++
i)
258 vtkXMLDataElement* plane = planes->GetNestedElement(
i);
260 if ((plane == NULL) || (STRCASECMP(
"Plane", plane->GetName())))
262 LOG_WARNING(
"Invalid plane definition found!");
267 const char* planeName = plane->GetAttribute(
"Name");
270 LOG_WARNING(
"Invalid plane name (plane #"<<
i+1<<
")");
275 std::vector<double> pointsOnPlane[3];
277 double pointOnPlane[3];
279 if (! plane->GetVectorAttribute(
"BasePoint", 3, pointOnPlane))
281 LOG_WARNING(
"Invalid base point position!");
284 for(
int j=0; j<3; j++)
286 pointsOnPlane[0].push_back(pointOnPlane[j]);
289 if (! plane->GetVectorAttribute(
"EndPoint1", 3, pointOnPlane))
291 LOG_WARNING(
"Invalid end point 1 position!");
294 for(
int j=0; j<3; j++)
296 pointsOnPlane[1].push_back(pointOnPlane[j]);
299 if (! plane->GetVectorAttribute(
"EndPoint2", 3, pointOnPlane))
301 LOG_WARNING(
"Invalid end point 2 position!");
304 for(
int j=0; j<3; j++)
306 pointsOnPlane[2].push_back(pointOnPlane[j]);
317 LOG_ERROR(
"No valid planes were found!");
333 LOG_TRACE(
"vtkPlusPhantomLinearObjectRegistrationAlgo::ComputeError");
373 LOG_TRACE(
"vtkPhantomLinearObjectRegistration::Initialize");
std::vector< Plane >::const_iterator PlanesBegin() const
virtual void SetRecordedPoints(vtkPoints *)
PlusStatus LinearObjectRegister(vtkIGSIOTransformRepository *aTransformRepository=NULL)
virtual void SetPhantomToReferenceTransformMatrix(vtkMatrix4x4 *)
const Plane & GetPlane(int index)
char * PhantomCoordinateFrame
virtual ~vtkPlusPhantomLinearObjectRegistrationAlgo()
vtkPlusPhantomLinearObjectRegistrationAlgo()
std::vector< std::string > DefinedPlaneNames
PlusStatus ComputeError()
virtual std::string ToXMLString() const
References DefinedReferences
vtkMatrix4x4 * PhantomToReferenceTransformMatrix
Landmark registration to determine the Phantom pose relative to the attached marker (PhantomReference...
void SetRecordedPlanes(Planes *planes)
std::vector< std::string > DefinedReferenceNames
char * StylusTipCoordinateFrame
void InsertPlane(const Plane &newPlane)
virtual void SetMarkerToReferenceTransformMatrixArray(vtkDoubleArray *)
void InsertReference(const Reference &newReference)
vtkDoubleArray * MarkerToReferenceTransformMatrixArray
char * ReferenceCoordinateFrame
std::vector< Plane >::const_iterator PlanesEnd() const
vtkPoints * RecordedPoints
PlusStatus InsertNextCalibrationPoint(vtkMatrix4x4 *aMarkerToReferenceTransformMatrix)
PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
static std::string ConfigurationElementName
void SetDefinedPlanesFromXML(Planes *planes)
vtkStandardNewMacro(vtkPlusPhantomLinearObjectRegistrationAlgo)
int GetNumberOfReferences()