@@ -70,6 +70,7 @@ the use of this software, even if advised of the possibility of such damage.
70
70
using namespace adsk ::core;
71
71
using namespace adsk ::fusion;
72
72
73
+
73
74
Ptr <Application> app;
74
75
Ptr <UserInterface> ui;
75
76
Ptr <Component> newComp;
@@ -389,7 +390,7 @@ cv::Mat dst;
389
390
cv::Mat detected_edges;
390
391
int lowThreshold = 50 ;
391
392
int const max_lowThreshold = 100 ;
392
- int ratio = 3 ;
393
+ int ratio3 = 3 ;
393
394
int kernel_size = 3 ;
394
395
const char * window_name = " Contour groove" ;
395
396
@@ -402,28 +403,36 @@ static bool showPreview = false;
402
403
403
404
static void CannyThreshold (int , void *)
404
405
{
405
- if (!detected_edges. empty () && detected_edges. data )
406
+ try
406
407
{
407
- detected_edges.release ();
408
- }
409
- detected_edges = cv::Scalar::all (0 );
410
-
411
- blur (src_gray, detected_edges, cv::Size (3 , 3 ));
408
+ if (!detected_edges.empty () && detected_edges.data )
409
+ {
410
+ detected_edges.release ();
411
+ }
412
+ detected_edges = cv::Scalar::all (0 );
413
+
414
+
415
+ blur (src_gray, detected_edges, cv::Size (3 , 3 ));
416
+
417
+ Canny (detected_edges, detected_edges, lowThreshold, lowThreshold * ratio3, kernel_size);
412
418
413
- Canny (detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
419
+ findContours (detected_edges, contours, hierarchy, 3 /* =RETR_TREE */ , 2 /* =CHAIN_APPROX_SIMPLE */ , cv::Point ( 0 , 0 ) );
414
420
415
- findContours (detected_edges, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point (0 , 0 ));
421
+ dst = cv::Mat::zeros (detected_edges.size (), CV_8UC3);
422
+ for (int i = 0 ; i < contours.size (); i++)
423
+ {
424
+ cv::Scalar color = cv::Scalar (rng.uniform (0 , 255 ), rng.uniform (0 , 255 ), rng.uniform (0 , 255 ));
425
+ drawContours (dst, contours, i, color, 2 , 8 , hierarchy, 0 , cv::Point ());
426
+ }
416
427
417
- dst = cv::Mat::zeros (detected_edges.size (), CV_8UC3);
418
- for (int i = 0 ; i < contours.size (); i++)
419
- {
420
- cv::Scalar color = cv::Scalar (rng.uniform (0 , 255 ), rng.uniform (0 , 255 ), rng.uniform (0 , 255 ));
421
- drawContours (dst, contours, i, color, 2 , 8 , hierarchy, 0 , cv::Point ());
428
+ if (showPreview)
429
+ {
430
+ cv::imshow (window_name, dst);
431
+ }
422
432
}
423
-
424
- if (showPreview)
433
+ catch (exception ex)
425
434
{
426
- cv::imshow (window_name, dst) ;
435
+ string str = " asd " ;
427
436
}
428
437
}
429
438
@@ -807,12 +816,14 @@ bool isApplicationStartup(std::string context)
807
816
return res;
808
817
}
809
818
819
+
810
820
extern " C" XI_EXPORT bool run (const char * context)
811
821
{
812
822
const std::string commandName = " Contour groove" ;
813
823
const std::string commandDescription = " Creates a grooved outline from edges identified from an image." ;
814
824
const std::string commandResources = " ./resources" ;
815
825
826
+
816
827
app = Application::get ();
817
828
if (!app)
818
829
return false ;
@@ -829,7 +840,11 @@ extern "C" XI_EXPORT bool run(const char* context)
829
840
if (!modelingWorkspace)
830
841
return false ;
831
842
832
- Ptr <ToolbarPanels> toolbarPanels = modelingWorkspace->toolbarPanels ();
843
+ Ptr <ToolbarTabs> modelingWorkspaceTabs = modelingWorkspace->toolbarTabs ();
844
+
845
+ Ptr <ToolbarTab> createTab = modelingWorkspaceTabs->item (0 );
846
+
847
+ Ptr <ToolbarPanels> toolbarPanels = createTab->toolbarPanels ();
833
848
if (!toolbarPanels)
834
849
return false ;
835
850
Ptr <ToolbarPanel> toolbarPanel = toolbarPanels->item (0 );
@@ -871,6 +886,7 @@ extern "C" XI_EXPORT bool run(const char* context)
871
886
if (!isApplicationStartup (context))
872
887
ui->messageBox (" Contour Groove is loaded successfully.\r\n\r\n You can run it from the create panel in modeling workspace." );
873
888
}
889
+
874
890
875
891
return true ;
876
892
}
@@ -879,6 +895,12 @@ extern "C" XI_EXPORT bool stop(const char* context)
879
895
{
880
896
if (ui)
881
897
{
898
+ Ptr <CommandDefinitions> commandDefinitions = ui->commandDefinitions ();
899
+ Ptr <CommandDefinition> commandDefinition = commandDefinitions->itemById (commandId);
900
+ if (commandDefinition)
901
+ {
902
+ commandDefinition->deleteMe ();
903
+ }
882
904
ui = nullptr ;
883
905
}
884
906
cvCleanup ();
0 commit comments