KVector3D KHalfEdgeMeshPrivate::calculateVertexNormal(const Vertex *vertex, std::vector<KVector3D> &accumulator) { // If the vertex isn't a part of any face, abandon it. if (!vertex->to) return KVector3D(); KVector3D cumulative, normal; const HalfEdge *startEdge = halfEdge(vertex->to); const HalfEdge *edge = startEdge; do { if (edge->face != 0) { normal = face(edge->face)->normal; if (std::none_of(accumulator.begin(), accumulator.end(), DotTest(normal))) { accumulator.push_back(normal); cumulative += normal; } } edge = cwSwivel(edge); } while (edge != startEdge); accumulator.clear(); // Note: QVector3D cannot handle small values. float length = cumulative.length(); if (length != 0.0f) cumulative /= length; return cumulative; }
int TriangleAdjacencyGraph::fillIndexFromFan( std::vector<Index> &indexVec, HalfEdge &firstEdge ) { int count = 0; HalfEdge *halfEdge(&firstEdge); HalfEdge *gateEdge = 0; if (halfEdge) { count = 3; indexVec.resize(2); indexVec[0] = halfEdge->vertexStart(); indexVec[1] = halfEdge->vertexEnd(); for ( gateEdge = halfEdge->next->next->twin; gateEdge != halfEdge; gateEdge = gateEdge->next->next->twin ) { indexVec.push_back(gateEdge->vertexEnd()); count++; } indexVec.push_back(halfEdge->vertexEnd()); } else { cerr << "Invalid fac in fillIndexFromFan()" << endl; } return count; }
void Square::setCenter(double x, double y) { QSizeF s=size(); double he = halfEdge(); setTopLeft(QPointF(x-he, y-he)); setSize(s); }
void Square::setCeter(const QPointF& c) { QSizeF s=size(); double he = halfEdge(); setTopLeft(QPointF(c.x()-he, c.y()-he)); setSize(s); }
KVector3D KHalfEdgeMeshPrivate::calculateFaceNormal(const Face *face) { const HalfEdge *edge = halfEdge(face->first); KVector3D pos1 = vertex(edge->to)->position; edge = halfEdge(edge->next); KVector3D pos2 = vertex(edge->to)->position; edge = halfEdge(edge->next); KVector3D pos3 = vertex(edge->to)->position; KVector3D a = pos2 - pos1; KVector3D b = pos3 - pos1; KVector3D c = KVector3D::crossProduct(a,b); // Note: QVector3D cannot handle small values. float length = c.length(); if (length != 0.0f) c /= length; return c; }
const KHalfEdgeMesh::HalfEdge *KHalfEdgeMesh::unsafeHalfEdge(size_t idx) const { return halfEdge(HalfEdgeIndex(static_cast<IndexType::index_type>(idx))); }
inline void KHalfEdgeMeshPrivate::initializeInnerHalfEdge(const KHalfEdgeMeshPrivate::HalfEdgeIndex &he, const KHalfEdgeMeshPrivate::FaceIndex &f, const KHalfEdgeMeshPrivate::HalfEdgeIndex &next) { HalfEdge *edge = halfEdge(he); edge->face = f; edge->next = next; }
inline KHalfEdgeMeshPrivate::HalfEdge const *KHalfEdgeMeshPrivate::cwBounds(HalfEdgeIndex const &idx) const { return halfEdge(cwBoundsIndex(idx)); }
inline KHalfEdgeMeshPrivate::HalfEdge const *KHalfEdgeMeshPrivate::cwBounds(HalfEdge const *he) const { return halfEdge(cwBoundsIndex(index(he))); }
inline KHalfEdgeMeshPrivate::HalfEdge const *KHalfEdgeMeshPrivate::cwSwivel(HalfEdgeIndex const &idx) const { return halfEdge(cwSwivelIndex(idx)); }
inline KHalfEdgeMeshPrivate::HalfEdge const *KHalfEdgeMeshPrivate::cwSwivel(HalfEdge const *he) const { return halfEdge(cwSwivelIndex(index(he))); }
inline KVector3D KHalfEdgeMeshPrivate::edgeVector(HalfEdgeIndex const &idx) const { return edgeVector(halfEdge(idx)); }
inline KHalfEdgeMeshPrivate::HalfEdge const *KHalfEdgeMeshPrivate::twin(HalfEdgeIndex const &idx) const { return halfEdge(twinIndex(idx)); }
inline KHalfEdgeMeshPrivate::HalfEdge const *KHalfEdgeMeshPrivate::twin(HalfEdge const *edge) const { return halfEdge(twinIndex(index(edge))); }
/******************************************************************************* * HalfEdgeMeshPrivate :: Traversal Commands ******************************************************************************/ inline KHalfEdgeMeshPrivate::HalfEdge *KHalfEdgeMeshPrivate::twin(HalfEdge *he) { return halfEdge(twinIndex(index(he))); }