Commit cf38bb2b authored by kraus's avatar kraus
Browse files

rebuild QuadTree correctly when OpalFlexibleCollimator is updated

parent a20cc2db
...@@ -200,6 +200,9 @@ ElementBase::ElementType FlexibleCollimator::getType() const { ...@@ -200,6 +200,9 @@ ElementBase::ElementType FlexibleCollimator::getType() const {
} }
void FlexibleCollimator::setDescription(const std::string &desc) { void FlexibleCollimator::setDescription(const std::string &desc) {
tree_m.reset();
holes_m.clear();
mslang::Function *fun; mslang::Function *fun;
if (!mslang::parse(desc, fun)) if (!mslang::parse(desc, fun))
...@@ -210,7 +213,7 @@ void FlexibleCollimator::setDescription(const std::string &desc) { ...@@ -210,7 +213,7 @@ void FlexibleCollimator::setDescription(const std::string &desc) {
if (holes_m.size() == 0) return; if (holes_m.size() == 0) return;
for (auto it: holes_m) { for (std::shared_ptr<mslang::Base> & it: holes_m) {
it->computeBoundingBox(); it->computeBoundingBox();
} }
...@@ -224,7 +227,7 @@ void FlexibleCollimator::setDescription(const std::string &desc) { ...@@ -224,7 +227,7 @@ void FlexibleCollimator::setDescription(const std::string &desc) {
bb.center_m[1] + 0.5 * bb.height_m, bb.center_m[1] + 0.5 * bb.height_m,
0.0); 0.0);
for (auto it: holes_m) { for (const std::shared_ptr<mslang::Base> & it: holes_m) {
const mslang::BoundingBox &bb = it->bb_m; const mslang::BoundingBox &bb = it->bb_m;
llc[0] = std::min(llc[0], bb.center_m[0] - 0.5 * bb.width_m); llc[0] = std::min(llc[0], bb.center_m[0] - 0.5 * bb.width_m);
llc[1] = std::min(llc[1], bb.center_m[1] - 0.5 * bb.height_m); llc[1] = std::min(llc[1], bb.center_m[1] - 0.5 * bb.height_m);
...@@ -246,10 +249,21 @@ void FlexibleCollimator::setDescription(const std::string &desc) { ...@@ -246,10 +249,21 @@ void FlexibleCollimator::setDescription(const std::string &desc) {
tree_m.objects_m.insert(tree_m.objects_m.end(), holes_m.begin(), holes_m.end()); tree_m.objects_m.insert(tree_m.objects_m.end(), holes_m.begin(), holes_m.end());
tree_m.buildUp(); tree_m.buildUp();
// if (Ippl::myNode() == 0) {
// std::ofstream out("data/quadtree.gpl");
// tree_m.writeGnuplot(out);
// }
delete fun; delete fun;
}
void FlexibleCollimator::writeHolesAndQuadtree(const std::string &baseFilename) const {
if (Ippl::myNode() == 0) {
std::ofstream out("data/" + baseFilename + "_quadtree.gpl");
tree_m.writeGnuplot(out);
out.close();
out.open("data/" + baseFilename + "_holes.gpl");
for (const std::shared_ptr<mslang::Base> &obj: holes_m) {
obj->writeGnuplot(out);
}
out.close();
}
} }
\ No newline at end of file
...@@ -62,6 +62,8 @@ public: ...@@ -62,6 +62,8 @@ public:
bool isStopped(const Vector_t &R, const Vector_t &P, double recpgamma); bool isStopped(const Vector_t &R, const Vector_t &P, double recpgamma);
void writeHolesAndQuadtree(const std::string &baseFilename) const;
private: private:
// Not implemented. // Not implemented.
......
...@@ -25,6 +25,11 @@ namespace mslang { ...@@ -25,6 +25,11 @@ namespace mslang {
nodes_m.clear(); nodes_m.clear();
} }
void QuadTree::reset() {
objects_m.clear();
nodes_m.clear();
}
void QuadTree::operator=(const QuadTree &right) { void QuadTree::operator=(const QuadTree &right) {
level_m = right.level_m; level_m = right.level_m;
objects_m.insert(objects_m.end(), objects_m.insert(objects_m.end(),
...@@ -85,13 +90,10 @@ namespace mslang { ...@@ -85,13 +90,10 @@ namespace mslang {
} }
} }
void QuadTree::writeGnuplot(std::ofstream &out) const { void QuadTree::writeGnuplot(std::ostream &out) const {
out << "# level: " << level_m << ", size: " << objects_m.size() << std::endl; out << "# level: " << level_m << ", size: " << objects_m.size() << std::endl;
bb_m.writeGnuplot(out); bb_m.writeGnuplot(out);
out << "# num holes: " << objects_m.size() << std::endl; out << "# num holes: " << objects_m.size() << std::endl;
// for (const Base *obj: objects_m) {
// obj->writeGnuplot(out);
// }
out << std::endl; out << std::endl;
if (nodes_m.size() != 0) { if (nodes_m.size() != 0) {
......
...@@ -28,12 +28,14 @@ namespace mslang { ...@@ -28,12 +28,14 @@ namespace mslang {
~QuadTree(); ~QuadTree();
void reset();
void operator=(const QuadTree &right); void operator=(const QuadTree &right);
void transferIfInside(std::list<std::shared_ptr<Base> > &objs); void transferIfInside(std::list<std::shared_ptr<Base> > &objs);
void buildUp(); void buildUp();
void writeGnuplot(std::ofstream &out) const; void writeGnuplot(std::ostream &out) const;
bool isInside(const Vector_t &R) const; bool isInside(const Vector_t &R) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment