Exemple #1
0
BB* BBTransform::lowerExpect(Code* code, BB* src, BB::Instrs::iterator position,
                             Value* condition, bool expected, BB* deoptBlock,
                             const std::string& debugMessage) {
    auto split = BBTransform::split(code->nextBBId++, src, position + 1, code);

    static SEXP print = Rf_findFun(Rf_install("cat"), R_GlobalEnv);

    if (debugMessage.size() != 0) {
        BB* debug = new BB(code, code->nextBBId++);
        SEXP msg = Rf_mkString(debugMessage.c_str());
        auto ldprint = new LdConst(print);
        auto ldmsg = new LdConst(msg);
        debug->append(ldmsg);
        debug->append(ldprint);
        debug->append(new Call(Env::elided(), ldprint, {ldmsg},
                               Tombstone::framestate(), 0));
        debug->setNext(deoptBlock);
        deoptBlock = debug;
    }

    src->replace(position, new Branch(condition));
    if (expected) {
        src->next1 = deoptBlock;
        src->next0 = split;
    } else {
        src->next0 = deoptBlock;
        src->next1 = split;
    }

    splitEdge(code->nextBBId++, src, deoptBlock, code);

    return split;
}
Exemple #2
0
// naja der name sagt es schon tasten abfragen
// "normale tasten"
GLvoid keyboard ( unsigned char key, int x, int y ) 
{
  switch ( key ) {
    case 27:        
      exit(0);
      break;       
	case 'a':  
      apoint.z -= 6.2f; 
      break;
    case 'y':  
      apoint.z += 6.2f; 
      break;
	 case 'o':  
      optimize(*model2, *model);
      cout << "qual: " << model2->erep/model2->crep << endl;
      break;
    case 's':  
      swapEdge(model2->edges[number], *model2, *model);
      break;
    case 'c':  
      collapseEdge(model2->edges[number], *model2, *model );
      cout << number << endl;
      break;
    case 'd':  
      splitEdge(model2->edges[number], *model2, *model );
      break;      
    case 'w':  
      roty += 5.5f; 
      break;
      
    default: 
		break;

  }
}
Exemple #3
0
void
GNENet::splitEdgesBidi(const std::set<GNEEdge*>& edges, const Position& pos, GNEUndoList* undoList) {
    GNEJunction* newJunction = 0;
    undoList->p_begin("split edges");
    for (std::set<GNEEdge*>::const_iterator it = edges.begin(); it != edges.end(); ++it) {
        newJunction = splitEdge(*it, pos, undoList, newJunction);
    }
    undoList->p_end();
}
Exemple #4
0
// Subdivide a face along a given axis
int OctreeGrid::splitFace(int node1, int node2, int node3, int node4, int normalAxis) {
	oct_debug(node1 != -1 && node2 != -1 && node3 != -1 && node4 != -1);
	oct_debug(normalAxis == X || normalAxis == Y || normalAxis == Z);
	const int ax1 = (normalAxis == X ? Y : X);
	const int ax2 = (normalAxis == Z ? Y : Z);

	// Start by splitting edges of the face
	int mid1 = splitEdge(node1, node2, ax1);
	int mid2 = splitEdge(node3, node4, ax1);
	int mid3 = splitEdge(node1, node3, ax2);
	int mid4 = splitEdge(node2, node4, ax2);

	// Connect central face node to adj nodes on ax1 and ax2
	createNodeLinks(mid1, mid2, ax2);
	createNodeLinks(mid3, mid4, ax1);
	int mid5 = splitEdge(mid1, mid2, ax2);
	updateNodeLinks(mid3, mid4, mid5, ax1);

	return mid5;
}
Halfedge_handle DegradeAnObject::addAndJoinNewPoint(Point_3 p, Halfedge_handle previousHalfedge, Halfedge_handle hh, Segment_3 s, int index) {
	Point_3 intersect;
	Halfedge_handle splittedHalfedge;
	Segment_3 seg(hh->opposite()->vertex()->point(), hh->vertex()->point());
	Point_3* chkPt; 
	CGAL::cpp11::result_of<Kernel::Intersect_3(Segment_3, Segment_3)>::type result = CGAL::intersection(s, seg);
	if (result) {
		chkPt = boost::get<Point_3 >(&*result);
		intersect = *chkPt;
	}
	Halfedge_handle split = splitEdge(hh, intersect, index);
	Halfedge_handle hhx = polys[index].split_facet(previousHalfedge, split);
	Halfedge_handle oppositePoint = hhx->next()->opposite();
	polys[index].split_facet(oppositePoint, oppositePoint->next()->next());
	
	return oppositePoint;
}
void AutoTriangleMesh<PointType>::limitEdgeLength(const typename AutoTriangleMesh<PointType>::BasePoint& center,double radius,double maxEdgeLength)
	{
	/* Iterate through all triangles: */
	FaceIterator faceIt=BaseMesh::beginFaces();
	while(faceIt!=BaseMesh::endFaces())
		{
		/* Check whether face overlaps area of influence and calculate face's maximum edge length: */
		bool overlaps=false;
		Edge* longestEdge=0;
		double longestEdgeLength2=maxEdgeLength*maxEdgeLength;
		Edge* e=faceIt->getEdge();
		for(int i=0;i<3;++i)
			{
			overlaps=overlaps||sqrDist(*e->getStart(),center)<=radius*radius;
			
			/* Calculate edge's squared length: */
			double edgeLength2=sqrDist(*e->getStart(),*e->getEnd());
			if(longestEdgeLength2<edgeLength2)
				{
				longestEdge=e;
				longestEdgeLength2=edgeLength2;
				}
			
			/* Go to next edge: */
			e=e->getFaceSucc();
			}
		
		/* Check whether the longest triangle edge is too long: */
		if(overlaps&&longestEdge!=0)
			{
			/* Split longest edge: */
			splitEdge(longestEdge);
			}
		else
			{
			/* Go to next triangle: */
			++faceIt;
			}
		}
	}
