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