Program: bbtk
Module: $RCSfile: bbtkBlackBox.cxx,v $
Language: C++
-Date: $Date: 2008/02/20 16:05:38 $
-Version: $Revision: 1.5 $
+Date: $Date: 2008/03/07 08:40:14 $
+Version: $Revision: 1.6 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See doc/license.txt or
// Looks for the adaptor
if (bbGetOutputType(output).name() != typeid(std::string).name() )
{
- BlackBox* a = 0;
- try
+ // Look for factory
+ Package* p = bbGetDescriptor()->GetPackage();
+ if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
{
- a = NewAdaptor(
- bbGetOutputType(output),
- typeid(std::string),
- "");
- } catch (bbtk::Exception e)
+ Factory* f = *p->GetFactorySet().begin();
+ BlackBox* a = 0;
+ try
+ {
+ a = f->NewAdaptor(
+ bbGetOutputType(output),
+ typeid(std::string),
+ "");
+ } catch (bbtk::Exception e)
+ {
+ }
+ if (a!=NULL){
+ // bbUpdate();
+ a->bbSetInput("In",bbGetOutput(output));
+ a->bbExecute();
+ v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
+ } else {
+ v="? (no adaptor found)";
+ }
+ }
+ else
{
+ v="? (no factory found)";
}
- if (a!=NULL){
- // bbUpdate();
- a->bbSetInput("In",bbGetOutput(output));
- a->bbExecute();
- v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
- } else {
- v="? (no adaptor found)";
- }
- } else {
- // bbUpdate();
- v = bbGetOutput(output).unsafe_get<std::string>() ;
- }
+ }
+ else
+ {
+ // bbUpdate();
+ v = bbGetOutput(output).unsafe_get<std::string>() ;
+ }
return v;
}
//=========================================================================
// Looks for the adaptor
if (bbGetInputType(input) != typeid(std::string))
{
- BlackBox* a = 0;
- try
+ // Look for factory
+ Package* p = bbGetDescriptor()->GetPackage();
+ if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
{
- a = NewAdaptor(
- bbGetInputType(input),
- typeid(std::string),
- "");
- }catch (bbtk::Exception e)
- {
- }
- if (a!=NULL)
- {
- // bbUpdate();
- a->bbSetInput("In",bbGetInput(input));
- a->bbExecute();
- v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
+ Factory* f = *p->GetFactorySet().begin();
+ BlackBox* a = 0;
+ try
+ {
+ a = f->NewAdaptor(
+ bbGetInputType(input),
+ typeid(std::string),
+ "");
+ }catch (bbtk::Exception e)
+ {
+ }
+ if (a!=NULL)
+ {
+ // bbUpdate();
+ a->bbSetInput("In",bbGetInput(input));
+ a->bbExecute();
+ v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
+ }
+ else
+ {
+ v="? (no adaptor found)";
+ }
}
else
{
- v="? (no adaptor found)";
+ v="? (no factory found)";
}
- }
+ }
else
{
v = bbGetInput(input).unsafe_get<std::string>() ;
Program: bbtk
Module: $RCSfile: bbtkBlackBoxDescriptor.h,v $
Language: C++
- Date: $Date: 2008/02/06 14:14:22 $
- Version: $Revision: 1.5 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.6 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/// Returns the Package to which the box belongs
Package* GetPackage() { return mPackage; }
- /// Returns the Package to which the box belongs
+ /// Returns the Package to which the box belongs (const pointer)
const Package* GetPackage() const { return mPackage; }
/// Returns the kind of box
Program: bbtk
Module: $RCSfile: bbtkExecuter.cxx,v $ $
Language: C++
- Date: $Date: 2008/02/14 20:57:27 $
- Version: $Revision: 1.12 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ 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
*
*/
Executer::Executer()
- : mPackage(0),
- mRoot(0),
- mNoExecMode(false),
- mDialogMode(NoDialog)
+ :
+ mFactory(0),
+ mRootPackage(0),
+ mRootCBB(0),
+ mNoExecMode(false),
+ mDialogMode(NoDialog)
{
- //VirtualExec();
-
bbtkDebugMessageInc("Kernel",9,"Executer::Executer()" <<std::endl);
+ mFactory = new Factory;
+ mFactory->SetExecuter(this);
Reset();
bbtkDebugDecTab("Kernel",9);
}
*/
Executer::~Executer()
{
-std::cout << "====================================================== delete Executer\n";
+ //std::cout << "===================================== delete Executer\n";
bbtkDebugMessageInc("Kernel",9,"Executer::~Executer()" <<std::endl);
- if (mRoot)
+ if (mRootCBB)
{
- mPackage->UnRegisterBlackBox("workspace");
- delete mRoot;
+ mRootPackage->UnRegisterBlackBox("workspace");
+ delete mRootCBB;
}
- if (mPackage)
+ if (mRootPackage)
{
- GetGlobalFactory()->UnLoadPackage("user");
+ GetFactory()->UnLoadPackage("user");
}
+ delete mFactory;
+
bbtkDebugDecTab("Kernel",9);
}
// all user defined CBB otherwise any instance
// of a user CBB that is in the 'workspace' would try to
// access a user CBB descriptor which has been previously freed
- if (mRoot)
+ if (mRootCBB)
{
- mPackage->UnRegisterBlackBox(mRoot->GetTypeName());
- delete mRoot;
+ mRootPackage->UnRegisterBlackBox(mRootCBB->GetTypeName());
+ delete mRootCBB;
}
- if (mPackage)
+ if (mRootPackage)
{
- GetGlobalFactory()->UnLoadPackage("user");
+ GetFactory()->UnLoadPackage("user");
}
- GetGlobalFactory()->Reset();
+ GetFactory()->Reset();
+
// Create user package
- mPackage = new Package("user","internal to bbi",
+ mRootPackage = new Package("user","internal to bbi",
"User defined black boxes",
"",
BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
// Create user workspace
- mRoot = new ComplexBlackBoxDescriptor("workspace"); //,f);
- mRoot->AddToAuthor("bbi (internal)");
- mRoot->AddToDescription("User's workspace");
- mOpenDefinition.push_back(CBBDefinition(mRoot,"user"));
+ mRootCBB = new ComplexBlackBoxDescriptor("workspace"); //,f);
+ mRootCBB->AddToAuthor("bbi (internal)");
+ mRootCBB->AddToDescription("User's workspace");
+ mOpenDefinition.push_back(CBBDefinition(mRootCBB,"user"));
// Register it into the user package
- mPackage->RegisterBlackBox(mRoot);
+ mRootPackage->RegisterBlackBox(mRootCBB);
// Insert the user package in the factory
- InsertPackage(mPackage);
- mOpenPackage.push_back(mPackage);
+ GetFactory()->InsertPackage(mRootPackage);
+ // And in the list of open packages
+ mOpenPackage.push_back(mRootPackage);
+
bbtkDebugDecTab("Kernel",9);
}
/// changes the workspace name
void Executer::SetWorkspaceName( const std::string& n )
{
- mPackage->ChangeBlackBoxName( mRoot->GetTypeName(), n );
+ mRootPackage->ChangeBlackBoxName( mRootCBB->GetTypeName(), n );
}
void Executer::BeginPackage (const std::string &name)
Package* p;
try
{
- p = GetGlobalFactory()->GetPackage(name);
+ p = GetFactory()->GetPackage(name);
}
catch (Exception e)
{
"",
"",
BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
- InsertPackage(p);
+ GetFactory()->InsertPackage(p);
}
mOpenPackage.push_back(p);
}
Package* p;
std::string pname(mOpenDefinition.back().package);
if (pname.size()>0)
- {
- try
{
- p = GetGlobalFactory()->GetPackage(pname);
+ try
+ {
+ p = GetFactory()->GetPackage(pname);
+ }
+ catch (Exception e)
+ {
+ p = new Package(pname,
+ "",
+ "",
+ "",
+ BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+ GetFactory()->InsertPackage(p);
+ }
}
- catch (Exception e)
+ else
{
- p = new Package(pname,
- "",
- "",
- "",
- BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
- InsertPackage(p);
+ p = mOpenPackage.back();
}
- }
- else
- {
- p = mOpenPackage.back();
- }
p->RegisterBlackBox(Current());
-
+
mOpenDefinition.pop_back();
}
-
+
void Executer::Create ( const std::string& nodeType,
const std::string& nodeName)
void Executer::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ?
{
// if in root
- if (Current()==mRoot)
+ if (Current()==mRootCBB)
{
if (!mNoExecMode)
{
const std::string& help)
{
// If the input is defined in the Root box
- if (Current()==mRoot)
+ if (Current()==mRootCBB)
{
// If the dialog mode is set to NoDialog
// and the user passed the name in the Inputs map
if ( b->bbGetInputType(input) != typeid(std::string) )
{
BlackBox* a =
- NewAdaptor(typeid(std::string),
- b->bbGetInputType(input),
- "tmp");
+ GetFactory()->NewAdaptor(typeid(std::string),
+ b->bbGetInputType(input),
+ "tmp");
if (!a)
- {
- bbtkError("No <"<<
- TypeName(b->bbGetInputType(input))
- <<"> to <std::string> found");
- }
+ {
+ bbtkError("No <"<<
+ TypeName(b->bbGetInputType(input))
+ <<"> to <std::string> found");
+ }
std::string v(value);
a->bbSetInput("In",v);
a->bbExecute();
// Looks for the adaptor
if (b->bbGetOutputType(output) != typeid(std::string))
{
- BlackBox* a =
- NewAdaptor(
- b->bbGetOutputType(output),
- typeid(std::string),
- "tmp");
- if (!a)
- {
- bbtkError("No <"<<
- TypeName(b->bbGetOutputType(output))
- <<"> to <std::string> found");
- }
+ BlackBox* a =
+ GetFactory()->NewAdaptor(
+ b->bbGetOutputType(output),
+ typeid(std::string),
+ "tmp");
+ if (!a)
+ {
+ bbtkError("No <"<<
+ TypeName(b->bbGetOutputType(output))
+ <<"> to <std::string> found");
+ }
b->bbExecute();
-
+
a->bbSetInput("In",b->bbGetOutput(output));
a->bbExecute();
std::string r = a->bbGetOutput("Out").unsafe_get<std::string>();
- //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
- // std::cout << a->bbGetOutput("Out").unsafe_get<std::string>()
- // << std::endl;
- //std::string v(value);
- //b->bbSetInput(input,a->bbGetOutput("Out"));
+ //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
+ // std::cout << a->bbGetOutput("Out").unsafe_get<std::string>()
+ // << std::endl;
+ //std::string v(value);
+ //b->bbSetInput(input,a->bbGetOutput("Out"));
a->bbDelete();
return r;
}
else
{
- b->bbExecute();
- return b->bbGetOutput(output).unsafe_get<std::string>();
- // std::string v = *((std::string*)b->bbGetOutput(output)) ;
- // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>()
- // << std::endl;
- // b->bbSetInput(input,&v);
+ b->bbExecute();
+ return b->bbGetOutput(output).unsafe_get<std::string>();
+ // std::string v = *((std::string*)b->bbGetOutput(output)) ;
+ // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>()
+ // << std::endl;
+ // b->bbSetInput(input,&v);
}
}
void Executer::Author(const std::string &authorName)
{
- Current()->AddToAuthor(authorName,Current()==mRoot);
+ Current()->AddToAuthor(authorName,Current()==mRootCBB);
}
void Executer::Category(const std::string &category)
{
- Current()->AddToCategory(category,Current()==mRoot);
+ Current()->AddToCategory(category,Current()==mRootCBB);
}
void Executer::Description(const std::string &d)
{
- Current()->AddToDescription(d,Current()==mRoot);
+ Current()->AddToDescription(d,Current()==mRootCBB);
}
Package* p;
try
{
- p = GetGlobalFactory()->GetPackage(nameblackbox);
+ p = GetFactory()->GetPackage(nameblackbox);
}
catch (Exception e)
{
- p = mPackage;
+ p = mRootPackage;
}
// Generating documentation-help of workspace
p->SetDocURL(filename_rootHtml);
Program: bbtk
Module: $RCSfile: bbtkExecuter.h,v $ $
Language: C++
- Date: $Date: 2008/02/14 20:26:54 $
- Version: $Revision: 1.9 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.10 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
namespace bbtk
{
+ class Interpreter;
+
+
class /*BBTK_EXPORT*/ Executer : public VirtualExec
{
/// Constructor
Executer();
-
- ///
- // void SetFactory(Factory* f);
-
/// Destructor
~Executer();
+
+ /// Gets the factory used by the executer
+ Factory* GetFactory() { return mFactory; }
+ /// Gets the factory used by the executer (const)
+ const Factory* GetFactory() const { return mFactory; }
+
+
/// Sets the inputs of the workspace :
void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
/// prints the list off the boxes of the current box
void PrintBoxes();
- /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
+ /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
std::string ShowGraph(const std::string &nameblackbox,
const std::string &detailStr,
const std::string &levelStr,
const std::string &custom_title,
bool system_display = true);
- /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
+ /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
/// Description of the actual pipeline
// ATTRIBUTES
/// The factory used
- // Factory* mFactory;
-
- /// The Root Package
- Package* mPackage;
+ Factory* mFactory;
- /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
+
+ /// The Root Package
+ /// Contains the root ComplexBlabkBox
+ /// In which ComplexBlackBoxes are put by default
+ /// Its name in bbi is 'user'
+ Package* mRootPackage;
+
+ /// The root ComplexBlackBox
+ /// in which operations are done when outside a define/endefine block
/// Its name in bbi is 'workspace'
- ComplexBlackBoxDescriptor* mRoot;
+ ComplexBlackBoxDescriptor* mRootCBB;
/// Struct that stores info on user defined complex black boxes
struct CBBDefinition
/// The stack of current working ComplexBlackBox
/// (is a stack for nested definitions)
- /// only contains the root when outside a define/endefine block
+ /// only contains the root cbb when outside a define/endefine block
std::deque<CBBDefinition> mOpenDefinition;
/// The stack of current working package
/// (is a stack for nested definitions)
std::deque<Package*> mOpenPackage;
- /// flag which is true when we are inside a Define/EndDefine block
- // bool mDefineFlag;
-
/// The input values of the Root ComplexBlackBox
std::map<std::string,std::string> mInputs;
Module: $RCSfile: bbtkFactory.cxx,v $
Language: C++
-Date: $Date: 2008/03/04 08:09:04 $
-Version: $Revision: 1.26 $
+Date: $Date: 2008/03/07 08:40:14 $
+Version: $Revision: 1.27 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
#include <cctype> // std::toupper
-// was in gdcm ...
-/*
-#ifdef _MSC_VER
-# define getcwd _getcwd
-#endif
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-# include <direct.h>
-#else
-# include <unistd.h>
-#endif
-
-*/
-
namespace bbtk
{
//===================================================================
/// Default ctor
Factory::Factory()
+ : mExecuter(0)
{
bbtkDebugMessage("Kernel",7,"Factory::Factory()"<<std::endl);
}
// Invokes the accessor to the PackageUnit pointer
pack.mPackage = ((PackageAccessor)getpack)();
- mPackageMap[pkgname] = pack;
-
// Test bbtk build version ok
if ( pack.mPackage->GetBBTKVersion() != bbtk::GetVersion() )
{
<< " whereas application build with version "
<< bbtk::GetVersion());
}
+
+ pack.mPackage->AddFactory(this);
+ mPackageMap[pkgname] = pack;
std::string separator =
ConfigurationFile::GetInstance().Get_file_separator ();
//===================================================================
/// \brief Close the package referenced by the iterator
- ///
- /// If it is a dynamically loaded package
- /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
- /// - Closes the dynamic library
- /// - Erases the package entry in the packages map
- ///
- /// Else simply erases the package entry in the packages map
- void Factory::ClosePackage(PackageMapType::iterator& i)
+ ///
+ /// First removes the factory from the set of factories which use the package
+ /// If the set is empty then :
+ /// If it is a dynamically loaded package :
+ /// - Loads and calls the function "<name>DeletePackage" of the dynamic library (responsible for package desallocation)
+ /// - Closes the dynamic library
+ /// Else :
+ /// - deletes the package normally
+ ///
+ /// Finally erases the package entry in the packages map
+ void Factory::ClosePackage(PackageMapType::iterator& i)
{
bbtkDebugMessageInc("Kernel",7,"Factory::ClosePackage(\""
<<i->second.mPackage->GetName()
<<"\")"<<std::endl);
- if (i->second.mDynamicLibraryHandler)
- {
-
- // If it is a dynamically loaded package
- // Loads the Package delete function
-
- std::string delfname(i->second.mPackage->GetName());
- delfname += "DeletePackage";
+
+ // Removes this from the set of factories which use the package
+ i->second.mPackage->RemoveFactory(this);
+
+ // If no more factory which use it
+ if (i->second.mPackage->GetFactorySet().empty())
+ {
+ // If it is a dynamically loaded package
+ if (i->second.mDynamicLibraryHandler)
+ {
+
+
+ // Loads the Package delete function
+
+ std::string delfname(i->second.mPackage->GetName());
+ delfname += "DeletePackage";
#if defined(__GNUC__)
- void *delf = dlsym(i->second.mDynamicLibraryHandler, delfname.c_str());
- if (!delf)
- {
- bbtkError("could not close package \""
- <<i->second.mPackage->GetName()
- <<"\" :"<<dlerror());
- }
+ void *delf = dlsym(i->second.mDynamicLibraryHandler, delfname.c_str());
+ if (!delf)
+ {
+ bbtkError("could not close package \""
+ <<i->second.mPackage->GetName()
+ <<"\" :"<<dlerror());
+ }
#elif defined(_WIN32)
- void *delf = GetProcAddress(i->second.mDynamicLibraryHandler,
- delfname.c_str());
- if (!delf)
- {
- bbtkError("could not close package \""
- <<i->second.mPackage->GetName()
- <<"\" : "<<delfname
- <<" symbol not found (how did you open it ???");
- //<<"\" :"<<dlerror());
- }
+ void *delf = GetProcAddress(i->second.mDynamicLibraryHandler,
+ delfname.c_str());
+ if (!delf)
+ {
+ bbtkError("could not close package \""
+ <<i->second.mPackage->GetName()
+ <<"\" : "<<delfname
+ <<" symbol not found (how did you open it ???");
+ //<<"\" :"<<dlerror());
+ }
#endif
-
- // deletes the package
- ((PackageDeleteFunction)delf)();
-
- // closes the dl handler
+
+ // deletes the package
+ ((PackageDeleteFunction)delf)();
+
+ // closes the dl handler
#if defined(__GNUC__)
- dlclose(i->second.mDynamicLibraryHandler);
+ dlclose(i->second.mDynamicLibraryHandler);
#elif defined(_WIN32)
-
- FreeLibrary(i->second.mDynamicLibraryHandler);
+
+ FreeLibrary(i->second.mDynamicLibraryHandler);
#endif
- }
- else
- {
- // If it is a manually inserted package
- delete i->second.mPackage;
- }
+ }
- // remove the entry in the map
- mPackageMap.erase(i);
- bbtkDebugDecTab("Kernel",7);
- }
- //===================================================================
+ else
+ {
+ // If it is a manually inserted package : delete it normally
+ delete i->second.mPackage;
+ }
+ }
+
+ // in any cases remove the entry in the map
+ mPackageMap.erase(i);
+ bbtkDebugDecTab("Kernel",7);
+ }
+ //===================================================================
+
//===================================================================
bbtkDebugMessageInc("Kernel",9,"Factory::InsertPackage(\""<<
p->GetName()<<"\")"<<std::endl);
+ p->AddFactory(this);
PackageInfoType pack;
pack.mDynamicLibraryHandler = 0;
-
pack.mPackage = p;
-
mPackageMap[p->GetName()] = pack;
+
bbtkDebugDecTab("Kernel",9);
}
//===================================================================
if (i!=mPackageMap.end())
{
- ClosePackage(i);
+ ClosePackage(i);
}
else
{
- bbtkError("Factory::RemovePackage(\""<<
- p->GetName()<<"\") : package absent from factory");
+ bbtkError("Factory::RemovePackage(\""<<
+ p->GetName()<<"\") : package absent from factory");
}
bbtkDebugDecTab("Kernel",9);
Program: bbtk
Module: $RCSfile: bbtkFactory.h,v $
Language: C++
- Date: $Date: 2008/03/03 14:55:55 $
- Version: $Revision: 1.9 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.10 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See doc/license.txt or
namespace bbtk
{
+
+ class Executer;
+
class BBTK_EXPORT Factory
{
Factory();
~Factory();
-
+
void LoadPackage( const std::string& name );
void UnLoadPackage( const std::string& name );
void PrintPackages(bool details = true, bool adaptors = false) const;
IndexEntryType;
void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
+ /// Sets the executer who created the factory (if any)
+ void SetExecuter(Executer *e) { mExecuter = e; }
+ /// Gets the executer who created the factory (if any)
+ Executer* GetExecuter() { return mExecuter; }
+ /// Gets the executer who created the factory (if any) - const
+ const Executer* GetExecuter() const { return mExecuter; }
+
+
private:
bool DoLoadPackage(std::string libname,
/// The map of packages
PackageMapType mPackageMap;
+ /// The executer which created the factory (if any)
+ Executer* mExecuter;
+
void CloseAllPackages();
void ClosePackage(PackageMapType::iterator& i);
// class Factory
+
+ /*
/// SYSTEM METHOD : Global method returning the global factory object pointer
inline Factory*& GlobalFactoryPointer()
{
{
GetGlobalFactory()->WriteDotFilePackagesList(ff);
}
-
+ */
}// namespace bbtk
Program: bbtk
Module: $RCSfile: bbtkInterpreter.cxx,v $ $
Language: C++
- Date: $Date: 2008/03/03 14:55:55 $
- Version: $Revision: 1.39 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.40 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
namespace bbtk
{
-Interpreter* Interpreter::mGlobalInterpreter = NULL;
+ //Interpreter* Interpreter::mGlobalInterpreter = NULL;
//=======================================================================
/**
*/
Interpreter::Interpreter()
:
+#ifdef _USE_WXWIDGETS_
+ mWxConsole(0),
+#endif
mCommandLine(false)
{
bbtk::MessageManager::RegisterMessageType("Echo","Level>0 : Prints the 'echo' commands of the user.\n\tLevel>1 : Prints the command being interpreted",1);
bbtk::MessageManager::RegisterMessageType("Interpreter","Messages of the interpreter",0);
bbtkDebugMessageInc("Interpreter",9,"Interpreter::Interpreter()" <<std::endl);
- mGlobalInterpreter = this;
-
mExecuter = new bbtk::Executer();
+ mExecuter->SetInterpreter(this);
// For the time being, comment out previous line, and
// uncomment next line to check Transcriptor
std::cout << "=========================================~Interpreter()" << std::endl;
bbtkDebugMessageInc("Interpreter",9,"Interpreter::~Interpreter()" <<std::endl);
delete mExecuter;
- //delete mFactory;
bbtkDebugDecTab("Interpreter",9);
}
// if 'source' was given
if (words.size()==3)
{
- this->mExecuter->SetCurrentFileName(words[1]);
+ GetExecuter()->SetCurrentFileName(words[1]);
}
break;
case cLoad:
- LoadPackage(words[1]);
+ GetExecuter()->GetFactory()->LoadPackage(words[1]);
break;
case cUnload:
- UnLoadPackage(words[1]);
+ GetExecuter()->GetFactory()->UnLoadPackage(words[1]);
break;
case cQuit :
{
if (words[1]=="packages")
{
- PrintPackages(true);
+ GetExecuter()->GetFactory()->PrintPackages(true);
return;
}
try
{
try
{
- HelpPackage(words[1]);
+ GetExecuter()->GetFactory()->HelpPackage(words[1]);
#ifdef _USE_WXWIDGETS_
- if ( WxConsole::GetInstance() != 0 )
+ if ( mWxConsole != 0 )
{
std::string url =
ConfigurationFile::GetInstance().Get_doc_path();
url += "/bbdoc/" + words[1] + "/index.html";
if (Utilities::FileExists(url))
{
- WxConsole::GetInstance()->ShowHtmlPage(url);
+ mWxConsole->ShowHtmlPage(url);
}
}
#endif
try
{
std::string package;
- HelpBlackBox(words[1],package);
+ GetExecuter()->GetFactory()->HelpBlackBox(words[1],package);
#ifdef _USE_WXWIDGETS_
- if ( WxConsole::GetInstance() != 0 )
+ if ( mWxConsole != 0 )
{
std::string url =
ConfigurationFile::GetInstance().Get_doc_path();
if (Utilities::FileExists(url))
{
url += "#" + words[1];
- WxConsole::GetInstance()->ShowHtmlPage(url);
+ mWxConsole->ShowHtmlPage(url);
}
}
#endif
{
try
{
- this->mExecuter->ShowRelations(words[1],"0","9999");
+ GetExecuter()->ShowRelations(words[1],"0","9999");
}
catch (bbtk::Exception h){
bbtkError("\""<<words[1].c_str()
{
if ( words[1]=="packages" )
{
- PrintPackages(true,true);
+ GetExecuter()->GetFactory()->PrintPackages(true,true);
return;
}
try
{
- HelpPackage(words[1],true);
+ GetExecuter()->GetFactory()->HelpPackage(words[1],true);
}
catch (bbtk::Exception f)
{
bool system_display = true;
#ifdef _USE_WXWIDGETS_
- if ( WxConsole::GetInstance() != 0 ) system_display = false;
+ if ( mWxConsole != 0 ) system_display = false;
#endif
if (words.size()==1)
}
#ifdef _USE_WXWIDGETS_
- if ( WxConsole::GetInstance() != 0 )
- WxConsole::GetInstance()->ShowHtmlPage(page);
+ if ( mWxConsole != 0 )
+ mWxConsole->ShowHtmlPage(page);
#endif
}
//=======================================================================
else if (type=="Packages") t = Factory::Packages;
else if (type=="Adaptors") t = Factory::Adaptors;
- GetGlobalFactory()->CreateHtmlIndex(t,filename);
+ GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
}
//=======================================================================
Program: bbtk
Module: $RCSfile: bbtkInterpreter.h,v $ $
Language: C++
- Date: $Date: 2008/03/03 08:06:36 $
- Version: $Revision: 1.12 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ 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
namespace bbtk
{
-
+#ifdef _USE_WXWIDGETS_
+ class WxConsole;
+#endif
+
class BBTK_EXPORT Interpreter
{
/// Destructor
~Interpreter();
- static Interpreter* mGlobalInterpreter;
-
/// Launches a command line interpreter (with a prompt)
void CommandLineInterpreter();
/// Sets the bool that indicates wether we are in command line context
void SetCommandLine(bool v = true) { mCommandLine = v; }
+#ifdef _USE_WXWIDGETS_
+ /// Sets the WxConsole that created the interpreter (if any)
+ void SetWxConsole(WxConsole* c) { mWxConsole = c; }
+ /// Gets the WxConsole that created the interpreter (if any)
+ WxConsole* GetWxConsole() { return mWxConsole; }
+ /// Gets the WxConsole that created the interpreter (if any) - const
+ const WxConsole* GetWxConsole() const { return mWxConsole; }
+#endif
+
+ /// Gets the Executer
+ VirtualExec* GetExecuter() { return mExecuter; }
+ /// Gets the Executer (const)
+ const VirtualExec* GetExecuter() const { return mExecuter; }
private:
//==================================================================
// ATTRIBUTES
- /// The factory
- // bbtk::Factory* mFactory;
-
- /// The command executer
+ /// The command executer used
bbtk::VirtualExec* mExecuter;
+#ifdef _USE_WXWIDGETS_
+ /// The WxConsole which uses the interpreter (0 if none)
+ bbtk::WxConsole* mWxConsole;
+#endif
+
/// Vector of open files
std::vector<std::ifstream*> mFile;
std::deque< char* > mHistory;
};
+ // EO class Interpreter
+
+
+
// The "Quit" exception
Program: bbtk
Module: $RCSfile: bbtkPackage.cxx,v $
Language: C++
- Date: $Date: 2008/02/18 10:41:02 $
- Version: $Revision: 1.9 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.10 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See doc/license.txt or
const std::string& description,
const std::string& version,
const std::string& BBTKVersion)
- : mName(name),
- mAuthor(author),
- mDescription(description),
- mVersion(version),
- mBBTKVersion(BBTKVersion)
+ :
+ mName(name),
+ mAuthor(author),
+ mDescription(description),
+ mVersion(version),
+ mBBTKVersion(BBTKVersion)
{
std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
Program: bbtk
Module: $RCSfile: bbtkPackage.h,v $
Language: C++
- Date: $Date: 2008/02/05 12:16:55 $
- Version: $Revision: 1.4 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.5 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See doc/license.txt or
const BlackBoxMapType& GetBlackBoxMap() const { return mBlackBoxMap; }
BlackBoxMapType& GetBlackBoxMap() { return mBlackBoxMap; }
+ // Factories management
+ /// Adds the factory to the set of factories which use the package
+ void AddFactory(Factory* f) { mFactorySet.insert(f); }
+ /// Removes the factory from the set of factories which use the package
+ void RemoveFactory(Factory* f) { mFactorySet.erase(f); }
+
+ /// Gets the set of factories which use the package
+ std::set<Factory*>& GetFactorySet() { return mFactorySet; }
+ /// Gets the set of factories which use the package (const)
+ const std::set<Factory*>& GetFactorySet() const { return mFactorySet; }
+
private:
+
/// The name of the package
std::string mName;
/// The author of the package
std::string mTypeOut;
};
- //typedef std::string AdaptorKey;
-
/// The type of map of adaptor descriptors
typedef std::map< AdaptorKey, BlackBoxDescriptor*> AdaptorMapType;
/// The map of adaptors descriptors
AdaptorMapType mAdaptorMap;
+
+
+ /// The set of factories which contain the package
+ std::set<Factory*> mFactorySet;
+
};
// EO class Package
//====================================================================
Program: bbtk
Module: $RCSfile: bbtkVirtualExec.h,v $ $
Language: C++
- Date: $Date: 2008/02/06 09:27:52 $
- Version: $Revision: 1.7 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.8 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#define __bbtkVirtualExec_h__
#include "bbtkSystem.h"
-#include "bbtkComplexBlackBox.h"
+//#include "bbtkComplexBlackBox.h"
#include "bbtkFactory.h"
-#include <string>
-#include <deque>
+//#include <string>
+//#include <deque>
namespace bbtk
{
+ class Interpreter;
+
class /*BBTK_EXPORT*/ VirtualExec // All methods are pure virtual
{
}
DialogModeType;
+ VirtualExec() : mInterpreter(0) {}
+
+ /// Sets the interpreter who uses it
+ void SetInterpreter(Interpreter* i) { mInterpreter = i; }
+ /// Gets the interpreter who uses it
+ Interpreter* GetInterpreter() { return mInterpreter; }
+ /// Gets the interpreter who uses it (const)
+ const Interpreter* GetInterpreter() const { return mInterpreter; }
+
+ /// Gets the factory used by the executer
+ virtual Factory* GetFactory() { return 0; }
+ /// Gets the factory used by the executer (const)
+ virtual const Factory* GetFactory() const { return 0; }
+
/// Sets the inputs of the workspace :
virtual void SetInputs(const std::map<std::string,std::string>& m) = 0;
private:
+ /// The interpreter which uses it (0 if none)
+ Interpreter* mInterpreter;
+ /*
/// Gets the current working black box
virtual ComplexBlackBoxDescriptor* Current() = 0;
/// Dialog mode
DialogModeType mDialogMode;
+ */
};
}
#endif
Program: bbtk
Module: $RCSfile: bbtkWxConsole.cxx,v $
Language: C++
- Date: $Date: 2008/03/03 10:48:47 $
- Version: $Revision: 1.6 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.7 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
mInstance = this;
mInterpreter = new bbtk::Interpreter();
+ mInterpreter->SetWxConsole(this);
mInterpreter->SetCommandLine(true);
//==============
// Menu
Program: bbtk
Module: $RCSfile: bbtkWxConsole.h,v $
Language: C++
- Date: $Date: 2008/03/03 10:48:48 $
- Version: $Revision: 1.5 $
+ Date: $Date: 2008/03/07 08:40:14 $
+ Version: $Revision: 1.6 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
WxConsole( wxWindow *parent, wxString title, wxSize size);
~WxConsole();
- static WxConsole* GetInstance() { return mInstance; }
+ // static WxConsole* GetInstance() { return mInstance; }
+
+ /// Returns the Interpreter used
+ /// ONLY ONE FOR THE MOMENT BUT IN THE FUTURE CAN BE DIFFERENT
+ /// (DIFFERENT WORKSPACES)
+ Interpreter* GetInterpreter() { return mInterpreter; }
+ /// Returns the Interpreter used (const)
+ const Interpreter* GetInterpreter() const { return mInterpreter; }
/// Sets the inputs of the workspace :
/// the map is passed as is to the Executer
/// which creates but does not execute pipelines.
void SetNoExecMode(bool b) { mInterpreter->SetNoExecMode(b); }
- void SetDialogMode(Interpreter::DialogModeType t) { mInterpreter->SetDialogMode(t); }
+ void SetDialogMode(Interpreter::DialogModeType t)
+ { mInterpreter->SetDialogMode(t); }
/// Runs the interpretation of a file
void InterpretFile( const std::string& filename)
--- /dev/null
+
+
+description "Demo of the box <a href=#bbBasicImageApplication>BasicImageApplication</a> : creates an interactive image thresholding application"
+author "laurent.guigues@creatis.insa-lyon.fr"
+category "example"
+
+## THE APPLICATION BOX
+include /home/guigues/coding/Sofa/bbtk/packages/wxvtk/bbs/boxes/bbBasicImageApplication
+#include wxvtk/boxes/bbBasicImageApplication
+new BasicImageApplication appli
+set appli.WinTitle "ExampleBasicImageApplication"
+
+## THE FILTER
+new BinaryThresholdImageFilter filter
+connect appli.AlgorithmInput filter.In
+connect filter.Out appli.AlgorithmOutput
+
+## THE WINDOW FOR PARAMETERS TUNING
+new LayoutLine parametersWindow
+new Slider upperThresholdSlider
+set upperThresholdSlider.Title "upper threshold"
+set upperThresholdSlider.In 100
+new Slider lowerThresholdSlider
+set lowerThresholdSlider.Title "lower threshold"
+set lowerThresholdSlider.In 0
+connect lowerThresholdSlider.Widget parametersWindow.Widget1
+connect upperThresholdSlider.Widget parametersWindow.Widget2
+connect upperThresholdSlider.Out filter.UpperThreshold
+connect lowerThresholdSlider.Out filter.LowerThreshold
+
+
+connect parametersWindow.Widget appli.ParametersWidget
+set appli.ParametersWindowHeight 200
+set appli.ParametersWindowWidth 400
+#set appli.Refresh Reactive
+
+#message Process 3
+## GO !
+#message All 9
+#graph
+
+#message Wx 9
+exec appli
+#graph
+
+
+
+
--- /dev/null
+include wxvtk/boxes/bbDoubleSlicer
+load wx
+load std
+load itk
+load itkvtk
+load vtk
+
+
+define BasicImageApplication
+
+##
+ description "Interface of a 'standard' image application. Displays two images : before/after processing; Offers buttons : open/parameters/run/save/quit. See <a href='../demo/index.html#DemoBasicImageApplication'>DemoBasicImageApplication.bbs</a>. Screenshot : <center><img src='../demo/DemoBasicImageApplication1.png' width=400></center>."
+ author "laurent.guigues@creatis.insa-lyon.fr"
+ category "widget"
+##
+
+
+# WINDOWS CREATION
+ new LayoutSplit mainWindow
+ set mainWindow.Proportion 90
+
+ new DoubleSlicer viewer
+
+ new LayoutLine buttonsBar
+
+ new CommandButton openButton
+ new CommandButton paramButton
+ new CommandButton runButton
+ new CommandButton saveButton
+ new CommandButton quitButton
+
+ connect viewer.Widget mainWindow.Widget1
+ connect buttonsBar.Widget mainWindow.Widget2
+
+ connect openButton.Widget buttonsBar.Widget1
+ connect paramButton.Widget buttonsBar.Widget2
+ connect runButton.Widget buttonsBar.Widget3
+ connect saveButton.Widget buttonsBar.Widget4
+ connect quitButton.Widget buttonsBar.Widget5
+
+ set viewer.Orientation 0
+ set buttonsBar.Orientation 0
+
+#OPEN
+ set openButton.Label "Open"
+ set paramButton.Label "Parameters"
+ set saveButton.Label "Save"
+ new FileSelector openFileDialog
+ connect openButton.BoxChange openFileDialog.BoxExecute
+ connect openButton.BoxChange viewer.RefreshSlicer1
+ set openFileDialog.Message "Select input image"
+ set openFileDialog.OpenSave "Open"
+#READER
+ new MetaImageReader reader
+# set reader.Filename "/home/guigues/coding/Sofa/bbtk/data/thorax.hdr"
+ connect openFileDialog.Out reader.In
+
+ connect reader.Out viewer.In1
+
+
+# RUN
+ set runButton.Label "Run"
+ new MultipleInputs refreshViewerOut
+ connect refreshViewerOut.Out viewer.RefreshSlicer2
+ connect runButton.BoxChange refreshViewerOut.In1
+
+#QUIT
+ set quitButton.Label "Quit"
+ set quitButton.In "quit"
+
+
+#SAVE
+ new ImageWriter writer
+ new FileSelector saveFileDialog
+ set saveFileDialog.BoxProcessMode Always
+ set saveFileDialog.DefaultFile "out.hdr"
+ set saveFileDialog.Message "Select output image"
+ set saveFileDialog.OpenSave "Save"
+ connect saveFileDialog.Out writer.Filename
+ connect saveButton.BoxChange refreshViewerOut.In2
+ connect saveButton.BoxChange writer.BoxExecute
+
+#PARAMETERS
+ new LayoutSplit paramWindow
+ set paramWindow.Proportion 80
+ set paramWindow.WinTitle "Parameters"
+# new LayoutLine userParamWindow
+# connect userParamWindow.Widget paramWindow.Widget1
+ new CommandButton paramWindowCloseButton
+ set paramWindowCloseButton.Label "Close"
+ connect paramWindowCloseButton.Widget paramWindow.Widget2
+ connect paramWindowCloseButton.BoxChange paramWindow.WinHide
+ connect paramButton.BoxChange paramWindow.BoxExecute
+
+
+# INPUTS / OUTPUTS
+ new anyItkImagePointerRelay imageOut
+ connect imageOut.Out viewer.In2
+ connect imageOut.Out writer.In
+
+ input AlgorithmOutput imageOut.In "Plug here the output of your algorithm"
+ output AlgorithmInput reader.Out "Plug this output to the input of your algorithm"
+ input ParametersWidget paramWindow.Widget1 "Connect here your parameter tuning widget"
+
+ input ParametersWindowWidth paramWindow.WinWidth "The width of the parameters window"
+ input ParametersWindowHeight paramWindow.WinHeight "The height of the parameters window"
+ input WinTitle mainWindow.WinTitle "Title of the main window"
+
+ input Refresh viewer.BoxProcessModeSlicer2 "Set to 'Reactive' to have automatic refresh when image or parameters change"
+
+ exec mainWindow
+
+
+endefine
+