size_t IsoffMainParser::parseSegmentBase(Node * segmentBaseNode, SegmentInformation *info) { SegmentBase *base; if(!segmentBaseNode || !(base = new (std::nothrow) SegmentBase(info))) return 0; if(segmentBaseNode->hasAttribute("indexRange")) { size_t start = 0, end = 0; if (std::sscanf(segmentBaseNode->getAttributeValue("indexRange").c_str(), "%zu-%zu", &start, &end) == 2) { IndexSegment *index = new (std::nothrow) DashIndexSegment(info); if(index) { index->setByteRange(start, end); base->indexSegment.Set(index); /* index must be before data, so data starts at index end */ base->setByteRange(end + 1, 0); } } } parseInitSegment(DOMHelper::getFirstChildElementByName(segmentBaseNode, "Initialization"), base, info); info->setSegmentBase(base); return 1; }
void Triangulation::print(std::string fileName) { std::string path = utilities::getPath(); path += fileName; std::ofstream file; file.open(path, std::ios::out); file << points.size() << std::endl; for(int i=0;i<points.size();i++){ file << points[i].getString() << std::endl; } file << this->edges.size() << std::endl; for(auto e: this->edges.getMap()){ IndexSegment edge = e.first; file << edge.getString() << std::endl; } file << this->triangles.size() << std::endl; for(int i=0;i<this->triangles.size();i++){ file << this->triangles[i].getString() << std::endl; } file.close(); }
void Mesh::printInStream(std::ofstream &file) { file << points.size() << std::endl; for(int i=0;i<points.size();i++){ file << points[i].getString() << std::endl; } file << this->edges.size() << std::endl; for(auto e: this->edges.getMap()){ IndexSegment edge = e.first; file << edge.getString() << std::endl; } writeElements(file); }
size_t IsoffMainParser::parseSegmentBase(Node * segmentBaseNode, SegmentInformation *info) { size_t list_count = 0; if(!segmentBaseNode) return 0; else if(segmentBaseNode->hasAttribute("indexRange")) { SegmentList *list = new SegmentList(); Segment *seg; size_t start = 0, end = 0; if (std::sscanf(segmentBaseNode->getAttributeValue("indexRange").c_str(), "%zu-%zu", &start, &end) == 2) { IndexSegment *index = new DashIndexSegment(info); index->setByteRange(start, end); list->indexSegment.Set(index); /* index must be before data, so data starts at index end */ seg = new Segment(info); seg->setByteRange(end + 1, 0); } else { seg = new Segment(info); } list_count++; list->addSegment(seg); info->setSegmentList(list); Node *initSeg = DOMHelper::getFirstChildElementByName(segmentBaseNode, "Initialization"); if(initSeg) { SegmentBase *base = new SegmentBase(); parseInitSegment(initSeg, base, info); info->setSegmentBase(base); } } else { SegmentBase *base = new SegmentBase(); parseInitSegment(DOMHelper::getFirstChildElementByName(segmentBaseNode, "Initialization"), base, info); info->setSegmentBase(base); } return list_count; }
bool IndexSegment::operator==(const IndexSegment& other) const { return getFirst()==other.getFirst() && getSecond()==other.getSecond() || getFirst()==other.getSecond() && getSecond()==other.getFirst(); }
bool IndexSegment::intersection(std::vector<Point> points, IndexSegment other, Point &inter) { return Segment::intersects(points[this->p1],points[this->p2], points[other.getFirst()], points[other.getSecond()], inter); }
bool IndexSegment::contains(std::vector<Point> p, IndexSegment s) { return this->contains(p, p[s.getFirst()]) && this->contains(p, p[s.getSecond()]); }
PolygonChangeData BreakableMesh::breakMesh(int init, PointSegment crack, bool initialCrackTip, UniqueList<Pair<int>> &newPoints, std::vector<int> previous, std::vector<int> &createdPolygonIndexes, Polygon &mergedPolygon) { std::vector<Polygon> oldPolygons; std::vector<Polygon> newPolygons; SimplePolygonMerger merger; int last = previous.size()==0? -1: (previous[0]==init? previous[1] : previous[0]); NeighbourInfo n1 = getNeighbour(init, crack, previous); bool firstTime = true; Polygon merged; if(n1.neighbour<0){ //If the crack is in one element, return the same element return PolygonChangeData(oldPolygons, newPolygons); } if(initialCrackTip){ IndexSegment container_edge = this->getPolygon(init).containerEdge(getPoints().getList(), crack.getFirst()); NeighbourInfo n0 = NeighbourInfo(init, container_edge,crack.getFirst() ,false); n0.isVertex = container_edge.isEndPoint(crack.getFirst(), this->points.getList()); breakPolygons(n0, n1, -1, oldPolygons, newPolygons, newPoints); last = this->polygons.size() - 1; } bool oneLastIteration = false; while(true){ Polygon& poly1 = getPolygon(n1.neighbour); if(poly1.containsPoint(this->points.getList(), crack.getSecond())){ if(poly1.inEdges(this->points.getList(), crack.getSecond())){ if(!oneLastIteration){ oneLastIteration = true; } }else{ mergedPolygon = merged; return PolygonChangeData(oldPolygons, newPolygons); } } if(firstTime){ merged = getPolygon(n1.neighbour); firstTime = false; }else{ merged = merger.mergePolygons(merged, this->polygons[n1.neighbour], this->points.getList()); } std::vector<int> poly1_points = poly1.getPoints(); if(!n1.isVertex){ previous = {init, last}; }else{ if(last==-1){ previous.push_back(last); }else{ previous = {init, last}; } } NeighbourInfo n2 = getNeighbour(n1.neighbour, crack, previous); if(n1.isEdge){ init = n1.neighbour; n1 = n2; continue; } Pair<int> exit = breakPolygons(n1, n2, init, oldPolygons, newPolygons, newPoints); createdPolygonIndexes.push_back(n1.neighbour); createdPolygonIndexes.push_back(this->polygons.size()-1); // Iterate if(oneLastIteration){ return PolygonChangeData(oldPolygons, newPolygons); } IndexSegment edge = n2.edge; edge.orderCCW(this->points.getList(), merged.getCentroid()); merged.insertOnSegment(n2.edge, {exit.second, exit.first}); last = this->polygons.size()-1; init = n1.neighbour; n1 = n2; this->printInFile("afterBreaking.txt"); } }