fw4spl
tests/fwTest/src/fwTest/generator/SeriesDB.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwTest/generator/SeriesDB.hpp"
8 #include "fwTest/generator/Image.hpp"
9 #include "fwTest/generator/Mesh.hpp"
10 
11 #include <fwTools/Type.hpp>
12 
13 #include <fwData/Composite.hpp>
14 #include <fwData/Image.hpp>
15 #include <fwData/Material.hpp>
16 #include <fwData/Mesh.hpp>
17 #include <fwData/Reconstruction.hpp>
18 #include <fwData/String.hpp>
19 
20 #include <fwMedData/SeriesDB.hpp>
21 #include <fwMedData/Series.hpp>
22 #include <fwMedData/ImageSeries.hpp>
23 #include <fwMedData/ModelSeries.hpp>
24 #include <fwMedData/ActivitySeries.hpp>
25 #include <fwMedData/Study.hpp>
26 #include <fwMedData/Patient.hpp>
27 #include <fwMedData/Equipment.hpp>
28 
29 #include <sstream>
30 
31 
32 namespace fwTest
33 {
34 namespace generator
35 {
36 
37 //------------------------------------------------------------------------------
38 
39 ::fwMedData::SeriesDB::sptr SeriesDB::createSeriesDB(const unsigned char nbImgSeries,
40  const unsigned char nbModelSeries,
41  const unsigned char nbActivitySeries)
42 {
44  ::fwMedData::SeriesDB::sptr seriesDB = ::fwMedData::SeriesDB::New();
45  for (unsigned char nb = 0; nb<nbImgSeries; ++nb)
46  {
47  ::fwMedData::Series::sptr imgSeries;
48  imgSeries = SeriesDB::createImageSeries();
49  seriesDB->getContainer().push_back(imgSeries);
50  }
51 
52  for (unsigned char nb = 0; nb<nbModelSeries; ++nb)
53  {
54  ::fwMedData::Series::sptr modelSeries;
55  modelSeries = SeriesDB::createModelSeries(rand()%15+1);
56  seriesDB->getContainer().push_back(modelSeries);
57  }
58 
59  for (unsigned char nb = 0; nb<nbActivitySeries; ++nb)
60  {
61  ::fwMedData::Series::sptr activitySeries;
62  activitySeries = SeriesDB::createActivitySeries();
63  seriesDB->getContainer().push_back(activitySeries);
64  }
65  return seriesDB;
66 }
67 
68 //------------------------------------------------------------------------------
69 
70 ::fwMedData::Patient::sptr SeriesDB::createPatient()
71 {
72  ::fwMedData::Patient::sptr patient = ::fwMedData::Patient::New();
73  const std::string PATIENT_NAME = "NomSeriesDB1";
74  const std::string PATIENT_FIRSTNAME = "PrenomSeriesDB1";
75  const std::string PATIENT_ID = "4564383757";
76  const std::string PATIENT_BIRTHDATE = "19710418";
77  const std::string PATIENT_SEX = "O ";
78 
79  patient->setName( PATIENT_NAME + "^" + PATIENT_FIRSTNAME );
80  patient->setPatientId( PATIENT_ID );
81  patient->setBirthdate( PATIENT_BIRTHDATE );
82  patient->setSex( PATIENT_SEX );
83 
84  return patient;
85 }
86 
87 //------------------------------------------------------------------------------
88 
89 ::fwMedData::Study::sptr SeriesDB::createStudy()
90 {
91  ::fwMedData::Study::sptr study = ::fwMedData::Study::New();
92 
93  static unsigned int count = 1;
94  std::stringstream str;
95  str.width(4);
96  str.fill('0');
97  str << count++;
98 
99  // studies informations
100  const std::string UID = "1.2.826.0.1.3680043.2.1125.44278200849347599055201494082232" + str.str();
101  const std::string DATE = "20130418";
102  const std::string TIME = "095948.689872 ";
103  const std::string PHYSICIAN = "Dr^Jekyl";
104  const std::string DESCRIPTION = "Say 33. ";
105  const std::string PATIENT_AGE = "042Y";
106 
107  study->setInstanceUID( UID );
108  study->setDate( DATE );
109  study->setTime( TIME );
110  study->setReferringPhysicianName( PHYSICIAN );
111  study->setDescription( DESCRIPTION );
112  study->setPatientAge( PATIENT_AGE );
113 
114  return study;
115 }
116 
117 //------------------------------------------------------------------------------
118 
119 ::fwMedData::Equipment::sptr SeriesDB::createEquipement()
120 {
121  ::fwMedData::Equipment::sptr equipment = ::fwMedData::Equipment::New();
122  const std::string INSTITUTION = "hospital";
123  equipment->setInstitutionName(INSTITUTION);
124 
125  return equipment;
126 }
127 
128 
129 //------------------------------------------------------------------------------
130 
131 void SeriesDB::generateSeriesInformation(::fwMedData::Series::sptr series)
132 {
133  series->setPatient(SeriesDB::createPatient());
134  series->setStudy(SeriesDB::createStudy());
135  series->setEquipment(SeriesDB::createEquipement());
136 
137  static unsigned int count = 1;
138  std::stringstream str;
139  str.width(4);
140  str.fill('0');
141  str << count++;
142 
143  const std::string UID = "1.2.826.0.1.3680043.2.1125.102906542887009256605006409108689" + str.str();
144  const std::string MODALITY = "CT";
145  const std::string DATE = "20130418";
146  const std::string TIME = "101010.101010 ";
147  const std::string DESCRIPTION = "Description ";
148 
149  ::fwMedData::DicomValuesType performingPhysiciansName;
150  performingPhysiciansName.push_back("Dr^Jekyl");
151  performingPhysiciansName.push_back("Dr^House");
152  performingPhysiciansName.push_back("Dr^Einstein ");
153  series->setPerformingPhysiciansName(performingPhysiciansName);
154 
155  series->setInstanceUID(UID);
156  series->setModality(MODALITY);
157  series->setDate(DATE);
158  series->setTime(TIME);
159  series->setDescription(DESCRIPTION);
160 }
161 
162 //------------------------------------------------------------------------------
163 
164 ::fwMedData::ImageSeries::sptr SeriesDB::createImageSeries()
165 {
166  ::fwMedData::ImageSeries::sptr imgSeries = ::fwMedData::ImageSeries::New();
167 
169 
170  ::fwData::Image::sptr image = ::fwData::Image::New();
171  Image::generateRandomImage(image, ::fwTools::Type::s_INT16);
172 
173  imgSeries->setImage(image);
174 
175  return imgSeries;
176 }
177 
178 //------------------------------------------------------------------------------
179 
180 ::fwMedData::ModelSeries::sptr SeriesDB::createModelSeries(unsigned char nbReconstruction)
181 {
182  ::fwMedData::ModelSeries::sptr modelSeries = ::fwMedData::ModelSeries::New();
183 
185 
186  ::fwMedData::ModelSeries::ReconstructionVectorType recDB;
187  for (unsigned char nb = 0; nb<nbReconstruction; ++nb)
188  {
189  ::fwData::Reconstruction::sptr rec = ::fwData::Reconstruction::New();
190 
192 
193  recDB.push_back(rec);
194  }
195  modelSeries->setReconstructionDB(recDB);
196 
197  return modelSeries;
198 }
199 
200 //------------------------------------------------------------------------------
201 
202 ::fwMedData::ActivitySeries::sptr SeriesDB::createActivitySeries()
203 {
204  ::fwMedData::ActivitySeries::sptr activitySeries = ::fwMedData::ActivitySeries::New();
205 
206  SeriesDB::generateSeriesInformation(activitySeries);
207 
208  const std::string CONFIG_ID = "IdOfTheConfig";
209  activitySeries->setActivityConfigId(CONFIG_ID);
210 
211  ::fwData::Composite::sptr data = ::fwData::Composite::New();
212  data->getContainer()["key1"] = ::fwData::String::New("ValueOfKey1");
213  activitySeries->setData(data);
214 
215  return activitySeries;
216 }
217 
218 //------------------------------------------------------------------------------
219 
220 void SeriesDB::generateReconstruction(::fwData::Reconstruction::sptr rec)
221 {
222  rec->setIsVisible(true);
223  rec->setOrganName("liver");
224  rec->setStructureType("Liver");
225 
226  ::fwData::Image::sptr img = ::fwData::Image::New();
227  Image::generateRandomImage(img, ::fwTools::Type::create("uint16"));
228  rec->setImage(img);
229 
230  ::fwData::Material::sptr material = ::fwData::Material::New();
231  material->ambient()->red() = 0.75f;
232  material->ambient()->green() = 0.10f;
233  material->ambient()->blue() = 0.56f;
234  material->ambient()->alpha() = 0.8f;
235  material->diffuse()->red() = 0.85f;
236  material->diffuse()->green() = 0.20f;
237  material->diffuse()->blue() = 0.66f;
238  material->diffuse()->alpha() = 0.9f;
239  rec->setMaterial(material);
240 
241  ::fwData::Mesh::sptr mesh = ::fwData::Mesh::New();
242  Mesh::generateMesh( mesh );
243 
244  rec->setMesh(mesh);
245 }
246 
247 //------------------------------------------------------------------------------
248 
249 } // namespace generator
250 } // namespace fwTest
static FWTEST_API std::shared_ptr< ::fwMedData::Study > createStudy()
Returns a Study with dummy informations.
static FWTEST_API std::shared_ptr< ::fwMedData::ImageSeries > createImageSeries()
Returns an ImageSeries with a randomized image.
static FWTEST_API void generateRandomImage(::fwData::Image::sptr image,::fwTools::Type type)
Generate an image with random information (size, spacing, ...). Buffer is filled with random values...
static FWTEST_API void initRand()
Initialize &#39;rand&#39; seed.
static FWTEST_API std::shared_ptr< ::fwMedData::ModelSeries > createModelSeries(unsigned char nbReconstruction)
Returns a ModelSeries containing random Reconstructions.
Definition: Data.hpp:15
static FWTEST_API std::shared_ptr< ::fwMedData::Patient > createPatient()
Returns a Patient with dummy informations.
static FWTEST_API void generateSeriesInformation(std::shared_ptr< ::fwMedData::Series > series)
Generates dummy informations for the series.
static FWTEST_API std::shared_ptr< ::fwMedData::SeriesDB > createSeriesDB(const unsigned char nbImgSeries, const unsigned char nbModelSeries, const unsigned char nbActivitySeries)
Creates a SeriesDB.
static FWTEST_API void generateReconstruction(std::shared_ptr< ::fwData::Reconstruction > rec)
Generate a reconstruction.
static FWTEST_API std::shared_ptr< ::fwMedData::ActivitySeries > createActivitySeries()
Returns an ActivitySeries with dummy data.
static FWTEST_API void generateMesh(::fwData::Mesh::sptr mesh)
Generate a mesh.
static FWTEST_API std::shared_ptr< ::fwMedData::Equipment > createEquipement()
Returns an Equipment with dummy informations.