Exemple #7
0
// Subdivide a cell and add the subcells to the octree
int OctreeGrid::splitCell(int cellId, bool graded, bool paired) {
	oct_debug(cellId != -1);
	oct_debug(cellIsLeaf(cellId));
	const Cell &cell = m_Cells[cellId];

	// Retrieve cell corners
	const int v0 = cell.corner(CORNER_X0_Y0_Z0);
	const int v1 = cell.corner(CORNER_X1_Y0_Z0);
	const int v2 = cell.corner(CORNER_X1_Y1_Z0);
	const int v3 = cell.corner(CORNER_X0_Y1_Z0);
	const int v4 = cell.corner(CORNER_X0_Y0_Z1);
	const int v5 = cell.corner(CORNER_X1_Y0_Z1);
	const int v6 = cell.corner(CORNER_X1_Y1_Z1);
	const int v7 = cell.corner(CORNER_X0_Y1_Z1);

	// Start by splitting incident faces
	const int f0 = splitFace(v0, v3, v4, v7, X);
	const int f1 = splitFace(v1, v2, v5, v6, X);
	const int f2 = splitFace(v0, v1, v4, v5, Y);
	const int f3 = splitFace(v3, v2, v7, v6, Y);
	const int f4 = splitFace(v0, v1, v3, v2, Z);
	const int f5 = splitFace(v4, v5, v7, v6, Z);

	// Then connect the middle points of the faces
	createNodeLinks(f0, f1, X);
	createNodeLinks(f2, f3, Y);
	createNodeLinks(f4, f5, Z);
	const int c0 = splitEdge(f0, f1, X);
	updateNodeLinks(f2, f3, c0, Y);
	updateNodeLinks(f4, f5, c0, Z);

	// Retrieve midpoint of cell edges
	const int e01 = getMidEdgeNode(v0, v1, X);
	const int e32 = getMidEdgeNode(v3, v2, X);
	const int e45 = getMidEdgeNode(v4, v5, X);
	const int e76 = getMidEdgeNode(v7, v6, X);
	const int e03 = getMidEdgeNode(v0, v3, Y);
	const int e12 = getMidEdgeNode(v1, v2, Y);
	const int e47 = getMidEdgeNode(v4, v7, Y);
	const int e56 = getMidEdgeNode(v5, v6, Y);
	const int e04 = getMidEdgeNode(v0, v4, Z);
	const int e15 = getMidEdgeNode(v1, v5, Z);
	const int e26 = getMidEdgeNode(v2, v6, Z);
	const int e37 = getMidEdgeNode(v3, v7, Z);

	// Create a new cell for each subvolume
	const int offset = (int) m_Cells.size();
	m_Cells.resize(m_Cells.size() + 8);
	m_Cells[offset+CORNER_X0_Y0_Z0].cornerNodeId = {{v0, e01, f4, e03, e04, f2, c0, f0}};
	m_Cells[offset+CORNER_X1_Y0_Z0].cornerNodeId = {{e01, v1, e12, f4, f2, e15, f1, c0}};
	m_Cells[offset+CORNER_X1_Y1_Z0].cornerNodeId = {{f4, e12, v2, e32, c0, f1, e26, f3}};
	m_Cells[offset+CORNER_X0_Y1_Z0].cornerNodeId = {{e03, f4, e32, v3, f0, c0, f3, e37}};
	m_Cells[offset+CORNER_X0_Y0_Z1].cornerNodeId = {{e04, f2, c0, f0, v4, e45, f5, e47}};
	m_Cells[offset+CORNER_X1_Y0_Z1].cornerNodeId = {{f2, e15, f1, c0, e45, v5, e56, f5}};
	m_Cells[offset+CORNER_X1_Y1_Z1].cornerNodeId = {{c0, f1, e26, f3, f5, e56, v6, e76}};
	m_Cells[offset+CORNER_X0_Y1_Z1].cornerNodeId = {{f0, c0, f3, e37, e47, f5, e76, v7}};

	// Update link to child cell
	m_Cells[cellId].firstChild = offset;

	// Update cell adjacency relations
	for (int axis = 0; axis < 3; ++axis) {
		updateSubcellLinks(cellId, axis);
		updateSubcellLinks(cellId, nextCell(cellId, axis), axis);
		updateSubcellLinks(prevCell(cellId, axis), cellId, axis);
	}

	// Ensure proper 2:1 grading
	if (graded) {
		makeCellGraded(cellId, paired);
	}

	// Ensure children are either all leaves, or all internal cells
	if (paired) {
		makeCellPaired(cellId, graded);

		if (cellId < m_NumRootCells) {
			// Special case for root cells: if one gets split, then we need to split all root cells
			for (int c = 0; c < m_NumRootCells; ++c) {
				if (cellIsLeaf(c)) { splitCell(c, graded, paired); }
			}
		} else {
			// Ensure sibling cells are also properly split
			int firstSibling = m_NumRootCells + 8 * ((cellId - m_NumRootCells) / 8);
			for (int c = firstSibling; c < firstSibling + 8; ++c) {
				if (cellIsLeaf(c)) { splitCell(c, graded, paired); }
			}
		}

	}

	return c0;
}
void AutoTriangleMesh<PointType>::splitEdge(const typename AutoTriangleMesh<PointType>::EdgeIterator& edge)
	{
	/* Get triangle topology: */
	Edge* e1=&(*edge);
	Edge* e2=e1->getFaceSucc();
	Edge* e3=e1->getFacePred();
	Vertex* v1=e1->getStart();
	Vertex* v2=e2->getStart();
	Vertex* v3=e3->getStart();
	Face* f1=e1->getFace();
	
	assert(e2->getFaceSucc()==e3&&e3->getFacePred()==e2);
	assert(e2->getFace()==f1);
	assert(e3->getFace()==f1);
	assert(f1->getEdge()==e1||f1->getEdge()==e2||f1->getEdge()==e3);
	
	Edge* e4=e1->getOpposite();
	if(e4!=0)
		{
		Edge* e5=e4->getFaceSucc();
		Edge* e6=e4->getFacePred();
		Vertex* v4=e6->getStart();
		Face* f2=e4->getFace();
		
		assert(e5->getFaceSucc()==e6&&e6->getFacePred()==e5);
		assert(e4->getStart()==v2);
		assert(e5->getStart()==v1);
		assert(e5->getFace()==f2);
		assert(e6->getFace()==f2);
		assert(f2->getEdge()==e4||f2->getEdge()==e5||f2->getEdge()==e6);
		
		/* Don't increase aspect ratio of triangles when splitting: */
		double e4Len2=sqrDist(*v1,*v2);
		double e5Len2=sqrDist(*v1,*v4);
		double e6Len2=sqrDist(*v2,*v4);
		if(e4Len2<e5Len2||e4Len2<e6Len2)
			{
			/* Split longest edge in neighbouring triangle first: */
			if(e5Len2>e6Len2)
				splitEdge(e5);
			else
				splitEdge(e6);
			
			/* Re-get triangle topology: */
			e4=e1->getOpposite();
			e5=e4->getFaceSucc();
			e6=e4->getFacePred();
			v4=e6->getStart();
			f2=e4->getFace();
			}
		
		/* Create new vertex for edge midpoint: */
		Point p=Point::zero();
		p.add(*edge->getStart());
		p.add(*edge->getEnd());
		p.normalize(2);
		p.index=nextVertexIndex;
		++nextVertexIndex;
		typename BaseMesh::Vertex* nv=newVertex(p);
		
		/* Create two quadrilaterals: */
		Edge* ne1=BaseMesh::newEdge();
		Edge* ne2=BaseMesh::newEdge();
		nv->setEdge(ne1);
		e1->setFaceSucc(ne1);
		e1->setOpposite(ne2);
		e2->setFacePred(ne1);
		e4->setFaceSucc(ne2);
		e4->setOpposite(ne1);
		e5->setFacePred(ne2);
		ne1->set(nv,f1,e1,e2,e4);
		ne1->sharpness=0;
		ne2->set(nv,f2,e4,e5,e1);
		ne2->sharpness=0;
		f1->setEdge(e1);
		f2->setEdge(e4);
		
		/* Triangulate first quadrilateral: */
		Edge* ne3=BaseMesh::newEdge();
		Edge* ne4=BaseMesh::newEdge();
		Face* nf1=BaseMesh::newFace();
		e1->setFaceSucc(ne3);
		e3->setFacePred(ne3);
		e2->setFace(nf1);
		e2->setFaceSucc(ne4);
		ne1->setFace(nf1);
		ne1->setFacePred(ne4);
		ne3->set(nv,f1,e1,e3,ne4);
		ne3->sharpness=0;
		ne4->set(v3,nf1,e2,ne1,ne3);
		ne4->sharpness=0;
		nf1->setEdge(ne1);
		
		/* Triangulate second quadrilateral: */
		Edge* ne5=BaseMesh::newEdge();
		Edge* ne6=BaseMesh::newEdge();
		Face* nf2=BaseMesh::newFace();
		e4->setFaceSucc(ne5);
		e6->setFacePred(ne5);
		e5->setFace(nf2);
		e5->setFaceSucc(ne6);
		ne2->setFace(nf2);
		ne2->setFacePred(ne6);
		ne5->set(nv,f2,e4,e6,ne6);
		ne5->sharpness=0;
		ne6->set(v4,nf2,e5,ne2,ne5);
		ne6->sharpness=0;
		nf2->setEdge(ne2);
		
		/* Update version numbers of all involved vertices: */
		++version;
		v1->version=version;
		v2->version=version;
		v3->version=version;
		v4->version=version;
		nv->version=version;
		}
	else
		{
		/* Create new vertex for edge midpoint: */
		Point p=Point::zero();
		p.add(*edge->getStart());
		p.add(*edge->getEnd());
		p.normalize(2);
		p.index=nextVertexIndex;
		++nextVertexIndex;
		typename BaseMesh::Vertex* nv=newVertex(p);
		
		/* Create one quadrilateral: */
		Edge* ne=BaseMesh::newEdge();
		nv->setEdge(ne);
		e1->setFaceSucc(ne);
		e2->setFacePred(ne);
		ne->set(nv,f1,e1,e2,0);
		ne->sharpness=0;
		f1->setEdge(e1);
		
		/* Triangulate quadrilateral: */
		Edge* ne3=BaseMesh::newEdge();
		Edge* ne4=BaseMesh::newEdge();
		Face* nf1=BaseMesh::newFace();
		e1->setFaceSucc(ne3);
		e3->setFacePred(ne3);
		e2->setFace(nf1);
		e2->setFaceSucc(ne4);
		ne->setFace(nf1);
		ne->setFacePred(ne4);
		ne3->set(nv,f1,e1,e3,ne4);
		ne3->sharpness=0;
		ne4->set(v3,nf1,e2,ne,ne3);
		ne4->sharpness=0;
		nf1->setEdge(ne);
		
		/* Update version numbers of all involved vertices: */
		++version;
		v1->version=version;
		v2->version=version;
		v3->version=version;
		nv->version=version;
		}
	}