void TriangleBvh::BuildBVH() { if (faces.size() == 0) return; vector<BVHItem> buildData; buildData.reserve(faces.size()); vector<uint32_t> prims(faces.size()); for (uint32_t i = 0; i < faces.size(); ++i) { Vec3f &v0 = positions[faces[i][0]]; Vec3f &v1 = positions[faces[i][1]]; Vec3f &v2 = positions[faces[i][2]]; Range3f bbox = ElementOperations::TriangleBoundingBox(v0, v1, v2); buildData.push_back(BVHItem(i, bbox)); prims[i] = i; } ordered.reserve(faces.size()); uint64_t totalNodes = 0; BVHBuildNode *root = RecursiveBuildBVH<uint32_t>(SPLIT_SAH, buildData.begin(), buildData.end(), &totalNodes, prims, ordered); bvhNodes.resize(totalNodes); uint32_t offset = 0; FlattenBVHTree(root, bvhNodes, &offset); }
int main() { Val ret; read(); prims(); ret = calc_result(); printf("MSP: %u\n", ret); return 0; }
int main() { int i,j,n,cost[10][10]; printf("enter n"); scanf("%d",&n); printf("enter the matrix\n"); for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%d",&cost[i][j]); prims(n,cost); return 0; }
int main() { int i,j; int wt_tree,count; struct edgeStruct tree[MAX]; //Calling Generate Graph Function to construct the adjancency matrix for the stated graph genGraph(); printf("\n *************Adjancency Matrix is *************** \n"); display(); prims(adj); }
int main(int argc, char** argv) { int i , j; scanf("%d",&numnodes); for(i=0;i<numnodes;i++) { for(j=0;j<numnodes;j++) { scanf("%d",&arcs[i][j]); } } prims(); // invokes the prims algorithm printf(" The minimum spanning tree edges \n"); for(i=0;i<tlen;i++) { printf(" %d --> %d ",T[i].node1,T[i].node2); } printf("\n"); return 0; }
int main() { int arr[SIZE][SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, INF, INF, 0, 1, 0, 3, 6, INF, 0, 3, 3, 0, 4, 2, 0, INF, 6, 4, 0, 5, 0, INF, INF, 2, 5, 0 }; Edge selectEdge[SIZE] = { 0, 0, 0 }; prims(arr, selectEdge); edgePrint(selectEdge); return 0; }
int main(int argc, char *argv[]) { int no, i, j; int a[10][10] = {0}; printf ("Enter the no of vertices\n"); scanf("%d", &no); printf("Enter the matrix\n"); for(i = 1; i <= no; i++) { for(j = 1; j <= no; j++) { scanf("%d",&a[i][j]); } } prims(a, no); return 0; }
int main() { printf("Here we go\n"); int numberOfNodes; int **adjMatrix=read(&numberOfNodes); int **returtree,i,j; returtree=prims(adjMatrix,numberOfNodes); for(i=0; i<numberOfNodes; i++) { for(j=0; j<numberOfNodes; j++) printf("%d ", returtree[i][j]); printf("\n"); } printf("\nCostul este: %d",cost(returtree,numberOfNodes)); //to do: FREE MEMORY!!! return 0; }
void main() { int i,j,total_cost; printf(“Enter no. of vertices:”); scanf(“%d”,&n); printf(“\nEnter the adjacency matrix:\n”); for(i=0; i<n; i++) for(j=0; j<n; j++) scanf(“%d”,&G[i][j]); total_cost=prims(); printf(“\nspanning tree matrix:\n”); for(i=0; i<n; i++) { printf(“\n”); for(j=0; j<n; j++) printf(“%d\t”,spanning[i][j]); } printf(“\n\nTotal cost of spanning tree=%d”,total_cost); }
void SphereBvh::BuildBVH() { if (centers.size() == 0) return; vector<BVHItem> buildData; buildData.reserve(centers.size()); vector<uint32_t> prims(centers.size()); for (uint32_t i = 0; i < centers.size(); ++i) { Range3f bbox = ElementOperations::SphereBoundingBox(centers[i], radius[i]); buildData.push_back(BVHItem(i, bbox)); prims[i] = i; } ordered.reserve(centers.size()); uint64_t totalNodes = 0; BVHBuildNode *root = RecursiveBuildBVH<uint32_t>(SPLIT_SAH, buildData.begin(), buildData.end(), &totalNodes, prims, ordered); bvhNodes.resize(totalNodes); uint32_t offset = 0; FlattenBVHTree(root, bvhNodes, &offset); }
// int totalDistance(RST* root); // Must check for errors in instance, if so output error to console. // If option output is given, output file to a text // If option output is not given output to screen int main(int argc, char** argv){ char* filename = NULL; char** lines; Plane plane; char* options = NULL; bool correctFile = true; int** MST = NULL; int* degrees; //initiallize rand() with current time srand(time(NULL)); // Cheching for arguments, if they are greater than or equal to two, assume // their are options and a filename being passed in trying to be passed in. if(argc >= 2){ filename = getFilename(argv, argc); options = getOption(argv, argc); } // Grab Data if (filename == NULL){ plane = getParameters(); plane.instance_size = plane.NUM_PT; } else { lines = readFile(filename); // Check to see if a file was succesffully parsed if(lines == NULL){ printf("File not found\n"); printf("Exiting...\n"); return -1; } plane.generation = getGeneration(filename); plane = getFileParameters(lines); correctFile = checkFile(plane); free(lines); } // Ensure instances is of the correct size; if(!correctFile){ printf("File is corrupt, the instance file does not match specification\n"); return -2; } if(filename != NULL){ // If we opened up a file, the Plane instance is all ready generated for us. printPlane(plane, filename, options); if(plane.instance_size > 1){ MST = prims(plane); printMST(MST,plane.instance_size, filename, options); degrees = nodeDegree(MST, plane.instance_size-1); } else { printf("Can not generate MST, insufficient nodes \n"); } } else { while(plane.generation < plane.total_gen){ // If not we need to generate instances for the number of planes required plane.instance = genInstance(plane.NUM_PT, plane.MAX_X, plane.MAX_Y); printPlane(plane, NULL, options); filename = genFilename(plane.NUM_PT, plane.generation); if(plane.instance_size > 1){ MST = prims(plane); printMST(MST,plane.instance_size, filename, options); degrees = nodeDegree(MST, plane.instance_size-1); } else { printf("Can not generate MST, insufficient nodes \n"); } plane.generation++; } } RST* root; int rootIndex = findRoot(MST, plane.instance_size-1); printf("Root index %i\n", rootIndex); root = buildNode(NULL, rootIndex, NULL, 0, 0 ); buildTree(root, plane.instance, MST, plane.instance_size-1); // Need to create code to free plane.instance and and sub arrays of instance printList(root,0); //printf("Overlap is %i\n", maxOverlap(root)); //printf("Distance is %i\n", totalDistance(root)); freeMST(MST, plane.instance_size-1); freePlane(&plane); freeRST(root); // need to free MST return 0; }
void GFXDrawUtil::_drawSolidPolyhedron( const GFXStateBlockDesc &desc, const AnyPolyhedron &poly, const ColorI &color, const MatrixF *xfm ) { GFXDEBUGEVENT_SCOPE( GFXDrawUtil_DrawSolidPolyhedron, ColorI::GREEN ); const U32 numPoints = poly.getNumPoints(); const Point3F* points = poly.getPoints(); const PlaneF* planes = poly.getPlanes(); const Point3F viewDir = GFX->getViewMatrix().getForwardVector(); // Create a temp buffer for the vertices and // put all the polyhedron's points in there. GFXVertexBufferHandle< GFXVertexPC > verts( mDevice, numPoints, GFXBufferTypeVolatile ); verts.lock(); for( U32 i = 0; i < numPoints; ++ i ) { verts[ i ].point = points[ i ]; verts[ i ].color = color; } if( xfm ) { for( U32 i = 0; i < numPoints; ++ i ) xfm->mulP( verts[ i ].point ); } verts.unlock(); // Allocate a temp buffer for the face indices. const U32 numIndices = poly.getNumEdges() * 2; const U32 numPlanes = poly.getNumPlanes(); GFXPrimitiveBufferHandle prims( mDevice, numIndices, 0, GFXBufferTypeVolatile ); // Unfortunately, since polygons may have varying numbers of // vertices, we also need to retain that information. FrameTemp< U32 > numIndicesForPoly( numPlanes ); U32 numPolys = 0; // Create all the polygon indices. U16* indices; prims.lock( &indices ); U32 idx = 0; for( U32 i = 0; i < numPlanes; ++ i ) { // Since face extraction is somewhat costly, don't bother doing it for // backfacing polygons if culling is enabled. if( !desc.cullDefined || desc.cullMode != GFXCullNone ) { F32 dot = mDot( planes[ i ], viewDir ); // See if it faces *the same way* as the view direction. This would // normally mean that the face is *not* backfacing but since we expect // planes on the polyhedron to be facing *inwards*, we need to reverse // the logic here. if( dot > 0.f ) continue; } U32 numPoints = poly.extractFace( i, &indices[ idx ], numIndices - idx ); numIndicesForPoly[ numPolys ] = numPoints; idx += numPoints; numPolys ++; } prims.unlock(); // Set up state. mDevice->setStateBlockByDesc( desc ); mDevice->setupGenericShaders(); mDevice->setVertexBuffer( verts ); mDevice->setPrimitiveBuffer( prims ); // Render one triangle fan for each polygon. U32 startIndex = 0; for( U32 i = 0; i < numPolys; ++ i ) { U32 numVerts = numIndicesForPoly[ i ]; mDevice->drawIndexedPrimitive( GFXTriangleFan, 0, 0, numPoints, startIndex, numVerts - 2 ); startIndex += numVerts; } }