- }
-
- // 1. - identify faces and vertices of the "cube"
- // 1.1 - ancestor maps vertex->edges in the cube
- MESSAGE("---");
-
- TopTools_IndexedDataMapOfShapeListOfShape MS;
- TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
-
- // 1.2 - first face is choosen as face Y=0 of the unit cube
- MESSAGE("---");
-
- const TopoDS_Shape& aFace = meshFaces[0]->GetSubShape();
- const TopoDS_Face& F = TopoDS::Face(aFace);
-
- // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
- MESSAGE("---");
-
- int i = 0;
- TopoDS_Edge E = _quads[0]->edge[i]; //edge will be Y=0,Z=0 on unit cube
- double f,l;
- Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
- TopoDS_Vertex VFirst, VLast;
- TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
- bool isForward = (((l-f)*(_quads[0]->last[i] - _quads[0]->first[i])) > 0);
-
- if (isForward)
- {
- _cube.V000 = VFirst; // will be (0,0,0) on the unit cube
- _cube.V100 = VLast; // will be (1,0,0) on the unit cube
- }
- else
- {
- _cube.V000 = VLast;
- _cube.V100 = VFirst;
- }
-
- i = 1;
- E = _quads[0]->edge[i];
- C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
- TopExp::Vertices(E, VFirst, VLast);
- isForward = (((l-f)*(_quads[0]->last[i] - _quads[0]->first[i])) > 0);
- if (isForward) _cube.V101 = VLast; // will be (1,0,1) on the unit cube
- else _cube.V101 = VFirst;
-
- i = 2;
- E = _quads[0]->edge[i];
- C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
- TopExp::Vertices(E, VFirst, VLast);
- isForward = (((l-f)*(_quads[0]->last[i] - _quads[0]->first[i])) > 0);
- if (isForward) _cube.V001 = VLast; // will be (0,0,1) on the unit cube
- else _cube.V001 = VFirst;
-
- // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
- // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
- // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
- // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
- MESSAGE("---");
-
- TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V000, MS);
- ASSERT(! E_0Y0.IsNull());
-
- TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V100, MS);
- ASSERT(! E_1Y0.IsNull());
-
- TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V101, MS);
- ASSERT(! E_1Y1.IsNull());
-
- TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V001, MS);
- ASSERT(! E_0Y1.IsNull());
-
- // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
- MESSAGE("---");
-
- TopExp::Vertices(E_0Y0, VFirst, VLast);
- if (VFirst.IsSame(_cube.V000)) _cube.V010 = VLast;
- else _cube.V010 = VFirst;
-
- TopExp::Vertices(E_1Y0, VFirst, VLast);
- if (VFirst.IsSame(_cube.V100)) _cube.V110 = VLast;
- else _cube.V110 = VFirst;
-
- TopExp::Vertices(E_1Y1, VFirst, VLast);
- if (VFirst.IsSame(_cube.V101)) _cube.V111 = VLast;
- else _cube.V111 = VFirst;
-
- TopExp::Vertices(E_0Y1, VFirst, VLast);
- if (VFirst.IsSame(_cube.V001)) _cube.V011 = VLast;
- else _cube.V011 = VFirst;
-
- // 1.6 - find remaining faces given 4 vertices
- MESSAGE("---");
-
- _indY0 = 0;
- _cube.quad_Y0 = _quads[_indY0];
-
- _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
- _cube.V010,_cube.V011,_cube.V110,_cube.V111);
- _cube.quad_Y1 = _quads[_indY1];
-
- _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
- _cube.V000,_cube.V010,_cube.V100,_cube.V110);
- _cube.quad_Z0 = _quads[_indZ0];
-
- _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
- _cube.V001,_cube.V011,_cube.V101,_cube.V111);
- _cube.quad_Z1 = _quads[_indZ1];
-
- _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
- _cube.V000,_cube.V001,_cube.V010,_cube.V011);
- _cube.quad_X0 = _quads[_indX0];
-
- _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
- _cube.V100,_cube.V101,_cube.V110,_cube.V111);
- _cube.quad_X1 = _quads[_indX1];
-
- MESSAGE("---");
-
- // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
-
- Conv2DStruct cx0; // for face X=0
- Conv2DStruct cx1; // for face X=1
- Conv2DStruct cy0;
- Conv2DStruct cy1;
- Conv2DStruct cz0;
- Conv2DStruct cz1;
-
- GetConv2DCoefs(*_cube.quad_X0, meshFaces[_indX0]->GetSubShape(),
- _cube.V000,_cube.V010,_cube.V011,_cube.V001,
- cx0);
- GetConv2DCoefs(*_cube.quad_X1, meshFaces[_indX1]->GetSubShape(),
- _cube.V100,_cube.V110,_cube.V111,_cube.V101,
- cx1);
- GetConv2DCoefs(*_cube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
- _cube.V000,_cube.V100,_cube.V101,_cube.V001,
- cy0);
- GetConv2DCoefs(*_cube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
- _cube.V010,_cube.V110,_cube.V111,_cube.V011,
- cy1);
- GetConv2DCoefs(*_cube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
- _cube.V000,_cube.V100,_cube.V110,_cube.V010,
- cz0);
- GetConv2DCoefs(*_cube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
- _cube.V001,_cube.V101,_cube.V111,_cube.V011,
- cz1);
-
- // 1.8 - create a 3D structure for normalized values
-
- MESSAGE("---");
- int nbx = _cube.quad_Y0->nbPts[0];
- int nby = _cube.quad_Y0->nbPts[1];
- int nbz;
- if (cx0.a1 != 0) nbz = _cube.quad_X0->nbPts[1];
- else nbz = _cube.quad_X0->nbPts[0];
- //SCRUTE(nbx);
- //SCRUTE(nby);
- //SCRUTE(nbz);
- int nbxyz= nbx*nby*nbz;
- Point3DStruct* np = new Point3DStruct[nbxyz];
-
- // 1.9 - store node indexes of faces
-
- {
- const TopoDS_Face& F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
- const TColStd_ListOfInteger& indElt
- = aMesh.GetSubMesh(F)->GetSubMeshDS()->GetIDNodes();
- TColStd_ListIteratorOfListOfInteger itf(indElt);
-
- faceQuadStruct* quad = _cube.quad_X0;
- int i=0; // j = x/face , k = y/face
- int nbdown = quad->nbPts[0];
- int nbright = quad->nbPts[1];
-
- for (; itf.More(); itf.Next())
- {
- int nodeId = itf.Value();
- Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
- Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
- Handle (SMDS_FacePosition) fpos
- = Handle (SMDS_FacePosition)::DownCast(node->GetPosition());
- double ri = fpos->GetUParameter();
- double rj = fpos->GetVParameter();
- int i1 = int(ri);
- int j1 = int(rj);
- int ij1 = j1*nbdown +i1;
- quad->uv_grid[ij1].nodeId = nodeId;
- }
-
- for (int i1=0; i1<nbdown; i1++)
- for (int j1=0; j1<nbright; j1++)