#include #include #include "TGeoNode.h" #include "TGeoVolume.h" #include "TGeoBBox.h" #include "TMath.h" #include "TGeoManager.h" #include "TGeoMatrix.h" #include "TGeoBoolNode.h" #include "TGeoCompositeShape.h" #include "TGeoArb8.h" #include "TGeoPcon.h" TString createConeFunc = "def createCone(z,rmin,rmax,n): \n" " bpy.ops.mesh.primitive_circle_add(enter_editmode=True, location=(0, 0, z[0])) \n" " fz=z[0] \n" " bpy.ops.transform.resize(value=(rmin[0], rmin[0], rmin[0])) \n" " bpy.ops.mesh.extrude_region_move() \n" " f=rmin[0] \n" " bpy.ops.transform.resize(value=(rmax[0]/f,rmax[0]/f,rmax[0]/f)) \n" " f=rmax[0] \n" " for i in range(1, n): \n" " bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate={\"value\":(0, 0, z[i]-fz),\"constraint_orientation\":'GLOBAL'}) \n" " fz=z[i] \n" " bpy.ops.transform.resize(value=(rmax[i]/f,rmax[i]/f,rmax[i]/f)) \n" " f=rmax[i] \n" " bpy.ops.mesh.extrude_region_move() \n" " bpy.ops.transform.resize(value=(1/f,1/f,1/f)) \n" " f=rmin[n-1] \n" " fz=-z[n-2] \n" " bpy.ops.transform.resize(value=(f,f,f)) \n" // " for i in range(n-2, -1,-1): \n" // " bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate={\"value\":(0, 0, -z[i+1]-fz),\"constraint_orientation\":'GLOBAL'}) \n" // " fz=-z[i+1] \n" // " bpy.ops.transform.resize(value=(rmin[i]/f,rmin[i]/f,rmin[i]/f)) \n" // " f=rmin[i] \n" " return \n"; TString join(TString mask){ TString code = ""; code += "objexist = False \n"; code += "for obj in bpy.context.scene.objects: \n"; code += " if(obj.name.startswith('" + mask +"')): \n"; code += " bpy.context.scene.objects.active=obj \n"; code += " obj.select = True \n"; code += " objexist = True \n"; code += "if(objexist): \n"; code += " bpy.ops.object.join() \n"; code += " bpy.ops.object.select_all(action='TOGGLE') \n"; return code; } TString blendTGeoBBox(TGeoShape *shape,TString name, Double_t *t, Double_t *r){ TGeoBBox * box = (TGeoBBox*)shape; TString spy=""; spy += Form("bpy.ops.mesh.primitive_cube_add(location=(%f,%f,%f), rotation=(%f,%f,%f)) \n",t[0],t[1],t[2],r[1],r[2],r[0]); spy += "bpy.context.object.name=\"" + name + "\" \n"; spy += Form("bpy.context.object.scale[0]=%f \n",box->GetDX()); spy += Form("bpy.context.object.scale[1]=%f \n",box->GetDY()); spy += Form("bpy.context.object.scale[2]=%f \n",box->GetDZ()); spy += "bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS') \n"; return spy; } TString blendTGeoTrap(TGeoShape *shape,TString name, Double_t *t, Double_t *r){ TGeoTrap *trap = (TGeoTrap*)shape; Double_t *vert = trap->GetVertices(); Double_t dz = trap->GetDz(); TString spy=""; TString trapf = "faceArb8 = [(0, 1, 2, 3),(4, 7, 6, 5),(0, 4, 5, 1),(1, 5, 6, 2),(2, 6, 7, 3),(4, 0, 3, 7)] \n"; TString trapv = "vertArb8 =["; for(Int_t p=0; p<8; p++){ if(p==4) dz = -dz; if(p<7) trapv += Form("(%f,%f,%f),",vert[p*2],vert[p*2+1],-dz); else trapv += Form("(%f,%f,%f)",vert[p*2],vert[p*2+1],-dz); } trapv += "] \n"; spy += trapv + trapf; spy += "meshArb8 = bpy.data.meshes.new(\"" + name + "\") \n"; spy += "meshArb8.from_pydata(vertArb8,[],faceArb8) \n"; spy += "meshArb8.update(calc_edges=True) \n"; spy += "objArb8 = bpy.data.objects.new(\"" + name + "\", meshArb8)" + " \n"; spy += "bpy.context.scene.objects.link(objArb8) \n"; spy += "objArb8.select = True \n"; spy += "bpy.context.scene.objects.active = objArb8 \n"; spy += Form("bpy.context.object.location.xyz = [%f,%f,%f] \n",t[0],t[1],t[2]); spy += Form("bpy.context.object.rotation_euler.x=%f \n",r[1]); spy += Form("bpy.context.object.rotation_euler.y=%f \n",r[2]); spy += Form("bpy.context.object.rotation_euler.z=%f \n",r[0]); return spy; } TString blendTGeoPcon(TGeoShape *shape,TString name, Double_t *t, Double_t *r){ if(name.Contains("Vacuum")) return ""; if(name.Contains("BarrelDIRC")) return ""; TGeoPcon * con = (TGeoPcon*)shape; TString spy=""; Int_t segments = con->GetNz(); TString z="z=[",rmin="rmin=[",rmax="rmax=["; TString n = Form("n=%d \n", segments); std::cout<<"Name "<< name <<" "<GetZ(i)); rmin += Form("%f,",con->GetRmin(i)); rmax += Form("%f,",con->GetRmax(i)); std::cout<<"z "<GetZ(i) <<" rmin "<< con->GetRmin(i) << " rmax "<< con->GetRmax(i)<GetBoolNode(); TString csaname = bnode->GetRightShape()->ClassName(); std::cout<<"csaname "<GetMedium("air")); //top->AddNode(gGeoManager->GetTopVolume(), 0,0); top->AddNode(gGeoManager->GetVolume("lExpHall"), 0,0); gGeoManager->SetTopVolume(top); gGeoManager->CloseGeometry(); //gGeoManager->GetTopVolume()->Draw("ogl"); TGeoIterator nextNode(gGeoManager->GetTopVolume()); TGeoNode *currentNode = 0; TGeoNode *motherNode = 0; TGeoNode *gmotherNode = 0; Int_t level; Int_t nd; ofstream file; file.open ("export.py"); file<<"import bpy \n" << createConeFunc; TGeoRotation *grm; while ((currentNode = nextNode())) { level = nextNode.GetLevel(); nd = currentNode->GetNdaughters(); TGeoMatrix *gmatrix; Double_t t[3]={0}, r[3]={0}, ttt[3]={0}; if (true){ for (int i = level; i > 1; i--) { if (i == 1) motherNode = gGeoManager->GetTopNode(); else motherNode = nextNode.GetNode(i); TGeoHMatrix matrix = *(motherNode->GetMatrix()); // if(i==level) gmatrix =(TGeoMatrix) matrix; // else gmatrix = gmatrix*(TGeoMatrix)matrix; const Double_t *tt=matrix.GetTranslation(); motherNode->LocalToMaster(t,ttt); // point coordinates in the global RS const Double_t *tr=matrix.GetRotationMatrix(); Double_t trl[3]={0}; TGeoRotation *rm = new TGeoRotation(); rm->SetMatrix(tr); rm->GetAngles(trl[0],trl[1],trl[2]); for(Int_t m=0; m<3; m++){ //t[m]+=tt[m]; t[m] = ttt[m]; r[m] += trl[m]*TMath::Pi()/180.; } } if(level==1 ) motherNode = gGeoManager->GetTopNode(); else motherNode = nextNode.GetNode(--level); TString pname = motherNode->GetName(); TString name = currentNode->GetName(); // if(name.BeginsWith("lFront") || name.BeginsWith("lDirc")) { std::cout<<"name "<< name << " parent " << pname <GetNdaughters(); TGeoShape *shape = currentNode->GetVolume()->GetShape(); TString shapeName = shape->ClassName(); if(shapeName=="TGeoBBox") file <