X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkComplexBlackBox.cxx;h=195b53a222040423bd4389139ebaf3fde5e904ef;hb=16993e9f411c62e9a73d13c40f3748bdd232ce09;hp=a3d2ce3e2acaec4c995da3e7caaabd1ff09415f1;hpb=51be19a0b4d980ef0bdcbbfc5c8255d811de1883;p=bbtk.git diff --git a/kernel/src/bbtkComplexBlackBox.cxx b/kernel/src/bbtkComplexBlackBox.cxx index a3d2ce3..195b53a 100644 --- a/kernel/src/bbtkComplexBlackBox.cxx +++ b/kernel/src/bbtkComplexBlackBox.cxx @@ -1,47 +1,84 @@ +/* + # --------------------------------------------------------------------- + # + # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image + # pour la SantÈ) + # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton + # Previous Authors : Laurent Guigues, Jean-Pierre Roux + # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil + # + # This software is governed by the CeCILL-B license under French law and + # abiding by the rules of distribution of free software. You can use, + # modify and/ or redistribute the software under the terms of the CeCILL-B + # license as circulated by CEA, CNRS and INRIA at the following URL + # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + # or in the file LICENSE.txt. + # + # As a counterpart to the access to the source code and rights to copy, + # modify and redistribute granted by the license, users are provided only + # with a limited warranty and the software's author, the holder of the + # economic rights, and the successive licensors have only limited + # liability. + # + # The fact that you are presently reading this means that you have had + # knowledge of the CeCILL-B license and that you accept its terms. + # ------------------------------------------------------------------------ */ + + /*========================================================================= - -Program: bbtk -Module: $RCSfile: bbtkComplexBlackBox.cxx,v $ -Language: C++ -Date: $Date: 2008/02/06 10:53:02 $ -Version: $Revision: 1.3 $ - -Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de -l'Image). All rights reserved. See Doc/License.txt or -http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notices for more information. - + Program: bbtk + Module: $RCSfile: bbtkComplexBlackBox.cxx,v $ + Language: C++ + Date: $Date: 2012/11/16 08:49:01 $ + Version: $Revision: 1.33 $ =========================================================================*/ + /** * \file * \brief class bbtk::ComplexBlackBox : user defined complex black boxes */ #include "bbtkComplexBlackBox.h" -#include "bbtkBlackBoxDescriptor.h" -#include "bbtkFactory.h" +#include "bbtkWx.h" +//#include "bbtkBlackBoxDescriptor.h" +//#include "bbtkFactory.h" #include "bbtkConfigurationFile.h" namespace bbtk { + //========================================================================== + /// Creates a new complex black box + ComplexBlackBox::Pointer ComplexBlackBox::New(const std::string& name, + ComplexBlackBoxDescriptor::Pointer desc) + { + bbtkDebugMessage("object",1,"##> ComplexBlackBox::New('"<GetTypeName()<<"')" <GetTypeName()<<"')" < ComplexBlackBox(\"" + < ComplexBlackBox(\"" <first<<"\""<second->bbClone(i->second->bbGetName()); + bbtkBlackBoxDebugMessage("object",5," * Cloning \""<first<<"\""<second->bbClone(i->second->bbGetName()); bbUnsafeAddBlackBox(B); - - bbtkDebugDecTab("Kernel",9); } - bbtkDebugDecTab("Kernel",9); - bbtkDebugMessageInc("Kernel",9,"* Cloning Connections"<GetFullName()<<"\""<GetFullName()<<"\""<GetBlackBoxFrom()->bbGetName() ); - BlackBox* bbto = bbGetBlackBox( (*j)->GetBlackBoxTo()->bbGetName() ); - Connection* c = /*mDescriptor->GetFactory()->Create*/ + BlackBox::Pointer bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() ); + BlackBox::Pointer bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() ); + + Connection::Pointer c = mDescriptor.lock()->GetFactory()-> NewConnection( bbfrom, - (*j)->GetBlackBoxFromOutput(), + (*j)->GetOriginalBlackBoxFromOutput(), bbto, - (*j)->GetBlackBoxToInput() ); + (*j)->GetOriginalBlackBoxToInput() ); + //c->Check(); bbAddConnection(c); - bbtkDebugDecTab("Kernel",9); } - bbtkDebugDecTab("Kernel",9); bbAllocateConnectors(); - bbtkDebugDecTab("Kernel",9); + bbtkBlackBoxDebugMessage("object",3, + "<## ComplexBlackBox(\"" + < ~ComplexBlackBox()" + <GetFullName()<<"\""<bbDesallocateConnectors(); - - bbtkDebugMessageInc("Kernel",9,"* Delete Black Boxes"<first<<"\""<second->bbDelete(); - bbtkDebugDecTab("Kernel",9); - } - bbtkDebugDecTab("Kernel",9); - // bbtkDebugMessage("Kernel",9,"EO ComplexBlackBox::~ComplexBlackBox [" - // <bbDesallocateConnectors(); - bbtkDebugDecTab("Kernel",9); + //======================================================================= + /// Clear + void ComplexBlackBox::Clear() + { + bbtkBlackBoxDebugMessage("object",3, + "==> ComplexBlackBox::Clear()" + < Releasing connections"< Releasing boxes"< ComplexBlackBox::bbAllocateConnectors()" <GetInputDescriptorMap(); BlackBoxDescriptor::InputDescriptorMapType::const_iterator i; for ( i = imap.begin(); i != imap.end(); ++i ) { - bbtkDebugMessage("Kernel",8,"* Allocate \""<first<<"\""<first<<"\""<bbGetInputConnectorMap()[ d->GetInput() ]; bbGetInputConnectorMap()[i->second->GetName()] = c; -//new BlackBoxInputConnector(); } // Output connectors @@ -169,7 +212,7 @@ namespace bbtk BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o; for ( o = omap.begin(); o != omap.end(); ++o ) { - bbtkDebugMessage("Kernel",8,"* Allocate \""<first<<"\""<first<<"\""<bbGetOutputConnectorMap()[ d->GetOutput() ]; bbGetOutputConnectorMap()[o->second->GetName()] = c; - //new BlackBoxOutputConnector(); } - bbtkDebugDecTab("Kernel",8); - } + bbtkBlackBoxDebugMessage("kernel",8, + "<== ComplexBlackBox::bbAllocateConnectors()" + < ComplexBlackBox::DesallocateConnectors()" < ComplexBlackBox::bbClone(\""< ComplexBlackBox::bbExecute()" + < Executing '"<<*i<<"'"< Executing '"<<*i<<"'"<bbExecute(force); } } else { - std::map::iterator i; + std::map::iterator i; for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i) { i->second->bbExecute(force); } } - - wx::EndBusyCursor(); - - bbtkDebugDecTab("Process",1); + bbtkBlackBoxDebugMessage("process",2, + "<** ComplexBlackBox::bbExecute()" + <GetBlackBox()->bbSetModifiedStatus(c); - - bbtkDebugMessage("Process",3, - "EO ComplexBlackBox::bbSetModifiedStatus(" - <GetFullName()<<") [" - <GetOutputDescriptorMap(); - BlackBoxDescriptor::OutputDescriptorMapType::const_iterator i - = omap.find(caller->GetBlackBoxFromOutput()); - if (i!=omap.end()) - { - // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor - ComplexBlackBoxOutputDescriptor* d = - (ComplexBlackBoxOutputDescriptor*)i->second; - // Get the internal box - BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() ); - // Calls BackwardUpdate on it - bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<GetTarget()<bbBackwardUpdate(caller); - // ??? STATUS OF CBBs ??? - // ??? Here it is only the final status of the boxes connected to the output - if (s1==MODIFIED) s=MODIFIED; - bbtkDebugDecTab("Process",2); - } - else - { - bbtkError("Connection '"<GetFullName()<<"' does not point to a valid output of the complex box !"); - } - bbtkDebugDecTab("Process",1); - return s; - } - //================================================================== - - /* - //================================================================== - void ComplexBlackBox::bbForwardUpdate(Connection* caller) - { - bbtkDebugMessageInc("Process",1, - "ComplexBlackBox::bbForwardUpdate("<GetFullName()<<") [" - <GetInputDescriptorMap(); - BlackBoxDescriptor::InputDescriptorMapType::const_iterator i - = imap.find(caller->GetBlackBoxToInput()); - if (i!=imap.end()) - { - // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor - ComplexBlackBoxInputDescriptor* d = - (ComplexBlackBoxInputDescriptor*)i->second; - // Get the internal box - BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() ); - // Calls ForwardUpdate on it - bbtkDebugMessage("Process",2,"-> Internal box connected to input : "<GetTarget()<bbForwardUpdate(caller); - } - else - { - bbtkError("Connection '"<GetFullName()<<"' does not point to a valid input of the complex box !"); - } - bbtkDebugDecTab("Process",1); + <GetTarget())->bbGetOutput(d->GetOutput()); - - bbtkDebugDecTab("Data",7); return p; } //================================================================== @@ -383,9 +344,9 @@ namespace bbtk /// Gets the input Data of a given name Data ComplexBlackBox::bbGetInput( const std::string &name ) { - bbtkDebugMessageInc("Data",7, - "ComplexBlackBox::bbGetInput(\""<GetTarget())->bbGetInput(d->GetInput()); - bbtkDebugDecTab("Data",7); return p; } //================================================================== @@ -402,9 +362,9 @@ namespace bbtk /// Sets the data of the output called void ComplexBlackBox::bbSetOutput( const std::string &name, Data data) { - bbtkDebugMessageInc("Data",7, - "ComplexBlackBox::bbSetOutput(\""<GetTarget())->bbSetOutput(d->GetOutput(),data); - bbtkDebugDecTab("Data",7); } //================================================================== @@ -421,16 +380,15 @@ namespace bbtk void ComplexBlackBox::bbSetInput( const std::string &name, Data data, bool setModified) { - bbtkDebugMessageInc("Data",7, - "ComplexBlackBox::bbSetInput(\""<GetInputDescriptor(name); bbGetBlackBox(d->GetTarget())->bbSetInput(d->GetInput(),data,setModified); - bbtkDebugDecTab("Data",7); } //================================================================== @@ -441,10 +399,10 @@ namespace bbtk void* data, bool setModified) { - bbtkDebugMessageInc("Data",7, + bbtkBlackBoxDebugMessage("data",7, "ComplexBlackBox::bbBruteForceSetInputPointer('" - <GetInputDescriptor(name); @@ -453,83 +411,166 @@ namespace bbtk data, setModified); - bbtkDebugDecTab("Data",7); } //================================================================== + //========================================================================= + /// Connects the input to the connection c + void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c) + { + bbtkBlackBoxDebugMessage("connection",2, + "==> ComplexBlackBox::bbConnectInput(\"" + <GetFullName()<<")" + <GetInputDescriptor(name); + + + BlackBox::Pointer t = bbGetBlackBox(d->GetTarget()); + + bbtkBlackBoxDebugMessage("connection",2," - Target = "<GetTarget()<<" = "<bbGetFullName()<SetBlackBoxTo(t); + c->SetBlackBoxToInput(d->GetInput()); + + bbtkBlackBoxDebugMessage("connection",2," - New conn = "<GetFullName()<bbConnectInput(d->GetInput(),c); + + bbtkBlackBoxDebugMessage("connection",2, + "<== ComplexBlackBox::bbConnectInput(\"" + <GetFullName()<<")" + < to the connection c + void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c) + { + bbtkBlackBoxDebugMessage("connection",2, + "==> ComplexBlackBox::bbConnectOutput(\"" + <GetFullName()<<")" + <GetOutputDescriptor(name); + + BlackBox::Pointer t = bbGetBlackBox(d->GetTarget()); + + bbtkBlackBoxDebugMessage("connection",2," - Target = "<GetTarget()<<" = "<bbGetFullName()<SetBlackBoxFrom(t); + c->SetBlackBoxFromOutput(d->GetOutput()); + + bbtkBlackBoxDebugMessage("connection",2," - New conn = "<GetFullName()<bbConnectOutput(d->GetOutput(),c); + + bbtkBlackBoxDebugMessage("connection",2, + "<== ComplexBlackBox::bbConnectOutput(\"" + <GetFullName()<<")" + <bbGetName() - <<"\") [" - <bbGetName() + <<"\")" + <bbGetName()) ) { bbtkError("a black box called \""<bbGetName() <<"\" already exists"); } - b->bbSetParent(this); + b->bbSetParent(GetThisPointer()); mBlackBoxMap[b->bbGetName()] = b; - bbtkDebugDecTab("Kernel",7); } //================================================================== //================================================================== /// Adds the black box to the complex box (unsafe) - void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox* b) + void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox::Pointer b) { - bbtkDebugMessageInc("Kernel",7, + bbtkBlackBoxDebugMessage("kernel",7, "ComplexBlackBox::UnsafeAddBlackBox(\""<bbGetName() - <<"\") [" - <bbSetParent(this); + b->bbSetParent(GetThisPointer()); mBlackBoxMap[b->bbGetName()] = b; - bbtkDebugDecTab("Kernel",7); } //================================================================== //================================================================== /// Removes the black box from the complex box - void ComplexBlackBox::bbRemoveBlackBox( const std::string& name ) + void ComplexBlackBox::bbRemoveBlackBox( const std::string& name, + bool remove_connections ) { - bbtkDebugMessageInc("Kernel",7, - "ComplexBlackBox::RemoveBlackBox(\""<second; + + if (remove_connections) + { + ConnectionListType::const_iterator j; + for ( j = mConnectionList.begin(); + j != mConnectionList.end(); ++j ) + { + (*j)->Check(); + } + } + if (p.use_count()!=1) + { + bbtkError("the black box \""< - BlackBox* ComplexBlackBox::bbGetBlackBox( const std::string& name ) + BlackBox::Pointer ComplexBlackBox::bbGetBlackBox( const std::string& name ) { - bbtkDebugMessageInc("Kernel",9, - "ComplexBlackBox::GetBlackBox(\""<second; } //================================================================== @@ -545,21 +585,18 @@ namespace bbtk //================================================================== /// Returns the black box with name : does not throw an exception /// if it does not exist but return a null pointer - BlackBox* ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name ) + BlackBox::Pointer ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name ) { - bbtkDebugMessageInc("Kernel",9, - "ComplexBlackBox::UnsafeGetBlackBox(\""<second; } @@ -568,18 +605,16 @@ namespace bbtk //================================================================== void ComplexBlackBox::bbPrintBlackBoxes() { - bbtkDebugMessageInc("Kernel",9, - "ComplexBlackBox::PrintBlackBoxes() [" - <second->bbGetFullName()<second->bbGetFullName()<"); @@ -621,11 +656,7 @@ namespace bbtk } BlackBoxMapType::iterator i = mBlackBoxMap.find(subname); - if ( i == mBlackBoxMap.end() ) - { - blackbox = NULL; - } - else + if ( i != mBlackBoxMap.end() ) { blackbox = i->second; if (restname!="") @@ -645,7 +676,6 @@ namespace bbtk const std::string& output_dir, bool relative_link ) { - std::string directory(output_dir); if (output_dir.length() == 0) @@ -667,10 +697,22 @@ namespace bbtk std::string filename_dot2 ("\"" + filename_dot + "\""); - std::string command1 ("dot -T png -o " - + filename_png2 + " " + filename_dot2); - std::string command1a("dot -T cmap -o " - + filename_cmap2 + " " + filename_dot2); +#ifdef WIN32 + std::string currentexecpath("\"\"" + crea::System::GetDllAppPath("bbtk") +"\\dot_embedded\\dot\""); + std::string command1 (currentexecpath + " -Tpng -o " + filename_png2 + " " + filename_dot2 + "\""); + std::string command1a(currentexecpath + " -T cmap -o " + filename_cmap2 + " " + filename_dot2 + "\""); +#else + #ifdef APPLE + std::string command1 ("dot -Tpng:quartz -o " + filename_png2 + " " + filename_dot2 ); + std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 ); + #else + std::string command1 ("dot -Tpng:cairo -o " + filename_png2 + " " + filename_dot2 ); + std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 ); + #endif +#endif + + + // 1. Generating .dot file FILE *ff; @@ -679,16 +721,20 @@ namespace bbtk fprintf(ff,"rankdir=LR%s\n",";"); fprintf(ff,"node [shape=record]%s\n",";"); - this->bbWriteDotFileBlackBox(ff,this,detail,level, + this->bbWriteDotFileBlackBox(ff, + GetThisPointer(), + detail,level, instanceOrtype, relative_link ); fprintf(ff,"}\n"); fclose(ff); + std::cout<<"JCP bbtkComplexBlackBox.cxx execute1="< png system( command1.c_str() ); // 3. Executing .dot file -> cmap + std::cout<<"JCP bbtkComplexBlackBox.cxx execute2="<\n\n"; // End @@ -720,14 +768,14 @@ namespace bbtk //========================================================================= /// Write Graphviz-dot description in file void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff, - BlackBox *parentblackbox, + BlackBox::Pointer parentblackbox, int detail, int level, bool instanceOrtype, bool relative_link ) { std::string tmp1; std::string valueStr(""); - Package *package = this->bbGetDescriptor()->GetPackage(); + Package::Pointer package = this->bbGetDescriptor()->GetPackage(); if (package!=NULL) { @@ -751,7 +799,7 @@ namespace bbtk } std::string boxname="["+bbGetTypeName()+"]"; - if (this!=parentblackbox) + if (GetThisPointer()!=parentblackbox) { if (detail==0) { @@ -858,7 +906,9 @@ namespace bbtk { if (level>-1) { - j->second->bbWriteDotFileBlackBox(ff,parentblackbox,detail, + j->second->bbWriteDotFileBlackBox(ff, + parentblackbox, + detail, level-1, instanceOrtype, relative_link); @@ -885,7 +935,7 @@ namespace bbtk fprintf(ff,":%s",cbbid->GetName().c_str() ); } fprintf(ff,"->" ); - BlackBox *bb = bbGetBlackBox( cbbid->GetTarget() ); + BlackBox::Pointer bb = bbGetBlackBox( cbbid->GetTarget() ); bb->bbWriteDotInputOutputName(ff,true,detail,level); if (detail==1) { @@ -906,7 +956,7 @@ namespace bbtk { ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second; fprintf(ff," "); - BlackBox *bb = bbGetBlackBox( cbbod->GetTarget() ); + BlackBox::Pointer bb = bbGetBlackBox( cbbod->GetTarget() ); bb->bbWriteDotInputOutputName(ff,false,detail,level); if (detail==1) { @@ -926,7 +976,7 @@ namespace bbtk // Relation from the out side of this ComplexBlackBox with its Inputs - if (this!=parentblackbox) { + if (GetThisPointer()!=parentblackbox) { for ( ii = bbGetInputConnectorMap().begin(); ii != bbGetInputConnectorMap().end(); ++ii ) { @@ -934,31 +984,32 @@ namespace bbtk { Connection* con = ii->second->GetConnection(); if (con!=NULL){ - BlackBox *a=con->GetBlackBoxFrom(); - BlackBox *b=con->GetBlackBoxTo(); + BlackBox::Pointer a=con->GetOriginalBlackBoxFrom(); + BlackBox::Pointer b=con->GetOriginalBlackBoxTo(); fprintf(ff," "); a->bbWriteDotInputOutputName(ff,false,detail,level); if (detail==1) { - fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str()); + fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str()); } fprintf(ff,"->"); b->bbWriteDotInputOutputName(ff,true,detail,level); if (detail==1) { - fprintf(ff,":%s",con->GetBlackBoxToInput().c_str()); + fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str()); } fprintf(ff,"%s\n",";"); } // if con } // if second } // for } // if parentblackbox - } //========================================================================= + + - /* + /* //======================================================================= /// Generates the list of the packages of which its depends @@ -975,4 +1026,97 @@ namespace bbtk } //======================================================================= */ + + //======================================================================= + void ComplexBlackBox::Check(bool recursive) + { + bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this + <<" ["<second->Check(recursive); + } + ConnectionListType::const_iterator j; + for ( j = mConnectionList.begin(); + j != mConnectionList.end(); ++j ) + { + (*j)->Check(); + } + bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this + <<" ["<GetFullTypeName() + ":" + bbGetName(); + } + else + { + return std::string(":") + bbGetName(); + } + } + //========================================================================= + + //========================================================================== + std::string ComplexBlackBox::GetObjectName() const + { + return std::string("ComplexBlackBox '")+bbGetNameWithParent() + +std::string("'"); + } + //========================================================================== + + //========================================================================== + std::string ComplexBlackBox::GetObjectInfo() const + { + std::stringstream i; + i << " - "<second->GetObjectRecursiveSize(); + } + ConnectionListType::const_iterator j; + for ( j = mConnectionList.begin(); + j != mConnectionList.end(); ++j ) + { + s += (*j)->GetObjectRecursiveSize(); + } + return s; + } + //========================================================================== + }