41 #include <visp3/core/vpConfig.h>
48 #include <visp3/gui/vpDisplayD3D.h>
49 #include <visp3/gui/vpDisplayGDI.h>
50 #include <visp3/gui/vpDisplayGTK.h>
51 #include <visp3/gui/vpDisplayOpenCV.h>
52 #include <visp3/gui/vpDisplayX.h>
54 #include <visp3/io/vpParseArgv.h>
56 #include <visp3/core/vpColVector.h>
57 #include <visp3/core/vpHomogeneousMatrix.h>
58 #include <visp3/core/vpImage.h>
59 #include <visp3/core/vpMatrix.h>
60 #if defined(VISP_HAVE_DISPLAY)
61 #include <visp3/gui/vpPlot.h>
63 #include <visp3/core/vpRGBa.h>
65 #include <visp3/ustk_needle_modeling/usNeedleModelingDisplayTools.h>
66 #include <visp3/ustk_needle_modeling/usNeedleInsertionModelRayleighRitzSpline.h>
67 #include <visp3/ustk_needle_modeling/usTissueTranslationEstimatorUKF.h>
70 #define GETOPTARGS "hlt:cd"
72 typedef enum { vpX11, vpGTK, vpGDI, vpD3D, vpCV } vpDisplayType;
74 void usage(
const char *name,
const char *badparam, vpDisplayType &dtype);
75 bool getOptions(
int argc,
const char **argv, vpDisplayType &dtype,
bool &list,
bool &display);
87 void usage(
const char *name,
const char *badparam, vpDisplayType &dtype)
90 Tests the class usTissueTranslationEstimatorUKF.\n\
93 %s [-t <type of video device>] [-l] [-d] [-h]\n\
118 -t <type of video device> \"%s\"\n\
119 String specifying the video device to use.\n\
121 \"X11\": only on UNIX platforms,\n\
122 \"GTK\": on all plaforms,\n\
123 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
124 \"D3D\": only on Windows platform (Direct3D).\n\
125 \"CV\" : (OpenCV).\n\
128 Print the list of video-devices available and exit.\n\
131 Turn off the display.\n\
134 Print the help.\n\n",
display.c_str());
137 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
156 bool getOptions(
int argc,
const char **argv, vpDisplayType &dtype,
bool &list,
bool &display)
160 std::string sDisplayType;
161 while((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1)
170 sDisplayType = optarg_;
172 if(sDisplayType.compare(
"X11") == 0) dtype = vpX11;
173 else if (sDisplayType.compare(
"GTK") == 0) dtype = vpGTK;
174 else if (sDisplayType.compare(
"GDI") == 0) dtype = vpGDI;
175 else if (sDisplayType.compare(
"D3D") == 0) dtype = vpD3D;
176 else if (sDisplayType.compare(
"CV") == 0) dtype = vpCV;
180 usage(argv[0], NULL, dtype);
191 usage(argv[0], optarg_, dtype);
197 if((c == 1) || (c == -1))
200 usage(argv[0], NULL, dtype);
201 std::cerr <<
"ERROR: " << std::endl;
202 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
211 int main(
int argc,
const char **argv)
213 bool opt_list =
false;
214 vpDisplayType opt_dtype;
215 bool opt_display =
true;
218 #if defined VISP_HAVE_GTK
220 #elif defined VISP_HAVE_X11
222 #elif defined VISP_HAVE_GDI
224 #elif defined VISP_HAVE_D3D9
226 #elif defined VISP_HAVE_OPENCV
231 if(!getOptions(argc, argv, opt_dtype, opt_list, opt_display)) exit(-1);
235 unsigned nbDevices = 0;
236 std::cout <<
"List of video-devices available: \n";
237 #if defined VISP_HAVE_GTK
238 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
241 #if defined VISP_HAVE_X11
242 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
245 #if defined VISP_HAVE_GDI
246 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
249 #if defined VISP_HAVE_D3D9
250 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
253 #if defined VISP_HAVE_OPENCV
254 std::cout <<
" CV (use \"-t CV\" option to use it)\n";
258 std::cout <<
" No display is available\n";
263 vpImage<unsigned char> I1(700, 500, 255);
264 vpImage<vpRGBa> I2(700, 500, vpRGBa(255,255,255,255));
266 vpDisplay *display1 =
nullptr;
267 vpDisplay *display2 =
nullptr;
268 #if defined(VISP_HAVE_DISPLAY)
269 vpPlot *statePlot = NULL;
277 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
278 #if defined VISP_HAVE_X11
279 display1 =
new vpDisplayX;
280 display2 =
new vpDisplayX;
282 std::cout <<
" Sorry, X11 video device is not available.\n";
283 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
288 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
289 #if defined VISP_HAVE_GTK
290 display1 =
new vpDisplayGTK;
291 display2 =
new vpDisplayGTK;
293 std::cout <<
" Sorry, GTK video device is not available.\n";
294 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
299 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
300 #if defined VISP_HAVE_GDI
301 display1 =
new vpDisplayGDI;
302 display2 =
new vpDisplayGDI;
304 std::cout <<
" Sorry, GDI video device is not available.\n";
305 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
310 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
311 #if defined VISP_HAVE_D3D9
312 display1 =
new vpDisplayD3D;
313 display2 =
new vpDisplayD3D;
315 std::cout <<
" Sorry, D3D video device is not available.\n";
316 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
321 std::cout <<
"Requested OpenCV display functionnalities..." << std::endl;
322 #if defined(VISP_HAVE_OPENCV)
323 display1 =
new vpDisplayOpenCV;
324 display2 =
new vpDisplayOpenCV;
326 std::cout <<
" Sorry, OpenCV video device is not available.\n";
327 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
334 std::cout <<
"Start test testUsTissueTranslationEstimatorUKF" << std::endl;
336 const int nbNeedles = 6;
340 display1->init(I1, 0,0,
"XZ");
341 display2->init(I2, display1->getWindowXPosition()+display1->getWidth(), display1->getWindowYPosition(),
"YZ");
343 #if defined(VISP_HAVE_DISPLAY)
344 statePlot =
new vpPlot;
346 for(
int i=0 ; i<4 ; i++) statePlot->initGraph(i,1+nbNeedles);
347 statePlot->setTitle(0,
"Tissue position X");
348 statePlot->setTitle(1,
"Tissue position Y");
349 statePlot->setTitle(2,
"Tissue velocity X");
350 statePlot->setTitle(3,
"Tissue velocity Y");
351 statePlot->setLegend(0,0,
"Ref");
352 for(
int i=0 ; i<nbNeedles ; i++) statePlot->setLegend(0,i+1,[i](){std::ostringstream t;t<<i;return t.str();}());
366 for(
int i = 0 ; i<nbNeedles ; i++) needle[i].setStiffnessPerUnitLength(10000);
368 vpPoseVector needleInitialBasePose(0,0,-0.08, 0, 0, 0);
370 for(
int i = 0 ; i<nbNeedles ; i++) needle[i].setBasePose(needleInitialBasePose);
373 for(
int i = 0 ; i<nbNeedles ; i++) needle[i].setSurfaceAtTip();
375 double std_measure_position = 1e-3;
376 double std_measure_tip_direction = 1e-3;
377 double std_measure_force = 1e-3;
378 double std_measure_torque = 1e-3;
379 double std_process_position_only = 1e-3;
380 double std_process_position = 1e-6;
381 double std_process_velocity = 1e-4;
384 for(
int i=0 ; i<nbNeedles ; i++)
401 for(
int i=0 ; i<nbNeedles/2 ; i++)
405 P[0][0] = std_process_position*std_process_position;
406 P[1][1] = std_process_position*std_process_position;
407 P[3][3] = std_process_velocity*std_process_velocity;
408 P[4][4] = std_process_velocity*std_process_velocity;
415 P[0][0] = std_process_position_only*std_process_position_only;
416 P[1][1] = std_process_position_only*std_process_position_only;
421 for(
int i=0 ; i<nbNeedles ; i+=3)
429 for(
int i=0; i<50 ;i++)
431 for(
int i=0 ; i<nbNeedles ; i++) Kalman[i].setCurrentNeedle(needle[i]);
435 vpColVector baseControl(6,0);
436 baseControl[2] = 0.005;
437 baseControl[1] = 0.0005;
439 for(
int i=0 ; i<nbNeedles ; i++) needle[i].moveBase(baseControl, 1);
446 #if defined(VISP_HAVE_DISPLAY)
449 statePlot->plot(2,0, time, 0.001);
450 statePlot->plot(3,0, time, 0);
458 #if defined(VISP_HAVE_DISPLAY)
461 statePlot->plot(2,0, time, 0);
462 statePlot->plot(3,0, time, 0.001);
470 #if defined(VISP_HAVE_DISPLAY)
473 statePlot->plot(2,0, time, -0.002);
474 statePlot->plot(3,0, time, 0);
482 #if defined(VISP_HAVE_DISPLAY)
485 statePlot->plot(2,0, time, 0);
486 statePlot->plot(3,0, time, -0.002);
494 #if defined(VISP_HAVE_DISPLAY)
497 statePlot->plot(2,0, time, 0.001);
498 statePlot->plot(3,0, time, 0.001);
503 #if defined(VISP_HAVE_DISPLAY)
513 vpColVector CP(3*nbObs);
515 for(
int j=0 ; j<nbObs ; j++)
521 vpColVector tipMeasures(6);
527 for(
int i=0 ; i<nbNeedles ; i++) Kalman[i].setPropagationTime(1.);
529 for(
int i=0 ; i<nbNeedles ; i+=3)
532 Kalman[i+1].
filter(tipMeasures);
533 Kalman[i+2].
filter(baseForceMeasures);
536 for(
int i=0 ; i<nbNeedles ; i++)
544 vpDisplay::display(I1);
545 vpDisplay::display(I2);
548 for(
int i=0 ; i<nbNeedles ; i++)
552 #if defined(VISP_HAVE_DISPLAY)
553 statePlot->plot(0,1+i, time, needle[i].accessTissue().getPose()[0]);
554 statePlot->plot(1,1+i, time, needle[i].accessTissue().getPose()[1]);
557 #if defined(VISP_HAVE_DISPLAY)
558 for(
int i=0 ; i<nbNeedles/2 ; i++)
560 statePlot->plot(2,1+i, time, Kalman[i].getState()[3]);
561 statePlot->plot(3,1+i, time, Kalman[i].getState()[4]);
564 vpDisplay::flush(I1);
565 vpDisplay::flush(I2);
570 if (display1)
delete display1;
571 if (display2)
delete display2;
572 #if defined(VISP_HAVE_DISPLAY)
573 if (statePlot)
delete statePlot;
double getParametricLength() const
bool moveBase(const vpColVector &v, double time)
double getInsertionDepth() const
void loadPreset(const ModelPreset preset)
Parameters saving and loading.
bool setStiffnessPerUnitLength(int i, double K)
bool setBasePose(const vpPoseVector &p)
The following methods should be redefined in the derived classes.
const usTissueModelSpline & accessTissue() const
Tissue parameters.
const usNeedleModelSpline & accessNeedle() const
Parameters setters and getters.
void setPathUpdateType(PathUpdateType type)
Model behavior.
virtual bool updateState()
void setSurfaceAtTip()
Control of the tissue.
vpColVector getTipDirection() const
vpColVector getTipPosition() const
vpColVector getBaseStaticTorsor() const
Force at base.
vpColVector getNeedlePoint(double l) const
Measure model information.
vpPoseVector getPose() const
bool move(const vpHomogeneousMatrix &H)
void setTissuePositionProcessNoiseVariance(double sigma)
void setStateDynamicsType(StateDynamicsType type)
void setPositionMeasureNoiseVariance(double sigma)
void setTipDirectionMeasureNoiseVariance(double sigma)
void setTorqueMeasureNoiseVariance(double sigma)
void setMeasureType(MeasureType type)
void applyStateToNeedle(usNeedleInsertionModelRayleighRitzSpline &needle) const
@ LATERAL_TRANSLATIONS_ONLY
void setTissueVelocityProcessNoiseVariance(double sigma)
void setTissueTranslationType(TissueTranslationType type)
@ TIP_POSITION_AND_DIRECTION
void setForceMeasureNoiseVariance(double sigma)
void setSigmaPointSpreadThreshold(double threshold)
void setProcessNoiseType(NoiseType type)
void setStateCovarianceMatrix(const vpMatrix &mat)
void setMeasureNoiseType(NoiseType type)
bool filter(const vpColVector &measure)
void setSigmaPointScalingFactor(double factor)
void setSigmaPointGenerationType(SigmaPointGenerationType type)