Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mv-mesh.cc
Go to the documentation of this file.
1 /*
2  * lib-mesh : Opérations de maillage et lissage.
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-mesh
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 "mesh-vertex.hh"
26 #include "g-map-vertex.hh"
27 #include "inter-smooth-diver.hh"
28 #include <cassert>
29 using namespace GMap3d;
30 //******************************************************************************
31 void CMeshVertex::mesh1(CDart * ADart, int ASx,
32  const CTransformationMatrix * AMeshMatrix,
33  bool AMeshWithMerges,
34  bool AMeshWithAdjacentSews,
35  bool AMeshAssociatedCells,
36  int ADirectInfoAlpha0, int ADirectInfoAssoc)
37 {
38  assert(ADart!=NULL);
39  assert(canMesh1(ADart));
40  assert(ASx>0);
41  assert(!AMeshWithMerges || ADirectInfoAlpha0>=0);
42  assert( AMeshWithMerges || ADirectInfoAssoc >=0);
43 
44  // Récupération des points de contrôle:
45  CMesh1Diver* diver;
46 
47  if (AMeshMatrix == &COONS || AMeshMatrix == NULL)
48  {
49  CVertex & V1 = * FMap->findVertex(ADart);
50  CVertex & V2 = * FMap->findVertex(FMap->alpha0(ADart));
51  diver = new CMesh1LinearDiver(ASx, V1,V2);
52  }
53  else
54  {
55  CVertex CP[4];
56 
57  get4ControlPoints(ADart, CP, ADirectInfoAlpha0);
58  diver = new CMesh1SmoothingDiver(ASx, *AMeshMatrix, CP);
59  }
60 
61  // Topologie:
62  CMeshGeneric::mesh1(ADart, ASx, AMeshMatrix, AMeshWithMerges,
63  AMeshWithAdjacentSews, AMeshAssociatedCells,
64  ADirectInfoAlpha0, ADirectInfoAssoc);
65 
66  // Plongements:
67  CDart * first = AMeshWithMerges
68  ? ADart : FMap->getDirectInfoAsDart(ADart, ADirectInfoAssoc);
69 
70  FMap->diveMesh1(first, *diver, CGMapVertex::GMV_CHECK);
71 
72  delete diver;
73 }
74 //******************************************************************************
75 void CMeshVertex::mesh2(CDart* ADart,
76  int ASx, int ASy,
77  const CTransformationMatrix * AMeshMatrix,
78  bool AMeshWithMerges,
79  bool AMeshWithAdjacentSews,
80  bool AMeshAssociatedCells,
81  bool AGetAssociatedEmbeddings,
82  int AInitialMeshDim, int AFinalMeshDim,
83  int ADirectInfoAlpha0, int ADirectInfoAssoc)
84 {
85  assert(ADart!=NULL);
86  assert(ASx>0);
87  assert(ASy>0);
88  assert(0<=AInitialMeshDim && AInitialMeshDim<=1);
89  assert(1<=AFinalMeshDim && AFinalMeshDim <=2);
90  assert(AInitialMeshDim < AFinalMeshDim);
91  assert(canMesh2(AMeshAssociatedCells
92  ? FMap->getDirectInfoAsDart(ADart, ADirectInfoAssoc) : ADart,
93  ASx,ASy, AInitialMeshDim));
94 
95  assert(FMap->findVertex(ADart)!=NULL);
96 
97  // Topologie:
98  CMeshGeneric::mesh2(ADart, ASx,ASy, AMeshMatrix, AMeshWithMerges,
99  AMeshWithAdjacentSews, AMeshAssociatedCells,
100  AGetAssociatedEmbeddings,
101  AInitialMeshDim, AFinalMeshDim,
102  ADirectInfoAlpha0, ADirectInfoAssoc);
103 
104  assert(FMap->findVertex(ADart)!=NULL);
105 
106  // Plongements:
107  if (AFinalMeshDim==2)
108  {
109  CMesh2Diver* diver;
110 
111  CDart* geo =
112  AGetAssociatedEmbeddings
113  ? FMap->getDirectInfoAsDart(ADart, ADirectInfoAssoc)
114  : ADart;
115 
116  assert(FMap->findVertex(geo)!=NULL);
117 
118  if (AMeshMatrix == &COONS || AMeshMatrix == NULL)
119  {
120  CDart * current;
121 
122  const CVertex ** bottom = new const CVertex * [ASx+1];
123  const CVertex ** top = new const CVertex * [ASx+1];
124  const CVertex ** left = new const CVertex * [ASy+1];
125  const CVertex ** right = new const CVertex * [ASy+1];
126 
127  bool already2Meshed = AInitialMeshDim!=1 || AMeshWithMerges;
128 
129  current = getMesh1Dive(geo, ASx, bottom, already2Meshed);
130  getMesh1Dive(FMap->alpha1(current), ASy, right, already2Meshed);
131 
132  current = getMesh1Dive(FMap->alpha1(geo), ASy, left, already2Meshed);
133  getMesh1Dive(FMap->alpha1(current), ASx, top, already2Meshed);
134 
135  diver = new CMesh2LinearDiver(ASx,ASy, bottom,top,left,right);
136 
137  delete [] bottom;
138  delete [] top;
139  delete [] left;
140  delete [] right;
141  }
142  else
143  {
144  CVertex** CP = allocVertexArray2(4,4);
145 
146  get16ControlPoints(ADart, CP, ADirectInfoAlpha0);
147 
148  diver = new CMesh2SmoothingDiver(ASx,ASy, *AMeshMatrix,
149  (const CVertex **) CP);
150 
151  freeVertexArray2(CP, 4,4);
152  }
153 
154  CDart * first =
155  AMeshAssociatedCells
156  ? FMap->getDirectInfoAsDart(ADart, ADirectInfoAssoc)
157  : ADart;
158 
159  FMap->diveMesh2(first, *diver, CGMapVertex::GMV_CHECK);
160 
161  delete diver;
162  }
163 }
164 //******************************************************************************
165 void CMeshVertex::mesh3(CDart * ADart,
166  int ASx, int ASy, int ASz,
167  const CTransformationMatrix * AMeshMatrix,
168  bool AMeshWithMerges,
169  bool AMeshWithAdjacentSews,
170  bool AMeshAssociatedCells,
171  int AInitialMeshDim, int AFinalMeshDim,
172  int /*ADirectInfoAlpha0*/, int ADirectInfoAssoc)
173 {
174  assert(ASx>0);
175  assert(ASy>0);
176  assert(ASz>0);
177 
178  assert(0 <= AInitialMeshDim);
179  assert(AInitialMeshDim < AFinalMeshDim);
180  assert(AFinalMeshDim <= 3);
181 
182  assert(canMesh3(ADart, ASx,ASy,ASz, AInitialMeshDim));
183 
184  // Topologie:
185  CMeshGeneric::mesh3(ADart, ASx,ASy,ASz, AMeshMatrix, AMeshWithMerges,
186  AMeshWithAdjacentSews, AMeshAssociatedCells,
187  AInitialMeshDim,AFinalMeshDim, ADirectInfoAssoc);
188 
189  // Plongements:
190  if (AFinalMeshDim==3)
191  {
192  const CVertex
193  *** left = allocVertexPtrArray2(ASy+1, ASz+1),
194  *** right = allocVertexPtrArray2(ASy+1, ASz+1),
195  *** front = allocVertexPtrArray2(ASz+1, ASx+1),
196  *** back = allocVertexPtrArray2(ASz+1, ASx+1),
197  *** bottom = allocVertexPtrArray2(ASx+1, ASy+1),
198  *** top = allocVertexPtrArray2(ASx+1, ASy+1);
199 
200  // Récupération des plongements du cube 2-maillé:
201  CDart * other;
202 
203  other = getMesh2Dive( ADart , ASx,ASy, bottom, true, 1);
204  /* - */ getMesh2Dive(FMap->alpha12 (other), ASy,ASz, right , true );
205  other = getMesh2Dive(FMap->alpha12 (ADart), ASy,ASz, left , true, 1);
206  /* - */ getMesh2Dive(FMap->alpha12 (other), ASz,ASx, back , true );
207  other = getMesh2Dive(FMap->alpha1212(ADart), ASz,ASx, front , true, 1);
208  /* - */ getMesh2Dive(FMap->alpha12 (other), ASx,ASy, top , true );
209 
210  // Affectation:
211  CMesh3LinearDiver diver(ASx,ASy,ASz, left,right,front,back,bottom,top);
212  FMap->diveMesh3(ADart, diver, CGMapVertex::GMV_CHECK);
213 
214  // Libération:
215  freeVertexPtrArray2(left , ASy+1, ASz+1);
216  freeVertexPtrArray2(right , ASy+1, ASz+1);
217  freeVertexPtrArray2(front , ASz+1, ASx+1);
218  freeVertexPtrArray2(back , ASz+1, ASx+1);
219  freeVertexPtrArray2(bottom, ASx+1, ASy+1);
220  freeVertexPtrArray2(top , ASx+1, ASy+1);
221  }
222 }
223 //******************************************************************************