static ACTC_var unmapVertexEdge(ref ACTCData tc, ref ACTCVertex v1, ACTCVertex v2) { int i; for (i = 0; i < v1.Edges.Length; i++) { if (v1.Edges[i].V2 == v2) { break; } } if (i == v1.Edges.Length) { //(int)ACTC_.DEBUG( // fprintf(stderr, "ACTC::unmapVertexEdge : Couldn't find edge %d,%d" // " from vertex in order to unmap it?!?\n", v1.V, v2.V); // abortWithOptionalDump(tc); //) return(tc.Error = ACTC_var.DATABASE_CORRUPT); } v1.Edges[i].Count--; if (v1.Edges[i].Count == 0) { //if (v1.Edges[i].Triangles != null) //v1.Edges[i].Triangles = new ACTCTriangle[0]; //free(v1.Edges[i].Triangles); v1.Edges[i] = v1.Edges[v1.Edges.Length - 1]; //v1.Edges.Length--; } return(ACTC_var.NO_ERROR); }
public static int tableRetrieve(uint a, TableRoot table, out ACTCVertex refe) { int i1 = (int)a / (LEVEL2COUNT * LEVEL3COUNT); int i2 = ((int)a / LEVEL3COUNT) % LEVEL2COUNT; int i3 = (int)a % LEVEL3COUNT; refe = null; if (table.Table[i1] == null) { return(0); } if (table.Table[i1].Table[i2] == null) { return(0); } if (table.Table[i1].Table[i2].IsSet[i3] == false) { return(0); } refe = table.Table[i1].Table[i2].Table[i3]; return(1); }
static ACTC_var mapVertexEdge(ACTCVertex v1, ACTCVertex v2, out ACTCEdge edge) { uint i; ACTCEdge tmp = new ACTCEdge(); for (i = 0; i < v1.Edges.Length; i++) { if (v1.Edges[i].V2 == v2) { v1.Edges[i].Count++; break; } } if (i == v1.Edges.Length) { tmp.V2 = v2; tmp.Count = 1; tmp.Triangles = new ACTCTriangle[0]; //Add the edge to the end of the first vertex edge array. if (v1.Edges == null) { v1.Edges = new ACTCEdge[0]; } Array.Resize <ACTCEdge>(ref v1.Edges, v1.Edges.Length + 1); v1.Edges[v1.Edges.Length - 1] = tmp; } edge = v1.Edges[i]; return(ACTC_var.NO_ERROR); }
static ACTC_var unmapEdgeTriangle(ref ACTCData tc, ref ACTCEdge edge, ACTCVertex v3) { int i; for (i = 0; i < edge.Triangles.Length; i++) { if (edge.Triangles[i].FinalVert == v3) { break; } } if (i == edge.Triangles.Length) { //(int)ACTC_.DEBUG( // fprintf(stderr, "ACTC::unmapEdgeTriangle : Couldn't find third vertex" // " from edge in order to delete it?!?\n"); // abortWithOptionalDump(tc); //) return(tc.Error = ACTC_var.DATABASE_CORRUPT); } edge.Triangles[i] = edge.Triangles[edge.Triangles.Length - 1]; //Array.Resize<ACTCTriangle>(ref edge.Triangles, edge.Triangles.Length - 1); //edge.TriangleCount--; return(ACTC_var.NO_ERROR); }
static ACTC_var decVertexValence(ref ACTCData tc, ref ACTCVertex v) { v.Count--; if (v.Count < 0) { //(int)ACTC_.DEBUG( // fprintf(stderr, "ACTC::decVertexValence : Valence went " // "negative?!?\n"); // abortWithOptionalDump(tc); //) return(tc.Error = ACTC_var.DATABASE_CORRUPT); } if (v.PointsToMe != null) { v.PointsToMe[0] = v.Next; if (v.Next != null) { v.Next.PointsToMe = v.PointsToMe; } v.Next = null; } if (v.Count == 0) { tc.VertexCount--; if (v.Edges != null) { //free(v.Edges); //v.Edges = null; } if (tc.UsingStaticVerts == 0) { ACTCVertex g = null; tableRemove(v.V, ref tc.Vertices, ref g); //free(v); } //v = null; } else { if (tc.VertexBins != null) { v.Next = tc.VertexBins[v.Count]; v.PointsToMe[0] = tc.VertexBins[v.Count]; if (v.Next != null) { v.Next.PointsToMe[0] = v.Next; } tc.VertexBins[v.Count] = v; if (v.Count < tc.CurMinVertValence) { tc.CurMinVertValence = v.Count; } } } return(ACTC_var.NO_ERROR); }
//No need to use pointers. //static void *reallocAndAppend(void **ptr, uint *itemCount, uint itemBytes, void *append) //{ // void *t; // t = (void*)Marshal.ReAllocCoTaskMem(new IntPtr(*ptr), (int)itemBytes * (int)(*itemCount + 1)); // if (t == null) // return null; // *ptr = t; // //memcpy((unsigned char *)*ptr + *itemCount * itemBytes, append, itemBytes); // (*itemCount) += 1; // return *ptr; //} /* * Call only during input; changes vertices' valences and does not * fix the bins that are ordered by vertex valence. (It's usually cheaper * to traverse the vertex list once after all are added, since that's * linear in the NUMBER OF UNIQUE VERTEX INDICES, which is almost always * going to be less than the number of vertices.) */ static ACTC_var incVertexValence(ref ACTCData tc, uint v, out ACTCVertex found) { ACTCVertex vertex; found = null; if (tc.UsingStaticVerts == 1) { vertex = tc.StaticVerts[v]; vertex.Count++; if (vertex.Count == 1) { vertex.V = v; tc.VertexCount++; } } else { if (tableRetrieve(v, tc.Vertices, out vertex) == 1) { if (vertex.V != v) { //(int)ACTC_.DEBUG( // fprintf(stderr, "ACTC::incVertexValence : Got vertex %d when " // "looking for vertex %d?!?\n", vertex.V, v); // abortWithOptionalDump(tc); //) return(tc.Error = ACTC_var.DATABASE_CORRUPT); } vertex.Count++; } else { ////chartedSetLabel("new Vertex"); vertex = new ACTCVertex(); vertex.V = v; vertex.Count = 1; vertex.Edges = new ACTCEdge[0]; //vertex.Edges.Length = 0; if (tableInsert(v, ref tc.Vertices, vertex) == 0) { //(int)ACTC_.DEBUG(fprintf(stderr, "ACTC::incVertexValence : Failed " // "to insert vertex into table\n");) return(tc.Error = ACTC_var.ALLOC_FAILED); } tc.VertexCount++; } } if (vertex.Count > tc.CurMaxVertValence) { tc.CurMaxVertValence = vertex.Count; } found = vertex; return(ACTC_var.NO_ERROR); }
static ACTC_var unmapEdgeTriangleByVerts(ref ACTCData tc, ACTCVertex v1, ACTCVertex v2, ACTCVertex v3) { ACTCEdge e; ACTC_CHECK(findEdge(v1, v2, out e)); if (e != null) { unmapEdgeTriangle(ref tc, ref e, v3); } return(ACTC_var.NO_ERROR); }
static ACTC_var findEdge(ACTCVertex v1, ACTCVertex v2, out ACTCEdge edge) { int i; for (i = 0; i < v1.Edges.Length; i++) { if (v1.Edges[i].V2 == v2) { edge = v1.Edges[i]; return(ACTC_var.TRUE); } } edge = null; return(ACTC_var.FALSE); }
public static int tableRemove(uint a, ref TableRoot table, ref ACTCVertex wasref) { int i1 = (int)a / (LEVEL2COUNT * LEVEL3COUNT); int i2 = ((int)a / LEVEL3COUNT) % LEVEL2COUNT; int i3 = (int)a % LEVEL3COUNT; if (table.Table[i1] == null) { return(0); } if (table.Table[i1].Table[i2] == null) { return(0); } if (table.Table[i1].Table[i2].IsSet[i3] == false) { return(0); } if (wasref != null) { wasref = table.Table[i1].Table[i2].Table[i3]; } table.Table[i1].Table[i2].IsSet[i3] = false; table.EmptyEntryCount++; if (--table.Table[i1].Table[i2].EntryCount == 0) { table.EmptyEntryCount -= LEVEL3COUNT; table.TotalEntryCount -= LEVEL3COUNT; //free(table.Table[i1].Table[i2]); //table.TotalAllocatedBytes -= (uint)sizeof(TableLevel3); table.Table[i1].Table[i2] = null; if (--table.Table[i1].EntryCount == 0) { //table.TotalAllocatedBytes -= (uint)sizeof(TableLevel2); //free(table.Table[i1]); table.Table[i1] = null; } } return(1); }
static ACTC_var mapEdgeTriangle(ref ACTCEdge edge, ACTCVertex v3) { ACTCTriangle tmp = new ACTCTriangle(); tmp.FinalVert = v3; if (edge.Triangles == null) { edge.Triangles = new ACTCTriangle[0]; } Array.Resize <ACTCTriangle>(ref edge.Triangles, edge.Triangles.Length + 1); edge.Triangles[edge.Triangles.Length - 1] = tmp; return(ACTC_var.NO_ERROR); }
static ACTC_var findNextStripVertex(ref ACTCData tc, ref ACTCVertex vert) { while (tc.VertexBins[tc.CurMinVertValence] == null) { tc.CurMinVertValence++; if (tc.CurMinVertValence > tc.CurMaxVertValence) { if (tc.VertexCount > 0) { //(int)ACTC_.DEBUG(fprintf(stderr, "tc::findNextStripVertex : no more " // "vertices in bins but VertexCount > 0\n");) return(tc.Error = ACTC_var.DATABASE_CORRUPT); } return(ACTC_var.NO_MATCHING_VERT); } } vert = tc.VertexBins[tc.CurMinVertValence]; return(ACTC_var.NO_ERROR); }
public static int tableInsert(uint a, ref TableRoot table, ACTCVertex refe) { int i1 = (int)a / (LEVEL2COUNT * LEVEL3COUNT); int i2 = ((int)a / LEVEL3COUNT) % LEVEL2COUNT; int i3 = (int)a % LEVEL3COUNT; if (table.Table[i1] == null) { ////chartedSetLabel("table level 2"); table.Table[i1] = new TableLevel2(); //table.TotalAllocatedBytes += (uint)sizeof(TableLevel2); if (table.Table[i1] == null) { return(0); } } if (table.Table[i1].Table[i2] == null) { ////chartedSetLabel("table level 3"); table.Table[i1].Table[i2] = new TableLevel3(); //table.TotalAllocatedBytes += (uint)sizeof(TableLevel3); if (table.Table[i1].Table[i2] == null) { return(0); } table.Table[i1].EntryCount++; table.TotalEntryCount += LEVEL3COUNT; table.EmptyEntryCount += LEVEL3COUNT; } if (table.Table[i1].Table[i2].IsSet[i3] == false) { table.Table[i1].Table[i2].EntryCount++; table.EmptyEntryCount--; table.Table[i1].Table[i2].IsSet[i3] = true; } table.Table[i1].Table[i2].Table[i3] = refe; return(1); }
//static uint allocatedForTriangles(ACTCEdge e) //{ // return (uint)sizeof(ACTCTriangle) * (uint)e.Triangles.Length; //} //static uint allocatedForEdges(ACTCVertex *vert) //{ // int i; // uint size; // size = (uint)sizeof(ACTCEdge) * (uint)vert.Edges.Length; // for(i = 0; i < vert.Edges.Length; i++) { // size += allocatedForTriangles(&vert.Edges[i]); // } // return size; //} //static uint allocatedForVertices(ACTCData *tc) //{ // int i; // int size = 0; // ACTCVertex *v; // if (tc.UsingStaticVerts == 0) // tableResetIterator(tc.VertexIterator); // if (tc.UsingStaticVerts != 0) { // size = (int)tc.VertRange * sizeof(ACTCVertex); // for(i = 0; i < tc.VertRange; i++) { // v = &tc.StaticVerts[i]; // if (v.Count > 0) // size += (int)allocatedForEdges(v); // } // } else { // for(i = 0; i < tc.VertexCount; i++) { // tableIterate(tc.Vertices, tc.VertexIterator, null, (void **)&v); // size += (int)allocatedForEdges(v); // } // } // return (uint)size; //} //int actcGetMemoryAllocation(ACTCData *tc, uint *bytesAllocated) //{ // int tableBytes = 0; // tableGetStats(*tc.Vertices, -1, -1, tableBytes); // *bytesAllocated = (uint)sizeof(ACTCData); // *bytesAllocated += (uint)tableBytes; // *bytesAllocated += allocatedForVertices(tc); /* recurses */ // return (int)ACTC_.NO_ERROR; //} static void freeVertex(ACTCVertex v) { v = new ACTCVertex(); }
static ACTC_var actcBeginOutput(ref ACTCData tc) { ACTCVertex v = new ACTCVertex(); int i; if (tc.IsInputting != 0) { //(int)ACTC_.DEBUG(fprintf(stderr, "actcBeginOutput : called within " // "BeginInput/EndInput\n");) return(tc.Error = ACTC_var.DURING_INPUT); } if (tc.IsOutputting != 0) { //(int)ACTC_.DEBUG(fprintf(stderr, "actcBeginOutput : called within " // "BeginOutput/EndOutput\n");) return(tc.Error = ACTC_var.DURING_OUTPUT); } tc.IsOutputting = 1; tc.CurMinVertValence = int.MaxValue; //chartedSetLabel("vertex bins"); tc.VertexBins = new ACTCVertex[tc.CurMaxVertValence + 1]; //if (tc.VertexBins == null) //{ // //(int)ACTC_.DEBUG(fprintf(stderr, "actcBeginOutput : couldn't allocate %d bytes " // // "for Vertex Bins\n", // // sizeof(ACTCVertex *) * tc.CurMaxVertValence);) // return tc.Error = (int)ACTC_.ALLOC_FAILED; //} if (tc.UsingStaticVerts != 0) { double edgeTotal = 0; for (i = 0; i < tc.VertRange; i++) { v = tc.StaticVerts[i]; if (v.Count > 0) { v.Next = tc.VertexBins[v.Count]; v.PointsToMe[0] = tc.VertexBins[v.Count]; tc.VertexBins[v.Count] = v; if (v.Next != null) { v.Next.PointsToMe[0] = v.Next; } if (v.Count < tc.CurMinVertValence) { tc.CurMinVertValence = v.Count; } edgeTotal += v.Edges.Length; } } } else { tableResetIterator(ref tc.VertexIterator); for (i = 0; i < tc.VertexCount; i++) { uint *g = null; if (tableIterate(tc.Vertices, ref tc.VertexIterator, ref g, ref v) == 0) { //(int)ACTC_.DEBUG(fprintf(stderr, "actcBeginOutput : fewer vertices in " // "the table than we expected!\n");) return(tc.Error = ACTC_var.DATABASE_CORRUPT); } v.Next = tc.VertexBins[v.Count]; ACTCVertex[] PointsToMe = new ACTCVertex[tc.VertexBins.Length - v.Count]; for (int x = v.Count; x < tc.VertexBins.Length; x++) { PointsToMe[x - v.Count] = tc.VertexBins[x]; } v.PointsToMe = PointsToMe; tc.VertexBins[v.Count] = v; if (v.Next != null) { if (v.Next.PointsToMe == null) { v.Next.PointsToMe = new ACTCVertex[1]; } v.Next.PointsToMe[0] = v.Next; } if (v.Count < tc.CurMinVertValence) { tc.CurMinVertValence = v.Count; } } } return(ACTC_var.NO_ERROR); }
public static int tableIterate(TableRoot table, ref TableIterator ti, ref uint *i, ref ACTCVertex refe) { int done; done = 0; while (ti.i1 < LEVEL1COUNT) { if (ti.CheckLevel1 == 1 && table.Table[ti.i1] == null) { ti.i += LEVEL2COUNT * LEVEL3COUNT; ti.i1++; continue; } else { ti.CheckLevel1 = 0; } if (ti.CheckLevel2 == 1 && table.Table[ti.i1].Table[ti.i2] == null) { ti.i += LEVEL3COUNT; if (++ti.i2 >= LEVEL2COUNT) { ti.i2 = 0; ti.i1++; ti.CheckLevel1 = 1; } continue; } else { ti.CheckLevel2 = 0; } if (ti.i3 == 0) { ti.CurLevel3 = table.Table[ti.i1].Table[ti.i2]; } if (ti.CurLevel3.IsSet[ti.i3] != false) { if (refe != null) { refe = ti.CurLevel3.Table[ti.i3]; } if (i != null) { *i = ti.i; } done = 1; } ti.i++; if (++ti.i3 >= LEVEL3COUNT) { ti.i3 = 0; ti.CheckLevel2 = 1; if (++ti.i2 >= LEVEL2COUNT) { ti.i2 = 0; ti.i1++; ti.CheckLevel1 = 1; } } if (done == 1) { return(1); } } return(0); }
static ACTC_var actcStartNextPrim(ref ACTCData tc, out int v1Return, out int v2Return) { ACTCVertex v1 = null; ACTCVertex v2 = null; ACTC_var findResult; v1Return = v2Return = -1; if (tc.IsInputting != 0) { //(int)ACTC_.DEBUG(fprintf(stderr, "actcStartNextPrim : within " // "BeginInput/EndInput\n");) return(tc.Error = ACTC_var.DURING_INPUT); } if (tc.IsOutputting == 0) { //(int)ACTC_.DEBUG(fprintf(stderr, "actcStartNextPrim : outside " // "BeginOutput/EndOutput\n");) return(tc.Error = ACTC_var.IDLE); } findResult = findNextFanVertex(ref tc, ref v1); if (findResult == ACTC_var.NO_ERROR) { tc.PrimType = ACTC_var.PRIM_FAN; } else if (findResult != ACTC_var.NO_MATCHING_VERT) { //(int)ACTC_.DEBUG(fprintf(stderr, "actcStartNextPrim : internal " // "error finding next appropriate vertex\n");) return(tc.Error = findResult); } else { findResult = findNextStripVertex(ref tc, ref v1); if (findResult != ACTC_var.NO_ERROR && findResult != ACTC_var.NO_MATCHING_VERT) { //(int)ACTC_.DEBUG(fprintf(stderr, "actcStartNextPrim : internal " //"error finding next appropriate vertex\n");) return(tc.Error = findResult); } tc.PrimType = ACTC_var.PRIM_STRIP; } if (findResult == ACTC_var.NO_MATCHING_VERT) { v1Return = -1; v2Return = -1; return(tc.Error = ACTC_var.DATABASE_EMPTY); } v2 = v1.Edges[0].V2; tc.CurWindOrder = ACTC_var.FWD_ORDER; tc.VerticesSoFar = 2; tc.V1 = v1; tc.V2 = v2; v1Return = (int)v1.V; v2Return = (int)v2.V; //(int)ACTC_.INFO(printf("starting with edge %u, %u\n", tc.V1.V, tc.V2.V);) return(tc.PrimType); }