From: Eduardo DAVILA Date: Mon, 26 Apr 2021 07:07:27 +0000 (+0200) Subject: #3459 Feuture box PointPicker X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=dabff1fc1b917ee33daff026390f7bd0e5722c37;p=creaVtk.git #3459 Feuture box PointPicker --- diff --git a/bbtk_creaVtk_PKG/bbs/appli/ExamplePointPicker.bbg b/bbtk_creaVtk_PKG/bbs/appli/ExamplePointPicker.bbg new file mode 100644 index 0000000..f8634e6 --- /dev/null +++ b/bbtk_creaVtk_PKG/bbs/appli/ExamplePointPicker.bbg @@ -0,0 +1,257 @@ +# ---------------------------------- +# - BBTKGEditor v 1.4 BBG BlackBox Diagram file +# - /home/davila/Creatis/C11/creatools_source/creaVtk/bbtk_creaVtk_PKG/bbs/appli/ExamplePointPicker.bbg +# ---------------------------------- + +APP_START +CATEGORY: +DESCRIPTION:Description ?? +AUTHOR:Author ?? +COMPLEXBOX:FALSE +COMPLEXINPUTS:0 +BOXES:19 +BOX +creaVtk:PointPicker:Box00 +ISEXEC:FALSE +42.388461:-60.890316:-900.000000 +79.338461:-70.890316:-900.000000 +FIN_BOX +BOX +vtk:SphereSource:Box01 +ISEXEC:FALSE +-86.646215:96.548464:-900.000000 +-46.821215:86.548464:-900.000000 +PORT +CenterX:"40" +PORT +CenterY:"40" +PORT +CenterZ:"40" +PORT +PhiResolution:"20" +PORT +Radius:"20" +PORT +ThetaResolution:"20" +FIN_BOX +BOX +vtk:PolyDataToActor:Box02 +ISEXEC:FALSE +-95.048252:31.209645:-900.000000 +-49.808252:21.209645:-900.000000 +FIN_BOX +BOX +creaMaracasVisu:ViewerNV:Box03 +ISEXEC:FALSE +8.401272:82.554547:-900.000000 +44.276272:72.554547:-900.000000 +FIN_BOX +BOX +wx:OutputText:Box04 +ISEXEC:FALSE +42.530164:-134.123521:-900.000000 +79.305164:-144.123521:-900.000000 +PORT +Title:"Point&&2P&&" +FIN_BOX +BOX +wx:LayoutLine:Box05 +ISEXEC:FALSE +-17.972686:-174.663538:-900.000000 +18.602314:-184.663538:-900.000000 +FIN_BOX +BOX +wx:Slider:Box07 +ISEXEC:FALSE +-147.867981:83.753544:-900.000000 +-96.467981:73.753544:-900.000000 +PORT +Label:"true" +PORT +Max:"100" +PORT +ReactiveOnTrack:"true" +PORT +Title:"Opacity" +FIN_BOX +BOX +vtk:LoadHola:Box08 +ISEXEC:FALSE +60.405272:125.283738:-900.000000 +95.955272:115.283738:-900.000000 +FIN_BOX +BOX +std:MathOperationVector:Box09 +ISEXEC:FALSE +140.121465:-78.587243:-900.000000 +187.646465:-88.587243:-900.000000 +PORT +Type:"3" +FIN_BOX +BOX +vtk:ImageVtkProperties:Box10 +ISEXEC:FALSE +137.805626:-58.052985:-900.000000 +183.155626:-68.052985:-900.000000 +FIN_BOX +BOX +creaMaracasVisu:SetPosition:Box11 +ISEXEC:FALSE +140.379252:-125.723679:-900.000000 +176.929252:-135.723679:-900.000000 +FIN_BOX +BOX +std:MathOperationVector:Box13 +ISEXEC:FALSE +146.565584:-95.540874:-900.000000 +194.090584:-105.540874:-900.000000 +PORT +Type:"23" +FIN_BOX +BOX +std:Div:Box14 +ISEXEC:FALSE +-108.350574:58.048497:-900.000000 +-79.025574:48.048497:-900.000000 +PORT +In2:"100" +FIN_BOX +BOX +wx:OutputText:Box15 +ISEXEC:FALSE +88.836059:-132.175947:-900.000000 +125.611059:-142.175947:-900.000000 +PORT +Title:"Round Point&&2P&&" +FIN_BOX +BOX +wx:CheckBox:Box16 +ISEXEC:FALSE +13.081332:16.677865:-900.000000 +49.406332:6.677865:-900.000000 +PORT +In:"true" +PORT +Title:"Point Picker Active" +FIN_BOX +BOX +creaVtk:OutputWindow:Box17 +ISEXEC:TRUE +-119.252058:-206.172997:-900.000000 +-78.652058:-216.172997:-900.000000 +FIN_BOX +BOX +wx:LayoutSplit:Box18 +ISEXEC:TRUE +-61.489869:-207.111169:-900.000000 +-24.814869:-217.111169:-900.000000 +PORT +Orientation:"H" +FIN_BOX +BOX +wx:ComboBox:Box19 +ISEXEC:FALSE +-39.256609:18.205522:-900.000000 +2.903391:8.205522:-900.000000 +PORT +In:"Nothing MouseMove ClickLeft DoubleClickLeft" +PORT +Selection:"2" +PORT +Title:"Event" +FIN_BOX +BOX +std:MultipleInputs:Box20 +ISEXEC:FALSE +-64.871846:-21.697611:-900.000000 +-25.171846:-31.697611:-900.000000 +FIN_BOX +CONNECTIONS:29 +CONNECTION +Box01:Out:Box02:In +NumberOfControlPoints:0 +CONNECTION +Box04:Widget:Box05:Widget2 +NumberOfControlPoints:0 +CONNECTION +Box03:Renderer1:Box02:Renderer +NumberOfControlPoints:0 +CONNECTION +Box03:Renderer1:Box00:Renderer +NumberOfControlPoints:0 +CONNECTION +Box07:Widget:Box05:Widget1 +NumberOfControlPoints:0 +CONNECTION +Box07:BoxChange:Box02:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box08:Out:Box03:In +NumberOfControlPoints:0 +CONNECTION +Box00:BoxChange:Box04:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box00:Point:Box09:In0 +NumberOfControlPoints:0 +CONNECTION +Box08:Out:Box10:In +NumberOfControlPoints:0 +CONNECTION +Box10:Spacing:Box09:In1 +NumberOfControlPoints:0 +CONNECTION +Box09:Out:Box04:In +NumberOfControlPoints:0 +CONNECTION +Box03:wxVtkBaseView1:Box11:wxVtkBaseView +NumberOfControlPoints:0 +CONNECTION +Box00:BoxChange:Box11:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box09:Out:Box13:In0 +NumberOfControlPoints:0 +CONNECTION +Box13:Out:Box11:Point +NumberOfControlPoints:0 +CONNECTION +Box07:Out:Box14:In1 +NumberOfControlPoints:0 +CONNECTION +Box14:Out:Box02:Opacity +NumberOfControlPoints:0 +CONNECTION +Box13:Out:Box15:In +NumberOfControlPoints:0 +CONNECTION +Box00:BoxChange:Box15:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box15:Widget:Box05:Widget3 +NumberOfControlPoints:0 +CONNECTION +Box16:Widget:Box05:Widget5 +NumberOfControlPoints:0 +CONNECTION +Box05:Widget:Box18:Widget1 +NumberOfControlPoints:0 +CONNECTION +Box03:Widget:Box18:Widget2 +NumberOfControlPoints:0 +CONNECTION +Box19:Widget:Box05:Widget6 +NumberOfControlPoints:0 +CONNECTION +Box19:Out:Box00:TypeEvent +NumberOfControlPoints:0 +CONNECTION +Box19:BoxChange:Box20:In1 +NumberOfControlPoints:0 +CONNECTION +Box16:BoxChange:Box20:In3 +NumberOfControlPoints:0 +CONNECTION +Box20:BoxChange:Box00:BoxExecute +NumberOfControlPoints:0 +APP_END diff --git a/bbtk_creaVtk_PKG/bbs/appli/ExamplePointPicker.bbs b/bbtk_creaVtk_PKG/bbs/appli/ExamplePointPicker.bbs new file mode 100644 index 0000000..0b66cb6 --- /dev/null +++ b/bbtk_creaVtk_PKG/bbs/appli/ExamplePointPicker.bbs @@ -0,0 +1,143 @@ +# ---------------------------------- +# - BBTKGEditor v 1.4 BBS BlackBox Script +# - /home/davila/Creatis/C11/creatools_source/creaVtk/bbtk_creaVtk_PKG/bbs/appli/ExamplePointPicker.bbs +# ---------------------------------- + +# BBTK GEditor Script +# ---------------------- + +include std +include itkvtk +include creaVtk +include vtk +include creaMaracasVisu +include wx +include std + +author "Author ??" +description "Description ??" +category "" + +new creaVtk:PointPicker Box00 + +new vtk:SphereSource Box01 + set Box01.CenterX "40" + set Box01.CenterY "40" + set Box01.CenterZ "40" + set Box01.PhiResolution "20" + set Box01.Radius "20" + set Box01.ThetaResolution "20" + +new vtk:PolyDataToActor Box02 + +new creaMaracasVisu:ViewerNV Box03 + +new wx:OutputText Box04 + set Box04.Title "Point:" + +new wx:LayoutLine Box05 + +new wx:Slider Box07 + set Box07.Label "true" + set Box07.Max "100" + set Box07.ReactiveOnTrack "true" + set Box07.Title "Opacity" + +new vtk:LoadHola Box08 + +new std:MathOperationVector Box09 + set Box09.Type "3" + +new vtk:ImageVtkProperties Box10 + +new creaMaracasVisu:SetPosition Box11 + +new std:MathOperationVector Box13 + set Box13.Type "23" + +new std:Div Box14 + set Box14.In2 "100" + +new wx:OutputText Box15 + set Box15.Title "Round Point:" + +new wx:CheckBox Box16 + set Box16.In "true" + set Box16.Title "Point Picker Active" + +new creaVtk:OutputWindow Box17 + +new wx:LayoutSplit Box18 + set Box18.Orientation "H" + +new wx:ComboBox Box19 + set Box19.In "Nothing MouseMove ClickLeft DoubleClickLeft" + set Box19.Selection "2" + set Box19.Title "Event" + +new std:MultipleInputs Box20 + + +connect Box01.Out Box02.In + +connect Box04.Widget Box05.Widget2 + +connect Box03.Renderer1 Box02.Renderer + +connect Box03.Renderer1 Box00.Renderer + +connect Box07.Widget Box05.Widget1 + +connect Box07.BoxChange Box02.BoxExecute + +connect Box08.Out Box03.In + +connect Box00.BoxChange Box04.BoxExecute + +connect Box00.Point Box09.In0 + +connect Box08.Out Box10.In + +connect Box10.Spacing Box09.In1 + +connect Box09.Out Box04.In + +connect Box03.wxVtkBaseView1 Box11.wxVtkBaseView + +connect Box00.BoxChange Box11.BoxExecute + +connect Box09.Out Box13.In0 + +connect Box13.Out Box11.Point + +connect Box07.Out Box14.In1 + +connect Box14.Out Box02.Opacity + +connect Box13.Out Box15.In + +connect Box00.BoxChange Box15.BoxExecute + +connect Box15.Widget Box05.Widget3 + +connect Box16.Widget Box05.Widget5 + +connect Box05.Widget Box18.Widget1 + +connect Box03.Widget Box18.Widget2 + +connect Box19.Widget Box05.Widget6 + +connect Box19.Out Box00.TypeEvent + +connect Box19.BoxChange Box20.In1 + +connect Box16.BoxChange Box20.In3 + +connect Box20.BoxChange Box00.BoxExecute + + + +# Complex input ports +exec Box17 +exec Box18 diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx index 6bc8262..5bb82f5 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx @@ -7,31 +7,53 @@ #include #include #include -#include #include namespace bbcreaVtk { +creaVtkCallbackPointPicker::creaVtkCallbackPointPicker(void) +{ + boxPointPicker=NULL; +} +void creaVtkCallbackPointPicker::setBox(PointPicker *box) +{ + boxPointPicker=box; +} void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*) { - printf("creaVtkCallbackPointPicker EED Picker\n"); - vtkRenderWindowInteractor *iren = static_cast(caller); - - int* pos = iren->GetEventPosition(); - vtkCellPicker *picker = vtkCellPicker::New(); - picker->SetTolerance(0.0005); - picker->Pick(pos[0], pos[1], 0, iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer() ); - - if(picker->GetCellId() != -1) - { - printf("creaVtkCallbackPointPicker EED picker OK\n"); - } else { - printf("creaVtkCallbackPointPicker EED picker --\n"); - } // if - + if (boxPointPicker!=NULL) + { + if (boxPointPicker->bbGetInputActive()==true) + { + printf("creaVtkCallbackPointPicker EED Picker\n"); + vtkRenderWindowInteractor *iren = static_cast(caller); + int* pos = iren->GetEventPosition(); + vtkCellPicker *picker = vtkCellPicker::New(); + picker->SetTolerance(0.0005); + picker->Pick(pos[0], pos[1], 0, iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer() ); + double point[3]; + + if(picker->GetCellId() != -1) + { + printf("creaVtkCallbackPointPicker EED picker OK\n"); + picker->GetPickPosition(point); + std::vector vecPoint; + vecPoint.push_back( point[0] ); + vecPoint.push_back( point[1] ); + vecPoint.push_back( point[2] ); + boxPointPicker->bbSetOutputPoint( vecPoint ); + boxPointPicker->bbSetOutputMesh( picker->GetProp3D() ); + boxPointPicker->bbSetOutputPointId( picker->GetPointId() ); + boxPointPicker->bbSetOutputCellId( picker->GetCellId() ); + boxPointPicker->bbSignalOutputModification(); + } else { + printf("creaVtkCallbackPointPicker EED picker --\n"); + } // if + } + } // if boxPoiintPicker /* { @@ -40,7 +62,7 @@ void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void* << " " << worldPosition[2] << endl; vtkSmartPointer ids = - vtkSmartPointer::New(); + vtkSmartPointer::New()creaVtkCallbackPointPicker *callPicker; ids->SetNumberOfComponents(1); ids->InsertNextValue(picker->GetCellId()); @@ -128,8 +150,6 @@ void PointPicker::Process() if (firsttime==true) { - -printf("EED PointPicker::Process Firsttime \n"); firsttime = false; // vtkCellPicker *picker = vtkCellPicker::New(); // vtkPropPicker *picker = vtkCellPicker::New(); @@ -147,26 +167,56 @@ printf("EED PointPicker::Process Firsttime \n"); bbGetInputRenderer()->GetRenderWindow()->GetInteractor()->SetPicker(picker); */ - creaVtkCallbackPointPicker *callPicker = creaVtkCallbackPointPicker::New(); - vtkRenderWindowInteractor *vrwi = bbGetInputRenderer()->GetRenderWindow()->GetInteractor(); - vrwi->AddObserver( vtkCommand::EndPickEvent , callPicker ); - vrwi->AddObserver( vtkCommand::StartPickEvent , callPicker ); - vrwi->AddObserver( vtkCommand::MouseMoveEvent , callPicker ); + callPicker = creaVtkCallbackPointPicker::New(); + callPicker->setBox( this ); } // if firsttime + + if (bbGetInputRenderer()!=NULL) + { + vtkRenderWindowInteractor *vrwi = bbGetInputRenderer()->GetRenderWindow()->GetInteractor(); + vrwi->RemoveObserver( callPicker ); + + if (bbGetInputTypeEvent()==0) + { + // Nothing + } else if (bbGetInputTypeEvent()==1) + { + vrwi->AddObserver( vtkCommand::MouseMoveEvent , callPicker ); + } else if (bbGetInputTypeEvent()==2) + { + vrwi->AddObserver( vtkCommand::LeftButtonPressEvent , callPicker ); + } else if (bbGetInputTypeEvent()==3) + { +#if VTK_MAJOR_VERSION >= 9 + vrwi->AddObserver( vtkCommand::LeftButtonDoubleClickEvent , callPicker ); +#else + printf("EED Warnning! PointPicker LeftButtonPressEvent since vtk 9 \n"); +#endif + } // if TypeEvent + // ....See vtkCommand EventIds + } // if bbGetInputRenderer() + + + + } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void PointPicker::bbUserSetDefaultValues() { - // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 // bbSetInputIn(0); - - firsttime=true; + bbSetInputActive(true); + bbSetInputTypeEvent(0); + bbSetOutputMesh(NULL); + bbSetOutputPointId(-1); + bbSetOutputCellId(-1); + firsttime=true; + callPicker=NULL; } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.h b/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.h index 804309f..94c9d37 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.h @@ -9,18 +9,28 @@ #include "vtkCommand.h" #include "vtkRenderer.h" +#include "vtkProp3D.h" +#include + namespace bbcreaVtk { +class PointPicker; //--------------------------------------------- class creaVtkCallbackPointPicker : public vtkCommand { + public: + creaVtkCallbackPointPicker(); + static creaVtkCallbackPointPicker *New() { return new creaVtkCallbackPointPicker; } void Delete() { delete this; } virtual void Execute(vtkObject *caller, unsigned long, void*); + void setBox(PointPicker *box); + private: + PointPicker *boxPointPicker; }; @@ -29,6 +39,7 @@ class creaVtkCallbackPointPicker : public vtkCommand //--------------------------------------------- //--------------------------------------------- +typedef long int longInt; class bbcreaVtk_EXPORT PointPicker : @@ -38,24 +49,39 @@ class bbcreaVtk_EXPORT PointPicker //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== + BBTK_DECLARE_INPUT(Active,bool); + BBTK_DECLARE_INPUT(TypeEvent,int ); BBTK_DECLARE_INPUT(Renderer,vtkRenderer*); - BBTK_DECLARE_OUTPUT(Out,std::vector); + BBTK_DECLARE_OUTPUT(Point,std::vector); + BBTK_DECLARE_OUTPUT(Mesh,vtkProp3D*); + BBTK_DECLARE_OUTPUT(PointId,longInt); + BBTK_DECLARE_OUTPUT(CellId,longInt); BBTK_PROCESS(Process); void Process(); bool firsttime; + creaVtkCallbackPointPicker *callPicker; + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== }; BBTK_BEGIN_DESCRIBE_BLACK_BOX(PointPicker,bbtk::AtomicBlackBox); -BBTK_NAME("PointPicker"); -BBTK_AUTHOR("InfoDev"); -BBTK_DESCRIPTION("No Description."); -BBTK_CATEGORY("empty"); -BBTK_INPUT(PointPicker,Renderer,"vtk Renderer",vtkRenderer*,""); -BBTK_OUTPUT(PointPicker,Out,"First output",std::vector,""); + BBTK_NAME("PointPicker"); + BBTK_AUTHOR("InfoDev"); + BBTK_DESCRIPTION("No Description."); + BBTK_CATEGORY("empty"); + + BBTK_INPUT(PointPicker,Active,"(true default) true/false",bool,""); + BBTK_INPUT(PointPicker,TypeEvent,"(0 default) 0:NOTHING, 1:MouseMoveEvent 2:LeftButtonPressEvent 3:LeftButtonDoubleClickEvent",int,""); + BBTK_INPUT(PointPicker,Renderer,"vtk Renderer",vtkRenderer*,""); + + BBTK_OUTPUT(PointPicker,Point,"Point (double)",std::vector,""); + BBTK_OUTPUT(PointPicker,Mesh,"Mesh",vtkProp3D*,""); + BBTK_OUTPUT(PointPicker,PointId,"Point Id in Mesh",longInt,""); + BBTK_OUTPUT(PointPicker,CellId,"Cell Id in Mesh",longInt,""); + BBTK_END_DESCRIBE_BLACK_BOX(PointPicker); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.cxx index ba2a9ea..b962c93 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.cxx @@ -227,9 +227,9 @@ void ScalarsToColors::Process() // std::cout << "Output value = " <colorRGB; _scalarstocolors->GetColor( bbGetInputScalarValue() , rgb ); @@ -353,7 +353,7 @@ void ScalarsToColors::bbUserSetDefaultValues() range.push_back( 1 ); bbSetInputRange(range); bbSetInputScalarValue(0); - firsttime = true; +// firsttime = true; _scalarstocolors = NULL; } //===== diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.h b/bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.h index a0652ae..15748a7 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkScalarsToColors.h @@ -31,7 +31,7 @@ class bbcreaVtk_EXPORT ScalarsToColors BBTK_PROCESS(Process); void Process(); - bool firsttime; +// bool firsttime; vtkScalarsToColors *_scalarstocolors; vtkColorTransferFunction *_volumeColor;