]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/Instant.cxx
License Files Headers
[creaEnvironment.git] / lib / kernel_Environment / Instant.cxx
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 // SYSTEM INCLUDES
30
31
32 // PROJECT INCLUDES
33 #include <iostream>
34 #include <vector>
35
36 // LOCAL INCLUDES
37 #include "ConceptInstantHandler.h"
38 #include "Instant.h"
39
40 // FORWARD REFERENCES
41 //NAMESPACE
42
43
44
45
46                         //====== LIFECYCLE ========
47                         
48                         Instant::Instant(std::vector<int>* instant)
49                                 {
50                                         nTuple=new std::vector<int>();
51                                         setInstant(instant);
52                                 }
53
54                         Instant::Instant()
55                                 {
56                                         nTuple=new std::vector<int>();
57                                 }
58                         
59                         Instant::Instant(int size)
60                                 {
61                                         nTuple= new std::vector<int>();
62                                         int i;
63                                         for(i=0;i<size;i++)
64                                                 nTuple->push_back(0);
65                                                 
66                                 }
67                         Instant::~Instant()
68                         {
69                                 //deleting nTuple
70                                 nTuple->clear();
71                                 
72                         }
73
74                         //====== OPERATIONS =======
75                         /*
76                         * Add a new concept to the instant
77                         * @param indexConcept: index concept that is going
78                         * to be added of the new concept added to the instant
79                         * @return --
80                         * 
81                         */
82                         void Instant::addConcept(int value)
83                                 {
84                                         nTuple->push_back(value);
85                                 }
86                         //======= INQUIRY ===========
87                         /*
88                         * Returns the value nTuple
89                         * @return nTuple
90                         */
91                         std::vector<int>* Instant::getInstant()
92                                 {
93                                         return nTuple;
94                                 }
95                         /*
96                         * Returns the index of the concept that's
97                         * in the instant's  concept index
98                         * @param indexConcept: index of the concept in the instant
99                         * @return indexInConcept
100                         */
101                         int Instant::getIndexInConcept(int indexConcept)
102                                 {
103                                         return (*nTuple)[indexConcept];
104                                 }
105
106                         /*
107                         * returns the number of concepts that the instant has
108                         * @return nTuple.size()
109                         */
110                         int Instant::getSize()
111                                 {
112                                         return nTuple->size();
113                                 }
114                         
115                         /*
116                         * Compares if the instant given is equals to the nTuple
117                         * @param instant: instant for compare
118                         * @return true if is equals to the nTuple, false otherwise
119                         */
120                         bool Instant::isEquals(Instant* instant)
121                                 {
122                                         int sizeInstant=instant->getSize();
123                                         bool equals=true;
124                                         int sizeThisInstant=getSize();
125                                         if(sizeInstant==sizeThisInstant)
126                                                 {
127                                                         int i;
128                                                         for(i=0;i<sizeThisInstant;i++)
129                                                                 {
130                                                                         int indexi=(*nTuple)[i];
131                                                                         int indexInConcept=instant->getIndexInConcept(i);
132                                                                         if(indexi!=indexInConcept)
133                                                                                 equals=false;
134                                                                 }
135                                                         
136                                                 }
137                                         else
138                                                 equals=false;
139                                         return equals;
140                                 }
141
142                         //=========== ACCESS ==========
143                         /*
144                         * Sets the nTuple
145                         * @param instant: the vector that's going to be save in
146                         * nTuple        
147                         */
148                         void Instant::setInstant(std::vector<int>* instant)
149                                 {
150                                         int i,size;
151                                         size=instant->size();
152                                         for(i=0;i<size;i++)
153                                                 {
154                                                         int k=(*instant)[i];
155                                                         nTuple->push_back(k);
156                                                 }
157                                 }
158                         
159                         /*
160                         * Change the  concept's index saved in the nTuple index (the index
161                         * that's is for that concept
162                         * @param indexConcept: Concept that's going to change the value
163                         * @return--
164                         * 
165                         */
166                         void Instant::setConcept(int indexConcept, int index)
167                                 {
168                                         (*nTuple)[indexConcept]=index;
169                                 }
170                         /*
171                         * remove a concept from the instant
172                         * @param indexConcept: Concept that's going to be removec
173                         * @return true if succesful, false otherwise
174                         * 
175                         */
176                         bool Instant::removeConcept(int indexConcept)
177                                 {
178                                         int i;
179                                         std::vector<int>::iterator conceptsIterator=nTuple->begin();
180                                         int size=nTuple->size();
181                                         for(i=0;i<size;i++)
182                                                 {
183                                                         if(i==indexConcept)
184                                                         {
185                                                                 nTuple->erase(conceptsIterator);
186                                                                 return true;
187                                                         }
188                                                         conceptsIterator++;
189                                                 }
190                                         return false;
191                                 }