7 #include "PlusConfigure.h" 13 #include "vtkMatrix4x4.h" 14 #include "vtkMultiThreader.h" 15 #include "vtkObjectFactory.h" 17 #include "vtkTransform.h" 18 #include "vtkXMLDataElement.h" 19 #include "vtksys/SystemTools.hxx" 27 #include <Smart32Interface.h> 34 this->MeasurementTool = NULL;
39 this->ConoProbe = NULL;
40 this->LensOriginAlignment[0] = 1.0;
41 this->LensOriginAlignment[1] = 1.0;
42 this->LensOriginAlignment[2] = 1.0;
43 this->LensOriginAlignment[3] = 1.0;
44 this->LensOriginAlignment[4] = 1.0;
45 this->LensOriginAlignment[5] = 1.0;
46 this->DelayBetweenMeasurements = 1;
48 this->CoarseLaserPower = 13;
49 this->FineLaserPower = 0;
50 this->ProbeDialogOpen =
false;
54 this->Thread = vtkMultiThreader::New();
66 this->Thread->Delete();
69 this->MeasurementTool = NULL;
72 ISmart::Destroy(this->ConoProbe);
73 this->ConoProbe = NULL;
86 LOG_TRACE(
"vtkPlusOptimetConoProbeMeasurer::Connect" );
88 this->ConoProbe = ISmart::Create();
92 this->ConoProbe->Init(0x01020304, 0x01020309, 10000);
94 catch (
const SmartException& e)
96 LOG_ERROR(e.ErrorString());
103 this->ConoProbe->SetAcquisitionParams(AcquisitionMode::TimeAcquisitionMode, this->Frequency, this->CalculateCompositeLaserPower(this->CoarseLaserPower, this->FineLaserPower), this->DelayBetweenMeasurements);
104 this->
SetLaserPower(this->CalculateCompositeLaserPower(this->CoarseLaserPower, this->FineLaserPower));
106 catch (
const SmartException& e)
108 LOG_ERROR(e.ErrorString());
112 this->MeasurementTool = NULL;
115 LOG_DEBUG(
"Successfully connected to ConoProbe device");
122 LOG_TRACE(
"vtkPlusOptimetConoProbeMeasurer::InternalDisconnect" );
123 this->MeasurementTool = NULL;
126 ISmart::Destroy(this->ConoProbe);
127 this->ConoProbe = NULL;
135 LOG_TRACE(
"vtkPlusOptimetConoProbeMeasurer::InternalUpdate" );
137 if (this->MeasurementTool != NULL)
139 vtkSmartPointer<vtkTransform> measurementToMeasurerTransform = vtkSmartPointer<vtkTransform>::New();
140 vtkSmartPointer<vtkTransform> parametersToMeasurerTransform = vtkSmartPointer<vtkTransform>::New();
142 if (!this->ProbeDialogOpen)
144 Measurement measurement;
148 measurement = this->ConoProbe->GetSingleMeasurement();
150 catch (
const SmartException& e)
152 LOG_ERROR(e.ErrorString());
155 catch (
const SmartExceptionBadResponse& e)
157 LOG_WARNING(e.MessageType());
161 double d = measurement.Distance;
162 double snr = measurement.Snr / 10;
163 double total = measurement.Total;
164 double dx = this->LensOriginAlignment[0];
165 double dy = this->LensOriginAlignment[1];
166 double dz = this->LensOriginAlignment[2];
167 double lx = this->LensOriginAlignment[3];
168 double ly = this->LensOriginAlignment[4];
169 double lz = this->LensOriginAlignment[5];
172 measurementToMeasurerTransform->Translate(dx * d + lx, dy * d + ly, dz * d + lz);
173 double params[16]{ d, snr, total, 0.0,
174 this->Frequency, this->LaserPower, 0.0, 0.0,
176 0.0, 0.0, 0.0, 0.0, };
177 parametersToMeasurerTransform->SetMatrix(params);
181 measurementToMeasurerTransform->Identity();
182 parametersToMeasurerTransform->Identity();
186 unsigned long frameNumber = this->MeasurementTool->GetFrameNumber() + 1 ;
187 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
191 this->
ToolTimeStampedUpdate(name.GetTransformName().c_str(), measurementToMeasurerTransform->GetMatrix(), ToolStatus::TOOL_OK, frameNumber, unfilteredTimestamp);
193 this->
ToolTimeStampedUpdate(parameters.GetTransformName().c_str(), parametersToMeasurerTransform->GetMatrix(), ToolStatus::TOOL_OK, frameNumber, unfilteredTimestamp);
204 double lensOriginAlignment[6];
205 if (deviceConfig->GetVectorAttribute(
"LensOriginAlignment", 6, lensOriginAlignment))
208 this->LensOriginAlignment[0] = lensOriginAlignment[0];
209 this->LensOriginAlignment[1] = lensOriginAlignment[1];
210 this->LensOriginAlignment[2] = lensOriginAlignment[2];
211 this->LensOriginAlignment[3] = lensOriginAlignment[3];
212 this->LensOriginAlignment[4] = lensOriginAlignment[4];
213 this->LensOriginAlignment[5] = lensOriginAlignment[5];
217 int delayBetweenMeasurements = 0;
218 if ( deviceConfig->GetScalarAttribute(
"DelayBetweenMeasurements", delayBetweenMeasurements ) )
221 this->DelayBetweenMeasurements = static_cast<unsigned short>(delayBetweenMeasurements);
226 if ( deviceConfig->GetScalarAttribute(
"Frequency",
frequency ) )
229 this->Frequency = static_cast<unsigned short>(
frequency);
233 int coarseLaserPower = 0;
234 if ( deviceConfig->GetScalarAttribute(
"CoarseLaserPower", coarseLaserPower ) )
237 this->CoarseLaserPower = static_cast<unsigned short>(coarseLaserPower);
241 int fineLaserPower = 0;
242 if ( deviceConfig->GetScalarAttribute(
"FineLaserPower", fineLaserPower ) )
245 this->FineLaserPower = static_cast<unsigned short>(fineLaserPower);
257 deviceConfig->SetIntAttribute(
"DelayBetweenMeasurements", static_cast<unsigned int>(this->DelayBetweenMeasurements));
258 deviceConfig->SetIntAttribute(
"Frequency", static_cast<unsigned int>(this->Frequency));
259 deviceConfig->SetIntAttribute(
"CoarseLaserPower", static_cast<unsigned int>(this->CoarseLaserPower));
260 deviceConfig->SetIntAttribute(
"FineLaserPower", static_cast<unsigned int>(this->FineLaserPower));
268 if (this->ThreadID == 0)
272 this->ProbeDialogOpen =
true;
274 this->Thread->SpawnThread((vtkThreadFunctionType)&vtkPlusOptimetConoProbeMeasurer::ProbeDialogThread,
this);
282 if (this->ThreadID == 0)
285 this->ProbeDialogOpen =
false;
286 this->Thread->TerminateThread(0);
297 void* vtkPlusOptimetConoProbeMeasurer::ProbeDialogThread(
void* ptr)
299 vtkMultiThreader::ThreadInfo* vinfo = static_cast<vtkMultiThreader::ThreadInfo*>(ptr);
305 ZeroMemory(&
p,
sizeof (ProbeDialogParams));
306 ZeroMemory(&r,
sizeof (ProbeDialogResult));
310 p.Power = logic->CoarseLaserPower;
311 p.FinePower = logic->FineLaserPower;
312 p.Frequency = logic->Frequency;
315 bool okPressed = ISmart::ShowProbeDialog(&logic->ConoProbe, 1, &
p, &r);
317 logic->ConoProbe->SetAcquisitionParams(AcquisitionMode::TimeAcquisitionMode, logic->Frequency, logic->CalculateCompositeLaserPower(r.Power, r.FinePower), logic->DelayBetweenMeasurements);
318 logic->
SetLaserPower(logic->CalculateCompositeLaserPower(r.Power, r.FinePower));
327 unsigned short vtkPlusOptimetConoProbeMeasurer::CalculateCompositeLaserPower(UINT16 coarseLaserPower, UINT16 fineLaserPower)
329 unsigned short compositeLaserPower = coarseLaserPower;
330 compositeLaserPower <<= 6;
331 compositeLaserPower |= fineLaserPower;
332 return compositeLaserPower;
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
vtkStandardNewMacro(vtkPlusOptimetConoProbeMeasurer)
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
bool RequirePortNameInDeviceSetConfiguration
PlusStatus InternalConnect()
void PrintSelf(ostream &os, vtkIndent indent)
vtkPlusOptimetConoProbeMeasurer()
virtual PlusStatus InternalDisconnect()
PlusStatus GetToolByPortName(const char *aPortName, vtkPlusDataSource *&aSource)
~vtkPlusOptimetConoProbeMeasurer()
virtual void SetFrequency(UINT16)
PlusStatus InternalUpdate()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
virtual void SetLaserPower(UINT16)
bool StartThreadForInternalUpdates
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *config)
Interface for the Optimet ConoProbe This class talks with Optimet ConoProbe over the Optimet Smart32 ...
std::string GetToolReferenceFrameName() const
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *config)