Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
spamod-api.cc
Go to the documentation of this file.
1 /*
2  * lib-spamod : Visualisation des objets en discret.
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-spamod
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 "spamod-api.hh"
26 
27 #include "g-map.hh"
28 
29 #include "topologic-view.hh"
30 #include "analytic-view.hh"
31 #include "euclidian-view.hh"
32 #include "voxel-view.hh"
33 #include "k2-view.hh"
34 
35 #include "color-table-att.hh"
36 #include "user.hh"
37 #include "gmap-ops.hh"
38 #include "ineq-op.hh"
39 
40 //#include "opengl-api.hh"
41 
42 using namespace GMap3d;
43 
44 //******************************************************************************
46 {
47  assert(AMap != NULL);
48 
49  FMap = AMap;
50  colors = NULL;
51  FViewMode = SPAMOD_NONE;
52 
53  EV = new Euclidian_View(FMap);
54  AV = new Analytic_View(FMap);
55  TV = new Topologic_View(FMap);
56  VV = new Voxel_View(FMap);
57  KV = new K2_View(FMap);
58 
59  FEuclidianParam[0] = true;
60  FEuclidianParam[1] = true;
61 
62  FAnalyticParam [0] = true;
63  FAnalyticParam [1] = true;
64  FAnalyticParam [2] = true;
65  FAnalyticParam [3] = true;
66 
67  FVoxelParam [0] = true;
68  FVoxelParam [1] = true;
69  FVoxelParam [2] = true;
70 
71  FK2Param [0] = true;
72  FK2Param [1] = true;
73  FK2Param [2] = true;
74 }
75 //******************************************************************************
77 {
78  delete EV;
79  delete AV;
80  delete TV;
81  delete VV;
82  delete KV;
83 }
84 //******************************************************************************
86 {
87  for (int orbit = ORBIT_SELF; orbit <= ORBIT_CC; ++orbit)
88  FUsedOrbits[orbit] = FMap->isOrbitUsed(orbit);
89 
90  FMap->setOrbitUsed(ORBIT_0123);
91  FMap->setOrbitUsed(ORBIT_123);
92  FMap->setOrbitUsed(ORBIT_023);
93  FMap->setOrbitUsed(ORBIT_013);
94  FMap->setOrbitUsed(ORBIT_01);
95  FMap->setOrbitUsed(ORBIT_0);
96  FMap->setOrbitUsed(ORBIT_012);
97  FMap->setOrbitUsed(ORBIT_SELF);
98 
99  Init_Gmap(FMap);
100 
101  colors =
102  ((Color_Table_Att *) Find_Attribute(FMap, ORBIT_0123,
103  COLOR_TABLE_ATTRIBUTE_ID))->Get_Data();
104 
105  TV->Create_Darts_View();
106  Create_Ineq(FMap);
107  Choose_Ineq(FMap);
108  AV->Create_Vertices_Faces();
109  AV->Create_Edges_Faces();
110  AV->Create_Faces();
111  VV->Create_Matrix();
112  KV->Calculate_Matrix();
113 }
114 
115 //******************************************************************************
117 {
118  CAttribute * attr;
119 
120  for (CDynamicCoverageAll dgm(FMap); dgm.cont(); dgm++)
121  {
122  // ORBIT_SELF, VERTEX_ATTRIBUTE_ID:
123  attr = (*dgm)->removeAttribute(ORBIT_SELF, VERTEX_ATTRIBUTE_ID);
124  if (attr != NULL) delete attr;
125 
126  // ORBIT_0, USE_ATTRIBUTE_ID:
127  attr = (*dgm)->removeAttribute(ORBIT_0, USE_ATTRIBUTE_ID);
128  if (attr != NULL) delete attr;
129 
130  // ORBIT_123, VOXEL_LIST_ATTRIBUTE_ID
131  attr = (*dgm)->removeAttribute(ORBIT_123, VOXEL_LIST_ATTRIBUTE_ID);
132  if (attr != NULL) delete attr;
133 
134  // ORBIT_VERTEX, INEQ6_ATTRIBUTE_ID
135  attr = (*dgm)->removeAttribute(ORBIT_123, INEQ6_ATTRIBUTE_ID);
136  if (attr != NULL) delete attr;
137 
138  // ORBIT_VERTEX, PT_LIST_ATTRIBUTE_ID
139  attr = (*dgm)->removeAttribute(ORBIT_123, PT_LIST_ATTRIBUTE_ID);
140  if (attr != NULL) delete attr;
141 
142  // ORBIT_EDGE, INEQ6_ATTRIBUTE_ID
143  attr = (*dgm)->removeAttribute(ORBIT_023, INEQ6_ATTRIBUTE_ID);
144  if (attr != NULL) delete attr;
145 
146  // ORBIT_EDGE, PT_LIST_ATTRIBUTE_ID
147  attr = (*dgm)->removeAttribute(ORBIT_023, PT_LIST_ATTRIBUTE_ID);
148  if (attr != NULL) delete attr;
149 
150  // ORBIT_EDGE, VOXEL_LIST_ATTRIBUTE_ID
151  attr = (*dgm)->removeAttribute(ORBIT_023, VOXEL_LIST_ATTRIBUTE_ID);
152  if (attr != NULL) delete attr;
153 
154  // ORBIT_FACE, INT_ATTRIBUTE_ID
155  attr = (*dgm)->removeAttribute(ORBIT_013, INT_ATTRIBUTE_ID);
156  if (attr != NULL) delete attr;
157 
158  // ORBIT_FACE, INEQ2_ATTRIBUTE_ID
159  attr = (*dgm)->removeAttribute(ORBIT_013, INEQ2_ATTRIBUTE_ID);
160  if (attr != NULL) delete attr;
161 
162  // ORBIT_FACE, PT_LIST_ATTRIBUTE_ID
163  attr = (*dgm)->removeAttribute(ORBIT_013, PT_LIST_ATTRIBUTE_ID);
164  if (attr != NULL) delete attr;
165 
166  // ORBIT_FACE, VOXEL_LIST_ATTRIBUTE_ID
167  attr = (*dgm)->removeAttribute(ORBIT_013, VOXEL_LIST_ATTRIBUTE_ID);
168  if (attr != NULL) delete attr;
169 
170  // ORBIT_CC, MATRIX_ATTRIBUTE_ID:
171  attr = (*dgm)->removeAttribute(ORBIT_0123, MATRIX_ATTRIBUTE_ID);
172  if (attr != NULL) delete attr;
173 
174  // ORBIT_CC, COLOR_TABLE_ATTRIBUTE_ID:
175  attr = (*dgm)->removeAttribute(ORBIT_0123, COLOR_TABLE_ATTRIBUTE_ID);
176  if (attr != NULL) delete attr;
177  }
178 
179  for (int orbit = ORBIT_SELF; orbit <= ORBIT_CC; ++orbit)
180  if (FMap->isOrbitUsed(orbit) && ! FUsedOrbits[orbit])
181  FMap->unsetOrbitUsed(orbit);
182 
183  colors = NULL;
184 }
185 //******************************************************************************
187 {
188  if (FViewMode == AMode)
189  return;
190 
191  TSpamodViewMode oldMode = FViewMode;
192  FViewMode = AMode;
193 
194  if (FViewMode == SPAMOD_NONE)
195  // Libération des attributs Spamod:
197  else
198  if (oldMode == SPAMOD_NONE)
199  // Calcul des attributs SpaMod:
201 }
202 //******************************************************************************
204 {
205  return FViewMode;
206 }
207 //******************************************************************************
209 {
210  assert(0<=i && i<=1);
211  return FEuclidianParam[i];
212 }
213 //******************************************************************************
214 void CSpamodAPI::setEuclidianParam(int i, bool val)
215 {
216  assert(0<=i && i<=1);
217  FEuclidianParam[i] = val;
218 }
219 //******************************************************************************
221 {
222  assert(0<=i && i<=3);
223  return FAnalyticParam[i];
224 }
225 //******************************************************************************
226 void CSpamodAPI::setAnalyticParam(int i, bool val)
227 {
228  assert(0<=i && i<=3);
229  FAnalyticParam[i] = val;
230 }
231 //******************************************************************************
233 {
234  assert(0<=i && i<=2);
235  return FVoxelParam[i];
236 }
237 //******************************************************************************
238 void CSpamodAPI::setVoxelParam(int i, bool val)
239 {
240  assert(0<=i && i<=2);
241  FVoxelParam[i] = val;
242 }
243 //******************************************************************************
245 {
246  assert(0<=i && i<=2);
247  return FK2Param[i];
248 }
249 //******************************************************************************
250 void CSpamodAPI::setK2Param(int i, bool val)
251 {
252  assert(0<=i && i<=2);
253  FK2Param[i] = val;
254 }
255 //******************************************************************************
257 {
258  Color * color;
259 
260  // Propriétés des surfaces.
261  GLfloat Material_Ks[] = {0.5, 0.5, 0.5, 1.0};
262  GLfloat Material_Ke[] = {0.0, 0.0, 0.0, 1.0};
263  GLfloat Material_Se = 200;
264 
265  // Couleur des lumières.
266  GLfloat Light_Ka[] = {0.1, 0.1, 0.1, 1.0};
267  GLfloat Light_Kd[] = {1.0, 1.0, 1.0, 1.0};
268  GLfloat Light_Ks[] = {0.5, 0.5, 0.5, 1.0};
269 
270  GLfloat Light_Kambient[] = {0.4, 0.4, 0.4, 1.0};
271  glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Light_Kambient);
272 
273  //glPushAttrib(GL_ALL_ATTRIB_BITS);
274 
275  // Active le test de profondeur.
276  //glEnable(GL_DEPTH_TEST);
277  //Active l'affectation simplifiée de couleurs.
278  glEnable(GL_COLOR_MATERIAL);
279  // Allume la lumière n°1.
280  glEnable(GL_LIGHT0);
281  // Allume la lumière n°2.
282  //glEnable(GL_LIGHT1);
283 
284  //GLfloat LightPos0[] = {1000,1000,1000,1};
285  //GLfloat LightPos1[] = {-1000,-1000,-1000,1};
286 
287 
288  //glLightfv(GL_LIGHT0,GL_POSITION,LightPos0);
289  //glLightfv(GL_LIGHT1,GL_POSITION,LightPos1);
290 
291  // Active l'éclairage des deux côtés des polygones.
292  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
293 
294  // Couleur de fond
295  //glClearColor(0.0, 0.0, 0.0, 1.0);
296 
297  // Mode de transparence à utiliser lors de l'activation de la transparence.
298  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
299 
300  // Modification des propriétés de la matière courante.
301  glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Material_Ks);
302  glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Material_Ke);
303  glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,Material_Se);
304 
305  // Modification de la couleur de la lumière n°1.
306  glLightfv(GL_LIGHT0,GL_AMBIENT, Light_Ka);
307  glLightfv(GL_LIGHT0,GL_DIFFUSE, Light_Kd);
308  glLightfv(GL_LIGHT0,GL_SPECULAR, Light_Ks);
309 
310  // Modification de la couleur de la lumière n°2.
311  glLightfv(GL_LIGHT1,GL_AMBIENT, Light_Ka);
312  glLightfv(GL_LIGHT1,GL_DIFFUSE, Light_Kd);
313  glLightfv(GL_LIGHT1,GL_SPECULAR, Light_Ks);
314 
315  switch (FViewMode)
316  {
317  case SPAMOD_TOPOLOGICAL:
318  {
319  glPointSize(3.0);
320 
321  // Affichage des brins.
322  glColor3f(1.0, 1.0, 0.0);
323 
324  // Creation de l'affichage Topologique (brins).
325  TV->Darts_Draw();
326 
327  glPointSize(1.0);
328 
329  glLineWidth(2.0);
330 
331  // Affichage des liaisons alpha0.
332  //if (parameters[0] == true)
333  //{
334  glColor3f(1.0, 0.0, 0.0);
335  // Creation de l'affichage Topologique (alpha i).
336  TV->Alpha_Draw(0);
337  //}
338 
339  // Affichage des liaisons alpha1.
340  //if (parameters[1] == true)
341  //{
342  glColor3f(0.0, 0.8, 0.0);
343  // Creation de l'affichage Topologique (alpha i).
344  TV->Alpha_Draw(1);
345  //}
346 
347  // Affichage des liaisons alpha2.
348  //if (parameters[2] == true)
349  //{
350  glColor3f(0.0, 0.0, 1.0);
351  // Creation de l'affichage Topologique (alpha i).
352  TV->Alpha_Draw(2);
353  //}
354 
355  // Affichage des liaisons alpha3.
356  //if (parameters[3] == true)
357  //{
358  glColor3f(0.7, 0.7, 0.7);
359  // Creation de l'affichage Topologique (alpha i).
360  TV->Alpha_Draw(3);
361  //}
362 
363  glLineWidth(1.0);
364  }
365  break;
366  case SPAMOD_EUCLIDIAN:
367  {
368 
369 
370  if (FEuclidianParam[0])
371  EV->Wire_Draw();
372 
373 
374 
375  if (FEuclidianParam[1])
376  {
377  // glEnable(GL_BLEND);
378  // glDepthMask(GL_FALSE);
379 
380  color = colors->Get_Color(2);
381 
382  glColor4f(color->Get_R(),
383  color->Get_G(),
384  color->Get_B(),
385  0.7);
386 
387  EV->Solid_Draw();
388 
389  // glDepthMask(GL_TRUE);
390  // glDisable(GL_BLEND);
391  }
392 
393  }
394  break;
395  case SPAMOD_ANALYTIC:
396  {
397  bool translucid = getAnalyticParam(3);
398 
399  //GL::enableLight();
400 
401  if (getAnalyticParam(0))
402  {
403  color = colors->Get_Color(0);
404  glColor4f(color->Get_R(), color->Get_G(), color->Get_B(),
405  translucid ? 0.5 : 1.0);
406  AV->Vertices_Draw();
407  }
408 
409  if (getAnalyticParam(1))
410  {
411  color = colors->Get_Color(1);
412  glColor4f(color->Get_R(), color->Get_G(), color->Get_B(),
413  translucid ? 0.5 : 1.0);
414  AV->Edges_Draw();
415  }
416 
417  if (getAnalyticParam(2))
418  {
419  if (translucid)
420  {
421  // FEuclidianView->Solid_Draw(FColors);
422  // glEnable(GL_BLEND);
423  // glDepthMask(GL_FALSE);
424  }
425 
426  color = colors->Get_Color(2);
427  glColor4f(color->Get_R(), color->Get_G(), color->Get_B(),
428  translucid ? 0.5 : 1.0);
429  AV->Faces_Draw();
430 
431  if (translucid)
432  {
433  // glDepthMask(GL_TRUE);
434  // glDisable(GL_BLEND);
435  }
436  }
437 
438  }
439  break;
440  case SPAMOD_VOXEL:
441  {
442  //GL::enableLight();
443 
444  if (getVoxelParam(0))
445  {
446  color = colors->Get_Color(0);
447  glColor3f(color->Get_R(), color->Get_G(), color->Get_B());
448  VV->Draw_Vertices();
449  }
450 
451  if (getVoxelParam(1))
452  {
453  color = colors->Get_Color(1);
454  glColor3f(color->Get_R(), color->Get_G(), color->Get_B());
455  VV->Draw_Edges();
456  }
457 
458  if (getVoxelParam(2))
459  {
460  color = colors->Get_Color(2);
461  glColor3f(color->Get_R(), color->Get_G(), color->Get_B());
462  VV->Draw_Faces();
463  }
464  }
465  break;
466  case SPAMOD_K2:
467  {
468  if (getK2Param(0))
469  {
470  color = colors->Get_Color(0);
471  //GL::disableLight();
472  glColor3f(color->Get_R(), color->Get_G(), color->Get_B());
473  KV->Draw_Pointels();
474  }
475 
476  if (getK2Param(1))
477  {
478  color = colors->Get_Color(3);
479  //GL::disableLight();
480  glColor3f(color->Get_R(), color->Get_G(), color->Get_B());
481  KV->Draw_Lignels();
482  }
483 
484  if (getK2Param(2))
485  {
486  // glEnable(GL_BLEND);
487  // glDepthMask(GL_FALSE);
488 
489  color = colors->Get_Color(2);
490  //GL::enableLight();
491  glColor4f(color->Get_R(), color->Get_G(), color->Get_B(), 0.8);
492  KV->Draw_Surfels();
493 
494  // glDepthMask(GL_TRUE);
495  // glDisable(GL_BLEND);
496  }
497  }
498  break;
499  default:
500  {
501  }
502  }
503  //glDisable(GL_LIGHT0);
504  //glDisable(GL_LIGHT1);
505 
506  //glPopAttrib();
507 
508 }
509 //******************************************************************************