Salome HOME
Mantis issue 0021191: GlueEdges and GlueFaces problem with tolerance 1. A fix by...
[modules/geom.git] / src / EntityGUI / EntityGUI_FeatureDetectorDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : EntityGUI_SketcherDlg.cxx
25 // Author : Renaud NEDELEC, Open CASCADE S.A.S.
26
27 #include "EntityGUI_FeatureDetectorDlg.h"
28 #include <ShapeRec_FeatureDetector.hxx>
29
30 #include <OCCViewer_ViewWindow.h>
31 #include <OCCViewer_ViewManager.h>
32
33 #include <SOCC_ViewModel.h>
34
35 #include <DlgRef.h>
36 #include <GeometryGUI.h>
37 #include <EntityGUI.h>
38 #include <GEOMBase.h>
39 #include <GEOM_Object.hxx>
40
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_ViewWindow.h>
45 #include <SalomeApp_Application.h>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
48
49 #include <SALOME_ListIteratorOfListIO.hxx>
50
51 #include <SalomeApp_Study.h>
52
53 #include <utilities.h>
54
55 #include <gp_Pnt.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Wire.hxx>
58
59 #include <BRepBuilderAPI_MakeVertex.hxx>
60 #include <BRepBuilderAPI_MakeFace.hxx>
61 #include <BRepBuilderAPI_MakePolygon.hxx>
62 #include <BRepBuilderAPI_Transform.hxx>
63
64 #include <AIS_TexturedShape.hxx>
65 #include <TCollection_AsciiString.hxx>
66 #include <StdSelect_DisplayMode.hxx>
67
68 #include <Graphic3d_MaterialAspect.hxx>
69
70 #include <Precision.hxx>
71
72 #include <set>
73 #include <utility>
74
75 #include <boost/utility.hpp>
76
77 // Constructors
78 enum{
79   CONTOURS,
80   CORNERS,
81   LINES
82 };
83
84 enum {
85   RADIO_BUTTONS,
86   MSG,
87   PUSH_BUTTON,
88 };
89
90 // // // View
91 // // enum {
92 // //   XY,
93 // //   YZ,
94 // //   XZ
95 // // };
96   
97
98 //=================================================================================
99 // class    : EntityGUI_FeatureDetectorDlg()
100 // purpose  : Constructs a EntityGUI_FeatureDetectorDlg which is a child of 'parent', with the
101 //            name 'name' and widget flags set to 'f'.
102 //            The dialog will by default be modeless, unless you set 'modal' to
103 //            TRUE to construct a modal dialog.
104 //=================================================================================
105 EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
106                                               bool modal, Qt::WindowFlags fl)
107   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl) 
108 {
109   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
110   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_DUMP")));
111
112   setWindowTitle(tr("GEOM_DETECT_TITLE"));
113   
114   /***************************************************************/
115   
116   mainFrame()->GroupConstructors->setTitle(tr("GEOM_FEATURES"));
117   mainFrame()->RadioButton1->setText(tr("GEOM_CONTOURS"));
118   mainFrame()->RadioButton2->setText(tr("GEOM_CORNERS"));
119   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
120   mainFrame()->RadioButton3->close();
121   
122 //   myViewGroup = new DlgRef_3Radio(centralWidget());
123 //   myViewGroup->GroupBox1->setTitle(tr("GEOM_VIEW"));
124 //   myViewGroup->RadioButton1->setText(tr( "GEOM_TOP"  ));
125 //   myViewGroup->RadioButton2->setText(tr( "GEOM_FRONT"));
126 //   myViewGroup->RadioButton3->setText(tr( "GEOM_LEFT" ));
127 //   myViewButtonGroup = new QButtonGroup( this );
128 //   myViewButtonGroup->addButton( myViewGroup->RadioButton1, XY ); // Top view
129 //   myViewButtonGroup->addButton( myViewGroup->RadioButton2, YZ ); // Front View
130 //   myViewButtonGroup->addButton( myViewGroup->RadioButton3, XZ ); // Left View
131 //   
132 //   myViewGroup->hide();
133   
134   // Widgets for the selection of the picture and the Region Of Interest 
135   
136   
137   mySelectionGroup = new DlgRef_1Sel1Frame(centralWidget());
138
139   mySelectionGroup->PushButton1->setIcon(image0);
140   mySelectionGroup->PushButton1->setCheckable(true);
141   mySelectionGroup->PushButton1->setAutoExclusive(true);
142   
143   mySelectionGroup->PushButton2->setIcon(image1);
144   mySelectionGroup->PushButton2->setCheckable(true);
145   mySelectionGroup->PushButton2->setAutoExclusive(true);
146
147   mySelectionGroup->TextLabel1->setText(tr( "GEOM_PICTURE" ));
148   mySelectionGroup->FrameLabel->setText("");
149   
150   myOutputGroup = new DlgRef_3Radio(centralWidget());
151   myOutputGroup->GroupBox1->setTitle(tr("GEOM_DETECT_OUTPUT"));
152   myOutputGroup->RadioButton2->setText(tr( "GEOM_POLYLINE"  ));
153   myOutputGroup->RadioButton1->setText(tr( "GEOM_SPLINE"));
154   myOutputGroup->RadioButton3->hide();
155   
156 //   myOutputGroup->hide(); //caché pour la demo
157     
158   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
159   layout->setMargin(0); layout->setSpacing(6);
160 //   layout->addWidget( myViewGroup);
161   layout->addWidget( mySelectionGroup);
162   layout->addWidget( myOutputGroup);
163   
164 //   mainFrame()->GroupBoxName->hide();
165   
166   // Build an instance of detection used to perform image processing operations
167   aDetector = new ShapeRec_FeatureDetector();
168   
169   Init();
170   
171 }
172
173 //=================================================================================
174 // function : ~EntityGUI_FeatureDetectorDlg()
175 // purpose  : Destroys the object and frees any allocated resources
176 //=================================================================================
177 EntityGUI_FeatureDetectorDlg::~EntityGUI_FeatureDetectorDlg()
178 {
179   
180 }
181
182 //=================================================================================
183 // function : Init()
184 // purpose  :
185 //=================================================================================
186 void EntityGUI_FeatureDetectorDlg::Init()
187 {
188   connect( myGeomGUI,         SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
189   connect( buttonOk(),        SIGNAL( clicked() ),               this, SLOT( ClickOnOk() ) );
190   connect( buttonApply(),     SIGNAL( clicked() ),               this, SLOT( ClickOnApply() ) );
191   connect( this,              SIGNAL(constructorsClicked(int)),  this, SLOT(ConstructorsClicked(int))); 
192   connect( mySelectionGroup->PushButton2,      SIGNAL( clicked() ),               this, SLOT( onButtonClicked() ) );
193   connect( mySelectionGroup->PushButton1,       SIGNAL( clicked() ),               this, SLOT( onButtonClicked() ) );  
194 //   connect( myViewButtonGroup, SIGNAL( buttonClicked( int ) ),    this, SLOT( onViewClicked( int ) ) );
195   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),this, SLOT( SelectionIntoArgument() ) );
196   
197   myConstructorId = 0;
198   mySelectionGroup->PushButton1->click();
199   
200 //   SetEditCurrentArgument();
201   SelectionIntoArgument();
202   
203   initName(tr("GEOM_CONTOURS")); 
204   resize(100,100);
205   
206 //   myViewGroup->RadioButton1->setChecked(true);
207   myOutputGroup->RadioButton1->setChecked(true);
208   
209   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
210   gp_Dir aDirZ = gp_Dir(0, 0, 1);
211   gp_Dir aDirX = gp_Dir(1, 0, 0);
212   
213   aGlobalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
214   
215   myStartPnt = gp_Pnt(0,0,0);
216   myEndPnt = myStartPnt;
217   
218   myGeomGUI->SetWorkingPlane( aGlobalCS );
219   myGeomGUI->ActiveWorkingPlane();
220   
221   ConstructorsClicked(myConstructorId);
222 }
223
224 //=================================================================================
225 // function : SelectionIntoArgument()
226 // purpose  : Called when selection as changed or other case
227 //=================================================================================
228 void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
229 {
230   
231   // TODO supprimer les lignes qui ne servent Ã  rien le cas Ã©chéant
232   SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
233   std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
234   SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel());
235
236   if (!myEditCurrentArgument->isEnabled())
237     return;
238   
239   myEditCurrentArgument->setText( "" );
240
241   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
242   SALOME_ListIO aSelList;
243   aSelMgr->selectedObjects(aSelList);
244   SALOME_ListIteratorOfListIO anIt( aSelList );
245   
246   for( ; anIt.More(); anIt.Next() )
247     if( !anIt.Value().IsNull() )
248     {
249       myFaceEntry = anIt.Value()->getEntry();
250     }
251
252   if (aSelList.Extent() != 1) {
253     if (myEditCurrentArgument == mySelectionGroup->LineEdit1) 
254       myFace.nullify();
255     return;
256   }
257
258   TopAbs_ShapeEnum aNeedType = TopAbs_FACE ;
259   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
260   TopoDS_Shape aShape;
261   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
262     QString aName = GEOMBase::GetName( aSelectedObject.get() );
263     myEditCurrentArgument->setText( aName );
264     
265     if ( myEditCurrentArgument == mySelectionGroup->LineEdit1 ) {
266       myFace = aSelectedObject;
267       AISit = soccViewer->entry2aisobjects.find(myFaceEntry.toStdString());
268       if (AISit == soccViewer->entry2aisobjects.end())
269         return;
270       
271       Handle(AIS_InteractiveObject) myAIS = (*AISit).second[0];
272       Handle(GEOM_AISShape) myAISShape;
273       if( myAIS->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
274         myAISShape = Handle(GEOM_AISShape)::DownCast( myAIS );
275       }
276       else
277         return ;
278       
279       std::string theImgFileName = myAISShape->TextureFile();      
280       if ( theImgFileName == "" )
281         return ;
282
283       // Setting the image caracteristics
284       aDetector->SetPath( theImgFileName );
285       height            =  aDetector->GetImgHeight();
286       width             =  aDetector->GetImgWidth();
287       pictureLeft       = -0.5 * width;              // X coordinate of the top left  corner of the background image in the view
288       pictureTop        =  0.5 * height;             // Y coordinate of both top corners
289       
290     } 
291   }
292   
293 }
294
295 //=================================================================================
296 // function : acceptMouseEvent()
297 // purpose  :
298 //=================================================================================
299 bool EntityGUI_FeatureDetectorDlg::acceptMouseEvent() const
300
301   return mySelectionGroup->PushButton2->isChecked();  
302 }
303
304 //=======================================================================
305 // function : ClickOnOk()
306 // purpose  :
307 //=======================================================================
308 void EntityGUI_FeatureDetectorDlg::ClickOnOk()
309 {
310   setIsApplyAndClose( true );
311   if (onAccept())
312     ClickOnCancel();
313 }
314
315 //=================================================================================
316 // function : ClickOnApply()
317 // purpose  :
318 //=================================================================================
319 bool EntityGUI_FeatureDetectorDlg::ClickOnApply()
320 {
321   if (!onAccept())
322     return false;
323
324 //   initName();
325   ConstructorsClicked(getConstructorId());
326   return true;
327 }
328
329 //=================================================================================
330 // function : onConstructorClicked(int)
331 // purpose  :
332 //=================================================================================
333 void EntityGUI_FeatureDetectorDlg::ConstructorsClicked(int id)
334 {
335   MESSAGE("Constructor id ="<<id)
336   myConstructorId = id;
337   switch (id)
338   {
339     case CORNERS:
340 //       myViewGroup->show();
341 //       mySelectionGroup->show();
342       myOutputGroup->hide();
343 //       mySelectionGroup->TextLabel2->setText(tr("GEOM_DETECT_ZONE"));
344       mySelectionGroup->TextLabel2->hide();
345       mySelectionGroup->Frame->hide();
346       mySelectionGroup->PushButton2->hide();
347       initName(tr("GEOM_CORNERS"));
348       break;
349     case CONTOURS:
350 //       myViewGroup->hide();
351 //       mySelectionGroup->hide();
352 //       mySelectionGroup->show();
353       myOutputGroup->show();
354       mySelectionGroup->TextLabel2->show();
355       mySelectionGroup->Frame->show();
356       mySelectionGroup->PushButton2->show();
357       mySelectionGroup->TextLabel2->setText(tr("GEOM_COLOR_FILTER"));
358       initName(tr("GEOM_CONTOURS"));
359       break;
360     case LINES:
361 //       myViewGroup->hide();
362 //       mySelectionGroup->hide();
363 //       mySelectionGroup->show();
364       myOutputGroup->hide();
365       mySelectionGroup->TextLabel2->setText(tr(""));
366       initName(tr("GEOM_LINES"));
367       break;
368   }
369 }
370
371 // //=================================================================================
372 // // function : onViewClicked()
373 // // purpose  :
374 // //=================================================================================
375 // void EntityGUI_FeatureDetectorDlg::onViewClicked(int id)
376 // {
377 //   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
378 //   gp_Dir aDirZ;
379 //   gp_Dir aDirX;
380 //   
381 //   switch(id)
382 //   {
383 //     case XY:
384 //         aDirZ = gp_Dir(0, 0, 1);
385 //         aDirX = gp_Dir(1, 0, 0);
386 //       break;
387 //     case YZ:
388 //         aDirZ = gp_Dir(1, 0, 0);
389 //         aDirX = gp_Dir(0, 1, 0);
390 //       break;
391 //     case XZ:
392 //         aDirZ = gp_Dir(0, -1, 0);
393 //         aDirX = gp_Dir(1, 0 , 0);
394 //       break;
395 //   }
396 //   
397 //   myWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
398 //   myGeomGUI->SetWorkingPlane( myWPlane );
399 //   myGeomGUI->ActiveWorkingPlane();
400 //   
401 // }
402
403 //=================================================================================
404 // function : onButtonClicked()
405 // purpose  :
406 //=================================================================================
407 void EntityGUI_FeatureDetectorDlg::onButtonClicked()
408 {
409   QPushButton* send = (QPushButton*)sender();
410   if (send == mySelectionGroup->PushButton2)
411   {
412     mySelectionGroup->LineEdit1->setEnabled(false);
413   }
414   else if (send == mySelectionGroup->PushButton1)
415   {
416     myStartPnt = gp_Pnt(0,0,0);
417     myEndPnt   = myStartPnt;
418     myEditCurrentArgument = mySelectionGroup->LineEdit1;
419     mySelectionGroup->LineEdit1->setEnabled(true);   
420   }
421 }
422
423 //=================================================================================
424 // function : setStartPnt( const QPoint& )
425 // purpose  :
426 //=================================================================================
427 void EntityGUI_FeatureDetectorDlg::setStartPnt(const gp_Pnt& theStartPnt)
428 {
429   myStartPnt = theStartPnt;
430   MESSAGE("myStartPnt = ("<<theStartPnt.X()<<", "<<theStartPnt.Y()<<")")
431 }
432
433 //=================================================================================
434 // function : setEndPnt( const QPoint& )
435 // purpose  :
436 //=================================================================================
437 void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt)
438 {
439   myEndPnt = theEndPnt;
440   MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
441   if (setSelectionRect())
442     showImageSample();
443 }
444
445 //=================================================================================
446 // function : setSelectionRect()
447 // purpose  :
448 //=================================================================================
449 bool EntityGUI_FeatureDetectorDlg::setSelectionRect()
450
451   // Set detection rectangle in the background image coordinates system
452   QPoint topLeft     = QPoint(myStartPnt.X() - pictureLeft, pictureTop - myStartPnt.Y());
453   QPoint bottomRight = QPoint(myEndPnt.X()   - pictureLeft, pictureTop - myEndPnt.Y());
454   myRect = QRect(topLeft, bottomRight);
455   
456   return (!myRect.isEmpty() && myRect.width() > 1);
457 }
458
459 //=================================================================================
460 // function : showImageSample()
461 // purpose  : Display a preview of the image sample selected by the user
462 //=================================================================================
463 void EntityGUI_FeatureDetectorDlg::showImageSample()
464
465   // Cropp the image to the selection rectangle given by the user
466   aDetector->SetROI( myRect ); 
467   std::string samplePicturePath = aDetector->CroppImage();
468   
469   // Display the result
470   QPixmap pixmap(QString(samplePicturePath.c_str()));
471   mySelectionGroup->FrameLabel->setPixmap(pixmap);
472   mySelectionGroup->FrameLabel->setMask(pixmap.mask());
473 }
474
475 //=================================================================================
476 // function : createOperation
477 // purpose  :
478 //=================================================================================
479 GEOM::GEOM_IOperations_ptr EntityGUI_FeatureDetectorDlg::createOperation()
480 {
481   return myGeomGUI->GetGeomGen()->GetIShapesOperations( getStudyId() );
482 }
483
484 //=================================================================================
485 // function : execute()
486 // purpose  :
487 //=================================================================================
488 bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
489 {
490   bool res = false;
491   
492   GEOM::GEOM_IBasicOperations_var  aBasicOperations  = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
493   GEOM::GEOM_IShapesOperations_var aShapesOperations = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
494   
495   if (myConstructorId == CORNERS)
496   {
497     double subPictureLeft;
498     double subPictureTop;
499     if( !myRect.isEmpty() )
500     {
501       aDetector->SetROI( myRect );
502       subPictureLeft    = myStartPnt.X();                
503       subPictureTop     = myStartPnt.Y();
504     }
505     else
506     {
507       subPictureLeft    = pictureLeft;
508       subPictureTop     = pictureTop;
509     }
510     aDetector->ComputeCorners();
511     CvPoint2D32f* corners     = aDetector->GetCorners();
512     int cornerCount           = aDetector->GetCornerCount();
513     int i;
514     
515     // Build the geom objects associated to the detected corners and returned by execute   
516     if( !aBasicOperations->_is_nil() && !aShapesOperations->_is_nil() ) 
517     {
518       GEOM::GEOM_Object_var  aGeomCorner;
519       GEOM::ListOfGO_var     geomCorners = new GEOM::ListOfGO();
520       geomCorners->length( cornerCount );
521       for (i = 0; i < cornerCount; i++)
522       {
523         double x = subPictureLeft + corners[i].x;
524         double y = subPictureTop  - corners[i].y;
525         double z =  0;
526         
527         aGeomCorner = aBasicOperations->MakePointXYZ( x,y,z );
528         
529         geomCorners[i] = aGeomCorner;  
530       } 
531       GEOM::GEOM_Object_var aCompound = aShapesOperations->MakeCompound(geomCorners);    
532       if ( !aCompound->_is_nil() )
533       {
534         // Dark blue color
535         SALOMEDS::Color aColor;
536         aColor.R = 0;
537         aColor.G = 0;
538         aColor.B = 0.8;
539         
540         aCompound->SetColor(aColor);
541         aCompound->SetMarkerStd(GEOM::MT_POINT,GEOM::MS_30);
542         objects.push_back( aCompound._retn() );
543         res = true;
544       }
545     }
546   }
547   else if (myConstructorId == CONTOURS)
548   {
549     int method = 0 ; //CANNY
550     if( !myRect.isEmpty() && myRect.width() > 1 )
551     {
552       aDetector->SetROI( myRect );
553       method = 1 ; //COLORFILTER    
554     }
555     
556     GEOM::GEOM_ICurvesOperations_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
557     
558     aDetector->ComputeContours( method );
559     std::vector< std::vector<cv::Point> >   contours  = aDetector->GetContours();
560     std::vector<cv::Vec4i>                  hierarchy = aDetector->GetContoursHierarchy();
561     
562     std::vector< cv::Point >                contour;
563     int idx = 0;
564     
565     GEOM::ListOfGO_var                      geomContours = new GEOM::ListOfGO();
566     int contourCount = 0;
567     
568     bool insert;
569     
570     MESSAGE("hierarchy.size() =" << hierarchy.size()) 
571     for( ; idx >= 0; idx = hierarchy[idx][0])
572     {
573 //       for(int count=0, child=idx; child>=0, count<1; child=hierarchy[idx][2], count++)
574 //       {     
575 //         contour = contours[child];
576         contour = contours[idx];
577         std::vector< cv::Point >::iterator it;
578         std::vector< cv::Point >::iterator it_previous;
579         std::vector< cv::Point >::iterator it_next;
580         GEOM::GEOM_Object_var  aGeomContourPnt;
581         GEOM::ListOfGO_var     geomContourPnts = new GEOM::ListOfGO();
582        
583         geomContourPnts->length( contour.size() );
584
585         int j = 0;
586         std::set< std::vector<int> > existing_points;
587         std::pair< std::set< std::vector<int> >::iterator,bool > pnt_it;
588         for ( it=contour.begin() ; it < contour.end(); it++ )
589         {
590           int pnt_array[] = {it->x,it->y};     
591           std::vector<int> pnt (pnt_array, pnt_array + sizeof(pnt_array) / sizeof(int) );
592
593           pnt_it=existing_points.insert(pnt);
594           if (pnt_it.second == true)         // To avoid double points in the contours
595           {
596             insert = true;
597             if (it!=contour.begin())         // From the second point on perform some checking to avoid loops in the contours we build
598             {
599               it_previous = boost::prior(it);
600               it_next = boost::next(it);
601               
602               double u_v_scalar_product = (it->x - it_previous->x) * (it_next->x - it->x) + 
603                                           (it->y - it_previous->y) * (it_next->y - it->y);                                       
604               if (u_v_scalar_product < 0)
605               {
606                 double u_v_det = (it->x - it_previous->x) * (it_next->y - it->y) - 
607                                  (it->y - it_previous->y) * (it_next->x - it->x);
608                                           
609                 double norme_u = sqrt ( (it->x - it_previous->x)*(it->x - it_previous->x) +
610                                         (it->y - it_previous->y)*(it->y - it_previous->y) );
611                 
612                 double norme_v = sqrt ( (it->x - it_next->x)*(it->x - it_next->x) +
613                                         (it->y - it_next->y)*(it->y - it_next->y) );
614                                                                                                 
615                 double u_v_sinus = u_v_det / (norme_u * norme_v);
616                 
617                 if (fabs(u_v_sinus) < Precision::Confusion())
618                 { 
619                   insert = false;
620                 }                         
621               }
622             }
623             double x = -0.5 *width  + it->x;
624             double y =  0.5 *height - it->y;
625             double z =  0;
626             if (insert)
627             {
628               aGeomContourPnt    = aBasicOperations->MakePointXYZ( x,y,z );
629               geomContourPnts->length( j+1 );
630               geomContourPnts[j] = aGeomContourPnt;
631               j++;
632             }
633           }
634         }
635         
636         GEOM::GEOM_Object_var aWire;
637         if(myOutputGroup->RadioButton2->isChecked())
638         {
639           aWire = aCurveOperations->MakePolyline(geomContourPnts.in(), false);
640         }
641         else if(myOutputGroup->RadioButton1->isChecked())
642         {
643           aWire = aCurveOperations->MakeSplineInterpolation(geomContourPnts.in(), /*closed =*/ false, /*reordering =*/ false);
644         }
645         else
646           return res;
647         
648         if ( !aWire->_is_nil() )
649         {
650           geomContours->length(contourCount + 1);
651           geomContours[contourCount] = aWire;
652           contourCount++;
653         }
654 //       }
655     }
656     GEOM::GEOM_Object_var aContoursCompound = aShapesOperations->MakeCompound(geomContours);
657     if ( !aContoursCompound->_is_nil() )
658     {
659       objects.push_back( aContoursCompound._retn() );
660     }
661     res=true;
662   }
663   
664   // TEST not very conclusive
665   
666 //   else if(myConstructorId ==LINES)
667 //   {
668 //     aDetector->ComputeLines();
669 //     std::vector<cv::Vec4i>  lines = aDetector->GetLines();
670 //     GEOM::GEOM_Object_var  Pnt1;
671 //     GEOM::GEOM_Object_var  Pnt2;
672 //     GEOM::GEOM_Object_var  aLine;
673 //     
674 //     GEOM::ListOfGO_var     geomLines = new GEOM::ListOfGO();
675 //     int linesCount=0;
676 //     for( int i = 0; i < lines.size(); i++ )
677 //     {
678 //       Pnt1 = aBasicOperations->MakePointXYZ( -0.5 *width + lines[i][0], 0.5 *height - lines[i][1], 0 );
679 //       Pnt2 = aBasicOperations->MakePointXYZ( -0.5 *width + lines[i][2], 0.5 *height - lines[i][3], 0 );
680 //       aLine = aBasicOperations->MakeLineTwoPnt( Pnt1, Pnt2 );
681 //       if ( !aLine->_is_nil() )
682 //       {
683 //         geomLines->length(linesCount + 1);
684 //         geomLines[linesCount] = aLine;
685 //         linesCount++;
686 //       }
687 //     }
688 //     GEOM::GEOM_Object_var aLinesCompound = aShapesOperations->MakeCompound(geomLines);
689 //     if ( !aLinesCompound->_is_nil() )
690 //     {
691 //       objects.push_back( aLinesCompound._retn() );
692 //     }
693 // 
694 //     res=true;
695 //   }
696   
697   return res;
698 }