-/*=========================================================================
-
-Program: bbtk
-Module: $RCSfile: bbtkComplexBlackBox.cxx,v $
-Language: C++
-Date: $Date: 2008/04/22 06:59:31 $
-Version: $Revision: 1.13 $
-
-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: 2009/03/30 15:22:51 $
+ Version: $Revision: 1.25 $
=========================================================================*/
+/* ---------------------------------------------------------------------
+
+* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
+* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
+*
+* 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.
+* ------------------------------------------------------------------------ */
+
/**
* \file
* \brief class bbtk::ComplexBlackBox : user defined complex black boxes
*/
#include "bbtkComplexBlackBox.h"
+#include "bbtkWx.h"
#include "bbtkBlackBoxDescriptor.h"
#include "bbtkFactory.h"
#include "bbtkConfigurationFile.h"
<<from.bbGetName()<<"\",\""
<<name<<"\")"<<std::endl);
bbtkDebugMessage("object",4," * Cloning Black Boxes"<<std::endl);
+
+ // We have to make the shared_ptr on this because it is used
+ // in bbUnsafeAddBlackBox !
+ MakeBlackBoxPointer(this,true);
+
BlackBoxMapType::const_iterator i;
for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i )
{
bbtkDebugMessageInc("object",5," * Cloning \""<<i->first<<"\""<<std::endl);
BlackBox::Pointer B = i->second->bbClone(i->second->bbGetName());
bbUnsafeAddBlackBox(B);
-
}
bbtkDebugMessage("object",4," * Cloning Connections"<<std::endl);
bbtkDebugMessage("object",3,
"==> ComplexBlackBox::~ComplexBlackBox() ["
<<bbGetName()<<"]"<<std::endl);
+
+ Clear();
+ this->bbDesallocateConnectors();
+
+ bbtkDebugMessage("object",3,
+ "<== ComplexBlackBox::~ComplexBlackBox() ["
+ <<bbGetName()<<"]"<<std::endl);
+ }
+ //=======================================================================
+
+
+ //=======================================================================
+ /// Clear
+ void ComplexBlackBox::Clear()
+ {
+ bbtkDebugMessage("object",3,
+ "==> ComplexBlackBox::Clear() ["
+ <<bbGetName()<<"]"<<std::endl);
bbtkDebugMessage("object",4,
" -> Releasing connections"<<std::endl);
" -> Releasing boxes"<<std::endl);
mBlackBoxMap.clear();
- /*
- // Clear();
- this->bbDesallocateConnectors();
- if (mLockedDescriptor)
- {
- bbtkMessage("object",3," --> Releasing descriptor"<<std::endl);
- mLockedDescriptor.reset();
- if (!mDescriptor.expired()) BlackBoxDescriptor::Release(mDescriptor);
- }
- */
bbtkDebugMessage("object",3,
- "<== ComplexBlackBox::~ComplexBlackBox() ["
+ "<== ComplexBlackBox::Clear() ["
<<bbGetName()<<"]"<<std::endl);
}
//=======================================================================
-
//=========================================================================
/// Allocates the i/o connectors of the black box
"ComplexBlackBox::bbAllocateConnectors() ["
<<bbGetFullName()<<"]"
<<std::endl);
- /*
+
// Input connectors
const BlackBoxDescriptor::InputDescriptorMapType& imap
= bbGetDescriptor()->GetInputDescriptorMap();
->bbGetInputConnectorMap()[ d->GetInput() ];
bbGetInputConnectorMap()[i->second->GetName()] = c;
-//new BlackBoxInputConnector();
}
// Output connectors
->bbGetOutputConnectorMap()[ d->GetOutput() ];
bbGetOutputConnectorMap()[o->second->GetName()] = c;
- //new BlackBoxOutputConnector();
}
-
-*/
-
+
bbtkDebugDecTab("Kernel",8);
}
//=========================================================================
// but by the internal boxes. Hence **DO NOT** desallocate !
// just clear the maps to avoid that
// BlackBox::bbDesallocateConnectors delete the connectors
-
- /*
- bbGetInputConnectorMap().clear();
+ bbGetInputConnectorMap().clear();
bbGetOutputConnectorMap().clear();
- */
+
bbtkDebugDecTab("Kernel",8);
}
/// 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() ["
<<bbGetFullName()<<"]"<<std::endl);
- Wx::BeginBusyCursor();
+ Wx::BusyCursor wait;
if (mExecutionList.size() != 0)
{
i!=mExecutionList.end();
++i)
{
- bbtkDebugMessage("Process",2," -> Executing '"<<*i<<"'"<<std::endl);
+ bbtkDebugMessage("process",3," -> Executing '"<<*i<<"'"<<std::endl);
mBlackBoxMap[*i]->bbExecute(force);
}
}
}
}
- Wx::EndBusyCursor();
-
-
- bbtkDebugDecTab("Process",1);
-
- }
- //==================================================================
-
- //==================================================================
- void ComplexBlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
- {
- bbtkDebugMessage("Process",3,
- "ComplexBlackBox::bbSetModifiedStatus("
- <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
-
- c->GetBlackBox()->bbSetModifiedStatus(c);
-
- bbtkDebugMessage("Process",3,
- "EO ComplexBlackBox::bbSetModifiedStatus("
- <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
}
//==================================================================
//==================================================================
void ComplexBlackBox::bbAddToExecutionList( const std::string& name )
{
- bbtkDebugMessageInc("Kernel",9,
+ bbtkDebugMessageInc("Kernel",9,
"ComplexBlackBox::bbAddToExecutionList(\""
<<name<<"\") ["
<<bbGetFullName()<<"]"<<std::endl);
-
- mExecutionList.push_back( name );
-
- bbtkDebugDecTab("Kernel",9);
-
- }
- //==================================================================
-
- //==================================================================
- IOStatus ComplexBlackBox::bbBackwardUpdate(Connection::Pointer caller)
- {
- bbtkDebugMessageInc("Process",1,
- "ComplexBlackBox::bbBackwardUpdate("
- <<(caller?caller->GetFullName():"0")<<") ["
- <<bbGetFullName()<<"]"<<std::endl);
- // bbtkInternalError("ComplexBlackBox::bbBackwardUpdate should never be called !");
- if (caller==0)
- {
- bbtkInternalError("ComplexBlackBox::bbBackwardUpdate called with caller=0");
- }
-
- std::cout << "CBB BUP : "<<caller->GetBlackBoxFrom()->bbGetFullName()
- <<"."<<caller->GetBlackBoxFromOutput()<<"----"
- <<caller->GetOriginalBlackBoxFrom()->bbGetFullName()
- <<"."<<caller->GetOriginalBlackBoxFromOutput()<<std::endl;
-
-
-
-
- IOStatus s = UPTODATE;
- const BlackBoxDescriptor::OutputDescriptorMapType& omap
- = bbGetDescriptor()->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::Pointer b = bbUnsafeGetBlackBox ( d->GetTarget() );
- // Calls BackwardUpdate on it
- bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<<d->GetTarget()<<std::endl);
- // Because internal box can also be a complex box we have to
- // temporarily change the connection BlackBoxFromOutput to the
- // mapped one
-
- // std::string oldout = caller->GetBlackBoxFromOutput();
- // std::cout << "oldout = "<<oldout<<std::endl;
- // std::cout << "tmpout = "<<d->GetOutput()<<std::endl;
- // caller->SetBlackBoxFromOutput(d->GetOutput());
- //
- //Connection newcaller(*caller);
- //newcaller.SetBlackBoxFromOutput(d->GetOutput());
- //IOStatus s1 = b->bbBackwardUpdate(&newcaller);
- IOStatus s1 = b->bbBackwardUpdate(caller);
- //newcaller.Clear();
- // restore old output
- // caller->SetBlackBoxFromOutput(oldout);
-
- // ??? 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 '"<<caller->GetFullName()<<"' does not point to a valid output of the complex box !");
- }
- bbtkDebugDecTab("Process",1);
-
- return s;
+ mExecutionList.push_back( name );
+
+ bbtkDebugDecTab("Kernel",9);
}
//==================================================================
//=========================================================================
/// Connects the input <name> to the connection c
- void ComplexBlackBox::bbConnectInput( const std::string& name, Connection::Pointer c)
+ void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
{
bbtkDebugMessage("connection",2,
"==> ComplexBlackBox::bbConnectInput(\""
//=========================================================================
/// Connects the output <name> to the connection c
- void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection::Pointer c)
+ void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
{
bbtkDebugMessage("connection",2,
"==> ComplexBlackBox::bbConnectOutput(\""
const std::string& output_dir,
bool relative_link )
{
-
std::string directory(output_dir);
if (output_dir.length() == 0)
std::string filename_dot2 ("\"" + filename_dot + "\"");
- std::string command1 ("dot -T png -o "
- + filename_png2 + " " + filename_dot2);
+ std::string command1 ("dot -Tpng:quartz -o "
+ + filename_png2 + " " + filename_dot2 );
std::string command1a("dot -T cmap -o "
- + filename_cmap2 + " " + filename_dot2);
+ + filename_cmap2 + " " + filename_dot2 );
// 1. Generating .dot file
FILE *ff;
FILE *ff2;
char c;
ff2=fopen(filename_cmap.c_str(),"r");
- while (!feof(ff2))
- {
- c=fgetc(ff2);
- if (c!=-1)
- {
- (s) << c;
- }
- }
+ if (ff2!=NULL){
+ while (!feof(ff2))
+ {
+ c=fgetc(ff2);
+ if (c!=-1)
+ {
+ (s) << c;
+ } // if
+ } // while
+ } // if ff2
(s) << "</map>\n\n";
// End
{
if (ii->second)
{
- Connection::Pointer con = ii->second->GetConnection();
+ Connection* con = ii->second->GetConnection();
if (con!=NULL){
- BlackBox::Pointer a=con->GetBlackBoxFrom();
- BlackBox::Pointer 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
//=======================================================================
void ComplexBlackBox::Check(bool recursive)
{
- bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this
+ bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
<<" ["<<bbGetFullName()<<"]"<<std::endl);
BlackBoxMapType::const_iterator i;
for ( j = mConnectionList.begin();
j != mConnectionList.end(); ++j )
{
- //(*j)->Check();
+ (*j)->Check();
}
- bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this
+ bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
<<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
}