X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkComplexBlackBox.cxx;h=195b53a222040423bd4389139ebaf3fde5e904ef;hb=f5ee1c433d1c86bc0aa11fdaba7aa891cbad9b8a;hp=dbd76efd197b83a0a697152a58ce75743c09934e;hpb=c2a4b1893412e50a3d9abff221938a2d16c4a7cb;p=bbtk.git diff --git a/kernel/src/bbtkComplexBlackBox.cxx b/kernel/src/bbtkComplexBlackBox.cxx index dbd76ef..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/04/09 11:16:57 $ -Version: $Revision: 1.9 $ - -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()<<"\""<GetOriginalBlackBoxFrom()->bbGetName() ); + BlackBox::Pointer bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() ); - BlackBox* bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() ); - BlackBox* bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() ); - Connection* c = mDescriptor->GetFactory()-> + Connection::Pointer c = mDescriptor.lock()->GetFactory()-> NewConnection( bbfrom, (*j)->GetOriginalBlackBoxFromOutput(), bbto, (*j)->GetOriginalBlackBoxToInput() ); - + //c->Check(); bbAddConnection(c); - bbtkDebugDecTab("Kernel",9); } - bbtkDebugDecTab("Kernel",9); bbAllocateConnectors(); - bbtkDebugDecTab("Kernel",9); + bbtkBlackBoxDebugMessage("object",3, + "<## ComplexBlackBox(\"" + <GetFullName()<<"\""<first<<"\""<second->bbDelete(); - bbtkDebugDecTab("Kernel",1); - } - bbtkDebugDecTab("Kernel",1); - - bbtkDebugMessage("Kernel",1,"EO ComplexBlackBox::~ComplexBlackBox [" - < ~ComplexBlackBox()" + <bbDesallocateConnectors(); - bbtkDebugDecTab("Kernel",1); + + bbtkBlackBoxDebugMessage("object",3, + "<== ~ComplexBlackBox()" + < 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 @@ -170,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(\""<Reference(); - - bbtkDebugDecTab("Kernel",9); - - return CBB; + bbtkBlackBoxDebugMessage("kernel",9, + "<== 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():"0")<<") [" - <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()<GetBlackBoxFromOutput(); - // std::cout << "oldout = "<GetFullName()<<"' does not point to a valid output of the complex box !"); - } - bbtkDebugDecTab("Process",1); - - bbSetExecuting(false); - - return s; - */ - return UPTODATE; + <GetTarget())->bbGetOutput(d->GetOutput()); - - bbtkDebugDecTab("Data",7); return p; } //================================================================== @@ -390,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; } //================================================================== @@ -409,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); } //================================================================== @@ -428,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); } //================================================================== @@ -448,10 +399,10 @@ namespace bbtk void* data, bool setModified) { - bbtkDebugMessageInc("Data",7, + bbtkBlackBoxDebugMessage("data",7, "ComplexBlackBox::bbBruteForceSetInputPointer('" - <GetInputDescriptor(name); @@ -460,7 +411,6 @@ namespace bbtk data, setModified); - bbtkDebugDecTab("Data",7); } //================================================================== @@ -468,24 +418,29 @@ namespace bbtk /// Connects the input to the connection c void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Kernel",7, - "ComplexBlackBox::bbConnectInput(\"" - < ComplexBlackBox::bbConnectInput(\"" + <GetFullName()<<")" + <GetInputDescriptor(name); - BlackBox* t = bbGetBlackBox(d->GetTarget()); + + BlackBox::Pointer t = bbGetBlackBox(d->GetTarget()); + + bbtkBlackBoxDebugMessage("connection",2," - Target = "<GetTarget()<<" = "<bbGetFullName()<SetBlackBoxTo(t); c->SetBlackBoxToInput(d->GetInput()); - t->bbConnectInput(d->GetInput(),c); - bbtkMessage("Debug",1,"ComplexBlackBox["<GetFullName()<GetFullName()<<")" + < to the connection c void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c) { - bbtkDebugMessageInc("Kernel",7, - "ComplexBlackBox::bbConnectOutput(\"" - < ComplexBlackBox::bbConnectOutput(\"" + <GetFullName()<<")" + <GetOutputDescriptor(name); - BlackBox* t = bbGetBlackBox(d->GetTarget()); + 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); - bbtkMessage("Debug",1,"ComplexBlackBox["<GetFullName()<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; } //================================================================== @@ -603,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; } @@ -626,18 +605,16 @@ namespace bbtk //================================================================== void ComplexBlackBox::bbPrintBlackBoxes() { - bbtkDebugMessageInc("Kernel",9, - "ComplexBlackBox::PrintBlackBoxes() [" - <second->bbGetFullName()<second->bbGetFullName()<"); @@ -679,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!="") @@ -703,7 +676,6 @@ namespace bbtk const std::string& output_dir, bool relative_link ) { - std::string directory(output_dir); if (output_dir.length() == 0) @@ -725,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; @@ -737,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 @@ -778,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) { @@ -809,7 +799,7 @@ namespace bbtk } std::string boxname="["+bbGetTypeName()+"]"; - if (this!=parentblackbox) + if (GetThisPointer()!=parentblackbox) { if (detail==0) { @@ -916,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); @@ -943,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) { @@ -964,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) { @@ -984,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 ) { @@ -992,19 +984,19 @@ 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 @@ -1038,7 +1030,7 @@ namespace bbtk //======================================================================= void ComplexBlackBox::Check(bool recursive) { - bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this + bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this <<" ["<Check(); } - bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this + 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; + } + //========================================================================== + }