bool SteerLib::GJK_EPA::Triangulate(const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB)
{
	std::vector<struct triangle> trianglesA, trianglesB;
	// Pairs edges from original polygon together and also gets the triangulated points
	GetEdges(trianglesA, _shapeA);
	GetEdges(trianglesB, _shapeB);
		
	std::vector<Util::Vector> _simplex;
	for (int i = 0; i < trianglesA.size(); i++) {
		// Get points of a triangle from shapeA
		std::vector<Util::Vector> a;
		a.push_back(trianglesA[i].p1);
		a.push_back(trianglesA[i].p2);
		a.push_back(trianglesA[i].p3);

		for (int j = 0; j < trianglesB.size(); j++) {
			_simplex.clear();

			// Get points of a triangle from shapeB
			std::vector<Util::Vector> b;
			b.push_back(trianglesB[j].p1);
			b.push_back(trianglesB[j].p2);
			b.push_back(trianglesB[j].p3);
			
			// Perform GJK on every pair of trianlges from the two polygons
			if (GJK(a, b, _simplex))
				return true;
		}
	}

	return false;
}
Beispiel #2
0
// Check the graph data structure for internal consistency.
bool TUNGraph::IsOk(const bool& ThrowExcept) const {
  bool RetVal = true;
  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
    const TNode& Node = NodeH[N];
    if (! Node.NIdV.IsSorted()) {
      const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", Node.GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
      RetVal=false;
    }
    int prevNId = -1;
    for (int e = 0; e < Node.GetDeg(); e++) {
      if (! IsNode(Node.GetNbrNId(e))) {
        const TStr Msg = TStr::Fmt("Edge %d --> %d: node %d does not exist.",
          Node.GetId(), Node.GetNbrNId(e), Node.GetNbrNId(e));
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
        RetVal=false;
      }
      if (e > 0 && prevNId == Node.GetNbrNId(e)) {
        const TStr Msg = TStr::Fmt("Node %d has duplicate edge %d --> %d.",
          Node.GetId(), Node.GetId(), Node.GetNbrNId(e));
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
        RetVal=false;
      }
      prevNId = Node.GetNbrNId(e);
    }
  }
  int EdgeCnt = 0;
  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) { EdgeCnt++; }
  if (EdgeCnt != GetEdges()) {
    const TStr Msg = TStr::Fmt("Number of edges counter is corrupted: GetEdges():%d, EdgeCount:%d.", GetEdges(), EdgeCnt);
    if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
    RetVal=false;
  }
  return RetVal;
}
Beispiel #3
0
void TWgtNet::DelMinWgtNodes(const double MinWgt) {
  printf("Deleting Min Wgt %g nodes\n", MinWgt);
  printf("  (%d,%d)  -->", GetNodes(), GetEdges());
  TIntV DelNIdV;  
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    double wgt = 0;
    for (int e = 0; e < NI.GetOutDeg(); e++) { 
      wgt += NI.GetOutEDat(e);
    }
    if (wgt < MinWgt) { DelNIdV.Add(NI.GetId()); }
  }
  for (int d = 0; d < DelNIdV.Len(); d++) {
    DelNode(DelNIdV[d]);
  }
  printf("  (%d,%d)\n", GetNodes(), GetEdges());
}
Beispiel #4
0
int GenPy(PUNGraph &res, ofstream& TFile, const TStr& parameters)
{
	Env = TEnv(parameters, TNotify::StdNotify);
	TStr mN = Env.GetIfArgPrefixStr("-module:", "random_graphs", "Module name");
	TStr fN = Env.GetIfArgPrefixStr("-func:", "fast_gnp_random_graph", "Function name");
	
	PyObject **G = new PyObject*[1];
		
	char *moduleName = mN.CStr();
	char *funcName = fN.CStr();
	AddFuncInfo();
	TStrV args, argTypes;
	if (!ParseArgs(funcName, parameters, args, argTypes))
	{
		printf("Fail to parse arguments for NetworkX generation...\n");
		return 0;
	};
	TExeTm execTime;
	if (!CallPyFunction(moduleName, funcName, args, argTypes, G))
	{
		cout << "CallPyFunction() raised error. Execution terminated.\n";
		system("pause");
		exit(1);
	};
	
	TFile << "Time of generation of graph by NetworkX: " << execTime.GetTmStr() << endl; 

	execTime.Tick();
	PyObject*** nodes = new PyObject**[1];
	GetNodes(G, nodes);
	int nodesCount = PyList_Size(*(nodes[0]));
	//printf("nodesCount = %d, ", nodesCount);
	res = PUNGraph::TObj::New();
    res->Reserve(nodesCount, nodesCount*nodesCount);
	for (size_t i = 0; i < nodesCount; i++)
		res->AddNode(i);
	Py_DECREF(nodes);

	PyObject*** edges = new PyObject**[1];
	GetEdges(G, edges);
	int edgesCount = PyList_Size(*(edges[0]));
	//printf("edgesCount = %d\n", edgesCount);
	for (size_t i = 0; i < edgesCount; i++)
	{
		PyObject* item = PySequence_Fast_GET_ITEM(*(edges[0]), i);
		int v1, v2;
		PyObject* node = PySequence_Fast_GET_ITEM(item,0);
		v1 = PyLong_AsLong(node);
		node = PySequence_Fast_GET_ITEM(item,1);
		v2 = PyLong_AsLong(node);
		res->AddEdge(v1,v2);
	}
	TFile << "Time of copying of graph from NetworkX representation: " << execTime.GetTmStr() << endl; 
	Py_DECREF(G);
	Py_DECREF(edges);
	//Py_Finalize(); // очищение памяти, отданной интерпретатору
	
	return 0;
}
Beispiel #5
0
void TNEANetMP::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
  fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
  for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
    fprintf(OutF, "  %*d]\n", NodePlaces, NodeI.GetId());
    // load node attributes
    TIntV IntAttrN;
    IntAttrValueNI(NodeI.GetId(), IntAttrN);
    fprintf(OutF, "    nai[%d]", IntAttrN.Len());
    for (int i = 0; i < IntAttrN.Len(); i++) {
      fprintf(OutF, " %*i", NodePlaces, IntAttrN[i]()); }
    TStrV StrAttrN;
    StrAttrValueNI(NodeI.GetId(), StrAttrN);
    fprintf(OutF, "    nas[%d]", StrAttrN.Len());
    for (int i = 0; i < StrAttrN.Len(); i++) {
      fprintf(OutF, " %*s", NodePlaces, StrAttrN[i]()); }
    TFltV FltAttrN;
    FltAttrValueNI(NodeI.GetId(), FltAttrN);
    fprintf(OutF, "    naf[%d]", FltAttrN.Len());
    for (int i = 0; i < FltAttrN.Len(); i++) {
      fprintf(OutF, " %*f", NodePlaces, FltAttrN[i]()); }

    fprintf(OutF, "    in[%d]", NodeI.GetInDeg());
    for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
    fprintf(OutF, "\n");
    fprintf(OutF, "    out[%d]", NodeI.GetOutDeg());
    for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
    fprintf(OutF, "\n");
  }
  for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
    fprintf(OutF, "  %*d]  %*d  ->  %*d", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());

    // load edge attributes
    TIntV IntAttrE;
    IntAttrValueEI(EdgeI.GetId(), IntAttrE);
    fprintf(OutF, "    eai[%d]", IntAttrE.Len());
    for (int i = 0; i < IntAttrE.Len(); i++) {
      fprintf(OutF, " %*i", EdgePlaces, IntAttrE[i]());
    }
    TStrV StrAttrE;
    StrAttrValueEI(EdgeI.GetId(), StrAttrE);
    fprintf(OutF, "    eas[%d]", StrAttrE.Len());
    for (int i = 0; i < StrAttrE.Len(); i++) {
      fprintf(OutF, " %*s", EdgePlaces, StrAttrE[i]());
    }
    TFltV FltAttrE;
    FltAttrValueEI(EdgeI.GetId(), FltAttrE);
    fprintf(OutF, "    eaf[%d]", FltAttrE.Len());
    for (int i = 0; i < FltAttrE.Len(); i++) {
      fprintf(OutF, " %*f", EdgePlaces, FltAttrE[i]());
    }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n");
}
Beispiel #6
0
PNGraph TGraphKey::GetNGraph() const {
  PNGraph G = TNGraph::New();
  for (int i = 0; i < GetNodes(); i++) G->AddNode(i);
  for (int e = 0; e < GetEdges(); e++) {
    G->AddEdge(EdgeV[e].Val1, EdgeV[e].Val2);
  }
  G->Defrag();
  return G;
}
Beispiel #7
0
void GetPairedEdges(const TriMeshWithTopology& in,vector<TriMeshEdge>& edges)
{
  GetEdges(in,edges);
  for(size_t i=0;i<edges.size();i++) {
    if(edges[i].t1 < 0 || edges[i].t2 < 0) {
      edges[i] = edges.back();
      i--;
      edges.resize(edges.size()-1);
    }
  } 
}
Beispiel #8
0
void TNEGraph::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
  fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Graph: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
  for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
    fprintf(OutF, "  %*d]\n", NodePlaces, NodeI.GetId());
    fprintf(OutF, "    in[%d]", NodeI.GetInDeg());
    for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
    fprintf(OutF, "\n    out[%d]", NodeI.GetOutDeg());
    for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
    fprintf(OutF, "\n");
  }
  for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
    fprintf(OutF, "  %*d]  %*d  ->  %*d\n", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
  }
  fprintf(OutF, "\n");
}
Beispiel #9
0
int main()
{
	int gd=DETECT,gm;
	initgraph(&gd,&gm,"c://TC/bgi");
	setlinestyle(SOLID_LINE,1,3);
	GetVertices();
	GetEdges();
	Redraw(adj,0);
	AllPath();
       //	Redraw(A,0);
     //	Redraw(A);
	//gotoxy(2,4);

	//printf("Minimum Cost of this spaning tree is : %d",mstcost);

	getch();

	closegraph();
	return 0;
}
Beispiel #10
0
/////////////////////////////////////////////////
// Simple Edge Graph
bool TSimpleGraph::Join(const TSimpleGraph& G1, const TSimpleGraph& G2) {
  const int Edges1 = G1.GetEdges();
  const int Edges2 = G2.GetEdges();
  const TIntPrV& EdgeV1 = G1.EdgeV;
  const TIntPrV& EdgeV2 = G2.EdgeV;
  const int MxEdges = Edges1+1;
  if (GetEdges() != MxEdges) EdgeV.Gen(MxEdges);
  IAssert(Edges1 == Edges2);

  int e=0, g1=0, g2=0;
  while (g1 < Edges1 && g2 < Edges2) {
    if (e == MxEdges) return false;
    if (abs(g1 - g2) > 1) return false;
    if (EdgeV1[g1] == EdgeV2[g2]) { e++;  g1++;  g2++; }
    else if (EdgeV1[g1] < EdgeV2[g2]) { e++;  g1++; }
    else { e++;  g2++; }
  }

  e=0; g1=0; g2=0;
  while (g1 < Edges1 && g2 < Edges2) {
    if (EdgeV1[g1] == EdgeV2[g2]) {
      EdgeV[e] = EdgeV1[g1];  e++;  g1++;  g2++; }
    else if (EdgeV1[g1] < EdgeV2[g2]) {
      EdgeV[e] = EdgeV1[g1];  e++;  g1++; }
    else {
      EdgeV[e] = EdgeV2[g2];  e++;  g2++; }
  }
  if (g1 == Edges1 && g2 == Edges2 && e == MxEdges) return true;
  if (e+1 == MxEdges) {
    if (g1+1 == Edges1 && g2 == Edges2) {
      EdgeV[e] = EdgeV1.Last();
      return true;
    }
    if (g1 == Edges1 && g2+1 == Edges2) {
      EdgeV[e] = EdgeV2.Last();
      return true;
    }
  }
  return false;
}
Beispiel #11
0
void TGraphKey::SaveGViz(const TStr& OutFNm, const TStr& Desc, const TStr& NodeAttrs, const int& Size) const {
  FILE *F = fopen(OutFNm.CStr(), "wt");
  fprintf(F, "/*****\n");
  fprintf(F, "  Graph (%d, %d)\n", GetNodes(), GetEdges());
  //if (! Desc.Empty()) fprintf(F, "  %s\n", Desc.CStr());
  fprintf(F, "*****/\n\n");
  fprintf(F, "digraph G {\n");
  if (Size != -1) fprintf(F, "  size=\"%d,%d\";\n", Size, Size);
  fprintf(F, "  graph [splines=true overlap=false]\n"); //size=\"12,10\" ratio=fill
  if (NodeAttrs.Empty()) fprintf(F, "  node  [shape=ellipse, width=0.3, height=0.3]\n");
  else fprintf(F, "  node  [shape=ellipse, %s]\n", NodeAttrs.CStr());
  if (! EdgeV.Empty()) {
    for (int e = 0; e < EdgeV.Len(); e++) {
      fprintf(F, "  %d -> %d;\n", EdgeV[e].Val1(), EdgeV[e].Val2()); }
  } else {
    for (int n = 0; n < Nodes; n++) { fprintf(F, "  %d;\n", n); }
  }
  if (! Desc.Empty()) {
    fprintf(F, "  label = \"\\n%s\\n\";", Desc.CStr());
    fprintf(F, "  fontsize=24;\n");
  }
  fprintf(F, "}\n");
  fclose(F);
}
Beispiel #12
0
void TGraphEnumUtils::GetIsoGraphs(uint64 graphId, int nodes, TVec<PNGraph> &isoG) {
	TIntV v(nodes); for(int i=0; i<nodes; i++) v[i]=i;
	TVec<TIntV> perms; GetPermutations(v, 0, perms);
	isoG.Gen(perms.Len());
	//
	TVec<TPair<int,int> > edges;
	GetEdges(graphId, nodes, edges);
	//
	for(int i=0; i<perms.Len(); i++) {
		isoG[i] = TNGraph::New();
		//Add nodes
		for(int j=0; j<nodes; j++) isoG[i]->AddNode(j);
		//Add edges
		for(int j=0; j<edges.Len(); j++) {
			int srcId = edges[j].Val1;
			int dstId = edges[j].Val2;
			//
			int pSrcId = perms[i][srcId];
			int pDstId = perms[i][dstId];
			//
			isoG[i]->AddEdge(pSrcId, pDstId);
		}
	}
}
Beispiel #13
0
bool
AreaSurfaceMesh::GetLineSegmentFacesAndMesh(
	__in const NWN::Vector2 & Start,
	__in const NWN::Vector2 & End,
	__in_opt const TileSurfaceMesh * ExcludeSurfaceMesh,
	__in bool Walkable,
	__out const SurfaceMeshFace * * Face1,
	__out const SurfaceMeshFace * * Face2,
	__out const TileSurfaceMesh * * SurfaceMesh
	) const
