bool MovePoly() { int origpos = RangeRand(poly_.size()); int newpos = RangeRand(poly_.size()); if (newpos == origpos) return false; PolyIt it = poly_.begin(); std::advance(it, origpos); DnaPolygon p(*it); poly_.erase(it); it = poly_.begin(); std::advance(it, newpos); poly_.insert(it, p); return true; }
bool AddPoly() { if (poly_.size() == Settings::MaxPolygons) return false; int idx = RangeRand(poly_.size()); PolyIt it = poly_.begin(); std::advance(it, idx); poly_.insert(it, DnaPolygon()); return true; }
bool DelPoly() { if (poly_.size() == Settings::MinPolygons) return false; int idx = RangeRand(poly_.size()); PolyIt it = poly_.begin(); std::advance(it, idx); poly_.erase(it); return true; }
/* -------------------------------------------------------------------------------- ------ FacetComplex class functions ----------------------------------------------- -------------------------------------------------------------------------------- */ FacetComplex::FacetComplex(const PolyRing& /*P*/, const PolyList& PL) { // facet f_tmp; // vector<long> v(NumIndets(P)); for (PolyList::const_iterator it=PL.begin(); it!=PL.end();++it) { // exponents(v,LPP(*it)); // f_tmp=facet(v); // myInsert(f_tmp); myInsert(facet(LPP(*it))); } }//FacetComplex
void dtEndComplexShape() { if (currentComplex->getBase().getPointer() == 0) { Point *ptr = new Point[pointBuf.size()]; copy(pointBuf.begin(), pointBuf.end(), ptr); currentComplex->setBase(ptr, true); pointBuf.erase(pointBuf.begin(), pointBuf.end()); } currentComplex->finish(polyList.size(), &polyList[0]); polyList.erase(polyList.begin(), polyList.end()); complexList.push_back(currentComplex); currentComplex = 0; }
bool Mutate() { bool dirty = false; if (DoMutate(AddPolyMutation)) dirty |= AddPoly(); if (DoMutate(DelPolyMutation)) dirty |= DelPoly(); if (DoMutate(MovePolyMutation)) dirty |= MovePoly(); for (PolyIt it = poly_.begin(); it != poly_.end(); ++it) dirty |= it->Mutate(); return dirty; }
void Render(Image &dest) const { dest.Clear(); for (PolyList::const_iterator it = poly_.begin(); it != poly_.end(); ++it) it->Render(dest); }
bool ITR3DMImport::findColinear(const Point3F& v1,const Point3F& v2, Poly* spoly,PolyList& polyList,ColinearList* colinearList) { colinearList->clear(); Point3F vec1 = v2; vec1 -= v1; float len = vec1.len(); if (!len || len < distancePrecision) return false; float timeScale = 1.0f / len; vec1 *= timeScale; float maxDistance = len - distancePrecision; float dist2Precision = distancePrecision * distancePrecision; for (PolyList::iterator ptr = polyList.begin(); ptr != polyList.end(); ptr++) { Poly* poly = *ptr; if (poly == spoly) continue; for (Poly::VertexList::iterator itr = poly->vertexList.begin(); itr != poly->vertexList.end(); itr++) { if ((*itr).colinear) // Skip points that were inserted, we should end up testing // the original point. continue; // Is it within the bounds of the line seg? Point3F vec2,&v3 = (*itr).point; vec2.x = v3.x - v1.x; vec2.y = v3.y - v1.y; vec2.z = v3.z - v1.z; float d = m_dot(vec1,vec2); if (d > distancePrecision && d < maxDistance) { // Now lets see if it's on the line Point3F dp; dp.x = v3.x - (v1.x + vec1.x * d); dp.y = v3.y - (v1.y + vec1.y * d); dp.z = v3.z - (v1.z + vec1.z * d); float dist2 = dp.x * dp.x + dp.y * dp.y + dp.z * dp.z; if (dist2 < dist2Precision) { // Sanity check here, make sure the point is // on the plane. if (spoly->plane.whichSide((*itr).point) == TPlaneF::OnPlane) { colinearList->increment(); colinearList->last().time = d * timeScale; colinearList->last().point = (*itr).point; } } } } } // Sort by increasing time value. float precision = distancePrecision / len; if (colinearList->size()) { qsort(colinearList->address(),colinearList->size(),sizeof(Colinear), Colinear::compare); // Remove duplicates for (int i = 1; i < colinearList->size(); i++) { float delta = (*colinearList)[i].time - (*colinearList)[i-1].time; if (fabs(delta) < precision) colinearList->erase(i--); } return true; } return false; }