]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx
Salome HOME
rnc: tiny modifications
[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
29 #include <OCCViewer_ViewWindow.h>
30 #include <OCCViewer_ViewManager.h>
31
32 #include <SOCC_ViewModel.h>
33
34 #include <DlgRef.h>
35 #include <GeometryGUI.h>
36 #include <EntityGUI.h>
37 #include <GEOMBase.h>
38 #include <GEOM_Object.hxx>
39 #include <ShapeRec_FeatureDetector.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("OCCViewer", tr("ICON_OCCVIEWER_VIEW_DUMP")));
110   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
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   mySelectionGroup = new QGroupBox(tr("GEOM_DETECT"), centralWidget());
135   QGridLayout* mySelectGrpLayout = new QGridLayout(mySelectionGroup);
136   myPushButton = new QPushButton(mySelectionGroup);
137   myPushButton->setIcon(image0);
138   myPushButton->setCheckable(true);
139   
140   mySelButton = new QPushButton(mySelectionGroup);
141   mySelButton->setIcon(image1);
142   myLineEdit = new QLineEdit(mySelectionGroup);
143   
144   mySnapshotLabel = new QLabel(mySelectionGroup);
145   mySelectGrpLayout->addWidget(myLineEdit,      0, 1);
146   mySelectGrpLayout->addWidget(mySelButton,     0, 0);
147   mySelectGrpLayout->addWidget(mySnapshotLabel, 1, 1);
148   mySelectGrpLayout->addWidget(myPushButton,    1, 0);
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   Init();
167   
168 }
169
170 //=================================================================================
171 // function : ~EntityGUI_FeatureDetectorDlg()
172 // purpose  : Destroys the object and frees any allocated resources
173 //=================================================================================
174 EntityGUI_FeatureDetectorDlg::~EntityGUI_FeatureDetectorDlg()
175 {
176   
177 }
178
179 //=================================================================================
180 // function : Init()
181 // purpose  :
182 //=================================================================================
183 void EntityGUI_FeatureDetectorDlg::Init()
184 {
185   connect( myGeomGUI,         SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
186   connect( buttonOk(),        SIGNAL( clicked() ),               this, SLOT( ClickOnOk() ) );
187   connect( buttonApply(),     SIGNAL( clicked() ),               this, SLOT( ClickOnApply() ) );
188  
189   connect( this,              SIGNAL(constructorsClicked(int)),  this, SLOT(ConstructorsClicked(int)));
190   
191   connect( myPushButton,      SIGNAL( toggled( bool ) ),         this, SLOT( onButtonToggled( bool ) ) );
192   connect( mySelButton,       SIGNAL( clicked() ),               this, SLOT( SetEditCurrentArgument() ) );
193   
194 //   connect( myViewButtonGroup, SIGNAL( buttonClicked( int ) ),    this, SLOT( onViewClicked( int ) ) );
195   
196   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),this, SLOT( SelectionIntoArgument() ) );
197   
198   myConstructorId = 0;
199   
200   mySelButton->click();
201   mySelButton->setDown(true);
202   
203 //   SetEditCurrentArgument();
204   SelectionIntoArgument();
205   
206   initName(tr("GEOM_CONTOURS")); 
207   resize(100,100);
208   
209 //   myViewGroup->RadioButton1->setChecked(true);
210   myOutputGroup->RadioButton1->setChecked(true);
211   
212   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
213   gp_Dir aDirZ = gp_Dir(0, 0, 1);
214   gp_Dir aDirX = gp_Dir(1, 0, 0);
215   
216   aGlobalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
217   
218   myStartPnt = gp_Pnt(0,0,0);
219   myEndPnt = myStartPnt;
220   
221   myGeomGUI->SetWorkingPlane( aGlobalCS );
222   myGeomGUI->ActiveWorkingPlane();
223   
224   ConstructorsClicked(myConstructorId);
225 }
226
227 //=================================================================================
228 // function : SetEditCurrentArgument()
229 // purpose  :
230 //=================================================================================
231 void EntityGUI_FeatureDetectorDlg::SetEditCurrentArgument()
232 {
233   QPushButton* send = (QPushButton*)sender();
234   if ( send == mySelButton ) { 
235     myEditCurrentArgument = myLineEdit;
236     myLineEdit->setEnabled(true);
237   }
238   else 
239     myLineEdit->setEnabled(false);
240   send->setDown(true);
241 }
242
243 //=================================================================================
244 // function : SelectionIntoArgument()
245 // purpose  : Called when selection as changed or other case
246 //=================================================================================
247 void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
248 {
249   if (!myEditCurrentArgument->isEnabled())
250     return;
251   
252   myEditCurrentArgument->setText( "" );
253
254   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
255   SALOME_ListIO aSelList;
256   aSelMgr->selectedObjects(aSelList);
257   SALOME_ListIteratorOfListIO anIt( aSelList );
258   for( ; anIt.More(); anIt.Next() )
259     if( !anIt.Value().IsNull() )
260     {
261       myFaceEntry = anIt.Value()->getEntry();
262     }
263
264   if (aSelList.Extent() != 1) {
265     if (myEditCurrentArgument == myLineEdit) 
266       myFace.nullify();
267     return;
268   }
269
270   TopAbs_ShapeEnum aNeedType = TopAbs_FACE ;
271   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
272   TopoDS_Shape aShape;
273   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
274     QString aName = GEOMBase::GetName( aSelectedObject.get() );
275     myEditCurrentArgument->setText( aName );
276     if ( myEditCurrentArgument == myLineEdit ) {
277       myFace = aSelectedObject;
278     } 
279   }
280 }
281
282 //=================================================================================
283 // function : acceptMouseEvent()
284 // purpose  :
285 //=================================================================================
286 bool EntityGUI_FeatureDetectorDlg::acceptMouseEvent() const
287
288   return myPushButton->isChecked();  
289 }
290
291 //=======================================================================
292 // function : ClickOnOk()
293 // purpose  :
294 //=======================================================================
295 void EntityGUI_FeatureDetectorDlg::ClickOnOk()
296 {
297   setIsApplyAndClose( true );
298   if (onAccept())
299     ClickOnCancel();
300 }
301
302 //=================================================================================
303 // function : ClickOnApply()
304 // purpose  :
305 //=================================================================================
306 bool EntityGUI_FeatureDetectorDlg::ClickOnApply()
307 {
308   if (!onAccept())
309     return false;
310
311 //   initName();
312   ConstructorsClicked(getConstructorId());
313   return true;
314 }
315
316 //=================================================================================
317 // function : onConstructorClicked(int)
318 // purpose  :
319 //=================================================================================
320 void EntityGUI_FeatureDetectorDlg::ConstructorsClicked(int id)
321 {
322   MESSAGE("Constructor id ="<<id)
323   myConstructorId = id;
324   switch (id)
325   {
326     case CORNERS:
327 //       myViewGroup->show();
328 //       mySelectionGroup->show();
329       myOutputGroup->hide();
330       mySnapshotLabel->setText(tr("GEOM_DETECT_ZONE"));
331       initName(tr("GEOM_CORNERS"));
332       break;
333     case CONTOURS:
334 //       myViewGroup->hide();
335 //       mySelectionGroup->hide();
336 //       mySelectionGroup->show();
337       myOutputGroup->show();
338       mySnapshotLabel->setText(tr("GEOM_COLOR_FILTER"));
339       initName(tr("GEOM_CONTOURS"));
340       break;
341     case LINES:
342 //       myViewGroup->hide();
343 //       mySelectionGroup->hide();
344 //       mySelectionGroup->show();
345       myOutputGroup->hide();
346       mySnapshotLabel->setText(tr(""));
347       initName(tr("GEOM_LINES"));
348       break;
349   }
350 }
351
352 // //=================================================================================
353 // // function : onViewClicked()
354 // // purpose  :
355 // //=================================================================================
356 // void EntityGUI_FeatureDetectorDlg::onViewClicked(int id)
357 // {
358 //   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
359 //   gp_Dir aDirZ;
360 //   gp_Dir aDirX;
361 //   
362 //   switch(id)
363 //   {
364 //     case XY:
365 //         aDirZ = gp_Dir(0, 0, 1);
366 //         aDirX = gp_Dir(1, 0, 0);
367 //       break;
368 //     case YZ:
369 //         aDirZ = gp_Dir(1, 0, 0);
370 //         aDirX = gp_Dir(0, 1, 0);
371 //       break;
372 //     case XZ:
373 //         aDirZ = gp_Dir(0, -1, 0);
374 //         aDirX = gp_Dir(1, 0 , 0);
375 //       break;
376 //   }
377 //   
378 //   myWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
379 //   myGeomGUI->SetWorkingPlane( myWPlane );
380 //   myGeomGUI->ActiveWorkingPlane();
381 //   
382 // }
383
384 //=================================================================================
385 // function : onButtonToggled()
386 // purpose  :
387 //=================================================================================
388 void EntityGUI_FeatureDetectorDlg::onButtonToggled( bool checked)
389 {
390   if (!checked)
391   {
392     myStartPnt = gp_Pnt(0,0,0);
393     myEndPnt = myStartPnt;
394     myLineEdit->setEnabled(true);
395   }
396   else
397   {
398     myLineEdit->setEnabled(false);
399   }
400 }
401
402 //=================================================================================
403 // function : setStartPnt( const QPoint& )
404 // purpose  :
405 //=================================================================================
406 void EntityGUI_FeatureDetectorDlg::setStartPnt(const gp_Pnt& theStartPnt)
407 {
408   myStartPnt = theStartPnt;
409   MESSAGE("myStartPnt = ("<<theStartPnt.X()<<", "<<theStartPnt.Y()<<")")
410 }
411
412 //=================================================================================
413 // function : setEndPnt( const QPoint& )
414 // purpose  :
415 //=================================================================================
416 void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt)
417 {
418   myEndPnt = theEndPnt;
419   MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
420 }
421
422 //=================================================================================
423 // function : createOperation
424 // purpose  :
425 //=================================================================================
426 GEOM::GEOM_IOperations_ptr EntityGUI_FeatureDetectorDlg::createOperation()
427 {
428   return myGeomGUI->GetGeomGen()->GetIShapesOperations( getStudyId() );
429 }
430
431 //=================================================================================
432 // function : execute()
433 // purpose  :
434 //=================================================================================
435 bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
436 {
437   bool res = false;
438   
439   SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
440   std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
441   SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel());
442   
443   AISit = soccViewer->entry2aisobjects.find(myFaceEntry.toStdString());
444   if (AISit == soccViewer->entry2aisobjects.end())
445     return res;
446   
447   Handle(AIS_InteractiveObject) myAIS = (*AISit).second[0];
448   Handle(GEOM_AISShape) myAISShape;
449   if( myAIS->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
450     myAISShape = Handle(GEOM_AISShape)::DownCast( myAIS );
451   }
452   else
453     return res;
454   
455   std::string theImgFileName = myAISShape->TextureFile();
456     
457   if ( theImgFileName == "" )
458     return res;
459   
460   // Build an instance of detection used to perform image processing operations
461   ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName );
462     
463   int height            =  aDetector->GetImgHeight();
464   int width             =  aDetector->GetImgWidth();
465   
466   // Operations to display the corners properly in the 3D scene
467   double pictureLeft  = -0.5 * width;   // X coordinate of the top left  corner of the background image in the view
468   double pictureTop   =  0.5 * height;  // Y coordinate of both top corners
469   
470   // Set detection rectangle in the background image coordinates system
471   QPoint topLeft     = QPoint(myStartPnt.X() - pictureLeft, pictureTop - myStartPnt.Y());
472   QPoint bottomRight = QPoint(myEndPnt.X()   - pictureLeft, pictureTop - myEndPnt.Y());
473   QRect aRect = QRect(topLeft, bottomRight);
474   
475   GEOM::GEOM_IBasicOperations_var  aBasicOperations  = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
476   GEOM::GEOM_IShapesOperations_var aShapesOperations = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
477   
478   if (myConstructorId == CORNERS)
479   {
480     if( !aRect.isEmpty() )
481     {
482       aDetector->SetROI( aRect );
483       pictureLeft  =  myStartPnt.X();                
484       pictureTop   =  myStartPnt.Y();
485     }
486     aDetector->ComputeCorners();
487     CvPoint2D32f* corners     = aDetector->GetCorners();
488     int cornerCount           = aDetector->GetCornerCount();
489     int i;
490     
491     // Build the geom objects associated to the detected corners and returned by execute   
492     if( !aBasicOperations->_is_nil() && !aShapesOperations->_is_nil() ) 
493     {
494       GEOM::GEOM_Object_var  aGeomCorner;
495       GEOM::ListOfGO_var     geomCorners = new GEOM::ListOfGO();
496       geomCorners->length( cornerCount );
497       for (i = 0; i < cornerCount; i++)
498       {
499         double x = pictureLeft + corners[i].x;
500         double y = pictureTop  - corners[i].y;
501         double z =  0;
502         
503         aGeomCorner = aBasicOperations->MakePointXYZ( x,y,z );
504         
505         geomCorners[i] = aGeomCorner;  
506       } 
507       GEOM::GEOM_Object_var aCompound = aShapesOperations->MakeCompound(geomCorners);    
508       if ( !aCompound->_is_nil() )
509       {
510         // Dark blue color
511         SALOMEDS::Color aColor;
512         aColor.R = 0;
513         aColor.G = 0;
514         aColor.B = 0.8;
515         
516         aCompound->SetColor(aColor);
517         aCompound->SetMarkerStd(GEOM::MT_POINT,GEOM::MS_30);
518         objects.push_back( aCompound._retn() );
519         res = true;
520       }
521     }
522   }
523   else if (myConstructorId == CONTOURS)
524   {
525     int method = 0 ; //CANNY
526     if( !aRect.isEmpty() && aRect.width() > 1 )
527     {
528       aDetector->SetROI( aRect );
529       method = 1 ; //COLORFILTER    
530     }
531     
532     GEOM::GEOM_ICurvesOperations_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
533     
534     aDetector->ComputeContours( method );
535     std::vector< std::vector<cv::Point> >   contours  = aDetector->GetContours();
536     std::vector<cv::Vec4i>                  hierarchy = aDetector->GetContoursHierarchy();
537     
538     std::vector< cv::Point >                contour;
539     int idx = 0;
540     
541     GEOM::ListOfGO_var                      geomContours = new GEOM::ListOfGO();
542     int contourCount = 0;
543     
544     bool insert;
545     
546     MESSAGE("hierarchy.size() =" << hierarchy.size()) 
547     for( ; idx >= 0; idx = hierarchy[idx][0])
548     {
549 //       for(int count=0, child=idx; child>=0, count<1; child=hierarchy[idx][2], count++)
550 //       {     
551 //         contour = contours[child];
552         contour = contours[idx];
553         std::vector< cv::Point >::iterator it;
554         std::vector< cv::Point >::iterator it_previous;
555         std::vector< cv::Point >::iterator it_next;
556         GEOM::GEOM_Object_var  aGeomContourPnt;
557         GEOM::ListOfGO_var     geomContourPnts = new GEOM::ListOfGO();
558        
559         geomContourPnts->length( contour.size() );
560
561         int j = 0;
562         std::set< std::vector<int> > existing_points;
563         std::pair< std::set< std::vector<int> >::iterator,bool > pnt_it;
564         for ( it=contour.begin() ; it < contour.end(); it++ )
565         {
566           int pnt_array[] = {it->x,it->y};     
567           std::vector<int> pnt (pnt_array, pnt_array + sizeof(pnt_array) / sizeof(int) );
568
569           pnt_it=existing_points.insert(pnt);
570           if (pnt_it.second == true)         // To avoid double points in the contours
571           {
572             insert = true;
573             if (it!=contour.begin())         // From the second point on perform some checking to avoid loops in the contours we build
574             {
575               it_previous = boost::prior(it);
576               it_next = boost::next(it);
577               
578               double u_v_scalar_product = (it->x - it_previous->x) * (it_next->x - it->x) + 
579                                           (it->y - it_previous->y) * (it_next->y - it->y);                                       
580               if (u_v_scalar_product < 0)
581               {
582                 double u_v_det = (it->x - it_previous->x) * (it_next->y - it->y) - 
583                                  (it->y - it_previous->y) * (it_next->x - it->x);
584                                           
585                 double norme_u = sqrt ( (it->x - it_previous->x)*(it->x - it_previous->x) +
586                                         (it->y - it_previous->y)*(it->y - it_previous->y) );
587                 
588                 double norme_v = sqrt ( (it->x - it_next->x)*(it->x - it_next->x) +
589                                         (it->y - it_next->y)*(it->y - it_next->y) );
590                                                                                                 
591                 double u_v_sinus = u_v_det / (norme_u * norme_v);
592                 
593                 if (fabs(u_v_sinus) < Precision::Confusion())
594                 { 
595                   insert = false;
596                 }                         
597               }
598             }
599             double x = -0.5 *width  + it->x;
600             double y =  0.5 *height - it->y;
601             double z =  0;
602             if (insert)
603             {
604               aGeomContourPnt    = aBasicOperations->MakePointXYZ( x,y,z );
605               geomContourPnts->length( j+1 );
606               geomContourPnts[j] = aGeomContourPnt;
607               j++;
608             }
609           }
610         }
611         
612         GEOM::GEOM_Object_var aWire;
613         if(myOutputGroup->RadioButton2->isChecked())
614         {
615           aWire = aCurveOperations->MakePolyline(geomContourPnts.in(), false);
616         }
617         else if(myOutputGroup->RadioButton1->isChecked())
618         {
619           aWire = aCurveOperations->MakeSplineInterpolation(geomContourPnts.in(), /*closed =*/ false, /*reordering =*/ false);
620         }
621         else
622           return res;
623         
624         if ( !aWire->_is_nil() )
625         {
626           geomContours->length(contourCount + 1);
627           geomContours[contourCount] = aWire;
628           contourCount++;
629         }
630 //       }
631     }
632     GEOM::GEOM_Object_var aContoursCompound = aShapesOperations->MakeCompound(geomContours);
633     if ( !aContoursCompound->_is_nil() )
634     {
635       objects.push_back( aContoursCompound._retn() );
636     }
637     res=true;
638   }
639   
640   else if(myConstructorId ==LINES)
641   {
642     aDetector->ComputeLines();
643     std::vector<cv::Vec4i>  lines = aDetector->GetLines();
644     GEOM::GEOM_Object_var  Pnt1;
645     GEOM::GEOM_Object_var  Pnt2;
646     GEOM::GEOM_Object_var  aLine;
647     
648     GEOM::ListOfGO_var     geomLines = new GEOM::ListOfGO();
649     int linesCount=0;
650     for( int i = 0; i < lines.size(); i++ )
651     {
652       Pnt1 = aBasicOperations->MakePointXYZ( -0.5 *width + lines[i][0], 0.5 *height - lines[i][1], 0 );
653       Pnt2 = aBasicOperations->MakePointXYZ( -0.5 *width + lines[i][2], 0.5 *height - lines[i][3], 0 );
654       aLine = aBasicOperations->MakeLineTwoPnt( Pnt1, Pnt2 );
655       if ( !aLine->_is_nil() )
656       {
657         geomLines->length(linesCount + 1);
658         geomLines[linesCount] = aLine;
659         linesCount++;
660       }
661     }
662     GEOM::GEOM_Object_var aLinesCompound = aShapesOperations->MakeCompound(geomLines);
663     if ( !aLinesCompound->_is_nil() )
664     {
665       objects.push_back( aLinesCompound._retn() );
666     }
667
668     res=true;
669   }
670   
671   return res;
672 }