X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkComplexBlackBox.cxx;h=f692435687233e6a03f5e17e4d707929ef96f449;hb=551b02f0819a98e9595a81570b1d1174f398f34d;hp=dbd76efd197b83a0a697152a58ce75743c09934e;hpb=c2a4b1893412e50a3d9abff221938a2d16c4a7cb;p=bbtk.git diff --git a/kernel/src/bbtkComplexBlackBox.cxx b/kernel/src/bbtkComplexBlackBox.cxx index dbd76ef..f692435 100644 --- a/kernel/src/bbtkComplexBlackBox.cxx +++ b/kernel/src/bbtkComplexBlackBox.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkComplexBlackBox.cxx,v $ Language: C++ -Date: $Date: 2008/04/09 11:16:57 $ -Version: $Revision: 1.9 $ +Date: $Date: 2008/04/24 11:49:59 $ +Version: $Revision: 1.19 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -29,19 +29,37 @@ PURPOSE. See the above copyright notices for more information. 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(\"" + < ComplexBlackBox::ComplexBlackBox(\"" <first<<"\""<second->bbClone(i->second->bbGetName()); + bbtkDebugMessageInc("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); + bbtkDebugMessage("object",3, + "<## ComplexBlackBox::ComplexBlackBox(\"" + <GetFullName()<<"\""<first<<"\""<second->bbDelete(); - bbtkDebugDecTab("Kernel",1); - } - bbtkDebugDecTab("Kernel",1); - - bbtkDebugMessage("Kernel",1,"EO ComplexBlackBox::~ComplexBlackBox [" - < ComplexBlackBox::~ComplexBlackBox() [" + < Releasing connections"< Releasing boxes"<bbDesallocateConnectors(); - bbtkDebugDecTab("Kernel",1); + + bbtkDebugMessage("object",3, + "<== ComplexBlackBox::~ComplexBlackBox() [" + <GetInputDescriptorMap(); @@ -161,7 +172,6 @@ namespace bbtk ->bbGetInputConnectorMap()[ d->GetInput() ]; bbGetInputConnectorMap()[i->second->GetName()] = c; -//new BlackBoxInputConnector(); } // Output connectors @@ -181,8 +191,8 @@ namespace bbtk ->bbGetOutputConnectorMap()[ d->GetOutput() ]; bbGetOutputConnectorMap()[o->second->GetName()] = c; - //new BlackBoxOutputConnector(); } + bbtkDebugDecTab("Kernel",8); } //========================================================================= @@ -209,18 +219,14 @@ namespace bbtk //========================================================================= //======================================================================= - BlackBox* ComplexBlackBox::bbClone(const std::string& name) + BlackBox::Pointer ComplexBlackBox::bbClone(const std::string& name) { bbtkDebugMessageInc("Kernel",9, "ComplexBlackBox::bbClone(\""<Reference(); - - bbtkDebugDecTab("Kernel",9); - - return CBB; + return MakeBlackBoxPointer(CBB); } //======================================================================= @@ -229,8 +235,8 @@ namespace bbtk /// Executes the box so that its outputs are up-to-date on exit void ComplexBlackBox::bbExecute(bool force) { - bbtkDebugMessageInc("Process",1, - "ComplexBlackBox::bbExecute() [" + bbtkDebugMessageInc("process",2, + "=> 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); @@ -259,8 +265,6 @@ namespace bbtk Wx::EndBusyCursor(); - - bbtkDebugDecTab("Process",1); } //================================================================== @@ -268,15 +272,17 @@ namespace bbtk //================================================================== void ComplexBlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c) { - bbtkDebugMessage("Process",3, - "ComplexBlackBox::bbSetModifiedStatus(" + bbtkDebugMessage("modified",1, + "==> ComplexBlackBox::bbSetModifiedStatus(" <GetBlackBox()->bbSetModifiedStatus(c); - bbtkDebugMessage("Process",3, - "EO ComplexBlackBox::bbSetModifiedStatus(" + /* + bbtkDebugMessage("modified",1, + "<== ComplexBlackBox::bbSetModifiedStatus(" < ComplexBlackBox::bbBackwardUpdate(" <<(caller?caller->GetFullName():"0")<<") [" <GetBlackBoxFrom()->bbGetFullName() + <<"."<GetBlackBoxFromOutput()<<"----" + <GetOriginalBlackBoxFrom()->bbGetFullName() + <<"."<GetOriginalBlackBoxFromOutput()<second; // Get the internal box - BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() ); + BlackBox::Pointer b = bbUnsafeGetBlackBox ( d->GetTarget() ); // Calls BackwardUpdate on it - bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<GetTarget()<GetTarget()<GetFullName()<<"' does not point to a valid output of the complex box !"); } - bbtkDebugDecTab("Process",1); - - bbSetExecuting(false); return s; - */ - return UPTODATE; + } //================================================================== @@ -468,24 +471,31 @@ 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()); + + bbtkDebugMessage("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()); + + bbtkDebugMessage("connection",2," - Target = "<GetTarget()<<" = "<bbGetFullName()<SetBlackBoxFrom(t); c->SetBlackBoxFromOutput(d->GetOutput()); + + bbtkDebugMessage("connection",2," - New conn = "<GetFullName()<bbConnectOutput(d->GetOutput(),c); - bbtkMessage("Debug",1,"ComplexBlackBox["<GetFullName()<GetFullName()<<") [" + <bbGetName() @@ -529,7 +545,7 @@ namespace bbtk bbtkError("a black box called \""<bbGetName() <<"\" already exists"); } - b->bbSetParent(this); + b->bbSetParent(GetThisPointer()); mBlackBoxMap[b->bbGetName()] = b; bbtkDebugDecTab("Kernel",7); @@ -538,14 +554,14 @@ namespace bbtk //================================================================== /// Adds the black box to the complex box (unsafe) - void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox* b) + void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox::Pointer b) { bbtkDebugMessageInc("Kernel",7, "ComplexBlackBox::UnsafeAddBlackBox(\""<bbGetName() <<"\") [" <bbSetParent(this); + b->bbSetParent(GetThisPointer()); mBlackBoxMap[b->bbGetName()] = b; bbtkDebugDecTab("Kernel",7); @@ -554,13 +570,39 @@ namespace bbtk //================================================================== /// 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(\""< : 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(\""<"); @@ -679,11 +721,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!="") @@ -737,7 +775,9 @@ 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 ); @@ -778,14 +818,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 +849,7 @@ namespace bbtk } std::string boxname="["+bbGetTypeName()+"]"; - if (this!=parentblackbox) + if (GetThisPointer()!=parentblackbox) { if (detail==0) { @@ -916,7 +956,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 +985,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 +1006,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 +1026,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 +1034,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 +1080,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; + } + //========================================================================== + }