From c60006db2a510edf10e880afa2c85a3d8335f9e7 Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Wed, 8 May 2024 09:30:42 +0200 Subject: [PATCH] #3556 Box TransformWidget2_tool --- bbtk/bbs/boxes/FreePlane.bbg | 14 +- bbtk/bbs/boxes/FreePlane.bbs | 3 +- .../src/bbcreaMaracasVisuTransformWidget2.cxx | 155 +++++++++++------- bbtk/src/bbcreaMaracasVisuTransformWidget2.h | 4 + ...bbcreaMaracasVisuTransformWidget2_tool.cxx | 86 ++++++++++ .../bbcreaMaracasVisuTransformWidget2_tool.h | 53 ++++++ bbtk/src/bbmaracasvisuSliderMinMax.cxx | 11 +- 7 files changed, 254 insertions(+), 72 deletions(-) create mode 100644 bbtk/src/bbcreaMaracasVisuTransformWidget2_tool.cxx create mode 100644 bbtk/src/bbcreaMaracasVisuTransformWidget2_tool.h diff --git a/bbtk/bbs/boxes/FreePlane.bbg b/bbtk/bbs/boxes/FreePlane.bbg index eb1ea4b..4b0868c 100644 --- a/bbtk/bbs/boxes/FreePlane.bbg +++ b/bbtk/bbs/boxes/FreePlane.bbg @@ -1,5 +1,5 @@ # ---------------------------------- -# - BBTKGEditor v 1.5 BBG BlackBox Diagram file +# - BBTKGEditor v 1.6 BBG BlackBox Diagram file # - /Users/davila/Creatis/C23/creatools_source/creaMaracasVisu/bbtk/bbs/boxes/FreePlane.bbg # ---------------------------------- @@ -7,10 +7,11 @@ APP_START CATEGORY: DESCRIPTION:Description ?? AUTHOR:Author ?? +EXPORTFORMAT:0 COMPLEXBOX:TRUE COMPLEXBOXNAME:FreePlane PACKAGENAME:creaMaracasVisu -COMPLEXOUTPUTS:4 +COMPLEXOUTPUTS:5 COMPLEX_PORT widgetOut -62.602729:-39.249279:-900.000000 @@ -27,6 +28,10 @@ COMPLEX_PORT boxChange -109.488119:-40.220094:-900.000000 FIN_COMPLEX_PORT +COMPLEX_PORT +box_TransformWidget2 +-30.291440:-37.573030:-900.000000 +FIN_COMPLEX_PORT COMPLEXINPUTS:5 COMPLEX_PORT possiblePoint @@ -225,7 +230,7 @@ ISEXEC:FALSE PORT Active:"true" FIN_BOX -CONNECTIONS:46 +CONNECTIONS:47 CONNECTION Box02:Out:Box04:In NumberOfControlPoints:0 @@ -364,4 +369,7 @@ NumberOfControlPoints:0 CONNECTION Box16:BoxChange:boxChange:boxChange NumberOfControlPoints:0 +CONNECTION +Box16:Box_TransformWidget2:box_TransformWidget2:box_TransformWidget2 +NumberOfControlPoints:0 APP_END diff --git a/bbtk/bbs/boxes/FreePlane.bbs b/bbtk/bbs/boxes/FreePlane.bbs index ebc297d..0e8eb48 100644 --- a/bbtk/bbs/boxes/FreePlane.bbs +++ b/bbtk/bbs/boxes/FreePlane.bbs @@ -1,5 +1,5 @@ # ---------------------------------- -# - BBTKGEditor v 1.5 BBS BlackBox Script (Complex Box) +# - BBTKGEditor v 1.6 BBS BlackBox Script (Complex Box) # - /Users/davila/Creatis/C23/creatools_source/creaMaracasVisu/bbtk/bbs/boxes/FreePlane.bbs # ---------------------------------- @@ -137,6 +137,7 @@ output widgetOut Box01.Widget " " output transform Box16.Out " " output actualPoint Box08.Out " " output boxChange Box16.BoxChange " " +output box_TransformWidget2 Box16.Box_TransformWidget2 " " endefine diff --git a/bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx b/bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx index 2bb4f19..f35942c 100644 --- a/bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx +++ b/bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx @@ -39,7 +39,9 @@ public: void OnRadioButtonZ(wxEvent& event); void OnRadioButtonN(wxEvent& event); void OnSave(wxCommandEvent& event); + void Save(std::string filename); void OnLoad(wxCommandEvent& event); + void Load(std::string filename); void OnReset(wxCommandEvent& event); void OnMoveDown(wxCommandEvent& event); void OnMoveUp(wxCommandEvent& event); @@ -405,6 +407,26 @@ void TransformWidgetPanel::OnMemory(wxCommandEvent& event) mMemoryMatrix->DeepCopy( t->GetMatrix() ); } +void TransformWidgetPanel::Save(std::string filename) +{ + FILE *ff; + ff = fopen( filename.c_str() , "w+" ); + if (ff!=NULL) + { + fprintf(ff,"ActualPoint:\n"); + fprintf(ff,"%f %f %f\n",mActualPoint[0], mActualPoint[1], mActualPoint[2] ); + vtkMatrix4x4 *m = t->GetMatrix(); + fprintf(ff,"Transform:\n"); + fprintf(ff,"%f %f %f %f \n",m->GetElement(0,0), m->GetElement(1,0), m->GetElement(2,0), m->GetElement(3,0) ); + fprintf(ff,"%f %f %f %f \n",m->GetElement(0,1), m->GetElement(1,1), m->GetElement(2,1), m->GetElement(3,1) ); + fprintf(ff,"%f %f %f %f \n",m->GetElement(0,2), m->GetElement(1,2), m->GetElement(2,2), m->GetElement(3,2) ); + fprintf(ff,"%f %f %f %f\n\n",m->GetElement(0,3), m->GetElement(1,3), m->GetElement(2,3), m->GetElement(3,3) ); + fclose(ff); + } else { // else ff + printf("TransformWidgetPanel::OnSave ...Error... creating file \n"); + } //ff +} + void TransformWidgetPanel::OnSave(wxCommandEvent& event) { wxFileDialog* FD = new wxFileDialog( 0, @@ -421,29 +443,63 @@ void TransformWidgetPanel::OnSave(wxCommandEvent& event) if (FD->GetReturnCode()==wxID_OK) { std::string filename= (const char*) ( FD->GetPath().mb_str() ); - FILE *ff; - ff = fopen( filename.c_str() , "w+" ); - if (ff!=NULL) - { - fprintf(ff,"ActualPoint:\n"); - fprintf(ff,"%f %f %f\n",mActualPoint[0], mActualPoint[1], mActualPoint[2] ); - vtkMatrix4x4 *m = t->GetMatrix(); - fprintf(ff,"Transform:\n"); - fprintf(ff,"%f %f %f %f \n",m->GetElement(0,0), m->GetElement(1,0), m->GetElement(2,0), m->GetElement(3,0) ); - fprintf(ff,"%f %f %f %f \n",m->GetElement(0,1), m->GetElement(1,1), m->GetElement(2,1), m->GetElement(3,1) ); - fprintf(ff,"%f %f %f %f \n",m->GetElement(0,2), m->GetElement(1,2), m->GetElement(2,2), m->GetElement(3,2) ); - fprintf(ff,"%f %f %f %f\n\n",m->GetElement(0,3), m->GetElement(1,3), m->GetElement(2,3), m->GetElement(3,3) ); - fclose(ff); - } else { // else ff - printf("TransformWidgetPanel::OnSave ...Error... creating file \n"); - } //ff + Save( filename ); } // dialog box } +void TransformWidgetPanel::Load(std::string filename) +{ + FILE *ff; + ff = fopen( filename.c_str() , "r" ); + if (ff!=NULL) + { + char tmpStr[128]; + float t0,t1,t2,t3; + fscanf(ff,"%s\n",tmpStr); // ActualPoint: + fscanf(ff,"%f %f %f\n",&t0,&t1,&t2); + mActualPoint[0]=t0; + mActualPoint[1]=t1; + mActualPoint[2]=t2; + + vtkMatrix4x4 *m = t->GetMatrix(); + fscanf(ff,"%s\n",tmpStr); // Transform: + fscanf(ff,"%f %f %f %f\n",&t0,&t1,&t2,&t3); + m->SetElement(0,0,t0); + m->SetElement(1,0,t1); + m->SetElement(2,0,t2); + m->SetElement(3,0,t3); + fscanf(ff,"%f %f %f %f\n",&t0,&t1,&t2,&t3); + m->SetElement(0,1,t0); + m->SetElement(1,1,t1); + m->SetElement(2,1,t2); + m->SetElement(3,1,t3); + fscanf(ff,"%f %f %f %f\n",&t0,&t1,&t2,&t3); + m->SetElement(0,2,t0); + m->SetElement(1,2,t1); + m->SetElement(2,2,t2); + m->SetElement(3,2,t3); + fscanf(ff,"%f %f %f %f\n",&t0,&t1,&t2,&t3); + m->SetElement(0,3,t0); + m->SetElement(1,3,t1); + m->SetElement(2,3,t2); + m->SetElement(3,3,t3); + t->Update(); + + mBox->bbSetOutputActualPoint( mActualPoint ); + mBox->bbSignalOutputModification(std::string("ActualPoint")); + mBox->bbSetOutputOut( t ); + mBox->bbSignalOutputModification(std::string("Out")); + + fclose(ff); + } else { // else ff + printf("TransformWidgetPanel::OnLoad ...Error... reading file \n"); + } //ff +} + void TransformWidgetPanel::OnLoad(wxCommandEvent& event) { wxFileDialog* FD = new wxFileDialog( 0, - _T("Load groups of points .."), + _T("Load configuration.."), _T(""), _T(""), _T("(*.fpConf)|*.fpConf"), @@ -456,53 +512,8 @@ void TransformWidgetPanel::OnLoad(wxCommandEvent& event) if (FD->GetReturnCode()==wxID_OK) { std::string filename= (const char*) ( FD->GetPath().mb_str() ); - FILE *ff; - ff = fopen( filename.c_str() , "r" ); - if (ff!=NULL) - { - char tmpStr[128]; - float t0,t1,t2,t3; - fscanf(ff,"%s\n",tmpStr); // ActualPoint: - fscanf(ff,"%f %f %f\n",&t0,&t1,&t2); - mActualPoint[0]=t0; - mActualPoint[1]=t1; - mActualPoint[2]=t2; - - vtkMatrix4x4 *m = t->GetMatrix(); - fscanf(ff,"%s\n",tmpStr); // Transform: - fscanf(ff,"%f %f %f %f\n",&t0,&t1,&t2,&t3); - m->SetElement(0,0,t0); - m->SetElement(1,0,t1); - m->SetElement(2,0,t2); - m->SetElement(3,0,t3); - fscanf(ff,"%f %f %f %f\n",&t0,&t1,&t2,&t3); - m->SetElement(0,1,t0); - m->SetElement(1,1,t1); - m->SetElement(2,1,t2); - m->SetElement(3,1,t3); - fscanf(ff,"%f %f %f %f\n",&t0,&t1,&t2,&t3); - m->SetElement(0,2,t0); - m->SetElement(1,2,t1); - m->SetElement(2,2,t2); - m->SetElement(3,2,t3); - fscanf(ff,"%f %f %f %f\n",&t0,&t1,&t2,&t3); - m->SetElement(0,3,t0); - m->SetElement(1,3,t1); - m->SetElement(2,3,t2); - m->SetElement(3,3,t3); - t->Update(); - - mBox->bbSetOutputActualPoint( mActualPoint ); - mBox->bbSignalOutputModification(std::string("ActualPoint")); - mBox->bbSetOutputOut( t ); - mBox->bbSignalOutputModification(std::string("Out")); - - fclose(ff); - } else { // else ff - printf("TransformWidgetPanel::OnLoad ...Error... reading file \n"); - } //ff + Load( filename ); } // dialog box - } @@ -555,6 +566,22 @@ BBTK_BLACK_BOX_IMPLEMENTATION(TransformWidget2,bbtk::WxBlackBox); //===== // 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 TransformWidget2::Save(std::string filename) +{ + TransformWidgetPanel *w = (TransformWidgetPanel*) bbGetOutputWidget( ); + w->Save(filename); +} + +//------------------------------------------------------ +void TransformWidget2::Load(std::string filename) +{ + TransformWidgetPanel *w = (TransformWidgetPanel*) bbGetOutputWidget( ); + w->Load(filename); +} + +//------------------------------------------------------ void TransformWidget2::Process() { TransformWidgetPanel *w = (TransformWidgetPanel*) bbGetOutputWidget( ); @@ -563,6 +590,7 @@ void TransformWidget2::Process() { firsttime=false; w->_OnSetPoint(); + bbSetOutputBox_TransformWidget2(this); }// if } @@ -582,6 +610,7 @@ void TransformWidget2::bbUserSetDefaultValues() { firsttime=true; bbSetInputType(1); + bbSetOutputBox_TransformWidget2(NULL); } //===== diff --git a/bbtk/src/bbcreaMaracasVisuTransformWidget2.h b/bbtk/src/bbcreaMaracasVisuTransformWidget2.h index 1e2e884..f77236d 100644 --- a/bbtk/src/bbcreaMaracasVisuTransformWidget2.h +++ b/bbtk/src/bbcreaMaracasVisuTransformWidget2.h @@ -25,7 +25,10 @@ class bbcreaMaracasVisu_EXPORT TransformWidget2 BBTK_DECLARE_INPUT(PossiblePoint,std::vector< double >); BBTK_DECLARE_OUTPUT(Out,vtkLinearTransform *); BBTK_DECLARE_OUTPUT(ActualPoint,std::vector< double >); + BBTK_DECLARE_OUTPUT(Box_TransformWidget2,TransformWidget2*); BBTK_PROCESS(Process); + void Save(std::string filename); + void Load(std::string filename); void Process(); BBTK_CREATE_WIDGET(CreateWidget); void CreateWidget(wxWindow*); @@ -44,6 +47,7 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(TransformWidget2,bbtk::WxBlackBox); BBTK_INPUT(TransformWidget2,PossiblePoint,"Potential Point [x y z]",std::vector,""); BBTK_OUTPUT(TransformWidget2,Out,"vtkTransform result",vtkLinearTransform *,""); BBTK_OUTPUT(TransformWidget2,ActualPoint,"Origin [x,y,z]",std::vector,""); + BBTK_OUTPUT(TransformWidget2,Box_TransformWidget2,"bbtk box TransformWidget2",TransformWidget2*,""); BBTK_END_DESCRIBE_BLACK_BOX(TransformWidget2); //===== // 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/src/bbcreaMaracasVisuTransformWidget2_tool.cxx b/bbtk/src/bbcreaMaracasVisuTransformWidget2_tool.cxx new file mode 100644 index 0000000..ed2c15d --- /dev/null +++ b/bbtk/src/bbcreaMaracasVisuTransformWidget2_tool.cxx @@ -0,0 +1,86 @@ +//===== +// 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) +//===== +#include "bbcreaMaracasVisuTransformWidget2_tool.h" +#include "bbcreaMaracasVisuPackage.h" +namespace bbcreaMaracasVisu +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TransformWidget2_tool) +BBTK_BLACK_BOX_IMPLEMENTATION(TransformWidget2_tool,bbtk::AtomicBlackBox); +//===== +// 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 TransformWidget2_tool::Process() +{ + +// THE MAIN PROCESSING METHOD BODY +// Here we simply set the input 'In' value to the output 'Out' +// And print out the output value +// INPUT/OUTPUT ACCESSORS ARE OF THE FORM : +// void bbSet{Input|Output}NAME(const TYPE&) +// const TYPE& bbGet{Input|Output}NAME() const +// Where : +// * NAME is the name of the input/output +// (the one provided in the attribute 'name' of the tag 'input') +// * TYPE is the C++ type of the input/output +// (the one provided in the attribute 'type' of the tag 'input') +// bbSetOutputOut( bbGetInputIn() ); +// std::cout << "Output value = " <Save( bbGetInputParam01()[0] ); + } + } // Type 1 Save + if (bbGetInputType()==2) + { + if (bbGetInputParam01().size()==1) + { + bbGetInputBox_TransformWidget2()->Load( bbGetInputParam01()[0] ); + } + } // Type 2 Load + +} +//===== +// 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 TransformWidget2_tool::bbUserSetDefaultValues() +{ + +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + bbSetInputType(0); + +} +//===== +// 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 TransformWidget2_tool::bbUserInitializeProcessing() +{ + +// THE INITIALIZATION METHOD BODY : +// Here does nothing +// but this is where you should allocate the internal/output pointers +// if any + + +} +//===== +// 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 TransformWidget2_tool::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbcreaMaracasVisu + + diff --git a/bbtk/src/bbcreaMaracasVisuTransformWidget2_tool.h b/bbtk/src/bbcreaMaracasVisuTransformWidget2_tool.h new file mode 100644 index 0000000..e314c80 --- /dev/null +++ b/bbtk/src/bbcreaMaracasVisuTransformWidget2_tool.h @@ -0,0 +1,53 @@ +//===== +// 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) +//===== +#ifndef __bbcreaMaracasVisuTransformWidget2_tool_h_INCLUDED__ +#define __bbcreaMaracasVisuTransformWidget2_tool_h_INCLUDED__ + +#include "bbcreaMaracasVisu_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + +#include "bbcreaMaracasVisuTransformWidget2.h" + + +namespace bbcreaMaracasVisu +{ + +class bbcreaMaracasVisu_EXPORT TransformWidget2_tool + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(TransformWidget2_tool,bbtk::AtomicBlackBox); +//===== +// 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(Type,int); + BBTK_DECLARE_INPUT(Param01,std::vector); + BBTK_DECLARE_INPUT(Box_TransformWidget2,TransformWidget2*); +// BBTK_DECLARE_OUTPUT(Out,double); + BBTK_PROCESS(Process); + void Process(); +//===== +// 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(TransformWidget2_tool,bbtk::AtomicBlackBox); + BBTK_NAME("TransformWidget2_tool"); + BBTK_AUTHOR("InfoDev"); + BBTK_DESCRIPTION("No Description."); + BBTK_CATEGORY("empty"); + BBTK_INPUT(TransformWidget2_tool,Type,"(default 0) 0:Nothing 1:Save file configuration 2:Load file configuration",int,""); + BBTK_INPUT(TransformWidget2_tool,Param01,"1:[FileName_save] 2:[FileName_load]",std::vector,""); + BBTK_INPUT(TransformWidget2_tool,Box_TransformWidget2,"bbtk Box TransformWidget2",TransformWidget2*,""); +// BBTK_OUTPUT(TransformWidget2_tool,Out,"First output",double,""); +BBTK_END_DESCRIBE_BLACK_BOX(TransformWidget2_tool); +//===== +// 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) +//===== +} +// EO namespace bbcreaMaracasVisu + +#endif // __bbcreaMaracasVisuTransformWidget2_tool_h_INCLUDED__ + diff --git a/bbtk/src/bbmaracasvisuSliderMinMax.cxx b/bbtk/src/bbmaracasvisuSliderMinMax.cxx index e9cc90a..6b432f4 100644 --- a/bbtk/src/bbmaracasvisuSliderMinMax.cxx +++ b/bbtk/src/bbmaracasvisuSliderMinMax.cxx @@ -110,12 +110,13 @@ void SliderMinMax::Process() if (mwxwidget!=NULL) { mwxwidget -> setRepresentedValues( bbGetInputInMin(), bbGetInputInMax() ); - if (firsttime==true) - { - firsttime=false; +// if (firsttime==true) +// { +// firsttime=false; mwxwidget -> SetStart(bbGetInputInMinShow()); - mwxwidget -> SetEnd(bbGetInputInMaxShow()); - } + mwxwidget -> SetEnd(bbGetInputInMaxShow()); +// } + bbSetOutputOutStart(mwxwidget->GetStart()); bbSetOutputOutEnd(mwxwidget->GetEnd()); bbSetOutputOutActual(mwxwidget->GetActual()); -- 2.47.1