Branch data Line data Source code
1 : : #include "meshkit/AF2RuleApplication.hpp"
2 : : #include "meshkit/Error.hpp"
3 : :
4 : 7479 : AF2RuleApplication::AF2RuleApplication(
5 : : std::list<const AF2Point2D*> const & newPointsList,
6 : : std::list<const AF2Polygon2D*> const & newFacesList) :
7 : 7479 : numNewPoints(newPointsList.size()), numNewFaces(newFacesList.size())
8 : : {
9 : : // type definitions for two iterators that the constructor will use
10 : : typedef std::list<const AF2Point2D*>::const_iterator ConstPntItrType;
11 : : typedef std::list<const AF2Polygon2D*>::const_iterator ConstPolyItrType;
12 : :
13 : : // check whether there is a null-valued pointer in the list of new points
14 [ + - + - ]: 24442 : for (ConstPntItrType itr = newPointsList.begin();
[ + + ]
15 : 12222 : itr != newPointsList.end(); ++itr)
16 : : {
17 [ + - ][ + + ]: 4743 : if (*itr == NULL)
18 : : {
19 [ + - ]: 1 : MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
20 [ + - ]: 1 : badArg.set_string("newPointsList may not contain a null pointer in AF2RuleApplication.");
21 [ + - ]: 1 : throw badArg;
22 : : }
23 : : }
24 : :
25 : : // check whether there is a null-valued pointer in the list of faces
26 [ + - + - ]: 37102 : for (ConstPolyItrType itr = newFacesList.begin();
[ + + ]
27 : 18552 : itr != newFacesList.end(); ++itr)
28 : : {
29 [ + - ][ + + ]: 11074 : if (*itr == NULL)
30 : : {
31 [ + - ]: 1 : MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
32 : : badArg.set_string(
33 [ + - ]: 1 : "newFacesList may not contain a null pointer in AF2RuleApplication.");
34 [ + - ]: 1 : throw badArg;
35 : : }
36 : : }
37 : :
38 : : // map from new points passed in to the copies of the new points
39 [ + - ]: 7477 : std::map<const AF2Point2D*, const AF2Point2D*> pointPtrCopyMap;
40 : :
41 : : // now that the constructor has checked things that will cause it
42 : : // to throw its own exceptions, proceed with allocating memory, etc.
43 [ + - ][ + - ]: 7477 : newPoints = new const AF2Point2D*[numNewPoints];
44 : 7477 : int indx = 0;
45 [ + - + - ]: 24436 : for (ConstPntItrType itr = newPointsList.begin();
[ + + ]
46 : 12218 : itr != newPointsList.end(); ++itr)
47 : : {
48 [ + - ][ + - ]: 4741 : newPoints[indx] = new AF2Point2D(*(*itr));
49 [ + - ][ + - ]: 4741 : pointPtrCopyMap[*itr] = newPoints[indx];
50 : 4741 : ++indx;
51 : : }
52 : :
53 [ + - ][ + - ]: 7477 : newFaces = new const AF2Polygon2D*[numNewFaces];
54 : 7477 : indx = 0;
55 [ + - + - ]: 37098 : for (ConstPolyItrType itr = newFacesList.begin();
[ + + ]
56 : 18549 : itr != newFacesList.end(); ++itr)
57 : : {
58 [ + - ][ + - ]: 11072 : mapCopyPolygon(*(*itr), newFaces[indx], pointPtrCopyMap);
59 : 11072 : ++indx;
60 : 7477 : }
61 : 7477 : }
62 : :
63 : 14036 : AF2RuleApplication::~AF2RuleApplication()
64 : : {
65 [ + + ]: 34393 : for (unsigned int plygnIndx = 0; plygnIndx < numNewFaces; ++plygnIndx)
66 : : {
67 [ + - ]: 20357 : delete newFaces[plygnIndx];
68 : : }
69 [ + - ]: 14036 : delete[] newFaces;
70 : :
71 [ + + ]: 22840 : for (unsigned int pntIndx = 0; pntIndx < numNewPoints; ++pntIndx)
72 : : {
73 : 8804 : delete newPoints[pntIndx];
74 : : }
75 [ + - ]: 14036 : delete[] newPoints;
76 : 14036 : }
77 : :
78 : 6559 : AF2RuleApplication::AF2RuleApplication(const AF2RuleApplication & toCopy) :
79 : 6559 : numNewPoints(toCopy.numNewPoints), numNewFaces(toCopy.numNewFaces)
80 : : {
81 [ + - ]: 6559 : std::map<const AF2Point2D*, const AF2Point2D*> pointPtrCopyMap;
82 : :
83 [ + - ][ + - ]: 6559 : newPoints = new const AF2Point2D*[numNewPoints];
84 [ + + ]: 10603 : for (unsigned int pntIndx = 0; pntIndx < numNewPoints; ++pntIndx)
85 : : {
86 [ + - ]: 4044 : newPoints[pntIndx] = new AF2Point2D(*(toCopy.newPoints[pntIndx]));
87 [ + - ]: 4044 : pointPtrCopyMap[toCopy.newPoints[pntIndx]] = newPoints[pntIndx];
88 : : }
89 : :
90 [ + - ][ + - ]: 6559 : newFaces = new const AF2Polygon2D*[numNewFaces];
91 [ + + ]: 15763 : for (unsigned int plygnIndx = 0; plygnIndx < numNewFaces; ++plygnIndx)
92 : : {
93 : 9204 : mapCopyPolygon(*(toCopy.newFaces[plygnIndx]),
94 [ + - ]: 9204 : newFaces[plygnIndx], pointPtrCopyMap);
95 : 6559 : }
96 : 6559 : }
97 : :
98 : 108 : AF2RuleApplication& AF2RuleApplication::operator=(
99 : : const AF2RuleApplication & rhs)
100 : : {
101 : : // copy constructor functionality, but copy to
102 : : // other parts of memory rather than to this
103 [ + - ]: 108 : std::map<const AF2Point2D*, const AF2Point2D*> pointPtrCopyMap;
104 : :
105 [ + - ][ + - ]: 108 : const AF2Point2D** otherNewPoints = new const AF2Point2D*[rhs.numNewPoints];
106 [ + + ]: 194 : for (unsigned int pntIndx = 0; pntIndx < rhs.numNewPoints; ++pntIndx)
107 : : {
108 [ + - ]: 86 : otherNewPoints[pntIndx] = new AF2Point2D(*(rhs.newPoints[pntIndx]));
109 [ + - ]: 86 : pointPtrCopyMap[rhs.newPoints[pntIndx]] = otherNewPoints[pntIndx];
110 : : }
111 : :
112 [ + - ][ + - ]: 108 : const AF2Polygon2D** otherNewFaces = new const AF2Polygon2D*[rhs.numNewFaces];
113 [ + + ]: 347 : for (unsigned int plygnIndx = 0; plygnIndx < rhs.numNewFaces; ++plygnIndx)
114 : : {
115 : 239 : mapCopyPolygon(*(rhs.newFaces[plygnIndx]),
116 [ + - ]: 239 : otherNewFaces[plygnIndx], pointPtrCopyMap);
117 : : }
118 : :
119 : : // destructor functionality to clean up current members of this
120 [ + + ]: 266 : for (unsigned int plygnIndx = 0; plygnIndx < numNewFaces; ++plygnIndx)
121 : : {
122 [ + - ]: 158 : delete newFaces[plygnIndx];
123 : : }
124 [ + - ]: 108 : delete[] newFaces;
125 : :
126 [ + + ]: 175 : for (unsigned int pntIndx = 0; pntIndx < numNewPoints; ++pntIndx)
127 : : {
128 : 67 : delete newPoints[pntIndx];
129 : : }
130 [ + - ]: 108 : delete[] newPoints;
131 : :
132 : : // transfer ownership from other parts of memory to this object
133 : 108 : numNewPoints = rhs.numNewPoints;
134 : 108 : newPoints = otherNewPoints;
135 : 108 : otherNewPoints = NULL; // not necessary, but to be explicit
136 : 108 : numNewFaces = rhs.numNewFaces;
137 : 108 : newFaces = otherNewFaces;
138 : 108 : otherNewFaces = NULL; // not necessary, but to be explicit
139 : :
140 : : // return reference to this
141 : 108 : return *this;
142 : : }
143 : :
144 : 34323 : unsigned int AF2RuleApplication::getNumNewFaces() const
145 : : {
146 : 34323 : return numNewFaces;
147 : : }
148 : :
149 : 20312 : const AF2Polygon2D* AF2RuleApplication::getNewFace(
150 : : unsigned int newFaceIndex) const
151 : : {
152 [ + + ]: 20312 : if (newFaceIndex >= numNewFaces)
153 : : {
154 [ + - ]: 1 : MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
155 [ + - ]: 1 : badArg.set_string("newFaceIndex is out of range");
156 [ + - ]: 1 : throw badArg;
157 : : }
158 : 20311 : return newFaces[newFaceIndex];
159 : : }
160 : :
161 : 10617 : unsigned int AF2RuleApplication::getNumNewPoints() const
162 : : {
163 : 10617 : return numNewPoints;
164 : : }
165 : :
166 : 4079 : const AF2Point2D* AF2RuleApplication::getNewPoint(
167 : : unsigned int newPointIndex) const
168 : : {
169 [ + + ]: 4079 : if (newPointIndex >= numNewPoints)
170 : : {
171 [ + - ]: 1 : MeshKit::Error badArg(MeshKit::MK_BAD_INPUT);
172 [ + - ]: 1 : badArg.set_string("newPointIndex is out of range");
173 [ + - ]: 1 : throw badArg;
174 : : }
175 : 4078 : return newPoints[newPointIndex];
176 : : }
177 : :
178 : 20515 : void AF2RuleApplication::mapCopyPolygon(const AF2Polygon2D & sourcePolygon,
179 : : const AF2Polygon2D* & targetPolygon,
180 : : const std::map<const AF2Point2D*, const AF2Point2D*> & vertexMap)
181 : : {
182 [ + - ]: 20515 : std::list<const AF2Point2D*> mapCopyVertices;
183 [ + - ][ + + ]: 82067 : for (unsigned int vIndx = 0; vIndx < sourcePolygon.getNumVertices(); ++vIndx)
184 : : {
185 [ + - ]: 61552 : const AF2Point2D* sourcePolyVertex = sourcePolygon.getVertex(vIndx);
186 : : typedef std::map<const AF2Point2D*, const AF2Point2D*>::const_iterator
187 : : ConstItrType;
188 [ + - ]: 61552 : ConstItrType mappedVertex = vertexMap.find(sourcePolyVertex);
189 [ + - ][ + + ]: 61552 : if (mappedVertex == vertexMap.end())
190 : : {
191 : : // The vertex is not a new vertex from rule application.
192 : : // Instead it is from the neighborhood and does not need to be mapped
193 [ + - ]: 46311 : mapCopyVertices.push_back(sourcePolyVertex);
194 : : }
195 : : else
196 : : {
197 : : // The vertex is a vertex from the rule application and
198 : : // this code maps it to the appropriate pointer in the object
199 : : // that is being constructed.
200 [ + - ][ + - ]: 15241 : mapCopyVertices.push_back(mappedVertex->second);
201 : : }
202 : : }
203 : :
204 [ + - ][ + - ]: 20515 : targetPolygon = new AF2Polygon2D(mapCopyVertices);
205 : 20515 : }
|