1 // Copyright (C) 2004-2010 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //=============================================================================
21 // File : HEXABLOCKPlugin_HEXABLOCK.cxx
23 // Author : Lioka RAZAFINDRAZAKA (CEA)
26 //=============================================================================
28 #include "HEXABLOCKPlugin_HEXABLOCK.hxx"
29 #include "HEXABLOCKPlugin_Hypothesis.hxx"
31 #include <Basics_Utils.hxx>
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_MesherHelper.hxx"
37 #include "HEXABLOCKPlugin_mesh.hxx"
39 #include "HexQuad.hxx"
40 #include "HexEdge.hxx"
41 #include "HexVertex.hxx"
42 #include "HexPropagation.hxx"
44 #include "utilities.h"
48 static int MYDEBUG = 0;
50 //=============================================================================
54 //=============================================================================
56 HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK(int hypId, int studyId, SMESH_Gen* gen)
57 : SMESH_3D_Algo(hypId, studyId, gen)
59 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK");
60 _name = "HEXABLOCK_3D";
61 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
62 _compatibleHypothesis.push_back("HEXABLOCK_Parameters");
63 _requireShape = false; // can work without shape
64 _requireDescretBoundary = false;
65 _onlyUnaryInput = false; // Compute() will be called on a compound of solids
67 _supportSubmeshes = false;
70 //=============================================================================
74 //=============================================================================
76 HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK()
78 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK");
81 //=============================================================================
85 //=============================================================================
87 bool HEXABLOCKPlugin_HEXABLOCK::CheckHypothesis ( SMESH_Mesh& aMesh,
88 const TopoDS_Shape& aShape,
89 Hypothesis_Status& aStatus )
91 aStatus = SMESH_Hypothesis::HYP_OK;
93 // there is only one compatible Hypothesis so far
95 const list <const SMESHDS_Hypothesis * >& hyps = GetUsedHypothesis(aMesh, aShape);
97 _hyp = static_cast<const HEXABLOCKPlugin_Hypothesis*> ( hyps.front() );
102 //=============================================================================
104 *Here we are going to use the HEXABLOCK mesher
106 //=============================================================================
108 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh,
109 const TopoDS_Shape& theShape)
111 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute with a shape");
113 switch (_hyp->GetDimension()) {
114 case 0 : return( Compute0D(theMesh) );
115 case 1 : return( Compute1D(theMesh) );
116 case 2 : return( Compute2D(theMesh) );
117 default: return( Compute3D(theMesh) );
121 //=============================================================================
123 *Here we are going to use the HEXABLOCK mesher w/o geometry
125 //=============================================================================
127 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh,
128 SMESH_MesherHelper* aHelper)
130 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute without a shape");
132 switch (_hyp->GetDimension()) {
133 case 0 : return( Compute0D(theMesh) );
134 case 1 : return( Compute1D(theMesh) );
135 case 2 : return( Compute2D(theMesh) );
136 default: return( Compute3D(theMesh) );
140 //=============================================================================
144 //=============================================================================
145 bool HEXABLOCKPlugin_HEXABLOCK::Evaluate(SMESH_Mesh& aMesh,
146 const TopoDS_Shape& aShape,
147 MapShapeNbElems& aResMap)
149 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Evaluate: do nothing");
154 //=============================================================================
156 * Generate hexehedral
158 //=============================================================================
160 bool HEXABLOCKPlugin_HEXABLOCK::Compute3D(SMESH_Mesh& theMesh) {
161 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D");
163 SMESH_HexaBlocks hexaBuilder(theMesh);
165 HEXA_NS::Document* doc = _hyp->GetDocument();
166 hexaBuilder.computeDoc(doc);
167 hexaBuilder.buildGroups(doc);
172 //=============================================================================
174 * Generate quadrangles
176 //=============================================================================
178 bool HEXABLOCKPlugin_HEXABLOCK::Compute2D(SMESH_Mesh& theMesh)
180 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 2D");
182 HEXA_NS::Document* doc = _hyp->GetDocument();
183 SMESH_HexaBlocks hexaBuilder(theMesh);
185 // A) Vertex computation
186 int nVertex = doc->countVertex();
187 HEXA_NS::Vertex* vertex = NULL;
188 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
189 vertex = doc->getVertex(j);
190 hexaBuilder.computeVertex(*vertex);
193 // B) Edges computation
195 HEXA_NS::Propagation* propa = NULL;
196 HEXA_NS::Law* law = NULL;
197 HEXA_NS::Edges edges;
199 nbPropa = doc->countPropagation();
200 for (int j=0; j < nbPropa; ++j ){ //Computing each edge's propagations of the document
201 propa = doc->getPropagation(j);
202 edges = propa->getEdges();
203 law = propa->getLaw();
205 law = doc->getLaw(0); // default law
207 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
208 hexaBuilder.computeEdge(**iter, *law);
212 // C) Quad computation
213 std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(doc);
214 int nQuad = doc->countQuad();
215 HEXA_NS::Quad* quad = NULL;
216 for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
217 quad = doc->getQuad(j);
218 int id = quad->getId();
219 if ( quadWays.count(quad) > 0 )
220 hexaBuilder.computeQuad(*quad, quadWays[quad]);
222 if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
226 hexaBuilder.buildGroups(doc);
231 // SMESH::SMESH_Mesh_ptr SMESH_Gen_i::HexaBlocksQuad( HEXABLOCK_ORB::Document_ptr docIn, ::CORBA::Long quadID )
234 // SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
235 // if ( !aNewMesh->_is_nil() ) {
236 // SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
237 // Document_impl* docServant = dynamic_cast<Document_impl*>( GetServant( docIn ).in() );
238 // ASSERT( aNewImpl );
239 // ASSERT( docServant );
241 // HEXA_NS::Document* doc = docServant->GetImpl();
242 // SMESH_HexaBlocks hexaBuilder(aNewImpl);
244 // // A) Vertex computation
245 // int nVertex = doc->countVertex();
246 // HEXA_NS::Vertex* vertex = NULL;
247 // for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
248 // vertex = doc->getVertex(j);
249 // hexaBuilder.computeVertex(*vertex);
252 // // B) Edges computation
254 // HEXA_NS::Propagation* propa = NULL;
255 // HEXA_NS::Law* law = NULL;
256 // HEXA_NS::Edges edges;
258 // nbPropa = doc->countPropagation();
259 // for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
260 // propa = doc->getPropagation(j);
261 // edges = propa->getEdges();
262 // law = propa->getLaw();
265 // law = doc->getLaw(0); // default law
267 // for( HEXA_NS::Edges::const_iterator iter = edges.begin();
268 // iter != edges.end();
270 // hexaBuilder.computeEdge(**iter, *law);
274 // // C) Quad computation
275 // std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(*doc);
276 // int nQuad = doc->countQuad();
277 // HEXA_NS::Quad* quad = NULL;
278 // for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
279 // quad = doc->getQuad(j);
280 // int id = quad->getId();
281 // if ( quadID == id and (quadWays.count(quad) > 0) )
282 // hexaBuilder.computeQuad( *quad, quadWays[quad] );
284 // if ( quadWays.count(quad) == 0 )
285 // if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
289 // // D) build Groups
290 // hexaBuilder.buildGroups(doc);
293 // return aNewMesh._retn();
294 // } catch (SALOME_Exception& S_ex) {
295 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
299 bool HEXABLOCKPlugin_HEXABLOCK::Compute1D(SMESH_Mesh& theMesh)
301 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 1D");
303 HEXA_NS::Document* doc = _hyp->GetDocument();
304 SMESH_HexaBlocks hexaBuilder(theMesh);
306 // A) Vertex computation
307 int nVertex = doc->countVertex();
308 HEXA_NS::Vertex* vertex = NULL;
309 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
310 vertex = doc->getVertex(j);
311 hexaBuilder.computeVertex(*vertex);
314 // B) Edges computation
316 HEXA_NS::Propagation* propa = NULL;
317 HEXA_NS::Law* law = NULL;
318 HEXA_NS::Edges edges;
320 nbPropa = doc->countPropagation();
321 for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
322 propa = doc->getPropagation(j);
323 edges = propa->getEdges();
324 law = propa->getLaw();
327 law = doc->getLaw(0); // default law
329 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
330 hexaBuilder.computeEdge(**iter, *law);
335 hexaBuilder.buildGroups(doc);
340 bool HEXABLOCKPlugin_HEXABLOCK::Compute0D(SMESH_Mesh& theMesh)
342 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 0D");
344 HEXA_NS::Document* doc = _hyp->GetDocument();
345 SMESH_HexaBlocks hexaBuilder(theMesh);
347 // A) Vertex computation
348 int nVertex = doc->countVertex();
349 HEXA_NS::Vertex* vertex = NULL;
350 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
351 vertex = doc->getVertex(j);
352 hexaBuilder.computeVertex(*vertex);
356 hexaBuilder.buildGroups(doc);