/*++

Routine Description:

	Given the start and end bounding points of a line segment, which must
	reside entirely within the same tile surface mesh (although it may reside
	upon a seam), this routine returns the walk mesh faces that contain the
	start and end points, respectively.  Both faces are guaranteed to be joined
	to the same tile surface mesh, which is also returned.

	Only walkable faces are returned.

Arguments:

	Start - Supplies the first point of the line segment.  The line segment
	        must reside entirely within one tile surface mesh.

	End - Supplies the second point of the line segment.  The line segment must
	      reside entirely within one tile surface mesh.

	ExcludeSurfaceMesh - Optionally supplies a surface mesh to exclude if there
	                     should be be a tie between which surface mesh to pick
	                     for a particular triangle.  If the caller is following
	                     a line through several intersecting segments, then
	                     subsequent calls must specify the previous surface
	                     mesh in order to ensure forward progress.

	Walkable - Supplies a Boolean value indicating whether only walkable faces
	           are to be considered.

	Face1 - Receives the face containing the Start point.

	Face2 - Receives the face containing the End point.

	SurfaceMesh - Receives the tile surface mesh that both faces are joined to.

Return Value:

	Returns true two faces joined to the same tile surface mesh and containing
	the Start and End points could be located.  Otherwise, the routine returns
	false.

Environment:

	User mode.

--*/
{
	const SurfaceMeshFace * f1;
	const TileSurfaceMesh * t1;
	const SurfaceMeshFace * f2;
	const TileSurfaceMesh * t2;

	f1 = FindFace( Start, &t1 );

	if (f1 == NULL)
		return false;

	if ((Walkable) && (!(f1->Flags & SurfaceMeshFace::WALKABLE)))
		return false;

	f2 = FindFace( End, &t2 );

	if (f2 == NULL)
		return false;

	if ((Walkable) && (!(f2->Flags & SurfaceMeshFace::WALKABLE)))
		return false;

//	WriteText( "Try (%f, %f) and (%f, %f)\n", f1->Centroid2.x, f1->Centroid2.y, f2->Centroid2.x, f2->Centroid2.y );

	//
	// If the points were not in the same surface mesh then it's possible
	// that we picked the wrong one.  This may happen as it is not very
	// well defined what the behavior should be should we be right on a
	// seam between tile surface walkmesh objects.
	//
	// In the seam case, we iterate through all neighbor edges, looking for
	// the edge that matches the line.  Once we've got the edge, we'll pick
	// the two triangles that are in the same tiele surface walkmesh.
	//

	if ((t1 != t2) || (t1 == ExcludeSurfaceMesh))
	{
		const SurfaceMeshFace * faces[ 4 ];
		const SurfaceMeshEdge * e1;
		const SurfaceMeshEdge * e2;
		NWN::Vector2            v1;
		NWN::Vector2            v2;
		NWN::Vector2            I0;
		unsigned long           TestFaceId;
		bool                    Parallel;

//		WriteText( "We weren't in the same walkmesh!\n" );

		//
		// Build a list of candidate faces.  We start with the two that we've
		// originally found, but these may be on the wrong sides -- that is,
		// they might not be on the correct tile surface walkmesh.  Check the
		// other sides (if applicable); two of the faces will be on opposite
		// walkmesh tiles (i.e. the triangle we just walked through, and the
		// triangle that we'll walk through after we pass through this next
		// walkmesh.  Conversely, two of the faces will be on the correct
		// walkmesh tile -- the next walkmesh tile up.
		//

		faces[ 0 ] = f1;
		faces[ 1 ] = NULL;
		faces[ 2 ] = f2;
		faces[ 3 ] = NULL;

		for (unsigned long i = 0; i < 3; i += 1)
		{
			e1 = &GetEdges( )[ f1->Edges[ i ] ];

			//
			// Check that the edge intersects with our line segment's overlap
			// coordinate set.
			//

			v1.x = GetPoints( )[ e1->Points1 ].x;
			v1.y = GetPoints( )[ e1->Points1 ].y;
			v2.x = GetPoints( )[ e1->Points2 ].x;
			v2.y = GetPoints( )[ e1->Points2 ].y;

			if (!Math::IntersectSegments2( Start, End, v1, v2, I0, Parallel ))
			{
				e1 = NULL;
				continue;
			}

			//
			// We want the triangle on the other edge of this face.  Try it
			// too.
			//

			if (GetFaceId( f1 ) != e1->Triangles1)
				TestFaceId = e1->Triangles1;
			else
				TestFaceId = e1->Triangles2;

			if (TestFaceId == (unsigned long) -1)
				continue;

			faces[ 1 ] = &GetTriangles( )[ TestFaceId ];

			if (!IsPointInTriangle( faces[ 1 ], Start, GetPoints( ) ))
			{
				faces[ 1 ] = NULL;
				continue;
			}

			break;
		}

		for (unsigned long i = 0; i < 3; i += 1)
		{
			e2 = &GetEdges( )[ f2->Edges[ i ] ];

			//
			// Check that the edge intersects with our line segment's overlap
			// coordinate set.
			//

			v1.x = GetPoints( )[ e2->Points1 ].x;
			v1.y = GetPoints( )[ e2->Points1 ].y;
			v2.x = GetPoints( )[ e2->Points2 ].x;
			v2.y = GetPoints( )[ e2->Points2 ].y;

			if (!Math::IntersectSegments2( Start, End, v1, v2, I0, Parallel ))
			{
				e2 = NULL;
				continue;
			}

			//
			// We want the triangle on the other edge of this face.  Try it
			// too.
			//

			if (GetFaceId( f2 ) != e2->Triangles1)
				TestFaceId = e2->Triangles1;
			else
				TestFaceId = e2->Triangles2;

			if (TestFaceId == (unsigned long) -1)
				continue;

			faces[ 3 ] = &GetTriangles( )[ TestFaceId ];

			if (!IsPointInTriangle( faces[ 3 ], End, GetPoints( )))
			{
				faces[ 3 ] = NULL;
				continue;
			}

			break;
		}

//		faces[ 0 ] = e1->Triangles1 == (unsigned long) -1 ? NULL : &GetTriangles( )[ e1->Triangles1 ];
//		faces[ 1 ] = e1->Triangles2 == (unsigned long) -1 ? NULL : &GetTriangles( )[ e1->Triangles2 ];
//		faces[ 2 ] = e2->Triangles1 == (unsigned long) -1 ? NULL : &GetTriangles( )[ e2->Triangles1 ];
//		faces[ 3 ] = e2->Triangles1 == (unsigned long) -1 ? NULL : &GetTriangles( )[ e2->Triangles2 ];

		f1 = NULL;
		f2 = NULL;

		//
		// Check each triangle/edge permutation for the two that have the
		// same tile surface mesh.  These two triangles will be the ones
		// that we're looking for.
		//

		for (unsigned long i = 0; i < 2 && f1 == NULL; i += 1)
		{
			if (faces[ i + 0 ] == NULL)
				continue;

			for (unsigned long j = 0; j < 2; j += 1)
			{
				if (faces[ j + 2 ] == NULL)
					continue;

//				if ((!IsPointInTriangle( faces[ i + 0 ], Start, GetPoints( ) )) ||
//				    (!IsPointInTriangle( faces[ j + 2 ], End, GetPoints( ) )))
//					continue;

				f1 = faces[ i + 0 ];
				f2 = faces[ j + 2 ];
				t1 = &GetTileSurfaceMesh( f1 );
				t2 = &GetTileSurfaceMesh( f2 );

//				WriteText( "Try again: (%f, %f) and (%f, %f)\n", f1->Centroid2.x, f1->Centroid2.y, f2->Centroid2.x, f2->Centroid2.y );

				if ((t1 == t2) &&
				    (t1 != ExcludeSurfaceMesh))
					break;

				f1 = NULL;
				f2 = NULL;
			}
		}

		if (f1 == NULL)
		{
//			WriteText( "No triangles sharing our edge have the same TSM???\n" );
			return false;
		}
	}

//	WriteText( "%f %f %f %f\n", f1->Centroid2.x, f1->Centroid2.y, f2->Centroid2.x, f2->Centroid2.y );

	*Face1 = f1;
	*Face2 = f2;
	*SurfaceMesh = t1;

	return true;
}
Beispiel #14
0
int main()
{
	int gd=DETECT,gm;
	initgraph(&gd,&gm,"c://TC/bgi");
	setbkcolor(BROWN);
	setlinestyle(SOLID_LINE,1,3);
	GetVertices();
	GetEdges();
      //	getch();
	edgecost();
       getch();
	Redraw(adj);
   //PRIMS ALGO
    Vertex *v;
	int min_edge=MAX_NUM;
   int min_x, min_y,k,l,z;

   for(z=0;z<vcount;z++) //create near
	 near1[z]=-1;

   for(k=0;k<vcount;k++) //near array fill
     {
	for(l=0;l<vcount;l++)
	  {
		if(adj[k][l]<min_edge)
		    {min_edge=adj[k][l];
		      min_x=k;
		      min_y=l;
		     }
	    }
	}

    mincost=0;
   mincost+=min_edge;
  // int m=MAX_VERT;
   //int t[m][2];
   t[0][0]=min_x;
   t[0][1]=min_y;

   Edge_fill(&v[min_x],&v[min_y],RED,TRUE);
   getch();
    extra[min_x][min_y]=1;
    extra[min_y][min_x]=1;

   for(z=0;z<vcount;z++)   //near array update
   {
	if(adj[z][min_x]<adj[z][min_y])
	       near1[z]=min_x;
	else
		 near1[z]=min_y;
   }

   near1[min_x]=near1[min_y]=-1;
  // int k;
   int min_j;
   //prims algorithm
   for( z =1;z<vcount-1;z++)
   {  min_j=MAX_NUM;

	     for(int j=0;j<vcount;j++) //choose nearest vertex
	      {
		if(adj[j][near1[j]]<min_j && near1[j]!=-1)
		    min_j=j;
		    }

	t[z][0]=min_j;
	   t[z][1]=near1[min_j];

	 mincost+=adj[min_j][near1[min_j]];

	 extra[min_j][near1[min_j]]=1;
	  extra[near1[min_j]][min_j]=1;

	 near1[min_j]=-1;

	 for(k=0;k<vcount;k++)
	 {
		if(near1[k]!=-1 && adj[k][near1[k]]>adj[k][min_j])
		    near1[k]=min_j;

	}
}
      getch();
	Redraw(extra);
	gotoxy(2,4);

	printf("Minimum Cost of this spaning tree is : %d",mincost);

	getch();

	closegraph();
	return 0;
}
std::vector<ribi::cmap::Edge> ribi::cmap::GetSortedEdges(const ConceptMap& c) noexcept
{
  auto v = GetEdges(c);
  std::sort(std::begin(v),std::end(v));
  return v;
}
Beispiel #16
0
void TNEGraph::GetEIdV(TIntV& EIdV) const {
  EIdV.Gen(GetEdges(), 0);
  for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
    EIdV.Add(EdgeH.GetKey(E));
  }
}
Beispiel #17
0
void TNGraph::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  fprintf(OutF, "-------------------------------------------------\nDirected Node Graph: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
    const TNode& Node = NodeH[N];
    fprintf(OutF, "  %*d]\n", NodePlaces, Node.GetId());
    fprintf(OutF, "    in [%d]", Node.GetInDeg());
    for (int edge = 0; edge < Node.GetInDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetInNId(edge)); }
    fprintf(OutF, "\n    out[%d]", Node.GetOutDeg());
    for (int edge = 0; edge < Node.GetOutDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetOutNId(edge)); }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n");
}
Beispiel #18
0
void TGStat::Plot(const TGStatDistr& Distr, const TStr& FNmPref, TStr Desc, bool PowerFit) const {
  if (Desc.Empty()) Desc = FNmPref.GetUc();
  if (! HasDistr(Distr) || Distr==gsdUndef || Distr==gsdMx) { return; }
  TPlotInfo Info = GetPlotInfo(Distr);
  TGnuPlot GnuPlot(Info.Val1+TStr(".")+FNmPref, TStr::Fmt("%s. G(%d, %d)", Desc.CStr(), GetNodes(),GetEdges()));
  GnuPlot.SetXYLabel(Info.Val2, Info.Val3);
  GnuPlot.SetScale(Info.Val4);
  const int plotId = GnuPlot.AddPlot(GetDistr(Distr), gpwLinesPoints, "");
  if (PowerFit) { GnuPlot.AddPwrFit(plotId, gpwLines); }
  #ifdef GLib_MACOSX
  GnuPlot.SaveEps();
  #else
  GnuPlot.SavePng();
  #endif
}
Beispiel #19
0
void TBPGraph::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  fprintf(OutF, "-------------------------------------------------\nBipartite Graph: nodes: %d+%d=%d, edges: %d\n", GetLNodes(), GetRNodes(), GetNodes(), GetEdges());
  for (int N = LeftH.FFirstKeyId(); LeftH.FNextKeyId(N); ) {
    const TNode& Node = LeftH[N];
    fprintf(OutF, "  %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
    for (int edge = 0; edge < Node.GetDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n");
  /*// Also dump the 'right' side
  fprintf(OutF, "\n");
  for (int N = RightH.FFirstKeyId(); RightH.FNextKeyId(N); ) {
    const TNode& Node = RightH[N];
    fprintf(OutF, "  %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
    for (int edge = 0; edge < Node.GetDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n"); //*/
}
Beispiel #20
0
void TGraphKey::SaveTxt(FILE *F) const {
  fprintf(F, "nodes: %d.  edges: %d\n", GetNodes(), GetEdges());
  for (int i = 0; i < EdgeV.Len(); i++) {
    fprintf(F,"  %d\t%d\n", EdgeV[i].Val1(), EdgeV[i].Val2());
  }
}