| 81 | |
| 82 | |
| 83 | void FaceRasterFilter::filter(PointView& v) |
| 84 | { |
| 85 | double halfEdge = m_limits->edgeLength / 2; |
| 86 | double edgeBit = m_limits->edgeLength * .000001; |
| 87 | |
| 88 | // If the user hasn't set bounds, set them based on the data. |
| 89 | if (m_computeLimits) |
| 90 | { |
| 91 | BOX2D bounds; |
| 92 | v.calculateBounds(bounds); |
| 93 | m_limits->xOrigin = bounds.minx - halfEdge; |
| 94 | m_limits->yOrigin = bounds.miny - halfEdge; |
| 95 | m_limits->width = (int)(((bounds.maxx - m_limits->xOrigin) / m_limits->edgeLength) + 1); |
| 96 | m_limits->height = (int)(((bounds.maxy - m_limits->yOrigin) / m_limits->edgeLength) + 1); |
| 97 | } |
| 98 | Rasterd *raster = v.createRaster("faceraster", *m_limits, m_noData); |
| 99 | if (!raster) |
| 100 | throwError("Raster already exists"); |
| 101 | |
| 102 | TriangularMesh *m = v.mesh(m_meshName); |
| 103 | if (!m) |
| 104 | throwError("Mesh '" + m_meshName + "' does not exist."); |
| 105 | |
| 106 | for (const Triangle& t : *m) |
| 107 | { |
| 108 | double x1 = v.getFieldAs<double>(Dimension::Id::X, t.m_a); |
| 109 | double y1 = v.getFieldAs<double>(Dimension::Id::Y, t.m_a); |
| 110 | double z1 = v.getFieldAs<double>(Dimension::Id::Z, t.m_a); |
| 111 | |
| 112 | double x2 = v.getFieldAs<double>(Dimension::Id::X, t.m_b); |
| 113 | double y2 = v.getFieldAs<double>(Dimension::Id::Y, t.m_b); |
| 114 | double z2 = v.getFieldAs<double>(Dimension::Id::Z, t.m_b); |
| 115 | |
| 116 | if (!std::isinf(m_maxTriangleEdgeLength) && |
| 117 | std::hypot(x2 - x1, y2 - y1) > m_maxTriangleEdgeLength) |
| 118 | continue; |
| 119 | |
| 120 | double x3 = v.getFieldAs<double>(Dimension::Id::X, t.m_c); |
| 121 | double y3 = v.getFieldAs<double>(Dimension::Id::Y, t.m_c); |
| 122 | double z3 = v.getFieldAs<double>(Dimension::Id::Z, t.m_c); |
| 123 | |
| 124 | if (!std::isinf(m_maxTriangleEdgeLength) && |
| 125 | (std::hypot(x2 - x3, y2 - y3) > m_maxTriangleEdgeLength || |
| 126 | std::hypot(x1 - x3, y1 - y3) > m_maxTriangleEdgeLength)) |
| 127 | continue; |
| 128 | |
| 129 | double xmax = (std::max)((std::max)(x1, x2), x3); |
| 130 | double xmin = (std::min)((std::min)(x1, x2), x3); |
| 131 | double ymax = (std::max)((std::max)(y1, y2), y3); |
| 132 | double ymin = (std::min)((std::min)(y1, y2), y3); |
| 133 | |
| 134 | // Since we're checking cell centers, we add 1/2 the edge length to avoid testing cells |
| 135 | // where we know the limiting position can't intersect the cell center. The |
| 136 | // subtraction of edgeBit for the lower bound is to allow for the case where the |
| 137 | // minimum position is exactly aligned with a cell center (we could simply start one cell |
| 138 | // lower and to the left, but this small adjustment eliminates that extra row/col in most |
| 139 | // cases). |
| 140 | bool okX, okY; |
nothing calls this directly
no test coverage detected