LevelAABBTree::LevelAABBTree(FLevelLocals *lev) { Level = lev; // Calculate the center of all lines TArray<FVector2> centroids; for (unsigned int i = 0; i < Level->lines.Size(); i++) { FVector2 v1 = { (float)Level->lines[i].v1->fX(), (float)Level->lines[i].v1->fY() }; FVector2 v2 = { (float)Level->lines[i].v2->fX(), (float)Level->lines[i].v2->fY() }; centroids.Push((v1 + v2) * 0.5f); } // Create the static subtree if (!GenerateTree(¢roids[0], false)) return; int staticroot = nodes.Size() - 1; dynamicStartNode = nodes.Size(); dynamicStartLine = treelines.Size(); // Create the dynamic subtree if (GenerateTree(¢roids[0], true)) { int dynamicroot = nodes.Size() - 1; // Create a shared root node FVector2 aabb_min, aabb_max; const auto &left = nodes[staticroot]; const auto &right = nodes[dynamicroot]; aabb_min.X = MIN(left.aabb_left, right.aabb_left); aabb_min.Y = MIN(left.aabb_top, right.aabb_top); aabb_max.X = MAX(left.aabb_right, right.aabb_right); aabb_max.Y = MAX(left.aabb_bottom, right.aabb_bottom); nodes.Push({ aabb_min, aabb_max, staticroot, dynamicroot }); } // Add the lines referenced by the leaf nodes treelines.Resize(mapLines.Size()); for (unsigned int i = 0; i < mapLines.Size(); i++) { const auto &line = Level->lines[mapLines[i]]; auto &treeline = treelines[i]; treeline.x = (float)line.v1->fX(); treeline.y = (float)line.v1->fY(); treeline.dx = (float)line.v2->fX() - treeline.x; treeline.dy = (float)line.v2->fY() - treeline.y; } }
int main(int argc, char *argv[]) { if (CheckArgCount(argc) == 0) { return EXIT_FAILURE; } /* Open the input file */ FILE* fptr = NULL; if ((fptr = OpenFile(argv[1], "rb")) == NULL) { return EXIT_FAILURE; } /* Generate the huffman tree from the header of the file */ LEAF* head = NULL; int charactersInData; if ((head = GenerateTree(fptr, &charactersInData)) == NULL) { /* After this call fptr is pointing to the data */ return EXIT_FAILURE; } /* Open the output file */ FILE* outfptr = NULL; if ((outfptr = OpenFile(argv[2], "w+")) == NULL) { return EXIT_FAILURE; } /* Print the data to the output file */ DecodeUsingTree(fptr, outfptr, head, charactersInData); /* When we make this call fptr is pointing directly to the data */ fclose(fptr); fclose(outfptr); // PostOrderWalk(head); DestroyTree(head); return EXIT_SUCCESS; }
ExpressionNode *GenerateTree(const mtlChars &expr) { ExpressionNode *tree = NULL; if (!GenerateTree(tree, expr)) { if (tree != NULL) { delete tree; tree = NULL; } } return tree; }
int main(int argc, char *argv[]) { if (CheckArgCount(argc) == 0) { return EXIT_FAILURE; } FILE* fptr = NULL; if ((fptr = OpenFile(argv[1], "rb")) == NULL) { return EXIT_FAILURE; } LEAF* head = NULL; if ((head = GenerateTree(fptr)) == NULL) { return EXIT_FAILURE; } fclose(fptr); PostOrderWalk(head); DestroyTree(head); return EXIT_SUCCESS; }
bool AssignVar(CompileInstance &inst, const mtlChars &name, const mtlChars &expr) { mtlChars base_name = GetBaseName(name); Definition *type = GetType(inst, base_name); if (type == NULL) { AddError(inst, "Undeclared variable", name); return false; } if (type->mut != Mutable) { AddError(inst, "Modifying a constant", name); return false; } ExpressionNode *tree = GenerateTree(expr); if (tree == NULL) { AddError(inst, "Malformed expression", expr); return false; } mtlChars base_mem = GetBaseMembers(name); bool result = true; Parser parser; mtlList<mtlChars> ops; mtlList<mtlChars> m; mtlString order_str; const int num_lanes = (base_mem.GetSize() > 0) ? base_mem.GetSize() : type->type.size; for (int lane = 0; lane < num_lanes; ++lane) { order_str.Free(); const int stack_size = tree->Evaluate(name, order_str, lane, 0); PushStack(inst, stack_size); order_str.SplitByChar(ops, ';'); mtlItem<mtlChars> *op = ops.GetFirst(); while (op != NULL && op->GetItem().GetSize() > 0) { parser.SetBuffer(op->GetItem()); switch (parser.MatchPart("%s+=%s%|%s-=%s%|%s*=%s%|%s/=%s%|%s=%s", m, NULL)) { case 0: EmitInstruction(inst, swsl::FLT_ADD_MM); break; case 1: EmitInstruction(inst, swsl::FLT_SUB_MM); break; case 2: EmitInstruction(inst, swsl::FLT_MUL_MM); break; case 3: EmitInstruction(inst, swsl::FLT_DIV_MM); break; case 4: EmitInstruction(inst, swsl::FLT_SET_MM); break; default: AddError(inst, "Invalid syntax", op->GetItem()); return false; break; } mtlItem<swsl::Instruction> *instr_item = inst.program.GetLast(); const mtlChars dst = m.GetFirst()->GetItem(); const mtlChars src = m.GetFirst()->GetNext()->GetItem(); EmitOperand(inst, dst); if (src.IsFloat()) { *((int*)(&instr_item->GetItem().instr)) += 1; } EmitOperand(inst, src); op = op->GetNext(); } PopStack(inst, stack_size); } delete tree; return result; }
bool GenerateTree(ExpressionNode *&node, mtlChars expr) { static const char zero_str[] = "0"; static const int OperationClasses = 2; static const char *Operations[OperationClasses] = { "+-", "*/" //,"|&" }; Parser p; p.SetBuffer(expr); mtlList<mtlChars> params; switch (p.Match("(%s)%|%s", params)) { case 0: case 1: expr = params.GetFirst()->GetItem(); break; default: return false; } if (expr.GetSize() == 0) { node = NULL; return false; } bool retval = true; int opIndex = -1; for (int i = 0; i < OperationClasses; ++i) { mtlChars ops = mtlChars::FromDynamic(Operations[i]); opIndex = FindOperation(ops, expr); if (opIndex != -1) { break; } } if (opIndex != -1) { OperationNode *op_node = new OperationNode; op_node->operation = expr[opIndex]; op_node->left = NULL; op_node->right = NULL; mtlChars lexpr = mtlChars(expr, 0, opIndex); mtlChars rexpr = mtlChars(expr, opIndex + 1, expr.GetSize()); if (expr[opIndex] == '-' && lexpr.GetSize() == 0) { lexpr = zero_str; } retval = GenerateTree(op_node->left, lexpr) && GenerateTree(op_node->right, rexpr); node = op_node; } else { // STOPPING CONDITION ValueNode *val_node = new ValueNode; val_node->term.Copy(expr); node = val_node; } return retval; }
//_____________________________________________________________________________ Bool_t ProofAux::Process(Long64_t entry) { // The Process() function is called for each entry in the tree (or possibly // keyed object in the case of PROOF) to be processed. The entry argument // specifies which entry in the currently loaded tree is to be processed. // It can be passed to either ProofAux::GetEntry() or TBranch::GetEntry() // to read either all or the required parts of the data. When processing // keyed objects with PROOF, the object is already loaded and is available // via the fObject pointer. // // This function should contain the "body" of the analysis. It can contain // simple or elaborate selection criteria, run algorithms on the data // of the event and typically fill histograms. // // The processing can be stopped by calling Abort(). // // Use fStatus to set the return value of TTree::Process(). // // The return value is currently not used. // Nothing to do if the action if not defined if (fAction < 0) { Error("Process", "action not specified!"); return kFALSE; } // Link to current element, if any TDSetElement *fCurrent = 0; TPair *elemPair = 0; if (fInput && (elemPair = dynamic_cast<TPair *>(fInput->FindObject("PROOF_CurrentElement")))) { if ((fCurrent = dynamic_cast<TDSetElement *>(elemPair->Value()))) { Info("Process", "entry %lld: file: '%s'", entry, fCurrent->GetName()); } else { Error("Process", "entry %lld: no file specified!", entry); return kFALSE; } } // Act now if (fAction == 0) { TString fnt; // Generate the TTree and save it in the specified file if (GenerateTree(fCurrent->GetName(), fNEvents, fnt) != 0) { Error("Process", "problems generating tree (%lld, %s, %lld)", entry, fCurrent->GetName(), fNEvents); return kFALSE; } // The output filename TString fnf(fnt); TString xf = gSystem->BaseName(fnf); fnf = gSystem->DirName(fnf); if (xf.Contains("tree")) { xf.ReplaceAll("tree", "friend"); } else { if (xf.EndsWith(".root")) { xf.ReplaceAll(".root", "_friend.root"); } else { xf += "_friend"; } } fnf += TString::Format("/%s", xf.Data()); // Generate the TTree friend and save it in the specified file if (GenerateFriend(fnt, fnf) != 0) { Error("Process", "problems generating friend tree for %s (%s)", fCurrent->GetName(), fnt.Data()); return kFALSE; } } else if (fAction == 1) { TString fnt; // Generate the TTree and save it in the specified file if (GenerateTree(fCurrent->GetName(), fNEvents, fnt) != 0) { Error("Process", "problems generating tree (%lld, %s, %lld)", entry, fCurrent->GetName(), fNEvents); return kFALSE; } // Generate the TTree friend and save it in the specified file if (GenerateFriend(fnt) != 0) { Error("Process", "problems generating friend tree for %s (%s)", fCurrent->GetName(), fnt.Data()); return kFALSE; } } else { // Unknown action Warning("Process", "do not know how to process action %d - do nothing", fAction); return kFALSE; } return kTRUE; }