Branch data Line data Source code
1 : : #include "meshkit/AF2DfltPlaneProjMaker.hpp"
2 : :
3 : : // C++
4 : : #include <cmath>
5 : :
6 : : // MeshKit
7 : : #include "meshkit/Matrix.hpp"
8 : : #include "meshkit/AF2PlaneProjection.hpp"
9 : :
10 : 41 : AF2DfltPlaneProjMaker::AF2DfltPlaneProjMaker(iGeom* iGeomPtrArg,
11 : : iGeom::EntityHandle surf, MeshKit::SizingFunction* sizingArg) :
12 : 41 : iGeomPtr(iGeomPtrArg), surface(surf), sizing(sizingArg)
13 : : {
14 : : // do nothing beyond constructing the members as above
15 : 41 : }
16 : :
17 : 9988 : AF2LocalTransform* AF2DfltPlaneProjMaker::makeLocalTransform(
18 : : const std::list<AF2Point3D*> & ngbhdPoints,
19 : : const AF2Edge3D* const & baselineEdge,
20 : : const std::list<const AF2Edge3D*> & otherNgbhdEdges) const
21 : : {
22 : : // In NetGen PLANESPACE projection type, the x-direction is the direction
23 : : // of the vector along the baseline edge, the normal is the mean of the
24 : : // normals at the endpoints of the baseline edge with the component
25 : : // in the x-direction removed, and the y-direction is the cross product.
26 : : // This implementation matches that, I think.
27 [ + - ]: 9988 : AF2Point3D* baseStart = baselineEdge->getStart();
28 [ + - ]: 9988 : AF2Point3D* baseEnd = baselineEdge->getEnd();
29 : :
30 : : // define the origin of the transformation to be the start of the
31 : : // baseline edge
32 [ + - ]: 9988 : MeshKit::Vector<3> planeOrigin;
33 [ + - ][ + - ]: 9988 : planeOrigin[0] = baseStart->getX();
34 [ + - ][ + - ]: 9988 : planeOrigin[1] = baseStart->getY();
35 [ + - ][ + - ]: 9988 : planeOrigin[2] = baseStart->getZ();
36 : :
37 : : // define the x-direction of the transformation as a unit vector in
38 : : // the direction of the baseline edge
39 [ + - ]: 9988 : MeshKit::Vector<3> planeXDir;
40 [ + - ][ + - ]: 9988 : planeXDir[0] = baseEnd->getX() - baseStart->getX();
[ + - ]
41 [ + - ][ + - ]: 9988 : planeXDir[1] = baseEnd->getY() - baseStart->getY();
[ + - ]
42 [ + - ][ + - ]: 9988 : planeXDir[2] = baseEnd->getZ() - baseStart->getZ();
[ + - ]
43 [ + - ][ + - ]: 9988 : double scale = std::sqrt(planeXDir[0] * planeXDir[0] +
44 [ + - ][ + - ]: 9988 : planeXDir[1] * planeXDir[1] + planeXDir[2] * planeXDir[2]);
[ + - ][ + - ]
45 [ + - ]: 9988 : planeXDir /= scale;
46 : :
47 : : // Get the components of the vectors that are normal to the surface
48 : : // at the endpoints of the baseline edge
49 : : double startNrmlX;
50 : : double startNrmlY;
51 : : double startNrmlZ;
52 : : iGeomPtr->getEntNrmlXYZ(surface, baseStart->getX(), baseStart->getY(),
53 [ + - ][ + - ]: 9988 : baseStart->getZ(), startNrmlX, startNrmlY, startNrmlZ);
[ + - ][ + - ]
54 : : double endNrmlX;
55 : : double endNrmlY;
56 : : double endNrmlZ;
57 : : iGeomPtr->getEntNrmlXYZ(surface, baseEnd->getX(), baseEnd->getY(),
58 [ + - ][ + - ]: 9988 : baseEnd->getZ(), endNrmlX, endNrmlY, endNrmlZ);
[ + - ][ + - ]
59 : :
60 : : // Start defining the normal vector to the plane as the mean of the
61 : : // normal vectors to the surface at the endpoints
62 [ + - ]: 9988 : MeshKit::Vector<3> planeNormal;
63 [ + - ]: 9988 : planeNormal[0] = 0.5 * (startNrmlX + endNrmlX);
64 [ + - ]: 9988 : planeNormal[1] = 0.5 * (startNrmlY + endNrmlY);
65 [ + - ]: 9988 : planeNormal[2] = 0.5 * (startNrmlZ + endNrmlZ);
66 : : // subtract from the normal vector any component in the x-direction
67 [ + - ][ + - ]: 9988 : planeNormal -= MeshKit::inner_product(planeNormal, planeXDir) * planeXDir;
[ + - ]
68 : : // normalize the normal vector to unit length
69 [ + - ][ + - ]: 9988 : planeNormal /= std::sqrt(planeNormal[0] * planeNormal[0] +
70 [ + - ][ + - ]: 9988 : planeNormal[1] * planeNormal[1] + planeNormal[2] * planeNormal[2]);
[ + - ][ + - ]
[ + - ]
71 : :
72 : 9988 : double planeSize = scale;
73 [ + + ]: 9988 : if (sizing != NULL)
74 : : {
75 : : MeshKit::Vector<3> baselineMidpoint =
76 [ + - ][ + - ]: 9668 : planeOrigin + (scale / 2.0) *planeXDir;
[ + - ]
77 [ + - ][ + - ]: 9668 : planeSize = sizing->size(baselineMidpoint.data());
78 [ - + ]: 9668 : if (planeSize < scale/1073741824.0) // 2^30 == 1073741824
79 : : {
80 : : // in particular, this catches the case where the size
81 : : // is not actually defined in the sizing function
82 : 0 : planeSize = scale;
83 : : }
84 [ - + ]: 9668 : else if (planeSize < scale / 4.0)
85 : : {
86 : 0 : planeSize = scale / 4.0;
87 : : }
88 [ - + ]: 9668 : else if (planeSize > 4.0 * scale)
89 : : {
90 : 9668 : planeSize = 4.0 * scale;
91 : : }
92 : : }
93 : :
94 : : return new AF2PlaneProjection(iGeomPtr, surface, planeOrigin,
95 [ + - ][ + - ]: 9988 : planeNormal, planeXDir, planeSize);
96 [ + - ][ + - ]: 156 : }
|