March along connected lines to the end----------------------------------
| 118 | |
| 119 | // March along connected lines to the end---------------------------------- |
| 120 | void OutputPolygon(LoopPointType& sortedPoints, vtkPoints* inPts, vtkCellArray* outLines, |
| 121 | vtkCellArray* outPolys, int loopClosure) |
| 122 | { |
| 123 | // Check to see that last point is the same as the first. Such a loop is |
| 124 | // closed and can be directly output. Otherwise, check on the strategy |
| 125 | // for closing the loop and close as appropriate. |
| 126 | vtkIdType num = static_cast<vtkIdType>(sortedPoints.size()); |
| 127 | if (sortedPoints[0].Id == sortedPoints[num - 1].Id) |
| 128 | { |
| 129 | --num; |
| 130 | sortedPoints.erase(sortedPoints.begin() + num); |
| 131 | } |
| 132 | |
| 133 | else if (loopClosure == VTK_LOOP_CLOSURE_ALL) |
| 134 | { |
| 135 | // do nothing and it will close between the first and last points |
| 136 | } |
| 137 | |
| 138 | // If here we assume that the loop begins and ends on the given bounding |
| 139 | // box (i.e. the boundary of the data). Close the loop by walking the |
| 140 | // bounding box in the plane defined by the Normal plus the loop start |
| 141 | // point. |
| 142 | else if (loopClosure == VTK_LOOP_CLOSURE_BOUNDARY) |
| 143 | { |
| 144 | // First check the simple case, complete the loop along horizontal or |
| 145 | // vertical lines (assumed on the boundary). |
| 146 | double p0[3], p1[3], delX, delY; |
| 147 | inPts->GetPoint(sortedPoints[0].Id, p0); |
| 148 | inPts->GetPoint(sortedPoints[num - 1].Id, p1); |
| 149 | delX = fabs(p0[0] - p1[0]); |
| 150 | delY = fabs(p0[1] - p1[1]); |
| 151 | |
| 152 | // if no change in either the x or y direction just return, the loop will complete |
| 153 | if (delX < FLT_EPSILON || delY < FLT_EPSILON) |
| 154 | { |
| 155 | // do nothing loop will complete; points are along same (horizontal or vertical) boundary |
| 156 | // edge |
| 157 | } |
| 158 | |
| 159 | // Otherwise check if the points are on the "boundary" and then complete the loop |
| 160 | // along the shortest path around the boundary. |
| 161 | else |
| 162 | { |
| 163 | return; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Don't close |
| 168 | else // loopClosure == VTK_LOOP_CLOSURE_OFF |
| 169 | { |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | // Return if not a valid loop |
| 174 | if (num < 3) |
| 175 | { |
| 176 | return; |
| 177 | } |
no test coverage detected