本文整理汇总了C++中ConvexPolygon类的典型用法代码示例。如果您正苦于以下问题:C++ ConvexPolygon类的具体用法?C++ ConvexPolygon怎么用?C++ ConvexPolygon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConvexPolygon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect
ConvexPolygon intersect(const ConvexPolygon &a1, const ConvexPolygon &a2)
{
ConvexPolygon toReturn;
toReturn = a1;
toReturn.append(a2);
toReturn.simplify();
return toReturn;
}
示例2: qstart
/**
* Rebin the input quadrilateral to the output grid
* @param inputQ The input polygon
* @param inputWS The input workspace containing the input intensity values
* @param i The index in the vertical axis direction that inputQ references
* @param j The index in the horizontal axis direction that inputQ references
* @param outputWS A pointer to the output workspace that accumulates the data
* @param verticalAxis A vector containing the output vertical axis bin boundaries
*/
void Rebin2D::rebinToFractionalOutput(const Geometry::Quadrilateral & inputQ,
MatrixWorkspace_const_sptr inputWS,
const size_t i, const size_t j,
RebinnedOutput_sptr outputWS,
const std::vector<double> & verticalAxis)
{
const MantidVec & X = outputWS->readX(0);
size_t qstart(0), qend(verticalAxis.size()-1), en_start(0), en_end(X.size() - 1);
if( !getIntersectionRegion(outputWS, verticalAxis, inputQ, qstart, qend, en_start, en_end)) return;
for( size_t qi = qstart; qi < qend; ++qi )
{
const double vlo = verticalAxis[qi];
const double vhi = verticalAxis[qi+1];
for( size_t ei = en_start; ei < en_end; ++ei )
{
const V2D ll(X[ei], vlo);
const V2D lr(X[ei+1], vlo);
const V2D ur(X[ei+1], vhi);
const V2D ul(X[ei], vhi);
const Quadrilateral outputQ(ll, lr, ur, ul);
double yValue = inputWS->readY(i)[j];
if (boost::math::isnan(yValue))
{
continue;
}
try
{
ConvexPolygon overlap = intersectionByLaszlo(outputQ, inputQ);
const double weight = overlap.area()/inputQ.area();
yValue *= weight;
double eValue = inputWS->readE(i)[j] * weight;
const double overlapWidth = overlap.largestX() - overlap.smallestX();
// Don't do the overlap removal if already RebinnedOutput.
// This wreaks havoc on the data.
if(inputWS->isDistribution() && inputWS->id() != "RebinnedOutput")
{
yValue *= overlapWidth;
eValue *= overlapWidth;
}
eValue *= eValue;
PARALLEL_CRITICAL(overlap)
{
outputWS->dataY(qi)[ei] += yValue;
outputWS->dataE(qi)[ei] += eValue;
outputWS->dataF(qi)[ei] += weight;
}
}
catch(Geometry::NoIntersectionException &)
{}
}
}
}
示例3:
// ---------------------------------------------------------------------------------
ConvexPolygon::ConvexPolygon(const ConvexPolygon& src) {
const PolygonPoints& pnts = src.getPoints();
unsigned int size = pnts.size();
mPoints.reserve(size);
for (unsigned int x = 0; x < size; x++)
mPoints.push_back(pnts.at(x));
this->mPlane = src.getPlane();
}
示例4: contains
/**
* Is the given polygon completely encosed by this one
* @param poly Another polygon
* @return True if the given polygon is enclosed by this, false otherwise
*/
bool ConvexPolygon::contains(const ConvexPolygon &poly) const {
// Basically just have to test if each point is inside us, this could be
// slow
const Vertex2D *current = poly.head();
for (size_t i = 0; i < poly.numVertices(); ++i) {
if (!this->contains(*current))
return false;
current = current->next();
}
return true;
}
示例5: envelopes
bool ConvexPolygon::envelopes(const ConvexPolygon &polygon) const
{
for(const Point &p : polygon.vertices())
if(!hasPoint(p))
return false;
return true;
}
示例6: if
size_t S4r::Pattern::Overlap(
const ConvexPolygon &poly,
std::vector<double> &value
) const{
value.resize(shape.size()+1);
value[0] = 1.;
for(size_t k = 1; k <= shape.size(); ++k){
value[k] = 0;
}
const double area = poly.Area();
const double inv_area = 1. / area;
const Vec2 org(poly.offset + poly.v[0]);
for(size_t j = 2; j < poly.v.size(); ++j){
const Vec2 u(poly.v[j-1]-poly.v[0]);
const Vec2 v(poly.v[j ]-poly.v[0]);
for(size_t k = 0; k < shape.size(); ++k){
double a = shape[k]->OverlapTriangle(org, u, v) * inv_area;
if(a > 0){
value[k+1] += a;
value[parent[k]+1] -= a;
}
}
}
size_t ret = 0;
const double tol = 4.*DBL_EPSILON * area;
for(size_t k = 0; k <= shape.size(); ++k){
if(value[k] < tol){ value[k] = 0; }
else if(value[k] > 1){ value[k] = 1; }
if(value[k] > 0){ ret++; }
}
return ret;
}
示例7: projectPolygon
void projectPolygon(Vector axis, ConvexPolygon polygon, qreal &min, qreal &max)
{
// To project a point on an axis use the dot product
//qDebug() << "Projecting on "<< axis;
qreal d = axis.dotProduct(polygon.at(0));
min = d;
max = d;
for (int i = 0; i < polygon.size(); i++)
{
d= polygon.at(i).dotProduct (axis);
if (d < min)
min = d;
else
if (d> max) max = d;
// qDebug() << "p="<<polygon.at(i)<<" d="<<d<<" (min, max)=("<<min<<","<<max<<")";
}
}
示例8: contains
/**
* Is the given polygon completely encosed by this one
* @param poly Another polygon
* @return True if the given polygon is enclosed by this, false otherwise
*/
bool ConvexPolygon::contains(const ConvexPolygon &poly) const {
// Basically just have to test if each point is inside us, this could be
// slow
for (size_t i = 0; i < poly.npoints(); ++i) {
if (!this->contains(poly[i]))
return false;
}
return true;
}
示例9: MakePolygonFromFace
void CBSPTree_CollisionModel_Exporter::MakePolygonFromFace(ConvexPolygon& rPolygon, // [out]
CMapFace& rFace) // [in]
{
Vector3 avVertex[128];
int i;
for( i=0; i<rFace.GetNumVertices(); i++ )
avVertex[i] = rFace.GetVertex(i);
rPolygon.SetVertices( avVertex, rFace.GetNumVertices() );
rPolygon.SetNormal( rFace.GetPlane().normal );
rPolygon.SetDistance( rFace.GetPlane().dist );
// if( rFace.m_iPolygonIndex < 0 )
// MessageBox( NULL, "invalid polygon index", "error", MB_OK|MB_ICONWARNING );
// set the index to the corresponding 'SPolygon'
rPolygon.m_iPolygonIndex = rFace.m_iPolygonIndex;
}
示例10: overlaps
bool ConvexPolygon::overlaps(const ConvexPolygon &polygon) const
{
// First a simple bound check
if(!bounds().overlaps(polygon.bounds()))
return false;
// Overlap check using separating axis theorem
for(const glm::vec2 &normal : m_normals) {
if(!test_projection(*this, polygon, normal))
return false;
}
return true;
}
示例11: n
void S4r::Layer::GetMaterialAverage(
const ConvexPolygon &poly,
CTensor2 &eps, CTensor2 &mu,
const std::vector<Material*> &mat,
const Material *bkmat,
std::vector<double> &value // workspace
){
size_t nmat = description.pattern.Overlap(poly, value);
if(2 != nmat){
eps = value[0] * bkmat->eps.block(0,0,2,2);
for(size_t s = 0; s < description.pattern.NumShapes(); ++s){
eps += value[s+1] * mat[description.pattern.GetShape(s).tag]->eps.block(0,0,2,2);
}
mu = value[0] * bkmat->mu.block(0,0,2,2);
for(size_t s = 0; s < description.pattern.NumShapes(); ++s){
mu += value[s+1] * mat[description.pattern.GetShape(s).tag]->mu.block(0,0,2,2);
}
}else{
// perform fancy averaging
int ip1 = -1, ip2 = -1;
for(size_t i = 0; i <= description.pattern.NumShapes(); ++i){
if(value[i] > 0){
if(ip1 >= 0){ ip2 = i; break; }
else{ ip1 = i; }
}
}
// Assert that ip1 and ip2 >= 0
CTensor2 eps1, mu1;
CTensor2 eps2, mu2;
const double fill1 = value[ip1], fill2 = value[ip2];
if(0 == ip1){
eps1 = bkmat->eps.block(0,0,2,2);
mu1 = bkmat->mu.block(0,0,2,2);
}else{
int imat = description.pattern.GetShape(ip1-1).tag;
eps1 = mat[imat]->eps.block(0,0,2,2);
mu1 = mat[imat]->mu.block(0,0,2,2);
}
{
int imat = description.pattern.GetShape(ip2-1).tag;
eps2 = mat[imat]->eps.block(0,0,2,2);
mu2 = mat[imat]->mu.block(0,0,2,2);
}
Vec2 n(description.pattern.GetShape(ip2-1).Normal(poly.ApproxCenter()));
AnisotropicAverage(n, fill1, eps1, fill2, eps2, eps);
AnisotropicAverage(n, fill1, mu1, fill2, mu2, mu );
}
}
示例12: Enable
void
GL::EnableClipPlanes(const ConvexPolygon& aPolygon, UniqueId aPolygonId)
{
MOZ_ASSERT(IsCurrent());
MOZ_ASSERT(aPolygon.NumSides() <= mMaxClipPlanes);
if (mClipPolygonId == aPolygonId) {
return;
}
if (aPolygon.IsEmpty()) {
if (!mNumClipPlanes) {
Enable(GL_CLIP_PLANE0);
} else {
for (size_t i = 1; i < mNumClipPlanes; i++) {
Disable(GL_CLIP_PLANE0 + i);
}
}
mNumClipPlanes = 1;
// We specify a single clip plane equation that fails for all vertices.
const double planeEquation[] = {0, 0, 0, -1};
ClipPlane(GL_CLIP_PLANE0, planeEquation);
mClipPolygonId = aPolygonId;
return;
}
for (size_t i = mNumClipPlanes; i < aPolygon.NumSides(); i++) {
Enable(GL_CLIP_PLANE0 + i);
}
for (size_t i = aPolygon.NumSides(); i < mNumClipPlanes; i++) {
Disable(GL_CLIP_PLANE0 + i);
}
mNumClipPlanes = aPolygon.NumSides();
for (size_t i = 0; i < aPolygon.NumSides(); i++) {
const Line& line = aPolygon.Sides()[i];
const double planeEquation[] = {line.A, line.B, 0, -line.C};
ClipPlane(GL_CLIP_PLANE0 + i, planeEquation);
}
mClipPolygonId = aPolygonId;
}
示例13: testIntersection
inline bool CollisionHull::testIntersection(const ConvexPolygon& other, const ruukku::GLFloatMat3& transformationOther) const {
const BoundingBox otherBoundingBoxTransformed = other.getBoundingBox().getTransformed(transformationOther);
if (!boundingBoxTransformed.intersect(otherBoundingBoxTransformed)) return false;
for (const CollisionHullEntry& entry : entryList) {
const BoundingBox entryBoundingBoxTransformed = entry.getBoundingBox().getTransformed(transformation);
if (!entryBoundingBoxTransformed.intersect(otherBoundingBoxTransformed)) continue;
for (const ConvexPolygon& polygon : entry.convexPolygonList) {
const BoundingBox polygonBoundingBoxTransformed = polygon.getBoundingBox().getTransformed(transformation);
if (!polygonBoundingBoxTransformed.intersect(otherBoundingBoxTransformed)) continue;
else if (intersectionTester.testIntersection(polygon, other, transformation, transformationOther)) return true;
}
}
return false;
}
示例14: if
//////////////////
// GradientLayerMesh
GradientLayerMesh::GradientLayerMesh(const Rect &rect,Vec2 axisStart,Vec2 axisEnd,const Gradient *gradient)
{
ConvexPolygon rectPol =
{
rect.GetCorner(0),
rect.GetCorner(2),
rect.GetCorner(3),
rect.GetCorner(1),
};
std::vector<float> slicePositions;
for(int i = 0;i < gradient->GetNumVertices();i++)
{
slicePositions.push_back(gradient->GetVertexPos(i));
}
Vec2 axis = axisEnd - axisStart;
axis /= axis.GetSqrLen();
float axisOffset = -Dot(axis,axisStart);
std::vector<ParallelSlice> slices = rectPol.GetParallelSlices(
axisStart,axisEnd,slicePositions.data(),(int)slicePositions.size());
for(const ParallelSlice &slice : slices)
{
int seg = slice.GetSegment();
if(seg == 0)
{
std::vector<Triangle2D> tris = slice.GetPolygon().Triangulate();
for(const Triangle2D &tri : tris)
{
mVertices.push_back(tri.mVertices[0]);
mVertices.push_back(tri.mVertices[1]);
mVertices.push_back(tri.mVertices[2]);
mColors.push_back(MakeVec4(1,0,0,1));
mColors.push_back(MakeVec4(0,1,0,1));
mColors.push_back(MakeVec4(0,0,1,1));
}
}
else if(seg == gradient->GetNumVertices())
{
std::vector<Triangle2D> tris = slice.GetPolygon().Triangulate();
for(const Triangle2D &tri : tris)
{
mVertices.push_back(tri.mVertices[0]);
mVertices.push_back(tri.mVertices[1]);
mVertices.push_back(tri.mVertices[2]);
mColors.push_back(MakeVec4(1,0,0,1));
mColors.push_back(MakeVec4(0,1,0,1));
mColors.push_back(MakeVec4(0,0,1,1));
}
}
else
{
std::vector<Triangle2D> tris = slice.GetPolygon().Triangulate();
for(const Triangle2D &tri : tris)
{
for(int i = 0;i < 3;i++)
{
mVertices.push_back(tri.mVertices[i]);
float t = Dot(axis,tri.mVertices[i]) + axisOffset;
float segT = (t - slicePositions[seg - 1]) / (slicePositions[seg] - slicePositions[seg - 1]);
Vec4 color = gradient->GetVertexColor(seg - 1) * (1 - segT) + gradient->GetVertexColor(seg) * segT;
mColors.push_back(color);
}
}
}
}
}
示例15: splitPolygon
void ConvexPolygon::booleanDifference(const ConvexPolygon &hole, std::vector<ConvexPolygon> &list) const
{
// Special case: this polygon is entirely swallowed by the hole
if(hole.envelopes(*this))
return;
// Special case: the hole is entirely inside this polygon
if(envelopes(hole)) {
Points p1, p2;
splitPolygon(*this, hole, p1, p2);
ConvexPolygon::make(p1, list);
ConvexPolygon::make(p2, list);
return;
}
// Common case: hole intersects with this polygon.
std::vector<bool> visited(vertexCount());
std::queue<unsigned int> queue;
queue.push(0);
// Perform intersection
unsigned int oldsize = list.size();
Points poly;
while(!queue.empty()) {
int i = queue.front();
while(i < vertexCount()) {
// Stop if we've already been here
if(visited[i])
break;
visited[i] = true;
// Include point if it is not inside the hole
bool inhole = hole.hasPoint(vertex(i));
if(!inhole)
poly.push_back(vertex(i));
// Check for intersections
Point isect[2];
int isectv[2];
findIntersections(*this, i, i+1, hole, isect, isectv);
if(isectv[0] >= 0) {
// Intersection found: this is the start of a hole,
// except when this edge started inside the hole.
poly.push_back(isect[0]);
if(!inhole) {
// Start tracing the hole
int j = isectv[0];
do {
// Check for intersections
// The first hole edge may intersect with another edges
Point hisect[2];
int hisectv[2];
findIntersections(hole, j+1, j, *this, hisect, hisectv);
// There is always one intersection (the one that got us here)
if((j == isectv[0] && hisectv[1] >= 0) || (j != isectv[0] && hisectv[0] >= 0)) {
// Pick the intersection that is not the one we came in on
Point ip;
int iv;
if(hisectv[1] < 0 || glm::distance2(hisect[0],isect[0]) > glm::distance(hisect[1],isect[0])) {
ip = hisect[0];
iv = hisectv[0];
} else {
ip = hisect[1];
iv = hisectv[1];
}
queue.push(i+1);
// Avoid adding duplicate point of origin
if(glm::distance2(poly.front(), ip) > 0.0001)
poly.push_back(ip);
i = iv;
break;
} else {
// No intersections? Just add the hole vertex then
poly.push_back(hole.vertex(j));
}
if(--j < 0)
j = hole.vertexCount() - 1;
} while(j != isectv[0]);
}
}
++i;
}
// Partition the generated polygon into convex polygons
// and add them to the list.
if(poly.size() >= 3) {
try {
ConvexPolygon::make(poly, list);
} catch(const algorithm::GeometryException &e) {
// Bad polygons generated... The algorithm works well
// enough most of the time, let's just roll back the error.
int changes = list.size() - oldsize;
#ifndef NDEBUG
cerr << "booleanDifference error: " << e.what() << " (" << changes << " change(s) rolled back)\n";
#endif
//.........这里部分代码省略.........