Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
precompile-normal-vector.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 "controler-gmap-types.hh"
27 #include "dart-vertex.hh"
28 #include "parameter-gmap-vertex.hh"
30 #include "parameter-selection.hh"
31 #include <cassert>
32 using namespace GMap3d;
33 //******************************************************************************
36  CParameterNormalVector * AParameterNormalVector,
37  CParameterSelection * AParameterSelection) :
38  FParameterGMapV (AParameterGMapV),
39  FParameterNormalVector(AParameterNormalVector),
40  FParameterSelection (AParameterSelection)
41 {
42  assert(FParameterGMapV!=NULL);
43  assert(FParameterNormalVector!=NULL && FParameterSelection!=NULL);
44 
45  FParameterGMapV->addPrecompileToUpdate(this);
46  FParameterNormalVector->addPrecompileToUpdate(this);
47  FParameterSelection->addPrecompileToUpdate(this);
48 }
49 //******************************************************************************
52  CPrecompile (APrecompile),
53  FParameterGMapV (APrecompile.FParameterGMapV),
54  FParameterNormalVector(static_cast<CParameterNormalVector*>
55  (APrecompile.FParameterNormalVector->copy())),
56  FParameterSelection (APrecompile.FParameterSelection)
57 {
58  assert(FParameterGMapV!=NULL);
59  assert(FParameterNormalVector!=NULL && FParameterSelection!=NULL);
60 
61  FParameterGMapV->addPrecompileToUpdate(this);
62  FParameterNormalVector->addPrecompileToUpdate(this);
63  FParameterSelection->addPrecompileToUpdate(this);
64 }
65 //******************************************************************************
67 {
68  FParameterGMapV->removePrecompileToUpdate(this);
69  FParameterNormalVector->removePrecompileToUpdate(this);
70  FParameterSelection->removePrecompileToUpdate(this);
71 }
72 //******************************************************************************
74 { return new CPrecompileNormalVector(*this); }
75 //******************************************************************************
77 {
78  switch (AParameter->getType())
79  {
81  setGMapVertex(static_cast<CParameterGMapVertex *>(AParameter));
82  break;
84  setNormalVector(static_cast<CParameterNormalVector *>(AParameter));
85  break;
87  setSelection(static_cast<CParameterSelection *>(AParameter));
88  break;
89  }
90 }
91 //******************************************************************************
93 { return FParameterNormalVector; }
94 //******************************************************************************
96 {
97  assert(AParameterGMapV != NULL);
98  AParameterGMapV->addPrecompileToUpdate(this);
99  FParameterGMapV->removePrecompileToUpdate(this);
100  FParameterGMapV = AParameterGMapV;
101  setToUpdate();
102 }
103 //******************************************************************************
105  ANormalVector)
106 {
107  assert(ANormalVector != NULL);
108  ANormalVector->addPrecompileToUpdate(this);
109  FParameterNormalVector->removePrecompileToUpdate(this);
110  FParameterNormalVector = ANormalVector;
111  setToUpdate();
112 }
113 //******************************************************************************
115 {
116  assert(ASelection != NULL);
117  ASelection->addPrecompileToUpdate(this);
118  FParameterSelection->removePrecompileToUpdate(this);
119  FParameterSelection = ASelection;
120  setToUpdate();
121 }
122 //******************************************************************************
124 { return PRECOMPILE_NORMAL_VECTOR; }
125 //******************************************************************************
126 void CPrecompileNormalVector::drawNormal(CDart* ADart, bool ATwoSides)
127 {
128  CVertex bary = FParameterGMapV->getMap()->barycenter(ADart, ORBIT_01);
129  CVertex normal = FParameterGMapV->getMap()->faceNormalVector(ADart);
130 
131  float k = FParameterNormalVector->getLGNormalVector();
132 
133  CVertex p1 = bary + k*normal;
134  CVertex p2 = ATwoSides ? bary-k*normal : bary;
135 
136  LINE(& p1, & p2);
137 }
138 //******************************************************************************
140 {
141  glLineWidth(FParameterNormalVector->getLWNormalVector());
142  glColor3fv(FParameterNormalVector->getCLNormalVector());
143  glBegin(GL_LINES);
144 
145  if (FParameterNormalVector->getShowAllNormals())
146  {
147  int treated = FParameterGMapV->getMap()->getNewMark();
148 
149  for (CDynamicCoverageAll it(FParameterGMapV->getMap()); it.cont(); ++it)
150  if (! FParameterGMapV->getMap()->isMarked(*it, treated))
151  {
152  bool done = false;
153  for (CDynamicCoverage01 face(FParameterGMapV->getMap(), *it); face.cont(); ++face)
154  {
155  if (! FParameterGMapV->getMap()->isFree0(*face))
156  {
157  done = true;
158  drawNormal(*face, true);
159  }
160 
161  FParameterGMapV->getMap()->setMark(*face, treated);
162  FParameterGMapV->getMap()->setMark(FParameterGMapV->getMap()->alpha3(*face), treated);
163  }
164 
165  if (!done)
166  drawNormal(*it, false);
167  }
168 
169  FParameterGMapV->getMap()->negateMaskMark(treated);
170  FParameterGMapV->getMap()->freeMark(treated);
171  }
172  else
173  {
174  CDart* last = FParameterSelection->getLastSelectedDart();
175 
176  if (last != NULL)
177  drawNormal(last, false);
178  }
179 
180  glEnd();
181 }
182 //******************************************************************************