Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
operations-save-load-export.cc
Go to the documentation of this file.
1 /*
2  * lib-controler-gmap : Le contrôleur de 3-G-cartes, surcouche de lib-controler.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-controler-gmap
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "g-map-vertex.hh"
26 #include "controler-gmap.hh"
27 #include <iostream>
28 #include <cassert>
29 
30 #ifdef MODULE_EXTRACTION_IMAGE
31 #include "extraction-images.hh"
32 #endif // MODULE_EXTRACTION_IMAGE
33 
34 using namespace GMap3d;
35 using namespace std;
36 //******************************************************************************
38 {
39  bool res = false;
40 
42  {
44 
45  FMap->removeAllDarts();
46 
48 
51  setMessage("Empty the map");
52  res = true;
53  }
54  return res;
55 }
56 //******************************************************************************
57 bool CControlerGMap::addMap(const char * AFilename)
58 {
59  bool res = false;
60 
62  {
64 
65  if (FMap->load(AFilename)!=NULL)
66  {
69  setMessage(string("Add the map from ") + AFilename + " done");
70  res = true;
71  }
72  else
73  {
75  setMessage(string("Error for loading ")+AFilename);
76  }
77 
78  assert(isMapOk());
79  }
80 
81  return res;
82 }
83 //******************************************************************************
84 bool CControlerGMap::loadMap(const char * AFilename)
85 {
86  bool res = false;
87 
89  {
91 
92  FMap->removeAllDarts();
94 
95  if (FMap->load(AFilename)!=NULL)
96  {
99  setMessage(string("Load the map from ")+AFilename+" done");
100  res = true;
101  }
102  else
103  {
105  setMessage(string("Error for loading ")+AFilename);
106  }
107 
108  assert(isMapOk());
109  std::cout<<"isMapOk ? "<<isMapOk()<<std::endl;
110  }
111 
112  return res;
113 }
114 //******************************************************************************
115 bool CControlerGMap::saveMapAscii(const char* AFilename)
116 {
117  bool res = false;
119  {
120  res = FMap->save(AFilename, AsciiFormat);
121  if (res)
122  setMessage(string("Save in ")+AFilename+" done");
123  else
124  setMessage(string("Error during saving ")+AFilename);
125  }
126 
127  return res;
128 }
129 //******************************************************************************
130 bool CControlerGMap::saveMapBinary(const char * AFilename)
131 {
132  bool res = false;
134  {
135  res = FMap->save(AFilename, BinaryFormat);
136  if (res)
137  setMessage(string("Binary save in ")+AFilename+ " done");
138  else
139  setMessage(string("Error during binary saving ")+AFilename);
140  }
141 
142  return res;
143 }
144 //******************************************************************************
145 bool CControlerGMap::exportXfig(const char * AFilename, TViewId AViewId,
146  bool AArrow, bool AFace, bool ASews,
147  bool AGrid, bool AVertices)
148 {
149  bool res = false;
151  {
152  // updateBurstView();
153  ofstream fout(AFilename, ios::trunc);
154  sauveCarteXfig(AViewId, fout, AArrow, AFace, ASews, AGrid, AVertices);
155  fout.close();
156  setMessage(string("Export Xfig ")+AFilename+" done");
157  res = true;
158  }
159 
160  return res;
161 }
162 //******************************************************************************
163 bool CControlerGMap::exportPov(const char * AFilename)
164 {
165  bool res = false;
167  {
168  // updateBurstView();
169  ofstream fout(AFilename, ios::trunc);
170  bool ok = FMap->exportToPov(fout);
171  fout.close();
172  setMessage(ok ? string("Export PoV ")+AFilename+" done" :
173  string("Error during export PoV ")+AFilename);
174  res = true;
175  }
176 
177  return res;
178 }
179 //******************************************************************************
180 bool CControlerGMap::exportXfigAsIntervoxel(const char * AFilename,
181  TViewId AViewId)
182 {
183  bool res = false;
185  {
186  // updateBurstView();
187  ofstream fout(AFilename, ios::trunc);
188  sauveCarteIntervoxelXfig(AViewId, fout);
189  fout.close();
190  setMessage(string("Export in intervoxel ") + AFilename + " done");
191  res = true;
192  }
193 
194  return res;
195 }
196 //******************************************************************************
197 #ifdef MODULE_EXTRACTION_IMAGE
198 //******************************************************************************
199 #ifndef MODULE_EXTRACTION_WITHOUT_MAGICK
200 //******************************************************************************
201 bool CControlerGMap::extractImage2D(const string & AFilename)
202 {
203  bool res = false;
205  {
206  undoRedoPreSave();
207 
208  CExtractionImage extractor(FMap);
209 
210  if (extractor.extract2dImage(AFilename))
211  {
213  setModelChanged();
214  setMessage("Extraction de l'image 2d effectuée");
215  res = true;
216  }
217  else
218  {
219  setMessage("Erreur durant l'extraction de l'image 2d");
221  }
222  }
223 
224  return res;
225 }
226 //******************************************************************************
227 #endif // MODULE_EXTRACTION_WITHOUT_MAGICK
228 //******************************************************************************
229 bool CControlerGMap::extractImage3D(const string & AFilename, int AFirstPlane,
230  int ANbPlane, int ALevel, int NbChiffres,
231  bool ADestroyBorder, bool AKeepFictiveEdges,
232  bool AShiftFictiveEdges, bool AWithPrecodes,
233  bool ACEAFormat)
234 {
235  bool res = false;
237  {
238  undoRedoPreSave();
239 
240  CExtractionImage extractor(FMap);
241 
242  if (ACEAFormat)
243  {
244  if (AWithPrecodes)
245  res =
246  extractor.extract3dImageCEAWithPrecodes(AFilename, AFirstPlane,
247  ANbPlane, ALevel,
248  ADestroyBorder,
249  AKeepFictiveEdges,
250  AShiftFictiveEdges);
251  else
252  res = extractor.extract3dImageCEA(AFilename, AFirstPlane, ANbPlane,
253  ALevel, ADestroyBorder,
254  AKeepFictiveEdges,
255  AShiftFictiveEdges);
256  }
257  else
258  {
259  if (AWithPrecodes)
260  res =
261  extractor.extract3dImageWithPrecodes(AFilename, AFirstPlane,
262  ANbPlane, ALevel,
263  NbChiffres, ADestroyBorder,
264  AKeepFictiveEdges,
265  AShiftFictiveEdges);
266  else
267  res = extractor.extract3dImage(AFilename, AFirstPlane, ANbPlane,
268  ALevel, NbChiffres, ADestroyBorder,
269  AKeepFictiveEdges,
270  AShiftFictiveEdges);
271  }
272 
273  if (res)
274  {
276  setModelChanged();
277  setMessage("Extraction de l'image 3d effectuée");
278  }
279  else
280  {
281  setMessage("Erreur durant l'extraction de l'image 3d");
283  }
284  }
285 
286  return res;
287 }
288 //******************************************************************************
289 bool CControlerGMap::extractOneRegionVoxels(const std::string & AFilename,
290  int AFirstPlane, int ANbPlane,
291  int NbChiffres,
292  int ARed, int AGreen, int ABlue,
293  int AAlpha)
294 {
295  bool res = false;
297  {
298  undoRedoPreSave();
299 
300  CExtractionImage extractor(FMap);
301 
302  res =
303  extractor.extractOneRegionVoxels(AFilename, AFirstPlane,
304  ANbPlane, NbChiffres,
305  ARed, AGreen, ABlue, AAlpha);
306 
307  if (res)
308  {
310  setModelChanged();
311  setMessage("Extraction des voxels d'une région effectuée");
312  }
313  else
314  {
315  setMessage("Erreur durant l'extraction des voxels "
316  "d'une région effectuée");
318  }
319  }
320 
321  return res;
322 }
323 //******************************************************************************
324 #endif // MODULE_EXTRACTION_IMAGE
325 //******************************************************************************
326 bool CControlerGMap::importOff(const char* AFilename)
327 {
328  bool res = false;
329 
331  {
332  undoRedoPreSave();
333 
334  if (FMap->importOff(AFilename)!=NULL)
335  {
337  setModelChanged();
338  setMessage(string("Import OFF ") + AFilename + " done");
339  res = true;
340  }
341  else
342  {
344  setMessage(string("Error during import OFF ")+AFilename);
345  }
346 
347  assert(isMapOk());
348  }
349 
350  return res;
351 }
352 //******************************************************************************
353 bool CControlerGMap::exportOff(const char* AFilename)
354 {
355  bool res = false;
356 
358  {
359  if (FMap->exportOff(AFilename))
360  {
361  setMessage(string("Export OFF ") + AFilename + " done");
362  res = true;
363  }
364  else
365  {
366  setMessage(string("Error during export OFF ")+AFilename);
367  }
368  }
369 
370  return res;
371 }
372 //******************************************************************************
373 bool CControlerGMap::exportOff3D(const char* AFilename)
374 {
375  bool res = false;
376 
378  {
379  if (FMap->exportOff3D(AFilename))
380  {
381  setMessage(string("Export OFF ")+AFilename+" done");
382  res = true;
383  }
384  else
385  {
386  setMessage(string("Error during export OFF")+AFilename);
387  }
388  }
389 
390  return res;
391 }
392 //******************************************************************************