]> Creatis software - bbtk.git/blob - kernel/src/bbtkComplexBlackBoxDescriptor.h
Obtaining the tree boxes related to a sigle box. The classes changed were Utilities...
[bbtk.git] / kernel / src / bbtkComplexBlackBoxDescriptor.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkComplexBlackBoxDescriptor.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.8 $
34 =========================================================================*/
35
36
37 /**
38  *  \file 
39  *  \brief Class bbtk::ComplexBlackBoxDescriptor : describes a ComplexBlackBox (constituents, connections) and is able to create an instance of it.
40  */
41 /**
42  * \class bbtk::ComplexBlackBoxDescriptor
43  * \brief Describes a ComplexBlackBox (constituents, connections) and is able to create an instance of it.
44  */
45
46 #ifndef __bbtkComplexBlackBoxDescriptor_h__
47 #define __bbtkComplexBlackBoxDescriptor_h__
48
49 #include "bbtkBlackBoxDescriptor.h"
50 #include "bbtkComplexBlackBoxInputDescriptor.h"
51 #include "bbtkComplexBlackBoxOutputDescriptor.h"
52 #include "bbtkFactory.h"
53 #include <fstream>
54 #include <vector>
55 #include "bbtkUtilities.h"
56 namespace bbtk
57 {
58
59   class ComplexBlackBox;
60   typedef boost::shared_ptr<ComplexBlackBox> ComplexBlackBoxPointer;
61
62   //==========================================================================
63   class BBTK_EXPORT ComplexBlackBoxDescriptor : 
64     public bbtk::BlackBoxDescriptor
65   {
66     BBTK_OBJECT_INTERFACE(ComplexBlackBoxDescriptor);
67     typedef BlackBoxDescriptor Superclass;
68   public:
69     friend class ComplexBlackBox;
70
71     static Pointer New(const std::string& name); 
72     /// Sets the factory used 
73     void SetFactory(Factory::Pointer f) { mFactory = f; }
74     /// Gets the factory used
75     Factory::Pointer GetFactory() const { return mFactory.lock(); }
76
77     /// Releases the descriptor
78     //    void Release(bool release_package = true);
79
80     /// Gets the factory used (const)
81     //    const Factory* GetFactory() const { return mFactory; }
82
83     /// Creates an instance of name <name> of the ComplexBlackBox of which this is the descriptor 
84     virtual BlackBoxPointer NewBlackBox(const std::string& name);
85
86     /// Adds a black box to the complex box
87     /// Needs a factory set !
88     void Add ( const std::string& type,
89                const std::string& name
90                ); 
91
92     /// Removes a black box from the complex box
93     void Remove( const std::string& name, bool remove_connections = true);
94
95     /// Connects two black boxes of the complex box
96     /// Needs a factory set !
97      void Connect ( const std::string& from,
98                    const std::string& output,
99                    const std::string& to,
100                    const std::string& input
101                    ); 
102     /// Defines an input of the complex box
103     void DefineInput ( const std::string& name,
104                        const std::string& box,
105                        const std::string& input,
106                        const std::string& help);
107     /// Defines an output of the complex box
108     void DefineOutput ( const std::string& name,
109                        const std::string& box,
110                        const std::string& output,
111                        const std::string& help);
112  
113  
114    
115     /// 
116     void AddToExecutionList( const std::string& box );
117
118     ComplexBlackBoxPointer GetPrototype() { return mPrototype; }
119     void PrintBlackBoxes(); 
120    
121     /// Prints help on the black box
122     void GetHelp(bool full=true) const;
123  
124     /// Writes html formatted help into the output file stream. 
125     /// detail and level are used for graphical representation of 
126     /// complex black boxes (see ComplexBlackBox::InsertHTMLGraph)
127     /// output_dir is the directory in which to write auxilliary files 
128     /// (.dot/.png/.cmap)
129     void InsertHtmlHelp ( std::ofstream& s, 
130                           int detail, int level,
131                           const std::string& output_dir = "",
132                           bool relative_link = false);
133
134     /// Generates a png image representing the pipeline graph of the 
135     /// complex box and writes html code to insert it 
136     /// into the output file stream. 
137     /// detail : 
138     /// level : depth of nested complex boxes graph development 
139     /// (0:only this box level 
140     /// output_dir is the directory in which to write the files 
141     /// (.dot/.png/.cmap)
142     void InsertHTMLGraph( std::ofstream& s, 
143                           int detail, int level, 
144                           const std::string& output_dir = "",
145                           bool relative_link = false );
146     
147                 void GetBoxesInside (NodeTreeC& tree, std::vector<std::string>& list, int cont);
148    ///
149     virtual void Check(bool recursive=true) const;
150        
151
152
153   protected:
154     /// Default ctor with name is protected
155     ComplexBlackBoxDescriptor(const std::string& name); 
156
157   private:
158         
159     /// The factory used
160     Factory::WeakPointer mFactory;
161     /// The complex box in which boxes and connections are stored
162     ComplexBlackBoxPointer mPrototype;
163               
164   };
165   // class ComplexBlackBoxDescriptor
166   //==========================================================================
167
168
169 }
170 // namespace bbtk
171 #endif